scvidctl.c revision 48667
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.9 1999/06/22 14:13:29 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 prev_ysize;
247    int error;
248    int s;
249
250    if ((*vidsw[scp->sc->adapter]->get_info)(scp->sc->adp, mode, &info))
251	return ENODEV;
252
253    /* stop screen saver, etc */
254    s = spltty();
255    if ((error = sc_clean_up(scp))) {
256	splx(s);
257	return error;
258    }
259
260    rndr = sc_render_match(scp, scp->sc->adp, GRAPHICS_MODE);
261    if (rndr == NULL) {
262	splx(s);
263	return ENODEV;
264    }
265
266    /* set up scp */
267    prev_ysize = scp->ysize;
268    scp->status |= (UNKNOWN_MODE | GRAPHICS_MODE);
269    scp->status &= ~PIXEL_MODE;
270    scp->mode = mode;
271    scp->xsize = info.vi_width/8;
272    scp->ysize = info.vi_height/info.vi_cheight;
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#ifndef SC_NO_HISTORY
284    sc_free_history_buffer(scp, prev_ysize);
285#endif
286    scp->rndr = rndr;
287    splx(s);
288
289    if (scp == scp->sc->cur_scp)
290	set_mode(scp);
291    /* clear_graphics();*/
292    scp->status &= ~UNKNOWN_MODE;
293
294    if (tp == NULL)
295	return 0;
296    if (tp->t_winsize.ws_xpixel != scp->xpixel
297	|| tp->t_winsize.ws_ypixel != scp->ypixel) {
298	tp->t_winsize.ws_xpixel = scp->xpixel;
299	tp->t_winsize.ws_ypixel = scp->ypixel;
300	pgsignal(tp->t_pgrp, SIGWINCH, 1);
301    }
302
303    return 0;
304#endif /* SC_NO_MODE_CHANGE */
305}
306
307int
308sc_set_pixel_mode(scr_stat *scp, struct tty *tp, int xsize, int ysize,
309		  int fontsize)
310{
311#ifndef SC_PIXEL_MODE
312    return ENODEV;
313#else
314    video_info_t info;
315    sc_rndr_sw_t *rndr;
316    u_char *font;
317    int prev_ysize;
318    int error;
319    int s;
320
321    if ((*vidsw[scp->sc->adapter]->get_info)(scp->sc->adp, scp->mode, &info))
322	return ENODEV;		/* this shouldn't happen */
323
324#ifdef SC_VIDEO_DEBUG
325    if (scp->scr_buf != NULL) {
326	printf("set_pixel_mode(): mode:%x, col:%d, row:%d, font:%d\n",
327	       scp->mode, xsize, ysize, fontsize);
328    }
329#endif
330
331    /* adjust argument values */
332    if ((fontsize <= 0) || (fontsize == FONT_NONE))
333	fontsize = info.vi_cheight;
334    if (fontsize < 14) {
335	fontsize = 8;
336#ifndef SC_NO_FONT_LOADING
337	if (!(scp->sc->fonts_loaded & FONT_8))
338	    return EINVAL;
339	font = scp->sc->font_8;
340#else
341	font = NULL;
342#endif
343    } else if (fontsize >= 16) {
344	fontsize = 16;
345#ifndef SC_NO_FONT_LOADING
346	if (!(scp->sc->fonts_loaded & FONT_16))
347	    return EINVAL;
348	font = scp->sc->font_16;
349#else
350	font = NULL;
351#endif
352    } else {
353	fontsize = 14;
354#ifndef SC_NO_FONT_LOADING
355	if (!(scp->sc->fonts_loaded & FONT_14))
356	    return EINVAL;
357	font = scp->sc->font_14;
358#else
359	font = NULL;
360#endif
361    }
362    if (xsize <= 0)
363	xsize = info.vi_width/8;
364    if (ysize <= 0)
365	ysize = info.vi_height/fontsize;
366
367#ifdef SC_VIDEO_DEBUG
368    if (scp->scr_buf != NULL) {
369	printf("set_pixel_mode(): mode:%x, col:%d, row:%d, font:%d\n",
370	       scp->mode, xsize, ysize, fontsize);
371	printf("set_pixel_mode(): window:%p, %dx%d, xoff:%d, yoff:%d\n",
372	       (void *)scp->sc->adp->va_window, info.vi_width, info.vi_height,
373	       (info.vi_width/8 - xsize)/2,
374	       (info.vi_height/fontsize - ysize)/2);
375    }
376#endif
377
378    if ((info.vi_width < xsize*8) || (info.vi_height < ysize*fontsize))
379	return EINVAL;
380
381    /* only 16 color, 4 plane modes are supported XXX */
382    if ((info.vi_depth != 4) || (info.vi_planes != 4))
383	return ENODEV;
384
385    /*
386     * set_pixel_mode() currently does not support video modes whose
387     * memory size is larger than 64K. Because such modes require
388     * bank switching to access the entire screen. XXX
389     */
390    if (info.vi_width*info.vi_height/8 > info.vi_window_size)
391	return ENODEV;
392
393    /* stop screen saver, etc */
394    s = spltty();
395    if ((error = sc_clean_up(scp))) {
396	splx(s);
397	return error;
398    }
399
400    rndr = sc_render_match(scp, scp->sc->adp, PIXEL_MODE);
401    if (rndr == NULL) {
402	splx(s);
403	return ENODEV;
404    }
405
406    /* set up scp */
407    prev_ysize = scp->ysize;
408    scp->status |= (UNKNOWN_MODE | PIXEL_MODE);
409    scp->status &= ~GRAPHICS_MODE;
410    scp->xsize = xsize;
411    scp->ysize = ysize;
412    scp->xoff = (scp->xpixel/8 - xsize)/2;
413    scp->yoff = (scp->ypixel/fontsize - ysize)/2;
414    scp->font = font;
415    scp->font_size = fontsize;
416
417    /* allocate buffers */
418    sc_alloc_scr_buffer(scp, TRUE, TRUE);
419#ifndef SC_NO_CUTPASTE
420    sc_alloc_cut_buffer(scp, FALSE);
421#endif
422#ifndef SC_NO_HISTORY
423    sc_alloc_history_buffer(scp, 0, prev_ysize, FALSE);
424#endif
425    scp->rndr = rndr;
426    splx(s);
427
428    if (scp == scp->sc->cur_scp) {
429	set_border(scp, scp->border);
430	sc_set_cursor_image(scp);
431    }
432
433    scp->status &= ~UNKNOWN_MODE;
434
435#ifdef SC_VIDEO_DEBUG
436    printf("set_pixel_mode(): status:%x\n", scp->status);
437#endif
438
439    if (tp == NULL)
440	return 0;
441    if (tp->t_winsize.ws_col != scp->xsize
442	|| tp->t_winsize.ws_row != scp->ysize) {
443	tp->t_winsize.ws_col = scp->xsize;
444	tp->t_winsize.ws_row = scp->ysize;
445	pgsignal(tp->t_pgrp, SIGWINCH, 1);
446    }
447
448    return 0;
449#endif /* SC_PIXEL_MODE */
450}
451
452sc_rndr_sw_t
453*sc_render_match(scr_stat *scp, video_adapter_t *adp, int mode)
454{
455    const sc_renderer_t **list;
456    const sc_renderer_t *p;
457
458    list = (const sc_renderer_t **)scrndr_set.ls_items;
459    while ((p = *list++) != NULL) {
460	if ((strcmp(p->name, adp->va_name) == 0)
461	    && (mode == p->mode)) {
462	    scp->status &= ~(VR_CURSOR_ON | VR_CURSOR_BLINK);
463	    return p->rndrsw;
464	}
465    }
466
467    return NULL;
468}
469
470#define fb_ioctl(a, c, d)		\
471	(((a) == NULL) ? ENODEV : 	\
472			 (*vidsw[(a)->va_index]->ioctl)((a), (c), (caddr_t)(d)))
473
474int
475sc_vid_ioctl(struct tty *tp, u_long cmd, caddr_t data, int flag, struct proc *p)
476{
477    scr_stat *scp;
478    video_adapter_t *adp;
479    video_info_t info;
480    video_adapter_info_t adp_info;
481    int error;
482    int s;
483
484    scp = sc_get_scr_stat(tp->t_dev);
485    if (scp == NULL)		/* tp == SC_MOUSE */
486	return ENOIOCTL;
487    adp = scp->sc->adp;
488    if (adp == NULL)		/* shouldn't happen??? */
489	return ENODEV;
490
491    switch (cmd) {
492
493    case CONS_CURRENTADP:	/* get current adapter index */
494    case FBIO_ADAPTER:
495	return fb_ioctl(adp, FBIO_ADAPTER, data);
496
497    case CONS_CURRENT:  	/* get current adapter type */
498    case FBIO_ADPTYPE:
499	return fb_ioctl(adp, FBIO_ADPTYPE, data);
500
501    case OLD_CONS_ADPINFO:	/* adapter information (old interface) */
502	if (((old_video_adapter_t *)data)->va_index >= 0) {
503	    adp = vid_get_adapter(((old_video_adapter_t *)data)->va_index);
504	    if (adp == NULL)
505		return ENODEV;
506	}
507	((old_video_adapter_t *)data)->va_index = adp->va_index;
508	((old_video_adapter_t *)data)->va_type = adp->va_type;
509	((old_video_adapter_t *)data)->va_flags = adp->va_flags;
510	((old_video_adapter_t *)data)->va_crtc_addr = adp->va_crtc_addr;
511	((old_video_adapter_t *)data)->va_window = adp->va_window;
512	((old_video_adapter_t *)data)->va_window_size = adp->va_window_size;
513	((old_video_adapter_t *)data)->va_window_gran = adp->va_window_gran;
514	((old_video_adapter_t *)data)->va_buffer = adp->va_buffer;
515	((old_video_adapter_t *)data)->va_buffer_size = adp->va_buffer_size;
516	((old_video_adapter_t *)data)->va_mode = adp->va_mode;
517	((old_video_adapter_t *)data)->va_initial_mode = adp->va_initial_mode;
518	((old_video_adapter_t *)data)->va_initial_bios_mode
519	    = adp->va_initial_bios_mode;
520	return 0;
521
522    case OLD_CONS_ADPINFO2:	/* adapter information (yet another old I/F) */
523	adp_info.va_index = ((old_video_adapter_info_t *)data)->va_index;
524	if (adp_info.va_index >= 0) {
525	    adp = vid_get_adapter(adp_info.va_index);
526	    if (adp == NULL)
527		return ENODEV;
528	}
529	error = fb_ioctl(adp, FBIO_ADPINFO, &adp_info);
530	if (error == 0)
531	    bcopy(&adp_info, data, sizeof(old_video_adapter_info_t));
532	return error;
533
534    case CONS_ADPINFO:		/* adapter information */
535    case FBIO_ADPINFO:
536	if (((video_adapter_info_t *)data)->va_index >= 0) {
537	    adp = vid_get_adapter(((video_adapter_info_t *)data)->va_index);
538	    if (adp == NULL)
539		return ENODEV;
540	}
541	return fb_ioctl(adp, FBIO_ADPINFO, data);
542
543    case CONS_GET:      	/* get current video mode */
544    case FBIO_GETMODE:
545	*(int *)data = scp->mode;
546	return 0;
547
548#ifndef SC_NO_MODE_CHANGE
549    case FBIO_SETMODE:		/* set video mode */
550	if (!(adp->va_flags & V_ADP_MODECHANGE))
551 	    return ENODEV;
552	info.vi_mode = *(int *)data;
553	error = fb_ioctl(adp, FBIO_MODEINFO, &info);
554	if (error)
555	    return error;
556	if (info.vi_flags & V_INFO_GRAPHICS)
557	    return sc_set_graphics_mode(scp, tp, *(int *)data);
558	else
559	    return sc_set_text_mode(scp, tp, *(int *)data, 0, 0, 0);
560#endif /* SC_NO_MODE_CHANGE */
561
562    case OLD_CONS_MODEINFO:	/* get mode information (old infterface) */
563	info.vi_mode = ((old_video_info_t *)data)->vi_mode;
564	error = fb_ioctl(adp, FBIO_MODEINFO, &info);
565	if (error == 0)
566	    bcopy(&info, (old_video_info_t *)data, sizeof(old_video_info_t));
567	return error;
568
569    case CONS_MODEINFO:		/* get mode information */
570    case FBIO_MODEINFO:
571	return fb_ioctl(adp, FBIO_MODEINFO, data);
572
573    case OLD_CONS_FINDMODE:	/* find a matching video mode (old interface) */
574	bzero(&info, sizeof(info));
575	bcopy((old_video_info_t *)data, &info, sizeof(old_video_info_t));
576	error = fb_ioctl(adp, FBIO_FINDMODE, &info);
577	if (error == 0)
578	    bcopy(&info, (old_video_info_t *)data, sizeof(old_video_info_t));
579	return error;
580
581    case CONS_FINDMODE:		/* find a matching video mode */
582    case FBIO_FINDMODE:
583	return fb_ioctl(adp, FBIO_FINDMODE, data);
584
585    case CONS_SETWINORG:	/* set frame buffer window origin */
586    case FBIO_SETWINORG:
587	if (scp != scp->sc->cur_scp)
588	    return ENODEV;	/* XXX */
589	return fb_ioctl(adp, FBIO_SETWINORG, data);
590
591    case FBIO_GETWINORG:	/* get frame buffer window origin */
592	if (scp != scp->sc->cur_scp)
593	    return ENODEV;	/* XXX */
594	return fb_ioctl(adp, FBIO_GETWINORG, data);
595
596    case FBIO_GETDISPSTART:
597    case FBIO_SETDISPSTART:
598    case FBIO_GETLINEWIDTH:
599    case FBIO_SETLINEWIDTH:
600	if (scp != scp->sc->cur_scp)
601	    return ENODEV;	/* XXX */
602	return fb_ioctl(adp, cmd, data);
603
604    /* XXX */
605    case FBIO_GETPALETTE:
606    case FBIO_SETPALETTE:
607    case FBIOPUTCMAP:
608    case FBIOGETCMAP:
609	return ENODEV;
610
611    case FBIOGTYPE:
612    case FBIOGATTR:
613    case FBIOSVIDEO:
614    case FBIOGVIDEO:
615    case FBIOSCURSOR:
616    case FBIOGCURSOR:
617    case FBIOSCURPOS:
618    case FBIOGCURPOS:
619    case FBIOGCURMAX:
620	if (scp != scp->sc->cur_scp)
621	    return ENODEV;	/* XXX */
622	return fb_ioctl(adp, cmd, data);
623
624#ifndef SC_NO_MODE_CHANGE
625    /* generic text modes */
626    case SW_TEXT_80x25:	case SW_TEXT_80x30:
627    case SW_TEXT_80x43: case SW_TEXT_80x50:
628    case SW_TEXT_80x60:
629	/* FALL THROUGH */
630
631    /* VGA TEXT MODES */
632    case SW_VGA_C40x25:
633    case SW_VGA_C80x25: case SW_VGA_M80x25:
634    case SW_VGA_C80x30: case SW_VGA_M80x30:
635    case SW_VGA_C80x50: case SW_VGA_M80x50:
636    case SW_VGA_C80x60: case SW_VGA_M80x60:
637    case SW_VGA_C90x25: case SW_VGA_M90x25:
638    case SW_VGA_C90x30: case SW_VGA_M90x30:
639    case SW_VGA_C90x43: case SW_VGA_M90x43:
640    case SW_VGA_C90x50: case SW_VGA_M90x50:
641    case SW_VGA_C90x60: case SW_VGA_M90x60:
642    case SW_B40x25:     case SW_C40x25:
643    case SW_B80x25:     case SW_C80x25:
644    case SW_ENH_B40x25: case SW_ENH_C40x25:
645    case SW_ENH_B80x25: case SW_ENH_C80x25:
646    case SW_ENH_B80x43: case SW_ENH_C80x43:
647    case SW_EGAMONO80x25:
648
649#ifdef PC98
650    /* PC98 TEXT MODES */
651    case SW_PC98_80x25:
652    case SW_PC98_80x30:
653#endif
654	if (!(adp->va_flags & V_ADP_MODECHANGE))
655 	    return ENODEV;
656	return sc_set_text_mode(scp, tp, cmd & 0xff, 0, 0, 0);
657
658    /* GRAPHICS MODES */
659    case SW_BG320:     case SW_BG640:
660    case SW_CG320:     case SW_CG320_D:   case SW_CG640_E:
661    case SW_CG640x350: case SW_ENH_CG640:
662    case SW_BG640x480: case SW_CG640x480: case SW_VGA_CG320:
663    case SW_VGA_MODEX:
664	if (!(adp->va_flags & V_ADP_MODECHANGE))
665	    return ENODEV;
666	return sc_set_graphics_mode(scp, tp, cmd & 0xff);
667#endif /* SC_NO_MODE_CHANGE */
668
669    case KDSETMODE:     	/* set current mode of this (virtual) console */
670	switch (*(int *)data) {
671	case KD_TEXT:   	/* switch to TEXT (known) mode */
672	    /*
673	     * If scp->mode is of graphics modes, we don't know which
674	     * text mode to switch back to...
675	     */
676	    if (scp->status & GRAPHICS_MODE)
677		return EINVAL;
678	    /* restore fonts & palette ! */
679#if 0
680#ifndef SC_NO_FONT_LOADING
681	    if (ISFONTAVAIL(adp->va_flags)
682		&& !(scp->status & (GRAPHICS_MODE | PIXEL_MODE)))
683		/*
684		 * FONT KLUDGE
685		 * Don't load fonts for now... XXX
686		 */
687		if (scp->sc->fonts_loaded & FONT_8)
688		    copy_font(scp, LOAD, 8, scp->sc->font_8);
689		if (scp->sc->fonts_loaded & FONT_14)
690		    copy_font(scp, LOAD, 14, scp->sc->font_14);
691		if (scp->sc->fonts_loaded & FONT_16)
692		    copy_font(scp, LOAD, 16, scp->sc->font_16);
693	    }
694#endif /* SC_NO_FONT_LOADING */
695#endif
696
697#ifndef SC_NO_PALETTE_LOADING
698	    load_palette(adp, scp->sc->palette);
699#endif
700
701#ifndef PC98
702	    /* move hardware cursor out of the way */
703	    (*vidsw[adp->va_index]->set_hw_cursor)(adp, -1, -1);
704#endif
705
706	    /* FALL THROUGH */
707
708	case KD_TEXT1:  	/* switch to TEXT (known) mode */
709	    /*
710	     * If scp->mode is of graphics modes, we don't know which
711	     * text/pixel mode to switch back to...
712	     */
713	    if (scp->status & GRAPHICS_MODE)
714		return EINVAL;
715	    s = spltty();
716	    if ((error = sc_clean_up(scp))) {
717		splx(s);
718		return error;
719	    }
720#ifndef PC98
721	    scp->status |= UNKNOWN_MODE;
722	    splx(s);
723	    /* no restore fonts & palette */
724	    if (scp == scp->sc->cur_scp)
725		set_mode(scp);
726	    sc_clear_screen(scp);
727	    scp->status &= ~UNKNOWN_MODE;
728#else /* PC98 */
729	    scp->status &= ~UNKNOWN_MODE;
730	    /* no restore fonts & palette */
731	    if (scp == scp->sc->cur_scp)
732		set_mode(scp);
733	    sc_clear_screen(scp);
734	    splx(s);
735#endif /* PC98 */
736	    return 0;
737
738#ifdef SC_PIXEL_MODE
739	case KD_PIXEL:		/* pixel (raster) display */
740	    if (!(scp->status & (GRAPHICS_MODE | PIXEL_MODE)))
741		return EINVAL;
742	    if (scp->status & GRAPHICS_MODE)
743		return sc_set_pixel_mode(scp, tp, scp->xsize, scp->ysize,
744					 scp->font_size);
745	    s = spltty();
746	    if ((error = sc_clean_up(scp))) {
747		splx(s);
748		return error;
749	    }
750	    scp->status |= (UNKNOWN_MODE | PIXEL_MODE);
751	    splx(s);
752	    if (scp == scp->sc->cur_scp) {
753		set_mode(scp);
754#ifndef SC_NO_PALETTE_LOADING
755		load_palette(adp, scp->sc->palette);
756#endif
757	    }
758	    sc_clear_screen(scp);
759	    scp->status &= ~UNKNOWN_MODE;
760	    return 0;
761#endif /* SC_PIXEL_MODE */
762
763	case KD_GRAPHICS:	/* switch to GRAPHICS (unknown) mode */
764	    s = spltty();
765	    if ((error = sc_clean_up(scp))) {
766		splx(s);
767		return error;
768	    }
769	    scp->status |= UNKNOWN_MODE;
770	    splx(s);
771#ifdef PC98
772	    if (scp == scp->sc->cur_scp)
773		set_mode(scp);
774#endif
775	    return 0;
776
777	default:
778	    return EINVAL;
779	}
780	/* NOT REACHED */
781
782#ifdef SC_PIXEL_MODE
783    case KDRASTER:		/* set pixel (raster) display mode */
784	if (ISUNKNOWNSC(scp) || ISTEXTSC(scp))
785	    return ENODEV;
786	return sc_set_pixel_mode(scp, tp, ((int *)data)[0], ((int *)data)[1],
787				 ((int *)data)[2]);
788#endif /* SC_PIXEL_MODE */
789
790    case KDGETMODE:     	/* get current mode of this (virtual) console */
791	/*
792	 * From the user program's point of view, KD_PIXEL is the same
793	 * as KD_TEXT...
794	 */
795	*data = ISGRAPHSC(scp) ? KD_GRAPHICS : KD_TEXT;
796	return 0;
797
798    case KDSBORDER:     	/* set border color of this (virtual) console */
799	scp->border = *data;
800	if (scp == scp->sc->cur_scp)
801	    set_border(scp, scp->border);
802	return 0;
803    }
804
805    return ENOIOCTL;
806}
807
808#endif /* NSC > 0 */
809