2 * The PCI Library -- Looking up Names via UDEV and HWDB
4 * Copyright (c) 2013--2014 Tom Gundersen <teg@jklm.no>
5 * Copyright (c) 2014 Martin Mares <mj@ucw.cz>
7 * Can be freely distributed and used under the terms of the GNU GPL v2+.
9 * SPDX-License-Identifier: GPL-2.0-or-later
24 pci_id_hwdb_lookup(struct pci_access *a, int cat, int id1, int id2, int id3, int id4)
27 const char *key = NULL;
29 const char *disabled = pci_get_param(a, "hwdb.disable");
30 if (disabled && atoi(disabled))
36 sprintf(modalias, "pci:v%08X*", id1);
37 key = "ID_VENDOR_FROM_DATABASE";
40 sprintf(modalias, "pci:v%08Xd%08X*", id1, id2);
41 key = "ID_MODEL_FROM_DATABASE";
44 sprintf(modalias, "pci:v%08Xd%08Xsv%08Xsd%08X*", id1, id2, id3, id4);
45 key = "ID_MODEL_FROM_DATABASE";
47 case ID_GEN_SUBSYSTEM:
48 sprintf(modalias, "pci:v*d*sv%08Xsd%08X*", id1, id2);
49 key = "ID_MODEL_FROM_DATABASE";
52 sprintf(modalias, "pci:v*d*sv*sd*bc%02X*", id1);
53 key = "ID_PCI_CLASS_FROM_DATABASE";
56 sprintf(modalias, "pci:v*d*sv*sd*bc%02Xsc%02X*", id1, id2);
57 key = "ID_PCI_SUBCLASS_FROM_DATABASE";
60 sprintf(modalias, "pci:v*d*sv*sd*bc%02Xsc%02Xi%02X*", id1, id2, id3);
61 key = "ID_PCI_INTERFACE_FROM_DATABASE";
69 a->debug("Initializing UDEV HWDB\n");
70 a->id_udev = udev_new();
71 a->id_udev_hwdb = udev_hwdb_new(a->id_udev);
74 struct udev_list_entry *entry;
75 udev_list_entry_foreach(entry, udev_hwdb_get_properties_list_entry(a->id_udev_hwdb, modalias, 0))
77 const char *entry_name = udev_list_entry_get_name(entry);
78 if (entry_name && !strcmp(entry_name, key))
80 const char *entry_value = udev_list_entry_get_value(entry);
82 return pci_strdup(a, entry_value);
91 pci_id_hwdb_free(struct pci_access *a)
95 udev_hwdb_unref(a->id_udev_hwdb);
96 a->id_udev_hwdb = NULL;
100 udev_unref(a->id_udev);
108 pci_id_hwdb_lookup(struct pci_access *a UNUSED, int cat UNUSED, int id1 UNUSED, int id2 UNUSED, int id3 UNUSED, int id4 UNUSED)
114 pci_id_hwdb_free(struct pci_access *a UNUSED)