]>
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.
22 pci_id_hwdb_lookup(struct pci_access
*a
, int cat
, int id1
, int id2
, int id3
, int id4
)
25 const char *key
= NULL
;
27 const char *disabled
= pci_get_param(a
, "hwdb.disable");
28 if (disabled
&& atoi(disabled
))
34 sprintf(modalias
, "pci:v%08X*", id1
);
35 key
= "ID_VENDOR_FROM_DATABASE";
38 sprintf(modalias
, "pci:v%08Xd%08X*", id1
, id2
);
39 key
= "ID_MODEL_FROM_DATABASE";
42 sprintf(modalias
, "pci:v%08Xd%08Xsv%08Xsd%08X*", id1
, id2
, id3
, id4
);
43 key
= "ID_MODEL_FROM_DATABASE";
45 case ID_GEN_SUBSYSTEM
:
46 sprintf(modalias
, "pci:v*d*sv%08Xsd%08X*", id1
, id2
);
47 key
= "ID_MODEL_FROM_DATABASE";
50 sprintf(modalias
, "pci:v*d*sv*sd*bc%02X*", id1
);
51 key
= "ID_PCI_CLASS_FROM_DATABASE";
54 sprintf(modalias
, "pci:v*d*sv*sd*bc%02Xsc%02X*", id1
, id2
);
55 key
= "ID_PCI_SUBCLASS_FROM_DATABASE";
58 sprintf(modalias
, "pci:v*d*sv*sd*bc%02Xsc%02Xi%02X*", id1
, id2
, id3
);
59 key
= "ID_PCI_INTERFACE_FROM_DATABASE";
67 a
->debug("Initializing UDEV HWDB\n");
68 a
->id_udev
= udev_new();
69 a
->id_udev_hwdb
= udev_hwdb_new(a
->id_udev
);
72 struct udev_list_entry
*entry
;
73 udev_list_entry_foreach(entry
, udev_hwdb_get_properties_list_entry(a
->id_udev_hwdb
, modalias
, 0))
74 if (strcmp(udev_list_entry_get_name(entry
), key
) == 0)
75 return pci_strdup(a
, udev_list_entry_get_value(entry
));
82 pci_id_hwdb_free(struct pci_access
*a
)
86 udev_hwdb_unref(a
->id_udev_hwdb
);
87 a
->id_udev_hwdb
= NULL
;
91 udev_unref(a
->id_udev
);
99 pci_id_hwdb_lookup(struct pci_access
*a UNUSED
, int cat UNUSED
, int id1 UNUSED
, int id2 UNUSED
, int id3 UNUSED
, int id4 UNUSED
)
105 pci_id_hwdb_free(struct pci_access
*a UNUSED
)