PERFORCE change 119602 for review

Bruce M Simpson bms at FreeBSD.org
Wed May 9 22:02:29 UTC 2007


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

Change 119602 by bms at bms_anglepoise on 2007/05/09 22:02:18

	Clean up bus enumeration slightly by moving the code which
	initializes the devinfo into siba_setup_devinfo(), and reading
	it from the currently mapped core.

Affected files ...

.. //depot/projects/mips2/src/sys/mips/mips32/sentry5/siba.c#6 edit

Differences ...

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

@@ -96,7 +96,9 @@
 		siba_alloc_resource(device_t, device_t, int, int *, u_long,
 		    u_long, u_long, u_int);
 static int	siba_attach(device_t);
+#ifdef notyet
 static void	siba_destroy_devinfo(struct siba_devinfo *);
+#endif
 static struct siba_devid *
 		siba_dev_match(uint16_t, uint16_t, uint8_t);
 static struct resource_list *
@@ -285,68 +287,26 @@
 {
 	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;
-	int idx;
+	device_t		 child;
+	int			 idx;
 
 	if (siba_debug)
 		printf("%s: entry\n", __func__);
 
-	bus_generic_probe(dev);	/* XXX should this happen here ? */
+	bus_generic_probe(dev);
 
 	/*
 	 * Now that all bus space is mapped and visible to the CPU,
 	 * enumerate its children.
-	 * Note that only one core may be mapped at any time if the siba
-	 * bus is the child of a PCI or PCMCIA bus.
+	 * NB: only one core may be mapped at any time if the siba bus
+	 * is the child of a PCI or PCMCIA bus.
 	 */
 	for (idx = 0; idx < sc->sc_ncores; idx++) {
-		idlo = siba_read_4(sc, idx, SIBA_CORE_IDLO);
-		idhi = siba_read_4(sc, idx, SIBA_CORE_IDHI);
-		ccid = ((idhi & 0x8ff0) >> 4);
-		vendorid = (idhi & SSB_IDHIGH_VC) >> SSB_IDHIGH_VC_SHIFT;
-		rev = (idhi & SSB_IDHIGH_RCLO);
-		rev |= (idhi & SSB_IDHIGH_RCHI) >> SSB_IDHIGH_RCHI_SHIFT;
-
-		/* 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;
-		sdi->sdi_rev = rev;
-		sdi->sdi_idx = idx;
-		sdi->sdi_irq = 0;	/* XXX notyet */
-
-		/*
-		 * Try to attach the child.
-		 * We need to set resources for the child from here;
-		 * drivers which attach to siba will need to use the
-		 * instance variables like children of pcib do.
-		 */
-		device_t child;
-
+		sdi = siba_setup_devinfo(dev, idx);
 		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 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);
-			resource_list_add(&sdi->sdi_rl, SYS_RES_MEMORY,
-			    MIPS_MEM_RID, /* XXX */
-			    baseaddr, baseaddr + SIBA_CORE_LEN - 1,
-			    SIBA_CORE_LEN);
-		}
+		if (child == NULL)
+			panic("%s: device_add_child() failed\n", __func__);
+		device_set_ivars(child, sdi);
 	}
 
 	return (bus_generic_attach(dev));
@@ -454,32 +414,55 @@
 	    start, end, count, flags));
 }
 
+/*
+ * The parent bus is responsible for resource activation; in the
+ * case of MIPS, this boils down to setting the virtual address and
+ * bus handle by mapping the physical address into KSEG1.
+ */
 static int
 siba_activate_resource(device_t bus, device_t child, int type, int rid,
     struct resource *r)
 {
 
-//	if (siba_debug)
-//		printf("%s: entry\n", __func__);
-
-	/*
-	 * 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)
 {
+	struct siba_softc *sc = device_get_softc(dev);
 	struct siba_devinfo *sdi;
+	uint32_t idlo, idhi, rev;
+	uint16_t vendorid, devid;
 
 	sdi = malloc(sizeof(*sdi), M_DEVBUF, M_WAITOK | M_ZERO);
 	resource_list_init(&sdi->sdi_rl);
 
+	idlo = siba_read_4(sc, idx, SIBA_CORE_IDLO);
+	idhi = siba_read_4(sc, idx, SIBA_CORE_IDHI);
+
+	vendorid = (idhi & SSB_IDHIGH_VC) >> SSB_IDHIGH_VC_SHIFT;
+	devid = ((idhi & 0x8ff0) >> 4);
+	rev = (idhi & SSB_IDHIGH_RCLO);
+	rev |= (idhi & SSB_IDHIGH_RCHI) >> SSB_IDHIGH_RCHI_SHIFT;
+
+	sdi->sdi_vid = vendorid;
+	sdi->sdi_devid = devid;
+	sdi->sdi_rev = rev;
+	sdi->sdi_idx = idx;
+	sdi->sdi_irq = 0;	/* XXX notyet */
+
+	bus_addr_t baseaddr;
+	baseaddr = sc->sc_maddr + (idx * SIBA_CORE_LEN);
+	resource_list_add(&sdi->sdi_rl, SYS_RES_MEMORY,
+	    MIPS_MEM_RID, /* XXX */
+	    baseaddr, baseaddr + SIBA_CORE_LEN - 1,
+	    SIBA_CORE_LEN);
+
 	return (sdi);
 }
 
+#ifdef notyet
 static void
 siba_destroy_devinfo(struct siba_devinfo *sdi)
 {
@@ -487,7 +470,9 @@
 	resource_list_free(&sdi->sdi_rl);
 	free(sdi, M_DEVBUF);
 }
+#endif
 
+/* XXX is this needed? */
 static device_t
 siba_add_child(device_t dev, int order, const char *name, int unit)
 {


More information about the p4-projects mailing list