2 * Copyright (c) 1992-1998 Søren Schmidt
5 * This code is derived from software contributed to The DragonFly Project
6 * by Sascha Wildner <saw@online.de>
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer,
13 * without modification, immediately at the beginning of the file.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
17 * 3. The name of the author may not be used to endorse or promote products
18 * derived from this software without specific prior written permission.
20 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
21 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
22 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
23 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
24 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
25 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
29 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 #include <sys/cdefs.h>
33 __FBSDID("$FreeBSD$");
35 #include "opt_compat.h"
36 #include "opt_syscons.h"
37 #include "opt_splash.h"
40 #include <sys/param.h>
41 #include <sys/systm.h>
45 #include <sys/consio.h>
47 #include <sys/eventhandler.h>
50 #include <sys/kernel.h>
52 #include <sys/malloc.h>
53 #include <sys/mutex.h>
56 #include <sys/random.h>
57 #include <sys/reboot.h>
58 #include <sys/serial.h>
59 #include <sys/signalvar.h>
60 #include <sys/sysctl.h>
62 #include <sys/power.h>
64 #include <machine/clock.h>
65 #if defined(__arm__) || defined(__mips__) || \
66 defined(__powerpc__) || defined(__sparc64__)
67 #include <machine/sc_machdep.h>
69 #include <machine/pc/display.h>
71 #if defined( __i386__) || defined(__amd64__)
72 #include <machine/psl.h>
73 #include <machine/frame.h>
75 #include <machine/stdarg.h>
77 #include <dev/kbd/kbdreg.h>
78 #include <dev/fb/fbreg.h>
79 #include <dev/fb/splashreg.h>
80 #include <dev/syscons/syscons.h>
85 #define DEFAULT_BLANKTIME (5*60) /* 5 minutes */
86 #define MAX_BLANKTIME (7*24*60*60) /* 7 days!? */
88 #define KEYCODE_BS 0x0e /* "<-- Backspace" key, XXX */
90 /* NULL-safe version of "tty_opened()" */
91 #define tty_opened_ns(tp) ((tp) != NULL && tty_opened(tp))
93 typedef struct default_attr {
94 int std_color; /* normal hardware color */
95 int rev_color; /* reverse hardware color */
98 static default_attr user_default = {
103 static int sc_console_unit = -1;
104 static int sc_saver_keyb_only = 1;
105 static scr_stat *sc_console;
106 static struct consdev *sc_consptr;
107 static scr_stat main_console;
108 static struct tty *main_devs[MAXCONS];
110 static char init_done = COLD;
111 static int shutdown_in_progress = FALSE;
112 static int suspend_in_progress = FALSE;
113 static char sc_malloc = FALSE;
115 static int saver_mode = CONS_NO_SAVER; /* LKM/user saver */
116 static int run_scrn_saver = FALSE; /* should run the saver? */
117 static int enable_bell = TRUE; /* enable beeper */
119 #ifndef SC_DISABLE_REBOOT
120 static int enable_reboot = TRUE; /* enable keyboard reboot */
123 #ifndef SC_DISABLE_KDBKEY
124 static int enable_kdbkey = TRUE; /* enable keyboard debug */
127 static long scrn_blank_time = 0; /* screen saver timeout value */
129 static int scrn_blanked; /* # of blanked screen */
130 static int sticky_splash = FALSE;
132 static void none_saver(sc_softc_t *sc, int blank) { }
133 static void (*current_saver)(sc_softc_t *, int) = none_saver;
136 #ifdef SC_NO_SUSPEND_VTYSWITCH
137 static int sc_no_suspend_vtswitch = 1;
139 static int sc_no_suspend_vtswitch = 0;
141 static int sc_susp_scr;
143 static SYSCTL_NODE(_hw, OID_AUTO, syscons, CTLFLAG_RD, 0, "syscons");
144 static SYSCTL_NODE(_hw_syscons, OID_AUTO, saver, CTLFLAG_RD, 0, "saver");
145 SYSCTL_INT(_hw_syscons_saver, OID_AUTO, keybonly, CTLFLAG_RW,
146 &sc_saver_keyb_only, 0, "screen saver interrupted by input only");
147 SYSCTL_INT(_hw_syscons, OID_AUTO, bell, CTLFLAG_RW, &enable_bell,
149 #ifndef SC_DISABLE_REBOOT
150 SYSCTL_INT(_hw_syscons, OID_AUTO, kbd_reboot, CTLFLAG_RW|CTLFLAG_SECURE, &enable_reboot,
151 0, "enable keyboard reboot");
153 #ifndef SC_DISABLE_KDBKEY
154 SYSCTL_INT(_hw_syscons, OID_AUTO, kbd_debug, CTLFLAG_RW|CTLFLAG_SECURE, &enable_kdbkey,
155 0, "enable keyboard debug");
157 SYSCTL_INT(_hw_syscons, OID_AUTO, sc_no_suspend_vtswitch, CTLFLAG_RWTUN,
158 &sc_no_suspend_vtswitch, 0, "Disable VT switch before suspend.");
159 #if !defined(SC_NO_FONT_LOADING) && defined(SC_DFLT_FONT)
163 tsw_ioctl_t *sc_user_ioctl;
165 static bios_values_t bios_value;
167 static int enable_panic_key;
168 SYSCTL_INT(_machdep, OID_AUTO, enable_panic_key, CTLFLAG_RW, &enable_panic_key,
169 0, "Enable panic via keypress specified in kbdmap(5)");
171 #define SC_CONSOLECTL 255
173 #define VTY_WCHAN(sc, vty) (&SC_DEV(sc, vty))
176 static int sc_allocate_keyboard(sc_softc_t *sc, int unit);
177 static int scvidprobe(int unit, int flags, int cons);
178 static int sckbdprobe(int unit, int flags, int cons);
179 static void scmeminit(void *arg);
180 static int scdevtounit(struct tty *tp);
181 static kbd_callback_func_t sckbdevent;
182 static void scinit(int unit, int flags);
183 static scr_stat *sc_get_stat(struct tty *tp);
184 static void scterm(int unit, int flags);
185 static void scshutdown(void *, int);
186 static void scsuspend(void *);
187 static void scresume(void *);
188 static u_int scgetc(sc_softc_t *sc, u_int flags, struct sc_cnstate *sp);
189 static void sc_puts(scr_stat *scp, u_char *buf, int len, int kernel);
191 #define SCGETC_NONBLOCK 2
192 static void sccnupdate(scr_stat *scp);
193 static scr_stat *alloc_scp(sc_softc_t *sc, int vty);
194 static void init_scp(sc_softc_t *sc, int vty, scr_stat *scp);
195 static timeout_t scrn_timer;
196 static int and_region(int *s1, int *e1, int s2, int e2);
197 static void scrn_update(scr_stat *scp, int show_cursor);
200 static int scsplash_callback(int event, void *arg);
201 static void scsplash_saver(sc_softc_t *sc, int show);
202 static int add_scrn_saver(void (*this_saver)(sc_softc_t *, int));
203 static int remove_scrn_saver(void (*this_saver)(sc_softc_t *, int));
204 static int set_scrn_saver_mode(scr_stat *scp, int mode, u_char *pal, int border);
205 static int restore_scrn_saver_mode(scr_stat *scp, int changemode);
206 static void stop_scrn_saver(sc_softc_t *sc, void (*saver)(sc_softc_t *, int));
207 static int wait_scrn_saver_stop(sc_softc_t *sc);
208 #define scsplash_stick(stick) (sticky_splash = (stick))
209 #else /* !DEV_SPLASH */
210 #define scsplash_stick(stick)
211 #endif /* DEV_SPLASH */
213 static int do_switch_scr(sc_softc_t *sc, int s);
214 static int vt_proc_alive(scr_stat *scp);
215 static int signal_vt_rel(scr_stat *scp);
216 static int signal_vt_acq(scr_stat *scp);
217 static int finish_vt_rel(scr_stat *scp, int release, int *s);
218 static int finish_vt_acq(scr_stat *scp);
219 static void exchange_scr(sc_softc_t *sc);
220 static void update_cursor_image(scr_stat *scp);
221 static void change_cursor_shape(scr_stat *scp, int flags, int base, int height);
222 static void update_font(scr_stat *);
223 static int save_kbd_state(scr_stat *scp);
224 static int update_kbd_state(scr_stat *scp, int state, int mask);
225 static int update_kbd_leds(scr_stat *scp, int which);
226 static timeout_t blink_screen;
227 static struct tty *sc_alloc_tty(int, int);
229 static cn_probe_t sc_cnprobe;
230 static cn_init_t sc_cninit;
231 static cn_term_t sc_cnterm;
232 static cn_getc_t sc_cngetc;
233 static cn_putc_t sc_cnputc;
234 static cn_grab_t sc_cngrab;
235 static cn_ungrab_t sc_cnungrab;
239 static tsw_open_t sctty_open;
240 static tsw_close_t sctty_close;
241 static tsw_outwakeup_t sctty_outwakeup;
242 static tsw_ioctl_t sctty_ioctl;
243 static tsw_mmap_t sctty_mmap;
245 static struct ttydevsw sc_ttydevsw = {
246 .tsw_open = sctty_open,
247 .tsw_close = sctty_close,
248 .tsw_outwakeup = sctty_outwakeup,
249 .tsw_ioctl = sctty_ioctl,
250 .tsw_mmap = sctty_mmap,
253 static d_ioctl_t consolectl_ioctl;
254 static d_close_t consolectl_close;
256 static struct cdevsw consolectl_devsw = {
257 .d_version = D_VERSION,
258 .d_flags = D_NEEDGIANT | D_TRACKCLOSE,
259 .d_ioctl = consolectl_ioctl,
260 .d_close = consolectl_close,
261 .d_name = "consolectl",
265 sc_probe_unit(int unit, int flags)
267 if (!vty_enabled(VTY_SC))
269 if (!scvidprobe(unit, flags, FALSE)) {
271 printf("%s%d: no video adapter found.\n", SC_DRIVER_NAME, unit);
275 /* syscons will be attached even when there is no keyboard */
276 sckbdprobe(unit, flags, FALSE);
281 /* probe video adapters, return TRUE if found */
283 scvidprobe(int unit, int flags, int cons)
286 * Access the video adapter driver through the back door!
287 * Video adapter drivers need to be configured before syscons.
288 * However, when syscons is being probed as the low-level console,
289 * they have not been initialized yet. We force them to initialize
290 * themselves here. XXX
292 vid_configure(cons ? VIO_PROBE_ONLY : 0);
294 return (vid_find_adapter("*", unit) >= 0);
297 /* probe the keyboard, return TRUE if found */
299 sckbdprobe(int unit, int flags, int cons)
301 /* access the keyboard driver through the backdoor! */
302 kbd_configure(cons ? KB_CONF_PROBE_ONLY : 0);
304 return (kbd_find_keyboard("*", unit) >= 0);
308 *adapter_name(video_adapter_t *adp)
314 { KD_MONO, { "MDA", "MDA" } },
315 { KD_HERCULES, { "Hercules", "Hercules" } },
316 { KD_CGA, { "CGA", "CGA" } },
317 { KD_EGA, { "EGA", "EGA (mono)" } },
318 { KD_VGA, { "VGA", "VGA (mono)" } },
319 { KD_TGA, { "TGA", "TGA" } },
320 { -1, { "Unknown", "Unknown" } },
324 for (i = 0; names[i].type != -1; ++i)
325 if (names[i].type == adp->va_type)
327 return names[i].name[(adp->va_flags & V_ADP_COLOR) ? 0 : 1];
331 sctty_outwakeup(struct tty *tp)
335 scr_stat *scp = sc_get_stat(tp);
337 if (scp->status & SLKED ||
338 (scp == scp->sc->cur_scp && scp->sc->blink_in_progress))
342 len = ttydisc_getc(tp, buf, sizeof buf);
345 SC_VIDEO_LOCK(scp->sc);
346 sc_puts(scp, buf, len, 0);
347 SC_VIDEO_UNLOCK(scp->sc);
352 sc_alloc_tty(int index, int devnum)
354 struct sc_ttysoftc *stc;
357 /* Allocate TTY object and softc to store unit number. */
358 stc = malloc(sizeof(struct sc_ttysoftc), M_DEVBUF, M_WAITOK);
359 stc->st_index = index;
361 tp = tty_alloc_mutex(&sc_ttydevsw, stc, &Giant);
363 /* Create device node. */
364 tty_makedev(tp, NULL, "v%r", devnum);
371 sc_set_vesa_mode(scr_stat *scp, sc_softc_t *sc, int unit)
381 (void)resource_int_value("sc", unit, "vesa_mode", &vmode);
382 if (vmode < M_VESA_BASE || vmode > M_VESA_MODE_MAX ||
383 vidd_get_info(sc->adp, vmode, &info) != 0 ||
384 !sc_support_pixel_mode(&info))
388 * If the mode is unset or unsupported, search for an available
389 * 800x600 graphics mode with the highest color depth.
392 for (depth = 0, i = M_VESA_BASE; i <= M_VESA_MODE_MAX; i++)
393 if (vidd_get_info(sc->adp, i, &info) == 0 &&
394 info.vi_width == 800 && info.vi_height == 600 &&
395 sc_support_pixel_mode(&info) &&
396 info.vi_depth > depth) {
398 depth = info.vi_depth;
402 vidd_get_info(sc->adp, vmode, &info);
405 #if !defined(SC_NO_FONT_LOADING) && defined(SC_DFLT_FONT)
406 fontsize = info.vi_cheight;
408 fontsize = scp->font_size;
412 else if (fontsize >= 16)
416 #ifndef SC_NO_FONT_LOADING
419 if ((sc->fonts_loaded & FONT_8) == 0)
424 if ((sc->fonts_loaded & FONT_14) == 0)
429 if ((sc->fonts_loaded & FONT_16) == 0)
438 if ((sc->flags & SC_SPLASH_SCRN) != 0)
439 splash_term(sc->adp);
441 #ifndef SC_NO_HISTORY
442 if (scp->history != NULL) {
443 sc_vtb_append(&scp->vtb, 0, scp->history,
444 scp->ypos * scp->xsize + scp->xpos);
445 scp->history_pos = sc_vtb_tail(scp->history);
448 vidd_set_mode(sc->adp, vmode);
449 scp->status |= (UNKNOWN_MODE | PIXEL_MODE | MOUSE_HIDDEN);
450 scp->status &= ~(GRAPHICS_MODE | MOUSE_VISIBLE);
451 scp->xpixel = info.vi_width;
452 scp->ypixel = info.vi_height;
453 scp->xsize = scp->xpixel / 8;
454 scp->ysize = scp->ypixel / fontsize;
456 scp->ypos = scp->ysize - 1;
457 scp->xoff = scp->yoff = 0;
459 scp->font_size = fontsize;
461 scp->start = scp->xsize * scp->ysize - 1;
463 scp->cursor_pos = scp->cursor_oldpos = scp->xsize * scp->xsize;
464 scp->mode = sc->initial_mode = vmode;
466 sc_vtb_init(&scp->scr, VTB_FRAMEBUFFER, scp->xsize, scp->ysize,
467 (void *)sc->adp->va_window, FALSE);
469 sc_alloc_scr_buffer(scp, FALSE, FALSE);
470 sc_init_emulator(scp, NULL);
471 #ifndef SC_NO_CUTPASTE
472 sc_alloc_cut_buffer(scp, FALSE);
474 #ifndef SC_NO_HISTORY
475 sc_alloc_history_buffer(scp, 0, 0, FALSE);
477 sc_set_border(scp, scp->border);
478 sc_set_cursor_image(scp);
479 scp->status &= ~UNKNOWN_MODE;
481 if ((sc->flags & SC_SPLASH_SCRN) != 0)
482 splash_init(sc->adp, scsplash_callback, sc);
488 sc_attach_unit(int unit, int flags)
495 if (!vty_enabled(VTY_SC))
498 flags &= ~SC_KERNEL_CONSOLE;
500 if (sc_console_unit == unit) {
502 * If this unit is being used as the system console, we need to
503 * adjust some variables and buffers before and after scinit().
505 /* assert(sc_console != NULL) */
506 flags |= SC_KERNEL_CONSOLE;
511 sc = sc_get_softc(unit, flags & SC_KERNEL_CONSOLE);
513 callout_init(&sc->ctimeout, 0);
514 callout_init(&sc->cblink, 0);
515 scp = sc_get_stat(sc->dev[0]);
516 if (sc_console == NULL) /* sc_console_unit < 0 */
520 if ((sc->config & SC_VESAMODE) != 0)
521 sc_set_vesa_mode(scp, sc, unit);
522 #endif /* SC_PIXEL_MODE */
524 /* initialize cursor */
526 update_cursor_image(scp);
528 /* get screen update going */
531 /* set up the keyboard */
532 (void)kbdd_ioctl(sc->kbd, KDSKBMODE, (caddr_t)&scp->kbd_mode);
533 update_kbd_state(scp, scp->status, LOCK_MASK);
535 printf("%s%d: %s <%d virtual consoles, flags=0x%x>\n",
536 SC_DRIVER_NAME, unit, adapter_name(sc->adp), sc->vtys, sc->config);
538 printf("%s%d:", SC_DRIVER_NAME, unit);
539 if (sc->adapter >= 0)
540 printf(" fb%d", sc->adapter);
541 if (sc->keyboard >= 0)
542 printf(", kbd%d", sc->keyboard);
544 printf(", terminal emulator: %s (%s)",
545 scp->tsw->te_name, scp->tsw->te_desc);
549 /* Register suspend/resume/shutdown callbacks for the kernel console. */
550 if (sc_console_unit == unit) {
551 EVENTHANDLER_REGISTER(power_suspend_early, scsuspend, NULL,
552 EVENTHANDLER_PRI_ANY);
553 EVENTHANDLER_REGISTER(power_resume, scresume, NULL,
554 EVENTHANDLER_PRI_ANY);
555 EVENTHANDLER_REGISTER(shutdown_pre_sync, scshutdown, NULL,
556 SHUTDOWN_PRI_DEFAULT);
559 for (vc = 0; vc < sc->vtys; vc++) {
560 if (sc->dev[vc] == NULL) {
561 sc->dev[vc] = sc_alloc_tty(vc, vc + unit * MAXCONS);
562 if (vc == 0 && sc->dev == main_devs)
563 SC_STAT(sc->dev[0]) = &main_console;
566 * The first vty already has struct tty and scr_stat initialized
567 * in scinit(). The other vtys will have these structs when
572 dev = make_dev(&consolectl_devsw, 0, UID_ROOT, GID_WHEEL, 0600,
574 dev->si_drv1 = sc->dev[0];
582 if (!vty_enabled(VTY_SC))
589 * As soon as malloc() becomes functional, we had better allocate
590 * various buffers for the kernel console.
593 if (sc_console_unit < 0) /* sc_console == NULL */
596 /* copy the temporary buffer to the final buffer */
597 sc_alloc_scr_buffer(sc_console, FALSE, FALSE);
599 #ifndef SC_NO_CUTPASTE
600 sc_alloc_cut_buffer(sc_console, FALSE);
603 #ifndef SC_NO_HISTORY
604 /* initialize history buffer & pointers */
605 sc_alloc_history_buffer(sc_console, 0, 0, FALSE);
610 SYSINIT(sc_mem, SI_SUB_KMEM, SI_ORDER_ANY, scmeminit, NULL);
613 scdevtounit(struct tty *tp)
615 int vty = SC_VTY(tp);
617 if (vty == SC_CONSOLECTL)
618 return ((sc_console != NULL) ? sc_console->sc->unit : -1);
619 else if ((vty < 0) || (vty >= MAXCONS*sc_max_unit()))
626 sctty_open(struct tty *tp)
628 int unit = scdevtounit(tp);
635 DPRINTF(5, ("scopen: dev:%s, unit:%d, vty:%d\n",
636 devtoname(tp->t_dev), unit, SC_VTY(tp)));
638 sc = sc_get_softc(unit, (sc_console_unit == unit) ? SC_KERNEL_CONSOLE : 0);
642 if (!tty_opened(tp)) {
643 /* Use the current setting of the <-- key as default VERASE. */
644 /* If the Delete key is preferable, an stty is necessary */
646 if (sc->kbd != NULL) {
647 key.keynum = KEYCODE_BS;
648 (void)kbdd_ioctl(sc->kbd, GIO_KEYMAPENT, (caddr_t)&key);
649 tp->t_termios.c_cc[VERASE] = key.key.map[0];
654 scp = sc_get_stat(tp);
656 scp = SC_STAT(tp) = alloc_scp(sc, SC_VTY(tp));
658 sc_set_pixel_mode(scp, NULL, 0, 0, 16, 8);
660 if (!tp->t_winsize.ws_col && !tp->t_winsize.ws_row) {
661 tp->t_winsize.ws_col = scp->xsize;
662 tp->t_winsize.ws_row = scp->ysize;
669 sctty_close(struct tty *tp)
674 if (SC_VTY(tp) != SC_CONSOLECTL) {
675 scp = sc_get_stat(tp);
676 /* were we in the middle of the VT switching process? */
677 DPRINTF(5, ("sc%d: scclose(), ", scp->sc->unit));
679 if ((scp == scp->sc->cur_scp) && (scp->sc->unit == sc_console_unit))
680 cnavailable(sc_consptr, TRUE);
681 if (finish_vt_rel(scp, TRUE, &s) == 0) /* force release */
682 DPRINTF(5, ("reset WAIT_REL, "));
683 if (finish_vt_acq(scp) == 0) /* force acknowledge */
684 DPRINTF(5, ("reset WAIT_ACQ, "));
686 if (scp == &main_console) {
689 scp->smode.mode = VT_AUTO;
692 sc_vtb_destroy(&scp->vtb);
694 sc_vtb_destroy(&scp->scr);
696 sc_free_history_buffer(scp, scp->ysize);
703 scp->smode.mode = VT_AUTO;
705 scp->kbd_mode = K_XLATE;
706 if (scp == scp->sc->cur_scp)
707 (void)kbdd_ioctl(scp->sc->kbd, KDSKBMODE, (caddr_t)&scp->kbd_mode);
708 DPRINTF(5, ("done.\n"));
712 #if 0 /* XXX mpsafetty: fix screensaver. What about outwakeup? */
714 scread(struct cdev *dev, struct uio *uio, int flag)
716 if (!sc_saver_keyb_only)
717 sc_touch_scrn_saver();
718 return ttyread(dev, uio, flag);
723 sckbdevent(keyboard_t *thiskbd, int event, void *arg)
731 sc = (sc_softc_t *)arg;
732 /* assert(thiskbd == sc->kbd) */
739 case KBDIO_UNLOADING:
742 kbd_release(thiskbd, (void *)&sc->keyboard);
750 * Loop while there is still input to get from the keyboard.
751 * I don't think this is nessesary, and it doesn't fix
752 * the Xaccel-2.1 keyboard hang, but it can't hurt. XXX
754 while ((c = scgetc(sc, SCGETC_NONBLOCK, NULL)) != NOKEY) {
756 cur_tty = SC_DEV(sc, sc->cur_scp->index);
757 if (!tty_opened_ns(cur_tty))
760 if ((*sc->cur_scp->tsw->te_input)(sc->cur_scp, c, cur_tty))
763 switch (KEYFLAGS(c)) {
764 case 0x0000: /* normal key */
765 ttydisc_rint(cur_tty, KEYCHAR(c), 0);
767 case FKEY: /* function key, return string */
768 cp = (*sc->cur_scp->tsw->te_fkeystr)(sc->cur_scp, c);
770 ttydisc_rint_simple(cur_tty, cp, strlen(cp));
773 cp = kbdd_get_fkeystr(thiskbd, KEYCHAR(c), &len);
775 ttydisc_rint_simple(cur_tty, cp, len);
777 case MKEY: /* meta is active, prepend ESC */
778 ttydisc_rint(cur_tty, 0x1b, 0);
779 ttydisc_rint(cur_tty, KEYCHAR(c), 0);
781 case BKEY: /* backtab fixed sequence (esc [ Z) */
782 ttydisc_rint_simple(cur_tty, "\x1B[Z", 3);
786 ttydisc_rint_done(cur_tty);
789 sc->cur_scp->status |= MOUSE_HIDDEN;
797 sctty_ioctl(struct tty *tp, u_long cmd, caddr_t data, struct thread *td)
804 #if defined(COMPAT_FREEBSD6) || defined(COMPAT_FREEBSD5) || \
805 defined(COMPAT_FREEBSD4) || defined(COMPAT_43)
809 /* If there is a user_ioctl function call that first */
811 error = (*sc_user_ioctl)(tp, cmd, data, td);
812 if (error != ENOIOCTL)
816 error = sc_vid_ioctl(tp, cmd, data, td);
817 if (error != ENOIOCTL)
820 #ifndef SC_NO_HISTORY
821 error = sc_hist_ioctl(tp, cmd, data, td);
822 if (error != ENOIOCTL)
826 #ifndef SC_NO_SYSMOUSE
827 error = sc_mouse_ioctl(tp, cmd, data, td);
828 if (error != ENOIOCTL)
832 scp = sc_get_stat(tp);
833 /* assert(scp != NULL) */
834 /* scp is sc_console, if SC_VTY(dev) == SC_CONSOLECTL. */
838 error = (*scp->tsw->te_ioctl)(scp, tp, cmd, data, td);
839 if (error != ENOIOCTL)
843 switch (cmd) { /* process console hardware related ioctl's */
845 case GIO_ATTR: /* get current attributes */
846 /* this ioctl is not processed here, but in the terminal emulator */
849 case GIO_COLOR: /* is this a color console ? */
850 *(int *)data = (sc->adp->va_flags & V_ADP_COLOR) ? 1 : 0;
853 case CONS_BLANKTIME: /* set screen saver timeout (0 = no saver) */
854 if (*(int *)data < 0 || *(int *)data > MAX_BLANKTIME)
857 scrn_blank_time = *(int *)data;
858 run_scrn_saver = (scrn_blank_time != 0);
862 case CONS_CURSORTYPE: /* set cursor type (obsolete) */
864 *(int *)data &= CONS_CURSOR_ATTRS;
865 sc_change_cursor_shape(scp, *(int *)data, -1, -1);
869 case CONS_GETCURSORSHAPE: /* get cursor shape (new interface) */
870 if (((int *)data)[0] & CONS_LOCAL_CURSOR) {
871 ((int *)data)[0] = scp->curr_curs_attr.flags;
872 ((int *)data)[1] = scp->curr_curs_attr.base;
873 ((int *)data)[2] = scp->curr_curs_attr.height;
875 ((int *)data)[0] = sc->curs_attr.flags;
876 ((int *)data)[1] = sc->curs_attr.base;
877 ((int *)data)[2] = sc->curs_attr.height;
881 case CONS_SETCURSORSHAPE: /* set cursor shape (new interface) */
883 sc_change_cursor_shape(scp, ((int *)data)[0],
884 ((int *)data)[1], ((int *)data)[2]);
888 case CONS_BELLTYPE: /* set bell type sound/visual */
889 if ((*(int *)data) & CONS_VISUAL_BELL)
890 sc->flags |= SC_VISUAL_BELL;
892 sc->flags &= ~SC_VISUAL_BELL;
893 if ((*(int *)data) & CONS_QUIET_BELL)
894 sc->flags |= SC_QUIET_BELL;
896 sc->flags &= ~SC_QUIET_BELL;
899 case CONS_GETINFO: /* get current (virtual) console info */
901 vid_info_t *ptr = (vid_info_t*)data;
902 if (ptr->size == sizeof(struct vid_info)) {
903 ptr->m_num = sc->cur_scp->index;
904 ptr->font_size = scp->font_size;
905 ptr->mv_col = scp->xpos;
906 ptr->mv_row = scp->ypos;
907 ptr->mv_csz = scp->xsize;
908 ptr->mv_rsz = scp->ysize;
909 ptr->mv_hsz = (scp->history != NULL) ? scp->history->vtb_rows : 0;
911 * The following fields are filled by the terminal emulator. XXX
918 ptr->mv_grfc.fore = 0; /* not supported */
919 ptr->mv_grfc.back = 0; /* not supported */
920 ptr->mv_ovscan = scp->border;
921 if (scp == sc->cur_scp)
923 ptr->mk_keylock = scp->status & LOCK_MASK;
929 case CONS_GETVERS: /* get version number */
930 *(int*)data = 0x200; /* version 2.0 */
933 case CONS_IDLE: /* see if the screen has been idle */
935 * When the screen is in the GRAPHICS_MODE or UNKNOWN_MODE,
936 * the user process may have been writing something on the
937 * screen and syscons is not aware of it. Declare the screen
938 * is NOT idle if it is in one of these modes. But there is
939 * an exception to it; if a screen saver is running in the
940 * graphics mode in the current screen, we should say that the
941 * screen has been idle.
943 *(int *)data = (sc->flags & SC_SCRN_IDLE)
944 && (!ISGRAPHSC(sc->cur_scp)
945 || (sc->cur_scp->status & SAVER_RUNNING));
948 case CONS_SAVERMODE: /* set saver mode */
949 switch(*(int *)data) {
952 /* if a LKM screen saver is running, stop it first. */
953 scsplash_stick(FALSE);
954 saver_mode = *(int *)data;
957 if ((error = wait_scrn_saver_stop(NULL))) {
962 run_scrn_saver = TRUE;
963 if (saver_mode == CONS_USR_SAVER)
964 scp->status |= SAVER_RUNNING;
966 scp->status &= ~SAVER_RUNNING;
967 scsplash_stick(TRUE);
972 if ((saver_mode == CONS_USR_SAVER) && (scp->status & SAVER_RUNNING))
973 scp->status &= ~SAVER_RUNNING;
974 saver_mode = *(int *)data;
982 case CONS_SAVERSTART: /* immediately start/stop the screen saver */
984 * Note that this ioctl does not guarantee the screen saver
985 * actually starts or stops. It merely attempts to do so...
988 run_scrn_saver = (*(int *)data != 0);
990 sc->scrn_time_stamp -= scrn_blank_time;
994 case CONS_SCRSHOT: /* get a screen shot */
996 int retval, hist_rsz;
998 vm_offset_t frbp, hstp;
1000 scrshot_t *ptr = (scrshot_t *)data;
1001 void *outp = ptr->buf;
1003 if (ptr->x < 0 || ptr->y < 0 || ptr->xsize < 0 || ptr->ysize < 0)
1006 if (ISGRAPHSC(scp)) {
1010 hist_rsz = (scp->history != NULL) ? scp->history->vtb_rows : 0;
1011 if (((u_int)ptr->x + ptr->xsize) > scp->xsize ||
1012 ((u_int)ptr->y + ptr->ysize) > (scp->ysize + hist_rsz)) {
1017 lsize = scp->xsize * sizeof(u_int16_t);
1018 csize = ptr->xsize * sizeof(u_int16_t);
1019 /* Pointer to the last line of framebuffer */
1020 frbp = scp->vtb.vtb_buffer + scp->ysize * lsize + ptr->x *
1022 /* Pointer to the last line of target buffer */
1023 outp = (char *)outp + ptr->ysize * csize;
1024 /* Pointer to the last line of history buffer */
1025 if (scp->history != NULL)
1026 hstp = scp->history->vtb_buffer + sc_vtb_tail(scp->history) *
1027 sizeof(u_int16_t) + ptr->x * sizeof(u_int16_t);
1032 for (lnum = 0; lnum < (ptr->y + ptr->ysize); lnum++) {
1033 if (lnum < scp->ysize) {
1037 if (hstp < scp->history->vtb_buffer)
1038 hstp += scp->history->vtb_rows * lsize;
1043 outp = (char *)outp - csize;
1044 retval = copyout((void *)frbp, outp, csize);
1052 case VT_SETMODE: /* set screen switcher mode */
1054 struct vt_mode *mode;
1057 mode = (struct vt_mode *)data;
1058 DPRINTF(5, ("%s%d: VT_SETMODE ", SC_DRIVER_NAME, sc->unit));
1059 if (scp->smode.mode == VT_PROCESS) {
1060 p1 = pfind(scp->pid);
1061 if (scp->proc == p1 && scp->proc != td->td_proc) {
1064 DPRINTF(5, ("error EPERM\n"));
1071 if (mode->mode == VT_AUTO) {
1072 scp->smode.mode = VT_AUTO;
1075 DPRINTF(5, ("VT_AUTO, "));
1076 if ((scp == sc->cur_scp) && (sc->unit == sc_console_unit))
1077 cnavailable(sc_consptr, TRUE);
1078 /* were we in the middle of the vty switching process? */
1079 if (finish_vt_rel(scp, TRUE, &s) == 0)
1080 DPRINTF(5, ("reset WAIT_REL, "));
1081 if (finish_vt_acq(scp) == 0)
1082 DPRINTF(5, ("reset WAIT_ACQ, "));
1084 if (!ISSIGVALID(mode->relsig) || !ISSIGVALID(mode->acqsig)
1085 || !ISSIGVALID(mode->frsig)) {
1087 DPRINTF(5, ("error EINVAL\n"));
1090 DPRINTF(5, ("VT_PROCESS %d, ", td->td_proc->p_pid));
1091 bcopy(data, &scp->smode, sizeof(struct vt_mode));
1092 scp->proc = td->td_proc;
1093 scp->pid = scp->proc->p_pid;
1094 if ((scp == sc->cur_scp) && (sc->unit == sc_console_unit))
1095 cnavailable(sc_consptr, FALSE);
1102 case VT_GETMODE: /* get screen switcher mode */
1103 bcopy(&scp->smode, data, sizeof(struct vt_mode));
1106 #if defined(COMPAT_FREEBSD6) || defined(COMPAT_FREEBSD5) || \
1107 defined(COMPAT_FREEBSD4) || defined(COMPAT_43)
1109 ival = IOCPARM_IVAL(data);
1110 data = (caddr_t)&ival;
1113 case VT_RELDISP: /* screen switcher ioctl */
1116 * This must be the current vty which is in the VT_PROCESS
1119 if ((scp != sc->cur_scp) || (scp->smode.mode != VT_PROCESS)) {
1123 /* ...and this process is controlling it. */
1124 if (scp->proc != td->td_proc) {
1129 switch(*(int *)data) {
1130 case VT_FALSE: /* user refuses to release screen, abort */
1131 if ((error = finish_vt_rel(scp, FALSE, &s)) == 0)
1132 DPRINTF(5, ("%s%d: VT_FALSE\n", SC_DRIVER_NAME, sc->unit));
1134 case VT_TRUE: /* user has released screen, go on */
1135 if ((error = finish_vt_rel(scp, TRUE, &s)) == 0)
1136 DPRINTF(5, ("%s%d: VT_TRUE\n", SC_DRIVER_NAME, sc->unit));
1138 case VT_ACKACQ: /* acquire acknowledged, switch completed */
1139 if ((error = finish_vt_acq(scp)) == 0)
1140 DPRINTF(5, ("%s%d: VT_ACKACQ\n", SC_DRIVER_NAME, sc->unit));
1148 case VT_OPENQRY: /* return free virtual console */
1149 for (i = sc->first_vty; i < sc->first_vty + sc->vtys; i++) {
1151 if (!tty_opened_ns(tp)) {
1152 *(int *)data = i + 1;
1158 #if defined(COMPAT_FREEBSD6) || defined(COMPAT_FREEBSD5) || \
1159 defined(COMPAT_FREEBSD4) || defined(COMPAT_43)
1161 ival = IOCPARM_IVAL(data);
1162 data = (caddr_t)&ival;
1165 case VT_ACTIVATE: /* switch to screen *data */
1166 i = (*(int *)data == 0) ? scp->index : (*(int *)data - 1);
1168 error = sc_clean_up(sc->cur_scp);
1172 error = sc_switch_scr(sc, i);
1175 #if defined(COMPAT_FREEBSD6) || defined(COMPAT_FREEBSD5) || \
1176 defined(COMPAT_FREEBSD4) || defined(COMPAT_43)
1178 ival = IOCPARM_IVAL(data);
1179 data = (caddr_t)&ival;
1182 case VT_WAITACTIVE: /* wait for switch to occur */
1183 i = (*(int *)data == 0) ? scp->index : (*(int *)data - 1);
1184 if ((i < sc->first_vty) || (i >= sc->first_vty + sc->vtys))
1186 if (i == sc->cur_scp->index)
1188 error = tsleep(VTY_WCHAN(sc, i), (PZERO + 1) | PCATCH, "waitvt", 0);
1191 case VT_GETACTIVE: /* get active vty # */
1192 *(int *)data = sc->cur_scp->index + 1;
1195 case VT_GETINDEX: /* get this vty # */
1196 *(int *)data = scp->index + 1;
1199 case VT_LOCKSWITCH: /* prevent vty switching */
1200 if ((*(int *)data) & 0x01)
1201 sc->flags |= SC_SCRN_VTYLOCK;
1203 sc->flags &= ~SC_SCRN_VTYLOCK;
1206 case KDENABIO: /* allow io operations */
1207 error = priv_check(td, PRIV_IO);
1210 error = securelevel_gt(td->td_ucred, 0);
1214 td->td_frame->tf_eflags |= PSL_IOPL;
1215 #elif defined(__amd64__)
1216 td->td_frame->tf_rflags |= PSL_IOPL;
1220 case KDDISABIO: /* disallow io operations (default) */
1222 td->td_frame->tf_eflags &= ~PSL_IOPL;
1223 #elif defined(__amd64__)
1224 td->td_frame->tf_rflags &= ~PSL_IOPL;
1228 #if defined(COMPAT_FREEBSD6) || defined(COMPAT_FREEBSD5) || \
1229 defined(COMPAT_FREEBSD4) || defined(COMPAT_43)
1231 ival = IOCPARM_IVAL(data);
1232 data = (caddr_t)&ival;
1235 case KDSKBSTATE: /* set keyboard state (locks) */
1236 if (*(int *)data & ~LOCK_MASK)
1238 scp->status &= ~LOCK_MASK;
1239 scp->status |= *(int *)data;
1240 if (scp == sc->cur_scp)
1241 update_kbd_state(scp, scp->status, LOCK_MASK);
1244 case KDGKBSTATE: /* get keyboard state (locks) */
1245 if (scp == sc->cur_scp)
1246 save_kbd_state(scp);
1247 *(int *)data = scp->status & LOCK_MASK;
1250 case KDGETREPEAT: /* get keyboard repeat & delay rates */
1251 case KDSETREPEAT: /* set keyboard repeat & delay rates (new) */
1252 error = kbdd_ioctl(sc->kbd, cmd, data);
1253 if (error == ENOIOCTL)
1257 #if defined(COMPAT_FREEBSD6) || defined(COMPAT_FREEBSD5) || \
1258 defined(COMPAT_FREEBSD4) || defined(COMPAT_43)
1260 ival = IOCPARM_IVAL(data);
1261 data = (caddr_t)&ival;
1264 case KDSETRAD: /* set keyboard repeat & delay rates (old) */
1265 if (*(int *)data & ~0x7f)
1267 error = kbdd_ioctl(sc->kbd, KDSETRAD, data);
1268 if (error == ENOIOCTL)
1272 #if defined(COMPAT_FREEBSD6) || defined(COMPAT_FREEBSD5) || \
1273 defined(COMPAT_FREEBSD4) || defined(COMPAT_43)
1275 ival = IOCPARM_IVAL(data);
1276 data = (caddr_t)&ival;
1279 case KDSKBMODE: /* set keyboard mode */
1280 switch (*(int *)data) {
1281 case K_XLATE: /* switch to XLT ascii mode */
1282 case K_RAW: /* switch to RAW scancode mode */
1283 case K_CODE: /* switch to CODE mode */
1284 scp->kbd_mode = *(int *)data;
1285 if (scp == sc->cur_scp)
1286 (void)kbdd_ioctl(sc->kbd, KDSKBMODE, data);
1293 case KDGKBMODE: /* get keyboard mode */
1294 *(int *)data = scp->kbd_mode;
1298 error = kbdd_ioctl(sc->kbd, cmd, data);
1299 if (error == ENOIOCTL)
1303 #if defined(COMPAT_FREEBSD6) || defined(COMPAT_FREEBSD5) || \
1304 defined(COMPAT_FREEBSD4) || defined(COMPAT_43)
1306 ival = IOCPARM_IVAL(data);
1307 data = (caddr_t)&ival;
1310 case KDMKTONE: /* sound the bell */
1312 sc_bell(scp, (*(int*)data)&0xffff,
1313 (((*(int*)data)>>16)&0xffff)*hz/1000);
1315 sc_bell(scp, scp->bell_pitch, scp->bell_duration);
1318 #if defined(COMPAT_FREEBSD6) || defined(COMPAT_FREEBSD5) || \
1319 defined(COMPAT_FREEBSD4) || defined(COMPAT_43)
1321 ival = IOCPARM_IVAL(data);
1322 data = (caddr_t)&ival;
1325 case KIOCSOUND: /* make tone (*data) hz */
1326 if (scp == sc->cur_scp) {
1328 return sc_tone(*(int *)data);
1334 case KDGKBTYPE: /* get keyboard type */
1335 error = kbdd_ioctl(sc->kbd, cmd, data);
1336 if (error == ENOIOCTL) {
1337 /* always return something? XXX */
1342 #if defined(COMPAT_FREEBSD6) || defined(COMPAT_FREEBSD5) || \
1343 defined(COMPAT_FREEBSD4) || defined(COMPAT_43)
1345 ival = IOCPARM_IVAL(data);
1346 data = (caddr_t)&ival;
1349 case KDSETLED: /* set keyboard LED status */
1350 if (*(int *)data & ~LED_MASK) /* FIXME: LOCK_MASK? */
1352 scp->status &= ~LED_MASK;
1353 scp->status |= *(int *)data;
1354 if (scp == sc->cur_scp)
1355 update_kbd_leds(scp, scp->status);
1358 case KDGETLED: /* get keyboard LED status */
1359 if (scp == sc->cur_scp)
1360 save_kbd_state(scp);
1361 *(int *)data = scp->status & LED_MASK;
1364 case KBADDKBD: /* add/remove keyboard to/from mux */
1366 error = kbdd_ioctl(sc->kbd, cmd, data);
1367 if (error == ENOIOCTL)
1371 #if defined(COMPAT_FREEBSD6) || defined(COMPAT_FREEBSD5) || \
1372 defined(COMPAT_FREEBSD4) || defined(COMPAT_43)
1374 ival = IOCPARM_IVAL(data);
1375 data = (caddr_t)&ival;
1378 case CONS_SETKBD: /* set the new keyboard */
1383 newkbd = kbd_get_keyboard(*(int *)data);
1384 if (newkbd == NULL) {
1389 if (sc->kbd != newkbd) {
1390 i = kbd_allocate(newkbd->kb_name, newkbd->kb_unit,
1391 (void *)&sc->keyboard, sckbdevent, sc);
1392 /* i == newkbd->kb_index */
1394 if (sc->kbd != NULL) {
1395 save_kbd_state(sc->cur_scp);
1396 kbd_release(sc->kbd, (void *)&sc->keyboard);
1398 sc->kbd = kbd_get_keyboard(i); /* sc->kbd == newkbd */
1400 (void)kbdd_ioctl(sc->kbd, KDSKBMODE,
1401 (caddr_t)&sc->cur_scp->kbd_mode);
1402 update_kbd_state(sc->cur_scp, sc->cur_scp->status,
1405 error = EPERM; /* XXX */
1412 case CONS_RELKBD: /* release the current keyboard */
1415 if (sc->kbd != NULL) {
1416 save_kbd_state(sc->cur_scp);
1417 error = kbd_release(sc->kbd, (void *)&sc->keyboard);
1426 case CONS_GETTERM: /* get the current terminal emulator info */
1430 if (((term_info_t *)data)->ti_index == 0) {
1433 sw = sc_term_match_by_number(((term_info_t *)data)->ti_index);
1436 strncpy(((term_info_t *)data)->ti_name, sw->te_name,
1437 sizeof(((term_info_t *)data)->ti_name));
1438 strncpy(((term_info_t *)data)->ti_desc, sw->te_desc,
1439 sizeof(((term_info_t *)data)->ti_desc));
1440 ((term_info_t *)data)->ti_flags = 0;
1443 ((term_info_t *)data)->ti_name[0] = '\0';
1444 ((term_info_t *)data)->ti_desc[0] = '\0';
1445 ((term_info_t *)data)->ti_flags = 0;
1450 case CONS_SETTERM: /* set the current terminal emulator */
1452 error = sc_init_emulator(scp, ((term_info_t *)data)->ti_name);
1453 /* FIXME: what if scp == sc_console! XXX */
1457 case GIO_SCRNMAP: /* get output translation table */
1458 bcopy(&sc->scr_map, data, sizeof(sc->scr_map));
1461 case PIO_SCRNMAP: /* set output translation table */
1462 bcopy(data, &sc->scr_map, sizeof(sc->scr_map));
1463 for (i=0; i<sizeof(sc->scr_map); i++) {
1464 sc->scr_rmap[sc->scr_map[i]] = i;
1468 case GIO_KEYMAP: /* get keyboard translation table */
1469 case PIO_KEYMAP: /* set keyboard translation table */
1470 case OGIO_KEYMAP: /* get keyboard translation table (compat) */
1471 case OPIO_KEYMAP: /* set keyboard translation table (compat) */
1472 case GIO_DEADKEYMAP: /* get accent key translation table */
1473 case PIO_DEADKEYMAP: /* set accent key translation table */
1474 case GETFKEY: /* get function key string */
1475 case SETFKEY: /* set function key string */
1476 error = kbdd_ioctl(sc->kbd, cmd, data);
1477 if (error == ENOIOCTL)
1481 #ifndef SC_NO_FONT_LOADING
1483 case PIO_FONT8x8: /* set 8x8 dot font */
1484 if (!ISFONTAVAIL(sc->adp->va_flags))
1486 bcopy(data, sc->font_8, 8*256);
1487 sc->fonts_loaded |= FONT_8;
1490 * Always use the font page #0. XXX
1491 * Don't load if the current font size is not 8x8.
1493 if (ISTEXTSC(sc->cur_scp) && (sc->cur_scp->font_size < 14))
1494 sc_load_font(sc->cur_scp, 0, 8, 8, sc->font_8, 0, 256);
1497 case GIO_FONT8x8: /* get 8x8 dot font */
1498 if (!ISFONTAVAIL(sc->adp->va_flags))
1500 if (sc->fonts_loaded & FONT_8) {
1501 bcopy(sc->font_8, data, 8*256);
1507 case PIO_FONT8x14: /* set 8x14 dot font */
1508 if (!ISFONTAVAIL(sc->adp->va_flags))
1510 bcopy(data, sc->font_14, 14*256);
1511 sc->fonts_loaded |= FONT_14;
1514 * Always use the font page #0. XXX
1515 * Don't load if the current font size is not 8x14.
1517 if (ISTEXTSC(sc->cur_scp)
1518 && (sc->cur_scp->font_size >= 14)
1519 && (sc->cur_scp->font_size < 16))
1520 sc_load_font(sc->cur_scp, 0, 14, 8, sc->font_14, 0, 256);
1523 case GIO_FONT8x14: /* get 8x14 dot font */
1524 if (!ISFONTAVAIL(sc->adp->va_flags))
1526 if (sc->fonts_loaded & FONT_14) {
1527 bcopy(sc->font_14, data, 14*256);
1533 case PIO_FONT8x16: /* set 8x16 dot font */
1534 if (!ISFONTAVAIL(sc->adp->va_flags))
1536 bcopy(data, sc->font_16, 16*256);
1537 sc->fonts_loaded |= FONT_16;
1540 * Always use the font page #0. XXX
1541 * Don't load if the current font size is not 8x16.
1543 if (ISTEXTSC(sc->cur_scp) && (sc->cur_scp->font_size >= 16))
1544 sc_load_font(sc->cur_scp, 0, 16, 8, sc->font_16, 0, 256);
1547 case GIO_FONT8x16: /* get 8x16 dot font */
1548 if (!ISFONTAVAIL(sc->adp->va_flags))
1550 if (sc->fonts_loaded & FONT_16) {
1551 bcopy(sc->font_16, data, 16*256);
1557 #endif /* SC_NO_FONT_LOADING */
1567 consolectl_ioctl(struct cdev *dev, u_long cmd, caddr_t data, int fflag,
1571 return sctty_ioctl(dev->si_drv1, cmd, data, td);
1575 consolectl_close(struct cdev *dev, int flags, int mode, struct thread *td)
1577 #ifndef SC_NO_SYSMOUSE
1579 memset(&info, 0, sizeof(info));
1580 info.operation = MOUSE_ACTION;
1583 * Make sure all buttons are released when moused and other
1584 * console daemons exit, so that no buttons are left pressed.
1586 (void) sctty_ioctl(dev->si_drv1, CONS_MOUSECTL, (caddr_t)&info, td);
1592 sc_cnprobe(struct consdev *cp)
1597 if (!vty_enabled(VTY_SC)) {
1598 cp->cn_pri = CN_DEAD;
1602 cp->cn_pri = sc_get_cons_priority(&unit, &flags);
1604 /* a video card is always required */
1605 if (!scvidprobe(unit, flags, TRUE))
1606 cp->cn_pri = CN_DEAD;
1608 /* syscons will become console even when there is no keyboard */
1609 sckbdprobe(unit, flags, TRUE);
1611 if (cp->cn_pri == CN_DEAD)
1614 /* initialize required fields */
1615 strcpy(cp->cn_name, "ttyv0");
1619 sc_cninit(struct consdev *cp)
1624 sc_get_cons_priority(&unit, &flags);
1625 scinit(unit, flags | SC_KERNEL_CONSOLE);
1626 sc_console_unit = unit;
1627 sc_console = sc_get_stat(sc_get_softc(unit, SC_KERNEL_CONSOLE)->dev[0]);
1632 sc_cnterm(struct consdev *cp)
1634 /* we are not the kernel console any more, release everything */
1636 if (sc_console_unit < 0)
1637 return; /* shouldn't happen */
1640 sc_clear_screen(sc_console);
1641 sccnupdate(sc_console);
1644 scterm(sc_console_unit, SC_KERNEL_CONSOLE);
1645 sc_console_unit = -1;
1649 static void sccnclose(sc_softc_t *sc, struct sc_cnstate *sp);
1650 static int sc_cngetc_locked(struct sc_cnstate *sp);
1651 static void sccnkbdlock(sc_softc_t *sc, struct sc_cnstate *sp);
1652 static void sccnkbdunlock(sc_softc_t *sc, struct sc_cnstate *sp);
1653 static void sccnopen(sc_softc_t *sc, struct sc_cnstate *sp, int flags);
1654 static void sccnscrlock(sc_softc_t *sc, struct sc_cnstate *sp);
1655 static void sccnscrunlock(sc_softc_t *sc, struct sc_cnstate *sp);
1658 sccnkbdlock(sc_softc_t *sc, struct sc_cnstate *sp)
1661 * Locking method: hope for the best.
1662 * The keyboard is supposed to be Giant locked. We can't handle that
1663 * in general. The kdb_active case here is not safe, and we will
1664 * proceed without the lock in all cases.
1666 sp->kbd_locked = !kdb_active && mtx_trylock(&Giant);
1670 sccnkbdunlock(sc_softc_t *sc, struct sc_cnstate *sp)
1674 sp->kbd_locked = FALSE;
1678 sccnscrlock(sc_softc_t *sc, struct sc_cnstate *sp)
1684 * - if kdb_active and video_mtx is not owned by anyone, then lock
1685 * by kdb remaining active
1686 * - if !kdb_active, try to acquire video_mtx without blocking or
1687 * recursing; if we get it then it works normally.
1688 * Note that video_mtx is especially unusable if we already own it,
1689 * since then it is protecting something and syscons is not reentrant
1690 * enough to ignore the protection even in the kdb_active case.
1693 sp->kdb_locked = sc->video_mtx.mtx_lock == MTX_UNOWNED || panicstr;
1694 sp->mtx_locked = FALSE;
1696 sp->kdb_locked = FALSE;
1697 for (retries = 0; retries < 1000; retries++) {
1698 sp->mtx_locked = mtx_trylock_spin_flags(&sc->video_mtx,
1699 MTX_QUIET) != 0 || panicstr;
1708 sccnscrunlock(sc_softc_t *sc, struct sc_cnstate *sp)
1711 mtx_unlock_spin(&sc->video_mtx);
1712 sp->mtx_locked = sp->kdb_locked = FALSE;
1716 sccnopen(sc_softc_t *sc, struct sc_cnstate *sp, int flags)
1720 /* assert(sc_console_unit >= 0) */
1722 sp->kbd_opened = FALSE;
1723 sp->scr_opened = FALSE;
1724 sp->kbd_locked = FALSE;
1726 /* Opening the keyboard is optional. */
1727 if (!(flags & 1) || sc->kbd == NULL)
1730 sccnkbdlock(sc, sp);
1733 * Make sure the keyboard is accessible even when the kbd device
1734 * driver is disabled.
1736 kbdd_enable(sc->kbd);
1738 /* Switch the keyboard to console mode (K_XLATE, polled) on all scp's. */
1740 (void)kbdd_ioctl(sc->kbd, KDSKBMODE, (caddr_t)&kbd_mode);
1741 sc->kbd_open_level++;
1742 kbdd_poll(sc->kbd, TRUE);
1744 sp->kbd_opened = TRUE;
1747 /* The screen is opened iff locking it succeeds. */
1748 sccnscrlock(sc, sp);
1749 if (!sp->kdb_locked && !sp->mtx_locked)
1751 sp->scr_opened = TRUE;
1753 /* The screen switch is optional. */
1757 /* try to switch to the kernel console screen */
1759 sc->cur_scp->index != sc_console->index &&
1760 sc->cur_scp->smode.mode == VT_AUTO &&
1761 sc_console->smode.mode == VT_AUTO)
1762 sc_switch_scr(sc, sc_console->index);
1766 sccnclose(sc_softc_t *sc, struct sc_cnstate *sp)
1768 sp->scr_opened = FALSE;
1769 sccnscrunlock(sc, sp);
1771 if (!sp->kbd_opened)
1774 /* Restore keyboard mode (for the current, possibly-changed scp). */
1775 kbdd_poll(sc->kbd, FALSE);
1776 if (--sc->kbd_open_level == 0)
1777 (void)kbdd_ioctl(sc->kbd, KDSKBMODE, (caddr_t)&sc->cur_scp->kbd_mode);
1779 kbdd_disable(sc->kbd);
1780 sp->kbd_opened = FALSE;
1781 sccnkbdunlock(sc, sp);
1785 * Grabbing switches the screen and keyboard focus to sc_console and the
1786 * keyboard mode to (K_XLATE, polled). Only switching to polled mode is
1787 * essential (for preventing the interrupt handler from eating input
1788 * between polls). Focus is part of the UI, and the other switches are
1789 * work just was well when they are done on every entry and exit.
1791 * Screen switches while grabbed are supported, and to maintain focus for
1792 * this ungrabbing and closing only restore the polling state and then
1793 * the keyboard mode if on the original screen.
1797 sc_cngrab(struct consdev *cp)
1802 sc = sc_console->sc;
1803 lev = atomic_fetchadd_int(&sc->grab_level, 1);
1804 if (lev >= 0 && lev < 2) {
1805 sccnopen(sc, &sc->grab_state[lev], 1 | 2);
1806 sccnscrunlock(sc, &sc->grab_state[lev]);
1807 sccnkbdunlock(sc, &sc->grab_state[lev]);
1812 sc_cnungrab(struct consdev *cp)
1817 sc = sc_console->sc;
1818 lev = atomic_load_acq_int(&sc->grab_level) - 1;
1819 if (lev >= 0 && lev < 2) {
1820 sccnkbdlock(sc, &sc->grab_state[lev]);
1821 sccnscrlock(sc, &sc->grab_state[lev]);
1822 sccnclose(sc, &sc->grab_state[lev]);
1824 atomic_add_int(&sc->grab_level, -1);
1827 static char sc_cnputc_log[0x1000];
1828 static u_int sc_cnputc_loghead;
1829 static u_int sc_cnputc_logtail;
1832 sc_cnputc(struct consdev *cd, int c)
1834 struct sc_cnstate st;
1836 scr_stat *scp = sc_console;
1837 #ifndef SC_NO_HISTORY
1841 #endif /* !SC_NO_HISTORY */
1845 /* assert(sc_console != NULL) */
1847 sccnopen(scp->sc, &st, 0);
1852 * In the unlocked case, the logging is intentionally only
1853 * perfectly atomic for the indexes.
1855 head = atomic_fetchadd_int(&sc_cnputc_loghead, 1);
1856 sc_cnputc_log[head % sizeof(sc_cnputc_log)] = c;
1859 * If we couldn't open, return to defer output.
1864 #ifndef SC_NO_HISTORY
1865 if (scp == scp->sc->cur_scp && scp->status & SLKED) {
1866 scp->status &= ~SLKED;
1867 update_kbd_state(scp, scp->status, SLKED);
1868 if (scp->status & BUFFER_SAVED) {
1869 if (!sc_hist_restore(scp))
1870 sc_remove_cutmarking(scp);
1871 scp->status &= ~BUFFER_SAVED;
1872 scp->status |= CURSOR_ENABLED;
1873 sc_draw_cursor_image(scp);
1877 * XXX: Now that TTY's have their own locks, we cannot process
1878 * any data after disabling scroll lock. cnputs already holds a
1881 tp = SC_DEV(scp->sc, scp->index);
1882 /* XXX "tp" can be NULL */
1885 sctty_outwakeup(tp);
1889 #endif /* !SC_NO_HISTORY */
1891 /* Play any output still in the log (our char may already be done). */
1892 while (sc_cnputc_logtail != atomic_load_acq_int(&sc_cnputc_loghead)) {
1893 buf[0] = sc_cnputc_log[sc_cnputc_logtail++ % sizeof(sc_cnputc_log)];
1894 if (atomic_load_acq_int(&sc_cnputc_loghead) - sc_cnputc_logtail >=
1895 sizeof(sc_cnputc_log))
1897 sc_puts(scp, buf, 1, 1);
1900 s = spltty(); /* block sckbdevent and scrn_timer */
1903 sccnclose(scp->sc, &st);
1907 sc_cngetc(struct consdev *cd)
1909 struct sc_cnstate st;
1912 /* assert(sc_console != NULL) */
1913 sccnopen(sc_console->sc, &st, 1);
1914 s = spltty(); /* block sckbdevent and scrn_timer while we poll */
1915 if (!st.kbd_opened) {
1917 sccnclose(sc_console->sc, &st);
1918 return -1; /* means no keyboard since we fudged the locking */
1920 c = sc_cngetc_locked(&st);
1922 sccnclose(sc_console->sc, &st);
1927 sc_cngetc_locked(struct sc_cnstate *sp)
1929 static struct fkeytab fkey;
1936 * Stop the screen saver and update the screen if necessary.
1937 * What if we have been running in the screen saver code... XXX
1940 sc_touch_scrn_saver();
1941 scp = sc_console->sc->cur_scp; /* XXX */
1945 if (fkeycp < fkey.len)
1946 return fkey.str[fkeycp++];
1948 c = scgetc(scp->sc, SCGETC_CN | SCGETC_NONBLOCK, sp);
1950 switch (KEYFLAGS(c)) {
1951 case 0: /* normal char */
1953 case FKEY: /* function key */
1954 p = (*scp->tsw->te_fkeystr)(scp, c);
1956 fkey.len = strlen(p);
1957 bcopy(p, fkey.str, fkey.len);
1961 p = kbdd_get_fkeystr(scp->sc->kbd, KEYCHAR(c), (size_t *)&fkeycp);
1963 if ((p != NULL) && (fkey.len > 0)) {
1964 bcopy(p, fkey.str, fkey.len);
1978 sccnupdate(scr_stat *scp)
1980 /* this is a cut-down version of scrn_timer()... */
1982 if (suspend_in_progress || scp->sc->font_loading_in_progress)
1985 if (kdb_active || panicstr || shutdown_in_progress) {
1986 sc_touch_scrn_saver();
1987 } else if (scp != scp->sc->cur_scp) {
1991 if (!run_scrn_saver)
1992 scp->sc->flags &= ~SC_SCRN_IDLE;
1994 if ((saver_mode != CONS_LKM_SAVER) || !(scp->sc->flags & SC_SCRN_IDLE))
1995 if (scp->sc->flags & SC_SCRN_BLANKED)
1996 stop_scrn_saver(scp->sc, current_saver);
1999 if (scp != scp->sc->cur_scp || scp->sc->blink_in_progress
2000 || scp->sc->switch_in_progress)
2003 * FIXME: unlike scrn_timer(), we call scrn_update() from here even
2004 * when write_in_progress is non-zero. XXX
2007 if (!ISGRAPHSC(scp) && !(scp->sc->flags & SC_SCRN_BLANKED))
2008 scrn_update(scp, TRUE);
2012 scrn_timer(void *arg)
2014 static time_t kbd_time_stamp = 0;
2019 again = (arg != NULL);
2021 sc = (sc_softc_t *)arg;
2022 else if (sc_console != NULL)
2023 sc = sc_console->sc;
2027 /* find the vty to update */
2030 /* don't do anything when we are performing some I/O operations */
2031 if (suspend_in_progress || sc->font_loading_in_progress)
2034 if ((sc->kbd == NULL) && (sc->config & SC_AUTODETECT_KBD)) {
2035 /* try to allocate a keyboard automatically */
2036 if (kbd_time_stamp != time_uptime) {
2037 kbd_time_stamp = time_uptime;
2038 sc->keyboard = sc_allocate_keyboard(sc, -1);
2039 if (sc->keyboard >= 0) {
2040 sc->kbd = kbd_get_keyboard(sc->keyboard);
2041 (void)kbdd_ioctl(sc->kbd, KDSKBMODE,
2042 (caddr_t)&sc->cur_scp->kbd_mode);
2043 update_kbd_state(sc->cur_scp, sc->cur_scp->status,
2049 /* should we stop the screen saver? */
2050 if (kdb_active || panicstr || shutdown_in_progress)
2051 sc_touch_scrn_saver();
2052 if (run_scrn_saver) {
2053 if (time_uptime > sc->scrn_time_stamp + scrn_blank_time)
2054 sc->flags |= SC_SCRN_IDLE;
2056 sc->flags &= ~SC_SCRN_IDLE;
2058 sc->scrn_time_stamp = time_uptime;
2059 sc->flags &= ~SC_SCRN_IDLE;
2060 if (scrn_blank_time > 0)
2061 run_scrn_saver = TRUE;
2064 if ((saver_mode != CONS_LKM_SAVER) || !(sc->flags & SC_SCRN_IDLE))
2065 if (sc->flags & SC_SCRN_BLANKED)
2066 stop_scrn_saver(sc, current_saver);
2069 /* should we just return ? */
2070 if (sc->blink_in_progress || sc->switch_in_progress
2071 || sc->write_in_progress)
2074 /* Update the screen */
2075 scp = sc->cur_scp; /* cur_scp may have changed... */
2076 if (!ISGRAPHSC(scp) && !(sc->flags & SC_SCRN_BLANKED))
2077 scrn_update(scp, TRUE);
2080 /* should we activate the screen saver? */
2081 if ((saver_mode == CONS_LKM_SAVER) && (sc->flags & SC_SCRN_IDLE))
2082 if (!ISGRAPHSC(scp) || (sc->flags & SC_SCRN_BLANKED))
2083 (*current_saver)(sc, TRUE);
2089 * Use reduced "refresh" rate if we are in graphics and that is not a
2090 * graphical screen saver. In such case we just have nothing to do.
2092 if (ISGRAPHSC(scp) && !(sc->flags & SC_SCRN_BLANKED))
2096 callout_reset_sbt(&sc->ctimeout, SBT_1S / rate, 0,
2097 scrn_timer, sc, C_PREL(1));
2102 and_region(int *s1, int *e1, int s2, int e2)
2104 if (*e1 < s2 || e2 < *s1)
2106 *s1 = imax(*s1, s2);
2107 *e1 = imin(*e1, e2);
2112 scrn_update(scr_stat *scp, int show_cursor)
2119 /* assert(scp == scp->sc->cur_scp) */
2121 SC_VIDEO_LOCK(scp->sc);
2123 #ifndef SC_NO_CUTPASTE
2124 /* remove the previous mouse pointer image if necessary */
2125 if (scp->status & MOUSE_VISIBLE) {
2127 e = scp->mouse_pos + scp->xsize + 1;
2128 if ((scp->status & (MOUSE_MOVED | MOUSE_HIDDEN))
2129 || and_region(&s, &e, scp->start, scp->end)
2130 || ((scp->status & CURSOR_ENABLED) &&
2131 (scp->cursor_pos != scp->cursor_oldpos) &&
2132 (and_region(&s, &e, scp->cursor_pos, scp->cursor_pos)
2133 || and_region(&s, &e, scp->cursor_oldpos, scp->cursor_oldpos)))) {
2134 sc_remove_mouse_image(scp);
2135 if (scp->end >= scp->xsize*scp->ysize)
2136 scp->end = scp->xsize*scp->ysize - 1;
2139 #endif /* !SC_NO_CUTPASTE */
2143 if (scp->end >= scp->xsize*scp->ysize) {
2144 printf("scrn_update(): scp->end %d > size_of_screen!!\n", scp->end);
2145 scp->end = scp->xsize*scp->ysize - 1;
2147 if (scp->start < 0) {
2148 printf("scrn_update(): scp->start %d < 0\n", scp->start);
2153 /* update screen image */
2154 if (scp->start <= scp->end) {
2155 if (scp->mouse_cut_end >= 0) {
2156 /* there is a marked region for cut & paste */
2157 if (scp->mouse_cut_start <= scp->mouse_cut_end) {
2158 start = scp->mouse_cut_start;
2159 end = scp->mouse_cut_end;
2161 start = scp->mouse_cut_end;
2162 end = scp->mouse_cut_start - 1;
2166 /* does the cut-mark region overlap with the update region? */
2167 if (and_region(&s, &e, scp->start, scp->end)) {
2168 (*scp->rndr->draw)(scp, s, e - s + 1, TRUE);
2171 if (and_region(&s, &e, scp->start, scp->end))
2172 (*scp->rndr->draw)(scp, s, e - s + 1, FALSE);
2174 e = scp->xsize*scp->ysize - 1;
2175 if (and_region(&s, &e, scp->start, scp->end))
2176 (*scp->rndr->draw)(scp, s, e - s + 1, FALSE);
2178 (*scp->rndr->draw)(scp, scp->start,
2179 scp->end - scp->start + 1, FALSE);
2182 (*scp->rndr->draw)(scp, scp->start,
2183 scp->end - scp->start + 1, FALSE);
2187 /* we are not to show the cursor and the mouse pointer... */
2190 scp->start = scp->xsize*scp->ysize - 1;
2191 SC_VIDEO_UNLOCK(scp->sc);
2195 /* update cursor image */
2196 if (scp->status & CURSOR_ENABLED) {
2199 /* did cursor move since last time ? */
2200 if (scp->cursor_pos != scp->cursor_oldpos) {
2201 /* do we need to remove old cursor image ? */
2202 if (!and_region(&s, &e, scp->cursor_oldpos, scp->cursor_oldpos))
2203 sc_remove_cursor_image(scp);
2204 sc_draw_cursor_image(scp);
2206 if (and_region(&s, &e, scp->cursor_pos, scp->cursor_pos))
2207 /* cursor didn't move, but has been overwritten */
2208 sc_draw_cursor_image(scp);
2209 else if (scp->curs_attr.flags & CONS_BLINK_CURSOR)
2210 /* if it's a blinking cursor, update it */
2211 (*scp->rndr->blink_cursor)(scp, scp->cursor_pos,
2212 sc_inside_cutmark(scp,
2217 #ifndef SC_NO_CUTPASTE
2218 /* update "pseudo" mouse pointer image */
2219 if (scp->sc->flags & SC_MOUSE_ENABLED) {
2220 if (!(scp->status & (MOUSE_VISIBLE | MOUSE_HIDDEN))) {
2221 scp->status &= ~MOUSE_MOVED;
2222 sc_draw_mouse_image(scp);
2225 #endif /* SC_NO_CUTPASTE */
2228 scp->start = scp->xsize*scp->ysize - 1;
2230 SC_VIDEO_UNLOCK(scp->sc);
2235 scsplash_callback(int event, void *arg)
2240 sc = (sc_softc_t *)arg;
2244 if (add_scrn_saver(scsplash_saver) == 0) {
2245 sc->flags &= ~SC_SAVER_FAILED;
2246 run_scrn_saver = TRUE;
2247 if (cold && !(boothowto & RB_VERBOSE)) {
2248 scsplash_stick(TRUE);
2249 (*current_saver)(sc, TRUE);
2255 if (current_saver == scsplash_saver) {
2256 scsplash_stick(FALSE);
2257 error = remove_scrn_saver(scsplash_saver);
2269 scsplash_saver(sc_softc_t *sc, int show)
2271 static int busy = FALSE;
2280 if (!(sc->flags & SC_SAVER_FAILED)) {
2281 if (!(sc->flags & SC_SCRN_BLANKED))
2282 set_scrn_saver_mode(scp, -1, NULL, 0);
2283 switch (splash(sc->adp, TRUE)) {
2284 case 0: /* succeeded */
2286 case EAGAIN: /* try later */
2287 restore_scrn_saver_mode(scp, FALSE);
2288 sc_touch_scrn_saver(); /* XXX */
2291 sc->flags |= SC_SAVER_FAILED;
2292 scsplash_stick(FALSE);
2293 restore_scrn_saver_mode(scp, TRUE);
2294 printf("scsplash_saver(): failed to put up the image\n");
2298 } else if (!sticky_splash) {
2299 if ((sc->flags & SC_SCRN_BLANKED) && (splash(sc->adp, FALSE) == 0))
2300 restore_scrn_saver_mode(scp, TRUE);
2306 add_scrn_saver(void (*this_saver)(sc_softc_t *, int))
2311 if (current_saver != none_saver) {
2312 error = remove_scrn_saver(current_saver);
2317 if (current_saver != none_saver)
2320 run_scrn_saver = FALSE;
2321 saver_mode = CONS_LKM_SAVER;
2322 current_saver = this_saver;
2327 remove_scrn_saver(void (*this_saver)(sc_softc_t *, int))
2329 if (current_saver != this_saver)
2334 * In order to prevent `current_saver' from being called by
2335 * the timeout routine `scrn_timer()' while we manipulate
2336 * the saver list, we shall set `current_saver' to `none_saver'
2337 * before stopping the current saver, rather than blocking by `splXX()'.
2339 current_saver = none_saver;
2341 stop_scrn_saver(this_saver);
2344 /* unblank all blanked screens */
2345 wait_scrn_saver_stop(NULL);
2349 current_saver = none_saver;
2354 set_scrn_saver_mode(scr_stat *scp, int mode, u_char *pal, int border)
2358 /* assert(scp == scp->sc->cur_scp) */
2360 if (!ISGRAPHSC(scp))
2361 sc_remove_cursor_image(scp);
2362 scp->splash_save_mode = scp->mode;
2363 scp->splash_save_status = scp->status & (GRAPHICS_MODE | PIXEL_MODE);
2364 scp->status &= ~(GRAPHICS_MODE | PIXEL_MODE);
2365 scp->status |= (UNKNOWN_MODE | SAVER_RUNNING);
2366 scp->sc->flags |= SC_SCRN_BLANKED;
2372 if (set_mode(scp) == 0) {
2373 if (scp->sc->adp->va_info.vi_flags & V_INFO_GRAPHICS)
2374 scp->status |= GRAPHICS_MODE;
2375 #ifndef SC_NO_PALETTE_LOADING
2377 vidd_load_palette(scp->sc->adp, pal);
2379 sc_set_border(scp, border);
2383 scp->mode = scp->splash_save_mode;
2384 scp->status &= ~(UNKNOWN_MODE | SAVER_RUNNING);
2385 scp->status |= scp->splash_save_status;
2392 restore_scrn_saver_mode(scr_stat *scp, int changemode)
2398 /* assert(scp == scp->sc->cur_scp) */
2401 status = scp->status;
2402 scp->mode = scp->splash_save_mode;
2403 scp->status &= ~(UNKNOWN_MODE | SAVER_RUNNING);
2404 scp->status |= scp->splash_save_status;
2405 scp->sc->flags &= ~SC_SCRN_BLANKED;
2407 if (!ISGRAPHSC(scp))
2408 sc_draw_cursor_image(scp);
2413 if (set_mode(scp) == 0) {
2414 #ifndef SC_NO_PALETTE_LOADING
2415 #ifdef SC_PIXEL_MODE
2416 if (scp->sc->adp->va_info.vi_mem_model == V_INFO_MM_DIRECT)
2417 vidd_load_palette(scp->sc->adp, scp->sc->palette2);
2420 vidd_load_palette(scp->sc->adp, scp->sc->palette);
2427 scp->status = status;
2434 stop_scrn_saver(sc_softc_t *sc, void (*saver)(sc_softc_t *, int))
2436 (*saver)(sc, FALSE);
2437 run_scrn_saver = FALSE;
2438 /* the screen saver may have chosen not to stop after all... */
2439 if (sc->flags & SC_SCRN_BLANKED)
2442 mark_all(sc->cur_scp);
2443 if (sc->delayed_next_scr)
2444 sc_switch_scr(sc, sc->delayed_next_scr - 1);
2446 wakeup(&scrn_blanked);
2450 wait_scrn_saver_stop(sc_softc_t *sc)
2454 while (scrn_blanked > 0) {
2455 run_scrn_saver = FALSE;
2456 if (sc && !(sc->flags & SC_SCRN_BLANKED)) {
2460 error = tsleep(&scrn_blanked, PZERO | PCATCH, "scrsav", 0);
2461 if ((error != 0) && (error != ERESTART))
2464 run_scrn_saver = FALSE;
2467 #endif /* DEV_SPLASH */
2470 sc_touch_scrn_saver(void)
2472 scsplash_stick(FALSE);
2473 run_scrn_saver = FALSE;
2477 sc_switch_scr(sc_softc_t *sc, u_int next_scr)
2484 DPRINTF(5, ("sc0: sc_switch_scr() %d ", next_scr + 1));
2486 if (sc->cur_scp == NULL)
2489 /* prevent switch if previously requested */
2490 if (sc->flags & SC_SCRN_VTYLOCK) {
2491 sc_bell(sc->cur_scp, sc->cur_scp->bell_pitch,
2492 sc->cur_scp->bell_duration);
2496 /* delay switch if the screen is blanked or being updated */
2497 if ((sc->flags & SC_SCRN_BLANKED) || sc->write_in_progress
2498 || sc->blink_in_progress) {
2499 sc->delayed_next_scr = next_scr + 1;
2500 sc_touch_scrn_saver();
2501 DPRINTF(5, ("switch delayed\n"));
2504 sc->delayed_next_scr = 0;
2507 cur_scp = sc->cur_scp;
2509 /* we are in the middle of the vty switching process... */
2510 if (sc->switch_in_progress
2511 && (cur_scp->smode.mode == VT_PROCESS)
2513 p = pfind(cur_scp->pid);
2514 if (cur_scp->proc != p) {
2518 * The controlling process has died!!. Do some clean up.
2519 * NOTE:`cur_scp->proc' and `cur_scp->smode.mode'
2520 * are not reset here yet; they will be cleared later.
2522 DPRINTF(5, ("cur_scp controlling process %d died, ",
2524 if (cur_scp->status & SWITCH_WAIT_REL) {
2526 * Force the previous switch to finish, but return now
2529 DPRINTF(5, ("reset WAIT_REL, "));
2530 finish_vt_rel(cur_scp, TRUE, &s);
2532 DPRINTF(5, ("finishing previous switch\n"));
2534 } else if (cur_scp->status & SWITCH_WAIT_ACQ) {
2535 /* let's assume screen switch has been completed. */
2536 DPRINTF(5, ("reset WAIT_ACQ, "));
2537 finish_vt_acq(cur_scp);
2540 * We are in between screen release and acquisition, and
2541 * reached here via scgetc() or scrn_timer() which has
2542 * interrupted exchange_scr(). Don't do anything stupid.
2544 DPRINTF(5, ("waiting nothing, "));
2550 * The controlling process is alive, but not responding...
2551 * It is either buggy or it may be just taking time.
2552 * The following code is a gross kludge to cope with this
2553 * problem for which there is no clean solution. XXX
2555 if (cur_scp->status & SWITCH_WAIT_REL) {
2556 switch (sc->switch_in_progress++) {
2560 DPRINTF(5, ("sending relsig again, "));
2561 signal_vt_rel(cur_scp);
2568 * Act as if the controlling program returned
2571 DPRINTF(5, ("force reset WAIT_REL, "));
2572 finish_vt_rel(cur_scp, FALSE, &s);
2574 DPRINTF(5, ("act as if VT_FALSE was seen\n"));
2577 } else if (cur_scp->status & SWITCH_WAIT_ACQ) {
2578 switch (sc->switch_in_progress++) {
2582 DPRINTF(5, ("sending acqsig again, "));
2583 signal_vt_acq(cur_scp);
2589 /* clear the flag and finish the previous switch */
2590 DPRINTF(5, ("force reset WAIT_ACQ, "));
2591 finish_vt_acq(cur_scp);
2599 * Return error if an invalid argument is given, or vty switch
2600 * is still in progress.
2602 if ((next_scr < sc->first_vty) || (next_scr >= sc->first_vty + sc->vtys)
2603 || sc->switch_in_progress) {
2605 sc_bell(cur_scp, bios_value.bell_pitch, BELL_DURATION);
2606 DPRINTF(5, ("error 1\n"));
2611 * Don't allow switching away from the graphics mode vty
2612 * if the switch mode is VT_AUTO, unless the next vty is the same
2613 * as the current or the current vty has been closed (but showing).
2615 tp = SC_DEV(sc, cur_scp->index);
2616 if ((cur_scp->index != next_scr)
2617 && tty_opened_ns(tp)
2618 && (cur_scp->smode.mode == VT_AUTO)
2619 && ISGRAPHSC(cur_scp)) {
2621 sc_bell(cur_scp, bios_value.bell_pitch, BELL_DURATION);
2622 DPRINTF(5, ("error, graphics mode\n"));
2627 * Is the wanted vty open? Don't allow switching to a closed vty.
2628 * If we are in DDB, don't switch to a vty in the VT_PROCESS mode.
2629 * Note that we always allow the user to switch to the kernel
2630 * console even if it is closed.
2632 if ((sc_console == NULL) || (next_scr != sc_console->index)) {
2633 tp = SC_DEV(sc, next_scr);
2634 if (!tty_opened_ns(tp)) {
2636 sc_bell(cur_scp, bios_value.bell_pitch, BELL_DURATION);
2637 DPRINTF(5, ("error 2, requested vty isn't open!\n"));
2640 if (kdb_active && SC_STAT(tp)->smode.mode == VT_PROCESS) {
2642 DPRINTF(5, ("error 3, requested vty is in the VT_PROCESS mode\n"));
2647 /* this is the start of vty switching process... */
2648 ++sc->switch_in_progress;
2649 sc->old_scp = cur_scp;
2650 sc->new_scp = sc_get_stat(SC_DEV(sc, next_scr));
2651 if (sc->new_scp == sc->old_scp) {
2652 sc->switch_in_progress = 0;
2654 * XXX wakeup() locks the scheduler lock which will hang if
2655 * the lock is in an in-between state, e.g., when we stop at
2656 * a breakpoint at fork_exit. It has always been wrong to call
2657 * wakeup() when the debugger is active. In RELENG_4, wakeup()
2658 * is supposed to be locked by splhigh(), but the debugger may
2659 * be invoked at splhigh().
2662 wakeup(VTY_WCHAN(sc,next_scr));
2664 DPRINTF(5, ("switch done (new == old)\n"));
2668 /* has controlling process died? */
2669 vt_proc_alive(sc->old_scp);
2670 vt_proc_alive(sc->new_scp);
2672 /* wait for the controlling process to release the screen, if necessary */
2673 if (signal_vt_rel(sc->old_scp)) {
2678 /* go set up the new vty screen */
2683 /* wake up processes waiting for this vty */
2685 wakeup(VTY_WCHAN(sc,next_scr));
2687 /* wait for the controlling process to acknowledge, if necessary */
2688 if (signal_vt_acq(sc->cur_scp)) {
2693 sc->switch_in_progress = 0;
2694 if (sc->unit == sc_console_unit)
2695 cnavailable(sc_consptr, TRUE);
2697 DPRINTF(5, ("switch done\n"));
2703 do_switch_scr(sc_softc_t *sc, int s)
2705 vt_proc_alive(sc->new_scp);
2710 /* sc->cur_scp == sc->new_scp */
2711 wakeup(VTY_WCHAN(sc,sc->cur_scp->index));
2713 /* wait for the controlling process to acknowledge, if necessary */
2714 if (!signal_vt_acq(sc->cur_scp)) {
2715 sc->switch_in_progress = 0;
2716 if (sc->unit == sc_console_unit)
2717 cnavailable(sc_consptr, TRUE);
2724 vt_proc_alive(scr_stat *scp)
2729 if ((p = pfind(scp->pid)) != NULL)
2734 scp->smode.mode = VT_AUTO;
2735 DPRINTF(5, ("vt controlling process %d died\n", scp->pid));
2741 signal_vt_rel(scr_stat *scp)
2743 if (scp->smode.mode != VT_PROCESS)
2745 scp->status |= SWITCH_WAIT_REL;
2746 PROC_LOCK(scp->proc);
2747 kern_psignal(scp->proc, scp->smode.relsig);
2748 PROC_UNLOCK(scp->proc);
2749 DPRINTF(5, ("sending relsig to %d\n", scp->pid));
2754 signal_vt_acq(scr_stat *scp)
2756 if (scp->smode.mode != VT_PROCESS)
2758 if (scp->sc->unit == sc_console_unit)
2759 cnavailable(sc_consptr, FALSE);
2760 scp->status |= SWITCH_WAIT_ACQ;
2761 PROC_LOCK(scp->proc);
2762 kern_psignal(scp->proc, scp->smode.acqsig);
2763 PROC_UNLOCK(scp->proc);
2764 DPRINTF(5, ("sending acqsig to %d\n", scp->pid));
2769 finish_vt_rel(scr_stat *scp, int release, int *s)
2771 if (scp == scp->sc->old_scp && scp->status & SWITCH_WAIT_REL) {
2772 scp->status &= ~SWITCH_WAIT_REL;
2774 *s = do_switch_scr(scp->sc, *s);
2776 scp->sc->switch_in_progress = 0;
2783 finish_vt_acq(scr_stat *scp)
2785 if (scp == scp->sc->new_scp && scp->status & SWITCH_WAIT_ACQ) {
2786 scp->status &= ~SWITCH_WAIT_ACQ;
2787 scp->sc->switch_in_progress = 0;
2794 exchange_scr(sc_softc_t *sc)
2798 /* save the current state of video and keyboard */
2799 sc_move_cursor(sc->old_scp, sc->old_scp->xpos, sc->old_scp->ypos);
2800 if (!ISGRAPHSC(sc->old_scp))
2801 sc_remove_cursor_image(sc->old_scp);
2802 if (sc->old_scp->kbd_mode == K_XLATE)
2803 save_kbd_state(sc->old_scp);
2805 /* set up the video for the new screen */
2806 scp = sc->cur_scp = sc->new_scp;
2807 if (sc->old_scp->mode != scp->mode || ISUNKNOWNSC(sc->old_scp))
2811 sc_vtb_init(&scp->scr, VTB_FRAMEBUFFER, scp->xsize, scp->ysize,
2812 (void *)sc->adp->va_window, FALSE);
2814 scp->status |= MOUSE_HIDDEN;
2815 sc_move_cursor(scp, scp->xpos, scp->ypos);
2816 if (!ISGRAPHSC(scp))
2817 sc_set_cursor_image(scp);
2818 #ifndef SC_NO_PALETTE_LOADING
2819 if (ISGRAPHSC(sc->old_scp)) {
2820 #ifdef SC_PIXEL_MODE
2821 if (sc->adp->va_info.vi_mem_model == V_INFO_MM_DIRECT)
2822 vidd_load_palette(sc->adp, sc->palette2);
2825 vidd_load_palette(sc->adp, sc->palette);
2828 sc_set_border(scp, scp->border);
2830 /* set up the keyboard for the new screen */
2831 if (sc->kbd_open_level == 0 && sc->old_scp->kbd_mode != scp->kbd_mode)
2832 (void)kbdd_ioctl(sc->kbd, KDSKBMODE, (caddr_t)&scp->kbd_mode);
2833 update_kbd_state(scp, scp->status, LOCK_MASK);
2839 sc_puts(scr_stat *scp, u_char *buf, int len, int kernel)
2842 /* make screensaver happy */
2843 if (!sticky_splash && scp == scp->sc->cur_scp && !sc_saver_keyb_only)
2844 run_scrn_saver = FALSE;
2848 (*scp->tsw->te_puts)(scp, buf, len, kernel);
2849 if (scp->sc->delayed_next_scr)
2850 sc_switch_scr(scp->sc, scp->sc->delayed_next_scr - 1);
2854 sc_draw_cursor_image(scr_stat *scp)
2856 /* assert(scp == scp->sc->cur_scp); */
2857 SC_VIDEO_LOCK(scp->sc);
2858 (*scp->rndr->draw_cursor)(scp, scp->cursor_pos,
2859 scp->curs_attr.flags & CONS_BLINK_CURSOR, TRUE,
2860 sc_inside_cutmark(scp, scp->cursor_pos));
2861 scp->cursor_oldpos = scp->cursor_pos;
2862 SC_VIDEO_UNLOCK(scp->sc);
2866 sc_remove_cursor_image(scr_stat *scp)
2868 /* assert(scp == scp->sc->cur_scp); */
2869 SC_VIDEO_LOCK(scp->sc);
2870 (*scp->rndr->draw_cursor)(scp, scp->cursor_oldpos,
2871 scp->curs_attr.flags & CONS_BLINK_CURSOR, FALSE,
2872 sc_inside_cutmark(scp, scp->cursor_oldpos));
2873 SC_VIDEO_UNLOCK(scp->sc);
2877 update_cursor_image(scr_stat *scp)
2879 /* assert(scp == scp->sc->cur_scp); */
2880 sc_remove_cursor_image(scp);
2881 sc_set_cursor_image(scp);
2882 sc_draw_cursor_image(scp);
2886 sc_set_cursor_image(scr_stat *scp)
2888 scp->curs_attr.flags = scp->curr_curs_attr.flags;
2889 if (scp->curs_attr.flags & CONS_HIDDEN_CURSOR) {
2890 /* hidden cursor is internally represented as zero-height underline */
2891 scp->curs_attr.flags = CONS_CHAR_CURSOR;
2892 scp->curs_attr.base = scp->curs_attr.height = 0;
2893 } else if (scp->curs_attr.flags & CONS_CHAR_CURSOR) {
2894 scp->curs_attr.base = imin(scp->curr_curs_attr.base,
2895 scp->font_size - 1);
2896 scp->curs_attr.height = imin(scp->curr_curs_attr.height,
2897 scp->font_size - scp->curs_attr.base);
2898 } else { /* block cursor */
2899 scp->curs_attr.base = 0;
2900 scp->curs_attr.height = scp->font_size;
2903 /* assert(scp == scp->sc->cur_scp); */
2904 SC_VIDEO_LOCK(scp->sc);
2905 (*scp->rndr->set_cursor)(scp, scp->curs_attr.base, scp->curs_attr.height,
2906 scp->curs_attr.flags & CONS_BLINK_CURSOR);
2907 SC_VIDEO_UNLOCK(scp->sc);
2911 change_cursor_shape(scr_stat *scp, int flags, int base, int height)
2913 if ((scp == scp->sc->cur_scp) && !ISGRAPHSC(scp))
2914 sc_remove_cursor_image(scp);
2917 scp->curr_curs_attr.base = base;
2919 scp->curr_curs_attr.height = height;
2920 if (flags & CONS_RESET_CURSOR)
2921 scp->curr_curs_attr = scp->dflt_curs_attr;
2923 scp->curr_curs_attr.flags = flags & CONS_CURSOR_ATTRS;
2925 if ((scp == scp->sc->cur_scp) && !ISGRAPHSC(scp)) {
2926 sc_set_cursor_image(scp);
2927 sc_draw_cursor_image(scp);
2932 sc_change_cursor_shape(scr_stat *scp, int flags, int base, int height)
2940 if ((flags != -1) && (flags & CONS_LOCAL_CURSOR)) {
2941 /* local (per vty) change */
2942 change_cursor_shape(scp, flags, base, height);
2950 sc->curs_attr.base = base;
2952 sc->curs_attr.height = height;
2954 if (flags & CONS_RESET_CURSOR)
2955 sc->curs_attr = sc->dflt_curs_attr;
2957 sc->curs_attr.flags = flags & CONS_CURSOR_ATTRS;
2960 for (i = sc->first_vty; i < sc->first_vty + sc->vtys; ++i) {
2961 if ((tp = SC_DEV(sc, i)) == NULL)
2963 if ((scp = sc_get_stat(tp)) == NULL)
2965 scp->dflt_curs_attr = sc->curs_attr;
2966 change_cursor_shape(scp, CONS_RESET_CURSOR, -1, -1);
2972 scinit(int unit, int flags)
2976 * When syscons is being initialized as the kernel console, malloc()
2977 * is not yet functional, because various kernel structures has not been
2978 * fully initialized yet. Therefore, we need to declare the following
2979 * static buffers for the console. This is less than ideal,
2980 * but is necessry evil for the time being. XXX
2982 static u_short sc_buffer[ROW*COL]; /* XXX */
2983 #ifndef SC_NO_FONT_LOADING
2984 static u_char font_8[256*8];
2985 static u_char font_14[256*14];
2986 static u_char font_16[256*16];
2991 video_adapter_t *adp;
2996 /* one time initialization */
2997 if (init_done == COLD)
2998 sc_get_bios_values(&bios_value);
3002 * Allocate resources. Even if we are being called for the second
3003 * time, we must allocate them again, because they might have
3006 sc = sc_get_softc(unit, flags & SC_KERNEL_CONSOLE);
3007 if ((sc->flags & SC_INIT_DONE) == 0)
3008 SC_VIDEO_LOCKINIT(sc);
3011 if (sc->adapter >= 0) {
3012 vid_release(sc->adp, (void *)&sc->adapter);
3016 if (sc->keyboard >= 0) {
3017 DPRINTF(5, ("sc%d: releasing kbd%d\n", unit, sc->keyboard));
3018 i = kbd_release(sc->kbd, (void *)&sc->keyboard);
3019 DPRINTF(5, ("sc%d: kbd_release returned %d\n", unit, i));
3020 if (sc->kbd != NULL) {
3021 DPRINTF(5, ("sc%d: kbd != NULL!, index:%d, unit:%d, flags:0x%x\n",
3022 unit, sc->kbd->kb_index, sc->kbd->kb_unit, sc->kbd->kb_flags));
3026 sc->adapter = vid_allocate("*", unit, (void *)&sc->adapter);
3027 sc->adp = vid_get_adapter(sc->adapter);
3028 /* assert((sc->adapter >= 0) && (sc->adp != NULL)) */
3030 sc->keyboard = sc_allocate_keyboard(sc, unit);
3031 DPRINTF(1, ("sc%d: keyboard %d\n", unit, sc->keyboard));
3033 sc->kbd = kbd_get_keyboard(sc->keyboard);
3034 if (sc->kbd != NULL) {
3035 DPRINTF(1, ("sc%d: kbd index:%d, unit:%d, flags:0x%x\n",
3036 unit, sc->kbd->kb_index, sc->kbd->kb_unit, sc->kbd->kb_flags));
3039 if (!(sc->flags & SC_INIT_DONE) || (adp != sc->adp)) {
3041 sc->initial_mode = sc->adp->va_initial_mode;
3043 #ifndef SC_NO_FONT_LOADING
3044 if (flags & SC_KERNEL_CONSOLE) {
3045 sc->font_8 = font_8;
3046 sc->font_14 = font_14;
3047 sc->font_16 = font_16;
3048 } else if (sc->font_8 == NULL) {
3049 /* assert(sc_malloc) */
3050 sc->font_8 = malloc(sizeof(font_8), M_DEVBUF, M_WAITOK);
3051 sc->font_14 = malloc(sizeof(font_14), M_DEVBUF, M_WAITOK);
3052 sc->font_16 = malloc(sizeof(font_16), M_DEVBUF, M_WAITOK);
3056 /* extract the hardware cursor location and hide the cursor for now */
3057 vidd_read_hw_cursor(sc->adp, &col, &row);
3058 vidd_set_hw_cursor(sc->adp, -1, -1);
3060 /* set up the first console */
3061 sc->first_vty = unit*MAXCONS;
3062 sc->vtys = MAXCONS; /* XXX: should be configurable */
3063 if (flags & SC_KERNEL_CONSOLE) {
3065 * Set up devs structure but don't use it yet, calling make_dev()
3066 * might panic kernel. Wait for sc_attach_unit() to actually
3067 * create the devices.
3069 sc->dev = main_devs;
3070 scp = &main_console;
3071 init_scp(sc, sc->first_vty, scp);
3072 sc_vtb_init(&scp->vtb, VTB_MEMORY, scp->xsize, scp->ysize,
3073 (void *)sc_buffer, FALSE);
3075 /* move cursors to the initial positions */
3076 if (col >= scp->xsize)
3078 if (row >= scp->ysize)
3079 row = scp->ysize - 1;
3082 scp->cursor_pos = scp->cursor_oldpos = row*scp->xsize + col;
3084 if (sc_init_emulator(scp, SC_DFLT_TERM))
3085 sc_init_emulator(scp, "*");
3086 (*scp->tsw->te_default_attr)(scp,
3087 user_default.std_color,
3088 user_default.rev_color);
3090 /* assert(sc_malloc) */
3091 sc->dev = malloc(sizeof(struct tty *)*sc->vtys, M_DEVBUF,
3093 sc->dev[0] = sc_alloc_tty(0, unit * MAXCONS);
3094 scp = alloc_scp(sc, sc->first_vty);
3095 SC_STAT(sc->dev[0]) = scp;
3100 /* copy screen to temporary buffer */
3101 sc_vtb_init(&scp->scr, VTB_FRAMEBUFFER, scp->xsize, scp->ysize,
3102 (void *)scp->sc->adp->va_window, FALSE);
3104 sc_vtb_copy(&scp->scr, 0, &scp->vtb, 0, scp->xsize*scp->ysize);
3107 if (bios_value.cursor_end < scp->font_size)
3108 sc->dflt_curs_attr.base = scp->font_size -
3109 bios_value.cursor_end - 1;
3111 sc->dflt_curs_attr.base = 0;
3112 i = bios_value.cursor_end - bios_value.cursor_start + 1;
3113 sc->dflt_curs_attr.height = imin(i, scp->font_size);
3114 sc->dflt_curs_attr.flags = 0;
3115 sc->curs_attr = sc->dflt_curs_attr;
3116 scp->curr_curs_attr = scp->dflt_curs_attr = sc->curs_attr;
3118 #ifndef SC_NO_SYSMOUSE
3119 sc_mouse_move(scp, scp->xpixel/2, scp->ypixel/2);
3121 if (!ISGRAPHSC(scp)) {
3122 sc_set_cursor_image(scp);
3123 sc_draw_cursor_image(scp);
3126 /* save font and palette */
3127 #ifndef SC_NO_FONT_LOADING
3128 sc->fonts_loaded = 0;
3129 if (ISFONTAVAIL(sc->adp->va_flags)) {
3131 bcopy(dflt_font_8, sc->font_8, sizeof(dflt_font_8));
3132 bcopy(dflt_font_14, sc->font_14, sizeof(dflt_font_14));
3133 bcopy(dflt_font_16, sc->font_16, sizeof(dflt_font_16));
3134 sc->fonts_loaded = FONT_16 | FONT_14 | FONT_8;
3135 if (scp->font_size < 14) {
3136 sc_load_font(scp, 0, 8, 8, sc->font_8, 0, 256);
3137 } else if (scp->font_size >= 16) {
3138 sc_load_font(scp, 0, 16, 8, sc->font_16, 0, 256);
3140 sc_load_font(scp, 0, 14, 8, sc->font_14, 0, 256);
3142 #else /* !SC_DFLT_FONT */
3143 if (scp->font_size < 14) {
3144 sc_save_font(scp, 0, 8, 8, sc->font_8, 0, 256);
3145 sc->fonts_loaded = FONT_8;
3146 } else if (scp->font_size >= 16) {
3147 sc_save_font(scp, 0, 16, 8, sc->font_16, 0, 256);
3148 sc->fonts_loaded = FONT_16;
3150 sc_save_font(scp, 0, 14, 8, sc->font_14, 0, 256);
3151 sc->fonts_loaded = FONT_14;
3153 #endif /* SC_DFLT_FONT */
3154 /* FONT KLUDGE: always use the font page #0. XXX */
3155 sc_show_font(scp, 0);
3157 #endif /* !SC_NO_FONT_LOADING */
3159 #ifndef SC_NO_PALETTE_LOADING
3160 vidd_save_palette(sc->adp, sc->palette);
3161 #ifdef SC_PIXEL_MODE
3162 for (i = 0; i < sizeof(sc->palette2); i++)
3163 sc->palette2[i] = i / 3;
3168 if (!(sc->flags & SC_SPLASH_SCRN)) {
3169 /* we are ready to put up the splash image! */
3170 splash_init(sc->adp, scsplash_callback, sc);
3171 sc->flags |= SC_SPLASH_SCRN;
3176 /* the rest is not necessary, if we have done it once */
3177 if (sc->flags & SC_INIT_DONE)
3180 /* initialize mapscrn arrays to a one to one map */
3181 for (i = 0; i < sizeof(sc->scr_map); i++)
3182 sc->scr_map[i] = sc->scr_rmap[i] = i;
3184 sc->flags |= SC_INIT_DONE;
3188 scterm(int unit, int flags)
3193 sc = sc_get_softc(unit, flags & SC_KERNEL_CONSOLE);
3195 return; /* shouldn't happen */
3198 /* this console is no longer available for the splash screen */
3199 if (sc->flags & SC_SPLASH_SCRN) {
3200 splash_term(sc->adp);
3201 sc->flags &= ~SC_SPLASH_SCRN;
3206 /* move the hardware cursor to the upper-left corner */
3207 vidd_set_hw_cursor(sc->adp, 0, 0);
3210 /* release the keyboard and the video card */
3211 if (sc->keyboard >= 0)
3212 kbd_release(sc->kbd, &sc->keyboard);
3213 if (sc->adapter >= 0)
3214 vid_release(sc->adp, &sc->adapter);
3216 /* stop the terminal emulator, if any */
3217 scp = sc_get_stat(sc->dev[0]);
3219 (*scp->tsw->te_term)(scp, &scp->ts);
3220 if (scp->ts != NULL)
3221 free(scp->ts, M_DEVBUF);
3222 mtx_destroy(&sc->video_mtx);
3224 /* clear the structure */
3225 if (!(flags & SC_KERNEL_CONSOLE)) {
3226 /* XXX: We need delete_dev() for this */
3227 free(sc->dev, M_DEVBUF);
3229 /* XXX: We need a ttyunregister for this */
3230 free(sc->tty, M_DEVBUF);
3232 #ifndef SC_NO_FONT_LOADING
3233 free(sc->font_8, M_DEVBUF);
3234 free(sc->font_14, M_DEVBUF);
3235 free(sc->font_16, M_DEVBUF);
3237 /* XXX vtb, history */
3239 bzero(sc, sizeof(*sc));
3245 scshutdown(__unused void *arg, __unused int howto)
3248 KASSERT(sc_console != NULL, ("sc_console != NULL"));
3249 KASSERT(sc_console->sc != NULL, ("sc_console->sc != NULL"));
3250 KASSERT(sc_console->sc->cur_scp != NULL,
3251 ("sc_console->sc->cur_scp != NULL"));
3253 sc_touch_scrn_saver();
3255 sc_console->sc->cur_scp->index != sc_console->index &&
3256 sc_console->sc->cur_scp->smode.mode == VT_AUTO &&
3257 sc_console->smode.mode == VT_AUTO)
3258 sc_switch_scr(sc_console->sc, sc_console->index);
3259 shutdown_in_progress = TRUE;
3263 scsuspend(__unused void *arg)
3267 KASSERT(sc_console != NULL, ("sc_console != NULL"));
3268 KASSERT(sc_console->sc != NULL, ("sc_console->sc != NULL"));
3269 KASSERT(sc_console->sc->cur_scp != NULL,
3270 ("sc_console->sc->cur_scp != NULL"));
3272 sc_susp_scr = sc_console->sc->cur_scp->index;
3273 if (sc_no_suspend_vtswitch ||
3274 sc_susp_scr == sc_console->index) {
3275 sc_touch_scrn_saver();
3279 for (retry = 0; retry < 10; retry++) {
3280 sc_switch_scr(sc_console->sc, sc_console->index);
3281 if (!sc_console->sc->switch_in_progress)
3283 pause("scsuspend", hz);
3285 suspend_in_progress = TRUE;
3289 scresume(__unused void *arg)
3292 KASSERT(sc_console != NULL, ("sc_console != NULL"));
3293 KASSERT(sc_console->sc != NULL, ("sc_console->sc != NULL"));
3294 KASSERT(sc_console->sc->cur_scp != NULL,
3295 ("sc_console->sc->cur_scp != NULL"));
3297 suspend_in_progress = FALSE;
3298 if (sc_susp_scr < 0) {
3299 update_font(sc_console->sc->cur_scp);
3302 sc_switch_scr(sc_console->sc, sc_susp_scr);
3306 sc_clean_up(scr_stat *scp)
3312 if (scp->sc->flags & SC_SCRN_BLANKED) {
3313 sc_touch_scrn_saver();
3315 if ((error = wait_scrn_saver_stop(scp->sc)))
3319 scp->status |= MOUSE_HIDDEN;
3320 sc_remove_mouse_image(scp);
3321 sc_remove_cutmarking(scp);
3326 sc_alloc_scr_buffer(scr_stat *scp, int wait, int discard)
3332 sc_vtb_init(&new, VTB_MEMORY, scp->xsize, scp->ysize, NULL, wait);
3333 if (!discard && (old.vtb_flags & VTB_VALID)) {
3334 /* retain the current cursor position and buffer contants */
3335 scp->cursor_oldpos = scp->cursor_pos;
3337 * This works only if the old buffer has the same size as or larger
3338 * than the new one. XXX
3340 sc_vtb_copy(&old, 0, &new, 0, scp->xsize*scp->ysize);
3344 sc_vtb_destroy(&old);
3347 #ifndef SC_NO_SYSMOUSE
3348 /* move the mouse cursor at the center of the screen */
3349 sc_mouse_move(scp, scp->xpixel / 2, scp->ypixel / 2);
3354 *alloc_scp(sc_softc_t *sc, int vty)
3358 /* assert(sc_malloc) */
3360 scp = (scr_stat *)malloc(sizeof(scr_stat), M_DEVBUF, M_WAITOK);
3361 init_scp(sc, vty, scp);
3363 sc_alloc_scr_buffer(scp, TRUE, TRUE);
3364 if (sc_init_emulator(scp, SC_DFLT_TERM))
3365 sc_init_emulator(scp, "*");
3367 #ifndef SC_NO_CUTPASTE
3368 sc_alloc_cut_buffer(scp, TRUE);
3371 #ifndef SC_NO_HISTORY
3372 sc_alloc_history_buffer(scp, 0, 0, TRUE);
3379 init_scp(sc_softc_t *sc, int vty, scr_stat *scp)
3383 bzero(scp, sizeof(*scp));
3388 scp->mode = sc->initial_mode;
3389 vidd_get_info(sc->adp, scp->mode, &info);
3390 if (info.vi_flags & V_INFO_GRAPHICS) {
3391 scp->status |= GRAPHICS_MODE;
3392 scp->xpixel = info.vi_width;
3393 scp->ypixel = info.vi_height;
3394 scp->xsize = info.vi_width/info.vi_cwidth;
3395 scp->ysize = info.vi_height/info.vi_cheight;
3399 scp->xsize = info.vi_width;
3400 scp->ysize = info.vi_height;
3401 scp->xpixel = scp->xsize*info.vi_cwidth;
3402 scp->ypixel = scp->ysize*info.vi_cheight;
3405 scp->font_size = info.vi_cheight;
3406 scp->font_width = info.vi_cwidth;
3407 #ifndef SC_NO_FONT_LOADING
3408 if (info.vi_cheight < 14)
3409 scp->font = sc->font_8;
3410 else if (info.vi_cheight >= 16)
3411 scp->font = sc->font_16;
3413 scp->font = sc->font_14;
3418 sc_vtb_init(&scp->vtb, VTB_MEMORY, 0, 0, NULL, FALSE);
3420 sc_vtb_init(&scp->scr, VTB_FRAMEBUFFER, 0, 0, NULL, FALSE);
3422 scp->xoff = scp->yoff = 0;
3423 scp->xpos = scp->ypos = 0;
3424 scp->start = scp->xsize * scp->ysize - 1;
3429 scp->border = (SC_NORM_ATTR >> 4) & 0x0f;
3430 scp->curr_curs_attr = scp->dflt_curs_attr = sc->curs_attr;
3431 scp->mouse_cut_start = scp->xsize*scp->ysize;
3432 scp->mouse_cut_end = -1;
3433 scp->mouse_signal = 0;
3435 scp->mouse_proc = NULL;
3436 scp->kbd_mode = K_XLATE;
3437 scp->bell_pitch = bios_value.bell_pitch;
3438 scp->bell_duration = BELL_DURATION;
3439 scp->status |= (bios_value.shift_state & NLKED);
3440 scp->status |= CURSOR_ENABLED | MOUSE_HIDDEN;
3443 scp->smode.mode = VT_AUTO;
3444 scp->history = NULL;
3445 scp->history_pos = 0;
3446 scp->history_size = 0;
3450 sc_init_emulator(scr_stat *scp, char *name)
3457 if (name == NULL) /* if no name is given, use the current emulator */
3459 else /* ...otherwise find the named emulator */
3460 sw = sc_term_match(name);
3465 if (strcmp(sw->te_renderer, "*") != 0) {
3466 rndr = sc_render_match(scp, sw->te_renderer,
3467 scp->status & (GRAPHICS_MODE | PIXEL_MODE));
3470 rndr = sc_render_match(scp, scp->sc->adp->va_name,
3471 scp->status & (GRAPHICS_MODE | PIXEL_MODE));
3476 if (sw == scp->tsw) {
3477 error = (*sw->te_init)(scp, &scp->ts, SC_TE_WARM_INIT);
3479 scp->rndr->init(scp);
3480 sc_clear_screen(scp);
3481 /* assert(error == 0); */
3485 if (sc_malloc && (sw->te_size > 0))
3486 p = malloc(sw->te_size, M_DEVBUF, M_NOWAIT);
3489 error = (*sw->te_init)(scp, &p, SC_TE_COLD_INIT);
3494 (*scp->tsw->te_term)(scp, &scp->ts);
3495 if (scp->ts != NULL)
3496 free(scp->ts, M_DEVBUF);
3500 scp->rndr->init(scp);
3503 (*sw->te_default_attr)(scp, user_default.std_color, user_default.rev_color);
3504 sc_clear_screen(scp);
3510 * scgetc(flags) - get character from keyboard.
3511 * If flags & SCGETC_CN, then avoid harmful side effects.
3512 * If flags & SCGETC_NONBLOCK, then wait until a key is pressed, else
3513 * return NOKEY if there is nothing there.
3516 scgetc(sc_softc_t *sc, u_int flags, struct sc_cnstate *sp)
3519 #ifndef SC_NO_HISTORY
3527 if (sc->kbd == NULL)
3532 /* I don't like this, but... XXX */
3533 if (flags & SCGETC_CN)
3534 sccnupdate(sc->cur_scp);
3537 /* first see if there is something in the keyboard port */
3539 if (flags & SCGETC_CN)
3540 sccnscrunlock(sc, sp);
3541 c = kbdd_read_char(sc->kbd, !(flags & SCGETC_NONBLOCK));
3542 if (flags & SCGETC_CN)
3543 sccnscrlock(sc, sp);
3545 if (!(flags & SCGETC_CN))
3546 sc_bell(scp, bios_value.bell_pitch, BELL_DURATION);
3547 } else if (c == NOKEY)
3553 /* make screensaver happy */
3555 sc_touch_scrn_saver();
3557 if (!(flags & SCGETC_CN))
3558 random_harvest_queue(&c, sizeof(c), 1, RANDOM_KEYBOARD);
3560 if (sc->kbd_open_level == 0 && scp->kbd_mode != K_XLATE)
3563 /* if scroll-lock pressed allow history browsing */
3564 if (!ISGRAPHSC(scp) && scp->history && scp->status & SLKED) {
3566 scp->status &= ~CURSOR_ENABLED;
3567 sc_remove_cursor_image(scp);
3569 #ifndef SC_NO_HISTORY
3570 if (!(scp->status & BUFFER_SAVED)) {
3571 scp->status |= BUFFER_SAVED;
3575 /* FIXME: key codes */
3576 case SPCLKEY | FKEY | F(49): /* home key */
3577 sc_remove_cutmarking(scp);
3581 case SPCLKEY | FKEY | F(57): /* end key */
3582 sc_remove_cutmarking(scp);
3586 case SPCLKEY | FKEY | F(50): /* up arrow key */
3587 sc_remove_cutmarking(scp);
3588 if (sc_hist_up_line(scp))
3589 if (!(flags & SCGETC_CN))
3590 sc_bell(scp, bios_value.bell_pitch, BELL_DURATION);
3593 case SPCLKEY | FKEY | F(58): /* down arrow key */
3594 sc_remove_cutmarking(scp);
3595 if (sc_hist_down_line(scp))
3596 if (!(flags & SCGETC_CN))
3597 sc_bell(scp, bios_value.bell_pitch, BELL_DURATION);
3600 case SPCLKEY | FKEY | F(51): /* page up key */
3601 sc_remove_cutmarking(scp);
3602 for (i=0; i<scp->ysize; i++)
3603 if (sc_hist_up_line(scp)) {
3604 if (!(flags & SCGETC_CN))
3605 sc_bell(scp, bios_value.bell_pitch, BELL_DURATION);
3610 case SPCLKEY | FKEY | F(59): /* page down key */
3611 sc_remove_cutmarking(scp);
3612 for (i=0; i<scp->ysize; i++)
3613 if (sc_hist_down_line(scp)) {
3614 if (!(flags & SCGETC_CN))
3615 sc_bell(scp, bios_value.bell_pitch, BELL_DURATION);
3620 #endif /* SC_NO_HISTORY */
3624 * Process and consume special keys here. Return a plain char code
3625 * or a char code with the META flag or a function key code.
3629 /* goto next_code */
3634 switch (KEYCHAR(c)) {
3636 case NLK: case CLK: case ALK:
3639 (void)kbdd_ioctl(sc->kbd, KDGKBSTATE, (caddr_t)&f);
3641 scp->status |= SLKED;
3643 if (scp->status & SLKED) {
3644 scp->status &= ~SLKED;
3645 #ifndef SC_NO_HISTORY
3646 if (scp->status & BUFFER_SAVED) {
3647 if (!sc_hist_restore(scp))
3648 sc_remove_cutmarking(scp);
3649 scp->status &= ~BUFFER_SAVED;
3650 scp->status |= CURSOR_ENABLED;
3651 sc_draw_cursor_image(scp);
3653 /* Only safe in Giant-locked context. */
3654 tp = SC_DEV(sc, scp->index);
3655 if (!(flags & SCGETC_CN) && tty_opened_ns(tp))
3656 sctty_outwakeup(tp);
3663 #ifndef SC_NO_CUTPASTE
3664 sc_mouse_paste(scp);
3668 /* NON-LOCKING KEYS */
3670 case LSH: case RSH: case LCTR: case RCTR:
3671 case LALT: case RALT: case ASH: case META:
3675 if (!(sc->flags & SC_SCRN_BLANKED))
3681 /* force activatation/deactivation of the screen saver */
3682 if (!(sc->flags & SC_SCRN_BLANKED)) {
3683 run_scrn_saver = TRUE;
3684 sc->scrn_time_stamp -= scrn_blank_time;
3688 * While devices are being probed, the screen saver need
3689 * to be invoked explicitly. XXX
3691 if (sc->flags & SC_SCRN_BLANKED) {
3692 scsplash_stick(FALSE);
3693 stop_scrn_saver(sc, current_saver);
3695 if (!ISGRAPHSC(scp)) {
3696 scsplash_stick(TRUE);
3697 (*current_saver)(sc, TRUE);
3701 #endif /* DEV_SPLASH */
3705 #ifndef SC_DISABLE_REBOOT
3706 if (enable_reboot && !(flags & SCGETC_CN))
3712 #ifndef SC_DISABLE_REBOOT
3713 if (enable_reboot && !(flags & SCGETC_CN))
3714 shutdown_nice(RB_HALT);
3719 #ifndef SC_DISABLE_REBOOT
3720 if (enable_reboot && !(flags & SCGETC_CN))
3721 shutdown_nice(RB_HALT|RB_POWEROFF);
3726 power_pm_suspend(POWER_SLEEP_STATE_SUSPEND);
3729 power_pm_suspend(POWER_SLEEP_STATE_STANDBY);
3733 #ifndef SC_DISABLE_KDBKEY
3740 if (enable_panic_key)
3741 panic("Forced by the panic key");
3745 this_scr = scp->index;
3746 for (i = (this_scr - sc->first_vty + 1)%sc->vtys;
3747 sc->first_vty + i != this_scr;
3748 i = (i + 1)%sc->vtys) {
3749 struct tty *tp = SC_DEV(sc, sc->first_vty + i);
3750 if (tty_opened_ns(tp)) {
3751 sc_switch_scr(scp->sc, sc->first_vty + i);
3758 this_scr = scp->index;
3759 for (i = (this_scr - sc->first_vty + sc->vtys - 1)%sc->vtys;
3760 sc->first_vty + i != this_scr;
3761 i = (i + sc->vtys - 1)%sc->vtys) {
3762 struct tty *tp = SC_DEV(sc, sc->first_vty + i);
3763 if (tty_opened_ns(tp)) {
3764 sc_switch_scr(scp->sc, sc->first_vty + i);
3771 if (KEYCHAR(c) >= F_SCR && KEYCHAR(c) <= L_SCR) {
3772 sc_switch_scr(scp->sc, sc->first_vty + KEYCHAR(c) - F_SCR);
3775 /* assert(c & FKEY) */
3776 if (!(sc->flags & SC_SCRN_BLANKED))
3780 /* goto next_code */
3782 /* regular keys (maybe MKEY is set) */
3783 #if !defined(SC_DISABLE_KDBKEY) && defined(KDB)
3785 kdb_alt_break(c, &sc->sc_altbrk);
3787 if (!(sc->flags & SC_SCRN_BLANKED))
3796 sctty_mmap(struct tty *tp, vm_ooffset_t offset, vm_paddr_t *paddr,
3797 int nprot, vm_memattr_t *memattr)
3801 scp = sc_get_stat(tp);
3802 if (scp != scp->sc->cur_scp)
3804 return vidd_mmap(scp->sc->adp, offset, paddr, nprot, memattr);
3808 update_font(scr_stat *scp)
3810 #ifndef SC_NO_FONT_LOADING
3811 /* load appropriate font */
3812 if (!(scp->status & GRAPHICS_MODE)) {
3813 if (!(scp->status & PIXEL_MODE) && ISFONTAVAIL(scp->sc->adp->va_flags)) {
3814 if (scp->font_size < 14) {
3815 if (scp->sc->fonts_loaded & FONT_8)
3816 sc_load_font(scp, 0, 8, 8, scp->sc->font_8, 0, 256);
3817 } else if (scp->font_size >= 16) {
3818 if (scp->sc->fonts_loaded & FONT_16)
3819 sc_load_font(scp, 0, 16, 8, scp->sc->font_16, 0, 256);
3821 if (scp->sc->fonts_loaded & FONT_14)
3822 sc_load_font(scp, 0, 14, 8, scp->sc->font_14, 0, 256);
3826 * This is an interim kludge to display correct font.
3827 * Always use the font page #0 on the video plane 2.
3828 * Somehow we cannot show the font in other font pages on
3829 * some video cards... XXX
3831 sc_show_font(scp, 0);
3835 #endif /* !SC_NO_FONT_LOADING */
3839 save_kbd_state(scr_stat *scp)
3844 error = kbdd_ioctl(scp->sc->kbd, KDGKBSTATE, (caddr_t)&state);
3845 if (error == ENOIOCTL)
3848 scp->status &= ~LOCK_MASK;
3849 scp->status |= state;
3855 update_kbd_state(scr_stat *scp, int new_bits, int mask)
3860 if (mask != LOCK_MASK) {
3861 error = kbdd_ioctl(scp->sc->kbd, KDGKBSTATE, (caddr_t)&state);
3862 if (error == ENOIOCTL)
3867 state |= new_bits & mask;
3869 state = new_bits & LOCK_MASK;
3871 error = kbdd_ioctl(scp->sc->kbd, KDSKBSTATE, (caddr_t)&state);
3872 if (error == ENOIOCTL)
3878 update_kbd_leds(scr_stat *scp, int which)
3883 error = kbdd_ioctl(scp->sc->kbd, KDSETLED, (caddr_t)&which);
3884 if (error == ENOIOCTL)
3890 set_mode(scr_stat *scp)
3894 /* reject unsupported mode */
3895 if (vidd_get_info(scp->sc->adp, scp->mode, &info))
3898 /* if this vty is not currently showing, do nothing */
3899 if (scp != scp->sc->cur_scp)
3902 /* setup video hardware for the given mode */
3903 vidd_set_mode(scp->sc->adp, scp->mode);
3904 scp->rndr->init(scp);
3906 sc_vtb_init(&scp->scr, VTB_FRAMEBUFFER, scp->xsize, scp->ysize,
3907 (void *)scp->sc->adp->va_window, FALSE);
3912 sc_set_border(scp, scp->border);
3913 sc_set_cursor_image(scp);
3919 sc_set_border(scr_stat *scp, int color)
3921 SC_VIDEO_LOCK(scp->sc);
3922 (*scp->rndr->draw_border)(scp, color);
3923 SC_VIDEO_UNLOCK(scp->sc);
3926 #ifndef SC_NO_FONT_LOADING
3928 sc_load_font(scr_stat *scp, int page, int size, int width, u_char *buf,
3929 int base, int count)
3934 sc->font_loading_in_progress = TRUE;
3935 vidd_load_font(sc->adp, page, size, width, buf, base, count);
3936 sc->font_loading_in_progress = FALSE;
3940 sc_save_font(scr_stat *scp, int page, int size, int width, u_char *buf,
3941 int base, int count)
3946 sc->font_loading_in_progress = TRUE;
3947 vidd_save_font(sc->adp, page, size, width, buf, base, count);
3948 sc->font_loading_in_progress = FALSE;
3952 sc_show_font(scr_stat *scp, int page)
3954 vidd_show_font(scp->sc->adp, page);
3956 #endif /* !SC_NO_FONT_LOADING */
3959 sc_paste(scr_stat *scp, const u_char *p, int count)
3964 tp = SC_DEV(scp->sc, scp->sc->cur_scp->index);
3965 if (!tty_opened_ns(tp))
3967 rmap = scp->sc->scr_rmap;
3968 for (; count > 0; --count)
3969 ttydisc_rint(tp, rmap[*p++], 0);
3970 ttydisc_rint_done(tp);
3974 sc_respond(scr_stat *scp, const u_char *p, int count, int wakeup)
3978 tp = SC_DEV(scp->sc, scp->sc->cur_scp->index);
3979 if (!tty_opened_ns(tp))
3981 ttydisc_rint_simple(tp, p, count);
3983 /* XXX: we can't always call ttydisc_rint_done() here! */
3984 ttydisc_rint_done(tp);
3989 sc_bell(scr_stat *scp, int pitch, int duration)
3991 if (cold || kdb_active || shutdown_in_progress || !enable_bell)
3994 if (scp != scp->sc->cur_scp && (scp->sc->flags & SC_QUIET_BELL))
3997 if (scp->sc->flags & SC_VISUAL_BELL) {
3998 if (scp->sc->blink_in_progress)
4000 scp->sc->blink_in_progress = 3;
4001 if (scp != scp->sc->cur_scp)
4002 scp->sc->blink_in_progress += 2;
4003 blink_screen(scp->sc->cur_scp);
4004 } else if (duration != 0 && pitch != 0) {
4005 if (scp != scp->sc->cur_scp)
4007 sysbeep(1193182 / pitch, duration);
4012 blink_screen(void *arg)
4014 scr_stat *scp = arg;
4017 if (ISGRAPHSC(scp) || (scp->sc->blink_in_progress <= 1)) {
4018 scp->sc->blink_in_progress = 0;
4020 tp = SC_DEV(scp->sc, scp->index);
4021 if (tty_opened_ns(tp))
4022 sctty_outwakeup(tp);
4023 if (scp->sc->delayed_next_scr)
4024 sc_switch_scr(scp->sc, scp->sc->delayed_next_scr - 1);
4027 (*scp->rndr->draw)(scp, 0, scp->xsize*scp->ysize,
4028 scp->sc->blink_in_progress & 1);
4029 scp->sc->blink_in_progress--;
4030 callout_reset_sbt(&scp->sc->cblink, SBT_1S / 15, 0,
4031 blink_screen, scp, C_PREL(0));
4036 * Until sc_attach_unit() gets called no dev structures will be available
4037 * to store the per-screen current status. This is the case when the
4038 * kernel is initially booting and needs access to its console. During
4039 * this early phase of booting the console's current status is kept in
4040 * one statically defined scr_stat structure, and any pointers to the
4041 * dev structures will be NULL.
4045 sc_get_stat(struct tty *tp)
4048 return (&main_console);
4049 return (SC_STAT(tp));
4053 * Allocate active keyboard. Try to allocate "kbdmux" keyboard first, and,
4054 * if found, add all non-busy keyboards to "kbdmux". Otherwise look for
4059 sc_allocate_keyboard(sc_softc_t *sc, int unit)
4065 idx0 = kbd_allocate("kbdmux", -1, (void *)&sc->keyboard, sckbdevent, sc);
4067 k0 = kbd_get_keyboard(idx0);
4069 for (idx = kbd_find_keyboard2("*", -1, 0);
4071 idx = kbd_find_keyboard2("*", -1, idx + 1)) {
4072 k = kbd_get_keyboard(idx);
4074 if (idx == idx0 || KBD_IS_BUSY(k))
4077 bzero(&ki, sizeof(ki));
4078 strcpy(ki.kb_name, k->kb_name);
4079 ki.kb_unit = k->kb_unit;
4081 (void)kbdd_ioctl(k0, KBADDKBD, (caddr_t) &ki);
4084 idx0 = kbd_allocate("*", unit, (void *)&sc->keyboard, sckbdevent, sc);