Date: Sun, 13 Jan 2013 16:51:58 +0000 (UTC) From: Robert Watson <rwatson@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r245378 - in head/sys: conf dev/altera/avgen Message-ID: <201301131651.r0DGpw3m019579@svn.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: rwatson Date: Sun Jan 13 16:51:57 2013 New Revision: 245378 URL: http://svnweb.freebsd.org/changeset/base/245378 Log: Partially merge Perforce changeset 219942 to head: Implement an FDT attachment for altera_avgen(4). Portions of the changeset updating DTS and device.hints will be merged separately. Sponsored by: DARPA, AFRL Modified: head/sys/conf/files head/sys/dev/altera/avgen/altera_avgen_fdt.c Modified: head/sys/conf/files ============================================================================== --- head/sys/conf/files Sun Jan 13 16:44:45 2013 (r245377) +++ head/sys/conf/files Sun Jan 13 16:51:57 2013 (r245378) @@ -638,6 +638,7 @@ dev/aic7xxx/aic7xxx_pci.c optional ahc p dev/alc/if_alc.c optional alc pci dev/ale/if_ale.c optional ale pci dev/altera/avgen/altera_avgen.c optional altera_avgen +dev/altera/avgen/altera_avgen_fdt.c optional altera_avgen fdt dev/altera/avgen/altera_avgen_nexus.c optional altera_avgen dev/altera/sdcard/altera_sdcard.c optional altera_sdcard dev/altera/sdcard/altera_sdcard_disk.c optional altera_sdcard Modified: head/sys/dev/altera/avgen/altera_avgen_fdt.c ============================================================================== --- head/sys/dev/altera/avgen/altera_avgen_fdt.c Sun Jan 13 16:44:45 2013 (r245377) +++ head/sys/dev/altera/avgen/altera_avgen_fdt.c Sun Jan 13 16:51:57 2013 (r245378) @@ -51,22 +51,32 @@ __FBSDID("$FreeBSD$"); #include <vm/vm.h> +#include <dev/fdt/fdt_common.h> +#include <dev/ofw/openfirm.h> +#include <dev/ofw/ofw_bus.h> +#include <dev/ofw/ofw_bus_subr.h> + #include <dev/altera/avgen/altera_avgen.h> static int -altera_avgen_nexus_probe(device_t dev) +altera_avgen_fdt_probe(device_t dev) { - device_set_desc(dev, "Generic Altera Avalon device attachment"); - return (BUS_PROBE_DEFAULT); + if (ofw_bus_is_compatible(dev, "sri-cambridge,avgen")) { + device_set_desc(dev, "Generic Altera Avalon device attachment"); + return (BUS_PROBE_DEFAULT); + } + return (ENXIO); } static int -altera_avgen_nexus_attach(device_t dev) +altera_avgen_fdt_attach(device_t dev) { struct altera_avgen_softc *sc; - const char *str_fileio, *str_mmapio; - const char *str_devname; + char *str_fileio, *str_mmapio; + char *str_devname; + phandle_t node; + pcell_t cell; int devunit, error; sc = device_get_softc(dev); @@ -74,28 +84,25 @@ altera_avgen_nexus_attach(device_t dev) sc->avg_unit = device_get_unit(dev); /* - * Query non-standard hints to find out what operations are permitted - * on the device, and whether it is cached. + * Query driver-specific OpenFirmware properties to determine how to + * expose the device via /dev. */ str_fileio = NULL; str_mmapio = NULL; str_devname = NULL; devunit = -1; sc->avg_width = 1; - error = resource_int_value(device_get_name(dev), device_get_unit(dev), - ALTERA_AVALON_STR_WIDTH, &sc->avg_width); - if (error != 0 && error != ENOENT) { - device_printf(dev, "invalid %s\n", ALTERA_AVALON_STR_WIDTH); - return (error); - } - (void)resource_string_value(device_get_name(dev), - device_get_unit(dev), ALTERA_AVALON_STR_FILEIO, &str_fileio); - (void)resource_string_value(device_get_name(dev), - device_get_unit(dev), ALTERA_AVALON_STR_MMAPIO, &str_mmapio); - (void)resource_string_value(device_get_name(dev), - device_get_unit(dev), ALTERA_AVALON_STR_DEVNAME, &str_devname); - (void)resource_int_value(device_get_name(dev), device_get_unit(dev), - ALTERA_AVALON_STR_DEVUNIT, &devunit); + node = ofw_bus_get_node(dev); + if (OF_getprop(node, "sri-cambridge,width", &cell, sizeof(cell)) > 0) + sc->avg_width = cell; + (void)OF_getprop_alloc(node, "sri-cambridge,fileio", sizeof(char), + (void **)&str_fileio); + (void)OF_getprop_alloc(node, "sri-cambridge,mmapio", sizeof(char), + (void **)&str_mmapio); + (void)OF_getprop_alloc(node, "sri-cambridge,devname", sizeof(char), + (void **)&str_devname); + if (OF_getprop(node, "sri-cambridge,devunit", &cell, sizeof(cell)) > 0) + devunit = cell; /* Memory allocation and checking. */ sc->avg_rid = 0; @@ -110,11 +117,17 @@ altera_avgen_nexus_attach(device_t dev) if (error != 0) bus_release_resource(dev, SYS_RES_MEMORY, sc->avg_rid, sc->avg_res); + if (str_fileio != NULL) + free(str_fileio, M_OFWPROP); + if (str_mmapio != NULL) + free(str_mmapio, M_OFWPROP); + if (str_devname != NULL) + free(str_devname, M_OFWPROP); return (error); } static int -altera_avgen_nexus_detach(device_t dev) +altera_avgen_fdt_detach(device_t dev) { struct altera_avgen_softc *sc; @@ -124,20 +137,20 @@ altera_avgen_nexus_detach(device_t dev) return (0); } -static device_method_t altera_avgen_nexus_methods[] = { - DEVMETHOD(device_probe, altera_avgen_nexus_probe), - DEVMETHOD(device_attach, altera_avgen_nexus_attach), - DEVMETHOD(device_detach, altera_avgen_nexus_detach), +static device_method_t altera_avgen_fdt_methods[] = { + DEVMETHOD(device_probe, altera_avgen_fdt_probe), + DEVMETHOD(device_attach, altera_avgen_fdt_attach), + DEVMETHOD(device_detach, altera_avgen_fdt_detach), { 0, 0 } }; -static driver_t altera_avgen_nexus_driver = { +static driver_t altera_avgen_fdt_driver = { "altera_avgen", - altera_avgen_nexus_methods, + altera_avgen_fdt_methods, sizeof(struct altera_avgen_softc), }; static devclass_t altera_avgen_devclass; -DRIVER_MODULE(avgen, nexus, altera_avgen_nexus_driver, altera_avgen_devclass, - 0, 0); +DRIVER_MODULE(avgen, simplebus, altera_avgen_fdt_driver, + altera_avgen_devclass, 0, 0);
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201301131651.r0DGpw3m019579>