From: Lucas De Marchi <lucas.demarchi@intel.com>
To: intel-xe@lists.freedesktop.org
Cc: Lucas De Marchi <lucas.demarchi@intel.com>, maarten.lankhorst@intel.com
Subject: [Intel-xe] [PATCH 5/7] drm/xe: Generalize fake device creation
Date: Tue, 21 Mar 2023 15:05:25 -0700 [thread overview]
Message-ID: <20230321220527.595462-6-lucas.demarchi@intel.com> (raw)
In-Reply-To: <20230321220527.595462-1-lucas.demarchi@intel.com>
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. This
migrates the xe_rtp tests to use this new helper.
Signed-off-by: Lucas De Marchi <lucas.demarchi@intel.com>
---
drivers/gpu/drm/xe/tests/xe_pci.c | 46 ++++++++++++++++++++++++++
drivers/gpu/drm/xe/tests/xe_pci_test.h | 16 +++++++++
drivers/gpu/drm/xe/tests/xe_rtp_test.c | 11 +++---
drivers/gpu/drm/xe/xe_pci.c | 2 +-
4 files changed, 68 insertions(+), 7 deletions(-)
diff --git a/drivers/gpu/drm/xe/tests/xe_pci.c b/drivers/gpu/drm/xe/tests/xe_pci.c
index 643bddb35214..81723b8c3aef 100644
--- a/drivers/gpu/drm/xe/tests/xe_pci.c
+++ b/drivers/gpu/drm/xe/tests/xe_pci.c
@@ -60,3 +60,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_NS_GPL(xe_pci_fake_device_init, XE_KUNIT);
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/tests/xe_rtp_test.c b/drivers/gpu/drm/xe/tests/xe_rtp_test.c
index bb633dd09a76..37d3cd1a43fc 100644
--- a/drivers/gpu/drm/xe/tests/xe_rtp_test.c
+++ b/drivers/gpu/drm/xe/tests/xe_rtp_test.c
@@ -11,16 +11,13 @@
#include <kunit/test.h>
#include "xe_device_types.h"
-
-static void xe_fake_device_init(struct xe_device *xe)
-{
- xe->gt[0].xe = xe;
-}
+#include "xe_pci_test.h"
static int xe_rtp_test_init(struct kunit *test)
{
struct xe_device *xe;
struct device *dev;
+ int ret;
dev = drm_kunit_helper_alloc_device(test);
KUNIT_ASSERT_NOT_ERR_OR_NULL(test, dev);
@@ -30,7 +27,9 @@ static int xe_rtp_test_init(struct kunit *test)
drm, DRIVER_GEM);
KUNIT_ASSERT_NOT_ERR_OR_NULL(test, xe);
- xe_fake_device_init(xe);
+ ret = xe_pci_fake_device_init_any(xe);
+ KUNIT_ASSERT_EQ(test, ret, 0);
+
xe->drm.dev = dev;
test->priv = xe;
diff --git a/drivers/gpu/drm/xe/xe_pci.c b/drivers/gpu/drm/xe/xe_pci.c
index 302f7f588da1..21ae5e6f8fe5 100644
--- a/drivers/gpu/drm/xe/xe_pci.c
+++ b/drivers/gpu/drm/xe/xe_pci.c
@@ -429,7 +429,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;
--
2.39.0
next prev parent reply other threads:[~2023-03-21 22:06 UTC|newest]
Thread overview: 30+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-03-21 22:05 [Intel-xe] [PATCH 0/7] Unit tests for rtp and GT wa/tuning Lucas De Marchi
2023-03-21 22:05 ` [Intel-xe] [PATCH 1/7] drm/xe: Add basic unit tests for rtp Lucas De Marchi
2023-03-27 17:56 ` Michał Winiarski
2023-03-31 13:43 ` Lucas De Marchi
2023-04-01 8:59 ` Lucas De Marchi
2023-04-01 18:54 ` Michał Winiarski
2023-04-02 1:24 ` Lucas De Marchi
2023-04-02 10:51 ` Michal Wajdeczko
2023-03-31 14:34 ` Lucas De Marchi
2023-04-01 8:54 ` Lucas De Marchi
2023-04-01 18:26 ` Michał Winiarski
2023-04-02 1:34 ` Lucas De Marchi
2023-04-02 11:17 ` Michal Wajdeczko
2023-04-02 21:54 ` Lucas De Marchi
2023-04-03 7:38 ` Michal Wajdeczko
2023-04-03 13:02 ` Lucas De Marchi
2023-03-21 22:05 ` [Intel-xe] [PATCH 2/7] drm/xe: Extract function to initialize xe->info Lucas De Marchi
2023-03-21 22:05 ` [Intel-xe] [PATCH 3/7] drm/xe: Move test infra out of xe_pci.[ch] Lucas De Marchi
2023-03-21 22:05 ` [Intel-xe] [PATCH 4/7] drm/xe: Use XE_KUNIT for symbol namespace Lucas De Marchi
2023-03-21 22:05 ` Lucas De Marchi [this message]
2023-03-21 22:05 ` [Intel-xe] [PATCH 6/7] drm/xe/reg_sr: Save errors for kunit integration Lucas De Marchi
2023-03-27 18:29 ` Michał Winiarski
2023-03-31 14:43 ` Lucas De Marchi
2023-03-21 22:05 ` [Intel-xe] [PATCH 7/7] drm/xe: Add test for GT workarounds and tunings Lucas De Marchi
2023-03-21 22:08 ` [Intel-xe] ✓ CI.Patch_applied: success for Unit tests for rtp and GT wa/tuning Patchwork
2023-03-31 15:14 ` Lucas De Marchi
2023-04-03 6:08 ` Mauro Carvalho Chehab
2023-03-21 22:09 ` [Intel-xe] ✓ CI.KUnit: " Patchwork
2023-03-21 22:13 ` [Intel-xe] ✓ CI.Build: " Patchwork
2023-03-21 22:25 ` [Intel-xe] ○ CI.BAT: info " Patchwork
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230321220527.595462-6-lucas.demarchi@intel.com \
--to=lucas.demarchi@intel.com \
--cc=intel-xe@lists.freedesktop.org \
--cc=maarten.lankhorst@intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox