[igt-dev] [PATCH i-g-t v2 1/2] lib/igt_device_scan: Remember vendor/device for pci devices
Zbigniew Kempczyński
zbigniew.kempczynski at intel.com
Tue Nov 17 12:00:41 UTC 2020
If we want to use pci device id for not opened device we need to
keep it in card structure.
To avoid compiler warnings after adding vendor/device fields
increase pci_slot_name length.
v2: display vendor/codename in lsgpu/intel_gpu_top device list (Tvrtko)
Signed-off-by: Zbigniew Kempczyński <zbigniew.kempczynski at intel.com>
Cc: Tvrtko Ursulin <tvrtko.ursulin at intel.com>
Cc: Petri Latvala <petri.latvala at intel.com>
---
lib/igt_device_scan.c | 59 ++++++++++++++++++++++++++++++++++++++++---
lib/igt_device_scan.h | 3 ++-
2 files changed, 57 insertions(+), 5 deletions(-)
diff --git a/lib/igt_device_scan.c b/lib/igt_device_scan.c
index e97f7163..4dde211c 100644
--- a/lib/igt_device_scan.c
+++ b/lib/igt_device_scan.c
@@ -25,7 +25,9 @@
#include "igt_core.h"
#include "igt_device_scan.h"
#include "igt_list.h"
+#include "intel_chipset.h"
+#include <ctype.h>
#include <dirent.h>
#include <fcntl.h>
#include <glib.h>
@@ -198,6 +200,16 @@ static const char *get_pci_vendor_id_by_name(const char *name)
return NULL;
}
+static const char *get_pci_vendor_name_by_id(const char *vendor_id)
+{
+ for (typeof(*pci_vendor_mapping) *vm = pci_vendor_mapping; vm->name; vm++) {
+ if (!strcasecmp(vendor_id, vm->vendor_id))
+ return vm->name;
+ }
+
+ return NULL;
+}
+
/* Reading sysattr values can take time (even seconds),
* we want to avoid reading such keys.
*/
@@ -463,6 +475,14 @@ __copy_dev_to_card(struct igt_device *dev, struct igt_device_card *card)
if (dev->pci_slot_name != NULL)
strncpy(card->pci_slot_name, dev->pci_slot_name,
PCI_SLOT_NAME_SIZE + 1);
+
+ if (dev->vendor != NULL && strlen(dev->vendor) == 4)
+ if (sscanf(dev->vendor, "%hx", &card->pci_vendor) != 1)
+ card->pci_vendor = 0;
+
+ if (dev->device != NULL && strlen(dev->device) == 4)
+ if (sscanf(dev->device, "%hx", &card->pci_device) != 1)
+ card->pci_device = 0;
}
/*
@@ -852,6 +872,7 @@ static void __print_filter(char *buf, int len,
};
}
+#define VENDOR_SIZE 30
static void
igt_devs_print_user(struct igt_list_head *view,
const struct igt_devices_print_format *fmt)
@@ -883,11 +904,41 @@ igt_devs_print_user(struct igt_list_head *view,
continue;
if (pci_dev) {
+ const struct intel_device_info *info;
+ uint16_t devid;
+ char device[VENDOR_SIZE], *codename, *vendor_name;
+
+ vendor_name = (char *) get_pci_vendor_name_by_id(pci_dev->vendor);
+ vendor_name = strdup(vendor_name ?: "");
+
+ if (sscanf(pci_dev->device, "%hx", &devid) != 1)
+ devid = 0;
+
__print_filter(filter, sizeof(filter), fmt, pci_dev,
false);
- printf("%-24s%4s:%4s %s\n",
- drm_name, pci_dev->vendor, pci_dev->device,
- filter);
+
+ info = intel_get_device_info(devid);
+ if (info) {
+ codename = strdup(info->codename);
+ if (strlen(info->codename))
+ codename[0] = toupper(codename[0]);
+ } else {
+ codename = strdup("");
+ }
+
+ if (strlen(vendor_name))
+ vendor_name[0] = toupper(vendor_name[0]);
+
+ snprintf(device, VENDOR_SIZE, "%s %s (Gen%d)",
+ vendor_name ?: "",
+ codename,
+ info ? ffs(info->gen) : 0);
+
+ printf("%-24s %-*s %s\n",
+ drm_name, VENDOR_SIZE, device, filter);
+
+ free(codename);
+ free(vendor_name);
} else {
__print_filter(filter, sizeof(filter), fmt, dev, false);
printf("%-24s %s\n", drm_name, filter);
@@ -919,7 +970,7 @@ igt_devs_print_user(struct igt_list_head *view,
if (fmt->option != IGT_PRINT_PCI) {
__print_filter(filter, sizeof(filter), fmt,
dev2, true);
- printf(" %s\n", filter);
+ printf("%-*s %s\n", VENDOR_SIZE, "", filter);
} else {
printf("\n");
}
diff --git a/lib/igt_device_scan.h b/lib/igt_device_scan.h
index bb4be723..e96d8a25 100644
--- a/lib/igt_device_scan.h
+++ b/lib/igt_device_scan.h
@@ -57,7 +57,8 @@ struct igt_device_card {
char subsystem[NAME_MAX];
char card[NAME_MAX];
char render[NAME_MAX];
- char pci_slot_name[PCI_SLOT_NAME_SIZE+1];
+ char pci_slot_name[PCI_SLOT_NAME_SIZE+2];
+ uint16_t pci_vendor, pci_device;
};
void igt_devices_scan(bool force);
--
2.26.0
More information about the igt-dev
mailing list