PERFORCE change 119601 for review

Bruce M Simpson bms at FreeBSD.org
Wed May 9 21:46:08 UTC 2007


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

Change 119601 by bms at bms_anglepoise on 2007/05/09 21:45:26

	do NEWBUS-ly correct probe and attach; resources allocated by
	siba are now managed and allocations handed out to children;
	bus handle and tag setup is proxied to parent nexus as all this
	stuff lives in KSEG1.

Affected files ...

.. //depot/projects/mips2/src/sys/mips/mips/nexus.c#11 edit
.. //depot/projects/mips2/src/sys/mips/mips32/sentry5/siba.c#5 edit
.. //depot/projects/mips2/src/sys/mips/mips32/sentry5/siba_cc.c#3 edit
.. //depot/projects/mips2/src/sys/mips/mips32/sentry5/siba_mips.c#2 edit
.. //depot/projects/mips2/src/sys/mips/mips32/sentry5/siba_pcib.c#2 edit
.. //depot/projects/mips2/src/sys/mips/mips32/sentry5/siba_sdram.c#2 edit

Differences ...

==== //depot/projects/mips2/src/sys/mips/mips/nexus.c#11 (text+ko) ====

@@ -155,7 +155,7 @@
 	irq_rman.rm_descr = "Hardware IRQs";
 	if (rman_init(&irq_rman) != 0 ||
 	    rman_manage_region(&irq_rman, 0, NUM_MIPS_IRQS - 1) != 0) {
-		panic("nexus_probe irq_rman");
+		panic("%s: irq_rman", __func__);
 	}
 
 	mem_rman.rm_start = 0;
@@ -163,8 +163,9 @@
 	mem_rman.rm_type = RMAN_ARRAY;
 	mem_rman.rm_descr = "Memory addresses";
 	if (rman_init(&mem_rman) != 0 ||
-	    rman_manage_region(&mem_rman, 0, ~0) != 0)
-	    panic("nexus_probe mem_rman");
+	    rman_manage_region(&mem_rman, 0, ~0) != 0) {
+		panic("%s: mem_rman", __func__);
+	}
 
 	return (0);
 }

==== //depot/projects/mips2/src/sys/mips/mips32/sentry5/siba.c#5 (text+ko) ====

@@ -42,12 +42,10 @@
 #include <mips/mips32/sentry5/siba_ids.h>
 
 /*
- * TODO: cpu clock calculation.
+ * TODO: cpu clock calculation. -> move to siba_cc instance
  * TODO: De-mipsify this code.
  * TODO: Move siba to a machine independent location.
- * TODO: Attempt to attach the children.
- * TODO: resource manager for children (proxy it to nexus)
- * TODO: Put the information into ivars like PCI does.
+ * TODO: Hardwire IRQs for attached cores on siba at probe time.
  * TODO: Support detach.
  * TODO: Power management.
  * TODO: code cleanup.
@@ -58,6 +56,10 @@
 #define MIPS_MEM_RID 0x20
 #endif
 
+extern int rman_debug;
+
+static struct rman mem_rman; 	/* XXX move to softc */
+
 static int siba_debug = 1;
 static const char descfmt[] = "Sonics SiliconBackplane rev %s";
 #define SIBA_DEVDESCLEN sizeof(descfmt) + 8
@@ -97,6 +99,8 @@
 static void	siba_destroy_devinfo(struct siba_devinfo *);
 static struct siba_devid *
 		siba_dev_match(uint16_t, uint16_t, uint8_t);
+static struct resource_list *
+		siba_get_reslist(device_t, device_t);
 static uint8_t	siba_getncores(uint16_t);
 static int	siba_print_all_resources(device_t dev);
 static int	siba_print_child(device_t, device_t);
@@ -141,6 +145,8 @@
 
 	sc->sc_dev = dev;
 
