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>
44 #include <sys/consio.h>
46 #include <sys/eventhandler.h>
49 #include <sys/kernel.h>
51 #include <sys/malloc.h>
52 #include <sys/mutex.h>
55 #include <sys/random.h>
56 #include <sys/reboot.h>
57 #include <sys/serial.h>
58 #include <sys/signalvar.h>
59 #include <sys/sysctl.h>
61 #include <sys/power.h>
63 #include <machine/clock.h>
64 #if defined(__sparc64__) || defined(__powerpc__)
65 #include <machine/sc_machdep.h>
67 #include <machine/pc/display.h>
69 #if defined( __i386__) || defined(__amd64__)
70 #include <machine/psl.h>
71 #include <machine/frame.h>
73 #include <machine/stdarg.h>
75 #include <dev/kbd/kbdreg.h>
76 #include <dev/fb/fbreg.h>
77 #include <dev/fb/splashreg.h>
78 #include <dev/syscons/syscons.h>
83 #define DEFAULT_BLANKTIME (5*60) /* 5 minutes */
84 #define MAX_BLANKTIME (7*24*60*60) /* 7 days!? */
86 #define KEYCODE_BS 0x0e /* "<-- Backspace" key, XXX */
88 typedef struct default_attr {
89 int std_color; /* normal hardware color */
90 int rev_color; /* reverse hardware color */
93 static default_attr user_default = {
98 static int sc_console_unit = -1;
99 static int sc_saver_keyb_only = 1;
100 static scr_stat *sc_console;
101 static struct consdev *sc_consptr;
102 static scr_stat main_console;
103 static struct tty *main_devs[MAXCONS];
105 static char init_done = COLD;
106 static char shutdown_in_progress = FALSE;
107 static char sc_malloc = FALSE;
109 static int saver_mode = CONS_NO_SAVER; /* LKM/user saver */
110 static int run_scrn_saver = FALSE; /* should run the saver? */
111 static int enable_bell = TRUE; /* enable beeper */
113 #ifndef SC_DISABLE_REBOOT
114 static int enable_reboot = TRUE; /* enable keyboard reboot */
117 #ifndef SC_DISABLE_KDBKEY
118 static int enable_kdbkey = TRUE; /* enable keyboard debug */
121 static long scrn_blank_time = 0; /* screen saver timeout value */
123 static int scrn_blanked; /* # of blanked screen */
124 static int sticky_splash = FALSE;
126 static void none_saver(sc_softc_t *sc, int blank) { }
127 static void (*current_saver)(sc_softc_t *, int) = none_saver;
130 SYSCTL_NODE(_hw, OID_AUTO, syscons, CTLFLAG_RD, 0, "syscons");
131 SYSCTL_NODE(_hw_syscons, OID_AUTO, saver, CTLFLAG_RD, 0, "saver");
132 SYSCTL_INT(_hw_syscons_saver, OID_AUTO, keybonly, CTLFLAG_RW,
133 &sc_saver_keyb_only, 0, "screen saver interrupted by input only");
134 SYSCTL_INT(_hw_syscons, OID_AUTO, bell, CTLFLAG_RW, &enable_bell,
136 #ifndef SC_DISABLE_REBOOT
137 SYSCTL_INT(_hw_syscons, OID_AUTO, kbd_reboot, CTLFLAG_RW|CTLFLAG_SECURE, &enable_reboot,
138 0, "enable keyboard reboot");
140 #ifndef SC_DISABLE_KDBKEY
141 SYSCTL_INT(_hw_syscons, OID_AUTO, kbd_debug, CTLFLAG_RW|CTLFLAG_SECURE, &enable_kdbkey,
142 0, "enable keyboard debug");
144 #if !defined(SC_NO_FONT_LOADING) && defined(SC_DFLT_FONT)
148 tsw_ioctl_t *sc_user_ioctl;
150 static bios_values_t bios_value;
152 static int enable_panic_key;
153 SYSCTL_INT(_machdep, OID_AUTO, enable_panic_key, CTLFLAG_RW, &enable_panic_key,
154 0, "Enable panic via keypress specified in kbdmap(5)");
156 #define SC_CONSOLECTL 255
158 #define VTY_WCHAN(sc, vty) (&SC_DEV(sc, vty))
163 static int sc_allocate_keyboard(sc_softc_t *sc, int unit);
164 static int scvidprobe(int unit, int flags, int cons);
165 static int sckbdprobe(int unit, int flags, int cons);
166 static void scmeminit(void *arg);
167 static int scdevtounit(struct tty *tp);
168 static kbd_callback_func_t sckbdevent;
169 static void scinit(int unit, int flags);
170 static scr_stat *sc_get_stat(struct tty *tp);
171 static void scterm(int unit, int flags);
172 static void scshutdown(void *arg, int howto);
173 static u_int scgetc(sc_softc_t *sc, u_int flags);
175 #define SCGETC_NONBLOCK 2
176 static void sccnupdate(scr_stat *scp);
177 static scr_stat *alloc_scp(sc_softc_t *sc, int vty);
178 static void init_scp(sc_softc_t *sc, int vty, scr_stat *scp);
179 static timeout_t scrn_timer;
180 static int and_region(int *s1, int *e1, int s2, int e2);
181 static void scrn_update(scr_stat *scp, int show_cursor);
184 static int scsplash_callback(int event, void *arg);
185 static void scsplash_saver(sc_softc_t *sc, int show);
186 static int add_scrn_saver(void (*this_saver)(sc_softc_t *, int));
187 static int remove_scrn_saver(void (*this_saver)(sc_softc_t *, int));
188 static int set_scrn_saver_mode(scr_stat *scp, int mode, u_char *pal, int border);
189 static int restore_scrn_saver_mode(scr_stat *scp, int changemode);
190 static void stop_scrn_saver(sc_softc_t *sc, void (*saver)(sc_softc_t *, int));
191 static int wait_scrn_saver_stop(sc_softc_t *sc);
192 #define scsplash_stick(stick) (sticky_splash = (stick))
193 #else /* !DEV_SPLASH */
194 #define scsplash_stick(stick)
195 #endif /* DEV_SPLASH */
197 static int do_switch_scr(sc_softc_t *sc, int s);
198 static int vt_proc_alive(scr_stat *scp);
199 static int signal_vt_rel(scr_stat *scp);
200 static int signal_vt_acq(scr_stat *scp);
201 static int finish_vt_rel(scr_stat *scp, int release, int *s);
202 static int finish_vt_acq(scr_stat *scp);
203 static void exchange_scr(sc_softc_t *sc);
204 static void update_cursor_image(scr_stat *scp);
205 static void change_cursor_shape(scr_stat *scp, int flags, int base, int height);
206 static int save_kbd_state(scr_stat *scp);
207 static int update_kbd_state(scr_stat *scp, int state, int mask);
208 static int update_kbd_leds(scr_stat *scp, int which);
209 static timeout_t blink_screen;
210 static struct tty *sc_alloc_tty(int, int);
212 static cn_probe_t sc_cnprobe;
213 static cn_init_t sc_cninit;
214 static cn_term_t sc_cnterm;
215 static cn_getc_t sc_cngetc;
216 static cn_putc_t sc_cnputc;
220 static tsw_open_t sctty_open;
221 static tsw_close_t sctty_close;
222 static tsw_outwakeup_t sctty_outwakeup;
223 static tsw_ioctl_t sctty_ioctl;
224 static tsw_mmap_t sctty_mmap;
226 static struct ttydevsw sc_ttydevsw = {
227 .tsw_open = sctty_open,
228 .tsw_close = sctty_close,
229 .tsw_outwakeup = sctty_outwakeup,
230 .tsw_ioctl = sctty_ioctl,
231 .tsw_mmap = sctty_mmap,
234 static d_ioctl_t consolectl_ioctl;
236 static struct cdevsw consolectl_devsw = {
237 .d_version = D_VERSION,
238 .d_flags = D_NEEDGIANT,
239 .d_ioctl = consolectl_ioctl,
240 .d_name = "consolectl",
244 sc_probe_unit(int unit, int flags)
246 if (!scvidprobe(unit, flags, FALSE)) {
248 printf("%s%d: no video adapter found.\n", SC_DRIVER_NAME, unit);
252 /* syscons will be attached even when there is no keyboard */
253 sckbdprobe(unit, flags, FALSE);
258 /* probe video adapters, return TRUE if found */
260 scvidprobe(int unit, int flags, int cons)
263 * Access the video adapter driver through the back door!
264 * Video adapter drivers need to be configured before syscons.
265 * However, when syscons is being probed as the low-level console,
266 * they have not been initialized yet. We force them to initialize
267 * themselves here. XXX
269 vid_configure(cons ? VIO_PROBE_ONLY : 0);
271 return (vid_find_adapter("*", unit) >= 0);
274 /* probe the keyboard, return TRUE if found */
276 sckbdprobe(int unit, int flags, int cons)
278 /* access the keyboard driver through the backdoor! */
279 kbd_configure(cons ? KB_CONF_PROBE_ONLY : 0);
281 return (kbd_find_keyboard("*", unit) >= 0);
285 *adapter_name(video_adapter_t *adp)
291 { KD_MONO, { "MDA", "MDA" } },
292 { KD_HERCULES, { "Hercules", "Hercules" } },
293 { KD_CGA, { "CGA", "CGA" } },
294 { KD_EGA, { "EGA", "EGA (mono)" } },
295 { KD_VGA, { "VGA", "VGA (mono)" } },
296 { KD_PC98, { "PC-98x1", "PC-98x1" } },
297 { KD_TGA, { "TGA", "TGA" } },
298 { -1, { "Unknown", "Unknown" } },
302 for (i = 0; names[i].type != -1; ++i)
303 if (names[i].type == adp->va_type)
305 return names[i].name[(adp->va_flags & V_ADP_COLOR) ? 0 : 1];
309 sctty_outwakeup(struct tty *tp)
313 scr_stat *scp = sc_get_stat(tp);
315 if (scp->status & SLKED ||
316 (scp == scp->sc->cur_scp && scp->sc->blink_in_progress))
320 len = ttydisc_getc(tp, buf, sizeof buf);
323 sc_puts(scp, buf, len, 0);
328 sc_alloc_tty(int index, int devnum)
330 struct sc_ttysoftc *stc;
333 /* Allocate TTY object and softc to store unit number. */
334 stc = malloc(sizeof(struct sc_ttysoftc), M_DEVBUF, M_WAITOK);
335 stc->st_index = index;
337 tp = tty_alloc_mutex(&sc_ttydevsw, stc, &Giant);
339 /* Create device node. */
340 tty_makedev(tp, NULL, "v%r", devnum);
346 sc_attach_unit(int unit, int flags)
356 flags &= ~SC_KERNEL_CONSOLE;
358 if (sc_console_unit == unit) {
360 * If this unit is being used as the system console, we need to
361 * adjust some variables and buffers before and after scinit().
363 /* assert(sc_console != NULL) */
364 flags |= SC_KERNEL_CONSOLE;
369 sc = sc_get_softc(unit, flags & SC_KERNEL_CONSOLE);
371 scp = sc_get_stat(sc->dev[0]);
372 if (sc_console == NULL) /* sc_console_unit < 0 */
376 if ((sc->config & SC_VESA800X600)
377 && (vidd_get_info(sc->adp, M_VESA_800x600, &info) == 0)) {
379 if (sc->flags & SC_SPLASH_SCRN)
380 splash_term(sc->adp);
382 sc_set_graphics_mode(scp, NULL, M_VESA_800x600);
383 sc_set_pixel_mode(scp, NULL, COL, ROW, 16, 8);
384 sc->initial_mode = M_VESA_800x600;
386 /* put up the splash again! */
387 if (sc->flags & SC_SPLASH_SCRN)
388 splash_init(sc->adp, scsplash_callback, sc);
391 #endif /* SC_PIXEL_MODE */
393 /* initialize cursor */
395 update_cursor_image(scp);
397 /* get screen update going */
400 /* set up the keyboard */
401 kbdd_ioctl(sc->kbd, KDSKBMODE, (caddr_t)&scp->kbd_mode);
402 update_kbd_state(scp, scp->status, LOCK_MASK);
404 printf("%s%d: %s <%d virtual consoles, flags=0x%x>\n",
405 SC_DRIVER_NAME, unit, adapter_name(sc->adp), sc->vtys, sc->config);
407 printf("%s%d:", SC_DRIVER_NAME, unit);
408 if (sc->adapter >= 0)
409 printf(" fb%d", sc->adapter);
410 if (sc->keyboard >= 0)
411 printf(", kbd%d", sc->keyboard);
413 printf(", terminal emulator: %s (%s)",
414 scp->tsw->te_name, scp->tsw->te_desc);
418 /* register a shutdown callback for the kernel console */
419 if (sc_console_unit == unit)
420 EVENTHANDLER_REGISTER(shutdown_pre_sync, scshutdown,
421 (void *)(uintptr_t)unit, SHUTDOWN_PRI_DEFAULT);
423 for (vc = 0; vc < sc->vtys; vc++) {
424 if (sc->dev[vc] == NULL) {
425 sc->dev[vc] = sc_alloc_tty(vc, vc + unit * MAXCONS);
426 if (vc == 0 && sc->dev == main_devs)
427 SC_STAT(sc->dev[0]) = &main_console;
430 * The first vty already has struct tty and scr_stat initialized
431 * in scinit(). The other vtys will have these structs when
436 dev = make_dev(&consolectl_devsw, 0, UID_ROOT, GID_WHEEL, 0600,
438 dev->si_drv1 = sc->dev[0];
451 * As soon as malloc() becomes functional, we had better allocate
452 * various buffers for the kernel console.
455 if (sc_console_unit < 0) /* sc_console == NULL */
458 /* copy the temporary buffer to the final buffer */
459 sc_alloc_scr_buffer(sc_console, FALSE, FALSE);
461 #ifndef SC_NO_CUTPASTE
462 sc_alloc_cut_buffer(sc_console, FALSE);
465 #ifndef SC_NO_HISTORY
466 /* initialize history buffer & pointers */
467 sc_alloc_history_buffer(sc_console, 0, 0, FALSE);
472 SYSINIT(sc_mem, SI_SUB_KMEM, SI_ORDER_ANY, scmeminit, NULL);
475 scdevtounit(struct tty *tp)
477 int vty = SC_VTY(tp);
479 if (vty == SC_CONSOLECTL)
480 return ((sc_console != NULL) ? sc_console->sc->unit : -1);
481 else if ((vty < 0) || (vty >= MAXCONS*sc_max_unit()))
488 sctty_open(struct tty *tp)
490 int unit = scdevtounit(tp);
497 DPRINTF(5, ("scopen: dev:%s, unit:%d, vty:%d\n",
498 devtoname(tp->t_dev), unit, SC_VTY(tp)));
500 sc = sc_get_softc(unit, (sc_console_unit == unit) ? SC_KERNEL_CONSOLE : 0);
504 if (!tty_opened(tp)) {
505 /* Use the current setting of the <-- key as default VERASE. */
506 /* If the Delete key is preferable, an stty is necessary */
508 if (sc->kbd != NULL) {
509 key.keynum = KEYCODE_BS;
510 kbdd_ioctl(sc->kbd, GIO_KEYMAPENT, (caddr_t)&key);
511 tp->t_termios.c_cc[VERASE] = key.key.map[0];
516 scp = sc_get_stat(tp);
518 scp = SC_STAT(tp) = alloc_scp(sc, SC_VTY(tp));
520 sc_set_pixel_mode(scp, NULL, COL, ROW, 16, 8);
522 if (!tp->t_winsize.ws_col && !tp->t_winsize.ws_row) {
523 tp->t_winsize.ws_col = scp->xsize;
524 tp->t_winsize.ws_row = scp->ysize;
531 sctty_close(struct tty *tp)
536 if (SC_VTY(tp) != SC_CONSOLECTL) {
537 scp = sc_get_stat(tp);
538 /* were we in the middle of the VT switching process? */
539 DPRINTF(5, ("sc%d: scclose(), ", scp->sc->unit));
541 if ((scp == scp->sc->cur_scp) && (scp->sc->unit == sc_console_unit))
542 cnavailable(sc_consptr, TRUE);
543 if (finish_vt_rel(scp, TRUE, &s) == 0) /* force release */
544 DPRINTF(5, ("reset WAIT_REL, "));
545 if (finish_vt_acq(scp) == 0) /* force acknowledge */
546 DPRINTF(5, ("reset WAIT_ACQ, "));
548 if (scp == &main_console) {
551 scp->smode.mode = VT_AUTO;
554 sc_vtb_destroy(&scp->vtb);
556 sc_vtb_destroy(&scp->scr);
558 sc_free_history_buffer(scp, scp->ysize);
565 scp->smode.mode = VT_AUTO;
567 scp->kbd_mode = K_XLATE;
568 if (scp == scp->sc->cur_scp)
569 kbdd_ioctl(scp->sc->kbd, KDSKBMODE, (caddr_t)&scp->kbd_mode);
570 DPRINTF(5, ("done.\n"));
574 #if 0 /* XXX mpsafetty: fix screensaver. What about outwakeup? */
576 scread(struct cdev *dev, struct uio *uio, int flag)
578 if (!sc_saver_keyb_only)
579 sc_touch_scrn_saver();
580 return ttyread(dev, uio, flag);
585 sckbdevent(keyboard_t *thiskbd, int event, void *arg)
593 sc = (sc_softc_t *)arg;
594 /* assert(thiskbd == sc->kbd) */
601 case KBDIO_UNLOADING:
604 kbd_release(thiskbd, (void *)&sc->keyboard);
612 * Loop while there is still input to get from the keyboard.
613 * I don't think this is nessesary, and it doesn't fix
614 * the Xaccel-2.1 keyboard hang, but it can't hurt. XXX
616 while ((c = scgetc(sc, SCGETC_NONBLOCK)) != NOKEY) {
618 cur_tty = SC_DEV(sc, sc->cur_scp->index);
619 if (!tty_opened(cur_tty))
622 if ((*sc->cur_scp->tsw->te_input)(sc->cur_scp, c, cur_tty))
625 switch (KEYFLAGS(c)) {
626 case 0x0000: /* normal key */
627 ttydisc_rint(cur_tty, KEYCHAR(c), 0);
629 case FKEY: /* function key, return string */
630 cp = kbdd_get_fkeystr(thiskbd, KEYCHAR(c), &len);
632 if (ttydisc_can_bypass(cur_tty)) {
633 ttydisc_rint_bypass(cur_tty, cp, len);
636 ttydisc_rint(cur_tty, *cp++, 0);
640 case MKEY: /* meta is active, prepend ESC */
641 ttydisc_rint(cur_tty, 0x1b, 0);
642 ttydisc_rint(cur_tty, KEYCHAR(c), 0);
644 case BKEY: /* backtab fixed sequence (esc [ Z) */
645 ttydisc_rint(cur_tty, 0x1b, 0);
646 ttydisc_rint(cur_tty, '[', 0);
647 ttydisc_rint(cur_tty, 'Z', 0);
651 ttydisc_rint_done(cur_tty);
654 sc->cur_scp->status |= MOUSE_HIDDEN;
662 sctty_ioctl(struct tty *tp, u_long cmd, caddr_t data, struct thread *td)
669 #if defined(COMPAT_FREEBSD6) || defined(COMPAT_FREEBSD5) || \
670 defined(COMPAT_FREEBSD4) || defined(COMPAT_43)
674 /* If there is a user_ioctl function call that first */
676 error = (*sc_user_ioctl)(tp, cmd, data, td);
677 if (error != ENOIOCTL)
681 error = sc_vid_ioctl(tp, cmd, data, td);
682 if (error != ENOIOCTL)
685 #ifndef SC_NO_HISTORY
686 error = sc_hist_ioctl(tp, cmd, data, td);
687 if (error != ENOIOCTL)
691 #ifndef SC_NO_SYSMOUSE
692 error = sc_mouse_ioctl(tp, cmd, data, td);
693 if (error != ENOIOCTL)
697 scp = sc_get_stat(tp);
698 /* assert(scp != NULL) */
699 /* scp is sc_console, if SC_VTY(dev) == SC_CONSOLECTL. */
703 error = (*scp->tsw->te_ioctl)(scp, tp, cmd, data, td);
704 if (error != ENOIOCTL)
708 switch (cmd) { /* process console hardware related ioctl's */
710 case GIO_ATTR: /* get current attributes */
711 /* this ioctl is not processed here, but in the terminal emulator */
714 case GIO_COLOR: /* is this a color console ? */
715 *(int *)data = (sc->adp->va_flags & V_ADP_COLOR) ? 1 : 0;
718 case CONS_BLANKTIME: /* set screen saver timeout (0 = no saver) */
719 if (*(int *)data < 0 || *(int *)data > MAX_BLANKTIME)
722 scrn_blank_time = *(int *)data;
723 run_scrn_saver = (scrn_blank_time != 0);
727 case CONS_CURSORTYPE: /* set cursor type (obsolete) */
729 *(int *)data &= CONS_CURSOR_ATTRS;
730 sc_change_cursor_shape(scp, *(int *)data, -1, -1);
734 case CONS_GETCURSORSHAPE: /* get cursor shape (new interface) */
735 if (((int *)data)[0] & CONS_LOCAL_CURSOR) {
736 ((int *)data)[0] = scp->curr_curs_attr.flags;
737 ((int *)data)[1] = scp->curr_curs_attr.base;
738 ((int *)data)[2] = scp->curr_curs_attr.height;
740 ((int *)data)[0] = sc->curs_attr.flags;
741 ((int *)data)[1] = sc->curs_attr.base;
742 ((int *)data)[2] = sc->curs_attr.height;
746 case CONS_SETCURSORSHAPE: /* set cursor shape (new interface) */
748 sc_change_cursor_shape(scp, ((int *)data)[0],
749 ((int *)data)[1], ((int *)data)[2]);
753 case CONS_BELLTYPE: /* set bell type sound/visual */
754 if ((*(int *)data) & CONS_VISUAL_BELL)
755 sc->flags |= SC_VISUAL_BELL;
757 sc->flags &= ~SC_VISUAL_BELL;
758 if ((*(int *)data) & CONS_QUIET_BELL)
759 sc->flags |= SC_QUIET_BELL;
761 sc->flags &= ~SC_QUIET_BELL;
764 case CONS_GETINFO: /* get current (virtual) console info */
766 vid_info_t *ptr = (vid_info_t*)data;
767 if (ptr->size == sizeof(struct vid_info)) {
768 ptr->m_num = sc->cur_scp->index;
769 ptr->font_size = scp->font_size;
770 ptr->mv_col = scp->xpos;
771 ptr->mv_row = scp->ypos;
772 ptr->mv_csz = scp->xsize;
773 ptr->mv_rsz = scp->ysize;
774 ptr->mv_hsz = (scp->history != NULL) ? scp->history->vtb_rows : 0;
776 * The following fields are filled by the terminal emulator. XXX
783 ptr->mv_grfc.fore = 0; /* not supported */
784 ptr->mv_grfc.back = 0; /* not supported */
785 ptr->mv_ovscan = scp->border;
786 if (scp == sc->cur_scp)
788 ptr->mk_keylock = scp->status & LOCK_MASK;
794 case CONS_GETVERS: /* get version number */
795 *(int*)data = 0x200; /* version 2.0 */
798 case CONS_IDLE: /* see if the screen has been idle */
800 * When the screen is in the GRAPHICS_MODE or UNKNOWN_MODE,
801 * the user process may have been writing something on the
802 * screen and syscons is not aware of it. Declare the screen
803 * is NOT idle if it is in one of these modes. But there is
804 * an exception to it; if a screen saver is running in the
805 * graphics mode in the current screen, we should say that the
806 * screen has been idle.
808 *(int *)data = (sc->flags & SC_SCRN_IDLE)
809 && (!ISGRAPHSC(sc->cur_scp)
810 || (sc->cur_scp->status & SAVER_RUNNING));
813 case CONS_SAVERMODE: /* set saver mode */
814 switch(*(int *)data) {
817 /* if a LKM screen saver is running, stop it first. */
818 scsplash_stick(FALSE);
819 saver_mode = *(int *)data;
822 if ((error = wait_scrn_saver_stop(NULL))) {
827 run_scrn_saver = TRUE;
828 if (saver_mode == CONS_USR_SAVER)
829 scp->status |= SAVER_RUNNING;
831 scp->status &= ~SAVER_RUNNING;
832 scsplash_stick(TRUE);
837 if ((saver_mode == CONS_USR_SAVER) && (scp->status & SAVER_RUNNING))
838 scp->status &= ~SAVER_RUNNING;
839 saver_mode = *(int *)data;
847 case CONS_SAVERSTART: /* immediately start/stop the screen saver */
849 * Note that this ioctl does not guarantee the screen saver
850 * actually starts or stops. It merely attempts to do so...
853 run_scrn_saver = (*(int *)data != 0);
855 sc->scrn_time_stamp -= scrn_blank_time;
859 case CONS_SCRSHOT: /* get a screen shot */
861 int retval, hist_rsz;
863 vm_offset_t frbp, hstp;
865 scrshot_t *ptr = (scrshot_t *)data;
866 void *outp = ptr->buf;
868 if (ptr->x < 0 || ptr->y < 0 || ptr->xsize < 0 || ptr->ysize < 0)
871 if (ISGRAPHSC(scp)) {
875 hist_rsz = (scp->history != NULL) ? scp->history->vtb_rows : 0;
876 if (((u_int)ptr->x + ptr->xsize) > scp->xsize ||
877 ((u_int)ptr->y + ptr->ysize) > (scp->ysize + hist_rsz)) {
882 lsize = scp->xsize * sizeof(u_int16_t);
883 csize = ptr->xsize * sizeof(u_int16_t);
884 /* Pointer to the last line of framebuffer */
885 frbp = scp->vtb.vtb_buffer + scp->ysize * lsize + ptr->x *
887 /* Pointer to the last line of target buffer */
888 outp = (char *)outp + ptr->ysize * csize;
889 /* Pointer to the last line of history buffer */
890 if (scp->history != NULL)
891 hstp = scp->history->vtb_buffer + sc_vtb_tail(scp->history) *
892 sizeof(u_int16_t) + ptr->x * sizeof(u_int16_t);
897 for (lnum = 0; lnum < (ptr->y + ptr->ysize); lnum++) {
898 if (lnum < scp->ysize) {
902 if (hstp < scp->history->vtb_buffer)
903 hstp += scp->history->vtb_rows * lsize;
908 outp = (char *)outp - csize;
909 retval = copyout((void *)frbp, outp, csize);
917 case VT_SETMODE: /* set screen switcher mode */
919 struct vt_mode *mode;
922 mode = (struct vt_mode *)data;
923 DPRINTF(5, ("%s%d: VT_SETMODE ", SC_DRIVER_NAME, sc->unit));
924 if (scp->smode.mode == VT_PROCESS) {
925 p1 = pfind(scp->pid);
926 if (scp->proc == p1 && scp->proc != td->td_proc) {
929 DPRINTF(5, ("error EPERM\n"));
936 if (mode->mode == VT_AUTO) {
937 scp->smode.mode = VT_AUTO;
940 DPRINTF(5, ("VT_AUTO, "));
941 if ((scp == sc->cur_scp) && (sc->unit == sc_console_unit))
942 cnavailable(sc_consptr, TRUE);
943 /* were we in the middle of the vty switching process? */
944 if (finish_vt_rel(scp, TRUE, &s) == 0)
945 DPRINTF(5, ("reset WAIT_REL, "));
946 if (finish_vt_acq(scp) == 0)
947 DPRINTF(5, ("reset WAIT_ACQ, "));
949 if (!ISSIGVALID(mode->relsig) || !ISSIGVALID(mode->acqsig)
950 || !ISSIGVALID(mode->frsig)) {
952 DPRINTF(5, ("error EINVAL\n"));
955 DPRINTF(5, ("VT_PROCESS %d, ", td->td_proc->p_pid));
956 bcopy(data, &scp->smode, sizeof(struct vt_mode));
957 scp->proc = td->td_proc;
958 scp->pid = scp->proc->p_pid;
959 if ((scp == sc->cur_scp) && (sc->unit == sc_console_unit))
960 cnavailable(sc_consptr, FALSE);
967 case VT_GETMODE: /* get screen switcher mode */
968 bcopy(&scp->smode, data, sizeof(struct vt_mode));
971 #if defined(COMPAT_FREEBSD6) || defined(COMPAT_FREEBSD5) || \
972 defined(COMPAT_FREEBSD4) || defined(COMPAT_43)
974 ival = IOCPARM_IVAL(data);
975 data = (caddr_t)&ival;
978 case VT_RELDISP: /* screen switcher ioctl */
981 * This must be the current vty which is in the VT_PROCESS
984 if ((scp != sc->cur_scp) || (scp->smode.mode != VT_PROCESS)) {
988 /* ...and this process is controlling it. */
989 if (scp->proc != td->td_proc) {
994 switch(*(int *)data) {
995 case VT_FALSE: /* user refuses to release screen, abort */
996 if ((error = finish_vt_rel(scp, FALSE, &s)) == 0)
997 DPRINTF(5, ("%s%d: VT_FALSE\n", SC_DRIVER_NAME, sc->unit));
999 case VT_TRUE: /* user has released screen, go on */
1000 if ((error = finish_vt_rel(scp, TRUE, &s)) == 0)
1001 DPRINTF(5, ("%s%d: VT_TRUE\n", SC_DRIVER_NAME, sc->unit));
1003 case VT_ACKACQ: /* acquire acknowledged, switch completed */
1004 if ((error = finish_vt_acq(scp)) == 0)
1005 DPRINTF(5, ("%s%d: VT_ACKACQ\n", SC_DRIVER_NAME, sc->unit));
1013 case VT_OPENQRY: /* return free virtual console */
1014 for (i = sc->first_vty; i < sc->first_vty + sc->vtys; i++) {
1016 if (!tty_opened(tp)) {
1017 *(int *)data = i + 1;
1023 #if defined(COMPAT_FREEBSD6) || defined(COMPAT_FREEBSD5) || \
1024 defined(COMPAT_FREEBSD4) || defined(COMPAT_43)
1026 ival = IOCPARM_IVAL(data);
1027 data = (caddr_t)&ival;
1030 case VT_ACTIVATE: /* switch to screen *data */
1031 i = (*(int *)data == 0) ? scp->index : (*(int *)data - 1);
1033 error = sc_clean_up(sc->cur_scp);
1037 error = sc_switch_scr(sc, i);
1040 #if defined(COMPAT_FREEBSD6) || defined(COMPAT_FREEBSD5) || \
1041 defined(COMPAT_FREEBSD4) || defined(COMPAT_43)
1043 ival = IOCPARM_IVAL(data);
1044 data = (caddr_t)&ival;
1047 case VT_WAITACTIVE: /* wait for switch to occur */
1048 i = (*(int *)data == 0) ? scp->index : (*(int *)data - 1);
1049 if ((i < sc->first_vty) || (i >= sc->first_vty + sc->vtys))
1051 if (i == sc->cur_scp->index)
1053 error = tsleep(VTY_WCHAN(sc, i), (PZERO + 1) | PCATCH, "waitvt", 0);
1056 case VT_GETACTIVE: /* get active vty # */
1057 *(int *)data = sc->cur_scp->index + 1;
1060 case VT_GETINDEX: /* get this vty # */
1061 *(int *)data = scp->index + 1;
1064 case VT_LOCKSWITCH: /* prevent vty switching */
1065 if ((*(int *)data) & 0x01)
1066 sc->flags |= SC_SCRN_VTYLOCK;
1068 sc->flags &= ~SC_SCRN_VTYLOCK;
1071 case KDENABIO: /* allow io operations */
1072 error = priv_check(td, PRIV_IO);
1075 error = securelevel_gt(td->td_ucred, 0);
1079 td->td_frame->tf_eflags |= PSL_IOPL;
1080 #elif defined(__amd64__)
1081 td->td_frame->tf_rflags |= PSL_IOPL;
1085 case KDDISABIO: /* disallow io operations (default) */
1087 td->td_frame->tf_eflags &= ~PSL_IOPL;
1088 #elif defined(__amd64__)
1089 td->td_frame->tf_rflags &= ~PSL_IOPL;
1093 #if defined(COMPAT_FREEBSD6) || defined(COMPAT_FREEBSD5) || \
1094 defined(COMPAT_FREEBSD4) || defined(COMPAT_43)
1096 ival = IOCPARM_IVAL(data);
1097 data = (caddr_t)&ival;
1100 case KDSKBSTATE: /* set keyboard state (locks) */
1101 if (*(int *)data & ~LOCK_MASK)
1103 scp->status &= ~LOCK_MASK;
1104 scp->status |= *(int *)data;
1105 if (scp == sc->cur_scp)
1106 update_kbd_state(scp, scp->status, LOCK_MASK);
1109 case KDGKBSTATE: /* get keyboard state (locks) */
1110 if (scp == sc->cur_scp)
1111 save_kbd_state(scp);
1112 *(int *)data = scp->status & LOCK_MASK;
1115 case KDGETREPEAT: /* get keyboard repeat & delay rates */
1116 case KDSETREPEAT: /* set keyboard repeat & delay rates (new) */
1117 error = kbdd_ioctl(sc->kbd, cmd, data);
1118 if (error == ENOIOCTL)
1122 #if defined(COMPAT_FREEBSD6) || defined(COMPAT_FREEBSD5) || \
1123 defined(COMPAT_FREEBSD4) || defined(COMPAT_43)
1125 ival = IOCPARM_IVAL(data);
1126 data = (caddr_t)&ival;
1129 case KDSETRAD: /* set keyboard repeat & delay rates (old) */
1130 if (*(int *)data & ~0x7f)
1132 error = kbdd_ioctl(sc->kbd, KDSETRAD, data);
1133 if (error == ENOIOCTL)
1137 #if defined(COMPAT_FREEBSD6) || defined(COMPAT_FREEBSD5) || \
1138 defined(COMPAT_FREEBSD4) || defined(COMPAT_43)
1140 ival = IOCPARM_IVAL(data);
1141 data = (caddr_t)&ival;
1144 case KDSKBMODE: /* set keyboard mode */
1145 switch (*(int *)data) {
1146 case K_XLATE: /* switch to XLT ascii mode */
1147 case K_RAW: /* switch to RAW scancode mode */
1148 case K_CODE: /* switch to CODE mode */
1149 scp->kbd_mode = *(int *)data;
1150 if (scp == sc->cur_scp)
1151 kbdd_ioctl(sc->kbd, KDSKBMODE, data);
1158 case KDGKBMODE: /* get keyboard mode */
1159 *(int *)data = scp->kbd_mode;
1163 error = kbdd_ioctl(sc->kbd, cmd, data);
1164 if (error == ENOIOCTL)
1168 #if defined(COMPAT_FREEBSD6) || defined(COMPAT_FREEBSD5) || \
1169 defined(COMPAT_FREEBSD4) || defined(COMPAT_43)
1171 ival = IOCPARM_IVAL(data);
1172 data = (caddr_t)&ival;
1175 case KDMKTONE: /* sound the bell */
1177 sc_bell(scp, (*(int*)data)&0xffff,
1178 (((*(int*)data)>>16)&0xffff)*hz/1000);
1180 sc_bell(scp, scp->bell_pitch, scp->bell_duration);
1183 #if defined(COMPAT_FREEBSD6) || defined(COMPAT_FREEBSD5) || \
1184 defined(COMPAT_FREEBSD4) || defined(COMPAT_43)
1186 ival = IOCPARM_IVAL(data);
1187 data = (caddr_t)&ival;
1190 case KIOCSOUND: /* make tone (*data) hz */
1191 if (scp == sc->cur_scp) {
1193 return sc_tone(*(int *)data);
1199 case KDGKBTYPE: /* get keyboard type */
1200 error = kbdd_ioctl(sc->kbd, cmd, data);
1201 if (error == ENOIOCTL) {
1202 /* always return something? XXX */
1207 #if defined(COMPAT_FREEBSD6) || defined(COMPAT_FREEBSD5) || \
1208 defined(COMPAT_FREEBSD4) || defined(COMPAT_43)
1210 ival = IOCPARM_IVAL(data);
1211 data = (caddr_t)&ival;
1214 case KDSETLED: /* set keyboard LED status */
1215 if (*(int *)data & ~LED_MASK) /* FIXME: LOCK_MASK? */
1217 scp->status &= ~LED_MASK;
1218 scp->status |= *(int *)data;
1219 if (scp == sc->cur_scp)
1220 update_kbd_leds(scp, scp->status);
1223 case KDGETLED: /* get keyboard LED status */
1224 if (scp == sc->cur_scp)
1225 save_kbd_state(scp);
1226 *(int *)data = scp->status & LED_MASK;
1229 case KBADDKBD: /* add/remove keyboard to/from mux */
1231 error = kbdd_ioctl(sc->kbd, cmd, data);
1232 if (error == ENOIOCTL)
1236 #if defined(COMPAT_FREEBSD6) || defined(COMPAT_FREEBSD5) || \
1237 defined(COMPAT_FREEBSD4) || defined(COMPAT_43)
1239 ival = IOCPARM_IVAL(data);
1240 data = (caddr_t)&ival;
1243 case CONS_SETKBD: /* set the new keyboard */
1248 newkbd = kbd_get_keyboard(*(int *)data);
1249 if (newkbd == NULL) {
1254 if (sc->kbd != newkbd) {
1255 i = kbd_allocate(newkbd->kb_name, newkbd->kb_unit,
1256 (void *)&sc->keyboard, sckbdevent, sc);
1257 /* i == newkbd->kb_index */
1259 if (sc->kbd != NULL) {
1260 save_kbd_state(sc->cur_scp);
1261 kbd_release(sc->kbd, (void *)&sc->keyboard);
1263 sc->kbd = kbd_get_keyboard(i); /* sc->kbd == newkbd */
1265 kbdd_ioctl(sc->kbd, KDSKBMODE,
1266 (caddr_t)&sc->cur_scp->kbd_mode);
1267 update_kbd_state(sc->cur_scp, sc->cur_scp->status,
1270 error = EPERM; /* XXX */
1277 case CONS_RELKBD: /* release the current keyboard */
1280 if (sc->kbd != NULL) {
1281 save_kbd_state(sc->cur_scp);
1282 error = kbd_release(sc->kbd, (void *)&sc->keyboard);
1291 case CONS_GETTERM: /* get the current terminal emulator info */
1295 if (((term_info_t *)data)->ti_index == 0) {
1298 sw = sc_term_match_by_number(((term_info_t *)data)->ti_index);
1301 strncpy(((term_info_t *)data)->ti_name, sw->te_name,
1302 sizeof(((term_info_t *)data)->ti_name));
1303 strncpy(((term_info_t *)data)->ti_desc, sw->te_desc,
1304 sizeof(((term_info_t *)data)->ti_desc));
1305 ((term_info_t *)data)->ti_flags = 0;
1308 ((term_info_t *)data)->ti_name[0] = '\0';
1309 ((term_info_t *)data)->ti_desc[0] = '\0';
1310 ((term_info_t *)data)->ti_flags = 0;
1315 case CONS_SETTERM: /* set the current terminal emulator */
1317 error = sc_init_emulator(scp, ((term_info_t *)data)->ti_name);
1318 /* FIXME: what if scp == sc_console! XXX */
1322 case GIO_SCRNMAP: /* get output translation table */
1323 bcopy(&sc->scr_map, data, sizeof(sc->scr_map));
1326 case PIO_SCRNMAP: /* set output translation table */
1327 bcopy(data, &sc->scr_map, sizeof(sc->scr_map));
1328 for (i=0; i<sizeof(sc->scr_map); i++) {
1329 sc->scr_rmap[sc->scr_map[i]] = i;
1333 case GIO_KEYMAP: /* get keyboard translation table */
1334 case PIO_KEYMAP: /* set keyboard translation table */
1335 case GIO_DEADKEYMAP: /* get accent key translation table */
1336 case PIO_DEADKEYMAP: /* set accent key translation table */
1337 case GETFKEY: /* get function key string */
1338 case SETFKEY: /* set function key string */
1339 error = kbdd_ioctl(sc->kbd, cmd, data);
1340 if (error == ENOIOCTL)
1344 #ifndef SC_NO_FONT_LOADING
1346 case PIO_FONT8x8: /* set 8x8 dot font */
1347 if (!ISFONTAVAIL(sc->adp->va_flags))
1349 bcopy(data, sc->font_8, 8*256);
1350 sc->fonts_loaded |= FONT_8;
1353 * Always use the font page #0. XXX
1354 * Don't load if the current font size is not 8x8.
1356 if (ISTEXTSC(sc->cur_scp) && (sc->cur_scp->font_size < 14))
1357 sc_load_font(sc->cur_scp, 0, 8, 8, sc->font_8, 0, 256);
1360 case GIO_FONT8x8: /* get 8x8 dot font */
1361 if (!ISFONTAVAIL(sc->adp->va_flags))
1363 if (sc->fonts_loaded & FONT_8) {
1364 bcopy(sc->font_8, data, 8*256);
1370 case PIO_FONT8x14: /* set 8x14 dot font */
1371 if (!ISFONTAVAIL(sc->adp->va_flags))
1373 bcopy(data, sc->font_14, 14*256);
1374 sc->fonts_loaded |= FONT_14;
1377 * Always use the font page #0. XXX
1378 * Don't load if the current font size is not 8x14.
1380 if (ISTEXTSC(sc->cur_scp)
1381 && (sc->cur_scp->font_size >= 14)
1382 && (sc->cur_scp->font_size < 16))
1383 sc_load_font(sc->cur_scp, 0, 14, 8, sc->font_14, 0, 256);
1386 case GIO_FONT8x14: /* get 8x14 dot font */
1387 if (!ISFONTAVAIL(sc->adp->va_flags))
1389 if (sc->fonts_loaded & FONT_14) {
1390 bcopy(sc->font_14, data, 14*256);
1396 case PIO_FONT8x16: /* set 8x16 dot font */
1397 if (!ISFONTAVAIL(sc->adp->va_flags))
1399 bcopy(data, sc->font_16, 16*256);
1400 sc->fonts_loaded |= FONT_16;
1403 * Always use the font page #0. XXX
1404 * Don't load if the current font size is not 8x16.
1406 if (ISTEXTSC(sc->cur_scp) && (sc->cur_scp->font_size >= 16))
1407 sc_load_font(sc->cur_scp, 0, 16, 8, sc->font_16, 0, 256);
1410 case GIO_FONT8x16: /* get 8x16 dot font */
1411 if (!ISFONTAVAIL(sc->adp->va_flags))
1413 if (sc->fonts_loaded & FONT_16) {
1414 bcopy(sc->font_16, data, 16*256);
1420 #endif /* SC_NO_FONT_LOADING */
1430 consolectl_ioctl(struct cdev *dev, u_long cmd, caddr_t data, int fflag,
1434 return sctty_ioctl(dev->si_drv1, cmd, data, td);
1438 sc_cnprobe(struct consdev *cp)
1443 cp->cn_pri = sc_get_cons_priority(&unit, &flags);
1445 /* a video card is always required */
1446 if (!scvidprobe(unit, flags, TRUE))
1447 cp->cn_pri = CN_DEAD;
1449 /* syscons will become console even when there is no keyboard */
1450 sckbdprobe(unit, flags, TRUE);
1452 if (cp->cn_pri == CN_DEAD)
1455 /* initialize required fields */
1456 strcpy(cp->cn_name, "ttyv0");
1460 sc_cninit(struct consdev *cp)
1465 sc_get_cons_priority(&unit, &flags);
1466 scinit(unit, flags | SC_KERNEL_CONSOLE);
1467 sc_console_unit = unit;
1468 sc_console = sc_get_stat(sc_get_softc(unit, SC_KERNEL_CONSOLE)->dev[0]);
1473 sc_cnterm(struct consdev *cp)
1475 /* we are not the kernel console any more, release everything */
1477 if (sc_console_unit < 0)
1478 return; /* shouldn't happen */
1481 sc_clear_screen(sc_console);
1482 sccnupdate(sc_console);
1485 scterm(sc_console_unit, SC_KERNEL_CONSOLE);
1486 sc_console_unit = -1;
1491 sc_cnputc(struct consdev *cd, int c)
1494 scr_stat *scp = sc_console;
1495 #ifndef SC_NO_HISTORY
1499 #endif /* !SC_NO_HISTORY */
1502 /* assert(sc_console != NULL) */
1504 #ifndef SC_NO_HISTORY
1505 if (scp == scp->sc->cur_scp && scp->status & SLKED) {
1506 scp->status &= ~SLKED;
1507 update_kbd_state(scp, scp->status, SLKED);
1508 if (scp->status & BUFFER_SAVED) {
1509 if (!sc_hist_restore(scp))
1510 sc_remove_cutmarking(scp);
1511 scp->status &= ~BUFFER_SAVED;
1512 scp->status |= CURSOR_ENABLED;
1513 sc_draw_cursor_image(scp);
1517 * XXX: Now that TTY's have their own locks, we cannot process
1518 * any data after disabling scroll lock. cnputs already holds a
1521 tp = SC_DEV(scp->sc, scp->index);
1524 sctty_outwakeup(tp);
1528 #endif /* !SC_NO_HISTORY */
1531 sc_puts(scp, buf, 1, 1);
1533 s = spltty(); /* block sckbdevent and scrn_timer */
1539 sc_cngetc(struct consdev *cd)
1541 static struct fkeytab fkey;
1546 int s = spltty(); /* block sckbdevent and scrn_timer while we poll */
1549 /* assert(sc_console != NULL) */
1552 * Stop the screen saver and update the screen if necessary.
1553 * What if we have been running in the screen saver code... XXX
1555 sc_touch_scrn_saver();
1556 scp = sc_console->sc->cur_scp; /* XXX */
1559 if (fkeycp < fkey.len) {
1561 return fkey.str[fkeycp++];
1564 if (scp->sc->kbd == NULL) {
1570 * Make sure the keyboard is accessible even when the kbd device
1571 * driver is disabled.
1573 kbdd_enable(scp->sc->kbd);
1575 /* we shall always use the keyboard in the XLATE mode here */
1576 cur_mode = scp->kbd_mode;
1577 scp->kbd_mode = K_XLATE;
1578 kbdd_ioctl(scp->sc->kbd, KDSKBMODE, (caddr_t)&scp->kbd_mode);
1580 kbdd_poll(scp->sc->kbd, TRUE);
1581 c = scgetc(scp->sc, SCGETC_CN | SCGETC_NONBLOCK);
1582 kbdd_poll(scp->sc->kbd, FALSE);
1584 scp->kbd_mode = cur_mode;
1585 kbdd_ioctl(scp->sc->kbd, KDSKBMODE, (caddr_t)&scp->kbd_mode);
1586 kbdd_disable(scp->sc->kbd);
1589 switch (KEYFLAGS(c)) {
1590 case 0: /* normal char */
1592 case FKEY: /* function key */
1593 p = kbdd_get_fkeystr(scp->sc->kbd, KEYCHAR(c), (size_t *)&fkeycp);
1595 if ((p != NULL) && (fkey.len > 0)) {
1596 bcopy(p, fkey.str, fkey.len);
1610 sccnupdate(scr_stat *scp)
1612 /* this is a cut-down version of scrn_timer()... */
1614 if (scp->sc->font_loading_in_progress)
1617 if (debugger > 0 || panicstr || shutdown_in_progress) {
1618 sc_touch_scrn_saver();
1619 } else if (scp != scp->sc->cur_scp) {
1623 if (!run_scrn_saver)
1624 scp->sc->flags &= ~SC_SCRN_IDLE;
1626 if ((saver_mode != CONS_LKM_SAVER) || !(scp->sc->flags & SC_SCRN_IDLE))
1627 if (scp->sc->flags & SC_SCRN_BLANKED)
1628 stop_scrn_saver(scp->sc, current_saver);
1631 if (scp != scp->sc->cur_scp || scp->sc->blink_in_progress
1632 || scp->sc->switch_in_progress)
1635 * FIXME: unlike scrn_timer(), we call scrn_update() from here even
1636 * when write_in_progress is non-zero. XXX
1639 if (!ISGRAPHSC(scp) && !(scp->sc->flags & SC_SCRN_BLANKED))
1640 scrn_update(scp, TRUE);
1644 scrn_timer(void *arg)
1647 static int kbd_interval = 0;
1655 again = (arg != NULL);
1657 sc = (sc_softc_t *)arg;
1658 else if (sc_console != NULL)
1659 sc = sc_console->sc;
1663 /* don't do anything when we are performing some I/O operations */
1664 if (sc->font_loading_in_progress) {
1666 timeout(scrn_timer, sc, hz / 10);
1672 if ((sc->kbd == NULL) && (sc->config & SC_AUTODETECT_KBD)) {
1673 /* try to allocate a keyboard automatically */
1674 if (++kbd_interval >= 25) {
1675 sc->keyboard = sc_allocate_keyboard(sc, -1);
1676 if (sc->keyboard >= 0) {
1677 sc->kbd = kbd_get_keyboard(sc->keyboard);
1678 kbdd_ioctl(sc->kbd, KDSKBMODE,
1679 (caddr_t)&sc->cur_scp->kbd_mode);
1680 update_kbd_state(sc->cur_scp, sc->cur_scp->status,
1688 /* find the vty to update */
1691 /* should we stop the screen saver? */
1692 getmicrouptime(&tv);
1693 if (debugger > 0 || panicstr || shutdown_in_progress)
1694 sc_touch_scrn_saver();
1695 if (run_scrn_saver) {
1696 if (tv.tv_sec > sc->scrn_time_stamp + scrn_blank_time)
1697 sc->flags |= SC_SCRN_IDLE;
1699 sc->flags &= ~SC_SCRN_IDLE;
1701 sc->scrn_time_stamp = tv.tv_sec;
1702 sc->flags &= ~SC_SCRN_IDLE;
1703 if (scrn_blank_time > 0)
1704 run_scrn_saver = TRUE;
1707 if ((saver_mode != CONS_LKM_SAVER) || !(sc->flags & SC_SCRN_IDLE))
1708 if (sc->flags & SC_SCRN_BLANKED)
1709 stop_scrn_saver(sc, current_saver);
1712 /* should we just return ? */
1713 if (sc->blink_in_progress || sc->switch_in_progress
1714 || sc->write_in_progress) {
1716 timeout(scrn_timer, sc, hz / 10);
1721 /* Update the screen */
1722 scp = sc->cur_scp; /* cur_scp may have changed... */
1723 if (!ISGRAPHSC(scp) && !(sc->flags & SC_SCRN_BLANKED))
1724 scrn_update(scp, TRUE);
1727 /* should we activate the screen saver? */
1728 if ((saver_mode == CONS_LKM_SAVER) && (sc->flags & SC_SCRN_IDLE))
1729 if (!ISGRAPHSC(scp) || (sc->flags & SC_SCRN_BLANKED))
1730 (*current_saver)(sc, TRUE);
1734 timeout(scrn_timer, sc, hz / 25);
1739 and_region(int *s1, int *e1, int s2, int e2)
1741 if (*e1 < s2 || e2 < *s1)
1743 *s1 = imax(*s1, s2);
1744 *e1 = imin(*e1, e2);
1749 scrn_update(scr_stat *scp, int show_cursor)
1756 /* assert(scp == scp->sc->cur_scp) */
1758 SC_VIDEO_LOCK(scp->sc);
1760 #ifndef SC_NO_CUTPASTE
1761 /* remove the previous mouse pointer image if necessary */
1762 if (scp->status & MOUSE_VISIBLE) {
1764 e = scp->mouse_pos + scp->xsize + 1;
1765 if ((scp->status & (MOUSE_MOVED | MOUSE_HIDDEN))
1766 || and_region(&s, &e, scp->start, scp->end)
1767 || ((scp->status & CURSOR_ENABLED) &&
1768 (scp->cursor_pos != scp->cursor_oldpos) &&
1769 (and_region(&s, &e, scp->cursor_pos, scp->cursor_pos)
1770 || and_region(&s, &e, scp->cursor_oldpos, scp->cursor_oldpos)))) {
1771 sc_remove_mouse_image(scp);
1772 if (scp->end >= scp->xsize*scp->ysize)
1773 scp->end = scp->xsize*scp->ysize - 1;
1776 #endif /* !SC_NO_CUTPASTE */
1780 if (scp->end >= scp->xsize*scp->ysize) {
1781 printf("scrn_update(): scp->end %d > size_of_screen!!\n", scp->end);
1782 scp->end = scp->xsize*scp->ysize - 1;
1784 if (scp->start < 0) {
1785 printf("scrn_update(): scp->start %d < 0\n", scp->start);
1790 /* update screen image */
1791 if (scp->start <= scp->end) {
1792 if (scp->mouse_cut_end >= 0) {
1793 /* there is a marked region for cut & paste */
1794 if (scp->mouse_cut_start <= scp->mouse_cut_end) {
1795 start = scp->mouse_cut_start;
1796 end = scp->mouse_cut_end;
1798 start = scp->mouse_cut_end;
1799 end = scp->mouse_cut_start - 1;
1803 /* does the cut-mark region overlap with the update region? */
1804 if (and_region(&s, &e, scp->start, scp->end)) {
1805 (*scp->rndr->draw)(scp, s, e - s + 1, TRUE);
1808 if (and_region(&s, &e, scp->start, scp->end))
1809 (*scp->rndr->draw)(scp, s, e - s + 1, FALSE);
1811 e = scp->xsize*scp->ysize - 1;
1812 if (and_region(&s, &e, scp->start, scp->end))
1813 (*scp->rndr->draw)(scp, s, e - s + 1, FALSE);
1815 (*scp->rndr->draw)(scp, scp->start,
1816 scp->end - scp->start + 1, FALSE);
1819 (*scp->rndr->draw)(scp, scp->start,
1820 scp->end - scp->start + 1, FALSE);
1824 /* we are not to show the cursor and the mouse pointer... */
1827 scp->start = scp->xsize*scp->ysize - 1;
1828 SC_VIDEO_UNLOCK(scp->sc);
1832 /* update cursor image */
1833 if (scp->status & CURSOR_ENABLED) {
1836 /* did cursor move since last time ? */
1837 if (scp->cursor_pos != scp->cursor_oldpos) {
1838 /* do we need to remove old cursor image ? */
1839 if (!and_region(&s, &e, scp->cursor_oldpos, scp->cursor_oldpos))
1840 sc_remove_cursor_image(scp);
1841 sc_draw_cursor_image(scp);
1843 if (and_region(&s, &e, scp->cursor_pos, scp->cursor_pos))
1844 /* cursor didn't move, but has been overwritten */
1845 sc_draw_cursor_image(scp);
1846 else if (scp->curs_attr.flags & CONS_BLINK_CURSOR)
1847 /* if it's a blinking cursor, update it */
1848 (*scp->rndr->blink_cursor)(scp, scp->cursor_pos,
1849 sc_inside_cutmark(scp,
1854 #ifndef SC_NO_CUTPASTE
1855 /* update "pseudo" mouse pointer image */
1856 if (scp->sc->flags & SC_MOUSE_ENABLED) {
1857 if (!(scp->status & (MOUSE_VISIBLE | MOUSE_HIDDEN))) {
1858 scp->status &= ~MOUSE_MOVED;
1859 sc_draw_mouse_image(scp);
1862 #endif /* SC_NO_CUTPASTE */
1865 scp->start = scp->xsize*scp->ysize - 1;
1867 SC_VIDEO_UNLOCK(scp->sc);
1872 scsplash_callback(int event, void *arg)
1877 sc = (sc_softc_t *)arg;
1881 if (add_scrn_saver(scsplash_saver) == 0) {
1882 sc->flags &= ~SC_SAVER_FAILED;
1883 run_scrn_saver = TRUE;
1884 if (cold && !(boothowto & RB_VERBOSE)) {
1885 scsplash_stick(TRUE);
1886 (*current_saver)(sc, TRUE);
1892 if (current_saver == scsplash_saver) {
1893 scsplash_stick(FALSE);
1894 error = remove_scrn_saver(scsplash_saver);
1906 scsplash_saver(sc_softc_t *sc, int show)
1908 static int busy = FALSE;
1917 if (!(sc->flags & SC_SAVER_FAILED)) {
1918 if (!(sc->flags & SC_SCRN_BLANKED))
1919 set_scrn_saver_mode(scp, -1, NULL, 0);
1920 switch (splash(sc->adp, TRUE)) {
1921 case 0: /* succeeded */
1923 case EAGAIN: /* try later */
1924 restore_scrn_saver_mode(scp, FALSE);
1925 sc_touch_scrn_saver(); /* XXX */
1928 sc->flags |= SC_SAVER_FAILED;
1929 scsplash_stick(FALSE);
1930 restore_scrn_saver_mode(scp, TRUE);
1931 printf("scsplash_saver(): failed to put up the image\n");
1935 } else if (!sticky_splash) {
1936 if ((sc->flags & SC_SCRN_BLANKED) && (splash(sc->adp, FALSE) == 0))
1937 restore_scrn_saver_mode(scp, TRUE);
1943 add_scrn_saver(void (*this_saver)(sc_softc_t *, int))
1948 if (current_saver != none_saver) {
1949 error = remove_scrn_saver(current_saver);
1954 if (current_saver != none_saver)
1957 run_scrn_saver = FALSE;
1958 saver_mode = CONS_LKM_SAVER;
1959 current_saver = this_saver;
1964 remove_scrn_saver(void (*this_saver)(sc_softc_t *, int))
1966 if (current_saver != this_saver)
1971 * In order to prevent `current_saver' from being called by
1972 * the timeout routine `scrn_timer()' while we manipulate
1973 * the saver list, we shall set `current_saver' to `none_saver'
1974 * before stopping the current saver, rather than blocking by `splXX()'.
1976 current_saver = none_saver;
1978 stop_scrn_saver(this_saver);
1981 /* unblank all blanked screens */
1982 wait_scrn_saver_stop(NULL);
1986 current_saver = none_saver;
1991 set_scrn_saver_mode(scr_stat *scp, int mode, u_char *pal, int border)
1995 /* assert(scp == scp->sc->cur_scp) */
1997 if (!ISGRAPHSC(scp))
1998 sc_remove_cursor_image(scp);
1999 scp->splash_save_mode = scp->mode;
2000 scp->splash_save_status = scp->status & (GRAPHICS_MODE | PIXEL_MODE);
2001 scp->status &= ~(GRAPHICS_MODE | PIXEL_MODE);
2002 scp->status |= (UNKNOWN_MODE | SAVER_RUNNING);
2003 scp->sc->flags |= SC_SCRN_BLANKED;
2009 if (set_mode(scp) == 0) {
2010 if (scp->sc->adp->va_info.vi_flags & V_INFO_GRAPHICS)
2011 scp->status |= GRAPHICS_MODE;
2012 #ifndef SC_NO_PALETTE_LOADING
2014 vidd_load_palette(scp->sc->adp, pal);
2016 sc_set_border(scp, border);
2020 scp->mode = scp->splash_save_mode;
2021 scp->status &= ~(UNKNOWN_MODE | SAVER_RUNNING);
2022 scp->status |= scp->splash_save_status;
2029 restore_scrn_saver_mode(scr_stat *scp, int changemode)
2035 /* assert(scp == scp->sc->cur_scp) */
2038 status = scp->status;
2039 scp->mode = scp->splash_save_mode;
2040 scp->status &= ~(UNKNOWN_MODE | SAVER_RUNNING);
2041 scp->status |= scp->splash_save_status;
2042 scp->sc->flags &= ~SC_SCRN_BLANKED;
2044 if (!ISGRAPHSC(scp))
2045 sc_draw_cursor_image(scp);
2050 if (set_mode(scp) == 0) {
2051 #ifndef SC_NO_PALETTE_LOADING
2052 vidd_load_palette(scp->sc->adp, scp->sc->palette);
2059 scp->status = status;
2066 stop_scrn_saver(sc_softc_t *sc, void (*saver)(sc_softc_t *, int))
2068 (*saver)(sc, FALSE);
2069 run_scrn_saver = FALSE;
2070 /* the screen saver may have chosen not to stop after all... */
2071 if (sc->flags & SC_SCRN_BLANKED)
2074 mark_all(sc->cur_scp);
2075 if (sc->delayed_next_scr)
2076 sc_switch_scr(sc, sc->delayed_next_scr - 1);
2078 wakeup(&scrn_blanked);
2082 wait_scrn_saver_stop(sc_softc_t *sc)
2086 while (scrn_blanked > 0) {
2087 run_scrn_saver = FALSE;
2088 if (sc && !(sc->flags & SC_SCRN_BLANKED)) {
2092 error = tsleep(&scrn_blanked, PZERO | PCATCH, "scrsav", 0);
2093 if ((error != 0) && (error != ERESTART))
2096 run_scrn_saver = FALSE;
2099 #endif /* DEV_SPLASH */
2102 sc_touch_scrn_saver(void)
2104 scsplash_stick(FALSE);
2105 run_scrn_saver = FALSE;
2109 sc_switch_scr(sc_softc_t *sc, u_int next_scr)
2116 DPRINTF(5, ("sc0: sc_switch_scr() %d ", next_scr + 1));
2118 if (sc->cur_scp == NULL)
2121 /* prevent switch if previously requested */
2122 if (sc->flags & SC_SCRN_VTYLOCK) {
2123 sc_bell(sc->cur_scp, sc->cur_scp->bell_pitch,
2124 sc->cur_scp->bell_duration);
2128 /* delay switch if the screen is blanked or being updated */
2129 if ((sc->flags & SC_SCRN_BLANKED) || sc->write_in_progress
2130 || sc->blink_in_progress) {
2131 sc->delayed_next_scr = next_scr + 1;
2132 sc_touch_scrn_saver();
2133 DPRINTF(5, ("switch delayed\n"));
2136 sc->delayed_next_scr = 0;
2139 cur_scp = sc->cur_scp;
2141 /* we are in the middle of the vty switching process... */
2142 if (sc->switch_in_progress
2143 && (cur_scp->smode.mode == VT_PROCESS)
2145 p = pfind(cur_scp->pid);
2146 if (cur_scp->proc != p) {
2150 * The controlling process has died!!. Do some clean up.
2151 * NOTE:`cur_scp->proc' and `cur_scp->smode.mode'
2152 * are not reset here yet; they will be cleared later.
2154 DPRINTF(5, ("cur_scp controlling process %d died, ",
2156 if (cur_scp->status & SWITCH_WAIT_REL) {
2158 * Force the previous switch to finish, but return now
2161 DPRINTF(5, ("reset WAIT_REL, "));
2162 finish_vt_rel(cur_scp, TRUE, &s);
2164 DPRINTF(5, ("finishing previous switch\n"));
2166 } else if (cur_scp->status & SWITCH_WAIT_ACQ) {
2167 /* let's assume screen switch has been completed. */
2168 DPRINTF(5, ("reset WAIT_ACQ, "));
2169 finish_vt_acq(cur_scp);
2172 * We are in between screen release and acquisition, and
2173 * reached here via scgetc() or scrn_timer() which has
2174 * interrupted exchange_scr(). Don't do anything stupid.
2176 DPRINTF(5, ("waiting nothing, "));
2182 * The controlling process is alive, but not responding...
2183 * It is either buggy or it may be just taking time.
2184 * The following code is a gross kludge to cope with this
2185 * problem for which there is no clean solution. XXX
2187 if (cur_scp->status & SWITCH_WAIT_REL) {
2188 switch (sc->switch_in_progress++) {
2192 DPRINTF(5, ("sending relsig again, "));
2193 signal_vt_rel(cur_scp);
2200 * Act as if the controlling program returned
2203 DPRINTF(5, ("force reset WAIT_REL, "));
2204 finish_vt_rel(cur_scp, FALSE, &s);
2206 DPRINTF(5, ("act as if VT_FALSE was seen\n"));
2209 } else if (cur_scp->status & SWITCH_WAIT_ACQ) {
2210 switch (sc->switch_in_progress++) {
2214 DPRINTF(5, ("sending acqsig again, "));
2215 signal_vt_acq(cur_scp);
2221 /* clear the flag and finish the previous switch */
2222 DPRINTF(5, ("force reset WAIT_ACQ, "));
2223 finish_vt_acq(cur_scp);
2231 * Return error if an invalid argument is given, or vty switch
2232 * is still in progress.
2234 if ((next_scr < sc->first_vty) || (next_scr >= sc->first_vty + sc->vtys)
2235 || sc->switch_in_progress) {
2237 sc_bell(cur_scp, bios_value.bell_pitch, BELL_DURATION);
2238 DPRINTF(5, ("error 1\n"));
2243 * Don't allow switching away from the graphics mode vty
2244 * if the switch mode is VT_AUTO, unless the next vty is the same
2245 * as the current or the current vty has been closed (but showing).
2247 tp = SC_DEV(sc, cur_scp->index);
2248 if ((cur_scp->index != next_scr)
2250 && (cur_scp->smode.mode == VT_AUTO)
2251 && ISGRAPHSC(cur_scp)) {
2253 sc_bell(cur_scp, bios_value.bell_pitch, BELL_DURATION);
2254 DPRINTF(5, ("error, graphics mode\n"));
2259 * Is the wanted vty open? Don't allow switching to a closed vty.
2260 * If we are in DDB, don't switch to a vty in the VT_PROCESS mode.
2261 * Note that we always allow the user to switch to the kernel
2262 * console even if it is closed.
2264 if ((sc_console == NULL) || (next_scr != sc_console->index)) {
2265 tp = SC_DEV(sc, next_scr);
2266 if (!tty_opened(tp)) {
2268 sc_bell(cur_scp, bios_value.bell_pitch, BELL_DURATION);
2269 DPRINTF(5, ("error 2, requested vty isn't open!\n"));
2272 if ((debugger > 0) && (SC_STAT(tp)->smode.mode == VT_PROCESS)) {
2274 DPRINTF(5, ("error 3, requested vty is in the VT_PROCESS mode\n"));
2279 /* this is the start of vty switching process... */
2280 ++sc->switch_in_progress;
2281 sc->old_scp = cur_scp;
2282 sc->new_scp = sc_get_stat(SC_DEV(sc, next_scr));
2283 if (sc->new_scp == sc->old_scp) {
2284 sc->switch_in_progress = 0;
2286 * XXX wakeup() locks the scheduler lock which will hang if
2287 * the lock is in an in-between state, e.g., when we stop at
2288 * a breakpoint at fork_exit. It has always been wrong to call
2289 * wakeup() when the debugger is active. In RELENG_4, wakeup()
2290 * is supposed to be locked by splhigh(), but the debugger may
2291 * be invoked at splhigh().
2294 wakeup(VTY_WCHAN(sc,next_scr));
2296 DPRINTF(5, ("switch done (new == old)\n"));
2300 /* has controlling process died? */
2301 vt_proc_alive(sc->old_scp);
2302 vt_proc_alive(sc->new_scp);
2304 /* wait for the controlling process to release the screen, if necessary */
2305 if (signal_vt_rel(sc->old_scp)) {
2310 /* go set up the new vty screen */
2315 /* wake up processes waiting for this vty */
2317 wakeup(VTY_WCHAN(sc,next_scr));
2319 /* wait for the controlling process to acknowledge, if necessary */
2320 if (signal_vt_acq(sc->cur_scp)) {
2325 sc->switch_in_progress = 0;
2326 if (sc->unit == sc_console_unit)
2327 cnavailable(sc_consptr, TRUE);
2329 DPRINTF(5, ("switch done\n"));
2335 do_switch_scr(sc_softc_t *sc, int s)
2337 vt_proc_alive(sc->new_scp);
2342 /* sc->cur_scp == sc->new_scp */
2343 wakeup(VTY_WCHAN(sc,sc->cur_scp->index));
2345 /* wait for the controlling process to acknowledge, if necessary */
2346 if (!signal_vt_acq(sc->cur_scp)) {
2347 sc->switch_in_progress = 0;
2348 if (sc->unit == sc_console_unit)
2349 cnavailable(sc_consptr, TRUE);
2356 vt_proc_alive(scr_stat *scp)
2361 if ((p = pfind(scp->pid)) != NULL)
2366 scp->smode.mode = VT_AUTO;
2367 DPRINTF(5, ("vt controlling process %d died\n", scp->pid));
2373 signal_vt_rel(scr_stat *scp)
2375 if (scp->smode.mode != VT_PROCESS)
2377 scp->status |= SWITCH_WAIT_REL;
2378 PROC_LOCK(scp->proc);
2379 psignal(scp->proc, scp->smode.relsig);
2380 PROC_UNLOCK(scp->proc);
2381 DPRINTF(5, ("sending relsig to %d\n", scp->pid));
2386 signal_vt_acq(scr_stat *scp)
2388 if (scp->smode.mode != VT_PROCESS)
2390 if (scp->sc->unit == sc_console_unit)
2391 cnavailable(sc_consptr, FALSE);
2392 scp->status |= SWITCH_WAIT_ACQ;
2393 PROC_LOCK(scp->proc);
2394 psignal(scp->proc, scp->smode.acqsig);
2395 PROC_UNLOCK(scp->proc);
2396 DPRINTF(5, ("sending acqsig to %d\n", scp->pid));
2401 finish_vt_rel(scr_stat *scp, int release, int *s)
2403 if (scp == scp->sc->old_scp && scp->status & SWITCH_WAIT_REL) {
2404 scp->status &= ~SWITCH_WAIT_REL;
2406 *s = do_switch_scr(scp->sc, *s);
2408 scp->sc->switch_in_progress = 0;
2415 finish_vt_acq(scr_stat *scp)
2417 if (scp == scp->sc->new_scp && scp->status & SWITCH_WAIT_ACQ) {
2418 scp->status &= ~SWITCH_WAIT_ACQ;
2419 scp->sc->switch_in_progress = 0;
2426 exchange_scr(sc_softc_t *sc)
2430 /* save the current state of video and keyboard */
2431 sc_move_cursor(sc->old_scp, sc->old_scp->xpos, sc->old_scp->ypos);
2432 if (!ISGRAPHSC(sc->old_scp))
2433 sc_remove_cursor_image(sc->old_scp);
2434 if (sc->old_scp->kbd_mode == K_XLATE)
2435 save_kbd_state(sc->old_scp);
2437 /* set up the video for the new screen */
2438 scp = sc->cur_scp = sc->new_scp;
2440 if (sc->old_scp->mode != scp->mode || ISUNKNOWNSC(sc->old_scp) || ISUNKNOWNSC(sc->new_scp))
2442 if (sc->old_scp->mode != scp->mode || ISUNKNOWNSC(sc->old_scp))
2447 sc_vtb_init(&scp->scr, VTB_FRAMEBUFFER, scp->xsize, scp->ysize,
2448 (void *)sc->adp->va_window, FALSE);
2450 scp->status |= MOUSE_HIDDEN;
2451 sc_move_cursor(scp, scp->xpos, scp->ypos);
2452 if (!ISGRAPHSC(scp))
2453 sc_set_cursor_image(scp);
2454 #ifndef SC_NO_PALETTE_LOADING
2455 if (ISGRAPHSC(sc->old_scp))
2456 vidd_load_palette(sc->adp, sc->palette);
2458 sc_set_border(scp, scp->border);
2460 /* set up the keyboard for the new screen */
2461 if (sc->old_scp->kbd_mode != scp->kbd_mode)
2462 kbdd_ioctl(sc->kbd, KDSKBMODE, (caddr_t)&scp->kbd_mode);
2463 update_kbd_state(scp, scp->status, LOCK_MASK);
2469 sc_puts(scr_stat *scp, u_char *buf, int len, int kernel)
2471 int need_unlock = 0;
2474 /* make screensaver happy */
2475 if (!sticky_splash && scp == scp->sc->cur_scp && !sc_saver_keyb_only)
2476 run_scrn_saver = FALSE;
2480 if (!kdb_active && !mtx_owned(&scp->scr_lock)) {
2482 mtx_lock_spin(&scp->scr_lock);
2484 (*scp->tsw->te_puts)(scp, buf, len, kernel);
2486 mtx_unlock_spin(&scp->scr_lock);
2489 if (scp->sc->delayed_next_scr)
2490 sc_switch_scr(scp->sc, scp->sc->delayed_next_scr - 1);
2494 sc_draw_cursor_image(scr_stat *scp)
2496 /* assert(scp == scp->sc->cur_scp); */
2497 SC_VIDEO_LOCK(scp->sc);
2498 (*scp->rndr->draw_cursor)(scp, scp->cursor_pos,
2499 scp->curs_attr.flags & CONS_BLINK_CURSOR, TRUE,
2500 sc_inside_cutmark(scp, scp->cursor_pos));
2501 scp->cursor_oldpos = scp->cursor_pos;
2502 SC_VIDEO_UNLOCK(scp->sc);
2506 sc_remove_cursor_image(scr_stat *scp)
2508 /* assert(scp == scp->sc->cur_scp); */
2509 SC_VIDEO_LOCK(scp->sc);
2510 (*scp->rndr->draw_cursor)(scp, scp->cursor_oldpos,
2511 scp->curs_attr.flags & CONS_BLINK_CURSOR, FALSE,
2512 sc_inside_cutmark(scp, scp->cursor_oldpos));
2513 SC_VIDEO_UNLOCK(scp->sc);
2517 update_cursor_image(scr_stat *scp)
2519 /* assert(scp == scp->sc->cur_scp); */
2520 sc_remove_cursor_image(scp);
2521 sc_set_cursor_image(scp);
2522 sc_draw_cursor_image(scp);
2526 sc_set_cursor_image(scr_stat *scp)
2528 scp->curs_attr.flags = scp->curr_curs_attr.flags;
2529 if (scp->curs_attr.flags & CONS_HIDDEN_CURSOR) {
2530 /* hidden cursor is internally represented as zero-height underline */
2531 scp->curs_attr.flags = CONS_CHAR_CURSOR;
2532 scp->curs_attr.base = scp->curs_attr.height = 0;
2533 } else if (scp->curs_attr.flags & CONS_CHAR_CURSOR) {
2534 scp->curs_attr.base = imin(scp->curr_curs_attr.base,
2535 scp->font_size - 1);
2536 scp->curs_attr.height = imin(scp->curr_curs_attr.height,
2537 scp->font_size - scp->curs_attr.base);
2538 } else { /* block cursor */
2539 scp->curs_attr.base = 0;
2540 scp->curs_attr.height = scp->font_size;
2543 /* assert(scp == scp->sc->cur_scp); */
2544 SC_VIDEO_LOCK(scp->sc);
2545 (*scp->rndr->set_cursor)(scp, scp->curs_attr.base, scp->curs_attr.height,
2546 scp->curs_attr.flags & CONS_BLINK_CURSOR);
2547 SC_VIDEO_UNLOCK(scp->sc);
2551 change_cursor_shape(scr_stat *scp, int flags, int base, int height)
2553 if ((scp == scp->sc->cur_scp) && !ISGRAPHSC(scp))
2554 sc_remove_cursor_image(scp);
2557 scp->curr_curs_attr.base = base;
2559 scp->curr_curs_attr.height = height;
2560 if (flags & CONS_RESET_CURSOR)
2561 scp->curr_curs_attr = scp->dflt_curs_attr;
2563 scp->curr_curs_attr.flags = flags & CONS_CURSOR_ATTRS;
2565 if ((scp == scp->sc->cur_scp) && !ISGRAPHSC(scp)) {
2566 sc_set_cursor_image(scp);
2567 sc_draw_cursor_image(scp);
2572 sc_change_cursor_shape(scr_stat *scp, int flags, int base, int height)
2580 if ((flags != -1) && (flags & CONS_LOCAL_CURSOR)) {
2581 /* local (per vty) change */
2582 change_cursor_shape(scp, flags, base, height);
2590 sc->curs_attr.base = base;
2592 sc->curs_attr.height = height;
2594 if (flags & CONS_RESET_CURSOR)
2595 sc->curs_attr = sc->dflt_curs_attr;
2597 sc->curs_attr.flags = flags & CONS_CURSOR_ATTRS;
2600 for (i = sc->first_vty; i < sc->first_vty + sc->vtys; ++i) {
2601 if ((tp = SC_DEV(sc, i)) == NULL)
2603 if ((scp = sc_get_stat(tp)) == NULL)
2605 scp->dflt_curs_attr = sc->curs_attr;
2606 change_cursor_shape(scp, CONS_RESET_CURSOR, -1, -1);
2612 scinit(int unit, int flags)
2616 * When syscons is being initialized as the kernel console, malloc()
2617 * is not yet functional, because various kernel structures has not been
2618 * fully initialized yet. Therefore, we need to declare the following
2619 * static buffers for the console. This is less than ideal,
2620 * but is necessry evil for the time being. XXX
2623 static u_short sc_buffer[ROW*COL*2];/* XXX */
2625 static u_short sc_buffer[ROW*COL]; /* XXX */
2627 #ifndef SC_NO_FONT_LOADING
2628 static u_char font_8[256*8];
2629 static u_char font_14[256*14];
2630 static u_char font_16[256*16];
2635 video_adapter_t *adp;
2640 /* one time initialization */
2641 if (init_done == COLD)
2642 sc_get_bios_values(&bios_value);
2646 * Allocate resources. Even if we are being called for the second
2647 * time, we must allocate them again, because they might have
2650 sc = sc_get_softc(unit, flags & SC_KERNEL_CONSOLE);
2651 if ((sc->flags & SC_INIT_DONE) == 0)
2652 SC_VIDEO_LOCKINIT(sc);
2655 if (sc->adapter >= 0) {
2656 vid_release(sc->adp, (void *)&sc->adapter);
2660 if (sc->keyboard >= 0) {
2661 DPRINTF(5, ("sc%d: releasing kbd%d\n", unit, sc->keyboard));
2662 i = kbd_release(sc->kbd, (void *)&sc->keyboard);
2663 DPRINTF(5, ("sc%d: kbd_release returned %d\n", unit, i));
2664 if (sc->kbd != NULL) {
2665 DPRINTF(5, ("sc%d: kbd != NULL!, index:%d, unit:%d, flags:0x%x\n",
2666 unit, sc->kbd->kb_index, sc->kbd->kb_unit, sc->kbd->kb_flags));
2670 sc->adapter = vid_allocate("*", unit, (void *)&sc->adapter);
2671 sc->adp = vid_get_adapter(sc->adapter);
2672 /* assert((sc->adapter >= 0) && (sc->adp != NULL)) */
2674 sc->keyboard = sc_allocate_keyboard(sc, unit);
2675 DPRINTF(1, ("sc%d: keyboard %d\n", unit, sc->keyboard));
2677 sc->kbd = kbd_get_keyboard(sc->keyboard);
2678 if (sc->kbd != NULL) {
2679 DPRINTF(1, ("sc%d: kbd index:%d, unit:%d, flags:0x%x\n",
2680 unit, sc->kbd->kb_index, sc->kbd->kb_unit, sc->kbd->kb_flags));
2683 if (!(sc->flags & SC_INIT_DONE) || (adp != sc->adp)) {
2685 sc->initial_mode = sc->adp->va_initial_mode;
2687 #ifndef SC_NO_FONT_LOADING
2688 if (flags & SC_KERNEL_CONSOLE) {
2689 sc->font_8 = font_8;
2690 sc->font_14 = font_14;
2691 sc->font_16 = font_16;
2692 } else if (sc->font_8 == NULL) {
2693 /* assert(sc_malloc) */
2694 sc->font_8 = malloc(sizeof(font_8), M_DEVBUF, M_WAITOK);
2695 sc->font_14 = malloc(sizeof(font_14), M_DEVBUF, M_WAITOK);
2696 sc->font_16 = malloc(sizeof(font_16), M_DEVBUF, M_WAITOK);
2700 /* extract the hardware cursor location and hide the cursor for now */
2701 vidd_read_hw_cursor(sc->adp, &col, &row);
2702 vidd_set_hw_cursor(sc->adp, -1, -1);
2704 /* set up the first console */
2705 sc->first_vty = unit*MAXCONS;
2706 sc->vtys = MAXCONS; /* XXX: should be configurable */
2707 if (flags & SC_KERNEL_CONSOLE) {
2709 * Set up devs structure but don't use it yet, calling make_dev()
2710 * might panic kernel. Wait for sc_attach_unit() to actually
2711 * create the devices.
2713 sc->dev = main_devs;
2714 scp = &main_console;
2715 init_scp(sc, sc->first_vty, scp);
2716 sc_vtb_init(&scp->vtb, VTB_MEMORY, scp->xsize, scp->ysize,
2717 (void *)sc_buffer, FALSE);
2719 /* move cursors to the initial positions */
2720 if (col >= scp->xsize)
2722 if (row >= scp->ysize)
2723 row = scp->ysize - 1;
2726 scp->cursor_pos = scp->cursor_oldpos = row*scp->xsize + col;
2728 if (sc_init_emulator(scp, SC_DFLT_TERM))
2729 sc_init_emulator(scp, "*");
2730 (*scp->tsw->te_default_attr)(scp,
2731 user_default.std_color,
2732 user_default.rev_color);
2734 /* assert(sc_malloc) */
2735 sc->dev = malloc(sizeof(struct tty *)*sc->vtys, M_DEVBUF,
2737 sc->dev[0] = sc_alloc_tty(0, unit * MAXCONS);
2738 scp = alloc_scp(sc, sc->first_vty);
2739 SC_STAT(sc->dev[0]) = scp;
2744 /* copy screen to temporary buffer */
2745 sc_vtb_init(&scp->scr, VTB_FRAMEBUFFER, scp->xsize, scp->ysize,
2746 (void *)scp->sc->adp->va_window, FALSE);
2748 sc_vtb_copy(&scp->scr, 0, &scp->vtb, 0, scp->xsize*scp->ysize);
2751 if (bios_value.cursor_end < scp->font_size)
2752 sc->dflt_curs_attr.base = scp->font_size -
2753 bios_value.cursor_end - 1;
2755 sc->dflt_curs_attr.base = 0;
2756 i = bios_value.cursor_end - bios_value.cursor_start + 1;
2757 sc->dflt_curs_attr.height = imin(i, scp->font_size);
2758 sc->dflt_curs_attr.flags = 0;
2759 sc->curs_attr = sc->dflt_curs_attr;
2760 scp->curr_curs_attr = scp->dflt_curs_attr = sc->curs_attr;
2762 #ifndef SC_NO_SYSMOUSE
2763 sc_mouse_move(scp, scp->xpixel/2, scp->ypixel/2);
2765 if (!ISGRAPHSC(scp)) {
2766 sc_set_cursor_image(scp);
2767 sc_draw_cursor_image(scp);
2770 /* save font and palette */
2771 #ifndef SC_NO_FONT_LOADING
2772 sc->fonts_loaded = 0;
2773 if (ISFONTAVAIL(sc->adp->va_flags)) {
2775 bcopy(dflt_font_8, sc->font_8, sizeof(dflt_font_8));
2776 bcopy(dflt_font_14, sc->font_14, sizeof(dflt_font_14));
2777 bcopy(dflt_font_16, sc->font_16, sizeof(dflt_font_16));
2778 sc->fonts_loaded = FONT_16 | FONT_14 | FONT_8;
2779 if (scp->font_size < 14) {
2780 sc_load_font(scp, 0, 8, 8, sc->font_8, 0, 256);
2781 } else if (scp->font_size >= 16) {
2782 sc_load_font(scp, 0, 16, 8, sc->font_16, 0, 256);
2784 sc_load_font(scp, 0, 14, 8, sc->font_14, 0, 256);
2786 #else /* !SC_DFLT_FONT */
2787 if (scp->font_size < 14) {
2788 sc_save_font(scp, 0, 8, 8, sc->font_8, 0, 256);
2789 sc->fonts_loaded = FONT_8;
2790 } else if (scp->font_size >= 16) {
2791 sc_save_font(scp, 0, 16, 8, sc->font_16, 0, 256);
2792 sc->fonts_loaded = FONT_16;
2794 sc_save_font(scp, 0, 14, 8, sc->font_14, 0, 256);
2795 sc->fonts_loaded = FONT_14;
2797 #endif /* SC_DFLT_FONT */
2798 /* FONT KLUDGE: always use the font page #0. XXX */
2799 sc_show_font(scp, 0);
2801 #endif /* !SC_NO_FONT_LOADING */
2803 #ifndef SC_NO_PALETTE_LOADING
2804 vidd_save_palette(sc->adp, sc->palette);
2808 if (!(sc->flags & SC_SPLASH_SCRN)) {
2809 /* we are ready to put up the splash image! */
2810 splash_init(sc->adp, scsplash_callback, sc);
2811 sc->flags |= SC_SPLASH_SCRN;
2816 /* the rest is not necessary, if we have done it once */
2817 if (sc->flags & SC_INIT_DONE)
2820 /* initialize mapscrn arrays to a one to one map */
2821 for (i = 0; i < sizeof(sc->scr_map); i++)
2822 sc->scr_map[i] = sc->scr_rmap[i] = i;
2824 sc->scr_map[0x5c] = (u_char)0xfc; /* for backslash */
2827 sc->flags |= SC_INIT_DONE;
2831 scterm(int unit, int flags)
2836 sc = sc_get_softc(unit, flags & SC_KERNEL_CONSOLE);
2838 return; /* shouldn't happen */
2841 /* this console is no longer available for the splash screen */
2842 if (sc->flags & SC_SPLASH_SCRN) {
2843 splash_term(sc->adp);
2844 sc->flags &= ~SC_SPLASH_SCRN;
2849 /* move the hardware cursor to the upper-left corner */
2850 vidd_set_hw_cursor(sc->adp, 0, 0);
2853 /* release the keyboard and the video card */
2854 if (sc->keyboard >= 0)
2855 kbd_release(sc->kbd, &sc->keyboard);
2856 if (sc->adapter >= 0)
2857 vid_release(sc->adp, &sc->adapter);
2859 /* stop the terminal emulator, if any */
2860 scp = sc_get_stat(sc->dev[0]);
2862 (*scp->tsw->te_term)(scp, &scp->ts);
2863 if (scp->ts != NULL)
2864 free(scp->ts, M_DEVBUF);
2865 mtx_destroy(&scp->scr_lock);
2867 /* clear the structure */
2868 if (!(flags & SC_KERNEL_CONSOLE)) {
2869 /* XXX: We need delete_dev() for this */
2870 free(sc->dev, M_DEVBUF);
2872 /* XXX: We need a ttyunregister for this */
2873 free(sc->tty, M_DEVBUF);
2875 #ifndef SC_NO_FONT_LOADING
2876 free(sc->font_8, M_DEVBUF);
2877 free(sc->font_14, M_DEVBUF);
2878 free(sc->font_16, M_DEVBUF);
2880 /* XXX vtb, history */
2882 bzero(sc, sizeof(*sc));
2888 scshutdown(void *arg, int howto)
2890 /* assert(sc_console != NULL) */
2892 sc_touch_scrn_saver();
2893 if (!cold && sc_console
2894 && sc_console->sc->cur_scp->smode.mode == VT_AUTO
2895 && sc_console->smode.mode == VT_AUTO)
2896 sc_switch_scr(sc_console->sc, sc_console->index);
2897 shutdown_in_progress = TRUE;
2901 sc_clean_up(scr_stat *scp)
2907 if (scp->sc->flags & SC_SCRN_BLANKED) {
2908 sc_touch_scrn_saver();
2910 if ((error = wait_scrn_saver_stop(scp->sc)))
2914 scp->status |= MOUSE_HIDDEN;
2915 sc_remove_mouse_image(scp);
2916 sc_remove_cutmarking(scp);
2921 sc_alloc_scr_buffer(scr_stat *scp, int wait, int discard)
2927 sc_vtb_init(&new, VTB_MEMORY, scp->xsize, scp->ysize, NULL, wait);
2928 if (!discard && (old.vtb_flags & VTB_VALID)) {
2929 /* retain the current cursor position and buffer contants */
2930 scp->cursor_oldpos = scp->cursor_pos;
2932 * This works only if the old buffer has the same size as or larger
2933 * than the new one. XXX
2935 sc_vtb_copy(&old, 0, &new, 0, scp->xsize*scp->ysize);
2939 sc_vtb_destroy(&old);
2942 #ifndef SC_NO_SYSMOUSE
2943 /* move the mouse cursor at the center of the screen */
2944 sc_mouse_move(scp, scp->xpixel / 2, scp->ypixel / 2);
2949 *alloc_scp(sc_softc_t *sc, int vty)
2953 /* assert(sc_malloc) */
2955 scp = (scr_stat *)malloc(sizeof(scr_stat), M_DEVBUF, M_WAITOK);
2956 init_scp(sc, vty, scp);
2958 sc_alloc_scr_buffer(scp, TRUE, TRUE);
2959 if (sc_init_emulator(scp, SC_DFLT_TERM))
2960 sc_init_emulator(scp, "*");
2962 #ifndef SC_NO_CUTPASTE
2963 sc_alloc_cut_buffer(scp, TRUE);
2966 #ifndef SC_NO_HISTORY
2967 sc_alloc_history_buffer(scp, 0, 0, TRUE);
2974 init_scp(sc_softc_t *sc, int vty, scr_stat *scp)
2978 bzero(scp, sizeof(*scp));
2983 scp->mode = sc->initial_mode;
2984 vidd_get_info(sc->adp, scp->mode, &info);
2985 if (info.vi_flags & V_INFO_GRAPHICS) {
2986 scp->status |= GRAPHICS_MODE;
2987 scp->xpixel = info.vi_width;
2988 scp->ypixel = info.vi_height;
2989 scp->xsize = info.vi_width/info.vi_cwidth;
2990 scp->ysize = info.vi_height/info.vi_cheight;
2994 scp->xsize = info.vi_width;
2995 scp->ysize = info.vi_height;
2996 scp->xpixel = scp->xsize*info.vi_cwidth;
2997 scp->ypixel = scp->ysize*info.vi_cheight;
2998 scp->font_size = info.vi_cheight;
2999 scp->font_width = info.vi_cwidth;
3000 if (info.vi_cheight < 14) {
3001 #ifndef SC_NO_FONT_LOADING
3002 scp->font = sc->font_8;
3006 } else if (info.vi_cheight >= 16) {
3007 #ifndef SC_NO_FONT_LOADING
3008 scp->font = sc->font_16;
3013 #ifndef SC_NO_FONT_LOADING
3014 scp->font = sc->font_14;
3020 sc_vtb_init(&scp->vtb, VTB_MEMORY, 0, 0, NULL, FALSE);
3022 sc_vtb_init(&scp->scr, VTB_FRAMEBUFFER, 0, 0, NULL, FALSE);
3024 scp->xoff = scp->yoff = 0;
3025 scp->xpos = scp->ypos = 0;
3026 scp->start = scp->xsize * scp->ysize - 1;
3031 scp->border = (SC_NORM_ATTR >> 4) & 0x0f;
3032 scp->curr_curs_attr = scp->dflt_curs_attr = sc->curs_attr;
3033 scp->mouse_cut_start = scp->xsize*scp->ysize;
3034 scp->mouse_cut_end = -1;
3035 scp->mouse_signal = 0;
3037 scp->mouse_proc = NULL;
3038 scp->kbd_mode = K_XLATE;
3039 scp->bell_pitch = bios_value.bell_pitch;
3040 scp->bell_duration = BELL_DURATION;
3041 scp->status |= (bios_value.shift_state & NLKED);
3042 scp->status |= CURSOR_ENABLED | MOUSE_HIDDEN;
3045 scp->smode.mode = VT_AUTO;
3046 scp->history = NULL;
3047 scp->history_pos = 0;
3048 scp->history_size = 0;
3050 mtx_init(&scp->scr_lock, "scrlock", NULL, MTX_SPIN);
3054 sc_init_emulator(scr_stat *scp, char *name)
3061 if (name == NULL) /* if no name is given, use the current emulator */
3063 else /* ...otherwise find the named emulator */
3064 sw = sc_term_match(name);
3069 if (strcmp(sw->te_renderer, "*") != 0) {
3070 rndr = sc_render_match(scp, sw->te_renderer,
3071 scp->status & (GRAPHICS_MODE | PIXEL_MODE));
3074 rndr = sc_render_match(scp, scp->sc->adp->va_name,
3075 scp->status & (GRAPHICS_MODE | PIXEL_MODE));
3080 if (sw == scp->tsw) {
3081 error = (*sw->te_init)(scp, &scp->ts, SC_TE_WARM_INIT);
3083 scp->rndr->init(scp);
3084 sc_clear_screen(scp);
3085 /* assert(error == 0); */
3089 if (sc_malloc && (sw->te_size > 0))
3090 p = malloc(sw->te_size, M_DEVBUF, M_NOWAIT);
3093 error = (*sw->te_init)(scp, &p, SC_TE_COLD_INIT);
3098 (*scp->tsw->te_term)(scp, &scp->ts);
3099 if (scp->ts != NULL)
3100 free(scp->ts, M_DEVBUF);
3104 scp->rndr->init(scp);
3107 (*sw->te_default_attr)(scp, user_default.std_color, user_default.rev_color);
3108 sc_clear_screen(scp);
3114 * scgetc(flags) - get character from keyboard.
3115 * If flags & SCGETC_CN, then avoid harmful side effects.
3116 * If flags & SCGETC_NONBLOCK, then wait until a key is pressed, else
3117 * return NOKEY if there is nothing there.
3120 scgetc(sc_softc_t *sc, u_int flags)
3123 #ifndef SC_NO_HISTORY
3131 if (sc->kbd == NULL)
3136 /* I don't like this, but... XXX */
3137 if (flags & SCGETC_CN)
3138 sccnupdate(sc->cur_scp);
3141 /* first see if there is something in the keyboard port */
3143 c = kbdd_read_char(sc->kbd, !(flags & SCGETC_NONBLOCK));
3145 if (!(flags & SCGETC_CN))
3146 sc_bell(scp, bios_value.bell_pitch, BELL_DURATION);
3147 } else if (c == NOKEY)
3153 /* make screensaver happy */
3155 sc_touch_scrn_saver();
3157 if (!(flags & SCGETC_CN))
3158 random_harvest(&c, sizeof(c), 1, 0, RANDOM_KEYBOARD);
3160 if (scp->kbd_mode != K_XLATE)
3163 /* if scroll-lock pressed allow history browsing */
3164 if (!ISGRAPHSC(scp) && scp->history && scp->status & SLKED) {
3166 scp->status &= ~CURSOR_ENABLED;
3167 sc_remove_cursor_image(scp);
3169 #ifndef SC_NO_HISTORY
3170 if (!(scp->status & BUFFER_SAVED)) {
3171 scp->status |= BUFFER_SAVED;
3175 /* FIXME: key codes */
3176 case SPCLKEY | FKEY | F(49): /* home key */
3177 sc_remove_cutmarking(scp);
3181 case SPCLKEY | FKEY | F(57): /* end key */
3182 sc_remove_cutmarking(scp);
3186 case SPCLKEY | FKEY | F(50): /* up arrow key */
3187 sc_remove_cutmarking(scp);
3188 if (sc_hist_up_line(scp))
3189 if (!(flags & SCGETC_CN))
3190 sc_bell(scp, bios_value.bell_pitch, BELL_DURATION);
3193 case SPCLKEY | FKEY | F(58): /* down arrow key */
3194 sc_remove_cutmarking(scp);
3195 if (sc_hist_down_line(scp))
3196 if (!(flags & SCGETC_CN))
3197 sc_bell(scp, bios_value.bell_pitch, BELL_DURATION);
3200 case SPCLKEY | FKEY | F(51): /* page up key */
3201 sc_remove_cutmarking(scp);
3202 for (i=0; i<scp->ysize; i++)
3203 if (sc_hist_up_line(scp)) {
3204 if (!(flags & SCGETC_CN))
3205 sc_bell(scp, bios_value.bell_pitch, BELL_DURATION);
3210 case SPCLKEY | FKEY | F(59): /* page down key */
3211 sc_remove_cutmarking(scp);
3212 for (i=0; i<scp->ysize; i++)
3213 if (sc_hist_down_line(scp)) {
3214 if (!(flags & SCGETC_CN))
3215 sc_bell(scp, bios_value.bell_pitch, BELL_DURATION);
3220 #endif /* SC_NO_HISTORY */
3224 * Process and consume special keys here. Return a plain char code
3225 * or a char code with the META flag or a function key code.
3229 /* goto next_code */
3234 switch (KEYCHAR(c)) {
3236 case NLK: case CLK: case ALK:
3239 kbdd_ioctl(sc->kbd, KDGKBSTATE, (caddr_t)&f);
3241 scp->status |= SLKED;
3243 if (scp->status & SLKED) {
3244 scp->status &= ~SLKED;
3245 #ifndef SC_NO_HISTORY
3246 if (scp->status & BUFFER_SAVED) {
3247 if (!sc_hist_restore(scp))
3248 sc_remove_cutmarking(scp);
3249 scp->status &= ~BUFFER_SAVED;
3250 scp->status |= CURSOR_ENABLED;
3251 sc_draw_cursor_image(scp);
3253 tp = SC_DEV(sc, scp->index);
3254 if (!kdb_active && tty_opened(tp))
3255 sctty_outwakeup(tp);
3262 #ifndef SC_NO_CUTPASTE
3263 sc_mouse_paste(scp);
3267 /* NON-LOCKING KEYS */
3269 case LSH: case RSH: case LCTR: case RCTR:
3270 case LALT: case RALT: case ASH: case META:
3274 if (!(sc->flags & SC_SCRN_BLANKED))
3280 /* force activatation/deactivation of the screen saver */
3281 if (!(sc->flags & SC_SCRN_BLANKED)) {
3282 run_scrn_saver = TRUE;
3283 sc->scrn_time_stamp -= scrn_blank_time;
3287 * While devices are being probed, the screen saver need
3288 * to be invoked explictly. XXX
3290 if (sc->flags & SC_SCRN_BLANKED) {
3291 scsplash_stick(FALSE);
3292 stop_scrn_saver(sc, current_saver);
3294 if (!ISGRAPHSC(scp)) {
3295 scsplash_stick(TRUE);
3296 (*current_saver)(sc, TRUE);
3300 #endif /* DEV_SPLASH */
3304 #ifndef SC_DISABLE_REBOOT
3311 #ifndef SC_DISABLE_REBOOT
3313 shutdown_nice(RB_HALT);
3318 #ifndef SC_DISABLE_REBOOT
3320 shutdown_nice(RB_HALT|RB_POWEROFF);
3325 power_pm_suspend(POWER_SLEEP_STATE_SUSPEND);
3328 power_pm_suspend(POWER_SLEEP_STATE_STANDBY);
3332 #ifndef SC_DISABLE_KDBKEY
3334 kdb_enter(KDB_WHY_BREAK, "manual escape to debugger");
3339 if (enable_panic_key)
3340 panic("Forced by the panic key");
3344 this_scr = scp->index;
3345 for (i = (this_scr - sc->first_vty + 1)%sc->vtys;
3346 sc->first_vty + i != this_scr;
3347 i = (i + 1)%sc->vtys) {
3348 struct tty *tp = SC_DEV(sc, sc->first_vty + i);
3349 if (tty_opened(tp)) {
3350 sc_switch_scr(scp->sc, sc->first_vty + i);
3357 this_scr = scp->index;
3358 for (i = (this_scr - sc->first_vty + sc->vtys - 1)%sc->vtys;
3359 sc->first_vty + i != this_scr;
3360 i = (i + sc->vtys - 1)%sc->vtys) {
3361 struct tty *tp = SC_DEV(sc, sc->first_vty + i);
3362 if (tty_opened(tp)) {
3363 sc_switch_scr(scp->sc, sc->first_vty + i);
3370 if (KEYCHAR(c) >= F_SCR && KEYCHAR(c) <= L_SCR) {
3371 sc_switch_scr(scp->sc, sc->first_vty + KEYCHAR(c) - F_SCR);
3374 /* assert(c & FKEY) */
3375 if (!(sc->flags & SC_SCRN_BLANKED))
3379 /* goto next_code */
3381 /* regular keys (maybe MKEY is set) */
3382 if (!(sc->flags & SC_SCRN_BLANKED))
3391 sctty_mmap(struct tty *tp, vm_offset_t offset, vm_paddr_t *paddr, int nprot)
3395 scp = sc_get_stat(tp);
3396 if (scp != scp->sc->cur_scp)
3398 return vidd_mmap(scp->sc->adp, offset, paddr, nprot);
3402 save_kbd_state(scr_stat *scp)
3407 error = kbdd_ioctl(scp->sc->kbd, KDGKBSTATE, (caddr_t)&state);
3408 if (error == ENOIOCTL)
3411 scp->status &= ~LOCK_MASK;
3412 scp->status |= state;
3418 update_kbd_state(scr_stat *scp, int new_bits, int mask)
3423 if (mask != LOCK_MASK) {
3424 error = kbdd_ioctl(scp->sc->kbd, KDGKBSTATE, (caddr_t)&state);
3425 if (error == ENOIOCTL)
3430 state |= new_bits & mask;
3432 state = new_bits & LOCK_MASK;
3434 error = kbdd_ioctl(scp->sc->kbd, KDSKBSTATE, (caddr_t)&state);
3435 if (error == ENOIOCTL)
3441 update_kbd_leds(scr_stat *scp, int which)
3446 error = kbdd_ioctl(scp->sc->kbd, KDSETLED, (caddr_t)&which);
3447 if (error == ENOIOCTL)
3453 set_mode(scr_stat *scp)
3457 /* reject unsupported mode */
3458 if (vidd_get_info(scp->sc->adp, scp->mode, &info))
3461 /* if this vty is not currently showing, do nothing */
3462 if (scp != scp->sc->cur_scp)
3465 /* setup video hardware for the given mode */
3466 vidd_set_mode(scp->sc->adp, scp->mode);
3467 scp->rndr->init(scp);
3469 sc_vtb_init(&scp->scr, VTB_FRAMEBUFFER, scp->xsize, scp->ysize,
3470 (void *)scp->sc->adp->va_window, FALSE);
3473 #ifndef SC_NO_FONT_LOADING
3474 /* load appropriate font */
3475 if (!(scp->status & GRAPHICS_MODE)) {
3476 if (!(scp->status & PIXEL_MODE) && ISFONTAVAIL(scp->sc->adp->va_flags)) {
3477 if (scp->font_size < 14) {
3478 if (scp->sc->fonts_loaded & FONT_8)
3479 sc_load_font(scp, 0, 8, 8, scp->sc->font_8, 0, 256);
3480 } else if (scp->font_size >= 16) {
3481 if (scp->sc->fonts_loaded & FONT_16)
3482 sc_load_font(scp, 0, 16, 8, scp->sc->font_16, 0, 256);
3484 if (scp->sc->fonts_loaded & FONT_14)
3485 sc_load_font(scp, 0, 14, 8, scp->sc->font_14, 0, 256);
3489 * This is an interim kludge to display correct font.
3490 * Always use the font page #0 on the video plane 2.
3491 * Somehow we cannot show the font in other font pages on
3492 * some video cards... XXX
3494 sc_show_font(scp, 0);
3498 #endif /* !SC_NO_FONT_LOADING */
3500 sc_set_border(scp, scp->border);
3501 sc_set_cursor_image(scp);
3507 sc_set_border(scr_stat *scp, int color)
3509 SC_VIDEO_LOCK(scp->sc);
3510 (*scp->rndr->draw_border)(scp, color);
3511 SC_VIDEO_UNLOCK(scp->sc);
3514 #ifndef SC_NO_FONT_LOADING
3516 sc_load_font(scr_stat *scp, int page, int size, int width, u_char *buf,
3517 int base, int count)
3522 sc->font_loading_in_progress = TRUE;
3523 vidd_load_font(sc->adp, page, size, width, buf, base, count);
3524 sc->font_loading_in_progress = FALSE;
3528 sc_save_font(scr_stat *scp, int page, int size, int width, u_char *buf,
3529 int base, int count)
3534 sc->font_loading_in_progress = TRUE;
3535 vidd_save_font(sc->adp, page, size, width, buf, base, count);
3536 sc->font_loading_in_progress = FALSE;
3540 sc_show_font(scr_stat *scp, int page)
3542 vidd_show_font(scp->sc->adp, page);
3544 #endif /* !SC_NO_FONT_LOADING */
3547 sc_paste(scr_stat *scp, const u_char *p, int count)
3552 tp = SC_DEV(scp->sc, scp->sc->cur_scp->index);
3553 if (!tty_opened(tp))
3555 rmap = scp->sc->scr_rmap;
3556 for (; count > 0; --count)
3557 ttydisc_rint(tp, rmap[*p++], 0);
3558 ttydisc_rint_done(tp);
3562 sc_respond(scr_stat *scp, const u_char *p, int count)
3566 tp = SC_DEV(scp->sc, scp->sc->cur_scp->index);
3567 if (!tty_opened(tp))
3569 for (; count > 0; --count)
3570 ttydisc_rint(tp, *p++, 0);
3572 /* XXX: we can't call ttydisc_rint_done() here! */
3573 ttydisc_rint_done(tp);
3578 sc_bell(scr_stat *scp, int pitch, int duration)
3580 if (cold || shutdown_in_progress || !enable_bell)
3583 if (scp != scp->sc->cur_scp && (scp->sc->flags & SC_QUIET_BELL))
3586 if (scp->sc->flags & SC_VISUAL_BELL) {
3587 if (scp->sc->blink_in_progress)
3589 scp->sc->blink_in_progress = 3;
3590 if (scp != scp->sc->cur_scp)
3591 scp->sc->blink_in_progress += 2;
3592 blink_screen(scp->sc->cur_scp);
3593 } else if (duration != 0 && pitch != 0) {
3594 if (scp != scp->sc->cur_scp)
3596 sysbeep(1193182 / pitch, duration);
3601 blink_screen(void *arg)
3603 scr_stat *scp = arg;
3606 if (ISGRAPHSC(scp) || (scp->sc->blink_in_progress <= 1)) {
3607 scp->sc->blink_in_progress = 0;
3609 tp = SC_DEV(scp->sc, scp->index);
3611 sctty_outwakeup(tp);
3612 if (scp->sc->delayed_next_scr)
3613 sc_switch_scr(scp->sc, scp->sc->delayed_next_scr - 1);
3616 (*scp->rndr->draw)(scp, 0, scp->xsize*scp->ysize,
3617 scp->sc->blink_in_progress & 1);
3618 scp->sc->blink_in_progress--;
3619 timeout(blink_screen, scp, hz / 10);
3624 * Until sc_attach_unit() gets called no dev structures will be available
3625 * to store the per-screen current status. This is the case when the
3626 * kernel is initially booting and needs access to its console. During
3627 * this early phase of booting the console's current status is kept in
3628 * one statically defined scr_stat structure, and any pointers to the
3629 * dev structures will be NULL.
3633 sc_get_stat(struct tty *tp)
3636 return (&main_console);
3637 return (SC_STAT(tp));
3641 * Allocate active keyboard. Try to allocate "kbdmux" keyboard first, and,
3642 * if found, add all non-busy keyboards to "kbdmux". Otherwise look for
3647 sc_allocate_keyboard(sc_softc_t *sc, int unit)
3653 idx0 = kbd_allocate("kbdmux", -1, (void *)&sc->keyboard, sckbdevent, sc);
3655 k0 = kbd_get_keyboard(idx0);
3657 for (idx = kbd_find_keyboard2("*", -1, 0);
3659 idx = kbd_find_keyboard2("*", -1, idx + 1)) {
3660 k = kbd_get_keyboard(idx);
3662 if (idx == idx0 || KBD_IS_BUSY(k))
3665 bzero(&ki, sizeof(ki));
3666 strcpy(ki.kb_name, k->kb_name);
3667 ki.kb_unit = k->kb_unit;
3669 kbdd_ioctl(k0, KBADDKBD, (caddr_t) &ki);
3672 idx0 = kbd_allocate("*", unit, (void *)&sc->keyboard, sckbdevent, sc);