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