+	//rman_debug = 1;	/* XXX */
+
 	/*
 	 * Map the ChipCommon register set using the hints the kernel
 	 * was compiled with.
@@ -255,21 +261,40 @@
 	}
 	bus_set_resource(dev, SYS_RES_MEMORY, rid, sc->sc_maddr, sc->sc_msize);
 
+	/*
+	 * We need a manager for the space we claim on nexus to
+	 * satisfy requests from children.
+	 * We need to keep the source reservation we took because
+	 * otherwise it may be claimed elsewhere.
+	 * XXX move to softc
+	 */
+	mem_rman.rm_start = sc->sc_maddr;
+	mem_rman.rm_end = sc->sc_maddr + sc->sc_msize - 1;
+	mem_rman.rm_type = RMAN_ARRAY;
+	mem_rman.rm_descr = "Memory addresses";
+	if (rman_init(&mem_rman) != 0 ||
+	    rman_manage_region(&mem_rman, mem_rman.rm_start, mem_rman.rm_end) != 0) {
+		panic("%s: mem_rman", __func__);
+	}
+
 	return (0);
 }
 
 static int
 siba_attach(device_t dev)
 {
-	struct siba_softc *sc = device_get_softc(dev);
+	struct siba_softc	*sc = device_get_softc(dev);
+	struct siba_devinfo	*sdi;
 	uint32_t idlo, idhi;
+	uint32_t rev;
+	uint16_t vendorid;
 	uint16_t ccid;
-	uint32_t rev;
+	int idx;
 
 	if (siba_debug)
 		printf("%s: entry\n", __func__);
 
-	bus_generic_probe(dev);
+	bus_generic_probe(dev);	/* XXX should this happen here ? */
 
 	/*
 	 * Now that all bus space is mapped and visible to the CPU,
@@ -277,12 +302,7 @@
 	 * Note that only one core may be mapped at any time if the siba
 	 * bus is the child of a PCI or PCMCIA bus.
 	 */
-	uint16_t vendorid;
-	int idx;
-
 	for (idx = 0; idx < sc->sc_ncores; idx++) {
-		struct siba_devid *sd;
-
 		idlo = siba_read_4(sc, idx, SIBA_CORE_IDLO);
 		idhi = siba_read_4(sc, idx, SIBA_CORE_IDHI);
 		ccid = ((idhi & 0x8ff0) >> 4);
@@ -290,8 +310,8 @@
 		rev = (idhi & SSB_IDHIGH_RCLO);
 		rev |= (idhi & SSB_IDHIGH_RCHI) >> SSB_IDHIGH_RCHI_SHIFT;
 
-		struct siba_devinfo *sdi;
-
+		/* XXX setup devinfo should read the values from
+		 * the core on the bus. */
 		sdi = siba_setup_devinfo(NULL, 0);
 		sdi->sdi_vid = vendorid;
 		sdi->sdi_devid = ccid;
@@ -299,20 +319,6 @@
 		sdi->sdi_idx = idx;
 		sdi->sdi_irq = 0;	/* XXX notyet */
 
-		sd = siba_dev_match(vendorid, ccid, rev);
-		(void)sd;
-#if 0
-		/* we do this the newbus way now */
-		if (sd != NULL) {
-			device_printf(dev, "core %d: %s rev %02x\n",
-			    idx, sd->sd_desc, rev);
-		} else {
-			device_printf(dev,
-			    "core %d: vid %04x pid %04x rev %02x\n",
-			    idx, vendorid, ccid, rev);
-		}
-#endif
-
 		/*
 		 * Try to attach the child.
 		 * We need to set resources for the child from here;
@@ -320,34 +326,29 @@
 		 * instance variables like children of pcib do.
 		 */
 		device_t child;
+
 		child = device_add_child(dev, NULL, -1);
 		if (child == NULL) {
 			/* XXX should panic */
 			device_printf(dev, "could not add child\n");
 			siba_destroy_devinfo(sdi);
 		} else {
-			/* Set memory window for immediate child. */
+			/*
+			 * Set resources for child.
+			 * TODO: IRQs.
+			 * Clean this up...
+			 */
 			device_set_ivars(child, sdi);
+			resource_list_init(&sdi->sdi_rl);
 			bus_addr_t baseaddr;
 			baseaddr = sc->sc_maddr + (idx * SIBA_CORE_LEN);
-			bus_set_resource(child, SYS_RES_MEMORY, MIPS_MEM_RID,
-			    baseaddr, baseaddr + SIBA_CORE_LEN - 1);
+			resource_list_add(&sdi->sdi_rl, SYS_RES_MEMORY,
+			    MIPS_MEM_RID, /* XXX */
+			    baseaddr, baseaddr + SIBA_CORE_LEN - 1,
+			    SIBA_CORE_LEN);
 		}
 	}
 
-	/*
-	 * Release our memory window before children are attached.
-	 */
-	int result;
-	int rid;
-	rid = MIPS_MEM_RID;
-	result = bus_release_resource(dev, SYS_RES_MEMORY, rid,
-	    sc->sc_mem);
-	if (result != 0) {
-		device_printf(dev, "error %d releasing resource\n", result);
-		return (ENXIO);
-	}
-
 	return (bus_generic_attach(dev));
 }
 
