1219888Sed/*-
2219888Sed * Copyright (c) 2009 The FreeBSD Foundation
3219888Sed * All rights reserved.
4219888Sed *
5219888Sed * This software was developed by Ed Schouten under sponsorship from the
6219888Sed * FreeBSD Foundation.
7219888Sed *
8219888Sed * Redistribution and use in source and binary forms, with or without
9219888Sed * modification, are permitted provided that the following conditions
10219888Sed * are met:
11219888Sed * 1. Redistributions of source code must retain the above copyright
12219888Sed *    notice, this list of conditions and the following disclaimer.
13219888Sed * 2. Redistributions in binary form must reproduce the above copyright
14219888Sed *    notice, this list of conditions and the following disclaimer in the
15219888Sed *    documentation and/or other materials provided with the distribution.
16219888Sed *
17219888Sed * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18219888Sed * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19219888Sed * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20219888Sed * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
21219888Sed * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22219888Sed * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23219888Sed * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24219888Sed * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25219888Sed * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26219888Sed * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27219888Sed * SUCH DAMAGE.
28219888Sed */
29219888Sed
30219888Sed#include <sys/cdefs.h>
31219888Sed__FBSDID("$FreeBSD$");
32219888Sed
33219888Sed#include <sys/param.h>
34219888Sed#include <sys/consio.h>
35219888Sed#include <sys/kernel.h>
36219888Sed#include <sys/systm.h>
37219888Sed
38219888Sed#include <dev/vt/vt.h>
39219888Sed
40219888Sedstatic d_ioctl_t	consolectl_ioctl;
41219888Sed
42219888Sedstatic struct cdevsw consolectl_cdevsw = {
43219888Sed	.d_version	= D_VERSION,
44219888Sed	.d_ioctl	= consolectl_ioctl,
45219888Sed	.d_name		= "consolectl",
46219888Sed};
47219888Sed
48219888Sedstatic int
49219888Sedconsolectl_ioctl(struct cdev *dev, u_long cmd, caddr_t data, int flag,
50219888Sed    struct thread *td)
51219888Sed{
52219888Sed
53219888Sed	switch (cmd) {
54271952Sray	case CONS_GETVERS:
55219888Sed		*(int*)data = 0x200;
56219888Sed		return 0;
57219888Sed	case CONS_MOUSECTL: {
58219888Sed		mouse_info_t *mi = (mouse_info_t*)data;
59219888Sed
60219888Sed		sysmouse_process_event(mi);
61219888Sed		return (0);
62219888Sed	}
63219888Sed	default:
64267538Sray#ifdef VT_CONSOLECTL_DEBUG
65219888Sed		printf("consolectl: unknown ioctl: %c:%lx\n",
66219888Sed		    (char)IOCGROUP(cmd), IOCBASECMD(cmd));
67267538Sray#endif
68219888Sed		return (ENOIOCTL);
69219888Sed	}
70219888Sed}
71219888Sed
72219888Sedstatic void
73219888Sedconsolectl_drvinit(void *unused)
74219888Sed{
75219888Sed
76268366Sray	if (!vty_enabled(VTY_VT))
77268366Sray		return;
78219888Sed	make_dev(&consolectl_cdevsw, 0, UID_ROOT, GID_WHEEL, 0600,
79219888Sed	    "consolectl");
80219888Sed}
81219888Sed
82219888SedSYSINIT(consolectl, SI_SUB_DRIVERS, SI_ORDER_MIDDLE, consolectl_drvinit, NULL);
83