[igt-dev] [PATCH i-g-t 5/6] lib/igt_device_scan: Add discrete/integrated pseudo-codenames

Zbigniew Kempczyński zbigniew.kempczynski at intel.com
Thu Jul 7 06:59:38 UTC 2022


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 at 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



More information about the igt-dev mailing list