@@ -390,11 +391,67 @@
 siba_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 resource			*rv;
+	struct resource_list		*rl;
+	struct resource_list_entry	*rle;
+	int				 isdefault, needactivate;
 
+#if 0
 	if (siba_debug)
 		printf("%s: entry\n", __func__);
+#endif
 
-	return (NULL);
+	isdefault = (start == 0UL && end == ~0UL && count == 1);
+	needactivate = flags & RF_ACTIVE;
+	rl = BUS_GET_RESOURCE_LIST(bus, child);
+	rle = NULL;
+
+	if (isdefault) {
+		rle = resource_list_find(rl, type, *rid);
+		if (rle == NULL)
+			return (NULL);
+		if (rle->res != NULL)
+			panic("%s: resource entry is busy", __func__);
+		start = rle->start;
+		end = rle->end;
+		count = rle->count;
+	}
+
+	/*
+	 * If the request is for a resource which we manage,
+	 * attempt to satisfy the allocation ourselves.
+	 */
+	if (type == SYS_RES_MEMORY &&
+	    start >= mem_rman.rm_start && end <= mem_rman.rm_end) {
+
+		rv = rman_reserve_resource(&mem_rman, start, end, count,
+		    flags, child);
+		if (rv == 0) {
+			printf("%s: could not reserve resource\n", __func__);
+			return (0);
+		}
+
+		rman_set_rid(rv, *rid);
+
+		if (needactivate) {
+			if (bus_activate_resource(child, type, *rid, rv)) {
+				printf("%s: could not activate resource\n",
+				    __func__);
+				rman_release_resource(rv);
+				return (0);
+			}
+		}
+
+		return (rv);
+	}
+
+	/*
+	 * Pass the request to the parent, usually MIPS nexus.
+	 */
+	if (siba_debug)
+		printf("%s: passing to parent", __func__);
+	return (resource_list_alloc(rl, bus, child, type, rid,
+	    start, end, count, flags));
 }
 
 static int
@@ -402,12 +459,16 @@
     struct resource *r)
 {
 
-	if (siba_debug)
-		printf("%s: entry\n", __func__);
+//	if (siba_debug)
+//		printf("%s: entry\n", __func__);
 
-	return (ENXIO);
+	/*
+	 * Pass it to parent.
+	 */
+	return (rman_activate_resource(r));
 }
 
