PERFORCE change 231063 for review

John Baldwin jhb at FreeBSD.org
Fri Jul 12 03:08:48 UTC 2013


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

Change 231063 by jhb at jhb_pippin on 2013/07/12 03:07:59

	Genericize the bus management code in the PCI-PCI driver so it
	can be used in the PCI-Cardbus driver.  Not tested, but does
	compile.

Affected files ...

.. //depot/projects/pci/sys/dev/acpica/acpi_pcib_pci.c#6 edit
.. //depot/projects/pci/sys/dev/cardbus/cardbus.c#9 edit
.. //depot/projects/pci/sys/dev/pccbb/pccbb.c#6 edit
.. //depot/projects/pci/sys/dev/pccbb/pccbb_isa.c#4 edit
.. //depot/projects/pci/sys/dev/pccbb/pccbb_pci.c#6 edit
.. //depot/projects/pci/sys/dev/pccbb/pccbbvar.h#3 edit
.. //depot/projects/pci/sys/dev/pci/pci_pci.c#38 edit
.. //depot/projects/pci/sys/dev/pci/pcib_private.h#25 edit
.. //depot/projects/pci/sys/sparc64/pci/apb.c#6 edit

Differences ...

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

@@ -120,7 +120,7 @@
     pcib_attach_common(dev);
     sc = device_get_softc(dev);
     sc->ap_handle = acpi_get_handle(dev);
-    return (acpi_pcib_attach(dev, &sc->ap_prt, sc->ap_pcibsc.secbus));
+    return (acpi_pcib_attach(dev, &sc->ap_prt, sc->ap_pcibsc.bus.sec));
 }
 
 static int

==== //depot/projects/pci/sys/dev/cardbus/cardbus.c#9 (text+ko) ====

@@ -124,7 +124,7 @@
 	cardbus_detach_card(cbdev);
 #ifdef PCI_RES_BUS
 	sc = device_get_softc(cbdev);
-	(void)bus_release_resource(cbdev, PCI_RES_BUS, 0, sc->sc_bus));
+	(void)bus_release_resource(cbdev, PCI_RES_BUS, 0, sc->sc_bus);
 #endif
 	return (0);
 }

==== //depot/projects/pci/sys/dev/pccbb/pccbb.c#6 (text+ko) ====

@@ -97,6 +97,7 @@
 
 #include <dev/pci/pcireg.h>
 #include <dev/pci/pcivar.h>
+#include <dev/pci/pcib_private.h>
 
 #include <dev/pccard/pccardreg.h>
 #include <dev/pccard/pccardvar.h>
