PERFORCE change 94650 for review

John-Mark Gurney jmg at FreeBSD.org
Wed Apr 5 00:13:23 UTC 2006


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

Change 94650 by jmg at jmg_carbon-60 on 2006/04/05 00:13:19

	first crack at getting pci resource allocation working..  no
	interrupts yet, and this is just to move code to a machine I can
	compile on...  buildable submit to come later..

Affected files ...

.. //depot/projects/kmacy_sun4v/src/sys/sun4v/include/bus.h#5 edit
.. //depot/projects/kmacy_sun4v/src/sys/sun4v/include/hv_pcivar.h#3 edit
.. //depot/projects/kmacy_sun4v/src/sys/sun4v/sun4v/bus_machdep.c#4 edit
.. //depot/projects/kmacy_sun4v/src/sys/sun4v/sun4v/hv_pci.c#19 edit

Differences ...

==== //depot/projects/kmacy_sun4v/src/sys/sun4v/include/bus.h#5 (text+ko) ====

@@ -216,36 +216,32 @@
 bus_space_read_1(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o)
 {
 
-	
 	__BUS_DEBUG_ACCESS(h, o, "read", 1);
-	return (0);
+	return (lduba_nc((caddr_t)(h + o), bus_type_asi[t->bst_type]));
 }
 
 static __inline uint16_t
 bus_space_read_2(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o)
 {
 
-	
 	__BUS_DEBUG_ACCESS(h, o, "read", 2);
-	return (0);
+	return (lduha_nc((caddr_t)(h + o), bus_type_asi[t->bst_type]));
 }
 
 static __inline uint32_t
 bus_space_read_4(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o)
 {
 
-	
 	__BUS_DEBUG_ACCESS(h, o, "read", 4);
-	return (0);
+	return (lduwa_nc((caddr_t)(h + o), bus_type_asi[t->bst_type]));
 }
 
 static __inline uint64_t
 bus_space_read_8(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o)
 {
 
-	
 	__BUS_DEBUG_ACCESS(h, o, "read", 8);
-	return (0);
+	return (ldxa_nc((caddr_t)(h + o), bus_type_asi[t->bst_type]));
 }
 
 static __inline void
@@ -289,8 +285,8 @@
     uint8_t v)
 {
 
-	
 	__BUS_DEBUG_ACCESS(h, o, "write", 1);
+	stba_nc((caddr_t)(h + o), bus_type_asi[t->bst_type], v);
 }
 
 static __inline void
@@ -298,8 +294,8 @@
     uint16_t v)
 {
 
-	
 	__BUS_DEBUG_ACCESS(h, o, "write", 2);
+	stha_nc((caddr_t)(h + o), bus_type_asi[t->bst_type], v);
 }
 
 static __inline void
@@ -307,8 +303,8 @@
     uint32_t v)
 {
 
-	
 	__BUS_DEBUG_ACCESS(h, o, "write", 4);
+	stwa_nc((caddr_t)(h + o), bus_type_asi[t->bst_type], v);
 }
 
 static __inline void
@@ -316,8 +312,8 @@
     uint64_t v)
 {
 
-	
 	__BUS_DEBUG_ACCESS(h, o, "write", 8);
+	stxa_nc((caddr_t)(h + o), bus_type_asi[t->bst_type], v);
 }
 
 static __inline void
@@ -524,7 +520,6 @@
 bus_space_read_stream_1(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o)
 {
 
-	
 	__BUS_DEBUG_ACCESS(h, o, "read stream", 1);
 	return (0);
 }
@@ -533,7 +528,6 @@
 bus_space_read_stream_2(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o)
 {
 
-	
 	__BUS_DEBUG_ACCESS(h, o, "read stream", 2);
 	return (0);
 }
@@ -542,7 +536,6 @@
 bus_space_read_stream_4(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o)
 {
 
-	
 	__BUS_DEBUG_ACCESS(h, o, "read stream", 4);
 	return (0);
 }
@@ -551,7 +544,6 @@
 bus_space_read_stream_8(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o)
 {
 
-	
 	__BUS_DEBUG_ACCESS(h, o, "read stream", 8);
 	return (0);
 }
