[PATCH 3/5] drm/xe/tests/pci: Ensure all platforms have a valid GT/tile count

Matt Roper matthew.d.roper at intel.com
Fri Jun 13 00:14:42 UTC 2025


Add a simple kunit test to ensure each platform's GT per tile count is
non-zero and does not exceed the global XE_MAX_GT_PER_TILE definition.

We need to move 'struct xe_subplatform_desc' from the .c file to the
types header to ensure it is accessible from the kunit test.

Signed-off-by: Matt Roper <matthew.d.roper at intel.com>
---
 drivers/gpu/drm/xe/tests/xe_pci.c      | 24 ++++++++++++++++
 drivers/gpu/drm/xe/tests/xe_pci_test.c | 15 ++++++++++
 drivers/gpu/drm/xe/tests/xe_pci_test.h |  3 ++
 drivers/gpu/drm/xe/xe_pci.c            | 38 ------------------------
 drivers/gpu/drm/xe/xe_pci_types.h      | 40 ++++++++++++++++++++++++++
 5 files changed, 82 insertions(+), 38 deletions(-)

diff --git a/drivers/gpu/drm/xe/tests/xe_pci.c b/drivers/gpu/drm/xe/tests/xe_pci.c
index 1d3e2e50c355..f8858e193213 100644
--- a/drivers/gpu/drm/xe/tests/xe_pci.c
+++ b/drivers/gpu/drm/xe/tests/xe_pci.c
@@ -56,6 +56,30 @@ void xe_call_for_each_media_ip(xe_media_fn xe_fn)
 }
 EXPORT_SYMBOL_IF_KUNIT(xe_call_for_each_media_ip);
 
+/**
+ * xe_call_for_each_platform - Iterate over all recognized platforms
+ * @xe_fn: Function to call for each device.
+ *
+ * This function iterates over the descriptors for all platforms recognized
+ * by the driver and calls @xe_fn: for each one of them.
+ */
+void xe_call_for_each_platform(xe_platform_fn xe_fn)
+{
+	const struct xe_device_desc *desc, *last = NULL;
+
+	for (int i = 0; i < ARRAY_SIZE(pciidlist); i++) {
+		desc = (const struct xe_device_desc *)pciidlist[i].driver_data;
+		if (!desc)
+			break;
+		if (desc == last)
+			continue;
+
+		xe_fn(desc);
+		last = desc;
+	}
+}
+EXPORT_SYMBOL_IF_KUNIT(xe_call_for_each_platform);
+
 static void fake_read_gmdid(struct xe_device *xe, enum xe_gmdid_type type,
 			    u32 *ver, u32 *revid)
 {
diff --git a/drivers/gpu/drm/xe/tests/xe_pci_test.c b/drivers/gpu/drm/xe/tests/xe_pci_test.c
index 744a37583d2d..a401a91af555 100644
--- a/drivers/gpu/drm/xe/tests/xe_pci_test.c
+++ b/drivers/gpu/drm/xe/tests/xe_pci_test.c
@@ -42,6 +42,15 @@ static void check_media_ip(const struct xe_media_desc *media)
 	KUNIT_ASSERT_EQ(test, mask, 0);
 }
 
+static void check_platform_gt_count(const struct xe_device_desc *platform)
+{
+	struct kunit *test = kunit_get_current_test();
+	int max_gt = platform->max_gt_per_tile;
+
+	KUNIT_ASSERT_GT(test, max_gt, 0);
+	KUNIT_ASSERT_LE(test, max_gt, XE_MAX_GT_PER_TILE);
+}
+
 static void xe_gmdid_graphics_ip(struct kunit *test)
 {
 	xe_call_for_each_graphics_ip(check_graphics_ip);
@@ -52,9 +61,15 @@ static void xe_gmdid_media_ip(struct kunit *test)
 	xe_call_for_each_media_ip(check_media_ip);
 }
 
+static void xe_platform_gt_count(struct kunit *test)
+{
+	xe_call_for_each_platform(check_platform_gt_count);
+}
+
 static struct kunit_case xe_pci_tests[] = {
 	KUNIT_CASE(xe_gmdid_graphics_ip),
 	KUNIT_CASE(xe_gmdid_media_ip),
+	KUNIT_CASE(xe_platform_gt_count),
 	{}
 };
 
diff --git a/drivers/gpu/drm/xe/tests/xe_pci_test.h b/drivers/gpu/drm/xe/tests/xe_pci_test.h
index ede46800aff1..5abbf522f7a8 100644
--- a/drivers/gpu/drm/xe/tests/xe_pci_test.h
+++ b/drivers/gpu/drm/xe/tests/xe_pci_test.h
@@ -14,13 +14,16 @@
 struct xe_device;
 struct xe_graphics_desc;
 struct xe_media_desc;
