Date: Sat, 25 Aug 2012 11:07:43 +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: r239674 - in head: share/man/man4 sys/conf sys/dev/altera sys/dev/altera/avgen Message-ID: <201208251107.q7PB7hZR028266@svn.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: rwatson Date: Sat Aug 25 11:07:43 2012 New Revision: 239674 URL: http://svn.freebsd.org/changeset/base/239674 Log: Add altera_avgen(4), a generic device driver to be used by hard and soft CPU cores on Altera FPGAs. The device driver allows memory-mapped devices on Altera's Avalon SoC bus to be exported to userspace via device nodes. device.hints directories dictate device name, permissible access methods, physical address and length, and I/O alignment. Devices can be accessed using read(2)/write(2), but also memory mapped in userspace using mmap(2). Devices attach directly to the Nexus, as is common for embedded device drivers; in the future something more mature might be desirable. There is currently no facility to support directing device-originated interrupts to userspace. In the future, this device driver may be renamed to socgen(4), as it can in principle also be used with other system-on-chip (SoC) busses, such as Axi on ASICs and FPGAs. However, we have only tested it on Avalon busses with memory-mapped ROMs, frame buffers, etc. Sponsored by: DARPA, AFRL Added: head/share/man/man4/altera_avgen.4 (contents, props changed) head/sys/dev/altera/ head/sys/dev/altera/avgen/ head/sys/dev/altera/avgen/altera_avgen.c (contents, props changed) head/sys/dev/altera/avgen/altera_avgen.h (contents, props changed) Modified: head/share/man/man4/Makefile head/sys/conf/files Modified: head/share/man/man4/Makefile ============================================================================== --- head/share/man/man4/Makefile Sat Aug 25 10:36:31 2012 (r239673) +++ head/share/man/man4/Makefile Sat Aug 25 11:07:43 2012 (r239674) @@ -32,6 +32,7 @@ MAN= aac.4 \ alc.4 \ ale.4 \ alpm.4 \ + altera_avgen.4 \ altq.4 \ amdpm.4 \ ${_amdsbwd.4} \ Added: head/share/man/man4/altera_avgen.4 ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ head/share/man/man4/altera_avgen.4 Sat Aug 25 11:07:43 2012 (r239674) @@ -0,0 +1,155 @@ +.\"- +.\" Copyright (c) 2012 Robert N. M. Watson +.\" All rights reserved. +.\" +.\" This software was developed by SRI International and the University of +.\" Cambridge Computer Laboratory under DARPA/AFRL contract (FA8750-10-C-0237) +.\" ("CTSRD"), as part of the DARPA CRASH research programme. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" $FreeBSD$ +.\" +.Dd August 18, 2012 +.Dt ALTERA_AVGEN 4 +.Os +.Sh NAME +.Nm altera_avgen +.Nd driver for generic Altera Avalon-bus-attached, memory-mapped devices +.Sh SYNOPSIS +.Cd "device altera_avgen" +.Pp +In +.Pa /boot/device.hints : +.Cd hint.altera_avgen.0.at="nexus0" +.Cd hint.altera_avgen.0.maddr=0x7f00a000 +.Cd hint.altera_avgen.0.msize=20 +.Cd hint.altera_avgen.0.width=4 +.Cd hint.altera_avgen.0.fileio="rw" +.Cd hint.altera_avgen.0.devname="berirom" +.Sh DESCRIPTION +The +.Nm +device driver provides generic support for memory-mapped devices on the +Altera Avalon bus. +.Pa device.hints +entries configure the address, size, I/O disposition, and +.Pa /dev +device node name that will be used. +The +.Xr open , +.Xr read , +.Xr write , +and +.Xr mmap +system calls (and variations) may be used on +.Nm +device nodes, subject to constraints imposed using +.Pa device.hints +entries. +Although reading and writing mapped memory is supported, +.Nm +does not currently support directing device interrupts to userspace. +.Pp +A number of +.Pa device.hints +sub-fields are available to configure +.Nm +device instances: +.Bl -tag -width devunit +.It maddr +base physical address of the memory region to export; must be aligned to +.Li width +.Ot msize +length of the memory region export; must be aligned to +.Li width +.It width +Granularity at which +.Xr read 2 +and +.Xr write 2 +operations will be performed. +Larger requests will be broken down into +.Li width -sized +operations; smaller requests will be rejected. +I/O operations must be aligned to +.Li width . +.It fileio +allowed file descriptor operations; +.Li r +authorizes +.Xr read 2 ; +.Li w +authorizes +.Xr write 2 . +.It mmapio +allowed +.Xr mmap 2 +permissions; +.Li w +authorizes +.Dv PROT_WRITE ; +.Li r +authorizes +.Dv PROT_READ ; +.Li x +authorizes +.Dv PROT_EXEC . +.It devname +specifies a device name relative to +.Pa /dev . +.It devunit +specifies a device unit number; no unit number is used if this is unspecified. +.El +.Sh SEE ALSO +.Xr mmap 2 , +.Xr open 2 , +.Xr read 2 , +.Xr write 2 +.Sh HISTORY +The +.Nm +device driver first appeared in +.Fx 10.0 . +.Sh AUTHORS +The +.Nm +device driver and this manual page were +developed by SRI International and the University of Cambridge Computer +Laboratory under DARPA/AFRL contract +.Pq FA8750-10-C-0237 +.Pq Do CTSRD Dc , +as part of the DARPA CRASH research programme. +This device driver was written by +.An Robert N. M. Watson . +.Sh BUGS +.Nm +is intended to support the writing of userspace device drivers; however, it +does not permit directing interrupts to userspace, only memory-mapped I/O. +.Pp +.Nm +supports only a +.Li nexus +bus attachment, which is appropriate for system-on-chip busses such as +Altera's Avalon bus. +If the target device is off of another bus type, then additional bus +attachments will be required. Modified: head/sys/conf/files ============================================================================== --- head/sys/conf/files Sat Aug 25 10:36:31 2012 (r239673) +++ head/sys/conf/files Sat Aug 25 11:07:43 2012 (r239674) @@ -659,6 +659,7 @@ dev/aic7xxx/aic7xxx_osm.c optional ahc dev/aic7xxx/aic7xxx_pci.c optional ahc pci 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/amr/amr.c optional amr dev/amr/amr_cam.c optional amrp amr dev/amr/amr_disk.c optional amr Added: head/sys/dev/altera/avgen/altera_avgen.c ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ head/sys/dev/altera/avgen/altera_avgen.c Sat Aug 25 11:07:43 2012 (r239674) @@ -0,0 +1,451 @@ +/*- + * Copyright (c) 2012 Robert N. M. Watson + * All rights reserved. + * + * This software was developed by SRI International and the University of + * Cambridge Computer Laboratory under DARPA/AFRL contract (FA8750-10-C-0237) + * ("CTSRD"), as part of the DARPA CRASH research programme. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include <sys/cdefs.h> +__FBSDID("$FreeBSD$"); + +#include <sys/param.h> +#include <sys/bus.h> +#include <sys/condvar.h> +#include <sys/conf.h> +#include <sys/kernel.h> +#include <sys/lock.h> +#include <sys/malloc.h> +#include <sys/module.h> +#include <sys/mutex.h> +#include <sys/rman.h> +#include <sys/stat.h> +#include <sys/systm.h> +#include <sys/uio.h> + +#include <machine/bus.h> +#include <machine/resource.h> +#include <machine/vm.h> + +#include <vm/vm.h> + +#include <dev/altera/avgen/altera_avgen.h> + +/* + * Generic device driver for allowing read(), write(), and mmap() on + * memory-mapped, Avalon-attached devices. There is no actual dependence on + * Avalon, so conceivably this should just be soc_dev or similar, since many + * system-on-chip bus environments would work fine with the same code. + */ + +static d_mmap_t altera_avgen_mmap; +static d_read_t altera_avgen_read; +static d_write_t altera_avgen_write; + +static struct cdevsw avg_cdevsw = { + .d_version = D_VERSION, + .d_mmap = altera_avgen_mmap, + .d_read = altera_avgen_read, + .d_write = altera_avgen_write, + .d_name = "altera_avgen", +}; + +static int +altera_avgen_read(struct cdev *dev, struct uio *uio, int flag) +{ + struct altera_avgen_softc *sc; + u_long offset, size; +#ifdef NOTYET + uint64_t v8; +#endif + uint32_t v4; + uint16_t v2; + uint8_t v1; + u_int width; + int error; + + sc = dev->si_drv1; + if ((sc->avg_flags & ALTERA_AVALON_FLAG_READ) == 0) + return (EACCES); + width = sc->avg_width; + if (uio->uio_offset < 0 || uio->uio_offset % width != 0 || + uio->uio_resid % width != 0) + return (ENODEV); + size = rman_get_size(sc->avg_res); + if ((uio->uio_offset + uio->uio_resid < 0) || + (uio->uio_offset + uio->uio_resid > size)) + return (ENODEV); + while (uio->uio_resid > 0) { + offset = uio->uio_offset; + if (offset + width > size) + return (ENODEV); + switch (width) { + case 1: + v1 = bus_read_1(sc->avg_res, offset); + error = uiomove(&v1, sizeof(v1), uio); + break; + + case 2: + v2 = bus_read_2(sc->avg_res, offset); + error = uiomove(&v2, sizeof(v2), uio); + break; + + case 4: + v4 = bus_read_4(sc->avg_res, offset); + error = uiomove(&v4, sizeof(v4), uio); + break; + +#ifdef NOTYET + case 8: + v8 = bus_read_8(sc->avg_res, offset); + error = uiomove(&v8, sizeof(v8), uio); + break; + +#endif + + default: + panic("%s: unexpected widthment %u", __func__, width); + } + if (error) + return (error); + } + return (0); +} + +static int +altera_avgen_write(struct cdev *dev, struct uio *uio, int flag) +{ + struct altera_avgen_softc *sc; + u_long offset, size; +#ifdef NOTYET + uint64_t v8; +#endif + uint32_t v4; + uint16_t v2; + uint8_t v1; + u_int width; + int error; + + sc = dev->si_drv1; + if ((sc->avg_flags & ALTERA_AVALON_FLAG_WRITE) == 0) + return (EACCES); + width = sc->avg_width; + if (uio->uio_offset < 0 || uio->uio_offset % width != 0 || + uio->uio_resid % width != 0) + return (ENODEV); + size = rman_get_size(sc->avg_res); + while (uio->uio_resid > 0) { + offset = uio->uio_offset; + if (offset + width > size) + return (ENODEV); + switch (width) { + case 1: + error = uiomove(&v1, sizeof(v1), uio); + if (error) + return (error); + bus_write_1(sc->avg_res, offset, v1); + break; + + case 2: + error = uiomove(&v2, sizeof(v2), uio); + if (error) + return (error); + bus_write_2(sc->avg_res, offset, v2); + break; + + case 4: + error = uiomove(&v4, sizeof(v4), uio); + if (error) + return (error); + bus_write_4(sc->avg_res, offset, v4); + break; + +#ifdef NOTYET + case 8: + error = uiomove(&v8, sizeof(v8), uio); + if (error) + return (error); + bus_write_8(sc->avg_res, offset, v8); + break; +#endif + + default: + panic("%s: unexpected width %u", __func__, width); + } + } + return (0); +} + +static int +altera_avgen_mmap(struct cdev *dev, vm_ooffset_t offset, vm_paddr_t *paddr, + int nprot, vm_memattr_t *memattr) +{ + struct altera_avgen_softc *sc; + + sc = dev->si_drv1; + if (nprot & VM_PROT_READ) { + if ((sc->avg_flags & ALTERA_AVALON_FLAG_MMAP_READ) == 0) + return (EACCES); + } + if (nprot & VM_PROT_WRITE) { + if ((sc->avg_flags & ALTERA_AVALON_FLAG_MMAP_WRITE) == 0) + return (EACCES); + } + if (nprot & VM_PROT_EXECUTE) { + if ((sc->avg_flags & ALTERA_AVALON_FLAG_MMAP_EXEC) == 0) + return (EACCES); + } + if (trunc_page(offset) == offset && + rman_get_size(sc->avg_res) >= offset + PAGE_SIZE) { + *paddr = rman_get_start(sc->avg_res) + offset; + *memattr = VM_MEMATTR_UNCACHEABLE; + } else + return (ENODEV); + return (0); +} + +static int +altera_avgen_nexus_probe(device_t dev) +{ + + device_set_desc(dev, "Generic Altera Avalon device attachment"); + return (BUS_PROBE_DEFAULT); +} + +static int +altera_avgen_process_options(struct altera_avgen_softc *sc, + const char *str_fileio, const char *str_mmapio, const char *str_devname, + int devunit) +{ + const char *cp; + device_t dev = sc->avg_dev; + + /* + * Check for valid combinations of options. + */ + if (str_fileio == NULL && str_mmapio == NULL) { + device_printf(dev, + "at least one of %s or %s must be specified\n", + ALTERA_AVALON_STR_FILEIO, ALTERA_AVALON_STR_MMAPIO); + return (ENXIO); + } + if (str_devname == NULL && devunit != -1) { + device_printf(dev, "%s requires %s be specified\n", + ALTERA_AVALON_STR_DEVUNIT, ALTERA_AVALON_STR_DEVNAME); + return (ENXIO); + } + + /* + * Extract, digest, and save values. + */ + switch (sc->avg_width) { + case 1: + case 2: + case 4: +#ifdef NOTYET + case 8: +#endif + break; + + default: + device_printf(dev, "%s unsupported value %u\n", + ALTERA_AVALON_STR_WIDTH, sc->avg_width); + return (ENXIO); + } + sc->avg_flags = 0; + if (str_fileio != NULL) { + for (cp = str_fileio; *cp != '\0'; cp++) { + switch (*cp) { + case ALTERA_AVALON_CHAR_READ: + sc->avg_flags |= ALTERA_AVALON_FLAG_READ; + break; + + case ALTERA_AVALON_CHAR_WRITE: + sc->avg_flags |= ALTERA_AVALON_FLAG_WRITE; + break; + + default: + device_printf(dev, + "invalid %s character %c\n", + ALTERA_AVALON_STR_FILEIO, *cp); + return (ENXIO); + } + } + } + if (str_mmapio != NULL) { + for (cp = str_mmapio; *cp != '\0'; cp++) { + switch (*cp) { + case ALTERA_AVALON_CHAR_READ: + sc->avg_flags |= ALTERA_AVALON_FLAG_MMAP_READ; + break; + + case ALTERA_AVALON_CHAR_WRITE: + sc->avg_flags |= + ALTERA_AVALON_FLAG_MMAP_WRITE; + break; + + case ALTERA_AVALON_CHAR_EXEC: + sc->avg_flags |= ALTERA_AVALON_FLAG_MMAP_EXEC; + break; + + default: + device_printf(dev, + "invalid %s character %c\n", + ALTERA_AVALON_STR_MMAPIO, *cp); + return (ENXIO); + } + } + } + return (0); +} + +static int +altera_avgen_nexus_attach(device_t dev) +{ + struct altera_avgen_softc *sc; + const char *str_fileio, *str_mmapio; + const char *str_devname; + char devname[SPECNAMELEN + 1]; + int devunit, error; + + sc = device_get_softc(dev); + sc->avg_dev = 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. + */ + 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); + error = altera_avgen_process_options(sc, str_fileio, str_mmapio, + str_devname, devunit); + if (error) + return (error); + + /* Select a device name. */ + if (str_devname != NULL) { + if (devunit != -1) + (void)snprintf(devname, sizeof(devname), "%s%d", + str_devname, devunit); + else + (void)snprintf(devname, sizeof(devname), "%s", + str_devname); + } else + snprintf(devname, sizeof(devname), "%s%d", "avgen", + sc->avg_unit); + + /* Memory allocation and checking. */ + sc->avg_rid = 0; + sc->avg_res = bus_alloc_resource_any(dev, SYS_RES_MEMORY, + &sc->avg_rid, RF_ACTIVE); + if (sc->avg_res == NULL) { + device_printf(dev, "couldn't map memory\n"); + return (ENXIO); + } + if (rman_get_size(sc->avg_res) >= PAGE_SIZE || str_mmapio != NULL) { + if (rman_get_size(sc->avg_res) % PAGE_SIZE != 0) { + device_printf(dev, + "memory region not even multiple of page size\n"); + error = ENXIO; + goto error; + } + if (rman_get_start(sc->avg_res) % PAGE_SIZE != 0) { + device_printf(dev, "memory region not page-aligned\n"); + error = ENXIO; + goto error; + } + } + + /* Device node allocation. */ + if (str_devname == NULL) { + str_devname = "altera_avgen%d"; + devunit = sc->avg_unit; + } + if (devunit != -1) + sc->avg_cdev = make_dev(&avg_cdevsw, sc->avg_unit, UID_ROOT, + GID_WHEEL, S_IRUSR | S_IWUSR, str_devname, devunit); + else + sc->avg_cdev = make_dev(&avg_cdevsw, sc->avg_unit, UID_ROOT, + GID_WHEEL, S_IRUSR | S_IWUSR, str_devname); + if (sc->avg_cdev == NULL) { + device_printf(sc->avg_dev, "%s: make_dev failed\n", __func__); + error = ENXIO; + goto error; + } + /* XXXRW: Slight race between make_dev(9) and here. */ + sc->avg_cdev->si_drv1 = sc; + return (0); + +error: + bus_release_resource(dev, SYS_RES_MEMORY, sc->avg_rid, sc->avg_res); + return (error); +} + +static int +altera_avgen_nexus_detach(device_t dev) +{ + struct altera_avgen_softc *sc; + + sc = device_get_softc(dev); + destroy_dev(sc->avg_cdev); + bus_release_resource(dev, SYS_RES_MEMORY, sc->avg_rid, sc->avg_res); + 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), + { 0, 0 } +}; + +static driver_t altera_avgen_nexus_driver = { + "altera_avgen", + altera_avgen_nexus_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); Added: head/sys/dev/altera/avgen/altera_avgen.h ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ head/sys/dev/altera/avgen/altera_avgen.h Sat Aug 25 11:07:43 2012 (r239674) @@ -0,0 +1,83 @@ +/*- + * Copyright (c) 2012 Robert N. M. Watson + * All rights reserved. + * + * This software was developed by SRI International and the University of + * Cambridge Computer Laboratory under DARPA/AFRL contract (FA8750-10-C-0237) + * ("CTSRD"), as part of the DARPA CRASH research programme. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#ifndef _DEV_ALTERA_AVALON_H_ +#define _DEV_ALTERA_AVALON_H_ + +struct altera_avgen_softc { + /* + * Bus-related fields. + */ + device_t avg_dev; + int avg_unit; + + /* + * The device node and memory-mapped I/O region. + */ + struct cdev *avg_cdev; + struct resource *avg_res; + int avg_rid; + + /* + * Access properties configured by device.hints. + */ + u_int avg_flags; + u_int avg_width; +}; + +/* + * Various flags extracted from device.hints to configure operations on the + * device. + */ +#define ALTERA_AVALON_FLAG_READ 0x01 +#define ALTERA_AVALON_FLAG_WRITE 0x02 +#define ALTERA_AVALON_FLAG_MMAP_READ 0x04 +#define ALTERA_AVALON_FLAG_MMAP_WRITE 0x08 +#define ALTERA_AVALON_FLAG_MMAP_EXEC 0x10 + +#define ALTERA_AVALON_CHAR_READ 'r' +#define ALTERA_AVALON_CHAR_WRITE 'w' +#define ALTERA_AVALON_CHAR_EXEC 'x' + +#define ALTERA_AVALON_STR_WIDTH "width" +#define ALTERA_AVALON_STR_FILEIO "fileio" +#define ALTERA_AVALON_STR_MMAPIO "mmapio" +#define ALTERA_AVALON_STR_DEVNAME "devname" +#define ALTERA_AVALON_STR_DEVUNIT "devunit" + +/* + * Driver setup routines from the bus attachment/teardown. + */ +int altera_avgen_attach(struct altera_avgen_softc *sc); +void altera_avgen_detach(struct altera_avgen_softc *sc); + +#endif /* _DEV_ALTERA_AVALON_H_ */
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201208251107.q7PB7hZR028266>