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__) || \
69 defined(__powerpc__) || defined(__sparc64__)
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;
136 static void none_saver(sc_softc_t *sc, int blank) { }
137 static void (*current_saver)(sc_softc_t *, int) = none_saver;
140 #ifdef SC_NO_SUSPEND_VTYSWITCH
141 static int sc_no_suspend_vtswitch = 1;
143 static int sc_no_suspend_vtswitch = 0;
145 static int sc_susp_scr;
147 static SYSCTL_NODE(_hw, OID_AUTO, syscons, CTLFLAG_RD, 0, "syscons");
148 static SYSCTL_NODE(_hw_syscons, OID_AUTO, saver, CTLFLAG_RD, 0, "saver");
149 SYSCTL_INT(_hw_syscons_saver, OID_AUTO, keybonly, CTLFLAG_RW,
150 &sc_saver_keyb_only, 0, "screen saver interrupted by input only");
151 SYSCTL_INT(_hw_syscons, OID_AUTO, bell, CTLFLAG_RW, &enable_bell,
153 #ifndef SC_DISABLE_REBOOT
154 SYSCTL_INT(_hw_syscons, OID_AUTO, kbd_reboot, CTLFLAG_RW|CTLFLAG_SECURE, &enable_reboot,
155 0, "enable keyboard reboot");
157 #ifndef SC_DISABLE_KDBKEY
158 SYSCTL_INT(_hw_syscons, OID_AUTO, kbd_debug, CTLFLAG_RW|CTLFLAG_SECURE, &enable_kdbkey,
159 0, "enable keyboard debug");
161 SYSCTL_INT(_hw_syscons, OID_AUTO, sc_no_suspend_vtswitch, CTLFLAG_RWTUN,
162 &sc_no_suspend_vtswitch, 0, "Disable VT switch before suspend.");
163 #if !defined(SC_NO_FONT_LOADING) && defined(SC_DFLT_FONT)
167 tsw_ioctl_t *sc_user_ioctl;
169 static bios_values_t bios_value;
171 static int enable_panic_key;
172 SYSCTL_INT(_machdep, OID_AUTO, enable_panic_key, CTLFLAG_RW, &enable_panic_key,
173 0, "Enable panic via keypress specified in kbdmap(5)");
175 #define SC_CONSOLECTL 255
177 #define VTY_WCHAN(sc, vty) (&SC_DEV(sc, vty))
180 static int sc_allocate_keyboard(sc_softc_t *sc, int unit);
181 static int scvidprobe(int unit, int flags, int cons);
182 static int sckbdprobe(int unit, int flags, int cons);
183 static void scmeminit(void *arg);
184 static int scdevtounit(struct tty *tp);
185 static kbd_callback_func_t sckbdevent;
186 static void scinit(int unit, int flags);
187 static scr_stat *sc_get_stat(struct tty *tp);
188 static void scterm(int unit, int flags);
189 static void scshutdown(void *, int);
190 static void scsuspend(void *);
191 static void scresume(void *);
192 static u_int scgetc(sc_softc_t *sc, u_int flags, struct sc_cnstate *sp);
193 static void sc_puts(scr_stat *scp, u_char *buf, int len);
195 #define SCGETC_NONBLOCK 2
196 static void sccnupdate(scr_stat *scp);
197 static scr_stat *alloc_scp(sc_softc_t *sc, int vty);
198 static void init_scp(sc_softc_t *sc, int vty, scr_stat *scp);
199 static timeout_t scrn_timer;
200 static int and_region(int *s1, int *e1, int s2, int e2);
201 static void scrn_update(scr_stat *scp, int show_cursor);
204 static int scsplash_callback(int event, void *arg);
205 static void scsplash_saver(sc_softc_t *sc, int show);
206 static int add_scrn_saver(void (*this_saver)(sc_softc_t *, int));
207 static int remove_scrn_saver(void (*this_saver)(sc_softc_t *, int));
208 static int set_scrn_saver_mode(scr_stat *scp, int mode, u_char *pal, int border);
209 static int restore_scrn_saver_mode(scr_stat *scp, int changemode);
210 static void stop_scrn_saver(sc_softc_t *sc, void (*saver)(sc_softc_t *, int));
211 static int wait_scrn_saver_stop(sc_softc_t *sc);
212 #define scsplash_stick(stick) (sticky_splash = (stick))
213 #else /* !DEV_SPLASH */
214 #define scsplash_stick(stick)
215 #endif /* DEV_SPLASH */
217 static int do_switch_scr(sc_softc_t *sc, int s);
218 static int vt_proc_alive(scr_stat *scp);
219 static int signal_vt_rel(scr_stat *scp);
220 static int signal_vt_acq(scr_stat *scp);
221 static int finish_vt_rel(scr_stat *scp, int release, int *s);
222 static int finish_vt_acq(scr_stat *scp);
223 static void exchange_scr(sc_softc_t *sc);
224 static void update_cursor_image(scr_stat *scp);
225 static void change_cursor_shape(scr_stat *scp, int flags, int base, int height);
226 static void update_font(scr_stat *);
227 static int save_kbd_state(scr_stat *scp);
228 static int update_kbd_state(scr_stat *scp, int state, int mask);
229 static int update_kbd_leds(scr_stat *scp, int which);
230 static int sc_kattr(void);
231 static timeout_t blink_screen;
232 static struct tty *sc_alloc_tty(int, int);
234 static cn_probe_t sc_cnprobe;
235 static cn_init_t sc_cninit;
236 static cn_term_t sc_cnterm;
237 static cn_getc_t sc_cngetc;
238 static cn_putc_t sc_cnputc;
239 static cn_grab_t sc_cngrab;
240 static cn_ungrab_t sc_cnungrab;
244 static tsw_open_t sctty_open;
245 static tsw_close_t sctty_close;
246 static tsw_outwakeup_t sctty_outwakeup;
247 static tsw_ioctl_t sctty_ioctl;
248 static tsw_mmap_t sctty_mmap;
250 static struct ttydevsw sc_ttydevsw = {
251 .tsw_open = sctty_open,
252 .tsw_close = sctty_close,
253 .tsw_outwakeup = sctty_outwakeup,
254 .tsw_ioctl = sctty_ioctl,
255 .tsw_mmap = sctty_mmap,
258 static d_ioctl_t consolectl_ioctl;
259 static d_close_t consolectl_close;
261 static struct cdevsw consolectl_devsw = {
262 .d_version = D_VERSION,
263 .d_flags = D_NEEDGIANT | D_TRACKCLOSE,
264 .d_ioctl = consolectl_ioctl,
265 .d_close = consolectl_close,
266 .d_name = "consolectl",
269 /* ec -- emergency console. */
271 static u_int ec_scroffset;
279 int attr, column, mysize, width, xsize, yborder, ysize;
281 if (c < 0 || c > 0xff || c == '\a')
283 if (sc_console == NULL) {
284 #if !defined(__amd64__) && !defined(__i386__)
288 * This is enough for ec_putc() to work very early on x86
289 * if the kernel starts in normal color text mode.
292 fb = KERNBASE + 0xb8000;
294 fb = PMAP_MAP_LOW + 0xb8000;
300 if (!ISTEXTSC(&main_console))
302 fb = main_console.sc->adp->va_window;
303 xsize = main_console.xsize;
304 ysize = main_console.ysize;
307 scrptr = (u_short *)(void *)fb + xsize * yborder;
308 mysize = xsize * (ysize - 2 * yborder);
311 column = ind % xsize;
312 width = (c == '\b' ? -1 : c == '\t' ? (column + 8) & ~7 :
313 c == '\r' ? -column : c == '\n' ? xsize - column : 1);
314 if (width == 0 || (width < 0 && ind < -width))
316 } while (atomic_cmpset_rel_int(&ec_scroffset, ind, ind + width) == 0);
317 if (c == '\b' || c == '\r')
320 ind += xsize; /* XXX clearing from new pos is not atomic */
323 if (c == '\t' || c == '\n')
326 scrptr[ind++ % mysize] = (attr << 8) | c;
327 while (--width != 0);
331 sc_probe_unit(int unit, int flags)
333 if (!vty_enabled(VTY_SC))
335 if (!scvidprobe(unit, flags, FALSE)) {
337 printf("%s%d: no video adapter found.\n", SC_DRIVER_NAME, unit);
341 /* syscons will be attached even when there is no keyboard */
342 sckbdprobe(unit, flags, FALSE);
347 /* probe video adapters, return TRUE if found */
349 scvidprobe(int unit, int flags, int cons)
352 * Access the video adapter driver through the back door!
353 * Video adapter drivers need to be configured before syscons.
354 * However, when syscons is being probed as the low-level console,
355 * they have not been initialized yet. We force them to initialize
356 * themselves here. XXX
358 vid_configure(cons ? VIO_PROBE_ONLY : 0);
360 return (vid_find_adapter("*", unit) >= 0);
363 /* probe the keyboard, return TRUE if found */
365 sckbdprobe(int unit, int flags, int cons)
367 /* access the keyboard driver through the backdoor! */
368 kbd_configure(cons ? KB_CONF_PROBE_ONLY : 0);
370 return (kbd_find_keyboard("*", unit) >= 0);
374 *adapter_name(video_adapter_t *adp)
380 { KD_MONO, { "MDA", "MDA" } },
381 { KD_HERCULES, { "Hercules", "Hercules" } },
382 { KD_CGA, { "CGA", "CGA" } },
383 { KD_EGA, { "EGA", "EGA (mono)" } },
384 { KD_VGA, { "VGA", "VGA (mono)" } },
385 { KD_TGA, { "TGA", "TGA" } },
386 { -1, { "Unknown", "Unknown" } },
390 for (i = 0; names[i].type != -1; ++i)
391 if (names[i].type == adp->va_type)
393 return names[i].name[(adp->va_flags & V_ADP_COLOR) ? 0 : 1];
397 sctty_outwakeup(struct tty *tp)
401 scr_stat *scp = sc_get_stat(tp);
403 if (scp->status & SLKED ||
404 (scp == scp->sc->cur_scp && scp->sc->blink_in_progress))
408 len = ttydisc_getc(tp, buf, sizeof buf);
411 SC_VIDEO_LOCK(scp->sc);
412 sc_puts(scp, buf, len);
413 SC_VIDEO_UNLOCK(scp->sc);
418 sc_alloc_tty(int index, int devnum)
420 struct sc_ttysoftc *stc;
423 /* Allocate TTY object and softc to store unit number. */
424 stc = malloc(sizeof(struct sc_ttysoftc), M_DEVBUF, M_WAITOK);
425 stc->st_index = index;
427 tp = tty_alloc_mutex(&sc_ttydevsw, stc, &Giant);
429 /* Create device node. */
430 tty_makedev(tp, NULL, "v%r", devnum);
437 sc_set_vesa_mode(scr_stat *scp, sc_softc_t *sc, int unit)
447 (void)resource_int_value("sc", unit, "vesa_mode", &vmode);
448 if (vmode < M_VESA_BASE || vmode > M_VESA_MODE_MAX ||
449 vidd_get_info(sc->adp, vmode, &info) != 0 ||
450 !sc_support_pixel_mode(&info))
454 * If the mode is unset or unsupported, search for an available
455 * 800x600 graphics mode with the highest color depth.
458 for (depth = 0, i = M_VESA_BASE; i <= M_VESA_MODE_MAX; i++)
459 if (vidd_get_info(sc->adp, i, &info) == 0 &&
460 info.vi_width == 800 && info.vi_height == 600 &&
461 sc_support_pixel_mode(&info) &&
462 info.vi_depth > depth) {
464 depth = info.vi_depth;
468 vidd_get_info(sc->adp, vmode, &info);
471 #if !defined(SC_NO_FONT_LOADING) && defined(SC_DFLT_FONT)
472 fontsize = info.vi_cheight;
474 fontsize = scp->font_size;
478 else if (fontsize >= 16)
482 #ifndef SC_NO_FONT_LOADING
485 if ((sc->fonts_loaded & FONT_8) == 0)
490 if ((sc->fonts_loaded & FONT_14) == 0)
495 if ((sc->fonts_loaded & FONT_16) == 0)
504 if ((sc->flags & SC_SPLASH_SCRN) != 0)
505 splash_term(sc->adp);
507 #ifndef SC_NO_HISTORY
508 if (scp->history != NULL) {
509 sc_vtb_append(&scp->vtb, 0, scp->history,
510 scp->ypos * scp->xsize + scp->xpos);
511 scp->history_pos = sc_vtb_tail(scp->history);
514 vidd_set_mode(sc->adp, vmode);
515 scp->status |= (UNKNOWN_MODE | PIXEL_MODE | MOUSE_HIDDEN);
516 scp->status &= ~(GRAPHICS_MODE | MOUSE_VISIBLE);
517 scp->xpixel = info.vi_width;
518 scp->ypixel = info.vi_height;
519 scp->xsize = scp->xpixel / 8;
520 scp->ysize = scp->ypixel / fontsize;
522 scp->ypos = scp->ysize - 1;
523 scp->xoff = scp->yoff = 0;
525 scp->font_size = fontsize;
527 scp->start = scp->xsize * scp->ysize - 1;
529 scp->cursor_pos = scp->cursor_oldpos = scp->xsize * scp->xsize;
530 scp->mode = sc->initial_mode = vmode;
532 sc_vtb_init(&scp->scr, VTB_FRAMEBUFFER, scp->xsize, scp->ysize,
533 (void *)sc->adp->va_window, FALSE);
535 sc_alloc_scr_buffer(scp, FALSE, FALSE);
536 sc_init_emulator(scp, NULL);
537 #ifndef SC_NO_CUTPASTE
538 sc_alloc_cut_buffer(scp, FALSE);
540 #ifndef SC_NO_HISTORY
541 sc_alloc_history_buffer(scp, 0, 0, FALSE);
543 sc_set_border(scp, scp->border);
544 sc_set_cursor_image(scp);
545 scp->status &= ~UNKNOWN_MODE;
547 if ((sc->flags & SC_SPLASH_SCRN) != 0)
548 splash_init(sc->adp, scsplash_callback, sc);
554 sc_attach_unit(int unit, int flags)
562 if (!vty_enabled(VTY_SC))
565 flags &= ~SC_KERNEL_CONSOLE;
567 if (sc_console_unit == unit) {
569 * If this unit is being used as the system console, we need to
570 * adjust some variables and buffers before and after scinit().
572 /* assert(sc_console != NULL) */
573 flags |= SC_KERNEL_CONSOLE;
578 if (sc_console->tsw->te_size > 0) {
579 sc_ktsw = sc_console->tsw;
580 /* assert(sc_console->ts != NULL); */
581 oldts = sc_console->ts;
582 for (i = 0; i <= mp_maxid; i++) {
583 ts = malloc(sc_console->tsw->te_size, M_DEVBUF,
585 (*sc_console->tsw->te_init)(sc_console, &ts, SC_TE_COLD_INIT);
587 (*sc_console->tsw->te_default_attr)(sc_console, sc_kattrtab[i],
588 SC_KERNEL_CONS_REV_ATTR);
591 sc_console->ts = oldts;
592 (*sc_console->tsw->te_default_attr)(sc_console, SC_NORM_ATTR,
599 sc = sc_get_softc(unit, flags & SC_KERNEL_CONSOLE);
601 callout_init(&sc->ctimeout, 0);
602 callout_init(&sc->cblink, 0);
603 scp = sc_get_stat(sc->dev[0]);
604 if (sc_console == NULL) /* sc_console_unit < 0 */
608 if ((sc->config & SC_VESAMODE) != 0)
609 sc_set_vesa_mode(scp, sc, unit);
610 #endif /* SC_PIXEL_MODE */
612 /* initialize cursor */
614 update_cursor_image(scp);
616 /* get screen update going */
619 /* set up the keyboard */
620 (void)kbdd_ioctl(sc->kbd, KDSKBMODE, (caddr_t)&scp->kbd_mode);
621 update_kbd_state(scp, scp->status, LOCK_MASK);
623 printf("%s%d: %s <%d virtual consoles, flags=0x%x>\n",
624 SC_DRIVER_NAME, unit, adapter_name(sc->adp), sc->vtys, sc->config);
626 printf("%s%d:", SC_DRIVER_NAME, unit);
627 if (sc->adapter >= 0)
628 printf(" fb%d", sc->adapter);
629 if (sc->keyboard >= 0)
630 printf(", kbd%d", sc->keyboard);
632 printf(", terminal emulator: %s (%s)",
633 scp->tsw->te_name, scp->tsw->te_desc);
637 /* Register suspend/resume/shutdown callbacks for the kernel console. */
638 if (sc_console_unit == unit) {
639 EVENTHANDLER_REGISTER(power_suspend_early, scsuspend, NULL,
640 EVENTHANDLER_PRI_ANY);
641 EVENTHANDLER_REGISTER(power_resume, scresume, NULL,
642 EVENTHANDLER_PRI_ANY);
643 EVENTHANDLER_REGISTER(shutdown_pre_sync, scshutdown, NULL,
644 SHUTDOWN_PRI_DEFAULT);
647 for (vc = 0; vc < sc->vtys; vc++) {
648 if (sc->dev[vc] == NULL) {
649 sc->dev[vc] = sc_alloc_tty(vc, vc + unit * MAXCONS);
650 if (vc == 0 && sc->dev == main_devs)
651 SC_STAT(sc->dev[0]) = &main_console;
654 * The first vty already has struct tty and scr_stat initialized
655 * in scinit(). The other vtys will have these structs when
660 dev = make_dev(&consolectl_devsw, 0, UID_ROOT, GID_WHEEL, 0600,
662 dev->si_drv1 = sc->dev[0];
670 if (!vty_enabled(VTY_SC))
677 * As soon as malloc() becomes functional, we had better allocate
678 * various buffers for the kernel console.
681 if (sc_console_unit < 0) /* sc_console == NULL */
684 /* copy the temporary buffer to the final buffer */
685 sc_alloc_scr_buffer(sc_console, FALSE, FALSE);
687 #ifndef SC_NO_CUTPASTE
688 sc_alloc_cut_buffer(sc_console, FALSE);
691 #ifndef SC_NO_HISTORY
692 /* initialize history buffer & pointers */
693 sc_alloc_history_buffer(sc_console, 0, 0, FALSE);
698 SYSINIT(sc_mem, SI_SUB_KMEM, SI_ORDER_ANY, scmeminit, NULL);
701 scdevtounit(struct tty *tp)
703 int vty = SC_VTY(tp);
705 if (vty == SC_CONSOLECTL)
706 return ((sc_console != NULL) ? sc_console->sc->unit : -1);
707 else if ((vty < 0) || (vty >= MAXCONS*sc_max_unit()))
714 sctty_open(struct tty *tp)
716 int unit = scdevtounit(tp);
723 DPRINTF(5, ("scopen: dev:%s, unit:%d, vty:%d\n",
724 devtoname(tp->t_dev), unit, SC_VTY(tp)));
726 sc = sc_get_softc(unit, (sc_console_unit == unit) ? SC_KERNEL_CONSOLE : 0);
730 if (!tty_opened(tp)) {
731 /* Use the current setting of the <-- key as default VERASE. */
732 /* If the Delete key is preferable, an stty is necessary */
734 if (sc->kbd != NULL) {
735 key.keynum = KEYCODE_BS;
736 (void)kbdd_ioctl(sc->kbd, GIO_KEYMAPENT, (caddr_t)&key);
737 tp->t_termios.c_cc[VERASE] = key.key.map[0];
742 scp = sc_get_stat(tp);
744 scp = SC_STAT(tp) = alloc_scp(sc, SC_VTY(tp));
746 sc_set_pixel_mode(scp, NULL, 0, 0, 16, 8);
748 if (!tp->t_winsize.ws_col && !tp->t_winsize.ws_row) {
749 tp->t_winsize.ws_col = scp->xsize;
750 tp->t_winsize.ws_row = scp->ysize;
757 sctty_close(struct tty *tp)
762 if (SC_VTY(tp) != SC_CONSOLECTL) {
763 scp = sc_get_stat(tp);
764 /* were we in the middle of the VT switching process? */
765 DPRINTF(5, ("sc%d: scclose(), ", scp->sc->unit));
767 if ((scp == scp->sc->cur_scp) && (scp->sc->unit == sc_console_unit))
768 cnavailable(sc_consptr, TRUE);
769 if (finish_vt_rel(scp, TRUE, &s) == 0) /* force release */
770 DPRINTF(5, ("reset WAIT_REL, "));
771 if (finish_vt_acq(scp) == 0) /* force acknowledge */
772 DPRINTF(5, ("reset WAIT_ACQ, "));
774 if (scp == &main_console) {
777 scp->smode.mode = VT_AUTO;
780 sc_vtb_destroy(&scp->vtb);
782 sc_vtb_destroy(&scp->scr);
784 sc_free_history_buffer(scp, scp->ysize);
791 scp->smode.mode = VT_AUTO;
793 scp->kbd_mode = K_XLATE;
794 if (scp == scp->sc->cur_scp)
795 (void)kbdd_ioctl(scp->sc->kbd, KDSKBMODE, (caddr_t)&scp->kbd_mode);
796 DPRINTF(5, ("done.\n"));
800 #if 0 /* XXX mpsafetty: fix screensaver. What about outwakeup? */
802 scread(struct cdev *dev, struct uio *uio, int flag)
804 if (!sc_saver_keyb_only)
805 sc_touch_scrn_saver();
806 return ttyread(dev, uio, flag);
811 sckbdevent(keyboard_t *thiskbd, int event, void *arg)
819 sc = (sc_softc_t *)arg;
820 /* assert(thiskbd == sc->kbd) */
827 case KBDIO_UNLOADING:
830 kbd_release(thiskbd, (void *)&sc->keyboard);
838 * Loop while there is still input to get from the keyboard.
839 * I don't think this is nessesary, and it doesn't fix
840 * the Xaccel-2.1 keyboard hang, but it can't hurt. XXX
842 while ((c = scgetc(sc, SCGETC_NONBLOCK, NULL)) != NOKEY) {
844 cur_tty = SC_DEV(sc, sc->cur_scp->index);
845 if (!tty_opened_ns(cur_tty))
848 if ((*sc->cur_scp->tsw->te_input)(sc->cur_scp, c, cur_tty))
851 switch (KEYFLAGS(c)) {
852 case 0x0000: /* normal key */
853 ttydisc_rint(cur_tty, KEYCHAR(c), 0);
855 case FKEY: /* function key, return string */
856 cp = (*sc->cur_scp->tsw->te_fkeystr)(sc->cur_scp, c);
858 ttydisc_rint_simple(cur_tty, cp, strlen(cp));
861 cp = kbdd_get_fkeystr(thiskbd, KEYCHAR(c), &len);
863 ttydisc_rint_simple(cur_tty, cp, len);
865 case MKEY: /* meta is active, prepend ESC */
866 ttydisc_rint(cur_tty, 0x1b, 0);
867 ttydisc_rint(cur_tty, KEYCHAR(c), 0);
869 case BKEY: /* backtab fixed sequence (esc [ Z) */
870 ttydisc_rint_simple(cur_tty, "\x1B[Z", 3);
874 ttydisc_rint_done(cur_tty);
877 sc->cur_scp->status |= MOUSE_HIDDEN;
885 sctty_ioctl(struct tty *tp, u_long cmd, caddr_t data, struct thread *td)
889 struct cursor_attr *cap;
893 #if defined(COMPAT_FREEBSD6) || defined(COMPAT_FREEBSD5) || \
894 defined(COMPAT_FREEBSD4) || defined(COMPAT_43)
898 /* If there is a user_ioctl function call that first */
900 error = (*sc_user_ioctl)(tp, cmd, data, td);
901 if (error != ENOIOCTL)
905 error = sc_vid_ioctl(tp, cmd, data, td);
906 if (error != ENOIOCTL)
909 #ifndef SC_NO_HISTORY
910 error = sc_hist_ioctl(tp, cmd, data, td);
911 if (error != ENOIOCTL)
915 #ifndef SC_NO_SYSMOUSE
916 error = sc_mouse_ioctl(tp, cmd, data, td);
917 if (error != ENOIOCTL)
921 scp = sc_get_stat(tp);
922 /* assert(scp != NULL) */
923 /* scp is sc_console, if SC_VTY(dev) == SC_CONSOLECTL. */
927 error = (*scp->tsw->te_ioctl)(scp, tp, cmd, data, td);
928 if (error != ENOIOCTL)
932 switch (cmd) { /* process console hardware related ioctl's */
934 case GIO_ATTR: /* get current attributes */
935 /* this ioctl is not processed here, but in the terminal emulator */
938 case GIO_COLOR: /* is this a color console ? */
939 *(int *)data = (sc->adp->va_flags & V_ADP_COLOR) ? 1 : 0;
942 case CONS_BLANKTIME: /* set screen saver timeout (0 = no saver) */
943 if (*(int *)data < 0 || *(int *)data > MAX_BLANKTIME)
946 scrn_blank_time = *(int *)data;
947 run_scrn_saver = (scrn_blank_time != 0);
951 case CONS_CURSORTYPE: /* set cursor type (old interface + HIDDEN) */
953 *(int *)data &= CONS_CURSOR_ATTRS;
954 sc_change_cursor_shape(scp, *(int *)data, -1, -1);
958 case CONS_GETCURSORSHAPE: /* get cursor shape (new interface) */
959 switch (((int *)data)[0] & (CONS_DEFAULT_CURSOR | CONS_LOCAL_CURSOR)) {
961 cap = &sc->curs_attr;
963 case CONS_LOCAL_CURSOR:
964 cap = &scp->base_curs_attr;
966 case CONS_DEFAULT_CURSOR:
967 cap = &sc->dflt_curs_attr;
969 case CONS_DEFAULT_CURSOR | CONS_LOCAL_CURSOR:
970 cap = &scp->dflt_curs_attr;
973 if (((int *)data)[0] & CONS_CHARCURSOR_COLORS) {
974 ((int *)data)[1] = cap->bg[0];
975 ((int *)data)[2] = cap->bg[1];
976 } else if (((int *)data)[0] & CONS_MOUSECURSOR_COLORS) {
977 ((int *)data)[1] = cap->mouse_ba;
978 ((int *)data)[2] = cap->mouse_ia;
980 ((int *)data)[1] = cap->base;
981 ((int *)data)[2] = cap->height;
983 ((int *)data)[0] = cap->flags;
986 case CONS_SETCURSORSHAPE: /* set cursor shape (new interface) */
988 sc_change_cursor_shape(scp, ((int *)data)[0],
989 ((int *)data)[1], ((int *)data)[2]);
993 case CONS_BELLTYPE: /* set bell type sound/visual */
994 if ((*(int *)data) & CONS_VISUAL_BELL)
995 sc->flags |= SC_VISUAL_BELL;
997 sc->flags &= ~SC_VISUAL_BELL;
998 if ((*(int *)data) & CONS_QUIET_BELL)
999 sc->flags |= SC_QUIET_BELL;
1001 sc->flags &= ~SC_QUIET_BELL;
1004 case CONS_GETINFO: /* get current (virtual) console info */
1006 vid_info_t *ptr = (vid_info_t*)data;
1007 if (ptr->size == sizeof(struct vid_info)) {
1008 ptr->m_num = sc->cur_scp->index;
1009 ptr->font_size = scp->font_size;
1010 ptr->mv_col = scp->xpos;
1011 ptr->mv_row = scp->ypos;
1012 ptr->mv_csz = scp->xsize;
1013 ptr->mv_rsz = scp->ysize;
1014 ptr->mv_hsz = (scp->history != NULL) ? scp->history->vtb_rows : 0;
1016 * The following fields are filled by the terminal emulator. XXX
1023 ptr->mv_grfc.fore = 0; /* not supported */
1024 ptr->mv_grfc.back = 0; /* not supported */
1025 ptr->mv_ovscan = scp->border;
1026 if (scp == sc->cur_scp)
1027 save_kbd_state(scp);
1028 ptr->mk_keylock = scp->status & LOCK_MASK;
1034 case CONS_GETVERS: /* get version number */
1035 *(int*)data = 0x200; /* version 2.0 */
1038 case CONS_IDLE: /* see if the screen has been idle */
1040 * When the screen is in the GRAPHICS_MODE or UNKNOWN_MODE,
1041 * the user process may have been writing something on the
1042 * screen and syscons is not aware of it. Declare the screen
1043 * is NOT idle if it is in one of these modes. But there is
1044 * an exception to it; if a screen saver is running in the
1045 * graphics mode in the current screen, we should say that the
1046 * screen has been idle.
1048 *(int *)data = (sc->flags & SC_SCRN_IDLE)
1049 && (!ISGRAPHSC(sc->cur_scp)
1050 || (sc->cur_scp->status & SAVER_RUNNING));
1053 case CONS_SAVERMODE: /* set saver mode */
1054 switch(*(int *)data) {
1056 case CONS_USR_SAVER:
1057 /* if a LKM screen saver is running, stop it first. */
1058 scsplash_stick(FALSE);
1059 saver_mode = *(int *)data;
1062 if ((error = wait_scrn_saver_stop(NULL))) {
1067 run_scrn_saver = TRUE;
1068 if (saver_mode == CONS_USR_SAVER)
1069 scp->status |= SAVER_RUNNING;
1071 scp->status &= ~SAVER_RUNNING;
1072 scsplash_stick(TRUE);
1075 case CONS_LKM_SAVER:
1077 if ((saver_mode == CONS_USR_SAVER) && (scp->status & SAVER_RUNNING))
1078 scp->status &= ~SAVER_RUNNING;
1079 saver_mode = *(int *)data;
1087 case CONS_SAVERSTART: /* immediately start/stop the screen saver */
1089 * Note that this ioctl does not guarantee the screen saver
1090 * actually starts or stops. It merely attempts to do so...
1093 run_scrn_saver = (*(int *)data != 0);
1095 sc->scrn_time_stamp -= scrn_blank_time;
1099 case CONS_SCRSHOT: /* get a screen shot */
1101 int retval, hist_rsz;
1102 size_t lsize, csize;
1103 vm_offset_t frbp, hstp;
1105 scrshot_t *ptr = (scrshot_t *)data;
1106 void *outp = ptr->buf;
1108 if (ptr->x < 0 || ptr->y < 0 || ptr->xsize < 0 || ptr->ysize < 0)
1111 if (ISGRAPHSC(scp)) {
1115 hist_rsz = (scp->history != NULL) ? scp->history->vtb_rows : 0;
1116 if (((u_int)ptr->x + ptr->xsize) > scp->xsize ||
1117 ((u_int)ptr->y + ptr->ysize) > (scp->ysize + hist_rsz)) {
1122 lsize = scp->xsize * sizeof(u_int16_t);
1123 csize = ptr->xsize * sizeof(u_int16_t);
1124 /* Pointer to the last line of framebuffer */
1125 frbp = scp->vtb.vtb_buffer + scp->ysize * lsize + ptr->x *
1127 /* Pointer to the last line of target buffer */
1128 outp = (char *)outp + ptr->ysize * csize;
1129 /* Pointer to the last line of history buffer */
1130 if (scp->history != NULL)
1131 hstp = scp->history->vtb_buffer + sc_vtb_tail(scp->history) *
1132 sizeof(u_int16_t) + ptr->x * sizeof(u_int16_t);
1137 for (lnum = 0; lnum < (ptr->y + ptr->ysize); lnum++) {
1138 if (lnum < scp->ysize) {
1142 if (hstp < scp->history->vtb_buffer)
1143 hstp += scp->history->vtb_rows * lsize;
1148 outp = (char *)outp - csize;
1149 retval = copyout((void *)frbp, outp, csize);
1157 case VT_SETMODE: /* set screen switcher mode */
1159 struct vt_mode *mode;
1162 mode = (struct vt_mode *)data;
1163 DPRINTF(5, ("%s%d: VT_SETMODE ", SC_DRIVER_NAME, sc->unit));
1164 if (scp->smode.mode == VT_PROCESS) {
1165 p1 = pfind(scp->pid);
1166 if (scp->proc == p1 && scp->proc != td->td_proc) {
1169 DPRINTF(5, ("error EPERM\n"));
1176 if (mode->mode == VT_AUTO) {
1177 scp->smode.mode = VT_AUTO;
1180 DPRINTF(5, ("VT_AUTO, "));
1181 if ((scp == sc->cur_scp) && (sc->unit == sc_console_unit))
1182 cnavailable(sc_consptr, TRUE);
1183 /* were we in the middle of the vty switching process? */
1184 if (finish_vt_rel(scp, TRUE, &s) == 0)
1185 DPRINTF(5, ("reset WAIT_REL, "));
1186 if (finish_vt_acq(scp) == 0)
1187 DPRINTF(5, ("reset WAIT_ACQ, "));
1189 if (!ISSIGVALID(mode->relsig) || !ISSIGVALID(mode->acqsig)
1190 || !ISSIGVALID(mode->frsig)) {
1192 DPRINTF(5, ("error EINVAL\n"));
1195 DPRINTF(5, ("VT_PROCESS %d, ", td->td_proc->p_pid));
1196 bcopy(data, &scp->smode, sizeof(struct vt_mode));
1197 scp->proc = td->td_proc;
1198 scp->pid = scp->proc->p_pid;
1199 if ((scp == sc->cur_scp) && (sc->unit == sc_console_unit))
1200 cnavailable(sc_consptr, FALSE);
1207 case VT_GETMODE: /* get screen switcher mode */
1208 bcopy(&scp->smode, data, sizeof(struct vt_mode));
1211 #if defined(COMPAT_FREEBSD6) || defined(COMPAT_FREEBSD5) || \
1212 defined(COMPAT_FREEBSD4) || defined(COMPAT_43)
1214 ival = IOCPARM_IVAL(data);
1215 data = (caddr_t)&ival;
1218 case VT_RELDISP: /* screen switcher ioctl */
1221 * This must be the current vty which is in the VT_PROCESS
1224 if ((scp != sc->cur_scp) || (scp->smode.mode != VT_PROCESS)) {
1228 /* ...and this process is controlling it. */
1229 if (scp->proc != td->td_proc) {
1234 switch(*(int *)data) {
1235 case VT_FALSE: /* user refuses to release screen, abort */
1236 if ((error = finish_vt_rel(scp, FALSE, &s)) == 0)
1237 DPRINTF(5, ("%s%d: VT_FALSE\n", SC_DRIVER_NAME, sc->unit));
1239 case VT_TRUE: /* user has released screen, go on */
1240 if ((error = finish_vt_rel(scp, TRUE, &s)) == 0)
1241 DPRINTF(5, ("%s%d: VT_TRUE\n", SC_DRIVER_NAME, sc->unit));
1243 case VT_ACKACQ: /* acquire acknowledged, switch completed */
1244 if ((error = finish_vt_acq(scp)) == 0)
1245 DPRINTF(5, ("%s%d: VT_ACKACQ\n", SC_DRIVER_NAME, sc->unit));
1253 case VT_OPENQRY: /* return free virtual console */
1254 for (i = sc->first_vty; i < sc->first_vty + sc->vtys; i++) {
1256 if (!tty_opened_ns(tp)) {
1257 *(int *)data = i + 1;
1263 #if defined(COMPAT_FREEBSD6) || defined(COMPAT_FREEBSD5) || \
1264 defined(COMPAT_FREEBSD4) || defined(COMPAT_43)
1266 ival = IOCPARM_IVAL(data);
1267 data = (caddr_t)&ival;
1270 case VT_ACTIVATE: /* switch to screen *data */
1271 i = (*(int *)data == 0) ? scp->index : (*(int *)data - 1);
1273 error = sc_clean_up(sc->cur_scp);
1277 error = sc_switch_scr(sc, i);
1280 #if defined(COMPAT_FREEBSD6) || defined(COMPAT_FREEBSD5) || \
1281 defined(COMPAT_FREEBSD4) || defined(COMPAT_43)
1283 ival = IOCPARM_IVAL(data);
1284 data = (caddr_t)&ival;
1287 case VT_WAITACTIVE: /* wait for switch to occur */
1288 i = (*(int *)data == 0) ? scp->index : (*(int *)data - 1);
1289 if ((i < sc->first_vty) || (i >= sc->first_vty + sc->vtys))
1291 if (i == sc->cur_scp->index)
1293 error = tsleep(VTY_WCHAN(sc, i), (PZERO + 1) | PCATCH, "waitvt", 0);
1296 case VT_GETACTIVE: /* get active vty # */
1297 *(int *)data = sc->cur_scp->index + 1;
1300 case VT_GETINDEX: /* get this vty # */
1301 *(int *)data = scp->index + 1;
1304 case VT_LOCKSWITCH: /* prevent vty switching */
1305 if ((*(int *)data) & 0x01)
1306 sc->flags |= SC_SCRN_VTYLOCK;
1308 sc->flags &= ~SC_SCRN_VTYLOCK;
1311 case KDENABIO: /* allow io operations */
1312 error = priv_check(td, PRIV_IO);
1315 error = securelevel_gt(td->td_ucred, 0);
1319 td->td_frame->tf_eflags |= PSL_IOPL;
1320 #elif defined(__amd64__)
1321 td->td_frame->tf_rflags |= PSL_IOPL;
1325 case KDDISABIO: /* disallow io operations (default) */
1327 td->td_frame->tf_eflags &= ~PSL_IOPL;
1328 #elif defined(__amd64__)
1329 td->td_frame->tf_rflags &= ~PSL_IOPL;
1333 #if defined(COMPAT_FREEBSD6) || defined(COMPAT_FREEBSD5) || \
1334 defined(COMPAT_FREEBSD4) || defined(COMPAT_43)
1336 ival = IOCPARM_IVAL(data);
1337 data = (caddr_t)&ival;
1340 case KDSKBSTATE: /* set keyboard state (locks) */
1341 if (*(int *)data & ~LOCK_MASK)
1343 scp->status &= ~LOCK_MASK;
1344 scp->status |= *(int *)data;
1345 if (scp == sc->cur_scp)
1346 update_kbd_state(scp, scp->status, LOCK_MASK);
1349 case KDGKBSTATE: /* get keyboard state (locks) */
1350 if (scp == sc->cur_scp)
1351 save_kbd_state(scp);
1352 *(int *)data = scp->status & LOCK_MASK;
1355 case KDGETREPEAT: /* get keyboard repeat & delay rates */
1356 case KDSETREPEAT: /* set keyboard repeat & delay rates (new) */
1357 error = kbdd_ioctl(sc->kbd, cmd, data);
1358 if (error == ENOIOCTL)
1362 #if defined(COMPAT_FREEBSD6) || defined(COMPAT_FREEBSD5) || \
1363 defined(COMPAT_FREEBSD4) || defined(COMPAT_43)
1365 ival = IOCPARM_IVAL(data);
1366 data = (caddr_t)&ival;
1369 case KDSETRAD: /* set keyboard repeat & delay rates (old) */
1370 if (*(int *)data & ~0x7f)
1372 error = kbdd_ioctl(sc->kbd, KDSETRAD, data);
1373 if (error == ENOIOCTL)
1377 #if defined(COMPAT_FREEBSD6) || defined(COMPAT_FREEBSD5) || \
1378 defined(COMPAT_FREEBSD4) || defined(COMPAT_43)
1380 ival = IOCPARM_IVAL(data);
1381 data = (caddr_t)&ival;
1384 case KDSKBMODE: /* set keyboard mode */
1385 switch (*(int *)data) {
1386 case K_XLATE: /* switch to XLT ascii mode */
1387 case K_RAW: /* switch to RAW scancode mode */
1388 case K_CODE: /* switch to CODE mode */
1389 scp->kbd_mode = *(int *)data;
1390 if (scp == sc->cur_scp)
1391 (void)kbdd_ioctl(sc->kbd, KDSKBMODE, data);
1398 case KDGKBMODE: /* get keyboard mode */
1399 *(int *)data = scp->kbd_mode;
1403 error = kbdd_ioctl(sc->kbd, cmd, data);
1404 if (error == ENOIOCTL)
1408 #if defined(COMPAT_FREEBSD6) || defined(COMPAT_FREEBSD5) || \
1409 defined(COMPAT_FREEBSD4) || defined(COMPAT_43)
1411 ival = IOCPARM_IVAL(data);
1412 data = (caddr_t)&ival;
1415 case KDMKTONE: /* sound the bell */
1417 sc_bell(scp, (*(int*)data)&0xffff,
1418 (((*(int*)data)>>16)&0xffff)*hz/1000);
1420 sc_bell(scp, scp->bell_pitch, scp->bell_duration);
1423 #if defined(COMPAT_FREEBSD6) || defined(COMPAT_FREEBSD5) || \
1424 defined(COMPAT_FREEBSD4) || defined(COMPAT_43)
1426 ival = IOCPARM_IVAL(data);
1427 data = (caddr_t)&ival;
1430 case KIOCSOUND: /* make tone (*data) hz */
1431 if (scp == sc->cur_scp) {
1433 return sc_tone(*(int *)data);
1439 case KDGKBTYPE: /* get keyboard type */
1440 error = kbdd_ioctl(sc->kbd, cmd, data);
1441 if (error == ENOIOCTL) {
1442 /* always return something? XXX */
1447 #if defined(COMPAT_FREEBSD6) || defined(COMPAT_FREEBSD5) || \
1448 defined(COMPAT_FREEBSD4) || defined(COMPAT_43)
1450 ival = IOCPARM_IVAL(data);
1451 data = (caddr_t)&ival;
1454 case KDSETLED: /* set keyboard LED status */
1455 if (*(int *)data & ~LED_MASK) /* FIXME: LOCK_MASK? */
1457 scp->status &= ~LED_MASK;
1458 scp->status |= *(int *)data;
1459 if (scp == sc->cur_scp)
1460 update_kbd_leds(scp, scp->status);
1463 case KDGETLED: /* get keyboard LED status */
1464 if (scp == sc->cur_scp)
1465 save_kbd_state(scp);
1466 *(int *)data = scp->status & LED_MASK;
1469 case KBADDKBD: /* add/remove keyboard to/from mux */
1471 error = kbdd_ioctl(sc->kbd, cmd, data);
1472 if (error == ENOIOCTL)
1476 #if defined(COMPAT_FREEBSD6) || defined(COMPAT_FREEBSD5) || \
1477 defined(COMPAT_FREEBSD4) || defined(COMPAT_43)
1479 ival = IOCPARM_IVAL(data);
1480 data = (caddr_t)&ival;
1483 case CONS_SETKBD: /* set the new keyboard */
1488 newkbd = kbd_get_keyboard(*(int *)data);
1489 if (newkbd == NULL) {
1494 if (sc->kbd != newkbd) {
1495 i = kbd_allocate(newkbd->kb_name, newkbd->kb_unit,
1496 (void *)&sc->keyboard, sckbdevent, sc);
1497 /* i == newkbd->kb_index */
1499 if (sc->kbd != NULL) {
1500 save_kbd_state(sc->cur_scp);
1501 kbd_release(sc->kbd, (void *)&sc->keyboard);
1503 sc->kbd = kbd_get_keyboard(i); /* sc->kbd == newkbd */
1505 (void)kbdd_ioctl(sc->kbd, KDSKBMODE,
1506 (caddr_t)&sc->cur_scp->kbd_mode);
1507 update_kbd_state(sc->cur_scp, sc->cur_scp->status,
1510 error = EPERM; /* XXX */
1517 case CONS_RELKBD: /* release the current keyboard */
1520 if (sc->kbd != NULL) {
1521 save_kbd_state(sc->cur_scp);
1522 error = kbd_release(sc->kbd, (void *)&sc->keyboard);
1531 case CONS_GETTERM: /* get the current terminal emulator info */
1535 if (((term_info_t *)data)->ti_index == 0) {
1538 sw = sc_term_match_by_number(((term_info_t *)data)->ti_index);
1541 strncpy(((term_info_t *)data)->ti_name, sw->te_name,
1542 sizeof(((term_info_t *)data)->ti_name));
1543 strncpy(((term_info_t *)data)->ti_desc, sw->te_desc,
1544 sizeof(((term_info_t *)data)->ti_desc));
1545 ((term_info_t *)data)->ti_flags = 0;
1548 ((term_info_t *)data)->ti_name[0] = '\0';
1549 ((term_info_t *)data)->ti_desc[0] = '\0';
1550 ((term_info_t *)data)->ti_flags = 0;
1555 case CONS_SETTERM: /* set the current terminal emulator */
1557 error = sc_init_emulator(scp, ((term_info_t *)data)->ti_name);
1558 /* FIXME: what if scp == sc_console! XXX */
1562 case GIO_SCRNMAP: /* get output translation table */
1563 bcopy(&sc->scr_map, data, sizeof(sc->scr_map));
1566 case PIO_SCRNMAP: /* set output translation table */
1567 bcopy(data, &sc->scr_map, sizeof(sc->scr_map));
1568 for (i=0; i<sizeof(sc->scr_map); i++) {
1569 sc->scr_rmap[sc->scr_map[i]] = i;
1573 case GIO_KEYMAP: /* get keyboard translation table */
1574 case PIO_KEYMAP: /* set keyboard translation table */
1575 case OGIO_KEYMAP: /* get keyboard translation table (compat) */
1576 case OPIO_KEYMAP: /* set keyboard translation table (compat) */
1577 case GIO_DEADKEYMAP: /* get accent key translation table */
1578 case PIO_DEADKEYMAP: /* set accent key translation table */
1579 case GETFKEY: /* get function key string */
1580 case SETFKEY: /* set function key string */
1581 error = kbdd_ioctl(sc->kbd, cmd, data);
1582 if (error == ENOIOCTL)
1586 #ifndef SC_NO_FONT_LOADING
1588 case PIO_FONT8x8: /* set 8x8 dot font */
1589 if (!ISFONTAVAIL(sc->adp->va_flags))
1591 bcopy(data, sc->font_8, 8*256);
1592 sc->fonts_loaded |= FONT_8;
1595 * Always use the font page #0. XXX
1596 * Don't load if the current font size is not 8x8.
1598 if (ISTEXTSC(sc->cur_scp) && (sc->cur_scp->font_size < 14))
1599 sc_load_font(sc->cur_scp, 0, 8, 8, sc->font_8, 0, 256);
1602 case GIO_FONT8x8: /* get 8x8 dot font */
1603 if (!ISFONTAVAIL(sc->adp->va_flags))
1605 if (sc->fonts_loaded & FONT_8) {
1606 bcopy(sc->font_8, data, 8*256);
1612 case PIO_FONT8x14: /* set 8x14 dot font */
1613 if (!ISFONTAVAIL(sc->adp->va_flags))
1615 bcopy(data, sc->font_14, 14*256);
1616 sc->fonts_loaded |= FONT_14;
1619 * Always use the font page #0. XXX
1620 * Don't load if the current font size is not 8x14.
1622 if (ISTEXTSC(sc->cur_scp)
1623 && (sc->cur_scp->font_size >= 14)
1624 && (sc->cur_scp->font_size < 16))
1625 sc_load_font(sc->cur_scp, 0, 14, 8, sc->font_14, 0, 256);
1628 case GIO_FONT8x14: /* get 8x14 dot font */
1629 if (!ISFONTAVAIL(sc->adp->va_flags))
1631 if (sc->fonts_loaded & FONT_14) {
1632 bcopy(sc->font_14, data, 14*256);
1638 case PIO_FONT8x16: /* set 8x16 dot font */
1639 if (!ISFONTAVAIL(sc->adp->va_flags))
1641 bcopy(data, sc->font_16, 16*256);
1642 sc->fonts_loaded |= FONT_16;
1645 * Always use the font page #0. XXX
1646 * Don't load if the current font size is not 8x16.
1648 if (ISTEXTSC(sc->cur_scp) && (sc->cur_scp->font_size >= 16))
1649 sc_load_font(sc->cur_scp, 0, 16, 8, sc->font_16, 0, 256);
1652 case GIO_FONT8x16: /* get 8x16 dot font */
1653 if (!ISFONTAVAIL(sc->adp->va_flags))
1655 if (sc->fonts_loaded & FONT_16) {
1656 bcopy(sc->font_16, data, 16*256);
1662 #endif /* SC_NO_FONT_LOADING */
1672 consolectl_ioctl(struct cdev *dev, u_long cmd, caddr_t data, int fflag,
1676 return sctty_ioctl(dev->si_drv1, cmd, data, td);
1680 consolectl_close(struct cdev *dev, int flags, int mode, struct thread *td)
1682 #ifndef SC_NO_SYSMOUSE
1684 memset(&info, 0, sizeof(info));
1685 info.operation = MOUSE_ACTION;
1688 * Make sure all buttons are released when moused and other
1689 * console daemons exit, so that no buttons are left pressed.
1691 (void) sctty_ioctl(dev->si_drv1, CONS_MOUSECTL, (caddr_t)&info, td);
1697 sc_cnprobe(struct consdev *cp)
1702 if (!vty_enabled(VTY_SC)) {
1703 cp->cn_pri = CN_DEAD;
1707 cp->cn_pri = sc_get_cons_priority(&unit, &flags);
1709 /* a video card is always required */
1710 if (!scvidprobe(unit, flags, TRUE))
1711 cp->cn_pri = CN_DEAD;
1713 /* syscons will become console even when there is no keyboard */
1714 sckbdprobe(unit, flags, TRUE);
1716 if (cp->cn_pri == CN_DEAD)
1719 /* initialize required fields */
1720 strcpy(cp->cn_name, "ttyv0");
1724 sc_cninit(struct consdev *cp)
1729 sc_get_cons_priority(&unit, &flags);
1730 scinit(unit, flags | SC_KERNEL_CONSOLE);
1731 sc_console_unit = unit;
1732 sc_console = sc_get_stat(sc_get_softc(unit, SC_KERNEL_CONSOLE)->dev[0]);
1737 sc_cnterm(struct consdev *cp)
1742 /* we are not the kernel console any more, release everything */
1744 if (sc_console_unit < 0)
1745 return; /* shouldn't happen */
1748 sc_clear_screen(sc_console);
1749 sccnupdate(sc_console);
1752 if (sc_ktsw != NULL) {
1753 for (i = 0; i <= mp_maxid; i++) {
1756 (*sc_ktsw->te_term)(sc_console, &ts);
1761 scterm(sc_console_unit, SC_KERNEL_CONSOLE);
1762 sc_console_unit = -1;
1766 static void sccnclose(sc_softc_t *sc, struct sc_cnstate *sp);
1767 static int sc_cngetc_locked(struct sc_cnstate *sp);
1768 static void sccnkbdlock(sc_softc_t *sc, struct sc_cnstate *sp);
1769 static void sccnkbdunlock(sc_softc_t *sc, struct sc_cnstate *sp);
1770 static void sccnopen(sc_softc_t *sc, struct sc_cnstate *sp, int flags);
1771 static void sccnscrlock(sc_softc_t *sc, struct sc_cnstate *sp);
1772 static void sccnscrunlock(sc_softc_t *sc, struct sc_cnstate *sp);
1775 sccnkbdlock(sc_softc_t *sc, struct sc_cnstate *sp)
1778 * Locking method: hope for the best.
1779 * The keyboard is supposed to be Giant locked. We can't handle that
1780 * in general. The kdb_active case here is not safe, and we will
1781 * proceed without the lock in all cases.
1783 sp->kbd_locked = !kdb_active && mtx_trylock(&Giant);
1787 sccnkbdunlock(sc_softc_t *sc, struct sc_cnstate *sp)
1791 sp->kbd_locked = FALSE;
1795 sccnscrlock(sc_softc_t *sc, struct sc_cnstate *sp)
1801 * - if kdb_active and video_mtx is not owned by anyone, then lock
1802 * by kdb remaining active
1803 * - if !kdb_active, try to acquire video_mtx without blocking or
1804 * recursing; if we get it then it works normally.
1805 * Note that video_mtx is especially unusable if we already own it,
1806 * since then it is protecting something and syscons is not reentrant
1807 * enough to ignore the protection even in the kdb_active case.
1810 sp->kdb_locked = sc->video_mtx.mtx_lock == MTX_UNOWNED ||
1811 SCHEDULER_STOPPED();
1812 sp->mtx_locked = FALSE;
1814 sp->kdb_locked = FALSE;
1815 for (retries = 0; retries < 1000; retries++) {
1816 sp->mtx_locked = mtx_trylock_spin_flags(&sc->video_mtx,
1818 if (SCHEDULER_STOPPED()) {
1819 sp->kdb_locked = TRUE;
1820 sp->mtx_locked = FALSE;
1831 sccnscrunlock(sc_softc_t *sc, struct sc_cnstate *sp)
1834 mtx_unlock_spin(&sc->video_mtx);
1835 sp->mtx_locked = sp->kdb_locked = FALSE;
1839 sccnopen(sc_softc_t *sc, struct sc_cnstate *sp, int flags)
1843 /* assert(sc_console_unit >= 0) */
1845 sp->kbd_opened = FALSE;
1846 sp->scr_opened = FALSE;
1847 sp->kbd_locked = FALSE;
1849 /* Opening the keyboard is optional. */
1850 if (!(flags & 1) || sc->kbd == NULL)
1853 sccnkbdlock(sc, sp);
1856 * Make sure the keyboard is accessible even when the kbd device
1857 * driver is disabled.
1859 kbdd_enable(sc->kbd);
1861 /* Switch the keyboard to console mode (K_XLATE, polled) on all scp's. */
1863 (void)kbdd_ioctl(sc->kbd, KDSKBMODE, (caddr_t)&kbd_mode);
1864 sc->kbd_open_level++;
1865 kbdd_poll(sc->kbd, TRUE);
1867 sp->kbd_opened = TRUE;
1870 /* The screen is opened iff locking it succeeds. */
1871 sccnscrlock(sc, sp);
1872 if (!sp->kdb_locked && !sp->mtx_locked)
1874 sp->scr_opened = TRUE;
1876 /* The screen switch is optional. */
1880 /* try to switch to the kernel console screen */
1882 sc->cur_scp->index != sc_console->index &&
1883 sc->cur_scp->smode.mode == VT_AUTO &&
1884 sc_console->smode.mode == VT_AUTO)
1885 sc_switch_scr(sc, sc_console->index);
1889 sccnclose(sc_softc_t *sc, struct sc_cnstate *sp)
1891 sp->scr_opened = FALSE;
1892 sccnscrunlock(sc, sp);
1894 if (!sp->kbd_opened)
1897 /* Restore keyboard mode (for the current, possibly-changed scp). */
1898 kbdd_poll(sc->kbd, FALSE);
1899 if (--sc->kbd_open_level == 0)
1900 (void)kbdd_ioctl(sc->kbd, KDSKBMODE, (caddr_t)&sc->cur_scp->kbd_mode);
1902 kbdd_disable(sc->kbd);
1903 sp->kbd_opened = FALSE;
1904 sccnkbdunlock(sc, sp);
1908 * Grabbing switches the screen and keyboard focus to sc_console and the
1909 * keyboard mode to (K_XLATE, polled). Only switching to polled mode is
1910 * essential (for preventing the interrupt handler from eating input
1911 * between polls). Focus is part of the UI, and the other switches are
1912 * work just was well when they are done on every entry and exit.
1914 * Screen switches while grabbed are supported, and to maintain focus for
1915 * this ungrabbing and closing only restore the polling state and then
1916 * the keyboard mode if on the original screen.
1920 sc_cngrab(struct consdev *cp)
1925 sc = sc_console->sc;
1926 lev = atomic_fetchadd_int(&sc->grab_level, 1);
1927 if (lev >= 0 && lev < 2) {
1928 sccnopen(sc, &sc->grab_state[lev], 1 | 2);
1929 sccnscrunlock(sc, &sc->grab_state[lev]);
1930 sccnkbdunlock(sc, &sc->grab_state[lev]);
1935 sc_cnungrab(struct consdev *cp)
1940 sc = sc_console->sc;
1941 lev = atomic_load_acq_int(&sc->grab_level) - 1;
1942 if (lev >= 0 && lev < 2) {
1943 sccnkbdlock(sc, &sc->grab_state[lev]);
1944 sccnscrlock(sc, &sc->grab_state[lev]);
1945 sccnclose(sc, &sc->grab_state[lev]);
1947 atomic_add_int(&sc->grab_level, -1);
1950 static char sc_cnputc_log[0x1000];
1951 static u_int sc_cnputc_loghead;
1952 static u_int sc_cnputc_logtail;
1955 sc_cnputc(struct consdev *cd, int c)
1957 struct sc_cnstate st;
1959 scr_stat *scp = sc_console;
1961 struct sc_term_sw *oldtsw;
1962 #ifndef SC_NO_HISTORY
1966 #endif /* !SC_NO_HISTORY */
1970 /* assert(sc_console != NULL) */
1972 sccnopen(scp->sc, &st, 0);
1977 * In the unlocked case, the logging is intentionally only
1978 * perfectly atomic for the indexes.
1980 head = atomic_fetchadd_int(&sc_cnputc_loghead, 1);
1981 sc_cnputc_log[head % sizeof(sc_cnputc_log)] = c;
1984 * If we couldn't open, do special reentrant output and return to defer
1987 if (!st.scr_opened) {
1992 #ifndef SC_NO_HISTORY
1993 if (scp == scp->sc->cur_scp && scp->status & SLKED) {
1994 scp->status &= ~SLKED;
1995 update_kbd_state(scp, scp->status, SLKED);
1996 if (scp->status & BUFFER_SAVED) {
1997 if (!sc_hist_restore(scp))
1998 sc_remove_cutmarking(scp);
1999 scp->status &= ~BUFFER_SAVED;
2000 scp->status |= CURSOR_ENABLED;
2001 sc_draw_cursor_image(scp);
2005 * XXX: Now that TTY's have their own locks, we cannot process
2006 * any data after disabling scroll lock. cnputs already holds a
2009 tp = SC_DEV(scp->sc, scp->index);
2010 /* XXX "tp" can be NULL */
2013 sctty_outwakeup(tp);
2017 #endif /* !SC_NO_HISTORY */
2019 /* Play any output still in the log (our char may already be done). */
2020 while (sc_cnputc_logtail != atomic_load_acq_int(&sc_cnputc_loghead)) {
2021 buf[0] = sc_cnputc_log[sc_cnputc_logtail++ % sizeof(sc_cnputc_log)];
2022 if (atomic_load_acq_int(&sc_cnputc_loghead) - sc_cnputc_logtail >=
2023 sizeof(sc_cnputc_log))
2025 /* Console output has a per-CPU "input" state. Switch for it. */
2026 ts = sc_kts[curcpu];
2032 (*scp->tsw->te_sync)(scp);
2034 /* Only 1 tsw early. Switch only its attr. */
2035 (*scp->tsw->te_default_attr)(scp, sc_kattrtab[curcpu],
2036 SC_KERNEL_CONS_REV_ATTR);
2038 sc_puts(scp, buf, 1);
2042 (*scp->tsw->te_sync)(scp);
2044 (*scp->tsw->te_default_attr)(scp, SC_KERNEL_CONS_ATTR,
2045 SC_KERNEL_CONS_REV_ATTR);
2049 s = spltty(); /* block sckbdevent and scrn_timer */
2052 sccnclose(scp->sc, &st);
2056 sc_cngetc(struct consdev *cd)
2058 struct sc_cnstate st;
2061 /* assert(sc_console != NULL) */
2062 sccnopen(sc_console->sc, &st, 1);
2063 s = spltty(); /* block sckbdevent and scrn_timer while we poll */
2064 if (!st.kbd_opened) {
2066 sccnclose(sc_console->sc, &st);
2067 return -1; /* means no keyboard since we fudged the locking */
2069 c = sc_cngetc_locked(&st);
2071 sccnclose(sc_console->sc, &st);
2076 sc_cngetc_locked(struct sc_cnstate *sp)
2078 static struct fkeytab fkey;
2085 * Stop the screen saver and update the screen if necessary.
2086 * What if we have been running in the screen saver code... XXX
2089 sc_touch_scrn_saver();
2090 scp = sc_console->sc->cur_scp; /* XXX */
2094 if (fkeycp < fkey.len)
2095 return fkey.str[fkeycp++];
2097 c = scgetc(scp->sc, SCGETC_CN | SCGETC_NONBLOCK, sp);
2099 switch (KEYFLAGS(c)) {
2100 case 0: /* normal char */
2102 case FKEY: /* function key */
2103 p = (*scp->tsw->te_fkeystr)(scp, c);
2105 fkey.len = strlen(p);
2106 bcopy(p, fkey.str, fkey.len);
2110 p = kbdd_get_fkeystr(scp->sc->kbd, KEYCHAR(c), (size_t *)&fkeycp);
2112 if ((p != NULL) && (fkey.len > 0)) {
2113 bcopy(p, fkey.str, fkey.len);
2127 sccnupdate(scr_stat *scp)
2129 /* this is a cut-down version of scrn_timer()... */
2131 if (suspend_in_progress || scp->sc->font_loading_in_progress)
2134 if (kdb_active || panicstr || shutdown_in_progress) {
2135 sc_touch_scrn_saver();
2136 } else if (scp != scp->sc->cur_scp) {
2140 if (!run_scrn_saver)
2141 scp->sc->flags &= ~SC_SCRN_IDLE;
2143 if ((saver_mode != CONS_LKM_SAVER) || !(scp->sc->flags & SC_SCRN_IDLE))
2144 if (scp->sc->flags & SC_SCRN_BLANKED)
2145 stop_scrn_saver(scp->sc, current_saver);
2148 if (scp != scp->sc->cur_scp || scp->sc->blink_in_progress
2149 || scp->sc->switch_in_progress)
2152 * FIXME: unlike scrn_timer(), we call scrn_update() from here even
2153 * when write_in_progress is non-zero. XXX
2156 if (!ISGRAPHSC(scp) && !(scp->sc->flags & SC_SCRN_BLANKED))
2157 scrn_update(scp, TRUE);
2161 scrn_timer(void *arg)
2163 static time_t kbd_time_stamp = 0;
2168 again = (arg != NULL);
2170 sc = (sc_softc_t *)arg;
2171 else if (sc_console != NULL)
2172 sc = sc_console->sc;
2176 /* find the vty to update */
2179 /* don't do anything when we are performing some I/O operations */
2180 if (suspend_in_progress || sc->font_loading_in_progress)
2183 if ((sc->kbd == NULL) && (sc->config & SC_AUTODETECT_KBD)) {
2184 /* try to allocate a keyboard automatically */
2185 if (kbd_time_stamp != time_uptime) {
2186 kbd_time_stamp = time_uptime;
2187 sc->keyboard = sc_allocate_keyboard(sc, -1);
2188 if (sc->keyboard >= 0) {
2189 sc->kbd = kbd_get_keyboard(sc->keyboard);
2190 (void)kbdd_ioctl(sc->kbd, KDSKBMODE,
2191 (caddr_t)&sc->cur_scp->kbd_mode);
2192 update_kbd_state(sc->cur_scp, sc->cur_scp->status,
2198 /* should we stop the screen saver? */
2199 if (kdb_active || panicstr || shutdown_in_progress)
2200 sc_touch_scrn_saver();
2201 if (run_scrn_saver) {
2202 if (time_uptime > sc->scrn_time_stamp + scrn_blank_time)
2203 sc->flags |= SC_SCRN_IDLE;
2205 sc->flags &= ~SC_SCRN_IDLE;
2207 sc->scrn_time_stamp = time_uptime;
2208 sc->flags &= ~SC_SCRN_IDLE;
2209 if (scrn_blank_time > 0)
2210 run_scrn_saver = TRUE;
2213 if ((saver_mode != CONS_LKM_SAVER) || !(sc->flags & SC_SCRN_IDLE))
2214 if (sc->flags & SC_SCRN_BLANKED)
2215 stop_scrn_saver(sc, current_saver);
2218 /* should we just return ? */
2219 if (sc->blink_in_progress || sc->switch_in_progress
2220 || sc->write_in_progress)
2223 /* Update the screen */
2224 scp = sc->cur_scp; /* cur_scp may have changed... */
2225 if (!ISGRAPHSC(scp) && !(sc->flags & SC_SCRN_BLANKED))
2226 scrn_update(scp, TRUE);
2229 /* should we activate the screen saver? */
2230 if ((saver_mode == CONS_LKM_SAVER) && (sc->flags & SC_SCRN_IDLE))
2231 if (!ISGRAPHSC(scp) || (sc->flags & SC_SCRN_BLANKED))
2232 (*current_saver)(sc, TRUE);
2238 * Use reduced "refresh" rate if we are in graphics and that is not a
2239 * graphical screen saver. In such case we just have nothing to do.
2241 if (ISGRAPHSC(scp) && !(sc->flags & SC_SCRN_BLANKED))
2245 callout_reset_sbt(&sc->ctimeout, SBT_1S / rate, 0,
2246 scrn_timer, sc, C_PREL(1));
2251 and_region(int *s1, int *e1, int s2, int e2)
2253 if (*e1 < s2 || e2 < *s1)
2255 *s1 = imax(*s1, s2);
2256 *e1 = imin(*e1, e2);
2261 scrn_update(scr_stat *scp, int show_cursor)
2268 /* assert(scp == scp->sc->cur_scp) */
2270 SC_VIDEO_LOCK(scp->sc);
2272 #ifndef SC_NO_CUTPASTE
2273 /* remove the previous mouse pointer image if necessary */
2274 if (scp->status & MOUSE_VISIBLE) {
2276 e = scp->mouse_pos + scp->xsize + 1;
2277 if ((scp->status & (MOUSE_MOVED | MOUSE_HIDDEN))
2278 || and_region(&s, &e, scp->start, scp->end)
2279 || ((scp->status & CURSOR_ENABLED) &&
2280 (scp->cursor_pos != scp->cursor_oldpos) &&
2281 (and_region(&s, &e, scp->cursor_pos, scp->cursor_pos)
2282 || and_region(&s, &e, scp->cursor_oldpos, scp->cursor_oldpos)))) {
2283 sc_remove_mouse_image(scp);
2284 if (scp->end >= scp->xsize*scp->ysize)
2285 scp->end = scp->xsize*scp->ysize - 1;
2288 #endif /* !SC_NO_CUTPASTE */
2292 if (scp->end >= scp->xsize*scp->ysize) {
2293 printf("scrn_update(): scp->end %d > size_of_screen!!\n", scp->end);
2294 scp->end = scp->xsize*scp->ysize - 1;
2296 if (scp->start < 0) {
2297 printf("scrn_update(): scp->start %d < 0\n", scp->start);
2302 /* update screen image */
2303 if (scp->start <= scp->end) {
2304 if (scp->mouse_cut_end >= 0) {
2305 /* there is a marked region for cut & paste */
2306 if (scp->mouse_cut_start <= scp->mouse_cut_end) {
2307 start = scp->mouse_cut_start;
2308 end = scp->mouse_cut_end;
2310 start = scp->mouse_cut_end;
2311 end = scp->mouse_cut_start - 1;
2315 /* does the cut-mark region overlap with the update region? */
2316 if (and_region(&s, &e, scp->start, scp->end)) {
2317 (*scp->rndr->draw)(scp, s, e - s + 1, TRUE);
2320 if (and_region(&s, &e, scp->start, scp->end))
2321 (*scp->rndr->draw)(scp, s, e - s + 1, FALSE);
2323 e = scp->xsize*scp->ysize - 1;
2324 if (and_region(&s, &e, scp->start, scp->end))
2325 (*scp->rndr->draw)(scp, s, e - s + 1, FALSE);
2327 (*scp->rndr->draw)(scp, scp->start,
2328 scp->end - scp->start + 1, FALSE);
2331 (*scp->rndr->draw)(scp, scp->start,
2332 scp->end - scp->start + 1, FALSE);
2336 /* we are not to show the cursor and the mouse pointer... */
2339 scp->start = scp->xsize*scp->ysize - 1;
2340 SC_VIDEO_UNLOCK(scp->sc);
2344 /* update cursor image */
2345 if (scp->status & CURSOR_ENABLED) {
2348 /* did cursor move since last time ? */
2349 if (scp->cursor_pos != scp->cursor_oldpos) {
2350 /* do we need to remove old cursor image ? */
2351 if (!and_region(&s, &e, scp->cursor_oldpos, scp->cursor_oldpos))
2352 sc_remove_cursor_image(scp);
2353 sc_draw_cursor_image(scp);
2355 if (and_region(&s, &e, scp->cursor_pos, scp->cursor_pos))
2356 /* cursor didn't move, but has been overwritten */
2357 sc_draw_cursor_image(scp);
2358 else if (scp->curs_attr.flags & CONS_BLINK_CURSOR)
2359 /* if it's a blinking cursor, update it */
2360 (*scp->rndr->blink_cursor)(scp, scp->cursor_pos,
2361 sc_inside_cutmark(scp,
2366 #ifndef SC_NO_CUTPASTE
2367 /* update "pseudo" mouse pointer image */
2368 if (scp->sc->flags & SC_MOUSE_ENABLED) {
2369 if (!(scp->status & (MOUSE_VISIBLE | MOUSE_HIDDEN))) {
2370 scp->status &= ~MOUSE_MOVED;
2371 sc_draw_mouse_image(scp);
2374 #endif /* SC_NO_CUTPASTE */
2377 scp->start = scp->xsize*scp->ysize - 1;
2379 SC_VIDEO_UNLOCK(scp->sc);
2384 scsplash_callback(int event, void *arg)
2389 sc = (sc_softc_t *)arg;
2393 if (add_scrn_saver(scsplash_saver) == 0) {
2394 sc->flags &= ~SC_SAVER_FAILED;
2395 run_scrn_saver = TRUE;
2396 if (cold && !(boothowto & RB_VERBOSE)) {
2397 scsplash_stick(TRUE);
2398 (*current_saver)(sc, TRUE);
2404 if (current_saver == scsplash_saver) {
2405 scsplash_stick(FALSE);
2406 error = remove_scrn_saver(scsplash_saver);
2418 scsplash_saver(sc_softc_t *sc, int show)
2420 static int busy = FALSE;
2429 if (!(sc->flags & SC_SAVER_FAILED)) {
2430 if (!(sc->flags & SC_SCRN_BLANKED))
2431 set_scrn_saver_mode(scp, -1, NULL, 0);
2432 switch (splash(sc->adp, TRUE)) {
2433 case 0: /* succeeded */
2435 case EAGAIN: /* try later */
2436 restore_scrn_saver_mode(scp, FALSE);
2437 sc_touch_scrn_saver(); /* XXX */
2440 sc->flags |= SC_SAVER_FAILED;
2441 scsplash_stick(FALSE);
2442 restore_scrn_saver_mode(scp, TRUE);
2443 printf("scsplash_saver(): failed to put up the image\n");
2447 } else if (!sticky_splash) {
2448 if ((sc->flags & SC_SCRN_BLANKED) && (splash(sc->adp, FALSE) == 0))
2449 restore_scrn_saver_mode(scp, TRUE);
2455 add_scrn_saver(void (*this_saver)(sc_softc_t *, int))
2460 if (current_saver != none_saver) {
2461 error = remove_scrn_saver(current_saver);
2466 if (current_saver != none_saver)
2469 run_scrn_saver = FALSE;
2470 saver_mode = CONS_LKM_SAVER;
2471 current_saver = this_saver;
2476 remove_scrn_saver(void (*this_saver)(sc_softc_t *, int))
2478 if (current_saver != this_saver)
2483 * In order to prevent `current_saver' from being called by
2484 * the timeout routine `scrn_timer()' while we manipulate
2485 * the saver list, we shall set `current_saver' to `none_saver'
2486 * before stopping the current saver, rather than blocking by `splXX()'.
2488 current_saver = none_saver;
2490 stop_scrn_saver(this_saver);
2493 /* unblank all blanked screens */
2494 wait_scrn_saver_stop(NULL);
2498 current_saver = none_saver;
2503 set_scrn_saver_mode(scr_stat *scp, int mode, u_char *pal, int border)
2507 /* assert(scp == scp->sc->cur_scp) */
2509 if (!ISGRAPHSC(scp))
2510 sc_remove_cursor_image(scp);
2511 scp->splash_save_mode = scp->mode;
2512 scp->splash_save_status = scp->status & (GRAPHICS_MODE | PIXEL_MODE);
2513 scp->status &= ~(GRAPHICS_MODE | PIXEL_MODE);
2514 scp->status |= (UNKNOWN_MODE | SAVER_RUNNING);
2515 scp->sc->flags |= SC_SCRN_BLANKED;
2521 if (set_mode(scp) == 0) {
2522 if (scp->sc->adp->va_info.vi_flags & V_INFO_GRAPHICS)
2523 scp->status |= GRAPHICS_MODE;
2524 #ifndef SC_NO_PALETTE_LOADING
2526 vidd_load_palette(scp->sc->adp, pal);
2528 sc_set_border(scp, border);
2532 scp->mode = scp->splash_save_mode;
2533 scp->status &= ~(UNKNOWN_MODE | SAVER_RUNNING);
2534 scp->status |= scp->splash_save_status;
2541 restore_scrn_saver_mode(scr_stat *scp, int changemode)
2547 /* assert(scp == scp->sc->cur_scp) */
2550 status = scp->status;
2551 scp->mode = scp->splash_save_mode;
2552 scp->status &= ~(UNKNOWN_MODE | SAVER_RUNNING);
2553 scp->status |= scp->splash_save_status;
2554 scp->sc->flags &= ~SC_SCRN_BLANKED;
2556 if (!ISGRAPHSC(scp))
2557 sc_draw_cursor_image(scp);
2562 if (set_mode(scp) == 0) {
2563 #ifndef SC_NO_PALETTE_LOADING
2564 #ifdef SC_PIXEL_MODE
2565 if (scp->sc->adp->va_info.vi_mem_model == V_INFO_MM_DIRECT)
2566 vidd_load_palette(scp->sc->adp, scp->sc->palette2);
2569 vidd_load_palette(scp->sc->adp, scp->sc->palette);
2576 scp->status = status;
2583 stop_scrn_saver(sc_softc_t *sc, void (*saver)(sc_softc_t *, int))
2585 (*saver)(sc, FALSE);
2586 run_scrn_saver = FALSE;
2587 /* the screen saver may have chosen not to stop after all... */
2588 if (sc->flags & SC_SCRN_BLANKED)
2591 mark_all(sc->cur_scp);
2592 if (sc->delayed_next_scr)
2593 sc_switch_scr(sc, sc->delayed_next_scr - 1);
2595 wakeup(&scrn_blanked);
2599 wait_scrn_saver_stop(sc_softc_t *sc)
2603 while (scrn_blanked > 0) {
2604 run_scrn_saver = FALSE;
2605 if (sc && !(sc->flags & SC_SCRN_BLANKED)) {
2609 error = tsleep(&scrn_blanked, PZERO | PCATCH, "scrsav", 0);
2610 if ((error != 0) && (error != ERESTART))
2613 run_scrn_saver = FALSE;
2616 #endif /* DEV_SPLASH */
2619 sc_touch_scrn_saver(void)
2621 scsplash_stick(FALSE);
2622 run_scrn_saver = FALSE;
2626 sc_switch_scr(sc_softc_t *sc, u_int next_scr)
2633 DPRINTF(5, ("sc0: sc_switch_scr() %d ", next_scr + 1));
2635 if (sc->cur_scp == NULL)
2638 /* prevent switch if previously requested */
2639 if (sc->flags & SC_SCRN_VTYLOCK) {
2640 sc_bell(sc->cur_scp, sc->cur_scp->bell_pitch,
2641 sc->cur_scp->bell_duration);
2645 /* delay switch if the screen is blanked or being updated */
2646 if ((sc->flags & SC_SCRN_BLANKED) || sc->write_in_progress
2647 || sc->blink_in_progress) {
2648 sc->delayed_next_scr = next_scr + 1;
2649 sc_touch_scrn_saver();
2650 DPRINTF(5, ("switch delayed\n"));
2653 sc->delayed_next_scr = 0;
2656 cur_scp = sc->cur_scp;
2658 /* we are in the middle of the vty switching process... */
2659 if (sc->switch_in_progress
2660 && (cur_scp->smode.mode == VT_PROCESS)
2662 p = pfind(cur_scp->pid);
2663 if (cur_scp->proc != p) {
2667 * The controlling process has died!!. Do some clean up.
2668 * NOTE:`cur_scp->proc' and `cur_scp->smode.mode'
2669 * are not reset here yet; they will be cleared later.
2671 DPRINTF(5, ("cur_scp controlling process %d died, ",
2673 if (cur_scp->status & SWITCH_WAIT_REL) {
2675 * Force the previous switch to finish, but return now
2678 DPRINTF(5, ("reset WAIT_REL, "));
2679 finish_vt_rel(cur_scp, TRUE, &s);
2681 DPRINTF(5, ("finishing previous switch\n"));
2683 } else if (cur_scp->status & SWITCH_WAIT_ACQ) {
2684 /* let's assume screen switch has been completed. */
2685 DPRINTF(5, ("reset WAIT_ACQ, "));
2686 finish_vt_acq(cur_scp);
2689 * We are in between screen release and acquisition, and
2690 * reached here via scgetc() or scrn_timer() which has
2691 * interrupted exchange_scr(). Don't do anything stupid.
2693 DPRINTF(5, ("waiting nothing, "));
2699 * The controlling process is alive, but not responding...
2700 * It is either buggy or it may be just taking time.
2701 * The following code is a gross kludge to cope with this
2702 * problem for which there is no clean solution. XXX
2704 if (cur_scp->status & SWITCH_WAIT_REL) {
2705 switch (sc->switch_in_progress++) {
2709 DPRINTF(5, ("sending relsig again, "));
2710 signal_vt_rel(cur_scp);
2717 * Act as if the controlling program returned
2720 DPRINTF(5, ("force reset WAIT_REL, "));
2721 finish_vt_rel(cur_scp, FALSE, &s);
2723 DPRINTF(5, ("act as if VT_FALSE was seen\n"));
2726 } else if (cur_scp->status & SWITCH_WAIT_ACQ) {
2727 switch (sc->switch_in_progress++) {
2731 DPRINTF(5, ("sending acqsig again, "));
2732 signal_vt_acq(cur_scp);
2738 /* clear the flag and finish the previous switch */
2739 DPRINTF(5, ("force reset WAIT_ACQ, "));
2740 finish_vt_acq(cur_scp);
2748 * Return error if an invalid argument is given, or vty switch
2749 * is still in progress.
2751 if ((next_scr < sc->first_vty) || (next_scr >= sc->first_vty + sc->vtys)
2752 || sc->switch_in_progress) {
2754 sc_bell(cur_scp, bios_value.bell_pitch, BELL_DURATION);
2755 DPRINTF(5, ("error 1\n"));
2760 * Don't allow switching away from the graphics mode vty
2761 * if the switch mode is VT_AUTO, unless the next vty is the same
2762 * as the current or the current vty has been closed (but showing).
2764 tp = SC_DEV(sc, cur_scp->index);
2765 if ((cur_scp->index != next_scr)
2766 && tty_opened_ns(tp)
2767 && (cur_scp->smode.mode == VT_AUTO)
2768 && ISGRAPHSC(cur_scp)) {
2770 sc_bell(cur_scp, bios_value.bell_pitch, BELL_DURATION);
2771 DPRINTF(5, ("error, graphics mode\n"));
2776 * Is the wanted vty open? Don't allow switching to a closed vty.
2777 * If we are in DDB, don't switch to a vty in the VT_PROCESS mode.
2778 * Note that we always allow the user to switch to the kernel
2779 * console even if it is closed.
2781 if ((sc_console == NULL) || (next_scr != sc_console->index)) {
2782 tp = SC_DEV(sc, next_scr);
2783 if (!tty_opened_ns(tp)) {
2785 sc_bell(cur_scp, bios_value.bell_pitch, BELL_DURATION);
2786 DPRINTF(5, ("error 2, requested vty isn't open!\n"));
2789 if (kdb_active && SC_STAT(tp)->smode.mode == VT_PROCESS) {
2791 DPRINTF(5, ("error 3, requested vty is in the VT_PROCESS mode\n"));
2796 /* this is the start of vty switching process... */
2797 ++sc->switch_in_progress;
2798 sc->old_scp = cur_scp;
2799 sc->new_scp = sc_get_stat(SC_DEV(sc, next_scr));
2800 if (sc->new_scp == sc->old_scp) {
2801 sc->switch_in_progress = 0;
2803 * XXX wakeup() locks the scheduler lock which will hang if
2804 * the lock is in an in-between state, e.g., when we stop at
2805 * a breakpoint at fork_exit. It has always been wrong to call
2806 * wakeup() when the debugger is active. In RELENG_4, wakeup()
2807 * is supposed to be locked by splhigh(), but the debugger may
2808 * be invoked at splhigh().
2811 wakeup(VTY_WCHAN(sc,next_scr));
2813 DPRINTF(5, ("switch done (new == old)\n"));
2817 /* has controlling process died? */
2818 vt_proc_alive(sc->old_scp);
2819 vt_proc_alive(sc->new_scp);
2821 /* wait for the controlling process to release the screen, if necessary */
2822 if (signal_vt_rel(sc->old_scp)) {
2827 /* go set up the new vty screen */
2832 /* wake up processes waiting for this vty */
2834 wakeup(VTY_WCHAN(sc,next_scr));
2836 /* wait for the controlling process to acknowledge, if necessary */
2837 if (signal_vt_acq(sc->cur_scp)) {
2842 sc->switch_in_progress = 0;
2843 if (sc->unit == sc_console_unit)
2844 cnavailable(sc_consptr, TRUE);
2846 DPRINTF(5, ("switch done\n"));
2852 do_switch_scr(sc_softc_t *sc, int s)
2854 vt_proc_alive(sc->new_scp);
2859 /* sc->cur_scp == sc->new_scp */
2860 wakeup(VTY_WCHAN(sc,sc->cur_scp->index));
2862 /* wait for the controlling process to acknowledge, if necessary */
2863 if (!signal_vt_acq(sc->cur_scp)) {
2864 sc->switch_in_progress = 0;
2865 if (sc->unit == sc_console_unit)
2866 cnavailable(sc_consptr, TRUE);
2873 vt_proc_alive(scr_stat *scp)
2878 if ((p = pfind(scp->pid)) != NULL)
2883 scp->smode.mode = VT_AUTO;
2884 DPRINTF(5, ("vt controlling process %d died\n", scp->pid));
2890 signal_vt_rel(scr_stat *scp)
2892 if (scp->smode.mode != VT_PROCESS)
2894 scp->status |= SWITCH_WAIT_REL;
2895 PROC_LOCK(scp->proc);
2896 kern_psignal(scp->proc, scp->smode.relsig);
2897 PROC_UNLOCK(scp->proc);
2898 DPRINTF(5, ("sending relsig to %d\n", scp->pid));
2903 signal_vt_acq(scr_stat *scp)
2905 if (scp->smode.mode != VT_PROCESS)
2907 if (scp->sc->unit == sc_console_unit)
2908 cnavailable(sc_consptr, FALSE);
2909 scp->status |= SWITCH_WAIT_ACQ;
2910 PROC_LOCK(scp->proc);
2911 kern_psignal(scp->proc, scp->smode.acqsig);
2912 PROC_UNLOCK(scp->proc);
2913 DPRINTF(5, ("sending acqsig to %d\n", scp->pid));
2918 finish_vt_rel(scr_stat *scp, int release, int *s)
2920 if (scp == scp->sc->old_scp && scp->status & SWITCH_WAIT_REL) {
2921 scp->status &= ~SWITCH_WAIT_REL;
2923 *s = do_switch_scr(scp->sc, *s);
2925 scp->sc->switch_in_progress = 0;
2932 finish_vt_acq(scr_stat *scp)
2934 if (scp == scp->sc->new_scp && scp->status & SWITCH_WAIT_ACQ) {
2935 scp->status &= ~SWITCH_WAIT_ACQ;
2936 scp->sc->switch_in_progress = 0;
2943 exchange_scr(sc_softc_t *sc)
2947 /* save the current state of video and keyboard */
2948 sc_move_cursor(sc->old_scp, sc->old_scp->xpos, sc->old_scp->ypos);
2949 if (!ISGRAPHSC(sc->old_scp))
2950 sc_remove_cursor_image(sc->old_scp);
2951 if (sc->old_scp->kbd_mode == K_XLATE)
2952 save_kbd_state(sc->old_scp);
2954 /* set up the video for the new screen */
2955 scp = sc->cur_scp = sc->new_scp;
2956 if (sc->old_scp->mode != scp->mode || ISUNKNOWNSC(sc->old_scp))
2960 sc_vtb_init(&scp->scr, VTB_FRAMEBUFFER, scp->xsize, scp->ysize,
2961 (void *)sc->adp->va_window, FALSE);
2963 scp->status |= MOUSE_HIDDEN;
2964 sc_move_cursor(scp, scp->xpos, scp->ypos);
2965 if (!ISGRAPHSC(scp))
2966 sc_set_cursor_image(scp);
2967 #ifndef SC_NO_PALETTE_LOADING
2968 if (ISGRAPHSC(sc->old_scp)) {
2969 #ifdef SC_PIXEL_MODE
2970 if (sc->adp->va_info.vi_mem_model == V_INFO_MM_DIRECT)
2971 vidd_load_palette(sc->adp, sc->palette2);
2974 vidd_load_palette(sc->adp, sc->palette);
2977 sc_set_border(scp, scp->border);
2979 /* set up the keyboard for the new screen */
2980 if (sc->kbd_open_level == 0 && sc->old_scp->kbd_mode != scp->kbd_mode)
2981 (void)kbdd_ioctl(sc->kbd, KDSKBMODE, (caddr_t)&scp->kbd_mode);
2982 update_kbd_state(scp, scp->status, LOCK_MASK);
2988 sc_puts(scr_stat *scp, u_char *buf, int len)
2991 /* make screensaver happy */
2992 if (!sticky_splash && scp == scp->sc->cur_scp && !sc_saver_keyb_only)
2993 run_scrn_saver = FALSE;
2997 (*scp->tsw->te_puts)(scp, buf, len);
2998 if (scp->sc->delayed_next_scr)
2999 sc_switch_scr(scp->sc, scp->sc->delayed_next_scr - 1);
3003 sc_draw_cursor_image(scr_stat *scp)
3005 /* assert(scp == scp->sc->cur_scp); */
3006 SC_VIDEO_LOCK(scp->sc);
3007 (*scp->rndr->draw_cursor)(scp, scp->cursor_pos,
3008 scp->curs_attr.flags & CONS_BLINK_CURSOR, TRUE,
3009 sc_inside_cutmark(scp, scp->cursor_pos));
3010 scp->cursor_oldpos = scp->cursor_pos;
3011 SC_VIDEO_UNLOCK(scp->sc);
3015 sc_remove_cursor_image(scr_stat *scp)
3017 /* assert(scp == scp->sc->cur_scp); */
3018 SC_VIDEO_LOCK(scp->sc);
3019 (*scp->rndr->draw_cursor)(scp, scp->cursor_oldpos,
3020 scp->curs_attr.flags & CONS_BLINK_CURSOR, FALSE,
3021 sc_inside_cutmark(scp, scp->cursor_oldpos));
3022 SC_VIDEO_UNLOCK(scp->sc);
3026 update_cursor_image(scr_stat *scp)
3028 /* assert(scp == scp->sc->cur_scp); */
3029 sc_remove_cursor_image(scp);
3030 sc_set_cursor_image(scp);
3031 sc_draw_cursor_image(scp);
3035 sc_set_cursor_image(scr_stat *scp)
3037 scp->curs_attr = scp->base_curs_attr;
3038 if (scp->curs_attr.flags & CONS_HIDDEN_CURSOR) {
3039 /* hidden cursor is internally represented as zero-height underline */
3040 scp->curs_attr.flags = CONS_CHAR_CURSOR;
3041 scp->curs_attr.base = scp->curs_attr.height = 0;
3042 } else if (scp->curs_attr.flags & CONS_CHAR_CURSOR) {
3043 scp->curs_attr.base = imin(scp->base_curs_attr.base,
3044 scp->font_size - 1);
3045 scp->curs_attr.height = imin(scp->base_curs_attr.height,
3046 scp->font_size - scp->curs_attr.base);
3047 } else { /* block cursor */
3048 scp->curs_attr.base = 0;
3049 scp->curs_attr.height = scp->font_size;
3052 /* assert(scp == scp->sc->cur_scp); */
3053 SC_VIDEO_LOCK(scp->sc);
3054 (*scp->rndr->set_cursor)(scp, scp->curs_attr.base, scp->curs_attr.height,
3055 scp->curs_attr.flags & CONS_BLINK_CURSOR);
3056 SC_VIDEO_UNLOCK(scp->sc);
3060 sc_adjust_ca(struct cursor_attr *cap, int flags, int base, int height)
3062 if (flags & CONS_CHARCURSOR_COLORS) {
3063 cap->bg[0] = base & 0xff;
3064 cap->bg[1] = height & 0xff;
3065 } else if (flags & CONS_MOUSECURSOR_COLORS) {
3066 cap->mouse_ba = base & 0xff;
3067 cap->mouse_ia = height & 0xff;
3072 cap->height = height;
3073 if (!(flags & CONS_SHAPEONLY_CURSOR))
3074 cap->flags = flags & CONS_CURSOR_ATTRS;
3079 change_cursor_shape(scr_stat *scp, int flags, int base, int height)
3081 if ((scp == scp->sc->cur_scp) && !ISGRAPHSC(scp))
3082 sc_remove_cursor_image(scp);
3084 if (flags & CONS_RESET_CURSOR)
3085 scp->base_curs_attr = scp->dflt_curs_attr;
3086 else if (flags & CONS_DEFAULT_CURSOR) {
3087 sc_adjust_ca(&scp->dflt_curs_attr, flags, base, height);
3088 scp->base_curs_attr = scp->dflt_curs_attr;
3090 sc_adjust_ca(&scp->base_curs_attr, flags, base, height);
3092 if ((scp == scp->sc->cur_scp) && !ISGRAPHSC(scp)) {
3093 sc_set_cursor_image(scp);
3094 sc_draw_cursor_image(scp);
3099 sc_change_cursor_shape(scr_stat *scp, int flags, int base, int height)
3107 flags = CONS_SHAPEONLY_CURSOR;
3110 if (flags & CONS_LOCAL_CURSOR) {
3111 /* local (per vty) change */
3112 change_cursor_shape(scp, flags, base, height);
3119 if (flags & CONS_RESET_CURSOR)
3120 sc->curs_attr = sc->dflt_curs_attr;
3121 else if (flags & CONS_DEFAULT_CURSOR) {
3122 sc_adjust_ca(&sc->dflt_curs_attr, flags, base, height);
3123 sc->curs_attr = sc->dflt_curs_attr;
3125 sc_adjust_ca(&sc->curs_attr, flags, base, height);
3127 for (i = sc->first_vty; i < sc->first_vty + sc->vtys; ++i) {
3128 if ((tp = SC_DEV(sc, i)) == NULL)
3130 if ((scp = sc_get_stat(tp)) == NULL)
3132 scp->dflt_curs_attr = sc->curs_attr;
3133 change_cursor_shape(scp, CONS_RESET_CURSOR, -1, -1);
3139 scinit(int unit, int flags)
3143 * When syscons is being initialized as the kernel console, malloc()
3144 * is not yet functional, because various kernel structures has not been
3145 * fully initialized yet. Therefore, we need to declare the following
3146 * static buffers for the console. This is less than ideal,
3147 * but is necessry evil for the time being. XXX
3149 static u_short sc_buffer[ROW*COL]; /* XXX */
3150 #ifndef SC_NO_FONT_LOADING
3151 static u_char font_8[256*8];
3152 static u_char font_14[256*14];
3153 static u_char font_16[256*16];
3156 #ifdef SC_KERNEL_CONS_ATTRS
3157 static const u_char dflt_kattrtab[] = SC_KERNEL_CONS_ATTRS;
3158 #elif SC_KERNEL_CONS_ATTR == FG_WHITE
3159 static const u_char dflt_kattrtab[] = {
3160 FG_WHITE, FG_YELLOW, FG_LIGHTMAGENTA, FG_LIGHTRED,
3161 FG_LIGHTCYAN, FG_LIGHTGREEN, FG_LIGHTBLUE, FG_GREEN,
3165 static const u_char dflt_kattrtab[] = { FG_WHITE, 0, };
3169 video_adapter_t *adp;
3174 /* one time initialization */
3175 if (init_done == COLD) {
3176 sc_get_bios_values(&bios_value);
3177 for (i = 0; i < nitems(sc_kattrtab); i++)
3178 sc_kattrtab[i] = dflt_kattrtab[i % (nitems(dflt_kattrtab) - 1)];
3183 * Allocate resources. Even if we are being called for the second
3184 * time, we must allocate them again, because they might have
3187 sc = sc_get_softc(unit, flags & SC_KERNEL_CONSOLE);
3188 if ((sc->flags & SC_INIT_DONE) == 0)
3189 SC_VIDEO_LOCKINIT(sc);
3192 if (sc->adapter >= 0) {
3193 vid_release(sc->adp, (void *)&sc->adapter);
3197 if (sc->keyboard >= 0) {
3198 DPRINTF(5, ("sc%d: releasing kbd%d\n", unit, sc->keyboard));
3199 i = kbd_release(sc->kbd, (void *)&sc->keyboard);
3200 DPRINTF(5, ("sc%d: kbd_release returned %d\n", unit, i));
3201 if (sc->kbd != NULL) {
3202 DPRINTF(5, ("sc%d: kbd != NULL!, index:%d, unit:%d, flags:0x%x\n",
3203 unit, sc->kbd->kb_index, sc->kbd->kb_unit, sc->kbd->kb_flags));
3207 sc->adapter = vid_allocate("*", unit, (void *)&sc->adapter);
3208 sc->adp = vid_get_adapter(sc->adapter);
3209 /* assert((sc->adapter >= 0) && (sc->adp != NULL)) */
3211 sc->keyboard = sc_allocate_keyboard(sc, unit);
3212 DPRINTF(1, ("sc%d: keyboard %d\n", unit, sc->keyboard));
3214 sc->kbd = kbd_get_keyboard(sc->keyboard);
3215 if (sc->kbd != NULL) {
3216 DPRINTF(1, ("sc%d: kbd index:%d, unit:%d, flags:0x%x\n",
3217 unit, sc->kbd->kb_index, sc->kbd->kb_unit, sc->kbd->kb_flags));
3220 if (!(sc->flags & SC_INIT_DONE) || (adp != sc->adp)) {
3222 sc->initial_mode = sc->adp->va_initial_mode;
3224 #ifndef SC_NO_FONT_LOADING
3225 if (flags & SC_KERNEL_CONSOLE) {
3226 sc->font_8 = font_8;
3227 sc->font_14 = font_14;
3228 sc->font_16 = font_16;
3229 } else if (sc->font_8 == NULL) {
3230 /* assert(sc_malloc) */
3231 sc->font_8 = malloc(sizeof(font_8), M_DEVBUF, M_WAITOK);
3232 sc->font_14 = malloc(sizeof(font_14), M_DEVBUF, M_WAITOK);
3233 sc->font_16 = malloc(sizeof(font_16), M_DEVBUF, M_WAITOK);
3237 /* extract the hardware cursor location and hide the cursor for now */
3238 vidd_read_hw_cursor(sc->adp, &col, &row);
3239 vidd_set_hw_cursor(sc->adp, -1, -1);
3241 /* set up the first console */
3242 sc->first_vty = unit*MAXCONS;
3243 sc->vtys = MAXCONS; /* XXX: should be configurable */
3244 if (flags & SC_KERNEL_CONSOLE) {
3246 * Set up devs structure but don't use it yet, calling make_dev()
3247 * might panic kernel. Wait for sc_attach_unit() to actually
3248 * create the devices.
3250 sc->dev = main_devs;
3251 scp = &main_console;
3252 init_scp(sc, sc->first_vty, scp);
3253 sc_vtb_init(&scp->vtb, VTB_MEMORY, scp->xsize, scp->ysize,
3254 (void *)sc_buffer, FALSE);
3255 if (sc_init_emulator(scp, SC_DFLT_TERM))
3256 sc_init_emulator(scp, "*");
3257 (*scp->tsw->te_default_attr)(scp, SC_KERNEL_CONS_ATTR,
3258 SC_KERNEL_CONS_REV_ATTR);
3260 /* assert(sc_malloc) */
3261 sc->dev = malloc(sizeof(struct tty *)*sc->vtys, M_DEVBUF,
3263 sc->dev[0] = sc_alloc_tty(0, unit * MAXCONS);
3264 scp = alloc_scp(sc, sc->first_vty);
3265 SC_STAT(sc->dev[0]) = scp;
3270 /* copy screen to temporary buffer */
3271 sc_vtb_init(&scp->scr, VTB_FRAMEBUFFER, scp->xsize, scp->ysize,
3272 (void *)scp->sc->adp->va_window, FALSE);
3274 sc_vtb_copy(&scp->scr, 0, &scp->vtb, 0, scp->xsize*scp->ysize);
3277 /* Sync h/w cursor position to s/w (sc and teken). */
3278 if (col >= scp->xsize)
3280 if (row >= scp->ysize)
3281 row = scp->ysize - 1;
3284 scp->cursor_pos = scp->cursor_oldpos = row*scp->xsize + col;
3285 (*scp->tsw->te_sync)(scp);
3287 sc->dflt_curs_attr.base = 0;
3288 sc->dflt_curs_attr.height = howmany(scp->font_size, 8);
3289 sc->dflt_curs_attr.flags = 0;
3290 sc->dflt_curs_attr.bg[0] = FG_RED;
3291 sc->dflt_curs_attr.bg[1] = FG_LIGHTGREY;
3292 sc->dflt_curs_attr.bg[2] = FG_BLUE;
3293 sc->dflt_curs_attr.mouse_ba = FG_WHITE;
3294 sc->dflt_curs_attr.mouse_ia = FG_RED;
3295 sc->curs_attr = sc->dflt_curs_attr;
3296 scp->base_curs_attr = scp->dflt_curs_attr = sc->curs_attr;
3297 scp->curs_attr = scp->base_curs_attr;
3299 #ifndef SC_NO_SYSMOUSE
3300 sc_mouse_move(scp, scp->xpixel/2, scp->ypixel/2);
3302 if (!ISGRAPHSC(scp)) {
3303 sc_set_cursor_image(scp);
3304 sc_draw_cursor_image(scp);
3307 /* save font and palette */
3308 #ifndef SC_NO_FONT_LOADING
3309 sc->fonts_loaded = 0;
3310 if (ISFONTAVAIL(sc->adp->va_flags)) {
3312 bcopy(dflt_font_8, sc->font_8, sizeof(dflt_font_8));
3313 bcopy(dflt_font_14, sc->font_14, sizeof(dflt_font_14));
3314 bcopy(dflt_font_16, sc->font_16, sizeof(dflt_font_16));
3315 sc->fonts_loaded = FONT_16 | FONT_14 | FONT_8;
3316 if (scp->font_size < 14) {
3317 sc_load_font(scp, 0, 8, 8, sc->font_8, 0, 256);
3318 } else if (scp->font_size >= 16) {
3319 sc_load_font(scp, 0, 16, 8, sc->font_16, 0, 256);
3321 sc_load_font(scp, 0, 14, 8, sc->font_14, 0, 256);
3323 #else /* !SC_DFLT_FONT */
3324 if (scp->font_size < 14) {
3325 sc_save_font(scp, 0, 8, 8, sc->font_8, 0, 256);
3326 sc->fonts_loaded = FONT_8;
3327 } else if (scp->font_size >= 16) {
3328 sc_save_font(scp, 0, 16, 8, sc->font_16, 0, 256);
3329 sc->fonts_loaded = FONT_16;
3331 sc_save_font(scp, 0, 14, 8, sc->font_14, 0, 256);
3332 sc->fonts_loaded = FONT_14;
3334 #endif /* SC_DFLT_FONT */
3335 /* FONT KLUDGE: always use the font page #0. XXX */
3336 sc_show_font(scp, 0);
3338 #endif /* !SC_NO_FONT_LOADING */
3340 #ifndef SC_NO_PALETTE_LOADING
3341 vidd_save_palette(sc->adp, sc->palette);
3342 #ifdef SC_PIXEL_MODE
3343 for (i = 0; i < sizeof(sc->palette2); i++)
3344 sc->palette2[i] = i / 3;
3349 if (!(sc->flags & SC_SPLASH_SCRN)) {
3350 /* we are ready to put up the splash image! */
3351 splash_init(sc->adp, scsplash_callback, sc);
3352 sc->flags |= SC_SPLASH_SCRN;
3357 /* the rest is not necessary, if we have done it once */
3358 if (sc->flags & SC_INIT_DONE)
3361 /* initialize mapscrn arrays to a one to one map */
3362 for (i = 0; i < sizeof(sc->scr_map); i++)
3363 sc->scr_map[i] = sc->scr_rmap[i] = i;
3365 sc->flags |= SC_INIT_DONE;
3369 scterm(int unit, int flags)
3374 sc = sc_get_softc(unit, flags & SC_KERNEL_CONSOLE);
3376 return; /* shouldn't happen */
3379 /* this console is no longer available for the splash screen */
3380 if (sc->flags & SC_SPLASH_SCRN) {
3381 splash_term(sc->adp);
3382 sc->flags &= ~SC_SPLASH_SCRN;
3387 /* move the hardware cursor to the upper-left corner */
3388 vidd_set_hw_cursor(sc->adp, 0, 0);
3391 /* release the keyboard and the video card */
3392 if (sc->keyboard >= 0)
3393 kbd_release(sc->kbd, &sc->keyboard);
3394 if (sc->adapter >= 0)
3395 vid_release(sc->adp, &sc->adapter);
3397 /* stop the terminal emulator, if any */
3398 scp = sc_get_stat(sc->dev[0]);
3400 (*scp->tsw->te_term)(scp, &scp->ts);
3401 mtx_destroy(&sc->video_mtx);
3403 /* clear the structure */
3404 if (!(flags & SC_KERNEL_CONSOLE)) {
3405 free(scp->ts, M_DEVBUF);
3406 /* XXX: We need delete_dev() for this */
3407 free(sc->dev, M_DEVBUF);
3409 /* XXX: We need a ttyunregister for this */
3410 free(sc->tty, M_DEVBUF);
3412 #ifndef SC_NO_FONT_LOADING
3413 free(sc->font_8, M_DEVBUF);
3414 free(sc->font_14, M_DEVBUF);
3415 free(sc->font_16, M_DEVBUF);
3417 /* XXX vtb, history */
3419 bzero(sc, sizeof(*sc));
3425 scshutdown(__unused void *arg, __unused int howto)
3428 KASSERT(sc_console != NULL, ("sc_console != NULL"));
3429 KASSERT(sc_console->sc != NULL, ("sc_console->sc != NULL"));
3430 KASSERT(sc_console->sc->cur_scp != NULL,
3431 ("sc_console->sc->cur_scp != NULL"));
3433 sc_touch_scrn_saver();
3435 sc_console->sc->cur_scp->index != sc_console->index &&
3436 sc_console->sc->cur_scp->smode.mode == VT_AUTO &&
3437 sc_console->smode.mode == VT_AUTO)
3438 sc_switch_scr(sc_console->sc, sc_console->index);
3439 shutdown_in_progress = TRUE;
3443 scsuspend(__unused void *arg)
3447 KASSERT(sc_console != NULL, ("sc_console != NULL"));
3448 KASSERT(sc_console->sc != NULL, ("sc_console->sc != NULL"));
3449 KASSERT(sc_console->sc->cur_scp != NULL,
3450 ("sc_console->sc->cur_scp != NULL"));
3452 sc_susp_scr = sc_console->sc->cur_scp->index;
3453 if (sc_no_suspend_vtswitch ||
3454 sc_susp_scr == sc_console->index) {
3455 sc_touch_scrn_saver();
3459 for (retry = 0; retry < 10; retry++) {
3460 sc_switch_scr(sc_console->sc, sc_console->index);
3461 if (!sc_console->sc->switch_in_progress)
3463 pause("scsuspend", hz);
3465 suspend_in_progress = TRUE;
3469 scresume(__unused void *arg)
3472 KASSERT(sc_console != NULL, ("sc_console != NULL"));
3473 KASSERT(sc_console->sc != NULL, ("sc_console->sc != NULL"));
3474 KASSERT(sc_console->sc->cur_scp != NULL,
3475 ("sc_console->sc->cur_scp != NULL"));
3477 suspend_in_progress = FALSE;
3478 if (sc_susp_scr < 0) {
3479 update_font(sc_console->sc->cur_scp);
3482 sc_switch_scr(sc_console->sc, sc_susp_scr);
3486 sc_clean_up(scr_stat *scp)
3492 if (scp->sc->flags & SC_SCRN_BLANKED) {
3493 sc_touch_scrn_saver();
3495 if ((error = wait_scrn_saver_stop(scp->sc)))
3499 scp->status |= MOUSE_HIDDEN;
3500 sc_remove_mouse_image(scp);
3501 sc_remove_cutmarking(scp);
3506 sc_alloc_scr_buffer(scr_stat *scp, int wait, int discard)
3512 sc_vtb_init(&new, VTB_MEMORY, scp->xsize, scp->ysize, NULL, wait);
3513 if (!discard && (old.vtb_flags & VTB_VALID)) {
3514 /* retain the current cursor position and buffer contants */
3515 scp->cursor_oldpos = scp->cursor_pos;
3517 * This works only if the old buffer has the same size as or larger
3518 * than the new one. XXX
3520 sc_vtb_copy(&old, 0, &new, 0, scp->xsize*scp->ysize);
3524 sc_vtb_destroy(&old);
3527 #ifndef SC_NO_SYSMOUSE
3528 /* move the mouse cursor at the center of the screen */
3529 sc_mouse_move(scp, scp->xpixel / 2, scp->ypixel / 2);
3534 *alloc_scp(sc_softc_t *sc, int vty)
3538 /* assert(sc_malloc) */
3540 scp = (scr_stat *)malloc(sizeof(scr_stat), M_DEVBUF, M_WAITOK);
3541 init_scp(sc, vty, scp);
3543 sc_alloc_scr_buffer(scp, TRUE, TRUE);
3544 if (sc_init_emulator(scp, SC_DFLT_TERM))
3545 sc_init_emulator(scp, "*");
3547 #ifndef SC_NO_CUTPASTE
3548 sc_alloc_cut_buffer(scp, TRUE);
3551 #ifndef SC_NO_HISTORY
3552 sc_alloc_history_buffer(scp, 0, 0, TRUE);
3559 init_scp(sc_softc_t *sc, int vty, scr_stat *scp)
3563 bzero(scp, sizeof(*scp));
3568 scp->mode = sc->initial_mode;
3569 vidd_get_info(sc->adp, scp->mode, &info);
3570 if (info.vi_flags & V_INFO_GRAPHICS) {
3571 scp->status |= GRAPHICS_MODE;
3572 scp->xpixel = info.vi_width;
3573 scp->ypixel = info.vi_height;
3574 scp->xsize = info.vi_width/info.vi_cwidth;
3575 scp->ysize = info.vi_height/info.vi_cheight;
3579 scp->xsize = info.vi_width;
3580 scp->ysize = info.vi_height;
3581 scp->xpixel = scp->xsize*info.vi_cwidth;
3582 scp->ypixel = scp->ysize*info.vi_cheight;
3585 scp->font_size = info.vi_cheight;
3586 scp->font_width = info.vi_cwidth;
3587 #ifndef SC_NO_FONT_LOADING
3588 if (info.vi_cheight < 14)
3589 scp->font = sc->font_8;
3590 else if (info.vi_cheight >= 16)
3591 scp->font = sc->font_16;
3593 scp->font = sc->font_14;
3598 sc_vtb_init(&scp->vtb, VTB_MEMORY, 0, 0, NULL, FALSE);
3600 sc_vtb_init(&scp->scr, VTB_FRAMEBUFFER, 0, 0, NULL, FALSE);
3602 scp->xoff = scp->yoff = 0;
3603 scp->xpos = scp->ypos = 0;
3604 scp->start = scp->xsize * scp->ysize - 1;
3609 scp->border = (SC_NORM_ATTR >> 4) & 0x0f;
3610 scp->base_curs_attr = scp->dflt_curs_attr = sc->curs_attr;
3611 scp->mouse_cut_start = scp->xsize*scp->ysize;
3612 scp->mouse_cut_end = -1;
3613 scp->mouse_signal = 0;
3615 scp->mouse_proc = NULL;
3616 scp->kbd_mode = K_XLATE;
3617 scp->bell_pitch = bios_value.bell_pitch;
3618 scp->bell_duration = BELL_DURATION;
3619 scp->status |= (bios_value.shift_state & NLKED);
3620 scp->status |= CURSOR_ENABLED | MOUSE_HIDDEN;
3623 scp->smode.mode = VT_AUTO;
3624 scp->history = NULL;
3625 scp->history_pos = 0;
3626 scp->history_size = 0;
3630 sc_init_emulator(scr_stat *scp, char *name)
3637 if (name == NULL) /* if no name is given, use the current emulator */
3639 else /* ...otherwise find the named emulator */
3640 sw = sc_term_match(name);
3645 if (strcmp(sw->te_renderer, "*") != 0) {
3646 rndr = sc_render_match(scp, sw->te_renderer,
3647 scp->status & (GRAPHICS_MODE | PIXEL_MODE));
3650 rndr = sc_render_match(scp, scp->sc->adp->va_name,
3651 scp->status & (GRAPHICS_MODE | PIXEL_MODE));
3656 if (sw == scp->tsw) {
3657 error = (*sw->te_init)(scp, &scp->ts, SC_TE_WARM_INIT);
3659 scp->rndr->init(scp);
3660 sc_clear_screen(scp);
3661 /* assert(error == 0); */
3665 if (sc_malloc && (sw->te_size > 0))
3666 p = malloc(sw->te_size, M_DEVBUF, M_NOWAIT);
3669 error = (*sw->te_init)(scp, &p, SC_TE_COLD_INIT);
3674 (*scp->tsw->te_term)(scp, &scp->ts);
3675 if (scp->ts != NULL)
3676 free(scp->ts, M_DEVBUF);
3680 scp->rndr->init(scp);
3682 (*sw->te_default_attr)(scp, SC_NORM_ATTR, SC_NORM_REV_ATTR);
3683 sc_clear_screen(scp);
3689 * scgetc(flags) - get character from keyboard.
3690 * If flags & SCGETC_CN, then avoid harmful side effects.
3691 * If flags & SCGETC_NONBLOCK, then wait until a key is pressed, else
3692 * return NOKEY if there is nothing there.
3695 scgetc(sc_softc_t *sc, u_int flags, struct sc_cnstate *sp)
3698 #ifndef SC_NO_HISTORY
3706 if (sc->kbd == NULL)
3711 /* I don't like this, but... XXX */
3712 if (flags & SCGETC_CN)
3713 sccnupdate(sc->cur_scp);
3716 /* first see if there is something in the keyboard port */
3718 if (flags & SCGETC_CN)
3719 sccnscrunlock(sc, sp);
3720 c = kbdd_read_char(sc->kbd, !(flags & SCGETC_NONBLOCK));
3721 if (flags & SCGETC_CN)
3722 sccnscrlock(sc, sp);
3724 if (!(flags & SCGETC_CN))
3725 sc_bell(scp, bios_value.bell_pitch, BELL_DURATION);
3726 } else if (c == NOKEY)
3732 /* make screensaver happy */
3734 sc_touch_scrn_saver();
3736 if (!(flags & SCGETC_CN))
3737 random_harvest_queue(&c, sizeof(c), RANDOM_KEYBOARD);
3739 if (sc->kbd_open_level == 0 && scp->kbd_mode != K_XLATE)
3742 /* if scroll-lock pressed allow history browsing */
3743 if (!ISGRAPHSC(scp) && scp->history && scp->status & SLKED) {
3745 scp->status &= ~CURSOR_ENABLED;
3746 sc_remove_cursor_image(scp);
3748 #ifndef SC_NO_HISTORY
3749 if (!(scp->status & BUFFER_SAVED)) {
3750 scp->status |= BUFFER_SAVED;
3754 /* FIXME: key codes */
3755 case SPCLKEY | FKEY | F(49): /* home key */
3756 sc_remove_cutmarking(scp);
3760 case SPCLKEY | FKEY | F(57): /* end key */
3761 sc_remove_cutmarking(scp);
3765 case SPCLKEY | FKEY | F(50): /* up arrow key */
3766 sc_remove_cutmarking(scp);
3767 if (sc_hist_up_line(scp))
3768 if (!(flags & SCGETC_CN))
3769 sc_bell(scp, bios_value.bell_pitch, BELL_DURATION);
3772 case SPCLKEY | FKEY | F(58): /* down arrow key */
3773 sc_remove_cutmarking(scp);
3774 if (sc_hist_down_line(scp))
3775 if (!(flags & SCGETC_CN))
3776 sc_bell(scp, bios_value.bell_pitch, BELL_DURATION);
3779 case SPCLKEY | FKEY | F(51): /* page up key */
3780 sc_remove_cutmarking(scp);
3781 for (i=0; i<scp->ysize; i++)
3782 if (sc_hist_up_line(scp)) {
3783 if (!(flags & SCGETC_CN))
3784 sc_bell(scp, bios_value.bell_pitch, BELL_DURATION);
3789 case SPCLKEY | FKEY | F(59): /* page down key */
3790 sc_remove_cutmarking(scp);
3791 for (i=0; i<scp->ysize; i++)
3792 if (sc_hist_down_line(scp)) {
3793 if (!(flags & SCGETC_CN))
3794 sc_bell(scp, bios_value.bell_pitch, BELL_DURATION);
3799 #endif /* SC_NO_HISTORY */
3803 * Process and consume special keys here. Return a plain char code
3804 * or a char code with the META flag or a function key code.
3808 /* goto next_code */
3813 switch (KEYCHAR(c)) {
3815 case NLK: case CLK: case ALK:
3818 (void)kbdd_ioctl(sc->kbd, KDGKBSTATE, (caddr_t)&f);
3820 scp->status |= SLKED;
3822 if (scp->status & SLKED) {
3823 scp->status &= ~SLKED;
3824 #ifndef SC_NO_HISTORY
3825 if (scp->status & BUFFER_SAVED) {
3826 if (!sc_hist_restore(scp))
3827 sc_remove_cutmarking(scp);
3828 scp->status &= ~BUFFER_SAVED;
3829 scp->status |= CURSOR_ENABLED;
3830 sc_draw_cursor_image(scp);
3832 /* Only safe in Giant-locked context. */
3833 tp = SC_DEV(sc, scp->index);
3834 if (!(flags & SCGETC_CN) && tty_opened_ns(tp))
3835 sctty_outwakeup(tp);
3842 #ifndef SC_NO_CUTPASTE
3843 sc_mouse_paste(scp);
3847 /* NON-LOCKING KEYS */
3849 case LSH: case RSH: case LCTR: case RCTR:
3850 case LALT: case RALT: case ASH: case META:
3854 if (!(sc->flags & SC_SCRN_BLANKED))
3860 /* force activatation/deactivation of the screen saver */
3861 if (!(sc->flags & SC_SCRN_BLANKED)) {
3862 run_scrn_saver = TRUE;
3863 sc->scrn_time_stamp -= scrn_blank_time;
3867 * While devices are being probed, the screen saver need
3868 * to be invoked explicitly. XXX
3870 if (sc->flags & SC_SCRN_BLANKED) {
3871 scsplash_stick(FALSE);
3872 stop_scrn_saver(sc, current_saver);
3874 if (!ISGRAPHSC(scp)) {
3875 scsplash_stick(TRUE);
3876 (*current_saver)(sc, TRUE);
3880 #endif /* DEV_SPLASH */
3884 #ifndef SC_DISABLE_REBOOT
3885 if (enable_reboot && !(flags & SCGETC_CN))
3891 #ifndef SC_DISABLE_REBOOT
3892 if (enable_reboot && !(flags & SCGETC_CN))
3893 shutdown_nice(RB_HALT);
3898 #ifndef SC_DISABLE_REBOOT
3899 if (enable_reboot && !(flags & SCGETC_CN))
3900 shutdown_nice(RB_HALT|RB_POWEROFF);
3905 power_pm_suspend(POWER_SLEEP_STATE_SUSPEND);
3908 power_pm_suspend(POWER_SLEEP_STATE_STANDBY);
3912 #ifndef SC_DISABLE_KDBKEY
3919 if (enable_panic_key)
3920 panic("Forced by the panic key");
3924 this_scr = scp->index;
3925 for (i = (this_scr - sc->first_vty + 1)%sc->vtys;
3926 sc->first_vty + i != this_scr;
3927 i = (i + 1)%sc->vtys) {
3928 struct tty *tp = SC_DEV(sc, sc->first_vty + i);
3929 if (tty_opened_ns(tp)) {
3930 sc_switch_scr(scp->sc, sc->first_vty + i);
3937 this_scr = scp->index;
3938 for (i = (this_scr - sc->first_vty + sc->vtys - 1)%sc->vtys;
3939 sc->first_vty + i != this_scr;
3940 i = (i + sc->vtys - 1)%sc->vtys) {
3941 struct tty *tp = SC_DEV(sc, sc->first_vty + i);
3942 if (tty_opened_ns(tp)) {
3943 sc_switch_scr(scp->sc, sc->first_vty + i);
3950 if (KEYCHAR(c) >= F_SCR && KEYCHAR(c) <= L_SCR) {
3951 sc_switch_scr(scp->sc, sc->first_vty + KEYCHAR(c) - F_SCR);
3954 /* assert(c & FKEY) */
3955 if (!(sc->flags & SC_SCRN_BLANKED))
3959 /* goto next_code */
3961 /* regular keys (maybe MKEY is set) */
3962 #if !defined(SC_DISABLE_KDBKEY) && defined(KDB)
3964 kdb_alt_break(c, &sc->sc_altbrk);
3966 if (!(sc->flags & SC_SCRN_BLANKED))
3975 sctty_mmap(struct tty *tp, vm_ooffset_t offset, vm_paddr_t *paddr,
3976 int nprot, vm_memattr_t *memattr)
3980 scp = sc_get_stat(tp);
3981 if (scp != scp->sc->cur_scp)
3983 return vidd_mmap(scp->sc->adp, offset, paddr, nprot, memattr);
3987 update_font(scr_stat *scp)
3989 #ifndef SC_NO_FONT_LOADING
3990 /* load appropriate font */
3991 if (!(scp->status & GRAPHICS_MODE)) {
3992 if (!(scp->status & PIXEL_MODE) && ISFONTAVAIL(scp->sc->adp->va_flags)) {
3993 if (scp->font_size < 14) {
3994 if (scp->sc->fonts_loaded & FONT_8)
3995 sc_load_font(scp, 0, 8, 8, scp->sc->font_8, 0, 256);
3996 } else if (scp->font_size >= 16) {
3997 if (scp->sc->fonts_loaded & FONT_16)
3998 sc_load_font(scp, 0, 16, 8, scp->sc->font_16, 0, 256);
4000 if (scp->sc->fonts_loaded & FONT_14)
4001 sc_load_font(scp, 0, 14, 8, scp->sc->font_14, 0, 256);
4005 * This is an interim kludge to display correct font.
4006 * Always use the font page #0 on the video plane 2.
4007 * Somehow we cannot show the font in other font pages on
4008 * some video cards... XXX
4010 sc_show_font(scp, 0);
4014 #endif /* !SC_NO_FONT_LOADING */
4018 save_kbd_state(scr_stat *scp)
4023 error = kbdd_ioctl(scp->sc->kbd, KDGKBSTATE, (caddr_t)&state);
4024 if (error == ENOIOCTL)
4027 scp->status &= ~LOCK_MASK;
4028 scp->status |= state;
4034 update_kbd_state(scr_stat *scp, int new_bits, int mask)
4039 if (mask != LOCK_MASK) {
4040 error = kbdd_ioctl(scp->sc->kbd, KDGKBSTATE, (caddr_t)&state);
4041 if (error == ENOIOCTL)
4046 state |= new_bits & mask;
4048 state = new_bits & LOCK_MASK;
4050 error = kbdd_ioctl(scp->sc->kbd, KDSKBSTATE, (caddr_t)&state);
4051 if (error == ENOIOCTL)
4057 update_kbd_leds(scr_stat *scp, int which)
4062 error = kbdd_ioctl(scp->sc->kbd, KDSETLED, (caddr_t)&which);
4063 if (error == ENOIOCTL)
4069 set_mode(scr_stat *scp)
4073 /* reject unsupported mode */
4074 if (vidd_get_info(scp->sc->adp, scp->mode, &info))
4077 /* if this vty is not currently showing, do nothing */
4078 if (scp != scp->sc->cur_scp)
4081 /* setup video hardware for the given mode */
4082 vidd_set_mode(scp->sc->adp, scp->mode);
4083 scp->rndr->init(scp);
4085 sc_vtb_init(&scp->scr, VTB_FRAMEBUFFER, scp->xsize, scp->ysize,
4086 (void *)scp->sc->adp->va_window, FALSE);
4091 sc_set_border(scp, scp->border);
4092 sc_set_cursor_image(scp);
4098 sc_set_border(scr_stat *scp, int color)
4100 SC_VIDEO_LOCK(scp->sc);
4101 (*scp->rndr->draw_border)(scp, color);
4102 SC_VIDEO_UNLOCK(scp->sc);
4105 #ifndef SC_NO_FONT_LOADING
4107 sc_load_font(scr_stat *scp, int page, int size, int width, u_char *buf,
4108 int base, int count)
4113 sc->font_loading_in_progress = TRUE;
4114 vidd_load_font(sc->adp, page, size, width, buf, base, count);
4115 sc->font_loading_in_progress = FALSE;
4119 sc_save_font(scr_stat *scp, int page, int size, int width, u_char *buf,
4120 int base, int count)
4125 sc->font_loading_in_progress = TRUE;
4126 vidd_save_font(sc->adp, page, size, width, buf, base, count);
4127 sc->font_loading_in_progress = FALSE;
4131 sc_show_font(scr_stat *scp, int page)
4133 vidd_show_font(scp->sc->adp, page);
4135 #endif /* !SC_NO_FONT_LOADING */
4138 sc_paste(scr_stat *scp, const u_char *p, int count)
4143 tp = SC_DEV(scp->sc, scp->sc->cur_scp->index);
4144 if (!tty_opened_ns(tp))
4146 rmap = scp->sc->scr_rmap;
4147 for (; count > 0; --count)
4148 ttydisc_rint(tp, rmap[*p++], 0);
4149 ttydisc_rint_done(tp);
4153 sc_respond(scr_stat *scp, const u_char *p, int count, int wakeup)
4157 tp = SC_DEV(scp->sc, scp->sc->cur_scp->index);
4158 if (!tty_opened_ns(tp))
4160 ttydisc_rint_simple(tp, p, count);
4162 /* XXX: we can't always call ttydisc_rint_done() here! */
4163 ttydisc_rint_done(tp);
4168 sc_bell(scr_stat *scp, int pitch, int duration)
4170 if (cold || kdb_active || shutdown_in_progress || !enable_bell)
4173 if (scp != scp->sc->cur_scp && (scp->sc->flags & SC_QUIET_BELL))
4176 if (scp->sc->flags & SC_VISUAL_BELL) {
4177 if (scp->sc->blink_in_progress)
4179 scp->sc->blink_in_progress = 3;
4180 if (scp != scp->sc->cur_scp)
4181 scp->sc->blink_in_progress += 2;
4182 blink_screen(scp->sc->cur_scp);
4183 } else if (duration != 0 && pitch != 0) {
4184 if (scp != scp->sc->cur_scp)
4186 sysbeep(1193182 / pitch, duration);
4193 if (sc_console == NULL)
4194 return (SC_KERNEL_CONS_ATTR); /* for very early, before pcpu */
4195 return (sc_kattrtab[curcpu % nitems(sc_kattrtab)]);
4199 blink_screen(void *arg)
4201 scr_stat *scp = arg;
4204 if (ISGRAPHSC(scp) || (scp->sc->blink_in_progress <= 1)) {
4205 scp->sc->blink_in_progress = 0;
4207 tp = SC_DEV(scp->sc, scp->index);
4208 if (tty_opened_ns(tp))
4209 sctty_outwakeup(tp);
4210 if (scp->sc->delayed_next_scr)
4211 sc_switch_scr(scp->sc, scp->sc->delayed_next_scr - 1);
4214 (*scp->rndr->draw)(scp, 0, scp->xsize*scp->ysize,
4215 scp->sc->blink_in_progress & 1);
4216 scp->sc->blink_in_progress--;
4217 callout_reset_sbt(&scp->sc->cblink, SBT_1S / 15, 0,
4218 blink_screen, scp, C_PREL(0));
4223 * Until sc_attach_unit() gets called no dev structures will be available
4224 * to store the per-screen current status. This is the case when the
4225 * kernel is initially booting and needs access to its console. During
4226 * this early phase of booting the console's current status is kept in
4227 * one statically defined scr_stat structure, and any pointers to the
4228 * dev structures will be NULL.
4232 sc_get_stat(struct tty *tp)
4235 return (&main_console);
4236 return (SC_STAT(tp));
4240 * Allocate active keyboard. Try to allocate "kbdmux" keyboard first, and,
4241 * if found, add all non-busy keyboards to "kbdmux". Otherwise look for
4246 sc_allocate_keyboard(sc_softc_t *sc, int unit)
4252 idx0 = kbd_allocate("kbdmux", -1, (void *)&sc->keyboard, sckbdevent, sc);
4254 k0 = kbd_get_keyboard(idx0);
4256 for (idx = kbd_find_keyboard2("*", -1, 0);
4258 idx = kbd_find_keyboard2("*", -1, idx + 1)) {
4259 k = kbd_get_keyboard(idx);
4261 if (idx == idx0 || KBD_IS_BUSY(k))
4264 bzero(&ki, sizeof(ki));
4265 strcpy(ki.kb_name, k->kb_name);
4266 ki.kb_unit = k->kb_unit;
4268 (void)kbdd_ioctl(k0, KBADDKBD, (caddr_t) &ki);
4271 idx0 = kbd_allocate("*", unit, (void *)&sc->keyboard, sckbdevent, sc);