aboutsummaryrefslogtreecommitdiff
path: root/hardinfo/pci_util.c
diff options
context:
space:
mode:
authorBurt P <pburt0@gmail.com>2019-12-31 23:15:28 -0600
committerLeandro A. F. Pereira <leandro@hardinfo.org>2020-01-03 09:33:24 -0800
commit2d2290b346927851044ffcf5bbb63a0a0040d5a5 (patch)
tree5412c87e21c2de78ce643e6b0b800034c92b8c7d /hardinfo/pci_util.c
parent1afd683fea89d759ea05a65194e05e4eed38847c (diff)
pci_util: read class strings from pci.ids, use class for unknown product
Signed-off-by: Burt P <pburt0@gmail.com>
Diffstat (limited to 'hardinfo/pci_util.c')
-rw-r--r--hardinfo/pci_util.c32
1 files changed, 32 insertions, 0 deletions
diff --git a/hardinfo/pci_util.c b/hardinfo/pci_util.c
index 11c9b32f..7077ed12 100644
--- a/hardinfo/pci_util.c
+++ b/hardinfo/pci_util.c
@@ -23,6 +23,15 @@
#include "util_ids.h"
gchar *pci_ids_file = NULL;
+const gboolean nolspci = FALSE; /* true for testing */
+
+/* Two pieces of info still only from lspci:
+ * - kernel driver in use
+ * - kernel modules list
+ *
+ * TODO: could use readlink() and basename() to get kernel driver from sysfs
+ * - /sys/bus/pci/devices/<addy>/driver is a symlink
+ */
static void find_pci_ids_file() {
if (pci_ids_file) return;
@@ -101,6 +110,26 @@ static gboolean pci_lookup_ids(pcid *d) {
ret = TRUE;
};
g_free(qpath);
+
+ /* lookup class */
+ qpath = g_strdup_printf("C %02x/%02x", (d->class >> 8) & 0xff, (d->class & 0xff));
+ scan_ids_file(pci_ids_file, qpath, &result, -1);
+ if (result.results[0]) {
+ if (d->class_str) g_free(d->class_str);
+ d->class_str = g_strdup(result.results[0]);
+ if (result.results[1]
+ && !SEQ(result.results[0], result.results[1]) ) {
+ /* options 1: results[0] + " :: " + results[1] */
+ //d->class_str = appf(d->class_str, " :: ", "%s", result.results[1]);
+
+ /* option 2: results[1] or results[0] */
+ g_free(d->class_str);
+ d->class_str = g_strdup(result.results[1]);
+ }
+ ret = TRUE;
+ }
+ g_free(qpath);
+
return ret;
}
@@ -177,6 +206,7 @@ static int lspci_line_string_and_code(char *line, char *prefix, char **str, uint
}
static gboolean pci_fill_details(pcid *s) {
+ if (nolspci) return FALSE;
gboolean spawned;
gchar *out, *err, *p, *l, *next_nl;
gchar *pci_loc = pci_address_str(s->domain, s->bus, s->device, s->function);
@@ -284,6 +314,7 @@ static gboolean pci_get_device_sysfs(uint32_t dom, uint32_t bus, uint32_t dev, u
}
static gboolean pci_get_device_lspci(uint32_t dom, uint32_t bus, uint32_t dev, uint32_t func, pcid *s) {
+ if (nolspci) return FALSE;
gboolean spawned;
gchar *out, *err, *p, *l, *next_nl;
gchar *pci_loc = pci_address_str(dom, bus, dev, func);
@@ -359,6 +390,7 @@ pcid *pci_get_device(uint32_t dom, uint32_t bus, uint32_t dev, uint32_t func) {
}
static pcid *pci_get_device_list_lspci(uint32_t class_min, uint32_t class_max) {
+ if (nolspci) return NULL;
gboolean spawned;
gchar *out, *err, *p, *next_nl;
pcid *head = NULL, *nd;