diff options
author | Emmanuel Vadot <manu@FreeBSD.org> | 2020-12-10 17:38:41 +0000 |
---|---|---|
committer | Emmanuel Vadot <manu@FreeBSD.org> | 2021-01-12 11:25:28 +0000 |
commit | 8517a547a05209c7da2c895e2d7c296ec54dd068 (patch) | |
tree | 64572a07835c04bb33ed75319895a535ebc9f2e9 | |
parent | 8b18395487506d3602205e5844e0b67ba0c0dc80 (diff) | |
download | src-8517a547a05209c7da2c895e2d7c296ec54dd068.tar.gz src-8517a547a05209c7da2c895e2d7c296ec54dd068.zip |
pci: Add pci_find_class_from
pci_find_class_from help finding one or multiple device matching
a class and subclass.
If the from argument is not null we will first loop in the device list
until we find the matching device and only then start to check if the
class/subclass matches.
Reviewed by: jhb
Differential Revision: https://reviews.freebsd.org/D27549
-rw-r--r-- | sys/dev/pci/pci.c | 22 | ||||
-rw-r--r-- | sys/dev/pci/pcivar.h | 1 |
2 files changed, 23 insertions, 0 deletions
diff --git a/sys/dev/pci/pci.c b/sys/dev/pci/pci.c index 342e55681fb3..1ca128a48ad0 100644 --- a/sys/dev/pci/pci.c +++ b/sys/dev/pci/pci.c @@ -493,6 +493,28 @@ pci_find_class(uint8_t class, uint8_t subclass) return (NULL); } +device_t +pci_find_class_from(uint8_t class, uint8_t subclass, device_t from) +{ + struct pci_devinfo *dinfo; + bool found = false; + + STAILQ_FOREACH(dinfo, &pci_devq, pci_links) { + if (from != NULL && found == false) { + if (from != dinfo->cfg.dev) + continue; + found = true; + continue; + } + if (dinfo->cfg.baseclass == class && + dinfo->cfg.subclass == subclass) { + return (dinfo->cfg.dev); + } + } + + return (NULL); +} + static int pci_printf(pcicfgregs *cfg, const char *fmt, ...) { diff --git a/sys/dev/pci/pcivar.h b/sys/dev/pci/pcivar.h index 29de6dad93f0..0f04ca8f623c 100644 --- a/sys/dev/pci/pcivar.h +++ b/sys/dev/pci/pcivar.h @@ -666,6 +666,7 @@ device_t pci_find_bsf(uint8_t, uint8_t, uint8_t); device_t pci_find_dbsf(uint32_t, uint8_t, uint8_t, uint8_t); device_t pci_find_device(uint16_t, uint16_t); device_t pci_find_class(uint8_t class, uint8_t subclass); +device_t pci_find_class_from(uint8_t class, uint8_t subclass, device_t devfrom); /* Can be used by drivers to manage the MSI-X table. */ int pci_pending_msix(device_t dev, u_int index); |