drm/xe/kunit: Add stub to read_gmdid
authorLucas De Marchi <lucas.demarchi@intel.com>
Tue, 5 Dec 2023 13:39:53 +0000 (05:39 -0800)
committerRodrigo Vivi <rodrigo.vivi@intel.com>
Thu, 21 Dec 2023 16:45:24 +0000 (11:45 -0500)
Currently it's not possible to test the WAs for platforms using gmdid
since they don't have the IP information on the descriptor struct. In
order to allow that, add a stub function for read_gmdid() that is
activated when the test executes, replacing the iomap and read of the
real register.

Reviewed-by: Matt Roper <matthew.d.roper@intel.com>
Link: https://lore.kernel.org/r/20231129232807.1499826-5-lucas.demarchi@intel.com
Link: https://lore.kernel.org/r/20231205133954.2089546-3-lucas.demarchi@intel.com
Signed-off-by: Lucas De Marchi <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
drivers/gpu/drm/xe/xe_step.h

index b93cb1e9610806fe7062c70ae336cbb0ab5d76fa..602793644f61d7145010feaaee2e36cee338fc40 100644 (file)
@@ -9,6 +9,7 @@
 
 #include <kunit/test-bug.h>
 #include <kunit/test.h>
+#include <kunit/test-bug.h>
 #include <kunit/visibility.h>
 
 struct kunit_test_data {
@@ -107,6 +108,21 @@ void xe_call_for_each_media_ip(xe_media_fn xe_fn)
 }
 EXPORT_SYMBOL_IF_KUNIT(xe_call_for_each_media_ip);
 
+static void fake_read_gmdid(struct xe_device *xe, enum xe_gmdid_type type,
+                           u32 *ver, u32 *revid)
+{
+       struct kunit *test = kunit_get_current_test();
+       struct xe_pci_fake_data *data = test->priv;
+
+       if (type == GMDID_MEDIA) {
+               *ver = data->media_verx100;
+               *revid = xe_step_to_gmdid(data->media_step);
+       } else {
+               *ver = data->graphics_verx100;
+               *revid = xe_step_to_gmdid(data->graphics_step);
+       }
+}
+
 int xe_pci_fake_device_init(struct xe_device *xe)
 {
        struct kunit *test = kunit_get_current_test();
@@ -140,6 +156,8 @@ int xe_pci_fake_device_init(struct xe_device *xe)
                return -ENODEV;
 
 done:
+       kunit_activate_static_stub(test, read_gmdid, fake_read_gmdid);
+
        xe_info_init_early(xe, desc, subplatform_desc);
        xe_info_init(xe, desc->graphics, desc->media);
 
index b4b3fb2df09ca5d643a1fbde89cc4c11906eedda..811ffe5bd9fd2e0bb0c1eb5739c4ddca25fbdd30 100644 (file)
@@ -6,6 +6,8 @@
 #ifndef _XE_PCI_TEST_H_
 #define _XE_PCI_TEST_H_
 
+#include <linux/types.h>
+
 #include "xe_platform_types.h"
 
 struct xe_device;
@@ -23,6 +25,10 @@ void xe_call_for_each_media_ip(xe_media_fn xe_fn);
 struct xe_pci_fake_data {
        enum xe_platform platform;
        enum xe_subplatform subplatform;
+       u32 graphics_verx100;
+       u32 media_verx100;
+       u32 graphics_step;
+       u32 media_step;
 };
 
 int xe_pci_fake_device_init(struct xe_device *xe);
index b85193d1dcc23a7b8d3447b4e1449491c1afff46..1488903573139cdd74514a91cec0ee9e17316f8f 100644 (file)
@@ -5,6 +5,7 @@
 
 #include "xe_pci.h"
 
+#include <kunit/static_stub.h>
 #include <linux/device/driver.h>
 #include <linux/module.h>
 #include <linux/pci.h>
@@ -456,6 +457,8 @@ static void read_gmdid(struct xe_device *xe, enum xe_gmdid_type type, u32 *ver,
        struct xe_reg gmdid_reg = GMD_ID;
        u32 val;
 
+       KUNIT_STATIC_STUB_REDIRECT(read_gmdid, xe, type, ver, revid);
+
        if (type == GMDID_MEDIA)
                gmdid_reg.addr += MEDIA_GT_GSI_OFFSET;
 
index a384b640f2af54de0c8cab7cb48656f671ff16dd..686cb59200c28cdc75065119d970fec3dadab5c5 100644 (file)
@@ -16,6 +16,8 @@ struct xe_step_info xe_step_pre_gmdid_get(struct xe_device *xe);
 struct xe_step_info xe_step_gmdid_get(struct xe_device *xe,
                                      u32 graphics_gmdid_revid,
                                      u32 media_gmdid_revid);
+static inline u32 xe_step_to_gmdid(enum xe_step step) { return step - STEP_A0; }
+
 const char *xe_step_name(enum xe_step step);
 
 #endif