+/* XXX this should read the info from the core being probed */
 static struct siba_devinfo *
 siba_setup_devinfo(device_t dev, uint8_t idx)
 {
@@ -485,21 +546,25 @@
 static void
 siba_probe_nomatch(device_t dev, device_t child)
 {
-	struct siba_devid *sd;
 
-	sd = siba_dev_match(siba_get_vendor(child), siba_get_device(child),
-	    SIBA_REV_ANY);
-	device_printf(dev, "<0x%04x, 0x%04x \"%s\"> not attached\n",
-	    siba_get_vendor(child), siba_get_device(child),
-	    sd != NULL ? sd->sd_desc : "unknown");
+	/*
+	 * Announce devices which weren't attached after we probed the bus.
+	 */
+	if (siba_debug) {
+		struct siba_devid *sd;
+		sd = siba_dev_match(siba_get_vendor(child),
+		    siba_get_device(child), SIBA_REV_ANY);
+		device_printf(dev, "<0x%04x, 0x%04x \"%s\"> not attached\n",
+		    siba_get_vendor(child), siba_get_device(child),
+		    sd != NULL ? sd->sd_desc : "unknown");
+	}
 }
 
 static int
 siba_print_all_resources(device_t dev)
 {
-#if 0
-	struct siba_device *ndev = DEVTONX(dev);
-	struct resource_list *rl = &ndev->nx_resources;
+	struct siba_devinfo *sdi = device_get_ivars(dev);
+	struct resource_list *rl = &sdi->sdi_rl;
 	int retval = 0;
 
 	if (STAILQ_FIRST(rl))
@@ -509,9 +574,14 @@
 	retval += resource_list_print_type(rl, "irq", SYS_RES_IRQ, "%ld");
 
 	return (retval);
-#else
-	return (0);
-#endif
+}
+
+static struct resource_list *
+siba_get_reslist(device_t dev, device_t child)
+{
+	struct siba_devinfo *sdi = device_get_ivars(child);
+
+	return (&sdi->sdi_rl);
 }
 
 static device_method_t siba_methods[] = {
@@ -527,6 +597,7 @@
 	DEVMETHOD(bus_activate_resource,siba_activate_resource),
 	DEVMETHOD(bus_add_child,	siba_add_child),
 	DEVMETHOD(bus_alloc_resource,	siba_alloc_resource),
+	DEVMETHOD(bus_get_resource_list,siba_get_reslist),
 	DEVMETHOD(bus_print_child,	siba_print_child),
 	DEVMETHOD(bus_probe_nomatch,	siba_probe_nomatch),
 	DEVMETHOD(bus_read_ivar,	siba_read_ivar),

==== //depot/projects/mips2/src/sys/mips/mips32/sentry5/siba_cc.c#3 (text+ko) ====

@@ -54,6 +54,7 @@
 
 	if (siba_get_vendor(dev) == SIBA_VID_BROADCOM &&
 	    siba_get_device(dev) == SIBA_DEVID_CHIPCOMMON) {
+		device_set_desc(dev, "ChipCommon core");
 		return (BUS_PROBE_DEFAULT);
 	}
 
@@ -84,10 +85,12 @@
 		device_printf(dev, "unable to allocate memory\n");
 		return (ENXIO);
 	}
+#if 0
 	device_printf(dev, "start %08lx size %04lx\n",
 	    rman_get_start(mem), rman_get_size(mem));
+#endif
 
-	device_set_desc(dev, "ChipCommon core");
+	/* TODO: attach uart child */
 
 	return (0);
 }

==== //depot/projects/mips2/src/sys/mips/mips32/sentry5/siba_mips.c#2 (text+ko) ====

@@ -54,6 +54,7 @@
 
 	if (siba_get_vendor(dev) == SIBA_VID_BROADCOM &&
 	    siba_get_device(dev) == SIBA_DEVID_MIPS_3302) {
+		device_set_desc(dev, "MIPS 3302 processor");
 		return (BUS_PROBE_DEFAULT);
 	}
 
@@ -84,10 +85,10 @@
 		device_printf(dev, "unable to allocate memory\n");
 		return (ENXIO);
 	}
+#if 0
 	device_printf(dev, "start %08lx size %04lx\n",
 	    rman_get_start(mem), rman_get_size(mem));
-
-	device_set_desc(dev, "MIPS 3302 processor");
+#endif
 
 	return (0);
 }

==== //depot/projects/mips2/src/sys/mips/mips32/sentry5/siba_pcib.c#2 (text+ko) ====

@@ -54,6 +54,7 @@
 
 	if (siba_get_vendor(dev) == SIBA_VID_BROADCOM &&
 	    siba_get_device(dev) == SIBA_DEVID_PCI) {
+		device_set_desc(dev, "SiBa-to-PCI host bridge");
 		return (BUS_PROBE_DEFAULT);
 	}
 
@@ -84,10 +85,10 @@
 		device_printf(dev, "unable to allocate memory\n");
 		return (ENXIO);
 	}
+#if 0
 	device_printf(dev, "start %08lx size %04lx\n",
 	    rman_get_start(mem), rman_get_size(mem));
-
-	device_set_desc(dev, "SiBa-to-PCI host bridge");
+#endif
 
 	return (0);
 }

==== //depot/projects/mips2/src/sys/mips/mips32/sentry5/siba_sdram.c#2 (text+ko) ====

@@ -54,6 +54,7 @@
 
 	if (siba_get_vendor(dev) == SIBA_VID_BROADCOM &&
 	    siba_get_device(dev) == SIBA_DEVID_SDRAMDDR) {
+		device_set_desc(dev, "SDRAM/DDR core");
 		return (BUS_PROBE_DEFAULT);
 	}
 
@@ -84,10 +85,11 @@
 		device_printf(dev, "unable to allocate memory\n");
 		return (ENXIO);
 	}
+
+#if 0
 	device_printf(dev, "start %08lx size %04lx\n",
 	    rman_get_start(mem), rman_get_size(mem));
-
-	device_set_desc(dev, "SDRAM/DDR core");
+#endif
 
 	return (0);
 }


More information about the p4-projects mailing list