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 | D_KQFILTER },
245 .d_kqfilter = ttykqfilter,
246 .d_revoke = ttyrevoke
250 sc_probe_unit(int unit, int flags)
252 if (!scvidprobe(unit, flags, FALSE)) {
254 kprintf("sc%d: no video adapter found.\n", unit);
258 /* syscons will be attached even when there is no keyboard */
259 sckbdprobe(unit, flags, FALSE);
264 /* probe video adapters, return TRUE if found */
266 scvidprobe(int unit, int flags, int cons)
269 * Access the video adapter driver through the back door!
270 * Video adapter drivers need to be configured before syscons.
271 * However, when syscons is being probed as the low-level console,
272 * they have not been initialized yet. We force them to initialize
273 * themselves here. XXX
275 vid_configure(cons ? VIO_PROBE_ONLY : 0);
277 return (vid_find_adapter("*", unit) >= 0);
280 /* probe the keyboard, return TRUE if found */
282 sckbdprobe(int unit, int flags, int cons)
284 /* access the keyboard driver through the backdoor! */
285 kbd_configure(cons ? KB_CONF_PROBE_ONLY : 0);
287 return (kbd_find_keyboard("*", unit) >= 0);
291 adapter_name(video_adapter_t *adp)
297 { KD_MONO, { "MDA", "MDA" } },
298 { KD_HERCULES, { "Hercules", "Hercules" } },
299 { KD_CGA, { "CGA", "CGA" } },
300 { KD_EGA, { "EGA", "EGA (mono)" } },
301 { KD_VGA, { "VGA", "VGA (mono)" } },
302 { KD_TGA, { "TGA", "TGA" } },
303 { -1, { "Unknown", "Unknown" } },
307 for (i = 0; names[i].type != -1; ++i)
308 if (names[i].type == adp->va_type)
310 return names[i].name[(adp->va_flags & V_ADP_COLOR) ? 0 : 1];
314 sc_attach_unit(int unit, int flags)
324 flags &= ~SC_KERNEL_CONSOLE;
326 if (sc_console_unit == unit) {
328 * If this unit is being used as the system console, we need to
329 * adjust some variables and buffers before and after scinit().
331 /* assert(sc_console != NULL) */
332 flags |= SC_KERNEL_CONSOLE;
337 if (sc_console->tsw->te_size > 0) {
338 /* assert(sc_console->ts != NULL); */
339 kernel_console_ts = sc_console->ts;
340 sc_console->ts = kmalloc(sc_console->tsw->te_size,
341 M_SYSCONS, M_WAITOK);
342 bcopy(kernel_console_ts, sc_console->ts, sc_console->tsw->te_size);
343 (*sc_console->tsw->te_default_attr)(sc_console,
344 user_default.std_color,
345 user_default.rev_color);
351 sc = sc_get_softc(unit, flags & SC_KERNEL_CONSOLE);
354 * If this is the console we couldn't setup sc->dev before because
355 * malloc wasn't working. Set it up now.
357 if (flags & SC_KERNEL_CONSOLE) {
358 KKASSERT(sc->dev == NULL);
359 sc->dev = kmalloc(sizeof(cdev_t)*sc->vtys, M_SYSCONS, M_WAITOK|M_ZERO);
360 sc->dev[0] = make_dev(&sc_ops, sc_console_unit*MAXCONS, UID_ROOT,
362 "ttyv%r", sc_console_unit*MAXCONS);
363 sc->dev[0]->si_tty = ttymalloc(sc->dev[0]->si_tty);
364 sc->dev[0]->si_drv1 = sc_console;
368 * Finish up the standard attach
371 callout_init(&sc->scrn_timer_ch);
372 scp = SC_STAT(sc->dev[0]);
373 if (sc_console == NULL) /* sc_console_unit < 0 */
377 if ((sc->config & SC_VESA800X600)
378 && ((*vidsw[sc->adapter]->get_info)(sc->adp, M_VESA_800x600, &info) == 0)) {
380 if (sc->flags & SC_SPLASH_SCRN)
381 splash_term(sc->adp);
383 sc_set_graphics_mode(scp, NULL, M_VESA_800x600);
384 sc_set_pixel_mode(scp, NULL, 0, 0, 16);
385 sc->initial_mode = M_VESA_800x600;
387 /* put up the splash again! */
388 if (sc->flags & SC_SPLASH_SCRN)
389 splash_init(sc->adp, scsplash_callback, sc);
392 #endif /* SC_PIXEL_MODE */
394 /* initialize cursor */
396 update_cursor_image(scp);
398 /* get screen update going */
401 /* set up the keyboard */
402 kbd_ioctl(sc->kbd, KDSKBMODE, (caddr_t)&scp->kbd_mode);
403 update_kbd_state(scp, scp->status, LOCK_MASK);
405 kprintf("sc%d: %s <%d virtual consoles, flags=0x%x>\n",
406 unit, adapter_name(sc->adp), sc->vtys, sc->config);
408 kprintf("sc%d:", unit);
409 if (sc->adapter >= 0)
410 kprintf(" fb%d", sc->adapter);
411 if (sc->keyboard >= 0)
412 kprintf(", kbd%d", sc->keyboard);
414 kprintf(", terminal emulator: %s (%s)",
415 scp->tsw->te_name, scp->tsw->te_desc);
419 /* register a shutdown callback for the kernel console */
420 if (sc_console_unit == unit)
421 EVENTHANDLER_REGISTER(shutdown_pre_sync, scshutdown,
422 (void *)(uintptr_t)unit, SHUTDOWN_PRI_DEFAULT);
427 * The first vty already has struct tty and scr_stat initialized
428 * in scinit(). The other vtys will have these structs when
431 for (vc = 1; vc < sc->vtys; vc++) {
432 dev = make_dev(&sc_ops, vc + unit * MAXCONS,
434 0600, "ttyv%r", vc + unit * MAXCONS);
437 cctl_dev = make_dev(&sc_ops, SC_CONSOLECTL,
438 UID_ROOT, GID_WHEEL, 0600, "consolectl");
439 cctl_dev->si_tty = sc_console_tty = ttymalloc(sc_console_tty);
440 cctl_dev->si_drv1 = sc_console;
452 * As soon as malloc() becomes functional, we had better allocate
453 * various buffers for the kernel console.
456 if (sc_console_unit < 0) /* sc_console == NULL */
459 /* copy the temporary buffer to the final buffer */
460 sc_alloc_scr_buffer(sc_console, TRUE, FALSE);
462 #ifndef SC_NO_CUTPASTE
463 sc_alloc_cut_buffer(sc_console, TRUE);
466 #ifndef SC_NO_HISTORY
467 /* initialize history buffer & pointers */
468 sc_alloc_history_buffer(sc_console, 0, 0, TRUE);
472 SYSINIT(sc_mem, SI_BOOT1_POST, SI_ORDER_ANY, scmeminit, NULL);
475 scdevtounit(cdev_t dev)
477 int vty = SC_VTY(dev);
479 if (vty == SC_CONSOLECTL)
480 return ((sc_console != NULL) ? sc_console->sc->unit : -1);
481 else if ((vty < 0) || (vty >= MAXCONS*sc_max_unit()))
488 scopen(struct dev_open_args *ap)
490 cdev_t dev = ap->a_head.a_dev;
491 int unit = scdevtounit(dev);
498 DPRINTF(5, ("scopen: dev:%d,%d, unit:%d, vty:%d\n",
499 major(dev), minor(dev), unit, SC_VTY(dev)));
501 sc = sc_get_softc(unit, (sc_console_unit == unit) ? SC_KERNEL_CONSOLE : 0);
505 tp = dev->si_tty = ttymalloc(dev->si_tty);
506 tp->t_oproc = scstart;
507 tp->t_param = scparam;
508 tp->t_stop = nottystop;
512 if (!ISTTYOPEN(tp)) {
514 /* Use the current setting of the <-- key as default VERASE. */
515 /* If the Delete key is preferable, an stty is necessary */
516 if (sc->kbd != NULL) {
517 key.keynum = KEYCODE_BS;
518 kbd_ioctl(sc->kbd, GIO_KEYMAPENT, (caddr_t)&key);
519 tp->t_cc[VERASE] = key.key.map[0];
521 tp->t_iflag = TTYDEF_IFLAG;
522 tp->t_oflag = TTYDEF_OFLAG;
523 tp->t_cflag = TTYDEF_CFLAG;
524 tp->t_lflag = TTYDEF_LFLAG;
525 tp->t_ispeed = tp->t_ospeed = TTYDEF_SPEED;
526 scparam(tp, &tp->t_termios);
527 (*linesw[tp->t_line].l_modem)(tp, 1);
530 if (tp->t_state & TS_XCLUDE && priv_check_cred(ap->a_cred, PRIV_ROOT, 0))
533 error = (*linesw[tp->t_line].l_open)(dev, tp);
537 scp = dev->si_drv1 = alloc_scp(sc, SC_VTY(dev));
539 sc_set_pixel_mode(scp, NULL, COL, ROW, 16);
541 if (!tp->t_winsize.ws_col && !tp->t_winsize.ws_row) {
542 tp->t_winsize.ws_col = scp->xsize;
543 tp->t_winsize.ws_row = scp->ysize;
550 scclose(struct dev_close_args *ap)
552 cdev_t dev = ap->a_head.a_dev;
553 struct tty *tp = dev->si_tty;
557 if (SC_VTY(dev) != SC_CONSOLECTL) {
558 scp = SC_STAT(tp->t_dev);
559 /* were we in the middle of the VT switching process? */
560 DPRINTF(5, ("sc%d: scclose(), ", scp->sc->unit));
561 if ((scp == scp->sc->cur_scp) && (scp->sc->unit == sc_console_unit))
562 cons_unavail = FALSE;
564 * note: must be called from a critical section because finish_vt_rel
565 * will call do_switch_scr which releases it temporarily
567 if (finish_vt_rel(scp, TRUE) == 0) /* force release */
568 DPRINTF(5, ("reset WAIT_REL, "));
569 if (finish_vt_acq(scp) == 0) /* force acknowledge */
570 DPRINTF(5, ("reset WAIT_ACQ, "));
572 if (scp == &main_console) {
575 scp->smode.mode = VT_AUTO;
578 sc_vtb_destroy(&scp->vtb);
579 sc_vtb_destroy(&scp->scr);
580 sc_free_history_buffer(scp, scp->ysize);
582 kfree(scp, M_SYSCONS);
587 scp->smode.mode = VT_AUTO;
589 scp->kbd_mode = K_XLATE;
590 if (scp == scp->sc->cur_scp)
591 kbd_ioctl(scp->sc->kbd, KDSKBMODE, (caddr_t)&scp->kbd_mode);
592 DPRINTF(5, ("done.\n"));
594 (*linesw[tp->t_line].l_close)(tp, ap->a_fflag);
602 scread(struct dev_read_args *ap)
604 sc_touch_scrn_saver();
605 return (ttyread(ap));
609 sckbdevent(keyboard_t *thiskbd, int event, void *arg)
618 * WARNING: In early boot sc->dev may not be setup yet.
620 sc = (sc_softc_t *)arg;
621 /* assert(thiskbd == sc->kbd) */
626 case KBDIO_UNLOADING:
629 kbd_release(thiskbd, (void *)&sc->keyboard);
636 * Loop while there is still input to get from the keyboard.
637 * I don't think this is nessesary, and it doesn't fix
638 * the Xaccel-2.1 keyboard hang, but it can't hurt. XXX
640 while ((c = scgetc(sc, SCGETC_NONBLOCK)) != NOKEY) {
641 cur_tty = VIRTUAL_TTY(sc, sc->cur_scp->index);
642 if (!ISTTYOPEN(cur_tty)) {
643 cur_tty = sc_console_tty;
644 if (!ISTTYOPEN(cur_tty))
648 if ((*sc->cur_scp->tsw->te_input)(sc->cur_scp, c, cur_tty))
651 switch (KEYFLAGS(c)) {
652 case 0x0000: /* normal key */
653 (*linesw[cur_tty->t_line].l_rint)(KEYCHAR(c), cur_tty);
655 case FKEY: /* function key, return string */
656 cp = kbd_get_fkeystr(thiskbd, KEYCHAR(c), &len);
659 (*linesw[cur_tty->t_line].l_rint)(*cp++, cur_tty);
662 case MKEY: /* meta is active, prepend ESC */
663 (*linesw[cur_tty->t_line].l_rint)(0x1b, cur_tty);
664 (*linesw[cur_tty->t_line].l_rint)(KEYCHAR(c), cur_tty);
666 case BKEY: /* backtab fixed sequence (esc [ Z) */
667 (*linesw[cur_tty->t_line].l_rint)(0x1b, cur_tty);
668 (*linesw[cur_tty->t_line].l_rint)('[', cur_tty);
669 (*linesw[cur_tty->t_line].l_rint)('Z', cur_tty);
674 sc->cur_scp->status |= MOUSE_HIDDEN;
680 scparam(struct tty *tp, struct termios *t)
682 tp->t_ispeed = t->c_ispeed;
683 tp->t_ospeed = t->c_ospeed;
684 tp->t_cflag = t->c_cflag;
689 scioctl(struct dev_ioctl_args *ap)
691 cdev_t dev = ap->a_head.a_dev;
692 u_long cmd = ap->a_cmd;
693 caddr_t data = ap->a_data;
694 int flag = ap->a_fflag;
703 error = sc_vid_ioctl(tp, cmd, data, flag);
704 if (error != ENOIOCTL)
707 #ifndef SC_NO_HISTORY
708 error = sc_hist_ioctl(tp, cmd, data, flag);
709 if (error != ENOIOCTL)
713 #ifndef SC_NO_SYSMOUSE
714 error = sc_mouse_ioctl(tp, cmd, data, flag);
715 if (error != ENOIOCTL)
719 scp = SC_STAT(tp->t_dev);
720 /* assert(scp != NULL) */
721 /* scp is sc_console, if SC_VTY(dev) == SC_CONSOLECTL. */
725 error = (*scp->tsw->te_ioctl)(scp, tp, cmd, data, flag);
726 if (error != ENOIOCTL)
730 switch (cmd) { /* process console hardware related ioctl's */
732 case GIO_ATTR: /* get current attributes */
733 /* this ioctl is not processed here, but in the terminal emulator */
736 case GIO_COLOR: /* is this a color console ? */
737 *(int *)data = (sc->adp->va_flags & V_ADP_COLOR) ? 1 : 0;
740 case CONS_BLANKTIME: /* set screen saver timeout (0 = no saver) */
741 if (*(int *)data < 0 || *(int *)data > MAX_BLANKTIME)
744 scrn_blank_time = *(int *)data;
745 run_scrn_saver = (scrn_blank_time != 0);
749 case CONS_CURSORTYPE: /* set cursor type blink/noblink */
751 if (!ISGRAPHSC(sc->cur_scp))
752 sc_remove_cursor_image(sc->cur_scp);
753 if ((*(int*)data) & 0x01)
754 sc->flags |= SC_BLINK_CURSOR;
756 sc->flags &= ~SC_BLINK_CURSOR;
757 if ((*(int*)data) & 0x02) {
758 sc->flags |= SC_CHAR_CURSOR;
760 sc->flags &= ~SC_CHAR_CURSOR;
762 * The cursor shape is global property; all virtual consoles
763 * are affected. Update the cursor in the current console...
765 if (!ISGRAPHSC(sc->cur_scp)) {
766 sc_set_cursor_image(sc->cur_scp);
767 sc_draw_cursor_image(sc->cur_scp);
772 case CONS_BELLTYPE: /* set bell type sound/visual */
773 if ((*(int *)data) & 0x01)
774 sc->flags |= SC_VISUAL_BELL;
776 sc->flags &= ~SC_VISUAL_BELL;
777 if ((*(int *)data) & 0x02)
778 sc->flags |= SC_QUIET_BELL;
780 sc->flags &= ~SC_QUIET_BELL;
783 case CONS_GETINFO: /* get current (virtual) console info */
785 vid_info_t *ptr = (vid_info_t*)data;
786 if (ptr->size == sizeof(struct vid_info)) {
787 ptr->m_num = sc->cur_scp->index;
788 ptr->font_size = scp->font_size;
789 ptr->mv_col = scp->xpos;
790 ptr->mv_row = scp->ypos;
791 ptr->mv_csz = scp->xsize;
792 ptr->mv_rsz = scp->ysize;
794 * The following fields are filled by the terminal emulator. XXX
801 ptr->mv_grfc.fore = 0; /* not supported */
802 ptr->mv_grfc.back = 0; /* not supported */
803 ptr->mv_ovscan = scp->border;
804 if (scp == sc->cur_scp)
806 ptr->mk_keylock = scp->status & LOCK_MASK;
812 case CONS_GETVERS: /* get version number */
813 *(int*)data = 0x200; /* version 2.0 */
816 case CONS_IDLE: /* see if the screen has been idle */
818 * When the screen is in the GRAPHICS_MODE or UNKNOWN_MODE,
819 * the user process may have been writing something on the
820 * screen and syscons is not aware of it. Declare the screen
821 * is NOT idle if it is in one of these modes. But there is
822 * an exception to it; if a screen saver is running in the
823 * graphics mode in the current screen, we should say that the
824 * screen has been idle.
826 *(int *)data = (sc->flags & SC_SCRN_IDLE)
827 && (!ISGRAPHSC(sc->cur_scp)
828 || (sc->cur_scp->status & SAVER_RUNNING));
831 case CONS_SAVERMODE: /* set saver mode */
832 switch(*(int *)data) {
835 /* if a LKM screen saver is running, stop it first. */
836 scsplash_stick(FALSE);
837 saver_mode = *(int *)data;
840 if ((error = wait_scrn_saver_stop(NULL))) {
845 run_scrn_saver = TRUE;
846 if (saver_mode == CONS_USR_SAVER)
847 scp->status |= SAVER_RUNNING;
849 scp->status &= ~SAVER_RUNNING;
850 scsplash_stick(TRUE);
855 if ((saver_mode == CONS_USR_SAVER) && (scp->status & SAVER_RUNNING))
856 scp->status &= ~SAVER_RUNNING;
857 saver_mode = *(int *)data;
865 case CONS_SAVERSTART: /* immediately start/stop the screen saver */
867 * Note that this ioctl does not guarantee the screen saver
868 * actually starts or stops. It merely attempts to do so...
871 run_scrn_saver = (*(int *)data != 0);
873 sc->scrn_time_stamp -= scrn_blank_time;
877 case CONS_SCRSHOT: /* get a screen shot */
879 scrshot_t *ptr = (scrshot_t*)data;
881 if (ISGRAPHSC(scp)) {
885 if (scp->xsize != ptr->xsize || scp->ysize != ptr->ysize) {
889 copyout ((void*)scp->vtb.vtb_buffer, ptr->buf,
890 ptr->xsize * ptr->ysize * sizeof(uint16_t));
895 case VT_SETMODE: /* set screen switcher mode */
897 struct vt_mode *mode;
899 mode = (struct vt_mode *)data;
900 DPRINTF(5, ("sc%d: VT_SETMODE ", sc->unit));
901 if (scp->smode.mode == VT_PROCESS) {
902 if (scp->proc == pfind(scp->pid) && scp->proc != curproc) {
903 DPRINTF(5, ("error EPERM\n"));
908 if (mode->mode == VT_AUTO) {
909 scp->smode.mode = VT_AUTO;
912 DPRINTF(5, ("VT_AUTO, "));
913 if ((scp == sc->cur_scp) && (sc->unit == sc_console_unit))
914 cons_unavail = FALSE;
916 * note: must be called from a critical section because
917 * finish_vt_rel will call do_switch_scr which releases it
920 if (finish_vt_rel(scp, TRUE) == 0)
921 DPRINTF(5, ("reset WAIT_REL, "));
922 if (finish_vt_acq(scp) == 0)
923 DPRINTF(5, ("reset WAIT_ACQ, "));
925 if (!ISSIGVALID(mode->relsig) || !ISSIGVALID(mode->acqsig)
926 || !ISSIGVALID(mode->frsig)) {
928 DPRINTF(5, ("error EINVAL\n"));
931 DPRINTF(5, ("VT_PROCESS %d, ", curproc->p_pid));
932 bcopy(data, &scp->smode, sizeof(struct vt_mode));
934 scp->pid = scp->proc->p_pid;
935 if ((scp == sc->cur_scp) && (sc->unit == sc_console_unit))
943 case VT_GETMODE: /* get screen switcher mode */
944 bcopy(&scp->smode, data, sizeof(struct vt_mode));
947 case VT_RELDISP: /* screen switcher ioctl */
950 * This must be the current vty which is in the VT_PROCESS
953 if ((scp != sc->cur_scp) || (scp->smode.mode != VT_PROCESS)) {
957 /* ...and this process is controlling it. */
958 if (scp->proc != curproc) {
963 switch(*(int *)data) {
964 case VT_FALSE: /* user refuses to release screen, abort */
966 * note: must be called from a critical section because
967 * finish_vt_rel will call do_switch_scr which releases it
970 if ((error = finish_vt_rel(scp, FALSE)) == 0)
971 DPRINTF(5, ("sc%d: VT_FALSE\n", sc->unit));
973 case VT_TRUE: /* user has released screen, go on */
975 * note: must be called from a critical section because
976 * finish_vt_rel will call do_switch_scr which releases it
979 if ((error = finish_vt_rel(scp, TRUE)) == 0)
980 DPRINTF(5, ("sc%d: VT_TRUE\n", sc->unit));
982 case VT_ACKACQ: /* acquire acknowledged, switch completed */
983 if ((error = finish_vt_acq(scp)) == 0)
984 DPRINTF(5, ("sc%d: VT_ACKACQ\n", sc->unit));
992 case VT_OPENQRY: /* return free virtual console */
993 for (i = sc->first_vty; i < sc->first_vty + sc->vtys; i++) {
994 tp = VIRTUAL_TTY(sc, i);
995 if (!ISTTYOPEN(tp)) {
996 *(int *)data = i + 1;
1002 case VT_ACTIVATE: /* switch to screen *data */
1003 i = (*(int *)data == 0) ? scp->index : (*(int *)data - 1);
1005 sc_clean_up(sc->cur_scp);
1007 return sc_switch_scr(sc, i);
1009 case VT_WAITACTIVE: /* wait for switch to occur */
1010 i = (*(int *)data == 0) ? scp->index : (*(int *)data - 1);
1011 if ((i < sc->first_vty) || (i >= sc->first_vty + sc->vtys))
1014 error = sc_clean_up(sc->cur_scp);
1018 scp = SC_STAT(SC_DEV(sc, i));
1019 if (scp == scp->sc->cur_scp)
1021 error = tsleep((caddr_t)&scp->smode, PCATCH, "waitvt", 0);
1022 /* May return ERESTART */
1025 case VT_GETACTIVE: /* get active vty # */
1026 *(int *)data = sc->cur_scp->index + 1;
1029 case VT_GETINDEX: /* get this vty # */
1030 *(int *)data = scp->index + 1;
1033 case VT_LOCKSWITCH: /* prevent vty switching */
1034 if ((*(int *)data) & 0x01)
1035 sc->flags |= SC_SCRN_VTYLOCK;
1037 sc->flags &= ~SC_SCRN_VTYLOCK;
1040 case KDENABIO: /* allow io operations */
1041 error = priv_check_cred(ap->a_cred, PRIV_ROOT, 0);
1044 if (securelevel > 0)
1046 #if defined(__i386__)
1047 curthread->td_lwp->lwp_md.md_regs->tf_eflags |= PSL_IOPL;
1048 #elif defined(__x86_64__)
1049 curthread->td_lwp->lwp_md.md_regs->tf_rflags |= PSL_IOPL;
1053 case KDDISABIO: /* disallow io operations (default) */
1054 #if defined(__i386__)
1055 curthread->td_lwp->lwp_md.md_regs->tf_eflags &= ~PSL_IOPL;
1056 #elif defined(__x86_64__)
1057 curthread->td_lwp->lwp_md.md_regs->tf_rflags &= ~PSL_IOPL;
1061 case KDSKBSTATE: /* set keyboard state (locks) */
1062 if (*(int *)data & ~LOCK_MASK)
1064 scp->status &= ~LOCK_MASK;
1065 scp->status |= *(int *)data;
1066 if (scp == sc->cur_scp)
1067 update_kbd_state(scp, scp->status, LOCK_MASK);
1070 case KDGKBSTATE: /* get keyboard state (locks) */
1071 if (scp == sc->cur_scp)
1072 save_kbd_state(scp);
1073 *(int *)data = scp->status & LOCK_MASK;
1076 case KDGETREPEAT: /* get keyboard repeat & delay rates */
1077 case KDSETREPEAT: /* set keyboard repeat & delay rates (new) */
1078 error = kbd_ioctl(sc->kbd, cmd, data);
1079 if (error == ENOIOCTL)
1083 case KDSETRAD: /* set keyboard repeat & delay rates (old) */
1084 if (*(int *)data & ~0x7f)
1086 error = kbd_ioctl(sc->kbd, cmd, data);
1087 if (error == ENOIOCTL)
1091 case KDSKBMODE: /* set keyboard mode */
1092 switch (*(int *)data) {
1093 case K_XLATE: /* switch to XLT ascii mode */
1094 case K_RAW: /* switch to RAW scancode mode */
1095 case K_CODE: /* switch to CODE mode */
1096 scp->kbd_mode = *(int *)data;
1097 if (scp == sc->cur_scp)
1098 kbd_ioctl(sc->kbd, cmd, data);
1105 case KDGKBMODE: /* get keyboard mode */
1106 *(int *)data = scp->kbd_mode;
1110 error = kbd_ioctl(sc->kbd, cmd, data);
1111 if (error == ENOIOCTL)
1115 case KDMKTONE: /* sound the bell */
1117 sc_bell(scp, (*(int*)data)&0xffff,
1118 (((*(int*)data)>>16)&0xffff)*hz/1000);
1120 sc_bell(scp, scp->bell_pitch, scp->bell_duration);
1123 case KIOCSOUND: /* make tone (*data) hz */
1124 if (scp == sc->cur_scp) {
1126 return sc_tone(*(int *)data);
1132 case KDGKBTYPE: /* get keyboard type */
1133 error = kbd_ioctl(sc->kbd, cmd, data);
1134 if (error == ENOIOCTL) {
1135 /* always return something? XXX */
1140 case KDSETLED: /* set keyboard LED status */
1141 if (*(int *)data & ~LED_MASK) /* FIXME: LOCK_MASK? */
1143 scp->status &= ~LED_MASK;
1144 scp->status |= *(int *)data;
1145 if (scp == sc->cur_scp)
1146 update_kbd_leds(scp, scp->status);
1149 case KDGETLED: /* get keyboard LED status */
1150 if (scp == sc->cur_scp)
1151 save_kbd_state(scp);
1152 *(int *)data = scp->status & LED_MASK;
1155 case KBADDKBD: /* add/remove keyboard to/from mux */
1157 error = kbd_ioctl(sc->kbd, cmd, data);
1158 if (error == ENOIOCTL)
1162 case CONS_SETKBD: /* set the new keyboard */
1167 newkbd = kbd_get_keyboard(*(int *)data);
1168 if (newkbd == NULL) {
1173 if (sc->kbd != newkbd) {
1174 i = kbd_allocate(newkbd->kb_name, newkbd->kb_unit,
1175 (void *)&sc->keyboard, sckbdevent, sc);
1176 /* i == newkbd->kb_index */
1178 if (sc->kbd != NULL) {
1179 save_kbd_state(sc->cur_scp);
1180 kbd_release(sc->kbd, (void *)&sc->keyboard);
1182 sc->kbd = kbd_get_keyboard(i); /* sc->kbd == newkbd */
1184 kbd_ioctl(sc->kbd, KDSKBMODE,
1185 (caddr_t)&sc->cur_scp->kbd_mode);
1186 update_kbd_state(sc->cur_scp, sc->cur_scp->status,
1189 error = EPERM; /* XXX */
1196 case CONS_RELKBD: /* release the current keyboard */
1199 if (sc->kbd != NULL) {
1200 save_kbd_state(sc->cur_scp);
1201 error = kbd_release(sc->kbd, (void *)&sc->keyboard);
1210 case CONS_GETTERM: /* get the current terminal emulator info */
1214 if (((term_info_t *)data)->ti_index == 0) {
1217 sw = sc_term_match_by_number(((term_info_t *)data)->ti_index);
1220 strncpy(((term_info_t *)data)->ti_name, sw->te_name,
1221 sizeof(((term_info_t *)data)->ti_name));
1222 strncpy(((term_info_t *)data)->ti_desc, sw->te_desc,
1223 sizeof(((term_info_t *)data)->ti_desc));
1224 ((term_info_t *)data)->ti_flags = 0;
1227 ((term_info_t *)data)->ti_name[0] = '\0';
1228 ((term_info_t *)data)->ti_desc[0] = '\0';
1229 ((term_info_t *)data)->ti_flags = 0;
1234 case CONS_SETTERM: /* set the current terminal emulator */
1236 error = sc_init_emulator(scp, ((term_info_t *)data)->ti_name);
1237 /* FIXME: what if scp == sc_console! XXX */
1241 case GIO_SCRNMAP: /* get output translation table */
1242 bcopy(&sc->scr_map, data, sizeof(sc->scr_map));
1245 case PIO_SCRNMAP: /* set output translation table */
1246 bcopy(data, &sc->scr_map, sizeof(sc->scr_map));
1247 for (i=0; i<sizeof(sc->scr_map); i++) {
1248 sc->scr_rmap[sc->scr_map[i]] = i;
1252 case GIO_KEYMAP: /* get keyboard translation table */
1253 case PIO_KEYMAP: /* set keyboard translation table */
1254 case GIO_DEADKEYMAP: /* get accent key translation table */
1255 case PIO_DEADKEYMAP: /* set accent key translation table */
1256 case GETFKEY: /* get function key string */
1257 case SETFKEY: /* set function key string */
1258 error = kbd_ioctl(sc->kbd, cmd, data);
1259 if (error == ENOIOCTL)
1263 #ifndef SC_NO_FONT_LOADING
1265 case PIO_FONT8x8: /* set 8x8 dot font */
1266 if (!ISFONTAVAIL(sc->adp->va_flags))
1268 bcopy(data, sc->font_8, 8*256);
1269 sc->fonts_loaded |= FONT_8;
1272 * Always use the font page #0. XXX
1273 * Don't load if the current font size is not 8x8.
1275 if (ISTEXTSC(sc->cur_scp) && (sc->cur_scp->font_size < 14))
1276 sc_load_font(sc->cur_scp, 0, 8, sc->font_8, 0, 256);
1279 case GIO_FONT8x8: /* get 8x8 dot font */
1280 if (!ISFONTAVAIL(sc->adp->va_flags))
1282 if (sc->fonts_loaded & FONT_8) {
1283 bcopy(sc->font_8, data, 8*256);
1289 case PIO_FONT8x14: /* set 8x14 dot font */
1290 if (!ISFONTAVAIL(sc->adp->va_flags))
1292 bcopy(data, sc->font_14, 14*256);
1293 sc->fonts_loaded |= FONT_14;
1296 * Always use the font page #0. XXX
1297 * Don't load if the current font size is not 8x14.
1299 if (ISTEXTSC(sc->cur_scp)
1300 && (sc->cur_scp->font_size >= 14)
1301 && (sc->cur_scp->font_size < 16))
1302 sc_load_font(sc->cur_scp, 0, 14, sc->font_14, 0, 256);
1305 case GIO_FONT8x14: /* get 8x14 dot font */
1306 if (!ISFONTAVAIL(sc->adp->va_flags))
1308 if (sc->fonts_loaded & FONT_14) {
1309 bcopy(sc->font_14, data, 14*256);
1315 case PIO_FONT8x16: /* set 8x16 dot font */
1316 if (!ISFONTAVAIL(sc->adp->va_flags))
1318 bcopy(data, sc->font_16, 16*256);
1319 sc->fonts_loaded |= FONT_16;
1322 * Always use the font page #0. XXX
1323 * Don't load if the current font size is not 8x16.
1325 if (ISTEXTSC(sc->cur_scp) && (sc->cur_scp->font_size >= 16))
1326 sc_load_font(sc->cur_scp, 0, 16, sc->font_16, 0, 256);
1329 case GIO_FONT8x16: /* get 8x16 dot font */
1330 if (!ISFONTAVAIL(sc->adp->va_flags))
1332 if (sc->fonts_loaded & FONT_16) {
1333 bcopy(sc->font_16, data, 16*256);
1339 #endif /* SC_NO_FONT_LOADING */
1345 error = (*linesw[tp->t_line].l_ioctl)(tp, cmd, data, flag, ap->a_cred);
1346 if (error != ENOIOCTL)
1348 error = ttioctl(tp, cmd, data, flag);
1349 if (error != ENOIOCTL)
1355 scstart(struct tty *tp)
1359 u_char buf[PCBURST];
1360 scr_stat *scp = SC_STAT(tp->t_dev);
1363 if (scp->status & SLKED ||
1364 (scp == scp->sc->cur_scp && scp->sc->blink_in_progress))
1369 if (!(tp->t_state & (TS_TIMEOUT | TS_BUSY | TS_TTSTOP))) {
1370 tp->t_state |= TS_BUSY;
1373 len = q_to_b(rbp, buf, PCBURST);
1374 sc_puts(scp, buf, len);
1376 tp->t_state &= ~TS_BUSY;
1383 sccnprobe(struct consdev *cp)
1388 cp->cn_pri = sc_get_cons_priority(&unit, &flags);
1390 /* a video card is always required */
1391 if (!scvidprobe(unit, flags, TRUE))
1392 cp->cn_pri = CN_DEAD;
1394 /* syscons will become console even when there is no keyboard */
1395 sckbdprobe(unit, flags, TRUE);
1397 if (cp->cn_pri == CN_DEAD)
1400 /* initialize required fields */
1401 cp->cn_probegood = 1;
1405 sccninit(struct consdev *cp)
1410 sc_get_cons_priority(&unit, &flags);
1411 scinit(unit, flags | SC_KERNEL_CONSOLE);
1412 sc_console_unit = unit;
1413 sc_console = sc_get_softc(unit, SC_KERNEL_CONSOLE)->console_scp;
1417 sccninit_fini(struct consdev *cp)
1419 if (cctl_dev == NULL)
1420 kprintf("sccninit_fini: WARNING: cctl_dev is NULL!\n");
1421 cp->cn_dev = cctl_dev;
1425 sccnterm(struct consdev *cp)
1427 /* we are not the kernel console any more, release everything */
1429 if (sc_console_unit < 0)
1430 return; /* shouldn't happen */
1433 sc_clear_screen(sc_console);
1434 sccnupdate(sc_console);
1436 scterm(sc_console_unit, SC_KERNEL_CONSOLE);
1437 sc_console_unit = -1;
1442 sccnputc(void *private, int c)
1445 scr_stat *scp = sc_console;
1447 #ifndef SC_NO_HISTORY
1449 #endif /* !SC_NO_HISTORY */
1451 /* assert(sc_console != NULL) */
1454 #ifndef SC_NO_HISTORY
1455 if (scp == scp->sc->cur_scp && scp->status & SLKED) {
1456 scp->status &= ~SLKED;
1457 update_kbd_state(scp, scp->status, SLKED);
1458 if (scp->status & BUFFER_SAVED) {
1459 if (!sc_hist_restore(scp))
1460 sc_remove_cutmarking(scp);
1461 scp->status &= ~BUFFER_SAVED;
1462 scp->status |= CURSOR_ENABLED;
1463 sc_draw_cursor_image(scp);
1465 tp = VIRTUAL_TTY(scp->sc, scp->index);
1466 if (ISTTYOPEN(tp)) {
1472 #endif /* !SC_NO_HISTORY */
1475 if (kernel_console_ts != NULL)
1476 scp->ts = kernel_console_ts;
1478 sc_puts(scp, buf, 1);
1486 sccngetc(void *private)
1488 return sccngetch(0);
1492 sccncheckc(void *private)
1494 return sccngetch(SCGETC_NONBLOCK);
1498 sccndbctl(void *private, int on)
1500 /* assert(sc_console_unit >= 0) */
1501 /* try to switch to the kernel console screen */
1502 if (on && debugger == 0) {
1504 * TRY to make sure the screen saver is stopped,
1505 * and the screen is updated before switching to
1510 && sc_console->sc->cur_scp->smode.mode == VT_AUTO
1511 && sc_console->smode.mode == VT_AUTO) {
1512 sc_console->sc->cur_scp->status |= MOUSE_HIDDEN;
1513 sc_switch_scr(sc_console->sc, sc_console->index);
1523 sccngetch(int flags)
1525 static struct fkeytab fkey;
1533 /* assert(sc_console != NULL) */
1536 * Stop the screen saver and update the screen if necessary.
1537 * What if we have been running in the screen saver code... XXX
1539 sc_touch_scrn_saver();
1540 scp = sc_console->sc->cur_scp; /* XXX */
1544 if (fkeycp < fkey.len)
1545 return fkey.str[fkeycp++];
1547 if (scp->sc->kbd == NULL)
1551 * Make sure the keyboard is accessible even when the kbd device
1552 * driver is disabled.
1555 kbd_enable(scp->sc->kbd);
1557 /* we shall always use the keyboard in the XLATE mode here */
1558 cur_mode = scp->kbd_mode;
1559 scp->kbd_mode = K_XLATE;
1560 kbd_ioctl(scp->sc->kbd, KDSKBMODE, (caddr_t)&scp->kbd_mode);
1562 kbd_poll(scp->sc->kbd, TRUE);
1563 c = scgetc(scp->sc, SCGETC_CN | flags);
1564 kbd_poll(scp->sc->kbd, FALSE);
1566 scp->kbd_mode = cur_mode;
1567 kbd_ioctl(scp->sc->kbd, KDSKBMODE, (caddr_t)&scp->kbd_mode);
1568 kbd_disable(scp->sc->kbd);
1571 switch (KEYFLAGS(c)) {
1572 case 0: /* normal char */
1574 case FKEY: /* function key */
1575 p = kbd_get_fkeystr(scp->sc->kbd, KEYCHAR(c), (size_t *)&fkeycp);
1577 if ((p != NULL) && (fkey.len > 0)) {
1578 bcopy(p, fkey.str, fkey.len);
1592 sccnupdate(scr_stat *scp)
1594 /* this is a cut-down version of scrn_timer()... */
1596 if (scp->sc->font_loading_in_progress || scp->sc->videoio_in_progress)
1599 if (debugger > 0 || panicstr || shutdown_in_progress) {
1600 sc_touch_scrn_saver();
1601 } else if (scp != scp->sc->cur_scp) {
1605 if (!run_scrn_saver)
1606 scp->sc->flags &= ~SC_SCRN_IDLE;
1608 if ((saver_mode != CONS_LKM_SAVER) || !(scp->sc->flags & SC_SCRN_IDLE))
1609 if (scp->sc->flags & SC_SCRN_BLANKED)
1610 stop_scrn_saver(scp->sc, current_saver);
1611 #endif /* NSPLASH */
1613 if (scp != scp->sc->cur_scp || scp->sc->blink_in_progress
1614 || scp->sc->switch_in_progress)
1617 * FIXME: unlike scrn_timer(), we call scrn_update() from here even
1618 * when write_in_progress is non-zero. XXX
1621 if (!ISGRAPHSC(scp) && !(scp->sc->flags & SC_SCRN_BLANKED))
1622 scrn_update(scp, TRUE);
1626 scrn_timer(void *arg)
1628 static int kbd_interval = 0;
1634 again = (arg != NULL);
1636 sc = (sc_softc_t *)arg;
1637 else if (sc_console != NULL)
1638 sc = sc_console->sc;
1642 if (syscons_lock_nonblock() == 0) {
1644 callout_reset(&sc->scrn_timer_ch, hz / 10, scrn_timer, sc);
1649 /* don't do anything when we are performing some I/O operations */
1650 if (sc->font_loading_in_progress || sc->videoio_in_progress) {
1652 callout_reset(&sc->scrn_timer_ch, hz / 10, scrn_timer, sc);
1657 if ((sc->kbd == NULL) && (sc->config & SC_AUTODETECT_KBD)) {
1658 /* try to allocate a keyboard automatically */
1659 if (++kbd_interval >= 25) {
1660 sc->keyboard = sc_allocate_keyboard(sc, -1);
1661 if (sc->keyboard >= 0) {
1662 sc->kbd = kbd_get_keyboard(sc->keyboard);
1663 kbd_ioctl(sc->kbd, KDSKBMODE,
1664 (caddr_t)&sc->cur_scp->kbd_mode);
1665 update_kbd_state(sc->cur_scp, sc->cur_scp->status,
1672 /* should we stop the screen saver? */
1673 getmicrouptime(&tv);
1674 if (debugger > 0 || panicstr || shutdown_in_progress)
1675 sc_touch_scrn_saver();
1676 if (run_scrn_saver) {
1677 if (tv.tv_sec > sc->scrn_time_stamp + scrn_blank_time)
1678 sc->flags |= SC_SCRN_IDLE;
1680 sc->flags &= ~SC_SCRN_IDLE;
1682 sc->scrn_time_stamp = tv.tv_sec;
1683 sc->flags &= ~SC_SCRN_IDLE;
1684 if (scrn_blank_time > 0)
1685 run_scrn_saver = TRUE;
1688 if ((saver_mode != CONS_LKM_SAVER) || !(sc->flags & SC_SCRN_IDLE))
1689 if (sc->flags & SC_SCRN_BLANKED)
1690 stop_scrn_saver(sc, current_saver);
1691 #endif /* NSPLASH */
1693 /* should we just return ? */
1694 if (sc->blink_in_progress || sc->switch_in_progress
1695 || sc->write_in_progress) {
1697 callout_reset(&sc->scrn_timer_ch, hz / 10, scrn_timer, sc);
1702 /* Update the screen */
1703 scp = sc->cur_scp; /* cur_scp may have changed... */
1704 if (!ISGRAPHSC(scp) && !(sc->flags & SC_SCRN_BLANKED))
1705 scrn_update(scp, TRUE);
1708 /* should we activate the screen saver? */
1709 if ((saver_mode == CONS_LKM_SAVER) && (sc->flags & SC_SCRN_IDLE))
1710 if (!ISGRAPHSC(scp) || (sc->flags & SC_SCRN_BLANKED))
1711 (*current_saver)(sc, TRUE);
1712 #endif /* NSPLASH */
1715 callout_reset(&sc->scrn_timer_ch, hz / 25, scrn_timer, sc);
1720 and_region(int *s1, int *e1, int s2, int e2)
1722 if (*e1 < s2 || e2 < *s1)
1724 *s1 = imax(*s1, s2);
1725 *e1 = imin(*e1, e2);
1730 scrn_update(scr_stat *scp, int show_cursor)
1737 /* assert(scp == scp->sc->cur_scp) */
1739 ++scp->sc->videoio_in_progress;
1741 #ifndef SC_NO_CUTPASTE
1742 /* remove the previous mouse pointer image if necessary */
1743 if (scp->status & MOUSE_VISIBLE) {
1745 e = scp->mouse_pos + scp->xsize + 1;
1746 if ((scp->status & (MOUSE_MOVED | MOUSE_HIDDEN))
1747 || and_region(&s, &e, scp->start, scp->end)
1748 || ((scp->status & CURSOR_ENABLED) &&
1749 (scp->cursor_pos != scp->cursor_oldpos) &&
1750 (and_region(&s, &e, scp->cursor_pos, scp->cursor_pos)
1751 || and_region(&s, &e, scp->cursor_oldpos, scp->cursor_oldpos)))) {
1752 sc_remove_mouse_image(scp);
1753 if (scp->end >= scp->xsize*scp->ysize)
1754 scp->end = scp->xsize*scp->ysize - 1;
1757 #endif /* !SC_NO_CUTPASTE */
1761 if (scp->end >= scp->xsize*scp->ysize) {
1762 kprintf("scrn_update(): scp->end %d > size_of_screen!!\n", scp->end);
1763 scp->end = scp->xsize*scp->ysize - 1;
1765 if (scp->start < 0) {
1766 kprintf("scrn_update(): scp->start %d < 0\n", scp->start);
1771 /* update screen image */
1772 if (scp->start <= scp->end) {
1773 if (scp->mouse_cut_end >= 0) {
1774 /* there is a marked region for cut & paste */
1775 if (scp->mouse_cut_start <= scp->mouse_cut_end) {
1776 start = scp->mouse_cut_start;
1777 end = scp->mouse_cut_end;
1779 start = scp->mouse_cut_end;
1780 end = scp->mouse_cut_start - 1;
1784 /* does the cut-mark region overlap with the update region? */
1785 if (and_region(&s, &e, scp->start, scp->end)) {
1786 (*scp->rndr->draw)(scp, s, e - s + 1, TRUE);
1789 if (and_region(&s, &e, scp->start, scp->end))
1790 (*scp->rndr->draw)(scp, s, e - s + 1, FALSE);
1792 e = scp->xsize*scp->ysize - 1;
1793 if (and_region(&s, &e, scp->start, scp->end))
1794 (*scp->rndr->draw)(scp, s, e - s + 1, FALSE);
1796 (*scp->rndr->draw)(scp, scp->start,
1797 scp->end - scp->start + 1, FALSE);
1800 (*scp->rndr->draw)(scp, scp->start,
1801 scp->end - scp->start + 1, FALSE);
1805 /* we are not to show the cursor and the mouse pointer... */
1808 scp->start = scp->xsize*scp->ysize - 1;
1809 --scp->sc->videoio_in_progress;
1813 /* update cursor image */
1814 if (scp->status & CURSOR_ENABLED) {
1817 /* did cursor move since last time ? */
1818 if (scp->cursor_pos != scp->cursor_oldpos) {
1819 /* do we need to remove old cursor image ? */
1820 if (!and_region(&s, &e, scp->cursor_oldpos, scp->cursor_oldpos))
1821 sc_remove_cursor_image(scp);
1822 sc_draw_cursor_image(scp);
1824 if (and_region(&s, &e, scp->cursor_pos, scp->cursor_pos))
1825 /* cursor didn't move, but has been overwritten */
1826 sc_draw_cursor_image(scp);
1827 else if (scp->sc->flags & SC_BLINK_CURSOR)
1828 /* if it's a blinking cursor, update it */
1829 (*scp->rndr->blink_cursor)(scp, scp->cursor_pos,
1830 sc_inside_cutmark(scp,
1835 #ifndef SC_NO_CUTPASTE
1836 /* update "pseudo" mouse pointer image */
1837 if (scp->sc->flags & SC_MOUSE_ENABLED) {
1838 if (!(scp->status & (MOUSE_VISIBLE | MOUSE_HIDDEN))) {
1839 scp->status &= ~MOUSE_MOVED;
1840 sc_draw_mouse_image(scp);
1843 #endif /* SC_NO_CUTPASTE */
1846 scp->start = scp->xsize*scp->ysize - 1;
1848 --scp->sc->videoio_in_progress;
1853 scsplash_callback(int event, void *arg)
1858 sc = (sc_softc_t *)arg;
1862 if (add_scrn_saver(scsplash_saver) == 0) {
1863 sc->flags &= ~SC_SAVER_FAILED;
1864 run_scrn_saver = TRUE;
1865 if (cold && !(boothowto & (RB_VERBOSE | RB_CONFIG))) {
1866 scsplash_stick(TRUE);
1867 (*current_saver)(sc, TRUE);
1873 if (current_saver == scsplash_saver) {
1874 scsplash_stick(FALSE);
1875 error = remove_scrn_saver(scsplash_saver);
1887 scsplash_saver(sc_softc_t *sc, int show)
1889 static int busy = FALSE;
1898 if (!(sc->flags & SC_SAVER_FAILED)) {
1899 if (!(sc->flags & SC_SCRN_BLANKED))
1900 set_scrn_saver_mode(scp, -1, NULL, 0);
1901 switch (splash(sc->adp, TRUE)) {
1902 case 0: /* succeeded */
1904 case EAGAIN: /* try later */
1905 restore_scrn_saver_mode(scp, FALSE);
1906 sc_touch_scrn_saver(); /* XXX */
1909 sc->flags |= SC_SAVER_FAILED;
1910 scsplash_stick(FALSE);
1911 restore_scrn_saver_mode(scp, TRUE);
1912 kprintf("scsplash_saver(): failed to put up the image\n");
1916 } else if (!sticky_splash) {
1917 if ((sc->flags & SC_SCRN_BLANKED) && (splash(sc->adp, FALSE) == 0))
1918 restore_scrn_saver_mode(scp, TRUE);
1924 add_scrn_saver(void (*this_saver)(sc_softc_t *, int))
1929 if (current_saver != none_saver) {
1930 error = remove_scrn_saver(current_saver);
1935 if (current_saver != none_saver)
1938 run_scrn_saver = FALSE;
1939 saver_mode = CONS_LKM_SAVER;
1940 current_saver = this_saver;
1945 remove_scrn_saver(void (*this_saver)(sc_softc_t *, int))
1947 if (current_saver != this_saver)
1952 * In order to prevent `current_saver' from being called by
1953 * the timeout routine `scrn_timer()' while we manipulate
1954 * the saver list, we shall set `current_saver' to `none_saver'
1955 * before stopping the current saver, rather than blocking by `splXX()'.
1957 current_saver = none_saver;
1959 stop_scrn_saver(this_saver);
1962 /* unblank all blanked screens */
1963 wait_scrn_saver_stop(NULL);
1967 current_saver = none_saver;
1972 set_scrn_saver_mode(scr_stat *scp, int mode, u_char *pal, int border)
1975 /* assert(scp == scp->sc->cur_scp) */
1977 if (!ISGRAPHSC(scp))
1978 sc_remove_cursor_image(scp);
1979 scp->splash_save_mode = scp->mode;
1980 scp->splash_save_status = scp->status & (GRAPHICS_MODE | PIXEL_MODE);
1981 scp->status &= ~(GRAPHICS_MODE | PIXEL_MODE);
1982 scp->status |= (UNKNOWN_MODE | SAVER_RUNNING);
1983 scp->sc->flags |= SC_SCRN_BLANKED;
1989 if (set_mode(scp) == 0) {
1990 if (scp->sc->adp->va_info.vi_flags & V_INFO_GRAPHICS)
1991 scp->status |= GRAPHICS_MODE;
1992 #ifndef SC_NO_PALETTE_LOADING
1994 load_palette(scp->sc->adp, pal);
1996 sc_set_border(scp, border);
2000 scp->mode = scp->splash_save_mode;
2001 scp->status &= ~(UNKNOWN_MODE | SAVER_RUNNING);
2002 scp->status |= scp->splash_save_status;
2009 restore_scrn_saver_mode(scr_stat *scp, int changemode)
2014 /* assert(scp == scp->sc->cur_scp) */
2017 status = scp->status;
2018 scp->mode = scp->splash_save_mode;
2019 scp->status &= ~(UNKNOWN_MODE | SAVER_RUNNING);
2020 scp->status |= scp->splash_save_status;
2021 scp->sc->flags &= ~SC_SCRN_BLANKED;
2023 if (!ISGRAPHSC(scp))
2024 sc_draw_cursor_image(scp);
2029 if (set_mode(scp) == 0) {
2030 #ifndef SC_NO_PALETTE_LOADING
2031 load_palette(scp->sc->adp, scp->sc->palette);
2038 scp->status = status;
2045 stop_scrn_saver(sc_softc_t *sc, void (*saver)(sc_softc_t *, int))
2047 (*saver)(sc, FALSE);
2048 run_scrn_saver = FALSE;
2049 /* the screen saver may have chosen not to stop after all... */
2050 if (sc->flags & SC_SCRN_BLANKED)
2053 mark_all(sc->cur_scp);
2054 if (sc->delayed_next_scr)
2055 sc_switch_scr(sc, sc->delayed_next_scr - 1);
2056 wakeup((caddr_t)&scrn_blanked);
2060 wait_scrn_saver_stop(sc_softc_t *sc)
2064 while (scrn_blanked > 0) {
2065 run_scrn_saver = FALSE;
2066 if (sc && !(sc->flags & SC_SCRN_BLANKED)) {
2070 error = tsleep((caddr_t)&scrn_blanked, PCATCH, "scrsav", 0);
2071 /* May return ERESTART */
2075 run_scrn_saver = FALSE;
2078 #endif /* NSPLASH */
2081 sc_touch_scrn_saver(void)
2083 scsplash_stick(FALSE);
2084 run_scrn_saver = FALSE;
2088 sc_switch_scr(sc_softc_t *sc, u_int next_scr)
2093 DPRINTF(5, ("sc0: sc_switch_scr() %d ", next_scr + 1));
2095 /* prevent switch if previously requested */
2096 if (sc->flags & SC_SCRN_VTYLOCK) {
2097 sc_bell(sc->cur_scp, sc->cur_scp->bell_pitch,
2098 sc->cur_scp->bell_duration);
2102 /* delay switch if the screen is blanked or being updated */
2103 if ((sc->flags & SC_SCRN_BLANKED) || sc->write_in_progress
2104 || sc->blink_in_progress || sc->videoio_in_progress) {
2105 sc->delayed_next_scr = next_scr + 1;
2106 sc_touch_scrn_saver();
2107 DPRINTF(5, ("switch delayed\n"));
2112 cur_scp = sc->cur_scp;
2114 /* we are in the middle of the vty switching process... */
2115 if (sc->switch_in_progress
2116 && (cur_scp->smode.mode == VT_PROCESS)
2118 if (cur_scp->proc != pfind(cur_scp->pid)) {
2120 * The controlling process has died!!. Do some clean up.
2121 * NOTE:`cur_scp->proc' and `cur_scp->smode.mode'
2122 * are not reset here yet; they will be cleared later.
2124 DPRINTF(5, ("cur_scp controlling process %d died, ",
2126 if (cur_scp->status & SWITCH_WAIT_REL) {
2128 * Force the previous switch to finish, but return now
2131 * note: must be called from a critical section because
2132 * finish_vt_rel will call do_switch_scr which releases it
2135 DPRINTF(5, ("reset WAIT_REL, "));
2136 finish_vt_rel(cur_scp, TRUE);
2138 DPRINTF(5, ("finishing previous switch\n"));
2140 } else if (cur_scp->status & SWITCH_WAIT_ACQ) {
2141 /* let's assume screen switch has been completed. */
2142 DPRINTF(5, ("reset WAIT_ACQ, "));
2143 finish_vt_acq(cur_scp);
2146 * We are in between screen release and acquisition, and
2147 * reached here via scgetc() or scrn_timer() which has
2148 * interrupted exchange_scr(). Don't do anything stupid.
2150 DPRINTF(5, ("waiting nothing, "));
2154 * The controlling process is alive, but not responding...
2155 * It is either buggy or it may be just taking time.
2156 * The following code is a gross kludge to cope with this
2157 * problem for which there is no clean solution. XXX
2159 if (cur_scp->status & SWITCH_WAIT_REL) {
2160 switch (sc->switch_in_progress++) {
2164 DPRINTF(5, ("sending relsig again, "));
2165 signal_vt_rel(cur_scp);
2172 * Act as if the controlling program returned
2175 * note: must be called from a critical section because
2176 * finish_vt_rel will call do_switch_scr which releases it
2179 DPRINTF(5, ("force reset WAIT_REL, "));
2180 finish_vt_rel(cur_scp, FALSE);
2182 DPRINTF(5, ("act as if VT_FALSE was seen\n"));
2185 } else if (cur_scp->status & SWITCH_WAIT_ACQ) {
2186 switch (sc->switch_in_progress++) {
2190 DPRINTF(5, ("sending acqsig again, "));
2191 signal_vt_acq(cur_scp);
2197 /* clear the flag and finish the previous switch */
2198 DPRINTF(5, ("force reset WAIT_ACQ, "));
2199 finish_vt_acq(cur_scp);
2207 * Return error if an invalid argument is given, or vty switch
2208 * is still in progress.
2210 if ((next_scr < sc->first_vty) || (next_scr >= sc->first_vty + sc->vtys)
2211 || sc->switch_in_progress) {
2213 sc_bell(cur_scp, bios_value.bell_pitch, BELL_DURATION);
2214 DPRINTF(5, ("error 1\n"));
2219 * Don't allow switching away from the graphics mode vty
2220 * if the switch mode is VT_AUTO, unless the next vty is the same
2221 * as the current or the current vty has been closed (but showing).
2223 tp = VIRTUAL_TTY(sc, cur_scp->index);
2224 if ((cur_scp->index != next_scr)
2226 && (cur_scp->smode.mode == VT_AUTO)
2227 && ISGRAPHSC(cur_scp)) {
2229 sc_bell(cur_scp, bios_value.bell_pitch, BELL_DURATION);
2230 DPRINTF(5, ("error, graphics mode\n"));
2235 * Is the wanted vty open? Don't allow switching to a closed vty.
2236 * If we are in DDB, don't switch to a vty in the VT_PROCESS mode.
2237 * Note that we always allow the user to switch to the kernel
2238 * console even if it is closed.
2240 if ((sc_console == NULL) || (next_scr != sc_console->index)) {
2241 tp = VIRTUAL_TTY(sc, next_scr);
2242 if (!ISTTYOPEN(tp)) {
2244 sc_bell(cur_scp, bios_value.bell_pitch, BELL_DURATION);
2245 DPRINTF(5, ("error 2, requested vty isn't open!\n"));
2248 if ((debugger > 0) && (SC_STAT(tp->t_dev)->smode.mode == VT_PROCESS)) {
2250 DPRINTF(5, ("error 3, requested vty is in the VT_PROCESS mode\n"));
2255 /* this is the start of vty switching process... */
2256 ++sc->switch_in_progress;
2257 sc->delayed_next_scr = 0;
2258 sc->old_scp = cur_scp;
2259 sc->new_scp = SC_STAT(SC_DEV(sc, next_scr));
2260 if (sc->new_scp == sc->old_scp) {
2261 sc->switch_in_progress = 0;
2262 wakeup((caddr_t)&sc->new_scp->smode);
2264 DPRINTF(5, ("switch done (new == old)\n"));
2268 /* has controlling process died? */
2269 vt_proc_alive(sc->old_scp);
2270 vt_proc_alive(sc->new_scp);
2272 /* wait for the controlling process to release the screen, if necessary */
2273 if (signal_vt_rel(sc->old_scp)) {
2278 /* go set up the new vty screen */
2283 /* wake up processes waiting for this vty */
2284 wakeup((caddr_t)&sc->cur_scp->smode);
2286 /* wait for the controlling process to acknowledge, if necessary */
2287 if (signal_vt_acq(sc->cur_scp)) {
2292 sc->switch_in_progress = 0;
2293 if (sc->unit == sc_console_unit)
2294 cons_unavail = FALSE;
2296 DPRINTF(5, ("switch done\n"));
2302 * NOTE: must be called from a critical section because do_switch_scr
2303 * will release it temporarily.
2306 do_switch_scr(sc_softc_t *sc)
2308 vt_proc_alive(sc->new_scp);
2313 /* sc->cur_scp == sc->new_scp */
2314 wakeup((caddr_t)&sc->cur_scp->smode);
2316 /* wait for the controlling process to acknowledge, if necessary */
2317 if (!signal_vt_acq(sc->cur_scp)) {
2318 sc->switch_in_progress = 0;
2319 if (sc->unit == sc_console_unit)
2320 cons_unavail = FALSE;
2325 vt_proc_alive(scr_stat *scp)
2328 if (scp->proc == pfind(scp->pid))
2331 scp->smode.mode = VT_AUTO;
2332 DPRINTF(5, ("vt controlling process %d died\n", scp->pid));
2338 signal_vt_rel(scr_stat *scp)
2340 if (scp->smode.mode != VT_PROCESS)
2342 scp->status |= SWITCH_WAIT_REL;
2343 ksignal(scp->proc, scp->smode.relsig);
2344 DPRINTF(5, ("sending relsig to %d\n", scp->pid));
2349 signal_vt_acq(scr_stat *scp)
2351 if (scp->smode.mode != VT_PROCESS)
2353 if (scp->sc->unit == sc_console_unit)
2354 cons_unavail = TRUE;
2355 scp->status |= SWITCH_WAIT_ACQ;
2356 ksignal(scp->proc, scp->smode.acqsig);
2357 DPRINTF(5, ("sending acqsig to %d\n", scp->pid));
2362 * NOTE: must be called from a critical section because do_switch_scr
2363 * will release it temporarily.
2366 finish_vt_rel(scr_stat *scp, int release)
2368 if (scp == scp->sc->old_scp && scp->status & SWITCH_WAIT_REL) {
2369 scp->status &= ~SWITCH_WAIT_REL;
2371 do_switch_scr(scp->sc);
2373 scp->sc->switch_in_progress = 0;
2380 finish_vt_acq(scr_stat *scp)
2382 if (scp == scp->sc->new_scp && scp->status & SWITCH_WAIT_ACQ) {
2383 scp->status &= ~SWITCH_WAIT_ACQ;
2384 scp->sc->switch_in_progress = 0;
2391 exchange_scr(sc_softc_t *sc)
2395 /* save the current state of video and keyboard */
2396 sc_move_cursor(sc->old_scp, sc->old_scp->xpos, sc->old_scp->ypos);
2397 if (!ISGRAPHSC(sc->old_scp))
2398 sc_remove_cursor_image(sc->old_scp);
2399 if (sc->old_scp->kbd_mode == K_XLATE)
2400 save_kbd_state(sc->old_scp);
2402 /* set up the video for the new screen */
2403 scp = sc->cur_scp = sc->new_scp;
2404 if (sc->old_scp->mode != scp->mode || ISUNKNOWNSC(sc->old_scp))
2407 sc_vtb_init(&scp->scr, VTB_FRAMEBUFFER, scp->xsize, scp->ysize,
2408 (void *)sc->adp->va_window, FALSE);
2409 scp->status |= MOUSE_HIDDEN;
2410 sc_move_cursor(scp, scp->xpos, scp->ypos);
2411 if (!ISGRAPHSC(scp))
2412 sc_set_cursor_image(scp);
2413 #ifndef SC_NO_PALETTE_LOADING
2414 if (ISGRAPHSC(sc->old_scp))
2415 load_palette(sc->adp, sc->palette);
2417 sc_set_border(scp, scp->border);
2419 /* set up the keyboard for the new screen */
2420 if (sc->old_scp->kbd_mode != scp->kbd_mode)
2421 kbd_ioctl(sc->kbd, KDSKBMODE, (caddr_t)&scp->kbd_mode);
2422 update_kbd_state(scp, scp->status, LOCK_MASK);
2428 sc_puts(scr_stat *scp, u_char *buf, int len)
2431 /* make screensaver happy */
2432 if (!sticky_splash && scp == scp->sc->cur_scp)
2433 run_scrn_saver = FALSE;
2437 (*scp->tsw->te_puts)(scp, buf, len);
2439 if (scp->sc->delayed_next_scr)
2440 sc_switch_scr(scp->sc, scp->sc->delayed_next_scr - 1);
2444 sc_draw_cursor_image(scr_stat *scp)
2446 /* assert(scp == scp->sc->cur_scp); */
2447 ++scp->sc->videoio_in_progress;
2448 (*scp->rndr->draw_cursor)(scp, scp->cursor_pos,
2449 scp->sc->flags & SC_BLINK_CURSOR, TRUE,
2450 sc_inside_cutmark(scp, scp->cursor_pos));
2451 scp->cursor_oldpos = scp->cursor_pos;
2452 --scp->sc->videoio_in_progress;
2456 sc_remove_cursor_image(scr_stat *scp)
2458 /* assert(scp == scp->sc->cur_scp); */
2459 ++scp->sc->videoio_in_progress;
2460 (*scp->rndr->draw_cursor)(scp, scp->cursor_oldpos,
2461 scp->sc->flags & SC_BLINK_CURSOR, FALSE,
2462 sc_inside_cutmark(scp, scp->cursor_oldpos));
2463 --scp->sc->videoio_in_progress;
2467 update_cursor_image(scr_stat *scp)
2471 if (scp->sc->flags & SC_CHAR_CURSOR) {
2472 scp->cursor_base = imax(0, scp->sc->cursor_base);
2473 scp->cursor_height = imin(scp->sc->cursor_height, scp->font_size);
2475 scp->cursor_base = 0;
2476 scp->cursor_height = scp->font_size;
2478 blink = scp->sc->flags & SC_BLINK_CURSOR;
2480 /* assert(scp == scp->sc->cur_scp); */
2481 ++scp->sc->videoio_in_progress;
2482 (*scp->rndr->draw_cursor)(scp, scp->cursor_oldpos, blink, FALSE,
2483 sc_inside_cutmark(scp, scp->cursor_pos));
2484 (*scp->rndr->set_cursor)(scp, scp->cursor_base, scp->cursor_height, blink);
2485 (*scp->rndr->draw_cursor)(scp, scp->cursor_pos, blink, TRUE,
2486 sc_inside_cutmark(scp, scp->cursor_pos));
2487 --scp->sc->videoio_in_progress;
2491 sc_set_cursor_image(scr_stat *scp)
2493 if (scp->sc->flags & SC_CHAR_CURSOR) {
2494 scp->cursor_base = imax(0, scp->sc->cursor_base);
2495 scp->cursor_height = imin(scp->sc->cursor_height, scp->font_size);
2497 scp->cursor_base = 0;
2498 scp->cursor_height = scp->font_size;
2501 /* assert(scp == scp->sc->cur_scp); */
2502 ++scp->sc->videoio_in_progress;
2503 (*scp->rndr->set_cursor)(scp, scp->cursor_base, scp->cursor_height,
2504 scp->sc->flags & SC_BLINK_CURSOR);
2505 --scp->sc->videoio_in_progress;
2509 scinit(int unit, int flags)
2512 * When syscons is being initialized as the kernel console, malloc()
2513 * is not yet functional, because various kernel structures has not been
2514 * fully initialized yet. Therefore, we need to declare the following
2515 * static buffers for the console. This is less than ideal,
2516 * but is necessry evil for the time being. XXX
2518 static scr_stat main_console;
2519 static u_short sc_buffer[ROW*COL]; /* XXX */
2520 #ifndef SC_NO_FONT_LOADING
2521 static u_char font_8[256*8];
2522 static u_char font_14[256*14];
2523 static u_char font_16[256*16];
2528 video_adapter_t *adp;
2533 /* one time initialization */
2534 if (init_done == COLD)
2535 sc_get_bios_values(&bios_value);
2539 * Allocate resources. Even if we are being called for the second
2540 * time, we must allocate them again, because they might have
2543 sc = sc_get_softc(unit, flags & SC_KERNEL_CONSOLE);
2545 if (sc->adapter >= 0) {
2546 vid_release(sc->adp, (void *)&sc->adapter);
2550 if (sc->keyboard >= 0) {
2551 DPRINTF(5, ("sc%d: releasing kbd%d\n", unit, sc->keyboard));
2552 i = kbd_release(sc->kbd, (void *)&sc->keyboard);
2553 DPRINTF(5, ("sc%d: kbd_release returned %d\n", unit, i));
2554 if (sc->kbd != NULL) {
2555 DPRINTF(5, ("sc%d: kbd != NULL!, index:%d, unit:%d, flags:0x%x\n",
2556 unit, sc->kbd->kb_index, sc->kbd->kb_unit, sc->kbd->kb_flags));
2560 sc->adapter = vid_allocate("*", unit, (void *)&sc->adapter);
2561 sc->adp = vid_get_adapter(sc->adapter);
2562 /* assert((sc->adapter >= 0) && (sc->adp != NULL)) */
2563 sc->keyboard = sc_allocate_keyboard(sc, unit);
2564 DPRINTF(1, ("sc%d: keyboard %d\n", unit, sc->keyboard));
2565 sc->kbd = kbd_get_keyboard(sc->keyboard);
2566 if (sc->kbd != NULL) {
2567 DPRINTF(1, ("sc%d: kbd index:%d, unit:%d, flags:0x%x\n",
2568 unit, sc->kbd->kb_index, sc->kbd->kb_unit, sc->kbd->kb_flags));
2571 if (!(sc->flags & SC_INIT_DONE) || (adp != sc->adp)) {
2573 sc->initial_mode = sc->adp->va_initial_mode;
2575 #ifndef SC_NO_FONT_LOADING
2576 if (flags & SC_KERNEL_CONSOLE) {
2577 sc->font_8 = font_8;
2578 sc->font_14 = font_14;
2579 sc->font_16 = font_16;
2580 } else if (sc->font_8 == NULL) {
2581 /* assert(sc_malloc) */
2582 sc->font_8 = kmalloc(sizeof(font_8), M_SYSCONS, M_WAITOK);
2583 sc->font_14 = kmalloc(sizeof(font_14), M_SYSCONS, M_WAITOK);
2584 sc->font_16 = kmalloc(sizeof(font_16), M_SYSCONS, M_WAITOK);
2588 /* extract the hardware cursor location and hide the cursor for now */
2589 (*vidsw[sc->adapter]->read_hw_cursor)(sc->adp, &col, &row);
2590 (*vidsw[sc->adapter]->set_hw_cursor)(sc->adp, -1, -1);
2592 /* set up the first console */
2593 sc->first_vty = unit*MAXCONS;
2594 sc->vtys = MAXCONS; /* XXX: should be configurable */
2595 if (flags & SC_KERNEL_CONSOLE) {
2596 scp = &main_console;
2597 sc->console_scp = scp;
2598 init_scp(sc, sc->first_vty, scp);
2599 sc_vtb_init(&scp->vtb, VTB_MEMORY, scp->xsize, scp->ysize,
2600 (void *)sc_buffer, FALSE);
2601 if (sc_init_emulator(scp, SC_DFLT_TERM))
2602 sc_init_emulator(scp, "*");
2603 (*scp->tsw->te_default_attr)(scp,
2604 kernel_default.std_color,
2605 kernel_default.rev_color);
2607 /* assert(sc_malloc) */
2608 sc->dev = kmalloc(sizeof(cdev_t)*sc->vtys, M_SYSCONS, M_WAITOK | M_ZERO);
2610 sc->dev[0] = make_dev(&sc_ops, unit*MAXCONS, UID_ROOT,
2611 GID_WHEEL, 0600, "ttyv%r", unit*MAXCONS);
2613 sc->dev[0]->si_tty = ttymalloc(sc->dev[0]->si_tty);
2614 scp = alloc_scp(sc, sc->first_vty);
2615 sc->dev[0]->si_drv1 = scp;
2619 /* copy screen to temporary buffer */
2620 sc_vtb_init(&scp->scr, VTB_FRAMEBUFFER, scp->xsize, scp->ysize,
2621 (void *)scp->sc->adp->va_window, FALSE);
2623 sc_vtb_copy(&scp->scr, 0, &scp->vtb, 0, scp->xsize*scp->ysize);
2625 /* move cursors to the initial positions */
2626 if (col >= scp->xsize)
2628 if (row >= scp->ysize)
2629 row = scp->ysize - 1;
2632 scp->cursor_pos = scp->cursor_oldpos = row*scp->xsize + col;
2633 if (bios_value.cursor_end < scp->font_size)
2634 sc->cursor_base = scp->font_size - bios_value.cursor_end - 1;
2636 sc->cursor_base = 0;
2637 i = bios_value.cursor_end - bios_value.cursor_start + 1;
2638 sc->cursor_height = imin(i, scp->font_size);
2639 #ifndef SC_NO_SYSMOUSE
2640 sc_mouse_move(scp, scp->xpixel/2, scp->ypixel/2);
2642 if (!ISGRAPHSC(scp)) {
2643 sc_set_cursor_image(scp);
2644 sc_draw_cursor_image(scp);
2647 /* save font and palette */
2648 #ifndef SC_NO_FONT_LOADING
2649 sc->fonts_loaded = 0;
2650 if (ISFONTAVAIL(sc->adp->va_flags)) {
2652 bcopy(dflt_font_8, sc->font_8, sizeof(dflt_font_8));
2653 bcopy(dflt_font_14, sc->font_14, sizeof(dflt_font_14));
2654 bcopy(dflt_font_16, sc->font_16, sizeof(dflt_font_16));
2655 sc->fonts_loaded = FONT_16 | FONT_14 | FONT_8;
2656 if (scp->font_size < 14) {
2657 sc_load_font(scp, 0, 8, sc->font_8, 0, 256);
2658 } else if (scp->font_size >= 16) {
2659 sc_load_font(scp, 0, 16, sc->font_16, 0, 256);
2661 sc_load_font(scp, 0, 14, sc->font_14, 0, 256);
2663 #else /* !SC_DFLT_FONT */
2664 if (scp->font_size < 14) {
2665 sc_save_font(scp, 0, 8, sc->font_8, 0, 256);
2666 sc->fonts_loaded = FONT_8;
2667 } else if (scp->font_size >= 16) {
2668 sc_save_font(scp, 0, 16, sc->font_16, 0, 256);
2669 sc->fonts_loaded = FONT_16;
2671 sc_save_font(scp, 0, 14, sc->font_14, 0, 256);
2672 sc->fonts_loaded = FONT_14;
2674 #endif /* SC_DFLT_FONT */
2675 /* FONT KLUDGE: always use the font page #0. XXX */
2676 sc_show_font(scp, 0);
2678 #endif /* !SC_NO_FONT_LOADING */
2680 #ifndef SC_NO_PALETTE_LOADING
2681 save_palette(sc->adp, sc->palette);
2685 if (!(sc->flags & SC_SPLASH_SCRN) && (flags & SC_KERNEL_CONSOLE)) {
2686 /* we are ready to put up the splash image! */
2687 splash_init(sc->adp, scsplash_callback, sc);
2688 sc->flags |= SC_SPLASH_SCRN;
2690 #endif /* NSPLASH */
2693 /* the rest is not necessary, if we have done it once */
2694 if (sc->flags & SC_INIT_DONE)
2697 /* initialize mapscrn arrays to a one to one map */
2698 for (i = 0; i < sizeof(sc->scr_map); i++)
2699 sc->scr_map[i] = sc->scr_rmap[i] = i;
2701 sc->flags |= SC_INIT_DONE;
2705 scterm(int unit, int flags)
2710 sc = sc_get_softc(unit, flags & SC_KERNEL_CONSOLE);
2712 return; /* shouldn't happen */
2715 /* this console is no longer available for the splash screen */
2716 if (sc->flags & SC_SPLASH_SCRN) {
2717 splash_term(sc->adp);
2718 sc->flags &= ~SC_SPLASH_SCRN;
2720 #endif /* NSPLASH */
2723 /* move the hardware cursor to the upper-left corner */
2724 (*vidsw[sc->adapter]->set_hw_cursor)(sc->adp, 0, 0);
2727 /* release the keyboard and the video card */
2728 if (sc->keyboard >= 0)
2729 kbd_release(sc->kbd, &sc->keyboard);
2730 if (sc->adapter >= 0)
2731 vid_release(sc->adp, &sc->adapter);
2734 * Stop the terminal emulator, if any. If operating on the
2735 * kernel console sc->dev may not be setup yet.
2737 if (flags & SC_KERNEL_CONSOLE)
2738 scp = sc->console_scp;
2740 scp = SC_STAT(sc->dev[0]);
2742 (*scp->tsw->te_term)(scp, &scp->ts);
2743 if (scp->ts != NULL)
2744 kfree(scp->ts, M_SYSCONS);
2746 /* clear the structure */
2747 if (!(flags & SC_KERNEL_CONSOLE)) {
2748 /* XXX: We need delete_dev() for this */
2749 kfree(sc->dev, M_SYSCONS);
2751 /* XXX: We need a ttyunregister for this */
2752 kfree(sc->tty, M_SYSCONS);
2754 #ifndef SC_NO_FONT_LOADING
2755 kfree(sc->font_8, M_SYSCONS);
2756 kfree(sc->font_14, M_SYSCONS);
2757 kfree(sc->font_16, M_SYSCONS);
2759 /* XXX vtb, history */
2761 bzero(sc, sizeof(*sc));
2767 scshutdown(void *arg, int howto)
2769 /* assert(sc_console != NULL) */
2771 sc_touch_scrn_saver();
2772 if (!cold && sc_console
2773 && sc_console->sc->cur_scp->smode.mode == VT_AUTO
2774 && sc_console->smode.mode == VT_AUTO)
2775 sc_switch_scr(sc_console->sc, sc_console->index);
2776 shutdown_in_progress = TRUE;
2780 sc_clean_up(scr_stat *scp)
2784 #endif /* NSPLASH */
2786 if (scp->sc->flags & SC_SCRN_BLANKED) {
2787 sc_touch_scrn_saver();
2789 if ((error = wait_scrn_saver_stop(scp->sc)))
2791 #endif /* NSPLASH */
2793 scp->status |= MOUSE_HIDDEN;
2794 sc_remove_mouse_image(scp);
2795 sc_remove_cutmarking(scp);
2800 sc_alloc_scr_buffer(scr_stat *scp, int wait, int discard)
2806 sc_vtb_init(&new, VTB_MEMORY, scp->xsize, scp->ysize, NULL, wait);
2807 if (!discard && (old.vtb_flags & VTB_VALID)) {
2808 /* retain the current cursor position and buffer contants */
2809 scp->cursor_oldpos = scp->cursor_pos;
2811 * This works only if the old buffer has the same size as or larger
2812 * than the new one. XXX
2814 sc_vtb_copy(&old, 0, &new, 0, scp->xsize*scp->ysize);
2818 sc_vtb_destroy(&old);
2821 #ifndef SC_NO_SYSMOUSE
2822 /* move the mouse cursor at the center of the screen */
2823 sc_mouse_move(scp, scp->xpixel / 2, scp->ypixel / 2);
2828 alloc_scp(sc_softc_t *sc, int vty)
2832 /* assert(sc_malloc) */
2834 scp = kmalloc(sizeof(scr_stat), M_SYSCONS, M_WAITOK);
2835 init_scp(sc, vty, scp);
2837 sc_alloc_scr_buffer(scp, TRUE, TRUE);
2838 if (sc_init_emulator(scp, SC_DFLT_TERM))
2839 sc_init_emulator(scp, "*");
2841 #ifndef SC_NO_CUTPASTE
2842 sc_alloc_cut_buffer(scp, TRUE);
2845 #ifndef SC_NO_HISTORY
2846 sc_alloc_history_buffer(scp, 0, 0, TRUE);
2853 init_scp(sc_softc_t *sc, int vty, scr_stat *scp)
2857 bzero(scp, sizeof(*scp));
2862 scp->mode = sc->initial_mode;
2863 callout_init(&scp->blink_screen_ch);
2864 (*vidsw[sc->adapter]->get_info)(sc->adp, scp->mode, &info);
2865 if (info.vi_flags & V_INFO_GRAPHICS) {
2866 scp->status |= GRAPHICS_MODE;
2867 scp->xpixel = info.vi_width;
2868 scp->ypixel = info.vi_height;
2869 scp->xsize = info.vi_width/8;
2870 scp->ysize = info.vi_height/info.vi_cheight;
2874 scp->xsize = info.vi_width;
2875 scp->ysize = info.vi_height;
2876 scp->xpixel = scp->xsize*8;
2877 scp->ypixel = scp->ysize*info.vi_cheight;
2878 if (info.vi_cheight < 14) {
2880 #ifndef SC_NO_FONT_LOADING
2881 scp->font = sc->font_8;
2885 } else if (info.vi_cheight >= 16) {
2886 scp->font_size = 16;
2887 #ifndef SC_NO_FONT_LOADING
2888 scp->font = sc->font_16;
2893 scp->font_size = 14;
2894 #ifndef SC_NO_FONT_LOADING
2895 scp->font = sc->font_14;
2901 sc_vtb_init(&scp->vtb, VTB_MEMORY, 0, 0, NULL, FALSE);
2902 sc_vtb_init(&scp->scr, VTB_FRAMEBUFFER, 0, 0, NULL, FALSE);
2903 scp->xoff = scp->yoff = 0;
2904 scp->xpos = scp->ypos = 0;
2905 scp->start = scp->xsize * scp->ysize - 1;
2910 scp->border = BG_BLACK;
2911 scp->cursor_base = sc->cursor_base;
2912 scp->cursor_height = imin(sc->cursor_height, scp->font_size);
2913 scp->mouse_cut_start = scp->xsize*scp->ysize;
2914 scp->mouse_cut_end = -1;
2915 scp->mouse_signal = 0;
2917 scp->mouse_proc = NULL;
2918 scp->kbd_mode = K_XLATE;
2919 scp->bell_pitch = bios_value.bell_pitch;
2920 scp->bell_duration = BELL_DURATION;
2921 scp->status |= (bios_value.shift_state & NLKED);
2922 scp->status |= CURSOR_ENABLED | MOUSE_HIDDEN;
2925 scp->smode.mode = VT_AUTO;
2926 scp->history = NULL;
2927 scp->history_pos = 0;
2928 scp->history_size = 0;
2932 sc_init_emulator(scr_stat *scp, char *name)
2939 if (name == NULL) /* if no name is given, use the current emulator */
2941 else /* ...otherwise find the named emulator */
2942 sw = sc_term_match(name);
2947 if (strcmp(sw->te_renderer, "*") != 0) {
2948 rndr = sc_render_match(scp, sw->te_renderer,
2949 scp->status & (GRAPHICS_MODE | PIXEL_MODE));
2952 rndr = sc_render_match(scp, scp->sc->adp->va_name,
2953 scp->status & (GRAPHICS_MODE | PIXEL_MODE));
2958 if (sw == scp->tsw) {
2959 error = (*sw->te_init)(scp, &scp->ts, SC_TE_WARM_INIT);
2961 scp->rndr->init(scp);
2962 sc_clear_screen(scp);
2963 /* assert(error == 0); */
2967 if (sc_malloc && (sw->te_size > 0))
2968 p = kmalloc(sw->te_size, M_SYSCONS, M_NOWAIT);
2971 error = (*sw->te_init)(scp, &p, SC_TE_COLD_INIT);
2976 (*scp->tsw->te_term)(scp, &scp->ts);
2977 if (scp->ts != NULL)
2978 kfree(scp->ts, M_SYSCONS);
2982 scp->rndr->init(scp);
2985 (*sw->te_default_attr)(scp, user_default.std_color, user_default.rev_color);
2986 sc_clear_screen(scp);
2992 * scgetc(flags) - get character from keyboard.
2993 * If flags & SCGETC_CN, then avoid harmful side effects.
2994 * If flags & SCGETC_NONBLOCK, then wait until a key is pressed, else
2995 * return NOKEY if there is nothing there.
2998 scgetc(sc_softc_t *sc, u_int flags)
3001 #ifndef SC_NO_HISTORY
3009 if (sc->kbd == NULL)
3014 /* I don't like this, but... XXX */
3015 if (flags & SCGETC_CN) {
3017 sccnupdate(sc->cur_scp);
3022 /* first see if there is something in the keyboard port */
3024 c = kbd_read_char(sc->kbd, !(flags & SCGETC_NONBLOCK));
3026 if (!(flags & SCGETC_CN))
3027 sc_bell(scp, bios_value.bell_pitch, BELL_DURATION);
3028 } else if (c == NOKEY)
3034 /* make screensaver happy */
3036 sc_touch_scrn_saver();
3038 if (!(flags & SCGETC_CN))
3039 /* do the /dev/random device a favour */
3040 add_keyboard_randomness(c);
3042 if (scp->kbd_mode != K_XLATE)
3045 /* if scroll-lock pressed allow history browsing */
3046 if (!ISGRAPHSC(scp) && scp->history && scp->status & SLKED) {
3048 scp->status &= ~CURSOR_ENABLED;
3049 sc_remove_cursor_image(scp);
3051 #ifndef SC_NO_HISTORY
3052 if (!(scp->status & BUFFER_SAVED)) {
3053 scp->status |= BUFFER_SAVED;
3057 /* FIXME: key codes */
3058 case SPCLKEY | FKEY | F(49): /* home key */
3059 sc_remove_cutmarking(scp);
3063 case SPCLKEY | FKEY | F(57): /* end key */
3064 sc_remove_cutmarking(scp);
3068 case SPCLKEY | FKEY | F(50): /* up arrow key */
3069 sc_remove_cutmarking(scp);
3070 if (sc_hist_up_line(scp))
3071 if (!(flags & SCGETC_CN))
3072 sc_bell(scp, bios_value.bell_pitch, BELL_DURATION);
3075 case SPCLKEY | FKEY | F(58): /* down arrow key */
3076 sc_remove_cutmarking(scp);
3077 if (sc_hist_down_line(scp))
3078 if (!(flags & SCGETC_CN))
3079 sc_bell(scp, bios_value.bell_pitch, BELL_DURATION);
3082 case SPCLKEY | FKEY | F(51): /* page up key */
3083 sc_remove_cutmarking(scp);
3084 for (i=0; i<scp->ysize; i++)
3085 if (sc_hist_up_line(scp)) {
3086 if (!(flags & SCGETC_CN))
3087 sc_bell(scp, bios_value.bell_pitch, BELL_DURATION);
3092 case SPCLKEY | FKEY | F(59): /* page down key */
3093 sc_remove_cutmarking(scp);
3094 for (i=0; i<scp->ysize; i++)
3095 if (sc_hist_down_line(scp)) {
3096 if (!(flags & SCGETC_CN))
3097 sc_bell(scp, bios_value.bell_pitch, BELL_DURATION);
3102 #endif /* SC_NO_HISTORY */
3106 * Process and consume special keys here. Return a plain char code
3107 * or a char code with the META flag or a function key code.
3111 /* goto next_code */
3116 switch (KEYCHAR(c)) {
3118 case NLK: case CLK: case ALK:
3121 kbd_ioctl(sc->kbd, KDGKBSTATE, (caddr_t)&f);
3123 scp->status |= SLKED;
3125 if (scp->status & SLKED) {
3126 scp->status &= ~SLKED;
3127 #ifndef SC_NO_HISTORY
3128 if (scp->status & BUFFER_SAVED) {
3129 if (!sc_hist_restore(scp))
3130 sc_remove_cutmarking(scp);
3131 scp->status &= ~BUFFER_SAVED;
3132 scp->status |= CURSOR_ENABLED;
3133 sc_draw_cursor_image(scp);
3135 tp = VIRTUAL_TTY(sc, scp->index);
3143 /* NON-LOCKING KEYS */
3145 case LSH: case RSH: case LCTR: case RCTR:
3146 case LALT: case RALT: case ASH: case META:
3150 if (!(sc->flags & SC_SCRN_BLANKED))
3156 /* force activatation/deactivation of the screen saver */
3157 if (!(sc->flags & SC_SCRN_BLANKED)) {
3158 run_scrn_saver = TRUE;
3159 sc->scrn_time_stamp -= scrn_blank_time;
3163 * While devices are being probed, the screen saver need
3164 * to be invoked explictly. XXX
3166 if (sc->flags & SC_SCRN_BLANKED) {
3167 scsplash_stick(FALSE);
3168 stop_scrn_saver(sc, current_saver);
3170 if (!ISGRAPHSC(scp)) {
3171 scsplash_stick(TRUE);
3172 (*current_saver)(sc, TRUE);
3176 #endif /* NSPLASH */
3180 #ifndef SC_DISABLE_REBOOT
3186 #ifndef SC_DISABLE_REBOOT
3187 shutdown_nice(RB_HALT);
3192 #ifndef SC_DISABLE_REBOOT
3193 shutdown_nice(RB_HALT|RB_POWEROFF);
3199 apm_suspend(PMST_SUSPEND);
3202 apm_suspend(PMST_STANDBY);
3211 #ifndef SC_DISABLE_DDBKEY
3213 Debugger("manual escape to debugger");
3215 kprintf("No debugger in kernel\n");
3217 #else /* SC_DISABLE_DDBKEY */
3219 #endif /* SC_DISABLE_DDBKEY */
3223 if (enable_panic_key)
3224 panic("Forced by the panic key");
3228 this_scr = scp->index;
3229 for (i = (this_scr - sc->first_vty + 1)%sc->vtys;
3230 sc->first_vty + i != this_scr;
3231 i = (i + 1)%sc->vtys) {
3232 struct tty *tp = VIRTUAL_TTY(sc, sc->first_vty + i);
3233 if (ISTTYOPEN(tp)) {
3234 sc_switch_scr(scp->sc, sc->first_vty + i);
3241 this_scr = scp->index;
3242 for (i = (this_scr - sc->first_vty + sc->vtys - 1)%sc->vtys;
3243 sc->first_vty + i != this_scr;
3244 i = (i + sc->vtys - 1)%sc->vtys) {
3245 struct tty *tp = VIRTUAL_TTY(sc, sc->first_vty + i);
3246 if (ISTTYOPEN(tp)) {
3247 sc_switch_scr(scp->sc, sc->first_vty + i);
3254 if (KEYCHAR(c) >= F_SCR && KEYCHAR(c) <= L_SCR) {
3255 sc_switch_scr(scp->sc, sc->first_vty + KEYCHAR(c) - F_SCR);
3258 /* assert(c & FKEY) */
3259 if (!(sc->flags & SC_SCRN_BLANKED))
3263 /* goto next_code */
3265 /* regular keys (maybe MKEY is set) */
3266 if (!(sc->flags & SC_SCRN_BLANKED))
3275 scmmap(struct dev_mmap_args *ap)
3279 scp = SC_STAT(ap->a_head.a_dev);
3280 if (scp != scp->sc->cur_scp)
3282 ap->a_result = (*vidsw[scp->sc->adapter]->mmap)(scp->sc->adp, ap->a_offset,
3288 save_kbd_state(scr_stat *scp)
3293 error = kbd_ioctl(scp->sc->kbd, KDGKBSTATE, (caddr_t)&state);
3294 if (error == ENOIOCTL)
3297 scp->status &= ~LOCK_MASK;
3298 scp->status |= state;
3304 update_kbd_state(scr_stat *scp, int new_bits, int mask)
3309 if (mask != LOCK_MASK) {
3310 error = kbd_ioctl(scp->sc->kbd, KDGKBSTATE, (caddr_t)&state);
3311 if (error == ENOIOCTL)
3316 state |= new_bits & mask;
3318 state = new_bits & LOCK_MASK;
3320 error = kbd_ioctl(scp->sc->kbd, KDSKBSTATE, (caddr_t)&state);
3321 if (error == ENOIOCTL)
3327 update_kbd_leds(scr_stat *scp, int which)
3332 error = kbd_ioctl(scp->sc->kbd, KDSETLED, (caddr_t)&which);
3333 if (error == ENOIOCTL)
3339 set_mode(scr_stat *scp)
3343 /* reject unsupported mode */
3344 if ((*vidsw[scp->sc->adapter]->get_info)(scp->sc->adp, scp->mode, &info))
3347 /* if this vty is not currently showing, do nothing */
3348 if (scp != scp->sc->cur_scp)
3351 /* setup video hardware for the given mode */
3352 (*vidsw[scp->sc->adapter]->set_mode)(scp->sc->adp, scp->mode);
3353 scp->rndr->init(scp);
3354 sc_vtb_init(&scp->scr, VTB_FRAMEBUFFER, scp->xsize, scp->ysize,
3355 (void *)scp->sc->adp->va_window, FALSE);
3357 #ifndef SC_NO_FONT_LOADING
3358 /* load appropriate font */
3359 if (!(scp->status & GRAPHICS_MODE)) {
3360 if (!(scp->status & PIXEL_MODE) && ISFONTAVAIL(scp->sc->adp->va_flags)) {
3361 if (scp->font_size < 14) {
3362 if (scp->sc->fonts_loaded & FONT_8)
3363 sc_load_font(scp, 0, 8, scp->sc->font_8, 0, 256);
3364 } else if (scp->font_size >= 16) {
3365 if (scp->sc->fonts_loaded & FONT_16)
3366 sc_load_font(scp, 0, 16, scp->sc->font_16, 0, 256);
3368 if (scp->sc->fonts_loaded & FONT_14)
3369 sc_load_font(scp, 0, 14, scp->sc->font_14, 0, 256);
3373 * This is an interim kludge to display correct font.
3374 * Always use the font page #0 on the video plane 2.
3375 * Somehow we cannot show the font in other font pages on
3376 * some video cards... XXX
3378 sc_show_font(scp, 0);
3382 #endif /* !SC_NO_FONT_LOADING */
3384 sc_set_border(scp, scp->border);
3385 sc_set_cursor_image(scp);
3391 refresh_ega_palette(scr_stat *scp)
3395 int rsize, gsize, bsize;
3396 int rfld, gfld, bfld;
3399 rsize = scp->sc->adp->va_info.vi_pixel_fsizes[0];
3400 gsize = scp->sc->adp->va_info.vi_pixel_fsizes[1];
3401 bsize = scp->sc->adp->va_info.vi_pixel_fsizes[2];
3402 rfld = scp->sc->adp->va_info.vi_pixel_fields[0];
3403 gfld = scp->sc->adp->va_info.vi_pixel_fields[1];
3404 bfld = scp->sc->adp->va_info.vi_pixel_fields[2];
3406 for (i = 0; i < 16; i++) {
3407 reg = scp->sc->adp->va_palette_regs[i];
3409 r = scp->sc->palette[reg * 3] >> (8 - rsize);
3410 g = scp->sc->palette[reg * 3 + 1] >> (8 - gsize);
3411 b = scp->sc->palette[reg * 3 + 2] >> (8 - bsize);
3413 scp->ega_palette[i] = (r << rfld) + (g << gfld) + (b << bfld);
3418 sc_set_border(scr_stat *scp, int color)
3420 ++scp->sc->videoio_in_progress;
3421 (*scp->rndr->draw_border)(scp, color);
3422 --scp->sc->videoio_in_progress;
3425 #ifndef SC_NO_FONT_LOADING
3427 sc_load_font(scr_stat *scp, int page, int size, u_char *buf,
3428 int base, int count)
3433 sc->font_loading_in_progress = TRUE;
3434 (*vidsw[sc->adapter]->load_font)(sc->adp, page, size, buf, base, count);
3435 sc->font_loading_in_progress = FALSE;
3439 sc_save_font(scr_stat *scp, int page, int size, u_char *buf,
3440 int base, int count)
3445 sc->font_loading_in_progress = TRUE;
3446 (*vidsw[sc->adapter]->save_font)(sc->adp, page, size, buf, base, count);
3447 sc->font_loading_in_progress = FALSE;
3451 sc_show_font(scr_stat *scp, int page)
3453 (*vidsw[scp->sc->adapter]->show_font)(scp->sc->adp, page);
3455 #endif /* !SC_NO_FONT_LOADING */
3458 sc_paste(scr_stat *scp, u_char *p, int count)
3463 if (scp->status & MOUSE_VISIBLE) {
3464 tp = VIRTUAL_TTY(scp->sc, scp->sc->cur_scp->index);
3467 rmap = scp->sc->scr_rmap;
3468 for (; count > 0; --count)
3469 (*linesw[tp->t_line].l_rint)(rmap[*p++], tp);
3474 sc_bell(scr_stat *scp, int pitch, int duration)
3476 if (cold || shutdown_in_progress)
3479 if (scp != scp->sc->cur_scp && (scp->sc->flags & SC_QUIET_BELL))
3482 if (scp->sc->flags & SC_VISUAL_BELL) {
3483 if (scp->sc->blink_in_progress)
3485 scp->sc->blink_in_progress = 3;
3486 if (scp != scp->sc->cur_scp)
3487 scp->sc->blink_in_progress += 2;
3488 blink_screen(scp->sc->cur_scp);
3489 } else if (duration != 0 && pitch != 0) {
3490 if (scp != scp->sc->cur_scp)
3492 sysbeep(pitch, duration);
3497 blink_screen(void *arg)
3499 scr_stat *scp = arg;
3502 if (ISGRAPHSC(scp) || (scp->sc->blink_in_progress <= 1)) {
3503 scp->sc->blink_in_progress = 0;
3505 tp = VIRTUAL_TTY(scp->sc, scp->index);
3508 if (scp->sc->delayed_next_scr)
3509 sc_switch_scr(scp->sc, scp->sc->delayed_next_scr - 1);
3512 (*scp->rndr->draw)(scp, 0, scp->xsize*scp->ysize,
3513 scp->sc->blink_in_progress & 1);
3514 scp->sc->blink_in_progress--;
3515 callout_reset(&scp->blink_screen_ch, hz / 10, blink_screen, scp);
3521 * Allocate active keyboard. Try to allocate "kbdmux" keyboard first, and,
3522 * if found, add all non-busy keyboards to "kbdmux". Otherwise look for
3527 sc_allocate_keyboard(sc_softc_t *sc, int unit)
3533 idx0 = kbd_allocate("kbdmux", -1, (void *)&sc->keyboard, sckbdevent, sc);
3535 k0 = kbd_get_keyboard(idx0);
3537 for (idx = kbd_find_keyboard2("*", -1, 0, 0);
3539 idx = kbd_find_keyboard2("*", -1, idx + 1, 0)) {
3540 k = kbd_get_keyboard(idx);
3542 if (idx == idx0 || KBD_IS_BUSY(k))
3545 bzero(&ki, sizeof(ki));
3546 strcpy(ki.kb_name, k->kb_name);
3547 ki.kb_unit = k->kb_unit;
3549 kbd_ioctl(k0, KBADDKBD, (caddr_t) &ki);
3552 idx0 = kbd_allocate("*", unit, (void *)&sc->keyboard, sckbdevent, sc);