@@ -1203,9 +1204,6 @@
 	u_long align;
 
 	switch (type) {
-#if defined(NEW_PCIB) && defined(PCI_RES_BUS)
-		/* XXX: PCI_RES_BUS handling */
-#endif
 	case SYS_RES_IRQ:
 		tmp = rman_get_start(sc->irq_res);
 		if (start > tmp || end < tmp || count != 1) {
@@ -1505,6 +1503,11 @@
 {
 	struct cbb_softc *sc = device_get_softc(brdev);
 
+#if defined(NEW_PCIB) && defined(PCI_RES_BUS)
+	if (type == PCI_RES_BUS)
+		return (pcib_alloc_subbus(&sc->bus, child, rid, start, end,
+		    count, flags));
+#endif
 	if (sc->flags & CBB_16BIT_CARD)
 		return (cbb_pcic_alloc_resource(brdev, child, type, rid,
 		    start, end, count, flags));
@@ -1518,7 +1521,20 @@
     struct resource *r)
 {
 	struct cbb_softc *sc = device_get_softc(brdev);
+#if defined(NEW_PCIB) && defined(PCI_RES_BUS)
+	int error;
 
+	if (type == PCI_RES_BUS) {
+		if (!rman_is_region_manager(r, &sc->bus.rman))
+			return (EINVAL);
+		if (rman_get_flags(r) & RF_ACTIVE) {
+			error = bus_deactivate_resource(child, type, rid, r);
+			if (error)
+				return (error);
+		}
+		return (rman_release_resource(r));
+	}
+#endif
 	if (sc->flags & CBB_16BIT_CARD)
 		return (cbb_pcic_release_resource(brdev, child, type,
 		    rid, r));
@@ -1537,7 +1553,7 @@
 		*result = sc->domain;
 		return (0);
 	case PCIB_IVAR_BUS:
-		*result = sc->secbus;
+		*result = sc->bus.sec;
 		return (0);
 	}
 	return (ENOENT);
@@ -1546,14 +1562,12 @@
 int
 cbb_write_ivar(device_t brdev, device_t child, int which, uintptr_t value)
 {
-	struct cbb_softc *sc = device_get_softc(brdev);
 
 	switch (which) {
 	case PCIB_IVAR_DOMAIN:
 		return (EINVAL);
 	case PCIB_IVAR_BUS:
-		sc->secbus = value;
-		return (0);
+		return (EINVAL);
 	}
 	return (ENOENT);
 }

==== //depot/projects/pci/sys/dev/pccbb/pccbb_isa.c#4 (text+ko) ====

@@ -51,6 +51,9 @@
 
 #include <isa/isavar.h>
 
+#include <dev/pci/pcivar.h>
+#include <dev/pci/pcib_private.h>
+
 #include <dev/pccard/pccardreg.h>
 #include <dev/pccard/pccardvar.h>
 

==== //depot/projects/pci/sys/dev/pccbb/pccbb_pci.c#6 (text+ko) ====

@@ -93,6 +93,7 @@
 
 #include <dev/pci/pcireg.h>
 #include <dev/pci/pcivar.h>
+#include <dev/pci/pcib_private.h>
 
 #include <dev/pccard/pccardreg.h>
 #include <dev/pccard/pccardvar.h>
@@ -303,13 +304,15 @@
 static int
 cbb_pci_attach(device_t brdev)
 {
+#if !(defined(NEW_PCIB) && defined(PCI_RES_BUS))
 	static int curr_bus_number = 2; /* XXX EVILE BAD (see below) */
+	uint32_t pribus;
+#endif
 	struct cbb_softc *sc = (struct cbb_softc *)device_get_softc(brdev);
 	struct sysctl_ctx_list *sctx;
 	struct sysctl_oid *soid;
 	int rid;
 	device_t parent;
-	uint32_t pribus;
 
 	parent = device_get_parent(brdev);
 	mtx_init(&sc->mtx, device_get_nameunit(brdev), "cbb", MTX_DEF);
@@ -318,11 +321,13 @@
 	sc->cbdev = NULL;
 	sc->exca[0].pccarddev = NULL;
 	sc->domain = pci_get_domain(brdev);
-	sc->secbus = pci_read_config(brdev, PCIR_SECBUS_2, 1);
-	sc->subbus = pci_read_config(brdev, PCIR_SUBBUS_2, 1);
+	sc->bus.sec = pci_read_config(brdev, PCIR_SECBUS_2, 1);
+	sc->bus.sub = pci_read_config(brdev, PCIR_SUBBUS_2, 1);
 	sc->pribus = pcib_get_bus(parent);
 #if defined(NEW_PCIB) && defined(PCI_RES_BUS)
-	/* XXX: Need something like pci_setup_secbus() here. */
+	sc->bus.sec_reg = PCIR_SECBUS_2;
+	sc->bus.sub_reg = PCIR_SUBBUS_2;
+	pcib_setup_secbus(brdev, &sc->bus);
 #endif
 	SLIST_INIT(&sc->rl);
 	cbb_powerstate_d0(brdev);
@@ -355,9 +360,9 @@
 	SYSCTL_ADD_UINT(sctx, SYSCTL_CHILDREN(soid), OID_AUTO, "pribus",
 	    CTLFLAG_RD, &sc->pribus, 0, "Primary bus number");
 	SYSCTL_ADD_UINT(sctx, SYSCTL_CHILDREN(soid), OID_AUTO, "secbus",
-	    CTLFLAG_RD, &sc->secbus, 0, "Secondary bus number");
+	    CTLFLAG_RD, &sc->bus.sec, 0, "Secondary bus number");
 	SYSCTL_ADD_UINT(sctx, SYSCTL_CHILDREN(soid), OID_AUTO, "subbus",
-	    CTLFLAG_RD, &sc->subbus, 0, "Subordinate bus number");
+	    CTLFLAG_RD, &sc->bus.sub, 0, "Subordinate bus number");
 #if 0
 	SYSCTL_ADD_UINT(sctx, SYSCTL_CHILDREN(soid), OID_AUTO, "memory",
 	    CTLFLAG_RD, &sc->subbus, 0, "Memory window open");
@@ -369,15 +374,16 @@
 	    CTLFLAG_RD, &sc->subbus, 0, "io range 2 open");
 #endif
 
