From af049be5a33e12fb993028eb378fd61545e72f5e Mon Sep 17 00:00:00 2001 From: Lucas De Marchi Date: Sat, 1 Apr 2023 01:51:46 -0700 Subject: drm/xe: Move test infra out of xe_pci.[ch] Move code out of xe_pci.[ch] into tests/*.[ch], like is done in other similar compilation units. Even if this is not part of "tests for xe_pci.c", they are functions exported and required by other tests. It's better not to clutter the module headers and sources with them. Signed-off-by: Lucas De Marchi Reviewed-by: Matt Roper Link: https://lore.kernel.org/r/20230401085151.1786204-3-lucas.demarchi@intel.com Signed-off-by: Rodrigo Vivi --- drivers/gpu/drm/xe/tests/xe_pci.c | 62 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 drivers/gpu/drm/xe/tests/xe_pci.c (limited to 'drivers/gpu/drm/xe/tests/xe_pci.c') diff --git a/drivers/gpu/drm/xe/tests/xe_pci.c b/drivers/gpu/drm/xe/tests/xe_pci.c new file mode 100644 index 000000000000..643bddb35214 --- /dev/null +++ b/drivers/gpu/drm/xe/tests/xe_pci.c @@ -0,0 +1,62 @@ +// SPDX-License-Identifier: GPL-2.0 AND MIT +/* + * Copyright © 2023 Intel Corporation + */ + +#include "tests/xe_pci_test.h" + +#include "tests/xe_test.h" + +#include + +struct kunit_test_data { + int ndevs; + xe_device_fn xe_fn; +}; + +static int dev_to_xe_device_fn(struct device *dev, void *__data) + +{ + struct drm_device *drm = dev_get_drvdata(dev); + struct kunit_test_data *data = __data; + int ret = 0; + int idx; + + data->ndevs++; + + if (drm_dev_enter(drm, &idx)) + ret = data->xe_fn(to_xe_device(dev_get_drvdata(dev))); + drm_dev_exit(idx); + + return ret; +} + +/** + * xe_call_for_each_device - Iterate over all devices this driver binds to + * @xe_fn: Function to call for each device. + * + * This function iterated over all devices this driver binds to, and calls + * @xe_fn: for each one of them. If the called function returns anything else + * than 0, iteration is stopped and the return value is returned by this + * function. Across each function call, drm_dev_enter() / drm_dev_exit() is + * called for the corresponding drm device. + * + * Return: Zero or the error code of a call to @xe_fn returning an error + * code. + */ +int xe_call_for_each_device(xe_device_fn xe_fn) +{ + int ret; + struct kunit_test_data data = { + .xe_fn = xe_fn, + .ndevs = 0, + }; + + ret = driver_for_each_device(&xe_pci_driver.driver, NULL, + &data, dev_to_xe_device_fn); + + if (!data.ndevs) + kunit_skip(current->kunit_test, "test runs only on hardware\n"); + + return ret; +} -- cgit v1.2.3 From e460410023d95b0845aa99f2d9c0625b143ca593 Mon Sep 17 00:00:00 2001 From: Lucas De Marchi Date: Sat, 1 Apr 2023 01:51:48 -0700 Subject: drm/xe: Generalize fake device creation 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 Reviewed-by: Matt Roper Link: https://lore.kernel.org/r/20230401085151.1786204-5-lucas.demarchi@intel.com Signed-off-by: Rodrigo Vivi --- drivers/gpu/drm/xe/tests/xe_pci.c | 47 ++++++++++++++++++++++++++++++++++ drivers/gpu/drm/xe/tests/xe_pci_test.h | 16 ++++++++++++ drivers/gpu/drm/xe/xe_pci.c | 2 +- 3 files changed, 64 insertions(+), 1 deletion(-) (limited to 'drivers/gpu/drm/xe/tests/xe_pci.c') diff --git a/drivers/gpu/drm/xe/tests/xe_pci.c b/drivers/gpu/drm/xe/tests/xe_pci.c index 643bddb35214..cc65ac5657b3 100644 --- a/drivers/gpu/drm/xe/tests/xe_pci.c +++ b/drivers/gpu/drm/xe/tests/xe_pci.c @@ -8,6 +8,7 @@ #include "tests/xe_test.h" #include +#include 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); diff --git a/drivers/gpu/drm/xe/tests/xe_pci_test.h b/drivers/gpu/drm/xe/tests/xe_pci_test.h index de65d8c9ccb5..43294e8c62bb 100644 --- a/drivers/gpu/drm/xe/tests/xe_pci_test.h +++ b/drivers/gpu/drm/xe/tests/xe_pci_test.h @@ -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 diff --git a/drivers/gpu/drm/xe/xe_pci.c b/drivers/gpu/drm/xe/xe_pci.c index c567436afcdc..f6050a17c950 100644 --- a/drivers/gpu/drm/xe/xe_pci.c +++ b/drivers/gpu/drm/xe/xe_pci.c @@ -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; -- cgit v1.2.3 From 3713ed52ef2bc9272afdd195fe24b011a4dcd44d Mon Sep 17 00:00:00 2001 From: Matt Roper Date: Thu, 6 Apr 2023 16:56:20 -0700 Subject: drm/xe: Add KUnit test for xe_pci.c IP engine lists 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 Reviewed-by: Lucas De Marchi Link: https://lore.kernel.org/r/20230406235621.1914492-9-matthew.d.roper@intel.com Signed-off-by: Matt Roper Signed-off-by: Rodrigo Vivi --- drivers/gpu/drm/xe/tests/Makefile | 1 + drivers/gpu/drm/xe/tests/xe_pci.c | 44 ++++++++++++++++++++ drivers/gpu/drm/xe/tests/xe_pci_test.c | 74 ++++++++++++++++++++++++++++++++++ drivers/gpu/drm/xe/tests/xe_pci_test.h | 6 +++ 4 files changed, 125 insertions(+) create mode 100644 drivers/gpu/drm/xe/tests/xe_pci_test.c (limited to 'drivers/gpu/drm/xe/tests/xe_pci.c') diff --git a/drivers/gpu/drm/xe/tests/Makefile b/drivers/gpu/drm/xe/tests/Makefile index 56919abb3f2a..51f1a7f017d4 100644 --- a/drivers/gpu/drm/xe/tests/Makefile +++ b/drivers/gpu/drm/xe/tests/Makefile @@ -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 diff --git a/drivers/gpu/drm/xe/tests/xe_pci.c b/drivers/gpu/drm/xe/tests/xe_pci.c index cc65ac5657b3..2178ad71c0da 100644 --- a/drivers/gpu/drm/xe/tests/xe_pci.c +++ b/drivers/gpu/drm/xe/tests/xe_pci.c @@ -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 index 000000000000..9c6f6c2c6c6e --- /dev/null +++ b/drivers/gpu/drm/xe/tests/xe_pci_test.c @@ -0,0 +1,74 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Copyright © 2023 Intel Corporation + */ + +#include +#include + +#include + +#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); + diff --git a/drivers/gpu/drm/xe/tests/xe_pci_test.h b/drivers/gpu/drm/xe/tests/xe_pci_test.h index 43294e8c62bb..cc0f1d141a4d 100644 --- a/drivers/gpu/drm/xe/tests/xe_pci_test.h +++ b/drivers/gpu/drm/xe/tests/xe_pci_test.h @@ -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); -- cgit v1.2.3 From 64c9ae213d2ab1cce824841518e9539f597ee91e Mon Sep 17 00:00:00 2001 From: Anusha Srivatsa Date: Tue, 13 Jun 2023 10:47:39 -0700 Subject: drm/xe/kunit: Handle fake device creation for all platform/subplatform cases For platform like Alderlake P there are subplatforms and just Alderlake P. Unlike DG2 in which every flavour is either a G10,G11 or G12 variant. In this case(Alderlake P/S), the Kunit test evaluates the subplatform to NONE and is unable to create a fake device. Removing the condition in xe_pci_fake_device_init() to support this corner case so driver can proceed with the unit testing. Cc: Lucas De Marchi Signed-off-by: Anusha Srivatsa Reviewed-by: Lucas De Marchi Link: https://lore.kernel.org/r/20230613174740.786041-1-anusha.srivatsa@intel.com Signed-off-by: Lucas De Marchi Signed-off-by: Rodrigo Vivi --- drivers/gpu/drm/xe/tests/xe_pci.c | 3 --- 1 file changed, 3 deletions(-) (limited to 'drivers/gpu/drm/xe/tests/xe_pci.c') diff --git a/drivers/gpu/drm/xe/tests/xe_pci.c b/drivers/gpu/drm/xe/tests/xe_pci.c index 2178ad71c0da..a40879da2fbe 100644 --- a/drivers/gpu/drm/xe/tests/xe_pci.c +++ b/drivers/gpu/drm/xe/tests/xe_pci.c @@ -139,9 +139,6 @@ int xe_pci_fake_device_init(struct xe_device *xe, enum xe_platform platform, if (subplatform_desc->subplatform == subplatform) break; - if (subplatform == XE_SUBPLATFORM_NONE && subplatform_desc) - return -ENODEV; - if (subplatform != XE_SUBPLATFORM_NONE && !subplatform_desc) return -ENODEV; -- cgit v1.2.3 From 5bb83841a3b9cecc49ae1f02e85909b426a6facc Mon Sep 17 00:00:00 2001 From: Michal Wajdeczko Date: Wed, 15 Nov 2023 12:58:16 +0100 Subject: drm/xe/kunit: Return number of iterated devices In xe_call_for_each_device() we are already counting number of iterated devices. Lets make that available to the caller too. We will use that functionality in upcoming patches. Reviewed-by: Lucas De Marchi Link: https://lore.kernel.org/r/20231115115816.1993-1-michal.wajdeczko@intel.com Signed-off-by: Michal Wajdeczko Signed-off-by: Rodrigo Vivi --- drivers/gpu/drm/xe/tests/xe_pci.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'drivers/gpu/drm/xe/tests/xe_pci.c') diff --git a/drivers/gpu/drm/xe/tests/xe_pci.c b/drivers/gpu/drm/xe/tests/xe_pci.c index a40879da2fbe..306ff8cb35cb 100644 --- a/drivers/gpu/drm/xe/tests/xe_pci.c +++ b/drivers/gpu/drm/xe/tests/xe_pci.c @@ -42,8 +42,8 @@ static int dev_to_xe_device_fn(struct device *dev, void *__data) * function. Across each function call, drm_dev_enter() / drm_dev_exit() is * called for the corresponding drm device. * - * Return: Zero or the error code of a call to @xe_fn returning an error - * code. + * Return: Number of devices iterated or + * the error code of a call to @xe_fn returning an error code. */ int xe_call_for_each_device(xe_device_fn xe_fn) { @@ -59,7 +59,7 @@ int xe_call_for_each_device(xe_device_fn xe_fn) if (!data.ndevs) kunit_skip(current->kunit_test, "test runs only on hardware\n"); - return ret; + return ret ?: data.ndevs; } /** -- cgit v1.2.3 From 4f5ee007f62a1825cec8140b14b28ef532f570f8 Mon Sep 17 00:00:00 2001 From: Michał Winiarski Date: Tue, 5 Dec 2023 02:32:56 +0100 Subject: drm/xe: Split xe_info_init MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Parts of xe_info_init are only dealing with processing driver_data. Extract it into xe_info_init_early to be able to use it earlier during probe. Signed-off-by: Michał Winiarski Reviewed-by: Matthew Brost Reviewed-by: Lucas De Marchi Signed-off-by: Rodrigo Vivi --- drivers/gpu/drm/xe/tests/xe_pci.c | 3 +- drivers/gpu/drm/xe/xe_pci.c | 78 +++++++++++++++++++++++---------------- 2 files changed, 48 insertions(+), 33 deletions(-) (limited to 'drivers/gpu/drm/xe/tests/xe_pci.c') diff --git a/drivers/gpu/drm/xe/tests/xe_pci.c b/drivers/gpu/drm/xe/tests/xe_pci.c index 306ff8cb35cb..d850dca85af1 100644 --- a/drivers/gpu/drm/xe/tests/xe_pci.c +++ b/drivers/gpu/drm/xe/tests/xe_pci.c @@ -143,7 +143,8 @@ int xe_pci_fake_device_init(struct xe_device *xe, enum xe_platform platform, return -ENODEV; done: - xe_info_init(xe, desc, subplatform_desc); + xe_info_init_early(xe, desc, subplatform_desc); + xe_info_init(xe, desc->graphics, desc->media); return 0; } diff --git a/drivers/gpu/drm/xe/xe_pci.c b/drivers/gpu/drm/xe/xe_pci.c index 6aaa16b15058..9e35ebfb3341 100644 --- a/drivers/gpu/drm/xe/xe_pci.c +++ b/drivers/gpu/drm/xe/xe_pci.c @@ -473,16 +473,13 @@ static void peek_gmdid(struct xe_device *xe, u32 gmdid_offset, u32 *ver, u32 *re * media is optional. */ static void handle_pre_gmdid(struct xe_device *xe, - const struct xe_device_desc *desc, - const struct xe_graphics_desc **graphics, - const struct xe_media_desc **media) + const struct xe_graphics_desc *graphics, + const struct xe_media_desc *media) { - *graphics = desc->graphics; - xe->info.graphics_verx100 = (*graphics)->ver * 100 + (*graphics)->rel; + xe->info.graphics_verx100 = graphics->ver * 100 + graphics->rel; - *media = desc->media; - if (*media) - xe->info.media_verx100 = (*media)->ver * 100 + (*media)->rel; + if (media) + xe->info.media_verx100 = media->ver * 100 + media->rel; } @@ -491,7 +488,6 @@ static void handle_pre_gmdid(struct xe_device *xe, * based on the result. */ static void handle_gmdid(struct xe_device *xe, - const struct xe_device_desc *desc, const struct xe_graphics_desc **graphics, const struct xe_media_desc **media, u32 *graphics_revid, @@ -535,32 +531,59 @@ static void handle_gmdid(struct xe_device *xe, } } +/* + * Initialize device info content that only depends on static driver_data + * passed to the driver at probe time from PCI ID table. + */ +static void xe_info_init_early(struct xe_device *xe, + const struct xe_device_desc *desc, + const struct xe_subplatform_desc *subplatform_desc) +{ + xe->info.platform = desc->platform; + xe->info.subplatform = subplatform_desc ? + subplatform_desc->subplatform : XE_SUBPLATFORM_NONE; + + xe->info.is_dgfx = desc->is_dgfx; + xe->info.has_heci_gscfi = desc->has_heci_gscfi; + xe->info.has_llc = desc->has_llc; + xe->info.has_sriov = desc->has_sriov; + xe->info.skip_mtcfg = desc->skip_mtcfg; + xe->info.skip_pcode = desc->skip_pcode; + xe->info.supports_mmio_ext = desc->supports_mmio_ext; + xe->info.skip_guc_pc = desc->skip_guc_pc; + + xe->info.enable_display = IS_ENABLED(CONFIG_DRM_XE_DISPLAY) && + xe_modparam.enable_display && + desc->has_display; +} + +/* + * Initialize device info content that does require knowledge about + * graphics / media IP version. + * Make sure that GT / tile structures allocated by the driver match the data + * present in device info. + */ static int xe_info_init(struct xe_device *xe, - const struct xe_device_desc *desc, - const struct xe_subplatform_desc *subplatform_desc) + const struct xe_graphics_desc *graphics_desc, + const struct xe_media_desc *media_desc) { - const struct xe_graphics_desc *graphics_desc = NULL; - const struct xe_media_desc *media_desc = NULL; u32 graphics_gmdid_revid = 0, media_gmdid_revid = 0; struct xe_tile *tile; struct xe_gt *gt; u8 id; - xe->info.platform = desc->platform; - xe->info.subplatform = subplatform_desc ? - subplatform_desc->subplatform : XE_SUBPLATFORM_NONE; - /* * If this platform supports GMD_ID, we'll detect the proper IP * descriptor to use from hardware registers. desc->graphics will only * ever be set at this point for platforms before GMD_ID. In that case * the IP descriptions and versions are simply derived from that. */ - if (desc->graphics) { - handle_pre_gmdid(xe, desc, &graphics_desc, &media_desc); + if (graphics_desc) { + handle_pre_gmdid(xe, graphics_desc, media_desc); xe->info.step = xe_step_pre_gmdid_get(xe); } else { - handle_gmdid(xe, desc, &graphics_desc, &media_desc, + xe_assert(xe, !media_desc); + handle_gmdid(xe, &graphics_desc, &media_desc, &graphics_gmdid_revid, &media_gmdid_revid); xe->info.step = xe_step_gmdid_get(xe, graphics_gmdid_revid, @@ -575,15 +598,8 @@ static int xe_info_init(struct xe_device *xe, if (!graphics_desc) return -ENODEV; - xe->info.is_dgfx = desc->is_dgfx; - xe->info.has_heci_gscfi = desc->has_heci_gscfi; xe->info.graphics_name = graphics_desc->name; xe->info.media_name = media_desc ? media_desc->name : "none"; - xe->info.has_llc = desc->has_llc; - xe->info.has_sriov = desc->has_sriov; - xe->info.skip_mtcfg = desc->skip_mtcfg; - xe->info.skip_pcode = desc->skip_pcode; - xe->info.supports_mmio_ext = desc->supports_mmio_ext; xe->info.tile_mmio_ext_size = graphics_desc->tile_mmio_ext_size; xe->info.dma_mask_size = graphics_desc->dma_mask_size; @@ -594,11 +610,7 @@ static int xe_info_init(struct xe_device *xe, xe->info.has_asid = graphics_desc->has_asid; xe->info.has_flat_ccs = graphics_desc->has_flat_ccs; xe->info.has_range_tlb_invalidation = graphics_desc->has_range_tlb_invalidation; - xe->info.skip_guc_pc = desc->skip_guc_pc; - xe->info.enable_display = IS_ENABLED(CONFIG_DRM_XE_DISPLAY) && - xe_modparam.enable_display && - desc->has_display; /* * All platforms have at least one primary GT. Any platform with media * version 13 or higher has an additional dedicated media GT. And @@ -711,9 +723,11 @@ static int xe_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent) pci_set_master(pdev); + xe_info_init_early(xe, desc, subplatform_desc); + xe_sriov_probe_early(xe, desc->has_sriov); - err = xe_info_init(xe, desc, subplatform_desc); + err = xe_info_init(xe, desc->graphics, desc->media); if (err) return err; -- cgit v1.2.3 From 1da0e581983c6f212499d44573b23ae48c1a4d00 Mon Sep 17 00:00:00 2001 From: Lucas De Marchi Date: Tue, 5 Dec 2023 05:39:51 -0800 Subject: drm/xe/kunit: Remove handling of XE_TEST_SUBPLATFORM_ANY The only user passing XE_TEST_SUBPLATFORM_ANY is xe_pci_fake_device_init_any(), but then the function would return earlier when handling XE_TEST_PLATFORM_ANY. Platforms without a subplatform use XE_SUBPLATFORM_NONE. Reviewed-by: Matt Roper Link: https://lore.kernel.org/r/20231129232807.1499826-3-lucas.demarchi@intel.com Link: https://lore.kernel.org/r/20231129232807.1499826-6-lucas.demarchi@intel.com Link: https://lore.kernel.org/r/20231205133954.2089546-1-lucas.demarchi@intel.com Signed-off-by: Lucas De Marchi Signed-off-by: Rodrigo Vivi --- drivers/gpu/drm/xe/tests/xe_pci.c | 5 ----- 1 file changed, 5 deletions(-) (limited to 'drivers/gpu/drm/xe/tests/xe_pci.c') diff --git a/drivers/gpu/drm/xe/tests/xe_pci.c b/drivers/gpu/drm/xe/tests/xe_pci.c index d850dca85af1..c1aa785cac18 100644 --- a/drivers/gpu/drm/xe/tests/xe_pci.c +++ b/drivers/gpu/drm/xe/tests/xe_pci.c @@ -128,11 +128,6 @@ int xe_pci_fake_device_init(struct xe_device *xe, enum xe_platform platform, 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++) -- cgit v1.2.3 From 5b2a63b40d5620ce453f2a509334ae6feb7b884e Mon Sep 17 00:00:00 2001 From: Lucas De Marchi Date: Tue, 5 Dec 2023 05:39:52 -0800 Subject: drm/xe/kunit: Move fake pci data to test-priv Instead of passing as parameter to xe_pci_fake_device_init(), use test->priv to pass parameters down the call stack. The main advantage is that then the data is readily available on other functions by using kunit_get_current_test(). This is a preparation to fix the initialization of fake devices when they were supposed to be using GMD_ID. Reviewed-by: Matt Roper Link: https://lore.kernel.org/r/20231129232807.1499826-4-lucas.demarchi@intel.com Link: https://lore.kernel.org/r/20231205133954.2089546-2-lucas.demarchi@intel.com Signed-off-by: Lucas De Marchi Signed-off-by: Rodrigo Vivi --- drivers/gpu/drm/xe/tests/xe_pci.c | 14 ++++++++------ drivers/gpu/drm/xe/tests/xe_pci_test.h | 17 +++++------------ drivers/gpu/drm/xe/tests/xe_rtp_test.c | 4 +++- drivers/gpu/drm/xe/tests/xe_wa_test.c | 7 ++++++- 4 files changed, 22 insertions(+), 20 deletions(-) (limited to 'drivers/gpu/drm/xe/tests/xe_pci.c') diff --git a/drivers/gpu/drm/xe/tests/xe_pci.c b/drivers/gpu/drm/xe/tests/xe_pci.c index c1aa785cac18..b93cb1e96108 100644 --- a/drivers/gpu/drm/xe/tests/xe_pci.c +++ b/drivers/gpu/drm/xe/tests/xe_pci.c @@ -7,6 +7,7 @@ #include "tests/xe_test.h" +#include #include #include @@ -106,14 +107,15 @@ void xe_call_for_each_media_ip(xe_media_fn xe_fn) } 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) +int xe_pci_fake_device_init(struct xe_device *xe) { + struct kunit *test = kunit_get_current_test(); + struct xe_pci_fake_data *data = test->priv; 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) { + if (!data) { desc = (const void *)ent->driver_data; subplatform_desc = NULL; goto done; @@ -121,7 +123,7 @@ int xe_pci_fake_device_init(struct xe_device *xe, enum xe_platform platform, for (ent = pciidlist; ent->device; ent++) { desc = (const void *)ent->driver_data; - if (desc->platform == platform) + if (desc->platform == data->platform) break; } @@ -131,10 +133,10 @@ int xe_pci_fake_device_init(struct xe_device *xe, enum xe_platform platform, for (subplatform_desc = desc->subplatforms; subplatform_desc && subplatform_desc->subplatform; subplatform_desc++) - if (subplatform_desc->subplatform == subplatform) + if (subplatform_desc->subplatform == data->subplatform) break; - if (subplatform != XE_SUBPLATFORM_NONE && !subplatform_desc) + if (data->subplatform != XE_SUBPLATFORM_NONE && !subplatform_desc) return -ENODEV; done: diff --git a/drivers/gpu/drm/xe/tests/xe_pci_test.h b/drivers/gpu/drm/xe/tests/xe_pci_test.h index cc0f1d141a4d..b4b3fb2df09c 100644 --- a/drivers/gpu/drm/xe/tests/xe_pci_test.h +++ b/drivers/gpu/drm/xe/tests/xe_pci_test.h @@ -12,13 +12,6 @@ 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 - * 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 *); typedef void (*xe_graphics_fn)(const struct xe_graphics_desc *); typedef void (*xe_media_fn)(const struct xe_media_desc *); @@ -27,11 +20,11 @@ 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); +struct xe_pci_fake_data { + 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) +int xe_pci_fake_device_init(struct xe_device *xe); #endif diff --git a/drivers/gpu/drm/xe/tests/xe_rtp_test.c b/drivers/gpu/drm/xe/tests/xe_rtp_test.c index a1d204133cc1..4a6972897675 100644 --- a/drivers/gpu/drm/xe/tests/xe_rtp_test.c +++ b/drivers/gpu/drm/xe/tests/xe_rtp_test.c @@ -281,7 +281,9 @@ static int xe_rtp_test_init(struct kunit *test) drm, DRIVER_GEM); KUNIT_ASSERT_NOT_ERR_OR_NULL(test, xe); - ret = xe_pci_fake_device_init_any(xe); + /* Initialize an empty device */ + test->priv = NULL; + ret = xe_pci_fake_device_init(xe); KUNIT_ASSERT_EQ(test, ret, 0); xe->drm.dev = dev; diff --git a/drivers/gpu/drm/xe/tests/xe_wa_test.c b/drivers/gpu/drm/xe/tests/xe_wa_test.c index 01ea974591ea..045afae43891 100644 --- a/drivers/gpu/drm/xe/tests/xe_wa_test.c +++ b/drivers/gpu/drm/xe/tests/xe_wa_test.c @@ -75,6 +75,10 @@ KUNIT_ARRAY_PARAM(platform, cases, platform_desc); static int xe_wa_test_init(struct kunit *test) { const struct platform_test_case *param = test->param_value; + struct xe_pci_fake_data data = { + .platform = param->platform, + .subplatform = param->subplatform, + }; struct xe_device *xe; struct device *dev; int ret; @@ -87,7 +91,8 @@ static int xe_wa_test_init(struct kunit *test) drm, DRIVER_GEM); KUNIT_ASSERT_NOT_ERR_OR_NULL(test, xe); - ret = xe_pci_fake_device_init(xe, param->platform, param->subplatform); + test->priv = &data; + ret = xe_pci_fake_device_init(xe); KUNIT_ASSERT_EQ(test, ret, 0); xe->info.step = param->step; -- cgit v1.2.3 From 6cad22853cb89da857ff636607dd0e9880172a43 Mon Sep 17 00:00:00 2001 From: Lucas De Marchi Date: Tue, 5 Dec 2023 05:39:53 -0800 Subject: drm/xe/kunit: Add stub to read_gmdid 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 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 Signed-off-by: Rodrigo Vivi --- drivers/gpu/drm/xe/tests/xe_pci.c | 18 ++++++++++++++++++ drivers/gpu/drm/xe/tests/xe_pci_test.h | 6 ++++++ drivers/gpu/drm/xe/xe_pci.c | 3 +++ drivers/gpu/drm/xe/xe_step.h | 2 ++ 4 files changed, 29 insertions(+) (limited to 'drivers/gpu/drm/xe/tests/xe_pci.c') diff --git a/drivers/gpu/drm/xe/tests/xe_pci.c b/drivers/gpu/drm/xe/tests/xe_pci.c index b93cb1e96108..602793644f61 100644 --- a/drivers/gpu/drm/xe/tests/xe_pci.c +++ b/drivers/gpu/drm/xe/tests/xe_pci.c @@ -9,6 +9,7 @@ #include #include +#include #include 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); diff --git a/drivers/gpu/drm/xe/tests/xe_pci_test.h b/drivers/gpu/drm/xe/tests/xe_pci_test.h index b4b3fb2df09c..811ffe5bd9fd 100644 --- a/drivers/gpu/drm/xe/tests/xe_pci_test.h +++ b/drivers/gpu/drm/xe/tests/xe_pci_test.h @@ -6,6 +6,8 @@ #ifndef _XE_PCI_TEST_H_ #define _XE_PCI_TEST_H_ +#include + #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); diff --git a/drivers/gpu/drm/xe/xe_pci.c b/drivers/gpu/drm/xe/xe_pci.c index b85193d1dcc2..148890357313 100644 --- a/drivers/gpu/drm/xe/xe_pci.c +++ b/drivers/gpu/drm/xe/xe_pci.c @@ -5,6 +5,7 @@ #include "xe_pci.h" +#include #include #include #include @@ -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; diff --git a/drivers/gpu/drm/xe/xe_step.h b/drivers/gpu/drm/xe/xe_step.h index a384b640f2af..686cb59200c2 100644 --- a/drivers/gpu/drm/xe/xe_step.h +++ b/drivers/gpu/drm/xe/xe_step.h @@ -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 -- cgit v1.2.3