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/ttydefaults.h> /* for TTYDEF_* */
52 #include <sys/kernel.h>
54 #include <sys/random.h>
57 #include <sys/thread2.h>
58 #include <sys/mutex2.h>
60 #include <machine/clock.h>
61 #include <machine/console.h>
62 #include <machine/psl.h>
63 #include <machine/pc/display.h>
64 #include <machine/frame.h>
65 #include <machine/framebuffer.h>
67 #include <dev/misc/kbd/kbdreg.h>
68 #include <dev/video/fb/fbreg.h>
69 #include <dev/video/fb/splashreg.h>
75 #define DEFAULT_BLANKTIME (5*60) /* 5 minutes */
76 #define MAX_BLANKTIME (7*24*60*60) /* 7 days!? */
78 #define SCRN_ASYNCOK 0x0001
79 #define SCRN_BULKUNLOCK 0x0002
81 #define KEYCODE_BS 0x0e /* "<-- Backspace" key, XXX */
82 #define WANT_UNLOCK(m) do { \
87 #define WANT_LOCK(m) do { \
93 MALLOC_DEFINE(M_SYSCONS, "syscons", "Syscons");
95 typedef struct default_attr {
96 int std_color; /* normal hardware color */
97 int rev_color; /* reverse hardware color */
100 static default_attr user_default = {
105 static default_attr kernel_default = {
107 SC_KERNEL_CONS_REV_ATTR,
110 static int sc_console_unit = -1;
111 static scr_stat *sc_console;
112 static struct tty *sc_console_tty;
113 static void *kernel_console_ts;
115 static char init_done = COLD;
116 static char shutdown_in_progress = FALSE;
117 static char sc_malloc = FALSE;
118 static char sc_filled_border = FALSE; /* filled initial VT border */
120 static int saver_mode = CONS_NO_SAVER; /* LKM/user saver */
121 static int run_scrn_saver = FALSE; /* should run the saver? */
122 static long scrn_blank_time = 0; /* screen saver timeout value */
124 static int scrn_blanked; /* # of blanked screen */
125 static int sticky_splash = FALSE;
127 static void none_saver(sc_softc_t *sc, int blank) { }
128 static void (*current_saver)(sc_softc_t *, int) = none_saver;
132 * Lock for asynchronous screen update thread, needed to safely modify the
133 * framebuffer information.
135 static struct lock sc_asynctd_lk;
137 #if !defined(SC_NO_FONT_LOADING) && defined(SC_DFLT_FONT)
141 static bios_values_t bios_value;
143 static int enable_panic_key;
144 SYSCTL_INT(_machdep, OID_AUTO, enable_panic_key, CTLFLAG_RW, &enable_panic_key,
145 0, "Enable the panic key (CTRL-ALT-SHIFT-ESC)");
146 static int syscons_async;
147 SYSCTL_INT(_kern, OID_AUTO, syscons_async, CTLFLAG_RW, &syscons_async,
148 0, "Asynchronous bulk syscons fb updates");
150 static int desired_cols = 0;
151 TUNABLE_INT("kern.kms_columns", &desired_cols);
153 #define SC_CONSOLECTL 255
155 #define VIRTUAL_TTY(sc, x) ((SC_DEV((sc),(x)) != NULL) ? \
156 (SC_DEV((sc),(x))->si_tty) : NULL)
157 #define ISTTYOPEN(tp) ((tp) && ((tp)->t_state & TS_ISOPEN))
160 static cdev_t cctl_dev;
161 static timeout_t blink_screen_callout;
162 static void sc_blink_screen(scr_stat *scp);
163 static struct mtx syscons_mtx = MTX_INITIALIZER("syscons");
164 static struct lock syscons_blink_lk = LOCK_INITIALIZER("sblnk", 0, 0);
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);
176 static void scterm(int unit, int flags);
178 static void scshutdown(void *arg, int howto);
179 static void sc_puts(scr_stat *scp, u_char *buf, int len);
180 static u_int scgetc(sc_softc_t *sc, u_int flags);
182 #define SCGETC_NONBLOCK 2
183 static int sccngetch(int flags);
184 static void sccnupdate(scr_stat *scp);
185 static scr_stat *alloc_scp(sc_softc_t *sc, int vty);
186 static void init_scp(sc_softc_t *sc, int vty, scr_stat *scp);
187 static timeout_t scrn_timer;
188 static int and_region(int *s1, int *e1, int s2, int e2);
189 static void scrn_update(scr_stat *scp, int show_cursor, int flags);
190 static void scrn_update_thread(void *arg);
192 static void sc_fb_set_par(void *context, int pending);
194 static void sc_fb_blank(void *context, int pending);
198 static void scframebuffer_saver(sc_softc_t *sc, int show);
199 static int scsplash_callback(int event, void *arg);
200 static void scsplash_saver(sc_softc_t *sc, int show);
201 static int add_scrn_saver(void (*this_saver)(sc_softc_t *, int));
202 static int remove_scrn_saver(void (*this_saver)(sc_softc_t *, int));
203 static int set_scrn_saver_mode(scr_stat *scp, int mode, u_char *pal, int border);
204 static int restore_scrn_saver_mode(scr_stat *scp, int changemode);
205 static void stop_scrn_saver(sc_softc_t *sc, void (*saver)(sc_softc_t *, int));
206 static int wait_scrn_saver_stop(sc_softc_t *sc, int need_unlock);
207 #define scsplash_stick(stick) (sticky_splash = (stick))
209 #define scsplash_stick(stick)
212 static void do_switch_scr(sc_softc_t *sc);
213 static int vt_proc_alive(scr_stat *scp);
214 static int signal_vt_rel(scr_stat *scp);
215 static int signal_vt_acq(scr_stat *scp);
216 static int finish_vt_rel(scr_stat *scp, int release);
217 static int finish_vt_acq(scr_stat *scp);
218 static void exchange_scr(sc_softc_t *sc);
219 static void update_cursor_image(scr_stat *scp);
220 static int save_kbd_state(scr_stat *scp, int unlock);
221 static int update_kbd_state(scr_stat *scp, int state, int mask, int unlock);
222 static int update_kbd_leds(scr_stat *scp, int which);
223 static int sc_allocate_keyboard(sc_softc_t *sc, int unit);
226 * Console locking support functions.
228 * We use mutex spinlocks here in order to allow reentrancy which should
229 * avoid issues during panics.
231 * A panic can stop a cpu while it is holding the syscons_mtx. If this
232 * occurs we try for up to 1/2 a second and then blow the spinlock away.
233 * The asynchronous update thread makes this happen more often.
238 if (panicstr || shutdown_in_progress) {
239 int retries = 500000;
240 while (mtx_spinlock_try(&syscons_mtx)) {
241 tsc_delay(1000); /* 1uS */
242 if (--retries == 0) {
243 mtx_init(&syscons_mtx, "syscons");
248 mtx_spinlock(&syscons_mtx);
253 * Returns 0 on success, EAGAIN on failure.
256 syscons_lock_nonblock(void)
258 return(mtx_spinlock_try(&syscons_mtx));
264 mtx_spinunlock(&syscons_mtx);
270 static cn_probe_t sccnprobe;
271 static cn_init_t sccninit;
272 static cn_init_t sccninit_fini;
273 static cn_getc_t sccngetc;
274 static cn_checkc_t sccncheckc;
275 static cn_putc_t sccnputc;
276 static cn_dbctl_t sccndbctl;
277 static cn_term_t sccnterm;
278 static cn_poll_t sccnpoll;
280 CONS_DRIVER(sc, sccnprobe, sccninit, sccninit_fini, sccnterm,
281 sccngetc, sccncheckc, sccnputc, sccndbctl, sccnpoll);
283 static d_open_t scopen;
284 static d_close_t scclose;
285 static d_read_t scread;
286 static d_ioctl_t scioctl;
287 static d_mmap_t scmmap;
289 static struct dev_ops sc_ops = {
290 { "sc", 0, D_TTY | D_MPSAFE },
297 .d_kqfilter = ttykqfilter,
298 .d_revoke = ttyrevoke
302 sc_probe_unit(int unit, int flags)
304 if ((flags & SC_EFI_FB) && (probe_efi_fb(0) != 0)) {
306 kprintf("sc%d: no EFI framebuffer found.\n", unit);
310 if (!(flags & SC_EFI_FB) && !scvidprobe(unit, flags, FALSE)) {
312 kprintf("sc%d: no video adapter found.\n", unit);
316 /* syscons will be attached even when there is no keyboard */
317 sckbdprobe(unit, flags, FALSE);
323 register_framebuffer(struct fb_info *info)
327 /* For now ignore framebuffers, which don't replace the vga display */
328 if (!info->is_vga_boot_display)
331 lwkt_gettoken(&vga_token);
332 sc = sc_get_softc(0, (sc_console_unit == 0) ? SC_KERNEL_CONSOLE : 0);
334 lwkt_reltoken(&vga_token);
335 kprintf("%s: sc_get_softc(%d, %d) returned NULL\n", __func__,
336 0, (sc_console_unit == 0) ? SC_KERNEL_CONSOLE : 0);
340 /* Ignore this framebuffer if we already switched to KMS framebuffer */
341 if (sc->fbi != NULL && sc->fbi != &efi_fb_info &&
342 sc->fbi != sc->dummy_fb_info) {
343 lwkt_reltoken(&vga_token);
347 if (sc->fb_set_par_task == NULL) {
348 sc->fb_set_par_task = kmalloc(sizeof(struct task),
349 M_SYSCONS, M_WAITOK | M_ZERO);
351 TASK_INIT(sc->fb_set_par_task, 0, sc_fb_set_par, sc);
353 if (sc->fb_blank_task == NULL) {
354 sc->fb_blank_task = kmalloc(sizeof(struct task),
355 M_SYSCONS, M_WAITOK | M_ZERO);
357 TASK_INIT(sc->fb_blank_task, 0, sc_fb_blank, sc);
361 * Make sure that console messages don't interfere too much with
364 atomic_add_int(&sc->videoio_in_progress, 1);
366 /* Lock against synchronous and asynchronous screen updates */
367 lockmgr(&sc_asynctd_lk, LK_EXCLUSIVE);
370 sc->fbi_generation++;
373 kprintf("kms console: xpixels %d ypixels %d\n",
374 sc->fbi->width, sc->fbi->height);
375 sc_update_render(sc->cur_scp);
376 if (info->fbops.fb_set_par != NULL)
377 info->fbops.fb_set_par(info);
378 atomic_add_int(&sc->videoio_in_progress, -1);
380 sc->fb_blanked = FALSE;
381 if (sc->unit == sc_console_unit && sc->cur_scp->smode.mode != VT_AUTO)
382 cons_unavail = FALSE;
384 if (info->fbops.fb_blank != NULL)
385 add_scrn_saver(scframebuffer_saver);
388 lockmgr(&sc_asynctd_lk, LK_RELEASE);
389 lwkt_reltoken(&vga_token);
394 unregister_framebuffer(struct fb_info *info)
398 lwkt_gettoken(&vga_token);
399 sc = sc_get_softc(0, (sc_console_unit == 0) ? SC_KERNEL_CONSOLE : 0);
401 lwkt_reltoken(&vga_token);
402 kprintf("%s: sc_get_softc(%d, %d) returned NULL\n", __func__,
403 0, (sc_console_unit == 0) ? SC_KERNEL_CONSOLE : 0);
407 if (sc->fbi != info) {
408 lwkt_reltoken(&vga_token);
413 if (info->fbops.fb_blank != NULL)
414 remove_scrn_saver(scframebuffer_saver);
417 if (sc->fb_set_par_task != NULL &&
418 taskqueue_cancel(taskqueue_thread[0], sc->fb_set_par_task, NULL)) {
419 taskqueue_drain(taskqueue_thread[0], sc->fb_set_par_task);
422 if (sc->fb_blank_task != NULL &&
423 taskqueue_cancel(taskqueue_thread[0], sc->fb_blank_task, NULL)) {
424 taskqueue_drain(taskqueue_thread[0], sc->fb_blank_task);
427 sc->fb_blanked = TRUE;
428 if (sc->unit == sc_console_unit)
431 if (sc->dummy_fb_info == NULL) {
432 sc->dummy_fb_info = kmalloc(sizeof(struct fb_info),
433 M_SYSCONS, M_WAITOK | M_ZERO);
435 memset(sc->dummy_fb_info, 0, sizeof(struct fb_info));
437 *sc->dummy_fb_info = *sc->fbi;
438 sc->dummy_fb_info->vaddr = 0;
439 sc->dummy_fb_info->fbops.fb_set_par = NULL;
440 sc->dummy_fb_info->fbops.fb_blank = NULL;
441 sc->dummy_fb_info->fbops.fb_debug_enter = NULL;
443 /* Lock against synchronous and asynchronous screen updates */
444 lockmgr(&sc_asynctd_lk, LK_EXCLUSIVE);
446 sc->fbi = sc->dummy_fb_info;
448 lockmgr(&sc_asynctd_lk, LK_RELEASE);
450 lwkt_reltoken(&vga_token);
454 sc_font_scale(scr_stat *scp, int max_cols, int max_rows)
459 * If columns not specified in /boot/loader.conf then
460 * calculate a non-fractional scaling that yields a
461 * reasonable number of rows and columns. If it is <0,
462 * don't scale at all.
464 if (desired_cols == 0) {
466 while (scp->xpixel / (scp->font_width * nomag) >= COL &&
467 scp->ypixel / (scp->font_height * nomag) >= ROW) {
472 cols = scp->xpixel / (scp->font_width * nomag);
473 } else if (desired_cols < 0) {
474 cols = scp->xpixel / scp->font_width;
478 scp->blk_width = scp->xpixel / cols;
479 scp->blk_height = scp->blk_width * scp->font_height / scp->font_width;
480 rows = scp->ypixel / scp->blk_height;
482 /* scp->xsize = scp->xpixel / scp->blk_width; total possible */
483 scp->xsize = max_cols ? imin(max_cols, cols) : cols;
484 scp->ysize = max_rows ? imin(max_rows, rows) : rows;
487 /* probe video adapters, return TRUE if found */
489 scvidprobe(int unit, int flags, int cons)
492 * Access the video adapter driver through the back door!
493 * Video adapter drivers need to be configured before syscons.
494 * However, when syscons is being probed as the low-level console,
495 * they have not been initialized yet. We force them to initialize
496 * themselves here. XXX
498 vid_configure(cons ? VIO_PROBE_ONLY : 0);
500 return (vid_find_adapter("*", unit) >= 0);
503 /* probe the keyboard, return TRUE if found */
505 sckbdprobe(int unit, int flags, int cons)
507 /* access the keyboard driver through the backdoor! */
508 kbd_configure(cons ? KB_CONF_PROBE_ONLY : 0);
510 return (kbd_find_keyboard("*", unit) >= 0);
514 adapter_name(video_adapter_t *adp)
520 { KD_MONO, { "MDA", "MDA" } },
521 { KD_HERCULES, { "Hercules", "Hercules" } },
522 { KD_CGA, { "CGA", "CGA" } },
523 { KD_EGA, { "EGA", "EGA (mono)" } },
524 { KD_VGA, { "VGA", "VGA (mono)" } },
525 { KD_TGA, { "TGA", "TGA" } },
526 { -1, { "Unknown", "Unknown" } },
530 for (i = 0; names[i].type != -1; ++i)
531 if (names[i].type == adp->va_type)
533 return names[i].name[(adp->va_flags & V_ADP_COLOR) ? 0 : 1];
537 sc_attach_unit(int unit, int flags)
543 flags &= ~SC_KERNEL_CONSOLE;
544 char tbuf[MAKEDEV_MINNBUF];
546 if ((flags & SC_EFI_FB) && probe_efi_fb(0) != 0)
549 if (sc_console_unit == unit) {
551 * If this unit is being used as the system console, we need to
552 * adjust some variables and buffers before and after scinit().
554 /* assert(sc_console != NULL) */
555 flags |= SC_KERNEL_CONSOLE;
560 if (sc_console->tsw->te_size > 0) {
561 /* assert(sc_console->ts != NULL); */
562 kernel_console_ts = sc_console->ts;
563 sc_console->ts = kmalloc(sc_console->tsw->te_size,
564 M_SYSCONS, M_WAITOK);
565 bcopy(kernel_console_ts, sc_console->ts, sc_console->tsw->te_size);
566 (*sc_console->tsw->te_default_attr)(sc_console,
567 user_default.std_color,
568 user_default.rev_color);
574 sc = sc_get_softc(unit, flags & SC_KERNEL_CONSOLE);
577 * If this is the console we couldn't setup sc->dev before because
578 * malloc wasn't working. Set it up now.
580 if (flags & SC_KERNEL_CONSOLE) {
581 KKASSERT(sc->dev == NULL);
582 sc->dev = kmalloc(sizeof(cdev_t)*sc->vtys, M_SYSCONS, M_WAITOK|M_ZERO);
583 sc->dev[0] = make_dev(&sc_ops, sc_console_unit*MAXCONS, UID_ROOT,
584 GID_WHEEL, 0600, "ttyv%s", makedev_unit_b32(tbuf,
585 sc_console_unit * MAXCONS));
586 ttymalloc(&sc->dev[0]->si_tty);
587 sc->dev[0]->si_drv1 = sc_console;
591 * Finish up the standard attach
594 callout_init_mp(&sc->scrn_timer_ch);
595 scp = SC_STAT(sc->dev[0]);
596 if (sc_console == NULL) /* sc_console_unit < 0 */
599 /* initialize cursor */
601 update_cursor_image(scp);
603 /* get screen update going */
606 /* set up the keyboard */
607 kbd_ioctl(sc->kbd, KDSKBMODE, (caddr_t)&scp->kbd_mode);
608 update_kbd_state(scp, scp->status, LOCK_MASK, FALSE);
610 kprintf("sc%d: %s <%d virtual consoles, flags=0x%x>\n",
611 unit, (sc->config & SC_EFI_FB) ? "EFI_FB" : adapter_name(sc->adp),
612 sc->vtys, sc->config);
614 kprintf("sc%d:", unit);
615 if (sc->adapter >= 0)
616 kprintf(" fb%d", sc->adapter);
617 if (sc->keyboard >= 0)
618 kprintf(", kbd%d", sc->keyboard);
620 kprintf(", terminal emulator: %s (%s)",
621 scp->tsw->te_name, scp->tsw->te_desc);
625 /* register a shutdown callback for the kernel console */
626 if (sc_console_unit == unit)
627 EVENTHANDLER_REGISTER(shutdown_pre_sync, scshutdown,
628 (void *)(uintptr_t)unit, SHUTDOWN_PRI_DEFAULT);
633 * The first vty already has struct tty and scr_stat initialized
634 * in scinit(). The other vtys will have these structs when
637 for (vc = 1; vc < sc->vtys; vc++) {
638 dev = make_dev(&sc_ops, vc + unit * MAXCONS,
639 UID_ROOT, GID_WHEEL, 0600, "ttyv%s",
640 makedev_unit_b32(tbuf, vc + unit * MAXCONS));
643 cctl_dev = make_dev(&sc_ops, SC_CONSOLECTL,
644 UID_ROOT, GID_WHEEL, 0600, "consolectl");
645 cctl_dev->si_tty = ttymalloc(&sc_console_tty);
646 cctl_dev->si_drv1 = sc_console;
658 * As soon as malloc() becomes functional, we had better allocate
659 * various buffers for the kernel console.
662 if (sc_console_unit < 0) /* sc_console == NULL */
665 /* copy the temporary buffer to the final buffer */
666 sc_alloc_scr_buffer(sc_console, TRUE, FALSE);
668 #ifndef SC_NO_CUTPASTE
669 sc_alloc_cut_buffer(sc_console, TRUE);
672 #ifndef SC_NO_HISTORY
673 /* initialize history buffer & pointers */
674 sc_alloc_history_buffer(sc_console, 0, 0, TRUE);
677 /* Fill initial terminal border, efi_fb_info.vaddr should be non-NULL now */
678 if (!sc_filled_border) {
679 sc_filled_border = TRUE;
680 sc_set_border(sc_console, sc_console->border);
684 SYSINIT(sc_mem, SI_BOOT1_POST, SI_ORDER_ANY, scmeminit, NULL);
687 scdevtounit(cdev_t dev)
689 int vty = SC_VTY(dev);
691 if (vty == SC_CONSOLECTL)
692 return ((sc_console != NULL) ? sc_console->sc->unit : -1);
693 else if ((vty < 0) || (vty >= MAXCONS*sc_max_unit()))
700 scopen(struct dev_open_args *ap)
702 cdev_t dev = ap->a_head.a_dev;
710 lwkt_gettoken(&vga_token);
711 unit = scdevtounit(dev);
712 DPRINTF(5, ("scopen: dev:%d,%d, unit:%d, vty:%d\n",
713 major(dev), minor(dev), unit, SC_VTY(dev)));
715 sc = sc_get_softc(unit, (sc_console_unit == unit) ? SC_KERNEL_CONSOLE : 0);
717 lwkt_reltoken(&vga_token);
721 tp = ttymalloc(&dev->si_tty);
722 lwkt_gettoken(&tp->t_token);
723 tp->t_oproc = scstart;
724 tp->t_param = scparam;
725 tp->t_stop = nottystop;
729 if (!ISTTYOPEN(tp)) {
731 /* Use the current setting of the <-- key as default VERASE. */
732 /* If the Delete key is preferable, an stty is necessary */
733 if (sc->kbd != NULL) {
734 key.keynum = KEYCODE_BS;
735 kbd_ioctl(sc->kbd, GIO_KEYMAPENT, (caddr_t)&key);
736 tp->t_cc[VERASE] = key.key.map[0];
738 tp->t_iflag = TTYDEF_IFLAG;
739 tp->t_oflag = TTYDEF_OFLAG;
740 tp->t_cflag = TTYDEF_CFLAG;
741 tp->t_lflag = TTYDEF_LFLAG;
742 tp->t_ispeed = tp->t_ospeed = TTYDEF_SPEED;
743 scparam(tp, &tp->t_termios);
744 (*linesw[tp->t_line].l_modem)(tp, 1);
747 if (tp->t_state & TS_XCLUDE && priv_check_cred(ap->a_cred, PRIV_ROOT, 0)) {
748 lwkt_reltoken(&tp->t_token);
749 lwkt_reltoken(&vga_token);
753 error = (*linesw[tp->t_line].l_open)(dev, tp);
757 scp = dev->si_drv1 = alloc_scp(sc, SC_VTY(dev));
760 sc_set_pixel_mode(scp, NULL, COL, ROW, 16);
763 if (!tp->t_winsize.ws_col && !tp->t_winsize.ws_row) {
764 tp->t_winsize.ws_col = scp->xsize;
765 tp->t_winsize.ws_row = scp->ysize;
769 * Start optional support thread for syscons refreshes. This thread
770 * will execute the refresh without the syscons_lock held and will
771 * allow interrupts while it is doing so.
773 if (scp->asynctd == NULL) {
774 lwkt_create(scrn_update_thread, scp, &scp->asynctd, NULL, 0, -1,
775 "syscons%d", SC_VTY(dev));
777 lwkt_reltoken(&tp->t_token);
778 lwkt_reltoken(&vga_token);
784 scclose(struct dev_close_args *ap)
786 cdev_t dev = ap->a_head.a_dev;
787 struct tty *tp = dev->si_tty;
790 lwkt_gettoken(&vga_token);
791 lwkt_gettoken(&tp->t_token);
792 if (SC_VTY(dev) != SC_CONSOLECTL) {
793 scp = SC_STAT(tp->t_dev);
794 /* were we in the middle of the VT switching process? */
795 DPRINTF(5, ("sc%d: scclose(), ", scp->sc->unit));
796 if ((scp == scp->sc->cur_scp) && (scp->sc->unit == sc_console_unit) &&
797 !scp->sc->fb_blanked) {
798 cons_unavail = FALSE;
800 if (finish_vt_rel(scp, TRUE) == 0) /* force release */
801 DPRINTF(5, ("reset WAIT_REL, "));
802 if (finish_vt_acq(scp) == 0) /* force acknowledge */
803 DPRINTF(5, ("reset WAIT_ACQ, "));
806 if (scp == &main_console) {
809 scp->smode.mode = VT_AUTO;
812 sc_vtb_destroy(&scp->vtb);
813 sc_vtb_destroy(&scp->scr);
814 sc_free_history_buffer(scp, scp->ysize);
816 kfree(scp, M_SYSCONS);
821 scp->smode.mode = VT_AUTO;
823 scp->kbd_mode = K_XLATE;
825 if (scp == scp->sc->cur_scp)
826 kbd_ioctl(scp->sc->kbd, KDSKBMODE, (caddr_t)&scp->kbd_mode);
827 DPRINTF(5, ("done.\n"));
829 (*linesw[tp->t_line].l_close)(tp, ap->a_fflag);
831 lwkt_reltoken(&tp->t_token);
832 lwkt_reltoken(&vga_token);
838 scread(struct dev_read_args *ap)
842 lwkt_gettoken(&vga_token);
843 sc_touch_scrn_saver();
845 lwkt_reltoken(&vga_token);
850 sckbdevent(keyboard_t *thiskbd, int event, void *arg)
858 lwkt_gettoken(&vga_token);
860 * WARNING: In early boot sc->dev may not be setup yet.
862 sc = (sc_softc_t *)arg;
863 /* assert(thiskbd == sc->kbd) */
867 if (sc->kbd && sc->kbd->kb_flags & KB_POLLED) {
868 lwkt_reltoken(&vga_token);
872 case KBDIO_UNLOADING:
877 kbd_release(thiskbd, (void *)&sc->keyboard);
878 lwkt_reltoken(&vga_token);
881 lwkt_reltoken(&vga_token);
886 * Loop while there is still input to get from the keyboard.
887 * I don't think this is nessesary, and it doesn't fix
888 * the Xaccel-2.1 keyboard hang, but it can't hurt. XXX
890 while ((c = scgetc(sc, SCGETC_NONBLOCK)) != NOKEY) {
891 cur_tty = VIRTUAL_TTY(sc, sc->cur_scp->index);
892 if (!ISTTYOPEN(cur_tty)) {
893 cur_tty = sc_console_tty;
894 if (!ISTTYOPEN(cur_tty))
899 if ((*sc->cur_scp->tsw->te_input)(sc->cur_scp, c, cur_tty)) {
905 lwkt_gettoken(&cur_tty->t_token);
907 switch (KEYFLAGS(c)) {
908 case 0x0000: /* normal key */
909 (*linesw[cur_tty->t_line].l_rint)(KEYCHAR(c), cur_tty);
911 case FKEY: /* function key, return string */
912 cp = kbd_get_fkeystr(thiskbd, KEYCHAR(c), &len);
915 (*linesw[cur_tty->t_line].l_rint)(*cp++, cur_tty);
918 case MKEY: /* meta is active, prepend ESC */
919 (*linesw[cur_tty->t_line].l_rint)(0x1b, cur_tty);
920 (*linesw[cur_tty->t_line].l_rint)(KEYCHAR(c), cur_tty);
922 case BKEY: /* backtab fixed sequence (esc [ Z) */
923 (*linesw[cur_tty->t_line].l_rint)(0x1b, cur_tty);
924 (*linesw[cur_tty->t_line].l_rint)('[', cur_tty);
925 (*linesw[cur_tty->t_line].l_rint)('Z', cur_tty);
928 lwkt_reltoken(&cur_tty->t_token);
932 sc->cur_scp->status |= MOUSE_HIDDEN;
935 lwkt_reltoken(&vga_token);
940 scparam(struct tty *tp, struct termios *t)
942 lwkt_gettoken(&tp->t_token);
943 tp->t_ispeed = t->c_ispeed;
944 tp->t_ospeed = t->c_ospeed;
945 tp->t_cflag = t->c_cflag;
946 lwkt_reltoken(&tp->t_token);
952 scioctl(struct dev_ioctl_args *ap)
954 cdev_t dev = ap->a_head.a_dev;
955 u_long cmd = ap->a_cmd;
956 caddr_t data = ap->a_data;
957 int flag = ap->a_fflag;
964 lwkt_gettoken(&vga_token);
967 error = sc_vid_ioctl(tp, cmd, data, flag);
968 if (error != ENOIOCTL) {
969 lwkt_reltoken(&vga_token);
973 #ifndef SC_NO_HISTORY
974 error = sc_hist_ioctl(tp, cmd, data, flag);
975 if (error != ENOIOCTL) {
976 lwkt_reltoken(&vga_token);
981 #ifndef SC_NO_SYSMOUSE
982 error = sc_mouse_ioctl(tp, cmd, data, flag);
983 if (error != ENOIOCTL) {
984 lwkt_reltoken(&vga_token);
989 scp = SC_STAT(tp->t_dev);
990 /* assert(scp != NULL) */
991 /* scp is sc_console, if SC_VTY(dev) == SC_CONSOLECTL. */
996 error = (*scp->tsw->te_ioctl)(scp, tp, cmd, data, flag);
998 if (error != ENOIOCTL) {
999 lwkt_reltoken(&vga_token);
1004 switch (cmd) { /* process console hardware related ioctl's */
1006 case GIO_ATTR: /* get current attributes */
1007 /* this ioctl is not processed here, but in the terminal emulator */
1008 lwkt_reltoken(&vga_token);
1011 case GIO_COLOR: /* is this a color console ? */
1012 if (sc->fbi != NULL)
1015 *(int *)data = (sc->adp->va_flags & V_ADP_COLOR) ? 1 : 0;
1016 lwkt_reltoken(&vga_token);
1019 case CONS_BLANKTIME: /* set screen saver timeout (0 = no saver) */
1020 if (*(int *)data < 0 || *(int *)data > MAX_BLANKTIME) {
1021 lwkt_reltoken(&vga_token);
1025 scrn_blank_time = *(int *)data;
1026 run_scrn_saver = (scrn_blank_time != 0);
1028 lwkt_reltoken(&vga_token);
1031 case CONS_CURSORTYPE: /* set cursor type blink/noblink */
1033 if (!ISGRAPHSC(sc->cur_scp))
1034 sc_remove_cursor_image(sc->cur_scp);
1035 if ((*(int*)data) & 0x01)
1036 sc->flags |= SC_BLINK_CURSOR;
1038 sc->flags &= ~SC_BLINK_CURSOR;
1039 if ((*(int*)data) & 0x02) {
1040 sc->flags |= SC_CHAR_CURSOR;
1042 sc->flags &= ~SC_CHAR_CURSOR;
1044 * The cursor shape is global property; all virtual consoles
1045 * are affected. Update the cursor in the current console...
1047 if (!ISGRAPHSC(sc->cur_scp)) {
1048 sc_set_cursor_image(sc->cur_scp);
1049 sc_draw_cursor_image(sc->cur_scp);
1052 lwkt_reltoken(&vga_token);
1055 case CONS_BELLTYPE: /* set bell type sound/visual */
1058 if ((*(int *)data) & 0x01)
1059 sc->flags |= SC_VISUAL_BELL;
1061 sc->flags &= ~SC_VISUAL_BELL;
1063 if ((*(int *)data) & 0x02)
1064 sc->flags |= SC_QUIET_BELL;
1066 sc->flags &= ~SC_QUIET_BELL;
1069 lwkt_reltoken(&vga_token);
1072 case CONS_GETINFO: /* get current (virtual) console info */
1074 vid_info_t *ptr = (vid_info_t*)data;
1075 if (ptr->size == sizeof(struct vid_info)) {
1076 ptr->m_num = sc->cur_scp->index;
1077 ptr->font_size = scp->font_height;
1078 ptr->mv_col = scp->xpos;
1079 ptr->mv_row = scp->ypos;
1080 ptr->mv_csz = scp->xsize;
1081 ptr->mv_rsz = scp->ysize;
1083 * The following fields are filled by the terminal emulator. XXX
1090 ptr->mv_grfc.fore = 0; /* not supported */
1091 ptr->mv_grfc.back = 0; /* not supported */
1092 ptr->mv_ovscan = scp->border;
1093 if (scp == sc->cur_scp)
1094 save_kbd_state(scp, FALSE);
1095 ptr->mk_keylock = scp->status & LOCK_MASK;
1096 lwkt_reltoken(&vga_token);
1099 lwkt_reltoken(&vga_token);
1103 case CONS_GETVERS: /* get version number */
1104 *(int*)data = 0x200; /* version 2.0 */
1105 lwkt_reltoken(&vga_token);
1108 case CONS_IDLE: /* see if the screen has been idle */
1110 * When the screen is in the GRAPHICS_MODE or UNKNOWN_MODE,
1111 * the user process may have been writing something on the
1112 * screen and syscons is not aware of it. Declare the screen
1113 * is NOT idle if it is in one of these modes. But there is
1114 * an exception to it; if a screen saver is running in the
1115 * graphics mode in the current screen, we should say that the
1116 * screen has been idle.
1118 *(int *)data = (sc->flags & SC_SCRN_IDLE)
1119 && (!ISGRAPHSC(sc->cur_scp)
1120 || (sc->cur_scp->status & SAVER_RUNNING));
1121 lwkt_reltoken(&vga_token);
1124 case CONS_SAVERMODE: /* set saver mode */
1125 switch(*(int *)data) {
1127 case CONS_USR_SAVER:
1129 /* if a LKM screen saver is running, stop it first. */
1130 scsplash_stick(FALSE);
1131 saver_mode = *(int *)data;
1133 if ((error = wait_scrn_saver_stop(NULL, TRUE))) {
1135 lwkt_reltoken(&vga_token);
1138 #endif /* NSPLASH */
1139 run_scrn_saver = TRUE;
1140 if (saver_mode == CONS_USR_SAVER)
1141 scp->status |= SAVER_RUNNING;
1143 scp->status &= ~SAVER_RUNNING;
1144 scsplash_stick(TRUE);
1147 case CONS_LKM_SAVER:
1149 if ((saver_mode == CONS_USR_SAVER) && (scp->status & SAVER_RUNNING))
1150 scp->status &= ~SAVER_RUNNING;
1151 saver_mode = *(int *)data;
1155 lwkt_reltoken(&vga_token);
1158 lwkt_reltoken(&vga_token);
1161 case CONS_SAVERSTART: /* immediately start/stop the screen saver */
1163 * Note that this ioctl does not guarantee the screen saver
1164 * actually starts or stops. It merely attempts to do so...
1167 run_scrn_saver = (*(int *)data != 0);
1169 sc->scrn_time_stamp -= scrn_blank_time;
1171 lwkt_reltoken(&vga_token);
1174 case CONS_SCRSHOT: /* get a screen shot */
1176 scrshot_t *ptr = (scrshot_t*)data;
1178 if (ISGRAPHSC(scp)) {
1180 lwkt_reltoken(&vga_token);
1183 if (scp->xsize != ptr->xsize || scp->ysize != ptr->ysize) {
1185 lwkt_reltoken(&vga_token);
1189 copyout ((void*)scp->vtb.vtb_buffer, ptr->buf,
1190 ptr->xsize * ptr->ysize * sizeof(uint16_t));
1191 lwkt_reltoken(&vga_token);
1195 case VT_SETMODE: /* set screen switcher mode */
1197 struct vt_mode *mode;
1199 mode = (struct vt_mode *)data;
1200 DPRINTF(5, ("sc%d: VT_SETMODE ", sc->unit));
1201 if (scp->smode.mode == VT_PROCESS) {
1202 if (scp->proc == pfindn(scp->pid) && scp->proc != curproc) {
1203 DPRINTF(5, ("error EPERM\n"));
1204 lwkt_reltoken(&vga_token);
1209 if (mode->mode == VT_AUTO) {
1210 scp->smode.mode = VT_AUTO;
1213 DPRINTF(5, ("VT_AUTO, "));
1214 if ((scp == sc->cur_scp) && (sc->unit == sc_console_unit) &&
1216 cons_unavail = FALSE;
1218 if (finish_vt_rel(scp, TRUE) == 0)
1219 DPRINTF(5, ("reset WAIT_REL, "));
1220 if (finish_vt_acq(scp) == 0)
1221 DPRINTF(5, ("reset WAIT_ACQ, "));
1223 if (!ISSIGVALID(mode->relsig) || !ISSIGVALID(mode->acqsig)
1224 || !ISSIGVALID(mode->frsig)) {
1226 DPRINTF(5, ("error EINVAL\n"));
1227 lwkt_reltoken(&vga_token);
1230 DPRINTF(5, ("VT_PROCESS %d, ", curproc->p_pid));
1231 bcopy(data, &scp->smode, sizeof(struct vt_mode));
1232 scp->proc = curproc;
1233 scp->pid = scp->proc->p_pid;
1234 if ((scp == sc->cur_scp) && (sc->unit == sc_console_unit))
1235 cons_unavail = TRUE;
1239 lwkt_reltoken(&vga_token);
1243 case VT_GETMODE: /* get screen switcher mode */
1244 bcopy(&scp->smode, data, sizeof(struct vt_mode));
1245 lwkt_reltoken(&vga_token);
1248 case VT_RELDISP: /* screen switcher ioctl */
1250 * This must be the current vty which is in the VT_PROCESS
1254 if ((scp != sc->cur_scp) || (scp->smode.mode != VT_PROCESS)) {
1256 lwkt_reltoken(&vga_token);
1259 /* ...and this process is controlling it. */
1260 if (scp->proc != curproc) {
1262 lwkt_reltoken(&vga_token);
1266 switch(*(int *)data) {
1267 case VT_FALSE: /* user refuses to release screen, abort */
1268 if ((error = finish_vt_rel(scp, FALSE)) == 0)
1269 DPRINTF(5, ("sc%d: VT_FALSE\n", sc->unit));
1271 case VT_TRUE: /* user has released screen, go on */
1272 if ((error = finish_vt_rel(scp, TRUE)) == 0)
1273 DPRINTF(5, ("sc%d: VT_TRUE\n", sc->unit));
1275 case VT_ACKACQ: /* acquire acknowledged, switch completed */
1276 if ((error = finish_vt_acq(scp)) == 0)
1277 DPRINTF(5, ("sc%d: VT_ACKACQ\n", sc->unit));
1279 /* Wait for drm modesetting callback to finish. */
1280 lwkt_reltoken(&vga_token);
1281 if (sc->fb_set_par_task != NULL)
1282 taskqueue_drain(taskqueue_thread[0], sc->fb_set_par_task);
1288 lwkt_reltoken(&vga_token);
1291 case VT_OPENQRY: /* return free virtual console */
1292 for (i = sc->first_vty; i < sc->first_vty + sc->vtys; i++) {
1293 tp = VIRTUAL_TTY(sc, i);
1294 if (!ISTTYOPEN(tp)) {
1295 *(int *)data = i + 1;
1296 lwkt_reltoken(&vga_token);
1300 lwkt_reltoken(&vga_token);
1303 case VT_ACTIVATE: /* switch to screen *data */
1304 i = (*(int *)data == 0) ? scp->index : (*(int *)data - 1);
1306 sc_clean_up(sc->cur_scp, TRUE);
1307 error = sc_switch_scr(sc, i);
1309 lwkt_reltoken(&vga_token);
1312 case VT_WAITACTIVE: /* wait for switch to occur */
1313 i = (*(int *)data == 0) ? scp->index : (*(int *)data - 1);
1314 if ((i < sc->first_vty) || (i >= sc->first_vty + sc->vtys)) {
1315 lwkt_reltoken(&vga_token);
1319 error = sc_clean_up(sc->cur_scp, TRUE);
1322 lwkt_reltoken(&vga_token);
1327 * scp might be NULL, we aren't sure why. Check for NULL.
1329 * http://bugs.dragonflybsd.org/issues/2481
1331 scp = SC_STAT(SC_DEV(sc, i));
1332 if (scp == NULL || scp == scp->sc->cur_scp) {
1333 lwkt_reltoken(&vga_token);
1336 error = tsleep((caddr_t)&scp->smode, PCATCH, "waitvt", 0);
1337 /* May return ERESTART */
1338 lwkt_reltoken(&vga_token);
1339 /* Wait for drm modesetting callback to finish. */
1340 if (sc->fb_set_par_task != NULL)
1341 taskqueue_drain(taskqueue_thread[0], sc->fb_set_par_task);
1344 case VT_GETACTIVE: /* get active vty # */
1345 *(int *)data = sc->cur_scp->index + 1;
1346 lwkt_reltoken(&vga_token);
1349 case VT_GETINDEX: /* get this vty # */
1350 *(int *)data = scp->index + 1;
1351 lwkt_reltoken(&vga_token);
1354 case VT_LOCKSWITCH: /* prevent vty switching */
1356 if ((*(int *)data) & 0x01)
1357 sc->flags |= SC_SCRN_VTYLOCK;
1359 sc->flags &= ~SC_SCRN_VTYLOCK;
1361 lwkt_reltoken(&vga_token);
1364 case KDENABIO: /* allow io operations */
1365 error = priv_check_cred(ap->a_cred, PRIV_ROOT, 0);
1367 lwkt_reltoken(&vga_token);
1370 if (securelevel > 0) {
1371 lwkt_reltoken(&vga_token);
1374 #if defined(__i386__)
1375 curthread->td_lwp->lwp_md.md_regs->tf_eflags |= PSL_IOPL;
1376 #elif defined(__x86_64__)
1377 curthread->td_lwp->lwp_md.md_regs->tf_rflags |= PSL_IOPL;
1379 lwkt_reltoken(&vga_token);
1382 case KDDISABIO: /* disallow io operations (default) */
1383 #if defined(__i386__)
1384 curthread->td_lwp->lwp_md.md_regs->tf_eflags &= ~PSL_IOPL;
1385 #elif defined(__x86_64__)
1386 curthread->td_lwp->lwp_md.md_regs->tf_rflags &= ~PSL_IOPL;
1388 lwkt_reltoken(&vga_token);
1391 case KDSKBSTATE: /* set keyboard state (locks) */
1392 if (*(int *)data & ~LOCK_MASK) {
1393 lwkt_reltoken(&vga_token);
1397 scp->status &= ~LOCK_MASK;
1398 scp->status |= *(int *)data;
1400 if (scp == sc->cur_scp)
1401 update_kbd_state(scp, scp->status, LOCK_MASK, FALSE);
1402 lwkt_reltoken(&vga_token);
1405 case KDGKBSTATE: /* get keyboard state (locks) */
1406 if (scp == sc->cur_scp)
1407 save_kbd_state(scp, FALSE);
1408 *(int *)data = scp->status & LOCK_MASK;
1409 lwkt_reltoken(&vga_token);
1412 case KDGETREPEAT: /* get keyboard repeat & delay rates */
1413 case KDSETREPEAT: /* set keyboard repeat & delay rates (new) */
1414 error = kbd_ioctl(sc->kbd, cmd, data);
1415 if (error == ENOIOCTL)
1417 lwkt_reltoken(&vga_token);
1420 case KDSKBMODE: /* set keyboard mode */
1421 switch (*(int *)data) {
1422 case K_XLATE: /* switch to XLT ascii mode */
1423 case K_RAW: /* switch to RAW scancode mode */
1424 case K_CODE: /* switch to CODE mode */
1425 scp->kbd_mode = *(int *)data;
1426 if (scp == sc->cur_scp)
1427 kbd_ioctl(sc->kbd, cmd, data);
1428 lwkt_reltoken(&vga_token);
1431 lwkt_reltoken(&vga_token);
1436 case KDGKBMODE: /* get keyboard mode */
1437 *(int *)data = scp->kbd_mode;
1438 lwkt_reltoken(&vga_token);
1442 error = kbd_ioctl(sc->kbd, cmd, data);
1443 if (error == ENOIOCTL)
1445 lwkt_reltoken(&vga_token);
1448 case KDMKTONE: /* sound the bell */
1451 sc_bell(scp, (*(int*)data)&0xffff,
1452 (((*(int*)data)>>16)&0xffff)*hz/1000);
1454 sc_bell(scp, scp->bell_pitch, scp->bell_duration);
1456 lwkt_reltoken(&vga_token);
1459 case KIOCSOUND: /* make tone (*data) hz */
1461 if (scp == sc->cur_scp) {
1463 error = sc_tone(*(int *)data);
1471 lwkt_reltoken(&vga_token);
1474 case KDGKBTYPE: /* get keyboard type */
1475 error = kbd_ioctl(sc->kbd, cmd, data);
1476 if (error == ENOIOCTL) {
1477 /* always return something? XXX */
1480 lwkt_reltoken(&vga_token);
1483 case KDSETLED: /* set keyboard LED status */
1484 if (*(int *)data & ~LED_MASK) { /* FIXME: LOCK_MASK? */
1485 lwkt_reltoken(&vga_token);
1489 scp->status &= ~LED_MASK;
1490 scp->status |= *(int *)data;
1492 if (scp == sc->cur_scp)
1493 update_kbd_leds(scp, scp->status);
1494 lwkt_reltoken(&vga_token);
1497 case KDGETLED: /* get keyboard LED status */
1498 if (scp == sc->cur_scp)
1499 save_kbd_state(scp, FALSE);
1500 *(int *)data = scp->status & LED_MASK;
1501 lwkt_reltoken(&vga_token);
1504 case KBADDKBD: /* add/remove keyboard to/from mux */
1506 error = kbd_ioctl(sc->kbd, cmd, data);
1507 if (error == ENOIOCTL)
1509 lwkt_reltoken(&vga_token);
1512 case CONS_SETKBD: /* set the new keyboard */
1516 newkbd = kbd_get_keyboard(*(int *)data);
1517 if (newkbd == NULL) {
1518 lwkt_reltoken(&vga_token);
1522 if (sc->kbd != newkbd) {
1523 i = kbd_allocate(newkbd->kb_name, newkbd->kb_unit,
1524 (void *)&sc->keyboard, sckbdevent, sc);
1525 /* i == newkbd->kb_index */
1527 if (sc->kbd != NULL) {
1528 save_kbd_state(sc->cur_scp, FALSE);
1529 kbd_release(sc->kbd, (void *)&sc->keyboard);
1532 sc->kbd = kbd_get_keyboard(i); /* sc->kbd == newkbd */
1535 kbd_ioctl(sc->kbd, KDSKBMODE,
1536 (caddr_t)&sc->cur_scp->kbd_mode);
1537 update_kbd_state(sc->cur_scp, sc->cur_scp->status,
1540 error = EPERM; /* XXX */
1543 lwkt_reltoken(&vga_token);
1547 case CONS_RELKBD: /* release the current keyboard */
1549 if (sc->kbd != NULL) {
1550 save_kbd_state(sc->cur_scp, FALSE);
1551 error = kbd_release(sc->kbd, (void *)&sc->keyboard);
1559 lwkt_reltoken(&vga_token);
1562 case CONS_GETTERM: /* get the current terminal emulator info */
1566 if (((term_info_t *)data)->ti_index == 0) {
1569 sw = sc_term_match_by_number(((term_info_t *)data)->ti_index);
1572 strncpy(((term_info_t *)data)->ti_name, sw->te_name,
1573 sizeof(((term_info_t *)data)->ti_name));
1574 strncpy(((term_info_t *)data)->ti_desc, sw->te_desc,
1575 sizeof(((term_info_t *)data)->ti_desc));
1576 ((term_info_t *)data)->ti_flags = 0;
1577 lwkt_reltoken(&vga_token);
1580 ((term_info_t *)data)->ti_name[0] = '\0';
1581 ((term_info_t *)data)->ti_desc[0] = '\0';
1582 ((term_info_t *)data)->ti_flags = 0;
1583 lwkt_reltoken(&vga_token);
1588 case CONS_SETTERM: /* set the current terminal emulator */
1590 error = sc_init_emulator(scp, ((term_info_t *)data)->ti_name);
1591 /* FIXME: what if scp == sc_console! XXX */
1593 lwkt_reltoken(&vga_token);
1596 case GIO_SCRNMAP: /* get output translation table */
1597 bcopy(&sc->scr_map, data, sizeof(sc->scr_map));
1598 lwkt_reltoken(&vga_token);
1601 case PIO_SCRNMAP: /* set output translation table */
1602 bcopy(data, &sc->scr_map, sizeof(sc->scr_map));
1603 for (i=0; i<sizeof(sc->scr_map); i++) {
1604 sc->scr_rmap[sc->scr_map[i]] = i;
1606 lwkt_reltoken(&vga_token);
1609 case GIO_KEYMAP: /* get keyboard translation table */
1610 case PIO_KEYMAP: /* set keyboard translation table */
1611 case GIO_DEADKEYMAP: /* get accent key translation table */
1612 case PIO_DEADKEYMAP: /* set accent key translation table */
1613 case GETFKEY: /* get function key string */
1614 case SETFKEY: /* set function key string */
1615 error = kbd_ioctl(sc->kbd, cmd, data);
1616 if (error == ENOIOCTL)
1618 lwkt_reltoken(&vga_token);
1621 #ifndef SC_NO_FONT_LOADING
1623 case PIO_FONT8x8: /* set 8x8 dot font */
1624 if (sc->fbi == NULL && !ISFONTAVAIL(sc->adp->va_flags)) {
1625 lwkt_reltoken(&vga_token);
1629 bcopy(data, sc->font_8, 8*256);
1630 sc->fonts_loaded |= FONT_8;
1633 * Always use the font page #0. XXX
1634 * Don't load if the current font size is not 8x8.
1637 && ISTEXTSC(sc->cur_scp) && (sc->cur_scp->font_height < 14)) {
1638 sc_load_font(sc->cur_scp, 0, 8, sc->font_8, 0, 256);
1641 lwkt_reltoken(&vga_token);
1644 case GIO_FONT8x8: /* get 8x8 dot font */
1645 if (sc->fbi == NULL && !ISFONTAVAIL(sc->adp->va_flags)) {
1646 lwkt_reltoken(&vga_token);
1649 if (sc->fonts_loaded & FONT_8) {
1650 bcopy(sc->font_8, data, 8*256);
1651 lwkt_reltoken(&vga_token);
1655 lwkt_reltoken(&vga_token);
1659 case PIO_FONT8x14: /* set 8x14 dot font */
1660 if (sc->fbi == NULL && !ISFONTAVAIL(sc->adp->va_flags)) {
1661 lwkt_reltoken(&vga_token);
1665 bcopy(data, sc->font_14, 14*256);
1666 sc->fonts_loaded |= FONT_14;
1669 * Always use the font page #0. XXX
1670 * Don't load if the current font size is not 8x14.
1673 && ISTEXTSC(sc->cur_scp)
1674 && (sc->cur_scp->font_height >= 14)
1675 && (sc->cur_scp->font_height < 16)) {
1676 sc_load_font(sc->cur_scp, 0, 14, sc->font_14, 0, 256);
1679 lwkt_reltoken(&vga_token);
1682 case GIO_FONT8x14: /* get 8x14 dot font */
1683 if (sc->fbi == NULL && !ISFONTAVAIL(sc->adp->va_flags)) {
1684 lwkt_reltoken(&vga_token);
1687 if (sc->fonts_loaded & FONT_14) {
1688 bcopy(sc->font_14, data, 14*256);
1689 lwkt_reltoken(&vga_token);
1693 lwkt_reltoken(&vga_token);
1697 case PIO_FONT8x16: /* set 8x16 dot font */
1698 if (sc->fbi == NULL && !ISFONTAVAIL(sc->adp->va_flags)) {
1699 lwkt_reltoken(&vga_token);
1703 bcopy(data, sc->font_16, 16*256);
1704 sc->fonts_loaded |= FONT_16;
1707 * Always use the font page #0. XXX
1708 * Don't load if the current font size is not 8x16.
1711 && ISTEXTSC(sc->cur_scp) && (sc->cur_scp->font_height >= 16)) {
1712 sc_load_font(sc->cur_scp, 0, 16, sc->font_16, 0, 256);
1715 lwkt_reltoken(&vga_token);
1718 case GIO_FONT8x16: /* get 8x16 dot font */
1719 if (sc->fbi == NULL && !ISFONTAVAIL(sc->adp->va_flags)) {
1720 lwkt_reltoken(&vga_token);
1723 if (sc->fonts_loaded & FONT_16) {
1724 bcopy(sc->font_16, data, 16*256);
1725 lwkt_reltoken(&vga_token);
1729 lwkt_reltoken(&vga_token);
1733 #endif /* SC_NO_FONT_LOADING */
1739 lwkt_gettoken(&tp->t_token);
1740 error = (*linesw[tp->t_line].l_ioctl)(tp, cmd, data, flag, ap->a_cred);
1741 if (error != ENOIOCTL) {
1742 lwkt_reltoken(&tp->t_token);
1743 lwkt_reltoken(&vga_token);
1748 error = ttioctl(tp, cmd, data, flag);
1749 if (error != ENOIOCTL) {
1750 lwkt_reltoken(&tp->t_token);
1751 lwkt_reltoken(&vga_token);
1756 lwkt_reltoken(&tp->t_token);
1757 lwkt_reltoken(&vga_token);
1763 scstart(struct tty *tp)
1767 u_char buf[PCBURST];
1768 scr_stat *scp = SC_STAT(tp->t_dev);
1771 if (scp->status & SLKED ||
1772 (scp == scp->sc->cur_scp && scp->sc->blink_in_progress))
1777 if (!(tp->t_state & (TS_TIMEOUT | TS_BUSY | TS_TTSTOP))) {
1778 tp->t_state |= TS_BUSY;
1781 len = clist_qtob(rbp, buf, PCBURST);
1782 sc_puts(scp, buf, len);
1784 tp->t_state &= ~TS_BUSY;
1793 sccnprobe(struct consdev *cp)
1798 cp->cn_pri = sc_get_cons_priority(&unit, &flags);
1800 /* a video card is always required */
1801 if (probe_efi_fb(1) != 0 && !scvidprobe(unit, flags, TRUE))
1802 cp->cn_pri = CN_DEAD;
1804 /* syscons will become console even when there is no keyboard */
1805 sckbdprobe(unit, flags, TRUE);
1807 if (cp->cn_pri == CN_DEAD) {
1811 /* initialize required fields */
1812 cp->cn_probegood = 1;
1816 sccninit(struct consdev *cp)
1821 sc_get_cons_priority(&unit, &flags);
1822 scinit(unit, flags | SC_KERNEL_CONSOLE);
1823 sc_console_unit = unit;
1824 sc_console = sc_get_softc(unit, SC_KERNEL_CONSOLE)->console_scp;
1828 sccninit_fini(struct consdev *cp)
1830 if (cctl_dev == NULL)
1831 kprintf("sccninit_fini: WARNING: cctl_dev is NULL!\n");
1832 cp->cn_dev = cctl_dev;
1836 * This is called when the console is switched away from syscons to
1837 * a late-configuring device (such as a PCIe serial port). Since
1838 * late-configuring devices basically didn't exist until now, this
1839 * routine was never called, and SURPRISE! It doesn't work... causes
1840 * syscons to implode due to all the funny console-not-console structure
1841 * selection syscons does.
1843 * Make it a NOP. Just leave the console designation intact, even
1844 * though it is no longer a console.
1847 sccnterm(struct consdev *cp)
1850 /* we are not the kernel console any more, release everything */
1852 if (sc_console_unit < 0)
1853 return; /* shouldn't happen */
1857 sc_clear_screen(sc_console);
1858 sccnupdate(sc_console);
1861 scterm(sc_console_unit, SC_KERNEL_CONSOLE);
1862 sc_console_unit = -1;
1868 * Console path - cannot block!
1871 sccnputc(void *private, int c)
1874 scr_stat *scp = sc_console;
1876 #ifndef SC_NO_HISTORY
1880 #endif /* !SC_NO_HISTORY */
1882 /* assert(sc_console != NULL) */
1885 #ifndef SC_NO_HISTORY
1886 if (scp == scp->sc->cur_scp && scp->status & SLKED) {
1887 scp->status &= ~SLKED;
1889 /* This can block, illegal in the console path */
1890 update_kbd_state(scp, scp->status, SLKED, TRUE);
1892 if (scp->status & BUFFER_SAVED) {
1893 if (!sc_hist_restore(scp))
1894 sc_remove_cutmarking(scp);
1895 scp->status &= ~BUFFER_SAVED;
1896 scp->status |= CURSOR_ENABLED;
1897 sc_draw_cursor_image(scp);
1900 tp = VIRTUAL_TTY(scp->sc, scp->index);
1901 /* This can block, illegal in the console path */
1902 if (ISTTYOPEN(tp)) {
1907 #endif /* !SC_NO_HISTORY */
1910 if (kernel_console_ts != NULL)
1911 scp->ts = kernel_console_ts;
1913 sc_puts(scp, buf, 1);
1921 * Console path - cannot block!
1924 sccngetc(void *private)
1926 return sccngetch(0);
1930 * Console path - cannot block!
1933 sccncheckc(void *private)
1935 return sccngetch(SCGETC_NONBLOCK);
1939 * Set polling mode (also disables the tty feed), use when
1940 * polling for console key input.
1943 sccnpoll(void *private, int on)
1948 sc_touch_scrn_saver();
1949 scp = sc_console->sc->cur_scp; /* XXX */
1952 kbd_poll(scp->sc->kbd, on);
1956 sccndbctl(void *private, int on)
1958 /* assert(sc_console_unit >= 0) */
1959 /* try to switch to the kernel console screen */
1960 if (on && debugger == 0) {
1962 * TRY to make sure the screen saver is stopped,
1963 * and the screen is updated before switching to
1968 && sc_console->sc->cur_scp->smode.mode == VT_AUTO
1969 && sc_console->smode.mode == VT_AUTO) {
1970 sc_console->sc->cur_scp->status |= MOUSE_HIDDEN;
1972 sc_switch_scr(sc_console->sc, sc_console->index);
1983 * Console path - cannot block!
1986 sccngetch(int flags)
1988 static struct fkeytab fkey;
1996 /* assert(sc_console != NULL) */
1999 * Stop the screen saver and update the screen if necessary.
2000 * What if we have been running in the screen saver code... XXX
2002 sc_touch_scrn_saver();
2003 scp = sc_console->sc->cur_scp; /* XXX */
2007 if (fkeycp < fkey.len) {
2008 return fkey.str[fkeycp++];
2011 if (scp->sc->kbd == NULL) {
2016 * Make sure the keyboard is accessible even when the kbd device
2017 * driver is disabled.
2020 kbd_enable(scp->sc->kbd);
2022 /* we shall always use the keyboard in the XLATE mode here */
2023 cur_mode = scp->kbd_mode;
2024 scp->kbd_mode = K_XLATE;
2025 kbd_ioctl(scp->sc->kbd, KDSKBMODE, (caddr_t)&scp->kbd_mode);
2027 c = scgetc(scp->sc, SCGETC_CN | flags);
2029 scp->kbd_mode = cur_mode;
2030 kbd_ioctl(scp->sc->kbd, KDSKBMODE, (caddr_t)&scp->kbd_mode);
2031 kbd_disable(scp->sc->kbd);
2034 switch (KEYFLAGS(c)) {
2035 case 0: /* normal char */
2037 case FKEY: /* function key */
2038 p = kbd_get_fkeystr(scp->sc->kbd, KEYCHAR(c), (size_t *)&fkeycp);
2040 if ((p != NULL) && (fkey.len > 0)) {
2041 bcopy(p, fkey.str, fkey.len);
2047 if (flags & SCGETC_NONBLOCK)
2058 sccnupdate(scr_stat *scp)
2063 ddb_active = db_active;
2068 /* this is a cut-down version of scrn_timer()... */
2071 * Don't update if videoio is in progress. However, if we are paniced
2072 * or in the debugger it is possible that the variables might be stuck,
2073 * so ignore it in such cases.
2075 if (scp->sc->font_loading_in_progress || scp->sc->videoio_in_progress) {
2076 if (panicstr == NULL && ddb_active == 0 && shutdown_in_progress == 0)
2080 if (debugger > 0 || panicstr || ddb_active || shutdown_in_progress) {
2081 sc_touch_scrn_saver();
2082 } else if (scp != scp->sc->cur_scp) {
2086 if (!run_scrn_saver)
2087 scp->sc->flags &= ~SC_SCRN_IDLE;
2090 * This is a hard path, we cannot call stop_scrn_saver() here.
2092 if ((saver_mode != CONS_LKM_SAVER) || !(scp->sc->flags & SC_SCRN_IDLE))
2093 if (scp->sc->flags & SC_SCRN_BLANKED) {
2094 sc_touch_scrn_saver();
2095 /*stop_scrn_saver(scp->sc, current_saver);*/
2097 #endif /* NSPLASH */
2099 if (scp != scp->sc->cur_scp || scp->sc->blink_in_progress
2100 || scp->sc->switch_in_progress) {
2105 * FIXME: unlike scrn_timer(), we call scrn_update() from here even
2106 * when write_in_progress is non-zero. XXX
2108 if (!ISGRAPHSC(scp) && !(scp->sc->flags & SC_SCRN_BLANKED))
2109 scrn_update(scp, TRUE, SCRN_ASYNCOK);
2113 scrn_timer(void *arg)
2115 static int kbd_interval = 0;
2122 * Setup depending on who called us
2124 again = (arg != NULL);
2126 sc = (sc_softc_t *)arg;
2127 } else if (sc_console != NULL) {
2128 sc = sc_console->sc;
2134 * Don't do anything when we are performing some I/O operations.
2135 * (These are initiated by the frontend?)
2137 if (sc->font_loading_in_progress || sc->videoio_in_progress) {
2139 callout_reset(&sc->scrn_timer_ch, hz / 10, scrn_timer, sc);
2144 * Try to allocate a keyboard automatically
2146 if ((sc->kbd == NULL) && (sc->config & SC_AUTODETECT_KBD)) {
2147 if (++kbd_interval >= 25) {
2148 sc->keyboard = sc_allocate_keyboard(sc, -1);
2149 if (sc->keyboard >= 0) {
2150 sc->kbd = kbd_get_keyboard(sc->keyboard);
2151 kbd_ioctl(sc->kbd, KDSKBMODE,
2152 (caddr_t)&sc->cur_scp->kbd_mode);
2153 update_kbd_state(sc->cur_scp, sc->cur_scp->status,
2161 * Should we stop the screen saver? We need the syscons_lock
2162 * for most of this stuff.
2164 getmicrouptime(&tv);
2166 if (syscons_lock_nonblock() != 0) {
2167 /* failed to get the lock */
2169 callout_reset(&sc->scrn_timer_ch, hz / 10, scrn_timer, sc);
2172 /* successful lock */
2174 if (debugger > 0 || panicstr || shutdown_in_progress)
2175 sc_touch_scrn_saver();
2176 if (run_scrn_saver) {
2177 if (tv.tv_sec > sc->scrn_time_stamp + scrn_blank_time)
2178 sc->flags |= SC_SCRN_IDLE;
2180 sc->flags &= ~SC_SCRN_IDLE;
2182 sc->scrn_time_stamp = tv.tv_sec;
2183 sc->flags &= ~SC_SCRN_IDLE;
2184 if (scrn_blank_time > 0)
2185 run_scrn_saver = TRUE;
2188 if ((saver_mode != CONS_LKM_SAVER) || !(sc->flags & SC_SCRN_IDLE)) {
2189 if ((sc->flags & SC_SCRN_BLANKED) && !ISGRAPHSC(sc->cur_scp))
2190 stop_scrn_saver(sc, current_saver);
2192 #endif /* NSPLASH */
2194 /* should we just return ? */
2195 if (sc->blink_in_progress || sc->switch_in_progress ||
2196 sc->write_in_progress)
2200 callout_reset(&sc->scrn_timer_ch, hz / 10, scrn_timer, sc);
2204 /* Update the screen */
2205 scp = sc->cur_scp; /* cur_scp may have changed... */
2206 if (!ISGRAPHSC(scp) && !(sc->flags & SC_SCRN_BLANKED))
2207 scrn_update(scp, TRUE, SCRN_ASYNCOK);
2210 /* should we activate the screen saver? */
2211 if ((saver_mode == CONS_LKM_SAVER) && (sc->flags & SC_SCRN_IDLE))
2212 if (!ISGRAPHSC(scp) || (sc->flags & SC_SCRN_BLANKED))
2213 (*current_saver)(sc, TRUE);
2214 #endif /* NSPLASH */
2218 callout_reset(&sc->scrn_timer_ch, hz / 25, scrn_timer, sc);
2222 and_region(int *s1, int *e1, int s2, int e2)
2224 if (*e1 < s2 || e2 < *s1)
2226 *s1 = imax(*s1, s2);
2227 *e1 = imin(*e1, e2);
2232 * Refresh modified frame buffer range. Also used to
2233 * scroll (entire FB is marked modified).
2235 * This function is allowed to run without the syscons_lock,
2236 * so scp fields can change unexpected. We cache most values
2237 * that we care about and silently discard illegal ranges.
2240 scrn_update(scr_stat *scp, int show_cursor, int flags)
2251 ddb_active = db_active;
2257 * Try to run large screen updates as an async operation, which will
2258 * call this function again from a thread with BULKUNLOCK set, allowing
2259 * interrupts during the update which tends to make the system behave
2260 * better (no sound glitches, etc).
2262 if ((flags & SCRN_ASYNCOK) && syscons_async && scp->asynctd &&
2263 (scp->end - scp->start) > 16 &&
2264 panicstr == NULL && ddb_active == 0 && shutdown_in_progress == 0) {
2265 scp->show_cursor = show_cursor;
2266 scp->queue_update_td = 1;
2267 wakeup(&scp->asynctd);
2270 if (flags & SCRN_BULKUNLOCK)
2274 * Synchronous operation or called from
2277 /* assert(scp == scp->sc->cur_scp) */
2278 atomic_add_int(&scp->sc->videoio_in_progress, 1);
2280 cpos = scp->cursor_pos;
2281 copos = scp->cursor_oldpos;
2283 #ifndef SC_NO_CUTPASTE
2284 /* remove the previous mouse pointer image if necessary */
2285 if (scp->status & MOUSE_VISIBLE) {
2287 e = scp->mouse_pos + scp->xsize + 1;
2288 if ((scp->status & (MOUSE_MOVED | MOUSE_HIDDEN))
2289 || and_region(&s, &e, scp->start, scp->end)
2290 || ((scp->status & CURSOR_ENABLED) &&
2292 (and_region(&s, &e, cpos, cpos)
2293 || and_region(&s, &e, copos, copos)))) {
2294 sc_remove_mouse_image(scp);
2295 if (scp->end >= scp->xsize*scp->ysize)
2296 scp->end = scp->xsize*scp->ysize - 1;
2299 #endif /* !SC_NO_CUTPASTE */
2302 * WARNING: Don't add debugging kprintf()s with syscons locked.
2305 if (scp->end >= scp->xsize*scp->ysize) {
2306 scp->end = scp->xsize*scp->ysize - 1;
2308 if (scp->start < 0) {
2313 * Main update, extract update range and reset
2319 scp->start = scp->xsize * scp->ysize - 1;
2322 if (flags & SCRN_BULKUNLOCK) {
2323 atomic_add_int(&scp->sc->videoio_in_progress, -1);
2326 (*scp->rndr->draw)(scp, start, end - start + 1, FALSE);
2327 if (flags & SCRN_BULKUNLOCK) {
2329 atomic_add_int(&scp->sc->videoio_in_progress, 1);
2333 * Handle cut sequence
2335 s = scp->mouse_cut_start;
2336 e = scp->mouse_cut_end;
2337 cpu_ccfence(); /* allowed to race */
2345 /* does the cut-mark region overlap with the update region? */
2346 if (and_region(&s, &e, start, end)) {
2347 if (flags & SCRN_BULKUNLOCK) {
2348 atomic_add_int(&scp->sc->videoio_in_progress, -1);
2351 (*scp->rndr->draw)(scp, s, e - s + 1, TRUE);
2352 if (flags & SCRN_BULKUNLOCK) {
2354 atomic_add_int(&scp->sc->videoio_in_progress, 1);
2360 /* we are not to show the cursor and the mouse pointer... */
2364 /* update cursor image */
2365 if (scp->status & CURSOR_ENABLED) {
2368 /* did cursor move since last time ? */
2369 if (cpos != copos) {
2370 /* do we need to remove old cursor image ? */
2371 if (!and_region(&s, &e, copos, copos))
2372 sc_remove_cursor_image(scp);
2373 sc_draw_cursor_image(scp);
2375 if (s <= e && and_region(&s, &e, cpos, cpos)) {
2376 /* cursor didn't move, but has been overwritten */
2377 sc_draw_cursor_image(scp);
2378 } else if (scp->sc->flags & SC_BLINK_CURSOR) {
2379 /* if it's a blinking cursor, update it */
2380 (*scp->rndr->blink_cursor)(scp, cpos,
2381 sc_inside_cutmark(scp, cpos));
2386 #ifndef SC_NO_CUTPASTE
2387 /* update "pseudo" mouse pointer image */
2388 if (scp->sc->flags & SC_MOUSE_ENABLED) {
2389 if (!(scp->status & (MOUSE_VISIBLE | MOUSE_HIDDEN))) {
2390 scp->status &= ~MOUSE_MOVED;
2391 sc_draw_mouse_image(scp);
2394 #endif /* SC_NO_CUTPASTE */
2400 atomic_add_int(&scp->sc->videoio_in_progress, -1);
2401 if (flags & SCRN_BULKUNLOCK)
2406 * Thread handles potentially expensive screen updates. The function is
2407 * expected to operate safely without locks.
2410 scrn_update_thread(void *arg)
2412 scr_stat *scp = arg;
2414 if (scp->queue_update_td == 0) {
2415 tsleep_interlock(&scp->asynctd, 0);
2416 if (scp->queue_update_td == 0)
2417 tsleep(&scp->asynctd, PINTERLOCKED, "wait", 0);
2419 scp->queue_update_td = 0;
2420 lockmgr(&sc_asynctd_lk, LK_EXCLUSIVE);
2421 atomic_add_int(&scp->sc->videoio_in_progress, 1);
2422 scrn_update(scp, scp->show_cursor, SCRN_BULKUNLOCK);
2423 atomic_add_int(&scp->sc->videoio_in_progress, -1);
2424 lockmgr(&sc_asynctd_lk, LK_RELEASE);
2429 sc_fb_set_par(void *context, int pending)
2431 sc_softc_t *sc = context;
2433 lwkt_gettoken(&vga_token);
2434 if (sc->fbi != NULL && sc->fbi->fbops.fb_set_par != NULL)
2435 sc->fbi->fbops.fb_set_par(sc->fbi);
2436 lwkt_reltoken(&vga_token);
2441 sc_fb_blank(void *context, int pending)
2443 sc_softc_t *sc = context;
2445 lwkt_gettoken(&vga_token);
2446 if (sc->fbi != NULL && sc->fbi->fbops.fb_blank != NULL) {
2447 /* 0 == FB_BLANK_UNBLANK and 4 == FB_BLANK_POWERDOWN */
2448 if (sc->flags & SC_SCRN_BLANKED) {
2449 sc->fbi->fbops.fb_blank(4, sc->fbi);
2450 sc->fb_blanked = TRUE;
2451 if (sc->unit == sc_console_unit)
2452 cons_unavail = TRUE;
2454 sc->fbi->fbops.fb_blank(0, sc->fbi);
2455 sc->fb_blanked = FALSE;
2456 if (sc->unit == sc_console_unit &&
2457 sc->cur_scp->smode.mode == VT_AUTO)
2458 cons_unavail = FALSE;
2461 lwkt_reltoken(&vga_token);
2465 scframebuffer_saver(sc_softc_t *sc, int show)
2467 scr_stat *scp = sc->cur_scp;
2473 * Gets called on every screen update while screensaver is active,
2474 * so we need to check the SC_SCRN_BLANKED flag ourselves.
2476 if ((sc->flags & SC_SCRN_BLANKED) && show)
2479 taskqueue_cancel(taskqueue_thread[0], sc->fb_blank_task, NULL);
2482 scp->status |= SAVER_RUNNING;
2483 sc->flags |= SC_SCRN_BLANKED;
2486 scp->status &= ~SAVER_RUNNING;
2487 sc->flags &= ~SC_SCRN_BLANKED;
2491 taskqueue_enqueue(taskqueue_thread[0], sc->fb_blank_task);
2495 scsplash_callback(int event, void *arg)
2500 sc = (sc_softc_t *)arg;
2504 if (add_scrn_saver(scsplash_saver) == 0) {
2505 sc->flags &= ~SC_SAVER_FAILED;
2506 run_scrn_saver = TRUE;
2508 scsplash_stick(TRUE);
2509 (*current_saver)(sc, TRUE);
2515 if (current_saver == scsplash_saver) {
2516 scsplash_stick(FALSE);
2517 error = remove_scrn_saver(scsplash_saver);
2530 scsplash_saver(sc_softc_t *sc, int show)
2532 static int busy = FALSE;
2541 if (!(sc->flags & SC_SAVER_FAILED)) {
2542 if (!(sc->flags & SC_SCRN_BLANKED))
2543 set_scrn_saver_mode(scp, -1, NULL, 0);
2544 switch (splash(sc->adp, TRUE)) {
2545 case 0: /* succeeded */
2547 case EAGAIN: /* try later */
2548 restore_scrn_saver_mode(scp, FALSE);
2549 sc_touch_scrn_saver(); /* XXX */
2552 sc->flags |= SC_SAVER_FAILED;
2553 scsplash_stick(FALSE);
2554 restore_scrn_saver_mode(scp, TRUE);
2555 kprintf("scsplash_saver(): failed to put up the image\n");
2559 } else if (!sticky_splash) {
2560 if ((sc->flags & SC_SCRN_BLANKED) && (splash(sc->adp, FALSE) == 0))
2561 restore_scrn_saver_mode(scp, TRUE);
2567 add_scrn_saver(void (*this_saver)(sc_softc_t *, int))
2572 if (current_saver != none_saver) {
2573 error = remove_scrn_saver(current_saver);
2578 if (current_saver != none_saver) {
2582 run_scrn_saver = FALSE;
2583 saver_mode = CONS_LKM_SAVER;
2584 current_saver = this_saver;
2589 remove_scrn_saver(void (*this_saver)(sc_softc_t *, int))
2591 if (current_saver != this_saver)
2596 * In order to prevent `current_saver' from being called by
2597 * the timeout routine `scrn_timer()' while we manipulate
2598 * the saver list, we shall set `current_saver' to `none_saver'
2599 * before stopping the current saver, rather than blocking by `splXX()'.
2601 current_saver = none_saver;
2603 stop_scrn_saver(this_saver);
2605 /* unblank all blanked screens */
2606 wait_scrn_saver_stop(NULL, FALSE);
2611 current_saver = none_saver;
2616 set_scrn_saver_mode(scr_stat *scp, int mode, u_char *pal, int border)
2619 /* assert(scp == scp->sc->cur_scp) */
2621 if (!ISGRAPHSC(scp))
2622 sc_remove_cursor_image(scp);
2623 scp->splash_save_mode = scp->mode;
2624 scp->splash_save_status = scp->status & (GRAPHICS_MODE | PIXEL_MODE);
2625 scp->status &= ~(GRAPHICS_MODE | PIXEL_MODE);
2626 scp->status |= (UNKNOWN_MODE | SAVER_RUNNING);
2627 scp->sc->flags |= SC_SCRN_BLANKED;
2634 if (set_mode(scp) == 0) {
2635 if (scp->sc->fbi == NULL &&
2636 scp->sc->adp->va_info.vi_flags & V_INFO_GRAPHICS) {
2637 scp->status |= GRAPHICS_MODE;
2639 if (scp->sc->fbi == NULL && pal != NULL)
2640 load_palette(scp->sc->adp, pal);
2641 sc_set_border(scp, border);
2645 scp->mode = scp->splash_save_mode;
2646 scp->status &= ~(UNKNOWN_MODE | SAVER_RUNNING);
2647 scp->status |= scp->splash_save_status;
2655 restore_scrn_saver_mode(scr_stat *scp, int changemode)
2660 /* assert(scp == scp->sc->cur_scp) */
2663 status = scp->status;
2664 scp->mode = scp->splash_save_mode;
2665 scp->status &= ~(UNKNOWN_MODE | SAVER_RUNNING);
2666 scp->status |= scp->splash_save_status;
2667 scp->sc->flags &= ~SC_SCRN_BLANKED;
2669 if (!ISGRAPHSC(scp))
2670 sc_draw_cursor_image(scp);
2675 if (set_mode(scp) == 0) {
2676 if (scp->sc->fbi == NULL)
2677 load_palette(scp->sc->adp, scp->sc->palette);
2683 scp->status = status;
2691 stop_scrn_saver(sc_softc_t *sc, void (*saver)(sc_softc_t *, int))
2693 (*saver)(sc, FALSE);
2694 run_scrn_saver = FALSE;
2695 /* the screen saver may have chosen not to stop after all... */
2696 if (sc->flags & SC_SCRN_BLANKED) {
2700 mark_all(sc->cur_scp);
2701 if (sc->delayed_next_scr)
2702 sc_switch_scr(sc, sc->delayed_next_scr - 1);
2703 wakeup(&scrn_blanked);
2707 wait_scrn_saver_stop(sc_softc_t *sc, int need_unlock)
2711 while (scrn_blanked > 0) {
2712 run_scrn_saver = FALSE;
2713 if (sc && !(sc->flags & SC_SCRN_BLANKED)) {
2718 tsleep_interlock(&scrn_blanked, PCATCH);
2720 error = tsleep(&scrn_blanked, PCATCH | PINTERLOCKED, "scrsav", 0);
2723 error = tsleep(&scrn_blanked, PCATCH, "scrsav", 0);
2725 /* May return ERESTART */
2729 run_scrn_saver = FALSE;
2732 #endif /* NSPLASH */
2735 sc_start_scrn_saver(sc_softc_t *sc)
2738 (*current_saver)(sc, TRUE);
2743 sc_stop_scrn_saver(sc_softc_t *sc)
2746 if (sc->flags & SC_SCRN_BLANKED)
2747 stop_scrn_saver(sc, current_saver);
2752 sc_touch_scrn_saver(void)
2754 scsplash_stick(FALSE);
2755 run_scrn_saver = FALSE;
2759 sc_switch_scr(sc_softc_t *sc, u_int next_scr)
2764 DPRINTF(5, ("sc0: sc_switch_scr() %d ", next_scr + 1));
2766 /* prevent switch if previously requested */
2767 if (sc->flags & SC_SCRN_VTYLOCK) {
2768 sc_bell(sc->cur_scp, sc->cur_scp->bell_pitch,
2769 sc->cur_scp->bell_duration);
2773 /* delay switch if the screen is blanked or being updated */
2774 if ((sc->flags & SC_SCRN_BLANKED) || sc->write_in_progress
2775 || sc->blink_in_progress || sc->videoio_in_progress) {
2776 sc->delayed_next_scr = next_scr + 1;
2777 sc_touch_scrn_saver();
2778 DPRINTF(5, ("switch delayed\n"));
2782 cur_scp = sc->cur_scp;
2785 * we are in the middle of the vty switching process...
2787 * This may be in the console path, be very careful. pfindn() is
2788 * still going to use a spinlock but it no longer uses tokens so
2791 if (sc->switch_in_progress &&
2792 (cur_scp->smode.mode == VT_PROCESS) &&
2794 if (cur_scp->proc != pfindn(cur_scp->pid)) {
2796 * The controlling process has died!!. Do some clean up.
2797 * NOTE:`cur_scp->proc' and `cur_scp->smode.mode'
2798 * are not reset here yet; they will be cleared later.
2800 DPRINTF(5, ("cur_scp controlling process %d died, ", cur_scp->pid));
2801 if (cur_scp->status & SWITCH_WAIT_REL) {
2803 * Force the previous switch to finish, but return now
2807 DPRINTF(5, ("reset WAIT_REL, "));
2808 finish_vt_rel(cur_scp, TRUE);
2809 DPRINTF(5, ("finishing previous switch\n"));
2811 } else if (cur_scp->status & SWITCH_WAIT_ACQ) {
2812 /* let's assume screen switch has been completed. */
2813 DPRINTF(5, ("reset WAIT_ACQ, "));
2814 finish_vt_acq(cur_scp);
2817 * We are in between screen release and acquisition, and
2818 * reached here via scgetc() or scrn_timer() which has
2819 * interrupted exchange_scr(). Don't do anything stupid.
2821 DPRINTF(5, ("waiting nothing, "));
2825 * The controlling process is alive, but not responding...
2826 * It is either buggy or it may be just taking time.
2827 * The following code is a gross kludge to cope with this
2828 * problem for which there is no clean solution. XXX
2830 if (cur_scp->status & SWITCH_WAIT_REL) {
2831 switch (sc->switch_in_progress++) {
2835 DPRINTF(5, ("sending relsig again, "));
2836 signal_vt_rel(cur_scp);
2843 * Act as if the controlling program returned
2847 DPRINTF(5, ("force reset WAIT_REL, "));
2848 finish_vt_rel(cur_scp, FALSE);
2849 DPRINTF(5, ("act as if VT_FALSE was seen\n"));
2852 } else if (cur_scp->status & SWITCH_WAIT_ACQ) {
2853 switch (sc->switch_in_progress++) {
2857 DPRINTF(5, ("sending acqsig again, "));
2858 signal_vt_acq(cur_scp);
2864 /* clear the flag and finish the previous switch */
2865 DPRINTF(5, ("force reset WAIT_ACQ, "));
2866 finish_vt_acq(cur_scp);
2874 * Return error if an invalid argument is given, or vty switch
2875 * is still in progress.
2877 if ((next_scr < sc->first_vty) || (next_scr >= sc->first_vty + sc->vtys)
2878 || sc->switch_in_progress) {
2879 sc_bell(cur_scp, bios_value.bell_pitch, BELL_DURATION);
2880 DPRINTF(5, ("error 1\n"));
2885 * Don't allow switching away from the graphics mode vty
2886 * if the switch mode is VT_AUTO, unless the next vty is the same
2887 * as the current or the current vty has been closed (but showing).
2889 tp = VIRTUAL_TTY(sc, cur_scp->index);
2890 if ((cur_scp->index != next_scr)
2892 && (cur_scp->smode.mode == VT_AUTO)
2893 && ISGRAPHSC(cur_scp)) {
2894 sc_bell(cur_scp, bios_value.bell_pitch, BELL_DURATION);
2895 DPRINTF(5, ("error, graphics mode\n"));
2900 * Is the wanted vty open? Don't allow switching to a closed vty.
2901 * If we are in DDB, don't switch to a vty in the VT_PROCESS mode.
2902 * Note that we always allow the user to switch to the kernel
2903 * console even if it is closed.
2905 if ((sc_console == NULL) || (next_scr != sc_console->index)) {
2906 tp = VIRTUAL_TTY(sc, next_scr);
2907 if (!ISTTYOPEN(tp)) {
2908 sc_bell(cur_scp, bios_value.bell_pitch, BELL_DURATION);
2909 DPRINTF(5, ("error 2, requested vty isn't open!\n"));
2912 if ((debugger > 0) && (SC_STAT(tp->t_dev)->smode.mode == VT_PROCESS)) {
2913 DPRINTF(5, ("error 3, requested vty is in the VT_PROCESS mode\n"));
2918 /* this is the start of vty switching process... */
2919 ++sc->switch_in_progress;
2920 sc->delayed_next_scr = 0;
2921 sc->old_scp = cur_scp;
2922 sc->new_scp = SC_STAT(SC_DEV(sc, next_scr));
2923 if (sc->new_scp == sc->old_scp) {
2924 sc->switch_in_progress = 0;
2925 wakeup((caddr_t)&sc->new_scp->smode);
2926 DPRINTF(5, ("switch done (new == old)\n"));
2930 /* has controlling process died? */
2931 vt_proc_alive(sc->old_scp);
2932 vt_proc_alive(sc->new_scp);
2934 /* wait for the controlling process to release the screen, if necessary */
2935 if (signal_vt_rel(sc->old_scp)) {
2939 /* go set up the new vty screen */
2942 /* wake up processes waiting for this vty */
2943 wakeup((caddr_t)&sc->cur_scp->smode);
2945 /* wait for the controlling process to acknowledge, if necessary */
2946 if (signal_vt_acq(sc->cur_scp)) {
2950 sc->switch_in_progress = 0;
2951 if (sc->unit == sc_console_unit && !sc->fb_blanked)
2952 cons_unavail = FALSE;
2953 DPRINTF(5, ("switch done\n"));
2959 do_switch_scr(sc_softc_t *sc)
2961 lwkt_gettoken(&vga_token);
2962 vt_proc_alive(sc->new_scp);
2965 /* sc->cur_scp == sc->new_scp */
2966 wakeup((caddr_t)&sc->cur_scp->smode);
2968 /* wait for the controlling process to acknowledge, if necessary */
2969 if (!signal_vt_acq(sc->cur_scp)) {
2970 sc->switch_in_progress = 0;
2971 if (sc->unit == sc_console_unit && !sc->fb_blanked)
2972 cons_unavail = FALSE;
2974 lwkt_reltoken(&vga_token);
2978 vt_proc_alive(scr_stat *scp)
2980 lwkt_gettoken(&vga_token);
2982 if (scp->proc == pfindn(scp->pid)) {
2983 lwkt_reltoken(&vga_token);
2987 scp->smode.mode = VT_AUTO;
2988 DPRINTF(5, ("vt controlling process %d died\n", scp->pid));
2990 lwkt_reltoken(&vga_token);
2995 signal_vt_rel(scr_stat *scp)
2999 lwkt_gettoken(&vga_token);
3000 if (scp->smode.mode != VT_PROCESS) {
3001 lwkt_reltoken(&vga_token);
3004 scp->status |= SWITCH_WAIT_REL;
3007 ksignal(p, scp->smode.relsig);
3009 DPRINTF(5, ("sending relsig to %d\n", scp->pid));
3010 lwkt_reltoken(&vga_token);
3016 signal_vt_acq(scr_stat *scp)
3020 lwkt_gettoken(&vga_token);
3021 if (scp->smode.mode != VT_PROCESS) {
3022 lwkt_reltoken(&vga_token);
3025 if (scp->sc->unit == sc_console_unit)
3026 cons_unavail = TRUE;
3027 scp->status |= SWITCH_WAIT_ACQ;
3030 ksignal(p, scp->smode.acqsig);
3032 DPRINTF(5, ("sending acqsig to %d\n", scp->pid));
3033 lwkt_reltoken(&vga_token);
3039 finish_vt_rel(scr_stat *scp, int release)
3041 lwkt_gettoken(&vga_token);
3042 if (scp == scp->sc->old_scp && scp->status & SWITCH_WAIT_REL) {
3043 scp->status &= ~SWITCH_WAIT_REL;
3045 do_switch_scr(scp->sc);
3047 scp->sc->switch_in_progress = 0;
3048 lwkt_reltoken(&vga_token);
3051 lwkt_reltoken(&vga_token);
3056 finish_vt_acq(scr_stat *scp)
3058 lwkt_gettoken(&vga_token);
3059 if (scp == scp->sc->new_scp && scp->status & SWITCH_WAIT_ACQ) {
3060 scp->status &= ~SWITCH_WAIT_ACQ;
3061 scp->sc->switch_in_progress = 0;
3062 lwkt_reltoken(&vga_token);
3065 lwkt_reltoken(&vga_token);
3070 exchange_scr(sc_softc_t *sc)
3074 lwkt_gettoken(&vga_token);
3075 /* save the current state of video and keyboard */
3076 sc_move_cursor(sc->old_scp, sc->old_scp->xpos, sc->old_scp->ypos);
3077 if (!ISGRAPHSC(sc->old_scp))
3078 sc_remove_cursor_image(sc->old_scp);
3079 if (sc->old_scp->kbd_mode == K_XLATE)
3080 save_kbd_state(sc->old_scp, TRUE);
3082 /* set up the video for the new screen */
3083 scp = sc->cur_scp = sc->new_scp;
3084 if (sc->old_scp->mode != scp->mode || ISUNKNOWNSC(sc->old_scp))
3086 else if (sc->adp != NULL)
3087 sc_vtb_init(&scp->scr, VTB_FRAMEBUFFER, scp->xsize, scp->ysize,
3088 (void *)sc->adp->va_window, FALSE);
3089 scp->status |= MOUSE_HIDDEN;
3090 sc_update_render(scp); /* Switch to kms renderer if necessary */
3091 sc_move_cursor(scp, scp->xpos, scp->ypos);
3092 if (!ISGRAPHSC(scp))
3093 sc_set_cursor_image(scp);
3094 if (sc->fbi == NULL && ISGRAPHSC(sc->old_scp))
3095 load_palette(sc->adp, sc->palette);
3096 if (!ISGRAPHSC(scp) || sc->fbi == NULL)
3097 sc_set_border(scp, scp->border);
3099 /* set up the keyboard for the new screen */
3100 if (sc->old_scp->kbd_mode != scp->kbd_mode)
3101 kbd_ioctl(sc->kbd, KDSKBMODE, (caddr_t)&scp->kbd_mode);
3102 update_kbd_state(scp, scp->status, LOCK_MASK, TRUE);
3107 * Restore DRM framebuffer console mode if necessary.
3108 * Especially avoid modesetting when switching to a vt which is in
3109 * graphics mode, because the fb_set_par() from the taskqueue thread
3110 * might race with the modesetting ioctl from the userland application.
3112 if (!ISTEXTSC(sc->old_scp) &&
3113 sc->fbi != NULL && sc->fbi->fbops.fb_set_par != NULL &&
3114 sc->fb_set_par_task != NULL) {
3115 taskqueue_enqueue(taskqueue_thread[0], sc->fb_set_par_task);
3118 lwkt_reltoken(&vga_token);
3122 sc_puts(scr_stat *scp, u_char *buf, int len)
3125 /* make screensaver happy */
3126 if (!sticky_splash && scp == scp->sc->cur_scp)
3127 run_scrn_saver = FALSE;
3131 (*scp->tsw->te_puts)(scp, buf, len);
3133 if (scp->sc->delayed_next_scr)
3134 sc_switch_scr(scp->sc, scp->sc->delayed_next_scr - 1);
3139 sc_draw_cursor_image(scr_stat *scp)
3141 /* assert(scp == scp->sc->cur_scp); */
3142 atomic_add_int(&scp->sc->videoio_in_progress, 1);
3143 (*scp->rndr->draw_cursor)(scp, scp->cursor_pos,
3144 scp->sc->flags & SC_BLINK_CURSOR, TRUE,
3145 sc_inside_cutmark(scp, scp->cursor_pos));
3146 scp->cursor_oldpos = scp->cursor_pos;
3147 atomic_add_int(&scp->sc->videoio_in_progress, -1);
3151 sc_remove_cursor_image(scr_stat *scp)
3153 /* assert(scp == scp->sc->cur_scp); */
3154 atomic_add_int(&scp->sc->videoio_in_progress, 1);
3155 (*scp->rndr->draw_cursor)(scp, scp->cursor_oldpos,
3156 scp->sc->flags & SC_BLINK_CURSOR, FALSE,
3157 sc_inside_cutmark(scp, scp->cursor_oldpos));
3158 atomic_add_int(&scp->sc->videoio_in_progress, -1);
3162 update_cursor_image(scr_stat *scp)
3166 if (scp->sc->flags & SC_CHAR_CURSOR) {
3167 scp->cursor_base = imax(0, scp->sc->cursor_base);
3168 scp->cursor_height = imin(scp->sc->cursor_height, scp->font_height);
3170 scp->cursor_base = 0;
3171 scp->cursor_height = scp->font_height;
3173 blink = scp->sc->flags & SC_BLINK_CURSOR;
3175 /* assert(scp == scp->sc->cur_scp); */
3176 atomic_add_int(&scp->sc->videoio_in_progress, 1);
3177 (*scp->rndr->draw_cursor)(scp, scp->cursor_oldpos, blink, FALSE,
3178 sc_inside_cutmark(scp, scp->cursor_pos));
3179 (*scp->rndr->set_cursor)(scp, scp->cursor_base, scp->cursor_height, blink);
3180 (*scp->rndr->draw_cursor)(scp, scp->cursor_pos, blink, TRUE,
3181 sc_inside_cutmark(scp, scp->cursor_pos));
3182 atomic_add_int(&scp->sc->videoio_in_progress, -1);
3186 sc_set_cursor_image(scr_stat *scp)
3188 if (scp->sc->flags & SC_CHAR_CURSOR) {
3189 scp->cursor_base = imax(0, scp->sc->cursor_base);
3190 scp->cursor_height = imin(scp->sc->cursor_height, scp->font_height);
3192 scp->cursor_base = 0;
3193 scp->cursor_height = scp->font_height;
3196 /* assert(scp == scp->sc->cur_scp); */
3197 atomic_add_int(&scp->sc->videoio_in_progress, 1);
3198 (*scp->rndr->set_cursor)(scp, scp->cursor_base, scp->cursor_height,
3199 scp->sc->flags & SC_BLINK_CURSOR);
3200 atomic_add_int(&scp->sc->videoio_in_progress, -1);
3204 scinit(int unit, int flags)
3207 * When syscons is being initialized as the kernel console, malloc()
3208 * is not yet functional, because various kernel structures has not been
3209 * fully initialized yet. Therefore, we need to declare the following
3210 * static buffers for the console. This is less than ideal,
3211 * but is necessry evil for the time being. XXX
3213 static scr_stat main_console;
3214 static u_short sc_buffer[2*ROW*2*COL]; /* XXX */
3215 #ifndef SC_NO_FONT_LOADING
3216 static u_char font_8[256*8];
3217 static u_char font_14[256*14];
3218 static u_char font_16[256*16];
3223 video_adapter_t *adp;
3224 char tbuf[MAKEDEV_MINNBUF];
3229 /* one time initialization */
3230 if (init_done == COLD)
3231 sc_get_bios_values(&bios_value);
3235 * Allocate resources. Even if we are being called for the second
3236 * time, we must allocate them again, because they might have
3239 sc = sc_get_softc(unit, flags & SC_KERNEL_CONSOLE);
3241 if (flags & SC_EFI_FB) {
3242 /* Don't replace already registered drm framebuffer here */
3243 if (sc->fbi == NULL) {
3244 sc->fbi = &efi_fb_info;
3245 sc->fbi_generation++;
3247 } else if (sc->adapter >= 0) {
3248 vid_release(sc->adp, (void *)&sc->adapter);
3252 if (sc->keyboard >= 0) {
3253 DPRINTF(5, ("sc%d: releasing kbd%d\n", unit, sc->keyboard));
3254 i = kbd_release(sc->kbd, (void *)&sc->keyboard);
3255 DPRINTF(5, ("sc%d: kbd_release returned %d\n", unit, i));
3256 if (sc->kbd != NULL) {
3257 DPRINTF(5, ("sc%d: kbd != NULL!, index:%d, unit:%d, flags:0x%x\n",
3258 unit, sc->kbd->kb_index, sc->kbd->kb_unit, sc->kbd->kb_flags));
3262 if (!(flags & SC_EFI_FB)) {
3263 sc->adapter = vid_allocate("*", unit, (void *)&sc->adapter);
3264 sc->adp = vid_get_adapter(sc->adapter);
3265 /* assert((sc->adapter >= 0) && (sc->adp != NULL)) */
3267 sc->keyboard = sc_allocate_keyboard(sc, unit);
3268 DPRINTF(1, ("sc%d: keyboard %d\n", unit, sc->keyboard));
3269 sc->kbd = kbd_get_keyboard(sc->keyboard);
3270 if (sc->kbd != NULL) {
3271 DPRINTF(1, ("sc%d: kbd index:%d, unit:%d, flags:0x%x\n",
3272 unit, sc->kbd->kb_index, sc->kbd->kb_unit, sc->kbd->kb_flags));
3275 if (!(sc->flags & SC_INIT_DONE) || (adp != sc->adp)) {
3277 if (sc->fbi != NULL)
3278 sc->initial_mode = 0;
3280 sc->initial_mode = sc->adp->va_initial_mode;
3282 #ifndef SC_NO_FONT_LOADING
3283 if (flags & SC_KERNEL_CONSOLE) {
3284 sc->font_8 = font_8;
3285 sc->font_14 = font_14;
3286 sc->font_16 = font_16;
3287 } else if (sc->font_8 == NULL) {
3288 /* assert(sc_malloc) */
3289 sc->font_8 = kmalloc(sizeof(font_8), M_SYSCONS, M_WAITOK);
3290 sc->font_14 = kmalloc(sizeof(font_14), M_SYSCONS, M_WAITOK);
3291 sc->font_16 = kmalloc(sizeof(font_16), M_SYSCONS, M_WAITOK);
3295 if (sc->fbi != NULL) {
3299 lwkt_gettoken(&vga_token);
3300 /* extract the hw cursor location and hide the cursor for now */
3301 (*vidsw[sc->adapter]->read_hw_cursor)(sc->adp, &col, &row);
3302 (*vidsw[sc->adapter]->set_hw_cursor)(sc->adp, -1, -1);
3303 lwkt_reltoken(&vga_token);
3306 /* set up the first console */
3307 sc->first_vty = unit*MAXCONS;
3308 sc->vtys = MAXCONS; /* XXX: should be configurable */
3309 if (flags & SC_KERNEL_CONSOLE) {
3310 scp = &main_console;
3311 sc->console_scp = scp;
3312 init_scp(sc, sc->first_vty, scp);
3313 sc_vtb_init(&scp->vtb, VTB_MEMORY, scp->xsize, scp->ysize,
3314 (void *)sc_buffer, FALSE);
3315 if (sc_init_emulator(scp, SC_DFLT_TERM))
3316 sc_init_emulator(scp, "*");
3317 (*scp->tsw->te_default_attr)(scp,
3318 kernel_default.std_color,
3319 kernel_default.rev_color);
3321 /* assert(sc_malloc) */
3322 sc->dev = kmalloc(sizeof(cdev_t)*sc->vtys, M_SYSCONS, M_WAITOK | M_ZERO);
3324 sc->dev[0] = make_dev(&sc_ops, unit*MAXCONS, UID_ROOT,
3325 GID_WHEEL, 0600, "ttyv%s",
3326 makedev_unit_b32(tbuf, unit * MAXCONS));
3328 ttymalloc(&sc->dev[0]->si_tty);
3329 scp = alloc_scp(sc, sc->first_vty);
3330 sc->dev[0]->si_drv1 = scp;
3334 /* copy screen to temporary buffer */
3335 if (scp->sc->fbi == NULL) {
3336 sc_vtb_init(&scp->scr, VTB_FRAMEBUFFER, scp->xsize, scp->ysize,
3337 (void *)scp->sc->adp->va_window, FALSE);
3339 sc_vtb_copy(&scp->scr, 0, &scp->vtb, 0, scp->xsize*scp->ysize);
3342 /* move cursors to the initial positions */
3343 if (col >= scp->xsize)
3345 if (row >= scp->ysize)
3346 row = scp->ysize - 1;
3349 if (sc->fbi != NULL) {
3350 scp->cursor_pos = 0;
3351 sc->cursor_base = 0;
3352 sc->cursor_height = scp->font_height;
3354 scp->cursor_pos = scp->cursor_oldpos = row*scp->xsize + col;
3355 if (bios_value.cursor_end < scp->font_height)
3356 sc->cursor_base = scp->font_height - bios_value.cursor_end - 1;
3358 sc->cursor_base = 0;
3359 i = bios_value.cursor_end - bios_value.cursor_start + 1;
3360 sc->cursor_height = imin(i, scp->font_height);
3362 #ifndef SC_NO_SYSMOUSE
3363 sc_mouse_move(scp, scp->xpixel/2, scp->ypixel/2);
3365 if (!ISGRAPHSC(scp)) {
3366 sc_set_cursor_image(scp);
3367 sc_draw_cursor_image(scp);
3368 /* If framebuffer vaddr is still 0, we can't draw the border yet */
3369 if (scp->sc->fbi != NULL && scp->sc->fbi->vaddr != 0) {
3370 sc_filled_border = TRUE;
3371 sc_set_border(scp, scp->border);
3375 /* save font and palette */
3376 #ifndef SC_NO_FONT_LOADING
3377 sc->fonts_loaded = 0;
3379 bcopy(dflt_font_8, sc->font_8, sizeof(dflt_font_8));
3380 bcopy(dflt_font_14, sc->font_14, sizeof(dflt_font_14));
3381 bcopy(dflt_font_16, sc->font_16, sizeof(dflt_font_16));
3382 sc->fonts_loaded = FONT_16 | FONT_14 | FONT_8;
3383 #endif /* SC_DFLT_FONT */
3384 if (sc->adp != NULL && ISFONTAVAIL(sc->adp->va_flags)) {
3386 if (scp->font_height < 14) {
3387 sc_load_font(scp, 0, 8, sc->font_8, 0, 256);
3388 } else if (scp->font_height >= 16) {
3389 sc_load_font(scp, 0, 16, sc->font_16, 0, 256);
3391 sc_load_font(scp, 0, 14, sc->font_14, 0, 256);
3393 #else /* !SC_DFLT_FONT */
3394 if (scp->font_height < 14) {
3395 sc_save_font(scp, 0, 8, sc->font_8, 0, 256);
3396 sc->fonts_loaded = FONT_8;
3397 } else if (scp->font_height >= 16) {
3398 sc_save_font(scp, 0, 16, sc->font_16, 0, 256);
3399 sc->fonts_loaded = FONT_16;
3401 sc_save_font(scp, 0, 14, sc->font_14, 0, 256);
3402 sc->fonts_loaded = FONT_14;
3404 #endif /* SC_DFLT_FONT */
3405 /* FONT KLUDGE: always use the font page #0. XXX */
3406 sc_show_font(scp, 0);
3408 #endif /* !SC_NO_FONT_LOADING */
3410 if (!(flags & SC_EFI_FB))
3411 save_palette(sc->adp, sc->palette);
3414 if (!(sc->flags & SC_SPLASH_SCRN) && (flags & SC_KERNEL_CONSOLE)) {
3415 /* we are ready to put up the splash image! */
3416 splash_init(sc->adp, scsplash_callback, sc);
3417 sc->flags |= SC_SPLASH_SCRN;
3419 #endif /* NSPLASH */
3422 /* the rest is not necessary, if we have done it once */
3423 if (sc->flags & SC_INIT_DONE) {
3427 /* initialize mapscrn arrays to a one to one map */
3428 for (i = 0; i < sizeof(sc->scr_map); i++)
3429 sc->scr_map[i] = sc->scr_rmap[i] = i;
3431 sc->flags |= SC_INIT_DONE;
3436 scterm(int unit, int flags)
3441 sc = sc_get_softc(unit, flags & SC_KERNEL_CONSOLE);
3443 return; /* shouldn't happen */
3445 lwkt_gettoken(&vga_token);
3447 /* this console is no longer available for the splash screen */
3448 if (sc->flags & SC_SPLASH_SCRN) {
3449 splash_term(sc->adp);
3450 sc->flags &= ~SC_SPLASH_SCRN;
3452 #endif /* NSPLASH */
3455 /* move the hardware cursor to the upper-left corner */
3456 (*vidsw[sc->adapter]->set_hw_cursor)(sc->adp, 0, 0);
3459 /* release the keyboard and the video card */
3460 if (sc->keyboard >= 0)
3461 kbd_release(sc->kbd, &sc->keyboard);
3462 if (sc->adapter >= 0)
3463 vid_release(sc->adp, &sc->adapter);
3466 * Stop the terminal emulator, if any. If operating on the
3467 * kernel console sc->dev may not be setup yet.
3469 if (flags & SC_KERNEL_CONSOLE)
3470 scp = sc->console_scp;
3472 scp = SC_STAT(sc->dev[0]);
3474 (*scp->tsw->te_term)(scp, &scp->ts);
3475 if (scp->ts != NULL)
3476 kfree(scp->ts, M_SYSCONS);
3478 /* clear the structure */
3479 if (!(flags & SC_KERNEL_CONSOLE)) {
3480 /* XXX: We need delete_dev() for this */
3481 kfree(sc->dev, M_SYSCONS);
3483 /* XXX: We need a ttyunregister for this */
3484 /* XXX: do not race tty token access */
3485 kfree(sc->tty, M_SYSCONS);
3487 #ifndef SC_NO_FONT_LOADING
3488 kfree(sc->font_8, M_SYSCONS);
3489 kfree(sc->font_14, M_SYSCONS);
3490 kfree(sc->font_16, M_SYSCONS);
3492 /* XXX vtb, history */
3494 bzero(sc, sizeof(*sc));
3497 lwkt_reltoken(&vga_token);
3502 scshutdown(void *arg, int howto)
3504 /* assert(sc_console != NULL) */
3506 lwkt_gettoken(&vga_token);
3508 sc_touch_scrn_saver();
3509 if (!cold && sc_console
3510 && sc_console->sc->cur_scp->smode.mode == VT_AUTO
3511 && sc_console->smode.mode == VT_AUTO) {
3512 sc_switch_scr(sc_console->sc, sc_console->index);
3514 shutdown_in_progress = TRUE;
3516 lwkt_reltoken(&vga_token);
3520 sc_clean_up(scr_stat *scp, int need_unlock)
3524 #endif /* NSPLASH */
3526 lwkt_gettoken(&vga_token);
3527 if (scp->sc->flags & SC_SCRN_BLANKED) {
3528 sc_touch_scrn_saver();
3530 if ((error = wait_scrn_saver_stop(scp->sc, need_unlock))) {
3531 lwkt_reltoken(&vga_token);
3534 #endif /* NSPLASH */
3536 scp->status |= MOUSE_HIDDEN;
3537 sc_remove_mouse_image(scp);
3538 sc_remove_cutmarking(scp);
3539 lwkt_reltoken(&vga_token);
3544 sc_alloc_scr_buffer(scr_stat *scp, int wait, int discard)
3549 lwkt_gettoken(&vga_token);
3551 sc_vtb_init(&new, VTB_MEMORY, scp->xsize, scp->ysize, NULL, wait);
3552 if (!discard && (old.vtb_flags & VTB_VALID)) {
3553 /* retain the current cursor position and buffer contants */
3554 scp->cursor_oldpos = scp->cursor_pos;
3556 * This works only if the old buffer has the same size as or larger
3557 * than the new one. XXX
3559 sc_vtb_copy(&old, 0, &new, 0, scp->xsize*scp->ysize);
3563 sc_vtb_destroy(&old);
3566 #ifndef SC_NO_SYSMOUSE
3567 /* move the mouse cursor at the center of the screen */
3568 sc_mouse_move(scp, scp->xpixel / 2, scp->ypixel / 2);
3570 lwkt_reltoken(&vga_token);
3574 alloc_scp(sc_softc_t *sc, int vty)
3578 /* assert(sc_malloc) */
3580 scp = kmalloc(sizeof(scr_stat), M_SYSCONS, M_WAITOK);
3581 init_scp(sc, vty, scp);
3583 sc_alloc_scr_buffer(scp, TRUE, TRUE);
3584 if (sc_init_emulator(scp, SC_DFLT_TERM))
3585 sc_init_emulator(scp, "*");
3587 #ifndef SC_NO_CUTPASTE
3588 sc_alloc_cut_buffer(scp, TRUE);
3591 #ifndef SC_NO_HISTORY
3592 sc_alloc_history_buffer(scp, 0, 0, TRUE);
3598 * NOTE: Must be called with vga_token held.
3601 init_scp(sc_softc_t *sc, int vty, scr_stat *scp)
3605 bzero(scp, sizeof(*scp));
3610 scp->mode = sc->initial_mode;
3611 scp->fbi_generation = sc->fbi_generation;
3612 callout_init_lk(&scp->blink_screen_ch, &syscons_blink_lk);
3613 if (scp->sc->fbi == NULL) {
3614 lwkt_gettoken(&vga_token);
3615 (*vidsw[sc->adapter]->get_info)(sc->adp, scp->mode, &info);
3616 lwkt_reltoken(&vga_token);
3618 if (scp->sc->fbi != NULL) {
3619 scp->xpixel = sc->fbi->width;
3620 scp->ypixel = sc->fbi->height;
3621 scp->font_width = 8;
3622 scp->font_height = 16;
3624 /* The first vty uses a statically allocated 160x50 buffer */
3625 if (vty == sc->first_vty)
3626 sc_font_scale(scp, 2*COL, 2*ROW);
3628 sc_font_scale(scp, 0, 0);
3630 #ifndef SC_NO_FONT_LOADING
3631 scp->font = sc->font_16;
3635 } else if (info.vi_flags & V_INFO_GRAPHICS) {
3636 scp->status |= GRAPHICS_MODE;
3637 scp->xpixel = info.vi_width;
3638 scp->ypixel = info.vi_height;
3639 scp->xsize = info.vi_width/8;
3640 scp->ysize = info.vi_height/info.vi_cheight;
3641 scp->font_height = 0;
3642 scp->font_width = 0;
3645 scp->xsize = info.vi_width;
3646 scp->ysize = info.vi_height;
3647 scp->xpixel = scp->xsize*8;
3648 scp->ypixel = scp->ysize*info.vi_cheight;
3649 scp->font_width = 8;
3650 if (info.vi_cheight < 14) {
3651 scp->font_height = 8;
3652 #ifndef SC_NO_FONT_LOADING
3653 scp->font = sc->font_8;
3657 } else if (info.vi_cheight >= 16) {
3658 scp->font_height = 16;
3659 #ifndef SC_NO_FONT_LOADING
3660 scp->font = sc->font_16;
3665 scp->font_height = 14;
3666 #ifndef SC_NO_FONT_LOADING
3667 scp->font = sc->font_14;
3673 scp->xoff = scp->yoff = 0;
3674 scp->xpos = scp->ypos = 0;
3675 sc_vtb_init(&scp->vtb, VTB_MEMORY, 0, 0, NULL, FALSE);
3676 sc_vtb_init(&scp->scr, VTB_FRAMEBUFFER, 0, 0, NULL, FALSE);
3677 scp->start = scp->xsize * scp->ysize - 1;
3682 scp->border = SC_BORDER_COLOR;
3683 scp->cursor_base = sc->cursor_base;
3684 scp->cursor_height = imin(sc->cursor_height, scp->font_height);
3685 scp->mouse_cut_start = scp->xsize * scp->ysize;
3686 scp->mouse_cut_end = -1;
3687 scp->mouse_signal = 0;
3689 scp->mouse_proc = NULL;
3690 scp->kbd_mode = K_XLATE;
3691 scp->bell_pitch = bios_value.bell_pitch;
3692 scp->bell_duration = BELL_DURATION;
3693 scp->status |= (bios_value.shift_state & NLKED);
3694 scp->status |= CURSOR_ENABLED | MOUSE_HIDDEN;
3697 scp->smode.mode = VT_AUTO;
3698 scp->history = NULL;
3699 scp->history_pos = 0;
3700 scp->history_size = 0;
3704 sc_init_emulator(scr_stat *scp, char *name)
3711 if (name == NULL) /* if no name is given, use the current emulator */
3713 else /* ...otherwise find the named emulator */
3714 sw = sc_term_match(name);
3720 if (strcmp(sw->te_renderer, "*") != 0) {
3721 rndr = sc_render_match(scp, sw->te_renderer, scp->model);
3723 if (rndr == NULL && scp->sc->fbi != NULL) {
3724 rndr = sc_render_match(scp, "kms", scp->model);
3727 rndr = sc_render_match(scp, scp->sc->adp->va_name, scp->model);
3733 if (sw == scp->tsw) {
3734 error = (*sw->te_init)(scp, &scp->ts, SC_TE_WARM_INIT);
3736 sc_clear_screen(scp);
3737 /* assert(error == 0); */
3741 if (sc_malloc && (sw->te_size > 0))
3742 p = kmalloc(sw->te_size, M_SYSCONS, M_NOWAIT);
3745 error = (*sw->te_init)(scp, &p, SC_TE_COLD_INIT);
3751 (*scp->tsw->te_term)(scp, &scp->ts);
3752 if (scp->ts != NULL)
3753 kfree(scp->ts, M_SYSCONS);
3759 (*sw->te_default_attr)(scp, user_default.std_color, user_default.rev_color);
3760 sc_clear_screen(scp);
3766 * scgetc(flags) - get character from keyboard.
3767 * If flags & SCGETC_CN, then avoid harmful side effects.
3768 * If flags & SCGETC_NONBLOCK, then wait until a key is pressed, else
3769 * return NOKEY if there is nothing there.
3772 scgetc(sc_softc_t *sc, u_int flags)
3775 #ifndef SC_NO_HISTORY
3783 lwkt_gettoken(&vga_token);
3784 if (sc->kbd == NULL) {
3785 lwkt_reltoken(&vga_token);
3791 /* I don't like this, but... XXX */
3792 if (flags & SCGETC_CN) {
3794 sccnupdate(sc->cur_scp);
3799 /* first see if there is something in the keyboard port */
3801 c = kbd_read_char(sc->kbd, !(flags & SCGETC_NONBLOCK));
3803 if (!(flags & SCGETC_CN))
3804 sc_bell(scp, bios_value.bell_pitch, BELL_DURATION);
3805 } else if (c == NOKEY) {
3806 lwkt_reltoken(&vga_token);
3813 /* make screensaver happy */
3815 sc_touch_scrn_saver();
3817 if (!(flags & SCGETC_CN))
3818 /* do the /dev/random device a favour */
3819 add_keyboard_randomness(c);
3821 if (scp->kbd_mode != K_XLATE) {
3822 lwkt_reltoken(&vga_token);
3826 /* if scroll-lock pressed allow history browsing */
3827 if (!ISGRAPHSC(scp) && scp->history && scp->status & SLKED) {
3829 scp->status &= ~CURSOR_ENABLED;
3830 sc_remove_cursor_image(scp);
3832 #ifndef SC_NO_HISTORY
3833 if (!(scp->status & BUFFER_SAVED)) {
3834 scp->status |= BUFFER_SAVED;
3838 /* FIXME: key codes */
3839 case SPCLKEY | FKEY | F(49): /* home key */
3840 sc_remove_cutmarking(scp);
3844 case SPCLKEY | FKEY | F(57): /* end key */
3845 sc_remove_cutmarking(scp);
3849 case SPCLKEY | FKEY | F(50): /* up arrow key */
3850 sc_remove_cutmarking(scp);
3851 if (sc_hist_up_line(scp))
3852 if (!(flags & SCGETC_CN))
3853 sc_bell(scp, bios_value.bell_pitch, BELL_DURATION);
3856 case SPCLKEY | FKEY | F(58): /* down arrow key */
3857 sc_remove_cutmarking(scp);
3858 if (sc_hist_down_line(scp))
3859 if (!(flags & SCGETC_CN))
3860 sc_bell(scp, bios_value.bell_pitch, BELL_DURATION);
3863 case SPCLKEY | FKEY | F(51): /* page up key */
3864 sc_remove_cutmarking(scp);
3865 for (i=0; i<scp->ysize; i++) {
3866 if (sc_hist_up_line(scp)) {
3867 if (!(flags & SCGETC_CN))
3868 sc_bell(scp, bios_value.bell_pitch, BELL_DURATION);
3874 case SPCLKEY | FKEY | F(59): /* page down key */
3875 sc_remove_cutmarking(scp);
3876 for (i=0; i<scp->ysize; i++) {
3877 if (sc_hist_down_line(scp)) {
3878 if (!(flags & SCGETC_CN))
3879 sc_bell(scp, bios_value.bell_pitch, BELL_DURATION);
3885 #endif /* SC_NO_HISTORY */
3889 * Process and consume special keys here. Return a plain char code
3890 * or a char code with the META flag or a function key code.
3894 /* goto next_code */
3899 switch (KEYCHAR(c)) {
3901 case NLK: case CLK: case ALK:
3904 kbd_ioctl(sc->kbd, KDGKBSTATE, (caddr_t)&f);
3906 scp->status |= SLKED;
3908 if (scp->status & SLKED) {
3909 scp->status &= ~SLKED;
3910 #ifndef SC_NO_HISTORY
3911 if (scp->status & BUFFER_SAVED) {
3912 if (!sc_hist_restore(scp))
3913 sc_remove_cutmarking(scp);
3914 scp->status &= ~BUFFER_SAVED;
3915 scp->status |= CURSOR_ENABLED;
3916 sc_draw_cursor_image(scp);
3918 tp = VIRTUAL_TTY(sc, scp->index);
3926 /* NON-LOCKING KEYS */
3928 case LSH: case RSH: case LCTR: case RCTR:
3929 case LALT: case RALT: case ASH: case META:
3933 if (!(sc->flags & SC_SCRN_BLANKED)) {
3934 lwkt_reltoken(&vga_token);
3941 /* force activatation/deactivation of the screen saver */
3942 if (!(sc->flags & SC_SCRN_BLANKED)) {
3943 run_scrn_saver = TRUE;
3944 sc->scrn_time_stamp -= scrn_blank_time;
3948 * While devices are being probed, the screen saver need
3949 * to be invoked explictly. XXX
3951 if (sc->flags & SC_SCRN_BLANKED) {
3952 scsplash_stick(FALSE);
3953 stop_scrn_saver(sc, current_saver);
3955 if (!ISGRAPHSC(scp)) {
3956 scsplash_stick(TRUE);
3957 (*current_saver)(sc, TRUE);
3961 #endif /* NSPLASH */
3965 #ifndef SC_DISABLE_REBOOT
3971 #ifndef SC_DISABLE_REBOOT
3972 shutdown_nice(RB_HALT);
3977 #ifndef SC_DISABLE_REBOOT
3978 shutdown_nice(RB_HALT|RB_POWEROFF);
3987 #ifndef SC_DISABLE_DDBKEY
3989 lwkt_reltoken(&vga_token);
3990 Debugger("manual escape to debugger");
3991 lwkt_gettoken(&vga_token);
3993 kprintf("No debugger in kernel\n");
3995 #else /* SC_DISABLE_DDBKEY */
3997 #endif /* SC_DISABLE_DDBKEY */
4001 if (enable_panic_key)
4002 panic("Forced by the panic key");
4006 this_scr = scp->index;
4007 for (i = (this_scr - sc->first_vty + 1)%sc->vtys;
4008 sc->first_vty + i != this_scr;
4009 i = (i + 1)%sc->vtys) {
4010 struct tty *tp = VIRTUAL_TTY(sc, sc->first_vty + i);
4011 if (ISTTYOPEN(tp)) {
4013 sc_switch_scr(scp->sc, sc->first_vty + i);
4021 this_scr = scp->index;
4022 for (i = (this_scr - sc->first_vty + sc->vtys - 1)%sc->vtys;
4023 sc->first_vty + i != this_scr;
4024 i = (i + sc->vtys - 1)%sc->vtys) {
4025 struct tty *tp = VIRTUAL_TTY(sc, sc->first_vty + i);
4026 if (ISTTYOPEN(tp)) {
4028 sc_switch_scr(scp->sc, sc->first_vty + i);
4036 if (KEYCHAR(c) >= F_SCR && KEYCHAR(c) <= L_SCR) {
4038 sc_switch_scr(scp->sc, sc->first_vty + KEYCHAR(c) - F_SCR);
4042 /* assert(c & FKEY) */
4043 if (!(sc->flags & SC_SCRN_BLANKED)) {
4044 lwkt_reltoken(&vga_token);
4049 /* goto next_code */
4051 /* regular keys (maybe MKEY is set) */
4052 if (!(sc->flags & SC_SCRN_BLANKED)) {
4053 lwkt_reltoken(&vga_token);
4063 scmmap(struct dev_mmap_args *ap)
4067 lwkt_gettoken(&vga_token);
4068 scp = SC_STAT(ap->a_head.a_dev);
4069 if (scp != scp->sc->cur_scp) {
4070 lwkt_reltoken(&vga_token);
4073 if (scp->sc->fbi != NULL) {
4075 roundup(scp->sc->fbi->height * scp->sc->fbi->stride, PAGE_SIZE);
4076 if (ap->a_offset > sz - PAGE_SIZE) {
4077 lwkt_reltoken(&vga_token);
4080 ap->a_result = atop(scp->sc->fbi->paddr + ap->a_offset);
4083 ap->a_result = (*vidsw[scp->sc->adapter]->mmap)(scp->sc->adp,
4087 lwkt_reltoken(&vga_token);
4092 save_kbd_state(scr_stat *scp, int unlock)
4097 WANT_UNLOCK(unlock);
4098 error = kbd_ioctl(scp->sc->kbd, KDGKBSTATE, (caddr_t)&state);
4101 if (error == ENOIOCTL)
4104 scp->status &= ~LOCK_MASK;
4105 scp->status |= state;
4111 update_kbd_state(scr_stat *scp, int new_bits, int mask, int unlock)
4116 if (mask != LOCK_MASK) {
4117 WANT_UNLOCK(unlock);
4118 error = kbd_ioctl(scp->sc->kbd, KDGKBSTATE, (caddr_t)&state);
4121 if (error == ENOIOCTL)
4127 state |= new_bits & mask;
4129 state = new_bits & LOCK_MASK;
4131 WANT_UNLOCK(unlock);
4132 error = kbd_ioctl(scp->sc->kbd, KDSKBSTATE, (caddr_t)&state);
4134 if (error == ENOIOCTL)
4140 update_kbd_leds(scr_stat *scp, int which)
4145 error = kbd_ioctl(scp->sc->kbd, KDSETLED, (caddr_t)&which);
4146 if (error == ENOIOCTL)
4152 set_mode(scr_stat *scp)
4156 lwkt_gettoken(&vga_token);
4157 /* reject unsupported mode */
4158 if (scp->sc->fbi == NULL && (*vidsw[scp->sc->adapter]->get_info)(scp->sc->adp, scp->mode, &info)) {
4159 lwkt_reltoken(&vga_token);
4163 /* if this vty is not currently showing, do nothing */
4164 if (scp != scp->sc->cur_scp) {
4165 lwkt_reltoken(&vga_token);
4169 /* setup video hardware for the given mode */
4170 if (scp->sc->fbi == NULL) {
4171 (*vidsw[scp->sc->adapter]->set_mode)(scp->sc->adp, scp->mode);
4172 sc_vtb_init(&scp->scr, VTB_FRAMEBUFFER, scp->xsize, scp->ysize,
4173 (void *)scp->sc->adp->va_window, FALSE);
4178 #ifndef SC_NO_FONT_LOADING
4179 /* load appropriate font */
4180 if (!(scp->status & GRAPHICS_MODE)) {
4181 if (!(scp->status & PIXEL_MODE) && ISFONTAVAIL(scp->sc->adp->va_flags)) {
4182 if (scp->font_height < 14) {
4183 if (scp->sc->fonts_loaded & FONT_8)
4184 sc_load_font(scp, 0, 8, scp->sc->font_8, 0, 256);
4185 } else if (scp->font_height >= 16) {
4186 if (scp->sc->fonts_loaded & FONT_16)
4187 sc_load_font(scp, 0, 16, scp->sc->font_16, 0, 256);
4189 if (scp->sc->fonts_loaded & FONT_14)
4190 sc_load_font(scp, 0, 14, scp->sc->font_14, 0, 256);
4194 * This is an interim kludge to display correct font.
4195 * Always use the font page #0 on the video plane 2.
4196 * Somehow we cannot show the font in other font pages on
4197 * some video cards... XXX
4199 sc_show_font(scp, 0);
4203 #endif /* !SC_NO_FONT_LOADING */
4205 sc_set_border(scp, scp->border);
4206 sc_set_cursor_image(scp);
4209 lwkt_reltoken(&vga_token);
4214 refresh_ega_palette(scr_stat *scp)
4218 int rsize, gsize, bsize;
4219 int rfld, gfld, bfld;
4222 rsize = scp->sc->adp->va_info.vi_pixel_fsizes[0];
4223 gsize = scp->sc->adp->va_info.vi_pixel_fsizes[1];
4224 bsize = scp->sc->adp->va_info.vi_pixel_fsizes[2];
4225 rfld = scp->sc->adp->va_info.vi_pixel_fields[0];
4226 gfld = scp->sc->adp->va_info.vi_pixel_fields[1];
4227 bfld = scp->sc->adp->va_info.vi_pixel_fields[2];
4229 for (i = 0; i < 16; i++) {
4230 reg = scp->sc->adp->va_palette_regs[i];
4232 r = scp->sc->palette[reg * 3] >> (8 - rsize);
4233 g = scp->sc->palette[reg * 3 + 1] >> (8 - gsize);
4234 b = scp->sc->palette[reg * 3 + 2] >> (8 - bsize);
4236 scp->ega_palette[i] = (r << rfld) + (g << gfld) + (b << bfld);
4241 sc_set_border(scr_stat *scp, int color)
4243 atomic_add_int(&scp->sc->videoio_in_progress, 1);
4244 (*scp->rndr->draw_border)(scp, color);
4245 atomic_add_int(&scp->sc->videoio_in_progress, -1);
4248 #ifndef SC_NO_FONT_LOADING
4250 sc_load_font(scr_stat *scp, int page, int size, u_char *buf,
4251 int base, int count)
4256 sc->font_loading_in_progress = TRUE;
4257 (*vidsw[sc->adapter]->load_font)(sc->adp, page, size, buf, base, count);
4258 sc->font_loading_in_progress = FALSE;
4262 sc_save_font(scr_stat *scp, int page, int size, u_char *buf,
4263 int base, int count)
4268 sc->font_loading_in_progress = TRUE;
4269 (*vidsw[sc->adapter]->save_font)(sc->adp, page, size, buf, base, count);
4270 sc->font_loading_in_progress = FALSE;
4274 sc_show_font(scr_stat *scp, int page)
4276 (*vidsw[scp->sc->adapter]->show_font)(scp->sc->adp, page);
4278 #endif /* !SC_NO_FONT_LOADING */
4281 sc_paste(scr_stat *scp, u_char *p, int count)
4287 * Holy hell, don't try to inject a paste buffer if the keyboard
4288 * is not in ascii mode!
4290 if (scp->kbd_mode != K_XLATE)
4293 lwkt_gettoken(&vga_token);
4294 if (scp->status & MOUSE_VISIBLE) {
4295 tp = VIRTUAL_TTY(scp->sc, scp->sc->cur_scp->index);
4296 lwkt_gettoken(&tp->t_token);
4297 if (!ISTTYOPEN(tp)) {
4298 lwkt_reltoken(&tp->t_token);
4299 lwkt_reltoken(&vga_token);
4302 rmap = scp->sc->scr_rmap;
4303 for (; count > 0; --count)
4304 (*linesw[tp->t_line].l_rint)(rmap[*p++], tp);
4305 lwkt_reltoken(&tp->t_token);
4307 lwkt_reltoken(&vga_token);
4311 sc_bell(scr_stat *scp, int pitch, int duration)
4313 if (cold || shutdown_in_progress)
4316 if (scp != scp->sc->cur_scp && (scp->sc->flags & SC_QUIET_BELL)) {
4320 if (scp->sc->flags & SC_VISUAL_BELL) {
4321 if (scp->sc->blink_in_progress) {
4324 scp->sc->blink_in_progress = 3;
4325 if (scp != scp->sc->cur_scp)
4326 scp->sc->blink_in_progress += 2;
4327 lockmgr(&syscons_blink_lk, LK_EXCLUSIVE);
4328 sc_blink_screen(scp->sc->cur_scp);
4329 lockmgr(&syscons_blink_lk, LK_RELEASE);
4330 } else if (duration != 0 && pitch != 0) {
4331 if (scp != scp->sc->cur_scp)
4333 sysbeep(pitch, duration);
4338 * Blink the screen, called with the syscons_mtx and syscons_blink_lk
4339 * held. Can be called directly or via the callout.
4342 sc_blink_screen(scr_stat *scp)
4344 if (ISGRAPHSC(scp) || (scp->sc->blink_in_progress <= 1)) {
4345 scp->sc->blink_in_progress = 0;
4347 if (scp->sc->delayed_next_scr)
4348 sc_switch_scr(scp->sc, scp->sc->delayed_next_scr - 1);
4350 (*scp->rndr->draw)(scp, 0, scp->xsize*scp->ysize,
4351 scp->sc->blink_in_progress & 1);
4352 scp->sc->blink_in_progress--;
4353 callout_reset(&scp->blink_screen_ch, hz / 10,
4354 blink_screen_callout, scp);
4359 * Screen blink callout. Note that there is a lock order
4360 * reversal between syscons_blink_lk and the syscons lock.
4361 * Acquire the syscons lock non-blocking.
4364 blink_screen_callout(void *arg)
4366 scr_stat *scp = arg;
4368 if (syscons_lock_nonblock() == 0) {
4369 sc_blink_screen(scp);
4372 callout_reset(&scp->blink_screen_ch, hz / 10,
4373 blink_screen_callout, scp);
4378 * Allocate active keyboard. Try to allocate "kbdmux" keyboard first, and,
4379 * if found, add all non-busy keyboards to "kbdmux". Otherwise look for
4384 sc_allocate_keyboard(sc_softc_t *sc, int unit)
4390 idx0 = kbd_allocate("kbdmux", -1, (void *)&sc->keyboard, sckbdevent, sc);
4392 k0 = kbd_get_keyboard(idx0);
4394 for (idx = kbd_find_keyboard2("*", -1, 0, 0);
4396 idx = kbd_find_keyboard2("*", -1, idx + 1, 0)) {
4397 k = kbd_get_keyboard(idx);
4399 if (idx == idx0 || KBD_IS_BUSY(k))
4402 bzero(&ki, sizeof(ki));
4403 strcpy(ki.kb_name, k->kb_name);
4404 ki.kb_unit = k->kb_unit;
4406 kbd_ioctl(k0, KBADDKBD, (caddr_t) &ki);
4409 idx0 = kbd_allocate("*", unit, (void *)&sc->keyboard, sckbdevent, sc);