PERFORCE change 105612 for review

John-Mark Gurney jmg at FreeBSD.org
Sun Sep 3 20:15:57 UTC 2006


http://perforce.freebsd.org/chv.cgi?CH=105612

Change 105612 by jmg at jmg_csjp on 2006/09/03 20:15:13

	route interrupts using the interrupt-map in hv_pci.c...  just
	pass through the setup_intr and teardown_intr...
	
	get the immediate subordinate device for setuping up the interrupt
	in nexus now that hv_pci passes the calls through...
	
	This gets mpt working on the T1k:
	mpt0: MPI Version=1.5.10.0
	mpt0: mpt_cam_event: MPI_EVENT_SAS_DEVICE_STATUS_CHANGE
	da0 at mpt0 bus 0 target 0 lun 0
	da0: <ATA HITACHI HDS7280S A6CA> Fixed Direct Access SCSI-5 device 
	da0: 300.000MB/s transfers, Tagged Queueing Enabled
	da0: 76319MB (156301488 512 byte sectors: 255H 63S/T 9729C)
	
	Though apprently doesn't fix ata on the T2k...

Affected files ...

.. //depot/projects/kmacy_sun4v_stable/src/sys/sun4v/include/hv_pcivar.h#2 edit
.. //depot/projects/kmacy_sun4v_stable/src/sys/sun4v/sun4v/hv_pci.c#2 edit
.. //depot/projects/kmacy_sun4v_stable/src/sys/sun4v/sun4v/nexus.c#3 edit

Differences ...

==== //depot/projects/kmacy_sun4v_stable/src/sys/sun4v/include/hv_pcivar.h#2 (text+ko) ====

@@ -31,23 +31,20 @@
 #define _HV_PCIVAR_H_
 
 struct hvpci_softc {
-	devhandle_t	hs_devhandle;
-	phandle_t	hs_node;
-	uint8_t		hs_busnum;
+	devhandle_t		hs_devhandle;
+	phandle_t		hs_node;
+	uint8_t			hs_busnum;
+
+	struct ofw_bus_iinfo	hs_pci_iinfo;
 
 	struct bus_dma_tag	hs_dmatag;
 
-	struct resource	*hs_intr[4];
-	int		hs_intrrefcnt[4];
-
-	struct rman	hs_pci_intr_rman;
-
-	struct rman	hs_pci_mem_rman;
-	bus_space_tag_t	hs_pci_memt;
+	struct rman		hs_pci_mem_rman;
+	bus_space_tag_t		hs_pci_memt;
 	bus_space_handle_t	hs_pci_memh;
 
-	struct rman	hs_pci_io_rman;
-	bus_space_tag_t	hs_pci_iot;
+	struct rman		hs_pci_io_rman;
+	bus_space_tag_t		hs_pci_iot;
 	bus_space_handle_t	hs_pci_ioh;
 };
 

==== //depot/projects/kmacy_sun4v_stable/src/sys/sun4v/sun4v/hv_pci.c#2 (text+ko) ====

@@ -48,6 +48,7 @@
 
 #include <dev/ofw/ofw_bus.h>
 #include <dev/ofw/ofw_bus_subr.h>
+#include <dev/ofw/ofw_pci.h>
 #include <dev/ofw/openfirm.h>
 #include <sparc64/pci/ofw_pci.h>
 
@@ -71,8 +72,6 @@
 static device_attach_t hvpci_attach;
 static bus_read_ivar_t hvpci_read_ivar;
 static bus_write_ivar_t hvpci_write_ivar;
-static bus_setup_intr_t hvpci_setup_intr;
-static bus_teardown_intr_t hvpci_teardown_intr;
 static bus_alloc_resource_t hvpci_alloc_resource;
 static bus_activate_resource_t hvpci_activate_resource;
 static bus_deactivate_resource_t hvpci_deactivate_resource;
@@ -98,8 +97,8 @@
 	DEVMETHOD(bus_print_child,	bus_generic_print_child),
 	DEVMETHOD(bus_read_ivar,	hvpci_read_ivar),
 	DEVMETHOD(bus_write_ivar,	hvpci_write_ivar),
-	DEVMETHOD(bus_setup_intr,	hvpci_setup_intr),
-	DEVMETHOD(bus_teardown_intr,	hvpci_teardown_intr),
+	DEVMETHOD(bus_setup_intr,	bus_generic_setup_intr),
+	DEVMETHOD(bus_teardown_intr,	bus_generic_teardown_intr),
 	DEVMETHOD(bus_alloc_resource,	hvpci_alloc_resource),
 	DEVMETHOD(bus_activate_resource,	hvpci_activate_resource),
 	DEVMETHOD(bus_deactivate_resource,	hvpci_deactivate_resource),
@@ -176,14 +175,6 @@
 	/* Setup the HyperVisor devhandle for this bus */
 	sc->hs_devhandle = nexus_get_devhandle(dev);
 
-	/* initalize intr resources */
-	sc->hs_pci_intr_rman.rm_type = RMAN_ARRAY;
-	sc->hs_pci_intr_rman.rm_descr = "HyperVisor PCI Interrupts";
-	if (rman_init(&sc->hs_pci_intr_rman) != 0 ||
-	    /* We use 1 (INTA) through 4 (INTD) */
-	    rman_manage_region(&sc->hs_pci_intr_rman, 1, 4) != 0)
-		panic("%s: failed to set up intr rman", __func__);
-	
 	/* Pull in the ra addresses out of OFW */
 	nrange = OF_getprop_alloc(node, "ranges", sizeof *range,
 	    (void **)&range);
@@ -248,6 +239,9 @@
 
 	free(dvma, M_OFWPROP);
 
