]> git.proxmox.com Git - mirror_ubuntu-kernels.git/commitdiff
drm/xe: Generalize fake device creation
authorLucas De Marchi <lucas.demarchi@intel.com>
Sat, 1 Apr 2023 08:51:48 +0000 (01:51 -0700)
committerRodrigo Vivi <rodrigo.vivi@intel.com>
Tue, 19 Dec 2023 23:31:32 +0000 (18:31 -0500)
Instead of requiring tests to initialize a fake device an keep it in
sync with xe_pci.c when it's platform-dependent, export a function from
xe_pci.c to be used and piggy back on the device info creation. For
simpler tests that don't need any specific platform and just need a fake
xe device to pass around, xe_pci_fake_device_init_any() can be used.

Signed-off-by: Lucas De Marchi <lucas.demarchi@intel.com>
Reviewed-by: Matt Roper <matthew.d.roper@intel.com>
Link: https://lore.kernel.org/r/20230401085151.1786204-5-lucas.demarchi@intel.com
Signed-off-by: Rodrigo Vivi <rodrigo.vivi@intel.com>
drivers/gpu/drm/xe/tests/xe_pci.c
drivers/gpu/drm/xe/tests/xe_pci_test.h
drivers/gpu/drm/xe/xe_pci.c

index 643bddb35214913e918a93bcb4022cbedf09372a..cc65ac5657b33de59f815135f77269917d55e213 100644 (file)
@@ -8,6 +8,7 @@
 #include "tests/xe_test.h"
 
 #include <kunit/test.h>
+#include <kunit/visibility.h>
 
 struct kunit_test_data {
        int ndevs;
@@ -60,3 +61,49 @@ int xe_call_for_each_device(xe_device_fn xe_fn)
 
        return ret;
 }
+
+int xe_pci_fake_device_init(struct xe_device *xe, enum xe_platform platform,
+                           enum xe_subplatform subplatform)
+{
+       const struct pci_device_id *ent = pciidlist;
+       const struct xe_device_desc *desc;
+       const struct xe_subplatform_desc *subplatform_desc;
+
+       if (platform == XE_TEST_PLATFORM_ANY) {
+               desc = (const void *)ent->driver_data;
+               subplatform_desc = NULL;
+               goto done;
+       }
+
+       for (ent = pciidlist; ent->device; ent++) {
+               desc = (const void *)ent->driver_data;
+               if (desc->platform == platform)
+                       break;
+       }
+
+       if (!ent->device)
+               return -ENODEV;
+
+       if (subplatform == XE_TEST_SUBPLATFORM_ANY) {
+               subplatform_desc = desc->subplatforms;
+               goto done;
+       }
+
+       for (subplatform_desc = desc->subplatforms;
+            subplatform_desc && subplatform_desc->subplatform;
+            subplatform_desc++)
+               if (subplatform_desc->subplatform == subplatform)
+                       break;
+
+       if (subplatform == XE_SUBPLATFORM_NONE && subplatform_desc)
+               return -ENODEV;
+
+       if (subplatform != XE_SUBPLATFORM_NONE && !subplatform_desc)
+               return -ENODEV;
+
+done:
+       xe_info_init(xe, desc, subplatform_desc);
+
+       return 0;
+}
+EXPORT_SYMBOL_IF_KUNIT(xe_pci_fake_device_init);
index de65d8c9ccb536ceede4083bd1b9fa246027f32c..43294e8c62bb247790544f845a0aad1a042e6938 100644 (file)
@@ -6,10 +6,26 @@
 #ifndef _XE_PCI_TEST_H_
 #define _XE_PCI_TEST_H_
 
+#include "xe_platform_types.h"
+
 struct xe_device;
 
+/*
+ * Some defines just for clarity: these mean the test doesn't care about what
+ * platform it will get since it doesn't depend on any platform-specific bits
+ */
+#define XE_TEST_PLATFORM_ANY   XE_PLATFORM_UNINITIALIZED
+#define XE_TEST_SUBPLATFORM_ANY        XE_SUBPLATFORM_UNINITIALIZED
+
 typedef int (*xe_device_fn)(struct xe_device *);
 
 int xe_call_for_each_device(xe_device_fn xe_fn);
 
+int xe_pci_fake_device_init(struct xe_device *xe, enum xe_platform platform,
+                           enum xe_subplatform subplatform);
+
+#define xe_pci_fake_device_init_any(xe__)                                      \
+       xe_pci_fake_device_init(xe__, XE_TEST_PLATFORM_ANY,                     \
+                               XE_TEST_SUBPLATFORM_ANY)
+
 #endif
index c567436afcdc4c84c359c4bdd5f760d066a8d586..f6050a17c950fcbc5604fb349af759185ce9a10f 100644 (file)
@@ -423,7 +423,7 @@ static void xe_pci_remove(struct pci_dev *pdev)
 
 static int xe_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
 {
-       const struct xe_device_desc *desc = (void *)ent->driver_data;
+       const struct xe_device_desc *desc = (const void *)ent->driver_data;
        const struct xe_subplatform_desc *subplatform_desc;
        struct xe_device *xe;
        int err;