+#if !(defined(NEW_PCIB) && defined(PCI_RES_BUS))
 	/*
 	 * This is a gross hack.  We should be scanning the entire pci
 	 * tree, assigning bus numbers in a way such that we (1) can
 	 * reserve 1 extra bus just in case and (2) all sub busses
 	 * are in an appropriate range.
 	 */
-	DEVPRINTF((brdev, "Secondary bus is %d\n", sc->secbus));
+	DEVPRINTF((brdev, "Secondary bus is %d\n", sc->bus.sec));
 	pribus = pci_read_config(brdev, PCIR_PRIBUS_2, 1);
-	if (sc->secbus == 0 || sc->pribus != pribus) {
+	if (sc->bus.sec == 0 || sc->pribus != pribus) {
 		if (curr_bus_number <= sc->pribus)
 			curr_bus_number = sc->pribus + 1;
 		if (pribus != sc->pribus) {
@@ -385,13 +391,14 @@
 			    sc->pribus));
 			pci_write_config(brdev, PCIR_PRIBUS_2, sc->pribus, 1);
 		}
-		sc->secbus = curr_bus_number++;
-		sc->subbus = curr_bus_number++;
+		sc->bus.sec = curr_bus_number++;
+		sc->bus.sub = curr_bus_number++;
 		DEVPRINTF((brdev, "Secondary bus set to %d subbus %d\n",
-		    sc->secbus, sc->subbus));
-		pci_write_config(brdev, PCIR_SECBUS_2, sc->secbus, 1);
-		pci_write_config(brdev, PCIR_SUBBUS_2, sc->subbus, 1);
+		    sc->bus.sec, sc->bus.sub));
+		pci_write_config(brdev, PCIR_SECBUS_2, sc->bus.sec, 1);
+		pci_write_config(brdev, PCIR_SUBBUS_2, sc->bus.sub, 1);
 	}
+#endif
 
 	/* attach children */
 	sc->cbdev = device_add_child(brdev, "cardbus", -1);
@@ -470,8 +477,8 @@
 
 	/* Restore bus configuration */
 	pci_write_config(sc->dev, PCIR_PRIBUS_2, sc->pribus, 1);
-	pci_write_config(sc->dev, PCIR_SECBUS_2, sc->secbus, 1);
-	pci_write_config(sc->dev, PCIR_SUBBUS_2, sc->subbus, 1);
+	pci_write_config(sc->dev, PCIR_SECBUS_2, sc->bus.sec, 1);
+	pci_write_config(sc->dev, PCIR_SUBBUS_2, sc->bus.sub, 1);
 
 	/* Enable memory access */
 	PCI_MASK_CONFIG(sc->dev, PCIR_COMMAND,
@@ -789,6 +796,23 @@
 	return retval;
 }
 
+#if defined(NEW_PCIB) && defined(PCI_RES_BUS)
+static int
+cbb_pci_adjust_resource(device_t bus, device_t child, int type,
+    struct resource *r, u_long start, u_long end)
+{
+	struct cbb_softc *sc;
+
+	sc = device_get_softc(bus);
+	if (type == PCI_RES_BUS) {
+		if (!rman_is_region_manager(r, &sc->bus.rman))
+			return (EINVAL);
+		return (rman_adjust_resource(r, start, end));
+	}
+	return (bus_generic_adjust_resource(bus, child, type, r, start, end));
+}
+#endif
+
 /************************************************************************/
 /* PCI compat methods							*/
 /************************************************************************/
@@ -833,6 +857,9 @@
 	DEVMETHOD(bus_read_ivar,		cbb_read_ivar),
 	DEVMETHOD(bus_write_ivar,		cbb_write_ivar),
 	DEVMETHOD(bus_alloc_resource,		cbb_alloc_resource),
+#if defined(NEW_PCIB) && defined(PCI_RES_BUS)
+	DEVMETHOD(bus_adjust_resource,		cbb_pci_adjust_resource),
+#endif
 	DEVMETHOD(bus_release_resource,		cbb_release_resource),
 	DEVMETHOD(bus_activate_resource,	cbb_activate_resource),
 	DEVMETHOD(bus_deactivate_resource,	cbb_deactivate_resource),

==== //depot/projects/pci/sys/dev/pccbb/pccbbvar.h#3 (text+ko) ====

@@ -64,8 +64,7 @@
 	bus_space_handle_t bsh;
 	uint32_t	domain;
 	unsigned int	pribus;
-	unsigned int	secbus;
-	unsigned int	subbus;
+	struct pcib_secbus bus;
 	struct mtx	mtx;
 	int		cardok;
 	u_int32_t	flags;

