git: 23e3b83ab61a - main - pcib: Add helper routines for [de]activating PCI_RES_BUS resources

From: John Baldwin <jhb_at_FreeBSD.org>
Date: Tue, 23 Jan 2024 17:45:48 UTC
The branch main has been updated by jhb:

URL: https://cgit.FreeBSD.org/src/commit/?id=23e3b83ab61a440ccce20da7fbf1340d58db361c

commit 23e3b83ab61a440ccce20da7fbf1340d58db361c
Author:     John Baldwin <jhb@FreeBSD.org>
AuthorDate: 2024-01-23 17:35:08 +0000
Commit:     John Baldwin <jhb@FreeBSD.org>
CommitDate: 2024-01-23 17:35:08 +0000

    pcib: Add helper routines for [de]activating PCI_RES_BUS resources
    
    Reviewed by:    imp
    Differential Revision:  https://reviews.freebsd.org/D43427
---
 sys/dev/pci/pci_subr.c     | 32 ++++++++++++++++++++++++++++++++
 sys/dev/pci/pcib_private.h |  4 ++++
 2 files changed, 36 insertions(+)

diff --git a/sys/dev/pci/pci_subr.c b/sys/dev/pci/pci_subr.c
index 71485875ebe3..d0f6c9500b17 100644
--- a/sys/dev/pci/pci_subr.c
+++ b/sys/dev/pci/pci_subr.c
@@ -379,6 +379,38 @@ pci_domain_release_bus(int domain, device_t dev, int rid, struct resource *r)
 #endif
 	return (rman_release_resource(r));
 }
+
+int
+pci_domain_activate_bus(int domain, device_t dev, int rid, struct resource *r)
+{
+#ifdef INVARIANTS
+	struct pci_domain *d;
+#endif
+
+	if (domain < 0 || domain > PCI_DOMAINMAX)
+		return (EINVAL);
+#ifdef INVARIANTS
+	d = pci_find_domain(domain);
+	KASSERT(rman_is_region_manager(r, &d->pd_bus_rman), ("bad resource"));
+#endif
+	return (rman_activate_resource(r));
+}
+
+int
+pci_domain_deactivate_bus(int domain, device_t dev, int rid, struct resource *r)
+{
+#ifdef INVARIANTS
+	struct pci_domain *d;
+#endif
+
+	if (domain < 0 || domain > PCI_DOMAINMAX)
+		return (EINVAL);
+#ifdef INVARIANTS
+	d = pci_find_domain(domain);
+	KASSERT(rman_is_region_manager(r, &d->pd_bus_rman), ("bad resource"));
+#endif
+	return (rman_deactivate_resource(r));
+}
 #endif /* PCI_RES_BUS */
 
 #endif /* NEW_PCIB */
diff --git a/sys/dev/pci/pcib_private.h b/sys/dev/pci/pcib_private.h
index cf689026a033..d8a354c0e498 100644
--- a/sys/dev/pci/pcib_private.h
+++ b/sys/dev/pci/pcib_private.h
@@ -160,6 +160,10 @@ int		pci_domain_adjust_bus(int domain, device_t dev,
 		    struct resource *r, rman_res_t start, rman_res_t end);
 int		pci_domain_release_bus(int domain, device_t dev, int rid,
 		    struct resource *r);
+int		pci_domain_activate_bus(int domain, device_t dev, int rid,
+		    struct resource *r);
+int		pci_domain_deactivate_bus(int domain, device_t dev, int rid,
+		    struct resource *r);
 struct resource *pcib_alloc_subbus(struct pcib_secbus *bus, device_t child,
 		    int *rid, rman_res_t start, rman_res_t end, rman_res_t count,
 		    u_int flags);