git: 16bedf532c02 - main - pci: Add helper routines to iterate over a device's BARs.

From: John Baldwin <jhb_at_FreeBSD.org>
Date: Fri, 19 Aug 2022 22:25:35 UTC
The branch main has been updated by jhb:

URL: https://cgit.FreeBSD.org/src/commit/?id=16bedf532c022f2380b0bb2970a3a3ebc7ca0f36

commit 16bedf532c022f2380b0bb2970a3a3ebc7ca0f36
Author:     John Baldwin <jhb@FreeBSD.org>
AuthorDate: 2022-08-19 21:59:06 +0000
Commit:     John Baldwin <jhb@FreeBSD.org>
CommitDate: 2022-08-19 21:59:06 +0000

    pci: Add helper routines to iterate over a device's BARs.
    
    Reviewed by:    imp, markj, emaste
    MFC after:      1 week
    Sponsored by:   The FreeBSD Foundation
    Differential Revision:  https://reviews.freebsd.org/D36237
---
 sys/dev/pci/pci.c    | 15 +++++++++++++++
 sys/dev/pci/pcivar.h |  2 ++
 2 files changed, 17 insertions(+)

diff --git a/sys/dev/pci/pci.c b/sys/dev/pci/pci.c
index 34eab9fdd2bb..ed48e20b153e 100644
--- a/sys/dev/pci/pci.c
+++ b/sys/dev/pci/pci.c
@@ -3170,6 +3170,21 @@ pci_find_bar(device_t dev, int reg)
 	return (NULL);
 }
 
+struct pci_map *
+pci_first_bar(device_t dev)
+{
+	struct pci_devinfo *dinfo;
+
+	dinfo = device_get_ivars(dev);
+	return (STAILQ_FIRST(&dinfo->cfg.maps));
+}
+
+struct pci_map *
+pci_next_bar(struct pci_map *pm)
+{
+	return (STAILQ_NEXT(pm, pm_link));
+}
+
 int
 pci_bar_enabled(device_t dev, struct pci_map *pm)
 {
diff --git a/sys/dev/pci/pcivar.h b/sys/dev/pci/pcivar.h
index 2454b05b9acc..6d575077f778 100644
--- a/sys/dev/pci/pcivar.h
+++ b/sys/dev/pci/pcivar.h
@@ -717,6 +717,8 @@ extern struct devlist	pci_devq;
 extern uint32_t	pci_generation;
 
 struct pci_map *pci_find_bar(device_t dev, int reg);
+struct pci_map *pci_first_bar(device_t dev);
+struct pci_map *pci_next_bar(struct pci_map *pm);
 int	pci_bar_enabled(device_t dev, struct pci_map *pm);
 struct pcicfg_vpd *pci_fetch_vpd_list(device_t dev);