2 * Copyright (c) 1992-1998 Søren Schmidt
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,
13 * without modification, immediately at the beginning of the file.
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.
17 * 3. The name of the author may not be used to endorse or promote products
18 * derived from this software without specific prior written permission.
20 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
21 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
22 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
23 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
24 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
25 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
29 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 * $FreeBSD: /usr/local/www/cvsroot/FreeBSD/src/sys/dev/syscons/syscons.c,v 1.336.2.17 2004/03/25 08:41:09 ru Exp $
32 * $DragonFly: src/sys/dev/misc/syscons/syscons.c,v 1.35 2008/08/10 19:47:31 swildner Exp $
35 #include "use_splash.h"
36 #include "opt_syscons.h"
42 #include <sys/param.h>
43 #include <sys/systm.h>
44 #include <sys/eventhandler.h>
45 #include <sys/reboot.h>
49 #include <sys/signalvar.h>
50 #include <sys/sysctl.h>
52 #include <sys/kernel.h>
54 #include <sys/random.h>
56 #include <sys/thread2.h>
57 #include <sys/spinlock2.h>
59 #include <machine/clock.h>
60 #include <machine/console.h>
61 #include <machine/psl.h>
62 #include <machine/pc/display.h>
64 #include <machine/apm_bios.h>
66 #include <machine/frame.h>
68 #include <dev/misc/kbd/kbdreg.h>
69 #include <dev/video/fb/fbreg.h>
70 #include <dev/video/fb/splashreg.h>
76 #define DEFAULT_BLANKTIME (5*60) /* 5 minutes */
77 #define MAX_BLANKTIME (7*24*60*60) /* 7 days!? */
79 #define KEYCODE_BS 0x0e /* "<-- Backspace" key, XXX */
81 MALLOC_DEFINE(M_SYSCONS, "syscons", "Syscons");
83 typedef struct default_attr {
84 int std_color; /* normal hardware color */
85 int rev_color; /* reverse hardware color */
88 static default_attr user_default = {
93 static default_attr kernel_default = {
95 SC_KERNEL_CONS_REV_ATTR,
98 static int sc_console_unit = -1;
99 static scr_stat *sc_console;
100 static struct tty *sc_console_tty;
101 static void *kernel_console_ts;
103 static char init_done = COLD;
104 static char shutdown_in_progress = FALSE;
105 static char sc_malloc = FALSE;
107 static int saver_mode = CONS_NO_SAVER; /* LKM/user saver */
108 static int run_scrn_saver = FALSE; /* should run the saver? */
109 static long scrn_blank_time = 0; /* screen saver timeout value */
111 static int scrn_blanked; /* # of blanked screen */
112 static int sticky_splash = FALSE;
114 static void none_saver(sc_softc_t *sc, int blank) { }
115 static void (*current_saver)(sc_softc_t *, int) = none_saver;
118 #if !defined(SC_NO_FONT_LOADING) && defined(SC_DFLT_FONT)
122 static bios_values_t bios_value;
124 static int enable_panic_key;
125 SYSCTL_INT(_machdep, OID_AUTO, enable_panic_key, CTLFLAG_RW, &enable_panic_key,
128 #define SC_CONSOLECTL 255
130 #define VIRTUAL_TTY(sc, x) ((SC_DEV((sc),(x)) != NULL) ? \
131 (SC_DEV((sc),(x))->si_tty) : NULL)
132 #define ISTTYOPEN(tp) ((tp) && ((tp)->t_state & TS_ISOPEN))
135 static cdev_t cctl_dev;
136 static timeout_t blink_screen;
137 static struct spinlock syscons_spin = SPINLOCK_INITIALIZER(syscons_spin);
140 static int scvidprobe(int unit, int flags, int cons);
141 static int sckbdprobe(int unit, int flags, int cons);
142 static void scmeminit(void *arg);
143 static int scdevtounit(cdev_t dev);
144 static kbd_callback_func_t sckbdevent;
145 static int scparam(struct tty *tp, struct termios *t);
146 static void scstart(struct tty *tp);
147 static void scinit(int unit, int flags);
148 static void scterm(int unit, int flags);
149 static void scshutdown(void *arg, int howto);
150 static void sc_puts(scr_stat *scp, u_char *buf, int len);
151 static u_int scgetc(sc_softc_t *sc, u_int flags);
153 #define SCGETC_NONBLOCK 2
154 static int sccngetch(int flags);
155 static void sccnupdate(scr_stat *scp);
156 static scr_stat *alloc_scp(sc_softc_t *sc, int vty);
157 static void init_scp(sc_softc_t *sc, int vty, scr_stat *scp);
158 static timeout_t scrn_timer;
159 static int and_region(int *s1, int *e1, int s2, int e2);
160 static void scrn_update(scr_stat *scp, int show_cursor);
163 static int scsplash_callback(int event, void *arg);
164 static void scsplash_saver(sc_softc_t *sc, int show);
165 static int add_scrn_saver(void (*this_saver)(sc_softc_t *, int));
166 static int remove_scrn_saver(void (*this_saver)(sc_softc_t *, int));
167 static int set_scrn_saver_mode(scr_stat *scp, int mode, u_char *pal, int border);
168 static int restore_scrn_saver_mode(scr_stat *scp, int changemode);
169 static void stop_scrn_saver(sc_softc_t *sc, void (*saver)(sc_softc_t *, int));
170 static int wait_scrn_saver_stop(sc_softc_t *sc);
171 #define scsplash_stick(stick) (sticky_splash = (stick))
173 #define scsplash_stick(stick)
176 static void do_switch_scr(sc_softc_t *sc);
177 static int vt_proc_alive(scr_stat *scp);
178 static int signal_vt_rel(scr_stat *scp);
179 static int signal_vt_acq(scr_stat *scp);
180 static int finish_vt_rel(scr_stat *scp, int release);
181 static int finish_vt_acq(scr_stat *scp);
182 static void exchange_scr(sc_softc_t *sc);
183 static void update_cursor_image(scr_stat *scp);
184 static int save_kbd_state(scr_stat *scp);
185 static int update_kbd_state(scr_stat *scp, int state, int mask);
186 static int update_kbd_leds(scr_stat *scp, int which);
187 static int sc_allocate_keyboard(sc_softc_t *sc, int unit);
190 * Console locking daemon
195 spin_lock_wr(&syscons_spin);
199 * Returns non-zero on success, 0 on failure.
202 syscons_lock_nonblock(void)
204 return(spin_trylock_wr(&syscons_spin));
210 spin_unlock_wr(&syscons_spin);
216 #define CDEV_MAJOR 12
218 static cn_probe_t sccnprobe;
219 static cn_init_t sccninit;
220 static cn_init_t sccninit_fini;
221 static cn_getc_t sccngetc;
222 static cn_checkc_t sccncheckc;
223 static cn_putc_t sccnputc;
224 static cn_dbctl_t sccndbctl;
225 static cn_term_t sccnterm;
227 CONS_DRIVER(sc, sccnprobe, sccninit, sccninit_fini, sccnterm,
228 sccngetc, sccncheckc, sccnputc, sccndbctl);
230 static d_open_t scopen;
231 static d_close_t scclose;
232 static d_read_t scread;
233 static d_ioctl_t scioctl;
234 static d_mmap_t scmmap;
236 static struct dev_ops sc_ops = {
237 { "sc", CDEV_MAJOR, D_TTY },
244 .d_kqfilter = ttykqfilter,
245 .d_revoke = ttyrevoke
249 sc_probe_unit(int unit, int flags)
251 if (!scvidprobe(unit, flags, FALSE)) {
253 kprintf("sc%d: no video adapter found.\n", unit);
257 /* syscons will be attached even when there is no keyboard */
258 sckbdprobe(unit, flags, FALSE);
263 /* probe video adapters, return TRUE if found */
265 scvidprobe(int unit, int flags, int cons)
268 * Access the video adapter driver through the back door!
269 * Video adapter drivers need to be configured before syscons.
270 * However, when syscons is being probed as the low-level console,
271 * they have not been initialized yet. We force them to initialize
272 * themselves here. XXX
274 vid_configure(cons ? VIO_PROBE_ONLY : 0);
276 return (vid_find_adapter("*", unit) >= 0);
279 /* probe the keyboard, return TRUE if found */
281 sckbdprobe(int unit, int flags, int cons)
283 /* access the keyboard driver through the backdoor! */
284 kbd_configure(cons ? KB_CONF_PROBE_ONLY : 0);
286 return (kbd_find_keyboard("*", unit) >= 0);
290 adapter_name(video_adapter_t *adp)
296 { KD_MONO, { "MDA", "MDA" } },
297 { KD_HERCULES, { "Hercules", "Hercules" } },
298 { KD_CGA, { "CGA", "CGA" } },
299 { KD_EGA, { "EGA", "EGA (mono)" } },
300 { KD_VGA, { "VGA", "VGA (mono)" } },
301 { KD_TGA, { "TGA", "TGA" } },
302 { -1, { "Unknown", "Unknown" } },
306 for (i = 0; names[i].type != -1; ++i)
307 if (names[i].type == adp->va_type)
309 return names[i].name[(adp->va_flags & V_ADP_COLOR) ? 0 : 1];
313 sc_attach_unit(int unit, int flags)
323 flags &= ~SC_KERNEL_CONSOLE;
325 if (sc_console_unit == unit) {
327 * If this unit is being used as the system console, we need to
328 * adjust some variables and buffers before and after scinit().
330 /* assert(sc_console != NULL) */
331 flags |= SC_KERNEL_CONSOLE;
336 if (sc_console->tsw->te_size > 0) {
337 /* assert(sc_console->ts != NULL); */
338 kernel_console_ts = sc_console->ts;
339 sc_console->ts = kmalloc(sc_console->tsw->te_size,
340 M_SYSCONS, M_WAITOK);
341 bcopy(kernel_console_ts, sc_console->ts, sc_console->tsw->te_size);
342 (*sc_console->tsw->te_default_attr)(sc_console,
343 user_default.std_color,
344 user_default.rev_color);
350 sc = sc_get_softc(unit, flags & SC_KERNEL_CONSOLE);
353 * If this is the console we couldn't setup sc->dev before because
354 * malloc wasn't working. Set it up now.
356 if (flags & SC_KERNEL_CONSOLE) {
357 KKASSERT(sc->dev == NULL);
358 sc->dev = kmalloc(sizeof(cdev_t)*sc->vtys, M_SYSCONS, M_WAITOK|M_ZERO);
359 sc->dev[0] = make_dev(&sc_ops, sc_console_unit*MAXCONS, UID_ROOT,
361 "ttyv%r", sc_console_unit*MAXCONS);
362 sc->dev[0]->si_tty = ttymalloc(sc->dev[0]->si_tty);
363 sc->dev[0]->si_drv1 = sc_console;
367 * Finish up the standard attach
370 callout_init(&sc->scrn_timer_ch);
371 scp = SC_STAT(sc->dev[0]);
372 if (sc_console == NULL) /* sc_console_unit < 0 */
376 if ((sc->config & SC_VESA800X600)
377 && ((*vidsw[sc->adapter]->get_info)(sc->adp, M_VESA_800x600, &info) == 0)) {
379 if (sc->flags & SC_SPLASH_SCRN)
380 splash_term(sc->adp);
382 sc_set_graphics_mode(scp, NULL, M_VESA_800x600);
383 sc_set_pixel_mode(scp, NULL, 0, 0, 16);
384 sc->initial_mode = M_VESA_800x600;
386 /* put up the splash again! */
387 if (sc->flags & SC_SPLASH_SCRN)
388 splash_init(sc->adp, scsplash_callback, sc);
391 #endif /* SC_PIXEL_MODE */
393 /* initialize cursor */
395 update_cursor_image(scp);
397 /* get screen update going */
400 /* set up the keyboard */
401 kbd_ioctl(sc->kbd, KDSKBMODE, (caddr_t)&scp->kbd_mode);
402 update_kbd_state(scp, scp->status, LOCK_MASK);
404 kprintf("sc%d: %s <%d virtual consoles, flags=0x%x>\n",
405 unit, adapter_name(sc->adp), sc->vtys, sc->config);
407 kprintf("sc%d:", unit);
408 if (sc->adapter >= 0)
409 kprintf(" fb%d", sc->adapter);
410 if (sc->keyboard >= 0)
411 kprintf(", kbd%d", sc->keyboard);
413 kprintf(", terminal emulator: %s (%s)",
414 scp->tsw->te_name, scp->tsw->te_desc);
418 /* register a shutdown callback for the kernel console */
419 if (sc_console_unit == unit)
420 EVENTHANDLER_REGISTER(shutdown_pre_sync, scshutdown,
421 (void *)(uintptr_t)unit, SHUTDOWN_PRI_DEFAULT);
426 * The first vty already has struct tty and scr_stat initialized
427 * in scinit(). The other vtys will have these structs when
430 for (vc = 1; vc < sc->vtys; vc++) {
431 dev = make_dev(&sc_ops, vc + unit * MAXCONS,
433 0600, "ttyv%r", vc + unit * MAXCONS);
436 cctl_dev = make_dev(&sc_ops, SC_CONSOLECTL,
437 UID_ROOT, GID_WHEEL, 0600, "consolectl");
438 cctl_dev->si_tty = sc_console_tty = ttymalloc(sc_console_tty);
439 cctl_dev->si_drv1 = sc_console;
451 * As soon as malloc() becomes functional, we had better allocate
452 * various buffers for the kernel console.
455 if (sc_console_unit < 0) /* sc_console == NULL */
458 /* copy the temporary buffer to the final buffer */
459 sc_alloc_scr_buffer(sc_console, TRUE, FALSE);
461 #ifndef SC_NO_CUTPASTE
462 sc_alloc_cut_buffer(sc_console, TRUE);
465 #ifndef SC_NO_HISTORY
466 /* initialize history buffer & pointers */
467 sc_alloc_history_buffer(sc_console, 0, 0, TRUE);
471 SYSINIT(sc_mem, SI_BOOT1_POST, SI_ORDER_ANY, scmeminit, NULL);
474 scdevtounit(cdev_t dev)
476 int vty = SC_VTY(dev);
478 if (vty == SC_CONSOLECTL)
479 return ((sc_console != NULL) ? sc_console->sc->unit : -1);
480 else if ((vty < 0) || (vty >= MAXCONS*sc_max_unit()))
487 scopen(struct dev_open_args *ap)
489 cdev_t dev = ap->a_head.a_dev;
490 int unit = scdevtounit(dev);
497 DPRINTF(5, ("scopen: dev:%d,%d, unit:%d, vty:%d\n",
498 major(dev), minor(dev), unit, SC_VTY(dev)));
500 sc = sc_get_softc(unit, (sc_console_unit == unit) ? SC_KERNEL_CONSOLE : 0);
504 tp = dev->si_tty = ttymalloc(dev->si_tty);
505 tp->t_oproc = scstart;
506 tp->t_param = scparam;
507 tp->t_stop = nottystop;
511 if (!ISTTYOPEN(tp)) {
513 /* Use the current setting of the <-- key as default VERASE. */
514 /* If the Delete key is preferable, an stty is necessary */
515 if (sc->kbd != NULL) {
516 key.keynum = KEYCODE_BS;
517 kbd_ioctl(sc->kbd, GIO_KEYMAPENT, (caddr_t)&key);
518 tp->t_cc[VERASE] = key.key.map[0];
520 tp->t_iflag = TTYDEF_IFLAG;
521 tp->t_oflag = TTYDEF_OFLAG;
522 tp->t_cflag = TTYDEF_CFLAG;
523 tp->t_lflag = TTYDEF_LFLAG;
524 tp->t_ispeed = tp->t_ospeed = TTYDEF_SPEED;
525 scparam(tp, &tp->t_termios);
526 (*linesw[tp->t_line].l_modem)(tp, 1);
529 if (tp->t_state & TS_XCLUDE && priv_check_cred(ap->a_cred, PRIV_ROOT, 0))
532 error = (*linesw[tp->t_line].l_open)(dev, tp);
536 scp = dev->si_drv1 = alloc_scp(sc, SC_VTY(dev));
538 sc_set_pixel_mode(scp, NULL, COL, ROW, 16);
540 if (!tp->t_winsize.ws_col && !tp->t_winsize.ws_row) {
541 tp->t_winsize.ws_col = scp->xsize;
542 tp->t_winsize.ws_row = scp->ysize;
549 scclose(struct dev_close_args *ap)
551 cdev_t dev = ap->a_head.a_dev;
552 struct tty *tp = dev->si_tty;
556 if (SC_VTY(dev) != SC_CONSOLECTL) {
557 scp = SC_STAT(tp->t_dev);
558 /* were we in the middle of the VT switching process? */
559 DPRINTF(5, ("sc%d: scclose(), ", scp->sc->unit));
560 if ((scp == scp->sc->cur_scp) && (scp->sc->unit == sc_console_unit))
561 cons_unavail = FALSE;
563 * note: must be called from a critical section because finish_vt_rel
564 * will call do_switch_scr which releases it temporarily
566 if (finish_vt_rel(scp, TRUE) == 0) /* force release */
567 DPRINTF(5, ("reset WAIT_REL, "));
568 if (finish_vt_acq(scp) == 0) /* force acknowledge */
569 DPRINTF(5, ("reset WAIT_ACQ, "));
571 if (scp == &main_console) {
574 scp->smode.mode = VT_AUTO;
577 sc_vtb_destroy(&scp->vtb);
578 sc_vtb_destroy(&scp->scr);
579 sc_free_history_buffer(scp, scp->ysize);
581 kfree(scp, M_SYSCONS);
586 scp->smode.mode = VT_AUTO;
588 scp->kbd_mode = K_XLATE;
589 if (scp == scp->sc->cur_scp)
590 kbd_ioctl(scp->sc->kbd, KDSKBMODE, (caddr_t)&scp->kbd_mode);
591 DPRINTF(5, ("done.\n"));
593 (*linesw[tp->t_line].l_close)(tp, ap->a_fflag);
601 scread(struct dev_read_args *ap)
603 sc_touch_scrn_saver();
604 return (ttyread(ap));
608 sckbdevent(keyboard_t *thiskbd, int event, void *arg)
617 * WARNING: In early boot sc->dev may not be setup yet.
619 sc = (sc_softc_t *)arg;
620 /* assert(thiskbd == sc->kbd) */
625 case KBDIO_UNLOADING:
628 kbd_release(thiskbd, (void *)&sc->keyboard);
635 * Loop while there is still input to get from the keyboard.
636 * I don't think this is nessesary, and it doesn't fix
637 * the Xaccel-2.1 keyboard hang, but it can't hurt. XXX
639 while ((c = scgetc(sc, SCGETC_NONBLOCK)) != NOKEY) {
640 cur_tty = VIRTUAL_TTY(sc, sc->cur_scp->index);
641 if (!ISTTYOPEN(cur_tty)) {
642 cur_tty = sc_console_tty;
643 if (!ISTTYOPEN(cur_tty))
647 if ((*sc->cur_scp->tsw->te_input)(sc->cur_scp, c, cur_tty))
650 switch (KEYFLAGS(c)) {
651 case 0x0000: /* normal key */
652 (*linesw[cur_tty->t_line].l_rint)(KEYCHAR(c), cur_tty);
654 case FKEY: /* function key, return string */
655 cp = kbd_get_fkeystr(thiskbd, KEYCHAR(c), &len);
658 (*linesw[cur_tty->t_line].l_rint)(*cp++, cur_tty);
661 case MKEY: /* meta is active, prepend ESC */
662 (*linesw[cur_tty->t_line].l_rint)(0x1b, cur_tty);
663 (*linesw[cur_tty->t_line].l_rint)(KEYCHAR(c), cur_tty);
665 case BKEY: /* backtab fixed sequence (esc [ Z) */
666 (*linesw[cur_tty->t_line].l_rint)(0x1b, cur_tty);
667 (*linesw[cur_tty->t_line].l_rint)('[', cur_tty);
668 (*linesw[cur_tty->t_line].l_rint)('Z', cur_tty);
673 sc->cur_scp->status |= MOUSE_HIDDEN;
679 scparam(struct tty *tp, struct termios *t)
681 tp->t_ispeed = t->c_ispeed;
682 tp->t_ospeed = t->c_ospeed;
683 tp->t_cflag = t->c_cflag;
688 scioctl(struct dev_ioctl_args *ap)
690 cdev_t dev = ap->a_head.a_dev;
691 u_long cmd = ap->a_cmd;
692 caddr_t data = ap->a_data;
693 int flag = ap->a_fflag;
702 error = sc_vid_ioctl(tp, cmd, data, flag);
703 if (error != ENOIOCTL)
706 #ifndef SC_NO_HISTORY
707 error = sc_hist_ioctl(tp, cmd, data, flag);
708 if (error != ENOIOCTL)
712 #ifndef SC_NO_SYSMOUSE
713 error = sc_mouse_ioctl(tp, cmd, data, flag);
714 if (error != ENOIOCTL)
718 scp = SC_STAT(tp->t_dev);
719 /* assert(scp != NULL) */
720 /* scp is sc_console, if SC_VTY(dev) == SC_CONSOLECTL. */
724 error = (*scp->tsw->te_ioctl)(scp, tp, cmd, data, flag);
725 if (error != ENOIOCTL)
729 switch (cmd) { /* process console hardware related ioctl's */
731 case GIO_ATTR: /* get current attributes */
732 /* this ioctl is not processed here, but in the terminal emulator */
735 case GIO_COLOR: /* is this a color console ? */
736 *(int *)data = (sc->adp->va_flags & V_ADP_COLOR) ? 1 : 0;
739 case CONS_BLANKTIME: /* set screen saver timeout (0 = no saver) */
740 if (*(int *)data < 0 || *(int *)data > MAX_BLANKTIME)
743 scrn_blank_time = *(int *)data;
744 run_scrn_saver = (scrn_blank_time != 0);
748 case CONS_CURSORTYPE: /* set cursor type blink/noblink */
750 if (!ISGRAPHSC(sc->cur_scp))
751 sc_remove_cursor_image(sc->cur_scp);
752 if ((*(int*)data) & 0x01)
753 sc->flags |= SC_BLINK_CURSOR;
755 sc->flags &= ~SC_BLINK_CURSOR;
756 if ((*(int*)data) & 0x02) {
757 sc->flags |= SC_CHAR_CURSOR;
759 sc->flags &= ~SC_CHAR_CURSOR;
761 * The cursor shape is global property; all virtual consoles
762 * are affected. Update the cursor in the current console...
764 if (!ISGRAPHSC(sc->cur_scp)) {
765 sc_set_cursor_image(sc->cur_scp);
766 sc_draw_cursor_image(sc->cur_scp);
771 case CONS_BELLTYPE: /* set bell type sound/visual */
772 if ((*(int *)data) & 0x01)
773 sc->flags |= SC_VISUAL_BELL;
775 sc->flags &= ~SC_VISUAL_BELL;
776 if ((*(int *)data) & 0x02)
777 sc->flags |= SC_QUIET_BELL;
779 sc->flags &= ~SC_QUIET_BELL;
782 case CONS_GETINFO: /* get current (virtual) console info */
784 vid_info_t *ptr = (vid_info_t*)data;
785 if (ptr->size == sizeof(struct vid_info)) {
786 ptr->m_num = sc->cur_scp->index;
787 ptr->font_size = scp->font_size;
788 ptr->mv_col = scp->xpos;
789 ptr->mv_row = scp->ypos;
790 ptr->mv_csz = scp->xsize;
791 ptr->mv_rsz = scp->ysize;
793 * The following fields are filled by the terminal emulator. XXX
800 ptr->mv_grfc.fore = 0; /* not supported */
801 ptr->mv_grfc.back = 0; /* not supported */
802 ptr->mv_ovscan = scp->border;
803 if (scp == sc->cur_scp)
805 ptr->mk_keylock = scp->status & LOCK_MASK;
811 case CONS_GETVERS: /* get version number */
812 *(int*)data = 0x200; /* version 2.0 */
815 case CONS_IDLE: /* see if the screen has been idle */
817 * When the screen is in the GRAPHICS_MODE or UNKNOWN_MODE,
818 * the user process may have been writing something on the
819 * screen and syscons is not aware of it. Declare the screen
820 * is NOT idle if it is in one of these modes. But there is
821 * an exception to it; if a screen saver is running in the
822 * graphics mode in the current screen, we should say that the
823 * screen has been idle.
825 *(int *)data = (sc->flags & SC_SCRN_IDLE)
826 && (!ISGRAPHSC(sc->cur_scp)
827 || (sc->cur_scp->status & SAVER_RUNNING));
830 case CONS_SAVERMODE: /* set saver mode */
831 switch(*(int *)data) {
834 /* if a LKM screen saver is running, stop it first. */
835 scsplash_stick(FALSE);
836 saver_mode = *(int *)data;
839 if ((error = wait_scrn_saver_stop(NULL))) {
844 run_scrn_saver = TRUE;
845 if (saver_mode == CONS_USR_SAVER)
846 scp->status |= SAVER_RUNNING;
848 scp->status &= ~SAVER_RUNNING;
849 scsplash_stick(TRUE);
854 if ((saver_mode == CONS_USR_SAVER) && (scp->status & SAVER_RUNNING))
855 scp->status &= ~SAVER_RUNNING;
856 saver_mode = *(int *)data;
864 case CONS_SAVERSTART: /* immediately start/stop the screen saver */
866 * Note that this ioctl does not guarantee the screen saver
867 * actually starts or stops. It merely attempts to do so...
870 run_scrn_saver = (*(int *)data != 0);
872 sc->scrn_time_stamp -= scrn_blank_time;
876 case CONS_SCRSHOT: /* get a screen shot */
878 scrshot_t *ptr = (scrshot_t*)data;
880 if (ISGRAPHSC(scp)) {
884 if (scp->xsize != ptr->xsize || scp->ysize != ptr->ysize) {
888 copyout ((void*)scp->vtb.vtb_buffer, ptr->buf,
889 ptr->xsize * ptr->ysize * sizeof(uint16_t));
894 case VT_SETMODE: /* set screen switcher mode */
896 struct vt_mode *mode;
898 mode = (struct vt_mode *)data;
899 DPRINTF(5, ("sc%d: VT_SETMODE ", sc->unit));
900 if (scp->smode.mode == VT_PROCESS) {
901 if (scp->proc == pfind(scp->pid) && scp->proc != curproc) {
902 DPRINTF(5, ("error EPERM\n"));
907 if (mode->mode == VT_AUTO) {
908 scp->smode.mode = VT_AUTO;
911 DPRINTF(5, ("VT_AUTO, "));
912 if ((scp == sc->cur_scp) && (sc->unit == sc_console_unit))
913 cons_unavail = FALSE;
915 * note: must be called from a critical section because
916 * finish_vt_rel will call do_switch_scr which releases it
919 if (finish_vt_rel(scp, TRUE) == 0)
920 DPRINTF(5, ("reset WAIT_REL, "));
921 if (finish_vt_acq(scp) == 0)
922 DPRINTF(5, ("reset WAIT_ACQ, "));
924 if (!ISSIGVALID(mode->relsig) || !ISSIGVALID(mode->acqsig)
925 || !ISSIGVALID(mode->frsig)) {
927 DPRINTF(5, ("error EINVAL\n"));
930 DPRINTF(5, ("VT_PROCESS %d, ", curproc->p_pid));
931 bcopy(data, &scp->smode, sizeof(struct vt_mode));
933 scp->pid = scp->proc->p_pid;
934 if ((scp == sc->cur_scp) && (sc->unit == sc_console_unit))
942 case VT_GETMODE: /* get screen switcher mode */
943 bcopy(&scp->smode, data, sizeof(struct vt_mode));
946 case VT_RELDISP: /* screen switcher ioctl */
949 * This must be the current vty which is in the VT_PROCESS
952 if ((scp != sc->cur_scp) || (scp->smode.mode != VT_PROCESS)) {
956 /* ...and this process is controlling it. */
957 if (scp->proc != curproc) {
962 switch(*(int *)data) {
963 case VT_FALSE: /* user refuses to release screen, abort */
965 * note: must be called from a critical section because
966 * finish_vt_rel will call do_switch_scr which releases it
969 if ((error = finish_vt_rel(scp, FALSE)) == 0)
970 DPRINTF(5, ("sc%d: VT_FALSE\n", sc->unit));
972 case VT_TRUE: /* user has released screen, go on */
974 * note: must be called from a critical section because
975 * finish_vt_rel will call do_switch_scr which releases it
978 if ((error = finish_vt_rel(scp, TRUE)) == 0)
979 DPRINTF(5, ("sc%d: VT_TRUE\n", sc->unit));
981 case VT_ACKACQ: /* acquire acknowledged, switch completed */
982 if ((error = finish_vt_acq(scp)) == 0)
983 DPRINTF(5, ("sc%d: VT_ACKACQ\n", sc->unit));
991 case VT_OPENQRY: /* return free virtual console */
992 for (i = sc->first_vty; i < sc->first_vty + sc->vtys; i++) {
993 tp = VIRTUAL_TTY(sc, i);
994 if (!ISTTYOPEN(tp)) {
995 *(int *)data = i + 1;
1001 case VT_ACTIVATE: /* switch to screen *data */
1002 i = (*(int *)data == 0) ? scp->index : (*(int *)data - 1);
1004 sc_clean_up(sc->cur_scp);
1006 return sc_switch_scr(sc, i);
1008 case VT_WAITACTIVE: /* wait for switch to occur */
1009 i = (*(int *)data == 0) ? scp->index : (*(int *)data - 1);
1010 if ((i < sc->first_vty) || (i >= sc->first_vty + sc->vtys))
1013 error = sc_clean_up(sc->cur_scp);
1017 scp = SC_STAT(SC_DEV(sc, i));
1018 if (scp == scp->sc->cur_scp)
1020 error = tsleep((caddr_t)&scp->smode, PCATCH, "waitvt", 0);
1021 /* May return ERESTART */
1024 case VT_GETACTIVE: /* get active vty # */
1025 *(int *)data = sc->cur_scp->index + 1;
1028 case VT_GETINDEX: /* get this vty # */
1029 *(int *)data = scp->index + 1;
1032 case VT_LOCKSWITCH: /* prevent vty switching */
1033 if ((*(int *)data) & 0x01)
1034 sc->flags |= SC_SCRN_VTYLOCK;
1036 sc->flags &= ~SC_SCRN_VTYLOCK;
1039 case KDENABIO: /* allow io operations */
1040 error = priv_check_cred(ap->a_cred, PRIV_ROOT, 0);
1043 if (securelevel > 0)
1045 #if defined(__i386__)
1046 curthread->td_lwp->lwp_md.md_regs->tf_eflags |= PSL_IOPL;
1047 #elif defined(__x86_64__)
1048 curthread->td_lwp->lwp_md.md_regs->tf_rflags |= PSL_IOPL;
1052 case KDDISABIO: /* disallow io operations (default) */
1053 #if defined(__i386__)
1054 curthread->td_lwp->lwp_md.md_regs->tf_eflags &= ~PSL_IOPL;
1055 #elif defined(__x86_64__)
1056 curthread->td_lwp->lwp_md.md_regs->tf_rflags &= ~PSL_IOPL;
1060 case KDSKBSTATE: /* set keyboard state (locks) */
1061 if (*(int *)data & ~LOCK_MASK)
1063 scp->status &= ~LOCK_MASK;
1064 scp->status |= *(int *)data;
1065 if (scp == sc->cur_scp)
1066 update_kbd_state(scp, scp->status, LOCK_MASK);
1069 case KDGKBSTATE: /* get keyboard state (locks) */
1070 if (scp == sc->cur_scp)
1071 save_kbd_state(scp);
1072 *(int *)data = scp->status & LOCK_MASK;
1075 case KDGETREPEAT: /* get keyboard repeat & delay rates */
1076 case KDSETREPEAT: /* set keyboard repeat & delay rates (new) */
1077 error = kbd_ioctl(sc->kbd, cmd, data);
1078 if (error == ENOIOCTL)
1082 case KDSETRAD: /* set keyboard repeat & delay rates (old) */
1083 if (*(int *)data & ~0x7f)
1085 error = kbd_ioctl(sc->kbd, cmd, data);
1086 if (error == ENOIOCTL)
1090 case KDSKBMODE: /* set keyboard mode */
1091 switch (*(int *)data) {
1092 case K_XLATE: /* switch to XLT ascii mode */
1093 case K_RAW: /* switch to RAW scancode mode */
1094 case K_CODE: /* switch to CODE mode */
1095 scp->kbd_mode = *(int *)data;
1096 if (scp == sc->cur_scp)
1097 kbd_ioctl(sc->kbd, cmd, data);
1104 case KDGKBMODE: /* get keyboard mode */
1105 *(int *)data = scp->kbd_mode;
1109 error = kbd_ioctl(sc->kbd, cmd, data);
1110 if (error == ENOIOCTL)
1114 case KDMKTONE: /* sound the bell */
1116 sc_bell(scp, (*(int*)data)&0xffff,
1117 (((*(int*)data)>>16)&0xffff)*hz/1000);
1119 sc_bell(scp, scp->bell_pitch, scp->bell_duration);
1122 case KIOCSOUND: /* make tone (*data) hz */
1123 if (scp == sc->cur_scp) {
1125 return sc_tone(*(int *)data);
1131 case KDGKBTYPE: /* get keyboard type */
1132 error = kbd_ioctl(sc->kbd, cmd, data);
1133 if (error == ENOIOCTL) {
1134 /* always return something? XXX */
1139 case KDSETLED: /* set keyboard LED status */
1140 if (*(int *)data & ~LED_MASK) /* FIXME: LOCK_MASK? */
1142 scp->status &= ~LED_MASK;
1143 scp->status |= *(int *)data;
1144 if (scp == sc->cur_scp)
1145 update_kbd_leds(scp, scp->status);
1148 case KDGETLED: /* get keyboard LED status */
1149 if (scp == sc->cur_scp)
1150 save_kbd_state(scp);
1151 *(int *)data = scp->status & LED_MASK;
1154 case KBADDKBD: /* add/remove keyboard to/from mux */
1156 error = kbd_ioctl(sc->kbd, cmd, data);
1157 if (error == ENOIOCTL)
1161 case CONS_SETKBD: /* set the new keyboard */
1166 newkbd = kbd_get_keyboard(*(int *)data);
1167 if (newkbd == NULL) {
1172 if (sc->kbd != newkbd) {
1173 i = kbd_allocate(newkbd->kb_name, newkbd->kb_unit,
1174 (void *)&sc->keyboard, sckbdevent, sc);
1175 /* i == newkbd->kb_index */
1177 if (sc->kbd != NULL) {
1178 save_kbd_state(sc->cur_scp);
1179 kbd_release(sc->kbd, (void *)&sc->keyboard);
1181 sc->kbd = kbd_get_keyboard(i); /* sc->kbd == newkbd */
1183 kbd_ioctl(sc->kbd, KDSKBMODE,
1184 (caddr_t)&sc->cur_scp->kbd_mode);
1185 update_kbd_state(sc->cur_scp, sc->cur_scp->status,
1188 error = EPERM; /* XXX */
1195 case CONS_RELKBD: /* release the current keyboard */
1198 if (sc->kbd != NULL) {
1199 save_kbd_state(sc->cur_scp);
1200 error = kbd_release(sc->kbd, (void *)&sc->keyboard);
1209 case CONS_GETTERM: /* get the current terminal emulator info */
1213 if (((term_info_t *)data)->ti_index == 0) {
1216 sw = sc_term_match_by_number(((term_info_t *)data)->ti_index);
1219 strncpy(((term_info_t *)data)->ti_name, sw->te_name,
1220 sizeof(((term_info_t *)data)->ti_name));
1221 strncpy(((term_info_t *)data)->ti_desc, sw->te_desc,
1222 sizeof(((term_info_t *)data)->ti_desc));
1223 ((term_info_t *)data)->ti_flags = 0;
1226 ((term_info_t *)data)->ti_name[0] = '\0';
1227 ((term_info_t *)data)->ti_desc[0] = '\0';
1228 ((term_info_t *)data)->ti_flags = 0;
1233 case CONS_SETTERM: /* set the current terminal emulator */
1235 error = sc_init_emulator(scp, ((term_info_t *)data)->ti_name);
1236 /* FIXME: what if scp == sc_console! XXX */
1240 case GIO_SCRNMAP: /* get output translation table */
1241 bcopy(&sc->scr_map, data, sizeof(sc->scr_map));
1244 case PIO_SCRNMAP: /* set output translation table */
1245 bcopy(data, &sc->scr_map, sizeof(sc->scr_map));
1246 for (i=0; i<sizeof(sc->scr_map); i++) {
1247 sc->scr_rmap[sc->scr_map[i]] = i;
1251 case GIO_KEYMAP: /* get keyboard translation table */
1252 case PIO_KEYMAP: /* set keyboard translation table */
1253 case GIO_DEADKEYMAP: /* get accent key translation table */
1254 case PIO_DEADKEYMAP: /* set accent key translation table */
1255 case GETFKEY: /* get function key string */
1256 case SETFKEY: /* set function key string */
1257 error = kbd_ioctl(sc->kbd, cmd, data);
1258 if (error == ENOIOCTL)
1262 #ifndef SC_NO_FONT_LOADING
1264 case PIO_FONT8x8: /* set 8x8 dot font */
1265 if (!ISFONTAVAIL(sc->adp->va_flags))
1267 bcopy(data, sc->font_8, 8*256);
1268 sc->fonts_loaded |= FONT_8;
1271 * Always use the font page #0. XXX
1272 * Don't load if the current font size is not 8x8.
1274 if (ISTEXTSC(sc->cur_scp) && (sc->cur_scp->font_size < 14))
1275 sc_load_font(sc->cur_scp, 0, 8, sc->font_8, 0, 256);
1278 case GIO_FONT8x8: /* get 8x8 dot font */
1279 if (!ISFONTAVAIL(sc->adp->va_flags))
1281 if (sc->fonts_loaded & FONT_8) {
1282 bcopy(sc->font_8, data, 8*256);
1288 case PIO_FONT8x14: /* set 8x14 dot font */
1289 if (!ISFONTAVAIL(sc->adp->va_flags))
1291 bcopy(data, sc->font_14, 14*256);
1292 sc->fonts_loaded |= FONT_14;
1295 * Always use the font page #0. XXX
1296 * Don't load if the current font size is not 8x14.
1298 if (ISTEXTSC(sc->cur_scp)
1299 && (sc->cur_scp->font_size >= 14)
1300 && (sc->cur_scp->font_size < 16))
1301 sc_load_font(sc->cur_scp, 0, 14, sc->font_14, 0, 256);
1304 case GIO_FONT8x14: /* get 8x14 dot font */
1305 if (!ISFONTAVAIL(sc->adp->va_flags))
1307 if (sc->fonts_loaded & FONT_14) {
1308 bcopy(sc->font_14, data, 14*256);
1314 case PIO_FONT8x16: /* set 8x16 dot font */
1315 if (!ISFONTAVAIL(sc->adp->va_flags))
1317 bcopy(data, sc->font_16, 16*256);
1318 sc->fonts_loaded |= FONT_16;
1321 * Always use the font page #0. XXX
1322 * Don't load if the current font size is not 8x16.
1324 if (ISTEXTSC(sc->cur_scp) && (sc->cur_scp->font_size >= 16))
1325 sc_load_font(sc->cur_scp, 0, 16, sc->font_16, 0, 256);
1328 case GIO_FONT8x16: /* get 8x16 dot font */
1329 if (!ISFONTAVAIL(sc->adp->va_flags))
1331 if (sc->fonts_loaded & FONT_16) {
1332 bcopy(sc->font_16, data, 16*256);
1338 #endif /* SC_NO_FONT_LOADING */
1344 error = (*linesw[tp->t_line].l_ioctl)(tp, cmd, data, flag, ap->a_cred);
1345 if (error != ENOIOCTL)
1347 error = ttioctl(tp, cmd, data, flag);
1348 if (error != ENOIOCTL)
1354 scstart(struct tty *tp)
1358 u_char buf[PCBURST];
1359 scr_stat *scp = SC_STAT(tp->t_dev);
1362 if (scp->status & SLKED ||
1363 (scp == scp->sc->cur_scp && scp->sc->blink_in_progress))
1368 if (!(tp->t_state & (TS_TIMEOUT | TS_BUSY | TS_TTSTOP))) {
1369 tp->t_state |= TS_BUSY;
1372 len = q_to_b(rbp, buf, PCBURST);
1373 sc_puts(scp, buf, len);
1375 tp->t_state &= ~TS_BUSY;
1382 sccnprobe(struct consdev *cp)
1387 cp->cn_pri = sc_get_cons_priority(&unit, &flags);
1389 /* a video card is always required */
1390 if (!scvidprobe(unit, flags, TRUE))
1391 cp->cn_pri = CN_DEAD;
1393 /* syscons will become console even when there is no keyboard */
1394 sckbdprobe(unit, flags, TRUE);
1396 if (cp->cn_pri == CN_DEAD)
1399 /* initialize required fields */
1400 cp->cn_probegood = 1;
1404 sccninit(struct consdev *cp)
1409 sc_get_cons_priority(&unit, &flags);
1410 scinit(unit, flags | SC_KERNEL_CONSOLE);
1411 sc_console_unit = unit;
1412 sc_console = sc_get_softc(unit, SC_KERNEL_CONSOLE)->console_scp;
1416 sccninit_fini(struct consdev *cp)
1418 if (cctl_dev == NULL)
1419 kprintf("sccninit_fini: WARNING: cctl_dev is NULL!\n");
1420 cp->cn_dev = cctl_dev;
1424 sccnterm(struct consdev *cp)
1426 /* we are not the kernel console any more, release everything */
1428 if (sc_console_unit < 0)
1429 return; /* shouldn't happen */
1432 sc_clear_screen(sc_console);
1433 sccnupdate(sc_console);
1435 scterm(sc_console_unit, SC_KERNEL_CONSOLE);
1436 sc_console_unit = -1;
1441 sccnputc(void *private, int c)
1444 scr_stat *scp = sc_console;
1446 #ifndef SC_NO_HISTORY
1448 #endif /* !SC_NO_HISTORY */
1450 /* assert(sc_console != NULL) */
1453 #ifndef SC_NO_HISTORY
1454 if (scp == scp->sc->cur_scp && scp->status & SLKED) {
1455 scp->status &= ~SLKED;
1456 update_kbd_state(scp, scp->status, SLKED);
1457 if (scp->status & BUFFER_SAVED) {
1458 if (!sc_hist_restore(scp))
1459 sc_remove_cutmarking(scp);
1460 scp->status &= ~BUFFER_SAVED;
1461 scp->status |= CURSOR_ENABLED;
1462 sc_draw_cursor_image(scp);
1464 tp = VIRTUAL_TTY(scp->sc, scp->index);
1465 if (ISTTYOPEN(tp)) {
1471 #endif /* !SC_NO_HISTORY */
1474 if (kernel_console_ts != NULL)
1475 scp->ts = kernel_console_ts;
1477 sc_puts(scp, buf, 1);
1485 sccngetc(void *private)
1487 return sccngetch(0);
1491 sccncheckc(void *private)
1493 return sccngetch(SCGETC_NONBLOCK);
1497 sccndbctl(void *private, int on)
1499 /* assert(sc_console_unit >= 0) */
1500 /* try to switch to the kernel console screen */
1501 if (on && debugger == 0) {
1503 * TRY to make sure the screen saver is stopped,
1504 * and the screen is updated before switching to
1509 && sc_console->sc->cur_scp->smode.mode == VT_AUTO
1510 && sc_console->smode.mode == VT_AUTO) {
1511 sc_console->sc->cur_scp->status |= MOUSE_HIDDEN;
1512 sc_switch_scr(sc_console->sc, sc_console->index);
1522 sccngetch(int flags)
1524 static struct fkeytab fkey;
1532 /* assert(sc_console != NULL) */
1535 * Stop the screen saver and update the screen if necessary.
1536 * What if we have been running in the screen saver code... XXX
1538 sc_touch_scrn_saver();
1539 scp = sc_console->sc->cur_scp; /* XXX */
1543 if (fkeycp < fkey.len)
1544 return fkey.str[fkeycp++];
1546 if (scp->sc->kbd == NULL)
1550 * Make sure the keyboard is accessible even when the kbd device
1551 * driver is disabled.
1554 kbd_enable(scp->sc->kbd);
1556 /* we shall always use the keyboard in the XLATE mode here */
1557 cur_mode = scp->kbd_mode;
1558 scp->kbd_mode = K_XLATE;
1559 kbd_ioctl(scp->sc->kbd, KDSKBMODE, (caddr_t)&scp->kbd_mode);
1561 kbd_poll(scp->sc->kbd, TRUE);
1562 c = scgetc(scp->sc, SCGETC_CN | flags);
1563 kbd_poll(scp->sc->kbd, FALSE);
1565 scp->kbd_mode = cur_mode;
1566 kbd_ioctl(scp->sc->kbd, KDSKBMODE, (caddr_t)&scp->kbd_mode);
1567 kbd_disable(scp->sc->kbd);
1570 switch (KEYFLAGS(c)) {
1571 case 0: /* normal char */
1573 case FKEY: /* function key */
1574 p = kbd_get_fkeystr(scp->sc->kbd, KEYCHAR(c), (size_t *)&fkeycp);
1576 if ((p != NULL) && (fkey.len > 0)) {
1577 bcopy(p, fkey.str, fkey.len);
1591 sccnupdate(scr_stat *scp)
1593 /* this is a cut-down version of scrn_timer()... */
1595 if (scp->sc->font_loading_in_progress || scp->sc->videoio_in_progress)
1598 if (debugger > 0 || panicstr || shutdown_in_progress) {
1599 sc_touch_scrn_saver();
1600 } else if (scp != scp->sc->cur_scp) {
1604 if (!run_scrn_saver)
1605 scp->sc->flags &= ~SC_SCRN_IDLE;
1607 if ((saver_mode != CONS_LKM_SAVER) || !(scp->sc->flags & SC_SCRN_IDLE))
1608 if (scp->sc->flags & SC_SCRN_BLANKED)
1609 stop_scrn_saver(scp->sc, current_saver);
1610 #endif /* NSPLASH */
1612 if (scp != scp->sc->cur_scp || scp->sc->blink_in_progress
1613 || scp->sc->switch_in_progress)
1616 * FIXME: unlike scrn_timer(), we call scrn_update() from here even
1617 * when write_in_progress is non-zero. XXX
1620 if (!ISGRAPHSC(scp) && !(scp->sc->flags & SC_SCRN_BLANKED))
1621 scrn_update(scp, TRUE);
1625 scrn_timer(void *arg)
1627 static int kbd_interval = 0;
1633 again = (arg != NULL);
1635 sc = (sc_softc_t *)arg;
1636 else if (sc_console != NULL)
1637 sc = sc_console->sc;
1641 if (syscons_lock_nonblock() == 0) {
1643 callout_reset(&sc->scrn_timer_ch, hz / 10, scrn_timer, sc);
1648 /* don't do anything when we are performing some I/O operations */
1649 if (sc->font_loading_in_progress || sc->videoio_in_progress) {
1651 callout_reset(&sc->scrn_timer_ch, hz / 10, scrn_timer, sc);
1656 if ((sc->kbd == NULL) && (sc->config & SC_AUTODETECT_KBD)) {
1657 /* try to allocate a keyboard automatically */
1658 if (++kbd_interval >= 25) {
1659 sc->keyboard = sc_allocate_keyboard(sc, -1);
1660 if (sc->keyboard >= 0) {
1661 sc->kbd = kbd_get_keyboard(sc->keyboard);
1662 kbd_ioctl(sc->kbd, KDSKBMODE,
1663 (caddr_t)&sc->cur_scp->kbd_mode);
1664 update_kbd_state(sc->cur_scp, sc->cur_scp->status,
1671 /* should we stop the screen saver? */
1672 getmicrouptime(&tv);
1673 if (debugger > 0 || panicstr || shutdown_in_progress)
1674 sc_touch_scrn_saver();
1675 if (run_scrn_saver) {
1676 if (tv.tv_sec > sc->scrn_time_stamp + scrn_blank_time)
1677 sc->flags |= SC_SCRN_IDLE;
1679 sc->flags &= ~SC_SCRN_IDLE;
1681 sc->scrn_time_stamp = tv.tv_sec;
1682 sc->flags &= ~SC_SCRN_IDLE;
1683 if (scrn_blank_time > 0)
1684 run_scrn_saver = TRUE;
1687 if ((saver_mode != CONS_LKM_SAVER) || !(sc->flags & SC_SCRN_IDLE))
1688 if (sc->flags & SC_SCRN_BLANKED)
1689 stop_scrn_saver(sc, current_saver);
1690 #endif /* NSPLASH */
1692 /* should we just return ? */
1693 if (sc->blink_in_progress || sc->switch_in_progress
1694 || sc->write_in_progress) {
1696 callout_reset(&sc->scrn_timer_ch, hz / 10, scrn_timer, sc);
1701 /* Update the screen */
1702 scp = sc->cur_scp; /* cur_scp may have changed... */
1703 if (!ISGRAPHSC(scp) && !(sc->flags & SC_SCRN_BLANKED))
1704 scrn_update(scp, TRUE);
1707 /* should we activate the screen saver? */
1708 if ((saver_mode == CONS_LKM_SAVER) && (sc->flags & SC_SCRN_IDLE))
1709 if (!ISGRAPHSC(scp) || (sc->flags & SC_SCRN_BLANKED))
1710 (*current_saver)(sc, TRUE);
1711 #endif /* NSPLASH */
1714 callout_reset(&sc->scrn_timer_ch, hz / 25, scrn_timer, sc);
1719 and_region(int *s1, int *e1, int s2, int e2)
1721 if (*e1 < s2 || e2 < *s1)
1723 *s1 = imax(*s1, s2);
1724 *e1 = imin(*e1, e2);
1729 scrn_update(scr_stat *scp, int show_cursor)
1736 /* assert(scp == scp->sc->cur_scp) */
1738 ++scp->sc->videoio_in_progress;
1740 #ifndef SC_NO_CUTPASTE
1741 /* remove the previous mouse pointer image if necessary */
1742 if (scp->status & MOUSE_VISIBLE) {
1744 e = scp->mouse_pos + scp->xsize + 1;
1745 if ((scp->status & (MOUSE_MOVED | MOUSE_HIDDEN))
1746 || and_region(&s, &e, scp->start, scp->end)
1747 || ((scp->status & CURSOR_ENABLED) &&
1748 (scp->cursor_pos != scp->cursor_oldpos) &&
1749 (and_region(&s, &e, scp->cursor_pos, scp->cursor_pos)
1750 || and_region(&s, &e, scp->cursor_oldpos, scp->cursor_oldpos)))) {
1751 sc_remove_mouse_image(scp);
1752 if (scp->end >= scp->xsize*scp->ysize)
1753 scp->end = scp->xsize*scp->ysize - 1;
1756 #endif /* !SC_NO_CUTPASTE */
1760 if (scp->end >= scp->xsize*scp->ysize) {
1761 kprintf("scrn_update(): scp->end %d > size_of_screen!!\n", scp->end);
1762 scp->end = scp->xsize*scp->ysize - 1;
1764 if (scp->start < 0) {
1765 kprintf("scrn_update(): scp->start %d < 0\n", scp->start);
1770 /* update screen image */
1771 if (scp->start <= scp->end) {
1772 if (scp->mouse_cut_end >= 0) {
1773 /* there is a marked region for cut & paste */
1774 if (scp->mouse_cut_start <= scp->mouse_cut_end) {
1775 start = scp->mouse_cut_start;
1776 end = scp->mouse_cut_end;
1778 start = scp->mouse_cut_end;
1779 end = scp->mouse_cut_start - 1;
1783 /* does the cut-mark region overlap with the update region? */
1784 if (and_region(&s, &e, scp->start, scp->end)) {
1785 (*scp->rndr->draw)(scp, s, e - s + 1, TRUE);
1788 if (and_region(&s, &e, scp->start, scp->end))
1789 (*scp->rndr->draw)(scp, s, e - s + 1, FALSE);
1791 e = scp->xsize*scp->ysize - 1;
1792 if (and_region(&s, &e, scp->start, scp->end))
1793 (*scp->rndr->draw)(scp, s, e - s + 1, FALSE);
1795 (*scp->rndr->draw)(scp, scp->start,
1796 scp->end - scp->start + 1, FALSE);
1799 (*scp->rndr->draw)(scp, scp->start,
1800 scp->end - scp->start + 1, FALSE);
1804 /* we are not to show the cursor and the mouse pointer... */
1807 scp->start = scp->xsize*scp->ysize - 1;
1808 --scp->sc->videoio_in_progress;
1812 /* update cursor image */
1813 if (scp->status & CURSOR_ENABLED) {
1816 /* did cursor move since last time ? */
1817 if (scp->cursor_pos != scp->cursor_oldpos) {
1818 /* do we need to remove old cursor image ? */
1819 if (!and_region(&s, &e, scp->cursor_oldpos, scp->cursor_oldpos))
1820 sc_remove_cursor_image(scp);
1821 sc_draw_cursor_image(scp);
1823 if (and_region(&s, &e, scp->cursor_pos, scp->cursor_pos))
1824 /* cursor didn't move, but has been overwritten */
1825 sc_draw_cursor_image(scp);
1826 else if (scp->sc->flags & SC_BLINK_CURSOR)
1827 /* if it's a blinking cursor, update it */
1828 (*scp->rndr->blink_cursor)(scp, scp->cursor_pos,
1829 sc_inside_cutmark(scp,
1834 #ifndef SC_NO_CUTPASTE
1835 /* update "pseudo" mouse pointer image */
1836 if (scp->sc->flags & SC_MOUSE_ENABLED) {
1837 if (!(scp->status & (MOUSE_VISIBLE | MOUSE_HIDDEN))) {
1838 scp->status &= ~MOUSE_MOVED;
1839 sc_draw_mouse_image(scp);
1842 #endif /* SC_NO_CUTPASTE */
1845 scp->start = scp->xsize*scp->ysize - 1;
1847 --scp->sc->videoio_in_progress;
1852 scsplash_callback(int event, void *arg)
1857 sc = (sc_softc_t *)arg;
1861 if (add_scrn_saver(scsplash_saver) == 0) {
1862 sc->flags &= ~SC_SAVER_FAILED;
1863 run_scrn_saver = TRUE;
1864 if (cold && !(boothowto & (RB_VERBOSE | RB_CONFIG))) {
1865 scsplash_stick(TRUE);
1866 (*current_saver)(sc, TRUE);
1872 if (current_saver == scsplash_saver) {
1873 scsplash_stick(FALSE);
1874 error = remove_scrn_saver(scsplash_saver);
1886 scsplash_saver(sc_softc_t *sc, int show)
1888 static int busy = FALSE;
1897 if (!(sc->flags & SC_SAVER_FAILED)) {
1898 if (!(sc->flags & SC_SCRN_BLANKED))
1899 set_scrn_saver_mode(scp, -1, NULL, 0);
1900 switch (splash(sc->adp, TRUE)) {
1901 case 0: /* succeeded */
1903 case EAGAIN: /* try later */
1904 restore_scrn_saver_mode(scp, FALSE);
1905 sc_touch_scrn_saver(); /* XXX */
1908 sc->flags |= SC_SAVER_FAILED;
1909 scsplash_stick(FALSE);
1910 restore_scrn_saver_mode(scp, TRUE);
1911 kprintf("scsplash_saver(): failed to put up the image\n");
1915 } else if (!sticky_splash) {
1916 if ((sc->flags & SC_SCRN_BLANKED) && (splash(sc->adp, FALSE) == 0))
1917 restore_scrn_saver_mode(scp, TRUE);
1923 add_scrn_saver(void (*this_saver)(sc_softc_t *, int))
1928 if (current_saver != none_saver) {
1929 error = remove_scrn_saver(current_saver);
1934 if (current_saver != none_saver)
1937 run_scrn_saver = FALSE;
1938 saver_mode = CONS_LKM_SAVER;
1939 current_saver = this_saver;
1944 remove_scrn_saver(void (*this_saver)(sc_softc_t *, int))
1946 if (current_saver != this_saver)
1951 * In order to prevent `current_saver' from being called by
1952 * the timeout routine `scrn_timer()' while we manipulate
1953 * the saver list, we shall set `current_saver' to `none_saver'
1954 * before stopping the current saver, rather than blocking by `splXX()'.
1956 current_saver = none_saver;
1958 stop_scrn_saver(this_saver);
1961 /* unblank all blanked screens */
1962 wait_scrn_saver_stop(NULL);
1966 current_saver = none_saver;
1971 set_scrn_saver_mode(scr_stat *scp, int mode, u_char *pal, int border)
1974 /* assert(scp == scp->sc->cur_scp) */
1976 if (!ISGRAPHSC(scp))
1977 sc_remove_cursor_image(scp);
1978 scp->splash_save_mode = scp->mode;
1979 scp->splash_save_status = scp->status & (GRAPHICS_MODE | PIXEL_MODE);
1980 scp->status &= ~(GRAPHICS_MODE | PIXEL_MODE);
1981 scp->status |= (UNKNOWN_MODE | SAVER_RUNNING);
1982 scp->sc->flags |= SC_SCRN_BLANKED;
1988 if (set_mode(scp) == 0) {
1989 if (scp->sc->adp->va_info.vi_flags & V_INFO_GRAPHICS)
1990 scp->status |= GRAPHICS_MODE;
1991 #ifndef SC_NO_PALETTE_LOADING
1993 load_palette(scp->sc->adp, pal);
1995 sc_set_border(scp, border);
1999 scp->mode = scp->splash_save_mode;
2000 scp->status &= ~(UNKNOWN_MODE | SAVER_RUNNING);
2001 scp->status |= scp->splash_save_status;
2008 restore_scrn_saver_mode(scr_stat *scp, int changemode)
2013 /* assert(scp == scp->sc->cur_scp) */
2016 status = scp->status;
2017 scp->mode = scp->splash_save_mode;
2018 scp->status &= ~(UNKNOWN_MODE | SAVER_RUNNING);
2019 scp->status |= scp->splash_save_status;
2020 scp->sc->flags &= ~SC_SCRN_BLANKED;
2022 if (!ISGRAPHSC(scp))
2023 sc_draw_cursor_image(scp);
2028 if (set_mode(scp) == 0) {
2029 #ifndef SC_NO_PALETTE_LOADING
2030 load_palette(scp->sc->adp, scp->sc->palette);
2037 scp->status = status;
2044 stop_scrn_saver(sc_softc_t *sc, void (*saver)(sc_softc_t *, int))
2046 (*saver)(sc, FALSE);
2047 run_scrn_saver = FALSE;
2048 /* the screen saver may have chosen not to stop after all... */
2049 if (sc->flags & SC_SCRN_BLANKED)
2052 mark_all(sc->cur_scp);
2053 if (sc->delayed_next_scr)
2054 sc_switch_scr(sc, sc->delayed_next_scr - 1);
2055 wakeup((caddr_t)&scrn_blanked);
2059 wait_scrn_saver_stop(sc_softc_t *sc)
2063 while (scrn_blanked > 0) {
2064 run_scrn_saver = FALSE;
2065 if (sc && !(sc->flags & SC_SCRN_BLANKED)) {
2069 error = tsleep((caddr_t)&scrn_blanked, PCATCH, "scrsav", 0);
2070 /* May return ERESTART */
2074 run_scrn_saver = FALSE;
2077 #endif /* NSPLASH */
2080 sc_touch_scrn_saver(void)
2082 scsplash_stick(FALSE);
2083 run_scrn_saver = FALSE;
2087 sc_switch_scr(sc_softc_t *sc, u_int next_scr)
2092 DPRINTF(5, ("sc0: sc_switch_scr() %d ", next_scr + 1));
2094 /* prevent switch if previously requested */
2095 if (sc->flags & SC_SCRN_VTYLOCK) {
2096 sc_bell(sc->cur_scp, sc->cur_scp->bell_pitch,
2097 sc->cur_scp->bell_duration);
2101 /* delay switch if the screen is blanked or being updated */
2102 if ((sc->flags & SC_SCRN_BLANKED) || sc->write_in_progress
2103 || sc->blink_in_progress || sc->videoio_in_progress) {
2104 sc->delayed_next_scr = next_scr + 1;
2105 sc_touch_scrn_saver();
2106 DPRINTF(5, ("switch delayed\n"));
2111 cur_scp = sc->cur_scp;
2113 /* we are in the middle of the vty switching process... */
2114 if (sc->switch_in_progress
2115 && (cur_scp->smode.mode == VT_PROCESS)
2117 if (cur_scp->proc != pfind(cur_scp->pid)) {
2119 * The controlling process has died!!. Do some clean up.
2120 * NOTE:`cur_scp->proc' and `cur_scp->smode.mode'
2121 * are not reset here yet; they will be cleared later.
2123 DPRINTF(5, ("cur_scp controlling process %d died, ",
2125 if (cur_scp->status & SWITCH_WAIT_REL) {
2127 * Force the previous switch to finish, but return now
2130 * note: must be called from a critical section because
2131 * finish_vt_rel will call do_switch_scr which releases it
2134 DPRINTF(5, ("reset WAIT_REL, "));
2135 finish_vt_rel(cur_scp, TRUE);
2137 DPRINTF(5, ("finishing previous switch\n"));
2139 } else if (cur_scp->status & SWITCH_WAIT_ACQ) {
2140 /* let's assume screen switch has been completed. */
2141 DPRINTF(5, ("reset WAIT_ACQ, "));
2142 finish_vt_acq(cur_scp);
2145 * We are in between screen release and acquisition, and
2146 * reached here via scgetc() or scrn_timer() which has
2147 * interrupted exchange_scr(). Don't do anything stupid.
2149 DPRINTF(5, ("waiting nothing, "));
2153 * The controlling process is alive, but not responding...
2154 * It is either buggy or it may be just taking time.
2155 * The following code is a gross kludge to cope with this
2156 * problem for which there is no clean solution. XXX
2158 if (cur_scp->status & SWITCH_WAIT_REL) {
2159 switch (sc->switch_in_progress++) {
2163 DPRINTF(5, ("sending relsig again, "));
2164 signal_vt_rel(cur_scp);
2171 * Act as if the controlling program returned
2174 * note: must be called from a critical section because
2175 * finish_vt_rel will call do_switch_scr which releases it
2178 DPRINTF(5, ("force reset WAIT_REL, "));
2179 finish_vt_rel(cur_scp, FALSE);
2181 DPRINTF(5, ("act as if VT_FALSE was seen\n"));
2184 } else if (cur_scp->status & SWITCH_WAIT_ACQ) {
2185 switch (sc->switch_in_progress++) {
2189 DPRINTF(5, ("sending acqsig again, "));
2190 signal_vt_acq(cur_scp);
2196 /* clear the flag and finish the previous switch */
2197 DPRINTF(5, ("force reset WAIT_ACQ, "));
2198 finish_vt_acq(cur_scp);
2206 * Return error if an invalid argument is given, or vty switch
2207 * is still in progress.
2209 if ((next_scr < sc->first_vty) || (next_scr >= sc->first_vty + sc->vtys)
2210 || sc->switch_in_progress) {
2212 sc_bell(cur_scp, bios_value.bell_pitch, BELL_DURATION);
2213 DPRINTF(5, ("error 1\n"));
2218 * Don't allow switching away from the graphics mode vty
2219 * if the switch mode is VT_AUTO, unless the next vty is the same
2220 * as the current or the current vty has been closed (but showing).
2222 tp = VIRTUAL_TTY(sc, cur_scp->index);
2223 if ((cur_scp->index != next_scr)
2225 && (cur_scp->smode.mode == VT_AUTO)
2226 && ISGRAPHSC(cur_scp)) {
2228 sc_bell(cur_scp, bios_value.bell_pitch, BELL_DURATION);
2229 DPRINTF(5, ("error, graphics mode\n"));
2234 * Is the wanted vty open? Don't allow switching to a closed vty.
2235 * If we are in DDB, don't switch to a vty in the VT_PROCESS mode.
2236 * Note that we always allow the user to switch to the kernel
2237 * console even if it is closed.
2239 if ((sc_console == NULL) || (next_scr != sc_console->index)) {
2240 tp = VIRTUAL_TTY(sc, next_scr);
2241 if (!ISTTYOPEN(tp)) {
2243 sc_bell(cur_scp, bios_value.bell_pitch, BELL_DURATION);
2244 DPRINTF(5, ("error 2, requested vty isn't open!\n"));
2247 if ((debugger > 0) && (SC_STAT(tp->t_dev)->smode.mode == VT_PROCESS)) {
2249 DPRINTF(5, ("error 3, requested vty is in the VT_PROCESS mode\n"));
2254 /* this is the start of vty switching process... */
2255 ++sc->switch_in_progress;
2256 sc->delayed_next_scr = 0;
2257 sc->old_scp = cur_scp;
2258 sc->new_scp = SC_STAT(SC_DEV(sc, next_scr));
2259 if (sc->new_scp == sc->old_scp) {
2260 sc->switch_in_progress = 0;
2261 wakeup((caddr_t)&sc->new_scp->smode);
2263 DPRINTF(5, ("switch done (new == old)\n"));
2267 /* has controlling process died? */
2268 vt_proc_alive(sc->old_scp);
2269 vt_proc_alive(sc->new_scp);
2271 /* wait for the controlling process to release the screen, if necessary */
2272 if (signal_vt_rel(sc->old_scp)) {
2277 /* go set up the new vty screen */
2282 /* wake up processes waiting for this vty */
2283 wakeup((caddr_t)&sc->cur_scp->smode);
2285 /* wait for the controlling process to acknowledge, if necessary */
2286 if (signal_vt_acq(sc->cur_scp)) {
2291 sc->switch_in_progress = 0;
2292 if (sc->unit == sc_console_unit)
2293 cons_unavail = FALSE;
2295 DPRINTF(5, ("switch done\n"));
2301 * NOTE: must be called from a critical section because do_switch_scr
2302 * will release it temporarily.
2305 do_switch_scr(sc_softc_t *sc)
2307 vt_proc_alive(sc->new_scp);
2312 /* sc->cur_scp == sc->new_scp */
2313 wakeup((caddr_t)&sc->cur_scp->smode);
2315 /* wait for the controlling process to acknowledge, if necessary */
2316 if (!signal_vt_acq(sc->cur_scp)) {
2317 sc->switch_in_progress = 0;
2318 if (sc->unit == sc_console_unit)
2319 cons_unavail = FALSE;
2324 vt_proc_alive(scr_stat *scp)
2327 if (scp->proc == pfind(scp->pid))
2330 scp->smode.mode = VT_AUTO;
2331 DPRINTF(5, ("vt controlling process %d died\n", scp->pid));
2337 signal_vt_rel(scr_stat *scp)
2339 if (scp->smode.mode != VT_PROCESS)
2341 scp->status |= SWITCH_WAIT_REL;
2342 ksignal(scp->proc, scp->smode.relsig);
2343 DPRINTF(5, ("sending relsig to %d\n", scp->pid));
2348 signal_vt_acq(scr_stat *scp)
2350 if (scp->smode.mode != VT_PROCESS)
2352 if (scp->sc->unit == sc_console_unit)
2353 cons_unavail = TRUE;
2354 scp->status |= SWITCH_WAIT_ACQ;
2355 ksignal(scp->proc, scp->smode.acqsig);
2356 DPRINTF(5, ("sending acqsig to %d\n", scp->pid));
2361 * NOTE: must be called from a critical section because do_switch_scr
2362 * will release it temporarily.
2365 finish_vt_rel(scr_stat *scp, int release)
2367 if (scp == scp->sc->old_scp && scp->status & SWITCH_WAIT_REL) {
2368 scp->status &= ~SWITCH_WAIT_REL;
2370 do_switch_scr(scp->sc);
2372 scp->sc->switch_in_progress = 0;
2379 finish_vt_acq(scr_stat *scp)
2381 if (scp == scp->sc->new_scp && scp->status & SWITCH_WAIT_ACQ) {
2382 scp->status &= ~SWITCH_WAIT_ACQ;
2383 scp->sc->switch_in_progress = 0;
2390 exchange_scr(sc_softc_t *sc)
2394 /* save the current state of video and keyboard */
2395 sc_move_cursor(sc->old_scp, sc->old_scp->xpos, sc->old_scp->ypos);
2396 if (!ISGRAPHSC(sc->old_scp))
2397 sc_remove_cursor_image(sc->old_scp);
2398 if (sc->old_scp->kbd_mode == K_XLATE)
2399 save_kbd_state(sc->old_scp);
2401 /* set up the video for the new screen */
2402 scp = sc->cur_scp = sc->new_scp;
2403 if (sc->old_scp->mode != scp->mode || ISUNKNOWNSC(sc->old_scp))
2406 sc_vtb_init(&scp->scr, VTB_FRAMEBUFFER, scp->xsize, scp->ysize,
2407 (void *)sc->adp->va_window, FALSE);
2408 scp->status |= MOUSE_HIDDEN;
2409 sc_move_cursor(scp, scp->xpos, scp->ypos);
2410 if (!ISGRAPHSC(scp))
2411 sc_set_cursor_image(scp);
2412 #ifndef SC_NO_PALETTE_LOADING
2413 if (ISGRAPHSC(sc->old_scp))
2414 load_palette(sc->adp, sc->palette);
2416 sc_set_border(scp, scp->border);
2418 /* set up the keyboard for the new screen */
2419 if (sc->old_scp->kbd_mode != scp->kbd_mode)
2420 kbd_ioctl(sc->kbd, KDSKBMODE, (caddr_t)&scp->kbd_mode);
2421 update_kbd_state(scp, scp->status, LOCK_MASK);
2427 sc_puts(scr_stat *scp, u_char *buf, int len)
2430 /* make screensaver happy */
2431 if (!sticky_splash && scp == scp->sc->cur_scp)
2432 run_scrn_saver = FALSE;
2436 (*scp->tsw->te_puts)(scp, buf, len);
2438 if (scp->sc->delayed_next_scr)
2439 sc_switch_scr(scp->sc, scp->sc->delayed_next_scr - 1);
2443 sc_draw_cursor_image(scr_stat *scp)
2445 /* assert(scp == scp->sc->cur_scp); */
2446 ++scp->sc->videoio_in_progress;
2447 (*scp->rndr->draw_cursor)(scp, scp->cursor_pos,
2448 scp->sc->flags & SC_BLINK_CURSOR, TRUE,
2449 sc_inside_cutmark(scp, scp->cursor_pos));
2450 scp->cursor_oldpos = scp->cursor_pos;
2451 --scp->sc->videoio_in_progress;
2455 sc_remove_cursor_image(scr_stat *scp)
2457 /* assert(scp == scp->sc->cur_scp); */
2458 ++scp->sc->videoio_in_progress;
2459 (*scp->rndr->draw_cursor)(scp, scp->cursor_oldpos,
2460 scp->sc->flags & SC_BLINK_CURSOR, FALSE,
2461 sc_inside_cutmark(scp, scp->cursor_oldpos));
2462 --scp->sc->videoio_in_progress;
2466 update_cursor_image(scr_stat *scp)
2470 if (scp->sc->flags & SC_CHAR_CURSOR) {
2471 scp->cursor_base = imax(0, scp->sc->cursor_base);
2472 scp->cursor_height = imin(scp->sc->cursor_height, scp->font_size);
2474 scp->cursor_base = 0;
2475 scp->cursor_height = scp->font_size;
2477 blink = scp->sc->flags & SC_BLINK_CURSOR;
2479 /* assert(scp == scp->sc->cur_scp); */
2480 ++scp->sc->videoio_in_progress;
2481 (*scp->rndr->draw_cursor)(scp, scp->cursor_oldpos, blink, FALSE,
2482 sc_inside_cutmark(scp, scp->cursor_pos));
2483 (*scp->rndr->set_cursor)(scp, scp->cursor_base, scp->cursor_height, blink);
2484 (*scp->rndr->draw_cursor)(scp, scp->cursor_pos, blink, TRUE,
2485 sc_inside_cutmark(scp, scp->cursor_pos));
2486 --scp->sc->videoio_in_progress;
2490 sc_set_cursor_image(scr_stat *scp)
2492 if (scp->sc->flags & SC_CHAR_CURSOR) {
2493 scp->cursor_base = imax(0, scp->sc->cursor_base);
2494 scp->cursor_height = imin(scp->sc->cursor_height, scp->font_size);
2496 scp->cursor_base = 0;
2497 scp->cursor_height = scp->font_size;
2500 /* assert(scp == scp->sc->cur_scp); */
2501 ++scp->sc->videoio_in_progress;
2502 (*scp->rndr->set_cursor)(scp, scp->cursor_base, scp->cursor_height,
2503 scp->sc->flags & SC_BLINK_CURSOR);
2504 --scp->sc->videoio_in_progress;
2508 scinit(int unit, int flags)
2511 * When syscons is being initialized as the kernel console, malloc()
2512 * is not yet functional, because various kernel structures has not been
2513 * fully initialized yet. Therefore, we need to declare the following
2514 * static buffers for the console. This is less than ideal,
2515 * but is necessry evil for the time being. XXX
2517 static scr_stat main_console;
2518 static u_short sc_buffer[ROW*COL]; /* XXX */
2519 #ifndef SC_NO_FONT_LOADING
2520 static u_char font_8[256*8];
2521 static u_char font_14[256*14];
2522 static u_char font_16[256*16];
2527 video_adapter_t *adp;
2532 /* one time initialization */
2533 if (init_done == COLD)
2534 sc_get_bios_values(&bios_value);
2538 * Allocate resources. Even if we are being called for the second
2539 * time, we must allocate them again, because they might have
2542 sc = sc_get_softc(unit, flags & SC_KERNEL_CONSOLE);
2544 if (sc->adapter >= 0) {
2545 vid_release(sc->adp, (void *)&sc->adapter);
2549 if (sc->keyboard >= 0) {
2550 DPRINTF(5, ("sc%d: releasing kbd%d\n", unit, sc->keyboard));
2551 i = kbd_release(sc->kbd, (void *)&sc->keyboard);
2552 DPRINTF(5, ("sc%d: kbd_release returned %d\n", unit, i));
2553 if (sc->kbd != NULL) {
2554 DPRINTF(5, ("sc%d: kbd != NULL!, index:%d, unit:%d, flags:0x%x\n",
2555 unit, sc->kbd->kb_index, sc->kbd->kb_unit, sc->kbd->kb_flags));
2559 sc->adapter = vid_allocate("*", unit, (void *)&sc->adapter);
2560 sc->adp = vid_get_adapter(sc->adapter);
2561 /* assert((sc->adapter >= 0) && (sc->adp != NULL)) */
2562 sc->keyboard = sc_allocate_keyboard(sc, unit);
2563 DPRINTF(1, ("sc%d: keyboard %d\n", unit, sc->keyboard));
2564 sc->kbd = kbd_get_keyboard(sc->keyboard);
2565 if (sc->kbd != NULL) {
2566 DPRINTF(1, ("sc%d: kbd index:%d, unit:%d, flags:0x%x\n",
2567 unit, sc->kbd->kb_index, sc->kbd->kb_unit, sc->kbd->kb_flags));
2570 if (!(sc->flags & SC_INIT_DONE) || (adp != sc->adp)) {
2572 sc->initial_mode = sc->adp->va_initial_mode;
2574 #ifndef SC_NO_FONT_LOADING
2575 if (flags & SC_KERNEL_CONSOLE) {
2576 sc->font_8 = font_8;
2577 sc->font_14 = font_14;
2578 sc->font_16 = font_16;
2579 } else if (sc->font_8 == NULL) {
2580 /* assert(sc_malloc) */
2581 sc->font_8 = kmalloc(sizeof(font_8), M_SYSCONS, M_WAITOK);
2582 sc->font_14 = kmalloc(sizeof(font_14), M_SYSCONS, M_WAITOK);
2583 sc->font_16 = kmalloc(sizeof(font_16), M_SYSCONS, M_WAITOK);
2587 /* extract the hardware cursor location and hide the cursor for now */
2588 (*vidsw[sc->adapter]->read_hw_cursor)(sc->adp, &col, &row);
2589 (*vidsw[sc->adapter]->set_hw_cursor)(sc->adp, -1, -1);
2591 /* set up the first console */
2592 sc->first_vty = unit*MAXCONS;
2593 sc->vtys = MAXCONS; /* XXX: should be configurable */
2594 if (flags & SC_KERNEL_CONSOLE) {
2595 scp = &main_console;
2596 sc->console_scp = scp;
2597 init_scp(sc, sc->first_vty, scp);
2598 sc_vtb_init(&scp->vtb, VTB_MEMORY, scp->xsize, scp->ysize,
2599 (void *)sc_buffer, FALSE);
2600 if (sc_init_emulator(scp, SC_DFLT_TERM))
2601 sc_init_emulator(scp, "*");
2602 (*scp->tsw->te_default_attr)(scp,
2603 kernel_default.std_color,
2604 kernel_default.rev_color);
2606 /* assert(sc_malloc) */
2607 sc->dev = kmalloc(sizeof(cdev_t)*sc->vtys, M_SYSCONS, M_WAITOK | M_ZERO);
2609 sc->dev[0] = make_dev(&sc_ops, unit*MAXCONS, UID_ROOT,
2610 GID_WHEEL, 0600, "ttyv%r", unit*MAXCONS);
2612 sc->dev[0]->si_tty = ttymalloc(sc->dev[0]->si_tty);
2613 scp = alloc_scp(sc, sc->first_vty);
2614 sc->dev[0]->si_drv1 = scp;
2618 /* copy screen to temporary buffer */
2619 sc_vtb_init(&scp->scr, VTB_FRAMEBUFFER, scp->xsize, scp->ysize,
2620 (void *)scp->sc->adp->va_window, FALSE);
2622 sc_vtb_copy(&scp->scr, 0, &scp->vtb, 0, scp->xsize*scp->ysize);
2624 /* move cursors to the initial positions */
2625 if (col >= scp->xsize)
2627 if (row >= scp->ysize)
2628 row = scp->ysize - 1;
2631 scp->cursor_pos = scp->cursor_oldpos = row*scp->xsize + col;
2632 if (bios_value.cursor_end < scp->font_size)
2633 sc->cursor_base = scp->font_size - bios_value.cursor_end - 1;
2635 sc->cursor_base = 0;
2636 i = bios_value.cursor_end - bios_value.cursor_start + 1;
2637 sc->cursor_height = imin(i, scp->font_size);
2638 #ifndef SC_NO_SYSMOUSE
2639 sc_mouse_move(scp, scp->xpixel/2, scp->ypixel/2);
2641 if (!ISGRAPHSC(scp)) {
2642 sc_set_cursor_image(scp);
2643 sc_draw_cursor_image(scp);
2646 /* save font and palette */
2647 #ifndef SC_NO_FONT_LOADING
2648 sc->fonts_loaded = 0;
2649 if (ISFONTAVAIL(sc->adp->va_flags)) {
2651 bcopy(dflt_font_8, sc->font_8, sizeof(dflt_font_8));
2652 bcopy(dflt_font_14, sc->font_14, sizeof(dflt_font_14));
2653 bcopy(dflt_font_16, sc->font_16, sizeof(dflt_font_16));
2654 sc->fonts_loaded = FONT_16 | FONT_14 | FONT_8;
2655 if (scp->font_size < 14) {
2656 sc_load_font(scp, 0, 8, sc->font_8, 0, 256);
2657 } else if (scp->font_size >= 16) {
2658 sc_load_font(scp, 0, 16, sc->font_16, 0, 256);
2660 sc_load_font(scp, 0, 14, sc->font_14, 0, 256);
2662 #else /* !SC_DFLT_FONT */
2663 if (scp->font_size < 14) {
2664 sc_save_font(scp, 0, 8, sc->font_8, 0, 256);
2665 sc->fonts_loaded = FONT_8;
2666 } else if (scp->font_size >= 16) {
2667 sc_save_font(scp, 0, 16, sc->font_16, 0, 256);
2668 sc->fonts_loaded = FONT_16;
2670 sc_save_font(scp, 0, 14, sc->font_14, 0, 256);
2671 sc->fonts_loaded = FONT_14;
2673 #endif /* SC_DFLT_FONT */
2674 /* FONT KLUDGE: always use the font page #0. XXX */
2675 sc_show_font(scp, 0);
2677 #endif /* !SC_NO_FONT_LOADING */
2679 #ifndef SC_NO_PALETTE_LOADING
2680 save_palette(sc->adp, sc->palette);
2684 if (!(sc->flags & SC_SPLASH_SCRN) && (flags & SC_KERNEL_CONSOLE)) {
2685 /* we are ready to put up the splash image! */
2686 splash_init(sc->adp, scsplash_callback, sc);
2687 sc->flags |= SC_SPLASH_SCRN;
2689 #endif /* NSPLASH */
2692 /* the rest is not necessary, if we have done it once */
2693 if (sc->flags & SC_INIT_DONE)
2696 /* initialize mapscrn arrays to a one to one map */
2697 for (i = 0; i < sizeof(sc->scr_map); i++)
2698 sc->scr_map[i] = sc->scr_rmap[i] = i;
2700 sc->flags |= SC_INIT_DONE;
2704 scterm(int unit, int flags)
2709 sc = sc_get_softc(unit, flags & SC_KERNEL_CONSOLE);
2711 return; /* shouldn't happen */
2714 /* this console is no longer available for the splash screen */
2715 if (sc->flags & SC_SPLASH_SCRN) {
2716 splash_term(sc->adp);
2717 sc->flags &= ~SC_SPLASH_SCRN;
2719 #endif /* NSPLASH */
2722 /* move the hardware cursor to the upper-left corner */
2723 (*vidsw[sc->adapter]->set_hw_cursor)(sc->adp, 0, 0);
2726 /* release the keyboard and the video card */
2727 if (sc->keyboard >= 0)
2728 kbd_release(sc->kbd, &sc->keyboard);
2729 if (sc->adapter >= 0)
2730 vid_release(sc->adp, &sc->adapter);
2733 * Stop the terminal emulator, if any. If operating on the
2734 * kernel console sc->dev may not be setup yet.
2736 if (flags & SC_KERNEL_CONSOLE)
2737 scp = sc->console_scp;
2739 scp = SC_STAT(sc->dev[0]);
2741 (*scp->tsw->te_term)(scp, &scp->ts);
2742 if (scp->ts != NULL)
2743 kfree(scp->ts, M_SYSCONS);
2745 /* clear the structure */
2746 if (!(flags & SC_KERNEL_CONSOLE)) {
2747 /* XXX: We need delete_dev() for this */
2748 kfree(sc->dev, M_SYSCONS);
2750 /* XXX: We need a ttyunregister for this */
2751 kfree(sc->tty, M_SYSCONS);
2753 #ifndef SC_NO_FONT_LOADING
2754 kfree(sc->font_8, M_SYSCONS);
2755 kfree(sc->font_14, M_SYSCONS);
2756 kfree(sc->font_16, M_SYSCONS);
2758 /* XXX vtb, history */
2760 bzero(sc, sizeof(*sc));
2766 scshutdown(void *arg, int howto)
2768 /* assert(sc_console != NULL) */
2770 sc_touch_scrn_saver();
2771 if (!cold && sc_console
2772 && sc_console->sc->cur_scp->smode.mode == VT_AUTO
2773 && sc_console->smode.mode == VT_AUTO)
2774 sc_switch_scr(sc_console->sc, sc_console->index);
2775 shutdown_in_progress = TRUE;
2779 sc_clean_up(scr_stat *scp)
2783 #endif /* NSPLASH */
2785 if (scp->sc->flags & SC_SCRN_BLANKED) {
2786 sc_touch_scrn_saver();
2788 if ((error = wait_scrn_saver_stop(scp->sc)))
2790 #endif /* NSPLASH */
2792 scp->status |= MOUSE_HIDDEN;
2793 sc_remove_mouse_image(scp);
2794 sc_remove_cutmarking(scp);
2799 sc_alloc_scr_buffer(scr_stat *scp, int wait, int discard)
2805 sc_vtb_init(&new, VTB_MEMORY, scp->xsize, scp->ysize, NULL, wait);
2806 if (!discard && (old.vtb_flags & VTB_VALID)) {
2807 /* retain the current cursor position and buffer contants */
2808 scp->cursor_oldpos = scp->cursor_pos;
2810 * This works only if the old buffer has the same size as or larger
2811 * than the new one. XXX
2813 sc_vtb_copy(&old, 0, &new, 0, scp->xsize*scp->ysize);
2817 sc_vtb_destroy(&old);
2820 #ifndef SC_NO_SYSMOUSE
2821 /* move the mouse cursor at the center of the screen */
2822 sc_mouse_move(scp, scp->xpixel / 2, scp->ypixel / 2);
2827 alloc_scp(sc_softc_t *sc, int vty)
2831 /* assert(sc_malloc) */
2833 scp = kmalloc(sizeof(scr_stat), M_SYSCONS, M_WAITOK);
2834 init_scp(sc, vty, scp);
2836 sc_alloc_scr_buffer(scp, TRUE, TRUE);
2837 if (sc_init_emulator(scp, SC_DFLT_TERM))
2838 sc_init_emulator(scp, "*");
2840 #ifndef SC_NO_CUTPASTE
2841 sc_alloc_cut_buffer(scp, TRUE);
2844 #ifndef SC_NO_HISTORY
2845 sc_alloc_history_buffer(scp, 0, 0, TRUE);
2852 init_scp(sc_softc_t *sc, int vty, scr_stat *scp)
2856 bzero(scp, sizeof(*scp));
2861 scp->mode = sc->initial_mode;
2862 callout_init(&scp->blink_screen_ch);
2863 (*vidsw[sc->adapter]->get_info)(sc->adp, scp->mode, &info);
2864 if (info.vi_flags & V_INFO_GRAPHICS) {
2865 scp->status |= GRAPHICS_MODE;
2866 scp->xpixel = info.vi_width;
2867 scp->ypixel = info.vi_height;
2868 scp->xsize = info.vi_width/8;
2869 scp->ysize = info.vi_height/info.vi_cheight;
2873 scp->xsize = info.vi_width;
2874 scp->ysize = info.vi_height;
2875 scp->xpixel = scp->xsize*8;
2876 scp->ypixel = scp->ysize*info.vi_cheight;
2877 if (info.vi_cheight < 14) {
2879 #ifndef SC_NO_FONT_LOADING
2880 scp->font = sc->font_8;
2884 } else if (info.vi_cheight >= 16) {
2885 scp->font_size = 16;
2886 #ifndef SC_NO_FONT_LOADING
2887 scp->font = sc->font_16;
2892 scp->font_size = 14;
2893 #ifndef SC_NO_FONT_LOADING
2894 scp->font = sc->font_14;
2900 sc_vtb_init(&scp->vtb, VTB_MEMORY, 0, 0, NULL, FALSE);
2901 sc_vtb_init(&scp->scr, VTB_FRAMEBUFFER, 0, 0, NULL, FALSE);
2902 scp->xoff = scp->yoff = 0;
2903 scp->xpos = scp->ypos = 0;
2904 scp->start = scp->xsize * scp->ysize - 1;
2909 scp->border = BG_BLACK;
2910 scp->cursor_base = sc->cursor_base;
2911 scp->cursor_height = imin(sc->cursor_height, scp->font_size);
2912 scp->mouse_cut_start = scp->xsize*scp->ysize;
2913 scp->mouse_cut_end = -1;
2914 scp->mouse_signal = 0;
2916 scp->mouse_proc = NULL;
2917 scp->kbd_mode = K_XLATE;
2918 scp->bell_pitch = bios_value.bell_pitch;
2919 scp->bell_duration = BELL_DURATION;
2920 scp->status |= (bios_value.shift_state & NLKED);
2921 scp->status |= CURSOR_ENABLED | MOUSE_HIDDEN;
2924 scp->smode.mode = VT_AUTO;
2925 scp->history = NULL;
2926 scp->history_pos = 0;
2927 scp->history_size = 0;
2931 sc_init_emulator(scr_stat *scp, char *name)
2938 if (name == NULL) /* if no name is given, use the current emulator */
2940 else /* ...otherwise find the named emulator */
2941 sw = sc_term_match(name);
2946 if (strcmp(sw->te_renderer, "*") != 0) {
2947 rndr = sc_render_match(scp, sw->te_renderer, scp->model);
2950 rndr = sc_render_match(scp, scp->sc->adp->va_name, scp->model);
2955 if (sw == scp->tsw) {
2956 error = (*sw->te_init)(scp, &scp->ts, SC_TE_WARM_INIT);
2958 sc_clear_screen(scp);
2959 /* assert(error == 0); */
2963 if (sc_malloc && (sw->te_size > 0))
2964 p = kmalloc(sw->te_size, M_SYSCONS, M_NOWAIT);
2967 error = (*sw->te_init)(scp, &p, SC_TE_COLD_INIT);
2972 (*scp->tsw->te_term)(scp, &scp->ts);
2973 if (scp->ts != NULL)
2974 kfree(scp->ts, M_SYSCONS);
2980 (*sw->te_default_attr)(scp, user_default.std_color, user_default.rev_color);
2981 sc_clear_screen(scp);
2987 * scgetc(flags) - get character from keyboard.
2988 * If flags & SCGETC_CN, then avoid harmful side effects.
2989 * If flags & SCGETC_NONBLOCK, then wait until a key is pressed, else
2990 * return NOKEY if there is nothing there.
2993 scgetc(sc_softc_t *sc, u_int flags)
2996 #ifndef SC_NO_HISTORY
3004 if (sc->kbd == NULL)
3009 /* I don't like this, but... XXX */
3010 if (flags & SCGETC_CN) {
3012 sccnupdate(sc->cur_scp);
3017 /* first see if there is something in the keyboard port */
3019 c = kbd_read_char(sc->kbd, !(flags & SCGETC_NONBLOCK));
3021 if (!(flags & SCGETC_CN))
3022 sc_bell(scp, bios_value.bell_pitch, BELL_DURATION);
3023 } else if (c == NOKEY)
3029 /* make screensaver happy */
3031 sc_touch_scrn_saver();
3033 if (!(flags & SCGETC_CN))
3034 /* do the /dev/random device a favour */
3035 add_keyboard_randomness(c);
3037 if (scp->kbd_mode != K_XLATE)
3040 /* if scroll-lock pressed allow history browsing */
3041 if (!ISGRAPHSC(scp) && scp->history && scp->status & SLKED) {
3043 scp->status &= ~CURSOR_ENABLED;
3044 sc_remove_cursor_image(scp);
3046 #ifndef SC_NO_HISTORY
3047 if (!(scp->status & BUFFER_SAVED)) {
3048 scp->status |= BUFFER_SAVED;
3052 /* FIXME: key codes */
3053 case SPCLKEY | FKEY | F(49): /* home key */
3054 sc_remove_cutmarking(scp);
3058 case SPCLKEY | FKEY | F(57): /* end key */
3059 sc_remove_cutmarking(scp);
3063 case SPCLKEY | FKEY | F(50): /* up arrow key */
3064 sc_remove_cutmarking(scp);
3065 if (sc_hist_up_line(scp))
3066 if (!(flags & SCGETC_CN))
3067 sc_bell(scp, bios_value.bell_pitch, BELL_DURATION);
3070 case SPCLKEY | FKEY | F(58): /* down arrow key */
3071 sc_remove_cutmarking(scp);
3072 if (sc_hist_down_line(scp))
3073 if (!(flags & SCGETC_CN))
3074 sc_bell(scp, bios_value.bell_pitch, BELL_DURATION);
3077 case SPCLKEY | FKEY | F(51): /* page up key */
3078 sc_remove_cutmarking(scp);
3079 for (i=0; i<scp->ysize; i++)
3080 if (sc_hist_up_line(scp)) {
3081 if (!(flags & SCGETC_CN))
3082 sc_bell(scp, bios_value.bell_pitch, BELL_DURATION);
3087 case SPCLKEY | FKEY | F(59): /* page down key */
3088 sc_remove_cutmarking(scp);
3089 for (i=0; i<scp->ysize; i++)
3090 if (sc_hist_down_line(scp)) {
3091 if (!(flags & SCGETC_CN))
3092 sc_bell(scp, bios_value.bell_pitch, BELL_DURATION);
3097 #endif /* SC_NO_HISTORY */
3101 * Process and consume special keys here. Return a plain char code
3102 * or a char code with the META flag or a function key code.
3106 /* goto next_code */
3111 switch (KEYCHAR(c)) {
3113 case NLK: case CLK: case ALK:
3116 kbd_ioctl(sc->kbd, KDGKBSTATE, (caddr_t)&f);
3118 scp->status |= SLKED;
3120 if (scp->status & SLKED) {
3121 scp->status &= ~SLKED;
3122 #ifndef SC_NO_HISTORY
3123 if (scp->status & BUFFER_SAVED) {
3124 if (!sc_hist_restore(scp))
3125 sc_remove_cutmarking(scp);
3126 scp->status &= ~BUFFER_SAVED;
3127 scp->status |= CURSOR_ENABLED;
3128 sc_draw_cursor_image(scp);
3130 tp = VIRTUAL_TTY(sc, scp->index);
3138 /* NON-LOCKING KEYS */
3140 case LSH: case RSH: case LCTR: case RCTR:
3141 case LALT: case RALT: case ASH: case META:
3145 if (!(sc->flags & SC_SCRN_BLANKED))
3151 /* force activatation/deactivation of the screen saver */
3152 if (!(sc->flags & SC_SCRN_BLANKED)) {
3153 run_scrn_saver = TRUE;
3154 sc->scrn_time_stamp -= scrn_blank_time;
3158 * While devices are being probed, the screen saver need
3159 * to be invoked explictly. XXX
3161 if (sc->flags & SC_SCRN_BLANKED) {
3162 scsplash_stick(FALSE);
3163 stop_scrn_saver(sc, current_saver);
3165 if (!ISGRAPHSC(scp)) {
3166 scsplash_stick(TRUE);
3167 (*current_saver)(sc, TRUE);
3171 #endif /* NSPLASH */
3175 #ifndef SC_DISABLE_REBOOT
3181 #ifndef SC_DISABLE_REBOOT
3182 shutdown_nice(RB_HALT);
3187 #ifndef SC_DISABLE_REBOOT
3188 shutdown_nice(RB_HALT|RB_POWEROFF);
3194 apm_suspend(PMST_SUSPEND);
3197 apm_suspend(PMST_STANDBY);
3206 #ifndef SC_DISABLE_DDBKEY
3208 Debugger("manual escape to debugger");
3210 kprintf("No debugger in kernel\n");
3212 #else /* SC_DISABLE_DDBKEY */
3214 #endif /* SC_DISABLE_DDBKEY */
3218 if (enable_panic_key)
3219 panic("Forced by the panic key");
3223 this_scr = scp->index;
3224 for (i = (this_scr - sc->first_vty + 1)%sc->vtys;
3225 sc->first_vty + i != this_scr;
3226 i = (i + 1)%sc->vtys) {
3227 struct tty *tp = VIRTUAL_TTY(sc, sc->first_vty + i);
3228 if (ISTTYOPEN(tp)) {
3229 sc_switch_scr(scp->sc, sc->first_vty + i);
3236 this_scr = scp->index;
3237 for (i = (this_scr - sc->first_vty + sc->vtys - 1)%sc->vtys;
3238 sc->first_vty + i != this_scr;
3239 i = (i + sc->vtys - 1)%sc->vtys) {
3240 struct tty *tp = VIRTUAL_TTY(sc, sc->first_vty + i);
3241 if (ISTTYOPEN(tp)) {
3242 sc_switch_scr(scp->sc, sc->first_vty + i);
3249 if (KEYCHAR(c) >= F_SCR && KEYCHAR(c) <= L_SCR) {
3250 sc_switch_scr(scp->sc, sc->first_vty + KEYCHAR(c) - F_SCR);
3253 /* assert(c & FKEY) */
3254 if (!(sc->flags & SC_SCRN_BLANKED))
3258 /* goto next_code */
3260 /* regular keys (maybe MKEY is set) */
3261 if (!(sc->flags & SC_SCRN_BLANKED))
3270 scmmap(struct dev_mmap_args *ap)
3274 scp = SC_STAT(ap->a_head.a_dev);
3275 if (scp != scp->sc->cur_scp)
3277 ap->a_result = (*vidsw[scp->sc->adapter]->mmap)(scp->sc->adp, ap->a_offset,
3283 save_kbd_state(scr_stat *scp)
3288 error = kbd_ioctl(scp->sc->kbd, KDGKBSTATE, (caddr_t)&state);
3289 if (error == ENOIOCTL)
3292 scp->status &= ~LOCK_MASK;
3293 scp->status |= state;
3299 update_kbd_state(scr_stat *scp, int new_bits, int mask)
3304 if (mask != LOCK_MASK) {
3305 error = kbd_ioctl(scp->sc->kbd, KDGKBSTATE, (caddr_t)&state);
3306 if (error == ENOIOCTL)
3311 state |= new_bits & mask;
3313 state = new_bits & LOCK_MASK;
3315 error = kbd_ioctl(scp->sc->kbd, KDSKBSTATE, (caddr_t)&state);
3316 if (error == ENOIOCTL)
3322 update_kbd_leds(scr_stat *scp, int which)
3327 error = kbd_ioctl(scp->sc->kbd, KDSETLED, (caddr_t)&which);
3328 if (error == ENOIOCTL)
3334 set_mode(scr_stat *scp)
3338 /* reject unsupported mode */
3339 if ((*vidsw[scp->sc->adapter]->get_info)(scp->sc->adp, scp->mode, &info))
3342 /* if this vty is not currently showing, do nothing */
3343 if (scp != scp->sc->cur_scp)
3346 /* setup video hardware for the given mode */
3347 (*vidsw[scp->sc->adapter]->set_mode)(scp->sc->adp, scp->mode);
3348 sc_vtb_init(&scp->scr, VTB_FRAMEBUFFER, scp->xsize, scp->ysize,
3349 (void *)scp->sc->adp->va_window, FALSE);
3351 #ifndef SC_NO_FONT_LOADING
3352 /* load appropriate font */
3353 if (!(scp->status & GRAPHICS_MODE)) {
3354 if (!(scp->status & PIXEL_MODE) && ISFONTAVAIL(scp->sc->adp->va_flags)) {
3355 if (scp->font_size < 14) {
3356 if (scp->sc->fonts_loaded & FONT_8)
3357 sc_load_font(scp, 0, 8, scp->sc->font_8, 0, 256);
3358 } else if (scp->font_size >= 16) {
3359 if (scp->sc->fonts_loaded & FONT_16)
3360 sc_load_font(scp, 0, 16, scp->sc->font_16, 0, 256);
3362 if (scp->sc->fonts_loaded & FONT_14)
3363 sc_load_font(scp, 0, 14, scp->sc->font_14, 0, 256);
3367 * This is an interim kludge to display correct font.
3368 * Always use the font page #0 on the video plane 2.
3369 * Somehow we cannot show the font in other font pages on
3370 * some video cards... XXX
3372 sc_show_font(scp, 0);
3376 #endif /* !SC_NO_FONT_LOADING */
3378 sc_set_border(scp, scp->border);
3379 sc_set_cursor_image(scp);
3385 refresh_ega_palette(scr_stat *scp)
3389 int rsize, gsize, bsize;
3390 int rfld, gfld, bfld;
3393 rsize = scp->sc->adp->va_info.vi_pixel_fsizes[0];
3394 gsize = scp->sc->adp->va_info.vi_pixel_fsizes[1];
3395 bsize = scp->sc->adp->va_info.vi_pixel_fsizes[2];
3396 rfld = scp->sc->adp->va_info.vi_pixel_fields[0];
3397 gfld = scp->sc->adp->va_info.vi_pixel_fields[1];
3398 bfld = scp->sc->adp->va_info.vi_pixel_fields[2];
3400 for (i = 0; i < 16; i++) {
3401 reg = scp->sc->adp->va_palette_regs[i];
3403 r = scp->sc->palette[reg * 3] >> (8 - rsize);
3404 g = scp->sc->palette[reg * 3 + 1] >> (8 - gsize);
3405 b = scp->sc->palette[reg * 3 + 2] >> (8 - bsize);
3407 scp->ega_palette[i] = (r << rfld) + (g << gfld) + (b << bfld);
3412 sc_set_border(scr_stat *scp, int color)
3414 ++scp->sc->videoio_in_progress;
3415 (*scp->rndr->draw_border)(scp, color);
3416 --scp->sc->videoio_in_progress;
3419 #ifndef SC_NO_FONT_LOADING
3421 sc_load_font(scr_stat *scp, int page, int size, u_char *buf,
3422 int base, int count)
3427 sc->font_loading_in_progress = TRUE;
3428 (*vidsw[sc->adapter]->load_font)(sc->adp, page, size, buf, base, count);
3429 sc->font_loading_in_progress = FALSE;
3433 sc_save_font(scr_stat *scp, int page, int size, u_char *buf,
3434 int base, int count)
3439 sc->font_loading_in_progress = TRUE;
3440 (*vidsw[sc->adapter]->save_font)(sc->adp, page, size, buf, base, count);
3441 sc->font_loading_in_progress = FALSE;
3445 sc_show_font(scr_stat *scp, int page)
3447 (*vidsw[scp->sc->adapter]->show_font)(scp->sc->adp, page);
3449 #endif /* !SC_NO_FONT_LOADING */
3452 sc_paste(scr_stat *scp, u_char *p, int count)
3457 if (scp->status & MOUSE_VISIBLE) {
3458 tp = VIRTUAL_TTY(scp->sc, scp->sc->cur_scp->index);
3461 rmap = scp->sc->scr_rmap;
3462 for (; count > 0; --count)
3463 (*linesw[tp->t_line].l_rint)(rmap[*p++], tp);
3468 sc_bell(scr_stat *scp, int pitch, int duration)
3470 if (cold || shutdown_in_progress)
3473 if (scp != scp->sc->cur_scp && (scp->sc->flags & SC_QUIET_BELL))
3476 if (scp->sc->flags & SC_VISUAL_BELL) {
3477 if (scp->sc->blink_in_progress)
3479 scp->sc->blink_in_progress = 3;
3480 if (scp != scp->sc->cur_scp)
3481 scp->sc->blink_in_progress += 2;
3482 blink_screen(scp->sc->cur_scp);
3483 } else if (duration != 0 && pitch != 0) {
3484 if (scp != scp->sc->cur_scp)
3486 sysbeep(pitch, duration);
3491 blink_screen(void *arg)
3493 scr_stat *scp = arg;
3496 if (ISGRAPHSC(scp) || (scp->sc->blink_in_progress <= 1)) {
3497 scp->sc->blink_in_progress = 0;
3499 tp = VIRTUAL_TTY(scp->sc, scp->index);
3502 if (scp->sc->delayed_next_scr)
3503 sc_switch_scr(scp->sc, scp->sc->delayed_next_scr - 1);
3506 (*scp->rndr->draw)(scp, 0, scp->xsize*scp->ysize,
3507 scp->sc->blink_in_progress & 1);
3508 scp->sc->blink_in_progress--;
3509 callout_reset(&scp->blink_screen_ch, hz / 10, blink_screen, scp);
3515 * Allocate active keyboard. Try to allocate "kbdmux" keyboard first, and,
3516 * if found, add all non-busy keyboards to "kbdmux". Otherwise look for
3521 sc_allocate_keyboard(sc_softc_t *sc, int unit)
3527 idx0 = kbd_allocate("kbdmux", -1, (void *)&sc->keyboard, sckbdevent, sc);
3529 k0 = kbd_get_keyboard(idx0);
3531 for (idx = kbd_find_keyboard2("*", -1, 0, 0);
3533 idx = kbd_find_keyboard2("*", -1, idx + 1, 0)) {
3534 k = kbd_get_keyboard(idx);
3536 if (idx == idx0 || KBD_IS_BUSY(k))
3539 bzero(&ki, sizeof(ki));
3540 strcpy(ki.kb_name, k->kb_name);
3541 ki.kb_unit = k->kb_unit;
3543 kbd_ioctl(k0, KBADDKBD, (caddr_t) &ki);
3546 idx0 = kbd_allocate("*", unit, (void *)&sc->keyboard, sckbdevent, sc);