]>
git.ipfire.org Git - thirdparty/pciutils.git/blob - lib/names-hwdb.c
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 UNUSED
)
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";
45 * There is no udev hwdb key which returns subsystem. Also note that query
46 * modalias "pci:v%08Xd%08Xsv%08Xsd%08X*" matches also hwdb device with
47 * modalias "pci:v%08Xd%08Xsv*sd*" (which is the default modalias), so
48 * there is no way to get information specific for the subsystem.
51 case ID_GEN_SUBSYSTEM
:
52 /* There is no udev hwdb key which returns generic subsystem. */
55 sprintf(modalias
, "pci:v*d*sv*sd*bc%02X*", id1
);
56 key
= "ID_PCI_CLASS_FROM_DATABASE";
59 sprintf(modalias
, "pci:v*d*sv*sd*bc%02Xsc%02X*", id1
, id2
);
60 key
= "ID_PCI_SUBCLASS_FROM_DATABASE";
63 sprintf(modalias
, "pci:v*d*sv*sd*bc%02Xsc%02Xi%02X*", id1
, id2
, id3
);
64 key
= "ID_PCI_INTERFACE_FROM_DATABASE";
72 a
->debug("Initializing UDEV HWDB\n");
73 a
->id_udev
= udev_new();
74 a
->id_udev_hwdb
= udev_hwdb_new(a
->id_udev
);
77 struct udev_list_entry
*entry
;
78 udev_list_entry_foreach(entry
, udev_hwdb_get_properties_list_entry(a
->id_udev_hwdb
, modalias
, 0))
80 const char *entry_name
= udev_list_entry_get_name(entry
);
81 if (entry_name
&& !strcmp(entry_name
, key
))
83 const char *entry_value
= udev_list_entry_get_value(entry
);
85 return pci_strdup(a
, entry_value
);
94 pci_id_hwdb_free(struct pci_access
*a
)
98 udev_hwdb_unref(a
->id_udev_hwdb
);
99 a
->id_udev_hwdb
= NULL
;
103 udev_unref(a
->id_udev
);
111 pci_id_hwdb_lookup(struct pci_access
*a UNUSED
, int cat UNUSED
, int id1 UNUSED
, int id2 UNUSED
, int id3 UNUSED
, int id4 UNUSED
)
117 pci_id_hwdb_free(struct pci_access
*a UNUSED
)