xref: /freebsd/sys/dev/syscons/scvesactl.c (revision 9336e0699bda8a301cd2bfa37106b6ec5e32012e)
1 /*-
2  * Copyright (c) 1998 Kazutaka YOKOTA <yokota@zodiac.mech.utsunomiya-u.ac.jp>
3  * All rights reserved.
4  *
5  * This code is derived from software contributed to The DragonFly Project
6  * by Sascha Wildner <saw@online.de>
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  * 1. Redistributions of source code must retain the above copyright
12  *    notice, this list of conditions and the following disclaimer as
13  *    the first lines of this file unmodified.
14  * 2. Redistributions in binary form must reproduce the above copyright
15  *    notice, this list of conditions and the following disclaimer in the
16  *    documentation and/or other materials provided with the distribution.
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
23  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28  *
29  */
30 
31 #include <sys/cdefs.h>
32 __FBSDID("$FreeBSD$");
33 
34 #include "opt_vga.h"
35 
36 #ifndef VGA_NO_MODE_CHANGE
37 
38 #include <sys/param.h>
39 #include <sys/systm.h>
40 #include <sys/conf.h>
41 #include <sys/tty.h>
42 #include <sys/kernel.h>
43 #include <sys/fbio.h>
44 #include <sys/consio.h>
45 
46 #include <machine/pc/vesa.h>
47 
48 #include <dev/fb/fbreg.h>
49 #include <dev/syscons/syscons.h>
50 
51 static d_ioctl_t *prev_user_ioctl;
52 
53 static int
54 vesa_ioctl(struct cdev *dev, u_long cmd, caddr_t data, int flag, struct thread *td)
55 {
56 	scr_stat *scp;
57 	struct tty *tp;
58 	int mode;
59 
60 	tp = dev->si_tty;
61 	if (!tp)
62 		return ENXIO;
63 	scp = SC_STAT(tp->t_dev);
64 
65 	switch (cmd) {
66 
67 	/* generic text modes */
68 	case SW_TEXT_132x25: case SW_TEXT_132x30:
69 	case SW_TEXT_132x43: case SW_TEXT_132x50:
70 	case SW_TEXT_132x60:
71 		if (!(scp->sc->adp->va_flags & V_ADP_MODECHANGE))
72 			return ENODEV;
73 		return sc_set_text_mode(scp, tp, cmd & 0xff, 0, 0, 0, 0);
74 
75 	/* text modes */
76 	case SW_VESA_C80x60:
77 	case SW_VESA_C132x25:
78 	case SW_VESA_C132x43:
79 	case SW_VESA_C132x50:
80 	case SW_VESA_C132x60:
81 		if (!(scp->sc->adp->va_flags & V_ADP_MODECHANGE))
82 			return ENODEV;
83 		mode = (cmd & 0xff) + M_VESA_BASE;
84 		return sc_set_text_mode(scp, tp, mode, 0, 0, 0, 0);
85 
86 	/* graphics modes */
87 	case SW_VESA_32K_320: 	case SW_VESA_64K_320:
88 	case SW_VESA_FULL_320:
89 
90 	case SW_VESA_CG640x400:
91 
92 	case SW_VESA_CG640x480:
93 	case SW_VESA_32K_640:	case SW_VESA_64K_640:
94 	case SW_VESA_FULL_640:
95 
96 	case SW_VESA_800x600:	case SW_VESA_CG800x600:
97 	case SW_VESA_32K_800:	case SW_VESA_64K_800:
98 	case SW_VESA_FULL_800:
99 
100 	case SW_VESA_1024x768:	case SW_VESA_CG1024x768:
101 	case SW_VESA_32K_1024:	case SW_VESA_64K_1024:
102 	case SW_VESA_FULL_1024:
103 
104 	case SW_VESA_1280x1024:	case SW_VESA_CG1280x1024:
105 	case SW_VESA_32K_1280:	case SW_VESA_64K_1280:
106 	case SW_VESA_FULL_1280:
107 		if (!(scp->sc->adp->va_flags & V_ADP_MODECHANGE))
108 			return ENODEV;
109 		mode = (cmd & 0xff) + M_VESA_BASE;
110 		return sc_set_graphics_mode(scp, tp, mode);
111 	default:
112 		if (IOCGROUP(cmd) == 'V') {
113 			if (!(scp->sc->adp->va_flags & V_ADP_MODECHANGE))
114 				return ENODEV;
115 
116 			mode = (cmd & 0xff) + M_VESA_BASE;
117 
118 			if (((cmd & IOC_DIRMASK) == IOC_VOID) &&
119 			    (mode > M_VESA_FULL_1280) &&
120 			    (mode < M_VESA_MODE_MAX))
121 				return sc_set_graphics_mode(scp, tp, mode);
122 		}
123 	}
124 
125 	if (prev_user_ioctl)
126 		return (*prev_user_ioctl)(dev, cmd, data, flag, td);
127 	else
128 		return ENOIOCTL;
129 }
130 
131 int
132 vesa_load_ioctl(void)
133 {
134 	if (prev_user_ioctl)
135 		return EBUSY;
136 	prev_user_ioctl = sc_user_ioctl;
137 	sc_user_ioctl = vesa_ioctl;
138 	return 0;
139 }
140 
141 int
142 vesa_unload_ioctl(void)
143 {
144 	if (sc_user_ioctl != vesa_ioctl)
145 		return EBUSY;
146 	sc_user_ioctl = prev_user_ioctl;
147 	prev_user_ioctl = NULL;
148 	return 0;
149 }
150 
151 #endif /* VGA_NO_MODE_CHANGE */
152