PERFORCE change 230999 for review

John Baldwin jhb at FreeBSD.org
Thu Jul 11 04:00:34 UTC 2013


http://p4web.freebsd.org/@@230999?ac=10

Change 230999 by jhb at jhb_pippin on 2013/07/11 04:00:22

	Move pci_domain_*() calls out of the x86 nexus and down into the
	Host-PCI bridge drivers.  Trying to use an ivar in the nexus to
	infer the right domain to allocate from was error-prone.  However,
	each Host-PCI bridge knows which PCI domain/segment it belongs to.

Affected files ...

.. //depot/projects/pci/sys/dev/acpica/acpi_pcib_acpi.c#34 edit
.. //depot/projects/pci/sys/x86/include/legacyvar.h#2 edit
.. //depot/projects/pci/sys/x86/pci/pci_bus.c#4 edit
.. //depot/projects/pci/sys/x86/x86/mptable_pci.c#18 edit
.. //depot/projects/pci/sys/x86/x86/nexus.c#14 edit

Differences ...

==== //depot/projects/pci/sys/dev/acpica/acpi_pcib_acpi.c#34 (text+ko) ====

@@ -97,6 +97,11 @@
 static int		acpi_pcib_acpi_adjust_resource(device_t dev,
 			    device_t child, int type, struct resource *r,
 			    u_long start, u_long end);
+#ifdef PCI_RES_BUS
+static int		acpi_pcib_acpi_release_resource(device_t dev,
+			    device_t child, int type, int rid,
+			    struct resource *r);
+#endif
 #endif
 
 static device_method_t acpi_pcib_acpi_methods[] = {
@@ -116,7 +121,11 @@
 #else
     DEVMETHOD(bus_adjust_resource,	bus_generic_adjust_resource),
 #endif
+#if defined(NEW_PCIB) && defined(PCI_RES_BUS)
+    DEVMETHOD(bus_release_resource,	acpi_pcib_acpi_release_resource),
+#else
     DEVMETHOD(bus_release_resource,	bus_generic_release_resource),
+#endif
     DEVMETHOD(bus_activate_resource,	bus_generic_activate_resource),
     DEVMETHOD(bus_deactivate_resource,	bus_generic_deactivate_resource),
     DEVMETHOD(bus_setup_intr,		bus_generic_setup_intr),
@@ -424,15 +433,16 @@
 		    sc->ap_bus = start;
 	    else {
 		    rid = 0;
-		    bus_res = bus_alloc_resource(dev, PCI_RES_BUS, &rid, 0,
+		    bus_res = pci_domain_alloc_bus(sc->ap_segment, dev, &rid, 0,
 			PCI_BUSMAX, 1, 0);
 		    if (bus_res == NULL) {
-			    device_printf(dev, "could not allocate bus number\n");
+			    device_printf(dev,
+				"could not allocate bus number\n");
 			    pcib_host_res_free(dev, &sc->ap_host_res);
 			    return (ENXIO);
 		    }
 		    sc->ap_bus = rman_get_start(bus_res);
-		    bus_release_resource(dev, PCI_RES_BUS, rid, bus_res);
+		    pci_domain_release_bus(sc->ap_segment, dev, rid, bus_res);
 	    }
     } else {
 #ifdef INVARIANTS
@@ -587,6 +597,11 @@
 
 #ifdef NEW_PCIB
     sc = device_get_softc(dev);
+#ifdef PCI_RES_BUS
+    if (type == PCI_RES_BUS)
+	return (pci_domain_alloc_bus(sc->ap_segment, child, rid, start, end,
+	    count, flags));
+#endif
     res = pcib_host_res_alloc(&sc->ap_host_res, child, type, rid, start, end,
 	count, flags);
 
@@ -615,7 +630,26 @@
 	struct acpi_hpcib_softc *sc;
 
 	sc = device_get_softc(dev);
+#ifdef PCI_RES_BUS
+	if (type == PCI_RES_BUS)
+		return (pci_domain_adjust_bus(sc->ap_segment, child, r, start,
+		    end));
+#endif
 	return (pcib_host_res_adjust(&sc->ap_host_res, child, type, r, start,
 	    end));
 }
+
+#ifdef PCI_RES_BUS
+int
+acpi_pcib_acpi_release_resource(device_t dev, device_t child, int type, int rid,
+    struct resource *r)
+{
+	struct acpi_hpcib_softc *sc;
+
+	sc = device_get_softc(dev);
+	if (type == PCI_RES_BUS)
+		return (pci_domain_release_bus(sc->ap_segment, child, rid, r));
+	return (bus_generic_release_resource(dev, child, type, rid, r));
+}
+#endif
 #endif

==== //depot/projects/pci/sys/x86/include/legacyvar.h#2 (text+ko) ====

@@ -57,6 +57,8 @@
     uintptr_t value);
 struct resource *legacy_pcib_alloc_resource(device_t dev, device_t child,
     int type, int *rid, u_long start, u_long end, u_long count, u_int flags);
