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.7 2005/01/28 20:17:18 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>
42 #include <machine/console.h>
44 #include <dev/video/fb/fbreg.h>
47 SET_DECLARE(scrndr_set, const sc_renderer_t);
50 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
171 if ((*vidsw[scp->sc->adapter]->get_info)(scp->sc->adp, mode, &info))
174 /* stop screen saver, etc */
176 if ((error = sc_clean_up(scp))) {
181 if (sc_render_match(scp, scp->sc->adp->va_name, GRAPHICS_MODE) == NULL) {
187 scp->status |= (UNKNOWN_MODE | GRAPHICS_MODE | MOUSE_HIDDEN);
188 scp->status &= ~(PIXEL_MODE | MOUSE_VISIBLE);
191 * Don't change xsize and ysize; preserve the previous vty
192 * and history buffers.
196 scp->xpixel = info.vi_width;
197 scp->ypixel = info.vi_height;
200 #ifndef SC_NO_SYSMOUSE
201 /* move the mouse cursor at the center of the screen */
202 sc_mouse_move(scp, scp->xpixel / 2, scp->ypixel / 2);
204 sc_init_emulator(scp, NULL);
207 if (scp == scp->sc->cur_scp)
209 /* clear_graphics();*/
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
238 if ((*vidsw[scp->sc->adapter]->get_info)(scp->sc->adp, scp->mode, &info))
239 return ENODEV; /* this shouldn't happen */
241 /* adjust argument values */
243 fontsize = info.vi_cheight;
246 #ifndef SC_NO_FONT_LOADING
247 if (!(scp->sc->fonts_loaded & FONT_8))
249 font = scp->sc->font_8;
253 } else if (fontsize >= 16) {
255 #ifndef SC_NO_FONT_LOADING
256 if (!(scp->sc->fonts_loaded & FONT_16))
258 font = scp->sc->font_16;
264 #ifndef SC_NO_FONT_LOADING
265 if (!(scp->sc->fonts_loaded & FONT_14))
267 font = scp->sc->font_14;
273 xsize = info.vi_width/8;
275 ysize = info.vi_height/fontsize;
277 if ((info.vi_width < xsize*8) || (info.vi_height < ysize*fontsize))
281 * We currently support the following graphic modes:
283 * - 4 bpp planar modes whose memory size does not exceed 64K
284 * - 15, 16, 24 and 32 bpp linear modes
287 if (info.vi_mem_model == V_INFO_MM_PLANAR) {
288 if (info.vi_planes != 4)
292 * A memory size >64K requires bank switching to access the entire
296 if (info.vi_width * info.vi_height / 8 > info.vi_window_size)
298 } else if (info.vi_mem_model == V_INFO_MM_DIRECT) {
299 if ((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;
383 scp = SC_STAT(tp->t_dev);
384 if (scp == NULL) /* tp == SC_MOUSE */
387 if (adp == NULL) /* shouldn't happen??? */
392 case CONS_CURRENTADP: /* get current adapter index */
394 return fb_ioctl(adp, FBIO_ADAPTER, data);
396 case CONS_CURRENT: /* get current adapter type */
398 return fb_ioctl(adp, FBIO_ADPTYPE, data);
400 case CONS_ADPINFO: /* adapter information */
402 if (((video_adapter_info_t *)data)->va_index >= 0) {
403 adp = vid_get_adapter(((video_adapter_info_t *)data)->va_index);
407 return fb_ioctl(adp, FBIO_ADPINFO, data);
409 case CONS_GET: /* get current video mode */
411 *(int *)data = scp->mode;
414 #ifndef SC_NO_MODE_CHANGE
415 case FBIO_SETMODE: /* set video mode */
416 if (!(adp->va_flags & V_ADP_MODECHANGE))
418 info.vi_mode = *(int *)data;
419 error = fb_ioctl(adp, FBIO_MODEINFO, &info);
422 if (info.vi_flags & V_INFO_GRAPHICS)
423 return sc_set_graphics_mode(scp, tp, *(int *)data);
425 return sc_set_text_mode(scp, tp, *(int *)data, 0, 0, 0);
426 #endif /* SC_NO_MODE_CHANGE */
428 case CONS_MODEINFO: /* get mode information */
430 return fb_ioctl(adp, FBIO_MODEINFO, data);
432 case CONS_FINDMODE: /* find a matching video mode */
434 return fb_ioctl(adp, FBIO_FINDMODE, data);
436 case CONS_SETWINORG: /* set frame buffer window origin */
438 if (scp != scp->sc->cur_scp)
439 return ENODEV; /* XXX */
440 return fb_ioctl(adp, FBIO_SETWINORG, data);
442 case FBIO_GETWINORG: /* get frame buffer window origin */
443 if (scp != scp->sc->cur_scp)
444 return ENODEV; /* XXX */
445 return fb_ioctl(adp, FBIO_GETWINORG, data);
447 case FBIO_GETDISPSTART:
448 case FBIO_SETDISPSTART:
449 case FBIO_GETLINEWIDTH:
450 case FBIO_SETLINEWIDTH:
451 if (scp != scp->sc->cur_scp)
452 return ENODEV; /* XXX */
453 return fb_ioctl(adp, cmd, data);
455 case FBIO_GETPALETTE:
456 case FBIO_SETPALETTE:
468 if (scp != scp->sc->cur_scp)
469 return ENODEV; /* XXX */
470 return fb_ioctl(adp, cmd, data);
472 #ifndef SC_NO_MODE_CHANGE
473 /* generic text modes */
474 case SW_TEXT_80x25: case SW_TEXT_80x30:
475 case SW_TEXT_80x43: case SW_TEXT_80x50:
481 case SW_VGA_C80x25: case SW_VGA_M80x25:
482 case SW_VGA_C80x30: case SW_VGA_M80x30:
483 case SW_VGA_C80x50: case SW_VGA_M80x50:
484 case SW_VGA_C80x60: case SW_VGA_M80x60:
485 case SW_VGA_C90x25: case SW_VGA_M90x25:
486 case SW_VGA_C90x30: case SW_VGA_M90x30:
487 case SW_VGA_C90x43: case SW_VGA_M90x43:
488 case SW_VGA_C90x50: case SW_VGA_M90x50:
489 case SW_VGA_C90x60: case SW_VGA_M90x60:
490 case SW_B40x25: case SW_C40x25:
491 case SW_B80x25: case SW_C80x25:
492 case SW_ENH_B40x25: case SW_ENH_C40x25:
493 case SW_ENH_B80x25: case SW_ENH_C80x25:
494 case SW_ENH_B80x43: case SW_ENH_C80x43:
495 case SW_EGAMONO80x25:
498 /* PC98 TEXT MODES */
502 if (!(adp->va_flags & V_ADP_MODECHANGE))
504 return sc_set_text_mode(scp, tp, cmd & 0xff, 0, 0, 0);
507 case SW_BG320: case SW_BG640:
508 case SW_CG320: case SW_CG320_D: case SW_CG640_E:
509 case SW_CG640x350: case SW_ENH_CG640:
510 case SW_BG640x480: case SW_CG640x480: case SW_VGA_CG320:
513 /* PC98 GRAPHICS MODES */
514 case SW_PC98_EGC640x400: case SW_PC98_PEGC640x400:
515 case SW_PC98_PEGC640x480:
517 if (!(adp->va_flags & V_ADP_MODECHANGE))
519 return sc_set_graphics_mode(scp, tp, cmd & 0xff);
520 #endif /* SC_NO_MODE_CHANGE */
522 case KDSETMODE: /* set current mode of this (virtual) console */
523 switch (*(int *)data) {
524 case KD_TEXT: /* switch to TEXT (known) mode */
526 * If scp->mode is of graphics modes, we don't know which
527 * text mode to switch back to...
529 if (scp->status & GRAPHICS_MODE)
531 /* restore fonts & palette ! */
533 #ifndef SC_NO_FONT_LOADING
534 if (ISFONTAVAIL(adp->va_flags)
535 && !(scp->status & (GRAPHICS_MODE | PIXEL_MODE)))
538 * Don't load fonts for now... XXX
540 if (scp->sc->fonts_loaded & FONT_8)
541 sc_load_font(scp, 0, 8, scp->sc->font_8, 0, 256);
542 if (scp->sc->fonts_loaded & FONT_14)
543 sc_load_font(scp, 0, 14, scp->sc->font_14, 0, 256);
544 if (scp->sc->fonts_loaded & FONT_16)
545 sc_load_font(scp, 0, 16, scp->sc->font_16, 0, 256);
547 #endif /* SC_NO_FONT_LOADING */
550 #ifndef SC_NO_PALETTE_LOADING
551 load_palette(adp, scp->sc->palette);
555 /* move hardware cursor out of the way */
556 (*vidsw[adp->va_index]->set_hw_cursor)(adp, -1, -1);
561 case KD_TEXT1: /* switch to TEXT (known) mode */
563 * If scp->mode is of graphics modes, we don't know which
564 * text/pixel mode to switch back to...
566 if (scp->status & GRAPHICS_MODE)
569 if ((error = sc_clean_up(scp))) {
574 scp->status |= UNKNOWN_MODE | MOUSE_HIDDEN;
576 /* no restore fonts & palette */
577 if (scp == scp->sc->cur_scp)
579 sc_clear_screen(scp);
580 scp->status &= ~UNKNOWN_MODE;
582 scp->status &= ~UNKNOWN_MODE;
583 /* no restore fonts & palette */
584 if (scp == scp->sc->cur_scp)
586 sc_clear_screen(scp);
592 case KD_PIXEL: /* pixel (raster) display */
593 if (!(scp->status & (GRAPHICS_MODE | PIXEL_MODE)))
595 if (scp->status & GRAPHICS_MODE)
596 return sc_set_pixel_mode(scp, tp, scp->xsize, scp->ysize,
599 if ((error = sc_clean_up(scp))) {
603 scp->status |= (UNKNOWN_MODE | PIXEL_MODE | MOUSE_HIDDEN);
605 if (scp == scp->sc->cur_scp) {
607 #ifndef SC_NO_PALETTE_LOADING
608 load_palette(adp, scp->sc->palette);
611 sc_clear_screen(scp);
612 scp->status &= ~UNKNOWN_MODE;
614 #endif /* SC_PIXEL_MODE */
616 case KD_GRAPHICS: /* switch to GRAPHICS (unknown) mode */
618 if ((error = sc_clean_up(scp))) {
622 scp->status |= UNKNOWN_MODE | MOUSE_HIDDEN;
625 if (scp == scp->sc->cur_scp)
636 case KDRASTER: /* set pixel (raster) display mode */
637 if (ISUNKNOWNSC(scp) || ISTEXTSC(scp))
639 return sc_set_pixel_mode(scp, tp, ((int *)data)[0], ((int *)data)[1],
641 #endif /* SC_PIXEL_MODE */
643 case KDGETMODE: /* get current mode of this (virtual) console */
645 * From the user program's point of view, KD_PIXEL is the same
648 *data = ISGRAPHSC(scp) ? KD_GRAPHICS : KD_TEXT;
651 case KDSBORDER: /* set border color of this (virtual) console */
653 if (scp == scp->sc->cur_scp)
654 sc_set_border(scp, scp->border);
661 static LIST_HEAD(, sc_renderer) sc_rndr_list =
662 LIST_HEAD_INITIALIZER(sc_rndr_list);
665 sc_render_add(sc_renderer_t *rndr)
667 LIST_INSERT_HEAD(&sc_rndr_list, rndr, link);
672 sc_render_remove(sc_renderer_t *rndr)
675 LIST_REMOVE(rndr, link);
677 return EBUSY; /* XXX */
681 *sc_render_match(scr_stat *scp, char *name, int mode)
683 const sc_renderer_t **list;
684 const sc_renderer_t *p;
686 if (!LIST_EMPTY(&sc_rndr_list)) {
687 LIST_FOREACH(p, &sc_rndr_list, link) {
688 if ((strcmp(p->name, name) == 0)
689 && (mode == p->mode)) {
691 ~(VR_CURSOR_ON | VR_CURSOR_BLINK);
696 SET_FOREACH(list, scrndr_set) {
698 if ((strcmp(p->name, name) == 0)
699 && (mode == p->mode)) {
701 ~(VR_CURSOR_ON | VR_CURSOR_BLINK);