All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Zbigniew Kempczyński" <zbigniew.kempczynski@intel.com>
To: igt-dev@lists.freedesktop.org
Subject: [igt-dev] [PATCH i-g-t 5/6] lib/igt_device_scan: Add discrete/integrated pseudo-codenames
Date: Thu,  7 Jul 2022 08:59:38 +0200	[thread overview]
Message-ID: <20220707065939.33453-6-zbigniew.kempczynski@intel.com> (raw)
In-Reply-To: <20220707065939.33453-1-zbigniew.kempczynski@intel.com>

For simply selection where test should just run on dedicated card type
pci + sriov selectors can now use:

pci:vendor=8086,device=integrated

or

pci:vendor=8086,device=discrete

or (when there're more discrete cards)

pci:vendor=8086,device=discrete,card=n

Signed-off-by: Zbigniew Kempczyński <zbigniew.kempczynski@intel.com>
---
 lib/igt_device_scan.c | 75 +++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 72 insertions(+), 3 deletions(-)

diff --git a/lib/igt_device_scan.c b/lib/igt_device_scan.c
index e41c9f8b64..0140460261 100644
--- a/lib/igt_device_scan.c
+++ b/lib/igt_device_scan.c
@@ -118,12 +118,19 @@
  *
  *   It selects the second one.
  *
- *   We may use device codename instead pci device id:
+ *   We may use device codename or pseudo-codename (integrated/discrete)
+ *   instead pci device id:
  *
  *   |[<!-- language="plain" -->
  *   pci:vendor=8086,device=skylake
  *   ]|
  *
+ *   or
+ *
+ *   |[<!-- language="plain" -->
+ *   pci:vendor=8086,device=integrated
+ *   ]|
+ *
  *   Another possibility is to select device using a PCI slot:
  *
  *   |[<!-- language="plain" -->
@@ -179,6 +186,15 @@
 #define DBG(...) {}
 #endif
 
+enum dev_type {
+	DEVTYPE_ALL,
+	DEVTYPE_INTEGRATED,
+	DEVTYPE_DISCRETE,
+};
+
+#define STR_INTEGRATED "integrated"
+#define STR_DISCRETE "discrete"
+
 static inline bool strequal(const char *a, const char *b)
 {
 	if (a == NULL || b == NULL)
@@ -214,6 +230,7 @@ struct igt_device {
 
 	/* For grouping by codename */
 	char *codename;
+	enum dev_type dev_type;
 
 	struct igt_list_head link;
 };
@@ -226,6 +243,7 @@ static struct {
 } igt_devs;
 
 typedef char *(*devname_fn)(uint16_t, uint16_t);
+typedef enum dev_type (*devtype_fn)(uint16_t, uint16_t, const char *);
 
 static char *devname_hex(uint16_t vendor, uint16_t device)
 {
@@ -274,14 +292,35 @@ static char *codename_intel(uint16_t vendor, uint16_t device)
 	return codename;
 }
 
+static enum dev_type devtype_intel(uint16_t vendor, uint16_t device, const char *pci_slot)
+{
+	(void) vendor;
+	(void) device;
+
+	if (!strncmp(pci_slot, INTEGRATED_I915_GPU_PCI_ID, PCI_SLOT_NAME_SIZE))
+		return DEVTYPE_INTEGRATED;
+
+	return DEVTYPE_DISCRETE;
+}
+
+static enum dev_type devtype_all(uint16_t vendor, uint16_t device, const char *pci_slot)
+{
+	(void) vendor;
+	(void) device;
+	(void) pci_slot;
+
+	return DEVTYPE_ALL;
+}
+
 static struct {
 	const char *name;
 	const char *vendor_id;
 	devname_fn devname;
 	devname_fn codename;
+	devtype_fn devtype;
 } pci_vendor_mapping[] = {
-	{ "intel", "8086", devname_intel, codename_intel },
-	{ "amd", "1002", devname_hex, devname_hex },
+	{ "intel", "8086", devname_intel, codename_intel, devtype_intel },
+	{ "amd", "1002", devname_hex, devname_hex, devtype_all },
 	{ NULL, },
 };
 
@@ -324,6 +363,20 @@ static devname_fn get_pci_vendor_device_codename_fn(uint16_t vendor)
 	return devname_hex;
 }
 
+static devtype_fn get_pci_vendor_device_devtype_fn(uint16_t vendor)
+{
+	char vendorstr[5];
+
+	snprintf(vendorstr, sizeof(vendorstr), "%04x", vendor);
+
+	for (typeof(*pci_vendor_mapping) *vm = pci_vendor_mapping; vm->name; vm++) {
+		if (!strcasecmp(vendorstr, vm->vendor_id))
+			return vm->devtype;
+	}
+
+	return devtype_all;
+}
+
 static void get_pci_vendor_device(const struct igt_device *dev,
 				  uint16_t *vendorp, uint16_t *devicep)
 {
@@ -358,6 +411,15 @@ static char *__pci_codename(uint16_t vendor, uint16_t device, bool numeric)
 	return fn(vendor, device);
 }
 
+static enum dev_type __pci_devtype(uint16_t vendor, uint16_t device, const char *pci_slot)
+{
+	devtype_fn fn;
+
+	fn = get_pci_vendor_device_devtype_fn(vendor);
+
+	return fn(vendor, device, pci_slot);
+}
+
 /* Reading sysattr values can take time (even seconds),
  * we want to avoid reading such keys.
  */
@@ -573,6 +635,7 @@ static struct igt_device *igt_device_new_from_udev(struct udev_device *dev)
 		set_pci_slot_name(idev);
 		get_pci_vendor_device(idev, &vendor, &device);
 		idev->codename = __pci_codename(vendor, device, false);
+		idev->dev_type = __pci_devtype(vendor, device, idev->pci_slot_name);
 	}
 
 	return idev;
@@ -624,6 +687,12 @@ static bool is_device_matched(struct igt_device *dev, const char *device)
 	if (!strcasecmp(dev->device, device))
 		return true;
 
+	/* Try "integrated" and "discrete" */
+	if (dev->dev_type == DEVTYPE_INTEGRATED && !strcasecmp(device, STR_INTEGRATED))
+		return true;
+	else if (dev->dev_type == DEVTYPE_DISCRETE && !strcasecmp(device, STR_DISCRETE))
+		return true;
+
 	/* Try codename */
 	return !strcasecmp(dev->codename, device);
 }