+int	legacy_pcib_release_resource(device_t dev, device_t child, int type,
+    int rid, struct resource *r);
 int	legacy_pcib_map_msi(device_t pcib, device_t dev, int irq,
     uint64_t *addr, uint32_t *data);
 

==== //depot/projects/pci/sys/x86/pci/pci_bus.c#4 (text+ko) ====

@@ -597,11 +597,39 @@
     u_long start, u_long end, u_long count, u_int flags)
 {
 
-    start = hostb_alloc_start(type, start, end, count);
-    return (bus_generic_alloc_resource(dev, child, type, rid, start, end,
-	count, flags));
+#if defined(NEW_PCIB) && defined(PCI_RES_BUS)
+	if (type == PCI_RES_BUS)
+		return (pci_domain_alloc_bus(0, child, rid, start, end, count,
+		    flags));
+#endif
+	start = hostb_alloc_start(type, start, end, count);
+	return (bus_generic_alloc_resource(dev, child, type, rid, start, end,
+	    count, flags));
+}
+
+#if defined(NEW_PCIB) && defined(PCI_RES_BUS)
+static int
+legacy_pcib_adjust_resource(device_t dev, device_t child, int type,
+    struct resource *r, u_long start, u_long end)
+{
+
+	if (type == PCI_RES_BUS)
+		return (pci_domain_adjust_bus(0, child, r, start, end));
+	return (bus_generic_adjust_resource(dev, child, type, r, start, end));
+}
+
+int
+legacy_pcib_release_resource(device_t dev, device_t child, int type, int rid,
+    struct resource *r)
+{
+
+	if (type == PCI_RES_BUS)
+		return (pci_domain_release_bus(0, child, rid, r));
+	return (bus_generic_release_resource(dev, child, type, rid, r));
 }
+#endif
 