==== //depot/projects/pci/sys/dev/pci/pci_pci.c#38 (text+ko) ====

@@ -119,6 +119,10 @@
 {
 
 	switch (type) {
+#ifdef PCI_RES_BUS
+	case PCI_RES_BUS:
+		return (rman_is_region_manager(r, &sc->bus.rman));
+#endif
 	case SYS_RES_IOPORT:
 		return (rman_is_region_manager(r, &sc->io.rman));
 	case SYS_RES_MEMORY:
@@ -533,24 +537,22 @@
  * Allocate a suitable secondary bus for this bridge if needed and
  * initialize the resource manager for the secondary bus range.
  */
-static void
-pcib_setup_secbus(struct pcib_softc *sc)
+void
+pcib_setup_secbus(device_t dev, struct pcib_secbus *bus)
 {
-	struct pcib_secbus *sec;
 	char buf[64];
 	int error, rid;
 
-	sec = &sc->bus;
-	sec->rman.rm_start = 0;
-	sec->rman.rm_end = PCI_BUSMAX;
-	sec->rman.rm_type = RMAN_ARRAY;
-	snprintf(buf, sizeof(buf), "%s bus numbers",
-	    device_get_nameunit(sc->dev));
-	sec->rman.rm_descr = strdup(buf, M_DEVBUF);
-	error = rman_init(&sec->rman);
+	bus->dev = dev;
+	bus->rman.rm_start = 0;
+	bus->rman.rm_end = PCI_BUSMAX;
+	bus->rman.rm_type = RMAN_ARRAY;
+	snprintf(buf, sizeof(buf), "%s bus numbers", device_get_nameunit(dev));
+	bus->rman.rm_descr = strdup(buf, M_DEVBUF);
+	error = rman_init(&bus->rman);
 	if (error)
 		panic("Failed to initialize %s bus number rman",
-		    device_get_nameunit(sc->dev));
+		    device_get_nameunit(dev));
 
 #if 0
 	/*
@@ -558,34 +560,34 @@
 	 * This would at least preserve the existing secbus if it is
 	 * valid.
 	 */
-	if (sc->subbus < sc->secbus)
-		sc->subbus = sc->secbus;
+	if (bus->sub < bus->sec)
+		bus->sub = bus->sec;
 #endif
 
 	/*
 	 * Allocate a resource for the existing secondary bus number
 	 * range if it is valid.
 	 */
-	if (sc->secbus != 0 && sc->subbus >= sc->secbus) {
+	if (bus->sec != 0 && bus->sub >= bus->sec) {
 		rid = 0;
-		sec->res = bus_alloc_resource(sc->dev, PCI_RES_BUS, &rid,
-		    sc->secbus, sc->subbus, sc->subbus - sc->secbus + 1, 0);
-		if (sec->res == NULL) {
+		bus->res = bus_alloc_resource(dev, PCI_RES_BUS, &rid, bus->sec,
+		    bus->sub, bus->sub - bus->sec + 1, 0);
+		if (bus->res == NULL) {
 			if (bootverbose || 1)
-				device_printf(sc->dev,
+				device_printf(dev,
 				    "failed to allocate initial secbus range: %u-%u\n",
-				    sc->secbus, sc->subbus);
+				    bus->sec, bus->sub);
 #if 0
 			/* XXX: Should we clear these on failure? */
-			sc->secbus = 0;
-			sc->subbus = 0;
+			bus->sec = 0;
+			bus->sub = 0;
 #endif
 		}
 		/* XXX */
-		if (sec->res != NULL)
-			device_printf(sc->dev,
+		if (bus->res != NULL)
+			device_printf(dev,
 			    "allocated initial secbus range %lu-%lu\n",
-			    rman_get_start(sec->res), rman_get_end(sec->res));
+			    rman_get_start(bus->res), rman_get_end(bus->res));
 	}
 
 	/*
@@ -597,25 +599,25 @@
 	 * it seems sensible.  OTOH, the existing rmans in any parent
 	 * PCI-PCI bridges should already enforce this.
 	 */
-	if (sec->res == NULL) {
+	if (bus->res == NULL) {
 		/*
 		 * This doesn't use bus_alloc_resource_any() as the
 		 * count of 1 is explicit.
 		 */
 		rid = 0;
-		sec->res = bus_alloc_resource(sc->dev, PCI_RES_BUS, &rid, 0ul,
-		    ~0ul, 1, 0);
-		if (sec->res != NULL) {
-			KASSERT(rman_get_size(sec->res) == 1,
+		bus->res = bus_alloc_resource(dev, PCI_RES_BUS, &rid, 0ul, ~0ul,
+		    1, 0);
+		if (bus->res != NULL) {
+			KASSERT(rman_get_size(bus->res) == 1,
 			    ("more than one bus number"));
 			if (bootverbose || 1)
-				device_printf(sc->dev,
+				device_printf(bus->dev,
 				    "allocated initial secbus %lu\n",
-				    rman_get_start(sec->res));
-			sc->secbus = rman_get_start(sec->res);
-			sc->subbus = rman_get_end(sec->res);
+				    rman_get_start(bus->res));
+			bus->sec = rman_get_start(bus->res);
+			bus->sub = rman_get_end(bus->res);
 		} else
-			device_printf(sc->dev,
+			device_printf(bus->dev,
 			    "failed to allocate secondary bus number\n");
 	}
 
@@ -623,29 +625,28 @@
 	 * Add the initial resource to the rman and write updated
 	 * secbus and subbus registers.
 	 */
-	if (sec->res != NULL) {
-		error = rman_manage_region(&sec->rman, rman_get_start(sec->res),
-		    rman_get_end(sec->res));
+	if (bus->res != NULL) {
+		error = rman_manage_region(&bus->rman, rman_get_start(bus->res),
+		    rman_get_end(bus->res));
 		if (error)
 			panic("Failed to add resource to rman");
 	}
-	pci_write_config(sc->dev, PCIR_SECBUS_1, sc->secbus, 1);
-	pci_write_config(sc->dev, PCIR_SUBBUS_1, sc->subbus, 1);
+	pci_write_config(dev, bus->sec_reg, bus->sec, 1);
+	pci_write_config(dev, bus->sub_reg, bus->sub, 1);
 }
 
 static struct resource *
-pcib_suballoc_bus(struct pcib_softc *sc, device_t child, int *rid, u_long start,
-    u_long end, u_long count, u_int flags)
+pcib_suballoc_bus(struct pcib_secbus *bus, device_t child, int *rid,
+    u_long start, u_long end, u_long count, u_int flags)
 {
 	struct resource *res;
 
-	res = rman_reserve_resource(&sc->bus.rman, start, end, count,
-	    flags, child);
+	res = rman_reserve_resource(&bus->rman, start, end, count, flags, child);
 	if (res == NULL)
 		return (NULL);
 
 	if (bootverbose)
-		device_printf(sc->dev,
+		device_printf(bus->dev,
 		    "allocated bus range (%lu-%lu) for rid %d of %s\n",
 		    rman_get_start(res), rman_get_end(res), *rid,
 		    pcib_child_name(child));
@@ -659,72 +660,72 @@
  * subbus.
  */
 static int
-pcib_grow_subbus(struct pcib_softc *sc, u_long new_end)
+pcib_grow_subbus(struct pcib_secbus *bus, u_long new_end)
 {
+	u_long old_end;
 	int error;
 
-	KASSERT(new_end > rman_get_end(sc->bus.res),
-	    ("attempt to shrink subbus"));
-	error = bus_adjust_resource(sc->dev, PCI_RES_BUS, sc->bus.res,
-	    rman_get_start(sc->bus.res), new_end);
+	old_end = rman_get_end(bus->res);
+	KASSERT(new_end > old_end, ("attempt to shrink subbus"));
+	error = bus_adjust_resource(bus->dev, PCI_RES_BUS, bus->res,
+	    rman_get_start(bus->res), new_end);
 	if (error)
 		return (error);
 	if (bootverbose || 1)
-		device_printf(sc->dev, "grew bus range to %lu-%lu\n",
-		    rman_get_start(sc->bus.res), rman_get_end(sc->bus.res));
-	sc->subbus = rman_get_end(sc->bus.res);
-	pci_write_config(sc->dev, PCIR_SUBBUS_1, sc->subbus, 1);
+		device_printf(bus->dev, "grew bus range to %lu-%lu\n",
+		    rman_get_start(bus->res), rman_get_end(bus->res));
+	error = rman_manage_region(&bus->rman, old_end + 1,
+	    rman_get_end(bus->res));
+	if (error)
+		panic("Failed to add resource to rman");
+	bus->sub = rman_get_end(bus->res);
+	pci_write_config(bus->dev, bus->sub_reg, bus->sub, 1);
 	return (0);
 }
 
-static struct resource *
-pcib_alloc_subbus(struct pcib_softc *sc, device_t child, int *rid, u_long start,
-    u_long end, u_long count, u_int flags)
+struct resource *
+pcib_alloc_subbus(struct pcib_secbus *bus, device_t child, int *rid,
+    u_long start, u_long end, u_long count, u_int flags)
 {
 	struct resource *res;
-	u_long start_free, end_free;
+	u_long start_free, end_free, new_end;
 
 	/*
 	 * First, see if the request can be satisified by the existing
 	 * bus range.
 	 */
-	res = pcib_suballoc_bus(sc, child, rid, start, end, count, flags);
+	res = pcib_suballoc_bus(bus, child, rid, start, end, count, flags);
 	if (res != NULL)
 		return (res);
 
 	/*
-	 * If this request is for a specific range, first attempt to
-	 * grow the existing resource to accomodate this request.  If
-	 * that fails, retry the allocation using an arbitrary range.
+	 * Figure out a range to grow the bus range.  First, find the
+	 * first bus number after the last allocated bus in the rman and
+	 * enforce that as a minimum starting point for the range.
 	 */
-	if (start + count - 1 == end) {
-		if (end < sc->subbus && pcib_grow_subbus(sc, end) == 0) {
-			res = pcib_suballoc_bus(sc, child, rid, start, end,
-			    count, flags);
-			if (res != NULL)
-				return (res);
-		}
-
-		res = pcib_suballoc_bus(sc, child, rid, 0ul, ~0ul, count, flags);
-		if (res != NULL)
-			return (res);
-	}
+	if (rman_last_free_region(&bus->rman, &start_free, &end_free) != 0 ||
+	    end_free != bus->sub)
+		start_free = bus->sub + 1;
+	if (start_free < start)
+		start_free = start;
+	new_end = start_free + count - 1;
 
 	/*
-	 * Finally, attempt to grow the existing resource to accomodate
-	 * the request using an arbitrary range.
+	 * See if this new range would satisfy the request if it
+	 * succeeds.
 	 */
-	if (rman_last_free_region(&sc->bus.rman, &start_free, &end_free) != 0 ||
-	    end_free != sc->subbus)
-		start_free = sc->subbus + 1;
+	if (new_end > end)
+		return (NULL);
+
+	/* Finally, attempt to grow the existing resource. */
 	if (bootverbose || 1) {
-		device_printf(sc->dev,
+		device_printf(bus->dev,
 		    "attempting to grow bus range for %lu buses\n", count);
 		printf("\tback candidate range: %lu-%lu\n", start_free,
-		    start_free + count - 1);
+		    new_end);
 	}
-	if (pcib_grow_subbus(sc, start_free + count - 1) == 0)
-		return (pcib_suballoc_bus(sc, child, rid, 0ul, ~0ul, count,
+	if (pcib_grow_subbus(bus, new_end) == 0)
+		return (pcib_suballoc_bus(bus, child, rid, start, end, count,
 		    flags));
 	return (NULL);
 }
@@ -876,8 +877,8 @@
 
 	sc->command = pci_read_config(dev, PCIR_COMMAND, 2);
 	sc->pribus = pci_read_config(dev, PCIR_PRIBUS_1, 1);
-	sc->secbus = pci_read_config(dev, PCIR_SECBUS_1, 1);
-	sc->subbus = pci_read_config(dev, PCIR_SUBBUS_1, 1);
+	sc->bus.sec = pci_read_config(dev, PCIR_SECBUS_1, 1);
+	sc->bus.sub = pci_read_config(dev, PCIR_SUBBUS_1, 1);
 	sc->bridgectl = pci_read_config(dev, PCIR_BRIDGECTL_1, 2);
 	sc->seclat = pci_read_config(dev, PCIR_SECLAT_1, 1);
 #ifndef NEW_PCIB
@@ -900,8 +901,8 @@
 
 	pci_write_config(dev, PCIR_COMMAND, sc->command, 2);
 	pci_write_config(dev, PCIR_PRIBUS_1, sc->pribus, 1);
-	pci_write_config(dev, PCIR_SECBUS_1, sc->secbus, 1);
-	pci_write_config(dev, PCIR_SUBBUS_1, sc->subbus, 1);
+	pci_write_config(dev, PCIR_SECBUS_1, sc->bus.sec, 1);
+	pci_write_config(dev, PCIR_SUBBUS_1, sc->bus.sub, 1);
 	pci_write_config(dev, PCIR_BRIDGECTL_1, sc->bridgectl, 2);
 	pci_write_config(dev, PCIR_SECLAT_1, sc->seclat, 1);
 #ifdef NEW_PCIB
@@ -956,9 +957,9 @@
     SYSCTL_ADD_UINT(sctx, SYSCTL_CHILDREN(soid), OID_AUTO, "pribus",
       CTLFLAG_RD, &sc->pribus, 0, "Primary bus number");
     SYSCTL_ADD_UINT(sctx, SYSCTL_CHILDREN(soid), OID_AUTO, "secbus",
-      CTLFLAG_RD, &sc->secbus, 0, "Secondary bus number");
+      CTLFLAG_RD, &sc->bus.sec, 0, "Secondary bus number");
     SYSCTL_ADD_UINT(sctx, SYSCTL_CHILDREN(soid), OID_AUTO, "subbus",
-      CTLFLAG_RD, &sc->subbus, 0, "Subordinate bus number");
+      CTLFLAG_RD, &sc->bus.sub, 0, "Subordinate bus number");
 
     /*
      * Quirk handling.
@@ -970,8 +971,8 @@
 
 	    supbus = pci_read_config(dev, 0x41, 1);
 	    if (supbus != 0xff) {
-		sc->secbus = supbus + 1;
-		sc->subbus = supbus + 1;
+		sc->bus.sec = supbus + 1;
+		sc->bus.sub = supbus + 1;
 	    }
 	    break;
 	}
@@ -1007,9 +1008,9 @@
 		break;
 	    }
 	    freeenv(cp);
-	    if (sc->subbus < 0xa) {
+	    if (sc->bus.sub < 0xa) {
 		pci_write_config(dev, PCIR_SUBBUS_1, 0xa, 1);
-		sc->subbus = pci_read_config(dev, PCIR_SUBBUS_1, 1);
+		sc->bus.sub = pci_read_config(dev, PCIR_SUBBUS_1, 1);
 	    }
 	    break;
 	}
@@ -1032,14 +1033,16 @@
 
 #ifdef NEW_PCIB
 #ifdef PCI_RES_BUS
-    pcib_setup_secbus(sc);
+    sc->bus.sec_reg = PCIR_SECBUS_1;
+    sc->bus.sub_reg = PCIR_SUBBUS_1;
+    pcib_setup_secbus(dev, &sc->bus);
 #endif
     pcib_probe_windows(sc);
 #endif
     if (bootverbose) {
 	device_printf(dev, "  domain            %d\n", sc->domain);
-	device_printf(dev, "  secondary bus     %d\n", sc->secbus);
-	device_printf(dev, "  subordinate bus   %d\n", sc->subbus);
+	device_printf(dev, "  secondary bus     %d\n", sc->bus.sec);
+	device_printf(dev, "  subordinate bus   %d\n", sc->bus.sub);
 #ifdef NEW_PCIB
 	if (pcib_is_window_open(&sc->io))
 	    device_printf(dev, "  I/O decode        0x%jx-0x%jx\n",
@@ -1095,8 +1098,8 @@
 
     pcib_attach_common(dev);
     sc = device_get_softc(dev);
-    if (sc->secbus != 0) {
-	child = device_add_child(dev, "pci", sc->secbus);
+    if (sc->bus.sec != 0) {
+	child = device_add_child(dev, "pci", sc->bus.sec);
 	if (child != NULL)
 	    return(bus_generic_attach(dev));
     }
@@ -1146,7 +1149,7 @@
 	*result = sc->domain;
 	return(0);
     case PCIB_IVAR_BUS:
-	*result = sc->secbus;
+	*result = sc->bus.sec;
 	return(0);
     }
     return(ENOENT);
@@ -1155,14 +1158,12 @@
 int
 pcib_write_ivar(device_t dev, device_t child, int which, uintptr_t value)
 {
-    struct pcib_softc	*sc = device_get_softc(dev);
 
     switch (which) {
     case PCIB_IVAR_DOMAIN:
 	return(EINVAL);
     case PCIB_IVAR_BUS:
-	sc->secbus = value;
-	return(0);
+	return(EINVAL);
     }
     return(ENOENT);
 }
@@ -1574,8 +1575,8 @@
 	switch (type) {
 #ifdef PCI_RES_BUS
 	case PCI_RES_BUS:
-		return (pcib_alloc_subbus(sc, child, rid, start, end, count,
-		    flags));
+		return (pcib_alloc_subbus(&sc->bus, child, rid, start, end,
+		    count, flags));
 #endif
 	case SYS_RES_IOPORT:
 		if (pcib_is_isa_range(sc, start, end, count))

==== //depot/projects/pci/sys/dev/pci/pcib_private.h#25 (text+ko) ====

@@ -81,15 +81,20 @@
 	int		step;		/* log_2 of window granularity */
 	const char	*name;
 };
+#endif
 
-#ifdef PCI_RES_BUS
 struct pcib_secbus {
+	u_int		sec;
+	u_int		sub;
+#if defined(NEW_PCIB) && defined(PCI_RES_BUS)
+	device_t	dev;
 	struct rman	rman;
 	struct resource	*res;
 	const char	*name;
+	int		sec_reg;
+	int		sub_reg;
+#endif
 };
-#endif
-#endif
 
 /*
  * Bridge-specific data.
@@ -103,15 +108,11 @@
     uint16_t	command;	/* command register */
     u_int	domain;		/* domain number */
     u_int	pribus;		/* primary bus number */
-    u_int	secbus;		/* secondary bus number */
-    u_int	subbus;		/* subordinate bus number */
+    struct pcib_secbus bus;	/* secondary bus numbers */
 #ifdef NEW_PCIB
     struct pcib_window io;	/* I/O port window */
     struct pcib_window mem;	/* memory window */
     struct pcib_window pmem;	/* prefetchable memory window */
-#ifdef PCI_RES_BUS
-    struct pcib_secbus bus;	/* secondary bus numbers */
-#endif
 #else
     pci_addr_t	pmembase;	/* base address of prefetchable memory */
     pci_addr_t	pmemlimit;	/* topmost address of prefetchable memory */
@@ -136,6 +137,10 @@
 		    struct resource *r, u_long start, u_long end);
 int		pci_domain_release_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, u_long start, u_long end, u_long count,
+		    u_int flags);
+void		pcib_setup_secbus(device_t dev, struct pcib_secbus *bus);
 #endif
 int		pcib_attach(device_t dev);
 void		pcib_attach_common(device_t dev);

==== //depot/projects/pci/sys/sparc64/pci/apb.c#6 (text+ko) ====

@@ -177,9 +177,9 @@
 	    pci_read_config(dev, PCIR_COMMAND, 2);
 	sc->sc_bsc.ops_pcib_sc.pribus =
 	    pci_read_config(dev, PCIR_PRIBUS_1, 1);
-	sc->sc_bsc.ops_pcib_sc.secbus =
+	sc->sc_bsc.ops_pcib_sc.bus.sec =
 	    pci_read_config(dev, PCIR_SECBUS_1, 1);
-	sc->sc_bsc.ops_pcib_sc.subbus =
+	sc->sc_bsc.ops_pcib_sc.bus.sub =
 	    pci_read_config(dev, PCIR_SUBBUS_1, 1);
 	sc->sc_bsc.ops_pcib_sc.bridgectl =
 	    pci_read_config(dev, PCIR_BRIDGECTL_1, 2);
@@ -200,10 +200,10 @@
 	    CTLFLAG_RD, &sc->sc_bsc.ops_pcib_sc.pribus, 0,
 	    "Primary bus number");
 	SYSCTL_ADD_UINT(sctx, SYSCTL_CHILDREN(soid), OID_AUTO, "secbus",
-	    CTLFLAG_RD, &sc->sc_bsc.ops_pcib_sc.secbus, 0,
+	    CTLFLAG_RD, &sc->sc_bsc.ops_pcib_sc.bus.sec, 0,
 	    "Secondary bus number");
 	SYSCTL_ADD_UINT(sctx, SYSCTL_CHILDREN(soid), OID_AUTO, "subbus",
-	    CTLFLAG_RD, &sc->sc_bsc.ops_pcib_sc.subbus, 0,
+	    CTLFLAG_RD, &sc->sc_bsc.ops_pcib_sc.bus.sub, 0,
 	    "Subordinate bus number");
 
 	ofw_pcib_gen_setup(dev);
@@ -212,9 +212,9 @@
 		device_printf(dev, "  domain            %d\n",
 		    sc->sc_bsc.ops_pcib_sc.domain);
 		device_printf(dev, "  secondary bus     %d\n",
-		    sc->sc_bsc.ops_pcib_sc.secbus);
+		    sc->sc_bsc.ops_pcib_sc.bus.sec);
 		device_printf(dev, "  subordinate bus   %d\n",
-		    sc->sc_bsc.ops_pcib_sc.subbus);
+		    sc->sc_bsc.ops_pcib_sc.bus.sub);
 		device_printf(dev, "  I/O decode        ");
 		apb_map_print(sc->sc_iomap, APB_IO_SCALE);
 		printf("\n");


More information about the p4-projects mailing list