xref: /freebsd/sys/dev/syscons/scvesactl.c (revision 4cf49a43559ed9fdad601bdcccd2c55963008675)
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  * $FreeBSD$
27  */
28 
29 #include "sc.h"
30 #include "vga.h"
31 #include "opt_syscons.h"
32 #include "opt_vga.h"
33 #include "opt_vesa.h"
34 
35 #ifdef VGA_NO_MODE_CHANGE
36 #undef VESA
37 #endif
38 
39 #if (NSC > 0 && NVGA > 0 && defined(VESA)) || defined(KLD_MODULE)
40 
41 #include <sys/param.h>
42 #include <sys/systm.h>
43 #include <sys/conf.h>
44 #include <sys/tty.h>
45 #include <sys/kernel.h>
46 
47 #include <machine/console.h>
48 #include <machine/pc/vesa.h>
49 
50 #include <dev/fb/fbreg.h>
51 #include <dev/syscons/syscons.h>
52 
53 static d_ioctl_t *prev_user_ioctl;
54 
55 static int
56 vesa_ioctl(dev_t dev, u_long cmd, caddr_t data, int flag, struct proc *p)
57 {
58 	scr_stat *scp;
59 	struct tty *tp;
60 	int mode;
61 
62 	tp = dev->si_tty;
63 	if (!tp)
64 		return ENXIO;
65 	scp = SC_STAT(tp->t_dev);
66 
67 	switch (cmd) {
68 
69 	/* generic text modes */
70 	case SW_TEXT_132x25: case SW_TEXT_132x30:
71 	case SW_TEXT_132x43: case SW_TEXT_132x50:
72 	case SW_TEXT_132x60:
73 		if (!(scp->sc->adp->va_flags & V_ADP_MODECHANGE))
74 			return ENODEV;
75 		return sc_set_text_mode(scp, tp, cmd & 0xff, 0, 0, 0);
76 
77 	/* text modes */
78 	case SW_VESA_C80x60:
79 	case SW_VESA_C132x25:
80 	case SW_VESA_C132x43:
81 	case SW_VESA_C132x50:
82 	case SW_VESA_C132x60:
83 		if (!(scp->sc->adp->va_flags & V_ADP_MODECHANGE))
84 			return ENODEV;
85 		mode = (cmd & 0xff) + M_VESA_BASE;
86 		return sc_set_text_mode(scp, tp, mode, 0, 0, 0);
87 
88 	/* graphics modes */
89 	case SW_VESA_32K_320: 	case SW_VESA_64K_320:
90 	case SW_VESA_FULL_320:
91 
92 	case SW_VESA_CG640x400:
93 
94 	case SW_VESA_CG640x480:
95 	case SW_VESA_32K_640:	case SW_VESA_64K_640:
96 	case SW_VESA_FULL_640:
97 
98 	case SW_VESA_800x600:	case SW_VESA_CG800x600:
99 	case SW_VESA_32K_800:	case SW_VESA_64K_800:
100 	case SW_VESA_FULL_800:
101 
102 	case SW_VESA_1024x768:	case SW_VESA_CG1024x768:
103 	case SW_VESA_32K_1024:	case SW_VESA_64K_1024:
104 	case SW_VESA_FULL_1024:
105 
106 	case SW_VESA_1280x1024:	case SW_VESA_CG1280x1024:
107 	case SW_VESA_32K_1280:	case SW_VESA_64K_1280:
108 	case SW_VESA_FULL_1280:
109 		if (!(scp->sc->adp->va_flags & V_ADP_MODECHANGE))
110 			return ENODEV;
111 		mode = (cmd & 0xff) + M_VESA_BASE;
112 		return sc_set_graphics_mode(scp, tp, mode);
113 	}
114 
115 	if (prev_user_ioctl)
116 		return (*prev_user_ioctl)(dev, cmd, data, flag, p);
117 	else
118 		return ENOIOCTL;
119 }
120 
121 int
122 vesa_load_ioctl(void)
123 {
124 	if (prev_user_ioctl)
125 		return EBUSY;
126 	prev_user_ioctl = sc_user_ioctl;
127 	sc_user_ioctl = vesa_ioctl;
128 	return 0;
129 }
130 
131 int
132 vesa_unload_ioctl(void)
133 {
134 	if (sc_user_ioctl != vesa_ioctl)
135 		return EBUSY;
136 	sc_user_ioctl = prev_user_ioctl;
137 	prev_user_ioctl = NULL;
138 	return 0;
139 }
140 
141 #endif /* (NSC > 0 && NVGA > 0 && VESA) || KLD_MODULE */
142