Deleted Added
sdiff udiff text old ( 239674 ) new ( 245376 )
full compact
1/*-
2 * Copyright (c) 2012-2013 Robert N. M. Watson
3 * All rights reserved.
4 *
5 * This software was developed by SRI International and the University of
6 * Cambridge Computer Laboratory under DARPA/AFRL contract (FA8750-10-C-0237)
7 * ("CTSRD"), as part of the DARPA CRASH research programme.
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions

--- 13 unchanged lines hidden (view full) ---

24 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28 * SUCH DAMAGE.
29 */
30
31#include <sys/cdefs.h>
32__FBSDID("$FreeBSD: head/sys/dev/altera/avgen/altera_avgen.c 245376 2013-01-13 16:43:59Z rwatson $");
33
34#include <sys/param.h>
35#include <sys/bus.h>
36#include <sys/condvar.h>
37#include <sys/conf.h>
38#include <sys/kernel.h>
39#include <sys/lock.h>
40#include <sys/malloc.h>

--- 180 unchanged lines hidden (view full) ---

221 rman_get_size(sc->avg_res) >= offset + PAGE_SIZE) {
222 *paddr = rman_get_start(sc->avg_res) + offset;
223 *memattr = VM_MEMATTR_UNCACHEABLE;
224 } else
225 return (ENODEV);
226 return (0);
227}
228
229
230static int
231altera_avgen_process_options(struct altera_avgen_softc *sc,
232 const char *str_fileio, const char *str_mmapio, const char *str_devname,
233 int devunit)
234{
235 const char *cp;
236 device_t dev = sc->avg_dev;
237

--- 71 unchanged lines hidden (view full) ---

309 ALTERA_AVALON_STR_MMAPIO, *cp);
310 return (ENXIO);
311 }
312 }
313 }
314 return (0);
315}
316
317int
318altera_avgen_attach(struct altera_avgen_softc *sc, const char *str_fileio,
319 const char *str_mmapio, const char *str_devname, int devunit)
320{
321 device_t dev = sc->avg_dev;
322 char devname[SPECNAMELEN + 1];
323 int error;
324
325 error = altera_avgen_process_options(sc, str_fileio, str_mmapio,
326 str_devname, devunit);
327 if (error)
328 return (error);
329
330 /* Select a device name. */
331 if (str_devname != NULL) {
332 if (devunit != -1)
333 (void)snprintf(devname, sizeof(devname), "%s%d",
334 str_devname, devunit);
335 else
336 (void)snprintf(devname, sizeof(devname), "%s",
337 str_devname);
338 } else
339 snprintf(devname, sizeof(devname), "%s%d", "avgen",
340 sc->avg_unit);
341
342 if (rman_get_size(sc->avg_res) >= PAGE_SIZE || str_mmapio != NULL) {
343 if (rman_get_size(sc->avg_res) % PAGE_SIZE != 0) {
344 device_printf(dev,
345 "memory region not even multiple of page size\n");
346 return (ENXIO);
347 }
348 if (rman_get_start(sc->avg_res) % PAGE_SIZE != 0) {
349 device_printf(dev, "memory region not page-aligned\n");
350 return (ENXIO);
351 }
352 }
353
354 /* Device node allocation. */
355 if (str_devname == NULL) {
356 str_devname = "altera_avgen%d";
357 devunit = sc->avg_unit;
358 }
359 if (devunit != -1)
360 sc->avg_cdev = make_dev(&avg_cdevsw, sc->avg_unit, UID_ROOT,
361 GID_WHEEL, S_IRUSR | S_IWUSR, str_devname, devunit);
362 else
363 sc->avg_cdev = make_dev(&avg_cdevsw, sc->avg_unit, UID_ROOT,
364 GID_WHEEL, S_IRUSR | S_IWUSR, str_devname);
365 if (sc->avg_cdev == NULL) {
366 device_printf(sc->avg_dev, "%s: make_dev failed\n", __func__);
367 return (ENXIO);
368 }
369 /* XXXRW: Slight race between make_dev(9) and here. */
370 sc->avg_cdev->si_drv1 = sc;
371 return (0);
372}
373
374void
375altera_avgen_detach(struct altera_avgen_softc *sc)
376{
377
378 destroy_dev(sc->avg_cdev);
379}