2 * SPDX-License-Identifier: BSD-3-Clause
4 * Copyright (c) 1992-1998 Søren Schmidt
7 * This code is derived from software contributed to The DragonFly Project
8 * by Sascha Wildner <saw@online.de>
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.
34 #include <sys/cdefs.h>
35 __FBSDID("$FreeBSD$");
37 #include "opt_syscons.h"
38 #include "opt_splash.h"
41 #include <sys/param.h>
42 #include <sys/systm.h>
46 #include <sys/consio.h>
48 #include <sys/eventhandler.h>
51 #include <sys/kernel.h>
53 #include <sys/malloc.h>
54 #include <sys/mutex.h>
58 #include <sys/random.h>
59 #include <sys/reboot.h>
60 #include <sys/serial.h>
61 #include <sys/signalvar.h>
63 #include <sys/sysctl.h>
65 #include <sys/power.h>
67 #include <machine/clock.h>
68 #if defined(__arm__) || defined(__mips__) || defined(__powerpc__) || \
70 #include <machine/sc_machdep.h>
72 #include <machine/pc/display.h>
74 #if defined(__i386__) || defined(__amd64__)
75 #include <machine/psl.h>
76 #include <machine/frame.h>
78 #include <machine/stdarg.h>
80 #if defined(__amd64__) || defined(__i386__)
81 #include <machine/vmparam.h>
87 #include <dev/kbd/kbdreg.h>
88 #include <dev/fb/fbreg.h>
89 #include <dev/fb/splashreg.h>
90 #include <dev/syscons/syscons.h>
95 #define DEFAULT_BLANKTIME (5 * 60) /* 5 minutes */
96 #define MAX_BLANKTIME (7 * 24 * 60 * 60) /* 7 days!? */
98 #define KEYCODE_BS 0x0e /* "<-- Backspace" key, XXX */
100 /* NULL-safe version of "tty_opened()" */
101 #define tty_opened_ns(tp) ((tp) != NULL && tty_opened(tp))
103 static u_char sc_kattrtab[MAXCPU];
105 static int sc_console_unit = -1;
106 static int sc_saver_keyb_only = 1;
107 static scr_stat *sc_console;
108 static struct consdev *sc_consptr;
109 static void *sc_kts[MAXCPU];
110 static struct sc_term_sw *sc_ktsw;
111 static scr_stat main_console;
112 static struct tty *main_devs[MAXCONS];
114 static char init_done = COLD;
115 static int shutdown_in_progress = FALSE;
116 static int suspend_in_progress = FALSE;
117 static char sc_malloc = FALSE;
119 static int saver_mode = CONS_NO_SAVER; /* LKM/user saver */
120 static int run_scrn_saver = FALSE; /* should run the saver? */
121 static int enable_bell = TRUE; /* enable beeper */
123 #ifndef SC_DISABLE_REBOOT
124 static int enable_reboot = TRUE; /* enable keyboard reboot */
127 #ifndef SC_DISABLE_KDBKEY
128 static int enable_kdbkey = TRUE; /* enable keyboard debug */
131 static long scrn_blank_time = 0; /* screen saver timeout value */
133 static int scrn_blanked; /* # of blanked screen */
134 static int sticky_splash = FALSE;
137 none_saver(sc_softc_t *sc, int blank)
140 static void (*current_saver)(sc_softc_t *, int) = none_saver;
143 #ifdef SC_NO_SUSPEND_VTYSWITCH
144 static int sc_no_suspend_vtswitch = 1;
146 static int sc_no_suspend_vtswitch = 0;
148 static int sc_susp_scr;
150 static SYSCTL_NODE(_hw, OID_AUTO, syscons, CTLFLAG_RD, 0, "syscons");
151 static SYSCTL_NODE(_hw_syscons, OID_AUTO, saver, CTLFLAG_RD, 0, "saver");
152 SYSCTL_INT(_hw_syscons_saver, OID_AUTO, keybonly, CTLFLAG_RW,
153 &sc_saver_keyb_only, 0, "screen saver interrupted by input only");
155 _hw_syscons, OID_AUTO, bell, CTLFLAG_RW, &enable_bell, 0, "enable bell");
156 #ifndef SC_DISABLE_REBOOT
157 SYSCTL_INT(_hw_syscons, OID_AUTO, kbd_reboot, CTLFLAG_RW | CTLFLAG_SECURE,
158 &enable_reboot, 0, "enable keyboard reboot");
160 #ifndef SC_DISABLE_KDBKEY
161 SYSCTL_INT(_hw_syscons, OID_AUTO, kbd_debug, CTLFLAG_RW | CTLFLAG_SECURE,
162 &enable_kdbkey, 0, "enable keyboard debug");
164 SYSCTL_INT(_hw_syscons, OID_AUTO, sc_no_suspend_vtswitch, CTLFLAG_RWTUN,
165 &sc_no_suspend_vtswitch, 0, "Disable VT switch before suspend.");
166 #if !defined(SC_NO_FONT_LOADING) && defined(SC_DFLT_FONT)
170 tsw_ioctl_t *sc_user_ioctl;
172 static bios_values_t bios_value;
174 static int enable_panic_key;
175 SYSCTL_INT(_machdep, OID_AUTO, enable_panic_key, CTLFLAG_RW, &enable_panic_key,
176 0, "Enable panic via keypress specified in kbdmap(5)");
178 #define SC_CONSOLECTL 255
180 #define VTY_WCHAN(sc, vty) (&SC_DEV(sc, vty))
183 static int sc_allocate_keyboard(sc_softc_t *sc, int unit);
184 static int scvidprobe(int unit, int flags, int cons);
185 static int sckbdprobe(int unit, int flags, int cons);
186 static void scmeminit(void *arg);
187 static int scdevtounit(struct tty *tp);
188 static kbd_callback_func_t sckbdevent;
189 static void scinit(int unit, int flags);
190 static scr_stat *sc_get_stat(struct tty *tp);
191 static void scterm(int unit, int flags);
192 static void scshutdown(void *, int);
193 static void scsuspend(void *);
194 static void scresume(void *);
195 static u_int scgetc(sc_softc_t *sc, u_int flags, struct sc_cnstate *sp);
196 static void sc_puts(scr_stat *scp, u_char *buf, int len);
198 #define SCGETC_NONBLOCK 2
199 static void sccnupdate(scr_stat *scp);
200 static scr_stat *alloc_scp(sc_softc_t *sc, int vty);
201 static void init_scp(sc_softc_t *sc, int vty, scr_stat *scp);
202 static callout_func_t scrn_timer;
203 static int and_region(int *s1, int *e1, int s2, int e2);
204 static void scrn_update(scr_stat *scp, int show_cursor);
207 static int scsplash_callback(int event, void *arg);
208 static void scsplash_saver(sc_softc_t *sc, int show);
209 static int add_scrn_saver(void (*this_saver)(sc_softc_t *, int));
210 static int remove_scrn_saver(void (*this_saver)(sc_softc_t *, int));
211 static int set_scrn_saver_mode(
212 scr_stat *scp, int mode, u_char *pal, int border);
213 static int restore_scrn_saver_mode(scr_stat *scp, int changemode);
214 static void stop_scrn_saver(sc_softc_t *sc, void (*saver)(sc_softc_t *, int));
215 static int wait_scrn_saver_stop(sc_softc_t *sc);
216 #define scsplash_stick(stick) (sticky_splash = (stick))
217 #else /* !DEV_SPLASH */
218 #define scsplash_stick(stick)
219 #endif /* DEV_SPLASH */
221 static int do_switch_scr(sc_softc_t *sc, int s);
222 static int vt_proc_alive(scr_stat *scp);
223 static int signal_vt_rel(scr_stat *scp);
224 static int signal_vt_acq(scr_stat *scp);
225 static int finish_vt_rel(scr_stat *scp, int release, int *s);
226 static int finish_vt_acq(scr_stat *scp);
227 static void exchange_scr(sc_softc_t *sc);
228 static void update_cursor_image(scr_stat *scp);
229 static void change_cursor_shape(scr_stat *scp, int flags, int base, int height);
230 static void update_font(scr_stat *);
231 static int save_kbd_state(scr_stat *scp);
232 static int update_kbd_state(scr_stat *scp, int state, int mask);
233 static int update_kbd_leds(scr_stat *scp, int which);
234 static int sc_kattr(void);
235 static callout_func_t blink_screen;
236 static struct tty *sc_alloc_tty(int, int);
238 static cn_probe_t sc_cnprobe;
239 static cn_init_t sc_cninit;
240 static cn_term_t sc_cnterm;
241 static cn_getc_t sc_cngetc;
242 static cn_putc_t sc_cnputc;
243 static cn_grab_t sc_cngrab;
244 static cn_ungrab_t sc_cnungrab;
248 static tsw_open_t sctty_open;
249 static tsw_close_t sctty_close;
250 static tsw_outwakeup_t sctty_outwakeup;
251 static tsw_ioctl_t sctty_ioctl;
252 static tsw_mmap_t sctty_mmap;
254 static struct ttydevsw sc_ttydevsw = {
255 .tsw_open = sctty_open,
256 .tsw_close = sctty_close,
257 .tsw_outwakeup = sctty_outwakeup,
258 .tsw_ioctl = sctty_ioctl,
259 .tsw_mmap = sctty_mmap,
262 static d_ioctl_t consolectl_ioctl;
263 static d_close_t consolectl_close;
265 static struct cdevsw consolectl_devsw = {
266 .d_version = D_VERSION,
267 .d_flags = D_NEEDGIANT | D_TRACKCLOSE,
268 .d_ioctl = consolectl_ioctl,
269 .d_close = consolectl_close,
270 .d_name = "consolectl",
273 /* ec -- emergency console. */
275 static u_int ec_scroffset;
283 int attr, column, mysize, width, xsize, yborder, ysize;
285 if (c < 0 || c > 0xff || c == '\a')
287 if (sc_console == NULL) {
288 #if !defined(__amd64__) && !defined(__i386__)
292 * This is enough for ec_putc() to work very early on x86
293 * if the kernel starts in normal color text mode.
296 fb = KERNBASE + 0xb8000;
298 fb = pmap_get_map_low() + 0xb8000;
304 if (!ISTEXTSC(&main_console))
306 fb = main_console.sc->adp->va_window;
307 xsize = main_console.xsize;
308 ysize = main_console.ysize;
311 scrptr = (u_short *)(void *)fb + xsize * yborder;
312 mysize = xsize * (ysize - 2 * yborder);
315 column = ind % xsize;
320 c == '\r' ? -column : c == '\n' ? xsize - column : 1);
321 if (width == 0 || (width < 0 && ind < -width))
323 } while (atomic_cmpset_rel_int(&ec_scroffset, ind, ind + width) == 0);
324 if (c == '\b' || c == '\r')
327 ind += xsize; /* XXX clearing from new pos is not atomic */
330 if (c == '\t' || c == '\n')
333 scrptr[ind++ % mysize] = (attr << 8) | c;
334 while (--width != 0);
338 sc_probe_unit(int unit, int flags)
340 if (!vty_enabled(VTY_SC))
342 if (!scvidprobe(unit, flags, FALSE)) {
344 printf("%s%d: no video adapter found.\n",
345 SC_DRIVER_NAME, unit);
349 /* syscons will be attached even when there is no keyboard */
350 sckbdprobe(unit, flags, FALSE);
355 /* probe video adapters, return TRUE if found */
357 scvidprobe(int unit, int flags, int cons)
360 * Access the video adapter driver through the back door!
361 * Video adapter drivers need to be configured before syscons.
362 * However, when syscons is being probed as the low-level console,
363 * they have not been initialized yet. We force them to initialize
364 * themselves here. XXX
366 vid_configure(cons ? VIO_PROBE_ONLY : 0);
368 return (vid_find_adapter("*", unit) >= 0);
371 /* probe the keyboard, return TRUE if found */
373 sckbdprobe(int unit, int flags, int cons)
375 /* access the keyboard driver through the backdoor! */
376 kbd_configure(cons ? KB_CONF_PROBE_ONLY : 0);
378 return (kbd_find_keyboard("*", unit) >= 0);
382 adapter_name(video_adapter_t *adp)
388 { KD_MONO, { "MDA", "MDA" } },
389 { KD_HERCULES, { "Hercules", "Hercules" } },
390 { KD_CGA, { "CGA", "CGA" } },
391 { KD_EGA, { "EGA", "EGA (mono)" } },
392 { KD_VGA, { "VGA", "VGA (mono)" } },
393 { KD_TGA, { "TGA", "TGA" } },
394 { -1, { "Unknown", "Unknown" } },
398 for (i = 0; names[i].type != -1; ++i)
399 if (names[i].type == adp->va_type)
401 return names[i].name[(adp->va_flags & V_ADP_COLOR) ? 0 : 1];
405 sctty_outwakeup(struct tty *tp)
409 scr_stat *scp = sc_get_stat(tp);
411 if (scp->status & SLKED ||
412 (scp == scp->sc->cur_scp && scp->sc->blink_in_progress))
416 len = ttydisc_getc(tp, buf, sizeof buf);
419 SC_VIDEO_LOCK(scp->sc);
420 sc_puts(scp, buf, len);
421 SC_VIDEO_UNLOCK(scp->sc);
426 sc_alloc_tty(int index, int devnum)
428 struct sc_ttysoftc *stc;
431 /* Allocate TTY object and softc to store unit number. */
432 stc = malloc(sizeof(struct sc_ttysoftc), M_DEVBUF, M_WAITOK);
433 stc->st_index = index;
435 tp = tty_alloc_mutex(&sc_ttydevsw, stc, &Giant);
437 /* Create device node. */
438 tty_makedev(tp, NULL, "v%r", devnum);
445 sc_set_vesa_mode(scr_stat *scp, sc_softc_t *sc, int unit)
455 (void)resource_int_value("sc", unit, "vesa_mode", &vmode);
456 if (vmode < M_VESA_BASE || vmode > M_VESA_MODE_MAX ||
457 vidd_get_info(sc->adp, vmode, &info) != 0 ||
458 !sc_support_pixel_mode(&info))
462 * If the mode is unset or unsupported, search for an available
463 * 800x600 graphics mode with the highest color depth.
466 for (depth = 0, i = M_VESA_BASE; i <= M_VESA_MODE_MAX; i++)
467 if (vidd_get_info(sc->adp, i, &info) == 0 &&
468 info.vi_width == 800 && info.vi_height == 600 &&
469 sc_support_pixel_mode(&info) &&
470 info.vi_depth > depth) {
472 depth = info.vi_depth;
476 vidd_get_info(sc->adp, vmode, &info);
479 #if !defined(SC_NO_FONT_LOADING) && defined(SC_DFLT_FONT)
480 fontsize = info.vi_cheight;
482 fontsize = scp->font_size;
486 else if (fontsize >= 16)
490 #ifndef SC_NO_FONT_LOADING
493 if ((sc->fonts_loaded & FONT_8) == 0)
498 if ((sc->fonts_loaded & FONT_14) == 0)
503 if ((sc->fonts_loaded & FONT_16) == 0)
512 if ((sc->flags & SC_SPLASH_SCRN) != 0)
513 splash_term(sc->adp);
515 #ifndef SC_NO_HISTORY
516 if (scp->history != NULL) {
517 sc_vtb_append(&scp->vtb, 0, scp->history,
518 scp->ypos * scp->xsize + scp->xpos);
519 scp->history_pos = sc_vtb_tail(scp->history);
522 vidd_set_mode(sc->adp, vmode);
523 scp->status |= (UNKNOWN_MODE | PIXEL_MODE | MOUSE_HIDDEN);
524 scp->status &= ~(GRAPHICS_MODE | MOUSE_VISIBLE);
525 scp->xpixel = info.vi_width;
526 scp->ypixel = info.vi_height;
527 scp->xsize = scp->xpixel / 8;
528 scp->ysize = scp->ypixel / fontsize;
530 scp->ypos = scp->ysize - 1;
531 scp->xoff = scp->yoff = 0;
533 scp->font_size = fontsize;
535 scp->start = scp->xsize * scp->ysize - 1;
537 scp->cursor_pos = scp->cursor_oldpos = scp->xsize * scp->xsize;
538 scp->mode = sc->initial_mode = vmode;
540 sc_vtb_init(&scp->scr, VTB_FRAMEBUFFER, scp->xsize, scp->ysize,
541 (void *)sc->adp->va_window, FALSE);
543 sc_alloc_scr_buffer(scp, FALSE, FALSE);
544 sc_init_emulator(scp, NULL);
545 #ifndef SC_NO_CUTPASTE
546 sc_alloc_cut_buffer(scp, FALSE);
548 #ifndef SC_NO_HISTORY
549 sc_alloc_history_buffer(scp, 0, 0, FALSE);
551 sc_set_border(scp, scp->border);
552 sc_set_cursor_image(scp);
553 scp->status &= ~UNKNOWN_MODE;
555 if ((sc->flags & SC_SPLASH_SCRN) != 0)
556 splash_init(sc->adp, scsplash_callback, sc);
562 sc_attach_unit(int unit, int flags)
570 if (!vty_enabled(VTY_SC))
573 flags &= ~SC_KERNEL_CONSOLE;
575 if (sc_console_unit == unit) {
577 * If this unit is being used as the system console, we need to
578 * adjust some variables and buffers before and after scinit().
580 /* assert(sc_console != NULL) */
581 flags |= SC_KERNEL_CONSOLE;
586 if (sc_console->tsw->te_size > 0) {
587 sc_ktsw = sc_console->tsw;
588 /* assert(sc_console->ts != NULL); */
589 oldts = sc_console->ts;
590 for (i = 0; i <= mp_maxid; i++) {
591 ts = malloc(sc_console->tsw->te_size, M_DEVBUF,
593 (*sc_console->tsw->te_init)(
594 sc_console, &ts, SC_TE_COLD_INIT);
596 (*sc_console->tsw->te_default_attr)(sc_console,
597 sc_kattrtab[i], SC_KERNEL_CONS_REV_ATTR);
600 sc_console->ts = oldts;
601 (*sc_console->tsw->te_default_attr)(
602 sc_console, SC_NORM_ATTR, SC_NORM_REV_ATTR);
608 sc = sc_get_softc(unit, flags & SC_KERNEL_CONSOLE);
610 callout_init(&sc->ctimeout, 0);
611 callout_init(&sc->cblink, 0);
612 scp = sc_get_stat(sc->dev[0]);
613 if (sc_console == NULL) /* sc_console_unit < 0 */
617 if ((sc->config & SC_VESAMODE) != 0)
618 sc_set_vesa_mode(scp, sc, unit);
619 #endif /* SC_PIXEL_MODE */
621 /* initialize cursor */
623 update_cursor_image(scp);
625 /* get screen update going */
628 /* set up the keyboard */
629 (void)kbdd_ioctl(sc->kbd, KDSKBMODE, (caddr_t)&scp->kbd_mode);
630 update_kbd_state(scp, scp->status, LOCK_MASK);
632 printf("%s%d: %s <%d virtual consoles, flags=0x%x>\n", SC_DRIVER_NAME,
633 unit, adapter_name(sc->adp), sc->vtys, sc->config);
635 printf("%s%d:", SC_DRIVER_NAME, unit);
636 if (sc->adapter >= 0)
637 printf(" fb%d", sc->adapter);
638 if (sc->keyboard >= 0)
639 printf(", kbd%d", sc->keyboard);
641 printf(", terminal emulator: %s (%s)",
642 scp->tsw->te_name, scp->tsw->te_desc);
646 /* Register suspend/resume/shutdown callbacks for the kernel console. */
647 if (sc_console_unit == unit) {
648 EVENTHANDLER_REGISTER(
649 power_suspend_early, scsuspend, NULL, EVENTHANDLER_PRI_ANY);
650 EVENTHANDLER_REGISTER(
651 power_resume, scresume, NULL, EVENTHANDLER_PRI_ANY);
652 EVENTHANDLER_REGISTER(
653 shutdown_pre_sync, scshutdown, NULL, SHUTDOWN_PRI_DEFAULT);
656 for (vc = 0; vc < sc->vtys; vc++) {
657 if (sc->dev[vc] == NULL) {
658 sc->dev[vc] = sc_alloc_tty(vc, vc + unit * MAXCONS);
659 if (vc == 0 && sc->dev == main_devs)
660 SC_STAT(sc->dev[0]) = &main_console;
663 * The first vty already has struct tty and scr_stat initialized
664 * in scinit(). The other vtys will have these structs when
670 &consolectl_devsw, 0, UID_ROOT, GID_WHEEL, 0600, "consolectl");
671 dev->si_drv1 = sc->dev[0];
679 if (!vty_enabled(VTY_SC))
686 * As soon as malloc() becomes functional, we had better allocate
687 * various buffers for the kernel console.
690 if (sc_console_unit < 0) /* sc_console == NULL */
693 /* copy the temporary buffer to the final buffer */
694 sc_alloc_scr_buffer(sc_console, FALSE, FALSE);
696 #ifndef SC_NO_CUTPASTE
697 sc_alloc_cut_buffer(sc_console, FALSE);
700 #ifndef SC_NO_HISTORY
701 /* initialize history buffer & pointers */
702 sc_alloc_history_buffer(sc_console, 0, 0, FALSE);
707 SYSINIT(sc_mem, SI_SUB_KMEM, SI_ORDER_ANY, scmeminit, NULL);
710 scdevtounit(struct tty *tp)
712 int vty = SC_VTY(tp);
714 if (vty == SC_CONSOLECTL)
715 return ((sc_console != NULL) ? sc_console->sc->unit : -1);
716 else if ((vty < 0) || (vty >= MAXCONS * sc_max_unit()))
719 return vty / MAXCONS;
723 sctty_open(struct tty *tp)
725 int unit = scdevtounit(tp);
733 ("scopen: dev:%s, unit:%d, vty:%d\n", devtoname(tp->t_dev), unit,
737 unit, (sc_console_unit == unit) ? SC_KERNEL_CONSOLE : 0);
741 if (!tty_opened(tp)) {
742 /* Use the current setting of the <-- key as default VERASE. */
743 /* If the Delete key is preferable, an stty is necessary */
745 if (sc->kbd != NULL) {
746 key.keynum = KEYCODE_BS;
747 (void)kbdd_ioctl(sc->kbd, GIO_KEYMAPENT, (caddr_t)&key);
748 tp->t_termios.c_cc[VERASE] = key.key.map[0];
753 scp = sc_get_stat(tp);
755 scp = SC_STAT(tp) = alloc_scp(sc, SC_VTY(tp));
757 sc_set_pixel_mode(scp, NULL, 0, 0, 16, 8);
759 if (!tp->t_winsize.ws_col && !tp->t_winsize.ws_row) {
760 tp->t_winsize.ws_col = scp->xsize;
761 tp->t_winsize.ws_row = scp->ysize;
768 sctty_close(struct tty *tp)
773 if (SC_VTY(tp) != SC_CONSOLECTL) {
774 scp = sc_get_stat(tp);
775 /* were we in the middle of the VT switching process? */
776 DPRINTF(5, ("sc%d: scclose(), ", scp->sc->unit));
778 if ((scp == scp->sc->cur_scp) &&
779 (scp->sc->unit == sc_console_unit))
780 cnavailable(sc_consptr, TRUE);
781 if (finish_vt_rel(scp, TRUE, &s) == 0) /* force release */
782 DPRINTF(5, ("reset WAIT_REL, "));
783 if (finish_vt_acq(scp) == 0) /* force acknowledge */
784 DPRINTF(5, ("reset WAIT_ACQ, "));
786 if (scp == &main_console) {
789 scp->smode.mode = VT_AUTO;
791 sc_vtb_destroy(&scp->vtb);
793 sc_vtb_destroy(&scp->scr);
795 sc_free_history_buffer(scp, scp->ysize);
802 scp->smode.mode = VT_AUTO;
804 scp->kbd_mode = K_XLATE;
805 if (scp == scp->sc->cur_scp)
807 scp->sc->kbd, KDSKBMODE, (caddr_t)&scp->kbd_mode);
808 DPRINTF(5, ("done.\n"));
812 #if 0 /* XXX mpsafetty: fix screensaver. What about outwakeup? */
814 scread(struct cdev *dev, struct uio *uio, int flag)
816 if (!sc_saver_keyb_only)
817 sc_touch_scrn_saver();
818 return ttyread(dev, uio, flag);
823 sckbdevent(keyboard_t *thiskbd, int event, void *arg)
831 sc = (sc_softc_t *)arg;
832 /* assert(thiskbd == sc->kbd) */
839 case KBDIO_UNLOADING:
842 kbd_release(thiskbd, (void *)&sc->keyboard);
850 * Loop while there is still input to get from the keyboard.
851 * I don't think this is nessesary, and it doesn't fix
852 * the Xaccel-2.1 keyboard hang, but it can't hurt. XXX
854 while ((c = scgetc(sc, SCGETC_NONBLOCK, NULL)) != NOKEY) {
856 cur_tty = SC_DEV(sc, sc->cur_scp->index);
857 if (!tty_opened_ns(cur_tty))
860 if ((*sc->cur_scp->tsw->te_input)(sc->cur_scp, c, cur_tty))
863 switch (KEYFLAGS(c)) {
864 case 0x0000: /* normal key */
865 ttydisc_rint(cur_tty, KEYCHAR(c), 0);
867 case FKEY: /* function key, return string */
868 cp = (*sc->cur_scp->tsw->te_fkeystr)(sc->cur_scp, c);
870 ttydisc_rint_simple(cur_tty, cp, strlen(cp));
873 cp = kbdd_get_fkeystr(thiskbd, KEYCHAR(c), &len);
875 ttydisc_rint_simple(cur_tty, cp, len);
877 case MKEY: /* meta is active, prepend ESC */
878 ttydisc_rint(cur_tty, 0x1b, 0);
879 ttydisc_rint(cur_tty, KEYCHAR(c), 0);
881 case BKEY: /* backtab fixed sequence (esc [ Z) */
882 ttydisc_rint_simple(cur_tty, "\x1B[Z", 3);
886 ttydisc_rint_done(cur_tty);
889 sc->cur_scp->status |= MOUSE_HIDDEN;
897 sctty_ioctl(struct tty *tp, u_long cmd, caddr_t data, struct thread *td)
901 struct cursor_attr *cap;
905 #if defined(COMPAT_FREEBSD6) || defined(COMPAT_FREEBSD5) || \
906 defined(COMPAT_FREEBSD4) || defined(COMPAT_43)
910 /* If there is a user_ioctl function call that first */
912 error = (*sc_user_ioctl)(tp, cmd, data, td);
913 if (error != ENOIOCTL)
917 error = sc_vid_ioctl(tp, cmd, data, td);
918 if (error != ENOIOCTL)
921 #ifndef SC_NO_HISTORY
922 error = sc_hist_ioctl(tp, cmd, data, td);
923 if (error != ENOIOCTL)
927 #ifndef SC_NO_SYSMOUSE
928 error = sc_mouse_ioctl(tp, cmd, data, td);
929 if (error != ENOIOCTL)
933 scp = sc_get_stat(tp);
934 /* assert(scp != NULL) */
935 /* scp is sc_console, if SC_VTY(dev) == SC_CONSOLECTL. */
939 error = (*scp->tsw->te_ioctl)(scp, tp, cmd, data, td);
940 if (error != ENOIOCTL)
944 switch (cmd) { /* process console hardware related ioctl's */
946 case GIO_ATTR: /* get current attributes */
947 /* this ioctl is not processed here, but in the terminal
951 case GIO_COLOR: /* is this a color console ? */
952 *(int *)data = (sc->adp->va_flags & V_ADP_COLOR) ? 1 : 0;
955 case CONS_BLANKTIME: /* set screen saver timeout (0 = no saver) */
956 if (*(int *)data < 0 || *(int *)data > MAX_BLANKTIME)
959 scrn_blank_time = *(int *)data;
960 run_scrn_saver = (scrn_blank_time != 0);
964 case CONS_CURSORTYPE: /* set cursor type (old interface + HIDDEN) */
966 *(int *)data &= CONS_CURSOR_ATTRS;
967 sc_change_cursor_shape(scp, *(int *)data, -1, -1);
971 case CONS_GETCURSORSHAPE: /* get cursor shape (new interface) */
972 switch (((int *)data)[0] &
973 (CONS_DEFAULT_CURSOR | CONS_LOCAL_CURSOR)) {
975 cap = &sc->curs_attr;
977 case CONS_LOCAL_CURSOR:
978 cap = &scp->base_curs_attr;
980 case CONS_DEFAULT_CURSOR:
981 cap = &sc->dflt_curs_attr;
983 case CONS_DEFAULT_CURSOR | CONS_LOCAL_CURSOR:
984 cap = &scp->dflt_curs_attr;
987 if (((int *)data)[0] & CONS_CHARCURSOR_COLORS) {
988 ((int *)data)[1] = cap->bg[0];
989 ((int *)data)[2] = cap->bg[1];
990 } else if (((int *)data)[0] & CONS_MOUSECURSOR_COLORS) {
991 ((int *)data)[1] = cap->mouse_ba;
992 ((int *)data)[2] = cap->mouse_ia;
994 ((int *)data)[1] = cap->base;
995 ((int *)data)[2] = cap->height;
997 ((int *)data)[0] = cap->flags;
1000 case CONS_SETCURSORSHAPE: /* set cursor shape (new interface) */
1002 sc_change_cursor_shape(
1003 scp, ((int *)data)[0], ((int *)data)[1], ((int *)data)[2]);
1007 case CONS_BELLTYPE: /* set bell type sound/visual */
1008 if ((*(int *)data) & CONS_VISUAL_BELL)
1009 sc->flags |= SC_VISUAL_BELL;
1011 sc->flags &= ~SC_VISUAL_BELL;
1012 if ((*(int *)data) & CONS_QUIET_BELL)
1013 sc->flags |= SC_QUIET_BELL;
1015 sc->flags &= ~SC_QUIET_BELL;
1018 case CONS_GETINFO: /* get current (virtual) console info */
1020 vid_info_t *ptr = (vid_info_t *)data;
1021 if (ptr->size == sizeof(struct vid_info)) {
1022 ptr->m_num = sc->cur_scp->index;
1023 ptr->font_size = scp->font_size;
1024 ptr->mv_col = scp->xpos;
1025 ptr->mv_row = scp->ypos;
1026 ptr->mv_csz = scp->xsize;
1027 ptr->mv_rsz = scp->ysize;
1029 (scp->history != NULL) ? scp->history->vtb_rows : 0;
1031 * The following fields are filled by the terminal
1039 ptr->mv_grfc.fore = 0; /* not supported */
1040 ptr->mv_grfc.back = 0; /* not supported */
1041 ptr->mv_ovscan = scp->border;
1042 if (scp == sc->cur_scp)
1043 save_kbd_state(scp);
1044 ptr->mk_keylock = scp->status & LOCK_MASK;
1050 case CONS_GETVERS: /* get version number */
1051 *(int *)data = 0x200; /* version 2.0 */
1054 case CONS_IDLE: /* see if the screen has been idle */
1056 * When the screen is in the GRAPHICS_MODE or UNKNOWN_MODE,
1057 * the user process may have been writing something on the
1058 * screen and syscons is not aware of it. Declare the screen
1059 * is NOT idle if it is in one of these modes. But there is
1060 * an exception to it; if a screen saver is running in the
1061 * graphics mode in the current screen, we should say that the
1062 * screen has been idle.
1064 *(int *)data = (sc->flags & SC_SCRN_IDLE) &&
1065 (!ISGRAPHSC(sc->cur_scp) ||
1066 (sc->cur_scp->status & SAVER_RUNNING));
1069 case CONS_SAVERMODE: /* set saver mode */
1070 switch (*(int *)data) {
1072 case CONS_USR_SAVER:
1073 /* if a LKM screen saver is running, stop it first. */
1074 scsplash_stick(FALSE);
1075 saver_mode = *(int *)data;
1078 if ((error = wait_scrn_saver_stop(NULL))) {
1083 run_scrn_saver = TRUE;
1084 if (saver_mode == CONS_USR_SAVER)
1085 scp->status |= SAVER_RUNNING;
1087 scp->status &= ~SAVER_RUNNING;
1088 scsplash_stick(TRUE);
1091 case CONS_LKM_SAVER:
1093 if ((saver_mode == CONS_USR_SAVER) &&
1094 (scp->status & SAVER_RUNNING))
1095 scp->status &= ~SAVER_RUNNING;
1096 saver_mode = *(int *)data;
1104 case CONS_SAVERSTART: /* immediately start/stop the screen saver */
1106 * Note that this ioctl does not guarantee the screen saver
1107 * actually starts or stops. It merely attempts to do so...
1110 run_scrn_saver = (*(int *)data != 0);
1112 sc->scrn_time_stamp -= scrn_blank_time;
1116 case CONS_SCRSHOT: /* get a screen shot */
1118 int retval, hist_rsz;
1119 size_t lsize, csize;
1120 vm_offset_t frbp, hstp;
1122 scrshot_t *ptr = (scrshot_t *)data;
1123 void *outp = ptr->buf;
1125 if (ptr->x < 0 || ptr->y < 0 || ptr->xsize < 0 ||
1129 if (ISGRAPHSC(scp)) {
1133 hist_rsz = (scp->history != NULL) ? scp->history->vtb_rows : 0;
1134 if (((u_int)ptr->x + ptr->xsize) > scp->xsize ||
1135 ((u_int)ptr->y + ptr->ysize) > (scp->ysize + hist_rsz)) {
1140 lsize = scp->xsize * sizeof(u_int16_t);
1141 csize = ptr->xsize * sizeof(u_int16_t);
1142 /* Pointer to the last line of framebuffer */
1143 frbp = scp->vtb.vtb_buffer + scp->ysize * lsize +
1144 ptr->x * sizeof(u_int16_t);
1145 /* Pointer to the last line of target buffer */
1146 outp = (char *)outp + ptr->ysize * csize;
1147 /* Pointer to the last line of history buffer */
1148 if (scp->history != NULL)
1149 hstp = scp->history->vtb_buffer +
1150 sc_vtb_tail(scp->history) * sizeof(u_int16_t) +
1151 ptr->x * sizeof(u_int16_t);
1156 for (lnum = 0; lnum < (ptr->y + ptr->ysize); lnum++) {
1157 if (lnum < scp->ysize) {
1161 if (hstp < scp->history->vtb_buffer)
1162 hstp += scp->history->vtb_rows * lsize;
1167 outp = (char *)outp - csize;
1168 retval = copyout((void *)frbp, outp, csize);
1176 case VT_SETMODE: /* set screen switcher mode */
1178 struct vt_mode *mode;
1181 mode = (struct vt_mode *)data;
1182 DPRINTF(5, ("%s%d: VT_SETMODE ", SC_DRIVER_NAME, sc->unit));
1183 if (scp->smode.mode == VT_PROCESS) {
1184 p1 = pfind(scp->pid);
1185 if (scp->proc == p1 && scp->proc != td->td_proc) {
1188 DPRINTF(5, ("error EPERM\n"));
1195 if (mode->mode == VT_AUTO) {
1196 scp->smode.mode = VT_AUTO;
1199 DPRINTF(5, ("VT_AUTO, "));
1200 if ((scp == sc->cur_scp) &&
1201 (sc->unit == sc_console_unit))
1202 cnavailable(sc_consptr, TRUE);
1203 /* were we in the middle of the vty switching process?
1205 if (finish_vt_rel(scp, TRUE, &s) == 0)
1206 DPRINTF(5, ("reset WAIT_REL, "));
1207 if (finish_vt_acq(scp) == 0)
1208 DPRINTF(5, ("reset WAIT_ACQ, "));
1210 if (!ISSIGVALID(mode->relsig) ||
1211 !ISSIGVALID(mode->acqsig) ||
1212 !ISSIGVALID(mode->frsig)) {
1214 DPRINTF(5, ("error EINVAL\n"));
1217 DPRINTF(5, ("VT_PROCESS %d, ", td->td_proc->p_pid));
1218 bcopy(data, &scp->smode, sizeof(struct vt_mode));
1219 scp->proc = td->td_proc;
1220 scp->pid = scp->proc->p_pid;
1221 if ((scp == sc->cur_scp) &&
1222 (sc->unit == sc_console_unit))
1223 cnavailable(sc_consptr, FALSE);
1230 case VT_GETMODE: /* get screen switcher mode */
1231 bcopy(&scp->smode, data, sizeof(struct vt_mode));
1234 #if defined(COMPAT_FREEBSD6) || defined(COMPAT_FREEBSD5) || \
1235 defined(COMPAT_FREEBSD4) || defined(COMPAT_43)
1237 ival = IOCPARM_IVAL(data);
1238 data = (caddr_t)&ival;
1241 case VT_RELDISP: /* screen switcher ioctl */
1244 * This must be the current vty which is in the VT_PROCESS
1247 if ((scp != sc->cur_scp) || (scp->smode.mode != VT_PROCESS)) {
1251 /* ...and this process is controlling it. */
1252 if (scp->proc != td->td_proc) {
1257 switch (*(int *)data) {
1258 case VT_FALSE: /* user refuses to release screen, abort */
1259 if ((error = finish_vt_rel(scp, FALSE, &s)) == 0)
1261 ("%s%d: VT_FALSE\n", SC_DRIVER_NAME,
1264 case VT_TRUE: /* user has released screen, go on */
1265 if ((error = finish_vt_rel(scp, TRUE, &s)) == 0)
1267 ("%s%d: VT_TRUE\n", SC_DRIVER_NAME,
1270 case VT_ACKACQ: /* acquire acknowledged, switch completed */
1271 if ((error = finish_vt_acq(scp)) == 0)
1273 ("%s%d: VT_ACKACQ\n", SC_DRIVER_NAME,
1282 case VT_OPENQRY: /* return free virtual console */
1283 for (i = sc->first_vty; i < sc->first_vty + sc->vtys; i++) {
1285 if (!tty_opened_ns(tp)) {
1286 *(int *)data = i + 1;
1292 #if defined(COMPAT_FREEBSD6) || defined(COMPAT_FREEBSD5) || \
1293 defined(COMPAT_FREEBSD4) || defined(COMPAT_43)
1295 ival = IOCPARM_IVAL(data);
1296 data = (caddr_t)&ival;
1299 case VT_ACTIVATE: /* switch to screen *data */
1300 i = (*(int *)data == 0) ? scp->index : (*(int *)data - 1);
1302 error = sc_clean_up(sc->cur_scp);
1306 error = sc_switch_scr(sc, i);
1309 #if defined(COMPAT_FREEBSD6) || defined(COMPAT_FREEBSD5) || \
1310 defined(COMPAT_FREEBSD4) || defined(COMPAT_43)
1312 ival = IOCPARM_IVAL(data);
1313 data = (caddr_t)&ival;
1316 case VT_WAITACTIVE: /* wait for switch to occur */
1317 i = (*(int *)data == 0) ? scp->index : (*(int *)data - 1);
1318 if ((i < sc->first_vty) || (i >= sc->first_vty + sc->vtys))
1320 if (i == sc->cur_scp->index)
1323 tsleep(VTY_WCHAN(sc, i), (PZERO + 1) | PCATCH, "waitvt", 0);
1326 case VT_GETACTIVE: /* get active vty # */
1327 *(int *)data = sc->cur_scp->index + 1;
1330 case VT_GETINDEX: /* get this vty # */
1331 *(int *)data = scp->index + 1;
1334 case VT_LOCKSWITCH: /* prevent vty switching */
1335 if ((*(int *)data) & 0x01)
1336 sc->flags |= SC_SCRN_VTYLOCK;
1338 sc->flags &= ~SC_SCRN_VTYLOCK;
1341 case KDENABIO: /* allow io operations */
1342 error = priv_check(td, PRIV_IO);
1345 error = securelevel_gt(td->td_ucred, 0);
1349 td->td_frame->tf_eflags |= PSL_IOPL;
1350 #elif defined(__amd64__)
1351 td->td_frame->tf_rflags |= PSL_IOPL;
1355 case KDDISABIO: /* disallow io operations (default) */
1357 td->td_frame->tf_eflags &= ~PSL_IOPL;
1358 #elif defined(__amd64__)
1359 td->td_frame->tf_rflags &= ~PSL_IOPL;
1363 #if defined(COMPAT_FREEBSD6) || defined(COMPAT_FREEBSD5) || \
1364 defined(COMPAT_FREEBSD4) || defined(COMPAT_43)
1366 ival = IOCPARM_IVAL(data);
1367 data = (caddr_t)&ival;
1370 case KDSKBSTATE: /* set keyboard state (locks) */
1371 if (*(int *)data & ~LOCK_MASK)
1373 scp->status &= ~LOCK_MASK;
1374 scp->status |= *(int *)data;
1375 if (scp == sc->cur_scp)
1376 update_kbd_state(scp, scp->status, LOCK_MASK);
1379 case KDGKBSTATE: /* get keyboard state (locks) */
1380 if (scp == sc->cur_scp)
1381 save_kbd_state(scp);
1382 *(int *)data = scp->status & LOCK_MASK;
1385 case KDGETREPEAT: /* get keyboard repeat & delay rates */
1386 case KDSETREPEAT: /* set keyboard repeat & delay rates (new) */
1387 error = kbdd_ioctl(sc->kbd, cmd, data);
1388 if (error == ENOIOCTL)
1392 #if defined(COMPAT_FREEBSD6) || defined(COMPAT_FREEBSD5) || \
1393 defined(COMPAT_FREEBSD4) || defined(COMPAT_43)
1395 ival = IOCPARM_IVAL(data);
1396 data = (caddr_t)&ival;
1399 case KDSETRAD: /* set keyboard repeat & delay rates (old) */
1400 if (*(int *)data & ~0x7f)
1402 error = kbdd_ioctl(sc->kbd, KDSETRAD, data);
1403 if (error == ENOIOCTL)
1407 #if defined(COMPAT_FREEBSD6) || defined(COMPAT_FREEBSD5) || \
1408 defined(COMPAT_FREEBSD4) || defined(COMPAT_43)
1410 ival = IOCPARM_IVAL(data);
1411 data = (caddr_t)&ival;
1414 case KDSKBMODE: /* set keyboard mode */
1415 switch (*(int *)data) {
1416 case K_XLATE: /* switch to XLT ascii mode */
1417 case K_RAW: /* switch to RAW scancode mode */
1418 case K_CODE: /* switch to CODE mode */
1419 scp->kbd_mode = *(int *)data;
1420 if (scp == sc->cur_scp)
1421 (void)kbdd_ioctl(sc->kbd, KDSKBMODE, data);
1428 case KDGKBMODE: /* get keyboard mode */
1429 *(int *)data = scp->kbd_mode;
1433 error = kbdd_ioctl(sc->kbd, cmd, data);
1434 if (error == ENOIOCTL)
1438 #if defined(COMPAT_FREEBSD6) || defined(COMPAT_FREEBSD5) || \
1439 defined(COMPAT_FREEBSD4) || defined(COMPAT_43)
1441 ival = IOCPARM_IVAL(data);
1442 data = (caddr_t)&ival;
1445 case KDMKTONE: /* sound the bell */
1447 sc_bell(scp, (*(int *)data) & 0xffff,
1448 (((*(int *)data) >> 16) & 0xffff) * hz / 1000);
1450 sc_bell(scp, scp->bell_pitch, scp->bell_duration);
1453 #if defined(COMPAT_FREEBSD6) || defined(COMPAT_FREEBSD5) || \
1454 defined(COMPAT_FREEBSD4) || defined(COMPAT_43)
1456 ival = IOCPARM_IVAL(data);
1457 data = (caddr_t)&ival;
1460 case KIOCSOUND: /* make tone (*data) hz */
1461 if (scp == sc->cur_scp) {
1463 return sc_tone(*(int *)data);
1469 case KDGKBTYPE: /* get keyboard type */
1470 error = kbdd_ioctl(sc->kbd, cmd, data);
1471 if (error == ENOIOCTL) {
1472 /* always return something? XXX */
1477 #if defined(COMPAT_FREEBSD6) || defined(COMPAT_FREEBSD5) || \
1478 defined(COMPAT_FREEBSD4) || defined(COMPAT_43)
1480 ival = IOCPARM_IVAL(data);
1481 data = (caddr_t)&ival;
1484 case KDSETLED: /* set keyboard LED status */
1485 if (*(int *)data & ~LED_MASK) /* FIXME: LOCK_MASK? */
1487 scp->status &= ~LED_MASK;
1488 scp->status |= *(int *)data;
1489 if (scp == sc->cur_scp)
1490 update_kbd_leds(scp, scp->status);
1493 case KDGETLED: /* get keyboard LED status */
1494 if (scp == sc->cur_scp)
1495 save_kbd_state(scp);
1496 *(int *)data = scp->status & LED_MASK;
1499 case KBADDKBD: /* add/remove keyboard to/from mux */
1501 error = kbdd_ioctl(sc->kbd, cmd, data);
1502 if (error == ENOIOCTL)
1506 #if defined(COMPAT_FREEBSD6) || defined(COMPAT_FREEBSD5) || \
1507 defined(COMPAT_FREEBSD4) || defined(COMPAT_43)
1509 ival = IOCPARM_IVAL(data);
1510 data = (caddr_t)&ival;
1513 case CONS_SETKBD: /* set the new keyboard */
1518 newkbd = kbd_get_keyboard(*(int *)data);
1519 if (newkbd == NULL) {
1524 if (sc->kbd != newkbd) {
1525 i = kbd_allocate(newkbd->kb_name, newkbd->kb_unit,
1526 (void *)&sc->keyboard, sckbdevent, sc);
1527 /* i == newkbd->kb_index */
1529 if (sc->kbd != NULL) {
1530 save_kbd_state(sc->cur_scp);
1532 sc->kbd, (void *)&sc->keyboard);
1535 kbd_get_keyboard(i); /* sc->kbd == newkbd */
1537 (void)kbdd_ioctl(sc->kbd, KDSKBMODE,
1538 (caddr_t)&sc->cur_scp->kbd_mode);
1539 update_kbd_state(sc->cur_scp,
1540 sc->cur_scp->status, LOCK_MASK);
1542 error = EPERM; /* XXX */
1549 case CONS_RELKBD: /* release the current keyboard */
1552 if (sc->kbd != NULL) {
1553 save_kbd_state(sc->cur_scp);
1554 error = kbd_release(sc->kbd, (void *)&sc->keyboard);
1563 case CONS_GETTERM: /* get the current terminal emulator info */
1567 if (((term_info_t *)data)->ti_index == 0) {
1570 sw = sc_term_match_by_number(
1571 ((term_info_t *)data)->ti_index);
1574 strncpy(((term_info_t *)data)->ti_name, sw->te_name,
1575 sizeof(((term_info_t *)data)->ti_name));
1576 strncpy(((term_info_t *)data)->ti_desc, sw->te_desc,
1577 sizeof(((term_info_t *)data)->ti_desc));
1578 ((term_info_t *)data)->ti_flags = 0;
1581 ((term_info_t *)data)->ti_name[0] = '\0';
1582 ((term_info_t *)data)->ti_desc[0] = '\0';
1583 ((term_info_t *)data)->ti_flags = 0;
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 */
1595 case GIO_SCRNMAP: /* get output translation table */
1596 bcopy(&sc->scr_map, data, sizeof(sc->scr_map));
1599 case PIO_SCRNMAP: /* set output translation table */
1600 bcopy(data, &sc->scr_map, sizeof(sc->scr_map));
1601 for (i = 0; i < sizeof(sc->scr_map); i++) {
1602 sc->scr_rmap[sc->scr_map[i]] = i;
1606 case GIO_KEYMAP: /* get keyboard translation table */
1607 case PIO_KEYMAP: /* set keyboard translation table */
1608 case OGIO_KEYMAP: /* get keyboard translation table (compat) */
1609 case OPIO_KEYMAP: /* set keyboard translation table (compat) */
1610 case GIO_DEADKEYMAP: /* get accent key translation table */
1611 case PIO_DEADKEYMAP: /* set accent key translation table */
1612 case GETFKEY: /* get function key string */
1613 case SETFKEY: /* set function key string */
1614 error = kbdd_ioctl(sc->kbd, cmd, data);
1615 if (error == ENOIOCTL)
1619 #ifndef SC_NO_FONT_LOADING
1621 case PIO_FONT8x8: /* set 8x8 dot font */
1622 if (!ISFONTAVAIL(sc->adp->va_flags))
1624 bcopy(data, sc->font_8, 8 * 256);
1625 sc->fonts_loaded |= FONT_8;
1628 * Always use the font page #0. XXX
1629 * Don't load if the current font size is not 8x8.
1631 if (ISTEXTSC(sc->cur_scp) && (sc->cur_scp->font_size < 14))
1632 sc_load_font(sc->cur_scp, 0, 8, 8, sc->font_8, 0, 256);
1635 case GIO_FONT8x8: /* get 8x8 dot font */
1636 if (!ISFONTAVAIL(sc->adp->va_flags))
1638 if (sc->fonts_loaded & FONT_8) {
1639 bcopy(sc->font_8, data, 8 * 256);
1644 case PIO_FONT8x14: /* set 8x14 dot font */
1645 if (!ISFONTAVAIL(sc->adp->va_flags))
1647 bcopy(data, sc->font_14, 14 * 256);
1648 sc->fonts_loaded |= FONT_14;
1651 * Always use the font page #0. XXX
1652 * Don't load if the current font size is not 8x14.
1654 if (ISTEXTSC(sc->cur_scp) && (sc->cur_scp->font_size >= 14) &&
1655 (sc->cur_scp->font_size < 16))
1657 sc->cur_scp, 0, 14, 8, sc->font_14, 0, 256);
1660 case GIO_FONT8x14: /* get 8x14 dot font */
1661 if (!ISFONTAVAIL(sc->adp->va_flags))
1663 if (sc->fonts_loaded & FONT_14) {
1664 bcopy(sc->font_14, data, 14 * 256);
1669 case PIO_FONT8x16: /* set 8x16 dot font */
1670 if (!ISFONTAVAIL(sc->adp->va_flags))
1672 bcopy(data, sc->font_16, 16 * 256);
1673 sc->fonts_loaded |= FONT_16;
1676 * Always use the font page #0. XXX
1677 * Don't load if the current font size is not 8x16.
1679 if (ISTEXTSC(sc->cur_scp) && (sc->cur_scp->font_size >= 16))
1681 sc->cur_scp, 0, 16, 8, sc->font_16, 0, 256);
1684 case GIO_FONT8x16: /* get 8x16 dot font */
1685 if (!ISFONTAVAIL(sc->adp->va_flags))
1687 if (sc->fonts_loaded & FONT_16) {
1688 bcopy(sc->font_16, data, 16 * 256);
1693 #endif /* SC_NO_FONT_LOADING */
1704 struct cdev *dev, u_long cmd, caddr_t data, int fflag, struct thread *td)
1707 return sctty_ioctl(dev->si_drv1, cmd, data, td);
1711 consolectl_close(struct cdev *dev, int flags, int mode, struct thread *td)
1713 #ifndef SC_NO_SYSMOUSE
1715 memset(&info, 0, sizeof(info));
1716 info.operation = MOUSE_ACTION;
1719 * Make sure all buttons are released when moused and other
1720 * console daemons exit, so that no buttons are left pressed.
1722 (void)sctty_ioctl(dev->si_drv1, CONS_MOUSECTL, (caddr_t)&info, td);
1728 sc_cnprobe(struct consdev *cp)
1733 if (!vty_enabled(VTY_SC)) {
1734 cp->cn_pri = CN_DEAD;
1738 cp->cn_pri = sc_get_cons_priority(&unit, &flags);
1740 /* a video card is always required */
1741 if (!scvidprobe(unit, flags, TRUE))
1742 cp->cn_pri = CN_DEAD;
1744 /* syscons will become console even when there is no keyboard */
1745 sckbdprobe(unit, flags, TRUE);
1747 if (cp->cn_pri == CN_DEAD)
1750 /* initialize required fields */
1751 strcpy(cp->cn_name, "ttyv0");
1755 sc_cninit(struct consdev *cp)
1760 sc_get_cons_priority(&unit, &flags);
1761 scinit(unit, flags | SC_KERNEL_CONSOLE);
1762 sc_console_unit = unit;
1763 sc_console = sc_get_stat(sc_get_softc(unit, SC_KERNEL_CONSOLE)->dev[0]);
1768 sc_cnterm(struct consdev *cp)
1773 /* we are not the kernel console any more, release everything */
1775 if (sc_console_unit < 0)
1776 return; /* shouldn't happen */
1779 sc_clear_screen(sc_console);
1780 sccnupdate(sc_console);
1783 if (sc_ktsw != NULL) {
1784 for (i = 0; i <= mp_maxid; i++) {
1787 (*sc_ktsw->te_term)(sc_console, &ts);
1792 scterm(sc_console_unit, SC_KERNEL_CONSOLE);
1793 sc_console_unit = -1;
1797 static void sccnclose(sc_softc_t *sc, struct sc_cnstate *sp);
1798 static int sc_cngetc_locked(struct sc_cnstate *sp);
1799 static void sccnkbdlock(sc_softc_t *sc, struct sc_cnstate *sp);
1800 static void sccnkbdunlock(sc_softc_t *sc, struct sc_cnstate *sp);
1801 static void sccnopen(sc_softc_t *sc, struct sc_cnstate *sp, int flags);
1802 static void sccnscrlock(sc_softc_t *sc, struct sc_cnstate *sp);
1803 static void sccnscrunlock(sc_softc_t *sc, struct sc_cnstate *sp);
1806 sccnkbdlock(sc_softc_t *sc, struct sc_cnstate *sp)
1809 * Locking method: hope for the best.
1810 * The keyboard is supposed to be Giant locked. We can't handle that
1811 * in general. The kdb_active case here is not safe, and we will
1812 * proceed without the lock in all cases.
1814 sp->kbd_locked = !kdb_active && mtx_trylock(&Giant);
1818 sccnkbdunlock(sc_softc_t *sc, struct sc_cnstate *sp)
1822 sp->kbd_locked = FALSE;
1826 sccnscrlock(sc_softc_t *sc, struct sc_cnstate *sp)
1832 * - if kdb_active and video_mtx is not owned by anyone, then lock
1833 * by kdb remaining active
1834 * - if !kdb_active, try to acquire video_mtx without blocking or
1835 * recursing; if we get it then it works normally.
1836 * Note that video_mtx is especially unusable if we already own it,
1837 * since then it is protecting something and syscons is not reentrant
1838 * enough to ignore the protection even in the kdb_active case.
1841 sp->kdb_locked = sc->video_mtx.mtx_lock == MTX_UNOWNED ||
1842 SCHEDULER_STOPPED();
1843 sp->mtx_locked = FALSE;
1845 sp->kdb_locked = FALSE;
1846 for (retries = 0; retries < 1000; retries++) {
1847 sp->mtx_locked = mtx_trylock_spin_flags(
1848 &sc->video_mtx, MTX_QUIET) != 0;
1849 if (SCHEDULER_STOPPED()) {
1850 sp->kdb_locked = TRUE;
1851 sp->mtx_locked = FALSE;
1862 sccnscrunlock(sc_softc_t *sc, struct sc_cnstate *sp)
1865 mtx_unlock_spin(&sc->video_mtx);
1866 sp->mtx_locked = sp->kdb_locked = FALSE;
1870 sccnopen(sc_softc_t *sc, struct sc_cnstate *sp, int flags)
1874 /* assert(sc_console_unit >= 0) */
1876 sp->kbd_opened = FALSE;
1877 sp->scr_opened = FALSE;
1878 sp->kbd_locked = FALSE;
1880 /* Opening the keyboard is optional. */
1881 if (!(flags & 1) || sc->kbd == NULL)
1884 sccnkbdlock(sc, sp);
1887 * Make sure the keyboard is accessible even when the kbd device
1888 * driver is disabled.
1890 kbdd_enable(sc->kbd);
1892 /* Switch the keyboard to console mode (K_XLATE, polled) on all scp's.
1895 (void)kbdd_ioctl(sc->kbd, KDSKBMODE, (caddr_t)&kbd_mode);
1896 sc->kbd_open_level++;
1897 kbdd_poll(sc->kbd, TRUE);
1899 sp->kbd_opened = TRUE;
1902 /* The screen is opened iff locking it succeeds. */
1903 sccnscrlock(sc, sp);
1904 if (!sp->kdb_locked && !sp->mtx_locked)
1906 sp->scr_opened = TRUE;
1908 /* The screen switch is optional. */
1912 /* try to switch to the kernel console screen */
1913 if (!cold && sc->cur_scp->index != sc_console->index &&
1914 sc->cur_scp->smode.mode == VT_AUTO &&
1915 sc_console->smode.mode == VT_AUTO)
1916 sc_switch_scr(sc, sc_console->index);
1920 sccnclose(sc_softc_t *sc, struct sc_cnstate *sp)
1922 sp->scr_opened = FALSE;
1923 sccnscrunlock(sc, sp);
1925 if (!sp->kbd_opened)
1928 /* Restore keyboard mode (for the current, possibly-changed scp). */
1929 kbdd_poll(sc->kbd, FALSE);
1930 if (--sc->kbd_open_level == 0)
1932 sc->kbd, KDSKBMODE, (caddr_t)&sc->cur_scp->kbd_mode);
1934 kbdd_disable(sc->kbd);
1935 sp->kbd_opened = FALSE;
1936 sccnkbdunlock(sc, sp);
1940 * Grabbing switches the screen and keyboard focus to sc_console and the
1941 * keyboard mode to (K_XLATE, polled). Only switching to polled mode is
1942 * essential (for preventing the interrupt handler from eating input
1943 * between polls). Focus is part of the UI, and the other switches are
1944 * work just was well when they are done on every entry and exit.
1946 * Screen switches while grabbed are supported, and to maintain focus for
1947 * this ungrabbing and closing only restore the polling state and then
1948 * the keyboard mode if on the original screen.
1952 sc_cngrab(struct consdev *cp)
1957 sc = sc_console->sc;
1958 lev = atomic_fetchadd_int(&sc->grab_level, 1);
1959 if (lev >= 0 && lev < 2) {
1960 sccnopen(sc, &sc->grab_state[lev], 1 | 2);
1961 sccnscrunlock(sc, &sc->grab_state[lev]);
1962 sccnkbdunlock(sc, &sc->grab_state[lev]);
1967 sc_cnungrab(struct consdev *cp)
1972 sc = sc_console->sc;
1973 lev = atomic_load_acq_int(&sc->grab_level) - 1;
1974 if (lev >= 0 && lev < 2) {
1975 sccnkbdlock(sc, &sc->grab_state[lev]);
1976 sccnscrlock(sc, &sc->grab_state[lev]);
1977 sccnclose(sc, &sc->grab_state[lev]);
1979 atomic_add_int(&sc->grab_level, -1);
1982 static char sc_cnputc_log[0x1000];
1983 static u_int sc_cnputc_loghead;
1984 static u_int sc_cnputc_logtail;
1987 sc_cnputc(struct consdev *cd, int c)
1989 struct sc_cnstate st;
1991 scr_stat *scp = sc_console;
1993 struct sc_term_sw *oldtsw;
1994 #ifndef SC_NO_HISTORY
1998 #endif /* !SC_NO_HISTORY */
2002 /* assert(sc_console != NULL) */
2004 sccnopen(scp->sc, &st, 0);
2009 * In the unlocked case, the logging is intentionally only
2010 * perfectly atomic for the indexes.
2012 head = atomic_fetchadd_int(&sc_cnputc_loghead, 1);
2013 sc_cnputc_log[head % sizeof(sc_cnputc_log)] = c;
2016 * If we couldn't open, do special reentrant output and return to defer
2019 if (!st.scr_opened) {
2024 #ifndef SC_NO_HISTORY
2025 if (scp == scp->sc->cur_scp && scp->status & SLKED) {
2026 scp->status &= ~SLKED;
2027 update_kbd_state(scp, scp->status, SLKED);
2028 if (scp->status & BUFFER_SAVED) {
2029 if (!sc_hist_restore(scp))
2030 sc_remove_cutmarking(scp);
2031 scp->status &= ~BUFFER_SAVED;
2032 scp->status |= CURSOR_ENABLED;
2033 sc_draw_cursor_image(scp);
2037 * XXX: Now that TTY's have their own locks, we cannot process
2038 * any data after disabling scroll lock. cnputs already holds a
2041 tp = SC_DEV(scp->sc, scp->index);
2042 /* XXX "tp" can be NULL */
2045 sctty_outwakeup(tp);
2049 #endif /* !SC_NO_HISTORY */
2051 /* Play any output still in the log (our char may already be done). */
2052 while (sc_cnputc_logtail != atomic_load_acq_int(&sc_cnputc_loghead)) {
2054 sc_cnputc_log[sc_cnputc_logtail++ % sizeof(sc_cnputc_log)];
2055 if (atomic_load_acq_int(&sc_cnputc_loghead) -
2056 sc_cnputc_logtail >=
2057 sizeof(sc_cnputc_log))
2059 /* Console output has a per-CPU "input" state. Switch for it.
2061 ts = sc_kts[curcpu];
2067 (*scp->tsw->te_sync)(scp);
2069 /* Only 1 tsw early. Switch only its attr. */
2070 (*scp->tsw->te_default_attr)(
2071 scp, sc_kattrtab[curcpu], SC_KERNEL_CONS_REV_ATTR);
2073 sc_puts(scp, buf, 1);
2077 (*scp->tsw->te_sync)(scp);
2079 (*scp->tsw->te_default_attr)(
2080 scp, SC_KERNEL_CONS_ATTR, SC_KERNEL_CONS_REV_ATTR);
2084 s = spltty(); /* block sckbdevent and scrn_timer */
2087 sccnclose(scp->sc, &st);
2091 sc_cngetc(struct consdev *cd)
2093 struct sc_cnstate st;
2096 /* assert(sc_console != NULL) */
2097 sccnopen(sc_console->sc, &st, 1);
2098 s = spltty(); /* block sckbdevent and scrn_timer while we poll */
2099 if (!st.kbd_opened) {
2101 sccnclose(sc_console->sc, &st);
2102 return -1; /* means no keyboard since we fudged the locking */
2104 c = sc_cngetc_locked(&st);
2106 sccnclose(sc_console->sc, &st);
2111 sc_cngetc_locked(struct sc_cnstate *sp)
2113 static struct fkeytab fkey;
2120 * Stop the screen saver and update the screen if necessary.
2121 * What if we have been running in the screen saver code... XXX
2124 sc_touch_scrn_saver();
2125 scp = sc_console->sc->cur_scp; /* XXX */
2129 if (fkeycp < fkey.len)
2130 return fkey.str[fkeycp++];
2132 c = scgetc(scp->sc, SCGETC_CN | SCGETC_NONBLOCK, sp);
2134 switch (KEYFLAGS(c)) {
2135 case 0: /* normal char */
2137 case FKEY: /* function key */
2138 p = (*scp->tsw->te_fkeystr)(scp, c);
2140 fkey.len = strlen(p);
2141 bcopy(p, fkey.str, fkey.len);
2145 p = kbdd_get_fkeystr(
2146 scp->sc->kbd, KEYCHAR(c), (size_t *)&fkeycp);
2148 if ((p != NULL) && (fkey.len > 0)) {
2149 bcopy(p, fkey.str, fkey.len);
2163 sccnupdate(scr_stat *scp)
2165 /* this is a cut-down version of scrn_timer()... */
2167 if (suspend_in_progress || scp->sc->font_loading_in_progress)
2170 if (kdb_active || panicstr || shutdown_in_progress) {
2171 sc_touch_scrn_saver();
2172 } else if (scp != scp->sc->cur_scp) {
2176 if (!run_scrn_saver)
2177 scp->sc->flags &= ~SC_SCRN_IDLE;
2179 if ((saver_mode != CONS_LKM_SAVER) || !(scp->sc->flags & SC_SCRN_IDLE))
2180 if (scp->sc->flags & SC_SCRN_BLANKED)
2181 stop_scrn_saver(scp->sc, current_saver);
2184 if (scp != scp->sc->cur_scp || scp->sc->blink_in_progress ||
2185 scp->sc->switch_in_progress)
2188 * FIXME: unlike scrn_timer(), we call scrn_update() from here even
2189 * when write_in_progress is non-zero. XXX
2192 if (!ISGRAPHSC(scp) && !(scp->sc->flags & SC_SCRN_BLANKED))
2193 scrn_update(scp, TRUE);
2197 scrn_timer(void *arg)
2199 static time_t kbd_time_stamp = 0;
2204 again = (arg != NULL);
2206 sc = (sc_softc_t *)arg;
2207 else if (sc_console != NULL)
2208 sc = sc_console->sc;
2212 /* find the vty to update */
2215 /* don't do anything when we are performing some I/O operations */
2216 if (suspend_in_progress || sc->font_loading_in_progress)
2219 if ((sc->kbd == NULL) && (sc->config & SC_AUTODETECT_KBD)) {
2220 /* try to allocate a keyboard automatically */
2221 if (kbd_time_stamp != time_uptime) {
2222 kbd_time_stamp = time_uptime;
2223 sc->keyboard = sc_allocate_keyboard(sc, -1);
2224 if (sc->keyboard >= 0) {
2225 sc->kbd = kbd_get_keyboard(sc->keyboard);
2226 (void)kbdd_ioctl(sc->kbd, KDSKBMODE,
2227 (caddr_t)&sc->cur_scp->kbd_mode);
2228 update_kbd_state(sc->cur_scp,
2229 sc->cur_scp->status, LOCK_MASK);
2234 /* should we stop the screen saver? */
2235 if (kdb_active || panicstr || shutdown_in_progress)
2236 sc_touch_scrn_saver();
2237 if (run_scrn_saver) {
2238 if (time_uptime > sc->scrn_time_stamp + scrn_blank_time)
2239 sc->flags |= SC_SCRN_IDLE;
2241 sc->flags &= ~SC_SCRN_IDLE;
2243 sc->scrn_time_stamp = time_uptime;
2244 sc->flags &= ~SC_SCRN_IDLE;
2245 if (scrn_blank_time > 0)
2246 run_scrn_saver = TRUE;
2249 if ((saver_mode != CONS_LKM_SAVER) || !(sc->flags & SC_SCRN_IDLE))
2250 if (sc->flags & SC_SCRN_BLANKED)
2251 stop_scrn_saver(sc, current_saver);
2254 /* should we just return ? */
2255 if (sc->blink_in_progress || sc->switch_in_progress ||
2256 sc->write_in_progress)
2259 /* Update the screen */
2260 scp = sc->cur_scp; /* cur_scp may have changed... */
2261 if (!ISGRAPHSC(scp) && !(sc->flags & SC_SCRN_BLANKED))
2262 scrn_update(scp, TRUE);
2265 /* should we activate the screen saver? */
2266 if ((saver_mode == CONS_LKM_SAVER) && (sc->flags & SC_SCRN_IDLE))
2267 if (!ISGRAPHSC(scp) || (sc->flags & SC_SCRN_BLANKED))
2268 (*current_saver)(sc, TRUE);
2274 * Use reduced "refresh" rate if we are in graphics and that is
2275 * not a graphical screen saver. In such case we just have
2278 if (ISGRAPHSC(scp) && !(sc->flags & SC_SCRN_BLANKED))
2283 &sc->ctimeout, SBT_1S / rate, 0, scrn_timer, sc, C_PREL(1));
2288 and_region(int *s1, int *e1, int s2, int e2)
2290 if (*e1 < s2 || e2 < *s1)
2292 *s1 = imax(*s1, s2);
2293 *e1 = imin(*e1, e2);
2298 scrn_update(scr_stat *scp, int show_cursor)
2305 /* assert(scp == scp->sc->cur_scp) */
2307 SC_VIDEO_LOCK(scp->sc);
2309 #ifndef SC_NO_CUTPASTE
2310 /* remove the previous mouse pointer image if necessary */
2311 if (scp->status & MOUSE_VISIBLE) {
2313 e = scp->mouse_pos + scp->xsize + 1;
2314 if ((scp->status & (MOUSE_MOVED | MOUSE_HIDDEN)) ||
2315 and_region(&s, &e, scp->start, scp->end) ||
2316 ((scp->status & CURSOR_ENABLED) &&
2317 (scp->cursor_pos != scp->cursor_oldpos) &&
2318 (and_region(&s, &e, scp->cursor_pos, scp->cursor_pos) ||
2319 and_region(&s, &e, scp->cursor_oldpos,
2320 scp->cursor_oldpos)))) {
2321 sc_remove_mouse_image(scp);
2322 if (scp->end >= scp->xsize * scp->ysize)
2323 scp->end = scp->xsize * scp->ysize - 1;
2326 #endif /* !SC_NO_CUTPASTE */
2330 if (scp->end >= scp->xsize * scp->ysize) {
2331 printf("scrn_update(): scp->end %d > size_of_screen!!\n",
2333 scp->end = scp->xsize * scp->ysize - 1;
2335 if (scp->start < 0) {
2336 printf("scrn_update(): scp->start %d < 0\n", scp->start);
2341 /* update screen image */
2342 if (scp->start <= scp->end) {
2343 if (scp->mouse_cut_end >= 0) {
2344 /* there is a marked region for cut & paste */
2345 if (scp->mouse_cut_start <= scp->mouse_cut_end) {
2346 start = scp->mouse_cut_start;
2347 end = scp->mouse_cut_end;
2349 start = scp->mouse_cut_end;
2350 end = scp->mouse_cut_start - 1;
2354 /* does the cut-mark region overlap with the update
2356 if (and_region(&s, &e, scp->start, scp->end)) {
2357 (*scp->rndr->draw)(scp, s, e - s + 1, TRUE);
2360 if (and_region(&s, &e, scp->start, scp->end))
2362 scp, s, e - s + 1, FALSE);
2364 e = scp->xsize * scp->ysize - 1;
2365 if (and_region(&s, &e, scp->start, scp->end))
2367 scp, s, e - s + 1, FALSE);
2369 (*scp->rndr->draw)(scp, scp->start,
2370 scp->end - scp->start + 1, FALSE);
2374 scp, scp->start, scp->end - scp->start + 1, FALSE);
2378 /* we are not to show the cursor and the mouse pointer... */
2381 scp->start = scp->xsize * scp->ysize - 1;
2382 SC_VIDEO_UNLOCK(scp->sc);
2386 /* update cursor image */
2387 if (scp->status & CURSOR_ENABLED) {
2390 /* did cursor move since last time ? */
2391 if (scp->cursor_pos != scp->cursor_oldpos) {
2392 /* do we need to remove old cursor image ? */
2394 &s, &e, scp->cursor_oldpos, scp->cursor_oldpos))
2395 sc_remove_cursor_image(scp);
2396 sc_draw_cursor_image(scp);
2399 &s, &e, scp->cursor_pos, scp->cursor_pos))
2400 /* cursor didn't move, but has been overwritten
2402 sc_draw_cursor_image(scp);
2403 else if (scp->curs_attr.flags & CONS_BLINK_CURSOR)
2404 /* if it's a blinking cursor, update it */
2405 (*scp->rndr->blink_cursor)(scp, scp->cursor_pos,
2406 sc_inside_cutmark(scp, scp->cursor_pos));
2410 #ifndef SC_NO_CUTPASTE
2411 /* update "pseudo" mouse pointer image */
2412 if (scp->sc->flags & SC_MOUSE_ENABLED) {
2413 if (!(scp->status & (MOUSE_VISIBLE | MOUSE_HIDDEN))) {
2414 scp->status &= ~MOUSE_MOVED;
2415 sc_draw_mouse_image(scp);
2418 #endif /* SC_NO_CUTPASTE */
2421 scp->start = scp->xsize * scp->ysize - 1;
2423 SC_VIDEO_UNLOCK(scp->sc);
2428 scsplash_callback(int event, void *arg)
2433 sc = (sc_softc_t *)arg;
2437 if (add_scrn_saver(scsplash_saver) == 0) {
2438 sc->flags &= ~SC_SAVER_FAILED;
2439 run_scrn_saver = TRUE;
2440 if (cold && !(boothowto & RB_VERBOSE)) {
2441 scsplash_stick(TRUE);
2442 (*current_saver)(sc, TRUE);
2448 if (current_saver == scsplash_saver) {
2449 scsplash_stick(FALSE);
2450 error = remove_scrn_saver(scsplash_saver);
2462 scsplash_saver(sc_softc_t *sc, int show)
2464 static int busy = FALSE;
2473 if (!(sc->flags & SC_SAVER_FAILED)) {
2474 if (!(sc->flags & SC_SCRN_BLANKED))
2475 set_scrn_saver_mode(scp, -1, NULL, 0);
2476 switch (splash(sc->adp, TRUE)) {
2477 case 0: /* succeeded */
2479 case EAGAIN: /* try later */
2480 restore_scrn_saver_mode(scp, FALSE);
2481 sc_touch_scrn_saver(); /* XXX */
2484 sc->flags |= SC_SAVER_FAILED;
2485 scsplash_stick(FALSE);
2486 restore_scrn_saver_mode(scp, TRUE);
2488 "scsplash_saver(): failed to put up the image\n");
2492 } else if (!sticky_splash) {
2493 if ((sc->flags & SC_SCRN_BLANKED) &&
2494 (splash(sc->adp, FALSE) == 0))
2495 restore_scrn_saver_mode(scp, TRUE);
2501 add_scrn_saver(void (*this_saver)(sc_softc_t *, int))
2506 if (current_saver != none_saver) {
2507 error = remove_scrn_saver(current_saver);
2512 if (current_saver != none_saver)
2515 run_scrn_saver = FALSE;
2516 saver_mode = CONS_LKM_SAVER;
2517 current_saver = this_saver;
2522 remove_scrn_saver(void (*this_saver)(sc_softc_t *, int))
2524 if (current_saver != this_saver)
2529 * In order to prevent `current_saver' from being called by
2530 * the timeout routine `scrn_timer()' while we manipulate
2531 * the saver list, we shall set `current_saver' to `none_saver'
2532 * before stopping the current saver, rather than blocking by `splXX()'.
2534 current_saver = none_saver;
2536 stop_scrn_saver(this_saver);
2539 /* unblank all blanked screens */
2540 wait_scrn_saver_stop(NULL);
2544 current_saver = none_saver;
2549 set_scrn_saver_mode(scr_stat *scp, int mode, u_char *pal, int border)
2553 /* assert(scp == scp->sc->cur_scp) */
2555 if (!ISGRAPHSC(scp))
2556 sc_remove_cursor_image(scp);
2557 scp->splash_save_mode = scp->mode;
2558 scp->splash_save_status = scp->status & (GRAPHICS_MODE | PIXEL_MODE);
2559 scp->status &= ~(GRAPHICS_MODE | PIXEL_MODE);
2560 scp->status |= (UNKNOWN_MODE | SAVER_RUNNING);
2561 scp->sc->flags |= SC_SCRN_BLANKED;
2567 if (set_mode(scp) == 0) {
2568 if (scp->sc->adp->va_info.vi_flags & V_INFO_GRAPHICS)
2569 scp->status |= GRAPHICS_MODE;
2570 #ifndef SC_NO_PALETTE_LOADING
2572 vidd_load_palette(scp->sc->adp, pal);
2574 sc_set_border(scp, border);
2578 scp->mode = scp->splash_save_mode;
2579 scp->status &= ~(UNKNOWN_MODE | SAVER_RUNNING);
2580 scp->status |= scp->splash_save_status;
2587 restore_scrn_saver_mode(scr_stat *scp, int changemode)
2593 /* assert(scp == scp->sc->cur_scp) */
2596 status = scp->status;
2597 scp->mode = scp->splash_save_mode;
2598 scp->status &= ~(UNKNOWN_MODE | SAVER_RUNNING);
2599 scp->status |= scp->splash_save_status;
2600 scp->sc->flags &= ~SC_SCRN_BLANKED;
2602 if (!ISGRAPHSC(scp))
2603 sc_draw_cursor_image(scp);
2608 if (set_mode(scp) == 0) {
2609 #ifndef SC_NO_PALETTE_LOADING
2610 #ifdef SC_PIXEL_MODE
2611 if (scp->sc->adp->va_info.vi_mem_model == V_INFO_MM_DIRECT)
2612 vidd_load_palette(scp->sc->adp, scp->sc->palette2);
2615 vidd_load_palette(scp->sc->adp, scp->sc->palette);
2622 scp->status = status;
2629 stop_scrn_saver(sc_softc_t *sc, void (*saver)(sc_softc_t *, int))
2631 (*saver)(sc, FALSE);
2632 run_scrn_saver = FALSE;
2633 /* the screen saver may have chosen not to stop after all... */
2634 if (sc->flags & SC_SCRN_BLANKED)
2637 mark_all(sc->cur_scp);
2638 if (sc->delayed_next_scr)
2639 sc_switch_scr(sc, sc->delayed_next_scr - 1);
2641 wakeup(&scrn_blanked);
2645 wait_scrn_saver_stop(sc_softc_t *sc)
2649 while (scrn_blanked > 0) {
2650 run_scrn_saver = FALSE;
2651 if (sc && !(sc->flags & SC_SCRN_BLANKED)) {
2655 error = tsleep(&scrn_blanked, PZERO | PCATCH, "scrsav", 0);
2656 if ((error != 0) && (error != ERESTART))
2659 run_scrn_saver = FALSE;
2662 #endif /* DEV_SPLASH */
2665 sc_touch_scrn_saver(void)
2667 scsplash_stick(FALSE);
2668 run_scrn_saver = FALSE;
2672 sc_switch_scr(sc_softc_t *sc, u_int next_scr)
2679 DPRINTF(5, ("sc0: sc_switch_scr() %d ", next_scr + 1));
2681 if (sc->cur_scp == NULL)
2684 /* prevent switch if previously requested */
2685 if (sc->flags & SC_SCRN_VTYLOCK) {
2686 sc_bell(sc->cur_scp, sc->cur_scp->bell_pitch,
2687 sc->cur_scp->bell_duration);
2691 /* delay switch if the screen is blanked or being updated */
2692 if ((sc->flags & SC_SCRN_BLANKED) || sc->write_in_progress ||
2693 sc->blink_in_progress) {
2694 sc->delayed_next_scr = next_scr + 1;
2695 sc_touch_scrn_saver();
2696 DPRINTF(5, ("switch delayed\n"));
2699 sc->delayed_next_scr = 0;
2702 cur_scp = sc->cur_scp;
2704 /* we are in the middle of the vty switching process... */
2705 if (sc->switch_in_progress && (cur_scp->smode.mode == VT_PROCESS) &&
2707 p = pfind(cur_scp->pid);
2708 if (cur_scp->proc != p) {
2712 * The controlling process has died!!. Do some clean
2713 * up. NOTE:`cur_scp->proc' and `cur_scp->smode.mode'
2714 * are not reset here yet; they will be cleared later.
2717 ("cur_scp controlling process %d died, ",
2719 if (cur_scp->status & SWITCH_WAIT_REL) {
2721 * Force the previous switch to finish, but
2722 * return now with error.
2724 DPRINTF(5, ("reset WAIT_REL, "));
2725 finish_vt_rel(cur_scp, TRUE, &s);
2727 DPRINTF(5, ("finishing previous switch\n"));
2729 } else if (cur_scp->status & SWITCH_WAIT_ACQ) {
2730 /* let's assume screen switch has been
2732 DPRINTF(5, ("reset WAIT_ACQ, "));
2733 finish_vt_acq(cur_scp);
2736 * We are in between screen release and
2737 * acquisition, and reached here via scgetc() or
2738 * scrn_timer() which has interrupted
2739 * exchange_scr(). Don't do anything stupid.
2741 DPRINTF(5, ("waiting nothing, "));
2747 * The controlling process is alive, but not
2748 * responding... It is either buggy or it may be just
2749 * taking time. The following code is a gross kludge to
2750 * cope with this problem for which there is no clean
2753 if (cur_scp->status & SWITCH_WAIT_REL) {
2754 switch (sc->switch_in_progress++) {
2758 DPRINTF(5, ("sending relsig again, "));
2759 signal_vt_rel(cur_scp);
2766 * Act as if the controlling program
2767 * returned VT_FALSE.
2769 DPRINTF(5, ("force reset WAIT_REL, "));
2770 finish_vt_rel(cur_scp, FALSE, &s);
2773 ("act as if VT_FALSE was seen\n"));
2776 } else if (cur_scp->status & SWITCH_WAIT_ACQ) {
2777 switch (sc->switch_in_progress++) {
2781 DPRINTF(5, ("sending acqsig again, "));
2782 signal_vt_acq(cur_scp);
2788 /* clear the flag and finish the
2789 * previous switch */
2790 DPRINTF(5, ("force reset WAIT_ACQ, "));
2791 finish_vt_acq(cur_scp);
2799 * Return error if an invalid argument is given, or vty switch
2800 * is still in progress.
2802 if ((next_scr < sc->first_vty) ||
2803 (next_scr >= sc->first_vty + sc->vtys) || sc->switch_in_progress) {
2805 sc_bell(cur_scp, bios_value.bell_pitch, BELL_DURATION);
2806 DPRINTF(5, ("error 1\n"));
2811 * Don't allow switching away from the graphics mode vty
2812 * if the switch mode is VT_AUTO, unless the next vty is the same
2813 * as the current or the current vty has been closed (but showing).
2815 tp = SC_DEV(sc, cur_scp->index);
2816 if ((cur_scp->index != next_scr) && tty_opened_ns(tp) &&
2817 (cur_scp->smode.mode == VT_AUTO) && ISGRAPHSC(cur_scp)) {
2819 sc_bell(cur_scp, bios_value.bell_pitch, BELL_DURATION);
2820 DPRINTF(5, ("error, graphics mode\n"));
2825 * Is the wanted vty open? Don't allow switching to a closed vty.
2826 * If we are in DDB, don't switch to a vty in the VT_PROCESS mode.
2827 * Note that we always allow the user to switch to the kernel
2828 * console even if it is closed.
2830 if ((sc_console == NULL) || (next_scr != sc_console->index)) {
2831 tp = SC_DEV(sc, next_scr);
2832 if (!tty_opened_ns(tp)) {
2834 sc_bell(cur_scp, bios_value.bell_pitch, BELL_DURATION);
2835 DPRINTF(5, ("error 2, requested vty isn't open!\n"));
2838 if (kdb_active && SC_STAT(tp)->smode.mode == VT_PROCESS) {
2841 ("error 3, requested vty is in the VT_PROCESS mode\n"));
2846 /* this is the start of vty switching process... */
2847 ++sc->switch_in_progress;
2848 sc->old_scp = cur_scp;
2849 sc->new_scp = sc_get_stat(SC_DEV(sc, next_scr));
2850 if (sc->new_scp == sc->old_scp) {
2851 sc->switch_in_progress = 0;
2853 * XXX wakeup() locks the scheduler lock which will hang if
2854 * the lock is in an in-between state, e.g., when we stop at
2855 * a breakpoint at fork_exit. It has always been wrong to call
2856 * wakeup() when the debugger is active. In RELENG_4, wakeup()
2857 * is supposed to be locked by splhigh(), but the debugger may
2858 * be invoked at splhigh().
2861 wakeup(VTY_WCHAN(sc, next_scr));
2863 DPRINTF(5, ("switch done (new == old)\n"));
2867 /* has controlling process died? */
2868 vt_proc_alive(sc->old_scp);
2869 vt_proc_alive(sc->new_scp);
2871 /* wait for the controlling process to release the screen, if necessary
2873 if (signal_vt_rel(sc->old_scp)) {
2878 /* go set up the new vty screen */
2883 /* wake up processes waiting for this vty */
2885 wakeup(VTY_WCHAN(sc, next_scr));
2887 /* wait for the controlling process to acknowledge, if necessary */
2888 if (signal_vt_acq(sc->cur_scp)) {
2893 sc->switch_in_progress = 0;
2894 if (sc->unit == sc_console_unit)
2895 cnavailable(sc_consptr, TRUE);
2897 DPRINTF(5, ("switch done\n"));
2903 do_switch_scr(sc_softc_t *sc, int s)
2905 vt_proc_alive(sc->new_scp);
2910 /* sc->cur_scp == sc->new_scp */
2911 wakeup(VTY_WCHAN(sc, sc->cur_scp->index));
2913 /* wait for the controlling process to acknowledge, if necessary */
2914 if (!signal_vt_acq(sc->cur_scp)) {
2915 sc->switch_in_progress = 0;
2916 if (sc->unit == sc_console_unit)
2917 cnavailable(sc_consptr, TRUE);
2924 vt_proc_alive(scr_stat *scp)
2929 if ((p = pfind(scp->pid)) != NULL)
2934 scp->smode.mode = VT_AUTO;
2935 DPRINTF(5, ("vt controlling process %d died\n", scp->pid));
2941 signal_vt_rel(scr_stat *scp)
2943 if (scp->smode.mode != VT_PROCESS)
2945 scp->status |= SWITCH_WAIT_REL;
2946 PROC_LOCK(scp->proc);
2947 kern_psignal(scp->proc, scp->smode.relsig);
2948 PROC_UNLOCK(scp->proc);
2949 DPRINTF(5, ("sending relsig to %d\n", scp->pid));
2954 signal_vt_acq(scr_stat *scp)
2956 if (scp->smode.mode != VT_PROCESS)
2958 if (scp->sc->unit == sc_console_unit)
2959 cnavailable(sc_consptr, FALSE);
2960 scp->status |= SWITCH_WAIT_ACQ;
2961 PROC_LOCK(scp->proc);
2962 kern_psignal(scp->proc, scp->smode.acqsig);
2963 PROC_UNLOCK(scp->proc);
2964 DPRINTF(5, ("sending acqsig to %d\n", scp->pid));
2969 finish_vt_rel(scr_stat *scp, int release, int *s)
2971 if (scp == scp->sc->old_scp && scp->status & SWITCH_WAIT_REL) {
2972 scp->status &= ~SWITCH_WAIT_REL;
2974 *s = do_switch_scr(scp->sc, *s);
2976 scp->sc->switch_in_progress = 0;
2983 finish_vt_acq(scr_stat *scp)
2985 if (scp == scp->sc->new_scp && scp->status & SWITCH_WAIT_ACQ) {
2986 scp->status &= ~SWITCH_WAIT_ACQ;
2987 scp->sc->switch_in_progress = 0;
2994 exchange_scr(sc_softc_t *sc)
2998 /* save the current state of video and keyboard */
2999 sc_move_cursor(sc->old_scp, sc->old_scp->xpos, sc->old_scp->ypos);
3000 if (!ISGRAPHSC(sc->old_scp))
3001 sc_remove_cursor_image(sc->old_scp);
3002 if (sc->old_scp->kbd_mode == K_XLATE)
3003 save_kbd_state(sc->old_scp);
3005 /* set up the video for the new screen */
3006 scp = sc->cur_scp = sc->new_scp;
3007 if (sc->old_scp->mode != scp->mode || ISUNKNOWNSC(sc->old_scp))
3011 sc_vtb_init(&scp->scr, VTB_FRAMEBUFFER, scp->xsize, scp->ysize,
3012 (void *)sc->adp->va_window, FALSE);
3014 scp->status |= MOUSE_HIDDEN;
3015 sc_move_cursor(scp, scp->xpos, scp->ypos);
3016 if (!ISGRAPHSC(scp))
3017 sc_set_cursor_image(scp);
3018 #ifndef SC_NO_PALETTE_LOADING
3019 if (ISGRAPHSC(sc->old_scp)) {
3020 #ifdef SC_PIXEL_MODE
3021 if (sc->adp->va_info.vi_mem_model == V_INFO_MM_DIRECT)
3022 vidd_load_palette(sc->adp, sc->palette2);
3025 vidd_load_palette(sc->adp, sc->palette);
3028 sc_set_border(scp, scp->border);
3030 /* set up the keyboard for the new screen */
3031 if (sc->kbd_open_level == 0 && sc->old_scp->kbd_mode != scp->kbd_mode)
3032 (void)kbdd_ioctl(sc->kbd, KDSKBMODE, (caddr_t)&scp->kbd_mode);
3033 update_kbd_state(scp, scp->status, LOCK_MASK);
3039 sc_puts(scr_stat *scp, u_char *buf, int len)
3042 /* make screensaver happy */
3043 if (!sticky_splash && scp == scp->sc->cur_scp && !sc_saver_keyb_only)
3044 run_scrn_saver = FALSE;
3048 (*scp->tsw->te_puts)(scp, buf, len);
3049 if (scp->sc->delayed_next_scr)
3050 sc_switch_scr(scp->sc, scp->sc->delayed_next_scr - 1);
3054 sc_draw_cursor_image(scr_stat *scp)
3056 /* assert(scp == scp->sc->cur_scp); */
3057 SC_VIDEO_LOCK(scp->sc);
3058 (*scp->rndr->draw_cursor)(scp, scp->cursor_pos,
3059 scp->curs_attr.flags & CONS_BLINK_CURSOR, TRUE,
3060 sc_inside_cutmark(scp, scp->cursor_pos));
3061 scp->cursor_oldpos = scp->cursor_pos;
3062 SC_VIDEO_UNLOCK(scp->sc);
3066 sc_remove_cursor_image(scr_stat *scp)
3068 /* assert(scp == scp->sc->cur_scp); */
3069 SC_VIDEO_LOCK(scp->sc);
3070 (*scp->rndr->draw_cursor)(scp, scp->cursor_oldpos,
3071 scp->curs_attr.flags & CONS_BLINK_CURSOR, FALSE,
3072 sc_inside_cutmark(scp, scp->cursor_oldpos));
3073 SC_VIDEO_UNLOCK(scp->sc);
3077 update_cursor_image(scr_stat *scp)
3079 /* assert(scp == scp->sc->cur_scp); */
3080 sc_remove_cursor_image(scp);
3081 sc_set_cursor_image(scp);
3082 sc_draw_cursor_image(scp);
3086 sc_set_cursor_image(scr_stat *scp)
3088 scp->curs_attr = scp->base_curs_attr;
3089 if (scp->curs_attr.flags & CONS_HIDDEN_CURSOR) {
3090 /* hidden cursor is internally represented as zero-height
3092 scp->curs_attr.flags = CONS_CHAR_CURSOR;
3093 scp->curs_attr.base = scp->curs_attr.height = 0;
3094 } else if (scp->curs_attr.flags & CONS_CHAR_CURSOR) {
3095 scp->curs_attr.base =
3096 imin(scp->base_curs_attr.base, scp->font_size - 1);
3097 scp->curs_attr.height = imin(scp->base_curs_attr.height,
3098 scp->font_size - scp->curs_attr.base);
3099 } else { /* block cursor */
3100 scp->curs_attr.base = 0;
3101 scp->curs_attr.height = scp->font_size;
3104 /* assert(scp == scp->sc->cur_scp); */
3105 SC_VIDEO_LOCK(scp->sc);
3106 (*scp->rndr->set_cursor)(scp, scp->curs_attr.base,
3107 scp->curs_attr.height, scp->curs_attr.flags & CONS_BLINK_CURSOR);
3108 SC_VIDEO_UNLOCK(scp->sc);
3112 sc_adjust_ca(struct cursor_attr *cap, int flags, int base, int height)
3114 if (flags & CONS_CHARCURSOR_COLORS) {
3115 cap->bg[0] = base & 0xff;
3116 cap->bg[1] = height & 0xff;
3117 } else if (flags & CONS_MOUSECURSOR_COLORS) {
3118 cap->mouse_ba = base & 0xff;
3119 cap->mouse_ia = height & 0xff;
3124 cap->height = height;
3125 if (!(flags & CONS_SHAPEONLY_CURSOR))
3126 cap->flags = flags & CONS_CURSOR_ATTRS;
3131 change_cursor_shape(scr_stat *scp, int flags, int base, int height)
3133 if ((scp == scp->sc->cur_scp) && !ISGRAPHSC(scp))
3134 sc_remove_cursor_image(scp);
3136 if (flags & CONS_RESET_CURSOR)
3137 scp->base_curs_attr = scp->dflt_curs_attr;
3138 else if (flags & CONS_DEFAULT_CURSOR) {
3139 sc_adjust_ca(&scp->dflt_curs_attr, flags, base, height);
3140 scp->base_curs_attr = scp->dflt_curs_attr;
3142 sc_adjust_ca(&scp->base_curs_attr, flags, base, height);
3144 if ((scp == scp->sc->cur_scp) && !ISGRAPHSC(scp)) {
3145 sc_set_cursor_image(scp);
3146 sc_draw_cursor_image(scp);
3151 sc_change_cursor_shape(scr_stat *scp, int flags, int base, int height)
3159 flags = CONS_SHAPEONLY_CURSOR;
3162 if (flags & CONS_LOCAL_CURSOR) {
3163 /* local (per vty) change */
3164 change_cursor_shape(scp, flags, base, height);
3171 if (flags & CONS_RESET_CURSOR)
3172 sc->curs_attr = sc->dflt_curs_attr;
3173 else if (flags & CONS_DEFAULT_CURSOR) {
3174 sc_adjust_ca(&sc->dflt_curs_attr, flags, base, height);
3175 sc->curs_attr = sc->dflt_curs_attr;
3177 sc_adjust_ca(&sc->curs_attr, flags, base, height);
3179 for (i = sc->first_vty; i < sc->first_vty + sc->vtys; ++i) {
3180 if ((tp = SC_DEV(sc, i)) == NULL)
3182 if ((scp = sc_get_stat(tp)) == NULL)
3184 scp->dflt_curs_attr = sc->curs_attr;
3185 change_cursor_shape(scp, CONS_RESET_CURSOR, -1, -1);
3191 scinit(int unit, int flags)
3195 * When syscons is being initialized as the kernel console, malloc()
3196 * is not yet functional, because various kernel structures has not been
3197 * fully initialized yet. Therefore, we need to declare the following
3198 * static buffers for the console. This is less than ideal,
3199 * but is necessry evil for the time being. XXX
3201 static u_short sc_buffer[ROW * COL]; /* XXX */
3202 #ifndef SC_NO_FONT_LOADING
3203 static u_char font_8[256 * 8];
3204 static u_char font_14[256 * 14];
3205 static u_char font_16[256 * 16];
3208 #ifdef SC_KERNEL_CONS_ATTRS
3209 static const u_char dflt_kattrtab[] = SC_KERNEL_CONS_ATTRS;
3210 #elif SC_KERNEL_CONS_ATTR == FG_WHITE
3211 static const u_char dflt_kattrtab[] = {
3223 static const u_char dflt_kattrtab[] = {
3230 video_adapter_t *adp;
3235 /* one time initialization */
3236 if (init_done == COLD) {
3237 sc_get_bios_values(&bios_value);
3238 for (i = 0; i < nitems(sc_kattrtab); i++)
3240 dflt_kattrtab[i % (nitems(dflt_kattrtab) - 1)];
3245 * Allocate resources. Even if we are being called for the second
3246 * time, we must allocate them again, because they might have
3249 sc = sc_get_softc(unit, flags & SC_KERNEL_CONSOLE);
3250 if ((sc->flags & SC_INIT_DONE) == 0)
3251 SC_VIDEO_LOCKINIT(sc);
3254 if (sc->adapter >= 0) {
3255 vid_release(sc->adp, (void *)&sc->adapter);
3259 if (sc->keyboard >= 0) {
3260 DPRINTF(5, ("sc%d: releasing kbd%d\n", unit, sc->keyboard));
3261 i = kbd_release(sc->kbd, (void *)&sc->keyboard);
3262 DPRINTF(5, ("sc%d: kbd_release returned %d\n", unit, i));
3263 if (sc->kbd != NULL) {
3265 ("sc%d: kbd != NULL!, index:%d, unit:%d, flags:0x%x\n",
3266 unit, sc->kbd->kb_index, sc->kbd->kb_unit,
3267 sc->kbd->kb_flags));
3271 sc->adapter = vid_allocate("*", unit, (void *)&sc->adapter);
3272 sc->adp = vid_get_adapter(sc->adapter);
3273 /* assert((sc->adapter >= 0) && (sc->adp != NULL)) */
3275 sc->keyboard = sc_allocate_keyboard(sc, unit);
3276 DPRINTF(1, ("sc%d: keyboard %d\n", unit, sc->keyboard));
3278 sc->kbd = kbd_get_keyboard(sc->keyboard);
3279 if (sc->kbd != NULL) {
3281 ("sc%d: kbd index:%d, unit:%d, flags:0x%x\n", unit,
3282 sc->kbd->kb_index, sc->kbd->kb_unit,
3283 sc->kbd->kb_flags));
3286 if (!(sc->flags & SC_INIT_DONE) || (adp != sc->adp)) {
3288 sc->initial_mode = sc->adp->va_initial_mode;
3290 #ifndef SC_NO_FONT_LOADING
3291 if (flags & SC_KERNEL_CONSOLE) {
3292 sc->font_8 = font_8;
3293 sc->font_14 = font_14;
3294 sc->font_16 = font_16;
3295 } else if (sc->font_8 == NULL) {
3296 /* assert(sc_malloc) */
3297 sc->font_8 = malloc(sizeof(font_8), M_DEVBUF, M_WAITOK);
3299 malloc(sizeof(font_14), M_DEVBUF, M_WAITOK);
3301 malloc(sizeof(font_16), M_DEVBUF, M_WAITOK);
3305 /* extract the hardware cursor location and hide the cursor for
3307 vidd_read_hw_cursor(sc->adp, &col, &row);
3308 vidd_set_hw_cursor(sc->adp, -1, -1);
3310 /* set up the first console */
3311 sc->first_vty = unit * MAXCONS;
3312 sc->vtys = MAXCONS; /* XXX: should be configurable */
3313 if (flags & SC_KERNEL_CONSOLE) {
3315 * Set up devs structure but don't use it yet, calling
3316 * make_dev() might panic kernel. Wait for
3317 * sc_attach_unit() to actually create the devices.
3319 sc->dev = main_devs;
3320 scp = &main_console;
3321 init_scp(sc, sc->first_vty, scp);
3322 sc_vtb_init(&scp->vtb, VTB_MEMORY, scp->xsize,
3323 scp->ysize, (void *)sc_buffer, FALSE);
3324 if (sc_init_emulator(scp, SC_DFLT_TERM))
3325 sc_init_emulator(scp, "*");
3326 (*scp->tsw->te_default_attr)(
3327 scp, SC_KERNEL_CONS_ATTR, SC_KERNEL_CONS_REV_ATTR);
3329 /* assert(sc_malloc) */
3330 sc->dev = malloc(sizeof(struct tty *) * sc->vtys,
3331 M_DEVBUF, M_WAITOK | M_ZERO);
3332 sc->dev[0] = sc_alloc_tty(0, unit * MAXCONS);
3333 scp = alloc_scp(sc, sc->first_vty);
3334 SC_STAT(sc->dev[0]) = scp;
3339 /* copy screen to temporary buffer */
3340 sc_vtb_init(&scp->scr, VTB_FRAMEBUFFER, scp->xsize, scp->ysize,
3341 (void *)scp->sc->adp->va_window, FALSE);
3343 sc_vtb_copy(&scp->scr, 0, &scp->vtb, 0,
3344 scp->xsize * scp->ysize);
3347 /* Sync h/w cursor position to s/w (sc and teken). */
3348 if (col >= scp->xsize)
3350 if (row >= scp->ysize)
3351 row = scp->ysize - 1;
3354 scp->cursor_pos = scp->cursor_oldpos = row * scp->xsize + col;
3355 (*scp->tsw->te_sync)(scp);
3357 sc->dflt_curs_attr.base = 0;
3358 sc->dflt_curs_attr.height = howmany(scp->font_size, 8);
3359 sc->dflt_curs_attr.flags = 0;
3360 sc->dflt_curs_attr.bg[0] = FG_RED;
3361 sc->dflt_curs_attr.bg[1] = FG_LIGHTGREY;
3362 sc->dflt_curs_attr.bg[2] = FG_BLUE;
3363 sc->dflt_curs_attr.mouse_ba = FG_WHITE;
3364 sc->dflt_curs_attr.mouse_ia = FG_RED;
3365 sc->curs_attr = sc->dflt_curs_attr;
3366 scp->base_curs_attr = scp->dflt_curs_attr = sc->curs_attr;
3367 scp->curs_attr = scp->base_curs_attr;
3369 #ifndef SC_NO_SYSMOUSE
3370 sc_mouse_move(scp, scp->xpixel / 2, scp->ypixel / 2);
3372 if (!ISGRAPHSC(scp)) {
3373 sc_set_cursor_image(scp);
3374 sc_draw_cursor_image(scp);
3377 /* save font and palette */
3378 #ifndef SC_NO_FONT_LOADING
3379 sc->fonts_loaded = 0;
3380 if (ISFONTAVAIL(sc->adp->va_flags)) {
3382 bcopy(dflt_font_8, sc->font_8, sizeof(dflt_font_8));
3383 bcopy(dflt_font_14, sc->font_14, sizeof(dflt_font_14));
3384 bcopy(dflt_font_16, sc->font_16, sizeof(dflt_font_16));
3385 sc->fonts_loaded = FONT_16 | FONT_14 | FONT_8;
3386 if (scp->font_size < 14) {
3387 sc_load_font(scp, 0, 8, 8, sc->font_8, 0, 256);
3388 } else if (scp->font_size >= 16) {
3390 scp, 0, 16, 8, sc->font_16, 0, 256);
3393 scp, 0, 14, 8, sc->font_14, 0, 256);
3395 #else /* !SC_DFLT_FONT */
3396 if (scp->font_size < 14) {
3397 sc_save_font(scp, 0, 8, 8, sc->font_8, 0, 256);
3398 sc->fonts_loaded = FONT_8;
3399 } else if (scp->font_size >= 16) {
3401 scp, 0, 16, 8, sc->font_16, 0, 256);
3402 sc->fonts_loaded = FONT_16;
3405 scp, 0, 14, 8, sc->font_14, 0, 256);
3406 sc->fonts_loaded = FONT_14;
3408 #endif /* SC_DFLT_FONT */
3409 /* FONT KLUDGE: always use the font page #0. XXX */
3410 sc_show_font(scp, 0);
3412 #endif /* !SC_NO_FONT_LOADING */
3414 #ifndef SC_NO_PALETTE_LOADING
3415 vidd_save_palette(sc->adp, sc->palette);
3416 #ifdef SC_PIXEL_MODE
3417 for (i = 0; i < sizeof(sc->palette2); i++)
3418 sc->palette2[i] = i / 3;
3423 if (!(sc->flags & SC_SPLASH_SCRN)) {
3424 /* we are ready to put up the splash image! */
3425 splash_init(sc->adp, scsplash_callback, sc);
3426 sc->flags |= SC_SPLASH_SCRN;
3431 /* the rest is not necessary, if we have done it once */
3432 if (sc->flags & SC_INIT_DONE)
3435 /* initialize mapscrn arrays to a one to one map */
3436 for (i = 0; i < sizeof(sc->scr_map); i++)
3437 sc->scr_map[i] = sc->scr_rmap[i] = i;
3439 sc->flags |= SC_INIT_DONE;
3443 scterm(int unit, int flags)
3448 sc = sc_get_softc(unit, flags & SC_KERNEL_CONSOLE);
3450 return; /* shouldn't happen */
3453 /* this console is no longer available for the splash screen */
3454 if (sc->flags & SC_SPLASH_SCRN) {
3455 splash_term(sc->adp);
3456 sc->flags &= ~SC_SPLASH_SCRN;
3461 /* move the hardware cursor to the upper-left corner */
3462 vidd_set_hw_cursor(sc->adp, 0, 0);
3465 /* release the keyboard and the video card */
3466 if (sc->keyboard >= 0)
3467 kbd_release(sc->kbd, &sc->keyboard);
3468 if (sc->adapter >= 0)
3469 vid_release(sc->adp, &sc->adapter);
3471 /* stop the terminal emulator, if any */
3472 scp = sc_get_stat(sc->dev[0]);
3474 (*scp->tsw->te_term)(scp, &scp->ts);
3475 mtx_destroy(&sc->video_mtx);
3477 /* clear the structure */
3478 if (!(flags & SC_KERNEL_CONSOLE)) {
3479 free(scp->ts, M_DEVBUF);
3480 /* XXX: We need delete_dev() for this */
3481 free(sc->dev, M_DEVBUF);
3483 /* XXX: We need a ttyunregister for this */
3484 free(sc->tty, M_DEVBUF);
3486 #ifndef SC_NO_FONT_LOADING
3487 free(sc->font_8, M_DEVBUF);
3488 free(sc->font_14, M_DEVBUF);
3489 free(sc->font_16, M_DEVBUF);
3491 /* XXX vtb, history */
3493 bzero(sc, sizeof(*sc));
3499 scshutdown(__unused void *arg, __unused int howto)
3502 KASSERT(sc_console != NULL, ("sc_console != NULL"));
3503 KASSERT(sc_console->sc != NULL, ("sc_console->sc != NULL"));
3504 KASSERT(sc_console->sc->cur_scp != NULL,
3505 ("sc_console->sc->cur_scp != NULL"));
3507 sc_touch_scrn_saver();
3508 if (!cold && sc_console->sc->cur_scp->index != sc_console->index &&
3509 sc_console->sc->cur_scp->smode.mode == VT_AUTO &&
3510 sc_console->smode.mode == VT_AUTO)
3511 sc_switch_scr(sc_console->sc, sc_console->index);
3512 shutdown_in_progress = TRUE;
3516 scsuspend(__unused void *arg)
3520 KASSERT(sc_console != NULL, ("sc_console != NULL"));
3521 KASSERT(sc_console->sc != NULL, ("sc_console->sc != NULL"));
3522 KASSERT(sc_console->sc->cur_scp != NULL,
3523 ("sc_console->sc->cur_scp != NULL"));
3525 sc_susp_scr = sc_console->sc->cur_scp->index;
3526 if (sc_no_suspend_vtswitch || sc_susp_scr == sc_console->index) {
3527 sc_touch_scrn_saver();
3531 for (retry = 0; retry < 10; retry++) {
3532 sc_switch_scr(sc_console->sc, sc_console->index);
3533 if (!sc_console->sc->switch_in_progress)
3535 pause("scsuspend", hz);
3537 suspend_in_progress = TRUE;
3541 scresume(__unused void *arg)
3544 KASSERT(sc_console != NULL, ("sc_console != NULL"));
3545 KASSERT(sc_console->sc != NULL, ("sc_console->sc != NULL"));
3546 KASSERT(sc_console->sc->cur_scp != NULL,
3547 ("sc_console->sc->cur_scp != NULL"));
3549 suspend_in_progress = FALSE;
3550 if (sc_susp_scr < 0) {
3551 update_font(sc_console->sc->cur_scp);
3554 sc_switch_scr(sc_console->sc, sc_susp_scr);
3558 sc_clean_up(scr_stat *scp)
3564 if (scp->sc->flags & SC_SCRN_BLANKED) {
3565 sc_touch_scrn_saver();
3567 if ((error = wait_scrn_saver_stop(scp->sc)))
3571 scp->status |= MOUSE_HIDDEN;
3572 sc_remove_mouse_image(scp);
3573 sc_remove_cutmarking(scp);
3578 sc_alloc_scr_buffer(scr_stat *scp, int wait, int discard)
3584 sc_vtb_init(&new, VTB_MEMORY, scp->xsize, scp->ysize, NULL, wait);
3585 if (!discard && (old.vtb_flags & VTB_VALID)) {
3586 /* retain the current cursor position and buffer contants */
3587 scp->cursor_oldpos = scp->cursor_pos;
3589 * This works only if the old buffer has the same size as or
3590 * larger than the new one. XXX
3592 sc_vtb_copy(&old, 0, &new, 0, scp->xsize * scp->ysize);
3596 sc_vtb_destroy(&old);
3599 #ifndef SC_NO_SYSMOUSE
3600 /* move the mouse cursor at the center of the screen */
3601 sc_mouse_move(scp, scp->xpixel / 2, scp->ypixel / 2);
3606 alloc_scp(sc_softc_t *sc, int vty)
3610 /* assert(sc_malloc) */
3612 scp = (scr_stat *)malloc(sizeof(scr_stat), M_DEVBUF, M_WAITOK);
3613 init_scp(sc, vty, scp);
3615 sc_alloc_scr_buffer(scp, TRUE, TRUE);
3616 if (sc_init_emulator(scp, SC_DFLT_TERM))
3617 sc_init_emulator(scp, "*");
3619 #ifndef SC_NO_CUTPASTE
3620 sc_alloc_cut_buffer(scp, TRUE);
3623 #ifndef SC_NO_HISTORY
3624 sc_alloc_history_buffer(scp, 0, 0, TRUE);
3631 init_scp(sc_softc_t *sc, int vty, scr_stat *scp)
3635 bzero(scp, sizeof(*scp));
3640 scp->mode = sc->initial_mode;
3641 vidd_get_info(sc->adp, scp->mode, &info);
3642 if (info.vi_flags & V_INFO_GRAPHICS) {
3643 scp->status |= GRAPHICS_MODE;
3644 scp->xpixel = info.vi_width;
3645 scp->ypixel = info.vi_height;
3646 scp->xsize = info.vi_width / info.vi_cwidth;
3647 scp->ysize = info.vi_height / info.vi_cheight;
3651 scp->xsize = info.vi_width;
3652 scp->ysize = info.vi_height;
3653 scp->xpixel = scp->xsize * info.vi_cwidth;
3654 scp->ypixel = scp->ysize * info.vi_cheight;
3657 scp->font_size = info.vi_cheight;
3658 scp->font_width = info.vi_cwidth;
3659 #ifndef SC_NO_FONT_LOADING
3660 if (info.vi_cheight < 14)
3661 scp->font = sc->font_8;
3662 else if (info.vi_cheight >= 16)
3663 scp->font = sc->font_16;
3665 scp->font = sc->font_14;
3670 sc_vtb_init(&scp->vtb, VTB_MEMORY, 0, 0, NULL, FALSE);
3672 sc_vtb_init(&scp->scr, VTB_FRAMEBUFFER, 0, 0, NULL, FALSE);
3674 scp->xoff = scp->yoff = 0;
3675 scp->xpos = scp->ypos = 0;
3676 scp->start = scp->xsize * scp->ysize - 1;
3681 scp->border = (SC_NORM_ATTR >> 4) & 0x0f;
3682 scp->base_curs_attr = scp->dflt_curs_attr = sc->curs_attr;
3683 scp->mouse_cut_start = scp->xsize * scp->ysize;
3684 scp->mouse_cut_end = -1;
3685 scp->mouse_signal = 0;
3687 scp->mouse_proc = NULL;
3688 scp->kbd_mode = K_XLATE;
3689 scp->bell_pitch = bios_value.bell_pitch;
3690 scp->bell_duration = BELL_DURATION;
3691 scp->status |= (bios_value.shift_state & NLKED);
3692 scp->status |= CURSOR_ENABLED | MOUSE_HIDDEN;
3695 scp->smode.mode = VT_AUTO;
3696 scp->history = NULL;
3697 scp->history_pos = 0;
3698 scp->history_size = 0;
3702 sc_init_emulator(scr_stat *scp, char *name)
3709 if (name == NULL) /* if no name is given, use the current emulator */
3711 else /* ...otherwise find the named emulator */
3712 sw = sc_term_match(name);
3717 if (strcmp(sw->te_renderer, "*") != 0) {
3718 rndr = sc_render_match(scp, sw->te_renderer,
3719 scp->status & (GRAPHICS_MODE | PIXEL_MODE));
3722 rndr = sc_render_match(scp, scp->sc->adp->va_name,
3723 scp->status & (GRAPHICS_MODE | PIXEL_MODE));
3728 if (sw == scp->tsw) {
3729 error = (*sw->te_init)(scp, &scp->ts, SC_TE_WARM_INIT);
3731 scp->rndr->init(scp);
3732 sc_clear_screen(scp);
3733 /* assert(error == 0); */
3737 if (sc_malloc && (sw->te_size > 0))
3738 p = malloc(sw->te_size, M_DEVBUF, M_NOWAIT);
3741 error = (*sw->te_init)(scp, &p, SC_TE_COLD_INIT);
3746 (*scp->tsw->te_term)(scp, &scp->ts);
3747 if (scp->ts != NULL)
3748 free(scp->ts, M_DEVBUF);
3752 scp->rndr->init(scp);
3754 (*sw->te_default_attr)(scp, SC_NORM_ATTR, SC_NORM_REV_ATTR);
3755 sc_clear_screen(scp);
3761 * scgetc(flags) - get character from keyboard.
3762 * If flags & SCGETC_CN, then avoid harmful side effects.
3763 * If flags & SCGETC_NONBLOCK, then wait until a key is pressed, else
3764 * return NOKEY if there is nothing there.
3767 scgetc(sc_softc_t *sc, u_int flags, struct sc_cnstate *sp)
3770 #ifndef SC_NO_HISTORY
3778 if (sc->kbd == NULL)
3783 /* I don't like this, but... XXX */
3784 if (flags & SCGETC_CN)
3785 sccnupdate(sc->cur_scp);
3788 /* first see if there is something in the keyboard port */
3790 if (flags & SCGETC_CN)
3791 sccnscrunlock(sc, sp);
3792 c = kbdd_read_char(sc->kbd, !(flags & SCGETC_NONBLOCK));
3793 if (flags & SCGETC_CN)
3794 sccnscrlock(sc, sp);
3796 if (!(flags & SCGETC_CN))
3798 scp, bios_value.bell_pitch, BELL_DURATION);
3799 } else if (c == NOKEY)
3805 /* make screensaver happy */
3807 sc_touch_scrn_saver();
3809 if (!(flags & SCGETC_CN))
3810 random_harvest_queue(&c, sizeof(c), RANDOM_KEYBOARD);
3812 if (sc->kbd_open_level == 0 && scp->kbd_mode != K_XLATE)
3815 /* if scroll-lock pressed allow history browsing */
3816 if (!ISGRAPHSC(scp) && scp->history && scp->status & SLKED) {
3818 scp->status &= ~CURSOR_ENABLED;
3819 sc_remove_cursor_image(scp);
3821 #ifndef SC_NO_HISTORY
3822 if (!(scp->status & BUFFER_SAVED)) {
3823 scp->status |= BUFFER_SAVED;
3827 /* FIXME: key codes */
3828 case SPCLKEY | FKEY | F(49): /* home key */
3829 sc_remove_cutmarking(scp);
3833 case SPCLKEY | FKEY | F(57): /* end key */
3834 sc_remove_cutmarking(scp);
3838 case SPCLKEY | FKEY | F(50): /* up arrow key */
3839 sc_remove_cutmarking(scp);
3840 if (sc_hist_up_line(scp))
3841 if (!(flags & SCGETC_CN))
3842 sc_bell(scp, bios_value.bell_pitch,
3846 case SPCLKEY | FKEY | F(58): /* down arrow key */
3847 sc_remove_cutmarking(scp);
3848 if (sc_hist_down_line(scp))
3849 if (!(flags & SCGETC_CN))
3850 sc_bell(scp, bios_value.bell_pitch,
3854 case SPCLKEY | FKEY | F(51): /* page up key */
3855 sc_remove_cutmarking(scp);
3856 for (i = 0; i < scp->ysize; i++)
3857 if (sc_hist_up_line(scp)) {
3858 if (!(flags & SCGETC_CN))
3860 bios_value.bell_pitch,
3866 case SPCLKEY | FKEY | F(59): /* page down key */
3867 sc_remove_cutmarking(scp);
3868 for (i = 0; i < scp->ysize; i++)
3869 if (sc_hist_down_line(scp)) {
3870 if (!(flags & SCGETC_CN))
3872 bios_value.bell_pitch,
3878 #endif /* SC_NO_HISTORY */
3882 * Process and consume special keys here. Return a plain char code
3883 * or a char code with the META flag or a function key code.
3887 /* goto next_code */
3892 switch (KEYCHAR(c)) {
3900 sc->kbd, KDGKBSTATE, (caddr_t)&f);
3902 scp->status |= SLKED;
3904 if (scp->status & SLKED) {
3905 scp->status &= ~SLKED;
3906 #ifndef SC_NO_HISTORY
3909 if (!sc_hist_restore(
3911 sc_remove_cutmarking(
3917 sc_draw_cursor_image(
3920 /* Only safe in Giant-locked
3922 tp = SC_DEV(sc, scp->index);
3923 if (!(flags & SCGETC_CN) &&
3925 sctty_outwakeup(tp);
3932 #ifndef SC_NO_CUTPASTE
3933 sc_mouse_paste(scp);
3937 /* NON-LOCKING KEYS */
3950 if (!(sc->flags & SC_SCRN_BLANKED))
3956 /* force activatation/deactivation of the screen
3958 if (!(sc->flags & SC_SCRN_BLANKED)) {
3959 run_scrn_saver = TRUE;
3960 sc->scrn_time_stamp -= scrn_blank_time;
3964 * While devices are being probed, the
3965 * screen saver need to be invoked
3968 if (sc->flags & SC_SCRN_BLANKED) {
3969 scsplash_stick(FALSE);
3973 if (!ISGRAPHSC(scp)) {
3974 scsplash_stick(TRUE);
3980 #endif /* DEV_SPLASH */
3984 #ifndef SC_DISABLE_REBOOT
3985 if (enable_reboot && !(flags & SCGETC_CN))
3991 #ifndef SC_DISABLE_REBOOT
3992 if (enable_reboot && !(flags & SCGETC_CN))
3993 shutdown_nice(RB_HALT);
3998 #ifndef SC_DISABLE_REBOOT
3999 if (enable_reboot && !(flags & SCGETC_CN))
4000 shutdown_nice(RB_HALT | RB_POWEROFF);
4005 power_pm_suspend(POWER_SLEEP_STATE_SUSPEND);
4008 power_pm_suspend(POWER_SLEEP_STATE_STANDBY);
4012 #ifndef SC_DISABLE_KDBKEY
4019 if (enable_panic_key)
4020 panic("Forced by the panic key");
4024 this_scr = scp->index;
4025 for (i = (this_scr - sc->first_vty + 1) %
4027 sc->first_vty + i != this_scr;
4028 i = (i + 1) % sc->vtys) {
4030 SC_DEV(sc, sc->first_vty + i);
4031 if (tty_opened_ns(tp)) {
4033 scp->sc, sc->first_vty + i);
4040 this_scr = scp->index;
4041 for (i = (this_scr - sc->first_vty + sc->vtys -
4044 sc->first_vty + i != this_scr;
4045 i = (i + sc->vtys - 1) % sc->vtys) {
4047 SC_DEV(sc, sc->first_vty + i);
4048 if (tty_opened_ns(tp)) {
4050 scp->sc, sc->first_vty + i);
4057 if (KEYCHAR(c) >= F_SCR &&
4058 KEYCHAR(c) <= L_SCR) {
4059 sc_switch_scr(scp->sc,
4060 sc->first_vty + KEYCHAR(c) - F_SCR);
4063 /* assert(c & FKEY) */
4064 if (!(sc->flags & SC_SCRN_BLANKED))
4068 /* goto next_code */
4070 /* regular keys (maybe MKEY is set) */
4071 #if !defined(SC_DISABLE_KDBKEY) && defined(KDB)
4073 kdb_alt_break(c, &sc->sc_altbrk);
4075 if (!(sc->flags & SC_SCRN_BLANKED))
4084 sctty_mmap(struct tty *tp, vm_ooffset_t offset, vm_paddr_t *paddr, int nprot,
4085 vm_memattr_t *memattr)
4089 scp = sc_get_stat(tp);
4090 if (scp != scp->sc->cur_scp)
4092 return vidd_mmap(scp->sc->adp, offset, paddr, nprot, memattr);
4096 update_font(scr_stat *scp)
4098 #ifndef SC_NO_FONT_LOADING
4099 /* load appropriate font */
4100 if (!(scp->status & GRAPHICS_MODE)) {
4101 if (!(scp->status & PIXEL_MODE) &&
4102 ISFONTAVAIL(scp->sc->adp->va_flags)) {
4103 if (scp->font_size < 14) {
4104 if (scp->sc->fonts_loaded & FONT_8)
4105 sc_load_font(scp, 0, 8, 8,
4106 scp->sc->font_8, 0, 256);
4107 } else if (scp->font_size >= 16) {
4108 if (scp->sc->fonts_loaded & FONT_16)
4109 sc_load_font(scp, 0, 16, 8,
4110 scp->sc->font_16, 0, 256);
4112 if (scp->sc->fonts_loaded & FONT_14)
4113 sc_load_font(scp, 0, 14, 8,
4114 scp->sc->font_14, 0, 256);
4118 * This is an interim kludge to display correct font.
4119 * Always use the font page #0 on the video plane 2.
4120 * Somehow we cannot show the font in other font pages
4121 * on some video cards... XXX
4123 sc_show_font(scp, 0);
4127 #endif /* !SC_NO_FONT_LOADING */
4131 save_kbd_state(scr_stat *scp)
4136 error = kbdd_ioctl(scp->sc->kbd, KDGKBSTATE, (caddr_t)&state);
4137 if (error == ENOIOCTL)
4140 scp->status &= ~LOCK_MASK;
4141 scp->status |= state;
4147 update_kbd_state(scr_stat *scp, int new_bits, int mask)
4152 if (mask != LOCK_MASK) {
4153 error = kbdd_ioctl(scp->sc->kbd, KDGKBSTATE, (caddr_t)&state);
4154 if (error == ENOIOCTL)
4159 state |= new_bits & mask;
4161 state = new_bits & LOCK_MASK;
4163 error = kbdd_ioctl(scp->sc->kbd, KDSKBSTATE, (caddr_t)&state);
4164 if (error == ENOIOCTL)
4170 update_kbd_leds(scr_stat *scp, int which)
4175 error = kbdd_ioctl(scp->sc->kbd, KDSETLED, (caddr_t)&which);
4176 if (error == ENOIOCTL)
4182 set_mode(scr_stat *scp)
4186 /* reject unsupported mode */
4187 if (vidd_get_info(scp->sc->adp, scp->mode, &info))
4190 /* if this vty is not currently showing, do nothing */
4191 if (scp != scp->sc->cur_scp)
4194 /* setup video hardware for the given mode */
4195 vidd_set_mode(scp->sc->adp, scp->mode);
4196 scp->rndr->init(scp);
4198 sc_vtb_init(&scp->scr, VTB_FRAMEBUFFER, scp->xsize, scp->ysize,
4199 (void *)scp->sc->adp->va_window, FALSE);
4204 sc_set_border(scp, scp->border);
4205 sc_set_cursor_image(scp);
4211 sc_set_border(scr_stat *scp, int color)
4213 SC_VIDEO_LOCK(scp->sc);
4214 (*scp->rndr->draw_border)(scp, color);
4215 SC_VIDEO_UNLOCK(scp->sc);
4218 #ifndef SC_NO_FONT_LOADING
4220 sc_load_font(scr_stat *scp, int page, int size, int width, u_char *buf,
4221 int base, int count)
4226 sc->font_loading_in_progress = TRUE;
4227 vidd_load_font(sc->adp, page, size, width, buf, base, count);
4228 sc->font_loading_in_progress = FALSE;
4232 sc_save_font(scr_stat *scp, int page, int size, int width, u_char *buf,
4233 int base, int count)
4238 sc->font_loading_in_progress = TRUE;
4239 vidd_save_font(sc->adp, page, size, width, buf, base, count);
4240 sc->font_loading_in_progress = FALSE;
4244 sc_show_font(scr_stat *scp, int page)
4246 vidd_show_font(scp->sc->adp, page);
4248 #endif /* !SC_NO_FONT_LOADING */
4251 sc_paste(scr_stat *scp, const u_char *p, int count)
4256 tp = SC_DEV(scp->sc, scp->sc->cur_scp->index);
4257 if (!tty_opened_ns(tp))
4259 rmap = scp->sc->scr_rmap;
4260 for (; count > 0; --count)
4261 ttydisc_rint(tp, rmap[*p++], 0);
4262 ttydisc_rint_done(tp);
4266 sc_respond(scr_stat *scp, const u_char *p, int count, int wakeup)
4270 tp = SC_DEV(scp->sc, scp->sc->cur_scp->index);
4271 if (!tty_opened_ns(tp))
4273 ttydisc_rint_simple(tp, p, count);
4275 /* XXX: we can't always call ttydisc_rint_done() here! */
4276 ttydisc_rint_done(tp);
4281 sc_bell(scr_stat *scp, int pitch, int duration)
4283 if (cold || kdb_active || shutdown_in_progress || !enable_bell)
4286 if (scp != scp->sc->cur_scp && (scp->sc->flags & SC_QUIET_BELL))
4289 if (scp->sc->flags & SC_VISUAL_BELL) {
4290 if (scp->sc->blink_in_progress)
4292 scp->sc->blink_in_progress = 3;
4293 if (scp != scp->sc->cur_scp)
4294 scp->sc->blink_in_progress += 2;
4295 blink_screen(scp->sc->cur_scp);
4296 } else if (duration != 0 && pitch != 0) {
4297 if (scp != scp->sc->cur_scp)
4299 sysbeep(1193182 / pitch, duration);
4306 if (sc_console == NULL)
4307 return (SC_KERNEL_CONS_ATTR); /* for very early, before pcpu */
4308 return (sc_kattrtab[curcpu % nitems(sc_kattrtab)]);
4312 blink_screen(void *arg)
4314 scr_stat *scp = arg;
4317 if (ISGRAPHSC(scp) || (scp->sc->blink_in_progress <= 1)) {
4318 scp->sc->blink_in_progress = 0;
4320 tp = SC_DEV(scp->sc, scp->index);
4321 if (tty_opened_ns(tp))
4322 sctty_outwakeup(tp);
4323 if (scp->sc->delayed_next_scr)
4324 sc_switch_scr(scp->sc, scp->sc->delayed_next_scr - 1);
4326 (*scp->rndr->draw)(scp, 0, scp->xsize * scp->ysize,
4327 scp->sc->blink_in_progress & 1);
4328 scp->sc->blink_in_progress--;
4329 callout_reset_sbt(&scp->sc->cblink, SBT_1S / 15, 0,
4330 blink_screen, scp, C_PREL(0));
4335 * Until sc_attach_unit() gets called no dev structures will be available
4336 * to store the per-screen current status. This is the case when the
4337 * kernel is initially booting and needs access to its console. During
4338 * this early phase of booting the console's current status is kept in
4339 * one statically defined scr_stat structure, and any pointers to the
4340 * dev structures will be NULL.
4344 sc_get_stat(struct tty *tp)
4347 return (&main_console);
4348 return (SC_STAT(tp));
4352 * Allocate active keyboard. Try to allocate "kbdmux" keyboard first, and,
4353 * if found, add all non-busy keyboards to "kbdmux". Otherwise look for
4358 sc_allocate_keyboard(sc_softc_t *sc, int unit)
4365 kbd_allocate("kbdmux", -1, (void *)&sc->keyboard, sckbdevent, sc);
4367 k0 = kbd_get_keyboard(idx0);
4369 for (idx = kbd_find_keyboard2("*", -1, 0); idx != -1;
4370 idx = kbd_find_keyboard2("*", -1, idx + 1)) {
4371 k = kbd_get_keyboard(idx);
4373 if (idx == idx0 || KBD_IS_BUSY(k))
4376 bzero(&ki, sizeof(ki));
4377 strcpy(ki.kb_name, k->kb_name);
4378 ki.kb_unit = k->kb_unit;
4380 (void)kbdd_ioctl(k0, KBADDKBD, (caddr_t)&ki);
4383 idx0 = kbd_allocate(
4384 "*", unit, (void *)&sc->keyboard, sckbdevent, sc);