[PATCH i-g-t 1/2] lib/xe/xe_query: Add xe_gt_type() and xe_is_main_gt() helpers

Marcin Bernatowicz marcin.bernatowicz at linux.intel.com
Fri Aug 29 10:40:36 UTC 2025


Introduce xe_gt_type() to return the GT type from query data. This
replaces open-coded access in xe_is_media_gt() and makes it easy to
add new GT-specific helpers. Add xe_is_main_gt() for MAIN GT checks.

Signed-off-by: Marcin Bernatowicz <marcin.bernatowicz at linux.intel.com>
Cc: Adam Miszczak <adam.miszczak at linux.intel.com>
Cc: Jakub Kolakowski <jakub1.kolakowski at intel.com>
Cc: Lukasz Laguna <lukasz.laguna at intel.com>
Cc: Michal Wajdeczko <michal.wajdeczko at intel.com>
Cc: Satyanarayana K V P <satyanarayana.k.v.p at intel.com>
---
 lib/xe/xe_query.c | 40 +++++++++++++++++++++++++++++++---------
 lib/xe/xe_query.h |  2 ++
 2 files changed, 33 insertions(+), 9 deletions(-)

diff --git a/lib/xe/xe_query.c b/lib/xe/xe_query.c
index 3b8a682f8..9b88cce8d 100644
--- a/lib/xe/xe_query.c
+++ b/lib/xe/xe_query.c
@@ -917,24 +917,46 @@ bool xe_has_media_gt(int fd)
 }
 
 /**
- * xe_is_media_gt:
+ * xe_gt_type:
  * @fd: xe device fd
  * @gt: gt id
  *
- * Returns true if @gt for device @fd is media GT, otherwise false.
+ * Returns the type of @gt for device @fd (e.g.,
+ * DRM_XE_QUERY_GT_TYPE_MAIN, DRM_XE_QUERY_GT_TYPE_MEDIA).
  */
-bool xe_is_media_gt(int fd, int gt)
+uint16_t xe_gt_type(int fd, int gt)
 {
-	struct xe_device *xe_dev;
+	struct xe_device *xe_dev = find_in_cache(fd);
 
-	xe_dev = find_in_cache(fd);
 	igt_assert(xe_dev);
-	igt_assert(gt < xe_number_gt(fd));
+	igt_assert_f(gt >= 0 && gt < xe_number_gt(fd),
+		     "gt %d out of range [0..%d)\n", gt, xe_number_gt(fd));
 
-	if (xe_dev->gt_list->gt_list[gt].type == DRM_XE_QUERY_GT_TYPE_MEDIA)
-		return true;
+	return xe_dev->gt_list->gt_list[gt].type;
+}
 
-	return false;
+/**
+ * xe_is_media_gt:
+ * @fd: xe device fd
+ * @gt: gt id
+ *
+ * Returns true if @gt for device @fd is MEDIA GT, otherwise false.
+ */
+bool xe_is_media_gt(int fd, int gt)
+{
+	return xe_gt_type(fd, gt) == DRM_XE_QUERY_GT_TYPE_MEDIA;
+}
+
+/**
+ * xe_is_main_gt:
+ * @fd: xe device fd
+ * @gt: gt id
+ *
+ * Returns true if @gt for device @fd is MAIN GT, otherwise false.
+ */
+bool xe_is_main_gt(int fd, int gt)
+{
+	return xe_gt_type(fd, gt) == DRM_XE_QUERY_GT_TYPE_MAIN;
 }
 
 /**
diff --git a/lib/xe/xe_query.h b/lib/xe/xe_query.h
index cc54ec956..4b8a6ee77 100644
--- a/lib/xe/xe_query.h
+++ b/lib/xe/xe_query.h
@@ -127,7 +127,9 @@ const char *xe_engine_class_short_string(uint32_t engine_class);
 bool xe_has_engine_class(int fd, uint16_t engine_class);
 struct drm_xe_engine *xe_find_engine_by_class(int fd, uint16_t engine_class);
 bool xe_has_media_gt(int fd);
+uint16_t xe_gt_type(int fd, int gt);
 bool xe_is_media_gt(int fd, int gt);
+bool xe_is_main_gt(int fd, int gt);
 uint16_t xe_gt_get_tile_id(int fd, int gt);
 uint32_t *xe_hwconfig_lookup_value(int fd, enum intel_hwconfig attribute, uint32_t *len);
 
-- 
2.31.1



More information about the igt-dev mailing list