git: 8517a547a052 - main - pci: Add pci_find_class_from

Emmanuel Vadot manu at FreeBSD.org
Tue Jan 12 11:42:57 UTC 2021


The branch main has been updated by manu:

URL: https://cgit.FreeBSD.org/src/commit/?id=8517a547a05209c7da2c895e2d7c296ec54dd068

commit 8517a547a05209c7da2c895e2d7c296ec54dd068
Author:     Emmanuel Vadot <manu at FreeBSD.org>
AuthorDate: 2020-12-10 17:38:41 +0000
Commit:     Emmanuel Vadot <manu at FreeBSD.org>
CommitDate: 2021-01-12 11:25:28 +0000

    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 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);


More information about the dev-commits-src-all mailing list