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