git: c19f1ad1c252 - main - pci_host_generic: Use SYS_RES_MEMORY for the parent of I/O resource ranges

From: John Baldwin <jhb_at_FreeBSD.org>
Date: Tue, 21 Jan 2025 16:03:06 UTC
The branch main has been updated by jhb:

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

commit c19f1ad1c252f434146c7210155d805b2ed0ff95
Author:     John Baldwin <jhb@FreeBSD.org>
AuthorDate: 2025-01-21 15:51:53 +0000
Commit:     John Baldwin <jhb@FreeBSD.org>
CommitDate: 2025-01-21 16:02:34 +0000

    pci_host_generic: Use SYS_RES_MEMORY for the parent of I/O resource ranges
    
    When a SYS_RES_IOPORT resource crosses a pci_host_generic bridge, it
    is translated into a memory access for an associated range, so use
    SYS_RES_MEMORY for the resource allocated from the parent.
    
    Tested by:      markj
    Differential Revision:  https://reviews.freebsd.org/D44207
---
 sys/dev/pci/pci_host_generic.c | 21 ++++++++-------------
 1 file changed, 8 insertions(+), 13 deletions(-)

diff --git a/sys/dev/pci/pci_host_generic.c b/sys/dev/pci/pci_host_generic.c
index 884ab25548ce..49b131cd2299 100644
--- a/sys/dev/pci/pci_host_generic.c
+++ b/sys/dev/pci/pci_host_generic.c
@@ -91,7 +91,7 @@ pci_host_generic_core_attach(device_t dev)
 	const char *range_descr;
 	char buf[64];
 	int domain, error;
-	int flags, rid, tuple, type;
+	int flags, rid, tuple;
 
 	sc = device_get_softc(dev);
 	sc->dev = dev;
@@ -187,19 +187,16 @@ pci_host_generic_core_attach(device_t dev)
 			sc->has_pmem = true;
 			range_descr = "prefetch";
 			flags = RF_PREFETCHABLE;
-			type = SYS_RES_MEMORY;
 			rm = &sc->pmem_rman;
 			break;
 		case FLAG_TYPE_MEM:
 			range_descr = "memory";
 			flags = 0;
-			type = SYS_RES_MEMORY;
 			rm = &sc->mem_rman;
 			break;
 		case FLAG_TYPE_IO:
 			range_descr = "I/O port";
 			flags = 0;
-			type = SYS_RES_IOPORT;
 			rm = &sc->io_rman;
 			break;
 		default:
@@ -209,7 +206,8 @@ pci_host_generic_core_attach(device_t dev)
 			device_printf(dev,
 			    "PCI addr: 0x%jx, CPU addr: 0x%jx, Size: 0x%jx, Type: %s\n",
 			    pci_base, phys_base, size, range_descr);
-		error = bus_set_resource(dev, type, rid, phys_base, size);
+		error = bus_set_resource(dev, SYS_RES_MEMORY, rid, phys_base,
+		    size);
 		if (error != 0) {
 			device_printf(dev,
 			    "failed to set resource for range %d: %d\n", tuple,
@@ -217,8 +215,8 @@ pci_host_generic_core_attach(device_t dev)
 			continue;
 		}
 		sc->ranges[tuple].rid = rid;
-		sc->ranges[tuple].res = bus_alloc_resource_any(dev, type, &rid,
-		    RF_ACTIVE | RF_UNMAPPED | flags);
+		sc->ranges[tuple].res = bus_alloc_resource_any(dev,
+		    SYS_RES_MEMORY, &rid, RF_ACTIVE | RF_UNMAPPED | flags);
 		if (sc->ranges[tuple].res == NULL) {
 			device_printf(dev,
 			    "failed to allocate resource for range %d\n", tuple);
@@ -253,7 +251,7 @@ int
 pci_host_generic_core_detach(device_t dev)
 {
 	struct generic_pcie_core_softc *sc;
-	int error, rid, tuple, type;
+	int error, rid, tuple;
 
 	sc = device_get_softc(dev);
 
@@ -272,18 +270,15 @@ pci_host_generic_core_detach(device_t dev)
 		switch (FLAG_TYPE(sc->ranges[tuple].flags)) {
 		case FLAG_TYPE_PMEM:
 		case FLAG_TYPE_MEM:
-			type = SYS_RES_MEMORY;
-			break;
 		case FLAG_TYPE_IO:
-			type = SYS_RES_IOPORT;
 			break;
 		default:
 			continue;
 		}
 		if (sc->ranges[tuple].res != NULL)
-			bus_release_resource(dev, type, rid,
+			bus_release_resource(dev, SYS_RES_MEMORY, rid,
 			    sc->ranges[tuple].res);
-		bus_delete_resource(dev, type, rid);
+		bus_delete_resource(dev, SYS_RES_MEMORY, rid);
 	}
 	rman_fini(&sc->io_rman);
 	rman_fini(&sc->mem_rman);