diff options
author | Ian Moffett <ian@osmora.org> | 2024-07-09 01:46:04 -0400 |
---|---|---|
committer | Ian Moffett <ian@osmora.org> | 2024-07-09 01:46:04 -0400 |
commit | 54c9c5246e28a8a3d586a5f7346e38648ef2b3f9 (patch) | |
tree | f7663e42ac340c660da2845546e101a05258ac54 /sys/dev/pci | |
parent | f031ad404e544c9332498a11d9956b27a4acc72b (diff) |
kernel: pci: Add PCI device lookups
Signed-off-by: Ian Moffett <ian@osmora.org>
Diffstat (limited to 'sys/dev/pci')
-rw-r--r-- | sys/dev/pci/pci.c | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/sys/dev/pci/pci.c b/sys/dev/pci/pci.c index 680e5ac..587881a 100644 --- a/sys/dev/pci/pci.c +++ b/sys/dev/pci/pci.c @@ -127,6 +127,48 @@ pci_scan_bus(uint8_t bus) } } +struct pci_device * +pci_get_device(struct pci_lookup lookup, uint16_t lookup_type) +{ + struct pci_device *dev; + uint16_t lookup_matches = 0; + + TAILQ_FOREACH(dev, &device_list, link) { + if (ISSET(lookup_type, PCI_DEVICE_ID)) { + /* Check device ID */ + if (lookup.device_id == dev->device_id) + lookup_matches |= PCI_DEVICE_ID; + } + + if (ISSET(lookup_type, PCI_VENDOR_ID)) { + /* Check vendor ID */ + if (lookup.vendor_id == dev->vendor_id) + lookup_matches |= PCI_VENDOR_ID; + } + + if (ISSET(lookup_type, PCI_CLASS)) { + /* Check PCI class */ + if (lookup.pci_class == dev->pci_class) + lookup_matches |= PCI_CLASS; + } + + if (ISSET(lookup_type, PCI_SUBCLASS)) { + /* Check PCI subclass */ + if (lookup.pci_subclass == dev->pci_subclass) + lookup_matches |= PCI_SUBCLASS; + } + + if (lookup_type == lookup_matches) { + /* We found the device! */ + return dev; + } + + lookup_matches = 0; + } + + return NULL; +} + int pci_init(void) { |