2 * Copyright (c) 1992-1998 Søren Schmidt
5 * This code is derived from software contributed to The DragonFly Project
6 * by Sascha Wildner <saw@online.de>
8 * Simple font scaling code by Sascha Wildner and Matthew Dillon
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer,
15 * without modification, immediately at the beginning of the file.
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.
19 * 3. The name of the author may not be used to endorse or promote products
20 * derived from this software without specific prior written permission.
22 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
23 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
24 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
25 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
26 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
27 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
31 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 * $FreeBSD: /usr/local/www/cvsroot/FreeBSD/src/sys/dev/syscons/syscons.c,v 1.336.2.17 2004/03/25 08:41:09 ru Exp $
36 #include "use_splash.h"
37 #include "opt_syscons.h"
40 #include <sys/param.h>
41 #include <sys/systm.h>
42 #include <sys/eventhandler.h>
43 #include <sys/reboot.h>
48 #include <sys/signalvar.h>
49 #include <sys/sysctl.h>
50 #include <sys/taskqueue.h>
52 #include <sys/ttydefaults.h> /* for TTYDEF_* */
53 #include <sys/kernel.h>
55 #include <sys/random.h>
58 #include <sys/thread2.h>
59 #include <sys/mutex2.h>
61 #include <machine/clock.h>
62 #include <machine/console.h>
63 #include <machine/psl.h>
64 #include <machine/pc/display.h>
65 #include <machine/frame.h>
66 #include <machine/framebuffer.h>
68 #include <dev/misc/kbd/kbdreg.h>
69 #include <dev/video/fb/fbreg.h>
70 #include <dev/video/fb/splashreg.h>
76 #define DEFAULT_BLANKTIME (5*60) /* 5 minutes */
77 #define MAX_BLANKTIME (7*24*60*60) /* 7 days!? */
79 #define SCRN_ASYNCOK 0x0001
80 #define SCRN_BULKUNLOCK 0x0002
82 #define KEYCODE_BS 0x0e /* "<-- Backspace" key, XXX */
83 #define WANT_UNLOCK(m) do { \
88 #define WANT_LOCK(m) do { \
94 MALLOC_DEFINE(M_SYSCONS
, "syscons", "Syscons");
96 typedef struct default_attr
{
97 int std_color
; /* normal hardware color */
98 int rev_color
; /* reverse hardware color */
101 static default_attr user_default
= {
106 static default_attr kernel_default
= {
108 SC_KERNEL_CONS_REV_ATTR
,
111 static int sc_console_unit
= -1;
112 static scr_stat
*sc_console
;
113 static struct tty
*sc_console_tty
;
114 static void *kernel_console_ts
;
116 static char init_done
= COLD
;
117 static char shutdown_in_progress
= FALSE
;
118 static char sc_malloc
= FALSE
;
119 static char sc_filled_border
= FALSE
; /* filled initial VT border */
121 static int saver_mode
= CONS_NO_SAVER
; /* LKM/user saver */
122 static int run_scrn_saver
= FALSE
; /* should run the saver? */
123 static long scrn_blank_time
= 0; /* screen saver timeout value */
125 static int scrn_blanked
; /* # of blanked screen */
126 static int sticky_splash
= FALSE
;
128 static void none_saver(sc_softc_t
*sc
, int blank
) { }
129 static void (*current_saver
)(sc_softc_t
*, int) = none_saver
;
133 * Lock for asynchronous screen update thread, needed to safely modify the
134 * framebuffer information.
136 static struct lock sc_asynctd_lk
;
138 #if !defined(SC_NO_FONT_LOADING) && defined(SC_DFLT_FONT)
142 static bios_values_t bios_value
;
144 static int enable_panic_key
;
145 SYSCTL_INT(_machdep
, OID_AUTO
, enable_panic_key
, CTLFLAG_RW
, &enable_panic_key
,
146 0, "Enable the panic key (CTRL-ALT-SHIFT-ESC)");
147 static int syscons_async
;
148 SYSCTL_INT(_kern
, OID_AUTO
, syscons_async
, CTLFLAG_RW
, &syscons_async
,
149 0, "Asynchronous bulk syscons fb updates");
151 static int desired_cols
= 0;
152 TUNABLE_INT("kern.kms_columns", &desired_cols
);
154 #define SC_CONSOLECTL 255
156 #define VIRTUAL_TTY(sc, x) ((SC_DEV((sc),(x)) != NULL) ? \
157 (SC_DEV((sc),(x))->si_tty) : NULL)
158 #define ISTTYOPEN(tp) ((tp) && ((tp)->t_state & TS_ISOPEN))
161 static cdev_t cctl_dev
;
162 static timeout_t blink_screen_callout
;
163 static void sc_blink_screen(scr_stat
*scp
);
164 static struct mtx syscons_mtx
= MTX_INITIALIZER("syscons");
165 static struct lock syscons_blink_lk
= LOCK_INITIALIZER("sblnk", 0, 0);
168 static int scvidprobe(int unit
, int flags
, int cons
);
169 static int sckbdprobe(int unit
, int flags
, int cons
);
170 static void scmeminit(void *arg
);
171 static int scdevtounit(cdev_t dev
);
172 static kbd_callback_func_t sckbdevent
;
173 static int scparam(struct tty
*tp
, struct termios
*t
);
174 static void scstart(struct tty
*tp
);
175 static void scinit(int unit
, int flags
);
177 static void scterm(int unit
, int flags
);
179 static void scshutdown(void *arg
, int howto
);
180 static void sc_puts(scr_stat
*scp
, u_char
*buf
, int len
);
181 static u_int
scgetc(sc_softc_t
*sc
, u_int flags
);
183 #define SCGETC_NONBLOCK 2
184 static int sccngetch(int flags
);
185 static void sccnupdate(scr_stat
*scp
);
186 static scr_stat
*alloc_scp(sc_softc_t
*sc
, int vty
);
187 static void init_scp(sc_softc_t
*sc
, int vty
, scr_stat
*scp
);
188 static timeout_t scrn_timer
;
189 static int and_region(int *s1
, int *e1
, int s2
, int e2
);
190 static void scrn_update(scr_stat
*scp
, int show_cursor
, int flags
);
191 static void scrn_update_thread(void *arg
);
193 static void sc_fb_set_par(void *context
, int pending
);
195 static void sc_fb_blank(void *context
, int pending
);
199 static void scframebuffer_saver(sc_softc_t
*sc
, int show
);
200 static int scsplash_callback(int event
, void *arg
);
201 static void scsplash_saver(sc_softc_t
*sc
, int show
);
202 static int add_scrn_saver(void (*this_saver
)(sc_softc_t
*, int));
203 static int remove_scrn_saver(void (*this_saver
)(sc_softc_t
*, int));
204 static int set_scrn_saver_mode(scr_stat
*scp
, int mode
, u_char
*pal
, int border
);
205 static int restore_scrn_saver_mode(scr_stat
*scp
, int changemode
);
206 static void stop_scrn_saver(sc_softc_t
*sc
, void (*saver
)(sc_softc_t
*, int));
207 static int wait_scrn_saver_stop(sc_softc_t
*sc
, int need_unlock
);
208 #define scsplash_stick(stick) (sticky_splash = (stick))
210 #define scsplash_stick(stick)
213 static void do_switch_scr(sc_softc_t
*sc
);
214 static int vt_proc_alive(scr_stat
*scp
);
215 static int signal_vt_rel(scr_stat
*scp
);
216 static int signal_vt_acq(scr_stat
*scp
);
217 static int finish_vt_rel(scr_stat
*scp
, int release
);
218 static int finish_vt_acq(scr_stat
*scp
);
219 static void exchange_scr(sc_softc_t
*sc
);
220 static void update_cursor_image(scr_stat
*scp
);
221 static int save_kbd_state(scr_stat
*scp
, int unlock
);
222 static int update_kbd_state(scr_stat
*scp
, int state
, int mask
, int unlock
);
223 static int update_kbd_leds(scr_stat
*scp
, int which
);
224 static int sc_allocate_keyboard(sc_softc_t
*sc
, int unit
);
227 * Console locking support functions.
229 * We use mutex spinlocks here in order to allow reentrancy which should
230 * avoid issues during panics.
232 * A panic can stop a cpu while it is holding the syscons_mtx. If this
233 * occurs we try for up to 1/2 a second and then blow the spinlock away.
234 * The asynchronous update thread makes this happen more often.
239 if (panicstr
|| shutdown_in_progress
) {
240 int retries
= 500000;
241 while (mtx_spinlock_try(&syscons_mtx
)) {
242 tsc_delay(1000); /* 1uS */
243 if (--retries
== 0) {
244 mtx_init(&syscons_mtx
, "syscons");
249 mtx_spinlock(&syscons_mtx
);
254 * Returns 0 on success, EAGAIN on failure.
257 syscons_lock_nonblock(void)
259 return(mtx_spinlock_try(&syscons_mtx
));
265 mtx_spinunlock(&syscons_mtx
);
271 static cn_probe_t sccnprobe
;
272 static cn_init_t sccninit
;
273 static cn_init_t sccninit_fini
;
274 static cn_getc_t sccngetc
;
275 static cn_checkc_t sccncheckc
;
276 static cn_putc_t sccnputc
;
277 static cn_dbctl_t sccndbctl
;
278 static cn_term_t sccnterm
;
279 static cn_poll_t sccnpoll
;
281 CONS_DRIVER(sc
, sccnprobe
, sccninit
, sccninit_fini
, sccnterm
,
282 sccngetc
, sccncheckc
, sccnputc
, sccndbctl
, sccnpoll
);
284 static d_open_t scopen
;
285 static d_close_t scclose
;
286 static d_read_t scread
;
287 static d_ioctl_t scioctl
;
288 static d_mmap_t scmmap
;
290 static struct dev_ops sc_ops
= {
291 { "sc", 0, D_TTY
| D_MPSAFE
},
298 .d_kqfilter
= ttykqfilter
,
299 .d_revoke
= ttyrevoke
303 sc_probe_unit(int unit
, int flags
)
305 if ((flags
& SC_EFI_FB
) && (probe_efi_fb(0) != 0)) {
307 kprintf("sc%d: no EFI framebuffer found.\n", unit
);
311 if (!(flags
& SC_EFI_FB
) && !scvidprobe(unit
, flags
, FALSE
)) {
313 kprintf("sc%d: no video adapter found.\n", unit
);
317 /* syscons will be attached even when there is no keyboard */
318 sckbdprobe(unit
, flags
, FALSE
);
324 register_framebuffer(struct fb_info
*info
)
328 /* For now ignore framebuffers, which don't replace the vga display */
329 if (!info
->is_vga_boot_display
)
332 lwkt_gettoken(&vga_token
);
333 sc
= sc_get_softc(0, (sc_console_unit
== 0) ? SC_KERNEL_CONSOLE
: 0);
335 lwkt_reltoken(&vga_token
);
336 kprintf("%s: sc_get_softc(%d, %d) returned NULL\n", __func__
,
337 0, (sc_console_unit
== 0) ? SC_KERNEL_CONSOLE
: 0);
341 /* Ignore this framebuffer if we already switched to KMS framebuffer */
342 if (sc
->fbi
!= NULL
&& sc
->fbi
!= &efi_fb_info
&&
343 sc
->fbi
!= sc
->dummy_fb_info
) {
344 lwkt_reltoken(&vga_token
);
348 if (sc
->fb_set_par_task
== NULL
) {
349 sc
->fb_set_par_task
= kmalloc(sizeof(struct task
),
350 M_SYSCONS
, M_WAITOK
| M_ZERO
);
352 TASK_INIT(sc
->fb_set_par_task
, 0, sc_fb_set_par
, sc
);
354 if (sc
->fb_blank_task
== NULL
) {
355 sc
->fb_blank_task
= kmalloc(sizeof(struct task
),
356 M_SYSCONS
, M_WAITOK
| M_ZERO
);
358 TASK_INIT(sc
->fb_blank_task
, 0, sc_fb_blank
, sc
);
362 * Make sure that console messages don't interfere too much with
365 atomic_add_int(&sc
->videoio_in_progress
, 1);
367 /* Lock against synchronous and asynchronous screen updates */
368 lockmgr(&sc_asynctd_lk
, LK_EXCLUSIVE
);
371 sc
->fbi_generation
++;
374 kprintf("kms console: xpixels %d ypixels %d\n",
375 sc
->fbi
->width
, sc
->fbi
->height
);
376 sc_update_render(sc
->cur_scp
);
377 if (info
->fbops
.fb_set_par
!= NULL
)
378 info
->fbops
.fb_set_par(info
);
379 atomic_add_int(&sc
->videoio_in_progress
, -1);
381 sc
->fb_blanked
= FALSE
;
382 if (sc
->unit
== sc_console_unit
&& sc
->cur_scp
->smode
.mode
!= VT_AUTO
)
383 cons_unavail
= FALSE
;
385 if (info
->fbops
.fb_blank
!= NULL
)
386 add_scrn_saver(scframebuffer_saver
);
389 lockmgr(&sc_asynctd_lk
, LK_RELEASE
);
390 lwkt_reltoken(&vga_token
);
395 unregister_framebuffer(struct fb_info
*info
)
399 lwkt_gettoken(&vga_token
);
400 sc
= sc_get_softc(0, (sc_console_unit
== 0) ? SC_KERNEL_CONSOLE
: 0);
402 lwkt_reltoken(&vga_token
);
403 kprintf("%s: sc_get_softc(%d, %d) returned NULL\n", __func__
,
404 0, (sc_console_unit
== 0) ? SC_KERNEL_CONSOLE
: 0);
408 if (sc
->fbi
!= info
) {
409 lwkt_reltoken(&vga_token
);
414 if (info
->fbops
.fb_blank
!= NULL
)
415 remove_scrn_saver(scframebuffer_saver
);
418 if (sc
->fb_set_par_task
!= NULL
&&
419 taskqueue_cancel(taskqueue_thread
[0], sc
->fb_set_par_task
, NULL
)) {
420 taskqueue_drain(taskqueue_thread
[0], sc
->fb_set_par_task
);
423 if (sc
->fb_blank_task
!= NULL
&&
424 taskqueue_cancel(taskqueue_thread
[0], sc
->fb_blank_task
, NULL
)) {
425 taskqueue_drain(taskqueue_thread
[0], sc
->fb_blank_task
);
428 sc
->fb_blanked
= TRUE
;
429 if (sc
->unit
== sc_console_unit
)
432 if (sc
->dummy_fb_info
== NULL
) {
433 sc
->dummy_fb_info
= kmalloc(sizeof(struct fb_info
),
434 M_SYSCONS
, M_WAITOK
| M_ZERO
);
436 memset(sc
->dummy_fb_info
, 0, sizeof(struct fb_info
));
438 *sc
->dummy_fb_info
= *sc
->fbi
;
439 sc
->dummy_fb_info
->vaddr
= 0;
440 sc
->dummy_fb_info
->fbops
.fb_set_par
= NULL
;
441 sc
->dummy_fb_info
->fbops
.fb_blank
= NULL
;
442 sc
->dummy_fb_info
->fbops
.fb_debug_enter
= NULL
;
444 /* Lock against synchronous and asynchronous screen updates */
445 lockmgr(&sc_asynctd_lk
, LK_EXCLUSIVE
);
447 sc
->fbi
= sc
->dummy_fb_info
;
449 lockmgr(&sc_asynctd_lk
, LK_RELEASE
);
451 lwkt_reltoken(&vga_token
);
455 sc_font_scale(scr_stat
*scp
, int max_cols
, int max_rows
)
460 * If columns not specified in /boot/loader.conf then
461 * calculate a non-fractional scaling that yields a
462 * reasonable number of rows and columns. If it is <0,
463 * don't scale at all.
465 if (desired_cols
== 0) {
467 while (scp
->xpixel
/ (scp
->font_width
* nomag
) >= COL
&&
468 scp
->ypixel
/ (scp
->font_height
* nomag
) >= ROW
) {
473 cols
= scp
->xpixel
/ (scp
->font_width
* nomag
);
474 } else if (desired_cols
< 0) {
475 cols
= scp
->xpixel
/ scp
->font_width
;
479 scp
->blk_width
= scp
->xpixel
/ cols
;
480 scp
->blk_height
= scp
->blk_width
* scp
->font_height
/ scp
->font_width
;
481 rows
= scp
->ypixel
/ scp
->blk_height
;
483 /* scp->xsize = scp->xpixel / scp->blk_width; total possible */
484 scp
->xsize
= max_cols
? imin(max_cols
, cols
) : cols
;
485 scp
->ysize
= max_rows
? imin(max_rows
, rows
) : rows
;
488 /* probe video adapters, return TRUE if found */
490 scvidprobe(int unit
, int flags
, int cons
)
493 * Access the video adapter driver through the back door!
494 * Video adapter drivers need to be configured before syscons.
495 * However, when syscons is being probed as the low-level console,
496 * they have not been initialized yet. We force them to initialize
497 * themselves here. XXX
499 vid_configure(cons
? VIO_PROBE_ONLY
: 0);
501 return (vid_find_adapter("*", unit
) >= 0);
504 /* probe the keyboard, return TRUE if found */
506 sckbdprobe(int unit
, int flags
, int cons
)
508 /* access the keyboard driver through the backdoor! */
509 kbd_configure(cons
? KB_CONF_PROBE_ONLY
: 0);
511 return (kbd_find_keyboard("*", unit
) >= 0);
515 adapter_name(video_adapter_t
*adp
)
521 { KD_MONO
, { "MDA", "MDA" } },
522 { KD_HERCULES
, { "Hercules", "Hercules" } },
523 { KD_CGA
, { "CGA", "CGA" } },
524 { KD_EGA
, { "EGA", "EGA (mono)" } },
525 { KD_VGA
, { "VGA", "VGA (mono)" } },
526 { KD_TGA
, { "TGA", "TGA" } },
527 { -1, { "Unknown", "Unknown" } },
531 for (i
= 0; names
[i
].type
!= -1; ++i
)
532 if (names
[i
].type
== adp
->va_type
)
534 return names
[i
].name
[(adp
->va_flags
& V_ADP_COLOR
) ? 0 : 1];
538 sc_attach_unit(int unit
, int flags
)
544 flags
&= ~SC_KERNEL_CONSOLE
;
545 char tbuf
[MAKEDEV_MINNBUF
];
547 if ((flags
& SC_EFI_FB
) && probe_efi_fb(0) != 0)
550 if (sc_console_unit
== unit
) {
552 * If this unit is being used as the system console, we need to
553 * adjust some variables and buffers before and after scinit().
555 /* assert(sc_console != NULL) */
556 flags
|= SC_KERNEL_CONSOLE
;
561 if (sc_console
->tsw
->te_size
> 0) {
562 /* assert(sc_console->ts != NULL); */
563 kernel_console_ts
= sc_console
->ts
;
564 sc_console
->ts
= kmalloc(sc_console
->tsw
->te_size
,
565 M_SYSCONS
, M_WAITOK
);
566 bcopy(kernel_console_ts
, sc_console
->ts
, sc_console
->tsw
->te_size
);
567 (*sc_console
->tsw
->te_default_attr
)(sc_console
,
568 user_default
.std_color
,
569 user_default
.rev_color
);
575 sc
= sc_get_softc(unit
, flags
& SC_KERNEL_CONSOLE
);
578 * If this is the console we couldn't setup sc->dev before because
579 * malloc wasn't working. Set it up now.
581 if (flags
& SC_KERNEL_CONSOLE
) {
582 KKASSERT(sc
->dev
== NULL
);
583 sc
->dev
= kmalloc(sizeof(cdev_t
)*sc
->vtys
, M_SYSCONS
, M_WAITOK
|M_ZERO
);
584 sc
->dev
[0] = make_dev(&sc_ops
, sc_console_unit
*MAXCONS
, UID_ROOT
,
585 GID_WHEEL
, 0600, "ttyv%s", makedev_unit_b32(tbuf
,
586 sc_console_unit
* MAXCONS
));
587 ttymalloc(&sc
->dev
[0]->si_tty
);
588 sc
->dev
[0]->si_drv1
= sc_console
;
592 * Finish up the standard attach
595 callout_init_mp(&sc
->scrn_timer_ch
);
596 scp
= SC_STAT(sc
->dev
[0]);
597 if (sc_console
== NULL
) /* sc_console_unit < 0 */
600 /* initialize cursor */
602 update_cursor_image(scp
);
604 /* get screen update going */
607 /* set up the keyboard */
608 kbd_ioctl(sc
->kbd
, KDSKBMODE
, (caddr_t
)&scp
->kbd_mode
);
609 update_kbd_state(scp
, scp
->status
, LOCK_MASK
, FALSE
);
611 kprintf("sc%d: %s <%d virtual consoles, flags=0x%x>\n",
612 unit
, (sc
->config
& SC_EFI_FB
) ? "EFI_FB" : adapter_name(sc
->adp
),
613 sc
->vtys
, sc
->config
);
615 kprintf("sc%d:", unit
);
616 if (sc
->adapter
>= 0)
617 kprintf(" fb%d", sc
->adapter
);
618 if (sc
->keyboard
>= 0)
619 kprintf(", kbd%d", sc
->keyboard
);
621 kprintf(", terminal emulator: %s (%s)",
622 scp
->tsw
->te_name
, scp
->tsw
->te_desc
);
626 /* register a shutdown callback for the kernel console */
627 if (sc_console_unit
== unit
)
628 EVENTHANDLER_REGISTER(shutdown_pre_sync
, scshutdown
,
629 (void *)(uintptr_t)unit
, SHUTDOWN_PRI_DEFAULT
);
634 * The first vty already has struct tty and scr_stat initialized
635 * in scinit(). The other vtys will have these structs when
638 for (vc
= 1; vc
< sc
->vtys
; vc
++) {
639 dev
= make_dev(&sc_ops
, vc
+ unit
* MAXCONS
,
640 UID_ROOT
, GID_WHEEL
, 0600, "ttyv%s",
641 makedev_unit_b32(tbuf
, vc
+ unit
* MAXCONS
));
644 cctl_dev
= make_dev(&sc_ops
, SC_CONSOLECTL
,
645 UID_ROOT
, GID_WHEEL
, 0600, "consolectl");
646 cctl_dev
->si_tty
= ttymalloc(&sc_console_tty
);
647 cctl_dev
->si_drv1
= sc_console
;
659 * As soon as malloc() becomes functional, we had better allocate
660 * various buffers for the kernel console.
663 if (sc_console_unit
< 0) /* sc_console == NULL */
666 /* copy the temporary buffer to the final buffer */
667 sc_alloc_scr_buffer(sc_console
, TRUE
, FALSE
);
669 #ifndef SC_NO_CUTPASTE
670 sc_alloc_cut_buffer(sc_console
, TRUE
);
673 #ifndef SC_NO_HISTORY
674 /* initialize history buffer & pointers */
675 sc_alloc_history_buffer(sc_console
, 0, 0, TRUE
);
678 /* Fill initial terminal border, efi_fb_info.vaddr should be non-NULL now */
679 if (!sc_filled_border
) {
680 sc_filled_border
= TRUE
;
681 sc_set_border(sc_console
, sc_console
->border
);
685 SYSINIT(sc_mem
, SI_BOOT1_POST
, SI_ORDER_ANY
, scmeminit
, NULL
);
688 scdevtounit(cdev_t dev
)
690 int vty
= SC_VTY(dev
);
692 if (vty
== SC_CONSOLECTL
)
693 return ((sc_console
!= NULL
) ? sc_console
->sc
->unit
: -1);
694 else if ((vty
< 0) || (vty
>= MAXCONS
*sc_max_unit()))
701 scopen(struct dev_open_args
*ap
)
703 cdev_t dev
= ap
->a_head
.a_dev
;
712 * Disallow access to disk volumes if RESTRICTEDROOT
714 if (caps_priv_check_self(SYSCAP_RESTRICTEDROOT
))
717 lwkt_gettoken(&vga_token
);
718 unit
= scdevtounit(dev
);
719 DPRINTF(5, ("scopen: dev:%d,%d, unit:%d, vty:%d\n",
720 major(dev
), minor(dev
), unit
, SC_VTY(dev
)));
722 sc
= sc_get_softc(unit
, (sc_console_unit
== unit
) ? SC_KERNEL_CONSOLE
: 0);
724 lwkt_reltoken(&vga_token
);
728 tp
= ttymalloc(&dev
->si_tty
);
729 lwkt_gettoken(&tp
->t_token
);
730 tp
->t_oproc
= scstart
;
731 tp
->t_param
= scparam
;
732 tp
->t_stop
= nottystop
;
736 if (!ISTTYOPEN(tp
)) {
738 /* Use the current setting of the <-- key as default VERASE. */
739 /* If the Delete key is preferable, an stty is necessary */
740 if (sc
->kbd
!= NULL
) {
741 key
.keynum
= KEYCODE_BS
;
742 kbd_ioctl(sc
->kbd
, GIO_KEYMAPENT
, (caddr_t
)&key
);
743 tp
->t_cc
[VERASE
] = key
.key
.map
[0];
745 tp
->t_iflag
= TTYDEF_IFLAG
;
746 tp
->t_oflag
= TTYDEF_OFLAG
;
747 tp
->t_cflag
= TTYDEF_CFLAG
;
748 tp
->t_lflag
= TTYDEF_LFLAG
;
749 tp
->t_ispeed
= tp
->t_ospeed
= TTYDEF_SPEED
;
750 scparam(tp
, &tp
->t_termios
);
751 (*linesw
[tp
->t_line
].l_modem
)(tp
, 1);
754 if ((tp
->t_state
& TS_XCLUDE
) &&
755 caps_priv_check(ap
->a_cred
, SYSCAP_RESTRICTEDROOT
))
757 lwkt_reltoken(&tp
->t_token
);
758 lwkt_reltoken(&vga_token
);
762 error
= (*linesw
[tp
->t_line
].l_open
)(dev
, tp
);
766 scp
= dev
->si_drv1
= alloc_scp(sc
, SC_VTY(dev
));
769 sc_set_pixel_mode(scp
, NULL
, COL
, ROW
, 16);
772 if (!tp
->t_winsize
.ws_col
&& !tp
->t_winsize
.ws_row
) {
773 tp
->t_winsize
.ws_col
= scp
->xsize
;
774 tp
->t_winsize
.ws_row
= scp
->ysize
;
778 * Start optional support thread for syscons refreshes. This thread
779 * will execute the refresh without the syscons_lock held and will
780 * allow interrupts while it is doing so.
782 if (scp
->asynctd
== NULL
) {
783 lwkt_create(scrn_update_thread
, scp
, &scp
->asynctd
, NULL
, 0, -1,
784 "syscons%d", SC_VTY(dev
));
786 lwkt_reltoken(&tp
->t_token
);
787 lwkt_reltoken(&vga_token
);
793 scclose(struct dev_close_args
*ap
)
795 cdev_t dev
= ap
->a_head
.a_dev
;
796 struct tty
*tp
= dev
->si_tty
;
799 lwkt_gettoken(&vga_token
);
800 lwkt_gettoken(&tp
->t_token
);
801 if (SC_VTY(dev
) != SC_CONSOLECTL
) {
802 scp
= SC_STAT(tp
->t_dev
);
803 /* were we in the middle of the VT switching process? */
804 DPRINTF(5, ("sc%d: scclose(), ", scp
->sc
->unit
));
805 if ((scp
== scp
->sc
->cur_scp
) && (scp
->sc
->unit
== sc_console_unit
) &&
806 !scp
->sc
->fb_blanked
) {
807 cons_unavail
= FALSE
;
809 if (finish_vt_rel(scp
, TRUE
) == 0) /* force release */
810 DPRINTF(5, ("reset WAIT_REL, "));
811 if (finish_vt_acq(scp
) == 0) /* force acknowledge */
812 DPRINTF(5, ("reset WAIT_ACQ, "));
815 if (scp
== &main_console
) {
818 scp
->smode
.mode
= VT_AUTO
;
821 sc_vtb_destroy(&scp
->vtb
);
822 sc_vtb_destroy(&scp
->scr
);
823 sc_free_history_buffer(scp
, scp
->ysize
);
825 kfree(scp
, M_SYSCONS
);
830 scp
->smode
.mode
= VT_AUTO
;
832 scp
->kbd_mode
= K_XLATE
;
834 if (scp
== scp
->sc
->cur_scp
)
835 kbd_ioctl(scp
->sc
->kbd
, KDSKBMODE
, (caddr_t
)&scp
->kbd_mode
);
836 DPRINTF(5, ("done.\n"));
838 (*linesw
[tp
->t_line
].l_close
)(tp
, ap
->a_fflag
);
840 lwkt_reltoken(&tp
->t_token
);
841 lwkt_reltoken(&vga_token
);
847 scread(struct dev_read_args
*ap
)
851 lwkt_gettoken(&vga_token
);
852 sc_touch_scrn_saver();
854 lwkt_reltoken(&vga_token
);
859 sckbdevent(keyboard_t
*thiskbd
, int event
, void *arg
)
867 lwkt_gettoken(&vga_token
);
869 * WARNING: In early boot sc->dev may not be setup yet.
871 sc
= (sc_softc_t
*)arg
;
872 /* assert(thiskbd == sc->kbd) */
876 if (sc
->kbd
&& sc
->kbd
->kb_flags
& KB_POLLED
) {
877 lwkt_reltoken(&vga_token
);
881 case KBDIO_UNLOADING
:
886 kbd_release(thiskbd
, (void *)&sc
->keyboard
);
887 lwkt_reltoken(&vga_token
);
890 lwkt_reltoken(&vga_token
);
895 * Loop while there is still input to get from the keyboard.
896 * I don't think this is nessesary, and it doesn't fix
897 * the Xaccel-2.1 keyboard hang, but it can't hurt. XXX
899 while ((c
= scgetc(sc
, SCGETC_NONBLOCK
)) != NOKEY
) {
900 cur_tty
= VIRTUAL_TTY(sc
, sc
->cur_scp
->index
);
901 if (!ISTTYOPEN(cur_tty
)) {
902 cur_tty
= sc_console_tty
;
903 if (!ISTTYOPEN(cur_tty
))
908 if ((*sc
->cur_scp
->tsw
->te_input
)(sc
->cur_scp
, c
, cur_tty
)) {
914 lwkt_gettoken(&cur_tty
->t_token
);
916 switch (KEYFLAGS(c
)) {
917 case 0x0000: /* normal key */
918 (*linesw
[cur_tty
->t_line
].l_rint
)(KEYCHAR(c
), cur_tty
);
920 case FKEY
: /* function key, return string */
921 cp
= kbd_get_fkeystr(thiskbd
, KEYCHAR(c
), &len
);
924 (*linesw
[cur_tty
->t_line
].l_rint
)(*cp
++, cur_tty
);
927 case MKEY
: /* meta is active, prepend ESC */
928 (*linesw
[cur_tty
->t_line
].l_rint
)(0x1b, cur_tty
);
929 (*linesw
[cur_tty
->t_line
].l_rint
)(KEYCHAR(c
), cur_tty
);
931 case BKEY
: /* backtab fixed sequence (esc [ Z) */
932 (*linesw
[cur_tty
->t_line
].l_rint
)(0x1b, cur_tty
);
933 (*linesw
[cur_tty
->t_line
].l_rint
)('[', cur_tty
);
934 (*linesw
[cur_tty
->t_line
].l_rint
)('Z', cur_tty
);
937 lwkt_reltoken(&cur_tty
->t_token
);
941 sc
->cur_scp
->status
|= MOUSE_HIDDEN
;
944 lwkt_reltoken(&vga_token
);
949 scparam(struct tty
*tp
, struct termios
*t
)
951 lwkt_gettoken(&tp
->t_token
);
952 tp
->t_ispeed
= t
->c_ispeed
;
953 tp
->t_ospeed
= t
->c_ospeed
;
954 tp
->t_cflag
= t
->c_cflag
;
955 lwkt_reltoken(&tp
->t_token
);
961 scioctl(struct dev_ioctl_args
*ap
)
963 cdev_t dev
= ap
->a_head
.a_dev
;
964 u_long cmd
= ap
->a_cmd
;
965 caddr_t data
= ap
->a_data
;
966 int flag
= ap
->a_fflag
;
973 lwkt_gettoken(&vga_token
);
976 error
= sc_vid_ioctl(tp
, cmd
, data
, flag
);
977 if (error
!= ENOIOCTL
) {
978 lwkt_reltoken(&vga_token
);
982 #ifndef SC_NO_HISTORY
983 error
= sc_hist_ioctl(tp
, cmd
, data
, flag
);
984 if (error
!= ENOIOCTL
) {
985 lwkt_reltoken(&vga_token
);
990 #ifndef SC_NO_SYSMOUSE
991 error
= sc_mouse_ioctl(tp
, cmd
, data
, flag
);
992 if (error
!= ENOIOCTL
) {
993 lwkt_reltoken(&vga_token
);
998 scp
= SC_STAT(tp
->t_dev
);
999 /* assert(scp != NULL) */
1000 /* scp is sc_console, if SC_VTY(dev) == SC_CONSOLECTL. */
1005 error
= (*scp
->tsw
->te_ioctl
)(scp
, tp
, cmd
, data
, flag
);
1007 if (error
!= ENOIOCTL
) {
1008 lwkt_reltoken(&vga_token
);
1013 switch (cmd
) { /* process console hardware related ioctl's */
1015 case GIO_ATTR
: /* get current attributes */
1016 /* this ioctl is not processed here, but in the terminal emulator */
1017 lwkt_reltoken(&vga_token
);
1020 case GIO_COLOR
: /* is this a color console ? */
1021 if (sc
->fbi
!= NULL
)
1024 *(int *)data
= (sc
->adp
->va_flags
& V_ADP_COLOR
) ? 1 : 0;
1025 lwkt_reltoken(&vga_token
);
1028 case CONS_BLANKTIME
: /* set screen saver timeout (0 = no saver) */
1029 if (*(int *)data
< 0 || *(int *)data
> MAX_BLANKTIME
) {
1030 lwkt_reltoken(&vga_token
);
1034 scrn_blank_time
= *(int *)data
;
1035 run_scrn_saver
= (scrn_blank_time
!= 0);
1037 lwkt_reltoken(&vga_token
);
1040 case CONS_CURSORTYPE
: /* set cursor type blink/noblink */
1042 if (!ISGRAPHSC(sc
->cur_scp
))
1043 sc_remove_cursor_image(sc
->cur_scp
);
1044 if ((*(int*)data
) & 0x01)
1045 sc
->flags
|= SC_BLINK_CURSOR
;
1047 sc
->flags
&= ~SC_BLINK_CURSOR
;
1048 if ((*(int*)data
) & 0x02) {
1049 sc
->flags
|= SC_CHAR_CURSOR
;
1051 sc
->flags
&= ~SC_CHAR_CURSOR
;
1053 * The cursor shape is global property; all virtual consoles
1054 * are affected. Update the cursor in the current console...
1056 if (!ISGRAPHSC(sc
->cur_scp
)) {
1057 sc_set_cursor_image(sc
->cur_scp
);
1058 sc_draw_cursor_image(sc
->cur_scp
);
1061 lwkt_reltoken(&vga_token
);
1064 case CONS_BELLTYPE
: /* set bell type sound/visual */
1067 if ((*(int *)data
) & 0x01)
1068 sc
->flags
|= SC_VISUAL_BELL
;
1070 sc
->flags
&= ~SC_VISUAL_BELL
;
1072 if ((*(int *)data
) & 0x02)
1073 sc
->flags
|= SC_QUIET_BELL
;
1075 sc
->flags
&= ~SC_QUIET_BELL
;
1078 lwkt_reltoken(&vga_token
);
1081 case CONS_GETINFO
: /* get current (virtual) console info */
1083 vid_info_t
*ptr
= (vid_info_t
*)data
;
1084 if (ptr
->size
== sizeof(struct vid_info
)) {
1085 ptr
->m_num
= sc
->cur_scp
->index
;
1086 ptr
->font_size
= scp
->font_height
;
1087 ptr
->mv_col
= scp
->xpos
;
1088 ptr
->mv_row
= scp
->ypos
;
1089 ptr
->mv_csz
= scp
->xsize
;
1090 ptr
->mv_rsz
= scp
->ysize
;
1092 * The following fields are filled by the terminal emulator. XXX
1099 ptr
->mv_grfc
.fore
= 0; /* not supported */
1100 ptr
->mv_grfc
.back
= 0; /* not supported */
1101 ptr
->mv_ovscan
= scp
->border
;
1102 if (scp
== sc
->cur_scp
)
1103 save_kbd_state(scp
, FALSE
);
1104 ptr
->mk_keylock
= scp
->status
& LOCK_MASK
;
1105 lwkt_reltoken(&vga_token
);
1108 lwkt_reltoken(&vga_token
);
1112 case CONS_GETVERS
: /* get version number */
1113 *(int*)data
= 0x200; /* version 2.0 */
1114 lwkt_reltoken(&vga_token
);
1117 case CONS_IDLE
: /* see if the screen has been idle */
1119 * When the screen is in the GRAPHICS_MODE or UNKNOWN_MODE,
1120 * the user process may have been writing something on the
1121 * screen and syscons is not aware of it. Declare the screen
1122 * is NOT idle if it is in one of these modes. But there is
1123 * an exception to it; if a screen saver is running in the
1124 * graphics mode in the current screen, we should say that the
1125 * screen has been idle.
1127 *(int *)data
= (sc
->flags
& SC_SCRN_IDLE
)
1128 && (!ISGRAPHSC(sc
->cur_scp
)
1129 || (sc
->cur_scp
->status
& SAVER_RUNNING
));
1130 lwkt_reltoken(&vga_token
);
1133 case CONS_SAVERMODE
: /* set saver mode */
1134 switch(*(int *)data
) {
1136 case CONS_USR_SAVER
:
1138 /* if a LKM screen saver is running, stop it first. */
1139 scsplash_stick(FALSE
);
1140 saver_mode
= *(int *)data
;
1142 if ((error
= wait_scrn_saver_stop(NULL
, TRUE
))) {
1144 lwkt_reltoken(&vga_token
);
1147 #endif /* NSPLASH */
1148 run_scrn_saver
= TRUE
;
1149 if (saver_mode
== CONS_USR_SAVER
)
1150 scp
->status
|= SAVER_RUNNING
;
1152 scp
->status
&= ~SAVER_RUNNING
;
1153 scsplash_stick(TRUE
);
1156 case CONS_LKM_SAVER
:
1158 if ((saver_mode
== CONS_USR_SAVER
) && (scp
->status
& SAVER_RUNNING
))
1159 scp
->status
&= ~SAVER_RUNNING
;
1160 saver_mode
= *(int *)data
;
1164 lwkt_reltoken(&vga_token
);
1167 lwkt_reltoken(&vga_token
);
1170 case CONS_SAVERSTART
: /* immediately start/stop the screen saver */
1172 * Note that this ioctl does not guarantee the screen saver
1173 * actually starts or stops. It merely attempts to do so...
1176 run_scrn_saver
= (*(int *)data
!= 0);
1178 sc
->scrn_time_stamp
-= scrn_blank_time
;
1180 lwkt_reltoken(&vga_token
);
1183 case CONS_SCRSHOT
: /* get a screen shot */
1185 scrshot_t
*ptr
= (scrshot_t
*)data
;
1187 if (ISGRAPHSC(scp
)) {
1189 lwkt_reltoken(&vga_token
);
1192 if (scp
->xsize
!= ptr
->xsize
|| scp
->ysize
!= ptr
->ysize
) {
1194 lwkt_reltoken(&vga_token
);
1198 copyout ((void*)scp
->vtb
.vtb_buffer
, ptr
->buf
,
1199 ptr
->xsize
* ptr
->ysize
* sizeof(uint16_t));
1200 lwkt_reltoken(&vga_token
);
1204 case VT_SETMODE
: /* set screen switcher mode */
1206 struct vt_mode
*mode
;
1208 mode
= (struct vt_mode
*)data
;
1209 DPRINTF(5, ("sc%d: VT_SETMODE ", sc
->unit
));
1210 if (scp
->smode
.mode
== VT_PROCESS
) {
1211 if (scp
->proc
== pfindn(scp
->pid
) && scp
->proc
!= curproc
) {
1212 DPRINTF(5, ("error EPERM\n"));
1213 lwkt_reltoken(&vga_token
);
1218 if (mode
->mode
== VT_AUTO
) {
1219 scp
->smode
.mode
= VT_AUTO
;
1222 DPRINTF(5, ("VT_AUTO, "));
1223 if ((scp
== sc
->cur_scp
) && (sc
->unit
== sc_console_unit
) &&
1225 cons_unavail
= FALSE
;
1227 if (finish_vt_rel(scp
, TRUE
) == 0)
1228 DPRINTF(5, ("reset WAIT_REL, "));
1229 if (finish_vt_acq(scp
) == 0)
1230 DPRINTF(5, ("reset WAIT_ACQ, "));
1232 if (!ISSIGVALID(mode
->relsig
) || !ISSIGVALID(mode
->acqsig
)
1233 || !ISSIGVALID(mode
->frsig
)) {
1235 DPRINTF(5, ("error EINVAL\n"));
1236 lwkt_reltoken(&vga_token
);
1239 DPRINTF(5, ("VT_PROCESS %d, ", curproc
->p_pid
));
1240 bcopy(data
, &scp
->smode
, sizeof(struct vt_mode
));
1241 scp
->proc
= curproc
;
1242 scp
->pid
= scp
->proc
->p_pid
;
1243 if ((scp
== sc
->cur_scp
) && (sc
->unit
== sc_console_unit
))
1244 cons_unavail
= TRUE
;
1248 lwkt_reltoken(&vga_token
);
1252 case VT_GETMODE
: /* get screen switcher mode */
1253 bcopy(&scp
->smode
, data
, sizeof(struct vt_mode
));
1254 lwkt_reltoken(&vga_token
);
1257 case VT_RELDISP
: /* screen switcher ioctl */
1259 * This must be the current vty which is in the VT_PROCESS
1263 if ((scp
!= sc
->cur_scp
) || (scp
->smode
.mode
!= VT_PROCESS
)) {
1265 lwkt_reltoken(&vga_token
);
1268 /* ...and this process is controlling it. */
1269 if (scp
->proc
!= curproc
) {
1271 lwkt_reltoken(&vga_token
);
1275 switch(*(int *)data
) {
1276 case VT_FALSE
: /* user refuses to release screen, abort */
1277 if ((error
= finish_vt_rel(scp
, FALSE
)) == 0)
1278 DPRINTF(5, ("sc%d: VT_FALSE\n", sc
->unit
));
1280 case VT_TRUE
: /* user has released screen, go on */
1281 if ((error
= finish_vt_rel(scp
, TRUE
)) == 0)
1282 DPRINTF(5, ("sc%d: VT_TRUE\n", sc
->unit
));
1284 case VT_ACKACQ
: /* acquire acknowledged, switch completed */
1285 if ((error
= finish_vt_acq(scp
)) == 0)
1286 DPRINTF(5, ("sc%d: VT_ACKACQ\n", sc
->unit
));
1288 /* Wait for drm modesetting callback to finish. */
1289 lwkt_reltoken(&vga_token
);
1290 if (sc
->fb_set_par_task
!= NULL
)
1291 taskqueue_drain(taskqueue_thread
[0], sc
->fb_set_par_task
);
1297 lwkt_reltoken(&vga_token
);
1300 case VT_OPENQRY
: /* return free virtual console */
1301 for (i
= sc
->first_vty
; i
< sc
->first_vty
+ sc
->vtys
; i
++) {
1302 tp
= VIRTUAL_TTY(sc
, i
);
1303 if (!ISTTYOPEN(tp
)) {
1304 *(int *)data
= i
+ 1;
1305 lwkt_reltoken(&vga_token
);
1309 lwkt_reltoken(&vga_token
);
1312 case VT_ACTIVATE
: /* switch to screen *data */
1313 i
= (*(int *)data
== 0) ? scp
->index
: (*(int *)data
- 1);
1315 sc_clean_up(sc
->cur_scp
, TRUE
);
1316 error
= sc_switch_scr(sc
, i
);
1318 lwkt_reltoken(&vga_token
);
1321 case VT_WAITACTIVE
: /* wait for switch to occur */
1322 i
= (*(int *)data
== 0) ? scp
->index
: (*(int *)data
- 1);
1323 if ((i
< sc
->first_vty
) || (i
>= sc
->first_vty
+ sc
->vtys
)) {
1324 lwkt_reltoken(&vga_token
);
1328 error
= sc_clean_up(sc
->cur_scp
, TRUE
);
1331 lwkt_reltoken(&vga_token
);
1336 * scp might be NULL, we aren't sure why. Check for NULL.
1338 * http://bugs.dragonflybsd.org/issues/2481
1340 scp
= SC_STAT(SC_DEV(sc
, i
));
1341 if (scp
== NULL
|| scp
== scp
->sc
->cur_scp
) {
1342 lwkt_reltoken(&vga_token
);
1345 error
= tsleep((caddr_t
)&scp
->smode
, PCATCH
, "waitvt", 0);
1346 /* May return ERESTART */
1347 lwkt_reltoken(&vga_token
);
1348 /* Wait for drm modesetting callback to finish. */
1349 if (sc
->fb_set_par_task
!= NULL
)
1350 taskqueue_drain(taskqueue_thread
[0], sc
->fb_set_par_task
);
1353 case VT_GETACTIVE
: /* get active vty # */
1354 *(int *)data
= sc
->cur_scp
->index
+ 1;
1355 lwkt_reltoken(&vga_token
);
1358 case VT_GETINDEX
: /* get this vty # */
1359 *(int *)data
= scp
->index
+ 1;
1360 lwkt_reltoken(&vga_token
);
1363 case VT_LOCKSWITCH
: /* prevent vty switching */
1365 if ((*(int *)data
) & 0x01)
1366 sc
->flags
|= SC_SCRN_VTYLOCK
;
1368 sc
->flags
&= ~SC_SCRN_VTYLOCK
;
1370 lwkt_reltoken(&vga_token
);
1373 case KDENABIO
: /* allow io operations */
1374 error
= caps_priv_check(ap
->a_cred
, SYSCAP_RESTRICTEDROOT
);
1376 lwkt_reltoken(&vga_token
);
1379 if (securelevel
> 0) {
1380 lwkt_reltoken(&vga_token
);
1383 #if defined(__x86_64__)
1384 curthread
->td_lwp
->lwp_md
.md_regs
->tf_rflags
|= PSL_IOPL
;
1386 lwkt_reltoken(&vga_token
);
1389 case KDDISABIO
: /* disallow io operations (default) */
1390 #if defined(__x86_64__)
1391 curthread
->td_lwp
->lwp_md
.md_regs
->tf_rflags
&= ~PSL_IOPL
;
1393 lwkt_reltoken(&vga_token
);
1396 case KDSKBSTATE
: /* set keyboard state (locks) */
1397 if (*(int *)data
& ~LOCK_MASK
) {
1398 lwkt_reltoken(&vga_token
);
1402 scp
->status
&= ~LOCK_MASK
;
1403 scp
->status
|= *(int *)data
;
1405 if (scp
== sc
->cur_scp
)
1406 update_kbd_state(scp
, scp
->status
, LOCK_MASK
, FALSE
);
1407 lwkt_reltoken(&vga_token
);
1410 case KDGKBSTATE
: /* get keyboard state (locks) */
1411 if (scp
== sc
->cur_scp
)
1412 save_kbd_state(scp
, FALSE
);
1413 *(int *)data
= scp
->status
& LOCK_MASK
;
1414 lwkt_reltoken(&vga_token
);
1417 case KDGETREPEAT
: /* get keyboard repeat & delay rates */
1418 case KDSETREPEAT
: /* set keyboard repeat & delay rates (new) */
1419 error
= kbd_ioctl(sc
->kbd
, cmd
, data
);
1420 if (error
== ENOIOCTL
)
1422 lwkt_reltoken(&vga_token
);
1425 case KDSKBMODE
: /* set keyboard mode */
1426 switch (*(int *)data
) {
1427 case K_XLATE
: /* switch to XLT ascii mode */
1428 case K_RAW
: /* switch to RAW scancode mode */
1429 case K_CODE
: /* switch to CODE mode */
1430 scp
->kbd_mode
= *(int *)data
;
1431 if (scp
== sc
->cur_scp
)
1432 kbd_ioctl(sc
->kbd
, cmd
, data
);
1433 lwkt_reltoken(&vga_token
);
1436 lwkt_reltoken(&vga_token
);
1441 case KDGKBMODE
: /* get keyboard mode */
1442 *(int *)data
= scp
->kbd_mode
;
1443 lwkt_reltoken(&vga_token
);
1447 error
= kbd_ioctl(sc
->kbd
, cmd
, data
);
1448 if (error
== ENOIOCTL
)
1450 lwkt_reltoken(&vga_token
);
1453 case KDMKTONE
: /* sound the bell */
1456 sc_bell(scp
, (*(int*)data
)&0xffff,
1457 (((*(int*)data
)>>16)&0xffff)*hz
/1000);
1459 sc_bell(scp
, scp
->bell_pitch
, scp
->bell_duration
);
1461 lwkt_reltoken(&vga_token
);
1464 case KIOCSOUND
: /* make tone (*data) hz */
1466 if (scp
== sc
->cur_scp
) {
1468 error
= sc_tone(*(int *)data
);
1476 lwkt_reltoken(&vga_token
);
1479 case KDGKBTYPE
: /* get keyboard type */
1480 error
= kbd_ioctl(sc
->kbd
, cmd
, data
);
1481 if (error
== ENOIOCTL
) {
1482 /* always return something? XXX */
1485 lwkt_reltoken(&vga_token
);
1488 case KDSETLED
: /* set keyboard LED status */
1489 if (*(int *)data
& ~LED_MASK
) { /* FIXME: LOCK_MASK? */
1490 lwkt_reltoken(&vga_token
);
1494 scp
->status
&= ~LED_MASK
;
1495 scp
->status
|= *(int *)data
;
1497 if (scp
== sc
->cur_scp
)
1498 update_kbd_leds(scp
, scp
->status
);
1499 lwkt_reltoken(&vga_token
);
1502 case KDGETLED
: /* get keyboard LED status */
1503 if (scp
== sc
->cur_scp
)
1504 save_kbd_state(scp
, FALSE
);
1505 *(int *)data
= scp
->status
& LED_MASK
;
1506 lwkt_reltoken(&vga_token
);
1509 case KBADDKBD
: /* add/remove keyboard to/from mux */
1511 error
= kbd_ioctl(sc
->kbd
, cmd
, data
);
1512 if (error
== ENOIOCTL
)
1514 lwkt_reltoken(&vga_token
);
1517 case CONS_SETKBD
: /* set the new keyboard */
1521 newkbd
= kbd_get_keyboard(*(int *)data
);
1522 if (newkbd
== NULL
) {
1523 lwkt_reltoken(&vga_token
);
1527 if (sc
->kbd
!= newkbd
) {
1528 i
= kbd_allocate(newkbd
->kb_name
, newkbd
->kb_unit
,
1529 (void *)&sc
->keyboard
, sckbdevent
, sc
);
1530 /* i == newkbd->kb_index */
1532 if (sc
->kbd
!= NULL
) {
1533 save_kbd_state(sc
->cur_scp
, FALSE
);
1534 kbd_release(sc
->kbd
, (void *)&sc
->keyboard
);
1537 sc
->kbd
= kbd_get_keyboard(i
); /* sc->kbd == newkbd */
1540 kbd_ioctl(sc
->kbd
, KDSKBMODE
,
1541 (caddr_t
)&sc
->cur_scp
->kbd_mode
);
1542 update_kbd_state(sc
->cur_scp
, sc
->cur_scp
->status
,
1545 error
= EPERM
; /* XXX */
1548 lwkt_reltoken(&vga_token
);
1552 case CONS_RELKBD
: /* release the current keyboard */
1554 if (sc
->kbd
!= NULL
) {
1555 save_kbd_state(sc
->cur_scp
, FALSE
);
1556 error
= kbd_release(sc
->kbd
, (void *)&sc
->keyboard
);
1564 lwkt_reltoken(&vga_token
);
1567 case CONS_GETTERM
: /* get the current terminal emulator info */
1571 if (((term_info_t
*)data
)->ti_index
== 0) {
1574 sw
= sc_term_match_by_number(((term_info_t
*)data
)->ti_index
);
1577 strncpy(((term_info_t
*)data
)->ti_name
, sw
->te_name
,
1578 sizeof(((term_info_t
*)data
)->ti_name
));
1579 strncpy(((term_info_t
*)data
)->ti_desc
, sw
->te_desc
,
1580 sizeof(((term_info_t
*)data
)->ti_desc
));
1581 ((term_info_t
*)data
)->ti_flags
= 0;
1582 lwkt_reltoken(&vga_token
);
1585 ((term_info_t
*)data
)->ti_name
[0] = '\0';
1586 ((term_info_t
*)data
)->ti_desc
[0] = '\0';
1587 ((term_info_t
*)data
)->ti_flags
= 0;
1588 lwkt_reltoken(&vga_token
);
1593 case CONS_SETTERM
: /* set the current terminal emulator */
1595 error
= sc_init_emulator(scp
, ((term_info_t
*)data
)->ti_name
);
1596 /* FIXME: what if scp == sc_console! XXX */
1598 lwkt_reltoken(&vga_token
);
1601 case GIO_SCRNMAP
: /* get output translation table */
1602 bcopy(&sc
->scr_map
, data
, sizeof(sc
->scr_map
));
1603 lwkt_reltoken(&vga_token
);
1606 case PIO_SCRNMAP
: /* set output translation table */
1607 bcopy(data
, &sc
->scr_map
, sizeof(sc
->scr_map
));
1608 for (i
=0; i
<sizeof(sc
->scr_map
); i
++) {
1609 sc
->scr_rmap
[sc
->scr_map
[i
]] = i
;
1611 lwkt_reltoken(&vga_token
);
1614 case GIO_KEYMAP
: /* get keyboard translation table */
1615 case PIO_KEYMAP
: /* set keyboard translation table */
1616 case GIO_DEADKEYMAP
: /* get accent key translation table */
1617 case PIO_DEADKEYMAP
: /* set accent key translation table */
1618 case GETFKEY
: /* get function key string */
1619 case SETFKEY
: /* set function key string */
1620 error
= kbd_ioctl(sc
->kbd
, cmd
, data
);
1621 if (error
== ENOIOCTL
)
1623 lwkt_reltoken(&vga_token
);
1626 #ifndef SC_NO_FONT_LOADING
1628 case PIO_FONT8x8
: /* set 8x8 dot font */
1629 if (sc
->fbi
== NULL
&& !ISFONTAVAIL(sc
->adp
->va_flags
)) {
1630 lwkt_reltoken(&vga_token
);
1634 bcopy(data
, sc
->font_8
, 8*256);
1635 sc
->fonts_loaded
|= FONT_8
;
1638 * Always use the font page #0. XXX
1639 * Don't load if the current font size is not 8x8.
1642 && ISTEXTSC(sc
->cur_scp
) && (sc
->cur_scp
->font_height
< 14)) {
1643 sc_load_font(sc
->cur_scp
, 0, 8, sc
->font_8
, 0, 256);
1646 lwkt_reltoken(&vga_token
);
1649 case GIO_FONT8x8
: /* get 8x8 dot font */
1650 if (sc
->fbi
== NULL
&& !ISFONTAVAIL(sc
->adp
->va_flags
)) {
1651 lwkt_reltoken(&vga_token
);
1654 if (sc
->fonts_loaded
& FONT_8
) {
1655 bcopy(sc
->font_8
, data
, 8*256);
1656 lwkt_reltoken(&vga_token
);
1660 lwkt_reltoken(&vga_token
);
1664 case PIO_FONT8x14
: /* set 8x14 dot font */
1665 if (sc
->fbi
== NULL
&& !ISFONTAVAIL(sc
->adp
->va_flags
)) {
1666 lwkt_reltoken(&vga_token
);
1670 bcopy(data
, sc
->font_14
, 14*256);
1671 sc
->fonts_loaded
|= FONT_14
;
1674 * Always use the font page #0. XXX
1675 * Don't load if the current font size is not 8x14.
1678 && ISTEXTSC(sc
->cur_scp
)
1679 && (sc
->cur_scp
->font_height
>= 14)
1680 && (sc
->cur_scp
->font_height
< 16)) {
1681 sc_load_font(sc
->cur_scp
, 0, 14, sc
->font_14
, 0, 256);
1684 lwkt_reltoken(&vga_token
);
1687 case GIO_FONT8x14
: /* get 8x14 dot font */
1688 if (sc
->fbi
== NULL
&& !ISFONTAVAIL(sc
->adp
->va_flags
)) {
1689 lwkt_reltoken(&vga_token
);
1692 if (sc
->fonts_loaded
& FONT_14
) {
1693 bcopy(sc
->font_14
, data
, 14*256);
1694 lwkt_reltoken(&vga_token
);
1698 lwkt_reltoken(&vga_token
);
1702 case PIO_FONT8x16
: /* set 8x16 dot font */
1703 if (sc
->fbi
== NULL
&& !ISFONTAVAIL(sc
->adp
->va_flags
)) {
1704 lwkt_reltoken(&vga_token
);
1708 bcopy(data
, sc
->font_16
, 16*256);
1709 sc
->fonts_loaded
|= FONT_16
;
1712 * Always use the font page #0. XXX
1713 * Don't load if the current font size is not 8x16.
1716 && ISTEXTSC(sc
->cur_scp
) && (sc
->cur_scp
->font_height
>= 16)) {
1717 sc_load_font(sc
->cur_scp
, 0, 16, sc
->font_16
, 0, 256);
1720 lwkt_reltoken(&vga_token
);
1723 case GIO_FONT8x16
: /* get 8x16 dot font */
1724 if (sc
->fbi
== NULL
&& !ISFONTAVAIL(sc
->adp
->va_flags
)) {
1725 lwkt_reltoken(&vga_token
);
1728 if (sc
->fonts_loaded
& FONT_16
) {
1729 bcopy(sc
->font_16
, data
, 16*256);
1730 lwkt_reltoken(&vga_token
);
1734 lwkt_reltoken(&vga_token
);
1738 #endif /* SC_NO_FONT_LOADING */
1744 lwkt_gettoken(&tp
->t_token
);
1745 error
= (*linesw
[tp
->t_line
].l_ioctl
)(tp
, cmd
, data
, flag
, ap
->a_cred
);
1746 if (error
!= ENOIOCTL
) {
1747 lwkt_reltoken(&tp
->t_token
);
1748 lwkt_reltoken(&vga_token
);
1753 error
= ttioctl(tp
, cmd
, data
, flag
);
1754 if (error
!= ENOIOCTL
) {
1755 lwkt_reltoken(&tp
->t_token
);
1756 lwkt_reltoken(&vga_token
);
1761 lwkt_reltoken(&tp
->t_token
);
1762 lwkt_reltoken(&vga_token
);
1768 scstart(struct tty
*tp
)
1772 u_char buf
[PCBURST
];
1773 scr_stat
*scp
= SC_STAT(tp
->t_dev
);
1776 if (scp
->status
& SLKED
||
1777 (scp
== scp
->sc
->cur_scp
&& scp
->sc
->blink_in_progress
))
1782 if (!(tp
->t_state
& (TS_TIMEOUT
| TS_BUSY
| TS_TTSTOP
))) {
1783 tp
->t_state
|= TS_BUSY
;
1786 len
= clist_qtob(rbp
, buf
, PCBURST
);
1787 sc_puts(scp
, buf
, len
);
1789 tp
->t_state
&= ~TS_BUSY
;
1798 sccnprobe(struct consdev
*cp
)
1803 cp
->cn_pri
= sc_get_cons_priority(&unit
, &flags
);
1805 /* a video card is always required */
1806 if (probe_efi_fb(1) != 0 && !scvidprobe(unit
, flags
, TRUE
))
1807 cp
->cn_pri
= CN_DEAD
;
1809 /* syscons will become console even when there is no keyboard */
1810 sckbdprobe(unit
, flags
, TRUE
);
1812 if (cp
->cn_pri
== CN_DEAD
) {
1816 /* initialize required fields */
1817 cp
->cn_probegood
= 1;
1821 sccninit(struct consdev
*cp
)
1826 sc_get_cons_priority(&unit
, &flags
);
1827 scinit(unit
, flags
| SC_KERNEL_CONSOLE
);
1828 sc_console_unit
= unit
;
1829 sc_console
= sc_get_softc(unit
, SC_KERNEL_CONSOLE
)->console_scp
;
1833 sccninit_fini(struct consdev
*cp
)
1835 if (cctl_dev
== NULL
)
1836 kprintf("sccninit_fini: WARNING: cctl_dev is NULL!\n");
1837 cp
->cn_dev
= cctl_dev
;
1841 * This is called when the console is switched away from syscons to
1842 * a late-configuring device (such as a PCIe serial port). Since
1843 * late-configuring devices basically didn't exist until now, this
1844 * routine was never called, and SURPRISE! It doesn't work... causes
1845 * syscons to implode due to all the funny console-not-console structure
1846 * selection syscons does.
1848 * Make it a NOP. Just leave the console designation intact, even
1849 * though it is no longer a console.
1852 sccnterm(struct consdev
*cp
)
1855 /* we are not the kernel console any more, release everything */
1857 if (sc_console_unit
< 0)
1858 return; /* shouldn't happen */
1862 sc_clear_screen(sc_console
);
1863 sccnupdate(sc_console
);
1866 scterm(sc_console_unit
, SC_KERNEL_CONSOLE
);
1867 sc_console_unit
= -1;
1873 * Console path - cannot block!
1876 sccnputc(void *private, int c
)
1879 scr_stat
*scp
= sc_console
;
1881 #ifndef SC_NO_HISTORY
1885 #endif /* !SC_NO_HISTORY */
1887 /* assert(sc_console != NULL) */
1889 if (syscons_lock_nonblock() != 0)
1891 #ifndef SC_NO_HISTORY
1892 if (scp
== scp
->sc
->cur_scp
&& scp
->status
& SLKED
) {
1893 scp
->status
&= ~SLKED
;
1895 /* This can block, illegal in the console path */
1896 update_kbd_state(scp
, scp
->status
, SLKED
, TRUE
);
1898 if (scp
->status
& BUFFER_SAVED
) {
1899 if (!sc_hist_restore(scp
))
1900 sc_remove_cutmarking(scp
);
1901 scp
->status
&= ~BUFFER_SAVED
;
1902 scp
->status
|= CURSOR_ENABLED
;
1903 sc_draw_cursor_image(scp
);
1906 tp
= VIRTUAL_TTY(scp
->sc
, scp
->index
);
1907 /* This can block, illegal in the console path */
1908 if (ISTTYOPEN(tp
)) {
1913 #endif /* !SC_NO_HISTORY */
1916 if (kernel_console_ts
!= NULL
)
1917 scp
->ts
= kernel_console_ts
;
1919 sc_puts(scp
, buf
, 1);
1927 * Console path - cannot block!
1930 sccngetc(void *private)
1932 return sccngetch(0);
1936 * Console path - cannot block!
1939 sccncheckc(void *private)
1941 return sccngetch(SCGETC_NONBLOCK
);
1945 * Set polling mode (also disables the tty feed), use when
1946 * polling for console key input.
1949 sccnpoll(void *private, int on
)
1954 sc_touch_scrn_saver();
1955 scp
= sc_console
->sc
->cur_scp
; /* XXX */
1958 kbd_poll(scp
->sc
->kbd
, on
);
1962 sccndbctl(void *private, int on
)
1964 /* assert(sc_console_unit >= 0) */
1965 /* try to switch to the kernel console screen */
1966 if (on
&& debugger
== 0) {
1968 * TRY to make sure the screen saver is stopped,
1969 * and the screen is updated before switching to
1974 && sc_console
->sc
->cur_scp
->smode
.mode
== VT_AUTO
1975 && sc_console
->smode
.mode
== VT_AUTO
) {
1976 sc_console
->sc
->cur_scp
->status
|= MOUSE_HIDDEN
;
1978 sc_switch_scr(sc_console
->sc
, sc_console
->index
);
1989 * Console path - cannot block!
1992 sccngetch(int flags
)
1994 static struct fkeytab fkey
;
2002 /* assert(sc_console != NULL) */
2005 * Stop the screen saver and update the screen if necessary.
2006 * What if we have been running in the screen saver code... XXX
2008 sc_touch_scrn_saver();
2009 scp
= sc_console
->sc
->cur_scp
; /* XXX */
2013 if (fkeycp
< fkey
.len
) {
2014 return fkey
.str
[fkeycp
++];
2017 if (scp
->sc
->kbd
== NULL
) {
2022 * Make sure the keyboard is accessible even when the kbd device
2023 * driver is disabled.
2026 kbd_enable(scp
->sc
->kbd
);
2028 /* we shall always use the keyboard in the XLATE mode here */
2029 cur_mode
= scp
->kbd_mode
;
2030 scp
->kbd_mode
= K_XLATE
;
2031 kbd_ioctl(scp
->sc
->kbd
, KDSKBMODE
, (caddr_t
)&scp
->kbd_mode
);
2033 c
= scgetc(scp
->sc
, SCGETC_CN
| flags
);
2035 scp
->kbd_mode
= cur_mode
;
2036 kbd_ioctl(scp
->sc
->kbd
, KDSKBMODE
, (caddr_t
)&scp
->kbd_mode
);
2037 kbd_disable(scp
->sc
->kbd
);
2040 switch (KEYFLAGS(c
)) {
2041 case 0: /* normal char */
2043 case FKEY
: /* function key */
2044 p
= kbd_get_fkeystr(scp
->sc
->kbd
, KEYCHAR(c
), (size_t *)&fkeycp
);
2046 if ((p
!= NULL
) && (fkey
.len
> 0)) {
2047 bcopy(p
, fkey
.str
, fkey
.len
);
2053 if (flags
& SCGETC_NONBLOCK
)
2064 sccnupdate(scr_stat
*scp
)
2069 ddb_active
= db_active
;
2074 /* this is a cut-down version of scrn_timer()... */
2077 * Don't update if videoio is in progress. However, if we are paniced
2078 * or in the debugger it is possible that the variables might be stuck,
2079 * so ignore it in such cases.
2081 if (scp
->sc
->font_loading_in_progress
|| scp
->sc
->videoio_in_progress
) {
2082 if (panicstr
== NULL
&& ddb_active
== 0 && shutdown_in_progress
== 0)
2086 if (debugger
> 0 || panicstr
|| ddb_active
|| shutdown_in_progress
) {
2087 sc_touch_scrn_saver();
2088 } else if (scp
!= scp
->sc
->cur_scp
) {
2092 if (!run_scrn_saver
)
2093 scp
->sc
->flags
&= ~SC_SCRN_IDLE
;
2096 * This is a hard path, we cannot call stop_scrn_saver() here.
2098 if ((saver_mode
!= CONS_LKM_SAVER
) || !(scp
->sc
->flags
& SC_SCRN_IDLE
))
2099 if (scp
->sc
->flags
& SC_SCRN_BLANKED
) {
2100 sc_touch_scrn_saver();
2101 /*stop_scrn_saver(scp->sc, current_saver);*/
2103 #endif /* NSPLASH */
2105 if (scp
!= scp
->sc
->cur_scp
|| scp
->sc
->blink_in_progress
2106 || scp
->sc
->switch_in_progress
) {
2111 * FIXME: unlike scrn_timer(), we call scrn_update() from here even
2112 * when write_in_progress is non-zero. XXX
2114 if (!ISGRAPHSC(scp
) && !(scp
->sc
->flags
& SC_SCRN_BLANKED
))
2115 scrn_update(scp
, TRUE
, SCRN_ASYNCOK
);
2119 scrn_timer(void *arg
)
2121 static int kbd_interval
= 0;
2128 * Setup depending on who called us
2130 again
= (arg
!= NULL
);
2132 sc
= (sc_softc_t
*)arg
;
2133 } else if (sc_console
!= NULL
) {
2134 sc
= sc_console
->sc
;
2140 * Don't do anything when we are performing some I/O operations.
2141 * (These are initiated by the frontend?)
2143 if (sc
->font_loading_in_progress
|| sc
->videoio_in_progress
) {
2145 callout_reset(&sc
->scrn_timer_ch
, hz
/ 10, scrn_timer
, sc
);
2150 * Try to allocate a keyboard automatically
2152 if ((sc
->kbd
== NULL
) && (sc
->config
& SC_AUTODETECT_KBD
)) {
2153 if (++kbd_interval
>= 25) {
2154 sc
->keyboard
= sc_allocate_keyboard(sc
, -1);
2155 if (sc
->keyboard
>= 0) {
2156 sc
->kbd
= kbd_get_keyboard(sc
->keyboard
);
2157 kbd_ioctl(sc
->kbd
, KDSKBMODE
,
2158 (caddr_t
)&sc
->cur_scp
->kbd_mode
);
2159 update_kbd_state(sc
->cur_scp
, sc
->cur_scp
->status
,
2167 * Should we stop the screen saver? We need the syscons_lock
2168 * for most of this stuff.
2170 getmicrouptime(&tv
);
2172 if (syscons_lock_nonblock() != 0) {
2173 /* failed to get the lock */
2175 callout_reset(&sc
->scrn_timer_ch
, hz
/ 10, scrn_timer
, sc
);
2178 /* successful lock */
2180 if (debugger
> 0 || panicstr
|| shutdown_in_progress
)
2181 sc_touch_scrn_saver();
2182 if (run_scrn_saver
) {
2183 if (tv
.tv_sec
> sc
->scrn_time_stamp
+ scrn_blank_time
)
2184 sc
->flags
|= SC_SCRN_IDLE
;
2186 sc
->flags
&= ~SC_SCRN_IDLE
;
2188 sc
->scrn_time_stamp
= tv
.tv_sec
;
2189 sc
->flags
&= ~SC_SCRN_IDLE
;
2190 if (scrn_blank_time
> 0)
2191 run_scrn_saver
= TRUE
;
2194 if ((saver_mode
!= CONS_LKM_SAVER
) || !(sc
->flags
& SC_SCRN_IDLE
)) {
2195 if ((sc
->flags
& SC_SCRN_BLANKED
) && !ISGRAPHSC(sc
->cur_scp
))
2196 stop_scrn_saver(sc
, current_saver
);
2198 #endif /* NSPLASH */
2200 /* should we just return ? */
2201 if (sc
->blink_in_progress
|| sc
->switch_in_progress
||
2202 sc
->write_in_progress
)
2206 callout_reset(&sc
->scrn_timer_ch
, hz
/ 10, scrn_timer
, sc
);
2210 /* Update the screen */
2211 scp
= sc
->cur_scp
; /* cur_scp may have changed... */
2212 if (!ISGRAPHSC(scp
) && !(sc
->flags
& SC_SCRN_BLANKED
))
2213 scrn_update(scp
, TRUE
, SCRN_ASYNCOK
);
2216 /* should we activate the screen saver? */
2217 if ((saver_mode
== CONS_LKM_SAVER
) && (sc
->flags
& SC_SCRN_IDLE
))
2218 if (!ISGRAPHSC(scp
) || (sc
->flags
& SC_SCRN_BLANKED
))
2219 (*current_saver
)(sc
, TRUE
);
2220 #endif /* NSPLASH */
2224 callout_reset(&sc
->scrn_timer_ch
, hz
/ 25, scrn_timer
, sc
);
2228 and_region(int *s1
, int *e1
, int s2
, int e2
)
2230 if (*e1
< s2
|| e2
< *s1
)
2232 *s1
= imax(*s1
, s2
);
2233 *e1
= imin(*e1
, e2
);
2238 * Refresh modified frame buffer range. Also used to
2239 * scroll (entire FB is marked modified).
2241 * This function is allowed to run without the syscons_lock,
2242 * so scp fields can change unexpected. We cache most values
2243 * that we care about and silently discard illegal ranges.
2246 scrn_update(scr_stat
*scp
, int show_cursor
, int flags
)
2257 ddb_active
= db_active
;
2263 * Try to run large screen updates as an async operation, which will
2264 * call this function again from a thread with BULKUNLOCK set, allowing
2265 * interrupts during the update which tends to make the system behave
2266 * better (no sound glitches, etc).
2268 if ((flags
& SCRN_ASYNCOK
) && syscons_async
&& scp
->asynctd
&&
2269 (scp
->end
- scp
->start
) > 16 &&
2270 panicstr
== NULL
&& ddb_active
== 0 && shutdown_in_progress
== 0) {
2271 scp
->show_cursor
= show_cursor
;
2272 scp
->queue_update_td
= 1;
2273 wakeup(&scp
->asynctd
);
2276 if (flags
& SCRN_BULKUNLOCK
)
2280 * Synchronous operation or called from
2283 /* assert(scp == scp->sc->cur_scp) */
2284 atomic_add_int(&scp
->sc
->videoio_in_progress
, 1);
2286 cpos
= scp
->cursor_pos
;
2287 copos
= scp
->cursor_oldpos
;
2289 #ifndef SC_NO_CUTPASTE
2290 /* remove the previous mouse pointer image if necessary */
2291 if (scp
->status
& MOUSE_VISIBLE
) {
2293 e
= scp
->mouse_pos
+ scp
->xsize
+ 1;
2294 if ((scp
->status
& (MOUSE_MOVED
| MOUSE_HIDDEN
))
2295 || and_region(&s
, &e
, scp
->start
, scp
->end
)
2296 || ((scp
->status
& CURSOR_ENABLED
) &&
2298 (and_region(&s
, &e
, cpos
, cpos
)
2299 || and_region(&s
, &e
, copos
, copos
)))) {
2300 sc_remove_mouse_image(scp
);
2301 if (scp
->end
>= scp
->xsize
*scp
->ysize
)
2302 scp
->end
= scp
->xsize
*scp
->ysize
- 1;
2305 #endif /* !SC_NO_CUTPASTE */
2308 * WARNING: Don't add debugging kprintf()s with syscons locked.
2311 if (scp
->end
>= scp
->xsize
*scp
->ysize
) {
2312 scp
->end
= scp
->xsize
*scp
->ysize
- 1;
2314 if (scp
->start
< 0) {
2319 * Main update, extract update range and reset
2325 scp
->start
= scp
->xsize
* scp
->ysize
- 1;
2328 if (flags
& SCRN_BULKUNLOCK
) {
2329 atomic_add_int(&scp
->sc
->videoio_in_progress
, -1);
2332 (*scp
->rndr
->draw
)(scp
, start
, end
- start
+ 1, FALSE
);
2333 if (flags
& SCRN_BULKUNLOCK
) {
2335 atomic_add_int(&scp
->sc
->videoio_in_progress
, 1);
2339 * Handle cut sequence
2341 s
= scp
->mouse_cut_start
;
2342 e
= scp
->mouse_cut_end
;
2343 cpu_ccfence(); /* allowed to race */
2351 /* does the cut-mark region overlap with the update region? */
2352 if (and_region(&s
, &e
, start
, end
)) {
2353 if (flags
& SCRN_BULKUNLOCK
) {
2354 atomic_add_int(&scp
->sc
->videoio_in_progress
, -1);
2357 (*scp
->rndr
->draw
)(scp
, s
, e
- s
+ 1, TRUE
);
2358 if (flags
& SCRN_BULKUNLOCK
) {
2360 atomic_add_int(&scp
->sc
->videoio_in_progress
, 1);
2366 /* we are not to show the cursor and the mouse pointer... */
2370 /* update cursor image */
2371 if (scp
->status
& CURSOR_ENABLED
) {
2374 /* did cursor move since last time ? */
2375 if (cpos
!= copos
) {
2376 /* do we need to remove old cursor image ? */
2377 if (!and_region(&s
, &e
, copos
, copos
))
2378 sc_remove_cursor_image(scp
);
2379 sc_draw_cursor_image(scp
);
2381 if (s
<= e
&& and_region(&s
, &e
, cpos
, cpos
)) {
2382 /* cursor didn't move, but has been overwritten */
2383 sc_draw_cursor_image(scp
);
2384 } else if (scp
->sc
->flags
& SC_BLINK_CURSOR
) {
2385 /* if it's a blinking cursor, update it */
2386 (*scp
->rndr
->blink_cursor
)(scp
, cpos
,
2387 sc_inside_cutmark(scp
, cpos
));
2392 #ifndef SC_NO_CUTPASTE
2393 /* update "pseudo" mouse pointer image */
2394 if (scp
->sc
->flags
& SC_MOUSE_ENABLED
) {
2395 if (!(scp
->status
& (MOUSE_VISIBLE
| MOUSE_HIDDEN
))) {
2396 scp
->status
&= ~MOUSE_MOVED
;
2397 sc_draw_mouse_image(scp
);
2400 #endif /* SC_NO_CUTPASTE */
2406 atomic_add_int(&scp
->sc
->videoio_in_progress
, -1);
2407 if (flags
& SCRN_BULKUNLOCK
)
2412 * Thread handles potentially expensive screen updates. The function is
2413 * expected to operate safely without locks.
2416 scrn_update_thread(void *arg
)
2418 scr_stat
*scp
= arg
;
2420 if (scp
->queue_update_td
== 0) {
2421 tsleep_interlock(&scp
->asynctd
, 0);
2422 if (scp
->queue_update_td
== 0)
2423 tsleep(&scp
->asynctd
, PINTERLOCKED
, "wait", 0);
2425 scp
->queue_update_td
= 0;
2426 lockmgr(&sc_asynctd_lk
, LK_EXCLUSIVE
);
2427 atomic_add_int(&scp
->sc
->videoio_in_progress
, 1);
2428 scrn_update(scp
, scp
->show_cursor
, SCRN_BULKUNLOCK
);
2429 atomic_add_int(&scp
->sc
->videoio_in_progress
, -1);
2430 lockmgr(&sc_asynctd_lk
, LK_RELEASE
);
2435 sc_fb_set_par(void *context
, int pending
)
2437 sc_softc_t
*sc
= context
;
2439 lwkt_gettoken(&vga_token
);
2440 if (sc
->fbi
!= NULL
&& sc
->fbi
->fbops
.fb_set_par
!= NULL
)
2441 sc
->fbi
->fbops
.fb_set_par(sc
->fbi
);
2442 lwkt_reltoken(&vga_token
);
2447 sc_fb_blank(void *context
, int pending
)
2449 sc_softc_t
*sc
= context
;
2451 lwkt_gettoken(&vga_token
);
2452 if (sc
->fbi
!= NULL
&& sc
->fbi
->fbops
.fb_blank
!= NULL
) {
2453 /* 0 == FB_BLANK_UNBLANK and 4 == FB_BLANK_POWERDOWN */
2454 if (sc
->flags
& SC_SCRN_BLANKED
) {
2455 sc
->fbi
->fbops
.fb_blank(4, sc
->fbi
);
2456 sc
->fb_blanked
= TRUE
;
2457 if (sc
->unit
== sc_console_unit
)
2458 cons_unavail
= TRUE
;
2460 sc
->fbi
->fbops
.fb_blank(0, sc
->fbi
);
2461 sc
->fb_blanked
= FALSE
;
2462 if (sc
->unit
== sc_console_unit
&&
2463 sc
->cur_scp
->smode
.mode
== VT_AUTO
)
2464 cons_unavail
= FALSE
;
2467 lwkt_reltoken(&vga_token
);
2471 scframebuffer_saver(sc_softc_t
*sc
, int show
)
2473 scr_stat
*scp
= sc
->cur_scp
;
2479 * Gets called on every screen update while screensaver is active,
2480 * so we need to check the SC_SCRN_BLANKED flag ourselves.
2482 if ((sc
->flags
& SC_SCRN_BLANKED
) && show
)
2485 taskqueue_cancel(taskqueue_thread
[0], sc
->fb_blank_task
, NULL
);
2488 scp
->status
|= SAVER_RUNNING
;
2489 sc
->flags
|= SC_SCRN_BLANKED
;
2492 scp
->status
&= ~SAVER_RUNNING
;
2493 sc
->flags
&= ~SC_SCRN_BLANKED
;
2497 taskqueue_enqueue(taskqueue_thread
[0], sc
->fb_blank_task
);
2501 scsplash_callback(int event
, void *arg
)
2506 sc
= (sc_softc_t
*)arg
;
2510 if (add_scrn_saver(scsplash_saver
) == 0) {
2511 sc
->flags
&= ~SC_SAVER_FAILED
;
2512 run_scrn_saver
= TRUE
;
2514 scsplash_stick(TRUE
);
2515 (*current_saver
)(sc
, TRUE
);
2521 if (current_saver
== scsplash_saver
) {
2522 scsplash_stick(FALSE
);
2523 error
= remove_scrn_saver(scsplash_saver
);
2536 scsplash_saver(sc_softc_t
*sc
, int show
)
2538 static int busy
= FALSE
;
2547 if (!(sc
->flags
& SC_SAVER_FAILED
)) {
2548 if (!(sc
->flags
& SC_SCRN_BLANKED
))
2549 set_scrn_saver_mode(scp
, -1, NULL
, 0);
2550 switch (splash(sc
->adp
, TRUE
)) {
2551 case 0: /* succeeded */
2553 case EAGAIN
: /* try later */
2554 restore_scrn_saver_mode(scp
, FALSE
);
2555 sc_touch_scrn_saver(); /* XXX */
2558 sc
->flags
|= SC_SAVER_FAILED
;
2559 scsplash_stick(FALSE
);
2560 restore_scrn_saver_mode(scp
, TRUE
);
2561 kprintf("scsplash_saver(): failed to put up the image\n");
2565 } else if (!sticky_splash
) {
2566 if ((sc
->flags
& SC_SCRN_BLANKED
) && (splash(sc
->adp
, FALSE
) == 0))
2567 restore_scrn_saver_mode(scp
, TRUE
);
2573 add_scrn_saver(void (*this_saver
)(sc_softc_t
*, int))
2578 if (current_saver
!= none_saver
) {
2579 error
= remove_scrn_saver(current_saver
);
2584 if (current_saver
!= none_saver
) {
2588 run_scrn_saver
= FALSE
;
2589 saver_mode
= CONS_LKM_SAVER
;
2590 current_saver
= this_saver
;
2595 remove_scrn_saver(void (*this_saver
)(sc_softc_t
*, int))
2597 if (current_saver
!= this_saver
)
2602 * In order to prevent `current_saver' from being called by
2603 * the timeout routine `scrn_timer()' while we manipulate
2604 * the saver list, we shall set `current_saver' to `none_saver'
2605 * before stopping the current saver, rather than blocking by `splXX()'.
2607 current_saver
= none_saver
;
2609 stop_scrn_saver(this_saver
);
2611 /* unblank all blanked screens */
2612 wait_scrn_saver_stop(NULL
, FALSE
);
2617 current_saver
= none_saver
;
2622 set_scrn_saver_mode(scr_stat
*scp
, int mode
, u_char
*pal
, int border
)
2625 /* assert(scp == scp->sc->cur_scp) */
2627 if (!ISGRAPHSC(scp
))
2628 sc_remove_cursor_image(scp
);
2629 scp
->splash_save_mode
= scp
->mode
;
2630 scp
->splash_save_status
= scp
->status
& (GRAPHICS_MODE
| PIXEL_MODE
);
2631 scp
->status
&= ~(GRAPHICS_MODE
| PIXEL_MODE
);
2632 scp
->status
|= (UNKNOWN_MODE
| SAVER_RUNNING
);
2633 scp
->sc
->flags
|= SC_SCRN_BLANKED
;
2640 if (set_mode(scp
) == 0) {
2641 if (scp
->sc
->fbi
== NULL
&&
2642 scp
->sc
->adp
->va_info
.vi_flags
& V_INFO_GRAPHICS
) {
2643 scp
->status
|= GRAPHICS_MODE
;
2645 if (scp
->sc
->fbi
== NULL
&& pal
!= NULL
)
2646 load_palette(scp
->sc
->adp
, pal
);
2647 sc_set_border(scp
, border
);
2651 scp
->mode
= scp
->splash_save_mode
;
2652 scp
->status
&= ~(UNKNOWN_MODE
| SAVER_RUNNING
);
2653 scp
->status
|= scp
->splash_save_status
;
2661 restore_scrn_saver_mode(scr_stat
*scp
, int changemode
)
2666 /* assert(scp == scp->sc->cur_scp) */
2669 status
= scp
->status
;
2670 scp
->mode
= scp
->splash_save_mode
;
2671 scp
->status
&= ~(UNKNOWN_MODE
| SAVER_RUNNING
);
2672 scp
->status
|= scp
->splash_save_status
;
2673 scp
->sc
->flags
&= ~SC_SCRN_BLANKED
;
2675 if (!ISGRAPHSC(scp
))
2676 sc_draw_cursor_image(scp
);
2681 if (set_mode(scp
) == 0) {
2682 if (scp
->sc
->fbi
== NULL
)
2683 load_palette(scp
->sc
->adp
, scp
->sc
->palette
);
2689 scp
->status
= status
;
2697 stop_scrn_saver(sc_softc_t
*sc
, void (*saver
)(sc_softc_t
*, int))
2699 (*saver
)(sc
, FALSE
);
2700 run_scrn_saver
= FALSE
;
2701 /* the screen saver may have chosen not to stop after all... */
2702 if (sc
->flags
& SC_SCRN_BLANKED
) {
2706 mark_all(sc
->cur_scp
);
2707 if (sc
->delayed_next_scr
)
2708 sc_switch_scr(sc
, sc
->delayed_next_scr
- 1);
2709 wakeup(&scrn_blanked
);
2713 wait_scrn_saver_stop(sc_softc_t
*sc
, int need_unlock
)
2717 while (scrn_blanked
> 0) {
2718 run_scrn_saver
= FALSE
;
2719 if (sc
&& !(sc
->flags
& SC_SCRN_BLANKED
)) {
2724 tsleep_interlock(&scrn_blanked
, PCATCH
);
2726 error
= tsleep(&scrn_blanked
, PCATCH
| PINTERLOCKED
, "scrsav", 0);
2729 error
= tsleep(&scrn_blanked
, PCATCH
, "scrsav", 0);
2731 /* May return ERESTART */
2735 run_scrn_saver
= FALSE
;
2738 #endif /* NSPLASH */
2741 sc_start_scrn_saver(sc_softc_t
*sc
)
2744 (*current_saver
)(sc
, TRUE
);
2749 sc_stop_scrn_saver(sc_softc_t
*sc
)
2752 if (sc
->flags
& SC_SCRN_BLANKED
)
2753 stop_scrn_saver(sc
, current_saver
);
2758 sc_touch_scrn_saver(void)
2760 scsplash_stick(FALSE
);
2761 run_scrn_saver
= FALSE
;
2765 sc_switch_scr(sc_softc_t
*sc
, u_int next_scr
)
2770 DPRINTF(5, ("sc0: sc_switch_scr() %d ", next_scr
+ 1));
2772 /* prevent switch if previously requested */
2773 if (sc
->flags
& SC_SCRN_VTYLOCK
) {
2774 sc_bell(sc
->cur_scp
, sc
->cur_scp
->bell_pitch
,
2775 sc
->cur_scp
->bell_duration
);
2779 /* delay switch if the screen is blanked or being updated */
2780 if ((sc
->flags
& SC_SCRN_BLANKED
) || sc
->write_in_progress
2781 || sc
->blink_in_progress
|| sc
->videoio_in_progress
) {
2782 sc
->delayed_next_scr
= next_scr
+ 1;
2783 sc_touch_scrn_saver();
2784 DPRINTF(5, ("switch delayed\n"));
2788 cur_scp
= sc
->cur_scp
;
2791 * we are in the middle of the vty switching process...
2793 * This may be in the console path, be very careful. pfindn() is
2794 * still going to use a spinlock but it no longer uses tokens so
2797 if (sc
->switch_in_progress
&&
2798 (cur_scp
->smode
.mode
== VT_PROCESS
) &&
2800 if (cur_scp
->proc
!= pfindn(cur_scp
->pid
)) {
2802 * The controlling process has died!!. Do some clean up.
2803 * NOTE:`cur_scp->proc' and `cur_scp->smode.mode'
2804 * are not reset here yet; they will be cleared later.
2806 DPRINTF(5, ("cur_scp controlling process %d died, ", cur_scp
->pid
));
2807 if (cur_scp
->status
& SWITCH_WAIT_REL
) {
2809 * Force the previous switch to finish, but return now
2813 DPRINTF(5, ("reset WAIT_REL, "));
2814 finish_vt_rel(cur_scp
, TRUE
);
2815 DPRINTF(5, ("finishing previous switch\n"));
2817 } else if (cur_scp
->status
& SWITCH_WAIT_ACQ
) {
2818 /* let's assume screen switch has been completed. */
2819 DPRINTF(5, ("reset WAIT_ACQ, "));
2820 finish_vt_acq(cur_scp
);
2823 * We are in between screen release and acquisition, and
2824 * reached here via scgetc() or scrn_timer() which has
2825 * interrupted exchange_scr(). Don't do anything stupid.
2827 DPRINTF(5, ("waiting nothing, "));
2831 * The controlling process is alive, but not responding...
2832 * It is either buggy or it may be just taking time.
2833 * The following code is a gross kludge to cope with this
2834 * problem for which there is no clean solution. XXX
2836 if (cur_scp
->status
& SWITCH_WAIT_REL
) {
2837 switch (sc
->switch_in_progress
++) {
2841 DPRINTF(5, ("sending relsig again, "));
2842 signal_vt_rel(cur_scp
);
2849 * Act as if the controlling program returned
2853 DPRINTF(5, ("force reset WAIT_REL, "));
2854 finish_vt_rel(cur_scp
, FALSE
);
2855 DPRINTF(5, ("act as if VT_FALSE was seen\n"));
2858 } else if (cur_scp
->status
& SWITCH_WAIT_ACQ
) {
2859 switch (sc
->switch_in_progress
++) {
2863 DPRINTF(5, ("sending acqsig again, "));
2864 signal_vt_acq(cur_scp
);
2870 /* clear the flag and finish the previous switch */
2871 DPRINTF(5, ("force reset WAIT_ACQ, "));
2872 finish_vt_acq(cur_scp
);
2880 * Return error if an invalid argument is given, or vty switch
2881 * is still in progress.
2883 if ((next_scr
< sc
->first_vty
) || (next_scr
>= sc
->first_vty
+ sc
->vtys
)
2884 || sc
->switch_in_progress
) {
2885 sc_bell(cur_scp
, bios_value
.bell_pitch
, BELL_DURATION
);
2886 DPRINTF(5, ("error 1\n"));
2891 * Don't allow switching away from the graphics mode vty
2892 * if the switch mode is VT_AUTO, unless the next vty is the same
2893 * as the current or the current vty has been closed (but showing).
2895 tp
= VIRTUAL_TTY(sc
, cur_scp
->index
);
2896 if ((cur_scp
->index
!= next_scr
)
2898 && (cur_scp
->smode
.mode
== VT_AUTO
)
2899 && ISGRAPHSC(cur_scp
)) {
2900 sc_bell(cur_scp
, bios_value
.bell_pitch
, BELL_DURATION
);
2901 DPRINTF(5, ("error, graphics mode\n"));
2906 * Is the wanted vty open? Don't allow switching to a closed vty.
2907 * If we are in DDB, don't switch to a vty in the VT_PROCESS mode.
2908 * Note that we always allow the user to switch to the kernel
2909 * console even if it is closed.
2911 if ((sc_console
== NULL
) || (next_scr
!= sc_console
->index
)) {
2912 tp
= VIRTUAL_TTY(sc
, next_scr
);
2913 if (!ISTTYOPEN(tp
)) {
2914 sc_bell(cur_scp
, bios_value
.bell_pitch
, BELL_DURATION
);
2915 DPRINTF(5, ("error 2, requested vty isn't open!\n"));
2918 if ((debugger
> 0) && (SC_STAT(tp
->t_dev
)->smode
.mode
== VT_PROCESS
)) {
2919 DPRINTF(5, ("error 3, requested vty is in the VT_PROCESS mode\n"));
2924 /* this is the start of vty switching process... */
2925 ++sc
->switch_in_progress
;
2926 sc
->delayed_next_scr
= 0;
2927 sc
->old_scp
= cur_scp
;
2928 sc
->new_scp
= SC_STAT(SC_DEV(sc
, next_scr
));
2929 if (sc
->new_scp
== sc
->old_scp
) {
2930 sc
->switch_in_progress
= 0;
2931 wakeup((caddr_t
)&sc
->new_scp
->smode
);
2932 DPRINTF(5, ("switch done (new == old)\n"));
2936 /* has controlling process died? */
2937 vt_proc_alive(sc
->old_scp
);
2938 vt_proc_alive(sc
->new_scp
);
2940 /* wait for the controlling process to release the screen, if necessary */
2941 if (signal_vt_rel(sc
->old_scp
)) {
2945 /* go set up the new vty screen */
2948 /* wake up processes waiting for this vty */
2949 wakeup((caddr_t
)&sc
->cur_scp
->smode
);
2951 /* wait for the controlling process to acknowledge, if necessary */
2952 if (signal_vt_acq(sc
->cur_scp
)) {
2956 sc
->switch_in_progress
= 0;
2957 if (sc
->unit
== sc_console_unit
&& !sc
->fb_blanked
)
2958 cons_unavail
= FALSE
;
2959 DPRINTF(5, ("switch done\n"));
2965 do_switch_scr(sc_softc_t
*sc
)
2967 lwkt_gettoken(&vga_token
);
2968 vt_proc_alive(sc
->new_scp
);
2971 /* sc->cur_scp == sc->new_scp */
2972 wakeup((caddr_t
)&sc
->cur_scp
->smode
);
2974 /* wait for the controlling process to acknowledge, if necessary */
2975 if (!signal_vt_acq(sc
->cur_scp
)) {
2976 sc
->switch_in_progress
= 0;
2977 if (sc
->unit
== sc_console_unit
&& !sc
->fb_blanked
)
2978 cons_unavail
= FALSE
;
2980 lwkt_reltoken(&vga_token
);
2984 vt_proc_alive(scr_stat
*scp
)
2986 lwkt_gettoken(&vga_token
);
2988 if (scp
->proc
== pfindn(scp
->pid
)) {
2989 lwkt_reltoken(&vga_token
);
2993 scp
->smode
.mode
= VT_AUTO
;
2994 DPRINTF(5, ("vt controlling process %d died\n", scp
->pid
));
2996 lwkt_reltoken(&vga_token
);
3001 signal_vt_rel(scr_stat
*scp
)
3005 lwkt_gettoken(&vga_token
);
3006 if (scp
->smode
.mode
!= VT_PROCESS
) {
3007 lwkt_reltoken(&vga_token
);
3010 scp
->status
|= SWITCH_WAIT_REL
;
3013 ksignal(p
, scp
->smode
.relsig
);
3015 DPRINTF(5, ("sending relsig to %d\n", scp
->pid
));
3016 lwkt_reltoken(&vga_token
);
3022 signal_vt_acq(scr_stat
*scp
)
3026 lwkt_gettoken(&vga_token
);
3027 if (scp
->smode
.mode
!= VT_PROCESS
) {
3028 lwkt_reltoken(&vga_token
);
3031 if (scp
->sc
->unit
== sc_console_unit
)
3032 cons_unavail
= TRUE
;
3033 scp
->status
|= SWITCH_WAIT_ACQ
;
3036 ksignal(p
, scp
->smode
.acqsig
);
3038 DPRINTF(5, ("sending acqsig to %d\n", scp
->pid
));
3039 lwkt_reltoken(&vga_token
);
3045 finish_vt_rel(scr_stat
*scp
, int release
)
3047 lwkt_gettoken(&vga_token
);
3048 if (scp
== scp
->sc
->old_scp
&& scp
->status
& SWITCH_WAIT_REL
) {
3049 scp
->status
&= ~SWITCH_WAIT_REL
;
3051 do_switch_scr(scp
->sc
);
3053 scp
->sc
->switch_in_progress
= 0;
3054 lwkt_reltoken(&vga_token
);
3057 lwkt_reltoken(&vga_token
);
3062 finish_vt_acq(scr_stat
*scp
)
3064 lwkt_gettoken(&vga_token
);
3065 if (scp
== scp
->sc
->new_scp
&& scp
->status
& SWITCH_WAIT_ACQ
) {
3066 scp
->status
&= ~SWITCH_WAIT_ACQ
;
3067 scp
->sc
->switch_in_progress
= 0;
3068 lwkt_reltoken(&vga_token
);
3071 lwkt_reltoken(&vga_token
);
3076 exchange_scr(sc_softc_t
*sc
)
3080 lwkt_gettoken(&vga_token
);
3081 /* save the current state of video and keyboard */
3082 sc_move_cursor(sc
->old_scp
, sc
->old_scp
->xpos
, sc
->old_scp
->ypos
);
3083 if (!ISGRAPHSC(sc
->old_scp
))
3084 sc_remove_cursor_image(sc
->old_scp
);
3085 if (sc
->old_scp
->kbd_mode
== K_XLATE
)
3086 save_kbd_state(sc
->old_scp
, TRUE
);
3088 /* set up the video for the new screen */
3089 scp
= sc
->cur_scp
= sc
->new_scp
;
3090 if (sc
->old_scp
->mode
!= scp
->mode
|| ISUNKNOWNSC(sc
->old_scp
))
3092 else if (sc
->adp
!= NULL
)
3093 sc_vtb_init(&scp
->scr
, VTB_FRAMEBUFFER
, scp
->xsize
, scp
->ysize
,
3094 (void *)sc
->adp
->va_window
, FALSE
);
3095 scp
->status
|= MOUSE_HIDDEN
;
3096 sc_update_render(scp
); /* Switch to kms renderer if necessary */
3097 sc_move_cursor(scp
, scp
->xpos
, scp
->ypos
);
3098 if (!ISGRAPHSC(scp
))
3099 sc_set_cursor_image(scp
);
3100 if (sc
->fbi
== NULL
&& ISGRAPHSC(sc
->old_scp
))
3101 load_palette(sc
->adp
, sc
->palette
);
3102 if (!ISGRAPHSC(scp
) || sc
->fbi
== NULL
)
3103 sc_set_border(scp
, scp
->border
);
3105 /* set up the keyboard for the new screen */
3106 if (sc
->old_scp
->kbd_mode
!= scp
->kbd_mode
)
3107 kbd_ioctl(sc
->kbd
, KDSKBMODE
, (caddr_t
)&scp
->kbd_mode
);
3108 update_kbd_state(scp
, scp
->status
, LOCK_MASK
, TRUE
);
3113 * Restore DRM framebuffer console mode if necessary.
3114 * Especially avoid modesetting when switching to a vt which is in
3115 * graphics mode, because the fb_set_par() from the taskqueue thread
3116 * might race with the modesetting ioctl from the userland application.
3118 if (!ISTEXTSC(sc
->old_scp
) &&
3119 sc
->fbi
!= NULL
&& sc
->fbi
->fbops
.fb_set_par
!= NULL
&&
3120 sc
->fb_set_par_task
!= NULL
) {
3121 taskqueue_enqueue(taskqueue_thread
[0], sc
->fb_set_par_task
);
3124 lwkt_reltoken(&vga_token
);
3128 sc_puts(scr_stat
*scp
, u_char
*buf
, int len
)
3131 /* make screensaver happy */
3132 if (!sticky_splash
&& scp
== scp
->sc
->cur_scp
)
3133 run_scrn_saver
= FALSE
;
3137 (*scp
->tsw
->te_puts
)(scp
, buf
, len
);
3139 if (scp
->sc
->delayed_next_scr
)
3140 sc_switch_scr(scp
->sc
, scp
->sc
->delayed_next_scr
- 1);
3145 sc_draw_cursor_image(scr_stat
*scp
)
3147 /* assert(scp == scp->sc->cur_scp); */
3148 atomic_add_int(&scp
->sc
->videoio_in_progress
, 1);
3149 (*scp
->rndr
->draw_cursor
)(scp
, scp
->cursor_pos
,
3150 scp
->sc
->flags
& SC_BLINK_CURSOR
, TRUE
,
3151 sc_inside_cutmark(scp
, scp
->cursor_pos
));
3152 scp
->cursor_oldpos
= scp
->cursor_pos
;
3153 atomic_add_int(&scp
->sc
->videoio_in_progress
, -1);
3157 sc_remove_cursor_image(scr_stat
*scp
)
3159 /* assert(scp == scp->sc->cur_scp); */
3160 atomic_add_int(&scp
->sc
->videoio_in_progress
, 1);
3161 (*scp
->rndr
->draw_cursor
)(scp
, scp
->cursor_oldpos
,
3162 scp
->sc
->flags
& SC_BLINK_CURSOR
, FALSE
,
3163 sc_inside_cutmark(scp
, scp
->cursor_oldpos
));
3164 atomic_add_int(&scp
->sc
->videoio_in_progress
, -1);
3168 update_cursor_image(scr_stat
*scp
)
3172 if (scp
->sc
->flags
& SC_CHAR_CURSOR
) {
3173 scp
->cursor_base
= imax(0, scp
->sc
->cursor_base
);
3174 scp
->cursor_height
= imin(scp
->sc
->cursor_height
, scp
->font_height
);
3176 scp
->cursor_base
= 0;
3177 scp
->cursor_height
= scp
->font_height
;
3179 blink
= scp
->sc
->flags
& SC_BLINK_CURSOR
;
3181 /* assert(scp == scp->sc->cur_scp); */
3182 atomic_add_int(&scp
->sc
->videoio_in_progress
, 1);
3183 (*scp
->rndr
->draw_cursor
)(scp
, scp
->cursor_oldpos
, blink
, FALSE
,
3184 sc_inside_cutmark(scp
, scp
->cursor_pos
));
3185 (*scp
->rndr
->set_cursor
)(scp
, scp
->cursor_base
, scp
->cursor_height
, blink
);
3186 (*scp
->rndr
->draw_cursor
)(scp
, scp
->cursor_pos
, blink
, TRUE
,
3187 sc_inside_cutmark(scp
, scp
->cursor_pos
));
3188 atomic_add_int(&scp
->sc
->videoio_in_progress
, -1);
3192 sc_set_cursor_image(scr_stat
*scp
)
3194 if (scp
->sc
->flags
& SC_CHAR_CURSOR
) {
3195 scp
->cursor_base
= imax(0, scp
->sc
->cursor_base
);
3196 scp
->cursor_height
= imin(scp
->sc
->cursor_height
, scp
->font_height
);
3198 scp
->cursor_base
= 0;
3199 scp
->cursor_height
= scp
->font_height
;
3202 /* assert(scp == scp->sc->cur_scp); */
3203 atomic_add_int(&scp
->sc
->videoio_in_progress
, 1);
3204 (*scp
->rndr
->set_cursor
)(scp
, scp
->cursor_base
, scp
->cursor_height
,
3205 scp
->sc
->flags
& SC_BLINK_CURSOR
);
3206 atomic_add_int(&scp
->sc
->videoio_in_progress
, -1);
3210 scinit(int unit
, int flags
)
3213 * When syscons is being initialized as the kernel console, malloc()
3214 * is not yet functional, because various kernel structures has not been
3215 * fully initialized yet. Therefore, we need to declare the following
3216 * static buffers for the console. This is less than ideal,
3217 * but is necessry evil for the time being. XXX
3219 static scr_stat main_console
;
3220 static u_short sc_buffer
[2*ROW
*2*COL
]; /* XXX */
3221 #ifndef SC_NO_FONT_LOADING
3222 static u_char font_8
[256*8];
3223 static u_char font_14
[256*14];
3224 static u_char font_16
[256*16];
3229 video_adapter_t
*adp
;
3230 char tbuf
[MAKEDEV_MINNBUF
];
3235 /* one time initialization */
3236 if (init_done
== COLD
)
3237 sc_get_bios_values(&bios_value
);
3241 * Allocate resources. Even if we are being called for the second
3242 * time, we must allocate them again, because they might have
3245 sc
= sc_get_softc(unit
, flags
& SC_KERNEL_CONSOLE
);
3247 if (flags
& SC_EFI_FB
) {
3248 /* Don't replace already registered drm framebuffer here */
3249 if (sc
->fbi
== NULL
) {
3250 sc
->fbi
= &efi_fb_info
;
3251 sc
->fbi_generation
++;
3253 } else if (sc
->adapter
>= 0) {
3254 vid_release(sc
->adp
, (void *)&sc
->adapter
);
3258 if (sc
->keyboard
>= 0) {
3259 DPRINTF(5, ("sc%d: releasing kbd%d\n", unit
, sc
->keyboard
));
3260 i
= kbd_release(sc
->kbd
, (void *)&sc
->keyboard
);
3261 DPRINTF(5, ("sc%d: kbd_release returned %d\n", unit
, i
));
3262 if (sc
->kbd
!= NULL
) {
3263 DPRINTF(5, ("sc%d: kbd != NULL!, index:%d, unit:%d, flags:0x%x\n",
3264 unit
, sc
->kbd
->kb_index
, sc
->kbd
->kb_unit
, sc
->kbd
->kb_flags
));
3268 if (!(flags
& SC_EFI_FB
)) {
3269 sc
->adapter
= vid_allocate("*", unit
, (void *)&sc
->adapter
);
3270 sc
->adp
= vid_get_adapter(sc
->adapter
);
3271 /* assert((sc->adapter >= 0) && (sc->adp != NULL)) */
3273 sc
->keyboard
= sc_allocate_keyboard(sc
, unit
);
3274 DPRINTF(1, ("sc%d: keyboard %d\n", unit
, sc
->keyboard
));
3275 sc
->kbd
= kbd_get_keyboard(sc
->keyboard
);
3276 if (sc
->kbd
!= NULL
) {
3277 DPRINTF(1, ("sc%d: kbd index:%d, unit:%d, flags:0x%x\n",
3278 unit
, sc
->kbd
->kb_index
, sc
->kbd
->kb_unit
, sc
->kbd
->kb_flags
));
3281 if (!(sc
->flags
& SC_INIT_DONE
) || (adp
!= sc
->adp
)) {
3283 if (sc
->fbi
!= NULL
)
3284 sc
->initial_mode
= 0;
3286 sc
->initial_mode
= sc
->adp
->va_initial_mode
;
3288 #ifndef SC_NO_FONT_LOADING
3289 if (flags
& SC_KERNEL_CONSOLE
) {
3290 sc
->font_8
= font_8
;
3291 sc
->font_14
= font_14
;
3292 sc
->font_16
= font_16
;
3293 } else if (sc
->font_8
== NULL
) {
3294 /* assert(sc_malloc) */
3295 sc
->font_8
= kmalloc(sizeof(font_8
), M_SYSCONS
, M_WAITOK
);
3296 sc
->font_14
= kmalloc(sizeof(font_14
), M_SYSCONS
, M_WAITOK
);
3297 sc
->font_16
= kmalloc(sizeof(font_16
), M_SYSCONS
, M_WAITOK
);
3301 if (sc
->fbi
!= NULL
) {
3305 lwkt_gettoken(&vga_token
);
3306 /* extract the hw cursor location and hide the cursor for now */
3307 (*vidsw
[sc
->adapter
]->read_hw_cursor
)(sc
->adp
, &col
, &row
);
3308 (*vidsw
[sc
->adapter
]->set_hw_cursor
)(sc
->adp
, -1, -1);
3309 lwkt_reltoken(&vga_token
);
3312 /* set up the first console */
3313 sc
->first_vty
= unit
*MAXCONS
;
3314 sc
->vtys
= MAXCONS
; /* XXX: should be configurable */
3315 if (flags
& SC_KERNEL_CONSOLE
) {
3316 scp
= &main_console
;
3317 sc
->console_scp
= scp
;
3318 init_scp(sc
, sc
->first_vty
, scp
);
3319 sc_vtb_init(&scp
->vtb
, VTB_MEMORY
, scp
->xsize
, scp
->ysize
,
3320 (void *)sc_buffer
, FALSE
);
3321 if (sc_init_emulator(scp
, SC_DFLT_TERM
))
3322 sc_init_emulator(scp
, "*");
3323 (*scp
->tsw
->te_default_attr
)(scp
,
3324 kernel_default
.std_color
,
3325 kernel_default
.rev_color
);
3327 /* assert(sc_malloc) */
3328 sc
->dev
= kmalloc(sizeof(cdev_t
)*sc
->vtys
, M_SYSCONS
, M_WAITOK
| M_ZERO
);
3330 sc
->dev
[0] = make_dev(&sc_ops
, unit
*MAXCONS
, UID_ROOT
,
3331 GID_WHEEL
, 0600, "ttyv%s",
3332 makedev_unit_b32(tbuf
, unit
* MAXCONS
));
3334 ttymalloc(&sc
->dev
[0]->si_tty
);
3335 scp
= alloc_scp(sc
, sc
->first_vty
);
3336 sc
->dev
[0]->si_drv1
= scp
;
3340 /* copy screen to temporary buffer */
3341 if (scp
->sc
->fbi
== NULL
) {
3342 sc_vtb_init(&scp
->scr
, VTB_FRAMEBUFFER
, scp
->xsize
, scp
->ysize
,
3343 (void *)scp
->sc
->adp
->va_window
, FALSE
);
3345 sc_vtb_copy(&scp
->scr
, 0, &scp
->vtb
, 0, scp
->xsize
*scp
->ysize
);
3348 /* move cursors to the initial positions */
3349 if (col
>= scp
->xsize
)
3351 if (row
>= scp
->ysize
)
3352 row
= scp
->ysize
- 1;
3355 if (sc
->fbi
!= NULL
) {
3356 scp
->cursor_pos
= 0;
3357 sc
->cursor_base
= 0;
3358 sc
->cursor_height
= scp
->font_height
;
3360 scp
->cursor_pos
= scp
->cursor_oldpos
= row
*scp
->xsize
+ col
;
3361 if (bios_value
.cursor_end
< scp
->font_height
)
3362 sc
->cursor_base
= scp
->font_height
- bios_value
.cursor_end
- 1;
3364 sc
->cursor_base
= 0;
3365 i
= bios_value
.cursor_end
- bios_value
.cursor_start
+ 1;
3366 sc
->cursor_height
= imin(i
, scp
->font_height
);
3368 #ifndef SC_NO_SYSMOUSE
3369 sc_mouse_move(scp
, scp
->xpixel
/2, scp
->ypixel
/2);
3371 if (!ISGRAPHSC(scp
)) {
3372 sc_set_cursor_image(scp
);
3373 sc_draw_cursor_image(scp
);
3374 /* If framebuffer vaddr is still 0, we can't draw the border yet */
3375 if (scp
->sc
->fbi
!= NULL
&& scp
->sc
->fbi
->vaddr
!= 0) {
3376 sc_filled_border
= TRUE
;
3377 sc_set_border(scp
, scp
->border
);
3381 /* save font and palette */
3382 #ifndef SC_NO_FONT_LOADING
3383 sc
->fonts_loaded
= 0;
3385 bcopy(dflt_font_8
, sc
->font_8
, sizeof(dflt_font_8
));
3386 bcopy(dflt_font_14
, sc
->font_14
, sizeof(dflt_font_14
));
3387 bcopy(dflt_font_16
, sc
->font_16
, sizeof(dflt_font_16
));
3388 sc
->fonts_loaded
= FONT_16
| FONT_14
| FONT_8
;
3389 #endif /* SC_DFLT_FONT */
3390 if (sc
->adp
!= NULL
&& ISFONTAVAIL(sc
->adp
->va_flags
)) {
3392 if (scp
->font_height
< 14) {
3393 sc_load_font(scp
, 0, 8, sc
->font_8
, 0, 256);
3394 } else if (scp
->font_height
>= 16) {
3395 sc_load_font(scp
, 0, 16, sc
->font_16
, 0, 256);
3397 sc_load_font(scp
, 0, 14, sc
->font_14
, 0, 256);
3399 #else /* !SC_DFLT_FONT */
3400 if (scp
->font_height
< 14) {
3401 sc_save_font(scp
, 0, 8, sc
->font_8
, 0, 256);
3402 sc
->fonts_loaded
= FONT_8
;
3403 } else if (scp
->font_height
>= 16) {
3404 sc_save_font(scp
, 0, 16, sc
->font_16
, 0, 256);
3405 sc
->fonts_loaded
= FONT_16
;
3407 sc_save_font(scp
, 0, 14, sc
->font_14
, 0, 256);
3408 sc
->fonts_loaded
= FONT_14
;
3410 #endif /* SC_DFLT_FONT */
3411 /* FONT KLUDGE: always use the font page #0. XXX */
3412 sc_show_font(scp
, 0);
3414 #endif /* !SC_NO_FONT_LOADING */
3416 if (!(flags
& SC_EFI_FB
))
3417 save_palette(sc
->adp
, sc
->palette
);
3420 if (!(sc
->flags
& SC_SPLASH_SCRN
) && (flags
& SC_KERNEL_CONSOLE
)) {
3421 /* we are ready to put up the splash image! */
3422 splash_init(sc
->adp
, scsplash_callback
, sc
);
3423 sc
->flags
|= SC_SPLASH_SCRN
;
3425 #endif /* NSPLASH */
3428 /* the rest is not necessary, if we have done it once */
3429 if (sc
->flags
& SC_INIT_DONE
) {
3433 /* initialize mapscrn arrays to a one to one map */
3434 for (i
= 0; i
< sizeof(sc
->scr_map
); i
++)
3435 sc
->scr_map
[i
] = sc
->scr_rmap
[i
] = i
;
3437 sc
->flags
|= SC_INIT_DONE
;
3442 scterm(int unit
, int flags
)
3447 sc
= sc_get_softc(unit
, flags
& SC_KERNEL_CONSOLE
);
3449 return; /* shouldn't happen */
3451 lwkt_gettoken(&vga_token
);
3453 /* this console is no longer available for the splash screen */
3454 if (sc
->flags
& SC_SPLASH_SCRN
) {
3455 splash_term(sc
->adp
);
3456 sc
->flags
&= ~SC_SPLASH_SCRN
;
3458 #endif /* NSPLASH */
3461 /* move the hardware cursor to the upper-left corner */
3462 (*vidsw
[sc
->adapter
]->set_hw_cursor
)(sc
->adp
, 0, 0);
3465 /* release the keyboard and the video card */
3466 if (sc
->keyboard
>= 0)
3467 kbd_release(sc
->kbd
, &sc
->keyboard
);
3468 if (sc
->adapter
>= 0)
3469 vid_release(sc
->adp
, &sc
->adapter
);
3472 * Stop the terminal emulator, if any. If operating on the
3473 * kernel console sc->dev may not be setup yet.
3475 if (flags
& SC_KERNEL_CONSOLE
)
3476 scp
= sc
->console_scp
;
3478 scp
= SC_STAT(sc
->dev
[0]);
3480 (*scp
->tsw
->te_term
)(scp
, &scp
->ts
);
3481 if (scp
->ts
!= NULL
)
3482 kfree(scp
->ts
, M_SYSCONS
);
3484 /* clear the structure */
3485 if (!(flags
& SC_KERNEL_CONSOLE
)) {
3486 /* XXX: We need delete_dev() for this */
3487 kfree(sc
->dev
, M_SYSCONS
);
3489 /* XXX: We need a ttyunregister for this */
3490 /* XXX: do not race tty token access */
3491 kfree(sc
->tty
, M_SYSCONS
);
3493 #ifndef SC_NO_FONT_LOADING
3494 kfree(sc
->font_8
, M_SYSCONS
);
3495 kfree(sc
->font_14
, M_SYSCONS
);
3496 kfree(sc
->font_16
, M_SYSCONS
);
3498 /* XXX vtb, history */
3500 bzero(sc
, sizeof(*sc
));
3503 lwkt_reltoken(&vga_token
);
3508 scshutdown(void *arg
, int howto
)
3510 /* assert(sc_console != NULL) */
3512 lwkt_gettoken(&vga_token
);
3514 sc_touch_scrn_saver();
3515 if (!cold
&& sc_console
3516 && sc_console
->sc
->cur_scp
->smode
.mode
== VT_AUTO
3517 && sc_console
->smode
.mode
== VT_AUTO
) {
3518 sc_switch_scr(sc_console
->sc
, sc_console
->index
);
3520 shutdown_in_progress
= TRUE
;
3522 lwkt_reltoken(&vga_token
);
3526 sc_clean_up(scr_stat
*scp
, int need_unlock
)
3530 #endif /* NSPLASH */
3532 lwkt_gettoken(&vga_token
);
3533 if (scp
->sc
->flags
& SC_SCRN_BLANKED
) {
3534 sc_touch_scrn_saver();
3536 if ((error
= wait_scrn_saver_stop(scp
->sc
, need_unlock
))) {
3537 lwkt_reltoken(&vga_token
);
3540 #endif /* NSPLASH */
3542 scp
->status
|= MOUSE_HIDDEN
;
3543 sc_remove_mouse_image(scp
);
3544 sc_remove_cutmarking(scp
);
3545 lwkt_reltoken(&vga_token
);
3550 sc_alloc_scr_buffer(scr_stat
*scp
, int wait
, int discard
)
3555 lwkt_gettoken(&vga_token
);
3557 sc_vtb_init(&new, VTB_MEMORY
, scp
->xsize
, scp
->ysize
, NULL
, wait
);
3558 if (!discard
&& (old
.vtb_flags
& VTB_VALID
)) {
3559 /* retain the current cursor position and buffer contants */
3560 scp
->cursor_oldpos
= scp
->cursor_pos
;
3562 * This works only if the old buffer has the same size as or larger
3563 * than the new one. XXX
3565 sc_vtb_copy(&old
, 0, &new, 0, scp
->xsize
*scp
->ysize
);
3569 sc_vtb_destroy(&old
);
3572 #ifndef SC_NO_SYSMOUSE
3573 /* move the mouse cursor at the center of the screen */
3574 sc_mouse_move(scp
, scp
->xpixel
/ 2, scp
->ypixel
/ 2);
3576 lwkt_reltoken(&vga_token
);
3580 alloc_scp(sc_softc_t
*sc
, int vty
)
3584 /* assert(sc_malloc) */
3586 scp
= kmalloc(sizeof(scr_stat
), M_SYSCONS
, M_WAITOK
);
3587 init_scp(sc
, vty
, scp
);
3589 sc_alloc_scr_buffer(scp
, TRUE
, TRUE
);
3590 if (sc_init_emulator(scp
, SC_DFLT_TERM
))
3591 sc_init_emulator(scp
, "*");
3593 #ifndef SC_NO_CUTPASTE
3594 sc_alloc_cut_buffer(scp
, TRUE
);
3597 #ifndef SC_NO_HISTORY
3598 sc_alloc_history_buffer(scp
, 0, 0, TRUE
);
3604 * NOTE: Must be called with vga_token held.
3607 init_scp(sc_softc_t
*sc
, int vty
, scr_stat
*scp
)
3611 bzero(scp
, sizeof(*scp
));
3616 scp
->mode
= sc
->initial_mode
;
3617 scp
->fbi_generation
= sc
->fbi_generation
;
3618 callout_init_lk(&scp
->blink_screen_ch
, &syscons_blink_lk
);
3619 if (scp
->sc
->fbi
== NULL
) {
3620 lwkt_gettoken(&vga_token
);
3621 (*vidsw
[sc
->adapter
]->get_info
)(sc
->adp
, scp
->mode
, &info
);
3622 lwkt_reltoken(&vga_token
);
3624 if (scp
->sc
->fbi
!= NULL
) {
3625 scp
->xpixel
= sc
->fbi
->width
;
3626 scp
->ypixel
= sc
->fbi
->height
;
3627 scp
->font_width
= 8;
3628 scp
->font_height
= 16;
3630 /* The first vty uses a statically allocated 160x50 buffer */
3631 if (vty
== sc
->first_vty
)
3632 sc_font_scale(scp
, 2*COL
, 2*ROW
);
3634 sc_font_scale(scp
, 0, 0);
3636 #ifndef SC_NO_FONT_LOADING
3637 scp
->font
= sc
->font_16
;
3641 } else if (info
.vi_flags
& V_INFO_GRAPHICS
) {
3642 scp
->status
|= GRAPHICS_MODE
;
3643 scp
->xpixel
= info
.vi_width
;
3644 scp
->ypixel
= info
.vi_height
;
3645 scp
->xsize
= info
.vi_width
/8;
3646 scp
->ysize
= info
.vi_height
/info
.vi_cheight
;
3647 scp
->font_height
= 0;
3648 scp
->font_width
= 0;
3651 scp
->xsize
= info
.vi_width
;
3652 scp
->ysize
= info
.vi_height
;
3653 scp
->xpixel
= scp
->xsize
*8;
3654 scp
->ypixel
= scp
->ysize
*info
.vi_cheight
;
3655 scp
->font_width
= 8;
3656 if (info
.vi_cheight
< 14) {
3657 scp
->font_height
= 8;
3658 #ifndef SC_NO_FONT_LOADING
3659 scp
->font
= sc
->font_8
;
3663 } else if (info
.vi_cheight
>= 16) {
3664 scp
->font_height
= 16;
3665 #ifndef SC_NO_FONT_LOADING
3666 scp
->font
= sc
->font_16
;
3671 scp
->font_height
= 14;
3672 #ifndef SC_NO_FONT_LOADING
3673 scp
->font
= sc
->font_14
;
3679 scp
->xoff
= scp
->yoff
= 0;
3680 scp
->xpos
= scp
->ypos
= 0;
3681 sc_vtb_init(&scp
->vtb
, VTB_MEMORY
, 0, 0, NULL
, FALSE
);
3682 sc_vtb_init(&scp
->scr
, VTB_FRAMEBUFFER
, 0, 0, NULL
, FALSE
);
3683 scp
->start
= scp
->xsize
* scp
->ysize
- 1;
3688 scp
->border
= SC_BORDER_COLOR
;
3689 scp
->cursor_base
= sc
->cursor_base
;
3690 scp
->cursor_height
= imin(sc
->cursor_height
, scp
->font_height
);
3691 scp
->mouse_cut_start
= scp
->xsize
* scp
->ysize
;
3692 scp
->mouse_cut_end
= -1;
3693 scp
->mouse_signal
= 0;
3695 scp
->mouse_proc
= NULL
;
3696 scp
->kbd_mode
= K_XLATE
;
3697 scp
->bell_pitch
= bios_value
.bell_pitch
;
3698 scp
->bell_duration
= BELL_DURATION
;
3699 scp
->status
|= (bios_value
.shift_state
& NLKED
);
3700 scp
->status
|= CURSOR_ENABLED
| MOUSE_HIDDEN
;
3703 scp
->smode
.mode
= VT_AUTO
;
3704 scp
->history
= NULL
;
3705 scp
->history_pos
= 0;
3706 scp
->history_size
= 0;
3710 sc_init_emulator(scr_stat
*scp
, char *name
)
3717 if (name
== NULL
) /* if no name is given, use the current emulator */
3719 else /* ...otherwise find the named emulator */
3720 sw
= sc_term_match(name
);
3726 if (strcmp(sw
->te_renderer
, "*") != 0) {
3727 rndr
= sc_render_match(scp
, sw
->te_renderer
, scp
->model
);
3729 if (rndr
== NULL
&& scp
->sc
->fbi
!= NULL
) {
3730 rndr
= sc_render_match(scp
, "kms", scp
->model
);
3733 rndr
= sc_render_match(scp
, scp
->sc
->adp
->va_name
, scp
->model
);
3739 if (sw
== scp
->tsw
) {
3740 error
= (*sw
->te_init
)(scp
, &scp
->ts
, SC_TE_WARM_INIT
);
3742 sc_clear_screen(scp
);
3743 /* assert(error == 0); */
3747 if (sc_malloc
&& (sw
->te_size
> 0))
3748 p
= kmalloc(sw
->te_size
, M_SYSCONS
, M_NOWAIT
);
3751 error
= (*sw
->te_init
)(scp
, &p
, SC_TE_COLD_INIT
);
3757 (*scp
->tsw
->te_term
)(scp
, &scp
->ts
);
3758 if (scp
->ts
!= NULL
)
3759 kfree(scp
->ts
, M_SYSCONS
);
3765 (*sw
->te_default_attr
)(scp
, user_default
.std_color
, user_default
.rev_color
);
3766 sc_clear_screen(scp
);
3772 * scgetc(flags) - get character from keyboard.
3773 * If flags & SCGETC_CN, then avoid harmful side effects.
3774 * If flags & SCGETC_NONBLOCK, then wait until a key is pressed, else
3775 * return NOKEY if there is nothing there.
3778 scgetc(sc_softc_t
*sc
, u_int flags
)
3781 #ifndef SC_NO_HISTORY
3789 lwkt_gettoken(&vga_token
);
3790 if (sc
->kbd
== NULL
) {
3791 lwkt_reltoken(&vga_token
);
3797 /* I don't like this, but... XXX */
3798 if (flags
& SCGETC_CN
) {
3800 sccnupdate(sc
->cur_scp
);
3805 /* first see if there is something in the keyboard port */
3807 c
= kbd_read_char(sc
->kbd
, !(flags
& SCGETC_NONBLOCK
));
3809 if (!(flags
& SCGETC_CN
))
3810 sc_bell(scp
, bios_value
.bell_pitch
, BELL_DURATION
);
3811 } else if (c
== NOKEY
) {
3812 lwkt_reltoken(&vga_token
);
3819 /* make screensaver happy */
3821 sc_touch_scrn_saver();
3823 if (!(flags
& SCGETC_CN
))
3824 /* do the /dev/random device a favour */
3825 add_keyboard_randomness(c
);
3827 if (scp
->kbd_mode
!= K_XLATE
) {
3828 lwkt_reltoken(&vga_token
);
3832 /* if scroll-lock pressed allow history browsing */
3833 if (!ISGRAPHSC(scp
) && scp
->history
&& scp
->status
& SLKED
) {
3835 scp
->status
&= ~CURSOR_ENABLED
;
3836 sc_remove_cursor_image(scp
);
3838 #ifndef SC_NO_HISTORY
3839 if (!(scp
->status
& BUFFER_SAVED
)) {
3840 scp
->status
|= BUFFER_SAVED
;
3844 /* FIXME: key codes */
3845 case SPCLKEY
| FKEY
| F(49): /* home key */
3846 sc_remove_cutmarking(scp
);
3850 case SPCLKEY
| FKEY
| F(57): /* end key */
3851 sc_remove_cutmarking(scp
);
3855 case SPCLKEY
| FKEY
| F(50): /* up arrow key */
3856 sc_remove_cutmarking(scp
);
3857 if (sc_hist_up_line(scp
))
3858 if (!(flags
& SCGETC_CN
))
3859 sc_bell(scp
, bios_value
.bell_pitch
, BELL_DURATION
);
3862 case SPCLKEY
| FKEY
| F(58): /* down arrow key */
3863 sc_remove_cutmarking(scp
);
3864 if (sc_hist_down_line(scp
))
3865 if (!(flags
& SCGETC_CN
))
3866 sc_bell(scp
, bios_value
.bell_pitch
, BELL_DURATION
);
3869 case SPCLKEY
| FKEY
| F(51): /* page up key */
3870 sc_remove_cutmarking(scp
);
3871 for (i
=0; i
<scp
->ysize
; i
++) {
3872 if (sc_hist_up_line(scp
)) {
3873 if (!(flags
& SCGETC_CN
))
3874 sc_bell(scp
, bios_value
.bell_pitch
, BELL_DURATION
);
3880 case SPCLKEY
| FKEY
| F(59): /* page down key */
3881 sc_remove_cutmarking(scp
);
3882 for (i
=0; i
<scp
->ysize
; i
++) {
3883 if (sc_hist_down_line(scp
)) {
3884 if (!(flags
& SCGETC_CN
))
3885 sc_bell(scp
, bios_value
.bell_pitch
, BELL_DURATION
);
3891 #endif /* SC_NO_HISTORY */
3895 * Process and consume special keys here. Return a plain char code
3896 * or a char code with the META flag or a function key code.
3900 /* goto next_code */
3905 switch (KEYCHAR(c
)) {
3907 case NLK
: case CLK
: case ALK
:
3910 kbd_ioctl(sc
->kbd
, KDGKBSTATE
, (caddr_t
)&f
);
3912 scp
->status
|= SLKED
;
3914 if (scp
->status
& SLKED
) {
3915 scp
->status
&= ~SLKED
;
3916 #ifndef SC_NO_HISTORY
3917 if (scp
->status
& BUFFER_SAVED
) {
3918 if (!sc_hist_restore(scp
))
3919 sc_remove_cutmarking(scp
);
3920 scp
->status
&= ~BUFFER_SAVED
;
3921 scp
->status
|= CURSOR_ENABLED
;
3922 sc_draw_cursor_image(scp
);
3924 tp
= VIRTUAL_TTY(sc
, scp
->index
);
3932 /* NON-LOCKING KEYS */
3934 case LSH
: case RSH
: case LCTR
: case RCTR
:
3935 case LALT
: case RALT
: case ASH
: case META
:
3939 if (!(sc
->flags
& SC_SCRN_BLANKED
)) {
3940 lwkt_reltoken(&vga_token
);
3947 /* force activatation/deactivation of the screen saver */
3948 if (!(sc
->flags
& SC_SCRN_BLANKED
)) {
3949 run_scrn_saver
= TRUE
;
3950 sc
->scrn_time_stamp
-= scrn_blank_time
;
3954 * While devices are being probed, the screen saver need
3955 * to be invoked explictly. XXX
3957 if (sc
->flags
& SC_SCRN_BLANKED
) {
3958 scsplash_stick(FALSE
);
3959 stop_scrn_saver(sc
, current_saver
);
3961 if (!ISGRAPHSC(scp
)) {
3962 scsplash_stick(TRUE
);
3963 (*current_saver
)(sc
, TRUE
);
3967 #endif /* NSPLASH */
3971 #ifndef SC_DISABLE_REBOOT
3977 #ifndef SC_DISABLE_REBOOT
3978 shutdown_nice(RB_HALT
);
3983 #ifndef SC_DISABLE_REBOOT
3984 shutdown_nice(RB_HALT
|RB_POWEROFF
);
3993 #ifndef SC_DISABLE_DDBKEY
3995 lwkt_reltoken(&vga_token
);
3996 Debugger("manual escape to debugger");
3997 lwkt_gettoken(&vga_token
);
3999 kprintf("No debugger in kernel\n");
4001 #else /* SC_DISABLE_DDBKEY */
4003 #endif /* SC_DISABLE_DDBKEY */
4007 if (enable_panic_key
)
4008 panic("Forced by the panic key");
4012 this_scr
= scp
->index
;
4013 for (i
= (this_scr
- sc
->first_vty
+ 1)%sc
->vtys
;
4014 sc
->first_vty
+ i
!= this_scr
;
4015 i
= (i
+ 1)%sc
->vtys
) {
4016 struct tty
*tp
= VIRTUAL_TTY(sc
, sc
->first_vty
+ i
);
4017 if (ISTTYOPEN(tp
)) {
4019 sc_switch_scr(scp
->sc
, sc
->first_vty
+ i
);
4027 this_scr
= scp
->index
;
4028 for (i
= (this_scr
- sc
->first_vty
+ sc
->vtys
- 1)%sc
->vtys
;
4029 sc
->first_vty
+ i
!= this_scr
;
4030 i
= (i
+ sc
->vtys
- 1)%sc
->vtys
) {
4031 struct tty
*tp
= VIRTUAL_TTY(sc
, sc
->first_vty
+ i
);
4032 if (ISTTYOPEN(tp
)) {
4034 sc_switch_scr(scp
->sc
, sc
->first_vty
+ i
);
4042 if (KEYCHAR(c
) >= F_SCR
&& KEYCHAR(c
) <= L_SCR
) {
4044 sc_switch_scr(scp
->sc
, sc
->first_vty
+ KEYCHAR(c
) - F_SCR
);
4048 /* assert(c & FKEY) */
4049 if (!(sc
->flags
& SC_SCRN_BLANKED
)) {
4050 lwkt_reltoken(&vga_token
);
4055 /* goto next_code */
4057 /* regular keys (maybe MKEY is set) */
4058 if (!(sc
->flags
& SC_SCRN_BLANKED
)) {
4059 lwkt_reltoken(&vga_token
);
4069 scmmap(struct dev_mmap_args
*ap
)
4073 lwkt_gettoken(&vga_token
);
4074 scp
= SC_STAT(ap
->a_head
.a_dev
);
4075 if (scp
!= scp
->sc
->cur_scp
) {
4076 lwkt_reltoken(&vga_token
);
4079 if (scp
->sc
->fbi
!= NULL
) {
4081 roundup(scp
->sc
->fbi
->height
* scp
->sc
->fbi
->stride
, PAGE_SIZE
);
4082 if (ap
->a_offset
> sz
- PAGE_SIZE
) {
4083 lwkt_reltoken(&vga_token
);
4086 ap
->a_result
= atop(scp
->sc
->fbi
->paddr
+ ap
->a_offset
);
4089 ap
->a_result
= (*vidsw
[scp
->sc
->adapter
]->mmap
)(scp
->sc
->adp
,
4093 lwkt_reltoken(&vga_token
);
4098 save_kbd_state(scr_stat
*scp
, int unlock
)
4103 WANT_UNLOCK(unlock
);
4104 error
= kbd_ioctl(scp
->sc
->kbd
, KDGKBSTATE
, (caddr_t
)&state
);
4107 if (error
== ENOIOCTL
)
4110 scp
->status
&= ~LOCK_MASK
;
4111 scp
->status
|= state
;
4117 update_kbd_state(scr_stat
*scp
, int new_bits
, int mask
, int unlock
)
4122 if (mask
!= LOCK_MASK
) {
4123 WANT_UNLOCK(unlock
);
4124 error
= kbd_ioctl(scp
->sc
->kbd
, KDGKBSTATE
, (caddr_t
)&state
);
4127 if (error
== ENOIOCTL
)
4133 state
|= new_bits
& mask
;
4135 state
= new_bits
& LOCK_MASK
;
4137 WANT_UNLOCK(unlock
);
4138 error
= kbd_ioctl(scp
->sc
->kbd
, KDSKBSTATE
, (caddr_t
)&state
);
4140 if (error
== ENOIOCTL
)
4146 update_kbd_leds(scr_stat
*scp
, int which
)
4151 error
= kbd_ioctl(scp
->sc
->kbd
, KDSETLED
, (caddr_t
)&which
);
4152 if (error
== ENOIOCTL
)
4158 set_mode(scr_stat
*scp
)
4162 lwkt_gettoken(&vga_token
);
4163 /* reject unsupported mode */
4164 if (scp
->sc
->fbi
== NULL
&& (*vidsw
[scp
->sc
->adapter
]->get_info
)(scp
->sc
->adp
, scp
->mode
, &info
)) {
4165 lwkt_reltoken(&vga_token
);
4169 /* if this vty is not currently showing, do nothing */
4170 if (scp
!= scp
->sc
->cur_scp
) {
4171 lwkt_reltoken(&vga_token
);
4175 /* setup video hardware for the given mode */
4176 if (scp
->sc
->fbi
== NULL
) {
4177 (*vidsw
[scp
->sc
->adapter
]->set_mode
)(scp
->sc
->adp
, scp
->mode
);
4178 sc_vtb_init(&scp
->scr
, VTB_FRAMEBUFFER
, scp
->xsize
, scp
->ysize
,
4179 (void *)scp
->sc
->adp
->va_window
, FALSE
);
4184 #ifndef SC_NO_FONT_LOADING
4185 /* load appropriate font */
4186 if (!(scp
->status
& GRAPHICS_MODE
)) {
4187 if (!(scp
->status
& PIXEL_MODE
) && ISFONTAVAIL(scp
->sc
->adp
->va_flags
)) {
4188 if (scp
->font_height
< 14) {
4189 if (scp
->sc
->fonts_loaded
& FONT_8
)
4190 sc_load_font(scp
, 0, 8, scp
->sc
->font_8
, 0, 256);
4191 } else if (scp
->font_height
>= 16) {
4192 if (scp
->sc
->fonts_loaded
& FONT_16
)
4193 sc_load_font(scp
, 0, 16, scp
->sc
->font_16
, 0, 256);
4195 if (scp
->sc
->fonts_loaded
& FONT_14
)
4196 sc_load_font(scp
, 0, 14, scp
->sc
->font_14
, 0, 256);
4200 * This is an interim kludge to display correct font.
4201 * Always use the font page #0 on the video plane 2.
4202 * Somehow we cannot show the font in other font pages on
4203 * some video cards... XXX
4205 sc_show_font(scp
, 0);
4209 #endif /* !SC_NO_FONT_LOADING */
4211 sc_set_border(scp
, scp
->border
);
4212 sc_set_cursor_image(scp
);
4215 lwkt_reltoken(&vga_token
);
4220 refresh_ega_palette(scr_stat
*scp
)
4224 int rsize
, gsize
, bsize
;
4225 int rfld
, gfld
, bfld
;
4228 rsize
= scp
->sc
->adp
->va_info
.vi_pixel_fsizes
[0];
4229 gsize
= scp
->sc
->adp
->va_info
.vi_pixel_fsizes
[1];
4230 bsize
= scp
->sc
->adp
->va_info
.vi_pixel_fsizes
[2];
4231 rfld
= scp
->sc
->adp
->va_info
.vi_pixel_fields
[0];
4232 gfld
= scp
->sc
->adp
->va_info
.vi_pixel_fields
[1];
4233 bfld
= scp
->sc
->adp
->va_info
.vi_pixel_fields
[2];
4235 for (i
= 0; i
< 16; i
++) {
4236 reg
= scp
->sc
->adp
->va_palette_regs
[i
];
4238 r
= scp
->sc
->palette
[reg
* 3] >> (8 - rsize
);
4239 g
= scp
->sc
->palette
[reg
* 3 + 1] >> (8 - gsize
);
4240 b
= scp
->sc
->palette
[reg
* 3 + 2] >> (8 - bsize
);
4242 scp
->ega_palette
[i
] = (r
<< rfld
) + (g
<< gfld
) + (b
<< bfld
);
4247 sc_set_border(scr_stat
*scp
, int color
)
4249 atomic_add_int(&scp
->sc
->videoio_in_progress
, 1);
4250 (*scp
->rndr
->draw_border
)(scp
, color
);
4251 atomic_add_int(&scp
->sc
->videoio_in_progress
, -1);
4254 #ifndef SC_NO_FONT_LOADING
4256 sc_load_font(scr_stat
*scp
, int page
, int size
, u_char
*buf
,
4257 int base
, int count
)
4262 sc
->font_loading_in_progress
= TRUE
;
4263 (*vidsw
[sc
->adapter
]->load_font
)(sc
->adp
, page
, size
, buf
, base
, count
);
4264 sc
->font_loading_in_progress
= FALSE
;
4268 sc_save_font(scr_stat
*scp
, int page
, int size
, u_char
*buf
,
4269 int base
, int count
)
4274 sc
->font_loading_in_progress
= TRUE
;
4275 (*vidsw
[sc
->adapter
]->save_font
)(sc
->adp
, page
, size
, buf
, base
, count
);
4276 sc
->font_loading_in_progress
= FALSE
;
4280 sc_show_font(scr_stat
*scp
, int page
)
4282 (*vidsw
[scp
->sc
->adapter
]->show_font
)(scp
->sc
->adp
, page
);
4284 #endif /* !SC_NO_FONT_LOADING */
4287 sc_paste(scr_stat
*scp
, u_char
*p
, int count
)
4293 * Holy hell, don't try to inject a paste buffer if the keyboard
4294 * is not in ascii mode!
4296 if (scp
->kbd_mode
!= K_XLATE
)
4299 lwkt_gettoken(&vga_token
);
4300 if (scp
->status
& MOUSE_VISIBLE
) {
4301 tp
= VIRTUAL_TTY(scp
->sc
, scp
->sc
->cur_scp
->index
);
4302 lwkt_gettoken(&tp
->t_token
);
4303 if (!ISTTYOPEN(tp
)) {
4304 lwkt_reltoken(&tp
->t_token
);
4305 lwkt_reltoken(&vga_token
);
4308 rmap
= scp
->sc
->scr_rmap
;
4309 for (; count
> 0; --count
)
4310 (*linesw
[tp
->t_line
].l_rint
)(rmap
[*p
++], tp
);
4311 lwkt_reltoken(&tp
->t_token
);
4313 lwkt_reltoken(&vga_token
);
4317 sc_bell(scr_stat
*scp
, int pitch
, int duration
)
4319 if (cold
|| shutdown_in_progress
)
4322 if (scp
!= scp
->sc
->cur_scp
&& (scp
->sc
->flags
& SC_QUIET_BELL
)) {
4326 if (scp
->sc
->flags
& SC_VISUAL_BELL
) {
4327 if (scp
->sc
->blink_in_progress
) {
4330 scp
->sc
->blink_in_progress
= 3;
4331 if (scp
!= scp
->sc
->cur_scp
)
4332 scp
->sc
->blink_in_progress
+= 2;
4333 lockmgr(&syscons_blink_lk
, LK_EXCLUSIVE
);
4334 sc_blink_screen(scp
->sc
->cur_scp
);
4335 lockmgr(&syscons_blink_lk
, LK_RELEASE
);
4336 } else if (duration
!= 0 && pitch
!= 0) {
4337 if (scp
!= scp
->sc
->cur_scp
)
4339 sysbeep(pitch
, duration
);
4344 * Blink the screen, called with the syscons_mtx and syscons_blink_lk
4345 * held. Can be called directly or via the callout.
4348 sc_blink_screen(scr_stat
*scp
)
4350 if (ISGRAPHSC(scp
) || (scp
->sc
->blink_in_progress
<= 1)) {
4351 scp
->sc
->blink_in_progress
= 0;
4353 if (scp
->sc
->delayed_next_scr
)
4354 sc_switch_scr(scp
->sc
, scp
->sc
->delayed_next_scr
- 1);
4356 (*scp
->rndr
->draw
)(scp
, 0, scp
->xsize
*scp
->ysize
,
4357 scp
->sc
->blink_in_progress
& 1);
4358 scp
->sc
->blink_in_progress
--;
4359 callout_reset(&scp
->blink_screen_ch
, hz
/ 10,
4360 blink_screen_callout
, scp
);
4365 * Screen blink callout. Note that there is a lock order
4366 * reversal between syscons_blink_lk and the syscons lock.
4367 * Acquire the syscons lock non-blocking.
4370 blink_screen_callout(void *arg
)
4372 scr_stat
*scp
= arg
;
4374 if (syscons_lock_nonblock() == 0) {
4375 sc_blink_screen(scp
);
4378 callout_reset(&scp
->blink_screen_ch
, hz
/ 10,
4379 blink_screen_callout
, scp
);
4384 * Allocate active keyboard. Try to allocate "kbdmux" keyboard first, and,
4385 * if found, add all non-busy keyboards to "kbdmux". Otherwise look for
4390 sc_allocate_keyboard(sc_softc_t
*sc
, int unit
)
4396 idx0
= kbd_allocate("kbdmux", -1, (void *)&sc
->keyboard
, sckbdevent
, sc
);
4398 k0
= kbd_get_keyboard(idx0
);
4400 for (idx
= kbd_find_keyboard2("*", -1, 0, 0);
4402 idx
= kbd_find_keyboard2("*", -1, idx
+ 1, 0)) {
4403 k
= kbd_get_keyboard(idx
);
4405 if (idx
== idx0
|| KBD_IS_BUSY(k
))
4408 bzero(&ki
, sizeof(ki
));
4409 strcpy(ki
.kb_name
, k
->kb_name
);
4410 ki
.kb_unit
= k
->kb_unit
;
4412 kbd_ioctl(k0
, KBADDKBD
, (caddr_t
) &ki
);
4415 idx0
= kbd_allocate("*", unit
, (void *)&sc
->keyboard
, sckbdevent
, sc
);