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(enable_bell, 1, "Enable bell");
125 VT_SYSCTL_INT(debug, 0, "vt(9) debug level");
126 VT_SYSCTL_INT(deadtimer, 15, "Time to wait busy process in VT_PROCESS mode");
127 VT_SYSCTL_INT(suspendswitch, 1, "Switch to VT0 before suspend");
129 /* Allow to disable some keyboard combinations. */
130 VT_SYSCTL_INT(kbd_halt, 1, "Enable halt keyboard combination. "
131 "See kbdmap(5) to configure.");
132 VT_SYSCTL_INT(kbd_poweroff, 1, "Enable Power Off keyboard combination. "
133 "See kbdmap(5) to configure.");
134 VT_SYSCTL_INT(kbd_reboot, 1, "Enable reboot keyboard combination. "
135 "See kbdmap(5) to configure (typically Ctrl-Alt-Delete).");
136 VT_SYSCTL_INT(kbd_debug, 1, "Enable key combination to enter debugger. "
137 "See kbdmap(5) to configure (typically Ctrl-Alt-Esc).");
138 VT_SYSCTL_INT(kbd_panic, 0, "Enable request to panic. "
139 "See kbdmap(5) to configure.");
141 static struct vt_device vt_consdev;
142 static unsigned int vt_unit = 0;
143 static MALLOC_DEFINE(M_VT, "vt", "vt device");
144 struct vt_device *main_vd = &vt_consdev;
147 extern unsigned int vt_logo_width;
148 extern unsigned int vt_logo_height;
149 extern unsigned int vt_logo_depth;
150 extern unsigned char vt_logo_image[];
153 extern struct vt_font vt_font_default;
154 #ifndef SC_NO_CUTPASTE
155 extern struct vt_mouse_cursor vt_default_mouse_pointer;
158 static int signal_vt_rel(struct vt_window *);
159 static int signal_vt_acq(struct vt_window *);
160 static int finish_vt_rel(struct vt_window *, int, int *);
161 static int finish_vt_acq(struct vt_window *);
162 static int vt_window_switch(struct vt_window *);
163 static int vt_late_window_switch(struct vt_window *);
164 static int vt_proc_alive(struct vt_window *);
165 static void vt_resize(struct vt_device *);
166 static void vt_update_static(void *);
167 #ifndef SC_NO_CUTPASTE
168 static void vt_mouse_paste(void);
170 static void vt_suspend_handler(void *priv);
171 static void vt_resume_handler(void *priv);
173 SET_DECLARE(vt_drv_set, struct vt_driver);
175 #define _VTDEFH MAX(100, PIXEL_HEIGHT(VT_FB_DEFAULT_HEIGHT))
176 #define _VTDEFW MAX(200, PIXEL_WIDTH(VT_FB_DEFAULT_WIDTH))
178 static struct terminal vt_consterm;
179 static struct vt_window vt_conswindow;
180 static struct vt_device vt_consdev = {
183 .vd_prev_driver = NULL,
184 .vd_prev_softc = NULL,
185 .vd_flags = VDF_INVALID,
186 .vd_windows = { [VT_CONSWINDOW] = &vt_conswindow, },
187 .vd_curwindow = &vt_conswindow,
190 #ifndef SC_NO_CUTPASTE
196 .vd_mcursor = &vt_default_mouse_pointer,
197 .vd_mcursor_fg = TC_WHITE,
198 .vd_mcursor_bg = TC_BLACK,
201 static term_char_t vt_constextbuf[(_VTDEFW) * (VBF_DEFAULT_HISTORY_SIZE)];
202 static term_char_t *vt_constextbufrows[VBF_DEFAULT_HISTORY_SIZE];
203 static struct vt_window vt_conswindow = {
204 .vw_number = VT_CONSWINDOW,
205 .vw_flags = VWF_CONSOLE,
207 .vb_buffer = &vt_constextbuf[0],
208 .vb_rows = &vt_constextbufrows[0],
209 .vb_history_size = VBF_DEFAULT_HISTORY_SIZE,
212 .vb_flags = VBF_STATIC,
213 .vb_mark_start = {.tp_row = 0, .tp_col = 0,},
214 .vb_mark_end = {.tp_row = 0, .tp_col = 0,},
220 .vw_device = &vt_consdev,
221 .vw_terminal = &vt_consterm,
222 .vw_kbdmode = K_XLATE,
225 static struct terminal vt_consterm = {
226 .tm_class = &vt_termclass,
227 .tm_softc = &vt_conswindow,
230 static struct consdev vt_consterm_consdev = {
231 .cn_ops = &termcn_cnops,
232 .cn_arg = &vt_consterm,
236 /* Add to set of consoles. */
237 DATA_SET(cons_set, vt_consterm_consdev);
240 * Right after kmem is done to allow early drivers to use locking and allocate
243 SYSINIT(vt_update_static, SI_SUB_KMEM, SI_ORDER_ANY, vt_update_static,
245 /* Delay until all devices attached, to not waste time. */
246 SYSINIT(vt_early_cons, SI_SUB_INT_CONFIG_HOOKS, SI_ORDER_ANY, vt_upgrade,
249 /* Initialize locks/mem depended members. */
251 vt_update_static(void *dummy)
254 if (!vty_enabled(VTY_VT))
256 if (main_vd->vd_driver != NULL)
257 printf("VT: running with driver \"%s\".\n",
258 main_vd->vd_driver->vd_name);
260 printf("VT: init without driver.\n");
262 mtx_init(&main_vd->vd_lock, "vtdev", NULL, MTX_DEF);
263 cv_init(&main_vd->vd_winswitch, "vtwswt");
267 vt_schedule_flush(struct vt_device *vd, int ms)
271 /* Default to initial value. */
272 ms = 1000 / VT_TIMERFREQ;
274 callout_schedule(&vd->vd_timer, hz / (1000 / ms));
278 vt_resume_flush_timer(struct vt_device *vd, int ms)
281 if (!(vd->vd_flags & VDF_ASYNC) ||
282 !atomic_cmpset_int(&vd->vd_timer_armed, 0, 1))
285 vt_schedule_flush(vd, ms);
289 vt_suspend_flush_timer(struct vt_device *vd)
292 * As long as this function is called locked, callout_stop()
293 * has the same effect like callout_drain() with regard to
294 * preventing the callback function from executing.
296 VT_LOCK_ASSERT(vd, MA_OWNED);
298 if (!(vd->vd_flags & VDF_ASYNC) ||
299 !atomic_cmpset_int(&vd->vd_timer_armed, 1, 0))
302 callout_stop(&vd->vd_timer);
306 vt_switch_timer(void *arg)
309 vt_late_window_switch((struct vt_window *)arg);
313 vt_save_kbd_mode(struct vt_window *vw, keyboard_t *kbd)
318 ret = kbdd_ioctl(kbd, KDGKBMODE, (caddr_t)&mode);
324 vw->vw_kbdmode = mode;
330 vt_update_kbd_mode(struct vt_window *vw, keyboard_t *kbd)
334 ret = kbdd_ioctl(kbd, KDSKBMODE, (caddr_t)&vw->vw_kbdmode);
342 vt_save_kbd_state(struct vt_window *vw, keyboard_t *kbd)
347 ret = kbdd_ioctl(kbd, KDGKBSTATE, (caddr_t)&state);
353 vw->vw_kbdstate &= ~LOCK_MASK;
354 vw->vw_kbdstate |= state & LOCK_MASK;
360 vt_update_kbd_state(struct vt_window *vw, keyboard_t *kbd)
364 state = vw->vw_kbdstate & LOCK_MASK;
365 ret = kbdd_ioctl(kbd, KDSKBSTATE, (caddr_t)&state);
373 vt_save_kbd_leds(struct vt_window *vw, keyboard_t *kbd)
378 ret = kbdd_ioctl(kbd, KDGETLED, (caddr_t)&leds);
384 vw->vw_kbdstate &= ~LED_MASK;
385 vw->vw_kbdstate |= leds & LED_MASK;
391 vt_update_kbd_leds(struct vt_window *vw, keyboard_t *kbd)
395 leds = vw->vw_kbdstate & LED_MASK;
396 ret = kbdd_ioctl(kbd, KDSETLED, (caddr_t)&leds);
404 vt_window_preswitch(struct vt_window *vw, struct vt_window *curvw)
407 DPRINTF(40, "%s\n", __func__);
408 curvw->vw_switch_to = vw;
409 /* Set timer to allow switch in case when process hang. */
410 callout_reset(&vw->vw_proc_dead_timer, hz * vt_deadtimer,
411 vt_switch_timer, (void *)vw);
412 /* Notify process about vt switch attempt. */
413 DPRINTF(30, "%s: Notify process.\n", __func__);
414 signal_vt_rel(curvw);
420 vt_window_postswitch(struct vt_window *vw)
427 /* vt_late_window_switch will done VT switching for regular case. */
429 vt_late_window_switch(struct vt_window *vw)
433 callout_stop(&vw->vw_proc_dead_timer);
435 ret = vt_window_switch(vw);
439 /* Notify owner process about terminal availability. */
440 if (vw->vw_smode.mode == VT_PROCESS) {
441 ret = vt_window_postswitch(vw);
448 vt_proc_window_switch(struct vt_window *vw)
450 struct vt_window *curvw;
451 struct vt_device *vd;
455 curvw = vd->vd_curwindow;
457 if (curvw->vw_flags & VWF_VTYLOCK)
460 /* Ask current process permission to switch away. */
461 if (curvw->vw_smode.mode == VT_PROCESS) {
462 DPRINTF(30, "%s: VT_PROCESS ", __func__);
463 if (vt_proc_alive(curvw) == FALSE) {
464 DPRINTF(30, "Dead. Cleaning.");
467 DPRINTF(30, "%s: Signaling process.\n", __func__);
468 /* Alive, try to ask him. */
469 ret = vt_window_preswitch(vw, curvw);
470 /* Wait for process answer or timeout. */
476 ret = vt_late_window_switch(vw);
480 /* Switch window ignoring process locking. */
482 vt_window_switch(struct vt_window *vw)
484 struct vt_device *vd = vw->vw_device;
485 struct vt_window *curvw = vd->vd_curwindow;
494 if (!(vw->vw_flags & (VWF_OPENED|VWF_CONSOLE))) {
499 vt_suspend_flush_timer(vd);
501 vd->vd_curwindow = vw;
502 vd->vd_flags |= VDF_INVALID;
503 cv_broadcast(&vd->vd_winswitch);
506 if (vd->vd_driver->vd_postswitch)
507 vd->vd_driver->vd_postswitch(vd);
509 vt_resume_flush_timer(vd, 0);
511 /* Restore per-window keyboard mode. */
513 kbd = kbd_get_keyboard(vd->vd_keyboard);
515 if (curvw->vw_kbdmode == K_XLATE)
516 vt_save_kbd_state(curvw, kbd);
518 vt_update_kbd_mode(vw, kbd);
519 vt_update_kbd_state(vw, kbd);
522 DPRINTF(10, "%s(ttyv%d) done\n", __func__, vw->vw_number);
528 vt_termsize(struct vt_device *vd, struct vt_font *vf, term_pos_t *size)
531 size->tp_row = vd->vd_height;
532 size->tp_col = vd->vd_width;
534 size->tp_row /= vf->vf_height;
535 size->tp_col /= vf->vf_width;
540 vt_winsize(struct vt_device *vd, struct vt_font *vf, struct winsize *size)
543 size->ws_row = size->ws_ypixel = vd->vd_height;
544 size->ws_col = size->ws_xpixel = vd->vd_width;
546 size->ws_row /= vf->vf_height;
547 size->ws_col /= vf->vf_width;
552 vt_compute_drawable_area(struct vt_window *vw)
554 struct vt_device *vd;
559 if (vw->vw_font == NULL) {
560 vw->vw_draw_area.tr_begin.tp_col = 0;
561 vw->vw_draw_area.tr_begin.tp_row = 0;
562 vw->vw_draw_area.tr_end.tp_col = vd->vd_width;
563 vw->vw_draw_area.tr_end.tp_row = vd->vd_height;
570 * Compute the drawable area, so that the text is centered on
574 vw->vw_draw_area.tr_begin.tp_col = (vd->vd_width % vf->vf_width) / 2;
575 vw->vw_draw_area.tr_begin.tp_row = (vd->vd_height % vf->vf_height) / 2;
576 vw->vw_draw_area.tr_end.tp_col = vw->vw_draw_area.tr_begin.tp_col +
577 vd->vd_width / vf->vf_width * vf->vf_width;
578 vw->vw_draw_area.tr_end.tp_row = vw->vw_draw_area.tr_begin.tp_row +
579 vd->vd_height / vf->vf_height * vf->vf_height;
583 vt_scroll(struct vt_window *vw, int offset, int whence)
588 if ((vw->vw_flags & VWF_SCROLL) == 0)
591 vt_termsize(vw->vw_device, vw->vw_font, &size);
593 diff = vthistory_seek(&vw->vw_buf, offset, whence);
595 vw->vw_device->vd_flags |= VDF_INVALID;
596 vt_resume_flush_timer(vw->vw_device, 0);
600 vt_machine_kbdevent(int c)
604 case SPCLKEY | DBG: /* kbdmap(5) keyword `debug`. */
606 kdb_enter(KDB_WHY_BREAK, "manual escape to debugger");
608 case SPCLKEY | HALT: /* kbdmap(5) keyword `halt`. */
610 shutdown_nice(RB_HALT);
612 case SPCLKEY | PASTE: /* kbdmap(5) keyword `paste`. */
613 #ifndef SC_NO_CUTPASTE
614 /* Insert text from cut-paste buffer. */
618 case SPCLKEY | PDWN: /* kbdmap(5) keyword `pdwn`. */
620 shutdown_nice(RB_HALT|RB_POWEROFF);
622 case SPCLKEY | PNC: /* kbdmap(5) keyword `panic`. */
624 * Request to immediate panic if sysctl
625 * kern.vt.enable_panic_key allow it.
628 panic("Forced by the panic key");
630 case SPCLKEY | RBT: /* kbdmap(5) keyword `boot`. */
632 shutdown_nice(RB_AUTOBOOT);
634 case SPCLKEY | SPSC: /* kbdmap(5) keyword `spsc`. */
635 /* Force activatation/deactivation of the screen saver. */
638 case SPCLKEY | STBY: /* XXX Not present in kbdcontrol parser. */
639 /* Put machine into Stand-By mode. */
640 power_pm_suspend(POWER_SLEEP_STATE_STANDBY);
642 case SPCLKEY | SUSP: /* kbdmap(5) keyword `susp`. */
643 /* Suspend machine. */
644 power_pm_suspend(POWER_SLEEP_STATE_SUSPEND);
652 vt_scrollmode_kbdevent(struct vt_window *vw, int c, int console)
654 struct vt_device *vd;
658 /* Only special keys handled in ScrollLock mode */
659 if ((c & SPCLKEY) == 0)
665 if (c >= F_SCR && c <= MIN(L_SCR, F_SCR + VT_MAXWINDOWS - 1)) {
666 vw = vd->vd_windows[c - F_SCR];
668 vt_proc_window_switch(vw);
676 /* Turn scrolling off. */
677 vt_scroll(vw, 0, VHS_END);
678 VTBUF_SLCK_DISABLE(&vw->vw_buf);
679 vw->vw_flags &= ~VWF_SCROLL;
682 case FKEY | F(49): /* Home key. */
683 vt_scroll(vw, 0, VHS_SET);
685 case FKEY | F(50): /* Arrow up. */
686 vt_scroll(vw, -1, VHS_CUR);
688 case FKEY | F(51): /* Page up. */
689 vt_termsize(vd, vw->vw_font, &size);
690 vt_scroll(vw, -size.tp_row, VHS_CUR);
692 case FKEY | F(57): /* End key. */
693 vt_scroll(vw, 0, VHS_END);
695 case FKEY | F(58): /* Arrow down. */
696 vt_scroll(vw, 1, VHS_CUR);
698 case FKEY | F(59): /* Page down. */
699 vt_termsize(vd, vw->vw_font, &size);
700 vt_scroll(vw, size.tp_row, VHS_CUR);
709 vt_processkey(keyboard_t *kbd, struct vt_device *vd, int c)
711 struct vt_window *vw = vd->vd_curwindow;
713 #if VT_ALT_TO_ESC_HACK
715 switch (c & ~RELKEY) {
716 case (SPCLKEY | RALT):
717 if (vt_enable_altgr != 0)
719 case (SPCLKEY | LALT):
720 vd->vd_kbstate &= ~ALKED;
722 /* Other keys ignored for RELKEY event. */
725 switch (c & ~RELKEY) {
726 case (SPCLKEY | RALT):
727 if (vt_enable_altgr != 0)
729 case (SPCLKEY | LALT):
730 vd->vd_kbstate |= ALKED;
735 /* Other keys ignored for RELKEY event. */
739 if (vt_machine_kbdevent(c))
742 if (vw->vw_flags & VWF_SCROLL) {
743 vt_scrollmode_kbdevent(vw, c, 0/* Not a console */);
744 /* Scroll mode keys handled, nothing to do more. */
751 if (c >= F_SCR && c <= MIN(L_SCR, F_SCR + VT_MAXWINDOWS - 1)) {
752 vw = vd->vd_windows[c - F_SCR];
754 vt_proc_window_switch(vw);
760 /* Switch to next VT. */
761 c = (vw->vw_number + 1) % VT_MAXWINDOWS;
762 vw = vd->vd_windows[c];
764 vt_proc_window_switch(vw);
767 /* Switch to previous VT. */
768 c = (vw->vw_number - 1) % VT_MAXWINDOWS;
769 vw = vd->vd_windows[c];
771 vt_proc_window_switch(vw);
774 vt_save_kbd_state(vw, kbd);
776 if (vw->vw_kbdstate & SLKED) {
777 /* Turn scrolling on. */
778 vw->vw_flags |= VWF_SCROLL;
779 VTBUF_SLCK_ENABLE(&vw->vw_buf);
781 /* Turn scrolling off. */
782 vw->vw_flags &= ~VWF_SCROLL;
783 VTBUF_SLCK_DISABLE(&vw->vw_buf);
784 vt_scroll(vw, 0, VHS_END);
789 case FKEY | F(1): case FKEY | F(2): case FKEY | F(3):
790 case FKEY | F(4): case FKEY | F(5): case FKEY | F(6):
791 case FKEY | F(7): case FKEY | F(8): case FKEY | F(9):
792 case FKEY | F(10): case FKEY | F(11): case FKEY | F(12):
793 /* F1 through F12 keys. */
794 terminal_input_special(vw->vw_terminal,
795 TKEY_F1 + c - (FKEY | F(1)));
797 case FKEY | F(49): /* Home key. */
798 terminal_input_special(vw->vw_terminal, TKEY_HOME);
800 case FKEY | F(50): /* Arrow up. */
801 terminal_input_special(vw->vw_terminal, TKEY_UP);
803 case FKEY | F(51): /* Page up. */
804 terminal_input_special(vw->vw_terminal, TKEY_PAGE_UP);
806 case FKEY | F(53): /* Arrow left. */
807 terminal_input_special(vw->vw_terminal, TKEY_LEFT);
809 case FKEY | F(55): /* Arrow right. */
810 terminal_input_special(vw->vw_terminal, TKEY_RIGHT);
812 case FKEY | F(57): /* End key. */
813 terminal_input_special(vw->vw_terminal, TKEY_END);
815 case FKEY | F(58): /* Arrow down. */
816 terminal_input_special(vw->vw_terminal, TKEY_DOWN);
818 case FKEY | F(59): /* Page down. */
819 terminal_input_special(vw->vw_terminal, TKEY_PAGE_DOWN);
821 case FKEY | F(60): /* Insert key. */
822 terminal_input_special(vw->vw_terminal, TKEY_INSERT);
824 case FKEY | F(61): /* Delete key. */
825 terminal_input_special(vw->vw_terminal, TKEY_DELETE);
828 } else if (KEYFLAGS(c) == 0) {
829 /* Don't do UTF-8 conversion when doing raw mode. */
830 if (vw->vw_kbdmode == K_XLATE) {
831 #if VT_ALT_TO_ESC_HACK
832 if (vd->vd_kbstate & ALKED) {
834 * Prepend ESC sequence if one of ALT keys down.
836 terminal_input_char(vw->vw_terminal, 0x1b);
840 kdb_alt_break(c, &vd->vd_altbrk);
842 terminal_input_char(vw->vw_terminal, KEYCHAR(c));
844 terminal_input_raw(vw->vw_terminal, c);
850 vt_kbdevent(keyboard_t *kbd, int event, void *arg)
852 struct vt_device *vd = arg;
858 case KBDIO_UNLOADING:
860 vd->vd_keyboard = -1;
861 kbd_release(kbd, (void *)vd);
868 while ((c = kbdd_read_char(kbd, 0)) != NOKEY)
869 vt_processkey(kbd, vd, c);
875 vt_allocate_keyboard(struct vt_device *vd)
881 idx0 = kbd_allocate("kbdmux", -1, vd, vt_kbdevent, vd);
883 DPRINTF(20, "%s: kbdmux allocated, idx = %d\n", __func__, idx0);
884 k0 = kbd_get_keyboard(idx0);
886 for (idx = kbd_find_keyboard2("*", -1, 0);
888 idx = kbd_find_keyboard2("*", -1, idx + 1)) {
889 k = kbd_get_keyboard(idx);
891 if (idx == idx0 || KBD_IS_BUSY(k))
894 bzero(&ki, sizeof(ki));
895 strncpy(ki.kb_name, k->kb_name, sizeof(ki.kb_name));
896 ki.kb_name[sizeof(ki.kb_name) - 1] = '\0';
897 ki.kb_unit = k->kb_unit;
899 kbdd_ioctl(k0, KBADDKBD, (caddr_t) &ki);
902 DPRINTF(20, "%s: no kbdmux allocated\n", __func__);
903 idx0 = kbd_allocate("*", -1, vd, vt_kbdevent, vd);
905 DPRINTF(10, "%s: No keyboard found.\n", __func__);
909 vd->vd_keyboard = idx0;
910 DPRINTF(20, "%s: vd_keyboard = %d\n", __func__, vd->vd_keyboard);
916 vtterm_bell(struct terminal *tm)
918 struct vt_window *vw = tm->tm_softc;
919 struct vt_device *vd = vw->vw_device;
924 if (vd->vd_flags & VDF_QUIET_BELL)
927 sysbeep(1193182 / VT_BELLPITCH, VT_BELLDURATION);
931 vtterm_beep(struct terminal *tm, u_int param)
938 if ((param == 0) || ((param & 0xffff) == 0)) {
943 period = ((param >> 16) & 0xffff) * hz / 1000;
944 freq = 1193182 / (param & 0xffff);
946 sysbeep(freq, period);
950 vtterm_cursor(struct terminal *tm, const term_pos_t *p)
952 struct vt_window *vw = tm->tm_softc;
954 vtbuf_cursor_position(&vw->vw_buf, p);
955 vt_resume_flush_timer(vw->vw_device, 0);
959 vtterm_putchar(struct terminal *tm, const term_pos_t *p, term_char_t c)
961 struct vt_window *vw = tm->tm_softc;
963 vtbuf_putchar(&vw->vw_buf, p, c);
964 vt_resume_flush_timer(vw->vw_device, 0);
968 vtterm_fill(struct terminal *tm, const term_rect_t *r, term_char_t c)
970 struct vt_window *vw = tm->tm_softc;
972 vtbuf_fill_locked(&vw->vw_buf, r, c);
973 vt_resume_flush_timer(vw->vw_device, 0);
977 vtterm_copy(struct terminal *tm, const term_rect_t *r,
980 struct vt_window *vw = tm->tm_softc;
982 vtbuf_copy(&vw->vw_buf, r, p);
983 vt_resume_flush_timer(vw->vw_device, 0);
987 vtterm_param(struct terminal *tm, int cmd, unsigned int arg)
989 struct vt_window *vw = tm->tm_softc;
993 vtbuf_cursor_visibility(&vw->vw_buf, arg);
994 vt_resume_flush_timer(vw->vw_device, 0);
997 vw->vw_mouse_level = arg;
1003 vt_determine_colors(term_char_t c, int cursor,
1004 term_color_t *fg, term_color_t *bg)
1011 *fg = TCHAR_FGCOLOR(c);
1012 if (TCHAR_FORMAT(c) & TF_BOLD)
1013 *fg = TCOLOR_LIGHT(*fg);
1014 *bg = TCHAR_BGCOLOR(c);
1016 if (TCHAR_FORMAT(c) & TF_REVERSE)
1028 #ifndef SC_NO_CUTPASTE
1030 vt_is_cursor_in_area(const struct vt_device *vd, const term_rect_t *area)
1032 unsigned int mx, my;
1035 * We use the cursor position saved during the current refresh,
1036 * in case the cursor moved since.
1038 mx = vd->vd_mx_drawn + vd->vd_curwindow->vw_draw_area.tr_begin.tp_col;
1039 my = vd->vd_my_drawn + vd->vd_curwindow->vw_draw_area.tr_begin.tp_row;
1041 if (mx >= area->tr_end.tp_col ||
1042 mx + vd->vd_mcursor->width <= area->tr_begin.tp_col ||
1043 my >= area->tr_end.tp_row ||
1044 my + vd->vd_mcursor->height <= area->tr_begin.tp_row)
1050 vt_mark_mouse_position_as_dirty(struct vt_device *vd)
1053 struct vt_window *vw;
1057 vw = vd->vd_curwindow;
1060 x = vd->vd_mx_drawn;
1061 y = vd->vd_my_drawn;
1064 area.tr_begin.tp_col = x / vf->vf_width;
1065 area.tr_begin.tp_row = y / vf->vf_height;
1066 area.tr_end.tp_col =
1067 ((x + vd->vd_mcursor->width) / vf->vf_width) + 1;
1068 area.tr_end.tp_row =
1069 ((y + vd->vd_mcursor->height) / vf->vf_height) + 1;
1072 * No font loaded (ie. vt_vga operating in textmode).
1074 * FIXME: This fake area needs to be revisited once the
1075 * mouse cursor is supported in vt_vga's textmode.
1077 area.tr_begin.tp_col = x;
1078 area.tr_begin.tp_row = y;
1079 area.tr_end.tp_col = x + 2;
1080 area.tr_end.tp_row = y + 2;
1083 vtbuf_dirty(&vw->vw_buf, &area);
1088 vt_flush(struct vt_device *vd)
1090 struct vt_window *vw;
1094 #ifndef SC_NO_CUTPASTE
1095 int cursor_was_shown, cursor_moved;
1098 vw = vd->vd_curwindow;
1102 if (vd->vd_flags & VDF_SPLASH || vw->vw_flags & VWF_BUSY)
1106 if (((vd->vd_flags & VDF_TEXTMODE) == 0) && (vf == NULL))
1109 #ifndef SC_NO_CUTPASTE
1110 cursor_was_shown = vd->vd_mshown;
1111 cursor_moved = (vd->vd_mx != vd->vd_mx_drawn ||
1112 vd->vd_my != vd->vd_my_drawn);
1114 /* Check if the cursor should be displayed or not. */
1115 if ((vd->vd_flags & VDF_MOUSECURSOR) && /* Mouse support enabled. */
1116 !(vw->vw_flags & VWF_MOUSE_HIDE) && /* Cursor displayed. */
1117 !kdb_active && panicstr == NULL) { /* DDB inactive. */
1124 * If the cursor changed display state or moved, we must mark
1125 * the old position as dirty, so that it's erased.
1127 if (cursor_was_shown != vd->vd_mshown ||
1128 (vd->vd_mshown && cursor_moved))
1129 vt_mark_mouse_position_as_dirty(vd);
1132 * Save position of the mouse cursor. It's used by backends to
1133 * know where to draw the cursor and during the next refresh to
1134 * erase the previous position.
1136 vd->vd_mx_drawn = vd->vd_mx;
1137 vd->vd_my_drawn = vd->vd_my;
1140 * If the cursor is displayed and has moved since last refresh,
1141 * mark the new position as dirty.
1143 if (vd->vd_mshown && cursor_moved)
1144 vt_mark_mouse_position_as_dirty(vd);
1147 vtbuf_undirty(&vw->vw_buf, &tarea);
1148 vt_termsize(vd, vf, &size);
1150 /* Force a full redraw when the screen contents are invalid. */
1151 if (vd->vd_flags & VDF_INVALID) {
1152 tarea.tr_begin.tp_row = tarea.tr_begin.tp_col = 0;
1153 tarea.tr_end = size;
1155 vd->vd_flags &= ~VDF_INVALID;
1158 if (tarea.tr_begin.tp_col < tarea.tr_end.tp_col) {
1159 vd->vd_driver->vd_bitblt_text(vd, vw, &tarea);
1169 struct vt_device *vd;
1173 /* Update screen if required. */
1174 changed = vt_flush(vd);
1176 /* Schedule for next update. */
1178 vt_schedule_flush(vd, 0);
1180 vd->vd_timer_armed = 0;
1184 vtterm_done(struct terminal *tm)
1186 struct vt_window *vw = tm->tm_softc;
1187 struct vt_device *vd = vw->vw_device;
1189 if (kdb_active || panicstr != NULL) {
1190 /* Switch to the debugger. */
1191 if (vd->vd_curwindow != vw) {
1192 vd->vd_curwindow = vw;
1193 vd->vd_flags |= VDF_INVALID;
1194 if (vd->vd_driver->vd_postswitch)
1195 vd->vd_driver->vd_postswitch(vd);
1197 vd->vd_flags &= ~VDF_SPLASH;
1199 } else if (!(vd->vd_flags & VDF_ASYNC)) {
1206 vtterm_splash(struct vt_device *vd)
1208 vt_axis_t top, left;
1210 /* Display a nice boot splash. */
1211 if (!(vd->vd_flags & VDF_TEXTMODE) && (boothowto & RB_MUTE)) {
1213 top = (vd->vd_height - vt_logo_height) / 2;
1214 left = (vd->vd_width - vt_logo_width) / 2;
1215 switch (vt_logo_depth) {
1217 /* XXX: Unhardcode colors! */
1218 vd->vd_driver->vd_bitblt_bmp(vd, vd->vd_curwindow,
1219 vt_logo_image, NULL, vt_logo_width, vt_logo_height,
1220 left, top, TC_WHITE, TC_BLACK);
1222 vd->vd_flags |= VDF_SPLASH;
1229 vtterm_cnprobe(struct terminal *tm, struct consdev *cp)
1231 struct vt_driver *vtd, **vtdlist, *vtdbest = NULL;
1232 struct vt_window *vw = tm->tm_softc;
1233 struct vt_device *vd = vw->vw_device;
1238 if (!vty_enabled(VTY_VT))
1241 if (vd->vd_flags & VDF_INITIALIZED)
1242 /* Initialization already done. */
1245 SET_FOREACH(vtdlist, vt_drv_set) {
1247 if (vtd->vd_probe == NULL)
1249 if (vtd->vd_probe(vd) == CN_DEAD)
1251 if ((vtdbest == NULL) ||
1252 (vtd->vd_priority > vtdbest->vd_priority))
1255 if (vtdbest == NULL) {
1256 cp->cn_pri = CN_DEAD;
1257 vd->vd_flags |= VDF_DEAD;
1259 vd->vd_driver = vtdbest;
1260 cp->cn_pri = vd->vd_driver->vd_init(vd);
1263 /* Check if driver's vt_init return CN_DEAD. */
1264 if (cp->cn_pri == CN_DEAD) {
1265 vd->vd_flags |= VDF_DEAD;
1268 /* Initialize any early-boot keyboard drivers */
1269 kbd_configure(KB_CONF_PROBE_ONLY);
1271 vd->vd_unit = atomic_fetchadd_int(&vt_unit, 1);
1272 vd->vd_windows[VT_CONSWINDOW] = vw;
1273 sprintf(cp->cn_name, "ttyv%r", VT_UNIT(vw));
1275 /* Attach default font if not in TEXTMODE. */
1276 if ((vd->vd_flags & VDF_TEXTMODE) == 0) {
1277 vw->vw_font = vtfont_ref(&vt_font_default);
1278 vt_compute_drawable_area(vw);
1282 * The original screen size was faked (_VTDEFW x _VTDEFH). Now
1283 * that we have the real viewable size, fix it in the static
1286 if (vd->vd_width != 0 && vd->vd_height != 0)
1287 vt_termsize(vd, vw->vw_font, &vw->vw_buf.vb_scr_size);
1289 vtbuf_init_early(&vw->vw_buf);
1290 vt_winsize(vd, vw->vw_font, &wsz);
1291 c = (boothowto & RB_MUTE) == 0 ? TERMINAL_KERN_ATTR :
1293 attr.ta_format = TCHAR_FORMAT(c);
1294 attr.ta_fgcolor = TCHAR_FGCOLOR(c);
1295 attr.ta_bgcolor = TCHAR_BGCOLOR(c);
1296 terminal_set_winsize_blank(tm, &wsz, 1, &attr);
1298 if (vtdbest != NULL) {
1302 vd->vd_flags |= VDF_INITIALIZED;
1307 vtterm_cngetc(struct terminal *tm)
1309 struct vt_window *vw = tm->tm_softc;
1310 struct vt_device *vd = vw->vw_device;
1314 if (vw->vw_kbdsq && *vw->vw_kbdsq)
1315 return (*vw->vw_kbdsq++);
1317 /* Make sure the splash screen is not there. */
1318 if (vd->vd_flags & VDF_SPLASH) {
1320 vd->vd_flags &= ~VDF_SPLASH;
1321 /* Mark screen as invalid to force update */
1322 vd->vd_flags |= VDF_INVALID;
1326 /* Stripped down keyboard handler. */
1327 kbd = kbd_get_keyboard(vd->vd_keyboard);
1331 /* Force keyboard input mode to K_XLATE */
1332 vw->vw_kbdmode = K_XLATE;
1333 vt_update_kbd_mode(vw, kbd);
1335 /* Switch the keyboard to polling to make it work here. */
1336 kbdd_poll(kbd, TRUE);
1337 c = kbdd_read_char(kbd, 0);
1338 kbdd_poll(kbd, FALSE);
1342 if (vw->vw_flags & VWF_SCROLL) {
1343 vt_scrollmode_kbdevent(vw, c, 1/* Console mode */);
1348 /* Stripped down handling of vt_kbdevent(), without locking, etc. */
1352 vt_save_kbd_state(vw, kbd);
1353 if (vw->vw_kbdstate & SLKED) {
1354 /* Turn scrolling on. */
1355 vw->vw_flags |= VWF_SCROLL;
1356 VTBUF_SLCK_ENABLE(&vw->vw_buf);
1358 /* Turn scrolling off. */
1359 vt_scroll(vw, 0, VHS_END);
1360 vw->vw_flags &= ~VWF_SCROLL;
1361 VTBUF_SLCK_DISABLE(&vw->vw_buf);
1364 /* XXX: KDB can handle history. */
1365 case SPCLKEY | FKEY | F(50): /* Arrow up. */
1366 vw->vw_kbdsq = "\x1b[A";
1368 case SPCLKEY | FKEY | F(58): /* Arrow down. */
1369 vw->vw_kbdsq = "\x1b[B";
1371 case SPCLKEY | FKEY | F(55): /* Arrow right. */
1372 vw->vw_kbdsq = "\x1b[C";
1374 case SPCLKEY | FKEY | F(53): /* Arrow left. */
1375 vw->vw_kbdsq = "\x1b[D";
1379 /* Force refresh to make scrollback work. */
1381 } else if (KEYFLAGS(c) == 0) {
1382 return (KEYCHAR(c));
1385 if (vw->vw_kbdsq && *vw->vw_kbdsq)
1386 return (*vw->vw_kbdsq++);
1392 vtterm_cngrab(struct terminal *tm)
1394 struct vt_device *vd;
1395 struct vt_window *vw;
1402 vt_window_switch(vw);
1404 kbd = kbd_get_keyboard(vd->vd_keyboard);
1408 if (vw->vw_grabbed++ > 0)
1412 * Make sure the keyboard is accessible even when the kbd device
1413 * driver is disabled.
1417 /* We shall always use the keyboard in the XLATE mode here. */
1418 vw->vw_prev_kbdmode = vw->vw_kbdmode;
1419 vw->vw_kbdmode = K_XLATE;
1420 vt_update_kbd_mode(vw, kbd);
1422 kbdd_poll(kbd, TRUE);
1426 vtterm_cnungrab(struct terminal *tm)
1428 struct vt_device *vd;
1429 struct vt_window *vw;
1435 kbd = kbd_get_keyboard(vd->vd_keyboard);
1439 if (--vw->vw_grabbed > 0)
1442 kbdd_poll(kbd, FALSE);
1444 vw->vw_kbdmode = vw->vw_prev_kbdmode;
1445 vt_update_kbd_mode(vw, kbd);
1450 vtterm_opened(struct terminal *tm, int opened)
1452 struct vt_window *vw = tm->tm_softc;
1453 struct vt_device *vd = vw->vw_device;
1456 vd->vd_flags &= ~VDF_SPLASH;
1458 vw->vw_flags |= VWF_OPENED;
1460 vw->vw_flags &= ~VWF_OPENED;
1461 /* TODO: finish ACQ/REL */
1467 vt_set_border(struct vt_window *vw, term_color_t c)
1469 struct vt_device *vd = vw->vw_device;
1471 if (vd->vd_driver->vd_drawrect == NULL)
1475 if (vw->vw_draw_area.tr_begin.tp_row > 0)
1476 vd->vd_driver->vd_drawrect(vd,
1478 vd->vd_width - 1, vw->vw_draw_area.tr_begin.tp_row - 1,
1482 if (vw->vw_draw_area.tr_begin.tp_col > 0)
1483 vd->vd_driver->vd_drawrect(vd,
1485 vw->vw_draw_area.tr_begin.tp_col - 1, vd->vd_height - 1,
1489 if (vw->vw_draw_area.tr_end.tp_col < vd->vd_width)
1490 vd->vd_driver->vd_drawrect(vd,
1491 vw->vw_draw_area.tr_end.tp_col - 1, 0,
1492 vd->vd_width - 1, vd->vd_height - 1,
1496 if (vw->vw_draw_area.tr_end.tp_row < vd->vd_height)
1497 vd->vd_driver->vd_drawrect(vd,
1498 0, vw->vw_draw_area.tr_end.tp_row - 1,
1499 vd->vd_width - 1, vd->vd_height - 1,
1506 vt_change_font(struct vt_window *vw, struct vt_font *vf)
1508 struct vt_device *vd = vw->vw_device;
1509 struct terminal *tm = vw->vw_terminal;
1516 * Changing fonts is a little tricky. We must prevent
1517 * simultaneous access to the device, so we must stop
1518 * the display timer and the terminal from accessing.
1519 * We need to switch fonts and grow our screen buffer.
1521 * XXX: Right now the code uses terminal_mute() to
1522 * prevent data from reaching the console driver while
1523 * resizing the screen buffer. This isn't elegant...
1527 if (vw->vw_flags & VWF_BUSY) {
1528 /* Another process is changing the font. */
1532 vw->vw_flags |= VWF_BUSY;
1535 vt_termsize(vd, vf, &size);
1536 vt_winsize(vd, vf, &wsz);
1538 /* Grow the screen buffer and terminal. */
1539 terminal_mute(tm, 1);
1540 vtbuf_grow(&vw->vw_buf, &size, vw->vw_buf.vb_history_size);
1541 terminal_set_winsize_blank(tm, &wsz, 0, NULL);
1542 terminal_set_cursor(tm, &vw->vw_buf.vb_cursor);
1543 terminal_mute(tm, 0);
1545 /* Actually apply the font to the current window. */
1547 if (vw->vw_font != vf && vw->vw_font != NULL && vf != NULL) {
1549 * In case vt_change_font called to update size we don't need
1550 * to update font link.
1552 vtfont_unref(vw->vw_font);
1553 vw->vw_font = vtfont_ref(vf);
1557 * Compute the drawable area and move the mouse cursor inside
1558 * it, in case the new area is smaller than the previous one.
1560 vt_compute_drawable_area(vw);
1561 vd->vd_mx = min(vd->vd_mx,
1562 vw->vw_draw_area.tr_end.tp_col -
1563 vw->vw_draw_area.tr_begin.tp_col - 1);
1564 vd->vd_my = min(vd->vd_my,
1565 vw->vw_draw_area.tr_end.tp_row -
1566 vw->vw_draw_area.tr_begin.tp_row - 1);
1568 /* Force a full redraw the next timer tick. */
1569 if (vd->vd_curwindow == vw) {
1570 vt_set_border(vw, TC_BLACK);
1571 vd->vd_flags |= VDF_INVALID;
1572 vt_resume_flush_timer(vw->vw_device, 0);
1574 vw->vw_flags &= ~VWF_BUSY;
1580 vt_proc_alive(struct vt_window *vw)
1584 if (vw->vw_smode.mode != VT_PROCESS)
1588 if ((p = pfind(vw->vw_pid)) != NULL)
1590 if (vw->vw_proc == p)
1593 vw->vw_smode.mode = VT_AUTO;
1594 DPRINTF(1, "vt controlling process %d died\n", vw->vw_pid);
1601 signal_vt_rel(struct vt_window *vw)
1604 if (vw->vw_smode.mode != VT_PROCESS)
1606 if (vw->vw_proc == NULL || vt_proc_alive(vw) == FALSE) {
1611 vw->vw_flags |= VWF_SWWAIT_REL;
1612 PROC_LOCK(vw->vw_proc);
1613 kern_psignal(vw->vw_proc, vw->vw_smode.relsig);
1614 PROC_UNLOCK(vw->vw_proc);
1615 DPRINTF(1, "sending relsig to %d\n", vw->vw_pid);
1620 signal_vt_acq(struct vt_window *vw)
1623 if (vw->vw_smode.mode != VT_PROCESS)
1625 if (vw == vw->vw_device->vd_windows[VT_CONSWINDOW])
1626 cnavailable(vw->vw_terminal->consdev, FALSE);
1627 if (vw->vw_proc == NULL || vt_proc_alive(vw) == FALSE) {
1632 vw->vw_flags |= VWF_SWWAIT_ACQ;
1633 PROC_LOCK(vw->vw_proc);
1634 kern_psignal(vw->vw_proc, vw->vw_smode.acqsig);
1635 PROC_UNLOCK(vw->vw_proc);
1636 DPRINTF(1, "sending acqsig to %d\n", vw->vw_pid);
1641 finish_vt_rel(struct vt_window *vw, int release, int *s)
1644 if (vw->vw_flags & VWF_SWWAIT_REL) {
1645 vw->vw_flags &= ~VWF_SWWAIT_REL;
1647 callout_drain(&vw->vw_proc_dead_timer);
1648 vt_late_window_switch(vw->vw_switch_to);
1656 finish_vt_acq(struct vt_window *vw)
1659 if (vw->vw_flags & VWF_SWWAIT_ACQ) {
1660 vw->vw_flags &= ~VWF_SWWAIT_ACQ;
1666 #ifndef SC_NO_CUTPASTE
1668 vt_mouse_terminput_button(struct vt_device *vd, int button)
1670 struct vt_window *vw;
1672 char mouseb[6] = "\x1B[M";
1675 vw = vd->vd_curwindow;
1678 /* Translate to char position. */
1679 x = vd->vd_mx / vf->vf_width;
1680 y = vd->vd_my / vf->vf_height;
1681 /* Avoid overflow. */
1682 x = MIN(x, 255 - '!');
1683 y = MIN(y, 255 - '!');
1685 mouseb[3] = ' ' + button;
1686 mouseb[4] = '!' + x;
1687 mouseb[5] = '!' + y;
1689 for (i = 0; i < sizeof(mouseb); i++)
1690 terminal_input_char(vw->vw_terminal, mouseb[i]);
1694 vt_mouse_terminput(struct vt_device *vd, int type, int x, int y, int event,
1699 case MOUSE_BUTTON_EVENT:
1701 /* Mouse button pressed. */
1702 if (event & MOUSE_BUTTON1DOWN)
1703 vt_mouse_terminput_button(vd, 0);
1704 if (event & MOUSE_BUTTON2DOWN)
1705 vt_mouse_terminput_button(vd, 1);
1706 if (event & MOUSE_BUTTON3DOWN)
1707 vt_mouse_terminput_button(vd, 2);
1709 /* Mouse button released. */
1710 vt_mouse_terminput_button(vd, 3);
1714 case MOUSE_MOTION_EVENT:
1715 if (mouse->u.data.z < 0) {
1717 sc_mouse_input_button(vd, 64);
1718 } else if (mouse->u.data.z > 0) {
1720 sc_mouse_input_button(vd, 65);
1733 len = VD_PASTEBUFLEN(main_vd);
1734 buf = VD_PASTEBUF(main_vd);
1735 len /= sizeof(term_char_t);
1736 for (i = 0; i < len; i++) {
1739 terminal_input_char(main_vd->vd_curwindow->vw_terminal,
1745 vt_mouse_event(int type, int x, int y, int event, int cnt, int mlevel)
1747 struct vt_device *vd;
1748 struct vt_window *vw;
1754 vw = vd->vd_curwindow;
1758 if (vw->vw_flags & (VWF_MOUSE_HIDE | VWF_GRAPHICS))
1760 * Either the mouse is disabled, or the window is in
1761 * "graphics mode". The graphics mode is usually set by
1762 * an X server, using the KDSETMODE ioctl.
1766 if (vf == NULL) /* Text mode. */
1770 * TODO: add flag about pointer position changed, to not redraw chars
1771 * under mouse pointer when nothing changed.
1774 if (vw->vw_mouse_level > 0)
1775 vt_mouse_terminput(vd, type, x, y, event, cnt);
1779 case MOUSE_MOTION_EVENT:
1784 vt_termsize(vd, vf, &size);
1789 x = MIN(x, (size.tp_col * vf->vf_width) - 1);
1790 y = MIN(y, (size.tp_row * vf->vf_height) - 1);
1794 if (vd->vd_mstate & MOUSE_BUTTON1DOWN)
1795 vtbuf_set_mark(&vw->vw_buf, VTB_MARK_MOVE,
1796 vd->vd_mx / vf->vf_width,
1797 vd->vd_my / vf->vf_height);
1799 vt_resume_flush_timer(vw->vw_device, 0);
1801 case MOUSE_BUTTON_EVENT:
1809 case MOUSE_BUTTON1DOWN:
1812 mark = VTB_MARK_END;
1814 case 1: /* single click: start cut operation */
1815 mark = VTB_MARK_START;
1817 case 2: /* double click: cut a word */
1818 mark = VTB_MARK_WORD;
1820 case 3: /* triple click: cut a line */
1821 mark = VTB_MARK_ROW;
1825 case VT_MOUSE_PASTEBUTTON:
1834 case VT_MOUSE_EXTENDBUTTON:
1837 if (!(vd->vd_mstate & MOUSE_BUTTON1DOWN))
1838 mark = VTB_MARK_EXTEND;
1843 mark = VTB_MARK_EXTEND;
1851 /* Save buttons state. */
1853 vd->vd_mstate |= event;
1855 vd->vd_mstate &= ~event;
1857 if (vtbuf_set_mark(&vw->vw_buf, mark, vd->vd_mx / vf->vf_width,
1858 vd->vd_my / vf->vf_height) == 1) {
1860 * We have something marked to copy, so update pointer to
1861 * window with selection.
1863 vt_resume_flush_timer(vw->vw_device, 0);
1869 case VTB_MARK_EXTEND:
1872 /* Other types of mark do not require to copy data. */
1876 /* Get current selection size in bytes. */
1877 len = vtbuf_get_marked_len(&vw->vw_buf);
1881 /* Reallocate buffer only if old one is too small. */
1882 if (len > VD_PASTEBUFSZ(vd)) {
1883 VD_PASTEBUF(vd) = realloc(VD_PASTEBUF(vd), len, M_VT,
1885 /* Update buffer size. */
1886 VD_PASTEBUFSZ(vd) = len;
1888 /* Request copy/paste buffer data, no more than `len' */
1889 vtbuf_extract_marked(&vw->vw_buf, VD_PASTEBUF(vd),
1892 VD_PASTEBUFLEN(vd) = len;
1894 /* XXX VD_PASTEBUF(vd) have to be freed on shutdown/unload. */
1899 vt_mouse_state(int show)
1901 struct vt_device *vd;
1902 struct vt_window *vw;
1905 vw = vd->vd_curwindow;
1909 vw->vw_flags |= VWF_MOUSE_HIDE;
1912 vw->vw_flags &= ~VWF_MOUSE_HIDE;
1916 /* Mark mouse position as dirty. */
1917 vt_mark_mouse_position_as_dirty(vd);
1918 vt_resume_flush_timer(vw->vw_device, 0);
1923 vtterm_mmap(struct terminal *tm, vm_ooffset_t offset, vm_paddr_t * paddr,
1924 int nprot, vm_memattr_t *memattr)
1926 struct vt_window *vw = tm->tm_softc;
1927 struct vt_device *vd = vw->vw_device;
1929 if (vd->vd_driver->vd_fb_mmap)
1930 return (vd->vd_driver->vd_fb_mmap(vd, offset, paddr, nprot,
1937 vtterm_ioctl(struct terminal *tm, u_long cmd, caddr_t data,
1940 struct vt_window *vw = tm->tm_softc;
1941 struct vt_device *vd = vw->vw_device;
1944 #if defined(COMPAT_FREEBSD6) || defined(COMPAT_FREEBSD5) || \
1945 defined(COMPAT_FREEBSD4) || defined(COMPAT_43)
1956 cmd = VT_WAITACTIVE;
1982 ival = IOCPARM_IVAL(data);
1983 data = (caddr_t)&ival;
1988 case KDSETRAD: /* set keyboard repeat & delay rates (old) */
1989 if (*(int *)data & ~0x7f)
1994 case GIO_DEADKEYMAP:
1995 case PIO_DEADKEYMAP:
2000 case KDGETREPEAT: /* get keyboard repeat & delay rates */
2001 case KDSETREPEAT: /* set keyboard repeat & delay rates (new) */
2002 case KBADDKBD: /* add/remove keyboard to/from mux */
2007 kbd = kbd_get_keyboard(vd->vd_keyboard);
2009 error = kbdd_ioctl(kbd, cmd, data);
2011 if (error == ENOIOCTL) {
2012 if (cmd == KDGKBTYPE) {
2013 /* always return something? XXX */
2021 case KDGKBSTATE: { /* get keyboard state (locks) */
2024 if (vw == vd->vd_curwindow) {
2026 kbd = kbd_get_keyboard(vd->vd_keyboard);
2028 error = vt_save_kbd_state(vw, kbd);
2035 *(int *)data = vw->vw_kbdstate & LOCK_MASK;
2039 case KDSKBSTATE: { /* set keyboard state (locks) */
2042 state = *(int *)data;
2043 if (state & ~LOCK_MASK)
2046 vw->vw_kbdstate &= ~LOCK_MASK;
2047 vw->vw_kbdstate |= state;
2050 if (vw == vd->vd_curwindow) {
2052 kbd = kbd_get_keyboard(vd->vd_keyboard);
2054 error = vt_update_kbd_state(vw, kbd);
2060 case KDGETLED: { /* get keyboard LED status */
2063 if (vw == vd->vd_curwindow) {
2065 kbd = kbd_get_keyboard(vd->vd_keyboard);
2067 error = vt_save_kbd_leds(vw, kbd);
2074 *(int *)data = vw->vw_kbdstate & LED_MASK;
2078 case KDSETLED: { /* set keyboard LED status */
2081 leds = *(int *)data;
2082 if (leds & ~LED_MASK)
2085 vw->vw_kbdstate &= ~LED_MASK;
2086 vw->vw_kbdstate |= leds;
2089 if (vw == vd->vd_curwindow) {
2091 kbd = kbd_get_keyboard(vd->vd_keyboard);
2093 error = vt_update_kbd_leds(vw, kbd);
2102 if (vw == vd->vd_curwindow) {
2104 kbd = kbd_get_keyboard(vd->vd_keyboard);
2106 error = vt_save_kbd_mode(vw, kbd);
2113 *(int *)data = vw->vw_kbdmode;
2120 mode = *(int *)data;
2125 vw->vw_kbdmode = mode;
2128 if (vw == vd->vd_curwindow) {
2130 kbd = kbd_get_keyboard(vd->vd_keyboard);
2132 error = vt_update_kbd_mode(vw, kbd);
2142 case FBIO_GETWINORG: /* get frame buffer window origin */
2143 case FBIO_GETDISPSTART: /* get display start address */
2144 case FBIO_GETLINEWIDTH: /* get scan line width in bytes */
2145 case FBIO_BLANK: /* blank display */
2146 if (vd->vd_driver->vd_fb_ioctl)
2147 return (vd->vd_driver->vd_fb_ioctl(vd, cmd, data, td));
2149 case CONS_BLANKTIME:
2154 *(int *)data = M_CG640x480;
2156 case CONS_BELLTYPE: /* set bell type sound */
2157 if ((*(int *)data) & CONS_QUIET_BELL)
2158 vd->vd_flags |= VDF_QUIET_BELL;
2160 vd->vd_flags &= ~VDF_QUIET_BELL;
2162 case CONS_GETINFO: {
2163 vid_info_t *vi = (vid_info_t *)data;
2164 if (vi->size != sizeof(struct vid_info))
2167 if (vw == vd->vd_curwindow) {
2168 kbd = kbd_get_keyboard(vd->vd_keyboard);
2170 vt_save_kbd_state(vw, kbd);
2173 vi->m_num = vd->vd_curwindow->vw_number + 1;
2174 vi->mk_keylock = vw->vw_kbdstate & LOCK_MASK;
2175 /* XXX: other fields! */
2179 *(int *)data = 0x200;
2184 case CONS_MOUSECTL: {
2185 mouse_info_t *mouse = (mouse_info_t*)data;
2188 * All the commands except MOUSE_SHOW nd MOUSE_HIDE
2189 * should not be applied to individual TTYs, but only to
2192 switch (mouse->operation) {
2194 if (vd->vd_flags & VDF_MOUSECURSOR) {
2195 vd->vd_flags &= ~VDF_MOUSECURSOR;
2196 #ifndef SC_NO_CUTPASTE
2197 vt_mouse_state(VT_MOUSE_HIDE);
2202 if (!(vd->vd_flags & VDF_MOUSECURSOR)) {
2203 vd->vd_flags |= VDF_MOUSECURSOR;
2204 vd->vd_mx = vd->vd_width / 2;
2205 vd->vd_my = vd->vd_height / 2;
2206 #ifndef SC_NO_CUTPASTE
2207 vt_mouse_state(VT_MOUSE_SHOW);
2218 if (vd->vd_flags & VDF_TEXTMODE)
2221 error = vtfont_load((void *)data, &vf);
2225 error = vt_change_font(vw, vf);
2229 case PIO_VFONT_DEFAULT: {
2230 /* Reset to default font. */
2231 error = vt_change_font(vw, &vt_font_default);
2235 scrmap_t *sm = (scrmap_t *)data;
2237 /* We don't have screen maps, so return a handcrafted one. */
2238 for (i = 0; i < 256; i++)
2244 * FIXME: This implementation is incomplete compared to
2247 switch (*(int *)data) {
2251 vw->vw_flags &= ~VWF_GRAPHICS;
2254 vw->vw_flags |= VWF_GRAPHICS;
2258 case KDENABIO: /* allow io operations */
2259 error = priv_check(td, PRIV_IO);
2262 error = securelevel_gt(td->td_ucred, 0);
2265 #if defined(__i386__)
2266 td->td_frame->tf_eflags |= PSL_IOPL;
2267 #elif defined(__amd64__)
2268 td->td_frame->tf_rflags |= PSL_IOPL;
2271 case KDDISABIO: /* disallow io operations (default) */
2272 #if defined(__i386__)
2273 td->td_frame->tf_eflags &= ~PSL_IOPL;
2274 #elif defined(__amd64__)
2275 td->td_frame->tf_rflags &= ~PSL_IOPL;
2278 case KDMKTONE: /* sound the bell */
2279 vtterm_beep(tm, *(u_int *)data);
2281 case KIOCSOUND: /* make tone (*data) hz */
2284 case CONS_SETKBD: /* set the new keyboard */
2287 if (vd->vd_keyboard != *(int *)data) {
2288 kbd = kbd_get_keyboard(*(int *)data);
2293 i = kbd_allocate(kbd->kb_name, kbd->kb_unit,
2294 (void *)vd, vt_kbdevent, vd);
2296 if (vd->vd_keyboard != -1) {
2297 vt_save_kbd_state(vd->vd_curwindow, kbd);
2298 kbd_release(kbd, (void *)vd);
2300 kbd = kbd_get_keyboard(i);
2301 vd->vd_keyboard = i;
2303 vt_update_kbd_mode(vd->vd_curwindow, kbd);
2304 vt_update_kbd_state(vd->vd_curwindow, kbd);
2306 error = EPERM; /* XXX */
2311 case CONS_RELKBD: /* release the current keyboard */
2314 if (vd->vd_keyboard != -1) {
2315 kbd = kbd_get_keyboard(vd->vd_keyboard);
2320 vt_save_kbd_state(vd->vd_curwindow, kbd);
2321 error = kbd_release(kbd, (void *)vd);
2323 vd->vd_keyboard = -1;
2330 win = *(int *)data - 1;
2331 DPRINTF(5, "%s%d: VT_ACTIVATE ttyv%d ", SC_DRIVER_NAME,
2333 if ((win >= VT_MAXWINDOWS) || (win < 0))
2335 return (vt_proc_window_switch(vd->vd_windows[win]));
2338 *(int *)data = vd->vd_curwindow->vw_number + 1;
2341 *(int *)data = vw->vw_number + 1;
2344 /* TODO: Check current state, switching can be in progress. */
2345 if ((*(int *)data) == 0x01)
2346 vw->vw_flags |= VWF_VTYLOCK;
2347 else if ((*(int *)data) == 0x02)
2348 vw->vw_flags &= ~VWF_VTYLOCK;
2354 for (i = 0; i < VT_MAXWINDOWS; i++) {
2355 vw = vd->vd_windows[i];
2358 if (!(vw->vw_flags & VWF_OPENED)) {
2359 *(int *)data = vw->vw_number + 1;
2366 case VT_WAITACTIVE: {
2371 idx = *(unsigned int *)data;
2372 if (idx > VT_MAXWINDOWS)
2375 vw = vd->vd_windows[idx - 1];
2378 while (vd->vd_curwindow != vw && error == 0)
2379 error = cv_wait_sig(&vd->vd_winswitch, &vd->vd_lock);
2383 case VT_SETMODE: { /* set screen switcher mode */
2384 struct vt_mode *mode;
2387 mode = (struct vt_mode *)data;
2388 DPRINTF(5, "%s%d: VT_SETMODE ", SC_DRIVER_NAME, VT_UNIT(vw));
2389 if (vw->vw_smode.mode == VT_PROCESS) {
2390 p1 = pfind(vw->vw_pid);
2391 if (vw->vw_proc == p1 && vw->vw_proc != td->td_proc) {
2394 DPRINTF(5, "error EPERM\n");
2400 if (mode->mode == VT_AUTO) {
2401 vw->vw_smode.mode = VT_AUTO;
2404 DPRINTF(5, "VT_AUTO, ");
2405 if (vw == vw->vw_device->vd_windows[VT_CONSWINDOW])
2406 cnavailable(vw->vw_terminal->consdev, TRUE);
2407 /* were we in the middle of the vty switching process? */
2408 if (finish_vt_rel(vw, TRUE, &s) == 0)
2409 DPRINTF(5, "reset WAIT_REL, ");
2410 if (finish_vt_acq(vw) == 0)
2411 DPRINTF(5, "reset WAIT_ACQ, ");
2413 } else if (mode->mode == VT_PROCESS) {
2414 if (!ISSIGVALID(mode->relsig) ||
2415 !ISSIGVALID(mode->acqsig) ||
2416 !ISSIGVALID(mode->frsig)) {
2417 DPRINTF(5, "error EINVAL\n");
2420 DPRINTF(5, "VT_PROCESS %d, ", td->td_proc->p_pid);
2421 bcopy(data, &vw->vw_smode, sizeof(struct vt_mode));
2422 vw->vw_proc = td->td_proc;
2423 vw->vw_pid = vw->vw_proc->p_pid;
2424 if (vw == vw->vw_device->vd_windows[VT_CONSWINDOW])
2425 cnavailable(vw->vw_terminal->consdev, FALSE);
2427 DPRINTF(5, "VT_SETMODE failed, unknown mode %d\n",
2434 case VT_GETMODE: /* get screen switcher mode */
2435 bcopy(&vw->vw_smode, data, sizeof(struct vt_mode));
2438 case VT_RELDISP: /* screen switcher ioctl */
2440 * This must be the current vty which is in the VT_PROCESS
2443 if ((vw != vd->vd_curwindow) || (vw->vw_smode.mode !=
2447 /* ...and this process is controlling it. */
2448 if (vw->vw_proc != td->td_proc) {
2452 switch(*(int *)data) {
2453 case VT_FALSE: /* user refuses to release screen, abort */
2454 if ((error = finish_vt_rel(vw, FALSE, &s)) == 0)
2455 DPRINTF(5, "%s%d: VT_RELDISP: VT_FALSE\n",
2456 SC_DRIVER_NAME, VT_UNIT(vw));
2458 case VT_TRUE: /* user has released screen, go on */
2459 /* finish_vt_rel(..., TRUE, ...) should not be locked */
2460 if (vw->vw_flags & VWF_SWWAIT_REL) {
2461 if ((error = finish_vt_rel(vw, TRUE, &s)) == 0)
2462 DPRINTF(5, "%s%d: VT_RELDISP: VT_TRUE\n",
2463 SC_DRIVER_NAME, VT_UNIT(vw));
2468 case VT_ACKACQ: /* acquire acknowledged, switch completed */
2469 if ((error = finish_vt_acq(vw)) == 0)
2470 DPRINTF(5, "%s%d: VT_RELDISP: VT_ACKACQ\n",
2471 SC_DRIVER_NAME, VT_UNIT(vw));
2482 static struct vt_window *
2483 vt_allocate_window(struct vt_device *vd, unsigned int window)
2485 struct vt_window *vw;
2486 struct terminal *tm;
2490 vw = malloc(sizeof *vw, M_VT, M_WAITOK|M_ZERO);
2492 vw->vw_number = window;
2493 vw->vw_kbdmode = K_XLATE;
2495 if ((vd->vd_flags & VDF_TEXTMODE) == 0) {
2496 vw->vw_font = vtfont_ref(&vt_font_default);
2497 vt_compute_drawable_area(vw);
2500 vt_termsize(vd, vw->vw_font, &size);
2501 vt_winsize(vd, vw->vw_font, &wsz);
2502 vtbuf_init(&vw->vw_buf, &size);
2504 tm = vw->vw_terminal = terminal_alloc(&vt_termclass, vw);
2505 terminal_set_winsize(tm, &wsz);
2506 vd->vd_windows[window] = vw;
2507 callout_init(&vw->vw_proc_dead_timer, 0);
2513 vt_upgrade(struct vt_device *vd)
2515 struct vt_window *vw;
2517 int register_handlers;
2519 if (!vty_enabled(VTY_VT))
2521 if (main_vd->vd_driver == NULL)
2524 for (i = 0; i < VT_MAXWINDOWS; i++) {
2525 vw = vd->vd_windows[i];
2528 vw = vt_allocate_window(vd, i);
2530 if (!(vw->vw_flags & VWF_READY)) {
2531 callout_init(&vw->vw_proc_dead_timer, 0);
2532 terminal_maketty(vw->vw_terminal, "v%r", VT_UNIT(vw));
2533 vw->vw_flags |= VWF_READY;
2534 if (vw->vw_flags & VWF_CONSOLE) {
2535 /* For existing console window. */
2536 EVENTHANDLER_REGISTER(shutdown_pre_sync,
2537 vt_window_switch, vw, SHUTDOWN_PRI_DEFAULT);
2543 if (vd->vd_curwindow == NULL)
2544 vd->vd_curwindow = vd->vd_windows[VT_CONSWINDOW];
2546 register_handlers = 0;
2547 if (!(vd->vd_flags & VDF_ASYNC)) {
2548 /* Attach keyboard. */
2549 vt_allocate_keyboard(vd);
2551 /* Init 25 Hz timer. */
2552 callout_init_mtx(&vd->vd_timer, &vd->vd_lock, 0);
2554 /* Start timer when everything ready. */
2555 vd->vd_flags |= VDF_ASYNC;
2556 callout_reset(&vd->vd_timer, hz / VT_TIMERFREQ, vt_timer, vd);
2557 vd->vd_timer_armed = 1;
2558 register_handlers = 1;
2563 /* Refill settings with new sizes. */
2566 if (register_handlers) {
2567 /* Register suspend/resume handlers. */
2568 EVENTHANDLER_REGISTER(power_suspend_early, vt_suspend_handler,
2569 vd, EVENTHANDLER_PRI_ANY);
2570 EVENTHANDLER_REGISTER(power_resume, vt_resume_handler, vd,
2571 EVENTHANDLER_PRI_ANY);
2576 vt_resize(struct vt_device *vd)
2578 struct vt_window *vw;
2581 for (i = 0; i < VT_MAXWINDOWS; i++) {
2582 vw = vd->vd_windows[i];
2584 /* Assign default font to window, if not textmode. */
2585 if (!(vd->vd_flags & VDF_TEXTMODE) && vw->vw_font == NULL)
2586 vw->vw_font = vtfont_ref(&vt_font_default);
2589 /* Resize terminal windows */
2590 while (vt_change_font(vw, vw->vw_font) == EBUSY) {
2591 DPRINTF(100, "%s: vt_change_font() is busy, "
2592 "window %d\n", __func__, i);
2598 vt_replace_backend(const struct vt_driver *drv, void *softc)
2600 struct vt_device *vd;
2604 if (vd->vd_flags & VDF_ASYNC) {
2605 /* Stop vt_flush periodic task. */
2607 vt_suspend_flush_timer(vd);
2610 * Mute current terminal until we done. vt_change_font (called
2611 * from vt_resize) will unmute it.
2613 terminal_mute(vd->vd_curwindow->vw_terminal, 1);
2617 * Reset VDF_TEXTMODE flag, driver who require that flag (vt_vga) will
2621 vd->vd_flags &= ~VDF_TEXTMODE;
2625 * We want to upgrade from the current driver to the
2629 vd->vd_prev_driver = vd->vd_driver;
2630 vd->vd_prev_softc = vd->vd_softc;
2631 vd->vd_driver = drv;
2632 vd->vd_softc = softc;
2634 vd->vd_driver->vd_init(vd);
2635 } else if (vd->vd_prev_driver != NULL && vd->vd_prev_softc != NULL) {
2637 * No driver given: we want to downgrade to the previous
2640 const struct vt_driver *old_drv;
2643 old_drv = vd->vd_driver;
2644 old_softc = vd->vd_softc;
2646 vd->vd_driver = vd->vd_prev_driver;
2647 vd->vd_softc = vd->vd_prev_softc;
2648 vd->vd_prev_driver = NULL;
2649 vd->vd_prev_softc = NULL;
2651 vd->vd_flags |= VDF_DOWNGRADE;
2653 vd->vd_driver->vd_init(vd);
2655 if (old_drv->vd_fini)
2656 old_drv->vd_fini(vd, old_softc);
2658 vd->vd_flags &= ~VDF_DOWNGRADE;
2663 /* Update windows sizes and initialize last items. */
2667 if (vd->vd_flags & VDF_SPLASH)
2671 if (vd->vd_flags & VDF_ASYNC) {
2672 /* Allow to put chars now. */
2673 terminal_mute(vd->vd_curwindow->vw_terminal, 0);
2674 /* Rerun timer for screen updates. */
2675 vt_resume_flush_timer(vd, 0);
2679 * Register as console. If it already registered, cnadd() will ignore
2682 termcn_cnregister(vd->vd_windows[VT_CONSWINDOW]->vw_terminal);
2686 vt_suspend_handler(void *priv)
2688 struct vt_device *vd;
2691 if (vd->vd_driver != NULL && vd->vd_driver->vd_suspend != NULL)
2692 vd->vd_driver->vd_suspend(vd);
2696 vt_resume_handler(void *priv)
2698 struct vt_device *vd;
2701 if (vd->vd_driver != NULL && vd->vd_driver->vd_resume != NULL)
2702 vd->vd_driver->vd_resume(vd);
2706 vt_allocate(const struct vt_driver *drv, void *softc)
2709 if (!vty_enabled(VTY_VT))
2712 if (main_vd->vd_driver == NULL) {
2713 main_vd->vd_driver = drv;
2714 printf("VT: initialize with new VT driver \"%s\".\n",
2718 * Check if have rights to replace current driver. For example:
2719 * it is bad idea to replace KMS driver with generic VGA one.
2721 if (drv->vd_priority <= main_vd->vd_driver->vd_priority) {
2722 printf("VT: Driver priority %d too low. Current %d\n ",
2723 drv->vd_priority, main_vd->vd_driver->vd_priority);
2726 printf("VT: Replacing driver \"%s\" with new \"%s\".\n",
2727 main_vd->vd_driver->vd_name, drv->vd_name);
2730 vt_replace_backend(drv, softc);
2734 vt_deallocate(const struct vt_driver *drv, void *softc)
2737 if (!vty_enabled(VTY_VT))
2740 if (main_vd->vd_prev_driver == NULL ||
2741 main_vd->vd_driver != drv ||
2742 main_vd->vd_softc != softc)
2745 printf("VT: Switching back from \"%s\" to \"%s\".\n",
2746 main_vd->vd_driver->vd_name, main_vd->vd_prev_driver->vd_name);
2748 vt_replace_backend(NULL, NULL);
2752 vt_suspend(struct vt_device *vd)
2756 if (vt_suspendswitch == 0)
2758 /* Save current window. */
2759 vd->vd_savedwindow = vd->vd_curwindow;
2760 /* Ask holding process to free window and switch to console window */
2761 vt_proc_window_switch(vd->vd_windows[VT_CONSWINDOW]);
2763 /* Wait for the window switch to complete. */
2766 while (vd->vd_curwindow != vd->vd_windows[VT_CONSWINDOW] && error == 0)
2767 error = cv_wait_sig(&vd->vd_winswitch, &vd->vd_lock);
2772 vt_resume(struct vt_device *vd)
2775 if (vt_suspendswitch == 0)
2777 /* Switch back to saved window */
2778 if (vd->vd_savedwindow != NULL)
2779 vt_proc_window_switch(vd->vd_savedwindow);
2780 vd->vd_savedwindow = NULL;