@@ -597,7 +589,6 @@
     uint8_t v)
 {
 
-	
 	__BUS_DEBUG_ACCESS(h, o, "write stream", 1);
 	stba_nc((caddr_t)(h + o), bus_stream_asi[t->bst_type], v);
 }
@@ -607,7 +598,6 @@
     uint16_t v)
 {
 
-	
 	__BUS_DEBUG_ACCESS(h, o, "write stream", 2);
 }
 
@@ -616,7 +606,6 @@
     uint32_t v)
 {
 
-	
 	__BUS_DEBUG_ACCESS(h, o, "write stream", 4);
 }
 
@@ -625,7 +614,6 @@
     uint64_t v)
 {
 
-	
 	__BUS_DEBUG_ACCESS(h, o, "write stream", 8);
 }
 
@@ -705,6 +693,7 @@
 bus_space_read_region_stream_1(bus_space_tag_t t, bus_space_handle_t h,
     bus_size_t o, u_int8_t *a, bus_size_t c)
 {
+
 	for (; c; a++, c--, o++)
 		*a = bus_space_read_stream_1(t, h, o);
 }
@@ -713,6 +702,7 @@
 bus_space_read_region_stream_2(bus_space_tag_t t, bus_space_handle_t h,
     bus_size_t o, u_int16_t *a, bus_size_t c)
 {
+
 	for (; c; a++, c--, o+=2)
 		*a = bus_space_read_stream_2(t, h, o);
 }
@@ -721,6 +711,7 @@
 bus_space_read_region_stream_4(bus_space_tag_t t, bus_space_handle_t h,
     bus_size_t o, u_int32_t *a, bus_size_t c)
 {
+
 	for (; c; a++, c--, o+=4)
 		*a = bus_space_read_stream_4(t, h, o);
 }
@@ -729,6 +720,7 @@
 bus_space_read_region_stream_8(bus_space_tag_t t, bus_space_handle_t h,
     bus_size_t o, u_int64_t *a, bus_size_t c)
 {
+
 	for (; c; a++, c--, o+=8)
 		*a = bus_space_read_stream_8(t, h, o);
 }
@@ -737,6 +729,7 @@
 bus_space_write_region_stream_1(bus_space_tag_t t, bus_space_handle_t h,
     bus_size_t o, const u_int8_t *a, bus_size_t c)
 {
+
 	for (; c; a++, c--, o++)
 		bus_space_write_stream_1(t, h, o, *a);
 }
@@ -745,6 +738,7 @@
 bus_space_write_region_stream_2(bus_space_tag_t t, bus_space_handle_t h,
     bus_size_t o, const u_int16_t *a, bus_size_t c)
 {
+
 	for (; c; a++, c--, o+=2)
 		bus_space_write_stream_2(t, h, o, *a);
 }
@@ -753,6 +747,7 @@
 bus_space_write_region_stream_4(bus_space_tag_t t, bus_space_handle_t h,
     bus_size_t o, const u_int32_t *a, bus_size_t c)
 {
+
 	for (; c; a++, c--, o+=4)
 		bus_space_write_stream_4(t, h, o, *a);
 }
@@ -761,6 +756,7 @@
 bus_space_write_region_stream_8(bus_space_tag_t t, bus_space_handle_t h,
     bus_size_t o, const u_int64_t *a, bus_size_t c)
 {
+
 	for (; c; a++, c--, o+=8)
 		bus_space_write_stream_8(t, h, o, *a);
 }
@@ -769,6 +765,7 @@
 bus_space_set_region_stream_1(bus_space_tag_t t, bus_space_handle_t h,
     bus_size_t o, const u_int8_t v, bus_size_t c)
 {
+
 	for (; c; c--, o++)
 		bus_space_write_stream_1(t, h, o, v);
 }
@@ -777,6 +774,7 @@
 bus_space_set_region_stream_2(bus_space_tag_t t, bus_space_handle_t h,
     bus_size_t o, const u_int16_t v, bus_size_t c)
 {
+
 	for (; c; c--, o+=2)
 		bus_space_write_stream_2(t, h, o, v);
 }
