2 * Copyright (c) 2015 Oleksandr Tymoshenko <gonzo@freebsd.org>
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
13 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
14 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
17 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
19 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
20 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
21 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
22 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25 #include <sys/cdefs.h>
26 __FBSDID("$FreeBSD$");
28 #include <sys/param.h>
29 #include <sys/systm.h>
30 #include <sys/kernel.h>
31 #include <sys/malloc.h>
32 #include <sys/module.h>
33 #include <sys/ioccom.h>
37 #include <arm/broadcom/bcm2835/bcm2835_mbox_prop.h>
39 MALLOC_DECLARE(M_VCIO);
40 MALLOC_DEFINE(M_VCIO, "vcio", "VCIO temporary buffers");
42 static struct cdev *sdev;
43 static d_ioctl_t vcio_ioctl;
45 static struct cdevsw vcio_devsw = {
46 /* version */ .d_version = D_VERSION,
47 /* ioctl */ .d_ioctl = vcio_ioctl,
50 #define VCIO_IOC_MAGIC 100
51 #define IOCTL_MBOX_PROPERTY _IOWR(VCIO_IOC_MAGIC, 0, char *)
54 vcio_ioctl(struct cdev *dev, u_long cmd, caddr_t arg, int mode,
64 case IOCTL_MBOX_PROPERTY:
65 memcpy (&ptr, arg, sizeof(ptr));
66 error = copyin(ptr, &size, sizeof(size));
70 property = malloc(size, M_VCIO, M_WAITOK);
72 error = copyin(ptr, property, size);
74 free(property, M_VCIO);
78 error = bcm2835_mbox_property(property, size);
80 free(property, M_VCIO);
84 error = copyout(property, ptr, size);
85 free(property, M_VCIO);
96 vcio_load(module_t mod, int cmd, void *arg)
102 sdev = make_dev(&vcio_devsw, 0, UID_ROOT, GID_WHEEL, 0600, "vcio");
117 DEV_MODULE(vcio, vcio_load, NULL);
118 MODULE_DEPEND(vcio, mbox, 1, 1, 1);