1156260Syar/*- 2156260Syar * Copyright (c) 2006 The FreeBSD Project 3156260Syar * All rights reserved. 4156260Syar * 5156260Syar * Redistribution and use in source and binary forms, with or without 6156260Syar * modification, are permitted provided that the following conditions 7156260Syar * are met: 8156260Syar * 1. Redistributions of source code must retain the above copyright 9156260Syar * notice, this list of conditions and the following disclaimer. 10156260Syar * 2. Redistributions in binary form must reproduce the above copyright 11156260Syar * notice, this list of conditions and the following disclaimer in the 12156260Syar * documentation and/or other materials provided with the distribution. 13156260Syar * 14156260Syar * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 15156260Syar * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16156260Syar * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17156260Syar * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 18156260Syar * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19156260Syar * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20156260Syar * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21156260Syar * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22156260Syar * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23156260Syar * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24156260Syar * SUCH DAMAGE. 25156260Syar */ 26156260Syar 27156260Syar#include <sys/cdefs.h> 28156260Syar__FBSDID("$FreeBSD$"); 29156260Syar 30156260Syar#include <sys/param.h> 31224778Srwatson#include <sys/capability.h> 32156260Syar#include <sys/file.h> 33156260Syar#include <sys/kernel.h> 34156260Syar#include <sys/module.h> 35156260Syar#include <sys/proc.h> 36156260Syar#include <sys/systm.h> 37156260Syar 38156260Syar#include <dev/tdfx/tdfx_linux.h> 39156260Syar 40156260SyarLINUX_IOCTL_SET(tdfx, LINUX_IOCTL_TDFX_MIN, LINUX_IOCTL_TDFX_MAX); 41156260Syar 42156260Syar/* 43156260Syar * Linux emulation IOCTL for /dev/tdfx 44156260Syar */ 45156260Syarstatic int 46156260Syarlinux_ioctl_tdfx(struct thread *td, struct linux_ioctl_args* args) 47156260Syar{ 48255219Spjd cap_rights_t rights; 49156260Syar int error = 0; 50156260Syar u_long cmd = args->cmd & 0xffff; 51156260Syar 52156260Syar /* The structure passed to ioctl has two shorts, one int 53156260Syar and one void*. */ 54156260Syar char d_pio[2*sizeof(short) + sizeof(int) + sizeof(void*)]; 55156260Syar 56156260Syar struct file *fp; 57156260Syar 58255219Spjd error = fget(td, args->fd, cap_rights_init(&rights, CAP_IOCTL), &fp); 59255219Spjd if (error != 0) 60156260Syar return (error); 61156260Syar /* We simply copy the data and send it right to ioctl */ 62156260Syar copyin((caddr_t)args->arg, &d_pio, sizeof(d_pio)); 63156260Syar error = fo_ioctl(fp, cmd, (caddr_t)&d_pio, td->td_ucred, td); 64156260Syar fdrop(fp, td); 65156260Syar return error; 66156260Syar} 67156260Syar 68156260Syarstatic int 69156260Syartdfx_linux_modevent(struct module *mod __unused, int what, void *arg __unused) 70156260Syar{ 71156260Syar 72156260Syar switch (what) { 73156260Syar case MOD_LOAD: 74156260Syar case MOD_UNLOAD: 75156260Syar return (0); 76156260Syar } 77156260Syar return (EOPNOTSUPP); 78156260Syar} 79156260Syar 80156260Syarstatic moduledata_t tdfx_linux_mod = { 81156260Syar "tdfx_linux", 82156260Syar tdfx_linux_modevent, 83241394Skevlo 0 84156260Syar}; 85156260Syar 86156260Syar/* As in SYSCALL_MODULE */ 87156260SyarDECLARE_MODULE(tdfx_linux, tdfx_linux_mod, SI_SUB_DRIVERS, SI_ORDER_MIDDLE); 88156260SyarMODULE_VERSION(tdfx_linux, 1); 89156260SyarMODULE_DEPEND(tdfx_linux, tdfx, 1, 1, 1); 90156260SyarMODULE_DEPEND(tdfx_linux, linux, 1, 1, 1); 91