+struct xe_device_desc;
 
 typedef int (*xe_device_fn)(struct xe_device *);
 typedef void (*xe_graphics_fn)(const struct xe_graphics_desc *);
 typedef void (*xe_media_fn)(const struct xe_media_desc *);
+typedef void (*xe_platform_fn)(const struct xe_device_desc *);
 
 void xe_call_for_each_graphics_ip(xe_graphics_fn xe_fn);
 void xe_call_for_each_media_ip(xe_media_fn xe_fn);
+void xe_call_for_each_platform(xe_platform_fn xe_fn);
 
 struct xe_pci_fake_data {
 	enum xe_sriov_mode sriov_mode;
diff --git a/drivers/gpu/drm/xe/xe_pci.c b/drivers/gpu/drm/xe/xe_pci.c
index 3b997c941bbc..a4885f64c2c4 100644
--- a/drivers/gpu/drm/xe/xe_pci.c
+++ b/drivers/gpu/drm/xe/xe_pci.c
@@ -38,44 +38,6 @@ enum toggle_d3cold {
 	D3COLD_ENABLE,
 };
 
-struct xe_subplatform_desc {
-	enum xe_subplatform subplatform;
-	const char *name;
-	const u16 *pciidlist;
-};
-
-struct xe_device_desc {
-	/* Should only ever be set for platforms without GMD_ID */
-	const struct xe_ip *pre_gmdid_graphics_ip;
-	/* Should only ever be set for platforms without GMD_ID */
-	const struct xe_ip *pre_gmdid_media_ip;
-
-	const char *platform_name;
-	const struct xe_subplatform_desc *subplatforms;
-
-	enum xe_platform platform;
-
-	u8 dma_mask_size;
-	u8 max_remote_tiles:2;
-	u8 max_gt_per_tile:2;
-
-	u8 require_force_probe:1;
-	u8 is_dgfx:1;
-
-	u8 has_display:1;
-	u8 has_fan_control:1;
-	u8 has_heci_gscfi:1;
-	u8 has_heci_cscfi:1;
-	u8 has_llc:1;
-	u8 has_mbx_power_limits:1;
-	u8 has_pxp:1;
-	u8 has_sriov:1;
-	u8 needs_scratch:1;
-	u8 skip_guc_pc:1;
-	u8 skip_mtcfg:1;
-	u8 skip_pcode:1;
-};
-
 __diag_push();
 __diag_ignore_all("-Woverride-init", "Allow field overrides in table");
 
diff --git a/drivers/gpu/drm/xe/xe_pci_types.h b/drivers/gpu/drm/xe/xe_pci_types.h
index ca6b10d35573..e4bfbafa6809 100644
--- a/drivers/gpu/drm/xe/xe_pci_types.h
+++ b/drivers/gpu/drm/xe/xe_pci_types.h
@@ -8,6 +8,46 @@
 
 #include <linux/types.h>
 
+#include "xe_platform_types.h"
+
+struct xe_subplatform_desc {
+	enum xe_subplatform subplatform;
+	const char *name;
+	const u16 *pciidlist;
+};
+
+struct xe_device_desc {
+	/* Should only ever be set for platforms without GMD_ID */
+	const struct xe_ip *pre_gmdid_graphics_ip;
+	/* Should only ever be set for platforms without GMD_ID */
+	const struct xe_ip *pre_gmdid_media_ip;
+
+	const char *platform_name;
+	const struct xe_subplatform_desc *subplatforms;
+
+	enum xe_platform platform;
+
+	u8 dma_mask_size;
+	u8 max_remote_tiles:2;
+	u8 max_gt_per_tile:2;
+
+	u8 require_force_probe:1;
+	u8 is_dgfx:1;
+
+	u8 has_display:1;
+	u8 has_fan_control:1;
+	u8 has_heci_gscfi:1;
+	u8 has_heci_cscfi:1;
+	u8 has_llc:1;
+	u8 has_mbx_power_limits:1;
+	u8 has_pxp:1;
+	u8 has_sriov:1;
+	u8 needs_scratch:1;
+	u8 skip_guc_pc:1;
+	u8 skip_mtcfg:1;
+	u8 skip_pcode:1;
+};
+
 struct xe_graphics_desc {
 	u8 va_bits;
 	u8 vm_max_level;
-- 
2.49.0



More information about the Intel-xe mailing list