diff options
| -rw-r--r-- | hardinfo/pci_util.c | 74 | ||||
| -rw-r--r-- | includes/pci_util.h | 2 | 
2 files changed, 76 insertions, 0 deletions
| diff --git a/hardinfo/pci_util.c b/hardinfo/pci_util.c index 2aa2ece3..e7ae81ac 100644 --- a/hardinfo/pci_util.c +++ b/hardinfo/pci_util.c @@ -20,6 +20,80 @@  #include "hardinfo.h"  #include "pci_util.h" +#include "util_ids.h" + +gchar *pci_ids_file = NULL; + +void find_pci_ids_file() { +    if (pci_ids_file) return; +    char *file_search_order[] = { +        g_strdup("/usr/share/hwdata/pci.ids"), +        g_build_filename(g_get_user_config_dir(), "hardinfo", "pci.ids", NULL), +        g_build_filename(params.path_data, "pci.ids", NULL), +        NULL +    }; +    int n; +    for(n = 0; file_search_order[n]; n++) { +        if (!pci_ids_file && !access(file_search_order[n], R_OK)) +            pci_ids_file = file_search_order[n]; +        else +            g_free(file_search_order[n]); +    } +} + +char *pci_lookup_ids_vendor_str(uint32_t id) { +    gchar *ret = NULL; + +    ids_query_result result = {}; +    gchar *qpath; + +    if (!pci_ids_file) +        find_pci_ids_file(); + +    qpath = g_strdup_printf("%04x", id); +    scan_ids_file(pci_ids_file, qpath, &result, -1); +    if (result.results[0]) { +        ret = g_strdup(result.results[0]); +    } +    g_free(qpath); + +    return ret; +} + +static void pci_lookup_ids(pcid *d) { +    ids_query_result result = {}; +    gchar *qpath; + +    if (!pci_ids_file) +        find_pci_ids_file(); + +    /* lookup vendor, device, sub device */ +    qpath = g_strdup_printf("%04x/%04x/%04x %04x", +        d->vendor_id, d->device_id, d->sub_vendor_id, d->sub_device_id); +    scan_ids_file(pci_ids_file, qpath, &result, -1); +    if (result.results[0]) { +        if (d->vendor_id_str) g_free(d->vendor_id_str); +        d->vendor_id_str = g_strdup(result.results[0]); +    } +    if (result.results[1]) { +        if (d->device_id_str) g_free(d->device_id_str); +        d->device_id_str = g_strdup(result.results[1]); +    } +    if (result.results[2]) { +        if (d->sub_device_id_str) g_free(d->sub_device_id_str); +        d->sub_device_id_str = g_strdup(result.results[2]); +    } +    g_free(qpath); + +    /* lookup sub vendor by itself */ +    qpath = g_strdup_printf("%04x", d->sub_vendor_id); +    scan_ids_file(pci_ids_file, qpath, &result, -1); +    if (result.results[0]) { +        if (d->sub_vendor_id_str) g_free(d->sub_vendor_id_str); +        d->sub_vendor_id_str = g_strdup(result.results[0]); +    } +    g_free(qpath); +}  pcid *pcid_new() {      return g_new0(pcid, 1); diff --git a/includes/pci_util.h b/includes/pci_util.h index 827f6197..732f63bc 100644 --- a/includes/pci_util.h +++ b/includes/pci_util.h @@ -69,4 +69,6 @@ void pcid_list_free(pcid *);  pcid *pci_get_device(uint32_t dom, uint32_t bus, uint32_t dev, uint32_t func);  void pcid_free(pcid *); +char *pci_lookup_ids_vendor_str(uint32_t id); +  #endif | 
