scvesactl.c revision 39591
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.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 *    notice, this list of conditions and the following disclaimer in the
12 *    documentation and/or other materials provided with the distribution.
13 * 3. The name of the author may not be used to endorse or promote
14 *    products derived from this software without specific prior written
15 *    permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 * SUCH DAMAGE.
28 *
29 * $Id: scvesactl.c,v 1.1 1998/09/15 18:16:37 sos Exp $
30 */
31
32#include "sc.h"
33#include "opt_vesa.h"
34#include "opt_vm86.h"
35
36#if (NSC > 0 && defined(VESA) && defined(VM86)) || defined(VESA_MODULE)
37
38#include <sys/param.h>
39#include <sys/systm.h>
40#include <sys/tty.h>
41#include <sys/kernel.h>
42
43#include <machine/apm_bios.h>
44#include <machine/console.h>
45#include <machine/pc/vesa.h>
46
47#include <i386/isa/videoio.h>
48#include <i386/isa/syscons.h>
49
50static int (*prev_user_ioctl)(dev_t dev, int cmd, caddr_t data, int flag,
51			      struct proc *p);
52
53/* external functions */
54struct tty *scdevtotty(dev_t dev);
55
56/* functions in this module */
57int vesa_ioctl(dev_t dev, int cmd, caddr_t data, int flag, struct proc *p);
58
59int
60vesa_ioctl(dev_t dev, int cmd, caddr_t data, int flag, struct proc *p)
61{
62	scr_stat *scp;
63	struct tty *tp;
64	video_info_t info;
65	video_adapter_t *adp;
66	int mode;
67	int error;
68	int s;
69
70	tp = scdevtotty(dev);
71	if (!tp)
72		return ENXIO;
73	scp = sc_get_scr_stat(tp->t_dev);
74
75	switch (cmd) {
76	case SW_VESA_USER:
77
78		mode = (int)data;
79		if ((*biosvidsw.get_info)(scp->adp, mode, &info))
80			return ENODEV;
81		if (info.vi_flags & V_INFO_GRAPHICS)
82			goto vesa_graphics;
83		else
84			goto vesa_text;
85
86	/* generic text modes */
87	case SW_TEXT_132x25: case SW_TEXT_132x30:
88	case SW_TEXT_132x43: case SW_TEXT_132x50:
89	case SW_TEXT_132x60:
90		adp = get_adapter(scp);
91		if (!(adp->va_flags & V_ADP_MODECHANGE))
92			return ENODEV;
93		return sc_set_text_mode(scp, tp, cmd & 0xff, 0, 0, 0);
94
95	/* text modes */
96	case SW_VESA_C80x60:
97	case SW_VESA_C132x25:
98	case SW_VESA_C132x43:
99	case SW_VESA_C132x50:
100	case SW_VESA_C132x60:
101		adp = get_adapter(scp);
102		if (!(adp->va_flags & V_ADP_MODECHANGE))
103			return ENODEV;
104		mode = (cmd & 0xff) + M_VESA_BASE;
105vesa_text:
106		return sc_set_text_mode(scp, tp, mode, 0, 0, 0);
107
108	/* graphics modes */
109	case SW_VESA_32K_320: 	case SW_VESA_64K_320:
110	case SW_VESA_FULL_320:
111
112	case SW_VESA_CG640x400:
113
114	case SW_VESA_CG640x480:
115	case SW_VESA_32K_640:	case SW_VESA_64K_640:
116	case SW_VESA_FULL_640:
117
118	case SW_VESA_800x600:	case SW_VESA_CG800x600:
119	case SW_VESA_32K_800:	case SW_VESA_64K_800:
120	case SW_VESA_FULL_800:
121
122	case SW_VESA_1024x768:	case SW_VESA_CG1024x768:
123	case SW_VESA_32K_1024:	case SW_VESA_64K_1024:
124	case SW_VESA_FULL_1024:
125
126	case SW_VESA_1280x1024:	case SW_VESA_CG1280x1024:
127	case SW_VESA_32K_1280:	case SW_VESA_64K_1280:
128	case SW_VESA_FULL_1280:
129		adp = get_adapter(scp);
130		if (!(adp->va_flags & V_ADP_MODECHANGE))
131			return ENODEV;
132		mode = (cmd & 0xff) + M_VESA_BASE;
133vesa_graphics:
134		return sc_set_graphics_mode(scp, tp, mode);
135	}
136
137	if (prev_user_ioctl)
138		return (*prev_user_ioctl)(dev, cmd, data, flag, p);
139	else
140		return ENOIOCTL;
141}
142
143int
144vesa_load_ioctl(void)
145{
146	if (prev_user_ioctl)
147		return EBUSY;
148	prev_user_ioctl = sc_user_ioctl;
149	sc_user_ioctl = vesa_ioctl;
150	return 0;
151}
152
153int
154vesa_unload_ioctl(void)
155{
156	if (sc_user_ioctl != vesa_ioctl)
157		return EBUSY;
158	sc_user_ioctl = prev_user_ioctl;
159	prev_user_ioctl = NULL;
160	return 0;
161}
162
163#endif /* (NSC > 0 && VESA && VM86) || VESA_MODULE */
164