drm/xe: Add KUnit test for xe_pci.c IP engine lists
authorMatt Roper <matthew.d.roper@intel.com>
Thu, 6 Apr 2023 23:56:20 +0000 (16:56 -0700)
committerRodrigo Vivi <rodrigo.vivi@intel.com>
Tue, 19 Dec 2023 23:31:40 +0000 (18:31 -0500)
Add a simple KUnit test to ensure that the hardware engine lists for
GMD_ID IP definitions are sensible (i.e., no graphics engines defined
for the media IP and vice versa).

Only the IP descriptors for GMD_ID platforms are checked for now.
Presumably the engine lists on older pre-GMD_ID platforms shouldn't be
changing.  We can extend the KUnit testing in the future if we decide we
want to check those as well.

v2:
 - Add missing 'const' in xe_call_for_each_media_ip to avoid compiler
   warning.

Cc: Lucas De Marchi <lucas.demarchi@intel.com>
Reviewed-by: Lucas De Marchi <lucas.demarchi@intel.com>
Link: https://lore.kernel.org/r/20230406235621.1914492-9-matthew.d.roper@intel.com
Signed-off-by: Matt Roper <matthew.d.roper@intel.com>
Signed-off-by: Rodrigo Vivi <rodrigo.vivi@intel.com>
drivers/gpu/drm/xe/tests/Makefile
drivers/gpu/drm/xe/tests/xe_pci.c
drivers/gpu/drm/xe/tests/xe_pci_test.c [new file with mode: 0644]
drivers/gpu/drm/xe/tests/xe_pci_test.h

index 56919abb3f2a5e292c04df6d1b73b654bb0f3767..51f1a7f017d4d891cdbf62dea42d3d567e9e10aa 100644 (file)
@@ -4,5 +4,6 @@ obj-$(CONFIG_DRM_XE_KUNIT_TEST) += \
        xe_bo_test.o \
        xe_dma_buf_test.o \
        xe_migrate_test.o \
+       xe_pci_test.o \
        xe_rtp_test.o \
        xe_wa_test.o
index cc65ac5657b33de59f815135f77269917d55e213..2178ad71c0da2d4444010b758a9b6e970699346c 100644 (file)
@@ -62,6 +62,50 @@ int xe_call_for_each_device(xe_device_fn xe_fn)
        return ret;
 }
 
