From 8517a547a05209c7da2c895e2d7c296ec54dd068 Mon Sep 17 00:00:00 2001 From: Emmanuel Vadot Date: Thu, 10 Dec 2020 18:38:41 +0100 Subject: [PATCH] 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 --- sys/dev/pci/pci.c | 22 ++++++++++++++++++++++ sys/dev/pci/pcivar.h | 1 + 2 files changed, 23 insertions(+) diff --git a/sys/dev/pci/pci.c b/sys/dev/pci/pci.c index 342e55681fb..1ca128a48ad 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 29de6dad93f..0f04ca8f623 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);