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