1 /*- 2 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD 3 * 4 * Copyright (c) 2009 The FreeBSD Foundation 5 * All rights reserved. 6 * 7 * This software was developed by Ed Schouten under sponsorship from the 8 * FreeBSD Foundation. 9 * 10 * Redistribution and use in source and binary forms, with or without 11 * modification, are permitted provided that the following conditions 12 * are met: 13 * 1. Redistributions of source code must retain the above copyright 14 * notice, this list of conditions and the following disclaimer. 15 * 2. Redistributions in binary form must reproduce the above copyright 16 * notice, this list of conditions and the following disclaimer in the 17 * documentation and/or other materials provided with the distribution. 18 * 19 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 29 * SUCH DAMAGE. 30 */ 31 32 #include <sys/cdefs.h> 33 __FBSDID("$FreeBSD$"); 34 35 #include <sys/param.h> 36 #include <sys/consio.h> 37 #include <sys/kernel.h> 38 #include <sys/systm.h> 39 40 #include <dev/vt/vt.h> 41 42 static d_ioctl_t consolectl_ioctl; 43 44 static struct cdevsw consolectl_cdevsw = { 45 .d_version = D_VERSION, 46 .d_ioctl = consolectl_ioctl, 47 .d_name = "consolectl", 48 }; 49 50 static int 51 consolectl_ioctl(struct cdev *dev, u_long cmd, caddr_t data, int flag, 52 struct thread *td) 53 { 54 55 switch (cmd) { 56 case CONS_GETVERS: 57 *(int*)data = 0x200; 58 return 0; 59 case CONS_MOUSECTL: { 60 mouse_info_t *mi = (mouse_info_t*)data; 61 62 sysmouse_process_event(mi); 63 return (0); 64 } 65 default: 66 #ifdef VT_CONSOLECTL_DEBUG 67 printf("consolectl: unknown ioctl: %c:%lx\n", 68 (char)IOCGROUP(cmd), IOCBASECMD(cmd)); 69 #endif 70 return (ENOIOCTL); 71 } 72 } 73 74 static void 75 consolectl_drvinit(void *unused) 76 { 77 78 if (!vty_enabled(VTY_VT)) 79 return; 80 make_dev(&consolectl_cdevsw, 0, UID_ROOT, GID_WHEEL, 0600, 81 "consolectl"); 82 } 83 84 SYSINIT(consolectl, SI_SUB_DRIVERS, SI_ORDER_MIDDLE, consolectl_drvinit, NULL); 85