Date: Sun, 09 Jul 2006 02:22:24 -0600 (MDT) From: "M. Warner Losh" <imp@bsdimp.com> To: jhb@freebsd.org Cc: acpi@freebsd.org Subject: Fw: PERFORCE change 101080 for review Message-ID: <20060709.022224.-1827343921.imp@bsdimp.com>
next in thread | raw e-mail | index | archive | help
----Next_Part(Sun_Jul__9_02_22_24_2006_113)-- Content-Type: Text/Plain; charset=us-ascii Content-Transfer-Encoding: 7bit John, I think the following change is good reguardless of how the current discussions about how to get acpi devices wired falls out. It modifies devclass unit number assignment to treat a pre-existing device as 'taken' as well as one that just might be hinted at. It has the nice side effect of obviating the need for device_set_unit, which I added holding my nose a long time ago. The reason I didn't go with this approach was that at the time (4.x or maybe 3.x) there wasn't the hints infrastructure we have today, and I never went back to revisit this kludge to remove it. Please let me know what you think of this. Warner ----Next_Part(Sun_Jul__9_02_22_24_2006_113)-- Content-Type: Message/Rfc822 Content-Transfer-Encoding: 7bit Content-Disposition: inline Return-Path: owner-perforce@freebsd.org Delivery-Date: Sun, 09 Jul 2006 02:17:09 -0600 X-Spam-Checker-Version: SpamAssassin 3.1.1 (2006-03-10) on harmony.bsdimp.com X-Spam-Level: X-Spam-Status: No, score=-2.4 required=4.5 tests=BAYES_00,HOT_NASTY autolearn=ham version=3.1.1 Received: from mx2.freebsd.org (mx2.freebsd.org [216.136.204.119]) by harmony.bsdimp.com (8.13.4/8.13.4) with ESMTP id k698FH0I093302 for <imp@bsdimp.com>; Sun, 9 Jul 2006 02:15:17 -0600 (MDT) (envelope-from owner-perforce@freebsd.org) Received: from hub.freebsd.org (hub.freebsd.org [216.136.204.18]) by mx2.freebsd.org (Postfix) with ESMTP id DBCA857F1B for <imp@bsdimp.com>; Sun, 9 Jul 2006 08:15:13 +0000 (GMT) (envelope-from owner-perforce@freebsd.org) Received: by hub.freebsd.org (Postfix) id E4D5316A50A; Sun, 9 Jul 2006 08:15:12 +0000 (UTC) Delivered-To: imp@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id CE97516A4E1; Sun, 9 Jul 2006 08:15:12 +0000 (UTC) X-Original-To: perforce@freebsd.org Delivered-To: perforce@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 674EB16A4DA for <perforce@freebsd.org>; Sun, 9 Jul 2006 08:15:12 +0000 (UTC) (envelope-from imp@freebsd.org) Received: from repoman.freebsd.org (repoman.freebsd.org [216.136.204.115]) by mx1.FreeBSD.org (Postfix) with ESMTP id 288B743D46 for <perforce@freebsd.org>; Sun, 9 Jul 2006 08:15:12 +0000 (GMT) (envelope-from imp@freebsd.org) Received: from repoman.freebsd.org (localhost [127.0.0.1]) by repoman.freebsd.org (8.13.6/8.13.6) with ESMTP id k698FC09071129 for <perforce@freebsd.org>; Sun, 9 Jul 2006 08:15:12 GMT (envelope-from imp@freebsd.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.13.6/8.13.4/Submit) id k698FBQl071126 for perforce@freebsd.org; Sun, 9 Jul 2006 08:15:11 GMT (envelope-from imp@freebsd.org) Date: Sun, 9 Jul 2006 08:15:11 GMT Message-Id: <200607090815.k698FBQl071126@repoman.freebsd.org> X-Authentication-Warning: repoman.freebsd.org: perforce set sender to imp@freebsd.org using -f From: Warner Losh <imp@freebsd.org> Subject: PERFORCE change 101080 for review To: Perforce Change Reviews <perforce@freebsd.org> http://perforce.freebsd.org/chv.cgi?CH=101080 Change 101080 by imp@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); ----Next_Part(Sun_Jul__9_02_22_24_2006_113)----
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20060709.022224.-1827343921.imp>