-- 
2.34.1

  parent reply	other threads:[~2022-07-07  7:00 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-07-07  6:59 [igt-dev] [PATCH i-g-t 0/6] Add codename in device selection Zbigniew Kempczyński
2022-07-07  6:59 ` [igt-dev] [PATCH i-g-t 1/6] lib/igt_device_scan: Migrate pci assignment Zbigniew Kempczyński
2022-07-07  6:59 ` [igt-dev] [PATCH i-g-t 2/6] lib/igt_device_scan: Introduce codename for platform selection Zbigniew Kempczyński
2022-07-11 14:26   ` Kamil Konieczny
2022-07-12  8:02     ` Zbigniew Kempczyński
2022-07-12  9:08     ` Zbigniew Kempczyński
2022-07-07  6:59 ` [igt-dev] [PATCH i-g-t 3/6] tools/lsgpu: Add codename switch (-c) Zbigniew Kempczyński
2022-07-11  8:52   ` Kamil Konieczny
2022-07-07  6:59 ` [igt-dev] [PATCH i-g-t 4/6] lib/igt_device_scan: Align microseconds to six leading zeros Zbigniew Kempczyński
2022-07-11 11:33   ` Kamil Konieczny
2022-07-12  8:12     ` Zbigniew Kempczyński
2022-07-07  6:59 ` Zbigniew Kempczyński [this message]
2022-07-07  6:59 ` [igt-dev] [PATCH i-g-t 6/6] lib/igt_device_scan: Simulate udev drm and pci device events Zbigniew Kempczyński
2022-07-07  7:37 ` [igt-dev] ✓ Fi.CI.BAT: success for Add codename in device selection Patchwork
2022-07-07 15:32 ` [igt-dev] ✓ Fi.CI.IGT: " 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=20220707065939.33453-6-zbigniew.kempczynski@intel.com \
    --to=zbigniew.kempczynski@intel.com \
    --cc=igt-dev@lists.freedesktop.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.