Date: Mon, 9 Jul 2007 20:44:39 GMT From: Maxim Zhuravlev <thioretic@FreeBSD.org> To: Perforce Change Reviews <perforce@FreeBSD.org> Subject: PERFORCE change 123226 for review Message-ID: <200707092044.l69Kida3006379@repoman.freebsd.org>
next in thread | raw e-mail | index | archive | help
http://perforce.freebsd.org/chv.cgi?CH=123226 Change 123226 by thioretic@thioretic on 2007/07/09 20:43:41 TODO: device_set_driver semantics, resource_* and bus_generic_* stuff, some cleanups. DONE: softc semantics. Affected files ... .. //depot/projects/soc2007/thioretic_gidl/TODO#11 edit .. //depot/projects/soc2007/thioretic_gidl/kern/subr_bus.c#12 edit Differences ... ==== //depot/projects/soc2007/thioretic_gidl/TODO#11 (text+ko) ==== @@ -123,4 +123,13 @@ # } # # here driver_handler & DEVICE_PROBE reside in subr_bus - # driver_probe resides in driver+ # driver_probe resides in driver + a.1.4 Softc + SOLUTION: add softc per driver to device structure + FILE(S) AFFECTED: kern/subr_bus.c + # Added devclass_get_driver_softc(), + # device_get_driver_softc(), + # device_set_driver_softc(). + # All these return softc of a specified driver for a device. Old functions + # (those without '_driver_') return softc of DRV_LOWEST driver (as expected). + ==== //depot/projects/soc2007/thioretic_gidl/kern/subr_bus.c#12 (text+ko) ==== @@ -83,6 +83,10 @@ struct pdrv_compat { drv_compat_t pdriver; + void *ivars; + void *softc; +#define DF_EXTERNALSOFTC 1 /* softc not allocated by us */ + int flags; TAILQ_ENTRY(pdrv_compat) link; }; @@ -159,7 +163,6 @@ #define DF_DESCMALLOCED 8 /* description was malloced */ #define DF_QUIET 16 /* don't print verbose attach message */ #define DF_DONENOMATCH 32 /* don't execute DEVICE_NOMATCH again */ -#define DF_EXTERNALSOFTC 64 /* softc not allocated by us */ #define DF_REBID 128 /* Can rebid after attach */ u_char order; /**< order from device_add_child_ordered() */ u_char pad; @@ -1557,6 +1560,17 @@ return (device_get_softc(dev)); } +void * +devclass_get_driver_softc (devclass_t dc, int unit, driver_t *driver){ + device_t dev; + + dev = devclass_get_device(dc, unit); + if (!dev) + return (NULL); + + return (device_get_driver_softc(dev, driver)); +} + /** * @brief Get a list of devices in the devclass * @@ -1990,7 +2004,7 @@ } } dev->ivars = NULL; - dev->softc = NULL; +// dev->softc = NULL; TAILQ_INSERT_TAIL(&bus_data_devices, dev, devlink); @@ -2719,9 +2733,29 @@ void * device_get_softc(device_t dev) { - return (dev->softc); + if(!TAILQ_EMPTY(&(dev->drivers[DRV_LOWEST]))) + return (TAILQ_FIRST(&(dev->drivers[DRV_LOWEST]))->softc); + return (NULL); +} + +void * +device_get_driver_softc(device_t dev, driver_t *driver){ + int level; + uint32_t flags; + pdrv_compat *pdrvc; + + if (!drv_compat_get_flags (driver, &flags)) + return (NULL); + level = drv_compat_flags2idx (flags); + + TAILQ_FOREACH (pdrvc, &(dev->drivers[level]), link){ + if (pdrvc->pdriver->driver == driver) + return (pdrvc->softc); + } + return (NULL); } + /** * @brief Set the device's softc field * @@ -2731,13 +2765,43 @@ void device_set_softc(device_t dev, void *softc) { - if (dev->softc && !(dev->flags & DF_EXTERNALSOFTC)) - free(dev->softc, M_BUS_SC); - dev->softc = softc; - if (dev->softc) - dev->flags |= DF_EXTERNALSOFTC; + void *psoftc; + pdrv_compat *pdrvc; + + if(!TAILQ_EMPTY(&(dev->drivers[DRV_LOWEST]))) + pdrvc = TAILQ_FIRST(&(dev->drivers[DRV_LOWEST])); + if (pdrvc && !(pdrvc->flags & DF_EXTERNALSOFTC)) + free(pdrvc->softc, M_BUS_SC); + pdrvc->softc = softc; + if (pdrvc->softc) + pdrvc->flags |= DF_EXTERNALSOFTC; + else + pdrvc->flags &= ~DF_EXTERNALSOFTC; +} + +void +device_set_driver_softc(device_t dev, driver_t *driver, void* softc){ + int level; + uint32_t flags; + pdrv_compat *pdrvc; + + if (!drv_compat_get_flags (driver, &flags)) + return(); + level = drv_compat_flags2idx (flags); + + TAILQ_FOREACH (pdrvc, &(dev->drivers[level]), link){ + if (pdrvc->pdriver->driver == driver) + break; + } + if (!pdrvc) return(); + + if (!(pdrv->flags & DF_EXTERNALSOFTC)) + free(pdrvc->softc, M_BUS_SC); + pdrvc->softc = softc; + if (pdrvc->softc) + pdrvc->flags |= DF_EXTERNALSOFTC; else - dev->flags &= ~DF_EXTERNALSOFTC; + pdrvc->flags &= ~DF_EXTERNALSOFTC; } /** @@ -4610,7 +4674,7 @@ (dev->flags&DF_DESCMALLOCED? "descmalloced,":""), (dev->flags&DF_REBID? "rebiddable,":""), (dev->ivars? "":"no "), - (dev->softc? "":"no "), + ((TAILQ_FIRST(&(dev->drivers[DRV_LOWEST])))->softc? "":"no "), dev->busy)); }
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200707092044.l69Kida3006379>