+/**
+ * xe_call_for_each_graphics_ip - Iterate over all recognized graphics IPs
+ * @xe_fn: Function to call for each device.
+ *
+ * This function iterates over the descriptors for all graphics IPs recognized
+ * by the driver and calls @xe_fn: for each one of them.
+ */
+void xe_call_for_each_graphics_ip(xe_graphics_fn xe_fn)
+{
+       const struct xe_graphics_desc *ip, *last = NULL;
+
+       for (int i = 0; i < ARRAY_SIZE(graphics_ip_map); i++) {
+               ip = graphics_ip_map[i].ip;
+               if (ip == last)
+                       continue;
+
+               xe_fn(ip);
+               last = ip;
+       }
+}
+EXPORT_SYMBOL_IF_KUNIT(xe_call_for_each_graphics_ip);
+
+/**
+ * xe_call_for_each_media_ip - Iterate over all recognized media IPs
+ * @xe_fn: Function to call for each device.
+ *
+ * This function iterates over the descriptors for all media IPs recognized
+ * by the driver and calls @xe_fn: for each one of them.
+ */
+void xe_call_for_each_media_ip(xe_media_fn xe_fn)
+{
+       const struct xe_media_desc *ip, *last = NULL;
+
+       for (int i = 0; i < ARRAY_SIZE(media_ip_map); i++) {
+               ip = media_ip_map[i].ip;
+               if (ip == last)
+                       continue;
+
+               xe_fn(ip);
+               last = ip;
+       }
+}
+EXPORT_SYMBOL_IF_KUNIT(xe_call_for_each_media_ip);
+
 int xe_pci_fake_device_init(struct xe_device *xe, enum xe_platform platform,
                            enum xe_subplatform subplatform)
 {
diff --git a/drivers/gpu/drm/xe/tests/xe_pci_test.c b/drivers/gpu/drm/xe/tests/xe_pci_test.c
new file mode 100644 (file)
index 0000000..9c6f6c2
--- /dev/null
@@ -0,0 +1,74 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright © 2023 Intel Corporation
+ */
+
+#include <drm/drm_drv.h>
+#include <drm/drm_kunit_helpers.h>
+
+#include <kunit/test.h>
+
+#include "tests/xe_test.h"
+
+#include "xe_device.h"
+#include "xe_pci_test.h"
+#include "xe_pci_types.h"
+
+static void check_graphics_ip(const struct xe_graphics_desc *graphics)
+{
+       struct kunit *test = xe_cur_kunit();
+       u64 mask = graphics->hw_engine_mask;
+
+       /* RCS, CCS, and BCS engines are allowed on the graphics IP */
+       mask &= ~(XE_HW_ENGINE_RCS_MASK |
+                 XE_HW_ENGINE_CCS_MASK |
+                 XE_HW_ENGINE_BCS_MASK);
+
+       /* Any remaining engines are an error */
+       KUNIT_ASSERT_EQ(test, mask, 0);
+}
+
+static void check_media_ip(const struct xe_media_desc *media)
+{
+       struct kunit *test = xe_cur_kunit();
+       u64 mask = media->hw_engine_mask;
+
+       /*
+        * VCS and VECS engines are allowed on the media IP
+        *
+        * TODO:  Add GSCCS once support is added to the driver.
+        */
+       mask &= ~(XE_HW_ENGINE_VCS_MASK |
+                 XE_HW_ENGINE_VECS_MASK);
+
+       /* Any remaining engines are an error */
+       KUNIT_ASSERT_EQ(test, mask, 0);
+}
+
+static void xe_gmdid_graphics_ip(struct kunit *test)
+{
+       xe_call_for_each_graphics_ip(check_graphics_ip);
+}
+
+static void xe_gmdid_media_ip(struct kunit *test)
+{
+       xe_call_for_each_media_ip(check_media_ip);
+}
+
+static struct kunit_case xe_pci_tests[] = {
+       KUNIT_CASE(xe_gmdid_graphics_ip),
+       KUNIT_CASE(xe_gmdid_media_ip),
+       {}
+};
+
+static struct kunit_suite xe_pci_test_suite = {
+       .name = "xe_pci",
+       .test_cases = xe_pci_tests,
+};
+
+kunit_test_suite(xe_pci_test_suite);
+
+MODULE_AUTHOR("Intel Corporation");
+MODULE_LICENSE("GPL");
+MODULE_IMPORT_NS(EXPORTED_FOR_KUNIT_TESTING);
+
index 43294e8c62bb247790544f845a0aad1a042e6938..cc0f1d141a4d75d7de11d97fc4733e917fe4f709 100644 (file)
@@ -9,6 +9,8 @@
 #include "xe_platform_types.h"
 
 struct xe_device;
+struct xe_graphics_desc;
+struct xe_media_desc;
 
 /*
  * Some defines just for clarity: these mean the test doesn't care about what
@@ -18,8 +20,12 @@ struct xe_device;
 #define XE_TEST_SUBPLATFORM_ANY        XE_SUBPLATFORM_UNINITIALIZED
 
 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 *);
 
 int xe_call_for_each_device(xe_device_fn xe_fn);
+void xe_call_for_each_graphics_ip(xe_graphics_fn xe_fn);
+void xe_call_for_each_media_ip(xe_media_fn xe_fn);
 
 int xe_pci_fake_device_init(struct xe_device *xe, enum xe_platform platform,
                            enum xe_subplatform subplatform);