/*-1* SPDX-License-Identifier: BSD-2-Clause2*3* Copyright (c) 2002 Scott Long4* Copyright (c) 2002-2010 Adaptec, Inc.5* Copyright (c) 2010-2012 PMC-Sierra, Inc.6* All rights reserved.7*8* Redistribution and use in source and binary forms, with or without9* modification, are permitted provided that the following conditions10* are met:11* 1. Redistributions of source code must retain the above copyright12* notice, this list of conditions and the following disclaimer.13* 2. Redistributions in binary form must reproduce the above copyright14* notice, this list of conditions and the following disclaimer in the15* documentation and/or other materials provided with the distribution.16*17* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND18* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE19* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE20* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE21* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL22* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS23* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)24* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT25* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY26* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF27* SUCH DAMAGE.28*/2930#include <sys/cdefs.h>31/*32* Linux ioctl handler for the aac device driver33*/3435#include <sys/param.h>36#include <sys/capsicum.h>37#include <sys/systm.h>38#include <sys/conf.h>39#include <sys/kernel.h>40#include <sys/module.h>41#include <sys/file.h>42#include <sys/proc.h>43#ifdef __amd64__44#include <machine/../linux32/linux.h>45#include <machine/../linux32/linux32_proto.h>46#else47#include <machine/../linux/linux.h>48#include <machine/../linux/linux_proto.h>49#endif50#include <compat/linux/linux_ioctl.h>5152/* There are multiple ioctl number ranges that need to be handled */53#define AAC_LINUX_IOCTL_MIN 0x000054#define AAC_LINUX_IOCTL_MAX 0x21ff5556static linux_ioctl_function_t aacraid_linux_ioctl;57static struct linux_ioctl_handler aacraid_linux_handler = {aacraid_linux_ioctl,58AAC_LINUX_IOCTL_MIN,59AAC_LINUX_IOCTL_MAX};6061SYSINIT (aacraid_linux_register, SI_SUB_KLD, SI_ORDER_MIDDLE,62linux_ioctl_register_handler, &aacraid_linux_handler);63SYSUNINIT(aacraid_linux_unregister, SI_SUB_KLD, SI_ORDER_MIDDLE,64linux_ioctl_unregister_handler, &aacraid_linux_handler);6566static int67aacraid_linux_modevent(module_t mod, int type, void *data)68{69/* Do we care about any specific load/unload actions? */70return (0);71}7273DEV_MODULE(aacraid_linux, aacraid_linux_modevent, NULL);74MODULE_DEPEND(aacraid_linux, linux, 1, 1, 1);7576static int77aacraid_linux_ioctl(struct thread *td, struct linux_ioctl_args *args)78{79struct file *fp;80cap_rights_t rights;81u_long cmd;82int error;8384if ((error = fget(td, args->fd,85cap_rights_init_one(&rights, CAP_IOCTL),86&fp)) != 0) {87return (error);88}89cmd = args->cmd;9091/*92* Pass the ioctl off to our standard handler.93*/94error = (fo_ioctl(fp, cmd, (caddr_t)args->arg, td->td_ucred, td));95fdrop(fp, td);96return (error);97}9899100