@@ -785,6 +783,7 @@
 bus_space_set_region_stream_4(bus_space_tag_t t, bus_space_handle_t h,
     bus_size_t o, const u_int32_t v, bus_size_t c)
 {
+
 	for (; c; c--, o+=4)
 		bus_space_write_stream_4(t, h, o, v);
 }
@@ -793,6 +792,7 @@
 bus_space_set_region_stream_8(bus_space_tag_t t, bus_space_handle_t h,
     bus_size_t o, const u_int64_t v, bus_size_t c)
 {
+
 	for (; c; c--, o+=8)
 		bus_space_write_stream_8(t, h, o, v);
 }
@@ -801,6 +801,7 @@
 bus_space_copy_region_stream_1(bus_space_tag_t t, bus_space_handle_t h1,
     bus_size_t o1, bus_space_handle_t h2, bus_size_t o2, bus_size_t c)
 {
+
 	for (; c; c--, o1++, o2++)
 	    bus_space_write_stream_1(t, h1, o1, bus_space_read_stream_1(t, h2,
 		o2));
@@ -810,6 +811,7 @@
 bus_space_copy_region_stream_2(bus_space_tag_t t, bus_space_handle_t h1,
     bus_size_t o1, bus_space_handle_t h2, bus_size_t o2, bus_size_t c)
 {
+
 	for (; c; c--, o1+=2, o2+=2)
 	    bus_space_write_stream_2(t, h1, o1, bus_space_read_stream_2(t, h2,
 		o2));
@@ -819,6 +821,7 @@
 bus_space_copy_region_stream_4(bus_space_tag_t t, bus_space_handle_t h1,
     bus_size_t o1, bus_space_handle_t h2, bus_size_t o2, bus_size_t c)
 {
+
 	for (; c; c--, o1+=4, o2+=4)
 	    bus_space_write_stream_4(t, h1, o1, bus_space_read_stream_4(t, h2,
 		o2));
@@ -828,59 +831,18 @@
 bus_space_copy_region_stream_8(bus_space_tag_t t, bus_space_handle_t h1,
     bus_size_t o1, bus_space_handle_t h2, bus_size_t o2, bus_size_t c)
 {
+
 	for (; c; c--, o1+=8, o2+=8)
 	    bus_space_write_stream_8(t, h1, o1, bus_space_read_8(t, h2, o2));
 }
 
-static __inline int
-bus_space_peek_1(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o,
-	u_int8_t *a)
-{
-	
-	int error;
-	uint32_t error_flag;
-
-	__BUS_DEBUG_ACCESS(h, o, "peek", 1);
-	error = hvio_peek(h, o, 1, &error_flag, (uint64_t *)a);
-	/* XXX map HV errors to BSD errors */
-	return (error);
-}
-
-static __inline int
-bus_space_peek_2(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o,
-	u_int16_t *a)
-{
-
-	int error;
-	uint32_t error_flag;
-
-	__BUS_DEBUG_ACCESS(h, o, "peek", 2);
-	error = hvio_peek(h, o, 2, &error_flag, (uint64_t *)a);
-	return (error);
-}
-
-static __inline int
-bus_space_peek_4(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o,
-	u_int32_t *a)
-{
-
-	int error;
-	uint32_t error_flag;
-
-	__BUS_DEBUG_ACCESS(h, o, "peek", 4);
-	error = hvio_peek(h, o, 4, &error_flag, (uint64_t *)a);
-	return (error);
-	
-	return (0);
-}
-
 /* Back-compat functions for old ISA drivers */
 extern bus_space_tag_t isa_io_bt;
 extern bus_space_handle_t isa_io_hdl;
 extern bus_space_tag_t isa_mem_bt;
 extern bus_space_handle_t isa_mem_hdl;
 
- #define inb(o)		bus_space_read_1(isa_io_bt, isa_io_hdl, o)
+#define inb(o)		bus_space_read_1(isa_io_bt, isa_io_hdl, o)
 #define inw(o)		bus_space_read_2(isa_io_bt, isa_io_hdl, o)
 #define inl(o)		bus_space_read_4(isa_io_bt, isa_io_hdl, o)
 #define outb(o, v)	bus_space_write_1(isa_io_bt, isa_io_hdl, o, v)

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

@@ -33,6 +33,14 @@
 struct hvpci_softc {
 	devhandle_t	hs_devhandle;
 	uint8_t		hs_busnum;
+
+	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;
+	bus_space_handle_t	hs_pci_ioh;
 };
 
 #endif /* _HV_PCIVAR_H_ */

==== //depot/projects/kmacy_sun4v/src/sys/sun4v/sun4v/bus_machdep.c#4 (text+ko) ====

@@ -129,6 +129,16 @@
 static void nexus_bus_barrier(bus_space_tag_t, bus_space_handle_t,
     bus_size_t, bus_size_t, int);
 
+/* ASI's for bus access. */
+int bus_type_asi[] = {
+	ASI_REAL_IO,		/* UPA */
+	ASI_REAL_IO,		/* SBUS */
+	ASI_REAL_IO_L,		/* PCI configuration space */
+	ASI_REAL_IO_L,		/* PCI memory space */
+	ASI_REAL_IO_L,		/* PCI I/O space */
+	0
+};
+
 /*
  * Convenience function for manipulating driver locks from busdma (during
  * busdma_swi, for example).  Drivers that don't provide their own locks

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

@@ -43,6 +43,7 @@
 
 #include <machine/bus.h>
 
+#include <sparc64/pci/ofw_pci.h>
 #include <machine/hypervisor_api.h>
 
 #include <dev/ofw/ofw_bus.h>
@@ -56,6 +57,11 @@
 #include <sys/rman.h>
 #define	SUN4V_REG_SPEC2CFG_HDL(x)	((x >> 32) & ~(0xfull << 28))
 /*
+ * XXX - should get this through the bus, but Sun overloaded the reg OFW
+ * property, so there isn't normal resources associated w/ this device.
+ */
+extern struct bus_space_tag nexus_bustag;
+/*
  * Methods
  */
 static device_probe_t hvpci_probe;
@@ -129,34 +135,35 @@
 static int
 hvpci_attach(device_t dev)
 {
+	struct ofw_pci_ranges *range;
+	struct rman *rmanp;
 	struct hvpci_softc *sc;
+	bus_space_tag_t *btp;
 	phandle_t node;
 #if 0
 	uint32_t cell;
 #endif
 	uint64_t reg, nreg;
 	int br[2];
-	int n;
+	int n, type;
+	int i, nrange, rid;
 
-	printf("hvpci_attach: dev_name=%s dev_type=%s\n", 
-	       ofw_bus_get_name(dev), ofw_bus_get_type(dev));
+	sc = device_get_softc(dev);
 
 	node = ofw_bus_get_node(dev);
-	printf("hvpci_attach: %p, node: %#x\n", dev, node);
 	if (node == -1)
 		panic("%s: ofw_bus_get_node failed.", __func__);
 
-	sc = device_get_softc(dev);
-	n = OF_getprop(node, "bus-range", &br[0], 8);
-	
+	/* Setup the root bus number for this bus */
+	n = OF_getprop(node, "bus-range", &br[0], sizeof br);
 	if (n == -1)
 		panic("%s: could not get bus-range", __func__);
-	if (n != sizeof(br))
+	if (n != sizeof br)
 		panic("%s: broken bus-range (%d)", __func__, n);
-
 	sc->hs_busnum = br[0];
 
-#if 0
+	/* Setup the HyperVisor devhandle for this bus */
+#if 1
 	if (OF_getprop(node, "reg", &cell, sizeof cell) == -1)
 		panic("%s: OF_getprop failed.", __func__);
 	sc->hs_devhandle = cell & 0xfffffff;
@@ -165,8 +172,51 @@
 	sc->hs_devhandle = SUN4V_REG_SPEC2CFG_HDL(reg);
 #endif
 
-	printf("%s, devhandle=0x%lx, busnum: %hhu\n", __func__,
-	    sc->hs_devhandle, sc->hs_busnum);
+	/* Pull in the ra addresses out of OFW */
+	nrange = OF_getprop_alloc(node, "ranges", sizeof *range,
+	    (void **)&range);
+
+	/* Initialize memory and I/O rmans. */
+	for (i = 0; i < nrange; i++) {
+/* XXX - from sun4v/io/px/px_lib4v.c: px_ranges_phi_mask */
+#define PHYS_MASK	((1ll << (28 + 32)) - 1)
+		switch (OFW_PCI_RANGE_CS(&range[i])) {
+		case OFW_PCI_CS_IO:
+			rmanp = &sc->hs_pci_io_rman;
+			rmanp->rm_descr = "HyperVisor PCI I/O Ports";
+			btp = &sc->hs_pci_iot;
+			sc->hs_pci_ioh = OFW_PCI_RANGE_PHYS(&range[i]) &
+			    PHYS_MASK;
+			type = PCI_IO_BUS_SPACE;
+			break;
+
+		case OFW_PCI_CS_MEM32:
+			continue;
+
+		case OFW_PCI_CS_MEM64:
+			rmanp = &sc->hs_pci_mem_rman;
+			rmanp->rm_descr = "HyperVisor PCI Memory";
+			btp = &sc->hs_pci_memt;
+			sc->hs_pci_memh = OFW_PCI_RANGE_PHYS(&range[i]) &
+			    PHYS_MASK;
+			type = PCI_MEMORY_BUS_SPACE;
+			break;
+
+		default:
+			panic("%s: unknown range type: %d", __func__,
+			    OFW_PCI_RANGE_CS(&range[i]));
+		}
+		rmanp->rm_type = RMAN_ARRAY;
+		if (rman_init(rmanp) != 0 || rman_manage_region(rmanp, 0,
+		    OFW_PCI_RANGE_SIZE(&range[i])) != 0)
+			panic("%s: failed to set up rman type: %d", __func__,
+			    OFW_PCI_RANGE_CS(&range[i]));
+
+		*btp = (bus_space_tag_t)malloc(sizeof **btp, M_DEVBUF,
+		    M_WAITOK|M_ZERO);
+		btp->bst_parent = &nexus_bustag;
+		btp->bst_type = type;
+	}
 
 	device_add_child(dev, "pci", -1);
 
@@ -326,16 +376,70 @@
 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)
 {
+	struct hvpci_softc *sc;
+	struct resource *rv;
+	struct rman *rm;
+	bus_space_tag_t bt;
+	bus_space_handle_t bh;
+	int needactivate;
+
+	sc = device_get_softc(dev);
+
+	needactivate = flags & RF_ACTIVE;
+	flags &= ~RF_ACTIVE;
+
+	switch (type) {
+	case SYS_RES_MEMORY:
+		rm = &sc->sc_pci_mem_rman;
+		bt = sc->sc_pci_memt;
+		bh = sc->sc_pci_memh;
+		break;
+	case SYS_RES_IOPORT:
+		rm = &sc->sc_pci_io_rman;
+		bt = sc->sc_pci_iot;
+		bh = sc->sc_pci_ioh;
+		break;
+	default:
+		return (NULL);
+	}
+
+	rv = rman_reserve_resource(rm, start, end, count, flags, child);
+	if (rv == NULL)
+		return (NULL);
+
+	bh += rman_get_start(rv);
+	rman_set_bustag(rv, bt);
+	rman_set_bushandle(rv, bh);
 
-	return (NULL);
+	if (needactivate) {
+		if (bus_activate_resource(child, type, *rid, rv)) {
+			rman_release_resource(rv);
+			return (NULL);
+		}
+	}
+
+	return (rv);
 }
 
 static int
 hvpci_activate_resource(device_t bus, device_t child, int type, int rid,
     struct resource *r) 
 {
+	void *p;
+	int error;
 
-	return (0);
+	if (type == SYS_RES_MEMORY) {
+		/*
+		 * Need to memory-map the device space, as some drivers depend
+		 * on the virtual address being set and useable.
+		 */
+		error = sparc64_bus_mem_map(rman_get_bustag(r),
+		    rman_get_bushandle(r), rman_get_size(r), 0, 0, &p);
+		if (error != 0)
+			return (error);
+		rman_set_virtual(r, p);
+	}
+	return (rman_activate_resource(r));
 }
 
 static int


More information about the p4-projects mailing list