+	/* Setup ofw imap */
+	ofw_bus_setup_iinfo(node, &sc->hs_pci_iinfo, sizeof(ofw_pci_intr_t));
+
 	device_add_child(dev, "pci", -1);
 
 	return (bus_generic_attach(dev));
@@ -341,8 +335,24 @@
 static int
 hvpci_route_interrupt(device_t bridge, device_t dev, int pin)
 {
+	struct hvpci_softc *sc;
+	struct ofw_pci_register reg;
+	phandle_t node;
+	ofw_pci_intr_t pintr, mintr;
+	int obli;
+	uint8_t maskbuf[sizeof(reg) + sizeof(pintr)];
 
-	return (pin);
+	sc = device_get_softc(bridge);
+	node = ofw_bus_get_node(dev);
+	pintr = pin;
+	obli = ofw_bus_lookup_imap(node, &sc->hs_pci_iinfo, &reg, sizeof(reg),
+	    &pintr, sizeof(pintr), &mintr, sizeof(mintr), maskbuf);
+	device_printf(dev, "called hvpci_route_intr: %d, got: mintr: %#x\n",
+	    obli, mintr);
+	if (obli)
+		return (mintr);
+
+	panic("pin %d not found in imap of %s", pin, device_get_nameunit(bridge));
 }
 
 static phandle_t
@@ -419,74 +429,6 @@
 	return (ENOENT);
 }
 
-static int
-hvpci_setup_intr(device_t dev, device_t child, struct resource *ires,
-    int flags, driver_intr_t *intr, void *arg, void **cookiep)
-{
-	struct hvpci_softc *sc;
-	int pciintr, rid;
-	int error;
-
-
-	sc = device_get_softc(dev);
-
-	rid = rman_get_start(ires);
-	KASSERT(rid >= 1 && rid <= 4, ("interrupt out of range"));
-
-	pciintr = rid - 1;
-	if (sc->hs_intr[pciintr] == NULL) {
-		if ((sc->hs_intr[pciintr] = bus_alloc_resource_any(dev,
-			  SYS_RES_IRQ, &rid, RF_SHAREABLE | RF_ACTIVE)) == NULL) {
-			device_printf(dev, "couldn't alloc interrupt\n");
-				return (ENXIO);
-		}
-		sc->hs_intrrefcnt[pciintr] = 1;
-	} else
-		sc->hs_intrrefcnt[pciintr]++;
-	
-	error = bus_setup_intr(dev, sc->hs_intr[pciintr], flags, intr, arg,
-			       cookiep);
-	if (error) {
-		sc->hs_intrrefcnt[pciintr]--;
-		if (sc->hs_intrrefcnt[pciintr] == 0) {
-			bus_release_resource(dev, SYS_RES_IRQ,
-					     rman_get_rid(sc->hs_intr[pciintr]),
-					     sc->hs_intr[pciintr]);
-			sc->hs_intr[pciintr] = NULL;
-		}
-		device_printf(dev, "bus_setup_intr: %d\n", error);
-			return (error);
-	}
-	return (0);
-}
-
-static int
-hvpci_teardown_intr(device_t dev, device_t child, struct resource *vec,
-     void *cookie)
-{
-	struct hvpci_softc *sc;
-	int pciintr;
-	int error;
-
-	sc = device_get_softc(dev);
-	pciintr = rman_get_start(vec);
-	KASSERT(pciintr >= 1 && pciintr <= 4, ("interrupt out of range"));
-	pciintr--;
-
-	error = bus_teardown_intr(dev, sc->hs_intr[pciintr], cookie);
-	if (error)
-		return (error);
-
-	sc->hs_intrrefcnt[pciintr]--;
-	if (sc->hs_intrrefcnt[pciintr] == 0) {
-		bus_release_resource(dev, SYS_RES_IRQ,
-		    rman_get_rid(sc->hs_intr[pciintr]), sc->hs_intr[pciintr]);
-		sc->hs_intr[pciintr] = NULL;
-	}
-
-	return (0);
-}
-
 static struct resource *
 hvpci_alloc_resource(device_t bus, device_t child, int type, int *rid,
     u_long start, u_long end, u_long count, u_int flags)
@@ -505,11 +447,8 @@
 
 	switch (type) {
 	case SYS_RES_IRQ:
-		if (end - start != 0)
-			return NULL;
-		rm = &sc->hs_pci_intr_rman;
-		bt = NULL;
-		bh = 0;
+		return BUS_ALLOC_RESOURCE(device_get_parent(bus), child, type,
+		    rid, start, end, count, flags);
 		break;
 
 	case SYS_RES_MEMORY:
@@ -532,12 +471,6 @@
 	}
 
 	rv = rman_reserve_resource(rm, start, end, count, flags, child);
-#ifdef DEBUG
-	if (type == SYS_RES_IRQ) {
-		printf("%s: reserve_resource: start: %ld, end: %ld, flags: %#x, rv: %p\n",
-		    __func__, start, end, flags, rv);
-	}
-#endif
 	if (rv == NULL)
 		return (NULL);
 

==== //depot/projects/kmacy_sun4v_stable/src/sys/sun4v/sun4v/nexus.c#3 (text+ko) ====

@@ -306,11 +306,17 @@
     driver_intr_t *intr, void *arg, void **cookiep)
 {
 	struct nexus_devinfo *ndi;
+	device_t ichild;
 	uint64_t ihdl;
 	uint64_t ino;
 	int error, cpuid;
 
-	ndi = device_get_ivars(child);
+	/* we need the devinfo from the immediate child */
+	ichild = child;
+	while (device_get_parent(ichild) != dev)
+		ichild = device_get_parent(ichild);
+
+	ndi = device_get_ivars(ichild);
 
 	if (res == NULL)
 		panic("%s: NULL interrupt resource!", __func__);


More information about the p4-projects mailing list