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.
34 #ifndef _DEV_SYSCONS_SYSCONS_H_
35 #define _DEV_SYSCONS_SYSCONS_H_
38 #include <sys/mutex.h>
40 /* machine-dependent part of the header */
43 #include <pc98/cbus/sc_machdep.h>
44 #elif defined(__i386__)
45 /* nothing for the moment */
48 /* default values for configuration options */
56 #define SC_NO_CUTPASTE 1
59 #ifdef SC_NO_MODE_CHANGE
63 /* Always load font data if the pixel (raster text) mode is to be used. */
65 #undef SC_NO_FONT_LOADING
69 * If font data is not available, the `arrow'-shaped mouse cursor cannot
70 * be drawn. Use the alternative drawing method.
72 #ifdef SC_NO_FONT_LOADING
73 #undef SC_ALT_MOUSE_IMAGE
74 #define SC_ALT_MOUSE_IMAGE 1
77 #ifndef SC_CURSOR_CHAR
78 #define SC_CURSOR_CHAR (0x07)
82 #define SC_MOUSE_CHAR (0xd0)
85 #if SC_MOUSE_CHAR <= SC_CURSOR_CHAR && SC_CURSOR_CHAR < (SC_MOUSE_CHAR + 4)
87 #define SC_CURSOR_CHAR (SC_MOUSE_CHAR + 4)
90 #ifndef SC_DEBUG_LEVEL
91 #define SC_DEBUG_LEVEL 0
94 #define DPRINTF(l, p) if (SC_DEBUG_LEVEL >= (l)) printf p
97 #define SC_DRIVER_NAME "sc"
100 * Use a different driver name on sparc64 so it does not get confused
101 * with the system controller devices which are also termed 'sc' in OFW.
103 #define SC_DRIVER_NAME "syscons"
105 #define SC_VTY(dev) (((sc_ttysoftc *)tty_softc(tp))->st_index)
106 #define SC_DEV(sc, vty) ((sc)->dev[(vty) - (sc)->first_vty])
107 #define SC_STAT(tp) (*((scr_stat **)&((sc_ttysoftc *)tty_softc(tp))->st_stat))
109 /* printable chars */
111 #define PRINTABLE(ch) ((ch) > 0x1b || ((ch) > 0x0d && (ch) < 0x1b) \
115 /* macros for "intelligent" screen update */
116 #define mark_for_update(scp, x) {\
117 if ((x) < scp->start) scp->start = (x);\
118 else if ((x) > scp->end) scp->end = (x);\
120 #define mark_all(scp) {\
122 scp->end = scp->xsize * scp->ysize - 1;\
125 /* vty status flags (scp->status) */
126 #define UNKNOWN_MODE 0x00010 /* unknown video mode */
127 #define SWITCH_WAIT_REL 0x00080 /* waiting for vty release */
128 #define SWITCH_WAIT_ACQ 0x00100 /* waiting for vty ack */
129 #define BUFFER_SAVED 0x00200 /* vty buffer is saved */
130 #define CURSOR_ENABLED 0x00400 /* text cursor is enabled */
131 #define MOUSE_MOVED 0x01000 /* mouse cursor has moved */
132 #define MOUSE_CUTTING 0x02000 /* mouse cursor is cutting text */
133 #define MOUSE_VISIBLE 0x04000 /* mouse cursor is showing */
134 #define GRAPHICS_MODE 0x08000 /* vty is in a graphics mode */
135 #define PIXEL_MODE 0x10000 /* vty is in a raster text mode */
136 #define SAVER_RUNNING 0x20000 /* screen saver is running */
137 #define VR_CURSOR_BLINK 0x40000 /* blinking text cursor */
138 #define VR_CURSOR_ON 0x80000 /* text cursor is on */
139 #define MOUSE_HIDDEN 0x100000 /* mouse cursor is temporarily hidden */
146 The following #defines are hard-coded for a maximum text
147 resolution corresponding to a maximum framebuffer
148 resolution of 1600x1200 with an 8x8 font...
155 #ifndef BELL_DURATION
156 #define BELL_DURATION ((5 * hz + 99) / 100)
157 #define BELL_PITCH 800
160 /* virtual terminal buffer */
161 typedef struct sc_vtb {
163 #define VTB_VALID (1 << 0)
164 #define VTB_ALLOCED (1 << 1)
166 #define VTB_INVALID 0
168 #define VTB_FRAMEBUFFER 2
169 #define VTB_RINGBUFFER 3
173 vm_offset_t vtb_buffer;
174 int vtb_tail; /* valid for VTB_RINGBUFFER only */
177 /* text cursor attributes */
187 struct video_adapter;
191 typedef struct sc_softc {
192 int unit; /* unit # */
193 int config; /* configuration flags */
194 #define SC_VESA800X600 (1 << 7)
195 #define SC_AUTODETECT_KBD (1 << 8)
196 #define SC_KERNEL_CONSOLE (1 << 9)
198 int flags; /* status flags */
199 #define SC_VISUAL_BELL (1 << 0)
200 #define SC_QUIET_BELL (1 << 1)
201 #if 0 /* not used anymore */
202 #define SC_BLINK_CURSOR (1 << 2)
203 #define SC_CHAR_CURSOR (1 << 3)
205 #define SC_MOUSE_ENABLED (1 << 4)
206 #define SC_SCRN_IDLE (1 << 5)
207 #define SC_SCRN_BLANKED (1 << 6)
208 #define SC_SAVER_FAILED (1 << 7)
209 #define SC_SCRN_VTYLOCK (1 << 8)
211 #define SC_INIT_DONE (1 << 16)
212 #define SC_SPLASH_SCRN (1 << 17)
214 int keyboard; /* -1 if unavailable */
215 struct keyboard *kbd;
218 struct video_adapter *adp;
219 int initial_mode; /* initial video mode */
224 struct scr_stat *cur_scp;
225 struct scr_stat *new_scp;
226 struct scr_stat *old_scp;
227 int delayed_next_scr;
229 char font_loading_in_progress;
230 char switch_in_progress;
231 char write_in_progress;
232 char blink_in_progress;
233 struct mtx video_mtx;
235 long scrn_time_stamp;
237 struct cursor_attr dflt_curs_attr;
238 struct cursor_attr curs_attr;
241 u_char scr_rmap[256];
243 #ifdef _SC_MD_SOFTC_DECLARED_
244 sc_md_softc_t md; /* machine dependent vars */
247 #ifndef SC_NO_PALETTE_LOADING
248 u_char palette[256*3];
251 #ifndef SC_NO_FONT_LOADING
269 typedef struct scr_stat {
270 int index; /* index of this vty */
271 struct sc_softc *sc; /* pointer to softc */
272 struct sc_rndr_sw *rndr; /* renderer */
278 int xpos; /* current X position */
279 int ypos; /* current Y position */
280 int xsize; /* X text size */
281 int ysize; /* Y text size */
282 int xpixel; /* X graphics size */
283 int ypixel; /* Y graphics size */
284 int xoff; /* X offset in pixel mode */
285 int yoff; /* Y offset in pixel mode */
287 u_char *font; /* current font */
288 int font_size; /* fontsize in Y direction */
289 int font_width; /* fontsize in X direction */
291 int start; /* modified area start */
292 int end; /* modified area end */
294 struct sc_term_sw *tsw;
297 int status; /* status (bitfield) */
298 int kbd_mode; /* keyboard I/O mode */
300 int cursor_pos; /* cursor buffer position */
301 int cursor_oldpos; /* cursor old buffer position */
302 u_short cursor_saveunder_char; /* saved char under cursor */
303 u_short cursor_saveunder_attr; /* saved attr under cursor */
304 struct cursor_attr dflt_curs_attr;
305 struct cursor_attr curr_curs_attr;
306 struct cursor_attr curs_attr;
308 int mouse_pos; /* mouse buffer position */
309 int mouse_oldpos; /* mouse old buffer position */
310 short mouse_xpos; /* mouse x coordinate */
311 short mouse_ypos; /* mouse y coordinate */
312 short mouse_oldxpos; /* mouse previous x coordinate */
313 short mouse_oldypos; /* mouse previous y coordinate */
314 short mouse_buttons; /* mouse buttons */
315 int mouse_cut_start; /* mouse cut start pos */
316 int mouse_cut_end; /* mouse cut end pos */
317 struct proc *mouse_proc; /* proc* of controlling proc */
318 pid_t mouse_pid; /* pid of controlling proc */
319 int mouse_signal; /* signal # to report with */
321 u_short bell_duration;
324 u_char border; /* border color */
326 pid_t pid; /* pid of controlling proc */
327 struct proc *proc; /* proc* of controlling proc */
328 struct vt_mode smode; /* switch mode */
330 sc_vtb_t *history; /* circular history buffer */
331 int history_pos; /* position shown on screen */
332 int history_size; /* size of history buffer */
334 int splash_save_mode; /* saved mode for splash screen */
335 int splash_save_status; /* saved status for splash screen */
336 struct mtx scr_lock; /* mutex for sc_puts() */
337 #ifdef _SCR_MD_STAT_DECLARED_
338 scr_md_stat_t md; /* machine dependent vars */
343 typedef struct sc_ttysoftc {
349 #define SC_NORM_ATTR (FG_LIGHTGREY | BG_BLACK)
351 #ifndef SC_NORM_REV_ATTR
352 #define SC_NORM_REV_ATTR (FG_BLACK | BG_LIGHTGREY)
354 #ifndef SC_KERNEL_CONS_ATTR
355 #define SC_KERNEL_CONS_ATTR (FG_WHITE | BG_BLACK)
357 #ifndef SC_KERNEL_CONS_REV_ATTR
358 #define SC_KERNEL_CONS_REV_ATTR (FG_BLACK | BG_LIGHTGREY)
361 /* terminal emulator */
364 #define SC_DFLT_TERM "*" /* any */
367 typedef int sc_term_init_t(scr_stat *scp, void **tcp, int code);
368 #define SC_TE_COLD_INIT 0
369 #define SC_TE_WARM_INIT 1
370 typedef int sc_term_term_t(scr_stat *scp, void **tcp);
371 typedef void sc_term_puts_t(scr_stat *scp, u_char *buf, int len, int kernel);
372 typedef int sc_term_ioctl_t(scr_stat *scp, struct tty *tp, u_long cmd,
373 caddr_t data, struct thread *td);
374 typedef int sc_term_reset_t(scr_stat *scp, int code);
375 #define SC_TE_HARD_RESET 0
376 #define SC_TE_SOFT_RESET 1
377 typedef void sc_term_default_attr_t(scr_stat *scp, int norm, int rev);
378 typedef void sc_term_clear_t(scr_stat *scp);
379 typedef void sc_term_notify_t(scr_stat *scp, int event);
380 #define SC_TE_NOTIFY_VTSWITCH_IN 0
381 #define SC_TE_NOTIFY_VTSWITCH_OUT 1
382 typedef int sc_term_input_t(scr_stat *scp, int c, struct tty *tp);
384 typedef struct sc_term_sw {
385 LIST_ENTRY(sc_term_sw) link;
386 char *te_name; /* name of the emulator */
387 char *te_desc; /* description */
388 char *te_renderer; /* matching renderer */
389 size_t te_size; /* size of internal buffer */
390 int te_refcount; /* reference counter */
391 sc_term_init_t *te_init;
392 sc_term_term_t *te_term;
393 sc_term_puts_t *te_puts;
394 sc_term_ioctl_t *te_ioctl;
395 sc_term_reset_t *te_reset;
396 sc_term_default_attr_t *te_default_attr;
397 sc_term_clear_t *te_clear;
398 sc_term_notify_t *te_notify;
399 sc_term_input_t *te_input;
402 #define SCTERM_MODULE(name, sw) \
403 DATA_SET(scterm_set, sw); \
405 scterm_##name##_event(module_t mod, int type, void *data) \
409 return sc_term_add(&sw); \
411 if (sw.te_refcount > 0) \
413 return sc_term_remove(&sw); \
420 static moduledata_t scterm_##name##_mod = { \
422 scterm_##name##_event, \
425 DECLARE_MODULE(scterm_##name, scterm_##name##_mod, \
426 SI_SUB_DRIVERS, SI_ORDER_MIDDLE)
428 /* renderer function table */
429 typedef void vr_init_t(scr_stat *scp);
430 typedef void vr_clear_t(scr_stat *scp, int c, int attr);
431 typedef void vr_draw_border_t(scr_stat *scp, int color);
432 typedef void vr_draw_t(scr_stat *scp, int from, int count, int flip);
433 typedef void vr_set_cursor_t(scr_stat *scp, int base, int height, int blink);
434 typedef void vr_draw_cursor_t(scr_stat *scp, int at, int blink,
436 typedef void vr_blink_cursor_t(scr_stat *scp, int at, int flip);
437 typedef void vr_set_mouse_t(scr_stat *scp);
438 typedef void vr_draw_mouse_t(scr_stat *scp, int x, int y, int on);
440 typedef struct sc_rndr_sw {
443 vr_draw_border_t *draw_border;
445 vr_set_cursor_t *set_cursor;
446 vr_draw_cursor_t *draw_cursor;
447 vr_blink_cursor_t *blink_cursor;
448 vr_set_mouse_t *set_mouse;
449 vr_draw_mouse_t *draw_mouse;
452 typedef struct sc_renderer {
455 sc_rndr_sw_t *rndrsw;
456 LIST_ENTRY(sc_renderer) link;
459 #define RENDERER(name, mode, sw, set) \
460 static struct sc_renderer scrndr_##name##_##mode = { \
463 DATA_SET(scrndr_set, scrndr_##name##_##mode); \
464 DATA_SET(set, scrndr_##name##_##mode)
466 #define RENDERER_MODULE(name, set) \
467 SET_DECLARE(set, sc_renderer_t); \
469 scrndr_##name##_event(module_t mod, int type, void *data) \
471 sc_renderer_t **list; \
475 SET_FOREACH(list, set) { \
476 error = sc_render_add(*list); \
482 SET_FOREACH(list, set) { \
483 error = sc_render_remove(*list);\
494 static moduledata_t scrndr_##name##_mod = { \
496 scrndr_##name##_event, \
499 DECLARE_MODULE(scrndr_##name, scrndr_##name##_mod, \
500 SI_SUB_DRIVERS, SI_ORDER_MIDDLE)
510 #define ISTEXTSC(scp) (!((scp)->status \
511 & (UNKNOWN_MODE | GRAPHICS_MODE | PIXEL_MODE)))
512 #define ISGRAPHSC(scp) (((scp)->status \
513 & (UNKNOWN_MODE | GRAPHICS_MODE)))
514 #define ISPIXELSC(scp) (((scp)->status \
515 & (UNKNOWN_MODE | GRAPHICS_MODE | PIXEL_MODE))\
517 #define ISUNKNOWNSC(scp) ((scp)->status & UNKNOWN_MODE)
519 #define ISMOUSEAVAIL(af) ((af) & V_ADP_FONT)
520 #define ISFONTAVAIL(af) ((af) & V_ADP_FONT)
521 #define ISPALAVAIL(af) ((af) & V_ADP_PALETTE)
523 #define ISSIGVALID(sig) ((sig) > 0 && (sig) < NSIG)
525 #define SC_VIDEO_LOCKINIT(sc) \
526 mtx_init(&(sc)->video_mtx, "syscons video lock", NULL, \
527 MTX_SPIN | MTX_RECURSE);
528 #define SC_VIDEO_LOCK(sc) \
531 mtx_lock_spin(&(sc)->video_mtx); \
533 #define SC_VIDEO_UNLOCK(sc) \
536 mtx_unlock_spin(&(sc)->video_mtx); \
540 extern int (*sc_user_ioctl)(struct tty *tp, u_long cmd, caddr_t data,
543 int sc_probe_unit(int unit, int flags);
544 int sc_attach_unit(int unit, int flags);
546 int set_mode(scr_stat *scp);
548 void sc_set_border(scr_stat *scp, int color);
549 void sc_load_font(scr_stat *scp, int page, int size, int width,
550 u_char *font, int base, int count);
551 void sc_save_font(scr_stat *scp, int page, int size, int width,
552 u_char *font, int base, int count);
553 void sc_show_font(scr_stat *scp, int page);
555 void sc_touch_scrn_saver(void);
556 void sc_puts(scr_stat *scp, u_char *buf, int len, int kernel);
557 void sc_draw_cursor_image(scr_stat *scp);
558 void sc_remove_cursor_image(scr_stat *scp);
559 void sc_set_cursor_image(scr_stat *scp);
560 void sc_change_cursor_shape(scr_stat *scp, int flags,
561 int base, int height);
562 int sc_clean_up(scr_stat *scp);
563 int sc_switch_scr(sc_softc_t *sc, u_int next_scr);
564 void sc_alloc_scr_buffer(scr_stat *scp, int wait, int discard);
565 int sc_init_emulator(scr_stat *scp, char *name);
566 void sc_paste(scr_stat *scp, const u_char *p, int count);
567 void sc_respond(scr_stat *scp, const u_char *p, int count);
568 void sc_bell(scr_stat *scp, int pitch, int duration);
571 #ifndef SC_NO_HISTORY
572 int sc_alloc_history_buffer(scr_stat *scp, int lines,
573 int prev_ysize, int wait);
574 void sc_free_history_buffer(scr_stat *scp, int prev_ysize);
575 void sc_hist_save(scr_stat *scp);
576 #define sc_hist_save_one_line(scp, from) \
577 sc_vtb_append(&(scp)->vtb, (from), (scp)->history, (scp)->xsize)
578 int sc_hist_restore(scr_stat *scp);
579 void sc_hist_home(scr_stat *scp);
580 void sc_hist_end(scr_stat *scp);
581 int sc_hist_up_line(scr_stat *scp);
582 int sc_hist_down_line(scr_stat *scp);
583 int sc_hist_ioctl(struct tty *tp, u_long cmd, caddr_t data,
585 #endif /* SC_NO_HISTORY */
588 #ifndef SC_NO_CUTPASTE
589 void sc_alloc_cut_buffer(scr_stat *scp, int wait);
590 void sc_draw_mouse_image(scr_stat *scp);
591 void sc_remove_mouse_image(scr_stat *scp);
592 int sc_inside_cutmark(scr_stat *scp, int pos);
593 void sc_remove_cutmarking(scr_stat *scp);
594 void sc_remove_all_cutmarkings(sc_softc_t *scp);
595 void sc_remove_all_mouse(sc_softc_t *scp);
596 void sc_mouse_paste(scr_stat *scp);
598 #define sc_draw_mouse_image(scp)
599 #define sc_remove_mouse_image(scp)
600 #define sc_inside_cutmark(scp, pos) FALSE
601 #define sc_remove_cutmarking(scp)
602 #define sc_remove_all_cutmarkings(scp)
603 #define sc_remove_all_mouse(scp)
604 #define sc_mouse_paste(scp)
605 #endif /* SC_NO_CUTPASTE */
606 #ifndef SC_NO_SYSMOUSE
607 void sc_mouse_move(scr_stat *scp, int x, int y);
608 int sc_mouse_ioctl(struct tty *tp, u_long cmd, caddr_t data,
610 #endif /* SC_NO_SYSMOUSE */
613 int sc_set_text_mode(scr_stat *scp, struct tty *tp, int mode,
614 int xsize, int ysize, int fontsize,
616 int sc_set_graphics_mode(scr_stat *scp, struct tty *tp, int mode);
617 int sc_set_pixel_mode(scr_stat *scp, struct tty *tp, int xsize,
618 int ysize, int fontsize, int font_width);
619 int sc_vid_ioctl(struct tty *tp, u_long cmd, caddr_t data,
622 int sc_render_add(sc_renderer_t *rndr);
623 int sc_render_remove(sc_renderer_t *rndr);
624 sc_rndr_sw_t *sc_render_match(scr_stat *scp, char *name, int mode);
627 void sc_vtb_init(sc_vtb_t *vtb, int type, int cols, int rows,
628 void *buffer, int wait);
629 void sc_vtb_destroy(sc_vtb_t *vtb);
630 size_t sc_vtb_size(int cols, int rows);
631 void sc_vtb_clear(sc_vtb_t *vtb, int c, int attr);
633 int sc_vtb_getc(sc_vtb_t *vtb, int at);
634 int sc_vtb_geta(sc_vtb_t *vtb, int at);
635 void sc_vtb_putc(sc_vtb_t *vtb, int at, int c, int a);
636 vm_offset_t sc_vtb_putchar(sc_vtb_t *vtb, vm_offset_t p, int c, int a);
637 vm_offset_t sc_vtb_pointer(sc_vtb_t *vtb, int at);
638 int sc_vtb_pos(sc_vtb_t *vtb, int pos, int offset);
640 #define sc_vtb_tail(vtb) ((vtb)->vtb_tail)
641 #define sc_vtb_rows(vtb) ((vtb)->vtb_rows)
642 #define sc_vtb_cols(vtb) ((vtb)->vtb_cols)
644 void sc_vtb_copy(sc_vtb_t *vtb1, int from, sc_vtb_t *vtb2, int to,
646 void sc_vtb_append(sc_vtb_t *vtb1, int from, sc_vtb_t *vtb2,
648 void sc_vtb_seek(sc_vtb_t *vtb, int pos);
649 void sc_vtb_erase(sc_vtb_t *vtb, int at, int count, int c, int attr);
650 void sc_vtb_move(sc_vtb_t *vtb, int from, int to, int count);
651 void sc_vtb_delete(sc_vtb_t *vtb, int at, int count, int c, int attr);
652 void sc_vtb_ins(sc_vtb_t *vtb, int at, int count, int c, int attr);
655 int sysmouse_event(mouse_info_t *info);
658 void sc_move_cursor(scr_stat *scp, int x, int y);
659 void sc_clear_screen(scr_stat *scp);
660 int sc_term_add(sc_term_sw_t *sw);
661 int sc_term_remove(sc_term_sw_t *sw);
662 sc_term_sw_t *sc_term_match(char *name);
663 sc_term_sw_t *sc_term_match_by_number(int index);
665 /* machine dependent functions */
666 int sc_max_unit(void);
667 sc_softc_t *sc_get_softc(int unit, int flags);
668 sc_softc_t *sc_find_softc(struct video_adapter *adp, struct keyboard *kbd);
669 int sc_get_cons_priority(int *unit, int *flags);
670 void sc_get_bios_values(bios_values_t *values);
671 int sc_tone(int herz);
673 #endif /* !_DEV_SYSCONS_SYSCONS_H_ */