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/random.h>
52 #include <sys/reboot.h>
53 #include <sys/systm.h>
54 #include <sys/terminal.h>
56 #include <dev/kbd/kbdreg.h>
57 #include <dev/vt/vt.h>
59 #if defined(__i386__) || defined(__amd64__)
60 #include <machine/psl.h>
61 #include <machine/frame.h>
64 static tc_bell_t vtterm_bell;
65 static tc_cursor_t vtterm_cursor;
66 static tc_putchar_t vtterm_putchar;
67 static tc_fill_t vtterm_fill;
68 static tc_copy_t vtterm_copy;
69 static tc_param_t vtterm_param;
70 static tc_done_t vtterm_done;
72 static tc_cnprobe_t vtterm_cnprobe;
73 static tc_cngetc_t vtterm_cngetc;
75 static tc_cngrab_t vtterm_cngrab;
76 static tc_cnungrab_t vtterm_cnungrab;
78 static tc_opened_t vtterm_opened;
79 static tc_ioctl_t vtterm_ioctl;
80 static tc_mmap_t vtterm_mmap;
82 const struct terminal_class vt_termclass = {
83 .tc_bell = vtterm_bell,
84 .tc_cursor = vtterm_cursor,
85 .tc_putchar = vtterm_putchar,
86 .tc_fill = vtterm_fill,
87 .tc_copy = vtterm_copy,
88 .tc_param = vtterm_param,
89 .tc_done = vtterm_done,
91 .tc_cnprobe = vtterm_cnprobe,
92 .tc_cngetc = vtterm_cngetc,
94 .tc_cngrab = vtterm_cngrab,
95 .tc_cnungrab = vtterm_cnungrab,
97 .tc_opened = vtterm_opened,
98 .tc_ioctl = vtterm_ioctl,
99 .tc_mmap = vtterm_mmap,
103 * Use a constant timer of 25 Hz to redraw the screen.
105 * XXX: In theory we should only fire up the timer when there is really
106 * activity. Unfortunately we cannot always start timers. We really
107 * don't want to process kernel messages synchronously, because it
108 * really slows down the system.
110 #define VT_TIMERFREQ 25
112 /* Bell pitch/duration. */
113 #define VT_BELLDURATION ((5 * hz + 99) / 100)
114 #define VT_BELLPITCH 800
116 #define VT_LOCK(vd) mtx_lock(&(vd)->vd_lock)
117 #define VT_UNLOCK(vd) mtx_unlock(&(vd)->vd_lock)
118 #define VT_LOCK_ASSERT(vd, what) mtx_assert(&(vd)->vd_lock, what)
120 #define VT_UNIT(vw) ((vw)->vw_device->vd_unit * VT_MAXWINDOWS + \
123 static SYSCTL_NODE(_kern, OID_AUTO, vt, CTLFLAG_RD, 0, "vt(9) parameters");
124 VT_SYSCTL_INT(enable_altgr, 1, "Enable AltGr key (Do not assume R.Alt as Alt)");
125 VT_SYSCTL_INT(enable_bell, 1, "Enable bell");
126 VT_SYSCTL_INT(debug, 0, "vt(9) debug level");
127 VT_SYSCTL_INT(deadtimer, 15, "Time to wait busy process in VT_PROCESS mode");
128 VT_SYSCTL_INT(suspendswitch, 1, "Switch to VT0 before suspend");
130 /* Allow to disable some keyboard combinations. */
131 VT_SYSCTL_INT(kbd_halt, 1, "Enable halt keyboard combination. "
132 "See kbdmap(5) to configure.");
133 VT_SYSCTL_INT(kbd_poweroff, 1, "Enable Power Off keyboard combination. "
134 "See kbdmap(5) to configure.");
135 VT_SYSCTL_INT(kbd_reboot, 1, "Enable reboot keyboard combination. "
136 "See kbdmap(5) to configure (typically Ctrl-Alt-Delete).");
137 VT_SYSCTL_INT(kbd_debug, 1, "Enable key combination to enter debugger. "
138 "See kbdmap(5) to configure (typically Ctrl-Alt-Esc).");
139 VT_SYSCTL_INT(kbd_panic, 0, "Enable request to panic. "
140 "See kbdmap(5) to configure.");
142 static struct vt_device vt_consdev;
143 static unsigned int vt_unit = 0;
144 static MALLOC_DEFINE(M_VT, "vt", "vt device");
145 struct vt_device *main_vd = &vt_consdev;
148 extern unsigned int vt_logo_width;
149 extern unsigned int vt_logo_height;
150 extern unsigned int vt_logo_depth;
151 extern unsigned char vt_logo_image[];
154 extern struct vt_font vt_font_default;
155 #ifndef SC_NO_CUTPASTE
156 extern struct vt_mouse_cursor vt_default_mouse_pointer;
159 static int signal_vt_rel(struct vt_window *);
160 static int signal_vt_acq(struct vt_window *);
161 static int finish_vt_rel(struct vt_window *, int, int *);
162 static int finish_vt_acq(struct vt_window *);
163 static int vt_window_switch(struct vt_window *);
164 static int vt_late_window_switch(struct vt_window *);
165 static int vt_proc_alive(struct vt_window *);
166 static void vt_resize(struct vt_device *);
167 static void vt_update_static(void *);
168 #ifndef SC_NO_CUTPASTE
169 static void vt_mouse_paste(void);
171 static void vt_suspend_handler(void *priv);
172 static void vt_resume_handler(void *priv);
174 SET_DECLARE(vt_drv_set, struct vt_driver);
176 #define _VTDEFH MAX(100, PIXEL_HEIGHT(VT_FB_DEFAULT_HEIGHT))
177 #define _VTDEFW MAX(200, PIXEL_WIDTH(VT_FB_DEFAULT_WIDTH))
179 static struct terminal vt_consterm;
180 static struct vt_window vt_conswindow;
181 static struct vt_device vt_consdev = {
184 .vd_prev_driver = NULL,
185 .vd_prev_softc = NULL,
186 .vd_flags = VDF_INVALID,
187 .vd_windows = { [VT_CONSWINDOW] = &vt_conswindow, },
188 .vd_curwindow = &vt_conswindow,
191 #ifndef SC_NO_CUTPASTE
197 .vd_mcursor = &vt_default_mouse_pointer,
198 .vd_mcursor_fg = TC_WHITE,
199 .vd_mcursor_bg = TC_BLACK,
202 static term_char_t vt_constextbuf[(_VTDEFW) * (VBF_DEFAULT_HISTORY_SIZE)];
203 static term_char_t *vt_constextbufrows[VBF_DEFAULT_HISTORY_SIZE];
204 static struct vt_window vt_conswindow = {
205 .vw_number = VT_CONSWINDOW,
206 .vw_flags = VWF_CONSOLE,
208 .vb_buffer = &vt_constextbuf[0],
209 .vb_rows = &vt_constextbufrows[0],
210 .vb_history_size = VBF_DEFAULT_HISTORY_SIZE,
213 .vb_flags = VBF_STATIC,
214 .vb_mark_start = {.tp_row = 0, .tp_col = 0,},
215 .vb_mark_end = {.tp_row = 0, .tp_col = 0,},
221 .vw_device = &vt_consdev,
222 .vw_terminal = &vt_consterm,
223 .vw_kbdmode = K_XLATE,
226 static struct terminal vt_consterm = {
227 .tm_class = &vt_termclass,
228 .tm_softc = &vt_conswindow,
231 static struct consdev vt_consterm_consdev = {
232 .cn_ops = &termcn_cnops,
233 .cn_arg = &vt_consterm,
237 /* Add to set of consoles. */
238 DATA_SET(cons_set, vt_consterm_consdev);
241 * Right after kmem is done to allow early drivers to use locking and allocate
244 SYSINIT(vt_update_static, SI_SUB_KMEM, SI_ORDER_ANY, vt_update_static,
246 /* Delay until all devices attached, to not waste time. */
247 SYSINIT(vt_early_cons, SI_SUB_INT_CONFIG_HOOKS, SI_ORDER_ANY, vt_upgrade,
250 /* Initialize locks/mem depended members. */
252 vt_update_static(void *dummy)
255 if (!vty_enabled(VTY_VT))
257 if (main_vd->vd_driver != NULL)
258 printf("VT: running with driver \"%s\".\n",
259 main_vd->vd_driver->vd_name);
261 printf("VT: init without driver.\n");
263 mtx_init(&main_vd->vd_lock, "vtdev", NULL, MTX_DEF);
264 cv_init(&main_vd->vd_winswitch, "vtwswt");
268 vt_schedule_flush(struct vt_device *vd, int ms)
272 /* Default to initial value. */
273 ms = 1000 / VT_TIMERFREQ;
275 callout_schedule(&vd->vd_timer, hz / (1000 / ms));
279 vt_resume_flush_timer(struct vt_device *vd, int ms)
282 if (!(vd->vd_flags & VDF_ASYNC) ||
283 !atomic_cmpset_int(&vd->vd_timer_armed, 0, 1))
286 vt_schedule_flush(vd, ms);
290 vt_suspend_flush_timer(struct vt_device *vd)
293 * As long as this function is called locked, callout_stop()
294 * has the same effect like callout_drain() with regard to
295 * preventing the callback function from executing.
297 VT_LOCK_ASSERT(vd, MA_OWNED);
299 if (!(vd->vd_flags & VDF_ASYNC) ||
300 !atomic_cmpset_int(&vd->vd_timer_armed, 1, 0))
303 callout_stop(&vd->vd_timer);
307 vt_switch_timer(void *arg)
310 vt_late_window_switch((struct vt_window *)arg);
314 vt_save_kbd_mode(struct vt_window *vw, keyboard_t *kbd)
319 ret = kbdd_ioctl(kbd, KDGKBMODE, (caddr_t)&mode);
325 vw->vw_kbdmode = mode;
331 vt_update_kbd_mode(struct vt_window *vw, keyboard_t *kbd)
335 ret = kbdd_ioctl(kbd, KDSKBMODE, (caddr_t)&vw->vw_kbdmode);
343 vt_save_kbd_state(struct vt_window *vw, keyboard_t *kbd)
348 ret = kbdd_ioctl(kbd, KDGKBSTATE, (caddr_t)&state);
354 vw->vw_kbdstate &= ~LOCK_MASK;
355 vw->vw_kbdstate |= state & LOCK_MASK;
361 vt_update_kbd_state(struct vt_window *vw, keyboard_t *kbd)
365 state = vw->vw_kbdstate & LOCK_MASK;
366 ret = kbdd_ioctl(kbd, KDSKBSTATE, (caddr_t)&state);
374 vt_save_kbd_leds(struct vt_window *vw, keyboard_t *kbd)
379 ret = kbdd_ioctl(kbd, KDGETLED, (caddr_t)&leds);
385 vw->vw_kbdstate &= ~LED_MASK;
386 vw->vw_kbdstate |= leds & LED_MASK;
392 vt_update_kbd_leds(struct vt_window *vw, keyboard_t *kbd)
396 leds = vw->vw_kbdstate & LED_MASK;
397 ret = kbdd_ioctl(kbd, KDSETLED, (caddr_t)&leds);
405 vt_window_preswitch(struct vt_window *vw, struct vt_window *curvw)
408 DPRINTF(40, "%s\n", __func__);
409 curvw->vw_switch_to = vw;
410 /* Set timer to allow switch in case when process hang. */
411 callout_reset(&vw->vw_proc_dead_timer, hz * vt_deadtimer,
412 vt_switch_timer, (void *)vw);
413 /* Notify process about vt switch attempt. */
414 DPRINTF(30, "%s: Notify process.\n", __func__);
415 signal_vt_rel(curvw);
421 vt_window_postswitch(struct vt_window *vw)
428 /* vt_late_window_switch will done VT switching for regular case. */
430 vt_late_window_switch(struct vt_window *vw)
434 callout_stop(&vw->vw_proc_dead_timer);
436 ret = vt_window_switch(vw);
440 /* Notify owner process about terminal availability. */
441 if (vw->vw_smode.mode == VT_PROCESS) {
442 ret = vt_window_postswitch(vw);
449 vt_proc_window_switch(struct vt_window *vw)
451 struct vt_window *curvw;
452 struct vt_device *vd;
455 /* Prevent switching to NULL */
457 DPRINTF(30, "%s: Cannot switch: vw is NULL.", __func__);
461 curvw = vd->vd_curwindow;
463 /* Check if virtual terminal is locked */
464 if (curvw->vw_flags & VWF_VTYLOCK)
467 /* Check if switch already in progress */
468 if (curvw->vw_flags & VWF_SWWAIT_REL) {
469 /* Check if switching to same window */
470 if (curvw->vw_switch_to == vw) {
471 DPRINTF(30, "%s: Switch in progress to same vw.", __func__);
472 return (0); /* success */
474 DPRINTF(30, "%s: Switch in progress to different vw.", __func__);
478 /* Avoid switching to already selected window */
480 DPRINTF(30, "%s: Cannot switch: vw == curvw.", __func__);
481 return (0); /* success */
484 /* Ask current process permission to switch away. */
485 if (curvw->vw_smode.mode == VT_PROCESS) {
486 DPRINTF(30, "%s: VT_PROCESS ", __func__);
487 if (vt_proc_alive(curvw) == FALSE) {
488 DPRINTF(30, "Dead. Cleaning.");
491 DPRINTF(30, "%s: Signaling process.\n", __func__);
492 /* Alive, try to ask him. */
493 ret = vt_window_preswitch(vw, curvw);
494 /* Wait for process answer or timeout. */
500 ret = vt_late_window_switch(vw);
504 /* Switch window ignoring process locking. */
506 vt_window_switch(struct vt_window *vw)
508 struct vt_device *vd = vw->vw_device;
509 struct vt_window *curvw = vd->vd_curwindow;
518 if (!(vw->vw_flags & (VWF_OPENED|VWF_CONSOLE))) {
523 vt_suspend_flush_timer(vd);
525 vd->vd_curwindow = vw;
526 vd->vd_flags |= VDF_INVALID;
527 cv_broadcast(&vd->vd_winswitch);
530 if (vd->vd_driver->vd_postswitch)
531 vd->vd_driver->vd_postswitch(vd);
533 vt_resume_flush_timer(vd, 0);
535 /* Restore per-window keyboard mode. */
537 kbd = kbd_get_keyboard(vd->vd_keyboard);
539 if (curvw->vw_kbdmode == K_XLATE)
540 vt_save_kbd_state(curvw, kbd);
542 vt_update_kbd_mode(vw, kbd);
543 vt_update_kbd_state(vw, kbd);
546 DPRINTF(10, "%s(ttyv%d) done\n", __func__, vw->vw_number);
552 vt_termsize(struct vt_device *vd, struct vt_font *vf, term_pos_t *size)
555 size->tp_row = vd->vd_height;
556 size->tp_col = vd->vd_width;
558 size->tp_row /= vf->vf_height;
559 size->tp_col /= vf->vf_width;
564 vt_winsize(struct vt_device *vd, struct vt_font *vf, struct winsize *size)
567 size->ws_row = size->ws_ypixel = vd->vd_height;
568 size->ws_col = size->ws_xpixel = vd->vd_width;
570 size->ws_row /= vf->vf_height;
571 size->ws_col /= vf->vf_width;
576 vt_compute_drawable_area(struct vt_window *vw)
578 struct vt_device *vd;
583 if (vw->vw_font == NULL) {
584 vw->vw_draw_area.tr_begin.tp_col = 0;
585 vw->vw_draw_area.tr_begin.tp_row = 0;
586 vw->vw_draw_area.tr_end.tp_col = vd->vd_width;
587 vw->vw_draw_area.tr_end.tp_row = vd->vd_height;
594 * Compute the drawable area, so that the text is centered on
598 vw->vw_draw_area.tr_begin.tp_col = (vd->vd_width % vf->vf_width) / 2;
599 vw->vw_draw_area.tr_begin.tp_row = (vd->vd_height % vf->vf_height) / 2;
600 vw->vw_draw_area.tr_end.tp_col = vw->vw_draw_area.tr_begin.tp_col +
601 vd->vd_width / vf->vf_width * vf->vf_width;
602 vw->vw_draw_area.tr_end.tp_row = vw->vw_draw_area.tr_begin.tp_row +
603 vd->vd_height / vf->vf_height * vf->vf_height;
607 vt_scroll(struct vt_window *vw, int offset, int whence)
612 if ((vw->vw_flags & VWF_SCROLL) == 0)
615 vt_termsize(vw->vw_device, vw->vw_font, &size);
617 diff = vthistory_seek(&vw->vw_buf, offset, whence);
619 vw->vw_device->vd_flags |= VDF_INVALID;
620 vt_resume_flush_timer(vw->vw_device, 0);
624 vt_machine_kbdevent(int c)
628 case SPCLKEY | DBG: /* kbdmap(5) keyword `debug`. */
630 kdb_enter(KDB_WHY_BREAK, "manual escape to debugger");
632 case SPCLKEY | HALT: /* kbdmap(5) keyword `halt`. */
634 shutdown_nice(RB_HALT);
636 case SPCLKEY | PASTE: /* kbdmap(5) keyword `paste`. */
637 #ifndef SC_NO_CUTPASTE
638 /* Insert text from cut-paste buffer. */
642 case SPCLKEY | PDWN: /* kbdmap(5) keyword `pdwn`. */
644 shutdown_nice(RB_HALT|RB_POWEROFF);
646 case SPCLKEY | PNC: /* kbdmap(5) keyword `panic`. */
648 * Request to immediate panic if sysctl
649 * kern.vt.enable_panic_key allow it.
652 panic("Forced by the panic key");
654 case SPCLKEY | RBT: /* kbdmap(5) keyword `boot`. */
656 shutdown_nice(RB_AUTOBOOT);
658 case SPCLKEY | SPSC: /* kbdmap(5) keyword `spsc`. */
659 /* Force activatation/deactivation of the screen saver. */
662 case SPCLKEY | STBY: /* XXX Not present in kbdcontrol parser. */
663 /* Put machine into Stand-By mode. */
664 power_pm_suspend(POWER_SLEEP_STATE_STANDBY);
666 case SPCLKEY | SUSP: /* kbdmap(5) keyword `susp`. */
667 /* Suspend machine. */
668 power_pm_suspend(POWER_SLEEP_STATE_SUSPEND);
676 vt_scrollmode_kbdevent(struct vt_window *vw, int c, int console)
678 struct vt_device *vd;
682 /* Only special keys handled in ScrollLock mode */
683 if ((c & SPCLKEY) == 0)
689 if (c >= F_SCR && c <= MIN(L_SCR, F_SCR + VT_MAXWINDOWS - 1)) {
690 vw = vd->vd_windows[c - F_SCR];
691 vt_proc_window_switch(vw);
699 /* Turn scrolling off. */
700 vt_scroll(vw, 0, VHS_END);
701 VTBUF_SLCK_DISABLE(&vw->vw_buf);
702 vw->vw_flags &= ~VWF_SCROLL;
705 case FKEY | F(49): /* Home key. */
706 vt_scroll(vw, 0, VHS_SET);
708 case FKEY | F(50): /* Arrow up. */
709 vt_scroll(vw, -1, VHS_CUR);
711 case FKEY | F(51): /* Page up. */
712 vt_termsize(vd, vw->vw_font, &size);
713 vt_scroll(vw, -size.tp_row, VHS_CUR);
715 case FKEY | F(57): /* End key. */
716 vt_scroll(vw, 0, VHS_END);
718 case FKEY | F(58): /* Arrow down. */
719 vt_scroll(vw, 1, VHS_CUR);
721 case FKEY | F(59): /* Page down. */
722 vt_termsize(vd, vw->vw_font, &size);
723 vt_scroll(vw, size.tp_row, VHS_CUR);
732 vt_processkey(keyboard_t *kbd, struct vt_device *vd, int c)
734 struct vt_window *vw = vd->vd_curwindow;
736 random_harvest_queue(&c, sizeof(c), 1, RANDOM_KEYBOARD);
737 #if VT_ALT_TO_ESC_HACK
739 switch (c & ~RELKEY) {
740 case (SPCLKEY | RALT):
741 if (vt_enable_altgr != 0)
743 case (SPCLKEY | LALT):
744 vd->vd_kbstate &= ~ALKED;
746 /* Other keys ignored for RELKEY event. */
749 switch (c & ~RELKEY) {
750 case (SPCLKEY | RALT):
751 if (vt_enable_altgr != 0)
753 case (SPCLKEY | LALT):
754 vd->vd_kbstate |= ALKED;
759 /* Other keys ignored for RELKEY event. */
763 if (vt_machine_kbdevent(c))
766 if (vw->vw_flags & VWF_SCROLL) {
767 vt_scrollmode_kbdevent(vw, c, 0/* Not a console */);
768 /* Scroll mode keys handled, nothing to do more. */
775 if (c >= F_SCR && c <= MIN(L_SCR, F_SCR + VT_MAXWINDOWS - 1)) {
776 vw = vd->vd_windows[c - F_SCR];
777 vt_proc_window_switch(vw);
783 /* Switch to next VT. */
784 c = (vw->vw_number + 1) % VT_MAXWINDOWS;
785 vw = vd->vd_windows[c];
786 vt_proc_window_switch(vw);
789 /* Switch to previous VT. */
790 c = (vw->vw_number + VT_MAXWINDOWS - 1) % VT_MAXWINDOWS;
791 vw = vd->vd_windows[c];
792 vt_proc_window_switch(vw);
795 vt_save_kbd_state(vw, kbd);
797 if (vw->vw_kbdstate & SLKED) {
798 /* Turn scrolling on. */
799 vw->vw_flags |= VWF_SCROLL;
800 VTBUF_SLCK_ENABLE(&vw->vw_buf);
802 /* Turn scrolling off. */
803 vw->vw_flags &= ~VWF_SCROLL;
804 VTBUF_SLCK_DISABLE(&vw->vw_buf);
805 vt_scroll(vw, 0, VHS_END);
810 case FKEY | F(1): case FKEY | F(2): case FKEY | F(3):
811 case FKEY | F(4): case FKEY | F(5): case FKEY | F(6):
812 case FKEY | F(7): case FKEY | F(8): case FKEY | F(9):
813 case FKEY | F(10): case FKEY | F(11): case FKEY | F(12):
814 /* F1 through F12 keys. */
815 terminal_input_special(vw->vw_terminal,
816 TKEY_F1 + c - (FKEY | F(1)));
818 case FKEY | F(49): /* Home key. */
819 terminal_input_special(vw->vw_terminal, TKEY_HOME);
821 case FKEY | F(50): /* Arrow up. */
822 terminal_input_special(vw->vw_terminal, TKEY_UP);
824 case FKEY | F(51): /* Page up. */
825 terminal_input_special(vw->vw_terminal, TKEY_PAGE_UP);
827 case FKEY | F(53): /* Arrow left. */
828 terminal_input_special(vw->vw_terminal, TKEY_LEFT);
830 case FKEY | F(55): /* Arrow right. */
831 terminal_input_special(vw->vw_terminal, TKEY_RIGHT);
833 case FKEY | F(57): /* End key. */
834 terminal_input_special(vw->vw_terminal, TKEY_END);
836 case FKEY | F(58): /* Arrow down. */
837 terminal_input_special(vw->vw_terminal, TKEY_DOWN);
839 case FKEY | F(59): /* Page down. */
840 terminal_input_special(vw->vw_terminal, TKEY_PAGE_DOWN);
842 case FKEY | F(60): /* Insert key. */
843 terminal_input_special(vw->vw_terminal, TKEY_INSERT);
845 case FKEY | F(61): /* Delete key. */
846 terminal_input_special(vw->vw_terminal, TKEY_DELETE);
849 } else if (KEYFLAGS(c) == 0) {
850 /* Don't do UTF-8 conversion when doing raw mode. */
851 if (vw->vw_kbdmode == K_XLATE) {
852 #if VT_ALT_TO_ESC_HACK
853 if (vd->vd_kbstate & ALKED) {
855 * Prepend ESC sequence if one of ALT keys down.
857 terminal_input_char(vw->vw_terminal, 0x1b);
861 kdb_alt_break(c, &vd->vd_altbrk);
863 terminal_input_char(vw->vw_terminal, KEYCHAR(c));
865 terminal_input_raw(vw->vw_terminal, c);
871 vt_kbdevent(keyboard_t *kbd, int event, void *arg)
873 struct vt_device *vd = arg;
879 case KBDIO_UNLOADING:
881 vd->vd_keyboard = -1;
882 kbd_release(kbd, (void *)vd);
889 while ((c = kbdd_read_char(kbd, 0)) != NOKEY)
890 vt_processkey(kbd, vd, c);
896 vt_allocate_keyboard(struct vt_device *vd)
902 idx0 = kbd_allocate("kbdmux", -1, vd, vt_kbdevent, vd);
904 DPRINTF(20, "%s: kbdmux allocated, idx = %d\n", __func__, idx0);
905 k0 = kbd_get_keyboard(idx0);
907 for (idx = kbd_find_keyboard2("*", -1, 0);
909 idx = kbd_find_keyboard2("*", -1, idx + 1)) {
910 k = kbd_get_keyboard(idx);
912 if (idx == idx0 || KBD_IS_BUSY(k))
915 bzero(&ki, sizeof(ki));
916 strncpy(ki.kb_name, k->kb_name, sizeof(ki.kb_name));
917 ki.kb_name[sizeof(ki.kb_name) - 1] = '\0';
918 ki.kb_unit = k->kb_unit;
920 kbdd_ioctl(k0, KBADDKBD, (caddr_t) &ki);
923 DPRINTF(20, "%s: no kbdmux allocated\n", __func__);
924 idx0 = kbd_allocate("*", -1, vd, vt_kbdevent, vd);
926 DPRINTF(10, "%s: No keyboard found.\n", __func__);
930 vd->vd_keyboard = idx0;
931 DPRINTF(20, "%s: vd_keyboard = %d\n", __func__, vd->vd_keyboard);
937 vtterm_bell(struct terminal *tm)
939 struct vt_window *vw = tm->tm_softc;
940 struct vt_device *vd = vw->vw_device;
945 if (vd->vd_flags & VDF_QUIET_BELL)
948 sysbeep(1193182 / VT_BELLPITCH, VT_BELLDURATION);
952 vtterm_beep(struct terminal *tm, u_int param)
959 if ((param == 0) || ((param & 0xffff) == 0)) {
964 period = ((param >> 16) & 0xffff) * hz / 1000;
965 freq = 1193182 / (param & 0xffff);
967 sysbeep(freq, period);
971 vtterm_cursor(struct terminal *tm, const term_pos_t *p)
973 struct vt_window *vw = tm->tm_softc;
975 vtbuf_cursor_position(&vw->vw_buf, p);
976 vt_resume_flush_timer(vw->vw_device, 0);
980 vtterm_putchar(struct terminal *tm, const term_pos_t *p, term_char_t c)
982 struct vt_window *vw = tm->tm_softc;
984 vtbuf_putchar(&vw->vw_buf, p, c);
985 vt_resume_flush_timer(vw->vw_device, 0);
989 vtterm_fill(struct terminal *tm, const term_rect_t *r, term_char_t c)
991 struct vt_window *vw = tm->tm_softc;
993 vtbuf_fill_locked(&vw->vw_buf, r, c);
994 vt_resume_flush_timer(vw->vw_device, 0);
998 vtterm_copy(struct terminal *tm, const term_rect_t *r,
1001 struct vt_window *vw = tm->tm_softc;
1003 vtbuf_copy(&vw->vw_buf, r, p);
1004 vt_resume_flush_timer(vw->vw_device, 0);
1008 vtterm_param(struct terminal *tm, int cmd, unsigned int arg)
1010 struct vt_window *vw = tm->tm_softc;
1014 vtbuf_cursor_visibility(&vw->vw_buf, arg);
1015 vt_resume_flush_timer(vw->vw_device, 0);
1018 vw->vw_mouse_level = arg;
1024 vt_determine_colors(term_char_t c, int cursor,
1025 term_color_t *fg, term_color_t *bg)
1032 *fg = TCHAR_FGCOLOR(c);
1033 if (TCHAR_FORMAT(c) & TF_BOLD)
1034 *fg = TCOLOR_LIGHT(*fg);
1035 *bg = TCHAR_BGCOLOR(c);
1037 if (TCHAR_FORMAT(c) & TF_REVERSE)
1049 #ifndef SC_NO_CUTPASTE
1051 vt_is_cursor_in_area(const struct vt_device *vd, const term_rect_t *area)
1053 unsigned int mx, my;
1056 * We use the cursor position saved during the current refresh,
1057 * in case the cursor moved since.
1059 mx = vd->vd_mx_drawn + vd->vd_curwindow->vw_draw_area.tr_begin.tp_col;
1060 my = vd->vd_my_drawn + vd->vd_curwindow->vw_draw_area.tr_begin.tp_row;
1062 if (mx >= area->tr_end.tp_col ||
1063 mx + vd->vd_mcursor->width <= area->tr_begin.tp_col ||
1064 my >= area->tr_end.tp_row ||
1065 my + vd->vd_mcursor->height <= area->tr_begin.tp_row)
1071 vt_mark_mouse_position_as_dirty(struct vt_device *vd)
1074 struct vt_window *vw;
1078 vw = vd->vd_curwindow;
1081 x = vd->vd_mx_drawn;
1082 y = vd->vd_my_drawn;
1085 area.tr_begin.tp_col = x / vf->vf_width;
1086 area.tr_begin.tp_row = y / vf->vf_height;
1087 area.tr_end.tp_col =
1088 ((x + vd->vd_mcursor->width) / vf->vf_width) + 1;
1089 area.tr_end.tp_row =
1090 ((y + vd->vd_mcursor->height) / vf->vf_height) + 1;
1093 * No font loaded (ie. vt_vga operating in textmode).
1095 * FIXME: This fake area needs to be revisited once the
1096 * mouse cursor is supported in vt_vga's textmode.
1098 area.tr_begin.tp_col = x;
1099 area.tr_begin.tp_row = y;
1100 area.tr_end.tp_col = x + 2;
1101 area.tr_end.tp_row = y + 2;
1104 vtbuf_dirty(&vw->vw_buf, &area);
1109 vt_flush(struct vt_device *vd)
1111 struct vt_window *vw;
1115 #ifndef SC_NO_CUTPASTE
1116 int cursor_was_shown, cursor_moved;
1119 vw = vd->vd_curwindow;
1123 if (vd->vd_flags & VDF_SPLASH || vw->vw_flags & VWF_BUSY)
1127 if (((vd->vd_flags & VDF_TEXTMODE) == 0) && (vf == NULL))
1130 #ifndef SC_NO_CUTPASTE
1131 cursor_was_shown = vd->vd_mshown;
1132 cursor_moved = (vd->vd_mx != vd->vd_mx_drawn ||
1133 vd->vd_my != vd->vd_my_drawn);
1135 /* Check if the cursor should be displayed or not. */
1136 if ((vd->vd_flags & VDF_MOUSECURSOR) && /* Mouse support enabled. */
1137 !(vw->vw_flags & VWF_MOUSE_HIDE) && /* Cursor displayed. */
1138 !kdb_active && panicstr == NULL) { /* DDB inactive. */
1145 * If the cursor changed display state or moved, we must mark
1146 * the old position as dirty, so that it's erased.
1148 if (cursor_was_shown != vd->vd_mshown ||
1149 (vd->vd_mshown && cursor_moved))
1150 vt_mark_mouse_position_as_dirty(vd);
1153 * Save position of the mouse cursor. It's used by backends to
1154 * know where to draw the cursor and during the next refresh to
1155 * erase the previous position.
1157 vd->vd_mx_drawn = vd->vd_mx;
1158 vd->vd_my_drawn = vd->vd_my;
1161 * If the cursor is displayed and has moved since last refresh,
1162 * mark the new position as dirty.
1164 if (vd->vd_mshown && cursor_moved)
1165 vt_mark_mouse_position_as_dirty(vd);
1168 vtbuf_undirty(&vw->vw_buf, &tarea);
1169 vt_termsize(vd, vf, &size);
1171 /* Force a full redraw when the screen contents are invalid. */
1172 if (vd->vd_flags & VDF_INVALID) {
1173 tarea.tr_begin.tp_row = tarea.tr_begin.tp_col = 0;
1174 tarea.tr_end = size;
1176 vd->vd_flags &= ~VDF_INVALID;
1179 if (tarea.tr_begin.tp_col < tarea.tr_end.tp_col) {
1180 vd->vd_driver->vd_bitblt_text(vd, vw, &tarea);
1190 struct vt_device *vd;
1194 /* Update screen if required. */
1195 changed = vt_flush(vd);
1197 /* Schedule for next update. */
1199 vt_schedule_flush(vd, 0);
1201 vd->vd_timer_armed = 0;
1205 vtterm_done(struct terminal *tm)
1207 struct vt_window *vw = tm->tm_softc;
1208 struct vt_device *vd = vw->vw_device;
1210 if (kdb_active || panicstr != NULL) {
1211 /* Switch to the debugger. */
1212 if (vd->vd_curwindow != vw) {
1213 vd->vd_curwindow = vw;
1214 vd->vd_flags |= VDF_INVALID;
1215 if (vd->vd_driver->vd_postswitch)
1216 vd->vd_driver->vd_postswitch(vd);
1218 vd->vd_flags &= ~VDF_SPLASH;
1220 } else if (!(vd->vd_flags & VDF_ASYNC)) {
1227 vtterm_splash(struct vt_device *vd)
1229 vt_axis_t top, left;
1231 /* Display a nice boot splash. */
1232 if (!(vd->vd_flags & VDF_TEXTMODE) && (boothowto & RB_MUTE)) {
1234 top = (vd->vd_height - vt_logo_height) / 2;
1235 left = (vd->vd_width - vt_logo_width) / 2;
1236 switch (vt_logo_depth) {
1238 /* XXX: Unhardcode colors! */
1239 vd->vd_driver->vd_bitblt_bmp(vd, vd->vd_curwindow,
1240 vt_logo_image, NULL, vt_logo_width, vt_logo_height,
1241 left, top, TC_WHITE, TC_BLACK);
1243 vd->vd_flags |= VDF_SPLASH;
1250 vtterm_cnprobe(struct terminal *tm, struct consdev *cp)
1252 struct vt_driver *vtd, **vtdlist, *vtdbest = NULL;
1253 struct vt_window *vw = tm->tm_softc;
1254 struct vt_device *vd = vw->vw_device;
1259 if (!vty_enabled(VTY_VT))
1262 if (vd->vd_flags & VDF_INITIALIZED)
1263 /* Initialization already done. */
1266 SET_FOREACH(vtdlist, vt_drv_set) {
1268 if (vtd->vd_probe == NULL)
1270 if (vtd->vd_probe(vd) == CN_DEAD)
1272 if ((vtdbest == NULL) ||
1273 (vtd->vd_priority > vtdbest->vd_priority))
1276 if (vtdbest == NULL) {
1277 cp->cn_pri = CN_DEAD;
1278 vd->vd_flags |= VDF_DEAD;
1280 vd->vd_driver = vtdbest;
1281 cp->cn_pri = vd->vd_driver->vd_init(vd);
1284 /* Check if driver's vt_init return CN_DEAD. */
1285 if (cp->cn_pri == CN_DEAD) {
1286 vd->vd_flags |= VDF_DEAD;
1289 /* Initialize any early-boot keyboard drivers */
1290 kbd_configure(KB_CONF_PROBE_ONLY);
1292 vd->vd_unit = atomic_fetchadd_int(&vt_unit, 1);
1293 vd->vd_windows[VT_CONSWINDOW] = vw;
1294 sprintf(cp->cn_name, "ttyv%r", VT_UNIT(vw));
1296 /* Attach default font if not in TEXTMODE. */
1297 if ((vd->vd_flags & VDF_TEXTMODE) == 0) {
1298 vw->vw_font = vtfont_ref(&vt_font_default);
1299 vt_compute_drawable_area(vw);
1303 * The original screen size was faked (_VTDEFW x _VTDEFH). Now
1304 * that we have the real viewable size, fix it in the static
1307 if (vd->vd_width != 0 && vd->vd_height != 0)
1308 vt_termsize(vd, vw->vw_font, &vw->vw_buf.vb_scr_size);
1310 vtbuf_init_early(&vw->vw_buf);
1311 vt_winsize(vd, vw->vw_font, &wsz);
1312 c = (boothowto & RB_MUTE) == 0 ? TERMINAL_KERN_ATTR :
1314 attr.ta_format = TCHAR_FORMAT(c);
1315 attr.ta_fgcolor = TCHAR_FGCOLOR(c);
1316 attr.ta_bgcolor = TCHAR_BGCOLOR(c);
1317 terminal_set_winsize_blank(tm, &wsz, 1, &attr);
1319 if (vtdbest != NULL) {
1323 vd->vd_flags |= VDF_INITIALIZED;
1328 vtterm_cngetc(struct terminal *tm)
1330 struct vt_window *vw = tm->tm_softc;
1331 struct vt_device *vd = vw->vw_device;
1335 if (vw->vw_kbdsq && *vw->vw_kbdsq)
1336 return (*vw->vw_kbdsq++);
1338 /* Make sure the splash screen is not there. */
1339 if (vd->vd_flags & VDF_SPLASH) {
1341 vd->vd_flags &= ~VDF_SPLASH;
1342 /* Mark screen as invalid to force update */
1343 vd->vd_flags |= VDF_INVALID;
1347 /* Stripped down keyboard handler. */
1348 kbd = kbd_get_keyboard(vd->vd_keyboard);
1352 /* Force keyboard input mode to K_XLATE */
1353 vw->vw_kbdmode = K_XLATE;
1354 vt_update_kbd_mode(vw, kbd);
1356 /* Switch the keyboard to polling to make it work here. */
1357 kbdd_poll(kbd, TRUE);
1358 c = kbdd_read_char(kbd, 0);
1359 kbdd_poll(kbd, FALSE);
1363 if (vw->vw_flags & VWF_SCROLL) {
1364 vt_scrollmode_kbdevent(vw, c, 1/* Console mode */);
1369 /* Stripped down handling of vt_kbdevent(), without locking, etc. */
1373 vt_save_kbd_state(vw, kbd);
1374 if (vw->vw_kbdstate & SLKED) {
1375 /* Turn scrolling on. */
1376 vw->vw_flags |= VWF_SCROLL;
1377 VTBUF_SLCK_ENABLE(&vw->vw_buf);
1379 /* Turn scrolling off. */
1380 vt_scroll(vw, 0, VHS_END);
1381 vw->vw_flags &= ~VWF_SCROLL;
1382 VTBUF_SLCK_DISABLE(&vw->vw_buf);
1385 /* XXX: KDB can handle history. */
1386 case SPCLKEY | FKEY | F(50): /* Arrow up. */
1387 vw->vw_kbdsq = "\x1b[A";
1389 case SPCLKEY | FKEY | F(58): /* Arrow down. */
1390 vw->vw_kbdsq = "\x1b[B";
1392 case SPCLKEY | FKEY | F(55): /* Arrow right. */
1393 vw->vw_kbdsq = "\x1b[C";
1395 case SPCLKEY | FKEY | F(53): /* Arrow left. */
1396 vw->vw_kbdsq = "\x1b[D";
1400 /* Force refresh to make scrollback work. */
1402 } else if (KEYFLAGS(c) == 0) {
1403 return (KEYCHAR(c));
1406 if (vw->vw_kbdsq && *vw->vw_kbdsq)
1407 return (*vw->vw_kbdsq++);
1413 vtterm_cngrab(struct terminal *tm)
1415 struct vt_device *vd;
1416 struct vt_window *vw;
1423 vt_window_switch(vw);
1425 kbd = kbd_get_keyboard(vd->vd_keyboard);
1429 if (vw->vw_grabbed++ > 0)
1433 * Make sure the keyboard is accessible even when the kbd device
1434 * driver is disabled.
1438 /* We shall always use the keyboard in the XLATE mode here. */
1439 vw->vw_prev_kbdmode = vw->vw_kbdmode;
1440 vw->vw_kbdmode = K_XLATE;
1441 vt_update_kbd_mode(vw, kbd);
1443 kbdd_poll(kbd, TRUE);
1447 vtterm_cnungrab(struct terminal *tm)
1449 struct vt_device *vd;
1450 struct vt_window *vw;
1456 kbd = kbd_get_keyboard(vd->vd_keyboard);
1460 if (--vw->vw_grabbed > 0)
1463 kbdd_poll(kbd, FALSE);
1465 vw->vw_kbdmode = vw->vw_prev_kbdmode;
1466 vt_update_kbd_mode(vw, kbd);
1471 vtterm_opened(struct terminal *tm, int opened)
1473 struct vt_window *vw = tm->tm_softc;
1474 struct vt_device *vd = vw->vw_device;
1477 vd->vd_flags &= ~VDF_SPLASH;
1479 vw->vw_flags |= VWF_OPENED;
1481 vw->vw_flags &= ~VWF_OPENED;
1482 /* TODO: finish ACQ/REL */
1488 vt_set_border(struct vt_window *vw, term_color_t c)
1490 struct vt_device *vd = vw->vw_device;
1492 if (vd->vd_driver->vd_drawrect == NULL)
1496 if (vw->vw_draw_area.tr_begin.tp_row > 0)
1497 vd->vd_driver->vd_drawrect(vd,
1499 vd->vd_width - 1, vw->vw_draw_area.tr_begin.tp_row - 1,
1503 if (vw->vw_draw_area.tr_begin.tp_col > 0)
1504 vd->vd_driver->vd_drawrect(vd,
1506 vw->vw_draw_area.tr_begin.tp_col - 1, vd->vd_height - 1,
1510 if (vw->vw_draw_area.tr_end.tp_col < vd->vd_width)
1511 vd->vd_driver->vd_drawrect(vd,
1512 vw->vw_draw_area.tr_end.tp_col - 1, 0,
1513 vd->vd_width - 1, vd->vd_height - 1,
1517 if (vw->vw_draw_area.tr_end.tp_row < vd->vd_height)
1518 vd->vd_driver->vd_drawrect(vd,
1519 0, vw->vw_draw_area.tr_end.tp_row - 1,
1520 vd->vd_width - 1, vd->vd_height - 1,
1527 vt_change_font(struct vt_window *vw, struct vt_font *vf)
1529 struct vt_device *vd = vw->vw_device;
1530 struct terminal *tm = vw->vw_terminal;
1537 * Changing fonts is a little tricky. We must prevent
1538 * simultaneous access to the device, so we must stop
1539 * the display timer and the terminal from accessing.
1540 * We need to switch fonts and grow our screen buffer.
1542 * XXX: Right now the code uses terminal_mute() to
1543 * prevent data from reaching the console driver while
1544 * resizing the screen buffer. This isn't elegant...
1548 if (vw->vw_flags & VWF_BUSY) {
1549 /* Another process is changing the font. */
1553 vw->vw_flags |= VWF_BUSY;
1556 vt_termsize(vd, vf, &size);
1557 vt_winsize(vd, vf, &wsz);
1559 /* Grow the screen buffer and terminal. */
1560 terminal_mute(tm, 1);
1561 vtbuf_grow(&vw->vw_buf, &size, vw->vw_buf.vb_history_size);
1562 terminal_set_winsize_blank(tm, &wsz, 0, NULL);
1563 terminal_set_cursor(tm, &vw->vw_buf.vb_cursor);
1564 terminal_mute(tm, 0);
1566 /* Actually apply the font to the current window. */
1568 if (vw->vw_font != vf && vw->vw_font != NULL && vf != NULL) {
1570 * In case vt_change_font called to update size we don't need
1571 * to update font link.
1573 vtfont_unref(vw->vw_font);
1574 vw->vw_font = vtfont_ref(vf);
1578 * Compute the drawable area and move the mouse cursor inside
1579 * it, in case the new area is smaller than the previous one.
1581 vt_compute_drawable_area(vw);
1582 vd->vd_mx = min(vd->vd_mx,
1583 vw->vw_draw_area.tr_end.tp_col -
1584 vw->vw_draw_area.tr_begin.tp_col - 1);
1585 vd->vd_my = min(vd->vd_my,
1586 vw->vw_draw_area.tr_end.tp_row -
1587 vw->vw_draw_area.tr_begin.tp_row - 1);
1589 /* Force a full redraw the next timer tick. */
1590 if (vd->vd_curwindow == vw) {
1591 vt_set_border(vw, TC_BLACK);
1592 vd->vd_flags |= VDF_INVALID;
1593 vt_resume_flush_timer(vw->vw_device, 0);
1595 vw->vw_flags &= ~VWF_BUSY;
1601 vt_proc_alive(struct vt_window *vw)
1605 if (vw->vw_smode.mode != VT_PROCESS)
1609 if ((p = pfind(vw->vw_pid)) != NULL)
1611 if (vw->vw_proc == p)
1614 vw->vw_smode.mode = VT_AUTO;
1615 DPRINTF(1, "vt controlling process %d died\n", vw->vw_pid);
1622 signal_vt_rel(struct vt_window *vw)
1625 if (vw->vw_smode.mode != VT_PROCESS)
1627 if (vw->vw_proc == NULL || vt_proc_alive(vw) == FALSE) {
1632 vw->vw_flags |= VWF_SWWAIT_REL;
1633 PROC_LOCK(vw->vw_proc);
1634 kern_psignal(vw->vw_proc, vw->vw_smode.relsig);
1635 PROC_UNLOCK(vw->vw_proc);
1636 DPRINTF(1, "sending relsig to %d\n", vw->vw_pid);
1641 signal_vt_acq(struct vt_window *vw)
1644 if (vw->vw_smode.mode != VT_PROCESS)
1646 if (vw == vw->vw_device->vd_windows[VT_CONSWINDOW])
1647 cnavailable(vw->vw_terminal->consdev, FALSE);
1648 if (vw->vw_proc == NULL || vt_proc_alive(vw) == FALSE) {
1653 vw->vw_flags |= VWF_SWWAIT_ACQ;
1654 PROC_LOCK(vw->vw_proc);
1655 kern_psignal(vw->vw_proc, vw->vw_smode.acqsig);
1656 PROC_UNLOCK(vw->vw_proc);
1657 DPRINTF(1, "sending acqsig to %d\n", vw->vw_pid);
1662 finish_vt_rel(struct vt_window *vw, int release, int *s)
1665 if (vw->vw_flags & VWF_SWWAIT_REL) {
1666 vw->vw_flags &= ~VWF_SWWAIT_REL;
1668 callout_drain(&vw->vw_proc_dead_timer);
1669 vt_late_window_switch(vw->vw_switch_to);
1677 finish_vt_acq(struct vt_window *vw)
1680 if (vw->vw_flags & VWF_SWWAIT_ACQ) {
1681 vw->vw_flags &= ~VWF_SWWAIT_ACQ;
1687 #ifndef SC_NO_CUTPASTE
1689 vt_mouse_terminput_button(struct vt_device *vd, int button)
1691 struct vt_window *vw;
1693 char mouseb[6] = "\x1B[M";
1696 vw = vd->vd_curwindow;
1699 /* Translate to char position. */
1700 x = vd->vd_mx / vf->vf_width;
1701 y = vd->vd_my / vf->vf_height;
1702 /* Avoid overflow. */
1703 x = MIN(x, 255 - '!');
1704 y = MIN(y, 255 - '!');
1706 mouseb[3] = ' ' + button;
1707 mouseb[4] = '!' + x;
1708 mouseb[5] = '!' + y;
1710 for (i = 0; i < sizeof(mouseb); i++)
1711 terminal_input_char(vw->vw_terminal, mouseb[i]);
1715 vt_mouse_terminput(struct vt_device *vd, int type, int x, int y, int event,
1720 case MOUSE_BUTTON_EVENT:
1722 /* Mouse button pressed. */
1723 if (event & MOUSE_BUTTON1DOWN)
1724 vt_mouse_terminput_button(vd, 0);
1725 if (event & MOUSE_BUTTON2DOWN)
1726 vt_mouse_terminput_button(vd, 1);
1727 if (event & MOUSE_BUTTON3DOWN)
1728 vt_mouse_terminput_button(vd, 2);
1730 /* Mouse button released. */
1731 vt_mouse_terminput_button(vd, 3);
1735 case MOUSE_MOTION_EVENT:
1736 if (mouse->u.data.z < 0) {
1738 sc_mouse_input_button(vd, 64);
1739 } else if (mouse->u.data.z > 0) {
1741 sc_mouse_input_button(vd, 65);
1754 len = VD_PASTEBUFLEN(main_vd);
1755 buf = VD_PASTEBUF(main_vd);
1756 len /= sizeof(term_char_t);
1757 for (i = 0; i < len; i++) {
1760 terminal_input_char(main_vd->vd_curwindow->vw_terminal,
1766 vt_mouse_event(int type, int x, int y, int event, int cnt, int mlevel)
1768 struct vt_device *vd;
1769 struct vt_window *vw;
1775 vw = vd->vd_curwindow;
1779 if (vw->vw_flags & (VWF_MOUSE_HIDE | VWF_GRAPHICS))
1781 * Either the mouse is disabled, or the window is in
1782 * "graphics mode". The graphics mode is usually set by
1783 * an X server, using the KDSETMODE ioctl.
1787 if (vf == NULL) /* Text mode. */
1791 * TODO: add flag about pointer position changed, to not redraw chars
1792 * under mouse pointer when nothing changed.
1795 if (vw->vw_mouse_level > 0)
1796 vt_mouse_terminput(vd, type, x, y, event, cnt);
1800 case MOUSE_MOTION_EVENT:
1805 vt_termsize(vd, vf, &size);
1810 x = MIN(x, (size.tp_col * vf->vf_width) - 1);
1811 y = MIN(y, (size.tp_row * vf->vf_height) - 1);
1815 if (vd->vd_mstate & MOUSE_BUTTON1DOWN)
1816 vtbuf_set_mark(&vw->vw_buf, VTB_MARK_MOVE,
1817 vd->vd_mx / vf->vf_width,
1818 vd->vd_my / vf->vf_height);
1820 vt_resume_flush_timer(vw->vw_device, 0);
1822 case MOUSE_BUTTON_EVENT:
1830 case MOUSE_BUTTON1DOWN:
1833 mark = VTB_MARK_END;
1835 case 1: /* single click: start cut operation */
1836 mark = VTB_MARK_START;
1838 case 2: /* double click: cut a word */
1839 mark = VTB_MARK_WORD;
1841 case 3: /* triple click: cut a line */
1842 mark = VTB_MARK_ROW;
1846 case VT_MOUSE_PASTEBUTTON:
1855 case VT_MOUSE_EXTENDBUTTON:
1858 if (!(vd->vd_mstate & MOUSE_BUTTON1DOWN))
1859 mark = VTB_MARK_EXTEND;
1864 mark = VTB_MARK_EXTEND;
1872 /* Save buttons state. */
1874 vd->vd_mstate |= event;
1876 vd->vd_mstate &= ~event;
1878 if (vtbuf_set_mark(&vw->vw_buf, mark, vd->vd_mx / vf->vf_width,
1879 vd->vd_my / vf->vf_height) == 1) {
1881 * We have something marked to copy, so update pointer to
1882 * window with selection.
1884 vt_resume_flush_timer(vw->vw_device, 0);
1890 case VTB_MARK_EXTEND:
1893 /* Other types of mark do not require to copy data. */
1897 /* Get current selection size in bytes. */
1898 len = vtbuf_get_marked_len(&vw->vw_buf);
1902 /* Reallocate buffer only if old one is too small. */
1903 if (len > VD_PASTEBUFSZ(vd)) {
1904 VD_PASTEBUF(vd) = realloc(VD_PASTEBUF(vd), len, M_VT,
1906 /* Update buffer size. */
1907 VD_PASTEBUFSZ(vd) = len;
1909 /* Request copy/paste buffer data, no more than `len' */
1910 vtbuf_extract_marked(&vw->vw_buf, VD_PASTEBUF(vd),
1913 VD_PASTEBUFLEN(vd) = len;
1915 /* XXX VD_PASTEBUF(vd) have to be freed on shutdown/unload. */
1920 vt_mouse_state(int show)
1922 struct vt_device *vd;
1923 struct vt_window *vw;
1926 vw = vd->vd_curwindow;
1930 vw->vw_flags |= VWF_MOUSE_HIDE;
1933 vw->vw_flags &= ~VWF_MOUSE_HIDE;
1937 /* Mark mouse position as dirty. */
1938 vt_mark_mouse_position_as_dirty(vd);
1939 vt_resume_flush_timer(vw->vw_device, 0);
1944 vtterm_mmap(struct terminal *tm, vm_ooffset_t offset, vm_paddr_t * paddr,
1945 int nprot, vm_memattr_t *memattr)
1947 struct vt_window *vw = tm->tm_softc;
1948 struct vt_device *vd = vw->vw_device;
1950 if (vd->vd_driver->vd_fb_mmap)
1951 return (vd->vd_driver->vd_fb_mmap(vd, offset, paddr, nprot,
1958 vtterm_ioctl(struct terminal *tm, u_long cmd, caddr_t data,
1961 struct vt_window *vw = tm->tm_softc;
1962 struct vt_device *vd = vw->vw_device;
1965 #if defined(COMPAT_FREEBSD6) || defined(COMPAT_FREEBSD5) || \
1966 defined(COMPAT_FREEBSD4) || defined(COMPAT_43)
1977 cmd = VT_WAITACTIVE;
2003 ival = IOCPARM_IVAL(data);
2004 data = (caddr_t)&ival;
2009 case KDSETRAD: /* set keyboard repeat & delay rates (old) */
2010 if (*(int *)data & ~0x7f)
2015 case GIO_DEADKEYMAP:
2016 case PIO_DEADKEYMAP:
2021 case KDGETREPEAT: /* get keyboard repeat & delay rates */
2022 case KDSETREPEAT: /* set keyboard repeat & delay rates (new) */
2023 case KBADDKBD: /* add/remove keyboard to/from mux */
2028 kbd = kbd_get_keyboard(vd->vd_keyboard);
2030 error = kbdd_ioctl(kbd, cmd, data);
2032 if (error == ENOIOCTL) {
2033 if (cmd == KDGKBTYPE) {
2034 /* always return something? XXX */
2042 case KDGKBSTATE: { /* get keyboard state (locks) */
2045 if (vw == vd->vd_curwindow) {
2047 kbd = kbd_get_keyboard(vd->vd_keyboard);
2049 error = vt_save_kbd_state(vw, kbd);
2056 *(int *)data = vw->vw_kbdstate & LOCK_MASK;
2060 case KDSKBSTATE: { /* set keyboard state (locks) */
2063 state = *(int *)data;
2064 if (state & ~LOCK_MASK)
2067 vw->vw_kbdstate &= ~LOCK_MASK;
2068 vw->vw_kbdstate |= state;
2071 if (vw == vd->vd_curwindow) {
2073 kbd = kbd_get_keyboard(vd->vd_keyboard);
2075 error = vt_update_kbd_state(vw, kbd);
2081 case KDGETLED: { /* get keyboard LED status */
2084 if (vw == vd->vd_curwindow) {
2086 kbd = kbd_get_keyboard(vd->vd_keyboard);
2088 error = vt_save_kbd_leds(vw, kbd);
2095 *(int *)data = vw->vw_kbdstate & LED_MASK;
2099 case KDSETLED: { /* set keyboard LED status */
2102 leds = *(int *)data;
2103 if (leds & ~LED_MASK)
2106 vw->vw_kbdstate &= ~LED_MASK;
2107 vw->vw_kbdstate |= leds;
2110 if (vw == vd->vd_curwindow) {
2112 kbd = kbd_get_keyboard(vd->vd_keyboard);
2114 error = vt_update_kbd_leds(vw, kbd);
2123 if (vw == vd->vd_curwindow) {
2125 kbd = kbd_get_keyboard(vd->vd_keyboard);
2127 error = vt_save_kbd_mode(vw, kbd);
2134 *(int *)data = vw->vw_kbdmode;
2141 mode = *(int *)data;
2146 vw->vw_kbdmode = mode;
2149 if (vw == vd->vd_curwindow) {
2151 kbd = kbd_get_keyboard(vd->vd_keyboard);
2153 error = vt_update_kbd_mode(vw, kbd);
2163 case FBIO_GETWINORG: /* get frame buffer window origin */
2164 case FBIO_GETDISPSTART: /* get display start address */
2165 case FBIO_GETLINEWIDTH: /* get scan line width in bytes */
2166 case FBIO_BLANK: /* blank display */
2167 if (vd->vd_driver->vd_fb_ioctl)
2168 return (vd->vd_driver->vd_fb_ioctl(vd, cmd, data, td));
2170 case CONS_BLANKTIME:
2175 *(int *)data = M_CG640x480;
2177 case CONS_BELLTYPE: /* set bell type sound */
2178 if ((*(int *)data) & CONS_QUIET_BELL)
2179 vd->vd_flags |= VDF_QUIET_BELL;
2181 vd->vd_flags &= ~VDF_QUIET_BELL;
2183 case CONS_GETINFO: {
2184 vid_info_t *vi = (vid_info_t *)data;
2185 if (vi->size != sizeof(struct vid_info))
2188 if (vw == vd->vd_curwindow) {
2189 kbd = kbd_get_keyboard(vd->vd_keyboard);
2191 vt_save_kbd_state(vw, kbd);
2194 vi->m_num = vd->vd_curwindow->vw_number + 1;
2195 vi->mk_keylock = vw->vw_kbdstate & LOCK_MASK;
2196 /* XXX: other fields! */
2200 *(int *)data = 0x200;
2205 case CONS_MOUSECTL: {
2206 mouse_info_t *mouse = (mouse_info_t*)data;
2209 * All the commands except MOUSE_SHOW nd MOUSE_HIDE
2210 * should not be applied to individual TTYs, but only to
2213 switch (mouse->operation) {
2215 if (vd->vd_flags & VDF_MOUSECURSOR) {
2216 vd->vd_flags &= ~VDF_MOUSECURSOR;
2217 #ifndef SC_NO_CUTPASTE
2218 vt_mouse_state(VT_MOUSE_HIDE);
2223 if (!(vd->vd_flags & VDF_MOUSECURSOR)) {
2224 vd->vd_flags |= VDF_MOUSECURSOR;
2225 vd->vd_mx = vd->vd_width / 2;
2226 vd->vd_my = vd->vd_height / 2;
2227 #ifndef SC_NO_CUTPASTE
2228 vt_mouse_state(VT_MOUSE_SHOW);
2239 if (vd->vd_flags & VDF_TEXTMODE)
2242 error = vtfont_load((void *)data, &vf);
2246 error = vt_change_font(vw, vf);
2250 case PIO_VFONT_DEFAULT: {
2251 /* Reset to default font. */
2252 error = vt_change_font(vw, &vt_font_default);
2256 scrmap_t *sm = (scrmap_t *)data;
2258 /* We don't have screen maps, so return a handcrafted one. */
2259 for (i = 0; i < 256; i++)
2265 * FIXME: This implementation is incomplete compared to
2268 switch (*(int *)data) {
2272 vw->vw_flags &= ~VWF_GRAPHICS;
2275 vw->vw_flags |= VWF_GRAPHICS;
2279 case KDENABIO: /* allow io operations */
2280 error = priv_check(td, PRIV_IO);
2283 error = securelevel_gt(td->td_ucred, 0);
2286 #if defined(__i386__)
2287 td->td_frame->tf_eflags |= PSL_IOPL;
2288 #elif defined(__amd64__)
2289 td->td_frame->tf_rflags |= PSL_IOPL;
2292 case KDDISABIO: /* disallow io operations (default) */
2293 #if defined(__i386__)
2294 td->td_frame->tf_eflags &= ~PSL_IOPL;
2295 #elif defined(__amd64__)
2296 td->td_frame->tf_rflags &= ~PSL_IOPL;
2299 case KDMKTONE: /* sound the bell */
2300 vtterm_beep(tm, *(u_int *)data);
2302 case KIOCSOUND: /* make tone (*data) hz */
2305 case CONS_SETKBD: /* set the new keyboard */
2308 if (vd->vd_keyboard != *(int *)data) {
2309 kbd = kbd_get_keyboard(*(int *)data);
2314 i = kbd_allocate(kbd->kb_name, kbd->kb_unit,
2315 (void *)vd, vt_kbdevent, vd);
2317 if (vd->vd_keyboard != -1) {
2318 vt_save_kbd_state(vd->vd_curwindow, kbd);
2319 kbd_release(kbd, (void *)vd);
2321 kbd = kbd_get_keyboard(i);
2322 vd->vd_keyboard = i;
2324 vt_update_kbd_mode(vd->vd_curwindow, kbd);
2325 vt_update_kbd_state(vd->vd_curwindow, kbd);
2327 error = EPERM; /* XXX */
2332 case CONS_RELKBD: /* release the current keyboard */
2335 if (vd->vd_keyboard != -1) {
2336 kbd = kbd_get_keyboard(vd->vd_keyboard);
2341 vt_save_kbd_state(vd->vd_curwindow, kbd);
2342 error = kbd_release(kbd, (void *)vd);
2344 vd->vd_keyboard = -1;
2351 win = *(int *)data - 1;
2352 DPRINTF(5, "%s%d: VT_ACTIVATE ttyv%d ", SC_DRIVER_NAME,
2354 if ((win >= VT_MAXWINDOWS) || (win < 0))
2356 return (vt_proc_window_switch(vd->vd_windows[win]));
2359 *(int *)data = vd->vd_curwindow->vw_number + 1;
2362 *(int *)data = vw->vw_number + 1;
2365 /* TODO: Check current state, switching can be in progress. */
2366 if ((*(int *)data) == 0x01)
2367 vw->vw_flags |= VWF_VTYLOCK;
2368 else if ((*(int *)data) == 0x02)
2369 vw->vw_flags &= ~VWF_VTYLOCK;
2375 for (i = 0; i < VT_MAXWINDOWS; i++) {
2376 vw = vd->vd_windows[i];
2379 if (!(vw->vw_flags & VWF_OPENED)) {
2380 *(int *)data = vw->vw_number + 1;
2387 case VT_WAITACTIVE: {
2392 idx = *(unsigned int *)data;
2393 if (idx > VT_MAXWINDOWS)
2396 vw = vd->vd_windows[idx - 1];
2399 while (vd->vd_curwindow != vw && error == 0)
2400 error = cv_wait_sig(&vd->vd_winswitch, &vd->vd_lock);
2404 case VT_SETMODE: { /* set screen switcher mode */
2405 struct vt_mode *mode;
2408 mode = (struct vt_mode *)data;
2409 DPRINTF(5, "%s%d: VT_SETMODE ", SC_DRIVER_NAME, VT_UNIT(vw));
2410 if (vw->vw_smode.mode == VT_PROCESS) {
2411 p1 = pfind(vw->vw_pid);
2412 if (vw->vw_proc == p1 && vw->vw_proc != td->td_proc) {
2415 DPRINTF(5, "error EPERM\n");
2421 if (mode->mode == VT_AUTO) {
2422 vw->vw_smode.mode = VT_AUTO;
2425 DPRINTF(5, "VT_AUTO, ");
2426 if (vw == vw->vw_device->vd_windows[VT_CONSWINDOW])
2427 cnavailable(vw->vw_terminal->consdev, TRUE);
2428 /* were we in the middle of the vty switching process? */
2429 if (finish_vt_rel(vw, TRUE, &s) == 0)
2430 DPRINTF(5, "reset WAIT_REL, ");
2431 if (finish_vt_acq(vw) == 0)
2432 DPRINTF(5, "reset WAIT_ACQ, ");
2434 } else if (mode->mode == VT_PROCESS) {
2435 if (!ISSIGVALID(mode->relsig) ||
2436 !ISSIGVALID(mode->acqsig) ||
2437 !ISSIGVALID(mode->frsig)) {
2438 DPRINTF(5, "error EINVAL\n");
2441 DPRINTF(5, "VT_PROCESS %d, ", td->td_proc->p_pid);
2442 bcopy(data, &vw->vw_smode, sizeof(struct vt_mode));
2443 vw->vw_proc = td->td_proc;
2444 vw->vw_pid = vw->vw_proc->p_pid;
2445 if (vw == vw->vw_device->vd_windows[VT_CONSWINDOW])
2446 cnavailable(vw->vw_terminal->consdev, FALSE);
2448 DPRINTF(5, "VT_SETMODE failed, unknown mode %d\n",
2455 case VT_GETMODE: /* get screen switcher mode */
2456 bcopy(&vw->vw_smode, data, sizeof(struct vt_mode));
2459 case VT_RELDISP: /* screen switcher ioctl */
2461 * This must be the current vty which is in the VT_PROCESS
2464 if ((vw != vd->vd_curwindow) || (vw->vw_smode.mode !=
2468 /* ...and this process is controlling it. */
2469 if (vw->vw_proc != td->td_proc) {
2473 switch(*(int *)data) {
2474 case VT_FALSE: /* user refuses to release screen, abort */
2475 if ((error = finish_vt_rel(vw, FALSE, &s)) == 0)
2476 DPRINTF(5, "%s%d: VT_RELDISP: VT_FALSE\n",
2477 SC_DRIVER_NAME, VT_UNIT(vw));
2479 case VT_TRUE: /* user has released screen, go on */
2480 /* finish_vt_rel(..., TRUE, ...) should not be locked */
2481 if (vw->vw_flags & VWF_SWWAIT_REL) {
2482 if ((error = finish_vt_rel(vw, TRUE, &s)) == 0)
2483 DPRINTF(5, "%s%d: VT_RELDISP: VT_TRUE\n",
2484 SC_DRIVER_NAME, VT_UNIT(vw));
2489 case VT_ACKACQ: /* acquire acknowledged, switch completed */
2490 if ((error = finish_vt_acq(vw)) == 0)
2491 DPRINTF(5, "%s%d: VT_RELDISP: VT_ACKACQ\n",
2492 SC_DRIVER_NAME, VT_UNIT(vw));
2503 static struct vt_window *
2504 vt_allocate_window(struct vt_device *vd, unsigned int window)
2506 struct vt_window *vw;
2507 struct terminal *tm;
2511 vw = malloc(sizeof *vw, M_VT, M_WAITOK|M_ZERO);
2513 vw->vw_number = window;
2514 vw->vw_kbdmode = K_XLATE;
2516 if ((vd->vd_flags & VDF_TEXTMODE) == 0) {
2517 vw->vw_font = vtfont_ref(&vt_font_default);
2518 vt_compute_drawable_area(vw);
2521 vt_termsize(vd, vw->vw_font, &size);
2522 vt_winsize(vd, vw->vw_font, &wsz);
2523 vtbuf_init(&vw->vw_buf, &size);
2525 tm = vw->vw_terminal = terminal_alloc(&vt_termclass, vw);
2526 terminal_set_winsize(tm, &wsz);
2527 vd->vd_windows[window] = vw;
2528 callout_init(&vw->vw_proc_dead_timer, 0);
2534 vt_upgrade(struct vt_device *vd)
2536 struct vt_window *vw;
2538 int register_handlers;
2540 if (!vty_enabled(VTY_VT))
2542 if (main_vd->vd_driver == NULL)
2545 for (i = 0; i < VT_MAXWINDOWS; i++) {
2546 vw = vd->vd_windows[i];
2549 vw = vt_allocate_window(vd, i);
2551 if (!(vw->vw_flags & VWF_READY)) {
2552 callout_init(&vw->vw_proc_dead_timer, 0);
2553 terminal_maketty(vw->vw_terminal, "v%r", VT_UNIT(vw));
2554 vw->vw_flags |= VWF_READY;
2555 if (vw->vw_flags & VWF_CONSOLE) {
2556 /* For existing console window. */
2557 EVENTHANDLER_REGISTER(shutdown_pre_sync,
2558 vt_window_switch, vw, SHUTDOWN_PRI_DEFAULT);
2564 if (vd->vd_curwindow == NULL)
2565 vd->vd_curwindow = vd->vd_windows[VT_CONSWINDOW];
2567 register_handlers = 0;
2568 if (!(vd->vd_flags & VDF_ASYNC)) {
2569 /* Attach keyboard. */
2570 vt_allocate_keyboard(vd);
2572 /* Init 25 Hz timer. */
2573 callout_init_mtx(&vd->vd_timer, &vd->vd_lock, 0);
2575 /* Start timer when everything ready. */
2576 vd->vd_flags |= VDF_ASYNC;
2577 callout_reset(&vd->vd_timer, hz / VT_TIMERFREQ, vt_timer, vd);
2578 vd->vd_timer_armed = 1;
2579 register_handlers = 1;
2584 /* Refill settings with new sizes. */
2587 if (register_handlers) {
2588 /* Register suspend/resume handlers. */
2589 EVENTHANDLER_REGISTER(power_suspend_early, vt_suspend_handler,
2590 vd, EVENTHANDLER_PRI_ANY);
2591 EVENTHANDLER_REGISTER(power_resume, vt_resume_handler, vd,
2592 EVENTHANDLER_PRI_ANY);
2597 vt_resize(struct vt_device *vd)
2599 struct vt_window *vw;
2602 for (i = 0; i < VT_MAXWINDOWS; i++) {
2603 vw = vd->vd_windows[i];
2605 /* Assign default font to window, if not textmode. */
2606 if (!(vd->vd_flags & VDF_TEXTMODE) && vw->vw_font == NULL)
2607 vw->vw_font = vtfont_ref(&vt_font_default);
2610 /* Resize terminal windows */
2611 while (vt_change_font(vw, vw->vw_font) == EBUSY) {
2612 DPRINTF(100, "%s: vt_change_font() is busy, "
2613 "window %d\n", __func__, i);
2619 vt_replace_backend(const struct vt_driver *drv, void *softc)
2621 struct vt_device *vd;
2625 if (vd->vd_flags & VDF_ASYNC) {
2626 /* Stop vt_flush periodic task. */
2628 vt_suspend_flush_timer(vd);
2631 * Mute current terminal until we done. vt_change_font (called
2632 * from vt_resize) will unmute it.
2634 terminal_mute(vd->vd_curwindow->vw_terminal, 1);
2638 * Reset VDF_TEXTMODE flag, driver who require that flag (vt_vga) will
2642 vd->vd_flags &= ~VDF_TEXTMODE;
2646 * We want to upgrade from the current driver to the
2650 vd->vd_prev_driver = vd->vd_driver;
2651 vd->vd_prev_softc = vd->vd_softc;
2652 vd->vd_driver = drv;
2653 vd->vd_softc = softc;
2655 vd->vd_driver->vd_init(vd);
2656 } else if (vd->vd_prev_driver != NULL && vd->vd_prev_softc != NULL) {
2658 * No driver given: we want to downgrade to the previous
2661 const struct vt_driver *old_drv;
2664 old_drv = vd->vd_driver;
2665 old_softc = vd->vd_softc;
2667 vd->vd_driver = vd->vd_prev_driver;
2668 vd->vd_softc = vd->vd_prev_softc;
2669 vd->vd_prev_driver = NULL;
2670 vd->vd_prev_softc = NULL;
2672 vd->vd_flags |= VDF_DOWNGRADE;
2674 vd->vd_driver->vd_init(vd);
2676 if (old_drv->vd_fini)
2677 old_drv->vd_fini(vd, old_softc);
2679 vd->vd_flags &= ~VDF_DOWNGRADE;
2684 /* Update windows sizes and initialize last items. */
2688 if (vd->vd_flags & VDF_SPLASH)
2692 if (vd->vd_flags & VDF_ASYNC) {
2693 /* Allow to put chars now. */
2694 terminal_mute(vd->vd_curwindow->vw_terminal, 0);
2695 /* Rerun timer for screen updates. */
2696 vt_resume_flush_timer(vd, 0);
2700 * Register as console. If it already registered, cnadd() will ignore
2703 termcn_cnregister(vd->vd_windows[VT_CONSWINDOW]->vw_terminal);
2707 vt_suspend_handler(void *priv)
2709 struct vt_device *vd;
2712 if (vd->vd_driver != NULL && vd->vd_driver->vd_suspend != NULL)
2713 vd->vd_driver->vd_suspend(vd);
2717 vt_resume_handler(void *priv)
2719 struct vt_device *vd;
2722 if (vd->vd_driver != NULL && vd->vd_driver->vd_resume != NULL)
2723 vd->vd_driver->vd_resume(vd);
2727 vt_allocate(const struct vt_driver *drv, void *softc)
2730 if (!vty_enabled(VTY_VT))
2733 if (main_vd->vd_driver == NULL) {
2734 main_vd->vd_driver = drv;
2735 printf("VT: initialize with new VT driver \"%s\".\n",
2739 * Check if have rights to replace current driver. For example:
2740 * it is bad idea to replace KMS driver with generic VGA one.
2742 if (drv->vd_priority <= main_vd->vd_driver->vd_priority) {
2743 printf("VT: Driver priority %d too low. Current %d\n ",
2744 drv->vd_priority, main_vd->vd_driver->vd_priority);
2747 printf("VT: Replacing driver \"%s\" with new \"%s\".\n",
2748 main_vd->vd_driver->vd_name, drv->vd_name);
2751 vt_replace_backend(drv, softc);
2755 vt_deallocate(const struct vt_driver *drv, void *softc)
2758 if (!vty_enabled(VTY_VT))
2761 if (main_vd->vd_prev_driver == NULL ||
2762 main_vd->vd_driver != drv ||
2763 main_vd->vd_softc != softc)
2766 printf("VT: Switching back from \"%s\" to \"%s\".\n",
2767 main_vd->vd_driver->vd_name, main_vd->vd_prev_driver->vd_name);
2769 vt_replace_backend(NULL, NULL);
2773 vt_suspend(struct vt_device *vd)
2777 if (vt_suspendswitch == 0)
2779 /* Save current window. */
2780 vd->vd_savedwindow = vd->vd_curwindow;
2781 /* Ask holding process to free window and switch to console window */
2782 vt_proc_window_switch(vd->vd_windows[VT_CONSWINDOW]);
2784 /* Wait for the window switch to complete. */
2787 while (vd->vd_curwindow != vd->vd_windows[VT_CONSWINDOW] && error == 0)
2788 error = cv_wait_sig(&vd->vd_winswitch, &vd->vd_lock);
2793 vt_resume(struct vt_device *vd)
2796 if (vt_suspendswitch == 0)
2798 /* Switch back to saved window, if any */
2799 vt_proc_window_switch(vd->vd_savedwindow);
2800 vd->vd_savedwindow = NULL;