Date: Sat, 3 Jun 2006 18:07:34 GMT From: Warner Losh <imp@FreeBSD.org> To: Perforce Change Reviews <perforce@freebsd.org> Subject: PERFORCE change 98406 for review Message-ID: <200606031807.k53I7YCZ068519@repoman.freebsd.org>
next in thread | raw e-mail | index | archive | help
http://perforce.freebsd.org/chv.cgi?CH=98406 Change 98406 by imp@imp_lighthouse on 2006/06/03 18:06:49 Keep track of resources better. Implement the sdhc_host device. Not 100% sure we need this extra layer of indirection, but it may be useful. Affected files ... .. //depot/projects/arm/src/sys/dev/sdhc/sdhc.c#3 edit .. //depot/projects/arm/src/sys/dev/sdhc/sdhc_pci.c#7 edit .. //depot/projects/arm/src/sys/dev/sdhc/sdhcvar.h#3 edit Differences ... ==== //depot/projects/arm/src/sys/dev/sdhc/sdhc.c#3 (text+ko) ==== @@ -35,6 +35,7 @@ #include <sys/param.h> #include <sys/bus.h> #include <sys/kernel.h> +#include <sys/malloc.h> #include <sys/module.h> #include <sys/systm.h> @@ -105,20 +106,84 @@ return (0); } -void -sdhc_child_detached(device_t dev, device_t child) +int +sdhc_attach(device_t dev) { - // XXX + return (0); } int -sdhc_attach(device_t dev) +sdhc_detach(device_t dev) +{ + struct sdhc_softc *sc = device_get_softc(dev); + int numdevs, tmp, i; + device_t *devlist; + + bus_generic_detach(dev); + + for (i = 0; i < sc->nres; i++) + bus_free_resource(dev, SYS_RES_MEMORY, sc->res[i]); + + // Since we create these devices in attach, we have to delete them + // in detach. + device_get_children(dev, &devlist, &numdevs); + for (tmp = 0; tmp < numdevs; tmp++) + device_delete_child(dev, devlist[tmp]); + free(devlist, M_TEMP); + + return (0); +} + +struct sdhc_host_softc +{ + int dummy; +}; + +static int +sdhc_host_probe(device_t dev) +{ + return (0); +} + +static int +sdhc_host_attach(device_t dev) { + device_add_child(dev, "mmcbus", -1); return (0); } -int -sdhc_detach(device_t dev) +static int +sdhc_host_detach(device_t dev) { - return (bus_generic_detach(dev)); + int numdevs, tmp; + device_t *devlist; + + // Since we create these devices in attach, we have to delete them + // in detach. + device_get_children(dev, &devlist, &numdevs); + for (tmp = 0; tmp < numdevs; tmp++) + device_delete_child(dev, devlist[tmp]); + free(devlist, M_TEMP); + + return (0); + } + +static device_method_t sdhc_host_methods[] = { + /* Device interface */ + DEVMETHOD(device_probe, sdhc_host_probe), + DEVMETHOD(device_attach, sdhc_host_attach), + DEVMETHOD(device_detach, sdhc_host_detach), + + { 0, 0 } +}; + +static driver_t sdhc_host_driver = { + "sdhc_host", + sdhc_host_methods, + sizeof(struct sdhc_host_softc), +}; + +devclass_t sdhc_host_devclass; + +DRIVER_MODULE(sdhc_host, sdhc, sdhc_host_driver, sdhc_host_devclass, 0, 0); ==== //depot/projects/arm/src/sys/dev/sdhc/sdhc_pci.c#7 (text+ko) ==== @@ -74,6 +74,7 @@ res = bus_alloc_resource_any(dev, SYS_RES_MEMORY, &i, RF_ACTIVE); if (res == NULL) continue; + sc->res[sc->nres++] = res; child = device_add_child(dev, "sdhc_host", -1); if (child == NULL) { device_printf(child, "Can't add host slot rid %#x\n", @@ -101,7 +102,6 @@ DEVMETHOD(bus_write_ivar, sdhc_write_ivar), DEVMETHOD(bus_alloc_resource, sdhc_alloc_resource), DEVMETHOD(bus_release_resource, sdhc_release_resource), - DEVMETHOD(bus_child_detached, sdhc_child_detached), { 0, 0 } }; ==== //depot/projects/arm/src/sys/dev/sdhc/sdhcvar.h#3 (text+ko) ==== @@ -27,10 +27,14 @@ #ifndef DEV_SDHC_SDHCVAR_H #define DEV_SDHC_SDHCVAR_H +#define SDHC_MAX_RES 6 + struct sdhc_softc { int flags; #define SDHC_FLAG_HASDMA 1 + int nres; + struct resource *res[SDHC_MAX_RES]; }; struct sdhc_ivars
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200606031807.k53I7YCZ068519>