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, x1, y1, x2, y2;
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 x1 = area->tr_begin.tp_col;
1042 y1 = area->tr_begin.tp_row;
1043 x2 = area->tr_end.tp_col;
1044 y2 = area->tr_end.tp_row;
1046 if (((mx >= x1 && x2 - 1 >= mx) ||
1047 (mx < x1 && mx + vd->vd_mcursor->width >= x1)) &&
1048 ((my >= y1 && y2 - 1 >= my) ||
1049 (my < y1 && my + vd->vd_mcursor->height >= y1)))
1056 vt_mark_mouse_position_as_dirty(struct vt_device *vd)
1059 struct vt_window *vw;
1063 vw = vd->vd_curwindow;
1066 x = vd->vd_mx_drawn;
1067 y = vd->vd_my_drawn;
1070 area.tr_begin.tp_col = x / vf->vf_width;
1071 area.tr_begin.tp_row = y / vf->vf_height;
1072 area.tr_end.tp_col =
1073 ((x + vd->vd_mcursor->width) / vf->vf_width) + 1;
1074 area.tr_end.tp_row =
1075 ((y + vd->vd_mcursor->height) / vf->vf_height) + 1;
1078 * No font loaded (ie. vt_vga operating in textmode).
1080 * FIXME: This fake area needs to be revisited once the
1081 * mouse cursor is supported in vt_vga's textmode.
1083 area.tr_begin.tp_col = x;
1084 area.tr_begin.tp_row = y;
1085 area.tr_end.tp_col = x + 2;
1086 area.tr_end.tp_row = y + 2;
1089 vtbuf_dirty(&vw->vw_buf, &area);
1094 vt_flush(struct vt_device *vd)
1096 struct vt_window *vw;
1100 #ifndef SC_NO_CUTPASTE
1101 int cursor_was_shown, cursor_moved;
1104 vw = vd->vd_curwindow;
1108 if (vd->vd_flags & VDF_SPLASH || vw->vw_flags & VWF_BUSY)
1112 if (((vd->vd_flags & VDF_TEXTMODE) == 0) && (vf == NULL))
1115 #ifndef SC_NO_CUTPASTE
1116 cursor_was_shown = vd->vd_mshown;
1117 cursor_moved = (vd->vd_mx != vd->vd_mx_drawn ||
1118 vd->vd_my != vd->vd_my_drawn);
1120 /* Check if the cursor should be displayed or not. */
1121 if ((vd->vd_flags & VDF_MOUSECURSOR) && /* Mouse support enabled. */
1122 !(vw->vw_flags & VWF_MOUSE_HIDE) && /* Cursor displayed. */
1123 !kdb_active && panicstr == NULL) { /* DDB inactive. */
1130 * If the cursor changed display state or moved, we must mark
1131 * the old position as dirty, so that it's erased.
1133 if (cursor_was_shown != vd->vd_mshown ||
1134 (vd->vd_mshown && cursor_moved))
1135 vt_mark_mouse_position_as_dirty(vd);
1138 * Save position of the mouse cursor. It's used by backends to
1139 * know where to draw the cursor and during the next refresh to
1140 * erase the previous position.
1142 vd->vd_mx_drawn = vd->vd_mx;
1143 vd->vd_my_drawn = vd->vd_my;
1146 * If the cursor is displayed and has moved since last refresh,
1147 * mark the new position as dirty.
1149 if (vd->vd_mshown && cursor_moved)
1150 vt_mark_mouse_position_as_dirty(vd);
1153 vtbuf_undirty(&vw->vw_buf, &tarea);
1154 vt_termsize(vd, vf, &size);
1156 /* Force a full redraw when the screen contents are invalid. */
1157 if (vd->vd_flags & VDF_INVALID) {
1158 tarea.tr_begin.tp_row = tarea.tr_begin.tp_col = 0;
1159 tarea.tr_end = size;
1161 vd->vd_flags &= ~VDF_INVALID;
1164 if (tarea.tr_begin.tp_col < tarea.tr_end.tp_col) {
1165 vd->vd_driver->vd_bitblt_text(vd, vw, &tarea);
1175 struct vt_device *vd;
1179 /* Update screen if required. */
1180 changed = vt_flush(vd);
1182 /* Schedule for next update. */
1184 vt_schedule_flush(vd, 0);
1186 vd->vd_timer_armed = 0;
1190 vtterm_done(struct terminal *tm)
1192 struct vt_window *vw = tm->tm_softc;
1193 struct vt_device *vd = vw->vw_device;
1195 if (kdb_active || panicstr != NULL) {
1196 /* Switch to the debugger. */
1197 if (vd->vd_curwindow != vw) {
1198 vd->vd_curwindow = vw;
1199 vd->vd_flags |= VDF_INVALID;
1200 if (vd->vd_driver->vd_postswitch)
1201 vd->vd_driver->vd_postswitch(vd);
1203 vd->vd_flags &= ~VDF_SPLASH;
1205 } else if (!(vd->vd_flags & VDF_ASYNC)) {
1212 vtterm_splash(struct vt_device *vd)
1214 vt_axis_t top, left;
1216 /* Display a nice boot splash. */
1217 if (!(vd->vd_flags & VDF_TEXTMODE) && (boothowto & RB_MUTE)) {
1219 top = (vd->vd_height - vt_logo_height) / 2;
1220 left = (vd->vd_width - vt_logo_width) / 2;
1221 switch (vt_logo_depth) {
1223 /* XXX: Unhardcode colors! */
1224 vd->vd_driver->vd_bitblt_bmp(vd, vd->vd_curwindow,
1225 vt_logo_image, NULL, vt_logo_width, vt_logo_height,
1226 left, top, TC_WHITE, TC_BLACK);
1228 vd->vd_flags |= VDF_SPLASH;
1235 vtterm_cnprobe(struct terminal *tm, struct consdev *cp)
1237 struct vt_driver *vtd, **vtdlist, *vtdbest = NULL;
1238 struct vt_window *vw = tm->tm_softc;
1239 struct vt_device *vd = vw->vw_device;
1244 if (!vty_enabled(VTY_VT))
1247 if (vd->vd_flags & VDF_INITIALIZED)
1248 /* Initialization already done. */
1251 SET_FOREACH(vtdlist, vt_drv_set) {
1253 if (vtd->vd_probe == NULL)
1255 if (vtd->vd_probe(vd) == CN_DEAD)
1257 if ((vtdbest == NULL) ||
1258 (vtd->vd_priority > vtdbest->vd_priority))
1261 if (vtdbest == NULL) {
1262 cp->cn_pri = CN_DEAD;
1263 vd->vd_flags |= VDF_DEAD;
1265 vd->vd_driver = vtdbest;
1266 cp->cn_pri = vd->vd_driver->vd_init(vd);
1269 /* Check if driver's vt_init return CN_DEAD. */
1270 if (cp->cn_pri == CN_DEAD) {
1271 vd->vd_flags |= VDF_DEAD;
1274 /* Initialize any early-boot keyboard drivers */
1275 kbd_configure(KB_CONF_PROBE_ONLY);
1277 vd->vd_unit = atomic_fetchadd_int(&vt_unit, 1);
1278 vd->vd_windows[VT_CONSWINDOW] = vw;
1279 sprintf(cp->cn_name, "ttyv%r", VT_UNIT(vw));
1281 /* Attach default font if not in TEXTMODE. */
1282 if ((vd->vd_flags & VDF_TEXTMODE) == 0) {
1283 vw->vw_font = vtfont_ref(&vt_font_default);
1284 vt_compute_drawable_area(vw);
1288 * The original screen size was faked (_VTDEFW x _VTDEFH). Now
1289 * that we have the real viewable size, fix it in the static
1292 if (vd->vd_width != 0 && vd->vd_height != 0)
1293 vt_termsize(vd, vw->vw_font, &vw->vw_buf.vb_scr_size);
1295 vtbuf_init_early(&vw->vw_buf);
1296 vt_winsize(vd, vw->vw_font, &wsz);
1297 c = (boothowto & RB_MUTE) == 0 ? TERMINAL_KERN_ATTR :
1299 attr.ta_format = TCHAR_FORMAT(c);
1300 attr.ta_fgcolor = TCHAR_FGCOLOR(c);
1301 attr.ta_bgcolor = TCHAR_BGCOLOR(c);
1302 terminal_set_winsize_blank(tm, &wsz, 1, &attr);
1304 if (vtdbest != NULL) {
1308 vd->vd_flags |= VDF_INITIALIZED;
1313 vtterm_cngetc(struct terminal *tm)
1315 struct vt_window *vw = tm->tm_softc;
1316 struct vt_device *vd = vw->vw_device;
1320 if (vw->vw_kbdsq && *vw->vw_kbdsq)
1321 return (*vw->vw_kbdsq++);
1323 /* Make sure the splash screen is not there. */
1324 if (vd->vd_flags & VDF_SPLASH) {
1326 vd->vd_flags &= ~VDF_SPLASH;
1327 /* Mark screen as invalid to force update */
1328 vd->vd_flags |= VDF_INVALID;
1332 /* Stripped down keyboard handler. */
1333 kbd = kbd_get_keyboard(vd->vd_keyboard);
1337 /* Force keyboard input mode to K_XLATE */
1338 vw->vw_kbdmode = K_XLATE;
1339 vt_update_kbd_mode(vw, kbd);
1341 /* Switch the keyboard to polling to make it work here. */
1342 kbdd_poll(kbd, TRUE);
1343 c = kbdd_read_char(kbd, 0);
1344 kbdd_poll(kbd, FALSE);
1348 if (vw->vw_flags & VWF_SCROLL) {
1349 vt_scrollmode_kbdevent(vw, c, 1/* Console mode */);
1354 /* Stripped down handling of vt_kbdevent(), without locking, etc. */
1358 vt_save_kbd_state(vw, kbd);
1359 if (vw->vw_kbdstate & SLKED) {
1360 /* Turn scrolling on. */
1361 vw->vw_flags |= VWF_SCROLL;
1362 VTBUF_SLCK_ENABLE(&vw->vw_buf);
1364 /* Turn scrolling off. */
1365 vt_scroll(vw, 0, VHS_END);
1366 vw->vw_flags &= ~VWF_SCROLL;
1367 VTBUF_SLCK_DISABLE(&vw->vw_buf);
1370 /* XXX: KDB can handle history. */
1371 case SPCLKEY | FKEY | F(50): /* Arrow up. */
1372 vw->vw_kbdsq = "\x1b[A";
1374 case SPCLKEY | FKEY | F(58): /* Arrow down. */
1375 vw->vw_kbdsq = "\x1b[B";
1377 case SPCLKEY | FKEY | F(55): /* Arrow right. */
1378 vw->vw_kbdsq = "\x1b[C";
1380 case SPCLKEY | FKEY | F(53): /* Arrow left. */
1381 vw->vw_kbdsq = "\x1b[D";
1385 /* Force refresh to make scrollback work. */
1387 } else if (KEYFLAGS(c) == 0) {
1388 return (KEYCHAR(c));
1391 if (vw->vw_kbdsq && *vw->vw_kbdsq)
1392 return (*vw->vw_kbdsq++);
1398 vtterm_cngrab(struct terminal *tm)
1400 struct vt_device *vd;
1401 struct vt_window *vw;
1408 vt_window_switch(vw);
1410 kbd = kbd_get_keyboard(vd->vd_keyboard);
1414 if (vw->vw_grabbed++ > 0)
1418 * Make sure the keyboard is accessible even when the kbd device
1419 * driver is disabled.
1423 /* We shall always use the keyboard in the XLATE mode here. */
1424 vw->vw_prev_kbdmode = vw->vw_kbdmode;
1425 vw->vw_kbdmode = K_XLATE;
1426 vt_update_kbd_mode(vw, kbd);
1428 kbdd_poll(kbd, TRUE);
1432 vtterm_cnungrab(struct terminal *tm)
1434 struct vt_device *vd;
1435 struct vt_window *vw;
1441 kbd = kbd_get_keyboard(vd->vd_keyboard);
1445 if (--vw->vw_grabbed > 0)
1448 kbdd_poll(kbd, FALSE);
1450 vw->vw_kbdmode = vw->vw_prev_kbdmode;
1451 vt_update_kbd_mode(vw, kbd);
1456 vtterm_opened(struct terminal *tm, int opened)
1458 struct vt_window *vw = tm->tm_softc;
1459 struct vt_device *vd = vw->vw_device;
1462 vd->vd_flags &= ~VDF_SPLASH;
1464 vw->vw_flags |= VWF_OPENED;
1466 vw->vw_flags &= ~VWF_OPENED;
1467 /* TODO: finish ACQ/REL */
1473 vt_set_border(struct vt_window *vw, term_color_t c)
1475 struct vt_device *vd = vw->vw_device;
1477 if (vd->vd_driver->vd_drawrect == NULL)
1481 if (vw->vw_draw_area.tr_begin.tp_row > 0)
1482 vd->vd_driver->vd_drawrect(vd,
1484 vd->vd_width - 1, vw->vw_draw_area.tr_begin.tp_row - 1,
1488 if (vw->vw_draw_area.tr_begin.tp_col > 0)
1489 vd->vd_driver->vd_drawrect(vd,
1491 vw->vw_draw_area.tr_begin.tp_col - 1, vd->vd_height - 1,
1495 if (vw->vw_draw_area.tr_end.tp_col < vd->vd_width)
1496 vd->vd_driver->vd_drawrect(vd,
1497 vw->vw_draw_area.tr_end.tp_col - 1, 0,
1498 vd->vd_width - 1, vd->vd_height - 1,
1502 if (vw->vw_draw_area.tr_end.tp_row < vd->vd_height)
1503 vd->vd_driver->vd_drawrect(vd,
1504 0, vw->vw_draw_area.tr_end.tp_row - 1,
1505 vd->vd_width - 1, vd->vd_height - 1,
1512 vt_change_font(struct vt_window *vw, struct vt_font *vf)
1514 struct vt_device *vd = vw->vw_device;
1515 struct terminal *tm = vw->vw_terminal;
1522 * Changing fonts is a little tricky. We must prevent
1523 * simultaneous access to the device, so we must stop
1524 * the display timer and the terminal from accessing.
1525 * We need to switch fonts and grow our screen buffer.
1527 * XXX: Right now the code uses terminal_mute() to
1528 * prevent data from reaching the console driver while
1529 * resizing the screen buffer. This isn't elegant...
1533 if (vw->vw_flags & VWF_BUSY) {
1534 /* Another process is changing the font. */
1538 vw->vw_flags |= VWF_BUSY;
1541 vt_termsize(vd, vf, &size);
1542 vt_winsize(vd, vf, &wsz);
1544 /* Grow the screen buffer and terminal. */
1545 terminal_mute(tm, 1);
1546 vtbuf_grow(&vw->vw_buf, &size, vw->vw_buf.vb_history_size);
1547 terminal_set_winsize_blank(tm, &wsz, 0, NULL);
1548 terminal_set_cursor(tm, &vw->vw_buf.vb_cursor);
1549 terminal_mute(tm, 0);
1551 /* Actually apply the font to the current window. */
1553 if (vw->vw_font != vf && vw->vw_font != NULL && vf != NULL) {
1555 * In case vt_change_font called to update size we don't need
1556 * to update font link.
1558 vtfont_unref(vw->vw_font);
1559 vw->vw_font = vtfont_ref(vf);
1563 * Compute the drawable area and move the mouse cursor inside
1564 * it, in case the new area is smaller than the previous one.
1566 vt_compute_drawable_area(vw);
1567 vd->vd_mx = min(vd->vd_mx,
1568 vw->vw_draw_area.tr_end.tp_col -
1569 vw->vw_draw_area.tr_begin.tp_col - 1);
1570 vd->vd_my = min(vd->vd_my,
1571 vw->vw_draw_area.tr_end.tp_row -
1572 vw->vw_draw_area.tr_begin.tp_row - 1);
1574 /* Force a full redraw the next timer tick. */
1575 if (vd->vd_curwindow == vw) {
1576 vt_set_border(vw, TC_BLACK);
1577 vd->vd_flags |= VDF_INVALID;
1578 vt_resume_flush_timer(vw->vw_device, 0);
1580 vw->vw_flags &= ~VWF_BUSY;
1586 vt_proc_alive(struct vt_window *vw)
1590 if (vw->vw_smode.mode != VT_PROCESS)
1594 if ((p = pfind(vw->vw_pid)) != NULL)
1596 if (vw->vw_proc == p)
1599 vw->vw_smode.mode = VT_AUTO;
1600 DPRINTF(1, "vt controlling process %d died\n", vw->vw_pid);
1607 signal_vt_rel(struct vt_window *vw)
1610 if (vw->vw_smode.mode != VT_PROCESS)
1612 if (vw->vw_proc == NULL || vt_proc_alive(vw) == FALSE) {
1617 vw->vw_flags |= VWF_SWWAIT_REL;
1618 PROC_LOCK(vw->vw_proc);
1619 kern_psignal(vw->vw_proc, vw->vw_smode.relsig);
1620 PROC_UNLOCK(vw->vw_proc);
1621 DPRINTF(1, "sending relsig to %d\n", vw->vw_pid);
1626 signal_vt_acq(struct vt_window *vw)
1629 if (vw->vw_smode.mode != VT_PROCESS)
1631 if (vw == vw->vw_device->vd_windows[VT_CONSWINDOW])
1632 cnavailable(vw->vw_terminal->consdev, FALSE);
1633 if (vw->vw_proc == NULL || vt_proc_alive(vw) == FALSE) {
1638 vw->vw_flags |= VWF_SWWAIT_ACQ;
1639 PROC_LOCK(vw->vw_proc);
1640 kern_psignal(vw->vw_proc, vw->vw_smode.acqsig);
1641 PROC_UNLOCK(vw->vw_proc);
1642 DPRINTF(1, "sending acqsig to %d\n", vw->vw_pid);
1647 finish_vt_rel(struct vt_window *vw, int release, int *s)
1650 if (vw->vw_flags & VWF_SWWAIT_REL) {
1651 vw->vw_flags &= ~VWF_SWWAIT_REL;
1653 callout_drain(&vw->vw_proc_dead_timer);
1654 vt_late_window_switch(vw->vw_switch_to);
1662 finish_vt_acq(struct vt_window *vw)
1665 if (vw->vw_flags & VWF_SWWAIT_ACQ) {
1666 vw->vw_flags &= ~VWF_SWWAIT_ACQ;
1672 #ifndef SC_NO_CUTPASTE
1674 vt_mouse_terminput_button(struct vt_device *vd, int button)
1676 struct vt_window *vw;
1678 char mouseb[6] = "\x1B[M";
1681 vw = vd->vd_curwindow;
1684 /* Translate to char position. */
1685 x = vd->vd_mx / vf->vf_width;
1686 y = vd->vd_my / vf->vf_height;
1687 /* Avoid overflow. */
1688 x = MIN(x, 255 - '!');
1689 y = MIN(y, 255 - '!');
1691 mouseb[3] = ' ' + button;
1692 mouseb[4] = '!' + x;
1693 mouseb[5] = '!' + y;
1695 for (i = 0; i < sizeof(mouseb); i++)
1696 terminal_input_char(vw->vw_terminal, mouseb[i]);
1700 vt_mouse_terminput(struct vt_device *vd, int type, int x, int y, int event,
1705 case MOUSE_BUTTON_EVENT:
1707 /* Mouse button pressed. */
1708 if (event & MOUSE_BUTTON1DOWN)
1709 vt_mouse_terminput_button(vd, 0);
1710 if (event & MOUSE_BUTTON2DOWN)
1711 vt_mouse_terminput_button(vd, 1);
1712 if (event & MOUSE_BUTTON3DOWN)
1713 vt_mouse_terminput_button(vd, 2);
1715 /* Mouse button released. */
1716 vt_mouse_terminput_button(vd, 3);
1720 case MOUSE_MOTION_EVENT:
1721 if (mouse->u.data.z < 0) {
1723 sc_mouse_input_button(vd, 64);
1724 } else if (mouse->u.data.z > 0) {
1726 sc_mouse_input_button(vd, 65);
1739 len = VD_PASTEBUFLEN(main_vd);
1740 buf = VD_PASTEBUF(main_vd);
1741 len /= sizeof(term_char_t);
1742 for (i = 0; i < len; i++) {
1745 terminal_input_char(main_vd->vd_curwindow->vw_terminal,
1751 vt_mouse_event(int type, int x, int y, int event, int cnt, int mlevel)
1753 struct vt_device *vd;
1754 struct vt_window *vw;
1760 vw = vd->vd_curwindow;
1764 if (vw->vw_flags & (VWF_MOUSE_HIDE | VWF_GRAPHICS))
1766 * Either the mouse is disabled, or the window is in
1767 * "graphics mode". The graphics mode is usually set by
1768 * an X server, using the KDSETMODE ioctl.
1772 if (vf == NULL) /* Text mode. */
1776 * TODO: add flag about pointer position changed, to not redraw chars
1777 * under mouse pointer when nothing changed.
1780 if (vw->vw_mouse_level > 0)
1781 vt_mouse_terminput(vd, type, x, y, event, cnt);
1785 case MOUSE_MOTION_EVENT:
1790 vt_termsize(vd, vf, &size);
1795 x = MIN(x, (size.tp_col * vf->vf_width) - 1);
1796 y = MIN(y, (size.tp_row * vf->vf_height) - 1);
1800 if (vd->vd_mstate & MOUSE_BUTTON1DOWN)
1801 vtbuf_set_mark(&vw->vw_buf, VTB_MARK_MOVE,
1802 vd->vd_mx / vf->vf_width,
1803 vd->vd_my / vf->vf_height);
1805 vt_resume_flush_timer(vw->vw_device, 0);
1807 case MOUSE_BUTTON_EVENT:
1815 case MOUSE_BUTTON1DOWN:
1818 mark = VTB_MARK_END;
1820 case 1: /* single click: start cut operation */
1821 mark = VTB_MARK_START;
1823 case 2: /* double click: cut a word */
1824 mark = VTB_MARK_WORD;
1826 case 3: /* triple click: cut a line */
1827 mark = VTB_MARK_ROW;
1831 case VT_MOUSE_PASTEBUTTON:
1840 case VT_MOUSE_EXTENDBUTTON:
1843 if (!(vd->vd_mstate & MOUSE_BUTTON1DOWN))
1844 mark = VTB_MARK_EXTEND;
1849 mark = VTB_MARK_EXTEND;
1857 /* Save buttons state. */
1859 vd->vd_mstate |= event;
1861 vd->vd_mstate &= ~event;
1863 if (vtbuf_set_mark(&vw->vw_buf, mark, vd->vd_mx / vf->vf_width,
1864 vd->vd_my / vf->vf_height) == 1) {
1866 * We have something marked to copy, so update pointer to
1867 * window with selection.
1869 vt_resume_flush_timer(vw->vw_device, 0);
1875 case VTB_MARK_EXTEND:
1878 /* Other types of mark do not require to copy data. */
1882 /* Get current selection size in bytes. */
1883 len = vtbuf_get_marked_len(&vw->vw_buf);
1887 /* Reallocate buffer only if old one is too small. */
1888 if (len > VD_PASTEBUFSZ(vd)) {
1889 VD_PASTEBUF(vd) = realloc(VD_PASTEBUF(vd), len, M_VT,
1891 /* Update buffer size. */
1892 VD_PASTEBUFSZ(vd) = len;
1894 /* Request copy/paste buffer data, no more than `len' */
1895 vtbuf_extract_marked(&vw->vw_buf, VD_PASTEBUF(vd),
1898 VD_PASTEBUFLEN(vd) = len;
1900 /* XXX VD_PASTEBUF(vd) have to be freed on shutdown/unload. */
1905 vt_mouse_state(int show)
1907 struct vt_device *vd;
1908 struct vt_window *vw;
1911 vw = vd->vd_curwindow;
1915 vw->vw_flags |= VWF_MOUSE_HIDE;
1918 vw->vw_flags &= ~VWF_MOUSE_HIDE;
1922 /* Mark mouse position as dirty. */
1923 vt_mark_mouse_position_as_dirty(vd);
1924 vt_resume_flush_timer(vw->vw_device, 0);
1929 vtterm_mmap(struct terminal *tm, vm_ooffset_t offset, vm_paddr_t * paddr,
1930 int nprot, vm_memattr_t *memattr)
1932 struct vt_window *vw = tm->tm_softc;
1933 struct vt_device *vd = vw->vw_device;
1935 if (vd->vd_driver->vd_fb_mmap)
1936 return (vd->vd_driver->vd_fb_mmap(vd, offset, paddr, nprot,
1943 vtterm_ioctl(struct terminal *tm, u_long cmd, caddr_t data,
1946 struct vt_window *vw = tm->tm_softc;
1947 struct vt_device *vd = vw->vw_device;
1950 #if defined(COMPAT_FREEBSD6) || defined(COMPAT_FREEBSD5) || \
1951 defined(COMPAT_FREEBSD4) || defined(COMPAT_43)
1962 cmd = VT_WAITACTIVE;
1988 ival = IOCPARM_IVAL(data);
1989 data = (caddr_t)&ival;
1994 case KDSETRAD: /* set keyboard repeat & delay rates (old) */
1995 if (*(int *)data & ~0x7f)
2000 case GIO_DEADKEYMAP:
2001 case PIO_DEADKEYMAP:
2006 case KDGETREPEAT: /* get keyboard repeat & delay rates */
2007 case KDSETREPEAT: /* set keyboard repeat & delay rates (new) */
2008 case KBADDKBD: /* add/remove keyboard to/from mux */
2013 kbd = kbd_get_keyboard(vd->vd_keyboard);
2015 error = kbdd_ioctl(kbd, cmd, data);
2017 if (error == ENOIOCTL) {
2018 if (cmd == KDGKBTYPE) {
2019 /* always return something? XXX */
2027 case KDGKBSTATE: { /* get keyboard state (locks) */
2030 if (vw == vd->vd_curwindow) {
2032 kbd = kbd_get_keyboard(vd->vd_keyboard);
2034 error = vt_save_kbd_state(vw, kbd);
2041 *(int *)data = vw->vw_kbdstate & LOCK_MASK;
2045 case KDSKBSTATE: { /* set keyboard state (locks) */
2048 state = *(int *)data;
2049 if (state & ~LOCK_MASK)
2052 vw->vw_kbdstate &= ~LOCK_MASK;
2053 vw->vw_kbdstate |= state;
2056 if (vw == vd->vd_curwindow) {
2058 kbd = kbd_get_keyboard(vd->vd_keyboard);
2060 error = vt_update_kbd_state(vw, kbd);
2066 case KDGETLED: { /* get keyboard LED status */
2069 if (vw == vd->vd_curwindow) {
2071 kbd = kbd_get_keyboard(vd->vd_keyboard);
2073 error = vt_save_kbd_leds(vw, kbd);
2080 *(int *)data = vw->vw_kbdstate & LED_MASK;
2084 case KDSETLED: { /* set keyboard LED status */
2087 leds = *(int *)data;
2088 if (leds & ~LED_MASK)
2091 vw->vw_kbdstate &= ~LED_MASK;
2092 vw->vw_kbdstate |= leds;
2095 if (vw == vd->vd_curwindow) {
2097 kbd = kbd_get_keyboard(vd->vd_keyboard);
2099 error = vt_update_kbd_leds(vw, kbd);
2108 if (vw == vd->vd_curwindow) {
2110 kbd = kbd_get_keyboard(vd->vd_keyboard);
2112 error = vt_save_kbd_mode(vw, kbd);
2119 *(int *)data = vw->vw_kbdmode;
2126 mode = *(int *)data;
2131 vw->vw_kbdmode = mode;
2134 if (vw == vd->vd_curwindow) {
2136 kbd = kbd_get_keyboard(vd->vd_keyboard);
2138 error = vt_update_kbd_mode(vw, kbd);
2148 case FBIO_GETWINORG: /* get frame buffer window origin */
2149 case FBIO_GETDISPSTART: /* get display start address */
2150 case FBIO_GETLINEWIDTH: /* get scan line width in bytes */
2151 case FBIO_BLANK: /* blank display */
2152 if (vd->vd_driver->vd_fb_ioctl)
2153 return (vd->vd_driver->vd_fb_ioctl(vd, cmd, data, td));
2155 case CONS_BLANKTIME:
2160 *(int *)data = M_CG640x480;
2162 case CONS_BELLTYPE: /* set bell type sound */
2163 if ((*(int *)data) & CONS_QUIET_BELL)
2164 vd->vd_flags |= VDF_QUIET_BELL;
2166 vd->vd_flags &= ~VDF_QUIET_BELL;
2168 case CONS_GETINFO: {
2169 vid_info_t *vi = (vid_info_t *)data;
2170 if (vi->size != sizeof(struct vid_info))
2173 if (vw == vd->vd_curwindow) {
2174 kbd = kbd_get_keyboard(vd->vd_keyboard);
2176 vt_save_kbd_state(vw, kbd);
2179 vi->m_num = vd->vd_curwindow->vw_number + 1;
2180 vi->mk_keylock = vw->vw_kbdstate & LOCK_MASK;
2181 /* XXX: other fields! */
2185 *(int *)data = 0x200;
2190 case CONS_MOUSECTL: {
2191 mouse_info_t *mouse = (mouse_info_t*)data;
2194 * All the commands except MOUSE_SHOW nd MOUSE_HIDE
2195 * should not be applied to individual TTYs, but only to
2198 switch (mouse->operation) {
2200 if (vd->vd_flags & VDF_MOUSECURSOR) {
2201 vd->vd_flags &= ~VDF_MOUSECURSOR;
2202 #ifndef SC_NO_CUTPASTE
2203 vt_mouse_state(VT_MOUSE_HIDE);
2208 if (!(vd->vd_flags & VDF_MOUSECURSOR)) {
2209 vd->vd_flags |= VDF_MOUSECURSOR;
2210 vd->vd_mx = vd->vd_width / 2;
2211 vd->vd_my = vd->vd_height / 2;
2212 #ifndef SC_NO_CUTPASTE
2213 vt_mouse_state(VT_MOUSE_SHOW);
2224 if (vd->vd_flags & VDF_TEXTMODE)
2227 error = vtfont_load((void *)data, &vf);
2231 error = vt_change_font(vw, vf);
2235 case PIO_VFONT_DEFAULT: {
2236 /* Reset to default font. */
2237 error = vt_change_font(vw, &vt_font_default);
2241 scrmap_t *sm = (scrmap_t *)data;
2243 /* We don't have screen maps, so return a handcrafted one. */
2244 for (i = 0; i < 256; i++)
2250 * FIXME: This implementation is incomplete compared to
2253 switch (*(int *)data) {
2257 vw->vw_flags &= ~VWF_GRAPHICS;
2260 vw->vw_flags |= VWF_GRAPHICS;
2264 case KDENABIO: /* allow io operations */
2265 error = priv_check(td, PRIV_IO);
2268 error = securelevel_gt(td->td_ucred, 0);
2271 #if defined(__i386__)
2272 td->td_frame->tf_eflags |= PSL_IOPL;
2273 #elif defined(__amd64__)
2274 td->td_frame->tf_rflags |= PSL_IOPL;
2277 case KDDISABIO: /* disallow io operations (default) */
2278 #if defined(__i386__)
2279 td->td_frame->tf_eflags &= ~PSL_IOPL;
2280 #elif defined(__amd64__)
2281 td->td_frame->tf_rflags &= ~PSL_IOPL;
2284 case KDMKTONE: /* sound the bell */
2285 vtterm_beep(tm, *(u_int *)data);
2287 case KIOCSOUND: /* make tone (*data) hz */
2290 case CONS_SETKBD: /* set the new keyboard */
2293 if (vd->vd_keyboard != *(int *)data) {
2294 kbd = kbd_get_keyboard(*(int *)data);
2299 i = kbd_allocate(kbd->kb_name, kbd->kb_unit,
2300 (void *)vd, vt_kbdevent, vd);
2302 if (vd->vd_keyboard != -1) {
2303 vt_save_kbd_state(vd->vd_curwindow, kbd);
2304 kbd_release(kbd, (void *)vd);
2306 kbd = kbd_get_keyboard(i);
2307 vd->vd_keyboard = i;
2309 vt_update_kbd_mode(vd->vd_curwindow, kbd);
2310 vt_update_kbd_state(vd->vd_curwindow, kbd);
2312 error = EPERM; /* XXX */
2317 case CONS_RELKBD: /* release the current keyboard */
2320 if (vd->vd_keyboard != -1) {
2321 kbd = kbd_get_keyboard(vd->vd_keyboard);
2326 vt_save_kbd_state(vd->vd_curwindow, kbd);
2327 error = kbd_release(kbd, (void *)vd);
2329 vd->vd_keyboard = -1;
2336 win = *(int *)data - 1;
2337 DPRINTF(5, "%s%d: VT_ACTIVATE ttyv%d ", SC_DRIVER_NAME,
2339 if ((win >= VT_MAXWINDOWS) || (win < 0))
2341 return (vt_proc_window_switch(vd->vd_windows[win]));
2344 *(int *)data = vd->vd_curwindow->vw_number + 1;
2347 *(int *)data = vw->vw_number + 1;
2350 /* TODO: Check current state, switching can be in progress. */
2351 if ((*(int *)data) == 0x01)
2352 vw->vw_flags |= VWF_VTYLOCK;
2353 else if ((*(int *)data) == 0x02)
2354 vw->vw_flags &= ~VWF_VTYLOCK;
2360 for (i = 0; i < VT_MAXWINDOWS; i++) {
2361 vw = vd->vd_windows[i];
2364 if (!(vw->vw_flags & VWF_OPENED)) {
2365 *(int *)data = vw->vw_number + 1;
2372 case VT_WAITACTIVE: {
2377 idx = *(unsigned int *)data;
2378 if (idx > VT_MAXWINDOWS)
2381 vw = vd->vd_windows[idx - 1];
2384 while (vd->vd_curwindow != vw && error == 0)
2385 error = cv_wait_sig(&vd->vd_winswitch, &vd->vd_lock);
2389 case VT_SETMODE: { /* set screen switcher mode */
2390 struct vt_mode *mode;
2393 mode = (struct vt_mode *)data;
2394 DPRINTF(5, "%s%d: VT_SETMODE ", SC_DRIVER_NAME, VT_UNIT(vw));
2395 if (vw->vw_smode.mode == VT_PROCESS) {
2396 p1 = pfind(vw->vw_pid);
2397 if (vw->vw_proc == p1 && vw->vw_proc != td->td_proc) {
2400 DPRINTF(5, "error EPERM\n");
2406 if (mode->mode == VT_AUTO) {
2407 vw->vw_smode.mode = VT_AUTO;
2410 DPRINTF(5, "VT_AUTO, ");
2411 if (vw == vw->vw_device->vd_windows[VT_CONSWINDOW])
2412 cnavailable(vw->vw_terminal->consdev, TRUE);
2413 /* were we in the middle of the vty switching process? */
2414 if (finish_vt_rel(vw, TRUE, &s) == 0)
2415 DPRINTF(5, "reset WAIT_REL, ");
2416 if (finish_vt_acq(vw) == 0)
2417 DPRINTF(5, "reset WAIT_ACQ, ");
2419 } else if (mode->mode == VT_PROCESS) {
2420 if (!ISSIGVALID(mode->relsig) ||
2421 !ISSIGVALID(mode->acqsig) ||
2422 !ISSIGVALID(mode->frsig)) {
2423 DPRINTF(5, "error EINVAL\n");
2426 DPRINTF(5, "VT_PROCESS %d, ", td->td_proc->p_pid);
2427 bcopy(data, &vw->vw_smode, sizeof(struct vt_mode));
2428 vw->vw_proc = td->td_proc;
2429 vw->vw_pid = vw->vw_proc->p_pid;
2430 if (vw == vw->vw_device->vd_windows[VT_CONSWINDOW])
2431 cnavailable(vw->vw_terminal->consdev, FALSE);
2433 DPRINTF(5, "VT_SETMODE failed, unknown mode %d\n",
2440 case VT_GETMODE: /* get screen switcher mode */
2441 bcopy(&vw->vw_smode, data, sizeof(struct vt_mode));
2444 case VT_RELDISP: /* screen switcher ioctl */
2446 * This must be the current vty which is in the VT_PROCESS
2449 if ((vw != vd->vd_curwindow) || (vw->vw_smode.mode !=
2453 /* ...and this process is controlling it. */
2454 if (vw->vw_proc != td->td_proc) {
2458 switch(*(int *)data) {
2459 case VT_FALSE: /* user refuses to release screen, abort */
2460 if ((error = finish_vt_rel(vw, FALSE, &s)) == 0)
2461 DPRINTF(5, "%s%d: VT_RELDISP: VT_FALSE\n",
2462 SC_DRIVER_NAME, VT_UNIT(vw));
2464 case VT_TRUE: /* user has released screen, go on */
2465 /* finish_vt_rel(..., TRUE, ...) should not be locked */
2466 if (vw->vw_flags & VWF_SWWAIT_REL) {
2467 if ((error = finish_vt_rel(vw, TRUE, &s)) == 0)
2468 DPRINTF(5, "%s%d: VT_RELDISP: VT_TRUE\n",
2469 SC_DRIVER_NAME, VT_UNIT(vw));
2474 case VT_ACKACQ: /* acquire acknowledged, switch completed */
2475 if ((error = finish_vt_acq(vw)) == 0)
2476 DPRINTF(5, "%s%d: VT_RELDISP: VT_ACKACQ\n",
2477 SC_DRIVER_NAME, VT_UNIT(vw));
2488 static struct vt_window *
2489 vt_allocate_window(struct vt_device *vd, unsigned int window)
2491 struct vt_window *vw;
2492 struct terminal *tm;
2496 vw = malloc(sizeof *vw, M_VT, M_WAITOK|M_ZERO);
2498 vw->vw_number = window;
2499 vw->vw_kbdmode = K_XLATE;
2501 if ((vd->vd_flags & VDF_TEXTMODE) == 0) {
2502 vw->vw_font = vtfont_ref(&vt_font_default);
2503 vt_compute_drawable_area(vw);
2506 vt_termsize(vd, vw->vw_font, &size);
2507 vt_winsize(vd, vw->vw_font, &wsz);
2508 vtbuf_init(&vw->vw_buf, &size);
2510 tm = vw->vw_terminal = terminal_alloc(&vt_termclass, vw);
2511 terminal_set_winsize(tm, &wsz);
2512 vd->vd_windows[window] = vw;
2513 callout_init(&vw->vw_proc_dead_timer, 0);
2519 vt_upgrade(struct vt_device *vd)
2521 struct vt_window *vw;
2523 int register_handlers;
2525 if (!vty_enabled(VTY_VT))
2527 if (main_vd->vd_driver == NULL)
2530 for (i = 0; i < VT_MAXWINDOWS; i++) {
2531 vw = vd->vd_windows[i];
2534 vw = vt_allocate_window(vd, i);
2536 if (!(vw->vw_flags & VWF_READY)) {
2537 callout_init(&vw->vw_proc_dead_timer, 0);
2538 terminal_maketty(vw->vw_terminal, "v%r", VT_UNIT(vw));
2539 vw->vw_flags |= VWF_READY;
2540 if (vw->vw_flags & VWF_CONSOLE) {
2541 /* For existing console window. */
2542 EVENTHANDLER_REGISTER(shutdown_pre_sync,
2543 vt_window_switch, vw, SHUTDOWN_PRI_DEFAULT);
2549 if (vd->vd_curwindow == NULL)
2550 vd->vd_curwindow = vd->vd_windows[VT_CONSWINDOW];
2552 register_handlers = 0;
2553 if (!(vd->vd_flags & VDF_ASYNC)) {
2554 /* Attach keyboard. */
2555 vt_allocate_keyboard(vd);
2557 /* Init 25 Hz timer. */
2558 callout_init_mtx(&vd->vd_timer, &vd->vd_lock, 0);
2560 /* Start timer when everything ready. */
2561 vd->vd_flags |= VDF_ASYNC;
2562 callout_reset(&vd->vd_timer, hz / VT_TIMERFREQ, vt_timer, vd);
2563 vd->vd_timer_armed = 1;
2564 register_handlers = 1;
2569 /* Refill settings with new sizes. */
2572 if (register_handlers) {
2573 /* Register suspend/resume handlers. */
2574 EVENTHANDLER_REGISTER(power_suspend_early, vt_suspend_handler,
2575 vd, EVENTHANDLER_PRI_ANY);
2576 EVENTHANDLER_REGISTER(power_resume, vt_resume_handler, vd,
2577 EVENTHANDLER_PRI_ANY);
2582 vt_resize(struct vt_device *vd)
2584 struct vt_window *vw;
2587 for (i = 0; i < VT_MAXWINDOWS; i++) {
2588 vw = vd->vd_windows[i];
2590 /* Assign default font to window, if not textmode. */
2591 if (!(vd->vd_flags & VDF_TEXTMODE) && vw->vw_font == NULL)
2592 vw->vw_font = vtfont_ref(&vt_font_default);
2595 /* Resize terminal windows */
2596 while (vt_change_font(vw, vw->vw_font) == EBUSY) {
2597 DPRINTF(100, "%s: vt_change_font() is busy, "
2598 "window %d\n", __func__, i);
2604 vt_replace_backend(const struct vt_driver *drv, void *softc)
2606 struct vt_device *vd;
2610 if (vd->vd_flags & VDF_ASYNC) {
2611 /* Stop vt_flush periodic task. */
2613 vt_suspend_flush_timer(vd);
2616 * Mute current terminal until we done. vt_change_font (called
2617 * from vt_resize) will unmute it.
2619 terminal_mute(vd->vd_curwindow->vw_terminal, 1);
2623 * Reset VDF_TEXTMODE flag, driver who require that flag (vt_vga) will
2627 vd->vd_flags &= ~VDF_TEXTMODE;
2631 * We want to upgrade from the current driver to the
2635 vd->vd_prev_driver = vd->vd_driver;
2636 vd->vd_prev_softc = vd->vd_softc;
2637 vd->vd_driver = drv;
2638 vd->vd_softc = softc;
2640 vd->vd_driver->vd_init(vd);
2641 } else if (vd->vd_prev_driver != NULL && vd->vd_prev_softc != NULL) {
2643 * No driver given: we want to downgrade to the previous
2646 const struct vt_driver *old_drv;
2649 old_drv = vd->vd_driver;
2650 old_softc = vd->vd_softc;
2652 vd->vd_driver = vd->vd_prev_driver;
2653 vd->vd_softc = vd->vd_prev_softc;
2654 vd->vd_prev_driver = NULL;
2655 vd->vd_prev_softc = NULL;
2657 vd->vd_flags |= VDF_DOWNGRADE;
2659 vd->vd_driver->vd_init(vd);
2661 if (old_drv->vd_fini)
2662 old_drv->vd_fini(vd, old_softc);
2664 vd->vd_flags &= ~VDF_DOWNGRADE;
2669 /* Update windows sizes and initialize last items. */
2673 if (vd->vd_flags & VDF_SPLASH)
2677 if (vd->vd_flags & VDF_ASYNC) {
2678 /* Allow to put chars now. */
2679 terminal_mute(vd->vd_curwindow->vw_terminal, 0);
2680 /* Rerun timer for screen updates. */
2681 vt_resume_flush_timer(vd, 0);
2685 * Register as console. If it already registered, cnadd() will ignore
2688 termcn_cnregister(vd->vd_windows[VT_CONSWINDOW]->vw_terminal);
2692 vt_suspend_handler(void *priv)
2694 struct vt_device *vd;
2697 if (vd->vd_driver != NULL && vd->vd_driver->vd_suspend != NULL)
2698 vd->vd_driver->vd_suspend(vd);
2702 vt_resume_handler(void *priv)
2704 struct vt_device *vd;
2707 if (vd->vd_driver != NULL && vd->vd_driver->vd_resume != NULL)
2708 vd->vd_driver->vd_resume(vd);
2712 vt_allocate(const struct vt_driver *drv, void *softc)
2715 if (!vty_enabled(VTY_VT))
2718 if (main_vd->vd_driver == NULL) {
2719 main_vd->vd_driver = drv;
2720 printf("VT: initialize with new VT driver \"%s\".\n",
2724 * Check if have rights to replace current driver. For example:
2725 * it is bad idea to replace KMS driver with generic VGA one.
2727 if (drv->vd_priority <= main_vd->vd_driver->vd_priority) {
2728 printf("VT: Driver priority %d too low. Current %d\n ",
2729 drv->vd_priority, main_vd->vd_driver->vd_priority);
2732 printf("VT: Replacing driver \"%s\" with new \"%s\".\n",
2733 main_vd->vd_driver->vd_name, drv->vd_name);
2736 vt_replace_backend(drv, softc);
2740 vt_deallocate(const struct vt_driver *drv, void *softc)
2743 if (!vty_enabled(VTY_VT))
2746 if (main_vd->vd_prev_driver == NULL ||
2747 main_vd->vd_driver != drv ||
2748 main_vd->vd_softc != softc)
2751 printf("VT: Switching back from \"%s\" to \"%s\".\n",
2752 main_vd->vd_driver->vd_name, main_vd->vd_prev_driver->vd_name);
2754 vt_replace_backend(NULL, NULL);
2758 vt_suspend(struct vt_device *vd)
2762 if (vt_suspendswitch == 0)
2764 /* Save current window. */
2765 vd->vd_savedwindow = vd->vd_curwindow;
2766 /* Ask holding process to free window and switch to console window */
2767 vt_proc_window_switch(vd->vd_windows[VT_CONSWINDOW]);
2769 /* Wait for the window switch to complete. */
2772 while (vd->vd_curwindow != vd->vd_windows[VT_CONSWINDOW] && error == 0)
2773 error = cv_wait_sig(&vd->vd_winswitch, &vd->vd_lock);
2778 vt_resume(struct vt_device *vd)
2781 if (vt_suspendswitch == 0)
2783 /* Switch back to saved window */
2784 if (vd->vd_savedwindow != NULL)
2785 vt_proc_window_switch(vd->vd_savedwindow);
2786 vd->vd_savedwindow = NULL;