1375ce679SYaroslav Tykhiy /*-
24d846d26SWarner Losh * SPDX-License-Identifier: BSD-2-Clause
3718cf2ccSPedro F. Giffuni *
4375ce679SYaroslav Tykhiy * Copyright (c) 2006 The FreeBSD Project
5375ce679SYaroslav Tykhiy * All rights reserved.
6375ce679SYaroslav Tykhiy *
7375ce679SYaroslav Tykhiy * Redistribution and use in source and binary forms, with or without
8375ce679SYaroslav Tykhiy * modification, are permitted provided that the following conditions
9375ce679SYaroslav Tykhiy * are met:
10375ce679SYaroslav Tykhiy * 1. Redistributions of source code must retain the above copyright
11375ce679SYaroslav Tykhiy * notice, this list of conditions and the following disclaimer.
12375ce679SYaroslav Tykhiy * 2. Redistributions in binary form must reproduce the above copyright
13375ce679SYaroslav Tykhiy * notice, this list of conditions and the following disclaimer in the
14375ce679SYaroslav Tykhiy * documentation and/or other materials provided with the distribution.
15375ce679SYaroslav Tykhiy *
16375ce679SYaroslav Tykhiy * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17375ce679SYaroslav Tykhiy * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18375ce679SYaroslav Tykhiy * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19375ce679SYaroslav Tykhiy * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20375ce679SYaroslav Tykhiy * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21375ce679SYaroslav Tykhiy * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22375ce679SYaroslav Tykhiy * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23375ce679SYaroslav Tykhiy * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24375ce679SYaroslav Tykhiy * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25375ce679SYaroslav Tykhiy * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26375ce679SYaroslav Tykhiy * SUCH DAMAGE.
27375ce679SYaroslav Tykhiy */
28375ce679SYaroslav Tykhiy
29375ce679SYaroslav Tykhiy #include <sys/param.h>
304a144410SRobert Watson #include <sys/capsicum.h>
31375ce679SYaroslav Tykhiy #include <sys/file.h>
32375ce679SYaroslav Tykhiy #include <sys/kernel.h>
33375ce679SYaroslav Tykhiy #include <sys/module.h>
34375ce679SYaroslav Tykhiy #include <sys/proc.h>
35375ce679SYaroslav Tykhiy #include <sys/systm.h>
36375ce679SYaroslav Tykhiy
37375ce679SYaroslav Tykhiy #include <dev/tdfx/tdfx_linux.h>
38375ce679SYaroslav Tykhiy
39375ce679SYaroslav Tykhiy LINUX_IOCTL_SET(tdfx, LINUX_IOCTL_TDFX_MIN, LINUX_IOCTL_TDFX_MAX);
40375ce679SYaroslav Tykhiy
41375ce679SYaroslav Tykhiy /*
42375ce679SYaroslav Tykhiy * Linux emulation IOCTL for /dev/tdfx
43375ce679SYaroslav Tykhiy */
44375ce679SYaroslav Tykhiy static int
linux_ioctl_tdfx(struct thread * td,struct linux_ioctl_args * args)45375ce679SYaroslav Tykhiy linux_ioctl_tdfx(struct thread *td, struct linux_ioctl_args* args)
46375ce679SYaroslav Tykhiy {
477008be5bSPawel Jakub Dawidek cap_rights_t rights;
48375ce679SYaroslav Tykhiy int error = 0;
49375ce679SYaroslav Tykhiy u_long cmd = args->cmd & 0xffff;
50375ce679SYaroslav Tykhiy
51375ce679SYaroslav Tykhiy /* The structure passed to ioctl has two shorts, one int
52375ce679SYaroslav Tykhiy and one void*. */
53375ce679SYaroslav Tykhiy char d_pio[2*sizeof(short) + sizeof(int) + sizeof(void*)];
54375ce679SYaroslav Tykhiy
55375ce679SYaroslav Tykhiy struct file *fp;
56375ce679SYaroslav Tykhiy
576b3a9a0fSMateusz Guzik error = fget(td, args->fd, cap_rights_init_one(&rights, CAP_IOCTL), &fp);
587008be5bSPawel Jakub Dawidek if (error != 0)
59375ce679SYaroslav Tykhiy return (error);
60375ce679SYaroslav Tykhiy /* We simply copy the data and send it right to ioctl */
61*2873d841SMark Johnston error = copyin((caddr_t)args->arg, &d_pio, sizeof(d_pio));
62*2873d841SMark Johnston if (error == 0)
63375ce679SYaroslav Tykhiy error = fo_ioctl(fp, cmd, (caddr_t)&d_pio, td->td_ucred, td);
64375ce679SYaroslav Tykhiy fdrop(fp, td);
65375ce679SYaroslav Tykhiy return error;
66375ce679SYaroslav Tykhiy }
67375ce679SYaroslav Tykhiy
68375ce679SYaroslav Tykhiy static int
tdfx_linux_modevent(struct module * mod __unused,int what,void * arg __unused)69375ce679SYaroslav Tykhiy tdfx_linux_modevent(struct module *mod __unused, int what, void *arg __unused)
70375ce679SYaroslav Tykhiy {
71375ce679SYaroslav Tykhiy
72375ce679SYaroslav Tykhiy switch (what) {
73375ce679SYaroslav Tykhiy case MOD_LOAD:
74375ce679SYaroslav Tykhiy case MOD_UNLOAD:
75375ce679SYaroslav Tykhiy return (0);
76375ce679SYaroslav Tykhiy }
77375ce679SYaroslav Tykhiy return (EOPNOTSUPP);
78375ce679SYaroslav Tykhiy }
79375ce679SYaroslav Tykhiy
80375ce679SYaroslav Tykhiy static moduledata_t tdfx_linux_mod = {
81375ce679SYaroslav Tykhiy "tdfx_linux",
82375ce679SYaroslav Tykhiy tdfx_linux_modevent,
839823d527SKevin Lo 0
84375ce679SYaroslav Tykhiy };
85375ce679SYaroslav Tykhiy
86375ce679SYaroslav Tykhiy /* As in SYSCALL_MODULE */
87375ce679SYaroslav Tykhiy DECLARE_MODULE(tdfx_linux, tdfx_linux_mod, SI_SUB_DRIVERS, SI_ORDER_MIDDLE);
88375ce679SYaroslav Tykhiy MODULE_VERSION(tdfx_linux, 1);
89375ce679SYaroslav Tykhiy MODULE_DEPEND(tdfx_linux, tdfx, 1, 1, 1);
90375ce679SYaroslav Tykhiy MODULE_DEPEND(tdfx_linux, linux, 1, 1, 1);
91