PERFORCE change 101080 for review

Warner Losh imp at FreeBSD.org
Sun Jul 9 08:15:13 UTC 2006


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

Change 101080 by imp at imp_lighthouse on 2006/07/09 08:14:50

	Kill that unsightly device_set_unit().  Make the assignment
	of units skip anything that is hinted 'at' :-).  This means
	we no longer need to skip low unit numbers for pci's sio since
	either there will be sio hints, in which case we'll be honoring
	them, or there won't, in which case it just won't matter.

Affected files ...

.. //depot/projects/arm/src/sys/dev/sio/sio_pci.c#3 edit
.. //depot/projects/arm/src/sys/kern/subr_bus.c#10 edit
.. //depot/projects/arm/src/sys/sys/bus.h#6 edit

Differences ...

==== //depot/projects/arm/src/sys/dev/sio/sio_pci.c#3 (text+ko) ====

@@ -43,7 +43,6 @@
 #include <dev/pci/pcivar.h>
 
 static	int	sio_pci_attach(device_t dev);
-static	void	sio_pci_kludge_unit(device_t dev);
 static	int	sio_pci_probe(device_t dev);
 
 static device_method_t sio_pci_methods[] = {
@@ -101,39 +100,9 @@
 		id++;
 	if (id->desc == NULL)
 		return (ENXIO);
-	sio_pci_kludge_unit(dev);
 	return (sioattach(dev, id->rid, 0UL));
 }
 
-/*
- * Don't cut and paste this to other drivers.  It is a horrible kludge
- * which will fail to work and also be unnecessary in future versions.
- */
-static void
-sio_pci_kludge_unit(dev)
-	device_t dev;
-{
-	devclass_t	dc;
-	int		err;
-	int		start;
-	int		unit;
-
-	unit = 0;
-	start = 0;
-	while (resource_int_value("sio", unit, "port", &start) == 0 && 
-	    start > 0)
-		unit++;
-	if (device_get_unit(dev) < unit) {
-		dc = device_get_devclass(dev);
-		while (devclass_get_device(dc, unit))
-			unit++;
-		device_printf(dev, "moving to sio%d\n", unit);
-		err = device_set_unit(dev, unit);	/* EVIL DO NOT COPY */
-		if (err)
-			device_printf(dev, "error moving device %d\n", err);
-	}
-}
-
 static int
 sio_pci_probe(dev)
 	device_t	dev;

==== //depot/projects/arm/src/sys/kern/subr_bus.c#10 (text+ko) ====

@@ -1295,11 +1295,11 @@
 devclass_alloc_unit(devclass_t dc, int *unitp)
 {
 	int unit = *unitp;
+	const char *where;
 
 	PDEBUG(("unit %d in devclass %s", unit, DEVCLANAME(dc)));
 
 	/* If we were given a wired unit number, check for existing device */
-	/* XXX imp XXX */
 	if (unit != -1) {
 		if (unit >= 0 && unit < dc->maxunit &&
 		    dc->devices[unit] != NULL) {
@@ -1309,9 +1309,16 @@
 			return (EEXIST);
 		}
 	} else {
-		/* Unwired device, find the next available slot for it */
+		/*
+		 * Unwired device, find the next available slot for it that
+		 * doesn't have an "at" hint indicating that it might be
+		 * wired on a bus that hasn't probed yet.  We skip those
+		 * units, even when we're past the 'end' of the current
+		 * array.
+		 */
 		unit = 0;
-		while (unit < dc->maxunit && dc->devices[unit] != NULL)
+		while ((unit < dc->maxunit && dc->devices[unit] != NULL) ||
+		    resource_string_value(dc->name, unit, "at", &where) == 0)
 			unit++;
 	}
 
@@ -2480,33 +2487,6 @@
 	return (DEVICE_SHUTDOWN(dev));
 }
 
-/**
- * @brief Set the unit number of a device
- *
- * This function can be used to override the unit number used for a
- * device (e.g. to wire a device to a pre-configured unit number).
- */
-int
-device_set_unit(device_t dev, int unit)
-{
-	devclass_t dc;
-	int err;
-
-	dc = device_get_devclass(dev);
-	if (unit < dc->maxunit && dc->devices[unit])
-		return (EBUSY);
-	err = devclass_delete_device(dc, dev);
-	if (err)
-		return (err);
-	dev->unit = unit;
-	err = devclass_add_device(dc, dev);
-	if (err)
-		return (err);
-
-	bus_data_generation_update();
-	return (0);
-}
-
 /*======================================*/
 /*
  * Some useful method implementations to make life easier for bus drivers.

==== //depot/projects/arm/src/sys/sys/bus.h#6 (text+ko) ====

@@ -375,7 +375,6 @@
 int	device_set_driver(device_t dev, driver_t *driver);
 void	device_set_flags(device_t dev, u_int32_t flags);
 void	device_set_softc(device_t dev, void *softc);
-int	device_set_unit(device_t dev, int unit);	/* XXX DONT USE XXX */
 int	device_shutdown(device_t dev);
 void	device_unbusy(device_t dev);
 void	device_verbose(device_t dev);


More information about the p4-projects mailing list