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 $
34 #include "use_splash.h"
35 #include "opt_syscons.h"
41 #include <sys/param.h>
42 #include <sys/systm.h>
43 #include <sys/eventhandler.h>
44 #include <sys/reboot.h>
48 #include <sys/signalvar.h>
49 #include <sys/sysctl.h>
51 #include <sys/kernel.h>
53 #include <sys/random.h>
55 #include <sys/thread2.h>
56 #include <sys/mutex2.h>
58 #include <machine/clock.h>
59 #include <machine/console.h>
60 #include <machine/psl.h>
61 #include <machine/pc/display.h>
63 #include <machine/apm_bios.h>
65 #include <machine/frame.h>
67 #include <dev/drm/include/linux/fb.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 */
80 #define WANT_UNLOCK(m) do { \
85 #define WANT_LOCK(m) do { \
91 MALLOC_DEFINE(M_SYSCONS, "syscons", "Syscons");
93 typedef struct default_attr {
94 int std_color; /* normal hardware color */
95 int rev_color; /* reverse hardware color */
98 static default_attr user_default = {
103 static default_attr kernel_default = {
105 SC_KERNEL_CONS_REV_ATTR,
108 static int sc_console_unit = -1;
109 static scr_stat *sc_console;
110 static struct tty *sc_console_tty;
111 static void *kernel_console_ts;
113 static char init_done = COLD;
114 static char shutdown_in_progress = FALSE;
115 static char sc_malloc = FALSE;
117 static int saver_mode = CONS_NO_SAVER; /* LKM/user saver */
118 static int run_scrn_saver = FALSE; /* should run the saver? */
119 static long scrn_blank_time = 0; /* screen saver timeout value */
121 static int scrn_blanked; /* # of blanked screen */
122 static int sticky_splash = FALSE;
124 static void none_saver(sc_softc_t *sc, int blank) { }
125 static void (*current_saver)(sc_softc_t *, int) = none_saver;
128 #if !defined(SC_NO_FONT_LOADING) && defined(SC_DFLT_FONT)
132 static bios_values_t bios_value;
134 static int enable_panic_key;
135 SYSCTL_INT(_machdep, OID_AUTO, enable_panic_key, CTLFLAG_RW, &enable_panic_key,
136 0, "Enable the panic key (CTRL-ALT-SHIFT-ESC)");
138 #define SC_CONSOLECTL 255
140 #define VIRTUAL_TTY(sc, x) ((SC_DEV((sc),(x)) != NULL) ? \
141 (SC_DEV((sc),(x))->si_tty) : NULL)
142 #define ISTTYOPEN(tp) ((tp) && ((tp)->t_state & TS_ISOPEN))
145 static cdev_t cctl_dev;
147 static timeout_t blink_screen_callout;
149 static void sc_blink_screen(scr_stat *scp);
150 static struct mtx syscons_mtx = MTX_INITIALIZER("syscons");
153 static int scvidprobe(int unit, int flags, int cons);
154 static int sckbdprobe(int unit, int flags, int cons);
155 static void scmeminit(void *arg);
156 static int scdevtounit(cdev_t dev);
157 static kbd_callback_func_t sckbdevent;
158 static int scparam(struct tty *tp, struct termios *t);
159 static void scstart(struct tty *tp);
160 static void scinit(int unit, int flags);
161 static void scterm(int unit, int flags);
162 static void scshutdown(void *arg, int howto);
163 static void sc_puts(scr_stat *scp, u_char *buf, int len);
164 static u_int scgetc(sc_softc_t *sc, u_int flags);
166 #define SCGETC_NONBLOCK 2
167 static int sccngetch(int flags);
168 static void sccnupdate(scr_stat *scp);
169 static scr_stat *alloc_scp(sc_softc_t *sc, int vty);
170 static void init_scp(sc_softc_t *sc, int vty, scr_stat *scp);
171 static timeout_t scrn_timer;
172 static int and_region(int *s1, int *e1, int s2, int e2);
173 static void scrn_update(scr_stat *scp, int show_cursor);
176 static int scsplash_callback(int event, void *arg);
177 static void scsplash_saver(sc_softc_t *sc, int show);
178 static int add_scrn_saver(void (*this_saver)(sc_softc_t *, int));
179 static int remove_scrn_saver(void (*this_saver)(sc_softc_t *, int));
180 static int set_scrn_saver_mode(scr_stat *scp, int mode, u_char *pal, int border);
181 static int restore_scrn_saver_mode(scr_stat *scp, int changemode);
182 static void stop_scrn_saver(sc_softc_t *sc, void (*saver)(sc_softc_t *, int));
183 static int wait_scrn_saver_stop(sc_softc_t *sc);
184 #define scsplash_stick(stick) (sticky_splash = (stick))
186 #define scsplash_stick(stick)
189 static void do_switch_scr(sc_softc_t *sc);
190 static int vt_proc_alive(scr_stat *scp);
191 static int signal_vt_rel(scr_stat *scp);
192 static int signal_vt_acq(scr_stat *scp);
193 static int finish_vt_rel(scr_stat *scp, int release);
194 static int finish_vt_acq(scr_stat *scp);
195 static void exchange_scr(sc_softc_t *sc);
196 static void update_cursor_image(scr_stat *scp);
197 static int save_kbd_state(scr_stat *scp, int unlock);
198 static int update_kbd_state(scr_stat *scp, int state, int mask, int unlock);
199 static int update_kbd_leds(scr_stat *scp, int which);
200 static int sc_allocate_keyboard(sc_softc_t *sc, int unit);
203 * Console locking support functions.
205 * We use mutex spinlocks here in order to allow reentrancy which should
206 * avoid issues during panics.
211 mtx_spinlock(&syscons_mtx);
215 * Returns 0 on success, EAGAIN on failure.
218 syscons_lock_nonblock(void)
220 return(mtx_spinlock_try(&syscons_mtx));
226 mtx_spinunlock(&syscons_mtx);
232 static cn_probe_t sccnprobe;
233 static cn_init_t sccninit;
234 static cn_init_t sccninit_fini;
235 static cn_getc_t sccngetc;
236 static cn_checkc_t sccncheckc;
237 static cn_putc_t sccnputc;
238 static cn_dbctl_t sccndbctl;
239 static cn_term_t sccnterm;
241 CONS_DRIVER(sc, sccnprobe, sccninit, sccninit_fini, sccnterm,
242 sccngetc, sccncheckc, sccnputc, sccndbctl);
244 static d_open_t scopen;
245 static d_close_t scclose;
246 static d_read_t scread;
247 static d_ioctl_t scioctl;
248 static d_mmap_t scmmap;
250 static struct dev_ops sc_ops = {
258 .d_kqfilter = ttykqfilter,
259 .d_revoke = ttyrevoke
263 sc_probe_unit(int unit, int flags)
265 if (!scvidprobe(unit, flags, FALSE)) {
267 kprintf("sc%d: no video adapter found.\n", unit);
271 /* syscons will be attached even when there is no keyboard */
272 sckbdprobe(unit, flags, FALSE);
278 register_framebuffer(struct fb_info *info)
282 /* For now ignore framebuffers, which don't replace the vga display */
283 if (!info->is_vga_boot_display)
286 lwkt_gettoken(&tty_token);
287 sc = sc_get_softc(0, (sc_console_unit == 0) ? SC_KERNEL_CONSOLE : 0);
289 lwkt_reltoken(&tty_token);
290 kprintf("%s: sc_get_softc(%d, %d) returned NULL\n", __func__,
291 0, (sc_console_unit == 0) ? SC_KERNEL_CONSOLE : 0);
295 /* Ignore this framebuffer if we have already switched to a framebuffer */
296 if (sc->fbi != NULL) {
297 lwkt_reltoken(&tty_token);
303 if (sc->fbi != NULL) {
304 sc_update_render(sc->cur_scp);
305 sc->fbi->restore(sc->fbi->cookie);
308 lwkt_reltoken(&tty_token);
312 /* probe video adapters, return TRUE if found */
314 scvidprobe(int unit, int flags, int cons)
317 * Access the video adapter driver through the back door!
318 * Video adapter drivers need to be configured before syscons.
319 * However, when syscons is being probed as the low-level console,
320 * they have not been initialized yet. We force them to initialize
321 * themselves here. XXX
323 vid_configure(cons ? VIO_PROBE_ONLY : 0);
325 return (vid_find_adapter("*", unit) >= 0);
328 /* probe the keyboard, return TRUE if found */
330 sckbdprobe(int unit, int flags, int cons)
332 /* access the keyboard driver through the backdoor! */
333 kbd_configure(cons ? KB_CONF_PROBE_ONLY : 0);
335 return (kbd_find_keyboard("*", unit) >= 0);
339 adapter_name(video_adapter_t *adp)
345 { KD_MONO, { "MDA", "MDA" } },
346 { KD_HERCULES, { "Hercules", "Hercules" } },
347 { KD_CGA, { "CGA", "CGA" } },
348 { KD_EGA, { "EGA", "EGA (mono)" } },
349 { KD_VGA, { "VGA", "VGA (mono)" } },
350 { KD_TGA, { "TGA", "TGA" } },
351 { -1, { "Unknown", "Unknown" } },
355 for (i = 0; names[i].type != -1; ++i)
356 if (names[i].type == adp->va_type)
358 return names[i].name[(adp->va_flags & V_ADP_COLOR) ? 0 : 1];
362 sc_attach_unit(int unit, int flags)
371 flags &= ~SC_KERNEL_CONSOLE;
373 if (sc_console_unit == unit) {
375 * If this unit is being used as the system console, we need to
376 * adjust some variables and buffers before and after scinit().
378 /* assert(sc_console != NULL) */
379 flags |= SC_KERNEL_CONSOLE;
384 if (sc_console->tsw->te_size > 0) {
385 /* assert(sc_console->ts != NULL); */
386 kernel_console_ts = sc_console->ts;
387 sc_console->ts = kmalloc(sc_console->tsw->te_size,
388 M_SYSCONS, M_WAITOK);
389 bcopy(kernel_console_ts, sc_console->ts, sc_console->tsw->te_size);
390 (*sc_console->tsw->te_default_attr)(sc_console,
391 user_default.std_color,
392 user_default.rev_color);
398 sc = sc_get_softc(unit, flags & SC_KERNEL_CONSOLE);
401 * If this is the console we couldn't setup sc->dev before because
402 * malloc wasn't working. Set it up now.
404 if (flags & SC_KERNEL_CONSOLE) {
405 KKASSERT(sc->dev == NULL);
406 sc->dev = kmalloc(sizeof(cdev_t)*sc->vtys, M_SYSCONS, M_WAITOK|M_ZERO);
407 sc->dev[0] = make_dev(&sc_ops, sc_console_unit*MAXCONS, UID_ROOT,
409 "ttyv%r", sc_console_unit*MAXCONS);
410 sc->dev[0]->si_tty = ttymalloc(sc->dev[0]->si_tty);
411 sc->dev[0]->si_drv1 = sc_console;
415 * Finish up the standard attach
418 callout_init_mp(&sc->scrn_timer_ch);
419 scp = SC_STAT(sc->dev[0]);
420 if (sc_console == NULL) /* sc_console_unit < 0 */
424 if ((sc->config & SC_VESA800X600)
425 && ((*vidsw[sc->adapter]->get_info)(sc->adp, M_VESA_800x600, &info) == 0)) {
427 if (sc->flags & SC_SPLASH_SCRN)
428 splash_term(sc->adp);
430 sc_set_graphics_mode(scp, NULL, M_VESA_800x600);
431 sc_set_pixel_mode(scp, NULL, 0, 0, 16);
432 sc->initial_mode = M_VESA_800x600;
434 /* put up the splash again! */
435 if (sc->flags & SC_SPLASH_SCRN)
436 splash_init(sc->adp, scsplash_callback, sc);
439 #endif /* SC_PIXEL_MODE */
441 /* initialize cursor */
443 update_cursor_image(scp);
445 /* get screen update going */
448 /* set up the keyboard */
449 kbd_ioctl(sc->kbd, KDSKBMODE, (caddr_t)&scp->kbd_mode);
450 update_kbd_state(scp, scp->status, LOCK_MASK, FALSE);
452 kprintf("sc%d: %s <%d virtual consoles, flags=0x%x>\n",
453 unit, adapter_name(sc->adp), sc->vtys, sc->config);
455 kprintf("sc%d:", unit);
456 if (sc->adapter >= 0)
457 kprintf(" fb%d", sc->adapter);
458 if (sc->keyboard >= 0)
459 kprintf(", kbd%d", sc->keyboard);
461 kprintf(", terminal emulator: %s (%s)",
462 scp->tsw->te_name, scp->tsw->te_desc);
466 /* register a shutdown callback for the kernel console */
467 if (sc_console_unit == unit)
468 EVENTHANDLER_REGISTER(shutdown_pre_sync, scshutdown,
469 (void *)(uintptr_t)unit, SHUTDOWN_PRI_DEFAULT);
474 * The first vty already has struct tty and scr_stat initialized
475 * in scinit(). The other vtys will have these structs when
478 for (vc = 1; vc < sc->vtys; vc++) {
479 dev = make_dev(&sc_ops, vc + unit * MAXCONS,
481 0600, "ttyv%r", vc + unit * MAXCONS);
484 cctl_dev = make_dev(&sc_ops, SC_CONSOLECTL,
485 UID_ROOT, GID_WHEEL, 0600, "consolectl");
486 cctl_dev->si_tty = sc_console_tty = ttymalloc(sc_console_tty);
487 cctl_dev->si_drv1 = sc_console;
499 * As soon as malloc() becomes functional, we had better allocate
500 * various buffers for the kernel console.
503 if (sc_console_unit < 0) /* sc_console == NULL */
506 /* copy the temporary buffer to the final buffer */
507 sc_alloc_scr_buffer(sc_console, TRUE, FALSE);
509 #ifndef SC_NO_CUTPASTE
510 sc_alloc_cut_buffer(sc_console, TRUE);
513 #ifndef SC_NO_HISTORY
514 /* initialize history buffer & pointers */
515 sc_alloc_history_buffer(sc_console, 0, 0, TRUE);
519 SYSINIT(sc_mem, SI_BOOT1_POST, SI_ORDER_ANY, scmeminit, NULL);
522 scdevtounit(cdev_t dev)
524 int vty = SC_VTY(dev);
526 if (vty == SC_CONSOLECTL)
527 return ((sc_console != NULL) ? sc_console->sc->unit : -1);
528 else if ((vty < 0) || (vty >= MAXCONS*sc_max_unit()))
535 scopen(struct dev_open_args *ap)
537 cdev_t dev = ap->a_head.a_dev;
545 lwkt_gettoken(&tty_token);
546 unit = scdevtounit(dev);
547 DPRINTF(5, ("scopen: dev:%d,%d, unit:%d, vty:%d\n",
548 major(dev), minor(dev), unit, SC_VTY(dev)));
550 sc = sc_get_softc(unit, (sc_console_unit == unit) ? SC_KERNEL_CONSOLE : 0);
552 lwkt_reltoken(&tty_token);
556 tp = dev->si_tty = ttymalloc(dev->si_tty);
557 tp->t_oproc = scstart;
558 tp->t_param = scparam;
559 tp->t_stop = nottystop;
563 if (!ISTTYOPEN(tp)) {
565 /* Use the current setting of the <-- key as default VERASE. */
566 /* If the Delete key is preferable, an stty is necessary */
567 if (sc->kbd != NULL) {
568 key.keynum = KEYCODE_BS;
569 kbd_ioctl(sc->kbd, GIO_KEYMAPENT, (caddr_t)&key);
570 tp->t_cc[VERASE] = key.key.map[0];
572 tp->t_iflag = TTYDEF_IFLAG;
573 tp->t_oflag = TTYDEF_OFLAG;
574 tp->t_cflag = TTYDEF_CFLAG;
575 tp->t_lflag = TTYDEF_LFLAG;
576 tp->t_ispeed = tp->t_ospeed = TTYDEF_SPEED;
577 scparam(tp, &tp->t_termios);
578 (*linesw[tp->t_line].l_modem)(tp, 1);
581 if (tp->t_state & TS_XCLUDE && priv_check_cred(ap->a_cred, PRIV_ROOT, 0)) {
582 lwkt_reltoken(&tty_token);
586 error = (*linesw[tp->t_line].l_open)(dev, tp);
590 scp = dev->si_drv1 = alloc_scp(sc, SC_VTY(dev));
593 sc_set_pixel_mode(scp, NULL, COL, ROW, 16);
596 if (!tp->t_winsize.ws_col && !tp->t_winsize.ws_row) {
597 tp->t_winsize.ws_col = scp->xsize;
598 tp->t_winsize.ws_row = scp->ysize;
601 lwkt_reltoken(&tty_token);
606 scclose(struct dev_close_args *ap)
608 cdev_t dev = ap->a_head.a_dev;
609 struct tty *tp = dev->si_tty;
612 lwkt_gettoken(&tty_token);
613 if (SC_VTY(dev) != SC_CONSOLECTL) {
614 scp = SC_STAT(tp->t_dev);
615 /* were we in the middle of the VT switching process? */
616 DPRINTF(5, ("sc%d: scclose(), ", scp->sc->unit));
617 if ((scp == scp->sc->cur_scp) && (scp->sc->unit == sc_console_unit))
618 cons_unavail = FALSE;
619 if (finish_vt_rel(scp, TRUE) == 0) /* force release */
620 DPRINTF(5, ("reset WAIT_REL, "));
621 if (finish_vt_acq(scp) == 0) /* force acknowledge */
622 DPRINTF(5, ("reset WAIT_ACQ, "));
625 if (scp == &main_console) {
628 scp->smode.mode = VT_AUTO;
631 sc_vtb_destroy(&scp->vtb);
632 sc_vtb_destroy(&scp->scr);
633 sc_free_history_buffer(scp, scp->ysize);
635 kfree(scp, M_SYSCONS);
640 scp->smode.mode = VT_AUTO;
642 scp->kbd_mode = K_XLATE;
644 if (scp == scp->sc->cur_scp)
645 kbd_ioctl(scp->sc->kbd, KDSKBMODE, (caddr_t)&scp->kbd_mode);
646 DPRINTF(5, ("done.\n"));
648 (*linesw[tp->t_line].l_close)(tp, ap->a_fflag);
650 lwkt_reltoken(&tty_token);
656 scread(struct dev_read_args *ap)
660 lwkt_gettoken(&tty_token);
661 sc_touch_scrn_saver();
663 lwkt_reltoken(&tty_token);
668 sckbdevent(keyboard_t *thiskbd, int event, void *arg)
676 lwkt_gettoken(&tty_token);
678 * WARNING: In early boot sc->dev may not be setup yet.
680 sc = (sc_softc_t *)arg;
681 /* assert(thiskbd == sc->kbd) */
686 case KBDIO_UNLOADING:
691 kbd_release(thiskbd, (void *)&sc->keyboard);
692 lwkt_reltoken(&tty_token);
695 lwkt_reltoken(&tty_token);
700 * Loop while there is still input to get from the keyboard.
701 * I don't think this is nessesary, and it doesn't fix
702 * the Xaccel-2.1 keyboard hang, but it can't hurt. XXX
704 while ((c = scgetc(sc, SCGETC_NONBLOCK)) != NOKEY) {
705 cur_tty = VIRTUAL_TTY(sc, sc->cur_scp->index);
706 if (!ISTTYOPEN(cur_tty)) {
707 cur_tty = sc_console_tty;
708 if (!ISTTYOPEN(cur_tty))
713 if ((*sc->cur_scp->tsw->te_input)(sc->cur_scp, c, cur_tty)) {
719 switch (KEYFLAGS(c)) {
720 case 0x0000: /* normal key */
721 (*linesw[cur_tty->t_line].l_rint)(KEYCHAR(c), cur_tty);
723 case FKEY: /* function key, return string */
724 cp = kbd_get_fkeystr(thiskbd, KEYCHAR(c), &len);
727 (*linesw[cur_tty->t_line].l_rint)(*cp++, cur_tty);
730 case MKEY: /* meta is active, prepend ESC */
731 (*linesw[cur_tty->t_line].l_rint)(0x1b, cur_tty);
732 (*linesw[cur_tty->t_line].l_rint)(KEYCHAR(c), cur_tty);
734 case BKEY: /* backtab fixed sequence (esc [ Z) */
735 (*linesw[cur_tty->t_line].l_rint)(0x1b, cur_tty);
736 (*linesw[cur_tty->t_line].l_rint)('[', cur_tty);
737 (*linesw[cur_tty->t_line].l_rint)('Z', cur_tty);
743 sc->cur_scp->status |= MOUSE_HIDDEN;
746 lwkt_reltoken(&tty_token);
751 scparam(struct tty *tp, struct termios *t)
753 lwkt_gettoken(&tty_token);
754 tp->t_ispeed = t->c_ispeed;
755 tp->t_ospeed = t->c_ospeed;
756 tp->t_cflag = t->c_cflag;
757 lwkt_reltoken(&tty_token);
762 scioctl(struct dev_ioctl_args *ap)
764 cdev_t dev = ap->a_head.a_dev;
765 u_long cmd = ap->a_cmd;
766 caddr_t data = ap->a_data;
767 int flag = ap->a_fflag;
774 lwkt_gettoken(&tty_token);
777 error = sc_vid_ioctl(tp, cmd, data, flag);
778 if (error != ENOIOCTL) {
779 lwkt_reltoken(&tty_token);
783 #ifndef SC_NO_HISTORY
784 error = sc_hist_ioctl(tp, cmd, data, flag);
785 if (error != ENOIOCTL) {
786 lwkt_reltoken(&tty_token);
791 #ifndef SC_NO_SYSMOUSE
792 error = sc_mouse_ioctl(tp, cmd, data, flag);
793 if (error != ENOIOCTL) {
794 lwkt_reltoken(&tty_token);
799 scp = SC_STAT(tp->t_dev);
800 /* assert(scp != NULL) */
801 /* scp is sc_console, if SC_VTY(dev) == SC_CONSOLECTL. */
806 error = (*scp->tsw->te_ioctl)(scp, tp, cmd, data, flag);
808 if (error != ENOIOCTL) {
809 lwkt_reltoken(&tty_token);
814 switch (cmd) { /* process console hardware related ioctl's */
816 case GIO_ATTR: /* get current attributes */
817 /* this ioctl is not processed here, but in the terminal emulator */
818 lwkt_reltoken(&tty_token);
821 case GIO_COLOR: /* is this a color console ? */
822 *(int *)data = (sc->adp->va_flags & V_ADP_COLOR) ? 1 : 0;
823 lwkt_reltoken(&tty_token);
826 case CONS_BLANKTIME: /* set screen saver timeout (0 = no saver) */
827 if (*(int *)data < 0 || *(int *)data > MAX_BLANKTIME) {
828 lwkt_reltoken(&tty_token);
832 scrn_blank_time = *(int *)data;
833 run_scrn_saver = (scrn_blank_time != 0);
835 lwkt_reltoken(&tty_token);
838 case CONS_CURSORTYPE: /* set cursor type blink/noblink */
840 if (!ISGRAPHSC(sc->cur_scp))
841 sc_remove_cursor_image(sc->cur_scp);
842 if ((*(int*)data) & 0x01)
843 sc->flags |= SC_BLINK_CURSOR;
845 sc->flags &= ~SC_BLINK_CURSOR;
846 if ((*(int*)data) & 0x02) {
847 sc->flags |= SC_CHAR_CURSOR;
849 sc->flags &= ~SC_CHAR_CURSOR;
851 * The cursor shape is global property; all virtual consoles
852 * are affected. Update the cursor in the current console...
854 if (!ISGRAPHSC(sc->cur_scp)) {
855 sc_set_cursor_image(sc->cur_scp);
856 sc_draw_cursor_image(sc->cur_scp);
859 lwkt_reltoken(&tty_token);
862 case CONS_BELLTYPE: /* set bell type sound/visual */
865 if ((*(int *)data) & 0x01)
866 sc->flags |= SC_VISUAL_BELL;
868 sc->flags &= ~SC_VISUAL_BELL;
870 if ((*(int *)data) & 0x02)
871 sc->flags |= SC_QUIET_BELL;
873 sc->flags &= ~SC_QUIET_BELL;
876 lwkt_reltoken(&tty_token);
879 case CONS_GETINFO: /* get current (virtual) console info */
881 vid_info_t *ptr = (vid_info_t*)data;
882 if (ptr->size == sizeof(struct vid_info)) {
883 ptr->m_num = sc->cur_scp->index;
884 ptr->font_size = scp->font_size;
885 ptr->mv_col = scp->xpos;
886 ptr->mv_row = scp->ypos;
887 ptr->mv_csz = scp->xsize;
888 ptr->mv_rsz = scp->ysize;
890 * The following fields are filled by the terminal emulator. XXX
897 ptr->mv_grfc.fore = 0; /* not supported */
898 ptr->mv_grfc.back = 0; /* not supported */
899 ptr->mv_ovscan = scp->border;
900 if (scp == sc->cur_scp)
901 save_kbd_state(scp, FALSE);
902 ptr->mk_keylock = scp->status & LOCK_MASK;
903 lwkt_reltoken(&tty_token);
906 lwkt_reltoken(&tty_token);
910 case CONS_GETVERS: /* get version number */
911 *(int*)data = 0x200; /* version 2.0 */
912 lwkt_reltoken(&tty_token);
915 case CONS_IDLE: /* see if the screen has been idle */
917 * When the screen is in the GRAPHICS_MODE or UNKNOWN_MODE,
918 * the user process may have been writing something on the
919 * screen and syscons is not aware of it. Declare the screen
920 * is NOT idle if it is in one of these modes. But there is
921 * an exception to it; if a screen saver is running in the
922 * graphics mode in the current screen, we should say that the
923 * screen has been idle.
925 *(int *)data = (sc->flags & SC_SCRN_IDLE)
926 && (!ISGRAPHSC(sc->cur_scp)
927 || (sc->cur_scp->status & SAVER_RUNNING));
928 lwkt_reltoken(&tty_token);
931 case CONS_SAVERMODE: /* set saver mode */
932 switch(*(int *)data) {
936 /* if a LKM screen saver is running, stop it first. */
937 scsplash_stick(FALSE);
938 saver_mode = *(int *)data;
940 if ((error = wait_scrn_saver_stop(NULL))) {
942 lwkt_reltoken(&tty_token);
946 run_scrn_saver = TRUE;
947 if (saver_mode == CONS_USR_SAVER)
948 scp->status |= SAVER_RUNNING;
950 scp->status &= ~SAVER_RUNNING;
951 scsplash_stick(TRUE);
956 if ((saver_mode == CONS_USR_SAVER) && (scp->status & SAVER_RUNNING))
957 scp->status &= ~SAVER_RUNNING;
958 saver_mode = *(int *)data;
962 lwkt_reltoken(&tty_token);
965 lwkt_reltoken(&tty_token);
968 case CONS_SAVERSTART: /* immediately start/stop the screen saver */
970 * Note that this ioctl does not guarantee the screen saver
971 * actually starts or stops. It merely attempts to do so...
974 run_scrn_saver = (*(int *)data != 0);
976 sc->scrn_time_stamp -= scrn_blank_time;
978 lwkt_reltoken(&tty_token);
981 case CONS_SCRSHOT: /* get a screen shot */
983 scrshot_t *ptr = (scrshot_t*)data;
985 if (ISGRAPHSC(scp)) {
987 lwkt_reltoken(&tty_token);
990 if (scp->xsize != ptr->xsize || scp->ysize != ptr->ysize) {
992 lwkt_reltoken(&tty_token);
996 copyout ((void*)scp->vtb.vtb_buffer, ptr->buf,
997 ptr->xsize * ptr->ysize * sizeof(uint16_t));
998 lwkt_reltoken(&tty_token);
1002 case VT_SETMODE: /* set screen switcher mode */
1004 struct vt_mode *mode;
1006 mode = (struct vt_mode *)data;
1007 DPRINTF(5, ("sc%d: VT_SETMODE ", sc->unit));
1008 if (scp->smode.mode == VT_PROCESS) {
1009 if (scp->proc == pfindn(scp->pid) && scp->proc != curproc) {
1010 DPRINTF(5, ("error EPERM\n"));
1011 lwkt_reltoken(&tty_token);
1016 if (mode->mode == VT_AUTO) {
1017 scp->smode.mode = VT_AUTO;
1020 DPRINTF(5, ("VT_AUTO, "));
1021 if ((scp == sc->cur_scp) && (sc->unit == sc_console_unit))
1022 cons_unavail = FALSE;
1023 if (finish_vt_rel(scp, TRUE) == 0)
1024 DPRINTF(5, ("reset WAIT_REL, "));
1025 if (finish_vt_acq(scp) == 0)
1026 DPRINTF(5, ("reset WAIT_ACQ, "));
1028 if (!ISSIGVALID(mode->relsig) || !ISSIGVALID(mode->acqsig)
1029 || !ISSIGVALID(mode->frsig)) {
1031 DPRINTF(5, ("error EINVAL\n"));
1032 lwkt_reltoken(&tty_token);
1035 DPRINTF(5, ("VT_PROCESS %d, ", curproc->p_pid));
1036 bcopy(data, &scp->smode, sizeof(struct vt_mode));
1037 scp->proc = curproc;
1038 scp->pid = scp->proc->p_pid;
1039 if ((scp == sc->cur_scp) && (sc->unit == sc_console_unit))
1040 cons_unavail = TRUE;
1044 lwkt_reltoken(&tty_token);
1048 case VT_GETMODE: /* get screen switcher mode */
1049 bcopy(&scp->smode, data, sizeof(struct vt_mode));
1050 lwkt_reltoken(&tty_token);
1053 case VT_RELDISP: /* screen switcher ioctl */
1055 * This must be the current vty which is in the VT_PROCESS
1059 if ((scp != sc->cur_scp) || (scp->smode.mode != VT_PROCESS)) {
1061 lwkt_reltoken(&tty_token);
1064 /* ...and this process is controlling it. */
1065 if (scp->proc != curproc) {
1067 lwkt_reltoken(&tty_token);
1071 switch(*(int *)data) {
1072 case VT_FALSE: /* user refuses to release screen, abort */
1073 if ((error = finish_vt_rel(scp, FALSE)) == 0)
1074 DPRINTF(5, ("sc%d: VT_FALSE\n", sc->unit));
1076 case VT_TRUE: /* user has released screen, go on */
1077 if ((error = finish_vt_rel(scp, TRUE)) == 0)
1078 DPRINTF(5, ("sc%d: VT_TRUE\n", sc->unit));
1080 case VT_ACKACQ: /* acquire acknowledged, switch completed */
1081 if ((error = finish_vt_acq(scp)) == 0)
1082 DPRINTF(5, ("sc%d: VT_ACKACQ\n", sc->unit));
1088 lwkt_reltoken(&tty_token);
1091 case VT_OPENQRY: /* return free virtual console */
1092 for (i = sc->first_vty; i < sc->first_vty + sc->vtys; i++) {
1093 tp = VIRTUAL_TTY(sc, i);
1094 if (!ISTTYOPEN(tp)) {
1095 *(int *)data = i + 1;
1096 lwkt_reltoken(&tty_token);
1100 lwkt_reltoken(&tty_token);
1103 case VT_ACTIVATE: /* switch to screen *data */
1104 i = (*(int *)data == 0) ? scp->index : (*(int *)data - 1);
1106 sc_clean_up(sc->cur_scp);
1107 error = sc_switch_scr(sc, i);
1109 lwkt_reltoken(&tty_token);
1112 case VT_WAITACTIVE: /* wait for switch to occur */
1113 i = (*(int *)data == 0) ? scp->index : (*(int *)data - 1);
1114 if ((i < sc->first_vty) || (i >= sc->first_vty + sc->vtys)) {
1115 lwkt_reltoken(&tty_token);
1119 error = sc_clean_up(sc->cur_scp);
1122 lwkt_reltoken(&tty_token);
1127 * scp might be NULL, we aren't sure why. Check for NULL.
1129 * http://bugs.dragonflybsd.org/issues/2481
1131 scp = SC_STAT(SC_DEV(sc, i));
1132 if (scp == NULL || scp == scp->sc->cur_scp) {
1133 lwkt_reltoken(&tty_token);
1136 error = tsleep((caddr_t)&scp->smode, PCATCH, "waitvt", 0);
1137 /* May return ERESTART */
1138 lwkt_reltoken(&tty_token);
1141 case VT_GETACTIVE: /* get active vty # */
1142 *(int *)data = sc->cur_scp->index + 1;
1143 lwkt_reltoken(&tty_token);
1146 case VT_GETINDEX: /* get this vty # */
1147 *(int *)data = scp->index + 1;
1148 lwkt_reltoken(&tty_token);
1151 case VT_LOCKSWITCH: /* prevent vty switching */
1153 if ((*(int *)data) & 0x01)
1154 sc->flags |= SC_SCRN_VTYLOCK;
1156 sc->flags &= ~SC_SCRN_VTYLOCK;
1158 lwkt_reltoken(&tty_token);
1161 case KDENABIO: /* allow io operations */
1162 error = priv_check_cred(ap->a_cred, PRIV_ROOT, 0);
1164 lwkt_reltoken(&tty_token);
1167 if (securelevel > 0) {
1168 lwkt_reltoken(&tty_token);
1171 #if defined(__i386__)
1172 curthread->td_lwp->lwp_md.md_regs->tf_eflags |= PSL_IOPL;
1173 #elif defined(__x86_64__)
1174 curthread->td_lwp->lwp_md.md_regs->tf_rflags |= PSL_IOPL;
1176 lwkt_reltoken(&tty_token);
1179 case KDDISABIO: /* disallow io operations (default) */
1180 #if defined(__i386__)
1181 curthread->td_lwp->lwp_md.md_regs->tf_eflags &= ~PSL_IOPL;
1182 #elif defined(__x86_64__)
1183 curthread->td_lwp->lwp_md.md_regs->tf_rflags &= ~PSL_IOPL;
1185 lwkt_reltoken(&tty_token);
1188 case KDSKBSTATE: /* set keyboard state (locks) */
1189 if (*(int *)data & ~LOCK_MASK) {
1190 lwkt_reltoken(&tty_token);
1194 scp->status &= ~LOCK_MASK;
1195 scp->status |= *(int *)data;
1197 if (scp == sc->cur_scp)
1198 update_kbd_state(scp, scp->status, LOCK_MASK, FALSE);
1199 lwkt_reltoken(&tty_token);
1202 case KDGKBSTATE: /* get keyboard state (locks) */
1203 if (scp == sc->cur_scp)
1204 save_kbd_state(scp, FALSE);
1205 *(int *)data = scp->status & LOCK_MASK;
1206 lwkt_reltoken(&tty_token);
1209 case KDGETREPEAT: /* get keyboard repeat & delay rates */
1210 case KDSETREPEAT: /* set keyboard repeat & delay rates (new) */
1211 error = kbd_ioctl(sc->kbd, cmd, data);
1212 if (error == ENOIOCTL)
1214 lwkt_reltoken(&tty_token);
1217 case KDSETRAD: /* set keyboard repeat & delay rates (old) */
1218 if (*(int *)data & ~0x7f) {
1219 lwkt_reltoken(&tty_token);
1222 error = kbd_ioctl(sc->kbd, cmd, data);
1223 if (error == ENOIOCTL)
1225 lwkt_reltoken(&tty_token);
1228 case KDSKBMODE: /* set keyboard mode */
1229 switch (*(int *)data) {
1230 case K_XLATE: /* switch to XLT ascii mode */
1231 case K_RAW: /* switch to RAW scancode mode */
1232 case K_CODE: /* switch to CODE mode */
1233 scp->kbd_mode = *(int *)data;
1234 if (scp == sc->cur_scp)
1235 kbd_ioctl(sc->kbd, cmd, data);
1236 lwkt_reltoken(&tty_token);
1239 lwkt_reltoken(&tty_token);
1244 case KDGKBMODE: /* get keyboard mode */
1245 *(int *)data = scp->kbd_mode;
1246 lwkt_reltoken(&tty_token);
1250 error = kbd_ioctl(sc->kbd, cmd, data);
1251 if (error == ENOIOCTL)
1253 lwkt_reltoken(&tty_token);
1256 case KDMKTONE: /* sound the bell */
1259 sc_bell(scp, (*(int*)data)&0xffff,
1260 (((*(int*)data)>>16)&0xffff)*hz/1000);
1262 sc_bell(scp, scp->bell_pitch, scp->bell_duration);
1264 lwkt_reltoken(&tty_token);
1267 case KIOCSOUND: /* make tone (*data) hz */
1269 if (scp == sc->cur_scp) {
1271 error = sc_tone(*(int *)data);
1279 lwkt_reltoken(&tty_token);
1282 case KDGKBTYPE: /* get keyboard type */
1283 error = kbd_ioctl(sc->kbd, cmd, data);
1284 if (error == ENOIOCTL) {
1285 /* always return something? XXX */
1288 lwkt_reltoken(&tty_token);
1291 case KDSETLED: /* set keyboard LED status */
1292 if (*(int *)data & ~LED_MASK) { /* FIXME: LOCK_MASK? */
1293 lwkt_reltoken(&tty_token);
1297 scp->status &= ~LED_MASK;
1298 scp->status |= *(int *)data;
1300 if (scp == sc->cur_scp)
1301 update_kbd_leds(scp, scp->status);
1302 lwkt_reltoken(&tty_token);
1305 case KDGETLED: /* get keyboard LED status */
1306 if (scp == sc->cur_scp)
1307 save_kbd_state(scp, FALSE);
1308 *(int *)data = scp->status & LED_MASK;
1309 lwkt_reltoken(&tty_token);
1312 case KBADDKBD: /* add/remove keyboard to/from mux */
1314 error = kbd_ioctl(sc->kbd, cmd, data);
1315 if (error == ENOIOCTL)
1317 lwkt_reltoken(&tty_token);
1320 case CONS_SETKBD: /* set the new keyboard */
1324 newkbd = kbd_get_keyboard(*(int *)data);
1325 if (newkbd == NULL) {
1326 lwkt_reltoken(&tty_token);
1330 if (sc->kbd != newkbd) {
1331 i = kbd_allocate(newkbd->kb_name, newkbd->kb_unit,
1332 (void *)&sc->keyboard, sckbdevent, sc);
1333 /* i == newkbd->kb_index */
1335 if (sc->kbd != NULL) {
1336 save_kbd_state(sc->cur_scp, FALSE);
1337 kbd_release(sc->kbd, (void *)&sc->keyboard);
1340 sc->kbd = kbd_get_keyboard(i); /* sc->kbd == newkbd */
1343 kbd_ioctl(sc->kbd, KDSKBMODE,
1344 (caddr_t)&sc->cur_scp->kbd_mode);
1345 update_kbd_state(sc->cur_scp, sc->cur_scp->status,
1348 error = EPERM; /* XXX */
1351 lwkt_reltoken(&tty_token);
1355 case CONS_RELKBD: /* release the current keyboard */
1357 if (sc->kbd != NULL) {
1358 save_kbd_state(sc->cur_scp, FALSE);
1359 error = kbd_release(sc->kbd, (void *)&sc->keyboard);
1367 lwkt_reltoken(&tty_token);
1370 case CONS_GETTERM: /* get the current terminal emulator info */
1374 if (((term_info_t *)data)->ti_index == 0) {
1377 sw = sc_term_match_by_number(((term_info_t *)data)->ti_index);
1380 strncpy(((term_info_t *)data)->ti_name, sw->te_name,
1381 sizeof(((term_info_t *)data)->ti_name));
1382 strncpy(((term_info_t *)data)->ti_desc, sw->te_desc,
1383 sizeof(((term_info_t *)data)->ti_desc));
1384 ((term_info_t *)data)->ti_flags = 0;
1385 lwkt_reltoken(&tty_token);
1388 ((term_info_t *)data)->ti_name[0] = '\0';
1389 ((term_info_t *)data)->ti_desc[0] = '\0';
1390 ((term_info_t *)data)->ti_flags = 0;
1391 lwkt_reltoken(&tty_token);
1396 case CONS_SETTERM: /* set the current terminal emulator */
1398 error = sc_init_emulator(scp, ((term_info_t *)data)->ti_name);
1399 /* FIXME: what if scp == sc_console! XXX */
1401 lwkt_reltoken(&tty_token);
1404 case GIO_SCRNMAP: /* get output translation table */
1405 bcopy(&sc->scr_map, data, sizeof(sc->scr_map));
1406 lwkt_reltoken(&tty_token);
1409 case PIO_SCRNMAP: /* set output translation table */
1410 bcopy(data, &sc->scr_map, sizeof(sc->scr_map));
1411 for (i=0; i<sizeof(sc->scr_map); i++) {
1412 sc->scr_rmap[sc->scr_map[i]] = i;
1414 lwkt_reltoken(&tty_token);
1417 case GIO_KEYMAP: /* get keyboard translation table */
1418 case PIO_KEYMAP: /* set keyboard translation table */
1419 case GIO_DEADKEYMAP: /* get accent key translation table */
1420 case PIO_DEADKEYMAP: /* set accent key translation table */
1421 case GETFKEY: /* get function key string */
1422 case SETFKEY: /* set function key string */
1423 error = kbd_ioctl(sc->kbd, cmd, data);
1424 if (error == ENOIOCTL)
1426 lwkt_reltoken(&tty_token);
1429 #ifndef SC_NO_FONT_LOADING
1431 case PIO_FONT8x8: /* set 8x8 dot font */
1432 if (!ISFONTAVAIL(sc->adp->va_flags)) {
1433 lwkt_reltoken(&tty_token);
1437 bcopy(data, sc->font_8, 8*256);
1438 sc->fonts_loaded |= FONT_8;
1441 * Always use the font page #0. XXX
1442 * Don't load if the current font size is not 8x8.
1444 if (ISTEXTSC(sc->cur_scp) && (sc->cur_scp->font_size < 14))
1445 sc_load_font(sc->cur_scp, 0, 8, sc->font_8, 0, 256);
1447 lwkt_reltoken(&tty_token);
1450 case GIO_FONT8x8: /* get 8x8 dot font */
1451 if (!ISFONTAVAIL(sc->adp->va_flags)) {
1452 lwkt_reltoken(&tty_token);
1455 if (sc->fonts_loaded & FONT_8) {
1456 bcopy(sc->font_8, data, 8*256);
1457 lwkt_reltoken(&tty_token);
1461 lwkt_reltoken(&tty_token);
1465 case PIO_FONT8x14: /* set 8x14 dot font */
1466 if (!ISFONTAVAIL(sc->adp->va_flags)) {
1467 lwkt_reltoken(&tty_token);
1471 bcopy(data, sc->font_14, 14*256);
1472 sc->fonts_loaded |= FONT_14;
1475 * Always use the font page #0. XXX
1476 * Don't load if the current font size is not 8x14.
1478 if (ISTEXTSC(sc->cur_scp)
1479 && (sc->cur_scp->font_size >= 14)
1480 && (sc->cur_scp->font_size < 16)) {
1481 sc_load_font(sc->cur_scp, 0, 14, sc->font_14, 0, 256);
1484 lwkt_reltoken(&tty_token);
1487 case GIO_FONT8x14: /* get 8x14 dot font */
1488 if (!ISFONTAVAIL(sc->adp->va_flags)) {
1489 lwkt_reltoken(&tty_token);
1492 if (sc->fonts_loaded & FONT_14) {
1493 bcopy(sc->font_14, data, 14*256);
1494 lwkt_reltoken(&tty_token);
1498 lwkt_reltoken(&tty_token);
1502 case PIO_FONT8x16: /* set 8x16 dot font */
1503 if (!ISFONTAVAIL(sc->adp->va_flags)) {
1504 lwkt_reltoken(&tty_token);
1508 bcopy(data, sc->font_16, 16*256);
1509 sc->fonts_loaded |= FONT_16;
1512 * Always use the font page #0. XXX
1513 * Don't load if the current font size is not 8x16.
1515 if (ISTEXTSC(sc->cur_scp) && (sc->cur_scp->font_size >= 16))
1516 sc_load_font(sc->cur_scp, 0, 16, sc->font_16, 0, 256);
1518 lwkt_reltoken(&tty_token);
1521 case GIO_FONT8x16: /* get 8x16 dot font */
1522 if (!ISFONTAVAIL(sc->adp->va_flags)) {
1523 lwkt_reltoken(&tty_token);
1526 if (sc->fonts_loaded & FONT_16) {
1527 bcopy(sc->font_16, data, 16*256);
1528 lwkt_reltoken(&tty_token);
1532 lwkt_reltoken(&tty_token);
1536 #endif /* SC_NO_FONT_LOADING */
1542 error = (*linesw[tp->t_line].l_ioctl)(tp, cmd, data, flag, ap->a_cred);
1543 if (error != ENOIOCTL) {
1544 lwkt_reltoken(&tty_token);
1547 error = ttioctl(tp, cmd, data, flag);
1548 if (error != ENOIOCTL) {
1549 lwkt_reltoken(&tty_token);
1552 lwkt_reltoken(&tty_token);
1557 scstart(struct tty *tp)
1561 u_char buf[PCBURST];
1562 scr_stat *scp = SC_STAT(tp->t_dev);
1565 if (scp->status & SLKED ||
1566 (scp == scp->sc->cur_scp && scp->sc->blink_in_progress))
1571 if (!(tp->t_state & (TS_TIMEOUT | TS_BUSY | TS_TTSTOP))) {
1572 tp->t_state |= TS_BUSY;
1575 len = q_to_b(rbp, buf, PCBURST);
1576 sc_puts(scp, buf, len);
1578 tp->t_state &= ~TS_BUSY;
1587 sccnprobe(struct consdev *cp)
1592 cp->cn_pri = sc_get_cons_priority(&unit, &flags);
1594 /* a video card is always required */
1595 if (!scvidprobe(unit, flags, TRUE))
1596 cp->cn_pri = CN_DEAD;
1598 /* syscons will become console even when there is no keyboard */
1599 sckbdprobe(unit, flags, TRUE);
1601 if (cp->cn_pri == CN_DEAD) {
1605 /* initialize required fields */
1606 cp->cn_probegood = 1;
1610 sccninit(struct consdev *cp)
1615 sc_get_cons_priority(&unit, &flags);
1616 scinit(unit, flags | SC_KERNEL_CONSOLE);
1617 sc_console_unit = unit;
1618 sc_console = sc_get_softc(unit, SC_KERNEL_CONSOLE)->console_scp;
1622 sccninit_fini(struct consdev *cp)
1624 if (cctl_dev == NULL)
1625 kprintf("sccninit_fini: WARNING: cctl_dev is NULL!\n");
1626 cp->cn_dev = cctl_dev;
1630 sccnterm(struct consdev *cp)
1632 /* we are not the kernel console any more, release everything */
1634 if (sc_console_unit < 0)
1635 return; /* shouldn't happen */
1639 sc_clear_screen(sc_console);
1640 sccnupdate(sc_console);
1643 scterm(sc_console_unit, SC_KERNEL_CONSOLE);
1644 sc_console_unit = -1;
1649 * Console path - cannot block!
1652 sccnputc(void *private, int c)
1655 scr_stat *scp = sc_console;
1657 #ifndef SC_NO_HISTORY
1661 #endif /* !SC_NO_HISTORY */
1663 /* assert(sc_console != NULL) */
1666 #ifndef SC_NO_HISTORY
1667 if (scp == scp->sc->cur_scp && scp->status & SLKED) {
1668 scp->status &= ~SLKED;
1670 /* This can block, illegal in the console path */
1671 update_kbd_state(scp, scp->status, SLKED, TRUE);
1673 if (scp->status & BUFFER_SAVED) {
1674 if (!sc_hist_restore(scp))
1675 sc_remove_cutmarking(scp);
1676 scp->status &= ~BUFFER_SAVED;
1677 scp->status |= CURSOR_ENABLED;
1678 sc_draw_cursor_image(scp);
1681 tp = VIRTUAL_TTY(scp->sc, scp->index);
1682 /* This can block, illegal in the console path */
1683 if (ISTTYOPEN(tp)) {
1688 #endif /* !SC_NO_HISTORY */
1691 if (kernel_console_ts != NULL)
1692 scp->ts = kernel_console_ts;
1694 sc_puts(scp, buf, 1);
1702 * Console path - cannot block!
1705 sccngetc(void *private)
1707 return sccngetch(0);
1711 * Console path - cannot block!
1714 sccncheckc(void *private)
1716 return sccngetch(SCGETC_NONBLOCK);
1720 sccndbctl(void *private, int on)
1722 /* assert(sc_console_unit >= 0) */
1723 /* try to switch to the kernel console screen */
1724 if (on && debugger == 0) {
1726 * TRY to make sure the screen saver is stopped,
1727 * and the screen is updated before switching to
1732 && sc_console->sc->cur_scp->smode.mode == VT_AUTO
1733 && sc_console->smode.mode == VT_AUTO) {
1734 sc_console->sc->cur_scp->status |= MOUSE_HIDDEN;
1736 sc_switch_scr(sc_console->sc, sc_console->index);
1747 * Console path - cannot block!
1750 sccngetch(int flags)
1752 static struct fkeytab fkey;
1760 /* assert(sc_console != NULL) */
1763 * Stop the screen saver and update the screen if necessary.
1764 * What if we have been running in the screen saver code... XXX
1766 sc_touch_scrn_saver();
1767 scp = sc_console->sc->cur_scp; /* XXX */
1771 if (fkeycp < fkey.len) {
1772 return fkey.str[fkeycp++];
1775 if (scp->sc->kbd == NULL) {
1780 * Make sure the keyboard is accessible even when the kbd device
1781 * driver is disabled.
1784 kbd_enable(scp->sc->kbd);
1786 /* we shall always use the keyboard in the XLATE mode here */
1787 cur_mode = scp->kbd_mode;
1788 scp->kbd_mode = K_XLATE;
1789 kbd_ioctl(scp->sc->kbd, KDSKBMODE, (caddr_t)&scp->kbd_mode);
1791 kbd_poll(scp->sc->kbd, TRUE);
1792 c = scgetc(scp->sc, SCGETC_CN | flags);
1793 kbd_poll(scp->sc->kbd, FALSE);
1795 scp->kbd_mode = cur_mode;
1796 kbd_ioctl(scp->sc->kbd, KDSKBMODE, (caddr_t)&scp->kbd_mode);
1797 kbd_disable(scp->sc->kbd);
1800 switch (KEYFLAGS(c)) {
1801 case 0: /* normal char */
1803 case FKEY: /* function key */
1804 p = kbd_get_fkeystr(scp->sc->kbd, KEYCHAR(c), (size_t *)&fkeycp);
1806 if ((p != NULL) && (fkey.len > 0)) {
1807 bcopy(p, fkey.str, fkey.len);
1821 sccnupdate(scr_stat *scp)
1823 /* this is a cut-down version of scrn_timer()... */
1825 if (scp->sc->font_loading_in_progress || scp->sc->videoio_in_progress) {
1829 if (debugger > 0 || panicstr || shutdown_in_progress) {
1830 sc_touch_scrn_saver();
1831 } else if (scp != scp->sc->cur_scp) {
1835 if (!run_scrn_saver)
1836 scp->sc->flags &= ~SC_SCRN_IDLE;
1839 * This is a hard path, we cannot call stop_scrn_saver() here.
1841 if ((saver_mode != CONS_LKM_SAVER) || !(scp->sc->flags & SC_SCRN_IDLE))
1842 if (scp->sc->flags & SC_SCRN_BLANKED) {
1843 sc_touch_scrn_saver();
1844 /*stop_scrn_saver(scp->sc, current_saver);*/
1846 #endif /* NSPLASH */
1848 if (scp != scp->sc->cur_scp || scp->sc->blink_in_progress
1849 || scp->sc->switch_in_progress) {
1853 * FIXME: unlike scrn_timer(), we call scrn_update() from here even
1854 * when write_in_progress is non-zero. XXX
1857 if (!ISGRAPHSC(scp) && !(scp->sc->flags & SC_SCRN_BLANKED))
1858 scrn_update(scp, TRUE);
1862 scrn_timer(void *arg)
1864 static int kbd_interval = 0;
1871 * Setup depending on who called us
1873 again = (arg != NULL);
1875 sc = (sc_softc_t *)arg;
1876 } else if (sc_console != NULL) {
1877 sc = sc_console->sc;
1883 * Don't do anything when we are performing some I/O operations.
1884 * (These are initiated by the frontend?)
1886 if (sc->font_loading_in_progress || sc->videoio_in_progress) {
1888 callout_reset(&sc->scrn_timer_ch, hz / 10, scrn_timer, sc);
1893 * Try to allocate a keyboard automatically
1895 if ((sc->kbd == NULL) && (sc->config & SC_AUTODETECT_KBD)) {
1896 if (++kbd_interval >= 25) {
1897 sc->keyboard = sc_allocate_keyboard(sc, -1);
1898 if (sc->keyboard >= 0) {
1899 sc->kbd = kbd_get_keyboard(sc->keyboard);
1900 kbd_ioctl(sc->kbd, KDSKBMODE,
1901 (caddr_t)&sc->cur_scp->kbd_mode);
1902 update_kbd_state(sc->cur_scp, sc->cur_scp->status,
1910 * Should we stop the screen saver? We need the syscons_lock
1911 * for most of this stuff.
1913 getmicrouptime(&tv);
1915 if (syscons_lock_nonblock() != 0) {
1916 /* failed to get the lock */
1918 callout_reset(&sc->scrn_timer_ch, hz / 10, scrn_timer, sc);
1921 /* successful lock */
1923 if (debugger > 0 || panicstr || shutdown_in_progress)
1924 sc_touch_scrn_saver();
1925 if (run_scrn_saver) {
1926 if (tv.tv_sec > sc->scrn_time_stamp + scrn_blank_time)
1927 sc->flags |= SC_SCRN_IDLE;
1929 sc->flags &= ~SC_SCRN_IDLE;
1931 sc->scrn_time_stamp = tv.tv_sec;
1932 sc->flags &= ~SC_SCRN_IDLE;
1933 if (scrn_blank_time > 0)
1934 run_scrn_saver = TRUE;
1937 if ((saver_mode != CONS_LKM_SAVER) || !(sc->flags & SC_SCRN_IDLE))
1938 if (sc->flags & SC_SCRN_BLANKED)
1939 stop_scrn_saver(sc, current_saver);
1940 #endif /* NSPLASH */
1942 /* should we just return ? */
1943 if (sc->blink_in_progress || sc->switch_in_progress ||
1944 sc->write_in_progress)
1948 callout_reset(&sc->scrn_timer_ch, hz / 10, scrn_timer, sc);
1952 /* Update the screen */
1953 scp = sc->cur_scp; /* cur_scp may have changed... */
1954 if (!ISGRAPHSC(scp) && !(sc->flags & SC_SCRN_BLANKED))
1955 scrn_update(scp, TRUE);
1958 /* should we activate the screen saver? */
1959 if ((saver_mode == CONS_LKM_SAVER) && (sc->flags & SC_SCRN_IDLE))
1960 if (!ISGRAPHSC(scp) || (sc->flags & SC_SCRN_BLANKED))
1961 (*current_saver)(sc, TRUE);
1962 #endif /* NSPLASH */
1966 callout_reset(&sc->scrn_timer_ch, hz / 25, scrn_timer, sc);
1970 and_region(int *s1, int *e1, int s2, int e2)
1972 if (*e1 < s2 || e2 < *s1)
1974 *s1 = imax(*s1, s2);
1975 *e1 = imin(*e1, e2);
1980 scrn_update(scr_stat *scp, int show_cursor)
1987 /* assert(scp == scp->sc->cur_scp) */
1989 ++scp->sc->videoio_in_progress;
1991 #ifndef SC_NO_CUTPASTE
1992 /* remove the previous mouse pointer image if necessary */
1993 if (scp->status & MOUSE_VISIBLE) {
1995 e = scp->mouse_pos + scp->xsize + 1;
1996 if ((scp->status & (MOUSE_MOVED | MOUSE_HIDDEN))
1997 || and_region(&s, &e, scp->start, scp->end)
1998 || ((scp->status & CURSOR_ENABLED) &&
1999 (scp->cursor_pos != scp->cursor_oldpos) &&
2000 (and_region(&s, &e, scp->cursor_pos, scp->cursor_pos)
2001 || and_region(&s, &e, scp->cursor_oldpos, scp->cursor_oldpos)))) {
2002 sc_remove_mouse_image(scp);
2003 if (scp->end >= scp->xsize*scp->ysize)
2004 scp->end = scp->xsize*scp->ysize - 1;
2007 #endif /* !SC_NO_CUTPASTE */
2011 if (scp->end >= scp->xsize*scp->ysize) {
2012 kprintf("scrn_update(): scp->end %d > size_of_screen!!\n", scp->end);
2013 scp->end = scp->xsize*scp->ysize - 1;
2015 if (scp->start < 0) {
2016 kprintf("scrn_update(): scp->start %d < 0\n", scp->start);
2021 /* update screen image */
2022 if (scp->start <= scp->end) {
2023 if (scp->mouse_cut_end >= 0) {
2024 /* there is a marked region for cut & paste */
2025 if (scp->mouse_cut_start <= scp->mouse_cut_end) {
2026 start = scp->mouse_cut_start;
2027 end = scp->mouse_cut_end;
2029 start = scp->mouse_cut_end;
2030 end = scp->mouse_cut_start - 1;
2034 /* does the cut-mark region overlap with the update region? */
2035 if (and_region(&s, &e, scp->start, scp->end)) {
2036 (*scp->rndr->draw)(scp, s, e - s + 1, TRUE);
2039 if (and_region(&s, &e, scp->start, scp->end))
2040 (*scp->rndr->draw)(scp, s, e - s + 1, FALSE);
2042 e = scp->xsize*scp->ysize - 1;
2043 if (and_region(&s, &e, scp->start, scp->end))
2044 (*scp->rndr->draw)(scp, s, e - s + 1, FALSE);
2046 (*scp->rndr->draw)(scp, scp->start,
2047 scp->end - scp->start + 1, FALSE);
2050 (*scp->rndr->draw)(scp, scp->start,
2051 scp->end - scp->start + 1, FALSE);
2055 /* we are not to show the cursor and the mouse pointer... */
2058 scp->start = scp->xsize*scp->ysize - 1;
2059 --scp->sc->videoio_in_progress;
2063 /* update cursor image */
2064 if (scp->status & CURSOR_ENABLED) {
2067 /* did cursor move since last time ? */
2068 if (scp->cursor_pos != scp->cursor_oldpos) {
2069 /* do we need to remove old cursor image ? */
2070 if (!and_region(&s, &e, scp->cursor_oldpos, scp->cursor_oldpos))
2071 sc_remove_cursor_image(scp);
2072 sc_draw_cursor_image(scp);
2074 if (and_region(&s, &e, scp->cursor_pos, scp->cursor_pos))
2075 /* cursor didn't move, but has been overwritten */
2076 sc_draw_cursor_image(scp);
2077 else if (scp->sc->flags & SC_BLINK_CURSOR)
2078 /* if it's a blinking cursor, update it */
2079 (*scp->rndr->blink_cursor)(scp, scp->cursor_pos,
2080 sc_inside_cutmark(scp,
2085 #ifndef SC_NO_CUTPASTE
2086 /* update "pseudo" mouse pointer image */
2087 if (scp->sc->flags & SC_MOUSE_ENABLED) {
2088 if (!(scp->status & (MOUSE_VISIBLE | MOUSE_HIDDEN))) {
2089 scp->status &= ~MOUSE_MOVED;
2090 sc_draw_mouse_image(scp);
2093 #endif /* SC_NO_CUTPASTE */
2096 scp->start = scp->xsize*scp->ysize - 1;
2098 --scp->sc->videoio_in_progress;
2103 scsplash_callback(int event, void *arg)
2108 sc = (sc_softc_t *)arg;
2112 if (add_scrn_saver(scsplash_saver) == 0) {
2113 sc->flags &= ~SC_SAVER_FAILED;
2114 run_scrn_saver = TRUE;
2115 if (cold && !(boothowto & (RB_VERBOSE | RB_CONFIG))) {
2116 scsplash_stick(TRUE);
2117 (*current_saver)(sc, TRUE);
2123 if (current_saver == scsplash_saver) {
2124 scsplash_stick(FALSE);
2125 error = remove_scrn_saver(scsplash_saver);
2138 scsplash_saver(sc_softc_t *sc, int show)
2140 static int busy = FALSE;
2149 if (!(sc->flags & SC_SAVER_FAILED)) {
2150 if (!(sc->flags & SC_SCRN_BLANKED))
2151 set_scrn_saver_mode(scp, -1, NULL, 0);
2152 switch (splash(sc->adp, TRUE)) {
2153 case 0: /* succeeded */
2155 case EAGAIN: /* try later */
2156 restore_scrn_saver_mode(scp, FALSE);
2157 sc_touch_scrn_saver(); /* XXX */
2160 sc->flags |= SC_SAVER_FAILED;
2161 scsplash_stick(FALSE);
2162 restore_scrn_saver_mode(scp, TRUE);
2163 kprintf("scsplash_saver(): failed to put up the image\n");
2167 } else if (!sticky_splash) {
2168 if ((sc->flags & SC_SCRN_BLANKED) && (splash(sc->adp, FALSE) == 0))
2169 restore_scrn_saver_mode(scp, TRUE);
2175 add_scrn_saver(void (*this_saver)(sc_softc_t *, int))
2180 if (current_saver != none_saver) {
2181 error = remove_scrn_saver(current_saver);
2186 if (current_saver != none_saver) {
2190 run_scrn_saver = FALSE;
2191 saver_mode = CONS_LKM_SAVER;
2192 current_saver = this_saver;
2197 remove_scrn_saver(void (*this_saver)(sc_softc_t *, int))
2199 if (current_saver != this_saver)
2204 * In order to prevent `current_saver' from being called by
2205 * the timeout routine `scrn_timer()' while we manipulate
2206 * the saver list, we shall set `current_saver' to `none_saver'
2207 * before stopping the current saver, rather than blocking by `splXX()'.
2209 current_saver = none_saver;
2211 stop_scrn_saver(this_saver);
2213 /* unblank all blanked screens */
2214 wait_scrn_saver_stop(NULL);
2219 current_saver = none_saver;
2224 set_scrn_saver_mode(scr_stat *scp, int mode, u_char *pal, int border)
2227 /* assert(scp == scp->sc->cur_scp) */
2229 if (!ISGRAPHSC(scp))
2230 sc_remove_cursor_image(scp);
2231 scp->splash_save_mode = scp->mode;
2232 scp->splash_save_status = scp->status & (GRAPHICS_MODE | PIXEL_MODE);
2233 scp->status &= ~(GRAPHICS_MODE | PIXEL_MODE);
2234 scp->status |= (UNKNOWN_MODE | SAVER_RUNNING);
2235 scp->sc->flags |= SC_SCRN_BLANKED;
2242 if (set_mode(scp) == 0) {
2243 if (scp->sc->adp->va_info.vi_flags & V_INFO_GRAPHICS)
2244 scp->status |= GRAPHICS_MODE;
2245 #ifndef SC_NO_PALETTE_LOADING
2247 load_palette(scp->sc->adp, pal);
2249 sc_set_border(scp, border);
2253 scp->mode = scp->splash_save_mode;
2254 scp->status &= ~(UNKNOWN_MODE | SAVER_RUNNING);
2255 scp->status |= scp->splash_save_status;
2263 restore_scrn_saver_mode(scr_stat *scp, int changemode)
2268 /* assert(scp == scp->sc->cur_scp) */
2271 status = scp->status;
2272 scp->mode = scp->splash_save_mode;
2273 scp->status &= ~(UNKNOWN_MODE | SAVER_RUNNING);
2274 scp->status |= scp->splash_save_status;
2275 scp->sc->flags &= ~SC_SCRN_BLANKED;
2277 if (!ISGRAPHSC(scp))
2278 sc_draw_cursor_image(scp);
2283 if (set_mode(scp) == 0) {
2284 #ifndef SC_NO_PALETTE_LOADING
2285 load_palette(scp->sc->adp, scp->sc->palette);
2292 scp->status = status;
2300 stop_scrn_saver(sc_softc_t *sc, void (*saver)(sc_softc_t *, int))
2302 (*saver)(sc, FALSE);
2303 run_scrn_saver = FALSE;
2304 /* the screen saver may have chosen not to stop after all... */
2305 if (sc->flags & SC_SCRN_BLANKED) {
2309 mark_all(sc->cur_scp);
2310 if (sc->delayed_next_scr)
2311 sc_switch_scr(sc, sc->delayed_next_scr - 1);
2312 wakeup((caddr_t)&scrn_blanked);
2316 wait_scrn_saver_stop(sc_softc_t *sc)
2320 while (scrn_blanked > 0) {
2321 run_scrn_saver = FALSE;
2322 if (sc && !(sc->flags & SC_SCRN_BLANKED)) {
2326 error = tsleep((caddr_t)&scrn_blanked, PCATCH, "scrsav", 0);
2327 /* May return ERESTART */
2331 run_scrn_saver = FALSE;
2334 #endif /* NSPLASH */
2337 sc_touch_scrn_saver(void)
2339 scsplash_stick(FALSE);
2340 run_scrn_saver = FALSE;
2344 sc_switch_scr(sc_softc_t *sc, u_int next_scr)
2349 DPRINTF(5, ("sc0: sc_switch_scr() %d ", next_scr + 1));
2351 /* prevent switch if previously requested */
2352 if (sc->flags & SC_SCRN_VTYLOCK) {
2353 sc_bell(sc->cur_scp, sc->cur_scp->bell_pitch,
2354 sc->cur_scp->bell_duration);
2358 /* delay switch if the screen is blanked or being updated */
2359 if ((sc->flags & SC_SCRN_BLANKED) || sc->write_in_progress
2360 || sc->blink_in_progress || sc->videoio_in_progress) {
2361 sc->delayed_next_scr = next_scr + 1;
2362 sc_touch_scrn_saver();
2363 DPRINTF(5, ("switch delayed\n"));
2367 cur_scp = sc->cur_scp;
2370 * we are in the middle of the vty switching process...
2372 * This may be in the console path, be very careful. pfindn() is
2373 * still going to use a spinlock but it no longer uses tokens so
2376 if (sc->switch_in_progress &&
2377 (cur_scp->smode.mode == VT_PROCESS) &&
2379 if (cur_scp->proc != pfindn(cur_scp->pid)) {
2381 * The controlling process has died!!. Do some clean up.
2382 * NOTE:`cur_scp->proc' and `cur_scp->smode.mode'
2383 * are not reset here yet; they will be cleared later.
2385 DPRINTF(5, ("cur_scp controlling process %d died, ", cur_scp->pid));
2386 if (cur_scp->status & SWITCH_WAIT_REL) {
2388 * Force the previous switch to finish, but return now
2392 DPRINTF(5, ("reset WAIT_REL, "));
2393 finish_vt_rel(cur_scp, TRUE);
2394 DPRINTF(5, ("finishing previous switch\n"));
2396 } else if (cur_scp->status & SWITCH_WAIT_ACQ) {
2397 /* let's assume screen switch has been completed. */
2398 DPRINTF(5, ("reset WAIT_ACQ, "));
2399 finish_vt_acq(cur_scp);
2402 * We are in between screen release and acquisition, and
2403 * reached here via scgetc() or scrn_timer() which has
2404 * interrupted exchange_scr(). Don't do anything stupid.
2406 DPRINTF(5, ("waiting nothing, "));
2410 * The controlling process is alive, but not responding...
2411 * It is either buggy or it may be just taking time.
2412 * The following code is a gross kludge to cope with this
2413 * problem for which there is no clean solution. XXX
2415 if (cur_scp->status & SWITCH_WAIT_REL) {
2416 switch (sc->switch_in_progress++) {
2420 DPRINTF(5, ("sending relsig again, "));
2421 signal_vt_rel(cur_scp);
2428 * Act as if the controlling program returned
2432 DPRINTF(5, ("force reset WAIT_REL, "));
2433 finish_vt_rel(cur_scp, FALSE);
2434 DPRINTF(5, ("act as if VT_FALSE was seen\n"));
2437 } else if (cur_scp->status & SWITCH_WAIT_ACQ) {
2438 switch (sc->switch_in_progress++) {
2442 DPRINTF(5, ("sending acqsig again, "));
2443 signal_vt_acq(cur_scp);
2449 /* clear the flag and finish the previous switch */
2450 DPRINTF(5, ("force reset WAIT_ACQ, "));
2451 finish_vt_acq(cur_scp);
2459 * Return error if an invalid argument is given, or vty switch
2460 * is still in progress.
2462 if ((next_scr < sc->first_vty) || (next_scr >= sc->first_vty + sc->vtys)
2463 || sc->switch_in_progress) {
2464 sc_bell(cur_scp, bios_value.bell_pitch, BELL_DURATION);
2465 DPRINTF(5, ("error 1\n"));
2470 * Don't allow switching away from the graphics mode vty
2471 * if the switch mode is VT_AUTO, unless the next vty is the same
2472 * as the current or the current vty has been closed (but showing).
2474 tp = VIRTUAL_TTY(sc, cur_scp->index);
2475 if ((cur_scp->index != next_scr)
2477 && (cur_scp->smode.mode == VT_AUTO)
2478 && ISGRAPHSC(cur_scp)) {
2479 sc_bell(cur_scp, bios_value.bell_pitch, BELL_DURATION);
2480 DPRINTF(5, ("error, graphics mode\n"));
2485 * Is the wanted vty open? Don't allow switching to a closed vty.
2486 * If we are in DDB, don't switch to a vty in the VT_PROCESS mode.
2487 * Note that we always allow the user to switch to the kernel
2488 * console even if it is closed.
2490 if ((sc_console == NULL) || (next_scr != sc_console->index)) {
2491 tp = VIRTUAL_TTY(sc, next_scr);
2492 if (!ISTTYOPEN(tp)) {
2493 sc_bell(cur_scp, bios_value.bell_pitch, BELL_DURATION);
2494 DPRINTF(5, ("error 2, requested vty isn't open!\n"));
2497 if ((debugger > 0) && (SC_STAT(tp->t_dev)->smode.mode == VT_PROCESS)) {
2498 DPRINTF(5, ("error 3, requested vty is in the VT_PROCESS mode\n"));
2503 /* this is the start of vty switching process... */
2504 ++sc->switch_in_progress;
2505 sc->delayed_next_scr = 0;
2506 sc->old_scp = cur_scp;
2507 sc->new_scp = SC_STAT(SC_DEV(sc, next_scr));
2508 if (sc->new_scp == sc->old_scp) {
2509 sc->switch_in_progress = 0;
2510 wakeup((caddr_t)&sc->new_scp->smode);
2511 DPRINTF(5, ("switch done (new == old)\n"));
2515 /* has controlling process died? */
2516 vt_proc_alive(sc->old_scp);
2517 vt_proc_alive(sc->new_scp);
2519 /* wait for the controlling process to release the screen, if necessary */
2520 if (signal_vt_rel(sc->old_scp)) {
2524 /* go set up the new vty screen */
2527 /* wake up processes waiting for this vty */
2528 wakeup((caddr_t)&sc->cur_scp->smode);
2530 /* wait for the controlling process to acknowledge, if necessary */
2531 if (signal_vt_acq(sc->cur_scp)) {
2535 sc->switch_in_progress = 0;
2536 if (sc->unit == sc_console_unit)
2537 cons_unavail = FALSE;
2538 DPRINTF(5, ("switch done\n"));
2544 do_switch_scr(sc_softc_t *sc)
2546 lwkt_gettoken(&tty_token);
2547 vt_proc_alive(sc->new_scp);
2550 /* sc->cur_scp == sc->new_scp */
2551 wakeup((caddr_t)&sc->cur_scp->smode);
2553 /* wait for the controlling process to acknowledge, if necessary */
2554 if (!signal_vt_acq(sc->cur_scp)) {
2555 sc->switch_in_progress = 0;
2556 if (sc->unit == sc_console_unit)
2557 cons_unavail = FALSE;
2559 lwkt_reltoken(&tty_token);
2563 vt_proc_alive(scr_stat *scp)
2565 lwkt_gettoken(&tty_token);
2567 if (scp->proc == pfindn(scp->pid)) {
2568 lwkt_reltoken(&tty_token);
2572 scp->smode.mode = VT_AUTO;
2573 DPRINTF(5, ("vt controlling process %d died\n", scp->pid));
2575 lwkt_reltoken(&tty_token);
2580 signal_vt_rel(scr_stat *scp)
2584 lwkt_gettoken(&tty_token);
2585 if (scp->smode.mode != VT_PROCESS) {
2586 lwkt_reltoken(&tty_token);
2589 scp->status |= SWITCH_WAIT_REL;
2592 ksignal(p, scp->smode.relsig);
2594 DPRINTF(5, ("sending relsig to %d\n", scp->pid));
2595 lwkt_reltoken(&tty_token);
2601 signal_vt_acq(scr_stat *scp)
2605 lwkt_gettoken(&tty_token);
2606 if (scp->smode.mode != VT_PROCESS) {
2607 lwkt_reltoken(&tty_token);
2610 if (scp->sc->unit == sc_console_unit)
2611 cons_unavail = TRUE;
2612 scp->status |= SWITCH_WAIT_ACQ;
2615 ksignal(p, scp->smode.acqsig);
2617 DPRINTF(5, ("sending acqsig to %d\n", scp->pid));
2618 lwkt_reltoken(&tty_token);
2624 finish_vt_rel(scr_stat *scp, int release)
2626 lwkt_gettoken(&tty_token);
2627 if (scp == scp->sc->old_scp && scp->status & SWITCH_WAIT_REL) {
2628 scp->status &= ~SWITCH_WAIT_REL;
2630 do_switch_scr(scp->sc);
2632 scp->sc->switch_in_progress = 0;
2633 lwkt_reltoken(&tty_token);
2636 lwkt_reltoken(&tty_token);
2641 finish_vt_acq(scr_stat *scp)
2643 lwkt_gettoken(&tty_token);
2644 if (scp == scp->sc->new_scp && scp->status & SWITCH_WAIT_ACQ) {
2645 scp->status &= ~SWITCH_WAIT_ACQ;
2646 scp->sc->switch_in_progress = 0;
2647 lwkt_reltoken(&tty_token);
2650 lwkt_reltoken(&tty_token);
2655 exchange_scr(sc_softc_t *sc)
2659 lwkt_gettoken(&tty_token);
2660 /* save the current state of video and keyboard */
2661 sc_move_cursor(sc->old_scp, sc->old_scp->xpos, sc->old_scp->ypos);
2662 if (!ISGRAPHSC(sc->old_scp))
2663 sc_remove_cursor_image(sc->old_scp);
2664 if (sc->old_scp->kbd_mode == K_XLATE)
2665 save_kbd_state(sc->old_scp, TRUE);
2667 /* set up the video for the new screen */
2668 scp = sc->cur_scp = sc->new_scp;
2669 if (sc->old_scp->mode != scp->mode || ISUNKNOWNSC(sc->old_scp))
2672 sc_vtb_init(&scp->scr, VTB_FRAMEBUFFER, scp->xsize, scp->ysize,
2673 (void *)sc->adp->va_window, FALSE);
2674 scp->status |= MOUSE_HIDDEN;
2675 sc_update_render(scp); /* Switch to kms renderer if necessary */
2676 sc_move_cursor(scp, scp->xpos, scp->ypos);
2677 if (!ISGRAPHSC(scp))
2678 sc_set_cursor_image(scp);
2679 #ifndef SC_NO_PALETTE_LOADING
2680 if (ISGRAPHSC(sc->old_scp))
2681 load_palette(sc->adp, sc->palette);
2683 sc_set_border(scp, scp->border);
2685 /* set up the keyboard for the new screen */
2686 if (sc->old_scp->kbd_mode != scp->kbd_mode)
2687 kbd_ioctl(sc->kbd, KDSKBMODE, (caddr_t)&scp->kbd_mode);
2688 update_kbd_state(scp, scp->status, LOCK_MASK, TRUE);
2691 if (scp->sc->fbi != NULL) {
2692 scp->sc->fbi->restore(scp->sc->fbi->cookie);
2694 lwkt_reltoken(&tty_token);
2698 sc_puts(scr_stat *scp, u_char *buf, int len)
2701 /* make screensaver happy */
2702 if (!sticky_splash && scp == scp->sc->cur_scp)
2703 run_scrn_saver = FALSE;
2707 (*scp->tsw->te_puts)(scp, buf, len);
2709 if (scp->sc->delayed_next_scr)
2710 sc_switch_scr(scp->sc, scp->sc->delayed_next_scr - 1);
2715 sc_draw_cursor_image(scr_stat *scp)
2717 /* assert(scp == scp->sc->cur_scp); */
2718 ++scp->sc->videoio_in_progress;
2719 (*scp->rndr->draw_cursor)(scp, scp->cursor_pos,
2720 scp->sc->flags & SC_BLINK_CURSOR, TRUE,
2721 sc_inside_cutmark(scp, scp->cursor_pos));
2722 scp->cursor_oldpos = scp->cursor_pos;
2723 --scp->sc->videoio_in_progress;
2727 sc_remove_cursor_image(scr_stat *scp)
2729 /* assert(scp == scp->sc->cur_scp); */
2730 ++scp->sc->videoio_in_progress;
2731 (*scp->rndr->draw_cursor)(scp, scp->cursor_oldpos,
2732 scp->sc->flags & SC_BLINK_CURSOR, FALSE,
2733 sc_inside_cutmark(scp, scp->cursor_oldpos));
2734 --scp->sc->videoio_in_progress;
2738 update_cursor_image(scr_stat *scp)
2742 if (scp->sc->flags & SC_CHAR_CURSOR) {
2743 scp->cursor_base = imax(0, scp->sc->cursor_base);
2744 scp->cursor_height = imin(scp->sc->cursor_height, scp->font_size);
2746 scp->cursor_base = 0;
2747 scp->cursor_height = scp->font_size;
2749 blink = scp->sc->flags & SC_BLINK_CURSOR;
2751 /* assert(scp == scp->sc->cur_scp); */
2752 ++scp->sc->videoio_in_progress;
2753 (*scp->rndr->draw_cursor)(scp, scp->cursor_oldpos, blink, FALSE,
2754 sc_inside_cutmark(scp, scp->cursor_pos));
2755 (*scp->rndr->set_cursor)(scp, scp->cursor_base, scp->cursor_height, blink);
2756 (*scp->rndr->draw_cursor)(scp, scp->cursor_pos, blink, TRUE,
2757 sc_inside_cutmark(scp, scp->cursor_pos));
2758 --scp->sc->videoio_in_progress;
2762 sc_set_cursor_image(scr_stat *scp)
2764 if (scp->sc->flags & SC_CHAR_CURSOR) {
2765 scp->cursor_base = imax(0, scp->sc->cursor_base);
2766 scp->cursor_height = imin(scp->sc->cursor_height, scp->font_size);
2768 scp->cursor_base = 0;
2769 scp->cursor_height = scp->font_size;
2772 /* assert(scp == scp->sc->cur_scp); */
2773 ++scp->sc->videoio_in_progress;
2774 (*scp->rndr->set_cursor)(scp, scp->cursor_base, scp->cursor_height,
2775 scp->sc->flags & SC_BLINK_CURSOR);
2776 --scp->sc->videoio_in_progress;
2780 scinit(int unit, int flags)
2783 * When syscons is being initialized as the kernel console, malloc()
2784 * is not yet functional, because various kernel structures has not been
2785 * fully initialized yet. Therefore, we need to declare the following
2786 * static buffers for the console. This is less than ideal,
2787 * but is necessry evil for the time being. XXX
2789 static scr_stat main_console;
2790 static u_short sc_buffer[ROW*COL]; /* XXX */
2791 #ifndef SC_NO_FONT_LOADING
2792 static u_char font_8[256*8];
2793 static u_char font_14[256*14];
2794 static u_char font_16[256*16];
2799 video_adapter_t *adp;
2804 /* one time initialization */
2805 if (init_done == COLD)
2806 sc_get_bios_values(&bios_value);
2810 * Allocate resources. Even if we are being called for the second
2811 * time, we must allocate them again, because they might have
2814 sc = sc_get_softc(unit, flags & SC_KERNEL_CONSOLE);
2816 if (sc->adapter >= 0) {
2817 vid_release(sc->adp, (void *)&sc->adapter);
2821 if (sc->keyboard >= 0) {
2822 DPRINTF(5, ("sc%d: releasing kbd%d\n", unit, sc->keyboard));
2823 i = kbd_release(sc->kbd, (void *)&sc->keyboard);
2824 DPRINTF(5, ("sc%d: kbd_release returned %d\n", unit, i));
2825 if (sc->kbd != NULL) {
2826 DPRINTF(5, ("sc%d: kbd != NULL!, index:%d, unit:%d, flags:0x%x\n",
2827 unit, sc->kbd->kb_index, sc->kbd->kb_unit, sc->kbd->kb_flags));
2831 sc->adapter = vid_allocate("*", unit, (void *)&sc->adapter);
2832 sc->adp = vid_get_adapter(sc->adapter);
2833 /* assert((sc->adapter >= 0) && (sc->adp != NULL)) */
2834 sc->keyboard = sc_allocate_keyboard(sc, unit);
2835 DPRINTF(1, ("sc%d: keyboard %d\n", unit, sc->keyboard));
2836 sc->kbd = kbd_get_keyboard(sc->keyboard);
2837 if (sc->kbd != NULL) {
2838 DPRINTF(1, ("sc%d: kbd index:%d, unit:%d, flags:0x%x\n",
2839 unit, sc->kbd->kb_index, sc->kbd->kb_unit, sc->kbd->kb_flags));
2842 if (!(sc->flags & SC_INIT_DONE) || (adp != sc->adp)) {
2844 sc->initial_mode = sc->adp->va_initial_mode;
2846 #ifndef SC_NO_FONT_LOADING
2847 if (flags & SC_KERNEL_CONSOLE) {
2848 sc->font_8 = font_8;
2849 sc->font_14 = font_14;
2850 sc->font_16 = font_16;
2851 } else if (sc->font_8 == NULL) {
2852 /* assert(sc_malloc) */
2853 sc->font_8 = kmalloc(sizeof(font_8), M_SYSCONS, M_WAITOK);
2854 sc->font_14 = kmalloc(sizeof(font_14), M_SYSCONS, M_WAITOK);
2855 sc->font_16 = kmalloc(sizeof(font_16), M_SYSCONS, M_WAITOK);
2859 lwkt_gettoken(&tty_token);
2860 /* extract the hardware cursor location and hide the cursor for now */
2861 (*vidsw[sc->adapter]->read_hw_cursor)(sc->adp, &col, &row);
2862 (*vidsw[sc->adapter]->set_hw_cursor)(sc->adp, -1, -1);
2863 lwkt_reltoken(&tty_token);
2865 /* set up the first console */
2866 sc->first_vty = unit*MAXCONS;
2867 sc->vtys = MAXCONS; /* XXX: should be configurable */
2868 if (flags & SC_KERNEL_CONSOLE) {
2869 scp = &main_console;
2870 sc->console_scp = scp;
2871 init_scp(sc, sc->first_vty, scp);
2872 sc_vtb_init(&scp->vtb, VTB_MEMORY, scp->xsize, scp->ysize,
2873 (void *)sc_buffer, FALSE);
2874 if (sc_init_emulator(scp, SC_DFLT_TERM))
2875 sc_init_emulator(scp, "*");
2876 (*scp->tsw->te_default_attr)(scp,
2877 kernel_default.std_color,
2878 kernel_default.rev_color);
2880 /* assert(sc_malloc) */
2881 sc->dev = kmalloc(sizeof(cdev_t)*sc->vtys, M_SYSCONS, M_WAITOK | M_ZERO);
2883 sc->dev[0] = make_dev(&sc_ops, unit*MAXCONS, UID_ROOT,
2884 GID_WHEEL, 0600, "ttyv%r", unit*MAXCONS);
2886 sc->dev[0]->si_tty = ttymalloc(sc->dev[0]->si_tty);
2887 scp = alloc_scp(sc, sc->first_vty);
2888 sc->dev[0]->si_drv1 = scp;
2892 /* copy screen to temporary buffer */
2893 sc_vtb_init(&scp->scr, VTB_FRAMEBUFFER, scp->xsize, scp->ysize,
2894 (void *)scp->sc->adp->va_window, FALSE);
2896 sc_vtb_copy(&scp->scr, 0, &scp->vtb, 0, scp->xsize*scp->ysize);
2898 /* move cursors to the initial positions */
2899 if (col >= scp->xsize)
2901 if (row >= scp->ysize)
2902 row = scp->ysize - 1;
2905 scp->cursor_pos = scp->cursor_oldpos = row*scp->xsize + col;
2906 if (bios_value.cursor_end < scp->font_size)
2907 sc->cursor_base = scp->font_size - bios_value.cursor_end - 1;
2909 sc->cursor_base = 0;
2910 i = bios_value.cursor_end - bios_value.cursor_start + 1;
2911 sc->cursor_height = imin(i, scp->font_size);
2912 #ifndef SC_NO_SYSMOUSE
2913 sc_mouse_move(scp, scp->xpixel/2, scp->ypixel/2);
2915 if (!ISGRAPHSC(scp)) {
2916 sc_set_cursor_image(scp);
2917 sc_draw_cursor_image(scp);
2920 /* save font and palette */
2921 #ifndef SC_NO_FONT_LOADING
2922 sc->fonts_loaded = 0;
2923 if (ISFONTAVAIL(sc->adp->va_flags)) {
2925 bcopy(dflt_font_8, sc->font_8, sizeof(dflt_font_8));
2926 bcopy(dflt_font_14, sc->font_14, sizeof(dflt_font_14));
2927 bcopy(dflt_font_16, sc->font_16, sizeof(dflt_font_16));
2928 sc->fonts_loaded = FONT_16 | FONT_14 | FONT_8;
2929 if (scp->font_size < 14) {
2930 sc_load_font(scp, 0, 8, sc->font_8, 0, 256);
2931 } else if (scp->font_size >= 16) {
2932 sc_load_font(scp, 0, 16, sc->font_16, 0, 256);
2934 sc_load_font(scp, 0, 14, sc->font_14, 0, 256);
2936 #else /* !SC_DFLT_FONT */
2937 if (scp->font_size < 14) {
2938 sc_save_font(scp, 0, 8, sc->font_8, 0, 256);
2939 sc->fonts_loaded = FONT_8;
2940 } else if (scp->font_size >= 16) {
2941 sc_save_font(scp, 0, 16, sc->font_16, 0, 256);
2942 sc->fonts_loaded = FONT_16;
2944 sc_save_font(scp, 0, 14, sc->font_14, 0, 256);
2945 sc->fonts_loaded = FONT_14;
2947 #endif /* SC_DFLT_FONT */
2948 /* FONT KLUDGE: always use the font page #0. XXX */
2949 sc_show_font(scp, 0);
2951 #endif /* !SC_NO_FONT_LOADING */
2953 #ifndef SC_NO_PALETTE_LOADING
2954 save_palette(sc->adp, sc->palette);
2958 if (!(sc->flags & SC_SPLASH_SCRN) && (flags & SC_KERNEL_CONSOLE)) {
2959 /* we are ready to put up the splash image! */
2960 splash_init(sc->adp, scsplash_callback, sc);
2961 sc->flags |= SC_SPLASH_SCRN;
2963 #endif /* NSPLASH */
2966 /* the rest is not necessary, if we have done it once */
2967 if (sc->flags & SC_INIT_DONE) {
2971 /* initialize mapscrn arrays to a one to one map */
2972 for (i = 0; i < sizeof(sc->scr_map); i++)
2973 sc->scr_map[i] = sc->scr_rmap[i] = i;
2975 sc->flags |= SC_INIT_DONE;
2979 scterm(int unit, int flags)
2984 sc = sc_get_softc(unit, flags & SC_KERNEL_CONSOLE);
2986 return; /* shouldn't happen */
2988 lwkt_gettoken(&tty_token);
2990 /* this console is no longer available for the splash screen */
2991 if (sc->flags & SC_SPLASH_SCRN) {
2992 splash_term(sc->adp);
2993 sc->flags &= ~SC_SPLASH_SCRN;
2995 #endif /* NSPLASH */
2998 /* move the hardware cursor to the upper-left corner */
2999 (*vidsw[sc->adapter]->set_hw_cursor)(sc->adp, 0, 0);
3002 /* release the keyboard and the video card */
3003 if (sc->keyboard >= 0)
3004 kbd_release(sc->kbd, &sc->keyboard);
3005 if (sc->adapter >= 0)
3006 vid_release(sc->adp, &sc->adapter);
3009 * Stop the terminal emulator, if any. If operating on the
3010 * kernel console sc->dev may not be setup yet.
3012 if (flags & SC_KERNEL_CONSOLE)
3013 scp = sc->console_scp;
3015 scp = SC_STAT(sc->dev[0]);
3017 (*scp->tsw->te_term)(scp, &scp->ts);
3018 if (scp->ts != NULL)
3019 kfree(scp->ts, M_SYSCONS);
3021 /* clear the structure */
3022 if (!(flags & SC_KERNEL_CONSOLE)) {
3023 /* XXX: We need delete_dev() for this */
3024 kfree(sc->dev, M_SYSCONS);
3026 /* XXX: We need a ttyunregister for this */
3027 kfree(sc->tty, M_SYSCONS);
3029 #ifndef SC_NO_FONT_LOADING
3030 kfree(sc->font_8, M_SYSCONS);
3031 kfree(sc->font_14, M_SYSCONS);
3032 kfree(sc->font_16, M_SYSCONS);
3034 /* XXX vtb, history */
3036 bzero(sc, sizeof(*sc));
3039 lwkt_reltoken(&tty_token);
3043 scshutdown(void *arg, int howto)
3045 /* assert(sc_console != NULL) */
3047 lwkt_gettoken(&tty_token);
3049 sc_touch_scrn_saver();
3050 if (!cold && sc_console
3051 && sc_console->sc->cur_scp->smode.mode == VT_AUTO
3052 && sc_console->smode.mode == VT_AUTO) {
3053 sc_switch_scr(sc_console->sc, sc_console->index);
3055 shutdown_in_progress = TRUE;
3057 lwkt_reltoken(&tty_token);
3061 sc_clean_up(scr_stat *scp)
3065 #endif /* NSPLASH */
3067 lwkt_gettoken(&tty_token);
3068 if (scp->sc->flags & SC_SCRN_BLANKED) {
3069 sc_touch_scrn_saver();
3071 if ((error = wait_scrn_saver_stop(scp->sc))) {
3072 lwkt_reltoken(&tty_token);
3075 #endif /* NSPLASH */
3077 scp->status |= MOUSE_HIDDEN;
3078 sc_remove_mouse_image(scp);
3079 sc_remove_cutmarking(scp);
3080 lwkt_reltoken(&tty_token);
3085 sc_alloc_scr_buffer(scr_stat *scp, int wait, int discard)
3090 lwkt_gettoken(&tty_token);
3092 sc_vtb_init(&new, VTB_MEMORY, scp->xsize, scp->ysize, NULL, wait);
3093 if (!discard && (old.vtb_flags & VTB_VALID)) {
3094 /* retain the current cursor position and buffer contants */
3095 scp->cursor_oldpos = scp->cursor_pos;
3097 * This works only if the old buffer has the same size as or larger
3098 * than the new one. XXX
3100 sc_vtb_copy(&old, 0, &new, 0, scp->xsize*scp->ysize);
3104 sc_vtb_destroy(&old);
3107 #ifndef SC_NO_SYSMOUSE
3108 /* move the mouse cursor at the center of the screen */
3109 sc_mouse_move(scp, scp->xpixel / 2, scp->ypixel / 2);
3111 lwkt_reltoken(&tty_token);
3115 alloc_scp(sc_softc_t *sc, int vty)
3119 /* assert(sc_malloc) */
3121 scp = kmalloc(sizeof(scr_stat), M_SYSCONS, M_WAITOK);
3122 init_scp(sc, vty, scp);
3124 sc_alloc_scr_buffer(scp, TRUE, TRUE);
3125 if (sc_init_emulator(scp, SC_DFLT_TERM))
3126 sc_init_emulator(scp, "*");
3128 #ifndef SC_NO_CUTPASTE
3129 sc_alloc_cut_buffer(scp, TRUE);
3132 #ifndef SC_NO_HISTORY
3133 sc_alloc_history_buffer(scp, 0, 0, TRUE);
3139 * NOTE: Must be called with tty_token held.
3142 init_scp(sc_softc_t *sc, int vty, scr_stat *scp)
3146 bzero(scp, sizeof(*scp));
3151 scp->mode = sc->initial_mode;
3152 callout_init_mp(&scp->blink_screen_ch);
3153 lwkt_gettoken(&tty_token);
3154 (*vidsw[sc->adapter]->get_info)(sc->adp, scp->mode, &info);
3155 lwkt_reltoken(&tty_token);
3156 if (info.vi_flags & V_INFO_GRAPHICS) {
3157 scp->status |= GRAPHICS_MODE;
3158 scp->xpixel = info.vi_width;
3159 scp->ypixel = info.vi_height;
3160 scp->xsize = info.vi_width/8;
3161 scp->ysize = info.vi_height/info.vi_cheight;
3165 scp->xsize = info.vi_width;
3166 scp->ysize = info.vi_height;
3167 scp->xpixel = scp->xsize*8;
3168 scp->ypixel = scp->ysize*info.vi_cheight;
3169 if (info.vi_cheight < 14) {
3171 #ifndef SC_NO_FONT_LOADING
3172 scp->font = sc->font_8;
3176 } else if (info.vi_cheight >= 16) {
3177 scp->font_size = 16;
3178 #ifndef SC_NO_FONT_LOADING
3179 scp->font = sc->font_16;
3184 scp->font_size = 14;
3185 #ifndef SC_NO_FONT_LOADING
3186 scp->font = sc->font_14;
3192 scp->xoff = scp->yoff = 0;
3193 scp->xpos = scp->ypos = 0;
3195 if (scp->fbi != NULL) {
3196 scp->xpixel = scp->fbi->width;
3197 scp->ypixel = scp->fbi->height;
3198 scp->xsize = scp->xpixel / 8;
3199 scp->ysize = scp->ypixel / scp->font_size;
3201 sc_vtb_init(&scp->vtb, VTB_MEMORY, 0, 0, NULL, FALSE);
3202 sc_vtb_init(&scp->scr, VTB_FRAMEBUFFER, 0, 0, NULL, FALSE);
3203 scp->start = scp->xsize * scp->ysize - 1;
3208 scp->border = BG_BLACK;
3209 scp->cursor_base = sc->cursor_base;
3210 scp->cursor_height = imin(sc->cursor_height, scp->font_size);
3211 scp->mouse_cut_start = scp->xsize*scp->ysize;
3212 scp->mouse_cut_end = -1;
3213 scp->mouse_signal = 0;
3215 scp->mouse_proc = NULL;
3216 scp->kbd_mode = K_XLATE;
3217 scp->bell_pitch = bios_value.bell_pitch;
3218 scp->bell_duration = BELL_DURATION;
3219 scp->status |= (bios_value.shift_state & NLKED);
3220 scp->status |= CURSOR_ENABLED | MOUSE_HIDDEN;
3223 scp->smode.mode = VT_AUTO;
3224 scp->history = NULL;
3225 scp->history_pos = 0;
3226 scp->history_size = 0;
3230 sc_init_emulator(scr_stat *scp, char *name)
3237 if (name == NULL) /* if no name is given, use the current emulator */
3239 else /* ...otherwise find the named emulator */
3240 sw = sc_term_match(name);
3246 if (strcmp(sw->te_renderer, "*") != 0) {
3247 rndr = sc_render_match(scp, sw->te_renderer, scp->model);
3249 if (rndr == NULL && scp->sc->fbi != NULL) {
3250 rndr = sc_render_match(scp, "kms", scp->model);
3253 rndr = sc_render_match(scp, scp->sc->adp->va_name, scp->model);
3259 if (sw == scp->tsw) {
3260 error = (*sw->te_init)(scp, &scp->ts, SC_TE_WARM_INIT);
3262 sc_clear_screen(scp);
3263 /* assert(error == 0); */
3267 if (sc_malloc && (sw->te_size > 0))
3268 p = kmalloc(sw->te_size, M_SYSCONS, M_NOWAIT);
3271 error = (*sw->te_init)(scp, &p, SC_TE_COLD_INIT);
3277 (*scp->tsw->te_term)(scp, &scp->ts);
3278 if (scp->ts != NULL)
3279 kfree(scp->ts, M_SYSCONS);
3285 (*sw->te_default_attr)(scp, user_default.std_color, user_default.rev_color);
3286 sc_clear_screen(scp);
3292 * scgetc(flags) - get character from keyboard.
3293 * If flags & SCGETC_CN, then avoid harmful side effects.
3294 * If flags & SCGETC_NONBLOCK, then wait until a key is pressed, else
3295 * return NOKEY if there is nothing there.
3298 scgetc(sc_softc_t *sc, u_int flags)
3301 #ifndef SC_NO_HISTORY
3309 lwkt_gettoken(&tty_token);
3310 if (sc->kbd == NULL) {
3311 lwkt_reltoken(&tty_token);
3317 /* I don't like this, but... XXX */
3318 if (flags & SCGETC_CN) {
3320 sccnupdate(sc->cur_scp);
3325 /* first see if there is something in the keyboard port */
3327 c = kbd_read_char(sc->kbd, !(flags & SCGETC_NONBLOCK));
3329 if (!(flags & SCGETC_CN))
3330 sc_bell(scp, bios_value.bell_pitch, BELL_DURATION);
3331 } else if (c == NOKEY) {
3332 lwkt_reltoken(&tty_token);
3339 /* make screensaver happy */
3341 sc_touch_scrn_saver();
3343 if (!(flags & SCGETC_CN))
3344 /* do the /dev/random device a favour */
3345 add_keyboard_randomness(c);
3347 if (scp->kbd_mode != K_XLATE) {
3348 lwkt_reltoken(&tty_token);
3352 /* if scroll-lock pressed allow history browsing */
3353 if (!ISGRAPHSC(scp) && scp->history && scp->status & SLKED) {
3355 scp->status &= ~CURSOR_ENABLED;
3356 sc_remove_cursor_image(scp);
3358 #ifndef SC_NO_HISTORY
3359 if (!(scp->status & BUFFER_SAVED)) {
3360 scp->status |= BUFFER_SAVED;
3364 /* FIXME: key codes */
3365 case SPCLKEY | FKEY | F(49): /* home key */
3366 sc_remove_cutmarking(scp);
3370 case SPCLKEY | FKEY | F(57): /* end key */
3371 sc_remove_cutmarking(scp);
3375 case SPCLKEY | FKEY | F(50): /* up arrow key */
3376 sc_remove_cutmarking(scp);
3377 if (sc_hist_up_line(scp))
3378 if (!(flags & SCGETC_CN))
3379 sc_bell(scp, bios_value.bell_pitch, BELL_DURATION);
3382 case SPCLKEY | FKEY | F(58): /* down arrow key */
3383 sc_remove_cutmarking(scp);
3384 if (sc_hist_down_line(scp))
3385 if (!(flags & SCGETC_CN))
3386 sc_bell(scp, bios_value.bell_pitch, BELL_DURATION);
3389 case SPCLKEY | FKEY | F(51): /* page up key */
3390 sc_remove_cutmarking(scp);
3391 for (i=0; i<scp->ysize; i++) {
3392 if (sc_hist_up_line(scp)) {
3393 if (!(flags & SCGETC_CN))
3394 sc_bell(scp, bios_value.bell_pitch, BELL_DURATION);
3400 case SPCLKEY | FKEY | F(59): /* page down key */
3401 sc_remove_cutmarking(scp);
3402 for (i=0; i<scp->ysize; i++) {
3403 if (sc_hist_down_line(scp)) {
3404 if (!(flags & SCGETC_CN))
3405 sc_bell(scp, bios_value.bell_pitch, BELL_DURATION);
3411 #endif /* SC_NO_HISTORY */
3415 * Process and consume special keys here. Return a plain char code
3416 * or a char code with the META flag or a function key code.
3420 /* goto next_code */
3425 switch (KEYCHAR(c)) {
3427 case NLK: case CLK: case ALK:
3430 kbd_ioctl(sc->kbd, KDGKBSTATE, (caddr_t)&f);
3432 scp->status |= SLKED;
3434 if (scp->status & SLKED) {
3435 scp->status &= ~SLKED;
3436 #ifndef SC_NO_HISTORY
3437 if (scp->status & BUFFER_SAVED) {
3438 if (!sc_hist_restore(scp))
3439 sc_remove_cutmarking(scp);
3440 scp->status &= ~BUFFER_SAVED;
3441 scp->status |= CURSOR_ENABLED;
3442 sc_draw_cursor_image(scp);
3444 tp = VIRTUAL_TTY(sc, scp->index);
3452 /* NON-LOCKING KEYS */
3454 case LSH: case RSH: case LCTR: case RCTR:
3455 case LALT: case RALT: case ASH: case META:
3459 if (!(sc->flags & SC_SCRN_BLANKED)) {
3460 lwkt_reltoken(&tty_token);
3467 /* force activatation/deactivation of the screen saver */
3468 if (!(sc->flags & SC_SCRN_BLANKED)) {
3469 run_scrn_saver = TRUE;
3470 sc->scrn_time_stamp -= scrn_blank_time;
3474 * While devices are being probed, the screen saver need
3475 * to be invoked explictly. XXX
3477 if (sc->flags & SC_SCRN_BLANKED) {
3478 scsplash_stick(FALSE);
3479 stop_scrn_saver(sc, current_saver);
3481 if (!ISGRAPHSC(scp)) {
3482 scsplash_stick(TRUE);
3483 (*current_saver)(sc, TRUE);
3487 #endif /* NSPLASH */
3491 #ifndef SC_DISABLE_REBOOT
3497 #ifndef SC_DISABLE_REBOOT
3498 shutdown_nice(RB_HALT);
3503 #ifndef SC_DISABLE_REBOOT
3504 shutdown_nice(RB_HALT|RB_POWEROFF);
3508 #if __i386__ && NAPM > 0
3510 apm_suspend(PMST_SUSPEND);
3513 apm_suspend(PMST_STANDBY);
3522 #ifndef SC_DISABLE_DDBKEY
3524 lwkt_reltoken(&tty_token);
3525 Debugger("manual escape to debugger");
3526 lwkt_gettoken(&tty_token);
3528 kprintf("No debugger in kernel\n");
3530 #else /* SC_DISABLE_DDBKEY */
3532 #endif /* SC_DISABLE_DDBKEY */
3536 if (enable_panic_key)
3537 panic("Forced by the panic key");
3541 this_scr = scp->index;
3542 for (i = (this_scr - sc->first_vty + 1)%sc->vtys;
3543 sc->first_vty + i != this_scr;
3544 i = (i + 1)%sc->vtys) {
3545 struct tty *tp = VIRTUAL_TTY(sc, sc->first_vty + i);
3546 if (ISTTYOPEN(tp)) {
3548 sc_switch_scr(scp->sc, sc->first_vty + i);
3556 this_scr = scp->index;
3557 for (i = (this_scr - sc->first_vty + sc->vtys - 1)%sc->vtys;
3558 sc->first_vty + i != this_scr;
3559 i = (i + sc->vtys - 1)%sc->vtys) {
3560 struct tty *tp = VIRTUAL_TTY(sc, sc->first_vty + i);
3561 if (ISTTYOPEN(tp)) {
3563 sc_switch_scr(scp->sc, sc->first_vty + i);
3571 if (KEYCHAR(c) >= F_SCR && KEYCHAR(c) <= L_SCR) {
3573 sc_switch_scr(scp->sc, sc->first_vty + KEYCHAR(c) - F_SCR);
3577 /* assert(c & FKEY) */
3578 if (!(sc->flags & SC_SCRN_BLANKED)) {
3579 lwkt_reltoken(&tty_token);
3584 /* goto next_code */
3586 /* regular keys (maybe MKEY is set) */
3587 if (!(sc->flags & SC_SCRN_BLANKED)) {
3588 lwkt_reltoken(&tty_token);
3598 scmmap(struct dev_mmap_args *ap)
3602 lwkt_gettoken(&tty_token);
3603 scp = SC_STAT(ap->a_head.a_dev);
3604 if (scp != scp->sc->cur_scp) {
3605 lwkt_reltoken(&tty_token);
3608 ap->a_result = (*vidsw[scp->sc->adapter]->mmap)(scp->sc->adp, ap->a_offset,
3610 lwkt_reltoken(&tty_token);
3615 save_kbd_state(scr_stat *scp, int unlock)
3620 WANT_UNLOCK(unlock);
3621 error = kbd_ioctl(scp->sc->kbd, KDGKBSTATE, (caddr_t)&state);
3624 if (error == ENOIOCTL)
3627 scp->status &= ~LOCK_MASK;
3628 scp->status |= state;
3634 update_kbd_state(scr_stat *scp, int new_bits, int mask, int unlock)
3639 if (mask != LOCK_MASK) {
3640 WANT_UNLOCK(unlock);
3641 error = kbd_ioctl(scp->sc->kbd, KDGKBSTATE, (caddr_t)&state);
3644 if (error == ENOIOCTL)
3650 state |= new_bits & mask;
3652 state = new_bits & LOCK_MASK;
3654 WANT_UNLOCK(unlock);
3655 error = kbd_ioctl(scp->sc->kbd, KDSKBSTATE, (caddr_t)&state);
3657 if (error == ENOIOCTL)
3663 update_kbd_leds(scr_stat *scp, int which)
3668 error = kbd_ioctl(scp->sc->kbd, KDSETLED, (caddr_t)&which);
3669 if (error == ENOIOCTL)
3675 set_mode(scr_stat *scp)
3679 lwkt_gettoken(&tty_token);
3680 /* reject unsupported mode */
3681 if (scp->sc->fbi == NULL && (*vidsw[scp->sc->adapter]->get_info)(scp->sc->adp, scp->mode, &info)) {
3682 lwkt_reltoken(&tty_token);
3686 /* if this vty is not currently showing, do nothing */
3687 if (scp != scp->sc->cur_scp) {
3688 lwkt_reltoken(&tty_token);
3692 /* setup video hardware for the given mode */
3693 if (scp->sc->fbi == NULL)
3694 (*vidsw[scp->sc->adapter]->set_mode)(scp->sc->adp, scp->mode);
3695 sc_vtb_init(&scp->scr, VTB_FRAMEBUFFER, scp->xsize, scp->ysize,
3696 (void *)scp->sc->adp->va_window, FALSE);
3697 if (scp->sc->fbi != NULL)
3700 #ifndef SC_NO_FONT_LOADING
3701 /* load appropriate font */
3702 if (!(scp->status & GRAPHICS_MODE)) {
3703 if (!(scp->status & PIXEL_MODE) && ISFONTAVAIL(scp->sc->adp->va_flags)) {
3704 if (scp->font_size < 14) {
3705 if (scp->sc->fonts_loaded & FONT_8)
3706 sc_load_font(scp, 0, 8, scp->sc->font_8, 0, 256);
3707 } else if (scp->font_size >= 16) {
3708 if (scp->sc->fonts_loaded & FONT_16)
3709 sc_load_font(scp, 0, 16, scp->sc->font_16, 0, 256);
3711 if (scp->sc->fonts_loaded & FONT_14)
3712 sc_load_font(scp, 0, 14, scp->sc->font_14, 0, 256);
3716 * This is an interim kludge to display correct font.
3717 * Always use the font page #0 on the video plane 2.
3718 * Somehow we cannot show the font in other font pages on
3719 * some video cards... XXX
3721 sc_show_font(scp, 0);
3725 #endif /* !SC_NO_FONT_LOADING */
3727 sc_set_border(scp, scp->border);
3728 sc_set_cursor_image(scp);
3731 lwkt_reltoken(&tty_token);
3736 refresh_ega_palette(scr_stat *scp)
3740 int rsize, gsize, bsize;
3741 int rfld, gfld, bfld;
3744 rsize = scp->sc->adp->va_info.vi_pixel_fsizes[0];
3745 gsize = scp->sc->adp->va_info.vi_pixel_fsizes[1];
3746 bsize = scp->sc->adp->va_info.vi_pixel_fsizes[2];
3747 rfld = scp->sc->adp->va_info.vi_pixel_fields[0];
3748 gfld = scp->sc->adp->va_info.vi_pixel_fields[1];
3749 bfld = scp->sc->adp->va_info.vi_pixel_fields[2];
3751 for (i = 0; i < 16; i++) {
3752 reg = scp->sc->adp->va_palette_regs[i];
3754 r = scp->sc->palette[reg * 3] >> (8 - rsize);
3755 g = scp->sc->palette[reg * 3 + 1] >> (8 - gsize);
3756 b = scp->sc->palette[reg * 3 + 2] >> (8 - bsize);
3758 scp->ega_palette[i] = (r << rfld) + (g << gfld) + (b << bfld);
3763 sc_set_border(scr_stat *scp, int color)
3765 ++scp->sc->videoio_in_progress;
3766 (*scp->rndr->draw_border)(scp, color);
3767 --scp->sc->videoio_in_progress;
3770 #ifndef SC_NO_FONT_LOADING
3772 sc_load_font(scr_stat *scp, int page, int size, u_char *buf,
3773 int base, int count)
3778 sc->font_loading_in_progress = TRUE;
3779 (*vidsw[sc->adapter]->load_font)(sc->adp, page, size, buf, base, count);
3780 sc->font_loading_in_progress = FALSE;
3784 sc_save_font(scr_stat *scp, int page, int size, u_char *buf,
3785 int base, int count)
3790 sc->font_loading_in_progress = TRUE;
3791 (*vidsw[sc->adapter]->save_font)(sc->adp, page, size, buf, base, count);
3792 sc->font_loading_in_progress = FALSE;
3796 sc_show_font(scr_stat *scp, int page)
3798 (*vidsw[scp->sc->adapter]->show_font)(scp->sc->adp, page);
3800 #endif /* !SC_NO_FONT_LOADING */
3803 sc_paste(scr_stat *scp, u_char *p, int count)
3809 * Holy hell, don't try to inject a paste buffer if the keyboard
3810 * is not in ascii mode!
3812 if (scp->kbd_mode != K_XLATE)
3815 lwkt_gettoken(&tty_token);
3816 if (scp->status & MOUSE_VISIBLE) {
3817 tp = VIRTUAL_TTY(scp->sc, scp->sc->cur_scp->index);
3818 if (!ISTTYOPEN(tp)) {
3819 lwkt_reltoken(&tty_token);
3822 rmap = scp->sc->scr_rmap;
3823 for (; count > 0; --count)
3824 (*linesw[tp->t_line].l_rint)(rmap[*p++], tp);
3826 lwkt_reltoken(&tty_token);
3830 sc_bell(scr_stat *scp, int pitch, int duration)
3832 if (cold || shutdown_in_progress)
3835 if (scp != scp->sc->cur_scp && (scp->sc->flags & SC_QUIET_BELL)) {
3839 if (scp->sc->flags & SC_VISUAL_BELL) {
3840 if (scp->sc->blink_in_progress) {
3843 scp->sc->blink_in_progress = 3;
3844 if (scp != scp->sc->cur_scp)
3845 scp->sc->blink_in_progress += 2;
3846 sc_blink_screen(scp->sc->cur_scp);
3847 } else if (duration != 0 && pitch != 0) {
3848 if (scp != scp->sc->cur_scp)
3850 sysbeep(pitch, duration);
3855 * Two versions of blink_screen(), one called from the console path
3856 * with the syscons locked, and one called from a timer callout.
3859 sc_blink_screen(scr_stat *scp)
3861 if (ISGRAPHSC(scp) || (scp->sc->blink_in_progress <= 1)) {
3862 scp->sc->blink_in_progress = 0;
3864 if (scp->sc->delayed_next_scr)
3865 sc_switch_scr(scp->sc, scp->sc->delayed_next_scr - 1);
3867 (*scp->rndr->draw)(scp, 0, scp->xsize*scp->ysize,
3868 scp->sc->blink_in_progress & 1);
3869 scp->sc->blink_in_progress--;
3875 blink_screen_callout(void *arg)
3877 scr_stat *scp = arg;
3880 if (ISGRAPHSC(scp) || (scp->sc->blink_in_progress <= 1)) {
3882 scp->sc->blink_in_progress = 0;
3885 tp = VIRTUAL_TTY(scp->sc, scp->index);
3888 if (scp->sc->delayed_next_scr) {
3890 sc_switch_scr(scp->sc, scp->sc->delayed_next_scr - 1);
3895 (*scp->rndr->draw)(scp, 0, scp->xsize*scp->ysize,
3896 scp->sc->blink_in_progress & 1);
3897 scp->sc->blink_in_progress--;
3899 callout_reset(&scp->blink_screen_ch, hz / 10,
3900 blink_screen_callout, scp);
3906 * Allocate active keyboard. Try to allocate "kbdmux" keyboard first, and,
3907 * if found, add all non-busy keyboards to "kbdmux". Otherwise look for
3912 sc_allocate_keyboard(sc_softc_t *sc, int unit)
3918 idx0 = kbd_allocate("kbdmux", -1, (void *)&sc->keyboard, sckbdevent, sc);
3920 k0 = kbd_get_keyboard(idx0);
3922 for (idx = kbd_find_keyboard2("*", -1, 0, 0);
3924 idx = kbd_find_keyboard2("*", -1, idx + 1, 0)) {
3925 k = kbd_get_keyboard(idx);
3927 if (idx == idx0 || KBD_IS_BUSY(k))
3930 bzero(&ki, sizeof(ki));
3931 strcpy(ki.kb_name, k->kb_name);
3932 ki.kb_unit = k->kb_unit;
3934 kbd_ioctl(k0, KBADDKBD, (caddr_t) &ki);
3937 idx0 = kbd_allocate("*", unit, (void *)&sc->keyboard, sckbdevent, sc);