17419815dSScott Long /*-
2*4d846d26SWarner Losh * SPDX-License-Identifier: BSD-2-Clause
3718cf2ccSPedro F. Giffuni *
47419815dSScott Long * Copyright (c) 2002 Scott Long
57419815dSScott Long * All rights reserved.
67419815dSScott Long *
77419815dSScott Long * Redistribution and use in source and binary forms, with or without
87419815dSScott Long * modification, are permitted provided that the following conditions
97419815dSScott Long * are met:
107419815dSScott Long * 1. Redistributions of source code must retain the above copyright
117419815dSScott Long * notice, this list of conditions and the following disclaimer.
127419815dSScott Long * 2. Redistributions in binary form must reproduce the above copyright
137419815dSScott Long * notice, this list of conditions and the following disclaimer in the
147419815dSScott Long * documentation and/or other materials provided with the distribution.
157419815dSScott Long *
167419815dSScott Long * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
177419815dSScott Long * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
187419815dSScott Long * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
197419815dSScott Long * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
207419815dSScott Long * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
217419815dSScott Long * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
227419815dSScott Long * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
237419815dSScott Long * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
247419815dSScott Long * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
257419815dSScott Long * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
267419815dSScott Long * SUCH DAMAGE.
277419815dSScott Long */
287419815dSScott Long
29aad970f1SDavid E. O'Brien #include <sys/cdefs.h>
307419815dSScott Long /*
317419815dSScott Long * Linux ioctl handler for the aac device driver
327419815dSScott Long */
337419815dSScott Long
347419815dSScott Long #include <sys/param.h>
357419815dSScott Long #include <sys/systm.h>
364a144410SRobert Watson #include <sys/capsicum.h>
377419815dSScott Long #include <sys/conf.h>
387419815dSScott Long #include <sys/kernel.h>
39fe12f24bSPoul-Henning Kamp #include <sys/module.h>
407419815dSScott Long #include <sys/file.h>
417419815dSScott Long #include <sys/proc.h>
42ca7d6243SXin LI #ifdef __amd64__
43ca7d6243SXin LI #include <machine/../linux32/linux.h>
44ca7d6243SXin LI #include <machine/../linux32/linux32_proto.h>
45ca7d6243SXin LI #else
467419815dSScott Long #include <machine/../linux/linux.h>
477419815dSScott Long #include <machine/../linux/linux_proto.h>
48ca7d6243SXin LI #endif
497419815dSScott Long #include <compat/linux/linux_ioctl.h>
507419815dSScott Long
517419815dSScott Long /* There are multiple ioctl number ranges that need to be handled */
527419815dSScott Long #define AAC_LINUX_IOCTL_MIN 0x0000
537419815dSScott Long #define AAC_LINUX_IOCTL_MAX 0x21ff
547419815dSScott Long
557419815dSScott Long static linux_ioctl_function_t aac_linux_ioctl;
567419815dSScott Long static struct linux_ioctl_handler aac_linux_handler = {aac_linux_ioctl,
577419815dSScott Long AAC_LINUX_IOCTL_MIN,
587419815dSScott Long AAC_LINUX_IOCTL_MAX};
597419815dSScott Long
607419815dSScott Long SYSINIT (aac_linux_register, SI_SUB_KLD, SI_ORDER_MIDDLE,
617419815dSScott Long linux_ioctl_register_handler, &aac_linux_handler);
627419815dSScott Long SYSUNINIT(aac_linux_unregister, SI_SUB_KLD, SI_ORDER_MIDDLE,
637419815dSScott Long linux_ioctl_unregister_handler, &aac_linux_handler);
647419815dSScott Long
657419815dSScott Long static int
aac_linux_modevent(module_t mod,int type,void * data)667419815dSScott Long aac_linux_modevent(module_t mod, int type, void *data)
677419815dSScott Long {
687419815dSScott Long /* Do we care about any specific load/unload actions? */
697419815dSScott Long return (0);
707419815dSScott Long }
717419815dSScott Long
727419815dSScott Long DEV_MODULE(aac_linux, aac_linux_modevent, NULL);
737419815dSScott Long MODULE_DEPEND(aac_linux, linux, 1, 1, 1);
747419815dSScott Long
757419815dSScott Long static int
aac_linux_ioctl(struct thread * td,struct linux_ioctl_args * args)767419815dSScott Long aac_linux_ioctl(struct thread *td, struct linux_ioctl_args *args)
777419815dSScott Long {
787008be5bSPawel Jakub Dawidek cap_rights_t rights;
797419815dSScott Long struct file *fp;
807419815dSScott Long u_long cmd;
817419815dSScott Long int error;
827419815dSScott Long
836b3a9a0fSMateusz Guzik error = fget(td, args->fd, cap_rights_init_one(&rights, CAP_IOCTL),
846b3a9a0fSMateusz Guzik &fp);
857008be5bSPawel Jakub Dawidek if (error != 0)
867419815dSScott Long return (error);
877419815dSScott Long cmd = args->cmd;
887419815dSScott Long
897419815dSScott Long /*
907419815dSScott Long * Pass the ioctl off to our standard handler.
917419815dSScott Long */
927419815dSScott Long error = (fo_ioctl(fp, cmd, (caddr_t)args->arg, td->td_ucred, td));
937419815dSScott Long fdrop(fp, td);
947419815dSScott Long return (error);
957419815dSScott Long }
96