+
 static device_method_t legacy_pcib_methods[] = {
 	/* Device interface */
 	DEVMETHOD(device_identify,	legacy_pcib_identify),
@@ -615,8 +643,13 @@
 	DEVMETHOD(bus_read_ivar,	legacy_pcib_read_ivar),
 	DEVMETHOD(bus_write_ivar,	legacy_pcib_write_ivar),
 	DEVMETHOD(bus_alloc_resource,	legacy_pcib_alloc_resource),
+#if defined(NEW_PCIB) && defined(PCI_RES_BUS)
+	DEVMETHOD(bus_adjust_resource,	legacy_pcib_adjust_resource),
+	DEVMETHOD(bus_release_resource,	legacy_pcib_release_resource),
+#else
 	DEVMETHOD(bus_adjust_resource,	bus_generic_adjust_resource),
 	DEVMETHOD(bus_release_resource,	bus_generic_release_resource),
+#endif
 	DEVMETHOD(bus_activate_resource, bus_generic_activate_resource),
 	DEVMETHOD(bus_deactivate_resource, bus_generic_deactivate_resource),
 	DEVMETHOD(bus_setup_intr,	bus_generic_setup_intr),

==== //depot/projects/pci/sys/x86/x86/mptable_pci.c#18 (text+ko) ====

@@ -129,6 +129,11 @@
 {
 	struct mptable_hostb_softc *sc;
 
+#ifdef PCI_RES_BUS
+	if (type == PCI_RES_BUS)
+		return (pci_domain_alloc_bus(0, child, rid, start, end, count,
+		    flags));
+#endif
 	sc = device_get_softc(dev);
 	if (type == SYS_RES_IOPORT && start + count - 1 == end) {
 		if (mptable_is_isa_range(start, end)) {
@@ -165,6 +170,10 @@
 {
 	struct mptable_hostb_softc *sc;
 
+#ifdef PCI_RES_BUS
+	if (type == PCI_RES_BUS)
+		return (pci_domain_adjust_bus(0, child, r, start, end));
+#endif
 	sc = device_get_softc(dev);
 	return (pcib_host_res_adjust(&sc->sc_host_res, child, type, r, start,
 	    end));
@@ -189,7 +198,11 @@
 	DEVMETHOD(bus_alloc_resource,	legacy_pcib_alloc_resource),
 	DEVMETHOD(bus_adjust_resource,	bus_generic_adjust_resource),
 #endif
+#if defined(NEW_PCIB) && defined(PCI_RES_BUS)
+	DEVMETHOD(bus_release_resource,	legacy_pcib_release_resource),
+#else
 	DEVMETHOD(bus_release_resource,	bus_generic_release_resource),
+#endif
 	DEVMETHOD(bus_activate_resource, bus_generic_activate_resource),
 	DEVMETHOD(bus_deactivate_resource, bus_generic_deactivate_resource),
 	DEVMETHOD(bus_setup_intr,	bus_generic_setup_intr),

==== //depot/projects/pci/sys/x86/x86/nexus.c#14 (text+ko) ====

@@ -70,11 +70,6 @@
 #include <machine/resource.h>
 #include <machine/pc/bios.h>
 
-#ifdef PCI_RES_BUS
-#include <dev/pci/pcivar.h>
-#include <dev/pci/pcib_private.h>
-#endif
-
 #ifdef DEV_APIC
 #include "pcib_if.h"
 #endif
@@ -372,20 +367,6 @@
 	struct	rman *rm;
 	int needactivate = flags & RF_ACTIVE;
 
-#ifdef PCI_RES_BUS
-	if (type == PCI_RES_BUS) {
-		/*
-		 * PCI bus number resources are allocated from a
-		 * specific PCI domain.  The child device must be a
-		 * 'pcib' device which implements the pcib ivars.  We
-		 * depend on that to determine which PCI domain to
-		 * allocate from.
-		 */
-		return (pci_domain_alloc_bus(pcib_get_domain(child), child, rid,
-		    start, end, count, flags));
-	}
-#endif
-
 	/*
 	 * If this is an allocation of the "default" range for a given
 	 * RID, and we know what the resources for this device are
@@ -429,11 +410,6 @@
 {
 	struct rman *rm;
 
-#ifdef PCI_RES_BUS
-	if (type == PCI_RES_BUS)
-		return (pci_domain_adjust_bus(pcib_get_domain(child), child, r,
-		    start, end));
-#endif
 	rm = nexus_rman(type);
 	if (rm == NULL)
 		return (ENXIO);
@@ -518,11 +494,6 @@
 		       struct resource *r)
 {
 
-#ifdef PCI_RES_BUS
-	if (type == PCI_RES_BUS)
-		return (pci_domain_release_bus(pcib_get_domain(child), child,
-		    rid, r));
-#endif
 	if (rman_get_flags(r) & RF_ACTIVE) {
 		int error = bus_deactivate_resource(child, type, rid, r);
 		if (error)


More information about the p4-projects mailing list