2 * Copyright (c) 1998 Kazutaka YOKOTA <yokota@zodiac.mech.utsunomiya-u.ac.jp>
5 * This code is derived from software contributed to The DragonFly Project
6 * by Sascha Wildner <saw@online.de>
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer as
13 * the first lines of this file unmodified.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
23 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 * $FreeBSD: src/sys/dev/syscons/scvidctl.c,v 1.19.2.2 2000/05/05 09:16:08 nyan Exp $
30 * $DragonFly: src/sys/dev/misc/syscons/scvidctl.c,v 1.11 2005/07/17 16:50:40 swildner Exp $
33 #include "opt_syscons.h"
35 #include <sys/param.h>
36 #include <sys/systm.h>
38 #include <sys/signalvar.h>
40 #include <sys/kernel.h>
41 #include <sys/thread2.h>
43 #include <machine/console.h>
45 #include <dev/video/fb/fbreg.h>
48 SET_DECLARE(scrndr_set, const sc_renderer_t);
51 sc_set_text_mode(scr_stat *scp, struct tty *tp, int mode, int xsize, int ysize,
59 if ((*vidsw[scp->sc->adapter]->get_info)(scp->sc->adp, mode, &info))
62 /* adjust argument values */
64 fontsize = info.vi_cheight;
67 #ifndef SC_NO_FONT_LOADING
68 if (!(scp->sc->fonts_loaded & FONT_8))
70 font = scp->sc->font_8;
74 } else if (fontsize >= 16) {
76 #ifndef SC_NO_FONT_LOADING
77 if (!(scp->sc->fonts_loaded & FONT_16))
79 font = scp->sc->font_16;
85 #ifndef SC_NO_FONT_LOADING
86 if (!(scp->sc->fonts_loaded & FONT_14))
88 font = scp->sc->font_14;
93 if ((xsize <= 0) || (xsize > info.vi_width))
94 xsize = info.vi_width;
95 if ((ysize <= 0) || (ysize > info.vi_height))
96 ysize = info.vi_height;
98 /* stop screen saver, etc */
100 if ((error = sc_clean_up(scp))) {
105 if (sc_render_match(scp, scp->sc->adp->va_name, 0) == NULL) {
111 #ifndef SC_NO_HISTORY
112 if (scp->history != NULL)
115 prev_ysize = scp->ysize;
117 * This is a kludge to fend off scrn_update() while we
118 * muck around with scp. XXX
120 scp->status |= UNKNOWN_MODE | MOUSE_HIDDEN;
121 scp->status &= ~(GRAPHICS_MODE | PIXEL_MODE | MOUSE_VISIBLE);
127 scp->xpixel = scp->xsize*8;
128 scp->ypixel = scp->ysize*fontsize;
130 scp->font_size = fontsize;
132 /* allocate buffers */
133 sc_alloc_scr_buffer(scp, TRUE, TRUE);
134 sc_init_emulator(scp, NULL);
135 #ifndef SC_NO_CUTPASTE
136 sc_alloc_cut_buffer(scp, FALSE);
138 #ifndef SC_NO_HISTORY
139 sc_alloc_history_buffer(scp, 0, prev_ysize, FALSE);
143 if (scp == scp->sc->cur_scp)
145 scp->status &= ~UNKNOWN_MODE;
149 DPRINTF(5, ("ws_*size (%d,%d), size (%d,%d)\n",
150 tp->t_winsize.ws_col, tp->t_winsize.ws_row, scp->xsize, scp->ysize));
151 if (tp->t_winsize.ws_col != scp->xsize
152 || tp->t_winsize.ws_row != scp->ysize) {
153 tp->t_winsize.ws_col = scp->xsize;
154 tp->t_winsize.ws_row = scp->ysize;
155 pgsignal(tp->t_pgrp, SIGWINCH, 1);
162 sc_set_graphics_mode(scr_stat *scp, struct tty *tp, int mode)
164 #ifdef SC_NO_MODE_CHANGE
170 if ((*vidsw[scp->sc->adapter]->get_info)(scp->sc->adp, mode, &info))
173 /* stop screen saver, etc */
175 if ((error = sc_clean_up(scp))) {
180 if (sc_render_match(scp, scp->sc->adp->va_name, GRAPHICS_MODE) == NULL) {
186 scp->status |= (UNKNOWN_MODE | GRAPHICS_MODE | MOUSE_HIDDEN);
187 scp->status &= ~(PIXEL_MODE | MOUSE_VISIBLE);
190 * Don't change xsize and ysize; preserve the previous vty
191 * and history buffers.
195 scp->xpixel = info.vi_width;
196 scp->ypixel = info.vi_height;
199 #ifndef SC_NO_SYSMOUSE
200 /* move the mouse cursor at the center of the screen */
201 sc_mouse_move(scp, scp->xpixel / 2, scp->ypixel / 2);
203 sc_init_emulator(scp, NULL);
206 if (scp == scp->sc->cur_scp)
208 /* clear_graphics();*/
209 refresh_ega_palette(scp);
210 scp->status &= ~UNKNOWN_MODE;
214 if (tp->t_winsize.ws_xpixel != scp->xpixel
215 || tp->t_winsize.ws_ypixel != scp->ypixel) {
216 tp->t_winsize.ws_xpixel = scp->xpixel;
217 tp->t_winsize.ws_ypixel = scp->ypixel;
218 pgsignal(tp->t_pgrp, SIGWINCH, 1);
222 #endif /* SC_NO_MODE_CHANGE */
226 sc_set_pixel_mode(scr_stat *scp, struct tty *tp, int xsize, int ysize,
229 #ifndef SC_PIXEL_MODE
237 if ((*vidsw[scp->sc->adapter]->get_info)(scp->sc->adp, scp->mode, &info))
238 return ENODEV; /* this shouldn't happen */
240 /* adjust argument values */
242 fontsize = info.vi_cheight;
245 #ifndef SC_NO_FONT_LOADING
246 if (!(scp->sc->fonts_loaded & FONT_8))
248 font = scp->sc->font_8;
252 } else if (fontsize >= 16) {
254 #ifndef SC_NO_FONT_LOADING
255 if (!(scp->sc->fonts_loaded & FONT_16))
257 font = scp->sc->font_16;
263 #ifndef SC_NO_FONT_LOADING
264 if (!(scp->sc->fonts_loaded & FONT_14))
266 font = scp->sc->font_14;
272 xsize = info.vi_width/8;
274 ysize = info.vi_height/fontsize;
276 if ((info.vi_width < xsize*8) || (info.vi_height < ysize*fontsize))
280 * We currently support the following graphic modes:
282 * - 4 bpp planar modes whose memory size does not exceed 64K
283 * - 15, 16, 24 and 32 bpp direct modes with linear frame buffer
286 if (info.vi_mem_model == V_INFO_MM_PLANAR) {
287 if (info.vi_planes != 4)
291 * A memory size >64K requires bank switching to access the entire
295 if (info.vi_width * info.vi_height / 8 > info.vi_window_size)
297 } else if (info.vi_mem_model == V_INFO_MM_DIRECT) {
298 if (!(info.vi_flags & V_INFO_LINEAR) &&
299 (info.vi_depth != 15) && (info.vi_depth != 16) &&
300 (info.vi_depth != 24) && (info.vi_depth != 32))
305 /* stop screen saver, etc */
307 if ((error = sc_clean_up(scp))) {
312 if (sc_render_match(scp, scp->sc->adp->va_name, PIXEL_MODE) == NULL) {
319 (*scp->tsw->te_term)(scp, scp->ts);
325 #ifndef SC_NO_HISTORY
326 if (scp->history != NULL)
329 prev_ysize = scp->ysize;
330 scp->status |= (UNKNOWN_MODE | PIXEL_MODE | MOUSE_HIDDEN);
331 scp->status &= ~(GRAPHICS_MODE | MOUSE_VISIBLE);
334 scp->xoff = (scp->xpixel/8 - xsize)/2;
335 scp->yoff = (scp->ypixel/fontsize - ysize)/2;
337 scp->font_size = fontsize;
339 /* allocate buffers */
340 sc_alloc_scr_buffer(scp, TRUE, TRUE);
341 sc_init_emulator(scp, NULL);
342 #ifndef SC_NO_CUTPASTE
343 sc_alloc_cut_buffer(scp, FALSE);
345 #ifndef SC_NO_HISTORY
346 sc_alloc_history_buffer(scp, 0, prev_ysize, FALSE);
350 if (scp == scp->sc->cur_scp) {
351 sc_set_border(scp, scp->border);
352 sc_set_cursor_image(scp);
355 scp->status &= ~UNKNOWN_MODE;
359 if (tp->t_winsize.ws_col != scp->xsize
360 || tp->t_winsize.ws_row != scp->ysize) {
361 tp->t_winsize.ws_col = scp->xsize;
362 tp->t_winsize.ws_row = scp->ysize;
363 pgsignal(tp->t_pgrp, SIGWINCH, 1);
367 #endif /* SC_PIXEL_MODE */
370 #define fb_ioctl(a, c, d) \
371 (((a) == NULL) ? ENODEV : \
372 (*vidsw[(a)->va_index]->ioctl)((a), (c), (caddr_t)(d)))
375 sc_vid_ioctl(struct tty *tp, u_long cmd, caddr_t data, int flag, struct thread *td)
378 video_adapter_t *adp;
382 scp = SC_STAT(tp->t_dev);
383 if (scp == NULL) /* tp == SC_MOUSE */
386 if (adp == NULL) /* shouldn't happen??? */
391 case CONS_CURRENTADP: /* get current adapter index */
393 return fb_ioctl(adp, FBIO_ADAPTER, data);
395 case CONS_CURRENT: /* get current adapter type */
397 return fb_ioctl(adp, FBIO_ADPTYPE, data);
399 case CONS_ADPINFO: /* adapter information */
401 if (((video_adapter_info_t *)data)->va_index >= 0) {
402 adp = vid_get_adapter(((video_adapter_info_t *)data)->va_index);
406 return fb_ioctl(adp, FBIO_ADPINFO, data);
408 case CONS_GET: /* get current video mode */
410 *(int *)data = scp->mode;
413 #ifndef SC_NO_MODE_CHANGE
414 case FBIO_SETMODE: /* set video mode */
415 if (!(adp->va_flags & V_ADP_MODECHANGE))
417 info.vi_mode = *(int *)data;
418 error = fb_ioctl(adp, FBIO_MODEINFO, &info);
421 if (info.vi_flags & V_INFO_GRAPHICS)
422 return sc_set_graphics_mode(scp, tp, *(int *)data);
424 return sc_set_text_mode(scp, tp, *(int *)data, 0, 0, 0);
425 #endif /* SC_NO_MODE_CHANGE */
427 case CONS_MODEINFO: /* get mode information */
429 return fb_ioctl(adp, FBIO_MODEINFO, data);
431 case CONS_FINDMODE: /* find a matching video mode */
433 return fb_ioctl(adp, FBIO_FINDMODE, data);
435 case CONS_SETWINORG: /* set frame buffer window origin */
437 if (scp != scp->sc->cur_scp)
438 return ENODEV; /* XXX */
439 return fb_ioctl(adp, FBIO_SETWINORG, data);
441 case FBIO_GETWINORG: /* get frame buffer window origin */
442 if (scp != scp->sc->cur_scp)
443 return ENODEV; /* XXX */
444 return fb_ioctl(adp, FBIO_GETWINORG, data);
446 case FBIO_GETDISPSTART:
447 case FBIO_SETDISPSTART:
448 case FBIO_GETLINEWIDTH:
449 case FBIO_SETLINEWIDTH:
450 if (scp != scp->sc->cur_scp)
451 return ENODEV; /* XXX */
452 return fb_ioctl(adp, cmd, data);
454 case FBIO_GETPALETTE:
455 case FBIO_SETPALETTE:
467 if (scp != scp->sc->cur_scp)
468 return ENODEV; /* XXX */
469 return fb_ioctl(adp, cmd, data);
471 #ifndef SC_NO_MODE_CHANGE
472 /* generic text modes */
473 case SW_TEXT_80x25: case SW_TEXT_80x30:
474 case SW_TEXT_80x43: case SW_TEXT_80x50:
480 case SW_VGA_C80x25: case SW_VGA_M80x25:
481 case SW_VGA_C80x30: case SW_VGA_M80x30:
482 case SW_VGA_C80x50: case SW_VGA_M80x50:
483 case SW_VGA_C80x60: case SW_VGA_M80x60:
484 case SW_VGA_C90x25: case SW_VGA_M90x25:
485 case SW_VGA_C90x30: case SW_VGA_M90x30:
486 case SW_VGA_C90x43: case SW_VGA_M90x43:
487 case SW_VGA_C90x50: case SW_VGA_M90x50:
488 case SW_VGA_C90x60: case SW_VGA_M90x60:
489 case SW_B40x25: case SW_C40x25:
490 case SW_B80x25: case SW_C80x25:
491 case SW_ENH_B40x25: case SW_ENH_C40x25:
492 case SW_ENH_B80x25: case SW_ENH_C80x25:
493 case SW_ENH_B80x43: case SW_ENH_C80x43:
494 case SW_EGAMONO80x25:
495 if (!(adp->va_flags & V_ADP_MODECHANGE))
497 return sc_set_text_mode(scp, tp, cmd & 0xff, 0, 0, 0);
500 case SW_BG320: case SW_BG640:
501 case SW_CG320: case SW_CG320_D: case SW_CG640_E:
502 case SW_CG640x350: case SW_ENH_CG640:
503 case SW_BG640x480: case SW_CG640x480: case SW_VGA_CG320:
505 if (!(adp->va_flags & V_ADP_MODECHANGE))
507 return sc_set_graphics_mode(scp, tp, cmd & 0xff);
508 #endif /* SC_NO_MODE_CHANGE */
510 case KDSETMODE: /* set current mode of this (virtual) console */
511 switch (*(int *)data) {
512 case KD_TEXT: /* switch to TEXT (known) mode */
514 * If scp->mode is of graphics modes, we don't know which
515 * text mode to switch back to...
517 if (scp->status & GRAPHICS_MODE)
519 /* restore fonts & palette ! */
521 #ifndef SC_NO_FONT_LOADING
522 if (ISFONTAVAIL(adp->va_flags)
523 && !(scp->status & (GRAPHICS_MODE | PIXEL_MODE)))
526 * Don't load fonts for now... XXX
528 if (scp->sc->fonts_loaded & FONT_8)
529 sc_load_font(scp, 0, 8, scp->sc->font_8, 0, 256);
530 if (scp->sc->fonts_loaded & FONT_14)
531 sc_load_font(scp, 0, 14, scp->sc->font_14, 0, 256);
532 if (scp->sc->fonts_loaded & FONT_16)
533 sc_load_font(scp, 0, 16, scp->sc->font_16, 0, 256);
535 #endif /* SC_NO_FONT_LOADING */
538 #ifndef SC_NO_PALETTE_LOADING
539 load_palette(adp, scp->sc->palette);
542 /* move hardware cursor out of the way */
543 (*vidsw[adp->va_index]->set_hw_cursor)(adp, -1, -1);
546 case KD_TEXT1: /* switch to TEXT (known) mode */
548 * If scp->mode is of graphics modes, we don't know which
549 * text/pixel mode to switch back to...
551 if (scp->status & GRAPHICS_MODE)
554 if ((error = sc_clean_up(scp))) {
558 scp->status |= UNKNOWN_MODE | MOUSE_HIDDEN;
560 /* no restore fonts & palette */
561 if (scp == scp->sc->cur_scp)
563 sc_clear_screen(scp);
564 scp->status &= ~UNKNOWN_MODE;
568 case KD_PIXEL: /* pixel (raster) display */
569 if (!(scp->status & (GRAPHICS_MODE | PIXEL_MODE)))
571 if (scp->status & GRAPHICS_MODE)
572 return sc_set_pixel_mode(scp, tp, scp->xsize, scp->ysize,
575 if ((error = sc_clean_up(scp))) {
579 scp->status |= (UNKNOWN_MODE | PIXEL_MODE | MOUSE_HIDDEN);
581 if (scp == scp->sc->cur_scp) {
583 #ifndef SC_NO_PALETTE_LOADING
584 load_palette(adp, scp->sc->palette);
587 sc_clear_screen(scp);
588 scp->status &= ~UNKNOWN_MODE;
590 #endif /* SC_PIXEL_MODE */
592 case KD_GRAPHICS: /* switch to GRAPHICS (unknown) mode */
594 if ((error = sc_clean_up(scp))) {
598 scp->status |= UNKNOWN_MODE | MOUSE_HIDDEN;
608 case KDRASTER: /* set pixel (raster) display mode */
609 if (ISUNKNOWNSC(scp) || ISTEXTSC(scp))
611 return sc_set_pixel_mode(scp, tp, ((int *)data)[0], ((int *)data)[1],
613 #endif /* SC_PIXEL_MODE */
615 case KDGETMODE: /* get current mode of this (virtual) console */
617 * From the user program's point of view, KD_PIXEL is the same
620 *data = ISGRAPHSC(scp) ? KD_GRAPHICS : KD_TEXT;
623 case KDSBORDER: /* set border color of this (virtual) console */
625 if (scp == scp->sc->cur_scp)
626 sc_set_border(scp, scp->border);
633 static LIST_HEAD(, sc_renderer) sc_rndr_list =
634 LIST_HEAD_INITIALIZER(sc_rndr_list);
637 sc_render_add(sc_renderer_t *rndr)
639 LIST_INSERT_HEAD(&sc_rndr_list, rndr, link);
644 sc_render_remove(sc_renderer_t *rndr)
647 LIST_REMOVE(rndr, link);
649 return EBUSY; /* XXX */
653 *sc_render_match(scr_stat *scp, char *name, int mode)
655 const sc_renderer_t **list;
656 const sc_renderer_t *p;
658 if (!LIST_EMPTY(&sc_rndr_list)) {
659 LIST_FOREACH(p, &sc_rndr_list, link) {
660 if ((strcmp(p->name, name) == 0)
661 && (mode == p->mode)) {
663 ~(VR_CURSOR_ON | VR_CURSOR_BLINK);
668 SET_FOREACH(list, scrndr_set) {
670 if ((strcmp(p->name, name) == 0)
671 && (mode == p->mode)) {
673 ~(VR_CURSOR_ON | VR_CURSOR_BLINK);