xref: /freebsd/sys/dev/syscons/scvidctl.c (revision 5129159789cc9d7bc514e4546b88e3427695002d)
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 "opt_syscons.h"
31 
32 #if NSC > 0
33 
34 #include <sys/param.h>
35 #include <sys/systm.h>
36 #include <sys/conf.h>
37 #include <sys/signalvar.h>
38 #include <sys/tty.h>
39 #include <sys/kernel.h>
40 
41 #include <vm/vm.h>
42 #include <vm/pmap.h>
43 
44 #include <machine/console.h>
45 
46 #include <dev/fb/fbreg.h>
47 #include <dev/syscons/syscons.h>
48 
49 /* for compatibility with previous versions */
50 /* 3.0-RELEASE used the following structure */
51 typedef struct old_video_adapter {
52     int			va_index;
53     int			va_type;
54     int			va_flags;
55 /* flag bits are the same as the -CURRENT
56 #define V_ADP_COLOR	(1<<0)
57 #define V_ADP_MODECHANGE (1<<1)
58 #define V_ADP_STATESAVE	(1<<2)
59 #define V_ADP_STATELOAD	(1<<3)
60 #define V_ADP_FONT	(1<<4)
61 #define V_ADP_PALETTE	(1<<5)
62 #define V_ADP_BORDER	(1<<6)
63 #define V_ADP_VESA	(1<<7)
64 */
65     int			va_crtc_addr;
66     u_int		va_window;	/* virtual address */
67     size_t		va_window_size;
68     size_t		va_window_gran;
69     u_int		va_buffer;	/* virtual address */
70     size_t		va_buffer_size;
71     int			va_initial_mode;
72     int			va_initial_bios_mode;
73     int			va_mode;
74 } old_video_adapter_t;
75 
76 #define OLD_CONS_ADPINFO _IOWR('c', 101, old_video_adapter_t)
77 
78 /* 3.1-RELEASE used the following structure */
79 typedef struct old_video_adapter_info {
80     int			va_index;
81     int			va_type;
82     char		va_name[16];
83     int			va_unit;
84     int			va_flags;
85     int			va_io_base;
86     int			va_io_size;
87     int			va_crtc_addr;
88     int			va_mem_base;
89     int			va_mem_size;
90     u_int		va_window;	/* virtual address */
91     size_t		va_window_size;
92     size_t		va_window_gran;
93     u_int		va_buffer;;
94     size_t		va_buffer_size;
95     int			va_initial_mode;
96     int			va_initial_bios_mode;
97     int			va_mode;
98     int			va_line_width;
99 } old_video_adapter_info_t;
100 
101 #define OLD_CONS_ADPINFO2 _IOWR('c', 101, old_video_adapter_info_t)
102 
103 /* 3.0-RELEASE and 3.1-RELEASE used the following structure */
104 typedef struct old_video_info {
105     int			vi_mode;
106     int			vi_flags;
107 /* flag bits are the same as the -CURRENT
108 #define V_INFO_COLOR	(1<<0)
109 #define V_INFO_GRAPHICS	(1<<1)
110 #define V_INFO_LINEAR	(1<<2)
111 #define V_INFO_VESA	(1<<3)
112 */
113     int			vi_width;
114     int			vi_height;
115     int			vi_cwidth;
116     int			vi_cheight;
117     int			vi_depth;
118     int			vi_planes;
119     u_int		vi_window;	/* physical address */
120     size_t		vi_window_size;
121     size_t		vi_window_gran;
122     u_int		vi_buffer;	/* physical address */
123     size_t		vi_buffer_size;
124 } old_video_info_t;
125 
126 #define OLD_CONS_MODEINFO _IOWR('c', 102, old_video_info_t)
127 #define OLD_CONS_FINDMODE _IOWR('c', 103, old_video_info_t)
128 
129 int
130 sc_set_text_mode(scr_stat *scp, struct tty *tp, int mode, int xsize, int ysize,
131 		 int fontsize)
132 {
133     video_info_t info;
134     sc_rndr_sw_t *rndr;
135     u_char *font;
136     int prev_ysize;
137     int error;
138     int s;
139 
140     if ((*vidsw[scp->sc->adapter]->get_info)(scp->sc->adp, mode, &info))
141 	return ENODEV;
142 
143     /* adjust argument values */
144     if (fontsize <= 0)
145 	fontsize = info.vi_cheight;
146     if (fontsize < 14) {
147 	fontsize = 8;
148 #ifndef SC_NO_FONT_LOADING
149 	if (!(scp->sc->fonts_loaded & FONT_8))
150 	    return EINVAL;
151 	font = scp->sc->font_8;
152 #else
153 	font = NULL;
154 #endif
155     } else if (fontsize >= 16) {
156 	fontsize = 16;
157 #ifndef SC_NO_FONT_LOADING
158 	if (!(scp->sc->fonts_loaded & FONT_16))
159 	    return EINVAL;
160 	font = scp->sc->font_16;
161 #else
162 	font = NULL;
163 #endif
164     } else {
165 	fontsize = 14;
166 #ifndef SC_NO_FONT_LOADING
167 	if (!(scp->sc->fonts_loaded & FONT_14))
168 	    return EINVAL;
169 	font = scp->sc->font_14;
170 #else
171 	font = NULL;
172 #endif
173     }
174     if ((xsize <= 0) || (xsize > info.vi_width))
175 	xsize = info.vi_width;
176     if ((ysize <= 0) || (ysize > info.vi_height))
177 	ysize = info.vi_height;
178 
179     /* stop screen saver, etc */
180     s = spltty();
181     if ((error = sc_clean_up(scp))) {
182 	splx(s);
183 	return error;
184     }
185 
186     rndr = sc_render_match(scp, scp->sc->adp, 0);
187     if (rndr == NULL) {
188 	splx(s);
189 	return ENODEV;
190     }
191 
192     /* set up scp */
193 #ifndef SC_NO_HISTORY
194     if (scp->history != NULL)
195 	sc_hist_save(scp);
196 #endif
197     prev_ysize = scp->ysize;
198     /*
199      * This is a kludge to fend off scrn_update() while we
200      * muck around with scp. XXX
201      */
202     scp->status |= UNKNOWN_MODE;
203     scp->status &= ~(GRAPHICS_MODE | PIXEL_MODE);
204     scp->mode = mode;
205     scp->xsize = xsize;
206     scp->ysize = ysize;
207     scp->xoff = 0;
208     scp->yoff = 0;
209     scp->xpixel = scp->xsize*8;
210     scp->ypixel = scp->ysize*fontsize;
211     scp->font = font;
212     scp->font_size = fontsize;
213 
214     /* allocate buffers */
215     sc_alloc_scr_buffer(scp, TRUE, TRUE);
216 #ifndef SC_NO_CUTPASTE
217     sc_alloc_cut_buffer(scp, FALSE);
218 #endif
219 #ifndef SC_NO_HISTORY
220     sc_alloc_history_buffer(scp, 0, prev_ysize, FALSE);
221 #endif
222     scp->rndr = rndr;
223     splx(s);
224 
225     if (scp == scp->sc->cur_scp)
226 	set_mode(scp);
227     scp->status &= ~UNKNOWN_MODE;
228 
229     if (tp == NULL)
230 	return 0;
231     DPRINTF(5, ("ws_*size (%d,%d), size (%d,%d)\n",
232 	tp->t_winsize.ws_col, tp->t_winsize.ws_row, scp->xsize, scp->ysize));
233     if (tp->t_winsize.ws_col != scp->xsize
234 	|| tp->t_winsize.ws_row != scp->ysize) {
235 	tp->t_winsize.ws_col = scp->xsize;
236 	tp->t_winsize.ws_row = scp->ysize;
237 	pgsignal(tp->t_pgrp, SIGWINCH, 1);
238     }
239 
240     return 0;
241 }
242 
243 int
244 sc_set_graphics_mode(scr_stat *scp, struct tty *tp, int mode)
245 {
246 #ifdef SC_NO_MODE_CHANGE
247     return ENODEV;
248 #else
249     video_info_t info;
250     sc_rndr_sw_t *rndr;
251     int error;
252     int s;
253 
254     if ((*vidsw[scp->sc->adapter]->get_info)(scp->sc->adp, mode, &info))
255 	return ENODEV;
256 
257     /* stop screen saver, etc */
258     s = spltty();
259     if ((error = sc_clean_up(scp))) {
260 	splx(s);
261 	return error;
262     }
263 
264     rndr = sc_render_match(scp, scp->sc->adp, GRAPHICS_MODE);
265     if (rndr == NULL) {
266 	splx(s);
267 	return ENODEV;
268     }
269 
270     /* set up scp */
271     scp->status |= (UNKNOWN_MODE | GRAPHICS_MODE);
272     scp->status &= ~PIXEL_MODE;
273     scp->mode = mode;
274     /*
275      * Don't change xsize and ysize; preserve the previous vty
276      * and history buffers.
277      */
278     scp->xoff = 0;
279     scp->yoff = 0;
280     scp->xpixel = info.vi_width;
281     scp->ypixel = info.vi_height;
282     scp->font = NULL;
283     scp->font_size = FONT_NONE;
284 #ifndef SC_NO_SYSMOUSE
285     /* move the mouse cursor at the center of the screen */
286     sc_mouse_move(scp, scp->xpixel / 2, scp->ypixel / 2);
287 #endif
288     scp->rndr = rndr;
289     splx(s);
290 
291     if (scp == scp->sc->cur_scp)
292 	set_mode(scp);
293     /* clear_graphics();*/
294     scp->status &= ~UNKNOWN_MODE;
295 
296     if (tp == NULL)
297 	return 0;
298     if (tp->t_winsize.ws_xpixel != scp->xpixel
299 	|| tp->t_winsize.ws_ypixel != scp->ypixel) {
300 	tp->t_winsize.ws_xpixel = scp->xpixel;
301 	tp->t_winsize.ws_ypixel = scp->ypixel;
302 	pgsignal(tp->t_pgrp, SIGWINCH, 1);
303     }
304 
305     return 0;
306 #endif /* SC_NO_MODE_CHANGE */
307 }
308 
309 int
310 sc_set_pixel_mode(scr_stat *scp, struct tty *tp, int xsize, int ysize,
311 		  int fontsize)
312 {
313 #ifndef SC_PIXEL_MODE
314     return ENODEV;
315 #else
316     video_info_t info;
317     sc_rndr_sw_t *rndr;
318     u_char *font;
319     int prev_ysize;
320     int error;
321     int s;
322 
323     if ((*vidsw[scp->sc->adapter]->get_info)(scp->sc->adp, scp->mode, &info))
324 	return ENODEV;		/* this shouldn't happen */
325 
326     /* adjust argument values */
327     if ((fontsize <= 0) || (fontsize == FONT_NONE))
328 	fontsize = info.vi_cheight;
329     if (fontsize < 14) {
330 	fontsize = 8;
331 #ifndef SC_NO_FONT_LOADING
332 	if (!(scp->sc->fonts_loaded & FONT_8))
333 	    return EINVAL;
334 	font = scp->sc->font_8;
335 #else
336 	font = NULL;
337 #endif
338     } else if (fontsize >= 16) {
339 	fontsize = 16;
340 #ifndef SC_NO_FONT_LOADING
341 	if (!(scp->sc->fonts_loaded & FONT_16))
342 	    return EINVAL;
343 	font = scp->sc->font_16;
344 #else
345 	font = NULL;
346 #endif
347     } else {
348 	fontsize = 14;
349 #ifndef SC_NO_FONT_LOADING
350 	if (!(scp->sc->fonts_loaded & FONT_14))
351 	    return EINVAL;
352 	font = scp->sc->font_14;
353 #else
354 	font = NULL;
355 #endif
356     }
357     if (xsize <= 0)
358 	xsize = info.vi_width/8;
359     if (ysize <= 0)
360 	ysize = info.vi_height/fontsize;
361 
362     if ((info.vi_width < xsize*8) || (info.vi_height < ysize*fontsize))
363 	return EINVAL;
364 
365     /* only 16 color, 4 plane modes are supported XXX */
366     if ((info.vi_depth != 4) || (info.vi_planes != 4))
367 	return ENODEV;
368 
369     /*
370      * set_pixel_mode() currently does not support video modes whose
371      * memory size is larger than 64K. Because such modes require
372      * bank switching to access the entire screen. XXX
373      */
374     if (info.vi_width*info.vi_height/8 > info.vi_window_size)
375 	return ENODEV;
376 
377     /* stop screen saver, etc */
378     s = spltty();
379     if ((error = sc_clean_up(scp))) {
380 	splx(s);
381 	return error;
382     }
383 
384     rndr = sc_render_match(scp, scp->sc->adp, PIXEL_MODE);
385     if (rndr == NULL) {
386 	splx(s);
387 	return ENODEV;
388     }
389 
390     /* set up scp */
391 #ifndef SC_NO_HISTORY
392     if (scp->history != NULL)
393 	sc_hist_save(scp);
394 #endif
395     prev_ysize = scp->ysize;
396     scp->status |= (UNKNOWN_MODE | PIXEL_MODE);
397     scp->status &= ~GRAPHICS_MODE;
398     scp->xsize = xsize;
399     scp->ysize = ysize;
400     scp->xoff = (scp->xpixel/8 - xsize)/2;
401     scp->yoff = (scp->ypixel/fontsize - ysize)/2;
402     scp->font = font;
403     scp->font_size = fontsize;
404 
405     /* allocate buffers */
406     sc_alloc_scr_buffer(scp, TRUE, TRUE);
407 #ifndef SC_NO_CUTPASTE
408     sc_alloc_cut_buffer(scp, FALSE);
409 #endif
410 #ifndef SC_NO_HISTORY
411     sc_alloc_history_buffer(scp, 0, prev_ysize, FALSE);
412 #endif
413     scp->rndr = rndr;
414     splx(s);
415 
416     if (scp == scp->sc->cur_scp) {
417 	set_border(scp, scp->border);
418 	sc_set_cursor_image(scp);
419     }
420 
421     scp->status &= ~UNKNOWN_MODE;
422 
423     if (tp == NULL)
424 	return 0;
425     if (tp->t_winsize.ws_col != scp->xsize
426 	|| tp->t_winsize.ws_row != scp->ysize) {
427 	tp->t_winsize.ws_col = scp->xsize;
428 	tp->t_winsize.ws_row = scp->ysize;
429 	pgsignal(tp->t_pgrp, SIGWINCH, 1);
430     }
431 
432     return 0;
433 #endif /* SC_PIXEL_MODE */
434 }
435 
436 sc_rndr_sw_t
437 *sc_render_match(scr_stat *scp, video_adapter_t *adp, int mode)
438 {
439     const sc_renderer_t **list;
440     const sc_renderer_t *p;
441 
442     list = (const sc_renderer_t **)scrndr_set.ls_items;
443     while ((p = *list++) != NULL) {
444 	if ((strcmp(p->name, adp->va_name) == 0)
445 	    && (mode == p->mode)) {
446 	    scp->status &= ~(VR_CURSOR_ON | VR_CURSOR_BLINK);
447 	    return p->rndrsw;
448 	}
449     }
450 
451     return NULL;
452 }
453 
454 #define fb_ioctl(a, c, d)		\
455 	(((a) == NULL) ? ENODEV : 	\
456 			 (*vidsw[(a)->va_index]->ioctl)((a), (c), (caddr_t)(d)))
457 
458 int
459 sc_vid_ioctl(struct tty *tp, u_long cmd, caddr_t data, int flag, struct proc *p)
460 {
461     scr_stat *scp;
462     video_adapter_t *adp;
463     video_info_t info;
464     video_adapter_info_t adp_info;
465     int error;
466     int s;
467 
468     scp = SC_STAT(tp->t_dev);
469     if (scp == NULL)		/* tp == SC_MOUSE */
470 	return ENOIOCTL;
471     adp = scp->sc->adp;
472     if (adp == NULL)		/* shouldn't happen??? */
473 	return ENODEV;
474 
475     switch (cmd) {
476 
477     case CONS_CURRENTADP:	/* get current adapter index */
478     case FBIO_ADAPTER:
479 	return fb_ioctl(adp, FBIO_ADAPTER, data);
480 
481     case CONS_CURRENT:  	/* get current adapter type */
482     case FBIO_ADPTYPE:
483 	return fb_ioctl(adp, FBIO_ADPTYPE, data);
484 
485     case OLD_CONS_ADPINFO:	/* adapter information (old interface) */
486 	if (((old_video_adapter_t *)data)->va_index >= 0) {
487 	    adp = vid_get_adapter(((old_video_adapter_t *)data)->va_index);
488 	    if (adp == NULL)
489 		return ENODEV;
490 	}
491 	((old_video_adapter_t *)data)->va_index = adp->va_index;
492 	((old_video_adapter_t *)data)->va_type = adp->va_type;
493 	((old_video_adapter_t *)data)->va_flags = adp->va_flags;
494 	((old_video_adapter_t *)data)->va_crtc_addr = adp->va_crtc_addr;
495 	((old_video_adapter_t *)data)->va_window = adp->va_window;
496 	((old_video_adapter_t *)data)->va_window_size = adp->va_window_size;
497 	((old_video_adapter_t *)data)->va_window_gran = adp->va_window_gran;
498 	((old_video_adapter_t *)data)->va_buffer = adp->va_buffer;
499 	((old_video_adapter_t *)data)->va_buffer_size = adp->va_buffer_size;
500 	((old_video_adapter_t *)data)->va_mode = adp->va_mode;
501 	((old_video_adapter_t *)data)->va_initial_mode = adp->va_initial_mode;
502 	((old_video_adapter_t *)data)->va_initial_bios_mode
503 	    = adp->va_initial_bios_mode;
504 	return 0;
505 
506     case OLD_CONS_ADPINFO2:	/* adapter information (yet another old I/F) */
507 	adp_info.va_index = ((old_video_adapter_info_t *)data)->va_index;
508 	if (adp_info.va_index >= 0) {
509 	    adp = vid_get_adapter(adp_info.va_index);
510 	    if (adp == NULL)
511 		return ENODEV;
512 	}
513 	error = fb_ioctl(adp, FBIO_ADPINFO, &adp_info);
514 	if (error == 0)
515 	    bcopy(&adp_info, data, sizeof(old_video_adapter_info_t));
516 	return error;
517 
518     case CONS_ADPINFO:		/* adapter information */
519     case FBIO_ADPINFO:
520 	if (((video_adapter_info_t *)data)->va_index >= 0) {
521 	    adp = vid_get_adapter(((video_adapter_info_t *)data)->va_index);
522 	    if (adp == NULL)
523 		return ENODEV;
524 	}
525 	return fb_ioctl(adp, FBIO_ADPINFO, data);
526 
527     case CONS_GET:      	/* get current video mode */
528     case FBIO_GETMODE:
529 	*(int *)data = scp->mode;
530 	return 0;
531 
532 #ifndef SC_NO_MODE_CHANGE
533     case FBIO_SETMODE:		/* set video mode */
534 	if (!(adp->va_flags & V_ADP_MODECHANGE))
535  	    return ENODEV;
536 	info.vi_mode = *(int *)data;
537 	error = fb_ioctl(adp, FBIO_MODEINFO, &info);
538 	if (error)
539 	    return error;
540 	if (info.vi_flags & V_INFO_GRAPHICS)
541 	    return sc_set_graphics_mode(scp, tp, *(int *)data);
542 	else
543 	    return sc_set_text_mode(scp, tp, *(int *)data, 0, 0, 0);
544 #endif /* SC_NO_MODE_CHANGE */
545 
546     case OLD_CONS_MODEINFO:	/* get mode information (old infterface) */
547 	info.vi_mode = ((old_video_info_t *)data)->vi_mode;
548 	error = fb_ioctl(adp, FBIO_MODEINFO, &info);
549 	if (error == 0)
550 	    bcopy(&info, (old_video_info_t *)data, sizeof(old_video_info_t));
551 	return error;
552 
553     case CONS_MODEINFO:		/* get mode information */
554     case FBIO_MODEINFO:
555 	return fb_ioctl(adp, FBIO_MODEINFO, data);
556 
557     case OLD_CONS_FINDMODE:	/* find a matching video mode (old interface) */
558 	bzero(&info, sizeof(info));
559 	bcopy((old_video_info_t *)data, &info, sizeof(old_video_info_t));
560 	error = fb_ioctl(adp, FBIO_FINDMODE, &info);
561 	if (error == 0)
562 	    bcopy(&info, (old_video_info_t *)data, sizeof(old_video_info_t));
563 	return error;
564 
565     case CONS_FINDMODE:		/* find a matching video mode */
566     case FBIO_FINDMODE:
567 	return fb_ioctl(adp, FBIO_FINDMODE, data);
568 
569     case CONS_SETWINORG:	/* set frame buffer window origin */
570     case FBIO_SETWINORG:
571 	if (scp != scp->sc->cur_scp)
572 	    return ENODEV;	/* XXX */
573 	return fb_ioctl(adp, FBIO_SETWINORG, data);
574 
575     case FBIO_GETWINORG:	/* get frame buffer window origin */
576 	if (scp != scp->sc->cur_scp)
577 	    return ENODEV;	/* XXX */
578 	return fb_ioctl(adp, FBIO_GETWINORG, data);
579 
580     case FBIO_GETDISPSTART:
581     case FBIO_SETDISPSTART:
582     case FBIO_GETLINEWIDTH:
583     case FBIO_SETLINEWIDTH:
584 	if (scp != scp->sc->cur_scp)
585 	    return ENODEV;	/* XXX */
586 	return fb_ioctl(adp, cmd, data);
587 
588     case FBIO_GETPALETTE:
589     case FBIO_SETPALETTE:
590     case FBIOPUTCMAP:
591     case FBIOGETCMAP:
592     case FBIOGTYPE:
593     case FBIOGATTR:
594     case FBIOSVIDEO:
595     case FBIOGVIDEO:
596     case FBIOSCURSOR:
597     case FBIOGCURSOR:
598     case FBIOSCURPOS:
599     case FBIOGCURPOS:
600     case FBIOGCURMAX:
601 	if (scp != scp->sc->cur_scp)
602 	    return ENODEV;	/* XXX */
603 	return fb_ioctl(adp, cmd, data);
604 
605 #ifndef SC_NO_MODE_CHANGE
606     /* generic text modes */
607     case SW_TEXT_80x25:	case SW_TEXT_80x30:
608     case SW_TEXT_80x43: case SW_TEXT_80x50:
609     case SW_TEXT_80x60:
610 	/* FALL THROUGH */
611 
612     /* VGA TEXT MODES */
613     case SW_VGA_C40x25:
614     case SW_VGA_C80x25: case SW_VGA_M80x25:
615     case SW_VGA_C80x30: case SW_VGA_M80x30:
616     case SW_VGA_C80x50: case SW_VGA_M80x50:
617     case SW_VGA_C80x60: case SW_VGA_M80x60:
618     case SW_VGA_C90x25: case SW_VGA_M90x25:
619     case SW_VGA_C90x30: case SW_VGA_M90x30:
620     case SW_VGA_C90x43: case SW_VGA_M90x43:
621     case SW_VGA_C90x50: case SW_VGA_M90x50:
622     case SW_VGA_C90x60: case SW_VGA_M90x60:
623     case SW_B40x25:     case SW_C40x25:
624     case SW_B80x25:     case SW_C80x25:
625     case SW_ENH_B40x25: case SW_ENH_C40x25:
626     case SW_ENH_B80x25: case SW_ENH_C80x25:
627     case SW_ENH_B80x43: case SW_ENH_C80x43:
628     case SW_EGAMONO80x25:
629 
630 #ifdef PC98
631     /* PC98 TEXT MODES */
632     case SW_PC98_80x25:
633     case SW_PC98_80x30:
634 #endif
635 	if (!(adp->va_flags & V_ADP_MODECHANGE))
636  	    return ENODEV;
637 	return sc_set_text_mode(scp, tp, cmd & 0xff, 0, 0, 0);
638 
639     /* GRAPHICS MODES */
640     case SW_BG320:     case SW_BG640:
641     case SW_CG320:     case SW_CG320_D:   case SW_CG640_E:
642     case SW_CG640x350: case SW_ENH_CG640:
643     case SW_BG640x480: case SW_CG640x480: case SW_VGA_CG320:
644     case SW_VGA_MODEX:
645 	if (!(adp->va_flags & V_ADP_MODECHANGE))
646 	    return ENODEV;
647 	return sc_set_graphics_mode(scp, tp, cmd & 0xff);
648 #endif /* SC_NO_MODE_CHANGE */
649 
650     case KDSETMODE:     	/* set current mode of this (virtual) console */
651 	switch (*(int *)data) {
652 	case KD_TEXT:   	/* switch to TEXT (known) mode */
653 	    /*
654 	     * If scp->mode is of graphics modes, we don't know which
655 	     * text mode to switch back to...
656 	     */
657 	    if (scp->status & GRAPHICS_MODE)
658 		return EINVAL;
659 	    /* restore fonts & palette ! */
660 #if 0
661 #ifndef SC_NO_FONT_LOADING
662 	    if (ISFONTAVAIL(adp->va_flags)
663 		&& !(scp->status & (GRAPHICS_MODE | PIXEL_MODE)))
664 		/*
665 		 * FONT KLUDGE
666 		 * Don't load fonts for now... XXX
667 		 */
668 		if (scp->sc->fonts_loaded & FONT_8)
669 		    copy_font(scp, LOAD, 8, scp->sc->font_8);
670 		if (scp->sc->fonts_loaded & FONT_14)
671 		    copy_font(scp, LOAD, 14, scp->sc->font_14);
672 		if (scp->sc->fonts_loaded & FONT_16)
673 		    copy_font(scp, LOAD, 16, scp->sc->font_16);
674 	    }
675 #endif /* SC_NO_FONT_LOADING */
676 #endif
677 
678 #ifndef SC_NO_PALETTE_LOADING
679 	    load_palette(adp, scp->sc->palette);
680 #endif
681 
682 #ifndef PC98
683 	    /* move hardware cursor out of the way */
684 	    (*vidsw[adp->va_index]->set_hw_cursor)(adp, -1, -1);
685 #endif
686 
687 	    /* FALL THROUGH */
688 
689 	case KD_TEXT1:  	/* switch to TEXT (known) mode */
690 	    /*
691 	     * If scp->mode is of graphics modes, we don't know which
692 	     * text/pixel mode to switch back to...
693 	     */
694 	    if (scp->status & GRAPHICS_MODE)
695 		return EINVAL;
696 	    s = spltty();
697 	    if ((error = sc_clean_up(scp))) {
698 		splx(s);
699 		return error;
700 	    }
701 #ifndef PC98
702 	    scp->status |= UNKNOWN_MODE;
703 	    splx(s);
704 	    /* no restore fonts & palette */
705 	    if (scp == scp->sc->cur_scp)
706 		set_mode(scp);
707 	    sc_clear_screen(scp);
708 	    scp->status &= ~UNKNOWN_MODE;
709 #else /* PC98 */
710 	    scp->status &= ~UNKNOWN_MODE;
711 	    /* no restore fonts & palette */
712 	    if (scp == scp->sc->cur_scp)
713 		set_mode(scp);
714 	    sc_clear_screen(scp);
715 	    splx(s);
716 #endif /* PC98 */
717 	    return 0;
718 
719 #ifdef SC_PIXEL_MODE
720 	case KD_PIXEL:		/* pixel (raster) display */
721 	    if (!(scp->status & (GRAPHICS_MODE | PIXEL_MODE)))
722 		return EINVAL;
723 	    if (scp->status & GRAPHICS_MODE)
724 		return sc_set_pixel_mode(scp, tp, scp->xsize, scp->ysize,
725 					 scp->font_size);
726 	    s = spltty();
727 	    if ((error = sc_clean_up(scp))) {
728 		splx(s);
729 		return error;
730 	    }
731 	    scp->status |= (UNKNOWN_MODE | PIXEL_MODE);
732 	    splx(s);
733 	    if (scp == scp->sc->cur_scp) {
734 		set_mode(scp);
735 #ifndef SC_NO_PALETTE_LOADING
736 		load_palette(adp, scp->sc->palette);
737 #endif
738 	    }
739 	    sc_clear_screen(scp);
740 	    scp->status &= ~UNKNOWN_MODE;
741 	    return 0;
742 #endif /* SC_PIXEL_MODE */
743 
744 	case KD_GRAPHICS:	/* switch to GRAPHICS (unknown) mode */
745 	    s = spltty();
746 	    if ((error = sc_clean_up(scp))) {
747 		splx(s);
748 		return error;
749 	    }
750 	    scp->status |= UNKNOWN_MODE;
751 	    splx(s);
752 #ifdef PC98
753 	    if (scp == scp->sc->cur_scp)
754 		set_mode(scp);
755 #endif
756 	    return 0;
757 
758 	default:
759 	    return EINVAL;
760 	}
761 	/* NOT REACHED */
762 
763 #ifdef SC_PIXEL_MODE
764     case KDRASTER:		/* set pixel (raster) display mode */
765 	if (ISUNKNOWNSC(scp) || ISTEXTSC(scp))
766 	    return ENODEV;
767 	return sc_set_pixel_mode(scp, tp, ((int *)data)[0], ((int *)data)[1],
768 				 ((int *)data)[2]);
769 #endif /* SC_PIXEL_MODE */
770 
771     case KDGETMODE:     	/* get current mode of this (virtual) console */
772 	/*
773 	 * From the user program's point of view, KD_PIXEL is the same
774 	 * as KD_TEXT...
775 	 */
776 	*data = ISGRAPHSC(scp) ? KD_GRAPHICS : KD_TEXT;
777 	return 0;
778 
779     case KDSBORDER:     	/* set border color of this (virtual) console */
780 	scp->border = *data;
781 	if (scp == scp->sc->cur_scp)
782 	    set_border(scp, scp->border);
783 	return 0;
784     }
785 
786     return ENOIOCTL;
787 }
788 
789 #endif /* NSC > 0 */
790