2 * Copyright (c) 1995-1998 Søren Schmidt
5 * This code is derived from software contributed to The DragonFly Project
6 * by Sascha Wildner <saw@online.de>
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer,
13 * without modification, immediately at the beginning of the file.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
17 * 3. The name of the author may not be used to endorse or promote products
18 * derived from this software without specific prior written permission.
20 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
21 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
22 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
23 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
24 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
25 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
29 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 * $FreeBSD: src/sys/dev/syscons/syscons.h,v 1.60.2.6 2002/09/15 22:30:45 dd Exp $
32 * $DragonFly: src/sys/dev/misc/syscons/syscons.h,v 1.21 2008/08/03 03:00:21 dillon Exp $
35 #ifndef _DEV_SYSCONS_SYSCONS_H_
36 #define _DEV_SYSCONS_SYSCONS_H_
38 #include <sys/malloc.h>
40 MALLOC_DECLARE(M_SYSCONS
);
42 /* default values for configuration options */
45 #define MAXCONS 16 /* power of 2 */
50 #define SC_NO_CUTPASTE 1
53 #ifdef SC_NO_MODE_CHANGE
57 /* Always load font data if the pixel (raster text) mode is to be used. */
59 #undef SC_NO_FONT_LOADING
63 * If font data is not available, the `arrow'-shaped mouse cursor cannot
64 * be drawn. Use the alternative drawing method.
66 #ifdef SC_NO_FONT_LOADING
67 #undef SC_ALT_MOUSE_IMAGE
68 #define SC_ALT_MOUSE_IMAGE 1
71 #ifndef SC_CURSOR_CHAR
72 #define SC_CURSOR_CHAR (0x07)
76 #define SC_MOUSE_CHAR (0xd0)
79 #if SC_MOUSE_CHAR <= SC_CURSOR_CHAR && SC_CURSOR_CHAR < (SC_MOUSE_CHAR + 4)
81 #define SC_CURSOR_CHAR (SC_MOUSE_CHAR + 4)
84 #ifndef SC_DEBUG_LEVEL
85 #define SC_DEBUG_LEVEL 0
88 #define DPRINTF(l, p) if (SC_DEBUG_LEVEL >= (l)) kprintf p
90 #define SC_DRIVER_NAME "sc"
91 #define SC_VTY(dev) minor(dev)
92 #define SC_DEV(sc, vty) ((sc)->dev ? (sc)->dev[(vty) - (sc)->first_vty] : NULL)
93 #define SC_STAT(dev) ((scr_stat *)(dev)->si_drv1)
97 #define PRINTABLE(ch) ((ch) > 0x1b || ((ch) > 0x0d && (ch) < 0x1b) \
101 /* macros for "intelligent" screen update */
102 #define mark_for_update(scp, x) {\
103 if ((x) < scp->start) scp->start = (x);\
104 else if ((x) > scp->end) scp->end = (x);\
106 #define mark_all(scp) {\
108 scp->end = scp->xsize * scp->ysize - 1;\
111 /* macro for calculating the drawing position in video memory */
113 #define VIDEO_MEMORY_POS(scp, pos, x) \
114 ((scp)->sc->adp->va_window + \
115 (x) * (scp)->xoff + \
116 (scp)->yoff * (scp)->font_size * (scp)->sc->adp->va_line_width +\
117 (x) * ((pos) % (scp)->xsize) + \
118 (scp)->font_size * (scp)->sc->adp->va_line_width * (pos / (scp)->xsize))
121 /* vty status flags (scp->status) */
122 #define UNKNOWN_MODE 0x00010 /* unknown video mode */
123 #define SWITCH_WAIT_REL 0x00080 /* waiting for vty release */
124 #define SWITCH_WAIT_ACQ 0x00100 /* waiting for vty ack */
125 #define BUFFER_SAVED 0x00200 /* vty buffer is saved */
126 #define CURSOR_ENABLED 0x00400 /* text cursor is enabled */
127 #define MOUSE_MOVED 0x01000 /* mouse cursor has moved */
128 #define MOUSE_CUTTING 0x02000 /* mouse cursor is cutting text */
129 #define MOUSE_VISIBLE 0x04000 /* mouse cursor is showing */
130 #define GRAPHICS_MODE 0x08000 /* vty is in a graphics mode */
131 #define PIXEL_MODE 0x10000 /* vty is in a raster text mode */
132 #define SAVER_RUNNING 0x20000 /* screen saver is running */
133 #define VR_CURSOR_BLINK 0x40000 /* blinking text cursor */
134 #define VR_CURSOR_ON 0x80000 /* text cursor is on */
135 #define MOUSE_HIDDEN 0x100000 /* mouse cursor is temporarily hidden */
144 #ifndef BELL_DURATION
145 #define BELL_DURATION ((5 * hz + 99) / 100)
146 #define BELL_PITCH 800
149 /* virtual terminal buffer */
150 typedef struct sc_vtb
{
152 #define VTB_VALID (1 << 0)
153 #define VTB_ALLOCED (1 << 1)
155 #define VTB_INVALID 0
157 #define VTB_FRAMEBUFFER 2
158 #define VTB_RINGBUFFER 3
162 uint16_t *vtb_buffer
;
163 int vtb_tail
; /* valid for VTB_RINGBUFFER only */
169 struct video_adapter
;
172 struct dev_ioctl_args
;
174 typedef struct sc_softc
{
175 int unit
; /* unit # */
176 int config
; /* configuration flags */
177 #define SC_VESA800X600 (1 << 7)
178 #define SC_AUTODETECT_KBD (1 << 8)
179 #define SC_KERNEL_CONSOLE (1 << 9)
181 int flags
; /* status flags */
182 #define SC_VISUAL_BELL (1 << 0)
183 #define SC_QUIET_BELL (1 << 1)
184 #define SC_BLINK_CURSOR (1 << 2)
185 #define SC_CHAR_CURSOR (1 << 3)
186 #define SC_MOUSE_ENABLED (1 << 4)
187 #define SC_SCRN_IDLE (1 << 5)
188 #define SC_SCRN_BLANKED (1 << 6)
189 #define SC_SAVER_FAILED (1 << 7)
190 #define SC_SCRN_VTYLOCK (1 << 8)
192 #define SC_INIT_DONE (1 << 16)
193 #define SC_SPLASH_SCRN (1 << 17)
195 int keyboard
; /* -1 if unavailable */
196 struct keyboard
*kbd
;
199 struct video_adapter
*adp
;
200 int initial_mode
; /* initial video mode */
205 struct scr_stat
*console_scp
;
206 struct scr_stat
*cur_scp
;
207 struct scr_stat
*new_scp
;
208 struct scr_stat
*old_scp
;
209 int delayed_next_scr
;
211 char font_loading_in_progress
;
212 char switch_in_progress
;
213 char videoio_in_progress
;
214 char write_in_progress
;
215 char blink_in_progress
;
217 long scrn_time_stamp
;
218 struct callout scrn_timer_ch
;
224 u_char scr_rmap
[256];
226 #ifdef _SC_MD_SOFTC_DECLARED_
227 sc_md_softc_t md
; /* machine dependent vars */
230 #ifndef SC_NO_PALETTE_LOADING
231 u_char palette
[256*3];
234 #ifndef SC_NO_FONT_LOADING
250 typedef struct scr_stat
{
251 int index
; /* index of this vty */
252 struct sc_softc
*sc
; /* pointer to softc */
253 struct sc_rndr_sw
*rndr
; /* renderer */
257 int xpos
; /* current X position */
258 int ypos
; /* current Y position */
259 int xsize
; /* X text size */
260 int ysize
; /* Y text size */
261 int xpixel
; /* X graphics size */
262 int ypixel
; /* Y graphics size */
263 int xoff
; /* X offset in pixel mode */
264 int yoff
; /* Y offset in pixel mode */
266 u_char
*font
; /* current font */
267 int font_size
; /* fontsize in Y direction */
269 int start
; /* modified area start */
270 int end
; /* modified area end */
272 struct sc_term_sw
*tsw
;
275 int status
; /* status (bitfield) */
276 int kbd_mode
; /* keyboard I/O mode */
278 int cursor_pos
; /* cursor buffer position */
279 int cursor_oldpos
; /* cursor old buffer position */
280 u_short cursor_saveunder_char
; /* saved char under cursor */
281 u_short cursor_saveunder_attr
; /* saved attr under cursor */
282 char cursor_base
; /* cursor base line # */
283 char cursor_height
; /* cursor height */
285 int mouse_pos
; /* mouse buffer position */
286 int mouse_oldpos
; /* mouse old buffer position */
287 short mouse_xpos
; /* mouse x coordinate */
288 short mouse_ypos
; /* mouse y coordinate */
289 short mouse_oldxpos
; /* mouse previous x coordinate */
290 short mouse_oldypos
; /* mouse previous y coordinate */
291 short mouse_buttons
; /* mouse buttons */
292 int mouse_cut_start
; /* mouse cut start pos */
293 int mouse_cut_end
; /* mouse cut end pos */
294 struct proc
*mouse_proc
; /* proc* of controlling proc */
295 pid_t mouse_pid
; /* pid of controlling proc */
296 int mouse_signal
; /* signal # to report with */
298 u_short bell_duration
;
301 struct callout blink_screen_ch
;
303 uint32_t ega_palette
[16]; /* ega palette */
304 u_char border
; /* border color */
306 pid_t pid
; /* pid of controlling proc */
307 struct proc
*proc
; /* proc* of controlling proc */
308 struct vt_mode smode
; /* switch mode */
310 sc_vtb_t
*history
; /* circular history buffer */
311 int history_pos
; /* position shown on screen */
312 int history_size
; /* size of history buffer */
314 int splash_save_mode
; /* saved mode for splash screen */
315 int splash_save_status
; /* saved status for splash screen */
316 #ifdef _SCR_MD_STAT_DECLARED_
317 scr_md_stat_t md
; /* machine dependent vars */
322 #define SC_NORM_ATTR (FG_LIGHTGREY | BG_BLACK)
324 #ifndef SC_NORM_REV_ATTR
325 #define SC_NORM_REV_ATTR (FG_BLACK | BG_LIGHTGREY)
327 #ifndef SC_KERNEL_CONS_ATTR
328 #define SC_KERNEL_CONS_ATTR (FG_WHITE | BG_BLACK)
330 #ifndef SC_KERNEL_CONS_REV_ATTR
331 #define SC_KERNEL_CONS_REV_ATTR (FG_BLACK | BG_LIGHTGREY)
334 /* terminal emulator */
337 #define SC_DFLT_TERM "*" /* any */
340 typedef int sc_term_init_t(scr_stat
*scp
, void **tcp
, int code
);
341 #define SC_TE_COLD_INIT 0
342 #define SC_TE_WARM_INIT 1
343 typedef int sc_term_term_t(scr_stat
*scp
, void **tcp
);
344 typedef void sc_term_puts_t(scr_stat
*scp
, u_char
*buf
, int len
);
345 typedef int sc_term_ioctl_t(scr_stat
*scp
, struct tty
*tp
, u_long cmd
,
346 caddr_t data
, int flag
);
347 typedef int sc_term_reset_t(scr_stat
*scp
, int code
);
348 #define SC_TE_HARD_RESET 0
349 #define SC_TE_SOFT_RESET 1
350 typedef void sc_term_default_attr_t(scr_stat
*scp
, int norm
, int rev
);
351 typedef void sc_term_clear_t(scr_stat
*scp
);
352 typedef void sc_term_notify_t(scr_stat
*scp
, int event
);
353 #define SC_TE_NOTIFY_VTSWITCH_IN 0
354 #define SC_TE_NOTIFY_VTSWITCH_OUT 1
355 typedef int sc_term_input_t(scr_stat
*scp
, int c
, struct tty
*tp
);
357 typedef struct sc_term_sw
{
358 LIST_ENTRY(sc_term_sw
) link
;
359 char *te_name
; /* name of the emulator */
360 char *te_desc
; /* description */
361 char *te_renderer
; /* matching renderer */
362 size_t te_size
; /* size of internal buffer */
363 int te_refcount
; /* reference counter */
364 sc_term_init_t
*te_init
;
365 sc_term_term_t
*te_term
;
366 sc_term_puts_t
*te_puts
;
367 sc_term_ioctl_t
*te_ioctl
;
368 sc_term_reset_t
*te_reset
;
369 sc_term_default_attr_t
*te_default_attr
;
370 sc_term_clear_t
*te_clear
;
371 sc_term_notify_t
*te_notify
;
372 sc_term_input_t
*te_input
;
375 extern struct linker_set scterm_set
;
377 #define SCTERM_MODULE(name, sw) \
378 DATA_SET(scterm_set, sw); \
380 scterm_##name##_event(module_t mod, int type, void *data) \
384 return sc_term_add(&sw); \
386 if (sw.te_refcount > 0) \
388 return sc_term_remove(&sw); \
394 static moduledata_t scterm_##name##_mod = { \
396 scterm_##name##_event, \
399 DECLARE_MODULE(scterm_##name, scterm_##name##_mod, \
400 SI_SUB_DRIVERS, SI_ORDER_MIDDLE)
402 /* renderer function table */
403 typedef void vr_init_t(scr_stat
*scp
);
404 typedef void vr_draw_border_t(scr_stat
*scp
, int color
);
405 typedef void vr_draw_t(scr_stat
*scp
, int from
, int count
, int flip
);
406 typedef void vr_set_cursor_t(scr_stat
*scp
, int base
, int height
, int blink
);
407 typedef void vr_draw_cursor_t(scr_stat
*scp
, int at
, int blink
,
409 typedef void vr_blink_cursor_t(scr_stat
*scp
, int at
, int flip
);
410 typedef void vr_set_mouse_t(scr_stat
*scp
);
411 typedef void vr_draw_mouse_t(scr_stat
*scp
, int x
, int y
, int on
);
413 typedef struct sc_rndr_sw
{
415 vr_draw_border_t
*draw_border
;
417 vr_set_cursor_t
*set_cursor
;
418 vr_draw_cursor_t
*draw_cursor
;
419 vr_blink_cursor_t
*blink_cursor
;
420 vr_set_mouse_t
*set_mouse
;
421 vr_draw_mouse_t
*draw_mouse
;
424 typedef struct sc_renderer
{
427 sc_rndr_sw_t
*rndrsw
;
428 LIST_ENTRY(sc_renderer
) link
;
431 extern struct linker_set scrndr_set
;
433 #define RENDERER(name, mode, sw, set) \
434 static struct sc_renderer scrndr_##name##_##mode = { \
437 DATA_SET(scrndr_set, scrndr_##name##_##mode); \
438 DATA_SET(set, scrndr_##name##_##mode)
440 #define RENDERER_MODULE(name, set) \
441 SET_DECLARE(set, sc_renderer_t); \
443 scrndr_##name##_event(module_t mod, int type, void *data) \
445 sc_renderer_t **list; \
449 SET_FOREACH(list, set) { \
450 error = sc_render_add(*list); \
456 SET_FOREACH(list, set) { \
457 error = sc_render_remove(*list); \
467 static moduledata_t scrndr_##name##_mod = { \
469 scrndr_##name##_event, \
472 DECLARE_MODULE(scrndr_##name, scrndr_##name##_mod, \
473 SI_SUB_DRIVERS, SI_ORDER_MIDDLE)
483 #define ISTEXTSC(scp) (!((scp)->status \
484 & (UNKNOWN_MODE | GRAPHICS_MODE | PIXEL_MODE)))
485 #define ISGRAPHSC(scp) (((scp)->status \
486 & (UNKNOWN_MODE | GRAPHICS_MODE)))
487 #define ISPIXELSC(scp) (((scp)->status \
488 & (UNKNOWN_MODE | GRAPHICS_MODE | PIXEL_MODE))\
490 #define ISUNKNOWNSC(scp) ((scp)->status & UNKNOWN_MODE)
492 #define ISMOUSEAVAIL(af) ((af) & V_ADP_FONT)
493 #define ISFONTAVAIL(af) ((af) & V_ADP_FONT)
494 #define ISPALAVAIL(af) ((af) & V_ADP_PALETTE)
496 #define ISSIGVALID(sig) ((sig) > 0 && (sig) < NSIG)
499 int sc_probe_unit(int unit
, int flags
);
500 int sc_attach_unit(int unit
, int flags
);
502 int set_mode(scr_stat
*scp
);
503 void refresh_ega_palette(scr_stat
*scp
);
505 void sc_set_border(scr_stat
*scp
, int color
);
506 void sc_load_font(scr_stat
*scp
, int page
, int size
, u_char
*font
,
507 int base
, int count
);
508 void sc_save_font(scr_stat
*scp
, int page
, int size
, u_char
*font
,
509 int base
, int count
);
510 void sc_show_font(scr_stat
*scp
, int page
);
512 void sc_touch_scrn_saver(void);
513 void sc_puts(scr_stat
*scp
, u_char
*buf
, int len
);
514 void sc_draw_cursor_image(scr_stat
*scp
);
515 void sc_remove_cursor_image(scr_stat
*scp
);
516 void sc_set_cursor_image(scr_stat
*scp
);
517 int sc_clean_up(scr_stat
*scp
);
518 int sc_switch_scr(sc_softc_t
*sc
, u_int next_scr
);
519 void sc_alloc_scr_buffer(scr_stat
*scp
, int wait
, int discard
);
520 int sc_init_emulator(scr_stat
*scp
, char *name
);
521 void sc_paste(scr_stat
*scp
, u_char
*p
, int count
);
522 void sc_bell(scr_stat
*scp
, int pitch
, int duration
);
525 #ifndef SC_NO_HISTORY
526 int sc_alloc_history_buffer(scr_stat
*scp
, int lines
,
527 int prev_ysize
, int wait
);
528 void sc_free_history_buffer(scr_stat
*scp
, int prev_ysize
);
529 void sc_hist_save(scr_stat
*scp
);
530 #define sc_hist_save_one_line(scp, from) \
531 sc_vtb_append(&(scp)->vtb, (from), (scp)->history, (scp)->xsize)
532 int sc_hist_restore(scr_stat
*scp
);
533 void sc_hist_home(scr_stat
*scp
);
534 void sc_hist_end(scr_stat
*scp
);
535 int sc_hist_up_line(scr_stat
*scp
);
536 int sc_hist_down_line(scr_stat
*scp
);
537 int sc_hist_ioctl(struct tty
*tp
, u_long cmd
, caddr_t data
,
539 #endif /* SC_NO_HISTORY */
542 #ifndef SC_NO_CUTPASTE
543 void sc_alloc_cut_buffer(scr_stat
*scp
, int wait
);
544 void sc_draw_mouse_image(scr_stat
*scp
);
545 void sc_remove_mouse_image(scr_stat
*scp
);
546 int sc_inside_cutmark(scr_stat
*scp
, int pos
);
547 void sc_remove_cutmarking(scr_stat
*scp
);
548 void sc_remove_all_cutmarkings(sc_softc_t
*scp
);
549 void sc_remove_all_mouse(sc_softc_t
*scp
);
551 #define sc_draw_mouse_image(scp)
552 #define sc_remove_mouse_image(scp)
553 #define sc_inside_cutmark(scp, pos) FALSE
554 #define sc_remove_cutmarking(scp)
555 #define sc_remove_all_cutmarkings(scp)
556 #define sc_remove_all_mouse(scp)
557 #endif /* SC_NO_CUTPASTE */
558 #ifndef SC_NO_SYSMOUSE
559 void sc_mouse_move(scr_stat
*scp
, int x
, int y
);
560 int sc_mouse_ioctl(struct tty
*tp
, u_long cmd
, caddr_t data
,
562 #endif /* SC_NO_SYSMOUSE */
565 int sc_set_text_mode(scr_stat
*scp
, struct tty
*tp
, int mode
,
566 int xsize
, int ysize
, int fontsize
);
567 int sc_set_graphics_mode(scr_stat
*scp
, struct tty
*tp
, int mode
);
568 int sc_set_pixel_mode(scr_stat
*scp
, struct tty
*tp
,
569 int xsize
, int ysize
, int fontsize
);
570 int sc_vid_ioctl(struct tty
*tp
, u_long cmd
, caddr_t data
,
573 int sc_render_add(sc_renderer_t
*rndr
);
574 int sc_render_remove(sc_renderer_t
*rndr
);
575 sc_rndr_sw_t
*sc_render_match(scr_stat
*scp
, char *name
, int mode
);
578 void sc_vtb_init(sc_vtb_t
*vtb
, int type
, int cols
, int rows
,
579 void *buffer
, int wait
);
580 void sc_vtb_destroy(sc_vtb_t
*vtb
);
581 size_t sc_vtb_size(int cols
, int rows
);
582 void sc_vtb_clear(sc_vtb_t
*vtb
, int c
, int attr
);
584 int sc_vtb_getc(sc_vtb_t
*vtb
, int at
);
585 int sc_vtb_geta(sc_vtb_t
*vtb
, int at
);
586 void sc_vtb_putc(sc_vtb_t
*vtb
, int at
, int c
, int a
);
587 uint16_t *sc_vtb_putchar(sc_vtb_t
*vtb
, uint16_t *p
, int c
, int a
);
588 int sc_vtb_pos(sc_vtb_t
*vtb
, int pos
, int offset
);
590 #define sc_vtb_tail(vtb) ((vtb)->vtb_tail)
591 #define sc_vtb_rows(vtb) ((vtb)->vtb_rows)
592 #define sc_vtb_cols(vtb) ((vtb)->vtb_cols)
594 void sc_vtb_copy(sc_vtb_t
*vtb1
, int from
, sc_vtb_t
*vtb2
, int to
,
596 void sc_vtb_append(sc_vtb_t
*vtb1
, int from
, sc_vtb_t
*vtb2
,
598 void sc_vtb_seek(sc_vtb_t
*vtb
, int pos
);
599 void sc_vtb_erase(sc_vtb_t
*vtb
, int at
, int count
, int c
, int attr
);
600 void sc_vtb_move(sc_vtb_t
*vtb
, int from
, int to
, int count
);
601 void sc_vtb_delete(sc_vtb_t
*vtb
, int at
, int count
, int c
, int attr
);
602 void sc_vtb_ins(sc_vtb_t
*vtb
, int at
, int count
, int c
, int attr
);
605 int sysmouse_event(mouse_info_t
*info
);
608 void sc_move_cursor(scr_stat
*scp
, int x
, int y
);
609 void sc_clear_screen(scr_stat
*scp
);
610 int sc_term_add(sc_term_sw_t
*sw
);
611 int sc_term_remove(sc_term_sw_t
*sw
);
612 sc_term_sw_t
*sc_term_match(char *name
);
613 sc_term_sw_t
*sc_term_match_by_number(int index
);
615 /* machine dependent functions */
616 int sc_max_unit(void);
617 sc_softc_t
*sc_get_softc(int unit
, int flags
);
618 sc_softc_t
*sc_find_softc(struct video_adapter
*adp
, struct keyboard
*kbd
);
619 int sc_get_cons_priority(int *unit
, int *flags
);
620 void sc_get_bios_values(bios_values_t
*values
);
621 int sc_tone(int hertz
);
623 #endif /* !_DEV_SYSCONS_SYSCONS_H_ */