Path: blob/main/sys/arm/broadcom/bcm2835/bcm2835_vcio.c
39566 views
/*-1* Copyright (c) 2015 Oleksandr Tymoshenko <[email protected]>2*3* Redistribution and use in source and binary forms, with or without4* modification, are permitted provided that the following conditions5* are met:6* 1. Redistributions of source code must retain the above copyright7* notice, this list of conditions and the following disclaimer.8* 2. Redistributions in binary form must reproduce the above copyright9* notice, this list of conditions and the following disclaimer in the10* documentation and/or other materials provided with the distribution.11*12* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND13* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE14* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE15* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE16* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL17* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS18* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)19* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT20* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY21* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF22* SUCH DAMAGE.23*/2425#include <sys/param.h>26#include <sys/systm.h>27#include <sys/kernel.h>28#include <sys/malloc.h>29#include <sys/module.h>30#include <sys/ioccom.h>31#include <sys/conf.h>32#include <sys/proc.h>3334#include <arm/broadcom/bcm2835/bcm2835_mbox_prop.h>3536MALLOC_DECLARE(M_VCIO);37MALLOC_DEFINE(M_VCIO, "vcio", "VCIO temporary buffers");3839static struct cdev *sdev;40static d_ioctl_t vcio_ioctl;4142static struct cdevsw vcio_devsw = {43/* version */ .d_version = D_VERSION,44/* ioctl */ .d_ioctl = vcio_ioctl,45};4647#define VCIO_IOC_MAGIC 10048#define IOCTL_MBOX_PROPERTY _IOWR(VCIO_IOC_MAGIC, 0, char *)4950int51vcio_ioctl(struct cdev *dev, u_long cmd, caddr_t arg, int mode,52struct thread *td)53{54int error;55void *ptr;56uint32_t size;57uint8_t *property;5859error = 0;60switch(cmd) {61case IOCTL_MBOX_PROPERTY:62memcpy (&ptr, arg, sizeof(ptr));63error = copyin(ptr, &size, sizeof(size));6465if (error != 0)66break;67property = malloc(size, M_VCIO, M_WAITOK);6869error = copyin(ptr, property, size);70if (error) {71free(property, M_VCIO);72break;73}7475error = bcm2835_mbox_property(property, size);76if (error) {77free(property, M_VCIO);78break;79}8081error = copyout(property, ptr, size);82free(property, M_VCIO);8384break;85default:86error = EINVAL;87break;88}89return (error);90}9192static int93vcio_load(module_t mod, int cmd, void *arg)94{95int err = 0;9697switch (cmd) {98case MOD_LOAD:99sdev = make_dev(&vcio_devsw, 0, UID_ROOT, GID_WHEEL, 0600, "vcio");100break;101102case MOD_UNLOAD:103destroy_dev(sdev);104break;105106default:107err = EOPNOTSUPP;108break;109}110111return(err);112}113114DEV_MODULE(vcio, vcio_load, NULL);115MODULE_DEPEND(vcio, mbox, 1, 1, 1);116117118