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 * Simple font scaling code by Sascha Wildner and Matthew Dillon
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer,
15 * without modification, immediately at the beginning of the file.
16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in the
18 * documentation and/or other materials provided with the distribution.
19 * 3. The name of the author may not be used to endorse or promote products
20 * derived from this software without specific prior written permission.
22 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
23 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
24 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
25 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
26 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
27 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
31 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 * $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 $
36 #include "use_splash.h"
37 #include "opt_syscons.h"
40 #include <sys/param.h>
41 #include <sys/systm.h>
42 #include <sys/eventhandler.h>
43 #include <sys/reboot.h>
47 #include <sys/signalvar.h>
48 #include <sys/sysctl.h>
49 #include <sys/taskqueue.h>
51 #include <sys/kernel.h>
53 #include <sys/random.h>
56 #include <sys/thread2.h>
57 #include <sys/mutex2.h>
59 #include <machine/clock.h>
60 #include <machine/console.h>
61 #include <machine/psl.h>
62 #include <machine/pc/display.h>
63 #include <machine/frame.h>
64 #include <machine/framebuffer.h>
66 #include <dev/misc/kbd/kbdreg.h>
67 #include <dev/video/fb/fbreg.h>
68 #include <dev/video/fb/splashreg.h>
74 #define DEFAULT_BLANKTIME (5*60) /* 5 minutes */
75 #define MAX_BLANKTIME (7*24*60*60) /* 7 days!? */
77 #define SCRN_ASYNCOK 0x0001
78 #define SCRN_BULKUNLOCK 0x0002
80 #define KEYCODE_BS 0x0e /* "<-- Backspace" key, XXX */
81 #define WANT_UNLOCK(m) do { \
86 #define WANT_LOCK(m) do { \
92 MALLOC_DEFINE(M_SYSCONS, "syscons", "Syscons");
94 typedef struct default_attr {
95 int std_color; /* normal hardware color */
96 int rev_color; /* reverse hardware color */
99 static default_attr user_default = {
104 static default_attr kernel_default = {
106 SC_KERNEL_CONS_REV_ATTR,
109 static int sc_console_unit = -1;
110 static scr_stat *sc_console;
111 static struct tty *sc_console_tty;
112 static void *kernel_console_ts;
114 static char init_done = COLD;
115 static char shutdown_in_progress = FALSE;
116 static char sc_malloc = FALSE;
117 static char sc_filled_border = FALSE; /* filled initial VT border */
119 static int saver_mode = CONS_NO_SAVER; /* LKM/user saver */
120 static int run_scrn_saver = FALSE; /* should run the saver? */
121 static long scrn_blank_time = 0; /* screen saver timeout value */
123 static int scrn_blanked; /* # of blanked screen */
124 static int sticky_splash = FALSE;
126 static void none_saver(sc_softc_t *sc, int blank) { }
127 static void (*current_saver)(sc_softc_t *, int) = none_saver;
131 * Lock for asynchronous screen update thread, needed to safely modify the
132 * framebuffer information.
134 static struct lock sc_asynctd_lk;
136 #if !defined(SC_NO_FONT_LOADING) && defined(SC_DFLT_FONT)
140 static bios_values_t bios_value;
142 static int enable_panic_key;
143 SYSCTL_INT(_machdep, OID_AUTO, enable_panic_key, CTLFLAG_RW, &enable_panic_key,
144 0, "Enable the panic key (CTRL-ALT-SHIFT-ESC)");
145 static int syscons_async;
146 SYSCTL_INT(_kern, OID_AUTO, syscons_async, CTLFLAG_RW, &syscons_async,
147 0, "Asynchronous bulk syscons fb updates");
149 static int desired_cols = 0;
150 TUNABLE_INT("kern.kms_columns", &desired_cols);
152 #define SC_CONSOLECTL 255
154 #define VIRTUAL_TTY(sc, x) ((SC_DEV((sc),(x)) != NULL) ? \
155 (SC_DEV((sc),(x))->si_tty) : NULL)
156 #define ISTTYOPEN(tp) ((tp) && ((tp)->t_state & TS_ISOPEN))
159 static cdev_t cctl_dev;
161 static timeout_t blink_screen_callout;
163 static void sc_blink_screen(scr_stat *scp);
164 static struct mtx syscons_mtx = MTX_INITIALIZER("syscons");
167 static int scvidprobe(int unit, int flags, int cons);
168 static int sckbdprobe(int unit, int flags, int cons);
169 static void scmeminit(void *arg);
170 static int scdevtounit(cdev_t dev);
171 static kbd_callback_func_t sckbdevent;
172 static int scparam(struct tty *tp, struct termios *t);
173 static void scstart(struct tty *tp);
174 static void scinit(int unit, int flags);
175 static void scterm(int unit, int flags);
176 static void scshutdown(void *arg, int howto);
177 static void sc_puts(scr_stat *scp, u_char *buf, int len);
178 static u_int scgetc(sc_softc_t *sc, u_int flags);
180 #define SCGETC_NONBLOCK 2
181 static int sccngetch(int flags);
182 static void sccnupdate(scr_stat *scp);
183 static scr_stat *alloc_scp(sc_softc_t *sc, int vty);
184 static void init_scp(sc_softc_t *sc, int vty, scr_stat *scp);
185 static timeout_t scrn_timer;
186 static int and_region(int *s1, int *e1, int s2, int e2);
187 static void scrn_update(scr_stat *scp, int show_cursor, int flags);
188 static void scrn_update_thread(void *arg);
190 static void sc_fb_set_par(void *context, int pending);
192 static void sc_fb_blank(void *context, int pending);
196 static void scframebuffer_saver(sc_softc_t *sc, int show);
197 static int scsplash_callback(int event, void *arg);
198 static void scsplash_saver(sc_softc_t *sc, int show);
199 static int add_scrn_saver(void (*this_saver)(sc_softc_t *, int));
200 static int remove_scrn_saver(void (*this_saver)(sc_softc_t *, int));
201 static int set_scrn_saver_mode(scr_stat *scp, int mode, u_char *pal, int border);
202 static int restore_scrn_saver_mode(scr_stat *scp, int changemode);
203 static void stop_scrn_saver(sc_softc_t *sc, void (*saver)(sc_softc_t *, int));
204 static int wait_scrn_saver_stop(sc_softc_t *sc, int need_unlock);
205 #define scsplash_stick(stick) (sticky_splash = (stick))
207 #define scsplash_stick(stick)
210 static void do_switch_scr(sc_softc_t *sc);
211 static int vt_proc_alive(scr_stat *scp);
212 static int signal_vt_rel(scr_stat *scp);
213 static int signal_vt_acq(scr_stat *scp);
214 static int finish_vt_rel(scr_stat *scp, int release);
215 static int finish_vt_acq(scr_stat *scp);
216 static void exchange_scr(sc_softc_t *sc);
217 static void update_cursor_image(scr_stat *scp);
218 static int save_kbd_state(scr_stat *scp, int unlock);
219 static int update_kbd_state(scr_stat *scp, int state, int mask, int unlock);
220 static int update_kbd_leds(scr_stat *scp, int which);
221 static int sc_allocate_keyboard(sc_softc_t *sc, int unit);
224 * Console locking support functions.
226 * We use mutex spinlocks here in order to allow reentrancy which should
227 * avoid issues during panics.
229 * A panic can stop a cpu while it is holding the syscons_mtx. If this
230 * occurs we try for up to 1/2 a second and then blow the spinlock away.
231 * The asynchronous update thread makes this happen more often.
236 if (panicstr || shutdown_in_progress) {
237 int retries = 500000;
238 while (mtx_spinlock_try(&syscons_mtx)) {
239 tsc_delay(1000); /* 1uS */
240 if (--retries == 0) {
241 mtx_init(&syscons_mtx, "syscons");
246 mtx_spinlock(&syscons_mtx);
251 * Returns 0 on success, EAGAIN on failure.
254 syscons_lock_nonblock(void)
256 return(mtx_spinlock_try(&syscons_mtx));
262 mtx_spinunlock(&syscons_mtx);
268 static cn_probe_t sccnprobe;
269 static cn_init_t sccninit;
270 static cn_init_t sccninit_fini;
271 static cn_getc_t sccngetc;
272 static cn_checkc_t sccncheckc;
273 static cn_putc_t sccnputc;
274 static cn_dbctl_t sccndbctl;
275 static cn_term_t sccnterm;
276 static cn_poll_t sccnpoll;
278 CONS_DRIVER(sc, sccnprobe, sccninit, sccninit_fini, sccnterm,
279 sccngetc, sccncheckc, sccnputc, sccndbctl, sccnpoll);
281 static d_open_t scopen;
282 static d_close_t scclose;
283 static d_read_t scread;
284 static d_ioctl_t scioctl;
285 static d_mmap_t scmmap;
287 static struct dev_ops sc_ops = {
288 { "sc", 0, D_TTY | D_MPSAFE },
295 .d_kqfilter = ttykqfilter,
296 .d_revoke = ttyrevoke
300 sc_probe_unit(int unit, int flags)
302 if ((flags & SC_EFI_FB) && (probe_efi_fb(0) != 0)) {
304 kprintf("sc%d: no EFI framebuffer found.\n", unit);
308 if (!(flags & SC_EFI_FB) && !scvidprobe(unit, flags, FALSE)) {
310 kprintf("sc%d: no video adapter found.\n", unit);
314 /* syscons will be attached even when there is no keyboard */
315 sckbdprobe(unit, flags, FALSE);
321 register_framebuffer(struct fb_info *info)
325 /* For now ignore framebuffers, which don't replace the vga display */
326 if (!info->is_vga_boot_display)
329 lwkt_gettoken(&tty_token);
330 sc = sc_get_softc(0, (sc_console_unit == 0) ? SC_KERNEL_CONSOLE : 0);
332 lwkt_reltoken(&tty_token);
333 kprintf("%s: sc_get_softc(%d, %d) returned NULL\n", __func__,
334 0, (sc_console_unit == 0) ? SC_KERNEL_CONSOLE : 0);
338 /* Ignore this framebuffer if we already switched to KMS framebuffer */
339 if (sc->fbi != NULL && sc->fbi != &efi_fb_info &&
340 sc->fbi != sc->dummy_fb_info) {
341 lwkt_reltoken(&tty_token);
345 if (sc->fb_set_par_task == NULL) {
346 sc->fb_set_par_task = kmalloc(sizeof(struct task),
347 M_SYSCONS, M_WAITOK | M_ZERO);
349 TASK_INIT(sc->fb_set_par_task, 0, sc_fb_set_par, sc);
351 if (sc->fb_blank_task == NULL) {
352 sc->fb_blank_task = kmalloc(sizeof(struct task),
353 M_SYSCONS, M_WAITOK | M_ZERO);
355 TASK_INIT(sc->fb_blank_task, 0, sc_fb_blank, sc);
359 * Make sure that console messages don't interfere too much with
362 atomic_add_int(&sc->videoio_in_progress, 1);
364 /* Lock against synchronous and asynchronous screen updates */
365 lockmgr(&sc_asynctd_lk, LK_EXCLUSIVE);
368 sc->fbi_generation++;
371 kprintf("kms console: xpixels %d ypixels %d\n",
372 sc->fbi->width, sc->fbi->height);
373 sc_update_render(sc->cur_scp);
374 if (info->fbops.fb_set_par != NULL)
375 info->fbops.fb_set_par(info);
376 atomic_add_int(&sc->videoio_in_progress, -1);
378 sc->fb_blanked = FALSE;
379 if (sc->unit == sc_console_unit && sc->cur_scp->smode.mode != VT_AUTO)
380 cons_unavail = FALSE;
382 if (info->fbops.fb_blank != NULL)
383 add_scrn_saver(scframebuffer_saver);
386 lockmgr(&sc_asynctd_lk, LK_RELEASE);
387 lwkt_reltoken(&tty_token);
392 unregister_framebuffer(struct fb_info *info)
396 lwkt_gettoken(&tty_token);
397 sc = sc_get_softc(0, (sc_console_unit == 0) ? SC_KERNEL_CONSOLE : 0);
399 lwkt_reltoken(&tty_token);
400 kprintf("%s: sc_get_softc(%d, %d) returned NULL\n", __func__,
401 0, (sc_console_unit == 0) ? SC_KERNEL_CONSOLE : 0);
405 if (sc->fbi != info) {
406 lwkt_reltoken(&tty_token);
411 if (info->fbops.fb_blank != NULL)
412 remove_scrn_saver(scframebuffer_saver);
415 if (sc->fb_set_par_task != NULL &&
416 taskqueue_cancel(taskqueue_thread[0], sc->fb_set_par_task, NULL)) {
417 taskqueue_drain(taskqueue_thread[0], sc->fb_set_par_task);
420 if (sc->fb_blank_task != NULL &&
421 taskqueue_cancel(taskqueue_thread[0], sc->fb_blank_task, NULL)) {
422 taskqueue_drain(taskqueue_thread[0], sc->fb_blank_task);
425 sc->fb_blanked = TRUE;
426 if (sc->unit == sc_console_unit)
429 if (sc->dummy_fb_info == NULL) {
430 sc->dummy_fb_info = kmalloc(sizeof(struct fb_info),
431 M_SYSCONS, M_WAITOK | M_ZERO);
433 memset(sc->dummy_fb_info, 0, sizeof(struct fb_info));
435 *sc->dummy_fb_info = *sc->fbi;
436 sc->dummy_fb_info->vaddr = 0;
437 sc->dummy_fb_info->fbops.fb_set_par = NULL;
438 sc->dummy_fb_info->fbops.fb_blank = NULL;
439 sc->dummy_fb_info->fbops.fb_debug_enter = NULL;
441 /* Lock against synchronous and asynchronous screen updates */
442 lockmgr(&sc_asynctd_lk, LK_EXCLUSIVE);
444 sc->fbi = sc->dummy_fb_info;
446 lockmgr(&sc_asynctd_lk, LK_RELEASE);
448 lwkt_reltoken(&tty_token);
452 sc_font_scale(scr_stat *scp, int max_cols, int max_rows)
457 * If columns not specified in /boot/loader.conf then
458 * calculate a non-fractional scaling that yields a
459 * reasonable number of rows and columns. If it is <0,
460 * don't scale at all.
462 if (desired_cols == 0) {
464 while (scp->xpixel / (scp->font_width * nomag) >= COL &&
465 scp->ypixel / (scp->font_height * nomag) >= ROW) {
470 cols = scp->xpixel / (scp->font_width * nomag);
471 } else if (desired_cols < 0) {
472 cols = scp->xpixel / scp->font_width;
476 scp->blk_width = scp->xpixel / cols;
477 scp->blk_height = scp->blk_width * scp->font_height / scp->font_width;
478 rows = scp->ypixel / scp->blk_height;
480 /* scp->xsize = scp->xpixel / scp->blk_width; total possible */
481 scp->xsize = max_cols ? imin(max_cols, cols) : cols;
482 scp->ysize = max_rows ? imin(max_rows, rows) : rows;
485 /* probe video adapters, return TRUE if found */
487 scvidprobe(int unit, int flags, int cons)
490 * Access the video adapter driver through the back door!
491 * Video adapter drivers need to be configured before syscons.
492 * However, when syscons is being probed as the low-level console,
493 * they have not been initialized yet. We force them to initialize
494 * themselves here. XXX
496 vid_configure(cons ? VIO_PROBE_ONLY : 0);
498 return (vid_find_adapter("*", unit) >= 0);
501 /* probe the keyboard, return TRUE if found */
503 sckbdprobe(int unit, int flags, int cons)
505 /* access the keyboard driver through the backdoor! */
506 kbd_configure(cons ? KB_CONF_PROBE_ONLY : 0);
508 return (kbd_find_keyboard("*", unit) >= 0);
512 adapter_name(video_adapter_t *adp)
518 { KD_MONO, { "MDA", "MDA" } },
519 { KD_HERCULES, { "Hercules", "Hercules" } },
520 { KD_CGA, { "CGA", "CGA" } },
521 { KD_EGA, { "EGA", "EGA (mono)" } },
522 { KD_VGA, { "VGA", "VGA (mono)" } },
523 { KD_TGA, { "TGA", "TGA" } },
524 { -1, { "Unknown", "Unknown" } },
528 for (i = 0; names[i].type != -1; ++i)
529 if (names[i].type == adp->va_type)
531 return names[i].name[(adp->va_flags & V_ADP_COLOR) ? 0 : 1];
535 sc_attach_unit(int unit, int flags)
541 flags &= ~SC_KERNEL_CONSOLE;
542 char tbuf[MAKEDEV_MINNBUF];
544 if ((flags & SC_EFI_FB) && probe_efi_fb(0) != 0)
547 if (sc_console_unit == unit) {
549 * If this unit is being used as the system console, we need to
550 * adjust some variables and buffers before and after scinit().
552 /* assert(sc_console != NULL) */
553 flags |= SC_KERNEL_CONSOLE;
558 if (sc_console->tsw->te_size > 0) {
559 /* assert(sc_console->ts != NULL); */
560 kernel_console_ts = sc_console->ts;
561 sc_console->ts = kmalloc(sc_console->tsw->te_size,
562 M_SYSCONS, M_WAITOK);
563 bcopy(kernel_console_ts, sc_console->ts, sc_console->tsw->te_size);
564 (*sc_console->tsw->te_default_attr)(sc_console,
565 user_default.std_color,
566 user_default.rev_color);
572 sc = sc_get_softc(unit, flags & SC_KERNEL_CONSOLE);
575 * If this is the console we couldn't setup sc->dev before because
576 * malloc wasn't working. Set it up now.
578 if (flags & SC_KERNEL_CONSOLE) {
579 KKASSERT(sc->dev == NULL);
580 sc->dev = kmalloc(sizeof(cdev_t)*sc->vtys, M_SYSCONS, M_WAITOK|M_ZERO);
581 sc->dev[0] = make_dev(&sc_ops, sc_console_unit*MAXCONS, UID_ROOT,
582 GID_WHEEL, 0600, "ttyv%s", makedev_unit_b32(tbuf,
583 sc_console_unit * MAXCONS));
584 sc->dev[0]->si_tty = ttymalloc(sc->dev[0]->si_tty);
585 sc->dev[0]->si_drv1 = sc_console;
589 * Finish up the standard attach
592 callout_init_mp(&sc->scrn_timer_ch);
593 scp = SC_STAT(sc->dev[0]);
594 if (sc_console == NULL) /* sc_console_unit < 0 */
597 /* initialize cursor */
599 update_cursor_image(scp);
601 /* get screen update going */
604 /* set up the keyboard */
605 kbd_ioctl(sc->kbd, KDSKBMODE, (caddr_t)&scp->kbd_mode);
606 update_kbd_state(scp, scp->status, LOCK_MASK, FALSE);
608 kprintf("sc%d: %s <%d virtual consoles, flags=0x%x>\n",
609 unit, (sc->config & SC_EFI_FB) ? "EFI_FB" : adapter_name(sc->adp),
610 sc->vtys, sc->config);
612 kprintf("sc%d:", unit);
613 if (sc->adapter >= 0)
614 kprintf(" fb%d", sc->adapter);
615 if (sc->keyboard >= 0)
616 kprintf(", kbd%d", sc->keyboard);
618 kprintf(", terminal emulator: %s (%s)",
619 scp->tsw->te_name, scp->tsw->te_desc);
623 /* register a shutdown callback for the kernel console */
624 if (sc_console_unit == unit)
625 EVENTHANDLER_REGISTER(shutdown_pre_sync, scshutdown,
626 (void *)(uintptr_t)unit, SHUTDOWN_PRI_DEFAULT);
631 * The first vty already has struct tty and scr_stat initialized
632 * in scinit(). The other vtys will have these structs when
635 for (vc = 1; vc < sc->vtys; vc++) {
636 dev = make_dev(&sc_ops, vc + unit * MAXCONS,
637 UID_ROOT, GID_WHEEL, 0600, "ttyv%s",
638 makedev_unit_b32(tbuf, vc + unit * MAXCONS));
641 cctl_dev = make_dev(&sc_ops, SC_CONSOLECTL,
642 UID_ROOT, GID_WHEEL, 0600, "consolectl");
643 cctl_dev->si_tty = sc_console_tty = ttymalloc(sc_console_tty);
644 cctl_dev->si_drv1 = sc_console;
656 * As soon as malloc() becomes functional, we had better allocate
657 * various buffers for the kernel console.
660 if (sc_console_unit < 0) /* sc_console == NULL */
663 /* copy the temporary buffer to the final buffer */
664 sc_alloc_scr_buffer(sc_console, TRUE, FALSE);
666 #ifndef SC_NO_CUTPASTE
667 sc_alloc_cut_buffer(sc_console, TRUE);
670 #ifndef SC_NO_HISTORY
671 /* initialize history buffer & pointers */
672 sc_alloc_history_buffer(sc_console, 0, 0, TRUE);
675 /* Fill initial terminal border, efi_fb_info.vaddr should be non-NULL now */
676 if (!sc_filled_border) {
677 sc_filled_border = TRUE;
678 sc_set_border(sc_console, sc_console->border);
682 SYSINIT(sc_mem, SI_BOOT1_POST, SI_ORDER_ANY, scmeminit, NULL);
685 scdevtounit(cdev_t dev)
687 int vty = SC_VTY(dev);
689 if (vty == SC_CONSOLECTL)
690 return ((sc_console != NULL) ? sc_console->sc->unit : -1);
691 else if ((vty < 0) || (vty >= MAXCONS*sc_max_unit()))
698 scopen(struct dev_open_args *ap)
700 cdev_t dev = ap->a_head.a_dev;
708 lwkt_gettoken(&tty_token);
709 unit = scdevtounit(dev);
710 DPRINTF(5, ("scopen: dev:%d,%d, unit:%d, vty:%d\n",
711 major(dev), minor(dev), unit, SC_VTY(dev)));
713 sc = sc_get_softc(unit, (sc_console_unit == unit) ? SC_KERNEL_CONSOLE : 0);
715 lwkt_reltoken(&tty_token);
719 tp = dev->si_tty = ttymalloc(dev->si_tty);
720 tp->t_oproc = scstart;
721 tp->t_param = scparam;
722 tp->t_stop = nottystop;
726 if (!ISTTYOPEN(tp)) {
728 /* Use the current setting of the <-- key as default VERASE. */
729 /* If the Delete key is preferable, an stty is necessary */
730 if (sc->kbd != NULL) {
731 key.keynum = KEYCODE_BS;
732 kbd_ioctl(sc->kbd, GIO_KEYMAPENT, (caddr_t)&key);
733 tp->t_cc[VERASE] = key.key.map[0];
735 tp->t_iflag = TTYDEF_IFLAG;
736 tp->t_oflag = TTYDEF_OFLAG;
737 tp->t_cflag = TTYDEF_CFLAG;
738 tp->t_lflag = TTYDEF_LFLAG;
739 tp->t_ispeed = tp->t_ospeed = TTYDEF_SPEED;
740 scparam(tp, &tp->t_termios);
741 (*linesw[tp->t_line].l_modem)(tp, 1);
744 if (tp->t_state & TS_XCLUDE && priv_check_cred(ap->a_cred, PRIV_ROOT, 0)) {
745 lwkt_reltoken(&tty_token);
749 error = (*linesw[tp->t_line].l_open)(dev, tp);
753 scp = dev->si_drv1 = alloc_scp(sc, SC_VTY(dev));
756 sc_set_pixel_mode(scp, NULL, COL, ROW, 16);
759 if (!tp->t_winsize.ws_col && !tp->t_winsize.ws_row) {
760 tp->t_winsize.ws_col = scp->xsize;
761 tp->t_winsize.ws_row = scp->ysize;
765 * Start optional support thread for syscons refreshes. This thread
766 * will execute the refresh without the syscons_lock held and will
767 * allow interrupts while it is doing so.
769 if (scp->asynctd == NULL) {
770 lwkt_create(scrn_update_thread, scp, &scp->asynctd, NULL, 0, -1,
771 "syscons%d", SC_VTY(dev));
773 lwkt_reltoken(&tty_token);
778 scclose(struct dev_close_args *ap)
780 cdev_t dev = ap->a_head.a_dev;
781 struct tty *tp = dev->si_tty;
784 lwkt_gettoken(&tty_token);
785 if (SC_VTY(dev) != SC_CONSOLECTL) {
786 scp = SC_STAT(tp->t_dev);
787 /* were we in the middle of the VT switching process? */
788 DPRINTF(5, ("sc%d: scclose(), ", scp->sc->unit));
789 if ((scp == scp->sc->cur_scp) && (scp->sc->unit == sc_console_unit) &&
790 !scp->sc->fb_blanked) {
791 cons_unavail = FALSE;
793 if (finish_vt_rel(scp, TRUE) == 0) /* force release */
794 DPRINTF(5, ("reset WAIT_REL, "));
795 if (finish_vt_acq(scp) == 0) /* force acknowledge */
796 DPRINTF(5, ("reset WAIT_ACQ, "));
799 if (scp == &main_console) {
802 scp->smode.mode = VT_AUTO;
805 sc_vtb_destroy(&scp->vtb);
806 sc_vtb_destroy(&scp->scr);
807 sc_free_history_buffer(scp, scp->ysize);
809 kfree(scp, M_SYSCONS);
814 scp->smode.mode = VT_AUTO;
816 scp->kbd_mode = K_XLATE;
818 if (scp == scp->sc->cur_scp)
819 kbd_ioctl(scp->sc->kbd, KDSKBMODE, (caddr_t)&scp->kbd_mode);
820 DPRINTF(5, ("done.\n"));
822 (*linesw[tp->t_line].l_close)(tp, ap->a_fflag);
824 lwkt_reltoken(&tty_token);
830 scread(struct dev_read_args *ap)
834 lwkt_gettoken(&tty_token);
835 sc_touch_scrn_saver();
837 lwkt_reltoken(&tty_token);
842 sckbdevent(keyboard_t *thiskbd, int event, void *arg)
850 lwkt_gettoken(&tty_token);
852 * WARNING: In early boot sc->dev may not be setup yet.
854 sc = (sc_softc_t *)arg;
855 /* assert(thiskbd == sc->kbd) */
859 if (sc->kbd && sc->kbd->kb_flags & KB_POLLED) {
860 lwkt_reltoken(&tty_token);
864 case KBDIO_UNLOADING:
869 kbd_release(thiskbd, (void *)&sc->keyboard);
870 lwkt_reltoken(&tty_token);
873 lwkt_reltoken(&tty_token);
878 * Loop while there is still input to get from the keyboard.
879 * I don't think this is nessesary, and it doesn't fix
880 * the Xaccel-2.1 keyboard hang, but it can't hurt. XXX
882 while ((c = scgetc(sc, SCGETC_NONBLOCK)) != NOKEY) {
883 cur_tty = VIRTUAL_TTY(sc, sc->cur_scp->index);
884 if (!ISTTYOPEN(cur_tty)) {
885 cur_tty = sc_console_tty;
886 if (!ISTTYOPEN(cur_tty))
891 if ((*sc->cur_scp->tsw->te_input)(sc->cur_scp, c, cur_tty)) {
897 switch (KEYFLAGS(c)) {
898 case 0x0000: /* normal key */
899 (*linesw[cur_tty->t_line].l_rint)(KEYCHAR(c), cur_tty);
901 case FKEY: /* function key, return string */
902 cp = kbd_get_fkeystr(thiskbd, KEYCHAR(c), &len);
905 (*linesw[cur_tty->t_line].l_rint)(*cp++, cur_tty);
908 case MKEY: /* meta is active, prepend ESC */
909 (*linesw[cur_tty->t_line].l_rint)(0x1b, cur_tty);
910 (*linesw[cur_tty->t_line].l_rint)(KEYCHAR(c), cur_tty);
912 case BKEY: /* backtab fixed sequence (esc [ Z) */
913 (*linesw[cur_tty->t_line].l_rint)(0x1b, cur_tty);
914 (*linesw[cur_tty->t_line].l_rint)('[', cur_tty);
915 (*linesw[cur_tty->t_line].l_rint)('Z', cur_tty);
921 sc->cur_scp->status |= MOUSE_HIDDEN;
924 lwkt_reltoken(&tty_token);
929 scparam(struct tty *tp, struct termios *t)
931 lwkt_gettoken(&tty_token);
932 tp->t_ispeed = t->c_ispeed;
933 tp->t_ospeed = t->c_ospeed;
934 tp->t_cflag = t->c_cflag;
935 lwkt_reltoken(&tty_token);
940 scioctl(struct dev_ioctl_args *ap)
942 cdev_t dev = ap->a_head.a_dev;
943 u_long cmd = ap->a_cmd;
944 caddr_t data = ap->a_data;
945 int flag = ap->a_fflag;
952 lwkt_gettoken(&tty_token);
955 error = sc_vid_ioctl(tp, cmd, data, flag);
956 if (error != ENOIOCTL) {
957 lwkt_reltoken(&tty_token);
961 #ifndef SC_NO_HISTORY
962 error = sc_hist_ioctl(tp, cmd, data, flag);
963 if (error != ENOIOCTL) {
964 lwkt_reltoken(&tty_token);
969 #ifndef SC_NO_SYSMOUSE
970 error = sc_mouse_ioctl(tp, cmd, data, flag);
971 if (error != ENOIOCTL) {
972 lwkt_reltoken(&tty_token);
977 scp = SC_STAT(tp->t_dev);
978 /* assert(scp != NULL) */
979 /* scp is sc_console, if SC_VTY(dev) == SC_CONSOLECTL. */
984 error = (*scp->tsw->te_ioctl)(scp, tp, cmd, data, flag);
986 if (error != ENOIOCTL) {
987 lwkt_reltoken(&tty_token);
992 switch (cmd) { /* process console hardware related ioctl's */
994 case GIO_ATTR: /* get current attributes */
995 /* this ioctl is not processed here, but in the terminal emulator */
996 lwkt_reltoken(&tty_token);
999 case GIO_COLOR: /* is this a color console ? */
1000 if (sc->fbi != NULL)
1003 *(int *)data = (sc->adp->va_flags & V_ADP_COLOR) ? 1 : 0;
1004 lwkt_reltoken(&tty_token);
1007 case CONS_BLANKTIME: /* set screen saver timeout (0 = no saver) */
1008 if (*(int *)data < 0 || *(int *)data > MAX_BLANKTIME) {
1009 lwkt_reltoken(&tty_token);
1013 scrn_blank_time = *(int *)data;
1014 run_scrn_saver = (scrn_blank_time != 0);
1016 lwkt_reltoken(&tty_token);
1019 case CONS_CURSORTYPE: /* set cursor type blink/noblink */
1021 if (!ISGRAPHSC(sc->cur_scp))
1022 sc_remove_cursor_image(sc->cur_scp);
1023 if ((*(int*)data) & 0x01)
1024 sc->flags |= SC_BLINK_CURSOR;
1026 sc->flags &= ~SC_BLINK_CURSOR;
1027 if ((*(int*)data) & 0x02) {
1028 sc->flags |= SC_CHAR_CURSOR;
1030 sc->flags &= ~SC_CHAR_CURSOR;
1032 * The cursor shape is global property; all virtual consoles
1033 * are affected. Update the cursor in the current console...
1035 if (!ISGRAPHSC(sc->cur_scp)) {
1036 sc_set_cursor_image(sc->cur_scp);
1037 sc_draw_cursor_image(sc->cur_scp);
1040 lwkt_reltoken(&tty_token);
1043 case CONS_BELLTYPE: /* set bell type sound/visual */
1046 if ((*(int *)data) & 0x01)
1047 sc->flags |= SC_VISUAL_BELL;
1049 sc->flags &= ~SC_VISUAL_BELL;
1051 if ((*(int *)data) & 0x02)
1052 sc->flags |= SC_QUIET_BELL;
1054 sc->flags &= ~SC_QUIET_BELL;
1057 lwkt_reltoken(&tty_token);
1060 case CONS_GETINFO: /* get current (virtual) console info */
1062 vid_info_t *ptr = (vid_info_t*)data;
1063 if (ptr->size == sizeof(struct vid_info)) {
1064 ptr->m_num = sc->cur_scp->index;
1065 ptr->font_size = scp->font_height;
1066 ptr->mv_col = scp->xpos;
1067 ptr->mv_row = scp->ypos;
1068 ptr->mv_csz = scp->xsize;
1069 ptr->mv_rsz = scp->ysize;
1071 * The following fields are filled by the terminal emulator. XXX
1078 ptr->mv_grfc.fore = 0; /* not supported */
1079 ptr->mv_grfc.back = 0; /* not supported */
1080 ptr->mv_ovscan = scp->border;
1081 if (scp == sc->cur_scp)
1082 save_kbd_state(scp, FALSE);
1083 ptr->mk_keylock = scp->status & LOCK_MASK;
1084 lwkt_reltoken(&tty_token);
1087 lwkt_reltoken(&tty_token);
1091 case CONS_GETVERS: /* get version number */
1092 *(int*)data = 0x200; /* version 2.0 */
1093 lwkt_reltoken(&tty_token);
1096 case CONS_IDLE: /* see if the screen has been idle */
1098 * When the screen is in the GRAPHICS_MODE or UNKNOWN_MODE,
1099 * the user process may have been writing something on the
1100 * screen and syscons is not aware of it. Declare the screen
1101 * is NOT idle if it is in one of these modes. But there is
1102 * an exception to it; if a screen saver is running in the
1103 * graphics mode in the current screen, we should say that the
1104 * screen has been idle.
1106 *(int *)data = (sc->flags & SC_SCRN_IDLE)
1107 && (!ISGRAPHSC(sc->cur_scp)
1108 || (sc->cur_scp->status & SAVER_RUNNING));
1109 lwkt_reltoken(&tty_token);
1112 case CONS_SAVERMODE: /* set saver mode */
1113 switch(*(int *)data) {
1115 case CONS_USR_SAVER:
1117 /* if a LKM screen saver is running, stop it first. */
1118 scsplash_stick(FALSE);
1119 saver_mode = *(int *)data;
1121 if ((error = wait_scrn_saver_stop(NULL, TRUE))) {
1123 lwkt_reltoken(&tty_token);
1126 #endif /* NSPLASH */
1127 run_scrn_saver = TRUE;
1128 if (saver_mode == CONS_USR_SAVER)
1129 scp->status |= SAVER_RUNNING;
1131 scp->status &= ~SAVER_RUNNING;
1132 scsplash_stick(TRUE);
1135 case CONS_LKM_SAVER:
1137 if ((saver_mode == CONS_USR_SAVER) && (scp->status & SAVER_RUNNING))
1138 scp->status &= ~SAVER_RUNNING;
1139 saver_mode = *(int *)data;
1143 lwkt_reltoken(&tty_token);
1146 lwkt_reltoken(&tty_token);
1149 case CONS_SAVERSTART: /* immediately start/stop the screen saver */
1151 * Note that this ioctl does not guarantee the screen saver
1152 * actually starts or stops. It merely attempts to do so...
1155 run_scrn_saver = (*(int *)data != 0);
1157 sc->scrn_time_stamp -= scrn_blank_time;
1159 lwkt_reltoken(&tty_token);
1162 case CONS_SCRSHOT: /* get a screen shot */
1164 scrshot_t *ptr = (scrshot_t*)data;
1166 if (ISGRAPHSC(scp)) {
1168 lwkt_reltoken(&tty_token);
1171 if (scp->xsize != ptr->xsize || scp->ysize != ptr->ysize) {
1173 lwkt_reltoken(&tty_token);
1177 copyout ((void*)scp->vtb.vtb_buffer, ptr->buf,
1178 ptr->xsize * ptr->ysize * sizeof(uint16_t));
1179 lwkt_reltoken(&tty_token);
1183 case VT_SETMODE: /* set screen switcher mode */
1185 struct vt_mode *mode;
1187 mode = (struct vt_mode *)data;
1188 DPRINTF(5, ("sc%d: VT_SETMODE ", sc->unit));
1189 if (scp->smode.mode == VT_PROCESS) {
1190 if (scp->proc == pfindn(scp->pid) && scp->proc != curproc) {
1191 DPRINTF(5, ("error EPERM\n"));
1192 lwkt_reltoken(&tty_token);
1197 if (mode->mode == VT_AUTO) {
1198 scp->smode.mode = VT_AUTO;
1201 DPRINTF(5, ("VT_AUTO, "));
1202 if ((scp == sc->cur_scp) && (sc->unit == sc_console_unit) &&
1204 cons_unavail = FALSE;
1206 if (finish_vt_rel(scp, TRUE) == 0)
1207 DPRINTF(5, ("reset WAIT_REL, "));
1208 if (finish_vt_acq(scp) == 0)
1209 DPRINTF(5, ("reset WAIT_ACQ, "));
1211 if (!ISSIGVALID(mode->relsig) || !ISSIGVALID(mode->acqsig)
1212 || !ISSIGVALID(mode->frsig)) {
1214 DPRINTF(5, ("error EINVAL\n"));
1215 lwkt_reltoken(&tty_token);
1218 DPRINTF(5, ("VT_PROCESS %d, ", curproc->p_pid));
1219 bcopy(data, &scp->smode, sizeof(struct vt_mode));
1220 scp->proc = curproc;
1221 scp->pid = scp->proc->p_pid;
1222 if ((scp == sc->cur_scp) && (sc->unit == sc_console_unit))
1223 cons_unavail = TRUE;
1227 lwkt_reltoken(&tty_token);
1231 case VT_GETMODE: /* get screen switcher mode */
1232 bcopy(&scp->smode, data, sizeof(struct vt_mode));
1233 lwkt_reltoken(&tty_token);
1236 case VT_RELDISP: /* screen switcher ioctl */
1238 * This must be the current vty which is in the VT_PROCESS
1242 if ((scp != sc->cur_scp) || (scp->smode.mode != VT_PROCESS)) {
1244 lwkt_reltoken(&tty_token);
1247 /* ...and this process is controlling it. */
1248 if (scp->proc != curproc) {
1250 lwkt_reltoken(&tty_token);
1254 switch(*(int *)data) {
1255 case VT_FALSE: /* user refuses to release screen, abort */
1256 if ((error = finish_vt_rel(scp, FALSE)) == 0)
1257 DPRINTF(5, ("sc%d: VT_FALSE\n", sc->unit));
1259 case VT_TRUE: /* user has released screen, go on */
1260 if ((error = finish_vt_rel(scp, TRUE)) == 0)
1261 DPRINTF(5, ("sc%d: VT_TRUE\n", sc->unit));
1263 case VT_ACKACQ: /* acquire acknowledged, switch completed */
1264 if ((error = finish_vt_acq(scp)) == 0)
1265 DPRINTF(5, ("sc%d: VT_ACKACQ\n", sc->unit));
1271 lwkt_reltoken(&tty_token);
1274 case VT_OPENQRY: /* return free virtual console */
1275 for (i = sc->first_vty; i < sc->first_vty + sc->vtys; i++) {
1276 tp = VIRTUAL_TTY(sc, i);
1277 if (!ISTTYOPEN(tp)) {
1278 *(int *)data = i + 1;
1279 lwkt_reltoken(&tty_token);
1283 lwkt_reltoken(&tty_token);
1286 case VT_ACTIVATE: /* switch to screen *data */
1287 i = (*(int *)data == 0) ? scp->index : (*(int *)data - 1);
1289 sc_clean_up(sc->cur_scp, TRUE);
1290 error = sc_switch_scr(sc, i);
1292 lwkt_reltoken(&tty_token);
1295 case VT_WAITACTIVE: /* wait for switch to occur */
1296 i = (*(int *)data == 0) ? scp->index : (*(int *)data - 1);
1297 if ((i < sc->first_vty) || (i >= sc->first_vty + sc->vtys)) {
1298 lwkt_reltoken(&tty_token);
1302 error = sc_clean_up(sc->cur_scp, TRUE);
1305 lwkt_reltoken(&tty_token);
1310 * scp might be NULL, we aren't sure why. Check for NULL.
1312 * http://bugs.dragonflybsd.org/issues/2481
1314 scp = SC_STAT(SC_DEV(sc, i));
1315 if (scp == NULL || scp == scp->sc->cur_scp) {
1316 lwkt_reltoken(&tty_token);
1319 error = tsleep((caddr_t)&scp->smode, PCATCH, "waitvt", 0);
1320 /* May return ERESTART */
1321 lwkt_reltoken(&tty_token);
1324 case VT_GETACTIVE: /* get active vty # */
1325 *(int *)data = sc->cur_scp->index + 1;
1326 lwkt_reltoken(&tty_token);
1329 case VT_GETINDEX: /* get this vty # */
1330 *(int *)data = scp->index + 1;
1331 lwkt_reltoken(&tty_token);
1334 case VT_LOCKSWITCH: /* prevent vty switching */
1336 if ((*(int *)data) & 0x01)
1337 sc->flags |= SC_SCRN_VTYLOCK;
1339 sc->flags &= ~SC_SCRN_VTYLOCK;
1341 lwkt_reltoken(&tty_token);
1344 case KDENABIO: /* allow io operations */
1345 error = priv_check_cred(ap->a_cred, PRIV_ROOT, 0);
1347 lwkt_reltoken(&tty_token);
1350 if (securelevel > 0) {
1351 lwkt_reltoken(&tty_token);
1354 #if defined(__i386__)
1355 curthread->td_lwp->lwp_md.md_regs->tf_eflags |= PSL_IOPL;
1356 #elif defined(__x86_64__)
1357 curthread->td_lwp->lwp_md.md_regs->tf_rflags |= PSL_IOPL;
1359 lwkt_reltoken(&tty_token);
1362 case KDDISABIO: /* disallow io operations (default) */
1363 #if defined(__i386__)
1364 curthread->td_lwp->lwp_md.md_regs->tf_eflags &= ~PSL_IOPL;
1365 #elif defined(__x86_64__)
1366 curthread->td_lwp->lwp_md.md_regs->tf_rflags &= ~PSL_IOPL;
1368 lwkt_reltoken(&tty_token);
1371 case KDSKBSTATE: /* set keyboard state (locks) */
1372 if (*(int *)data & ~LOCK_MASK) {
1373 lwkt_reltoken(&tty_token);
1377 scp->status &= ~LOCK_MASK;
1378 scp->status |= *(int *)data;
1380 if (scp == sc->cur_scp)
1381 update_kbd_state(scp, scp->status, LOCK_MASK, FALSE);
1382 lwkt_reltoken(&tty_token);
1385 case KDGKBSTATE: /* get keyboard state (locks) */
1386 if (scp == sc->cur_scp)
1387 save_kbd_state(scp, FALSE);
1388 *(int *)data = scp->status & LOCK_MASK;
1389 lwkt_reltoken(&tty_token);
1392 case KDGETREPEAT: /* get keyboard repeat & delay rates */
1393 case KDSETREPEAT: /* set keyboard repeat & delay rates (new) */
1394 error = kbd_ioctl(sc->kbd, cmd, data);
1395 if (error == ENOIOCTL)
1397 lwkt_reltoken(&tty_token);
1400 case KDSKBMODE: /* set keyboard mode */
1401 switch (*(int *)data) {
1402 case K_XLATE: /* switch to XLT ascii mode */
1403 case K_RAW: /* switch to RAW scancode mode */
1404 case K_CODE: /* switch to CODE mode */
1405 scp->kbd_mode = *(int *)data;
1406 if (scp == sc->cur_scp)
1407 kbd_ioctl(sc->kbd, cmd, data);
1408 lwkt_reltoken(&tty_token);
1411 lwkt_reltoken(&tty_token);
1416 case KDGKBMODE: /* get keyboard mode */
1417 *(int *)data = scp->kbd_mode;
1418 lwkt_reltoken(&tty_token);
1422 error = kbd_ioctl(sc->kbd, cmd, data);
1423 if (error == ENOIOCTL)
1425 lwkt_reltoken(&tty_token);
1428 case KDMKTONE: /* sound the bell */
1431 sc_bell(scp, (*(int*)data)&0xffff,
1432 (((*(int*)data)>>16)&0xffff)*hz/1000);
1434 sc_bell(scp, scp->bell_pitch, scp->bell_duration);
1436 lwkt_reltoken(&tty_token);
1439 case KIOCSOUND: /* make tone (*data) hz */
1441 if (scp == sc->cur_scp) {
1443 error = sc_tone(*(int *)data);
1451 lwkt_reltoken(&tty_token);
1454 case KDGKBTYPE: /* get keyboard type */
1455 error = kbd_ioctl(sc->kbd, cmd, data);
1456 if (error == ENOIOCTL) {
1457 /* always return something? XXX */
1460 lwkt_reltoken(&tty_token);
1463 case KDSETLED: /* set keyboard LED status */
1464 if (*(int *)data & ~LED_MASK) { /* FIXME: LOCK_MASK? */
1465 lwkt_reltoken(&tty_token);
1469 scp->status &= ~LED_MASK;
1470 scp->status |= *(int *)data;
1472 if (scp == sc->cur_scp)
1473 update_kbd_leds(scp, scp->status);
1474 lwkt_reltoken(&tty_token);
1477 case KDGETLED: /* get keyboard LED status */
1478 if (scp == sc->cur_scp)
1479 save_kbd_state(scp, FALSE);
1480 *(int *)data = scp->status & LED_MASK;
1481 lwkt_reltoken(&tty_token);
1484 case KBADDKBD: /* add/remove keyboard to/from mux */
1486 error = kbd_ioctl(sc->kbd, cmd, data);
1487 if (error == ENOIOCTL)
1489 lwkt_reltoken(&tty_token);
1492 case CONS_SETKBD: /* set the new keyboard */
1496 newkbd = kbd_get_keyboard(*(int *)data);
1497 if (newkbd == NULL) {
1498 lwkt_reltoken(&tty_token);
1502 if (sc->kbd != newkbd) {
1503 i = kbd_allocate(newkbd->kb_name, newkbd->kb_unit,
1504 (void *)&sc->keyboard, sckbdevent, sc);
1505 /* i == newkbd->kb_index */
1507 if (sc->kbd != NULL) {
1508 save_kbd_state(sc->cur_scp, FALSE);
1509 kbd_release(sc->kbd, (void *)&sc->keyboard);
1512 sc->kbd = kbd_get_keyboard(i); /* sc->kbd == newkbd */
1515 kbd_ioctl(sc->kbd, KDSKBMODE,
1516 (caddr_t)&sc->cur_scp->kbd_mode);
1517 update_kbd_state(sc->cur_scp, sc->cur_scp->status,
1520 error = EPERM; /* XXX */
1523 lwkt_reltoken(&tty_token);
1527 case CONS_RELKBD: /* release the current keyboard */
1529 if (sc->kbd != NULL) {
1530 save_kbd_state(sc->cur_scp, FALSE);
1531 error = kbd_release(sc->kbd, (void *)&sc->keyboard);
1539 lwkt_reltoken(&tty_token);
1542 case CONS_GETTERM: /* get the current terminal emulator info */
1546 if (((term_info_t *)data)->ti_index == 0) {
1549 sw = sc_term_match_by_number(((term_info_t *)data)->ti_index);
1552 strncpy(((term_info_t *)data)->ti_name, sw->te_name,
1553 sizeof(((term_info_t *)data)->ti_name));
1554 strncpy(((term_info_t *)data)->ti_desc, sw->te_desc,
1555 sizeof(((term_info_t *)data)->ti_desc));
1556 ((term_info_t *)data)->ti_flags = 0;
1557 lwkt_reltoken(&tty_token);
1560 ((term_info_t *)data)->ti_name[0] = '\0';
1561 ((term_info_t *)data)->ti_desc[0] = '\0';
1562 ((term_info_t *)data)->ti_flags = 0;
1563 lwkt_reltoken(&tty_token);
1568 case CONS_SETTERM: /* set the current terminal emulator */
1570 error = sc_init_emulator(scp, ((term_info_t *)data)->ti_name);
1571 /* FIXME: what if scp == sc_console! XXX */
1573 lwkt_reltoken(&tty_token);
1576 case GIO_SCRNMAP: /* get output translation table */
1577 bcopy(&sc->scr_map, data, sizeof(sc->scr_map));
1578 lwkt_reltoken(&tty_token);
1581 case PIO_SCRNMAP: /* set output translation table */
1582 bcopy(data, &sc->scr_map, sizeof(sc->scr_map));
1583 for (i=0; i<sizeof(sc->scr_map); i++) {
1584 sc->scr_rmap[sc->scr_map[i]] = i;
1586 lwkt_reltoken(&tty_token);
1589 case GIO_KEYMAP: /* get keyboard translation table */
1590 case PIO_KEYMAP: /* set keyboard translation table */
1591 case GIO_DEADKEYMAP: /* get accent key translation table */
1592 case PIO_DEADKEYMAP: /* set accent key translation table */
1593 case GETFKEY: /* get function key string */
1594 case SETFKEY: /* set function key string */
1595 error = kbd_ioctl(sc->kbd, cmd, data);
1596 if (error == ENOIOCTL)
1598 lwkt_reltoken(&tty_token);
1601 #ifndef SC_NO_FONT_LOADING
1603 case PIO_FONT8x8: /* set 8x8 dot font */
1604 if (sc->fbi == NULL && !ISFONTAVAIL(sc->adp->va_flags)) {
1605 lwkt_reltoken(&tty_token);
1609 bcopy(data, sc->font_8, 8*256);
1610 sc->fonts_loaded |= FONT_8;
1613 * Always use the font page #0. XXX
1614 * Don't load if the current font size is not 8x8.
1617 && ISTEXTSC(sc->cur_scp) && (sc->cur_scp->font_height < 14)) {
1618 sc_load_font(sc->cur_scp, 0, 8, sc->font_8, 0, 256);
1621 lwkt_reltoken(&tty_token);
1624 case GIO_FONT8x8: /* get 8x8 dot font */
1625 if (sc->fbi == NULL && !ISFONTAVAIL(sc->adp->va_flags)) {
1626 lwkt_reltoken(&tty_token);
1629 if (sc->fonts_loaded & FONT_8) {
1630 bcopy(sc->font_8, data, 8*256);
1631 lwkt_reltoken(&tty_token);
1635 lwkt_reltoken(&tty_token);
1639 case PIO_FONT8x14: /* set 8x14 dot font */
1640 if (sc->fbi == NULL && !ISFONTAVAIL(sc->adp->va_flags)) {
1641 lwkt_reltoken(&tty_token);
1645 bcopy(data, sc->font_14, 14*256);
1646 sc->fonts_loaded |= FONT_14;
1649 * Always use the font page #0. XXX
1650 * Don't load if the current font size is not 8x14.
1653 && ISTEXTSC(sc->cur_scp)
1654 && (sc->cur_scp->font_height >= 14)
1655 && (sc->cur_scp->font_height < 16)) {
1656 sc_load_font(sc->cur_scp, 0, 14, sc->font_14, 0, 256);
1659 lwkt_reltoken(&tty_token);
1662 case GIO_FONT8x14: /* get 8x14 dot font */
1663 if (sc->fbi == NULL && !ISFONTAVAIL(sc->adp->va_flags)) {
1664 lwkt_reltoken(&tty_token);
1667 if (sc->fonts_loaded & FONT_14) {
1668 bcopy(sc->font_14, data, 14*256);
1669 lwkt_reltoken(&tty_token);
1673 lwkt_reltoken(&tty_token);
1677 case PIO_FONT8x16: /* set 8x16 dot font */
1678 if (sc->fbi == NULL && !ISFONTAVAIL(sc->adp->va_flags)) {
1679 lwkt_reltoken(&tty_token);
1683 bcopy(data, sc->font_16, 16*256);
1684 sc->fonts_loaded |= FONT_16;
1687 * Always use the font page #0. XXX
1688 * Don't load if the current font size is not 8x16.
1691 && ISTEXTSC(sc->cur_scp) && (sc->cur_scp->font_height >= 16)) {
1692 sc_load_font(sc->cur_scp, 0, 16, sc->font_16, 0, 256);
1695 lwkt_reltoken(&tty_token);
1698 case GIO_FONT8x16: /* get 8x16 dot font */
1699 if (sc->fbi == NULL && !ISFONTAVAIL(sc->adp->va_flags)) {
1700 lwkt_reltoken(&tty_token);
1703 if (sc->fonts_loaded & FONT_16) {
1704 bcopy(sc->font_16, data, 16*256);
1705 lwkt_reltoken(&tty_token);
1709 lwkt_reltoken(&tty_token);
1713 #endif /* SC_NO_FONT_LOADING */
1719 error = (*linesw[tp->t_line].l_ioctl)(tp, cmd, data, flag, ap->a_cred);
1720 if (error != ENOIOCTL) {
1721 lwkt_reltoken(&tty_token);
1724 error = ttioctl(tp, cmd, data, flag);
1725 if (error != ENOIOCTL) {
1726 lwkt_reltoken(&tty_token);
1729 lwkt_reltoken(&tty_token);
1734 scstart(struct tty *tp)
1738 u_char buf[PCBURST];
1739 scr_stat *scp = SC_STAT(tp->t_dev);
1742 if (scp->status & SLKED ||
1743 (scp == scp->sc->cur_scp && scp->sc->blink_in_progress))
1748 if (!(tp->t_state & (TS_TIMEOUT | TS_BUSY | TS_TTSTOP))) {
1749 tp->t_state |= TS_BUSY;
1752 len = q_to_b(rbp, buf, PCBURST);
1753 sc_puts(scp, buf, len);
1755 tp->t_state &= ~TS_BUSY;
1764 sccnprobe(struct consdev *cp)
1769 cp->cn_pri = sc_get_cons_priority(&unit, &flags);
1771 /* a video card is always required */
1772 if (probe_efi_fb(1) != 0 && !scvidprobe(unit, flags, TRUE))
1773 cp->cn_pri = CN_DEAD;
1775 /* syscons will become console even when there is no keyboard */
1776 sckbdprobe(unit, flags, TRUE);
1778 if (cp->cn_pri == CN_DEAD) {
1782 /* initialize required fields */
1783 cp->cn_probegood = 1;
1787 sccninit(struct consdev *cp)
1792 sc_get_cons_priority(&unit, &flags);
1793 scinit(unit, flags | SC_KERNEL_CONSOLE);
1794 sc_console_unit = unit;
1795 sc_console = sc_get_softc(unit, SC_KERNEL_CONSOLE)->console_scp;
1799 sccninit_fini(struct consdev *cp)
1801 if (cctl_dev == NULL)
1802 kprintf("sccninit_fini: WARNING: cctl_dev is NULL!\n");
1803 cp->cn_dev = cctl_dev;
1807 sccnterm(struct consdev *cp)
1809 /* we are not the kernel console any more, release everything */
1811 if (sc_console_unit < 0)
1812 return; /* shouldn't happen */
1816 sc_clear_screen(sc_console);
1817 sccnupdate(sc_console);
1820 scterm(sc_console_unit, SC_KERNEL_CONSOLE);
1821 sc_console_unit = -1;
1826 * Console path - cannot block!
1829 sccnputc(void *private, int c)
1832 scr_stat *scp = sc_console;
1834 #ifndef SC_NO_HISTORY
1838 #endif /* !SC_NO_HISTORY */
1840 /* assert(sc_console != NULL) */
1843 #ifndef SC_NO_HISTORY
1844 if (scp == scp->sc->cur_scp && scp->status & SLKED) {
1845 scp->status &= ~SLKED;
1847 /* This can block, illegal in the console path */
1848 update_kbd_state(scp, scp->status, SLKED, TRUE);
1850 if (scp->status & BUFFER_SAVED) {
1851 if (!sc_hist_restore(scp))
1852 sc_remove_cutmarking(scp);
1853 scp->status &= ~BUFFER_SAVED;
1854 scp->status |= CURSOR_ENABLED;
1855 sc_draw_cursor_image(scp);
1858 tp = VIRTUAL_TTY(scp->sc, scp->index);
1859 /* This can block, illegal in the console path */
1860 if (ISTTYOPEN(tp)) {
1865 #endif /* !SC_NO_HISTORY */
1868 if (kernel_console_ts != NULL)
1869 scp->ts = kernel_console_ts;
1871 sc_puts(scp, buf, 1);
1879 * Console path - cannot block!
1882 sccngetc(void *private)
1884 return sccngetch(0);
1888 * Console path - cannot block!
1891 sccncheckc(void *private)
1893 return sccngetch(SCGETC_NONBLOCK);
1897 * Set polling mode (also disables the tty feed), use when
1898 * polling for console key input.
1901 sccnpoll(void *private, int on)
1906 sc_touch_scrn_saver();
1907 scp = sc_console->sc->cur_scp; /* XXX */
1910 kbd_poll(scp->sc->kbd, on);
1914 sccndbctl(void *private, int on)
1916 /* assert(sc_console_unit >= 0) */
1917 /* try to switch to the kernel console screen */
1918 if (on && debugger == 0) {
1920 * TRY to make sure the screen saver is stopped,
1921 * and the screen is updated before switching to
1926 && sc_console->sc->cur_scp->smode.mode == VT_AUTO
1927 && sc_console->smode.mode == VT_AUTO) {
1928 sc_console->sc->cur_scp->status |= MOUSE_HIDDEN;
1930 sc_switch_scr(sc_console->sc, sc_console->index);
1941 * Console path - cannot block!
1944 sccngetch(int flags)
1946 static struct fkeytab fkey;
1954 /* assert(sc_console != NULL) */
1957 * Stop the screen saver and update the screen if necessary.
1958 * What if we have been running in the screen saver code... XXX
1960 sc_touch_scrn_saver();
1961 scp = sc_console->sc->cur_scp; /* XXX */
1965 if (fkeycp < fkey.len) {
1966 return fkey.str[fkeycp++];
1969 if (scp->sc->kbd == NULL) {
1974 * Make sure the keyboard is accessible even when the kbd device
1975 * driver is disabled.
1978 kbd_enable(scp->sc->kbd);
1980 /* we shall always use the keyboard in the XLATE mode here */
1981 cur_mode = scp->kbd_mode;
1982 scp->kbd_mode = K_XLATE;
1983 kbd_ioctl(scp->sc->kbd, KDSKBMODE, (caddr_t)&scp->kbd_mode);
1985 c = scgetc(scp->sc, SCGETC_CN | flags);
1987 scp->kbd_mode = cur_mode;
1988 kbd_ioctl(scp->sc->kbd, KDSKBMODE, (caddr_t)&scp->kbd_mode);
1989 kbd_disable(scp->sc->kbd);
1992 switch (KEYFLAGS(c)) {
1993 case 0: /* normal char */
1995 case FKEY: /* function key */
1996 p = kbd_get_fkeystr(scp->sc->kbd, KEYCHAR(c), (size_t *)&fkeycp);
1998 if ((p != NULL) && (fkey.len > 0)) {
1999 bcopy(p, fkey.str, fkey.len);
2005 if (flags & SCGETC_NONBLOCK)
2016 sccnupdate(scr_stat *scp)
2021 ddb_active = db_active;
2026 /* this is a cut-down version of scrn_timer()... */
2029 * Don't update if videoio is in progress. However, if we are paniced
2030 * or in the debugger it is possible that the variables might be stuck,
2031 * so ignore it in such cases.
2033 if (scp->sc->font_loading_in_progress || scp->sc->videoio_in_progress) {
2034 if (panicstr == NULL && ddb_active == 0 && shutdown_in_progress == 0)
2038 if (debugger > 0 || panicstr || ddb_active || shutdown_in_progress) {
2039 sc_touch_scrn_saver();
2040 } else if (scp != scp->sc->cur_scp) {
2044 if (!run_scrn_saver)
2045 scp->sc->flags &= ~SC_SCRN_IDLE;
2048 * This is a hard path, we cannot call stop_scrn_saver() here.
2050 if ((saver_mode != CONS_LKM_SAVER) || !(scp->sc->flags & SC_SCRN_IDLE))
2051 if (scp->sc->flags & SC_SCRN_BLANKED) {
2052 sc_touch_scrn_saver();
2053 /*stop_scrn_saver(scp->sc, current_saver);*/
2055 #endif /* NSPLASH */
2057 if (scp != scp->sc->cur_scp || scp->sc->blink_in_progress
2058 || scp->sc->switch_in_progress) {
2063 * FIXME: unlike scrn_timer(), we call scrn_update() from here even
2064 * when write_in_progress is non-zero. XXX
2066 if (!ISGRAPHSC(scp) && !(scp->sc->flags & SC_SCRN_BLANKED))
2067 scrn_update(scp, TRUE, SCRN_ASYNCOK);
2071 scrn_timer(void *arg)
2073 static int kbd_interval = 0;
2080 * Setup depending on who called us
2082 again = (arg != NULL);
2084 sc = (sc_softc_t *)arg;
2085 } else if (sc_console != NULL) {
2086 sc = sc_console->sc;
2092 * Don't do anything when we are performing some I/O operations.
2093 * (These are initiated by the frontend?)
2095 if (sc->font_loading_in_progress || sc->videoio_in_progress) {
2097 callout_reset(&sc->scrn_timer_ch, hz / 10, scrn_timer, sc);
2102 * Try to allocate a keyboard automatically
2104 if ((sc->kbd == NULL) && (sc->config & SC_AUTODETECT_KBD)) {
2105 if (++kbd_interval >= 25) {
2106 sc->keyboard = sc_allocate_keyboard(sc, -1);
2107 if (sc->keyboard >= 0) {
2108 sc->kbd = kbd_get_keyboard(sc->keyboard);
2109 kbd_ioctl(sc->kbd, KDSKBMODE,
2110 (caddr_t)&sc->cur_scp->kbd_mode);
2111 update_kbd_state(sc->cur_scp, sc->cur_scp->status,
2119 * Should we stop the screen saver? We need the syscons_lock
2120 * for most of this stuff.
2122 getmicrouptime(&tv);
2124 if (syscons_lock_nonblock() != 0) {
2125 /* failed to get the lock */
2127 callout_reset(&sc->scrn_timer_ch, hz / 10, scrn_timer, sc);
2130 /* successful lock */
2132 if (debugger > 0 || panicstr || shutdown_in_progress)
2133 sc_touch_scrn_saver();
2134 if (run_scrn_saver) {
2135 if (tv.tv_sec > sc->scrn_time_stamp + scrn_blank_time)
2136 sc->flags |= SC_SCRN_IDLE;
2138 sc->flags &= ~SC_SCRN_IDLE;
2140 sc->scrn_time_stamp = tv.tv_sec;
2141 sc->flags &= ~SC_SCRN_IDLE;
2142 if (scrn_blank_time > 0)
2143 run_scrn_saver = TRUE;
2146 if ((saver_mode != CONS_LKM_SAVER) || !(sc->flags & SC_SCRN_IDLE)) {
2147 if ((sc->flags & SC_SCRN_BLANKED) && !ISGRAPHSC(sc->cur_scp))
2148 stop_scrn_saver(sc, current_saver);
2150 #endif /* NSPLASH */
2152 /* should we just return ? */
2153 if (sc->blink_in_progress || sc->switch_in_progress ||
2154 sc->write_in_progress)
2158 callout_reset(&sc->scrn_timer_ch, hz / 10, scrn_timer, sc);
2162 /* Update the screen */
2163 scp = sc->cur_scp; /* cur_scp may have changed... */
2164 if (!ISGRAPHSC(scp) && !(sc->flags & SC_SCRN_BLANKED))
2165 scrn_update(scp, TRUE, SCRN_ASYNCOK);
2168 /* should we activate the screen saver? */
2169 if ((saver_mode == CONS_LKM_SAVER) && (sc->flags & SC_SCRN_IDLE))
2170 if (!ISGRAPHSC(scp) || (sc->flags & SC_SCRN_BLANKED))
2171 (*current_saver)(sc, TRUE);
2172 #endif /* NSPLASH */
2176 callout_reset(&sc->scrn_timer_ch, hz / 25, scrn_timer, sc);
2180 and_region(int *s1, int *e1, int s2, int e2)
2182 if (*e1 < s2 || e2 < *s1)
2184 *s1 = imax(*s1, s2);
2185 *e1 = imin(*e1, e2);
2190 * Refresh modified frame buffer range. Also used to
2191 * scroll (entire FB is marked modified).
2193 * This function is allowed to run without the syscons_lock,
2194 * so scp fields can change unexpected. We cache most values
2195 * that we care about and silently discard illegal ranges.
2198 scrn_update(scr_stat *scp, int show_cursor, int flags)
2209 ddb_active = db_active;
2215 * Try to run large screen updates as an async operation, which will
2216 * call this function again from a thread with BULKUNLOCK set, allowing
2217 * interrupts during the update which tends to make the system behave
2218 * better (no sound glitches, etc).
2220 if ((flags & SCRN_ASYNCOK) && syscons_async && scp->asynctd &&
2221 (scp->end - scp->start) > 16 &&
2222 panicstr == NULL && ddb_active == 0 && shutdown_in_progress == 0) {
2223 scp->show_cursor = show_cursor;
2224 scp->queue_update_td = 1;
2225 wakeup(&scp->asynctd);
2228 if (flags & SCRN_BULKUNLOCK)
2232 * Synchronous operation or called from
2235 /* assert(scp == scp->sc->cur_scp) */
2236 atomic_add_int(&scp->sc->videoio_in_progress, 1);
2238 cpos = scp->cursor_pos;
2239 copos = scp->cursor_oldpos;
2241 #ifndef SC_NO_CUTPASTE
2242 /* remove the previous mouse pointer image if necessary */
2243 if (scp->status & MOUSE_VISIBLE) {
2245 e = scp->mouse_pos + scp->xsize + 1;
2246 if ((scp->status & (MOUSE_MOVED | MOUSE_HIDDEN))
2247 || and_region(&s, &e, scp->start, scp->end)
2248 || ((scp->status & CURSOR_ENABLED) &&
2250 (and_region(&s, &e, cpos, cpos)
2251 || and_region(&s, &e, copos, copos)))) {
2252 sc_remove_mouse_image(scp);
2253 if (scp->end >= scp->xsize*scp->ysize)
2254 scp->end = scp->xsize*scp->ysize - 1;
2257 #endif /* !SC_NO_CUTPASTE */
2260 * WARNING: Don't add debugging kprintf()s with syscons locked.
2263 if (scp->end >= scp->xsize*scp->ysize) {
2264 scp->end = scp->xsize*scp->ysize - 1;
2266 if (scp->start < 0) {
2271 * Main update, extract update range and reset
2277 scp->start = scp->xsize * scp->ysize - 1;
2280 if (flags & SCRN_BULKUNLOCK) {
2281 atomic_add_int(&scp->sc->videoio_in_progress, -1);
2284 (*scp->rndr->draw)(scp, start, end - start + 1, FALSE);
2285 if (flags & SCRN_BULKUNLOCK) {
2287 atomic_add_int(&scp->sc->videoio_in_progress, 1);
2291 * Handle cut sequence
2293 s = scp->mouse_cut_start;
2294 e = scp->mouse_cut_end;
2295 cpu_ccfence(); /* allowed to race */
2303 /* does the cut-mark region overlap with the update region? */
2304 if (and_region(&s, &e, start, end)) {
2305 if (flags & SCRN_BULKUNLOCK) {
2306 atomic_add_int(&scp->sc->videoio_in_progress, -1);
2309 (*scp->rndr->draw)(scp, s, e - s + 1, TRUE);
2310 if (flags & SCRN_BULKUNLOCK) {
2312 atomic_add_int(&scp->sc->videoio_in_progress, 1);
2318 /* we are not to show the cursor and the mouse pointer... */
2322 /* update cursor image */
2323 if (scp->status & CURSOR_ENABLED) {
2326 /* did cursor move since last time ? */
2327 if (cpos != copos) {
2328 /* do we need to remove old cursor image ? */
2329 if (!and_region(&s, &e, copos, copos))
2330 sc_remove_cursor_image(scp);
2331 sc_draw_cursor_image(scp);
2333 if (s <= e && and_region(&s, &e, cpos, cpos)) {
2334 /* cursor didn't move, but has been overwritten */
2335 sc_draw_cursor_image(scp);
2336 } else if (scp->sc->flags & SC_BLINK_CURSOR) {
2337 /* if it's a blinking cursor, update it */
2338 (*scp->rndr->blink_cursor)(scp, cpos,
2339 sc_inside_cutmark(scp, cpos));
2344 #ifndef SC_NO_CUTPASTE
2345 /* update "pseudo" mouse pointer image */
2346 if (scp->sc->flags & SC_MOUSE_ENABLED) {
2347 if (!(scp->status & (MOUSE_VISIBLE | MOUSE_HIDDEN))) {
2348 scp->status &= ~MOUSE_MOVED;
2349 sc_draw_mouse_image(scp);
2352 #endif /* SC_NO_CUTPASTE */
2358 atomic_add_int(&scp->sc->videoio_in_progress, -1);
2359 if (flags & SCRN_BULKUNLOCK)
2364 * Thread handles potentially expensive screen updates. The function is
2365 * expected to operate safely without locks.
2368 scrn_update_thread(void *arg)
2370 scr_stat *scp = arg;
2372 if (scp->queue_update_td == 0) {
2373 tsleep_interlock(&scp->asynctd, 0);
2374 if (scp->queue_update_td == 0)
2375 tsleep(&scp->asynctd, PINTERLOCKED, "wait", 0);
2377 scp->queue_update_td = 0;
2378 lockmgr(&sc_asynctd_lk, LK_EXCLUSIVE);
2379 atomic_add_int(&scp->sc->videoio_in_progress, 1);
2380 scrn_update(scp, scp->show_cursor, SCRN_BULKUNLOCK);
2381 atomic_add_int(&scp->sc->videoio_in_progress, -1);
2382 lockmgr(&sc_asynctd_lk, LK_RELEASE);
2387 sc_fb_set_par(void *context, int pending)
2389 sc_softc_t *sc = context;
2390 scr_stat *scp = sc->cur_scp;
2392 lwkt_gettoken(&tty_token);
2393 if (ISTEXTSC(scp) &&
2394 sc->fbi != NULL && sc->fbi->fbops.fb_set_par != NULL) {
2395 sc->fbi->fbops.fb_set_par(sc->fbi);
2397 lwkt_reltoken(&tty_token);
2402 sc_fb_blank(void *context, int pending)
2404 sc_softc_t *sc = context;
2406 lwkt_gettoken(&tty_token);
2407 if (sc->fbi != NULL && sc->fbi->fbops.fb_blank != NULL) {
2408 /* 0 == FB_BLANK_UNBLANK and 4 == FB_BLANK_POWERDOWN */
2409 if (sc->flags & SC_SCRN_BLANKED) {
2410 sc->fbi->fbops.fb_blank(4, sc->fbi);
2411 sc->fb_blanked = TRUE;
2412 if (sc->unit == sc_console_unit)
2413 cons_unavail = TRUE;
2415 sc->fbi->fbops.fb_blank(0, sc->fbi);
2416 sc->fb_blanked = FALSE;
2417 if (sc->unit == sc_console_unit &&
2418 sc->cur_scp->smode.mode == VT_AUTO)
2419 cons_unavail = FALSE;
2422 lwkt_reltoken(&tty_token);
2426 scframebuffer_saver(sc_softc_t *sc, int show)
2428 scr_stat *scp = sc->cur_scp;
2434 * Gets called on every screen update while screensaver is active,
2435 * so we need to check the SC_SCRN_BLANKED flag ourselves.
2437 if ((sc->flags & SC_SCRN_BLANKED) && show)
2440 taskqueue_cancel(taskqueue_thread[0], sc->fb_blank_task, NULL);
2443 scp->status |= SAVER_RUNNING;
2444 sc->flags |= SC_SCRN_BLANKED;
2447 scp->status &= ~SAVER_RUNNING;
2448 sc->flags &= ~SC_SCRN_BLANKED;
2452 taskqueue_enqueue(taskqueue_thread[0], sc->fb_blank_task);
2456 scsplash_callback(int event, void *arg)
2461 sc = (sc_softc_t *)arg;
2465 if (add_scrn_saver(scsplash_saver) == 0) {
2466 sc->flags &= ~SC_SAVER_FAILED;
2467 run_scrn_saver = TRUE;
2469 scsplash_stick(TRUE);
2470 (*current_saver)(sc, TRUE);
2476 if (current_saver == scsplash_saver) {
2477 scsplash_stick(FALSE);
2478 error = remove_scrn_saver(scsplash_saver);
2491 scsplash_saver(sc_softc_t *sc, int show)
2493 static int busy = FALSE;
2502 if (!(sc->flags & SC_SAVER_FAILED)) {
2503 if (!(sc->flags & SC_SCRN_BLANKED))
2504 set_scrn_saver_mode(scp, -1, NULL, 0);
2505 switch (splash(sc->adp, TRUE)) {
2506 case 0: /* succeeded */
2508 case EAGAIN: /* try later */
2509 restore_scrn_saver_mode(scp, FALSE);
2510 sc_touch_scrn_saver(); /* XXX */
2513 sc->flags |= SC_SAVER_FAILED;
2514 scsplash_stick(FALSE);
2515 restore_scrn_saver_mode(scp, TRUE);
2516 kprintf("scsplash_saver(): failed to put up the image\n");
2520 } else if (!sticky_splash) {
2521 if ((sc->flags & SC_SCRN_BLANKED) && (splash(sc->adp, FALSE) == 0))
2522 restore_scrn_saver_mode(scp, TRUE);
2528 add_scrn_saver(void (*this_saver)(sc_softc_t *, int))
2533 if (current_saver != none_saver) {
2534 error = remove_scrn_saver(current_saver);
2539 if (current_saver != none_saver) {
2543 run_scrn_saver = FALSE;
2544 saver_mode = CONS_LKM_SAVER;
2545 current_saver = this_saver;
2550 remove_scrn_saver(void (*this_saver)(sc_softc_t *, int))
2552 if (current_saver != this_saver)
2557 * In order to prevent `current_saver' from being called by
2558 * the timeout routine `scrn_timer()' while we manipulate
2559 * the saver list, we shall set `current_saver' to `none_saver'
2560 * before stopping the current saver, rather than blocking by `splXX()'.
2562 current_saver = none_saver;
2564 stop_scrn_saver(this_saver);
2566 /* unblank all blanked screens */
2567 wait_scrn_saver_stop(NULL, FALSE);
2572 current_saver = none_saver;
2577 set_scrn_saver_mode(scr_stat *scp, int mode, u_char *pal, int border)
2580 /* assert(scp == scp->sc->cur_scp) */
2582 if (!ISGRAPHSC(scp))
2583 sc_remove_cursor_image(scp);
2584 scp->splash_save_mode = scp->mode;
2585 scp->splash_save_status = scp->status & (GRAPHICS_MODE | PIXEL_MODE);
2586 scp->status &= ~(GRAPHICS_MODE | PIXEL_MODE);
2587 scp->status |= (UNKNOWN_MODE | SAVER_RUNNING);
2588 scp->sc->flags |= SC_SCRN_BLANKED;
2595 if (set_mode(scp) == 0) {
2596 if (scp->sc->fbi == NULL &&
2597 scp->sc->adp->va_info.vi_flags & V_INFO_GRAPHICS) {
2598 scp->status |= GRAPHICS_MODE;
2600 #ifndef SC_NO_PALETTE_LOADING
2601 if (scp->sc->fbi == NULL && pal != NULL)
2602 load_palette(scp->sc->adp, pal);
2604 sc_set_border(scp, border);
2608 scp->mode = scp->splash_save_mode;
2609 scp->status &= ~(UNKNOWN_MODE | SAVER_RUNNING);
2610 scp->status |= scp->splash_save_status;
2618 restore_scrn_saver_mode(scr_stat *scp, int changemode)
2623 /* assert(scp == scp->sc->cur_scp) */
2626 status = scp->status;
2627 scp->mode = scp->splash_save_mode;
2628 scp->status &= ~(UNKNOWN_MODE | SAVER_RUNNING);
2629 scp->status |= scp->splash_save_status;
2630 scp->sc->flags &= ~SC_SCRN_BLANKED;
2632 if (!ISGRAPHSC(scp))
2633 sc_draw_cursor_image(scp);
2638 if (set_mode(scp) == 0) {
2639 #ifndef SC_NO_PALETTE_LOADING
2640 if (scp->sc->fbi == NULL)
2641 load_palette(scp->sc->adp, scp->sc->palette);
2648 scp->status = status;
2656 stop_scrn_saver(sc_softc_t *sc, void (*saver)(sc_softc_t *, int))
2658 (*saver)(sc, FALSE);
2659 run_scrn_saver = FALSE;
2660 /* the screen saver may have chosen not to stop after all... */
2661 if (sc->flags & SC_SCRN_BLANKED) {
2665 mark_all(sc->cur_scp);
2666 if (sc->delayed_next_scr)
2667 sc_switch_scr(sc, sc->delayed_next_scr - 1);
2668 wakeup(&scrn_blanked);
2672 wait_scrn_saver_stop(sc_softc_t *sc, int need_unlock)
2676 while (scrn_blanked > 0) {
2677 run_scrn_saver = FALSE;
2678 if (sc && !(sc->flags & SC_SCRN_BLANKED)) {
2683 tsleep_interlock(&scrn_blanked, PCATCH);
2685 error = tsleep(&scrn_blanked, PCATCH | PINTERLOCKED, "scrsav", 0);
2688 error = tsleep(&scrn_blanked, PCATCH, "scrsav", 0);
2690 /* May return ERESTART */
2694 run_scrn_saver = FALSE;
2697 #endif /* NSPLASH */
2700 sc_start_scrn_saver(sc_softc_t *sc)
2703 (*current_saver)(sc, TRUE);
2708 sc_stop_scrn_saver(sc_softc_t *sc)
2711 if (sc->flags & SC_SCRN_BLANKED)
2712 stop_scrn_saver(sc, current_saver);
2717 sc_touch_scrn_saver(void)
2719 scsplash_stick(FALSE);
2720 run_scrn_saver = FALSE;
2724 sc_switch_scr(sc_softc_t *sc, u_int next_scr)
2729 DPRINTF(5, ("sc0: sc_switch_scr() %d ", next_scr + 1));
2731 /* prevent switch if previously requested */
2732 if (sc->flags & SC_SCRN_VTYLOCK) {
2733 sc_bell(sc->cur_scp, sc->cur_scp->bell_pitch,
2734 sc->cur_scp->bell_duration);
2738 /* delay switch if the screen is blanked or being updated */
2739 if ((sc->flags & SC_SCRN_BLANKED) || sc->write_in_progress
2740 || sc->blink_in_progress || sc->videoio_in_progress) {
2741 sc->delayed_next_scr = next_scr + 1;
2742 sc_touch_scrn_saver();
2743 DPRINTF(5, ("switch delayed\n"));
2747 cur_scp = sc->cur_scp;
2750 * we are in the middle of the vty switching process...
2752 * This may be in the console path, be very careful. pfindn() is
2753 * still going to use a spinlock but it no longer uses tokens so
2756 if (sc->switch_in_progress &&
2757 (cur_scp->smode.mode == VT_PROCESS) &&
2759 if (cur_scp->proc != pfindn(cur_scp->pid)) {
2761 * The controlling process has died!!. Do some clean up.
2762 * NOTE:`cur_scp->proc' and `cur_scp->smode.mode'
2763 * are not reset here yet; they will be cleared later.
2765 DPRINTF(5, ("cur_scp controlling process %d died, ", cur_scp->pid));
2766 if (cur_scp->status & SWITCH_WAIT_REL) {
2768 * Force the previous switch to finish, but return now
2772 DPRINTF(5, ("reset WAIT_REL, "));
2773 finish_vt_rel(cur_scp, TRUE);
2774 DPRINTF(5, ("finishing previous switch\n"));
2776 } else if (cur_scp->status & SWITCH_WAIT_ACQ) {
2777 /* let's assume screen switch has been completed. */
2778 DPRINTF(5, ("reset WAIT_ACQ, "));
2779 finish_vt_acq(cur_scp);
2782 * We are in between screen release and acquisition, and
2783 * reached here via scgetc() or scrn_timer() which has
2784 * interrupted exchange_scr(). Don't do anything stupid.
2786 DPRINTF(5, ("waiting nothing, "));
2790 * The controlling process is alive, but not responding...
2791 * It is either buggy or it may be just taking time.
2792 * The following code is a gross kludge to cope with this
2793 * problem for which there is no clean solution. XXX
2795 if (cur_scp->status & SWITCH_WAIT_REL) {
2796 switch (sc->switch_in_progress++) {
2800 DPRINTF(5, ("sending relsig again, "));
2801 signal_vt_rel(cur_scp);
2808 * Act as if the controlling program returned
2812 DPRINTF(5, ("force reset WAIT_REL, "));
2813 finish_vt_rel(cur_scp, FALSE);
2814 DPRINTF(5, ("act as if VT_FALSE was seen\n"));
2817 } else if (cur_scp->status & SWITCH_WAIT_ACQ) {
2818 switch (sc->switch_in_progress++) {
2822 DPRINTF(5, ("sending acqsig again, "));
2823 signal_vt_acq(cur_scp);
2829 /* clear the flag and finish the previous switch */
2830 DPRINTF(5, ("force reset WAIT_ACQ, "));
2831 finish_vt_acq(cur_scp);
2839 * Return error if an invalid argument is given, or vty switch
2840 * is still in progress.
2842 if ((next_scr < sc->first_vty) || (next_scr >= sc->first_vty + sc->vtys)
2843 || sc->switch_in_progress) {
2844 sc_bell(cur_scp, bios_value.bell_pitch, BELL_DURATION);
2845 DPRINTF(5, ("error 1\n"));
2850 * Don't allow switching away from the graphics mode vty
2851 * if the switch mode is VT_AUTO, unless the next vty is the same
2852 * as the current or the current vty has been closed (but showing).
2854 tp = VIRTUAL_TTY(sc, cur_scp->index);
2855 if ((cur_scp->index != next_scr)
2857 && (cur_scp->smode.mode == VT_AUTO)
2858 && ISGRAPHSC(cur_scp)) {
2859 sc_bell(cur_scp, bios_value.bell_pitch, BELL_DURATION);
2860 DPRINTF(5, ("error, graphics mode\n"));
2865 * Is the wanted vty open? Don't allow switching to a closed vty.
2866 * If we are in DDB, don't switch to a vty in the VT_PROCESS mode.
2867 * Note that we always allow the user to switch to the kernel
2868 * console even if it is closed.
2870 if ((sc_console == NULL) || (next_scr != sc_console->index)) {
2871 tp = VIRTUAL_TTY(sc, next_scr);
2872 if (!ISTTYOPEN(tp)) {
2873 sc_bell(cur_scp, bios_value.bell_pitch, BELL_DURATION);
2874 DPRINTF(5, ("error 2, requested vty isn't open!\n"));
2877 if ((debugger > 0) && (SC_STAT(tp->t_dev)->smode.mode == VT_PROCESS)) {
2878 DPRINTF(5, ("error 3, requested vty is in the VT_PROCESS mode\n"));
2883 /* this is the start of vty switching process... */
2884 ++sc->switch_in_progress;
2885 sc->delayed_next_scr = 0;
2886 sc->old_scp = cur_scp;
2887 sc->new_scp = SC_STAT(SC_DEV(sc, next_scr));
2888 if (sc->new_scp == sc->old_scp) {
2889 sc->switch_in_progress = 0;
2890 wakeup((caddr_t)&sc->new_scp->smode);
2891 DPRINTF(5, ("switch done (new == old)\n"));
2895 /* has controlling process died? */
2896 vt_proc_alive(sc->old_scp);
2897 vt_proc_alive(sc->new_scp);
2899 /* wait for the controlling process to release the screen, if necessary */
2900 if (signal_vt_rel(sc->old_scp)) {
2904 /* go set up the new vty screen */
2907 /* wake up processes waiting for this vty */
2908 wakeup((caddr_t)&sc->cur_scp->smode);
2910 /* wait for the controlling process to acknowledge, if necessary */
2911 if (signal_vt_acq(sc->cur_scp)) {
2915 sc->switch_in_progress = 0;
2916 if (sc->unit == sc_console_unit && !sc->fb_blanked)
2917 cons_unavail = FALSE;
2918 DPRINTF(5, ("switch done\n"));
2924 do_switch_scr(sc_softc_t *sc)
2926 lwkt_gettoken(&tty_token);
2927 vt_proc_alive(sc->new_scp);
2930 /* sc->cur_scp == sc->new_scp */
2931 wakeup((caddr_t)&sc->cur_scp->smode);
2933 /* wait for the controlling process to acknowledge, if necessary */
2934 if (!signal_vt_acq(sc->cur_scp)) {
2935 sc->switch_in_progress = 0;
2936 if (sc->unit == sc_console_unit && !sc->fb_blanked)
2937 cons_unavail = FALSE;
2939 lwkt_reltoken(&tty_token);
2943 vt_proc_alive(scr_stat *scp)
2945 lwkt_gettoken(&tty_token);
2947 if (scp->proc == pfindn(scp->pid)) {
2948 lwkt_reltoken(&tty_token);
2952 scp->smode.mode = VT_AUTO;
2953 DPRINTF(5, ("vt controlling process %d died\n", scp->pid));
2955 lwkt_reltoken(&tty_token);
2960 signal_vt_rel(scr_stat *scp)
2964 lwkt_gettoken(&tty_token);
2965 if (scp->smode.mode != VT_PROCESS) {
2966 lwkt_reltoken(&tty_token);
2969 scp->status |= SWITCH_WAIT_REL;
2972 ksignal(p, scp->smode.relsig);
2974 DPRINTF(5, ("sending relsig to %d\n", scp->pid));
2975 lwkt_reltoken(&tty_token);
2981 signal_vt_acq(scr_stat *scp)
2985 lwkt_gettoken(&tty_token);
2986 if (scp->smode.mode != VT_PROCESS) {
2987 lwkt_reltoken(&tty_token);
2990 if (scp->sc->unit == sc_console_unit)
2991 cons_unavail = TRUE;
2992 scp->status |= SWITCH_WAIT_ACQ;
2995 ksignal(p, scp->smode.acqsig);
2997 DPRINTF(5, ("sending acqsig to %d\n", scp->pid));
2998 lwkt_reltoken(&tty_token);
3004 finish_vt_rel(scr_stat *scp, int release)
3006 lwkt_gettoken(&tty_token);
3007 if (scp == scp->sc->old_scp && scp->status & SWITCH_WAIT_REL) {
3008 scp->status &= ~SWITCH_WAIT_REL;
3010 do_switch_scr(scp->sc);
3012 scp->sc->switch_in_progress = 0;
3013 lwkt_reltoken(&tty_token);
3016 lwkt_reltoken(&tty_token);
3021 finish_vt_acq(scr_stat *scp)
3023 lwkt_gettoken(&tty_token);
3024 if (scp == scp->sc->new_scp && scp->status & SWITCH_WAIT_ACQ) {
3025 scp->status &= ~SWITCH_WAIT_ACQ;
3026 scp->sc->switch_in_progress = 0;
3027 lwkt_reltoken(&tty_token);
3030 lwkt_reltoken(&tty_token);
3035 exchange_scr(sc_softc_t *sc)
3039 lwkt_gettoken(&tty_token);
3040 /* save the current state of video and keyboard */
3041 sc_move_cursor(sc->old_scp, sc->old_scp->xpos, sc->old_scp->ypos);
3042 if (!ISGRAPHSC(sc->old_scp))
3043 sc_remove_cursor_image(sc->old_scp);
3044 if (sc->old_scp->kbd_mode == K_XLATE)
3045 save_kbd_state(sc->old_scp, TRUE);
3047 /* set up the video for the new screen */
3048 scp = sc->cur_scp = sc->new_scp;
3049 if (sc->old_scp->mode != scp->mode || ISUNKNOWNSC(sc->old_scp))
3051 else if (sc->adp != NULL)
3052 sc_vtb_init(&scp->scr, VTB_FRAMEBUFFER, scp->xsize, scp->ysize,
3053 (void *)sc->adp->va_window, FALSE);
3054 scp->status |= MOUSE_HIDDEN;
3055 sc_update_render(scp); /* Switch to kms renderer if necessary */
3056 sc_move_cursor(scp, scp->xpos, scp->ypos);
3057 if (!ISGRAPHSC(scp))
3058 sc_set_cursor_image(scp);
3059 #ifndef SC_NO_PALETTE_LOADING
3060 if (sc->fbi == NULL && ISGRAPHSC(sc->old_scp))
3061 load_palette(sc->adp, sc->palette);
3063 if (!ISGRAPHSC(scp) || sc->fbi == NULL)
3064 sc_set_border(scp, scp->border);
3066 /* set up the keyboard for the new screen */
3067 if (sc->old_scp->kbd_mode != scp->kbd_mode)
3068 kbd_ioctl(sc->kbd, KDSKBMODE, (caddr_t)&scp->kbd_mode);
3069 update_kbd_state(scp, scp->status, LOCK_MASK, TRUE);
3074 * Restore DRM framebuffer console mode if necessary.
3075 * Especially avoid modesetting when switching to a vt which is in
3076 * graphics mode, because the fb_set_par() from the taskqueue thread
3077 * might race with the modesetting ioctl from the userland application.
3079 if (ISTEXTSC(scp) && !ISTEXTSC(sc->old_scp) &&
3080 sc->fbi != NULL && sc->fbi->fbops.fb_set_par != NULL &&
3081 sc->fb_set_par_task != NULL) {
3082 taskqueue_enqueue(taskqueue_thread[0], sc->fb_set_par_task);
3085 lwkt_reltoken(&tty_token);
3089 sc_puts(scr_stat *scp, u_char *buf, int len)
3092 /* make screensaver happy */
3093 if (!sticky_splash && scp == scp->sc->cur_scp)
3094 run_scrn_saver = FALSE;
3098 (*scp->tsw->te_puts)(scp, buf, len);
3100 if (scp->sc->delayed_next_scr)
3101 sc_switch_scr(scp->sc, scp->sc->delayed_next_scr - 1);
3106 sc_draw_cursor_image(scr_stat *scp)
3108 /* assert(scp == scp->sc->cur_scp); */
3109 atomic_add_int(&scp->sc->videoio_in_progress, 1);
3110 (*scp->rndr->draw_cursor)(scp, scp->cursor_pos,
3111 scp->sc->flags & SC_BLINK_CURSOR, TRUE,
3112 sc_inside_cutmark(scp, scp->cursor_pos));
3113 scp->cursor_oldpos = scp->cursor_pos;
3114 atomic_add_int(&scp->sc->videoio_in_progress, -1);
3118 sc_remove_cursor_image(scr_stat *scp)
3120 /* assert(scp == scp->sc->cur_scp); */
3121 atomic_add_int(&scp->sc->videoio_in_progress, 1);
3122 (*scp->rndr->draw_cursor)(scp, scp->cursor_oldpos,
3123 scp->sc->flags & SC_BLINK_CURSOR, FALSE,
3124 sc_inside_cutmark(scp, scp->cursor_oldpos));
3125 atomic_add_int(&scp->sc->videoio_in_progress, -1);
3129 update_cursor_image(scr_stat *scp)
3133 if (scp->sc->flags & SC_CHAR_CURSOR) {
3134 scp->cursor_base = imax(0, scp->sc->cursor_base);
3135 scp->cursor_height = imin(scp->sc->cursor_height, scp->font_height);
3137 scp->cursor_base = 0;
3138 scp->cursor_height = scp->font_height;
3140 blink = scp->sc->flags & SC_BLINK_CURSOR;
3142 /* assert(scp == scp->sc->cur_scp); */
3143 atomic_add_int(&scp->sc->videoio_in_progress, 1);
3144 (*scp->rndr->draw_cursor)(scp, scp->cursor_oldpos, blink, FALSE,
3145 sc_inside_cutmark(scp, scp->cursor_pos));
3146 (*scp->rndr->set_cursor)(scp, scp->cursor_base, scp->cursor_height, blink);
3147 (*scp->rndr->draw_cursor)(scp, scp->cursor_pos, blink, TRUE,
3148 sc_inside_cutmark(scp, scp->cursor_pos));
3149 atomic_add_int(&scp->sc->videoio_in_progress, -1);
3153 sc_set_cursor_image(scr_stat *scp)
3155 if (scp->sc->flags & SC_CHAR_CURSOR) {
3156 scp->cursor_base = imax(0, scp->sc->cursor_base);
3157 scp->cursor_height = imin(scp->sc->cursor_height, scp->font_height);
3159 scp->cursor_base = 0;
3160 scp->cursor_height = scp->font_height;
3163 /* assert(scp == scp->sc->cur_scp); */
3164 atomic_add_int(&scp->sc->videoio_in_progress, 1);
3165 (*scp->rndr->set_cursor)(scp, scp->cursor_base, scp->cursor_height,
3166 scp->sc->flags & SC_BLINK_CURSOR);
3167 atomic_add_int(&scp->sc->videoio_in_progress, -1);
3171 scinit(int unit, int flags)
3174 * When syscons is being initialized as the kernel console, malloc()
3175 * is not yet functional, because various kernel structures has not been
3176 * fully initialized yet. Therefore, we need to declare the following
3177 * static buffers for the console. This is less than ideal,
3178 * but is necessry evil for the time being. XXX
3180 static scr_stat main_console;
3181 static u_short sc_buffer[ROW*COL]; /* XXX */
3182 #ifndef SC_NO_FONT_LOADING
3183 static u_char font_8[256*8];
3184 static u_char font_14[256*14];
3185 static u_char font_16[256*16];
3190 video_adapter_t *adp;
3191 char tbuf[MAKEDEV_MINNBUF];
3196 /* one time initialization */
3197 if (init_done == COLD)
3198 sc_get_bios_values(&bios_value);
3202 * Allocate resources. Even if we are being called for the second
3203 * time, we must allocate them again, because they might have
3206 sc = sc_get_softc(unit, flags & SC_KERNEL_CONSOLE);
3208 if (flags & SC_EFI_FB) {
3209 /* Don't replace already registered drm framebuffer here */
3210 if (sc->fbi == NULL) {
3211 sc->fbi = &efi_fb_info;
3212 sc->fbi_generation++;
3214 } else if (sc->adapter >= 0) {
3215 vid_release(sc->adp, (void *)&sc->adapter);
3219 if (sc->keyboard >= 0) {
3220 DPRINTF(5, ("sc%d: releasing kbd%d\n", unit, sc->keyboard));
3221 i = kbd_release(sc->kbd, (void *)&sc->keyboard);
3222 DPRINTF(5, ("sc%d: kbd_release returned %d\n", unit, i));
3223 if (sc->kbd != NULL) {
3224 DPRINTF(5, ("sc%d: kbd != NULL!, index:%d, unit:%d, flags:0x%x\n",
3225 unit, sc->kbd->kb_index, sc->kbd->kb_unit, sc->kbd->kb_flags));
3229 if (!(flags & SC_EFI_FB)) {
3230 sc->adapter = vid_allocate("*", unit, (void *)&sc->adapter);
3231 sc->adp = vid_get_adapter(sc->adapter);
3232 /* assert((sc->adapter >= 0) && (sc->adp != NULL)) */
3234 sc->keyboard = sc_allocate_keyboard(sc, unit);
3235 DPRINTF(1, ("sc%d: keyboard %d\n", unit, sc->keyboard));
3236 sc->kbd = kbd_get_keyboard(sc->keyboard);
3237 if (sc->kbd != NULL) {
3238 DPRINTF(1, ("sc%d: kbd index:%d, unit:%d, flags:0x%x\n",
3239 unit, sc->kbd->kb_index, sc->kbd->kb_unit, sc->kbd->kb_flags));
3242 if (!(sc->flags & SC_INIT_DONE) || (adp != sc->adp)) {
3244 if (sc->fbi != NULL)
3245 sc->initial_mode = 0;
3247 sc->initial_mode = sc->adp->va_initial_mode;
3249 #ifndef SC_NO_FONT_LOADING
3250 if (flags & SC_KERNEL_CONSOLE) {
3251 sc->font_8 = font_8;
3252 sc->font_14 = font_14;
3253 sc->font_16 = font_16;
3254 } else if (sc->font_8 == NULL) {
3255 /* assert(sc_malloc) */
3256 sc->font_8 = kmalloc(sizeof(font_8), M_SYSCONS, M_WAITOK);
3257 sc->font_14 = kmalloc(sizeof(font_14), M_SYSCONS, M_WAITOK);
3258 sc->font_16 = kmalloc(sizeof(font_16), M_SYSCONS, M_WAITOK);
3262 if (sc->fbi != NULL) {
3266 lwkt_gettoken(&tty_token);
3267 /* extract the hw cursor location and hide the cursor for now */
3268 (*vidsw[sc->adapter]->read_hw_cursor)(sc->adp, &col, &row);
3269 (*vidsw[sc->adapter]->set_hw_cursor)(sc->adp, -1, -1);
3270 lwkt_reltoken(&tty_token);
3273 /* set up the first console */
3274 sc->first_vty = unit*MAXCONS;
3275 sc->vtys = MAXCONS; /* XXX: should be configurable */
3276 if (flags & SC_KERNEL_CONSOLE) {
3277 scp = &main_console;
3278 sc->console_scp = scp;
3279 init_scp(sc, sc->first_vty, scp);
3280 sc_vtb_init(&scp->vtb, VTB_MEMORY, scp->xsize, scp->ysize,
3281 (void *)sc_buffer, FALSE);
3282 if (sc_init_emulator(scp, SC_DFLT_TERM))
3283 sc_init_emulator(scp, "*");
3284 (*scp->tsw->te_default_attr)(scp,
3285 kernel_default.std_color,
3286 kernel_default.rev_color);
3288 /* assert(sc_malloc) */
3289 sc->dev = kmalloc(sizeof(cdev_t)*sc->vtys, M_SYSCONS, M_WAITOK | M_ZERO);
3291 sc->dev[0] = make_dev(&sc_ops, unit*MAXCONS, UID_ROOT,
3292 GID_WHEEL, 0600, "ttyv%s",
3293 makedev_unit_b32(tbuf, unit * MAXCONS));
3295 sc->dev[0]->si_tty = ttymalloc(sc->dev[0]->si_tty);
3296 scp = alloc_scp(sc, sc->first_vty);
3297 sc->dev[0]->si_drv1 = scp;
3301 /* copy screen to temporary buffer */
3302 if (scp->sc->fbi == NULL) {
3303 sc_vtb_init(&scp->scr, VTB_FRAMEBUFFER, scp->xsize, scp->ysize,
3304 (void *)scp->sc->adp->va_window, FALSE);
3306 sc_vtb_copy(&scp->scr, 0, &scp->vtb, 0, scp->xsize*scp->ysize);
3309 /* move cursors to the initial positions */
3310 if (col >= scp->xsize)
3312 if (row >= scp->ysize)
3313 row = scp->ysize - 1;
3316 if (sc->fbi != NULL) {
3317 scp->cursor_pos = 0;
3318 sc->cursor_base = 0;
3319 sc->cursor_height = scp->font_height;
3321 scp->cursor_pos = scp->cursor_oldpos = row*scp->xsize + col;
3322 if (bios_value.cursor_end < scp->font_height)
3323 sc->cursor_base = scp->font_height - bios_value.cursor_end - 1;
3325 sc->cursor_base = 0;
3326 i = bios_value.cursor_end - bios_value.cursor_start + 1;
3327 sc->cursor_height = imin(i, scp->font_height);
3329 #ifndef SC_NO_SYSMOUSE
3330 sc_mouse_move(scp, scp->xpixel/2, scp->ypixel/2);
3332 if (!ISGRAPHSC(scp)) {
3333 sc_set_cursor_image(scp);
3334 sc_draw_cursor_image(scp);
3335 /* If framebuffer vaddr is still 0, we can't draw the border yet */
3336 if (scp->sc->fbi != NULL && scp->sc->fbi->vaddr != 0) {
3337 sc_filled_border = TRUE;
3338 sc_set_border(scp, scp->border);
3342 /* save font and palette */
3343 #ifndef SC_NO_FONT_LOADING
3344 sc->fonts_loaded = 0;
3346 bcopy(dflt_font_8, sc->font_8, sizeof(dflt_font_8));
3347 bcopy(dflt_font_14, sc->font_14, sizeof(dflt_font_14));
3348 bcopy(dflt_font_16, sc->font_16, sizeof(dflt_font_16));
3349 sc->fonts_loaded = FONT_16 | FONT_14 | FONT_8;
3350 #endif /* SC_DFLT_FONT */
3351 if (sc->adp != NULL && ISFONTAVAIL(sc->adp->va_flags)) {
3353 if (scp->font_height < 14) {
3354 sc_load_font(scp, 0, 8, sc->font_8, 0, 256);
3355 } else if (scp->font_height >= 16) {
3356 sc_load_font(scp, 0, 16, sc->font_16, 0, 256);
3358 sc_load_font(scp, 0, 14, sc->font_14, 0, 256);
3360 #else /* !SC_DFLT_FONT */
3361 if (scp->font_height < 14) {
3362 sc_save_font(scp, 0, 8, sc->font_8, 0, 256);
3363 sc->fonts_loaded = FONT_8;
3364 } else if (scp->font_height >= 16) {
3365 sc_save_font(scp, 0, 16, sc->font_16, 0, 256);
3366 sc->fonts_loaded = FONT_16;
3368 sc_save_font(scp, 0, 14, sc->font_14, 0, 256);
3369 sc->fonts_loaded = FONT_14;
3371 #endif /* SC_DFLT_FONT */
3372 /* FONT KLUDGE: always use the font page #0. XXX */
3373 sc_show_font(scp, 0);
3375 #endif /* !SC_NO_FONT_LOADING */
3377 #ifndef SC_NO_PALETTE_LOADING
3378 if (!(flags & SC_EFI_FB))
3379 save_palette(sc->adp, sc->palette);
3383 if (!(sc->flags & SC_SPLASH_SCRN) && (flags & SC_KERNEL_CONSOLE)) {
3384 /* we are ready to put up the splash image! */
3385 splash_init(sc->adp, scsplash_callback, sc);
3386 sc->flags |= SC_SPLASH_SCRN;
3388 #endif /* NSPLASH */
3391 /* the rest is not necessary, if we have done it once */
3392 if (sc->flags & SC_INIT_DONE) {
3396 /* initialize mapscrn arrays to a one to one map */
3397 for (i = 0; i < sizeof(sc->scr_map); i++)
3398 sc->scr_map[i] = sc->scr_rmap[i] = i;
3400 sc->flags |= SC_INIT_DONE;
3404 scterm(int unit, int flags)
3409 sc = sc_get_softc(unit, flags & SC_KERNEL_CONSOLE);
3411 return; /* shouldn't happen */
3413 lwkt_gettoken(&tty_token);
3415 /* this console is no longer available for the splash screen */
3416 if (sc->flags & SC_SPLASH_SCRN) {
3417 splash_term(sc->adp);
3418 sc->flags &= ~SC_SPLASH_SCRN;
3420 #endif /* NSPLASH */
3423 /* move the hardware cursor to the upper-left corner */
3424 (*vidsw[sc->adapter]->set_hw_cursor)(sc->adp, 0, 0);
3427 /* release the keyboard and the video card */
3428 if (sc->keyboard >= 0)
3429 kbd_release(sc->kbd, &sc->keyboard);
3430 if (sc->adapter >= 0)
3431 vid_release(sc->adp, &sc->adapter);
3434 * Stop the terminal emulator, if any. If operating on the
3435 * kernel console sc->dev may not be setup yet.
3437 if (flags & SC_KERNEL_CONSOLE)
3438 scp = sc->console_scp;
3440 scp = SC_STAT(sc->dev[0]);
3442 (*scp->tsw->te_term)(scp, &scp->ts);
3443 if (scp->ts != NULL)
3444 kfree(scp->ts, M_SYSCONS);
3446 /* clear the structure */
3447 if (!(flags & SC_KERNEL_CONSOLE)) {
3448 /* XXX: We need delete_dev() for this */
3449 kfree(sc->dev, M_SYSCONS);
3451 /* XXX: We need a ttyunregister for this */
3452 kfree(sc->tty, M_SYSCONS);
3454 #ifndef SC_NO_FONT_LOADING
3455 kfree(sc->font_8, M_SYSCONS);
3456 kfree(sc->font_14, M_SYSCONS);
3457 kfree(sc->font_16, M_SYSCONS);
3459 /* XXX vtb, history */
3461 bzero(sc, sizeof(*sc));
3464 lwkt_reltoken(&tty_token);
3468 scshutdown(void *arg, int howto)
3470 /* assert(sc_console != NULL) */
3472 lwkt_gettoken(&tty_token);
3474 sc_touch_scrn_saver();
3475 if (!cold && sc_console
3476 && sc_console->sc->cur_scp->smode.mode == VT_AUTO
3477 && sc_console->smode.mode == VT_AUTO) {
3478 sc_switch_scr(sc_console->sc, sc_console->index);
3480 shutdown_in_progress = TRUE;
3482 lwkt_reltoken(&tty_token);
3486 sc_clean_up(scr_stat *scp, int need_unlock)
3490 #endif /* NSPLASH */
3492 lwkt_gettoken(&tty_token);
3493 if (scp->sc->flags & SC_SCRN_BLANKED) {
3494 sc_touch_scrn_saver();
3496 if ((error = wait_scrn_saver_stop(scp->sc, need_unlock))) {
3497 lwkt_reltoken(&tty_token);
3500 #endif /* NSPLASH */
3502 scp->status |= MOUSE_HIDDEN;
3503 sc_remove_mouse_image(scp);
3504 sc_remove_cutmarking(scp);
3505 lwkt_reltoken(&tty_token);
3510 sc_alloc_scr_buffer(scr_stat *scp, int wait, int discard)
3515 lwkt_gettoken(&tty_token);
3517 sc_vtb_init(&new, VTB_MEMORY, scp->xsize, scp->ysize, NULL, wait);
3518 if (!discard && (old.vtb_flags & VTB_VALID)) {
3519 /* retain the current cursor position and buffer contants */
3520 scp->cursor_oldpos = scp->cursor_pos;
3522 * This works only if the old buffer has the same size as or larger
3523 * than the new one. XXX
3525 sc_vtb_copy(&old, 0, &new, 0, scp->xsize*scp->ysize);
3529 sc_vtb_destroy(&old);
3532 #ifndef SC_NO_SYSMOUSE
3533 /* move the mouse cursor at the center of the screen */
3534 sc_mouse_move(scp, scp->xpixel / 2, scp->ypixel / 2);
3536 lwkt_reltoken(&tty_token);
3540 alloc_scp(sc_softc_t *sc, int vty)
3544 /* assert(sc_malloc) */
3546 scp = kmalloc(sizeof(scr_stat), M_SYSCONS, M_WAITOK);
3547 init_scp(sc, vty, scp);
3549 sc_alloc_scr_buffer(scp, TRUE, TRUE);
3550 if (sc_init_emulator(scp, SC_DFLT_TERM))
3551 sc_init_emulator(scp, "*");
3553 #ifndef SC_NO_CUTPASTE
3554 sc_alloc_cut_buffer(scp, TRUE);
3557 #ifndef SC_NO_HISTORY
3558 sc_alloc_history_buffer(scp, 0, 0, TRUE);
3564 * NOTE: Must be called with tty_token held.
3567 init_scp(sc_softc_t *sc, int vty, scr_stat *scp)
3571 bzero(scp, sizeof(*scp));
3576 scp->mode = sc->initial_mode;
3577 scp->fbi_generation = sc->fbi_generation;
3578 callout_init_mp(&scp->blink_screen_ch);
3579 if (scp->sc->fbi == NULL) {
3580 lwkt_gettoken(&tty_token);
3581 (*vidsw[sc->adapter]->get_info)(sc->adp, scp->mode, &info);
3582 lwkt_reltoken(&tty_token);
3584 if (scp->sc->fbi != NULL) {
3585 scp->xpixel = sc->fbi->width;
3586 scp->ypixel = sc->fbi->height;
3587 scp->font_width = 8;
3588 scp->font_height = 16;
3590 /* The first vty uses a statically allocated 80x25 buffer */
3591 if (vty == sc->first_vty)
3592 sc_font_scale(scp, COL, ROW);
3594 sc_font_scale(scp, 0, 0);
3596 #ifndef SC_NO_FONT_LOADING
3597 scp->font = sc->font_16;
3601 } else if (info.vi_flags & V_INFO_GRAPHICS) {
3602 scp->status |= GRAPHICS_MODE;
3603 scp->xpixel = info.vi_width;
3604 scp->ypixel = info.vi_height;
3605 scp->xsize = info.vi_width/8;
3606 scp->ysize = info.vi_height/info.vi_cheight;
3607 scp->font_height = 0;
3608 scp->font_width = 0;
3611 scp->xsize = info.vi_width;
3612 scp->ysize = info.vi_height;
3613 scp->xpixel = scp->xsize*8;
3614 scp->ypixel = scp->ysize*info.vi_cheight;
3615 scp->font_width = 8;
3616 if (info.vi_cheight < 14) {
3617 scp->font_height = 8;
3618 #ifndef SC_NO_FONT_LOADING
3619 scp->font = sc->font_8;
3623 } else if (info.vi_cheight >= 16) {
3624 scp->font_height = 16;
3625 #ifndef SC_NO_FONT_LOADING
3626 scp->font = sc->font_16;
3631 scp->font_height = 14;
3632 #ifndef SC_NO_FONT_LOADING
3633 scp->font = sc->font_14;
3639 scp->xoff = scp->yoff = 0;
3640 scp->xpos = scp->ypos = 0;
3641 sc_vtb_init(&scp->vtb, VTB_MEMORY, 0, 0, NULL, FALSE);
3642 sc_vtb_init(&scp->scr, VTB_FRAMEBUFFER, 0, 0, NULL, FALSE);
3643 scp->start = scp->xsize * scp->ysize - 1;
3648 scp->border = SC_BORDER_COLOR;
3649 scp->cursor_base = sc->cursor_base;
3650 scp->cursor_height = imin(sc->cursor_height, scp->font_height);
3651 scp->mouse_cut_start = scp->xsize * scp->ysize;
3652 scp->mouse_cut_end = -1;
3653 scp->mouse_signal = 0;
3655 scp->mouse_proc = NULL;
3656 scp->kbd_mode = K_XLATE;
3657 scp->bell_pitch = bios_value.bell_pitch;
3658 scp->bell_duration = BELL_DURATION;
3659 scp->status |= (bios_value.shift_state & NLKED);
3660 scp->status |= CURSOR_ENABLED | MOUSE_HIDDEN;
3663 scp->smode.mode = VT_AUTO;
3664 scp->history = NULL;
3665 scp->history_pos = 0;
3666 scp->history_size = 0;
3670 sc_init_emulator(scr_stat *scp, char *name)
3677 if (name == NULL) /* if no name is given, use the current emulator */
3679 else /* ...otherwise find the named emulator */
3680 sw = sc_term_match(name);
3686 if (strcmp(sw->te_renderer, "*") != 0) {
3687 rndr = sc_render_match(scp, sw->te_renderer, scp->model);
3689 if (rndr == NULL && scp->sc->fbi != NULL) {
3690 rndr = sc_render_match(scp, "kms", scp->model);
3693 rndr = sc_render_match(scp, scp->sc->adp->va_name, scp->model);
3699 if (sw == scp->tsw) {
3700 error = (*sw->te_init)(scp, &scp->ts, SC_TE_WARM_INIT);
3702 sc_clear_screen(scp);
3703 /* assert(error == 0); */
3707 if (sc_malloc && (sw->te_size > 0))
3708 p = kmalloc(sw->te_size, M_SYSCONS, M_NOWAIT);
3711 error = (*sw->te_init)(scp, &p, SC_TE_COLD_INIT);
3717 (*scp->tsw->te_term)(scp, &scp->ts);
3718 if (scp->ts != NULL)
3719 kfree(scp->ts, M_SYSCONS);
3725 (*sw->te_default_attr)(scp, user_default.std_color, user_default.rev_color);
3726 sc_clear_screen(scp);
3732 * scgetc(flags) - get character from keyboard.
3733 * If flags & SCGETC_CN, then avoid harmful side effects.
3734 * If flags & SCGETC_NONBLOCK, then wait until a key is pressed, else
3735 * return NOKEY if there is nothing there.
3738 scgetc(sc_softc_t *sc, u_int flags)
3741 #ifndef SC_NO_HISTORY
3749 lwkt_gettoken(&tty_token);
3750 if (sc->kbd == NULL) {
3751 lwkt_reltoken(&tty_token);
3757 /* I don't like this, but... XXX */
3758 if (flags & SCGETC_CN) {
3760 sccnupdate(sc->cur_scp);
3765 /* first see if there is something in the keyboard port */
3767 c = kbd_read_char(sc->kbd, !(flags & SCGETC_NONBLOCK));
3769 if (!(flags & SCGETC_CN))
3770 sc_bell(scp, bios_value.bell_pitch, BELL_DURATION);
3771 } else if (c == NOKEY) {
3772 lwkt_reltoken(&tty_token);
3779 /* make screensaver happy */
3781 sc_touch_scrn_saver();
3783 if (!(flags & SCGETC_CN))
3784 /* do the /dev/random device a favour */
3785 add_keyboard_randomness(c);
3787 if (scp->kbd_mode != K_XLATE) {
3788 lwkt_reltoken(&tty_token);
3792 /* if scroll-lock pressed allow history browsing */
3793 if (!ISGRAPHSC(scp) && scp->history && scp->status & SLKED) {
3795 scp->status &= ~CURSOR_ENABLED;
3796 sc_remove_cursor_image(scp);
3798 #ifndef SC_NO_HISTORY
3799 if (!(scp->status & BUFFER_SAVED)) {
3800 scp->status |= BUFFER_SAVED;
3804 /* FIXME: key codes */
3805 case SPCLKEY | FKEY | F(49): /* home key */
3806 sc_remove_cutmarking(scp);
3810 case SPCLKEY | FKEY | F(57): /* end key */
3811 sc_remove_cutmarking(scp);
3815 case SPCLKEY | FKEY | F(50): /* up arrow key */
3816 sc_remove_cutmarking(scp);
3817 if (sc_hist_up_line(scp))
3818 if (!(flags & SCGETC_CN))
3819 sc_bell(scp, bios_value.bell_pitch, BELL_DURATION);
3822 case SPCLKEY | FKEY | F(58): /* down arrow key */
3823 sc_remove_cutmarking(scp);
3824 if (sc_hist_down_line(scp))
3825 if (!(flags & SCGETC_CN))
3826 sc_bell(scp, bios_value.bell_pitch, BELL_DURATION);
3829 case SPCLKEY | FKEY | F(51): /* page up key */
3830 sc_remove_cutmarking(scp);
3831 for (i=0; i<scp->ysize; i++) {
3832 if (sc_hist_up_line(scp)) {
3833 if (!(flags & SCGETC_CN))
3834 sc_bell(scp, bios_value.bell_pitch, BELL_DURATION);
3840 case SPCLKEY | FKEY | F(59): /* page down key */
3841 sc_remove_cutmarking(scp);
3842 for (i=0; i<scp->ysize; i++) {
3843 if (sc_hist_down_line(scp)) {
3844 if (!(flags & SCGETC_CN))
3845 sc_bell(scp, bios_value.bell_pitch, BELL_DURATION);
3851 #endif /* SC_NO_HISTORY */
3855 * Process and consume special keys here. Return a plain char code
3856 * or a char code with the META flag or a function key code.
3860 /* goto next_code */
3865 switch (KEYCHAR(c)) {
3867 case NLK: case CLK: case ALK:
3870 kbd_ioctl(sc->kbd, KDGKBSTATE, (caddr_t)&f);
3872 scp->status |= SLKED;
3874 if (scp->status & SLKED) {
3875 scp->status &= ~SLKED;
3876 #ifndef SC_NO_HISTORY
3877 if (scp->status & BUFFER_SAVED) {
3878 if (!sc_hist_restore(scp))
3879 sc_remove_cutmarking(scp);
3880 scp->status &= ~BUFFER_SAVED;
3881 scp->status |= CURSOR_ENABLED;
3882 sc_draw_cursor_image(scp);
3884 tp = VIRTUAL_TTY(sc, scp->index);
3892 /* NON-LOCKING KEYS */
3894 case LSH: case RSH: case LCTR: case RCTR:
3895 case LALT: case RALT: case ASH: case META:
3899 if (!(sc->flags & SC_SCRN_BLANKED)) {
3900 lwkt_reltoken(&tty_token);
3907 /* force activatation/deactivation of the screen saver */
3908 if (!(sc->flags & SC_SCRN_BLANKED)) {
3909 run_scrn_saver = TRUE;
3910 sc->scrn_time_stamp -= scrn_blank_time;
3914 * While devices are being probed, the screen saver need
3915 * to be invoked explictly. XXX
3917 if (sc->flags & SC_SCRN_BLANKED) {
3918 scsplash_stick(FALSE);
3919 stop_scrn_saver(sc, current_saver);
3921 if (!ISGRAPHSC(scp)) {
3922 scsplash_stick(TRUE);
3923 (*current_saver)(sc, TRUE);
3927 #endif /* NSPLASH */
3931 #ifndef SC_DISABLE_REBOOT
3937 #ifndef SC_DISABLE_REBOOT
3938 shutdown_nice(RB_HALT);
3943 #ifndef SC_DISABLE_REBOOT
3944 shutdown_nice(RB_HALT|RB_POWEROFF);
3953 #ifndef SC_DISABLE_DDBKEY
3955 lwkt_reltoken(&tty_token);
3956 Debugger("manual escape to debugger");
3957 lwkt_gettoken(&tty_token);
3959 kprintf("No debugger in kernel\n");
3961 #else /* SC_DISABLE_DDBKEY */
3963 #endif /* SC_DISABLE_DDBKEY */
3967 if (enable_panic_key)
3968 panic("Forced by the panic key");
3972 this_scr = scp->index;
3973 for (i = (this_scr - sc->first_vty + 1)%sc->vtys;
3974 sc->first_vty + i != this_scr;
3975 i = (i + 1)%sc->vtys) {
3976 struct tty *tp = VIRTUAL_TTY(sc, sc->first_vty + i);
3977 if (ISTTYOPEN(tp)) {
3979 sc_switch_scr(scp->sc, sc->first_vty + i);
3987 this_scr = scp->index;
3988 for (i = (this_scr - sc->first_vty + sc->vtys - 1)%sc->vtys;
3989 sc->first_vty + i != this_scr;
3990 i = (i + sc->vtys - 1)%sc->vtys) {
3991 struct tty *tp = VIRTUAL_TTY(sc, sc->first_vty + i);
3992 if (ISTTYOPEN(tp)) {
3994 sc_switch_scr(scp->sc, sc->first_vty + i);
4002 if (KEYCHAR(c) >= F_SCR && KEYCHAR(c) <= L_SCR) {
4004 sc_switch_scr(scp->sc, sc->first_vty + KEYCHAR(c) - F_SCR);
4008 /* assert(c & FKEY) */
4009 if (!(sc->flags & SC_SCRN_BLANKED)) {
4010 lwkt_reltoken(&tty_token);
4015 /* goto next_code */
4017 /* regular keys (maybe MKEY is set) */
4018 if (!(sc->flags & SC_SCRN_BLANKED)) {
4019 lwkt_reltoken(&tty_token);
4029 scmmap(struct dev_mmap_args *ap)
4033 lwkt_gettoken(&tty_token);
4034 scp = SC_STAT(ap->a_head.a_dev);
4035 if (scp != scp->sc->cur_scp) {
4036 lwkt_reltoken(&tty_token);
4039 if (scp->sc->fbi != NULL) {
4041 roundup(scp->sc->fbi->height * scp->sc->fbi->stride, PAGE_SIZE);
4042 if (ap->a_offset > sz - PAGE_SIZE) {
4043 lwkt_reltoken(&tty_token);
4046 ap->a_result = atop(scp->sc->fbi->paddr + ap->a_offset);
4049 ap->a_result = (*vidsw[scp->sc->adapter]->mmap)(scp->sc->adp,
4053 lwkt_reltoken(&tty_token);
4058 save_kbd_state(scr_stat *scp, int unlock)
4063 WANT_UNLOCK(unlock);
4064 error = kbd_ioctl(scp->sc->kbd, KDGKBSTATE, (caddr_t)&state);
4067 if (error == ENOIOCTL)
4070 scp->status &= ~LOCK_MASK;
4071 scp->status |= state;
4077 update_kbd_state(scr_stat *scp, int new_bits, int mask, int unlock)
4082 if (mask != LOCK_MASK) {
4083 WANT_UNLOCK(unlock);
4084 error = kbd_ioctl(scp->sc->kbd, KDGKBSTATE, (caddr_t)&state);
4087 if (error == ENOIOCTL)
4093 state |= new_bits & mask;
4095 state = new_bits & LOCK_MASK;
4097 WANT_UNLOCK(unlock);
4098 error = kbd_ioctl(scp->sc->kbd, KDSKBSTATE, (caddr_t)&state);
4100 if (error == ENOIOCTL)
4106 update_kbd_leds(scr_stat *scp, int which)
4111 error = kbd_ioctl(scp->sc->kbd, KDSETLED, (caddr_t)&which);
4112 if (error == ENOIOCTL)
4118 set_mode(scr_stat *scp)
4122 lwkt_gettoken(&tty_token);
4123 /* reject unsupported mode */
4124 if (scp->sc->fbi == NULL && (*vidsw[scp->sc->adapter]->get_info)(scp->sc->adp, scp->mode, &info)) {
4125 lwkt_reltoken(&tty_token);
4129 /* if this vty is not currently showing, do nothing */
4130 if (scp != scp->sc->cur_scp) {
4131 lwkt_reltoken(&tty_token);
4135 /* setup video hardware for the given mode */
4136 if (scp->sc->fbi == NULL) {
4137 (*vidsw[scp->sc->adapter]->set_mode)(scp->sc->adp, scp->mode);
4138 sc_vtb_init(&scp->scr, VTB_FRAMEBUFFER, scp->xsize, scp->ysize,
4139 (void *)scp->sc->adp->va_window, FALSE);
4144 #ifndef SC_NO_FONT_LOADING
4145 /* load appropriate font */
4146 if (!(scp->status & GRAPHICS_MODE)) {
4147 if (!(scp->status & PIXEL_MODE) && ISFONTAVAIL(scp->sc->adp->va_flags)) {
4148 if (scp->font_height < 14) {
4149 if (scp->sc->fonts_loaded & FONT_8)
4150 sc_load_font(scp, 0, 8, scp->sc->font_8, 0, 256);
4151 } else if (scp->font_height >= 16) {
4152 if (scp->sc->fonts_loaded & FONT_16)
4153 sc_load_font(scp, 0, 16, scp->sc->font_16, 0, 256);
4155 if (scp->sc->fonts_loaded & FONT_14)
4156 sc_load_font(scp, 0, 14, scp->sc->font_14, 0, 256);
4160 * This is an interim kludge to display correct font.
4161 * Always use the font page #0 on the video plane 2.
4162 * Somehow we cannot show the font in other font pages on
4163 * some video cards... XXX
4165 sc_show_font(scp, 0);
4169 #endif /* !SC_NO_FONT_LOADING */
4171 sc_set_border(scp, scp->border);
4172 sc_set_cursor_image(scp);
4175 lwkt_reltoken(&tty_token);
4180 refresh_ega_palette(scr_stat *scp)
4184 int rsize, gsize, bsize;
4185 int rfld, gfld, bfld;
4188 rsize = scp->sc->adp->va_info.vi_pixel_fsizes[0];
4189 gsize = scp->sc->adp->va_info.vi_pixel_fsizes[1];
4190 bsize = scp->sc->adp->va_info.vi_pixel_fsizes[2];
4191 rfld = scp->sc->adp->va_info.vi_pixel_fields[0];
4192 gfld = scp->sc->adp->va_info.vi_pixel_fields[1];
4193 bfld = scp->sc->adp->va_info.vi_pixel_fields[2];
4195 for (i = 0; i < 16; i++) {
4196 reg = scp->sc->adp->va_palette_regs[i];
4198 r = scp->sc->palette[reg * 3] >> (8 - rsize);
4199 g = scp->sc->palette[reg * 3 + 1] >> (8 - gsize);
4200 b = scp->sc->palette[reg * 3 + 2] >> (8 - bsize);
4202 scp->ega_palette[i] = (r << rfld) + (g << gfld) + (b << bfld);
4207 sc_set_border(scr_stat *scp, int color)
4209 atomic_add_int(&scp->sc->videoio_in_progress, 1);
4210 (*scp->rndr->draw_border)(scp, color);
4211 atomic_add_int(&scp->sc->videoio_in_progress, -1);
4214 #ifndef SC_NO_FONT_LOADING
4216 sc_load_font(scr_stat *scp, int page, int size, u_char *buf,
4217 int base, int count)
4222 sc->font_loading_in_progress = TRUE;
4223 (*vidsw[sc->adapter]->load_font)(sc->adp, page, size, buf, base, count);
4224 sc->font_loading_in_progress = FALSE;
4228 sc_save_font(scr_stat *scp, int page, int size, u_char *buf,
4229 int base, int count)
4234 sc->font_loading_in_progress = TRUE;
4235 (*vidsw[sc->adapter]->save_font)(sc->adp, page, size, buf, base, count);
4236 sc->font_loading_in_progress = FALSE;
4240 sc_show_font(scr_stat *scp, int page)
4242 (*vidsw[scp->sc->adapter]->show_font)(scp->sc->adp, page);
4244 #endif /* !SC_NO_FONT_LOADING */
4247 sc_paste(scr_stat *scp, u_char *p, int count)
4253 * Holy hell, don't try to inject a paste buffer if the keyboard
4254 * is not in ascii mode!
4256 if (scp->kbd_mode != K_XLATE)
4259 lwkt_gettoken(&tty_token);
4260 if (scp->status & MOUSE_VISIBLE) {
4261 tp = VIRTUAL_TTY(scp->sc, scp->sc->cur_scp->index);
4262 if (!ISTTYOPEN(tp)) {
4263 lwkt_reltoken(&tty_token);
4266 rmap = scp->sc->scr_rmap;
4267 for (; count > 0; --count)
4268 (*linesw[tp->t_line].l_rint)(rmap[*p++], tp);
4270 lwkt_reltoken(&tty_token);
4274 sc_bell(scr_stat *scp, int pitch, int duration)
4276 if (cold || shutdown_in_progress)
4279 if (scp != scp->sc->cur_scp && (scp->sc->flags & SC_QUIET_BELL)) {
4283 if (scp->sc->flags & SC_VISUAL_BELL) {
4284 if (scp->sc->blink_in_progress) {
4287 scp->sc->blink_in_progress = 3;
4288 if (scp != scp->sc->cur_scp)
4289 scp->sc->blink_in_progress += 2;
4290 sc_blink_screen(scp->sc->cur_scp);
4291 } else if (duration != 0 && pitch != 0) {
4292 if (scp != scp->sc->cur_scp)
4294 sysbeep(pitch, duration);
4299 * Two versions of blink_screen(), one called from the console path
4300 * with the syscons locked, and one called from a timer callout.
4303 sc_blink_screen(scr_stat *scp)
4305 if (ISGRAPHSC(scp) || (scp->sc->blink_in_progress <= 1)) {
4306 scp->sc->blink_in_progress = 0;
4308 if (scp->sc->delayed_next_scr)
4309 sc_switch_scr(scp->sc, scp->sc->delayed_next_scr - 1);
4311 (*scp->rndr->draw)(scp, 0, scp->xsize*scp->ysize,
4312 scp->sc->blink_in_progress & 1);
4313 scp->sc->blink_in_progress--;
4319 blink_screen_callout(void *arg)
4321 scr_stat *scp = arg;
4324 if (ISGRAPHSC(scp) || (scp->sc->blink_in_progress <= 1)) {
4326 scp->sc->blink_in_progress = 0;
4329 tp = VIRTUAL_TTY(scp->sc, scp->index);
4332 if (scp->sc->delayed_next_scr) {
4334 sc_switch_scr(scp->sc, scp->sc->delayed_next_scr - 1);
4339 (*scp->rndr->draw)(scp, 0, scp->xsize*scp->ysize,
4340 scp->sc->blink_in_progress & 1);
4341 scp->sc->blink_in_progress--;
4343 callout_reset(&scp->blink_screen_ch, hz / 10,
4344 blink_screen_callout, scp);
4350 * Allocate active keyboard. Try to allocate "kbdmux" keyboard first, and,
4351 * if found, add all non-busy keyboards to "kbdmux". Otherwise look for
4356 sc_allocate_keyboard(sc_softc_t *sc, int unit)
4362 idx0 = kbd_allocate("kbdmux", -1, (void *)&sc->keyboard, sckbdevent, sc);
4364 k0 = kbd_get_keyboard(idx0);
4366 for (idx = kbd_find_keyboard2("*", -1, 0, 0);
4368 idx = kbd_find_keyboard2("*", -1, idx + 1, 0)) {
4369 k = kbd_get_keyboard(idx);
4371 if (idx == idx0 || KBD_IS_BUSY(k))
4374 bzero(&ki, sizeof(ki));
4375 strcpy(ki.kb_name, k->kb_name);
4376 ki.kb_unit = k->kb_unit;
4378 kbd_ioctl(k0, KBADDKBD, (caddr_t) &ki);
4381 idx0 = kbd_allocate("*", unit, (void *)&sc->keyboard, sckbdevent, sc);