2 * Copyright (c) 2009, 2013 The FreeBSD Foundation
5 * This software was developed by Ed Schouten under sponsorship from the
8 * Portions of this software were developed by Oleksandr Rybalko
9 * under sponsorship from the FreeBSD Foundation.
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer.
16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in the
18 * documentation and/or other materials provided with the distribution.
20 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
21 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
24 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 #include <sys/cdefs.h>
34 __FBSDID("$FreeBSD$");
36 #include "opt_compat.h"
38 #include <sys/param.h>
39 #include <sys/consio.h>
40 #include <sys/eventhandler.h>
44 #include <sys/kernel.h>
46 #include <sys/malloc.h>
47 #include <sys/mutex.h>
48 #include <sys/power.h>
51 #include <sys/reboot.h>
52 #include <sys/systm.h>
53 #include <sys/terminal.h>
55 #include <dev/kbd/kbdreg.h>
56 #include <dev/vt/vt.h>
58 #if defined(__i386__) || defined(__amd64__)
59 #include <machine/psl.h>
60 #include <machine/frame.h>
63 static tc_bell_t vtterm_bell;
64 static tc_cursor_t vtterm_cursor;
65 static tc_putchar_t vtterm_putchar;
66 static tc_fill_t vtterm_fill;
67 static tc_copy_t vtterm_copy;
68 static tc_param_t vtterm_param;
69 static tc_done_t vtterm_done;
71 static tc_cnprobe_t vtterm_cnprobe;
72 static tc_cngetc_t vtterm_cngetc;
74 static tc_cngrab_t vtterm_cngrab;
75 static tc_cnungrab_t vtterm_cnungrab;
77 static tc_opened_t vtterm_opened;
78 static tc_ioctl_t vtterm_ioctl;
79 static tc_mmap_t vtterm_mmap;
81 const struct terminal_class vt_termclass = {
82 .tc_bell = vtterm_bell,
83 .tc_cursor = vtterm_cursor,
84 .tc_putchar = vtterm_putchar,
85 .tc_fill = vtterm_fill,
86 .tc_copy = vtterm_copy,
87 .tc_param = vtterm_param,
88 .tc_done = vtterm_done,
90 .tc_cnprobe = vtterm_cnprobe,
91 .tc_cngetc = vtterm_cngetc,
93 .tc_cngrab = vtterm_cngrab,
94 .tc_cnungrab = vtterm_cnungrab,
96 .tc_opened = vtterm_opened,
97 .tc_ioctl = vtterm_ioctl,
98 .tc_mmap = vtterm_mmap,
102 * Use a constant timer of 25 Hz to redraw the screen.
104 * XXX: In theory we should only fire up the timer when there is really
105 * activity. Unfortunately we cannot always start timers. We really
106 * don't want to process kernel messages synchronously, because it
107 * really slows down the system.
109 #define VT_TIMERFREQ 25
111 /* Bell pitch/duration. */
112 #define VT_BELLDURATION ((5 * hz + 99) / 100)
113 #define VT_BELLPITCH 800
115 #define VT_LOCK(vd) mtx_lock(&(vd)->vd_lock)
116 #define VT_UNLOCK(vd) mtx_unlock(&(vd)->vd_lock)
117 #define VT_LOCK_ASSERT(vd, what) mtx_assert(&(vd)->vd_lock, what)
119 #define VT_UNIT(vw) ((vw)->vw_device->vd_unit * VT_MAXWINDOWS + \
122 static SYSCTL_NODE(_kern, OID_AUTO, vt, CTLFLAG_RD, 0, "vt(9) parameters");
123 VT_SYSCTL_INT(enable_altgr, 1, "Enable AltGr key (Do not assume R.Alt as Alt)");
124 VT_SYSCTL_INT(debug, 0, "vt(9) debug level");
125 VT_SYSCTL_INT(deadtimer, 15, "Time to wait busy process in VT_PROCESS mode");
126 VT_SYSCTL_INT(suspendswitch, 1, "Switch to VT0 before suspend");
128 /* Allow to disable some keyboard combinations. */
129 VT_SYSCTL_INT(kbd_halt, 1, "Enable halt keyboard combination. "
130 "See kbdmap(5) to configure.");
131 VT_SYSCTL_INT(kbd_poweroff, 1, "Enable Power Off keyboard combination. "
132 "See kbdmap(5) to configure.");
133 VT_SYSCTL_INT(kbd_reboot, 1, "Enable reboot keyboard combination. "
134 "See kbdmap(5) to configure (typically Ctrl-Alt-Delete).");
135 VT_SYSCTL_INT(kbd_debug, 1, "Enable key combination to enter debugger. "
136 "See kbdmap(5) to configure (typically Ctrl-Alt-Esc).");
137 VT_SYSCTL_INT(kbd_panic, 0, "Enable request to panic. "
138 "See kbdmap(5) to configure.");
140 static struct vt_device vt_consdev;
141 static unsigned int vt_unit = 0;
142 static MALLOC_DEFINE(M_VT, "vt", "vt device");
143 struct vt_device *main_vd = &vt_consdev;
146 extern unsigned int vt_logo_width;
147 extern unsigned int vt_logo_height;
148 extern unsigned int vt_logo_depth;
149 extern unsigned char vt_logo_image[];
152 extern struct vt_font vt_font_default;
153 #ifndef SC_NO_CUTPASTE
154 extern struct vt_mouse_cursor vt_default_mouse_pointer;
157 static int signal_vt_rel(struct vt_window *);
158 static int signal_vt_acq(struct vt_window *);
159 static int finish_vt_rel(struct vt_window *, int, int *);
160 static int finish_vt_acq(struct vt_window *);
161 static int vt_window_switch(struct vt_window *);
162 static int vt_late_window_switch(struct vt_window *);
163 static int vt_proc_alive(struct vt_window *);
164 static void vt_resize(struct vt_device *);
165 static void vt_update_static(void *);
166 #ifndef SC_NO_CUTPASTE
167 static void vt_mouse_paste(void);
169 static void vt_suspend_handler(void *priv);
170 static void vt_resume_handler(void *priv);
172 SET_DECLARE(vt_drv_set, struct vt_driver);
174 #define _VTDEFH MAX(100, PIXEL_HEIGHT(VT_FB_DEFAULT_HEIGHT))
175 #define _VTDEFW MAX(200, PIXEL_WIDTH(VT_FB_DEFAULT_WIDTH))
177 static struct terminal vt_consterm;
178 static struct vt_window vt_conswindow;
179 static struct vt_device vt_consdev = {
182 .vd_flags = VDF_INVALID,
183 .vd_windows = { [VT_CONSWINDOW] = &vt_conswindow, },
184 .vd_curwindow = &vt_conswindow,
187 #ifndef SC_NO_CUTPASTE
193 .vd_mcursor = &vt_default_mouse_pointer,
194 .vd_mcursor_fg = TC_WHITE,
195 .vd_mcursor_bg = TC_BLACK,
198 static term_char_t vt_constextbuf[(_VTDEFW) * (VBF_DEFAULT_HISTORY_SIZE)];
199 static term_char_t *vt_constextbufrows[VBF_DEFAULT_HISTORY_SIZE];
200 static struct vt_window vt_conswindow = {
201 .vw_number = VT_CONSWINDOW,
202 .vw_flags = VWF_CONSOLE,
204 .vb_buffer = &vt_constextbuf[0],
205 .vb_rows = &vt_constextbufrows[0],
206 .vb_history_size = VBF_DEFAULT_HISTORY_SIZE,
209 .vb_flags = VBF_STATIC,
210 .vb_mark_start = {.tp_row = 0, .tp_col = 0,},
211 .vb_mark_end = {.tp_row = 0, .tp_col = 0,},
217 .vw_device = &vt_consdev,
218 .vw_terminal = &vt_consterm,
219 .vw_kbdmode = K_XLATE,
222 static struct terminal vt_consterm = {
223 .tm_class = &vt_termclass,
224 .tm_softc = &vt_conswindow,
227 static struct consdev vt_consterm_consdev = {
228 .cn_ops = &termcn_cnops,
229 .cn_arg = &vt_consterm,
233 /* Add to set of consoles. */
234 DATA_SET(cons_set, vt_consterm_consdev);
237 * Right after kmem is done to allow early drivers to use locking and allocate
240 SYSINIT(vt_update_static, SI_SUB_KMEM, SI_ORDER_ANY, vt_update_static,
242 /* Delay until all devices attached, to not waste time. */
243 SYSINIT(vt_early_cons, SI_SUB_INT_CONFIG_HOOKS, SI_ORDER_ANY, vt_upgrade,
246 /* Initialize locks/mem depended members. */
248 vt_update_static(void *dummy)
251 if (!vty_enabled(VTY_VT))
253 if (main_vd->vd_driver != NULL)
254 printf("VT: running with driver \"%s\".\n",
255 main_vd->vd_driver->vd_name);
257 printf("VT: init without driver.\n");
259 mtx_init(&main_vd->vd_lock, "vtdev", NULL, MTX_DEF);
260 cv_init(&main_vd->vd_winswitch, "vtwswt");
264 vt_schedule_flush(struct vt_device *vd, int ms)
268 /* Default to initial value. */
269 ms = 1000 / VT_TIMERFREQ;
271 callout_schedule(&vd->vd_timer, hz / (1000 / ms));
275 vt_resume_flush_timer(struct vt_device *vd, int ms)
278 if (!(vd->vd_flags & VDF_ASYNC) ||
279 !atomic_cmpset_int(&vd->vd_timer_armed, 0, 1))
282 vt_schedule_flush(vd, ms);
286 vt_suspend_flush_timer(struct vt_device *vd)
289 * As long as this function is called locked, callout_stop()
290 * has the same effect like callout_drain() with regard to
291 * preventing the callback function from executing.
293 VT_LOCK_ASSERT(vd, MA_OWNED);
295 if (!(vd->vd_flags & VDF_ASYNC) ||
296 !atomic_cmpset_int(&vd->vd_timer_armed, 1, 0))
299 callout_stop(&vd->vd_timer);
303 vt_switch_timer(void *arg)
306 vt_late_window_switch((struct vt_window *)arg);
310 vt_save_kbd_mode(struct vt_window *vw, keyboard_t *kbd)
315 ret = kbdd_ioctl(kbd, KDGKBMODE, (caddr_t)&mode);
321 vw->vw_kbdmode = mode;
327 vt_update_kbd_mode(struct vt_window *vw, keyboard_t *kbd)
331 ret = kbdd_ioctl(kbd, KDSKBMODE, (caddr_t)&vw->vw_kbdmode);
339 vt_save_kbd_state(struct vt_window *vw, keyboard_t *kbd)
344 ret = kbdd_ioctl(kbd, KDGKBSTATE, (caddr_t)&state);
350 vw->vw_kbdstate &= ~LOCK_MASK;
351 vw->vw_kbdstate |= state & LOCK_MASK;
357 vt_update_kbd_state(struct vt_window *vw, keyboard_t *kbd)
361 state = vw->vw_kbdstate & LOCK_MASK;
362 ret = kbdd_ioctl(kbd, KDSKBSTATE, (caddr_t)&state);
370 vt_save_kbd_leds(struct vt_window *vw, keyboard_t *kbd)
375 ret = kbdd_ioctl(kbd, KDGETLED, (caddr_t)&leds);
381 vw->vw_kbdstate &= ~LED_MASK;
382 vw->vw_kbdstate |= leds & LED_MASK;
388 vt_update_kbd_leds(struct vt_window *vw, keyboard_t *kbd)
392 leds = vw->vw_kbdstate & LED_MASK;
393 ret = kbdd_ioctl(kbd, KDSETLED, (caddr_t)&leds);
401 vt_window_preswitch(struct vt_window *vw, struct vt_window *curvw)
404 DPRINTF(40, "%s\n", __func__);
405 curvw->vw_switch_to = vw;
406 /* Set timer to allow switch in case when process hang. */
407 callout_reset(&vw->vw_proc_dead_timer, hz * vt_deadtimer,
408 vt_switch_timer, (void *)vw);
409 /* Notify process about vt switch attempt. */
410 DPRINTF(30, "%s: Notify process.\n", __func__);
411 signal_vt_rel(curvw);
417 vt_window_postswitch(struct vt_window *vw)
424 /* vt_late_window_switch will done VT switching for regular case. */
426 vt_late_window_switch(struct vt_window *vw)
430 callout_stop(&vw->vw_proc_dead_timer);
432 ret = vt_window_switch(vw);
436 /* Notify owner process about terminal availability. */
437 if (vw->vw_smode.mode == VT_PROCESS) {
438 ret = vt_window_postswitch(vw);
445 vt_proc_window_switch(struct vt_window *vw)
447 struct vt_window *curvw;
448 struct vt_device *vd;
451 /* Prevent switching to NULL */
453 DPRINTF(30, "%s: Cannot switch: vw is NULL.", __func__);
457 curvw = vd->vd_curwindow;
459 /* Check if virtual terminal is locked */
460 if (curvw->vw_flags & VWF_VTYLOCK)
463 /* Check if switch already in progress */
464 if (curvw->vw_flags & VWF_SWWAIT_REL) {
465 /* Check if switching to same window */
466 if (curvw->vw_switch_to == vw) {
467 DPRINTF(30, "%s: Switch in progress to same vw.", __func__);
468 return (0); /* success */
470 DPRINTF(30, "%s: Switch in progress to different vw.", __func__);
474 /* Avoid switching to already selected window */
476 DPRINTF(30, "%s: Cannot switch: vw == curvw.", __func__);
477 return (0); /* success */
480 /* Ask current process permission to switch away. */
481 if (curvw->vw_smode.mode == VT_PROCESS) {
482 DPRINTF(30, "%s: VT_PROCESS ", __func__);
483 if (vt_proc_alive(curvw) == FALSE) {
484 DPRINTF(30, "Dead. Cleaning.");
487 DPRINTF(30, "%s: Signaling process.\n", __func__);
488 /* Alive, try to ask him. */
489 ret = vt_window_preswitch(vw, curvw);
490 /* Wait for process answer or timeout. */
496 ret = vt_late_window_switch(vw);
500 /* Switch window ignoring process locking. */
502 vt_window_switch(struct vt_window *vw)
504 struct vt_device *vd = vw->vw_device;
505 struct vt_window *curvw = vd->vd_curwindow;
514 if (!(vw->vw_flags & (VWF_OPENED|VWF_CONSOLE))) {
519 vt_suspend_flush_timer(vd);
521 vd->vd_curwindow = vw;
522 vd->vd_flags |= VDF_INVALID;
523 cv_broadcast(&vd->vd_winswitch);
526 if (vd->vd_driver->vd_postswitch)
527 vd->vd_driver->vd_postswitch(vd);
529 vt_resume_flush_timer(vd, 0);
531 /* Restore per-window keyboard mode. */
533 kbd = kbd_get_keyboard(vd->vd_keyboard);
535 if (curvw->vw_kbdmode == K_XLATE)
536 vt_save_kbd_state(curvw, kbd);
538 vt_update_kbd_mode(vw, kbd);
539 vt_update_kbd_state(vw, kbd);
542 DPRINTF(10, "%s(ttyv%d) done\n", __func__, vw->vw_number);
548 vt_termsize(struct vt_device *vd, struct vt_font *vf, term_pos_t *size)
551 size->tp_row = vd->vd_height;
552 size->tp_col = vd->vd_width;
554 size->tp_row /= vf->vf_height;
555 size->tp_col /= vf->vf_width;
560 vt_winsize(struct vt_device *vd, struct vt_font *vf, struct winsize *size)
563 size->ws_row = size->ws_ypixel = vd->vd_height;
564 size->ws_col = size->ws_xpixel = vd->vd_width;
566 size->ws_row /= vf->vf_height;
567 size->ws_col /= vf->vf_width;
572 vt_compute_drawable_area(struct vt_window *vw)
574 struct vt_device *vd;
579 if (vw->vw_font == NULL) {
580 vw->vw_draw_area.tr_begin.tp_col = 0;
581 vw->vw_draw_area.tr_begin.tp_row = 0;
582 vw->vw_draw_area.tr_end.tp_col = vd->vd_width;
583 vw->vw_draw_area.tr_end.tp_row = vd->vd_height;
590 * Compute the drawable area, so that the text is centered on
594 vw->vw_draw_area.tr_begin.tp_col = (vd->vd_width % vf->vf_width) / 2;
595 vw->vw_draw_area.tr_begin.tp_row = (vd->vd_height % vf->vf_height) / 2;
596 vw->vw_draw_area.tr_end.tp_col = vw->vw_draw_area.tr_begin.tp_col +
597 vd->vd_width / vf->vf_width * vf->vf_width;
598 vw->vw_draw_area.tr_end.tp_row = vw->vw_draw_area.tr_begin.tp_row +
599 vd->vd_height / vf->vf_height * vf->vf_height;
603 vt_scroll(struct vt_window *vw, int offset, int whence)
608 if ((vw->vw_flags & VWF_SCROLL) == 0)
611 vt_termsize(vw->vw_device, vw->vw_font, &size);
613 diff = vthistory_seek(&vw->vw_buf, offset, whence);
615 vw->vw_device->vd_flags |= VDF_INVALID;
616 vt_resume_flush_timer(vw->vw_device, 0);
620 vt_machine_kbdevent(int c)
624 case SPCLKEY | DBG: /* kbdmap(5) keyword `debug`. */
626 kdb_enter(KDB_WHY_BREAK, "manual escape to debugger");
628 case SPCLKEY | HALT: /* kbdmap(5) keyword `halt`. */
630 shutdown_nice(RB_HALT);
632 case SPCLKEY | PASTE: /* kbdmap(5) keyword `paste`. */
633 #ifndef SC_NO_CUTPASTE
634 /* Insert text from cut-paste buffer. */
638 case SPCLKEY | PDWN: /* kbdmap(5) keyword `pdwn`. */
640 shutdown_nice(RB_HALT|RB_POWEROFF);
642 case SPCLKEY | PNC: /* kbdmap(5) keyword `panic`. */
644 * Request to immediate panic if sysctl
645 * kern.vt.enable_panic_key allow it.
648 panic("Forced by the panic key");
650 case SPCLKEY | RBT: /* kbdmap(5) keyword `boot`. */
652 shutdown_nice(RB_AUTOBOOT);
654 case SPCLKEY | SPSC: /* kbdmap(5) keyword `spsc`. */
655 /* Force activatation/deactivation of the screen saver. */
658 case SPCLKEY | STBY: /* XXX Not present in kbdcontrol parser. */
659 /* Put machine into Stand-By mode. */
660 power_pm_suspend(POWER_SLEEP_STATE_STANDBY);
662 case SPCLKEY | SUSP: /* kbdmap(5) keyword `susp`. */
663 /* Suspend machine. */
664 power_pm_suspend(POWER_SLEEP_STATE_SUSPEND);
672 vt_scrollmode_kbdevent(struct vt_window *vw, int c, int console)
674 struct vt_device *vd;
678 /* Only special keys handled in ScrollLock mode */
679 if ((c & SPCLKEY) == 0)
685 if (c >= F_SCR && c <= MIN(L_SCR, F_SCR + VT_MAXWINDOWS - 1)) {
686 vw = vd->vd_windows[c - F_SCR];
687 vt_proc_window_switch(vw);
695 /* Turn scrolling off. */
696 vt_scroll(vw, 0, VHS_END);
697 VTBUF_SLCK_DISABLE(&vw->vw_buf);
698 vw->vw_flags &= ~VWF_SCROLL;
701 case FKEY | F(49): /* Home key. */
702 vt_scroll(vw, 0, VHS_SET);
704 case FKEY | F(50): /* Arrow up. */
705 vt_scroll(vw, -1, VHS_CUR);
707 case FKEY | F(51): /* Page up. */
708 vt_termsize(vd, vw->vw_font, &size);
709 vt_scroll(vw, -size.tp_row, VHS_CUR);
711 case FKEY | F(57): /* End key. */
712 vt_scroll(vw, 0, VHS_END);
714 case FKEY | F(58): /* Arrow down. */
715 vt_scroll(vw, 1, VHS_CUR);
717 case FKEY | F(59): /* Page down. */
718 vt_termsize(vd, vw->vw_font, &size);
719 vt_scroll(vw, size.tp_row, VHS_CUR);
728 vt_processkey(keyboard_t *kbd, struct vt_device *vd, int c)
730 struct vt_window *vw = vd->vd_curwindow;
732 #if VT_ALT_TO_ESC_HACK
734 switch (c & ~RELKEY) {
735 case (SPCLKEY | RALT):
736 if (vt_enable_altgr != 0)
738 case (SPCLKEY | LALT):
739 vd->vd_kbstate &= ~ALKED;
741 /* Other keys ignored for RELKEY event. */
744 switch (c & ~RELKEY) {
745 case (SPCLKEY | RALT):
746 if (vt_enable_altgr != 0)
748 case (SPCLKEY | LALT):
749 vd->vd_kbstate |= ALKED;
754 /* Other keys ignored for RELKEY event. */
758 if (vt_machine_kbdevent(c))
761 if (vw->vw_flags & VWF_SCROLL) {
762 vt_scrollmode_kbdevent(vw, c, 0/* Not a console */);
763 /* Scroll mode keys handled, nothing to do more. */
770 if (c >= F_SCR && c <= MIN(L_SCR, F_SCR + VT_MAXWINDOWS - 1)) {
771 vw = vd->vd_windows[c - F_SCR];
772 vt_proc_window_switch(vw);
778 /* Switch to next VT. */
779 c = (vw->vw_number + 1) % VT_MAXWINDOWS;
780 vw = vd->vd_windows[c];
781 vt_proc_window_switch(vw);
784 /* Switch to previous VT. */
785 c = (vw->vw_number + VT_MAXWINDOWS - 1) % VT_MAXWINDOWS;
786 vw = vd->vd_windows[c];
787 vt_proc_window_switch(vw);
790 vt_save_kbd_state(vw, kbd);
792 if (vw->vw_kbdstate & SLKED) {
793 /* Turn scrolling on. */
794 vw->vw_flags |= VWF_SCROLL;
795 VTBUF_SLCK_ENABLE(&vw->vw_buf);
797 /* Turn scrolling off. */
798 vw->vw_flags &= ~VWF_SCROLL;
799 VTBUF_SLCK_DISABLE(&vw->vw_buf);
800 vt_scroll(vw, 0, VHS_END);
805 case FKEY | F(1): case FKEY | F(2): case FKEY | F(3):
806 case FKEY | F(4): case FKEY | F(5): case FKEY | F(6):
807 case FKEY | F(7): case FKEY | F(8): case FKEY | F(9):
808 case FKEY | F(10): case FKEY | F(11): case FKEY | F(12):
809 /* F1 through F12 keys. */
810 terminal_input_special(vw->vw_terminal,
811 TKEY_F1 + c - (FKEY | F(1)));
813 case FKEY | F(49): /* Home key. */
814 terminal_input_special(vw->vw_terminal, TKEY_HOME);
816 case FKEY | F(50): /* Arrow up. */
817 terminal_input_special(vw->vw_terminal, TKEY_UP);
819 case FKEY | F(51): /* Page up. */
820 terminal_input_special(vw->vw_terminal, TKEY_PAGE_UP);
822 case FKEY | F(53): /* Arrow left. */
823 terminal_input_special(vw->vw_terminal, TKEY_LEFT);
825 case FKEY | F(55): /* Arrow right. */
826 terminal_input_special(vw->vw_terminal, TKEY_RIGHT);
828 case FKEY | F(57): /* End key. */
829 terminal_input_special(vw->vw_terminal, TKEY_END);
831 case FKEY | F(58): /* Arrow down. */
832 terminal_input_special(vw->vw_terminal, TKEY_DOWN);
834 case FKEY | F(59): /* Page down. */
835 terminal_input_special(vw->vw_terminal, TKEY_PAGE_DOWN);
837 case FKEY | F(60): /* Insert key. */
838 terminal_input_special(vw->vw_terminal, TKEY_INSERT);
840 case FKEY | F(61): /* Delete key. */
841 terminal_input_special(vw->vw_terminal, TKEY_DELETE);
844 } else if (KEYFLAGS(c) == 0) {
845 /* Don't do UTF-8 conversion when doing raw mode. */
846 if (vw->vw_kbdmode == K_XLATE) {
847 #if VT_ALT_TO_ESC_HACK
848 if (vd->vd_kbstate & ALKED) {
850 * Prepend ESC sequence if one of ALT keys down.
852 terminal_input_char(vw->vw_terminal, 0x1b);
856 terminal_input_char(vw->vw_terminal, KEYCHAR(c));
858 terminal_input_raw(vw->vw_terminal, c);
864 vt_kbdevent(keyboard_t *kbd, int event, void *arg)
866 struct vt_device *vd = arg;
872 case KBDIO_UNLOADING:
874 vd->vd_keyboard = -1;
875 kbd_release(kbd, (void *)vd);
882 while ((c = kbdd_read_char(kbd, 0)) != NOKEY)
883 vt_processkey(kbd, vd, c);
889 vt_allocate_keyboard(struct vt_device *vd)
895 idx0 = kbd_allocate("kbdmux", -1, vd, vt_kbdevent, vd);
897 DPRINTF(20, "%s: kbdmux allocated, idx = %d\n", __func__, idx0);
898 k0 = kbd_get_keyboard(idx0);
900 for (idx = kbd_find_keyboard2("*", -1, 0);
902 idx = kbd_find_keyboard2("*", -1, idx + 1)) {
903 k = kbd_get_keyboard(idx);
905 if (idx == idx0 || KBD_IS_BUSY(k))
908 bzero(&ki, sizeof(ki));
909 strncpy(ki.kb_name, k->kb_name, sizeof(ki.kb_name));
910 ki.kb_name[sizeof(ki.kb_name) - 1] = '\0';
911 ki.kb_unit = k->kb_unit;
913 kbdd_ioctl(k0, KBADDKBD, (caddr_t) &ki);
916 DPRINTF(20, "%s: no kbdmux allocated\n", __func__);
917 idx0 = kbd_allocate("*", -1, vd, vt_kbdevent, vd);
919 DPRINTF(10, "%s: No keyboard found.\n", __func__);
923 vd->vd_keyboard = idx0;
924 DPRINTF(20, "%s: vd_keyboard = %d\n", __func__, vd->vd_keyboard);
930 vtterm_bell(struct terminal *tm)
932 struct vt_window *vw = tm->tm_softc;
933 struct vt_device *vd = vw->vw_device;
935 if (vd->vd_flags & VDF_QUIET_BELL)
938 sysbeep(1193182 / VT_BELLPITCH, VT_BELLDURATION);
942 vtterm_beep(struct terminal *tm, u_int param)
946 if ((param == 0) || ((param & 0xffff) == 0)) {
951 period = ((param >> 16) & 0xffff) * hz / 1000;
952 freq = 1193182 / (param & 0xffff);
954 sysbeep(freq, period);
958 vtterm_cursor(struct terminal *tm, const term_pos_t *p)
960 struct vt_window *vw = tm->tm_softc;
962 vtbuf_cursor_position(&vw->vw_buf, p);
963 vt_resume_flush_timer(vw->vw_device, 0);
967 vtterm_putchar(struct terminal *tm, const term_pos_t *p, term_char_t c)
969 struct vt_window *vw = tm->tm_softc;
971 vtbuf_putchar(&vw->vw_buf, p, c);
972 vt_resume_flush_timer(vw->vw_device, 0);
976 vtterm_fill(struct terminal *tm, const term_rect_t *r, term_char_t c)
978 struct vt_window *vw = tm->tm_softc;
980 vtbuf_fill_locked(&vw->vw_buf, r, c);
981 vt_resume_flush_timer(vw->vw_device, 0);
985 vtterm_copy(struct terminal *tm, const term_rect_t *r,
988 struct vt_window *vw = tm->tm_softc;
990 vtbuf_copy(&vw->vw_buf, r, p);
991 vt_resume_flush_timer(vw->vw_device, 0);
995 vtterm_param(struct terminal *tm, int cmd, unsigned int arg)
997 struct vt_window *vw = tm->tm_softc;
1001 vtbuf_cursor_visibility(&vw->vw_buf, arg);
1002 vt_resume_flush_timer(vw->vw_device, 0);
1005 vw->vw_mouse_level = arg;
1011 vt_determine_colors(term_char_t c, int cursor,
1012 term_color_t *fg, term_color_t *bg)
1019 *fg = TCHAR_FGCOLOR(c);
1020 if (TCHAR_FORMAT(c) & TF_BOLD)
1021 *fg = TCOLOR_LIGHT(*fg);
1022 *bg = TCHAR_BGCOLOR(c);
1024 if (TCHAR_FORMAT(c) & TF_REVERSE)
1036 #ifndef SC_NO_CUTPASTE
1038 vt_is_cursor_in_area(const struct vt_device *vd, const term_rect_t *area)
1040 unsigned int mx, my;
1043 * We use the cursor position saved during the current refresh,
1044 * in case the cursor moved since.
1046 mx = vd->vd_mx_drawn + vd->vd_curwindow->vw_draw_area.tr_begin.tp_col;
1047 my = vd->vd_my_drawn + vd->vd_curwindow->vw_draw_area.tr_begin.tp_row;
1049 if (mx >= area->tr_end.tp_col ||
1050 mx + vd->vd_mcursor->width <= area->tr_begin.tp_col ||
1051 my >= area->tr_end.tp_row ||
1052 my + vd->vd_mcursor->height <= area->tr_begin.tp_row)
1058 vt_mark_mouse_position_as_dirty(struct vt_device *vd)
1061 struct vt_window *vw;
1065 vw = vd->vd_curwindow;
1068 x = vd->vd_mx_drawn;
1069 y = vd->vd_my_drawn;
1072 area.tr_begin.tp_col = x / vf->vf_width;
1073 area.tr_begin.tp_row = y / vf->vf_height;
1074 area.tr_end.tp_col =
1075 ((x + vd->vd_mcursor->width) / vf->vf_width) + 1;
1076 area.tr_end.tp_row =
1077 ((y + vd->vd_mcursor->height) / vf->vf_height) + 1;
1080 * No font loaded (ie. vt_vga operating in textmode).
1082 * FIXME: This fake area needs to be revisited once the
1083 * mouse cursor is supported in vt_vga's textmode.
1085 area.tr_begin.tp_col = x;
1086 area.tr_begin.tp_row = y;
1087 area.tr_end.tp_col = x + 2;
1088 area.tr_end.tp_row = y + 2;
1091 vtbuf_dirty(&vw->vw_buf, &area);
1096 vt_flush(struct vt_device *vd)
1098 struct vt_window *vw;
1102 #ifndef SC_NO_CUTPASTE
1103 int cursor_was_shown, cursor_moved;
1106 vw = vd->vd_curwindow;
1110 if (vd->vd_flags & VDF_SPLASH || vw->vw_flags & VWF_BUSY)
1114 if (((vd->vd_flags & VDF_TEXTMODE) == 0) && (vf == NULL))
1117 #ifndef SC_NO_CUTPASTE
1118 cursor_was_shown = vd->vd_mshown;
1119 cursor_moved = (vd->vd_mx != vd->vd_mx_drawn ||
1120 vd->vd_my != vd->vd_my_drawn);
1122 /* Check if the cursor should be displayed or not. */
1123 if ((vd->vd_flags & VDF_MOUSECURSOR) && /* Mouse support enabled. */
1124 !(vw->vw_flags & VWF_MOUSE_HIDE) && /* Cursor displayed. */
1125 !kdb_active && panicstr == NULL) { /* DDB inactive. */
1132 * If the cursor changed display state or moved, we must mark
1133 * the old position as dirty, so that it's erased.
1135 if (cursor_was_shown != vd->vd_mshown ||
1136 (vd->vd_mshown && cursor_moved))
1137 vt_mark_mouse_position_as_dirty(vd);
1140 * Save position of the mouse cursor. It's used by backends to
1141 * know where to draw the cursor and during the next refresh to
1142 * erase the previous position.
1144 vd->vd_mx_drawn = vd->vd_mx;
1145 vd->vd_my_drawn = vd->vd_my;
1148 * If the cursor is displayed and has moved since last refresh,
1149 * mark the new position as dirty.
1151 if (vd->vd_mshown && cursor_moved)
1152 vt_mark_mouse_position_as_dirty(vd);
1155 vtbuf_undirty(&vw->vw_buf, &tarea);
1156 vt_termsize(vd, vf, &size);
1158 /* Force a full redraw when the screen contents are invalid. */
1159 if (vd->vd_flags & VDF_INVALID) {
1160 tarea.tr_begin.tp_row = tarea.tr_begin.tp_col = 0;
1161 tarea.tr_end = size;
1163 vd->vd_flags &= ~VDF_INVALID;
1166 if (tarea.tr_begin.tp_col < tarea.tr_end.tp_col) {
1167 vd->vd_driver->vd_bitblt_text(vd, vw, &tarea);
1177 struct vt_device *vd;
1181 /* Update screen if required. */
1182 changed = vt_flush(vd);
1184 /* Schedule for next update. */
1186 vt_schedule_flush(vd, 0);
1188 vd->vd_timer_armed = 0;
1192 vtterm_done(struct terminal *tm)
1194 struct vt_window *vw = tm->tm_softc;
1195 struct vt_device *vd = vw->vw_device;
1197 if (kdb_active || panicstr != NULL) {
1198 /* Switch to the debugger. */
1199 if (vd->vd_curwindow != vw) {
1200 vd->vd_curwindow = vw;
1201 vd->vd_flags |= VDF_INVALID;
1202 if (vd->vd_driver->vd_postswitch)
1203 vd->vd_driver->vd_postswitch(vd);
1205 vd->vd_flags &= ~VDF_SPLASH;
1207 } else if (!(vd->vd_flags & VDF_ASYNC)) {
1214 vtterm_splash(struct vt_device *vd)
1216 vt_axis_t top, left;
1218 /* Display a nice boot splash. */
1219 if (!(vd->vd_flags & VDF_TEXTMODE) && (boothowto & RB_MUTE)) {
1221 top = (vd->vd_height - vt_logo_height) / 2;
1222 left = (vd->vd_width - vt_logo_width) / 2;
1223 switch (vt_logo_depth) {
1225 /* XXX: Unhardcode colors! */
1226 vd->vd_driver->vd_bitblt_bmp(vd, vd->vd_curwindow,
1227 vt_logo_image, NULL, vt_logo_width, vt_logo_height,
1228 left, top, TC_WHITE, TC_BLACK);
1230 vd->vd_flags |= VDF_SPLASH;
1237 vtterm_cnprobe(struct terminal *tm, struct consdev *cp)
1239 struct vt_driver *vtd, **vtdlist, *vtdbest = NULL;
1240 struct vt_window *vw = tm->tm_softc;
1241 struct vt_device *vd = vw->vw_device;
1246 if (!vty_enabled(VTY_VT))
1249 if (vd->vd_flags & VDF_INITIALIZED)
1250 /* Initialization already done. */
1253 SET_FOREACH(vtdlist, vt_drv_set) {
1255 if (vtd->vd_probe == NULL)
1257 if (vtd->vd_probe(vd) == CN_DEAD)
1259 if ((vtdbest == NULL) ||
1260 (vtd->vd_priority > vtdbest->vd_priority))
1263 if (vtdbest == NULL) {
1264 cp->cn_pri = CN_DEAD;
1265 vd->vd_flags |= VDF_DEAD;
1267 vd->vd_driver = vtdbest;
1268 cp->cn_pri = vd->vd_driver->vd_init(vd);
1271 /* Check if driver's vt_init return CN_DEAD. */
1272 if (cp->cn_pri == CN_DEAD) {
1273 vd->vd_flags |= VDF_DEAD;
1276 /* Initialize any early-boot keyboard drivers */
1277 kbd_configure(KB_CONF_PROBE_ONLY);
1279 vd->vd_unit = atomic_fetchadd_int(&vt_unit, 1);
1280 vd->vd_windows[VT_CONSWINDOW] = vw;
1281 sprintf(cp->cn_name, "ttyv%r", VT_UNIT(vw));
1283 /* Attach default font if not in TEXTMODE. */
1284 if ((vd->vd_flags & VDF_TEXTMODE) == 0) {
1285 vw->vw_font = vtfont_ref(&vt_font_default);
1286 vt_compute_drawable_area(vw);
1290 * The original screen size was faked (_VTDEFW x _VTDEFH). Now
1291 * that we have the real viewable size, fix it in the static
1294 if (vd->vd_width != 0 && vd->vd_height != 0)
1295 vt_termsize(vd, vw->vw_font, &vw->vw_buf.vb_scr_size);
1297 vtbuf_init_early(&vw->vw_buf);
1298 vt_winsize(vd, vw->vw_font, &wsz);
1299 c = (boothowto & RB_MUTE) == 0 ? TERMINAL_KERN_ATTR :
1301 attr.ta_format = TCHAR_FORMAT(c);
1302 attr.ta_fgcolor = TCHAR_FGCOLOR(c);
1303 attr.ta_bgcolor = TCHAR_BGCOLOR(c);
1304 terminal_set_winsize_blank(tm, &wsz, 1, &attr);
1306 if (vtdbest != NULL) {
1310 vd->vd_flags |= VDF_INITIALIZED;
1315 vtterm_cngetc(struct terminal *tm)
1317 struct vt_window *vw = tm->tm_softc;
1318 struct vt_device *vd = vw->vw_device;
1322 if (vw->vw_kbdsq && *vw->vw_kbdsq)
1323 return (*vw->vw_kbdsq++);
1325 /* Make sure the splash screen is not there. */
1326 if (vd->vd_flags & VDF_SPLASH) {
1328 vd->vd_flags &= ~VDF_SPLASH;
1329 /* Mark screen as invalid to force update */
1330 vd->vd_flags |= VDF_INVALID;
1334 /* Stripped down keyboard handler. */
1335 kbd = kbd_get_keyboard(vd->vd_keyboard);
1339 /* Force keyboard input mode to K_XLATE */
1340 vw->vw_kbdmode = K_XLATE;
1341 vt_update_kbd_mode(vw, kbd);
1343 /* Switch the keyboard to polling to make it work here. */
1344 kbdd_poll(kbd, TRUE);
1345 c = kbdd_read_char(kbd, 0);
1346 kbdd_poll(kbd, FALSE);
1350 if (vw->vw_flags & VWF_SCROLL) {
1351 vt_scrollmode_kbdevent(vw, c, 1/* Console mode */);
1356 /* Stripped down handling of vt_kbdevent(), without locking, etc. */
1360 vt_save_kbd_state(vw, kbd);
1361 if (vw->vw_kbdstate & SLKED) {
1362 /* Turn scrolling on. */
1363 vw->vw_flags |= VWF_SCROLL;
1364 VTBUF_SLCK_ENABLE(&vw->vw_buf);
1366 /* Turn scrolling off. */
1367 vt_scroll(vw, 0, VHS_END);
1368 vw->vw_flags &= ~VWF_SCROLL;
1369 VTBUF_SLCK_DISABLE(&vw->vw_buf);
1372 /* XXX: KDB can handle history. */
1373 case SPCLKEY | FKEY | F(50): /* Arrow up. */
1374 vw->vw_kbdsq = "\x1b[A";
1376 case SPCLKEY | FKEY | F(58): /* Arrow down. */
1377 vw->vw_kbdsq = "\x1b[B";
1379 case SPCLKEY | FKEY | F(55): /* Arrow right. */
1380 vw->vw_kbdsq = "\x1b[C";
1382 case SPCLKEY | FKEY | F(53): /* Arrow left. */
1383 vw->vw_kbdsq = "\x1b[D";
1387 /* Force refresh to make scrollback work. */
1389 } else if (KEYFLAGS(c) == 0) {
1390 return (KEYCHAR(c));
1393 if (vw->vw_kbdsq && *vw->vw_kbdsq)
1394 return (*vw->vw_kbdsq++);
1400 vtterm_cngrab(struct terminal *tm)
1402 struct vt_device *vd;
1403 struct vt_window *vw;
1410 vt_window_switch(vw);
1412 kbd = kbd_get_keyboard(vd->vd_keyboard);
1416 if (vw->vw_grabbed++ > 0)
1420 * Make sure the keyboard is accessible even when the kbd device
1421 * driver is disabled.
1425 /* We shall always use the keyboard in the XLATE mode here. */
1426 vw->vw_prev_kbdmode = vw->vw_kbdmode;
1427 vw->vw_kbdmode = K_XLATE;
1428 vt_update_kbd_mode(vw, kbd);
1430 kbdd_poll(kbd, TRUE);
1434 vtterm_cnungrab(struct terminal *tm)
1436 struct vt_device *vd;
1437 struct vt_window *vw;
1443 kbd = kbd_get_keyboard(vd->vd_keyboard);
1447 if (--vw->vw_grabbed > 0)
1450 kbdd_poll(kbd, FALSE);
1452 vw->vw_kbdmode = vw->vw_prev_kbdmode;
1453 vt_update_kbd_mode(vw, kbd);
1458 vtterm_opened(struct terminal *tm, int opened)
1460 struct vt_window *vw = tm->tm_softc;
1461 struct vt_device *vd = vw->vw_device;
1464 vd->vd_flags &= ~VDF_SPLASH;
1466 vw->vw_flags |= VWF_OPENED;
1468 vw->vw_flags &= ~VWF_OPENED;
1469 /* TODO: finish ACQ/REL */
1475 vt_set_border(struct vt_window *vw, term_color_t c)
1477 struct vt_device *vd = vw->vw_device;
1479 if (vd->vd_driver->vd_drawrect == NULL)
1483 if (vw->vw_draw_area.tr_begin.tp_row > 0)
1484 vd->vd_driver->vd_drawrect(vd,
1486 vd->vd_width - 1, vw->vw_draw_area.tr_begin.tp_row - 1,
1490 if (vw->vw_draw_area.tr_begin.tp_col > 0)
1491 vd->vd_driver->vd_drawrect(vd,
1493 vw->vw_draw_area.tr_begin.tp_col - 1, vd->vd_height - 1,
1497 if (vw->vw_draw_area.tr_end.tp_col < vd->vd_width)
1498 vd->vd_driver->vd_drawrect(vd,
1499 vw->vw_draw_area.tr_end.tp_col - 1, 0,
1500 vd->vd_width - 1, vd->vd_height - 1,
1504 if (vw->vw_draw_area.tr_end.tp_row < vd->vd_height)
1505 vd->vd_driver->vd_drawrect(vd,
1506 0, vw->vw_draw_area.tr_end.tp_row - 1,
1507 vd->vd_width - 1, vd->vd_height - 1,
1514 vt_change_font(struct vt_window *vw, struct vt_font *vf)
1516 struct vt_device *vd = vw->vw_device;
1517 struct terminal *tm = vw->vw_terminal;
1524 * Changing fonts is a little tricky. We must prevent
1525 * simultaneous access to the device, so we must stop
1526 * the display timer and the terminal from accessing.
1527 * We need to switch fonts and grow our screen buffer.
1529 * XXX: Right now the code uses terminal_mute() to
1530 * prevent data from reaching the console driver while
1531 * resizing the screen buffer. This isn't elegant...
1535 if (vw->vw_flags & VWF_BUSY) {
1536 /* Another process is changing the font. */
1540 vw->vw_flags |= VWF_BUSY;
1543 vt_termsize(vd, vf, &size);
1544 vt_winsize(vd, vf, &wsz);
1546 /* Grow the screen buffer and terminal. */
1547 terminal_mute(tm, 1);
1548 vtbuf_grow(&vw->vw_buf, &size, vw->vw_buf.vb_history_size);
1549 terminal_set_winsize_blank(tm, &wsz, 0, NULL);
1550 terminal_set_cursor(tm, &vw->vw_buf.vb_cursor);
1551 terminal_mute(tm, 0);
1553 /* Actually apply the font to the current window. */
1555 if (vw->vw_font != vf && vw->vw_font != NULL && vf != NULL) {
1557 * In case vt_change_font called to update size we don't need
1558 * to update font link.
1560 vtfont_unref(vw->vw_font);
1561 vw->vw_font = vtfont_ref(vf);
1565 * Compute the drawable area and move the mouse cursor inside
1566 * it, in case the new area is smaller than the previous one.
1568 vt_compute_drawable_area(vw);
1569 vd->vd_mx = min(vd->vd_mx,
1570 vw->vw_draw_area.tr_end.tp_col -
1571 vw->vw_draw_area.tr_begin.tp_col - 1);
1572 vd->vd_my = min(vd->vd_my,
1573 vw->vw_draw_area.tr_end.tp_row -
1574 vw->vw_draw_area.tr_begin.tp_row - 1);
1576 /* Force a full redraw the next timer tick. */
1577 if (vd->vd_curwindow == vw) {
1578 vt_set_border(vw, TC_BLACK);
1579 vd->vd_flags |= VDF_INVALID;
1580 vt_resume_flush_timer(vw->vw_device, 0);
1582 vw->vw_flags &= ~VWF_BUSY;
1588 vt_proc_alive(struct vt_window *vw)
1592 if (vw->vw_smode.mode != VT_PROCESS)
1596 if ((p = pfind(vw->vw_pid)) != NULL)
1598 if (vw->vw_proc == p)
1601 vw->vw_smode.mode = VT_AUTO;
1602 DPRINTF(1, "vt controlling process %d died\n", vw->vw_pid);
1609 signal_vt_rel(struct vt_window *vw)
1612 if (vw->vw_smode.mode != VT_PROCESS)
1614 if (vw->vw_proc == NULL || vt_proc_alive(vw) == FALSE) {
1619 vw->vw_flags |= VWF_SWWAIT_REL;
1620 PROC_LOCK(vw->vw_proc);
1621 kern_psignal(vw->vw_proc, vw->vw_smode.relsig);
1622 PROC_UNLOCK(vw->vw_proc);
1623 DPRINTF(1, "sending relsig to %d\n", vw->vw_pid);
1628 signal_vt_acq(struct vt_window *vw)
1631 if (vw->vw_smode.mode != VT_PROCESS)
1633 if (vw == vw->vw_device->vd_windows[VT_CONSWINDOW])
1634 cnavailable(vw->vw_terminal->consdev, FALSE);
1635 if (vw->vw_proc == NULL || vt_proc_alive(vw) == FALSE) {
1640 vw->vw_flags |= VWF_SWWAIT_ACQ;
1641 PROC_LOCK(vw->vw_proc);
1642 kern_psignal(vw->vw_proc, vw->vw_smode.acqsig);
1643 PROC_UNLOCK(vw->vw_proc);
1644 DPRINTF(1, "sending acqsig to %d\n", vw->vw_pid);
1649 finish_vt_rel(struct vt_window *vw, int release, int *s)
1652 if (vw->vw_flags & VWF_SWWAIT_REL) {
1653 vw->vw_flags &= ~VWF_SWWAIT_REL;
1655 callout_drain(&vw->vw_proc_dead_timer);
1656 vt_late_window_switch(vw->vw_switch_to);
1664 finish_vt_acq(struct vt_window *vw)
1667 if (vw->vw_flags & VWF_SWWAIT_ACQ) {
1668 vw->vw_flags &= ~VWF_SWWAIT_ACQ;
1674 #ifndef SC_NO_CUTPASTE
1676 vt_mouse_terminput_button(struct vt_device *vd, int button)
1678 struct vt_window *vw;
1680 char mouseb[6] = "\x1B[M";
1683 vw = vd->vd_curwindow;
1686 /* Translate to char position. */
1687 x = vd->vd_mx / vf->vf_width;
1688 y = vd->vd_my / vf->vf_height;
1689 /* Avoid overflow. */
1690 x = MIN(x, 255 - '!');
1691 y = MIN(y, 255 - '!');
1693 mouseb[3] = ' ' + button;
1694 mouseb[4] = '!' + x;
1695 mouseb[5] = '!' + y;
1697 for (i = 0; i < sizeof(mouseb); i++)
1698 terminal_input_char(vw->vw_terminal, mouseb[i]);
1702 vt_mouse_terminput(struct vt_device *vd, int type, int x, int y, int event,
1707 case MOUSE_BUTTON_EVENT:
1709 /* Mouse button pressed. */
1710 if (event & MOUSE_BUTTON1DOWN)
1711 vt_mouse_terminput_button(vd, 0);
1712 if (event & MOUSE_BUTTON2DOWN)
1713 vt_mouse_terminput_button(vd, 1);
1714 if (event & MOUSE_BUTTON3DOWN)
1715 vt_mouse_terminput_button(vd, 2);
1717 /* Mouse button released. */
1718 vt_mouse_terminput_button(vd, 3);
1722 case MOUSE_MOTION_EVENT:
1723 if (mouse->u.data.z < 0) {
1725 sc_mouse_input_button(vd, 64);
1726 } else if (mouse->u.data.z > 0) {
1728 sc_mouse_input_button(vd, 65);
1741 len = VD_PASTEBUFLEN(main_vd);
1742 buf = VD_PASTEBUF(main_vd);
1743 len /= sizeof(term_char_t);
1744 for (i = 0; i < len; i++) {
1747 terminal_input_char(main_vd->vd_curwindow->vw_terminal,
1753 vt_mouse_event(int type, int x, int y, int event, int cnt, int mlevel)
1755 struct vt_device *vd;
1756 struct vt_window *vw;
1762 vw = vd->vd_curwindow;
1766 if (vw->vw_flags & (VWF_MOUSE_HIDE | VWF_GRAPHICS))
1768 * Either the mouse is disabled, or the window is in
1769 * "graphics mode". The graphics mode is usually set by
1770 * an X server, using the KDSETMODE ioctl.
1774 if (vf == NULL) /* Text mode. */
1778 * TODO: add flag about pointer position changed, to not redraw chars
1779 * under mouse pointer when nothing changed.
1782 if (vw->vw_mouse_level > 0)
1783 vt_mouse_terminput(vd, type, x, y, event, cnt);
1787 case MOUSE_MOTION_EVENT:
1792 vt_termsize(vd, vf, &size);
1797 x = MIN(x, (size.tp_col * vf->vf_width) - 1);
1798 y = MIN(y, (size.tp_row * vf->vf_height) - 1);
1802 if (vd->vd_mstate & MOUSE_BUTTON1DOWN)
1803 vtbuf_set_mark(&vw->vw_buf, VTB_MARK_MOVE,
1804 vd->vd_mx / vf->vf_width,
1805 vd->vd_my / vf->vf_height);
1807 vt_resume_flush_timer(vw->vw_device, 0);
1809 case MOUSE_BUTTON_EVENT:
1817 case MOUSE_BUTTON1DOWN:
1820 mark = VTB_MARK_END;
1822 case 1: /* single click: start cut operation */
1823 mark = VTB_MARK_START;
1825 case 2: /* double click: cut a word */
1826 mark = VTB_MARK_WORD;
1828 case 3: /* triple click: cut a line */
1829 mark = VTB_MARK_ROW;
1833 case VT_MOUSE_PASTEBUTTON:
1842 case VT_MOUSE_EXTENDBUTTON:
1845 if (!(vd->vd_mstate & MOUSE_BUTTON1DOWN))
1846 mark = VTB_MARK_EXTEND;
1851 mark = VTB_MARK_EXTEND;
1859 /* Save buttons state. */
1861 vd->vd_mstate |= event;
1863 vd->vd_mstate &= ~event;
1865 if (vtbuf_set_mark(&vw->vw_buf, mark, vd->vd_mx / vf->vf_width,
1866 vd->vd_my / vf->vf_height) == 1) {
1868 * We have something marked to copy, so update pointer to
1869 * window with selection.
1871 vt_resume_flush_timer(vw->vw_device, 0);
1877 case VTB_MARK_EXTEND:
1880 /* Other types of mark do not require to copy data. */
1884 /* Get current selection size in bytes. */
1885 len = vtbuf_get_marked_len(&vw->vw_buf);
1889 /* Reallocate buffer only if old one is too small. */
1890 if (len > VD_PASTEBUFSZ(vd)) {
1891 VD_PASTEBUF(vd) = realloc(VD_PASTEBUF(vd), len, M_VT,
1893 /* Update buffer size. */
1894 VD_PASTEBUFSZ(vd) = len;
1896 /* Request copy/paste buffer data, no more than `len' */
1897 vtbuf_extract_marked(&vw->vw_buf, VD_PASTEBUF(vd),
1900 VD_PASTEBUFLEN(vd) = len;
1902 /* XXX VD_PASTEBUF(vd) have to be freed on shutdown/unload. */
1907 vt_mouse_state(int show)
1909 struct vt_device *vd;
1910 struct vt_window *vw;
1913 vw = vd->vd_curwindow;
1917 vw->vw_flags |= VWF_MOUSE_HIDE;
1920 vw->vw_flags &= ~VWF_MOUSE_HIDE;
1924 /* Mark mouse position as dirty. */
1925 vt_mark_mouse_position_as_dirty(vd);
1926 vt_resume_flush_timer(vw->vw_device, 0);
1931 vtterm_mmap(struct terminal *tm, vm_ooffset_t offset, vm_paddr_t * paddr,
1932 int nprot, vm_memattr_t *memattr)
1934 struct vt_window *vw = tm->tm_softc;
1935 struct vt_device *vd = vw->vw_device;
1937 if (vd->vd_driver->vd_fb_mmap)
1938 return (vd->vd_driver->vd_fb_mmap(vd, offset, paddr, nprot,
1945 vtterm_ioctl(struct terminal *tm, u_long cmd, caddr_t data,
1948 struct vt_window *vw = tm->tm_softc;
1949 struct vt_device *vd = vw->vw_device;
1952 #if defined(COMPAT_FREEBSD6) || defined(COMPAT_FREEBSD5) || \
1953 defined(COMPAT_FREEBSD4) || defined(COMPAT_43)
1964 cmd = VT_WAITACTIVE;
1990 ival = IOCPARM_IVAL(data);
1991 data = (caddr_t)&ival;
1996 case KDSETRAD: /* set keyboard repeat & delay rates (old) */
1997 if (*(int *)data & ~0x7f)
2002 case GIO_DEADKEYMAP:
2003 case PIO_DEADKEYMAP:
2008 case KDGETREPEAT: /* get keyboard repeat & delay rates */
2009 case KDSETREPEAT: /* set keyboard repeat & delay rates (new) */
2010 case KBADDKBD: /* add/remove keyboard to/from mux */
2015 kbd = kbd_get_keyboard(vd->vd_keyboard);
2017 error = kbdd_ioctl(kbd, cmd, data);
2019 if (error == ENOIOCTL) {
2020 if (cmd == KDGKBTYPE) {
2021 /* always return something? XXX */
2029 case KDGKBSTATE: { /* get keyboard state (locks) */
2032 if (vw == vd->vd_curwindow) {
2034 kbd = kbd_get_keyboard(vd->vd_keyboard);
2036 error = vt_save_kbd_state(vw, kbd);
2043 *(int *)data = vw->vw_kbdstate & LOCK_MASK;
2047 case KDSKBSTATE: { /* set keyboard state (locks) */
2050 state = *(int *)data;
2051 if (state & ~LOCK_MASK)
2054 vw->vw_kbdstate &= ~LOCK_MASK;
2055 vw->vw_kbdstate |= state;
2058 if (vw == vd->vd_curwindow) {
2060 kbd = kbd_get_keyboard(vd->vd_keyboard);
2062 error = vt_update_kbd_state(vw, kbd);
2068 case KDGETLED: { /* get keyboard LED status */
2071 if (vw == vd->vd_curwindow) {
2073 kbd = kbd_get_keyboard(vd->vd_keyboard);
2075 error = vt_save_kbd_leds(vw, kbd);
2082 *(int *)data = vw->vw_kbdstate & LED_MASK;
2086 case KDSETLED: { /* set keyboard LED status */
2089 leds = *(int *)data;
2090 if (leds & ~LED_MASK)
2093 vw->vw_kbdstate &= ~LED_MASK;
2094 vw->vw_kbdstate |= leds;
2097 if (vw == vd->vd_curwindow) {
2099 kbd = kbd_get_keyboard(vd->vd_keyboard);
2101 error = vt_update_kbd_leds(vw, kbd);
2110 if (vw == vd->vd_curwindow) {
2112 kbd = kbd_get_keyboard(vd->vd_keyboard);
2114 error = vt_save_kbd_mode(vw, kbd);
2121 *(int *)data = vw->vw_kbdmode;
2128 mode = *(int *)data;
2133 vw->vw_kbdmode = mode;
2136 if (vw == vd->vd_curwindow) {
2138 kbd = kbd_get_keyboard(vd->vd_keyboard);
2140 error = vt_update_kbd_mode(vw, kbd);
2150 case FBIO_GETWINORG: /* get frame buffer window origin */
2151 case FBIO_GETDISPSTART: /* get display start address */
2152 case FBIO_GETLINEWIDTH: /* get scan line width in bytes */
2153 case FBIO_BLANK: /* blank display */
2154 if (vd->vd_driver->vd_fb_ioctl)
2155 return (vd->vd_driver->vd_fb_ioctl(vd, cmd, data, td));
2157 case CONS_BLANKTIME:
2162 *(int *)data = M_CG640x480;
2164 case CONS_BELLTYPE: /* set bell type sound */
2165 if ((*(int *)data) & CONS_QUIET_BELL)
2166 vd->vd_flags |= VDF_QUIET_BELL;
2168 vd->vd_flags &= ~VDF_QUIET_BELL;
2170 case CONS_GETINFO: {
2171 vid_info_t *vi = (vid_info_t *)data;
2172 if (vi->size != sizeof(struct vid_info))
2175 if (vw == vd->vd_curwindow) {
2176 kbd = kbd_get_keyboard(vd->vd_keyboard);
2178 vt_save_kbd_state(vw, kbd);
2181 vi->m_num = vd->vd_curwindow->vw_number + 1;
2182 vi->mk_keylock = vw->vw_kbdstate & LOCK_MASK;
2183 /* XXX: other fields! */
2187 *(int *)data = 0x200;
2192 case CONS_MOUSECTL: {
2193 mouse_info_t *mouse = (mouse_info_t*)data;
2196 * All the commands except MOUSE_SHOW nd MOUSE_HIDE
2197 * should not be applied to individual TTYs, but only to
2200 switch (mouse->operation) {
2202 if (vd->vd_flags & VDF_MOUSECURSOR) {
2203 vd->vd_flags &= ~VDF_MOUSECURSOR;
2204 #ifndef SC_NO_CUTPASTE
2205 vt_mouse_state(VT_MOUSE_HIDE);
2210 if (!(vd->vd_flags & VDF_MOUSECURSOR)) {
2211 vd->vd_flags |= VDF_MOUSECURSOR;
2212 vd->vd_mx = vd->vd_width / 2;
2213 vd->vd_my = vd->vd_height / 2;
2214 #ifndef SC_NO_CUTPASTE
2215 vt_mouse_state(VT_MOUSE_SHOW);
2226 if (vd->vd_flags & VDF_TEXTMODE)
2229 error = vtfont_load((void *)data, &vf);
2233 error = vt_change_font(vw, vf);
2237 case PIO_VFONT_DEFAULT: {
2238 /* Reset to default font. */
2239 error = vt_change_font(vw, &vt_font_default);
2243 scrmap_t *sm = (scrmap_t *)data;
2245 /* We don't have screen maps, so return a handcrafted one. */
2246 for (i = 0; i < 256; i++)
2252 * FIXME: This implementation is incomplete compared to
2255 switch (*(int *)data) {
2259 vw->vw_flags &= ~VWF_GRAPHICS;
2262 vw->vw_flags |= VWF_GRAPHICS;
2266 case KDENABIO: /* allow io operations */
2267 error = priv_check(td, PRIV_IO);
2270 error = securelevel_gt(td->td_ucred, 0);
2273 #if defined(__i386__)
2274 td->td_frame->tf_eflags |= PSL_IOPL;
2275 #elif defined(__amd64__)
2276 td->td_frame->tf_rflags |= PSL_IOPL;
2279 case KDDISABIO: /* disallow io operations (default) */
2280 #if defined(__i386__)
2281 td->td_frame->tf_eflags &= ~PSL_IOPL;
2282 #elif defined(__amd64__)
2283 td->td_frame->tf_rflags &= ~PSL_IOPL;
2286 case KDMKTONE: /* sound the bell */
2287 vtterm_beep(tm, *(u_int *)data);
2289 case KIOCSOUND: /* make tone (*data) hz */
2292 case CONS_SETKBD: /* set the new keyboard */
2295 if (vd->vd_keyboard != *(int *)data) {
2296 kbd = kbd_get_keyboard(*(int *)data);
2301 i = kbd_allocate(kbd->kb_name, kbd->kb_unit,
2302 (void *)vd, vt_kbdevent, vd);
2304 if (vd->vd_keyboard != -1) {
2305 vt_save_kbd_state(vd->vd_curwindow, kbd);
2306 kbd_release(kbd, (void *)vd);
2308 kbd = kbd_get_keyboard(i);
2309 vd->vd_keyboard = i;
2311 vt_update_kbd_mode(vd->vd_curwindow, kbd);
2312 vt_update_kbd_state(vd->vd_curwindow, kbd);
2314 error = EPERM; /* XXX */
2319 case CONS_RELKBD: /* release the current keyboard */
2322 if (vd->vd_keyboard != -1) {
2323 kbd = kbd_get_keyboard(vd->vd_keyboard);
2328 vt_save_kbd_state(vd->vd_curwindow, kbd);
2329 error = kbd_release(kbd, (void *)vd);
2331 vd->vd_keyboard = -1;
2338 win = *(int *)data - 1;
2339 DPRINTF(5, "%s%d: VT_ACTIVATE ttyv%d ", SC_DRIVER_NAME,
2341 if ((win >= VT_MAXWINDOWS) || (win < 0))
2343 return (vt_proc_window_switch(vd->vd_windows[win]));
2346 *(int *)data = vd->vd_curwindow->vw_number + 1;
2349 *(int *)data = vw->vw_number + 1;
2352 /* TODO: Check current state, switching can be in progress. */
2353 if ((*(int *)data) == 0x01)
2354 vw->vw_flags |= VWF_VTYLOCK;
2355 else if ((*(int *)data) == 0x02)
2356 vw->vw_flags &= ~VWF_VTYLOCK;
2362 for (i = 0; i < VT_MAXWINDOWS; i++) {
2363 vw = vd->vd_windows[i];
2366 if (!(vw->vw_flags & VWF_OPENED)) {
2367 *(int *)data = vw->vw_number + 1;
2374 case VT_WAITACTIVE: {
2379 idx = *(unsigned int *)data;
2380 if (idx > VT_MAXWINDOWS)
2383 vw = vd->vd_windows[idx - 1];
2386 while (vd->vd_curwindow != vw && error == 0)
2387 error = cv_wait_sig(&vd->vd_winswitch, &vd->vd_lock);
2391 case VT_SETMODE: { /* set screen switcher mode */
2392 struct vt_mode *mode;
2395 mode = (struct vt_mode *)data;
2396 DPRINTF(5, "%s%d: VT_SETMODE ", SC_DRIVER_NAME, VT_UNIT(vw));
2397 if (vw->vw_smode.mode == VT_PROCESS) {
2398 p1 = pfind(vw->vw_pid);
2399 if (vw->vw_proc == p1 && vw->vw_proc != td->td_proc) {
2402 DPRINTF(5, "error EPERM\n");
2408 if (mode->mode == VT_AUTO) {
2409 vw->vw_smode.mode = VT_AUTO;
2412 DPRINTF(5, "VT_AUTO, ");
2413 if (vw == vw->vw_device->vd_windows[VT_CONSWINDOW])
2414 cnavailable(vw->vw_terminal->consdev, TRUE);
2415 /* were we in the middle of the vty switching process? */
2416 if (finish_vt_rel(vw, TRUE, &s) == 0)
2417 DPRINTF(5, "reset WAIT_REL, ");
2418 if (finish_vt_acq(vw) == 0)
2419 DPRINTF(5, "reset WAIT_ACQ, ");
2421 } else if (mode->mode == VT_PROCESS) {
2422 if (!ISSIGVALID(mode->relsig) ||
2423 !ISSIGVALID(mode->acqsig) ||
2424 !ISSIGVALID(mode->frsig)) {
2425 DPRINTF(5, "error EINVAL\n");
2428 DPRINTF(5, "VT_PROCESS %d, ", td->td_proc->p_pid);
2429 bcopy(data, &vw->vw_smode, sizeof(struct vt_mode));
2430 vw->vw_proc = td->td_proc;
2431 vw->vw_pid = vw->vw_proc->p_pid;
2432 if (vw == vw->vw_device->vd_windows[VT_CONSWINDOW])
2433 cnavailable(vw->vw_terminal->consdev, FALSE);
2435 DPRINTF(5, "VT_SETMODE failed, unknown mode %d\n",
2442 case VT_GETMODE: /* get screen switcher mode */
2443 bcopy(&vw->vw_smode, data, sizeof(struct vt_mode));
2446 case VT_RELDISP: /* screen switcher ioctl */
2448 * This must be the current vty which is in the VT_PROCESS
2451 if ((vw != vd->vd_curwindow) || (vw->vw_smode.mode !=
2455 /* ...and this process is controlling it. */
2456 if (vw->vw_proc != td->td_proc) {
2460 switch(*(int *)data) {
2461 case VT_FALSE: /* user refuses to release screen, abort */
2462 if ((error = finish_vt_rel(vw, FALSE, &s)) == 0)
2463 DPRINTF(5, "%s%d: VT_RELDISP: VT_FALSE\n",
2464 SC_DRIVER_NAME, VT_UNIT(vw));
2466 case VT_TRUE: /* user has released screen, go on */
2467 /* finish_vt_rel(..., TRUE, ...) should not be locked */
2468 if (vw->vw_flags & VWF_SWWAIT_REL) {
2469 if ((error = finish_vt_rel(vw, TRUE, &s)) == 0)
2470 DPRINTF(5, "%s%d: VT_RELDISP: VT_TRUE\n",
2471 SC_DRIVER_NAME, VT_UNIT(vw));
2476 case VT_ACKACQ: /* acquire acknowledged, switch completed */
2477 if ((error = finish_vt_acq(vw)) == 0)
2478 DPRINTF(5, "%s%d: VT_RELDISP: VT_ACKACQ\n",
2479 SC_DRIVER_NAME, VT_UNIT(vw));
2490 static struct vt_window *
2491 vt_allocate_window(struct vt_device *vd, unsigned int window)
2493 struct vt_window *vw;
2494 struct terminal *tm;
2498 vw = malloc(sizeof *vw, M_VT, M_WAITOK|M_ZERO);
2500 vw->vw_number = window;
2501 vw->vw_kbdmode = K_XLATE;
2503 if ((vd->vd_flags & VDF_TEXTMODE) == 0) {
2504 vw->vw_font = vtfont_ref(&vt_font_default);
2505 vt_compute_drawable_area(vw);
2508 vt_termsize(vd, vw->vw_font, &size);
2509 vt_winsize(vd, vw->vw_font, &wsz);
2510 vtbuf_init(&vw->vw_buf, &size);
2512 tm = vw->vw_terminal = terminal_alloc(&vt_termclass, vw);
2513 terminal_set_winsize(tm, &wsz);
2514 vd->vd_windows[window] = vw;
2515 callout_init(&vw->vw_proc_dead_timer, 0);
2521 vt_upgrade(struct vt_device *vd)
2523 struct vt_window *vw;
2525 int register_handlers;
2527 if (!vty_enabled(VTY_VT))
2529 if (main_vd->vd_driver == NULL)
2532 for (i = 0; i < VT_MAXWINDOWS; i++) {
2533 vw = vd->vd_windows[i];
2536 vw = vt_allocate_window(vd, i);
2538 if (!(vw->vw_flags & VWF_READY)) {
2539 callout_init(&vw->vw_proc_dead_timer, 0);
2540 terminal_maketty(vw->vw_terminal, "v%r", VT_UNIT(vw));
2541 vw->vw_flags |= VWF_READY;
2542 if (vw->vw_flags & VWF_CONSOLE) {
2543 /* For existing console window. */
2544 EVENTHANDLER_REGISTER(shutdown_pre_sync,
2545 vt_window_switch, vw, SHUTDOWN_PRI_DEFAULT);
2551 if (vd->vd_curwindow == NULL)
2552 vd->vd_curwindow = vd->vd_windows[VT_CONSWINDOW];
2554 register_handlers = 0;
2555 if (!(vd->vd_flags & VDF_ASYNC)) {
2556 /* Attach keyboard. */
2557 vt_allocate_keyboard(vd);
2559 /* Init 25 Hz timer. */
2560 callout_init_mtx(&vd->vd_timer, &vd->vd_lock, 0);
2562 /* Start timer when everything ready. */
2563 vd->vd_flags |= VDF_ASYNC;
2564 callout_reset(&vd->vd_timer, hz / VT_TIMERFREQ, vt_timer, vd);
2565 vd->vd_timer_armed = 1;
2566 register_handlers = 1;
2571 /* Refill settings with new sizes. */
2574 if (register_handlers) {
2575 /* Register suspend/resume handlers. */
2576 EVENTHANDLER_REGISTER(power_suspend_early, vt_suspend_handler,
2577 vd, EVENTHANDLER_PRI_ANY);
2578 EVENTHANDLER_REGISTER(power_resume, vt_resume_handler, vd,
2579 EVENTHANDLER_PRI_ANY);
2584 vt_resize(struct vt_device *vd)
2586 struct vt_window *vw;
2589 for (i = 0; i < VT_MAXWINDOWS; i++) {
2590 vw = vd->vd_windows[i];
2592 /* Assign default font to window, if not textmode. */
2593 if (!(vd->vd_flags & VDF_TEXTMODE) && vw->vw_font == NULL)
2594 vw->vw_font = vtfont_ref(&vt_font_default);
2597 /* Resize terminal windows */
2598 while (vt_change_font(vw, vw->vw_font) == EBUSY) {
2599 DPRINTF(100, "%s: vt_change_font() is busy, "
2600 "window %d\n", __func__, i);
2606 vt_allocate(struct vt_driver *drv, void *softc)
2608 struct vt_device *vd;
2610 if (!vty_enabled(VTY_VT))
2613 if (main_vd->vd_driver == NULL) {
2614 main_vd->vd_driver = drv;
2615 printf("VT: initialize with new VT driver \"%s\".\n",
2619 * Check if have rights to replace current driver. For example:
2620 * it is bad idea to replace KMS driver with generic VGA one.
2622 if (drv->vd_priority <= main_vd->vd_driver->vd_priority) {
2623 printf("VT: Driver priority %d too low. Current %d\n ",
2624 drv->vd_priority, main_vd->vd_driver->vd_priority);
2627 printf("VT: Replacing driver \"%s\" with new \"%s\".\n",
2628 main_vd->vd_driver->vd_name, drv->vd_name);
2632 if (vd->vd_flags & VDF_ASYNC) {
2633 /* Stop vt_flush periodic task. */
2635 vt_suspend_flush_timer(vd);
2638 * Mute current terminal until we done. vt_change_font (called
2639 * from vt_resize) will unmute it.
2641 terminal_mute(vd->vd_curwindow->vw_terminal, 1);
2645 * Reset VDF_TEXTMODE flag, driver who require that flag (vt_vga) will
2649 vd->vd_flags &= ~VDF_TEXTMODE;
2651 vd->vd_driver = drv;
2652 vd->vd_softc = softc;
2653 vd->vd_driver->vd_init(vd);
2656 /* Update windows sizes and initialize last items. */
2660 if (vd->vd_flags & VDF_SPLASH)
2664 if (vd->vd_flags & VDF_ASYNC) {
2665 /* Allow to put chars now. */
2666 terminal_mute(vd->vd_curwindow->vw_terminal, 0);
2667 /* Rerun timer for screen updates. */
2668 vt_resume_flush_timer(vd, 0);
2672 * Register as console. If it already registered, cnadd() will ignore
2675 termcn_cnregister(vd->vd_windows[VT_CONSWINDOW]->vw_terminal);
2679 vt_suspend_handler(void *priv)
2681 struct vt_device *vd;
2684 if (vd->vd_driver != NULL && vd->vd_driver->vd_suspend != NULL)
2685 vd->vd_driver->vd_suspend(vd);
2689 vt_resume_handler(void *priv)
2691 struct vt_device *vd;
2694 if (vd->vd_driver != NULL && vd->vd_driver->vd_resume != NULL)
2695 vd->vd_driver->vd_resume(vd);
2699 vt_suspend(struct vt_device *vd)
2703 if (vt_suspendswitch == 0)
2705 /* Save current window. */
2706 vd->vd_savedwindow = vd->vd_curwindow;
2707 /* Ask holding process to free window and switch to console window */
2708 vt_proc_window_switch(vd->vd_windows[VT_CONSWINDOW]);
2710 /* Wait for the window switch to complete. */
2713 while (vd->vd_curwindow != vd->vd_windows[VT_CONSWINDOW] && error == 0)
2714 error = cv_wait_sig(&vd->vd_winswitch, &vd->vd_lock);
2719 vt_resume(struct vt_device *vd)
2722 if (vt_suspendswitch == 0)
2724 /* Switch back to saved window, if any */
2725 vt_proc_window_switch(vd->vd_savedwindow);
2726 vd->vd_savedwindow = NULL;