16628Ssos/*-
239287Ssos * Copyright (c) 1995-1998 S�ren Schmidt
36628Ssos * All rights reserved.
46628Ssos *
5146736Sdelphij * This code is derived from software contributed to The DragonFly Project
6146736Sdelphij * by Sascha Wildner <saw@online.de>
7146736Sdelphij *
86628Ssos * Redistribution and use in source and binary forms, with or without
96628Ssos * modification, are permitted provided that the following conditions
106628Ssos * are met:
116628Ssos * 1. Redistributions of source code must retain the above copyright
1239287Ssos *    notice, this list of conditions and the following disclaimer,
1339287Ssos *    without modification, immediately at the beginning of the file.
146628Ssos * 2. Redistributions in binary form must reproduce the above copyright
156628Ssos *    notice, this list of conditions and the following disclaimer in the
166628Ssos *    documentation and/or other materials provided with the distribution.
176628Ssos * 3. The name of the author may not be used to endorse or promote products
1839287Ssos *    derived from this software without specific prior written permission.
196628Ssos *
206628Ssos * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
216628Ssos * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
226628Ssos * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
236628Ssos * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
246628Ssos * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
256628Ssos * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
266628Ssos * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
276628Ssos * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
286628Ssos * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
296628Ssos * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
306628Ssos *
3150477Speter * $FreeBSD$
326628Ssos */
336628Ssos
3442504Syokota#ifndef _DEV_SYSCONS_SYSCONS_H_
3542504Syokota#define	_DEV_SYSCONS_SYSCONS_H_
366712Spst
37162285Sscottl#include <sys/lock.h>
38162285Sscottl#include <sys/mutex.h>
39162285Sscottl
4048104Syokota/* machine-dependent part of the header */
416628Ssos
4248104Syokota#ifdef PC98
43146049Snyan#include <pc98/cbus/sc_machdep.h>
4448104Syokota#elif defined(__i386__)
4548104Syokota/* nothing for the moment */
4648104Syokota#endif
4748104Syokota
4848104Syokota/* default values for configuration options */
4948104Syokota
5048104Syokota#ifndef MAXCONS
5148104Syokota#define MAXCONS		16
5248104Syokota#endif
5348104Syokota
5448104Syokota#ifdef SC_NO_SYSMOUSE
5548104Syokota#undef SC_NO_CUTPASTE
5648104Syokota#define SC_NO_CUTPASTE	1
5748104Syokota#endif
5848104Syokota
5948104Syokota#ifdef SC_NO_MODE_CHANGE
6048104Syokota#undef SC_PIXEL_MODE
6148104Syokota#endif
6248104Syokota
6379534Syokota/* Always load font data if the pixel (raster text) mode is to be used. */
6479534Syokota#ifdef SC_PIXEL_MODE
6579534Syokota#undef SC_NO_FONT_LOADING
6679534Syokota#endif
6779534Syokota
6879534Syokota/*
6979534Syokota * If font data is not available, the `arrow'-shaped mouse cursor cannot
7079534Syokota * be drawn.  Use the alternative drawing method.
7179534Syokota */
7279534Syokota#ifdef SC_NO_FONT_LOADING
7379534Syokota#undef SC_ALT_MOUSE_IMAGE
7479534Syokota#define SC_ALT_MOUSE_IMAGE 1
7579534Syokota#endif
7679534Syokota
7758872Syokota#ifndef SC_CURSOR_CHAR
7858872Syokota#define SC_CURSOR_CHAR	(0x07)
7958872Syokota#endif
8058872Syokota
8155849Syokota#ifndef SC_MOUSE_CHAR
8255849Syokota#define SC_MOUSE_CHAR	(0xd0)
8355849Syokota#endif
8455849Syokota
8558872Syokota#if SC_MOUSE_CHAR <= SC_CURSOR_CHAR && SC_CURSOR_CHAR < (SC_MOUSE_CHAR + 4)
8658872Syokota#undef SC_CURSOR_CHAR
8758872Syokota#define SC_CURSOR_CHAR	(SC_MOUSE_CHAR + 4)
8858872Syokota#endif
8958872Syokota
9048104Syokota#ifndef SC_DEBUG_LEVEL
9148104Syokota#define SC_DEBUG_LEVEL	0
9248104Syokota#endif
9348104Syokota
9448104Syokota#define DPRINTF(l, p)	if (SC_DEBUG_LEVEL >= (l)) printf p
9548104Syokota
96146477Smarius#ifndef __sparc64__
9748104Syokota#define SC_DRIVER_NAME	"sc"
98146477Smarius#else
99146477Smarius/*
100146477Smarius * Use a different driver name on sparc64 so it does not get confused
101146477Smarius * with the system controller devices which are also termed 'sc' in OFW.
102146477Smarius */
103146477Smarius#define SC_DRIVER_NAME	"syscons"
104146477Smarius#endif
105181905Sed#define SC_VTY(dev)	(((sc_ttysoftc *)tty_softc(tp))->st_index)
10651404Syokota#define SC_DEV(sc, vty)	((sc)->dev[(vty) - (sc)->first_vty])
107181905Sed#define SC_STAT(tp)	(*((scr_stat **)&((sc_ttysoftc *)tty_softc(tp))->st_stat))
10848104Syokota
1096628Ssos/* printable chars */
11048104Syokota#ifndef PRINTABLE
1118017Sbde#define PRINTABLE(ch)	((ch) > 0x1b || ((ch) > 0x0d && (ch) < 0x1b) \
1128017Sbde			 || (ch) < 0x07)
11348104Syokota#endif
1146628Ssos
1157623Ssos/* macros for "intelligent" screen update */
1167623Ssos#define mark_for_update(scp, x)	{\
1177623Ssos			  	    if ((x) < scp->start) scp->start = (x);\
1187623Ssos				    else if ((x) > scp->end) scp->end = (x);\
1197623Ssos				}
1207623Ssos#define mark_all(scp)		{\
1217623Ssos				    scp->start = 0;\
12233283Sphk				    scp->end = scp->xsize * scp->ysize - 1;\
1237623Ssos				}
1247623Ssos
12548104Syokota/* vty status flags (scp->status) */
12658872Syokota#define UNKNOWN_MODE	0x00010		/* unknown video mode */
12758872Syokota#define SWITCH_WAIT_REL	0x00080		/* waiting for vty release */
12858872Syokota#define SWITCH_WAIT_ACQ	0x00100		/* waiting for vty ack */
12958872Syokota#define BUFFER_SAVED	0x00200		/* vty buffer is saved */
13058872Syokota#define CURSOR_ENABLED 	0x00400		/* text cursor is enabled */
13158872Syokota#define MOUSE_MOVED	0x01000		/* mouse cursor has moved */
13258872Syokota#define MOUSE_CUTTING	0x02000		/* mouse cursor is cutting text */
13358872Syokota#define MOUSE_VISIBLE	0x04000		/* mouse cursor is showing */
13458872Syokota#define GRAPHICS_MODE	0x08000		/* vty is in a graphics mode */
13558872Syokota#define PIXEL_MODE	0x10000		/* vty is in a raster text mode */
13658872Syokota#define SAVER_RUNNING	0x20000		/* screen saver is running */
13758872Syokota#define VR_CURSOR_BLINK	0x40000		/* blinking text cursor */
13858872Syokota#define VR_CURSOR_ON	0x80000		/* text cursor is on */
13958872Syokota#define MOUSE_HIDDEN	0x100000	/* mouse cursor is temporarily hidden */
1406628Ssos
1416628Ssos/* misc defines */
1426628Ssos#define FALSE		0
1436628Ssos#define TRUE		1
14494617Sobrien
14594617Sobrien/*
14694617Sobrien   The following #defines are hard-coded for a maximum text
14794617Sobrien   resolution corresponding to a maximum framebuffer
14894617Sobrien   resolution of 1600x1200 with an 8x8 font...
14994617Sobrien*/
15094617Sobrien#define	COL		200
15194617Sobrien#define	ROW		150
15294617Sobrien
1536628Ssos#define PCBURST		128
1546628Ssos
15548104Syokota#ifndef BELL_DURATION
15677364Sphk#define BELL_DURATION	((5 * hz + 99) / 100)
15748104Syokota#define BELL_PITCH	800
15848104Syokota#endif
15948104Syokota
16048104Syokota/* virtual terminal buffer */
16148104Syokotatypedef struct sc_vtb {
16248104Syokota	int		vtb_flags;
16348104Syokota#define VTB_VALID	(1 << 0)
16478956Syokota#define VTB_ALLOCED	(1 << 1)
16548104Syokota	int		vtb_type;
16648104Syokota#define VTB_INVALID	0
16748104Syokota#define VTB_MEMORY	1
16848104Syokota#define VTB_FRAMEBUFFER	2
16948104Syokota#define VTB_RINGBUFFER	3
17048104Syokota	int		vtb_cols;
17148104Syokota	int		vtb_rows;
17248104Syokota	int		vtb_size;
17348104Syokota	vm_offset_t	vtb_buffer;
17448104Syokota	int		vtb_tail;	/* valid for VTB_RINGBUFFER only */
17548104Syokota} sc_vtb_t;
17648104Syokota
17781030Syokota/* text cursor attributes */
17881030Syokotastruct cursor_attr {
17981030Syokota	int		flags;
18081030Syokota	int		base;
18181030Syokota	int		height;
18281030Syokota};
18381030Syokota
18448104Syokota/* softc */
18548104Syokota
18648104Syokotastruct keyboard;
18748104Syokotastruct video_adapter;
18848104Syokotastruct scr_stat;
18948104Syokotastruct tty;
19048104Syokota
19148104Syokotatypedef struct sc_softc {
19248104Syokota	int		unit;			/* unit # */
19348104Syokota	int		config;			/* configuration flags */
194197085Sdelphij#define SC_VESAMODE	(1 << 7)
19548104Syokota#define SC_AUTODETECT_KBD (1 << 8)
19648104Syokota#define SC_KERNEL_CONSOLE (1 << 9)
19748104Syokota
19848104Syokota	int		flags;			/* status flags */
19948104Syokota#define SC_VISUAL_BELL	(1 << 0)
20048104Syokota#define SC_QUIET_BELL	(1 << 1)
20181030Syokota#if 0 /* not used anymore */
20248104Syokota#define SC_BLINK_CURSOR	(1 << 2)
20348104Syokota#define SC_CHAR_CURSOR	(1 << 3)
20481030Syokota#endif
20548104Syokota#define SC_MOUSE_ENABLED (1 << 4)
20648104Syokota#define	SC_SCRN_IDLE	(1 << 5)
20748104Syokota#define	SC_SCRN_BLANKED	(1 << 6)
20848104Syokota#define	SC_SAVER_FAILED	(1 << 7)
20999704Sdd#define	SC_SCRN_VTYLOCK	(1 << 8)
21048104Syokota
21148104Syokota#define	SC_INIT_DONE	(1 << 16)
21248104Syokota#define	SC_SPLASH_SCRN	(1 << 17)
21348104Syokota
21448104Syokota	int		keyboard;		/* -1 if unavailable */
21548104Syokota	struct keyboard	*kbd;
21648104Syokota
21748104Syokota	int		adapter;
21848104Syokota	struct video_adapter *adp;
21948104Syokota	int		initial_mode;		/* initial video mode */
22048104Syokota
22148104Syokota	int		first_vty;
22248104Syokota	int		vtys;
223181905Sed	struct tty **dev;
22448104Syokota	struct scr_stat	*cur_scp;
22548104Syokota	struct scr_stat	*new_scp;
22648104Syokota	struct scr_stat	*old_scp;
22748104Syokota	int     	delayed_next_scr;
22848104Syokota
22948104Syokota	char        	font_loading_in_progress;
23048104Syokota	char        	switch_in_progress;
23148104Syokota	char        	write_in_progress;
23248104Syokota	char        	blink_in_progress;
233162285Sscottl	struct mtx	video_mtx;
23448104Syokota
23548104Syokota	long		scrn_time_stamp;
23648104Syokota
23781030Syokota	struct cursor_attr dflt_curs_attr;
23881030Syokota	struct cursor_attr curs_attr;
23948104Syokota
24048104Syokota	u_char      	scr_map[256];
24148104Syokota	u_char      	scr_rmap[256];
24248104Syokota
24348104Syokota#ifdef _SC_MD_SOFTC_DECLARED_
24448104Syokota	sc_md_softc_t	md;			/* machine dependent vars */
24548104Syokota#endif
24648104Syokota
24748104Syokota#ifndef SC_NO_PALETTE_LOADING
248204265Sjkim	u_char		palette[256 * 3];
249204265Sjkim#ifdef SC_PIXEL_MODE
250204265Sjkim	u_char		palette2[256 * 3];
25148104Syokota#endif
252204265Sjkim#endif
25348104Syokota
25448104Syokota#ifndef SC_NO_FONT_LOADING
25548104Syokota	int     	fonts_loaded;
25656043Syokota#define FONT_8		2
25756043Syokota#define FONT_14		4
25856043Syokota#define FONT_16		8
259150686Smarius#define FONT_22		8
26048104Syokota	u_char		*font_8;
26148104Syokota	u_char		*font_14;
26248104Syokota	u_char		*font_16;
263150686Smarius	u_char		*font_22;
26448104Syokota#endif
26548104Syokota
26658872Syokota	u_char		cursor_char;
26755849Syokota	u_char		mouse_char;
26855849Syokota
269225221Srwatson#ifdef KDB
270225221Srwatson	int		sc_altbrk;
271225221Srwatson#endif
27248104Syokota} sc_softc_t;
27348104Syokota
27448104Syokota/* virtual screen */
2756628Ssostypedef struct scr_stat {
27648104Syokota	int		index;			/* index of this vty */
27748104Syokota	struct sc_softc *sc;			/* pointer to softc */
27848104Syokota	struct sc_rndr_sw *rndr;		/* renderer */
279119379Sjake#ifndef __sparc64__
28048104Syokota	sc_vtb_t	scr;
281119379Sjake#endif
28248104Syokota	sc_vtb_t	vtb;
28356043Syokota
2846628Ssos	int 		xpos;			/* current X position */
2856628Ssos	int 		ypos;			/* current Y position */
28618587Ssos	int 		xsize;			/* X text size */
28718587Ssos	int 		ysize;			/* Y text size */
28818587Ssos	int 		xpixel;			/* X graphics size */
28918587Ssos	int 		ypixel;			/* Y graphics size */
29039287Ssos	int		xoff;			/* X offset in pixel mode */
29139287Ssos	int		yoff;			/* Y offset in pixel mode */
29256043Syokota
29348104Syokota	u_char		*font;			/* current font */
29416769Ssos	int		font_size;		/* fontsize in Y direction */
295119388Sjake	int		font_width;		/* fontsize in X direction */
29656043Syokota
2977475Ssos	int		start;			/* modified area start */
2987475Ssos	int		end;			/* modified area end */
29956043Syokota
30056043Syokota	struct sc_term_sw *tsw;
30156043Syokota	void		*ts;
30256043Syokota
3036628Ssos	int	 	status;			/* status (bitfield) */
304235408Savg	int		grabbed;
30542504Syokota	int		kbd_mode;		/* keyboard I/O mode */
306235408Savg	int		kbd_prev_mode;		/* keyboard I/O mode */
30756043Syokota
30848104Syokota	int		cursor_pos;		/* cursor buffer position */
30948104Syokota	int		cursor_oldpos;		/* cursor old buffer position */
31048104Syokota	u_short		cursor_saveunder_char;	/* saved char under cursor */
31148104Syokota	u_short		cursor_saveunder_attr;	/* saved attr under cursor */
31281030Syokota	struct cursor_attr dflt_curs_attr;
31381030Syokota	struct cursor_attr curr_curs_attr;
31481030Syokota	struct cursor_attr curs_attr;
31556043Syokota
31648104Syokota	int		mouse_pos;		/* mouse buffer position */
31748104Syokota	int		mouse_oldpos;		/* mouse old buffer position */
3186628Ssos	short		mouse_xpos;		/* mouse x coordinate */
3196628Ssos	short		mouse_ypos;		/* mouse y coordinate */
32058872Syokota	short		mouse_oldxpos;		/* mouse previous x coordinate */
32158872Syokota	short		mouse_oldypos;		/* mouse previous y coordinate */
32216693Ssos	short		mouse_buttons;		/* mouse buttons */
32348104Syokota	int		mouse_cut_start;	/* mouse cut start pos */
32448104Syokota	int		mouse_cut_end;		/* mouse cut end pos */
325197539Sed	int		mouse_level;		/* xterm mouse protocol */
32616693Ssos	struct proc 	*mouse_proc;		/* proc* of controlling proc */
32716693Ssos	pid_t 		mouse_pid;		/* pid of controlling proc */
32816693Ssos	int		mouse_signal;		/* signal # to report with */
32956043Syokota
3306628Ssos	u_short		bell_duration;
3316628Ssos	u_short		bell_pitch;
33256043Syokota
3336628Ssos	u_char		border;			/* border color */
33438052Syokota	int	 	mode;			/* mode */
3356628Ssos	pid_t 		pid;			/* pid of controlling proc */
3366628Ssos	struct proc 	*proc;			/* proc* of controlling proc */
3376628Ssos	struct vt_mode 	smode;			/* switch mode */
33856043Syokota
33948104Syokota	sc_vtb_t	*history;		/* circular history buffer */
34048104Syokota	int		history_pos;		/* position shown on screen */
3416628Ssos	int		history_size;		/* size of history buffer */
34256043Syokota
34339287Ssos	int		splash_save_mode;	/* saved mode for splash screen */
34439287Ssos	int		splash_save_status;	/* saved status for splash screen */
345172250Ssimokawa	struct mtx	scr_lock;		/* mutex for sc_puts() */
34648104Syokota#ifdef _SCR_MD_STAT_DECLARED_
34748104Syokota	scr_md_stat_t	md;			/* machine dependent vars */
34848104Syokota#endif
3496628Ssos} scr_stat;
3506628Ssos
351181905Sed/* TTY softc. */
352181905Sedtypedef struct sc_ttysoftc {
353181905Sed	int		st_index;
354181905Sed	scr_stat	*st_stat;
355181905Sed} sc_ttysoftc;
356181905Sed
35748104Syokota#ifndef SC_NORM_ATTR
35848104Syokota#define SC_NORM_ATTR		(FG_LIGHTGREY | BG_BLACK)
35948104Syokota#endif
36048104Syokota#ifndef SC_NORM_REV_ATTR
36148104Syokota#define SC_NORM_REV_ATTR	(FG_BLACK | BG_LIGHTGREY)
36248104Syokota#endif
36348104Syokota#ifndef SC_KERNEL_CONS_ATTR
36448104Syokota#define SC_KERNEL_CONS_ATTR	(FG_WHITE | BG_BLACK)
36548104Syokota#endif
36648104Syokota#ifndef SC_KERNEL_CONS_REV_ATTR
36748104Syokota#define SC_KERNEL_CONS_REV_ATTR	(FG_BLACK | BG_LIGHTGREY)
36848104Syokota#endif
36939287Ssos
37056043Syokota/* terminal emulator */
37156043Syokota
37256043Syokota#ifndef SC_DFLT_TERM
37356043Syokota#define SC_DFLT_TERM	"*"			/* any */
37456043Syokota#endif
37556043Syokota
37656043Syokotatypedef int	sc_term_init_t(scr_stat *scp, void **tcp, int code);
37756043Syokota#define SC_TE_COLD_INIT	0
37856043Syokota#define SC_TE_WARM_INIT	1
37956043Syokotatypedef int	sc_term_term_t(scr_stat *scp, void **tcp);
380189617Sedtypedef void	sc_term_puts_t(scr_stat *scp, u_char *buf, int len, int kernel);
38156043Syokotatypedef int	sc_term_ioctl_t(scr_stat *scp, struct tty *tp, u_long cmd,
382181905Sed				caddr_t data, struct thread *td);
38356043Syokotatypedef int	sc_term_reset_t(scr_stat *scp, int code);
38456043Syokota#define SC_TE_HARD_RESET 0
38556043Syokota#define SC_TE_SOFT_RESET 1
38656043Syokotatypedef void	sc_term_default_attr_t(scr_stat *scp, int norm, int rev);
38756043Syokotatypedef void	sc_term_clear_t(scr_stat *scp);
38856043Syokotatypedef void	sc_term_notify_t(scr_stat *scp, int event);
38956043Syokota#define SC_TE_NOTIFY_VTSWITCH_IN	0
39056043Syokota#define SC_TE_NOTIFY_VTSWITCH_OUT	1
39156043Syokotatypedef int	sc_term_input_t(scr_stat *scp, int c, struct tty *tp);
392199171Sedtypedef const char *sc_term_fkeystr_t(scr_stat *scp, int c);
39356043Syokota
39456043Syokotatypedef struct sc_term_sw {
39560938Sjake	LIST_ENTRY(sc_term_sw)	link;
39656043Syokota	char 			*te_name;	/* name of the emulator */
39756043Syokota	char 			*te_desc;	/* description */
39856043Syokota	char 			*te_renderer;	/* matching renderer */
39956043Syokota	size_t			te_size;	/* size of internal buffer */
40056043Syokota	int			te_refcount;	/* reference counter */
40156043Syokota	sc_term_init_t		*te_init;
40256043Syokota	sc_term_term_t		*te_term;
40356043Syokota	sc_term_puts_t		*te_puts;
40456043Syokota	sc_term_ioctl_t		*te_ioctl;
40556043Syokota	sc_term_reset_t		*te_reset;
40656043Syokota	sc_term_default_attr_t	*te_default_attr;
40756043Syokota	sc_term_clear_t		*te_clear;
40856043Syokota	sc_term_notify_t	*te_notify;
40956043Syokota	sc_term_input_t		*te_input;
410199171Sed	sc_term_fkeystr_t	*te_fkeystr;
41156043Syokota} sc_term_sw_t;
41256043Syokota
41356043Syokota#define SCTERM_MODULE(name, sw)					\
41456043Syokota	DATA_SET(scterm_set, sw);				\
41556043Syokota	static int						\
41656043Syokota	scterm_##name##_event(module_t mod, int type, void *data) \
41756043Syokota	{							\
41856043Syokota		switch (type) {					\
41956043Syokota		case MOD_LOAD:					\
42056043Syokota			return sc_term_add(&sw);		\
42156043Syokota		case MOD_UNLOAD:				\
42256043Syokota			if (sw.te_refcount > 0)			\
42356043Syokota				return EBUSY;			\
42456043Syokota			return sc_term_remove(&sw);		\
42556043Syokota		default:					\
426132199Sphk			return EOPNOTSUPP;			\
42756043Syokota			break;					\
42856043Syokota		}						\
42956043Syokota		return 0;					\
43056043Syokota	}							\
43156043Syokota	static moduledata_t scterm_##name##_mod = {		\
43256043Syokota		"scterm-" #name,				\
43356043Syokota		scterm_##name##_event,				\
43456043Syokota		NULL,						\
43556043Syokota	};							\
43656043Syokota	DECLARE_MODULE(scterm_##name, scterm_##name##_mod,	\
43756043Syokota		       SI_SUB_DRIVERS, SI_ORDER_MIDDLE)
43856043Syokota
43948104Syokota/* renderer function table */
440146736Sdelphijtypedef void	vr_init_t(scr_stat *scp);
44148104Syokotatypedef void	vr_clear_t(scr_stat *scp, int c, int attr);
44248104Syokotatypedef void	vr_draw_border_t(scr_stat *scp, int color);
44348104Syokotatypedef void	vr_draw_t(scr_stat *scp, int from, int count, int flip);
44448104Syokotatypedef void	vr_set_cursor_t(scr_stat *scp, int base, int height, int blink);
44548104Syokotatypedef void	vr_draw_cursor_t(scr_stat *scp, int at, int blink,
44648104Syokota				 int on, int flip);
44748104Syokotatypedef void	vr_blink_cursor_t(scr_stat *scp, int at, int flip);
44848104Syokotatypedef void	vr_set_mouse_t(scr_stat *scp);
44948104Syokotatypedef void	vr_draw_mouse_t(scr_stat *scp, int x, int y, int on);
45048104Syokota
45148104Syokotatypedef struct sc_rndr_sw {
452146736Sdelphij	vr_init_t		*init;
45348104Syokota	vr_clear_t		*clear;
45448104Syokota	vr_draw_border_t	*draw_border;
45548104Syokota	vr_draw_t		*draw;
45648104Syokota	vr_set_cursor_t		*set_cursor;
45748104Syokota	vr_draw_cursor_t	*draw_cursor;
45848104Syokota	vr_blink_cursor_t	*blink_cursor;
45948104Syokota	vr_set_mouse_t		*set_mouse;
46048104Syokota	vr_draw_mouse_t		*draw_mouse;
46148104Syokota} sc_rndr_sw_t;
46248104Syokota
46348104Syokotatypedef struct sc_renderer {
46456043Syokota	char			*name;
46556043Syokota	int			mode;
46656043Syokota	sc_rndr_sw_t		*rndrsw;
46760938Sjake	LIST_ENTRY(sc_renderer)	link;
46848104Syokota} sc_renderer_t;
46948104Syokota
47056043Syokota#define RENDERER(name, mode, sw, set)				\
47183274Speter	static struct sc_renderer scrndr_##name##_##mode = {	\
47248104Syokota		#name, mode, &sw				\
47348104Syokota	};							\
47483274Speter	DATA_SET(scrndr_set, scrndr_##name##_##mode);		\
47583274Speter	DATA_SET(set, scrndr_##name##_##mode)
47648104Syokota
47756043Syokota#define RENDERER_MODULE(name, set)				\
47878161Speter	SET_DECLARE(set, sc_renderer_t);			\
47956043Syokota	static int						\
48056043Syokota	scrndr_##name##_event(module_t mod, int type, void *data) \
48156043Syokota	{							\
48256043Syokota		sc_renderer_t **list;				\
48356043Syokota		int error = 0;					\
48456043Syokota		switch (type) {					\
48556043Syokota		case MOD_LOAD:					\
48678161Speter			SET_FOREACH(list, set) {		\
48778161Speter				error = sc_render_add(*list);	\
48856043Syokota				if (error)			\
48956043Syokota					break;			\
49056043Syokota			}					\
49156043Syokota			break;					\
49256043Syokota		case MOD_UNLOAD:				\
49378161Speter			SET_FOREACH(list, set) {		\
49478161Speter				error = sc_render_remove(*list);\
49556043Syokota				if (error)			\
49656043Syokota					break;			\
49756043Syokota			}					\
49856043Syokota			break;					\
49956043Syokota		default:					\
500132199Sphk			return EOPNOTSUPP;			\
50156043Syokota			break;					\
50256043Syokota		}						\
50356043Syokota		return error;					\
50456043Syokota	}							\
50556043Syokota	static moduledata_t scrndr_##name##_mod = {		\
50656043Syokota		"scrndr-" #name,				\
50756043Syokota		scrndr_##name##_event,				\
50856043Syokota		NULL,						\
50956043Syokota	};							\
51083274Speter	DECLARE_MODULE(scrndr_##name, scrndr_##name##_mod, 	\
51156043Syokota		       SI_SUB_DRIVERS, SI_ORDER_MIDDLE)
51248104Syokota
51348104Syokotatypedef struct {
51448104Syokota	int		cursor_start;
51548104Syokota	int		cursor_end;
51648104Syokota	int		shift_state;
51748104Syokota	int		bell_pitch;
51848104Syokota} bios_values_t;
51948104Syokota
52048104Syokota/* other macros */
52139287Ssos#define ISTEXTSC(scp)	(!((scp)->status 				\
52239287Ssos			  & (UNKNOWN_MODE | GRAPHICS_MODE | PIXEL_MODE)))
52339287Ssos#define ISGRAPHSC(scp)	(((scp)->status 				\
52439287Ssos			  & (UNKNOWN_MODE | GRAPHICS_MODE)))
52539287Ssos#define ISPIXELSC(scp)	(((scp)->status 				\
52639287Ssos			  & (UNKNOWN_MODE | GRAPHICS_MODE | PIXEL_MODE))\
52739287Ssos			  == PIXEL_MODE)
52839287Ssos#define ISUNKNOWNSC(scp) ((scp)->status & UNKNOWN_MODE)
52939287Ssos
53048104Syokota#define ISMOUSEAVAIL(af) ((af) & V_ADP_FONT)
53139287Ssos#define ISFONTAVAIL(af)	((af) & V_ADP_FONT)
53239287Ssos#define ISPALAVAIL(af)	((af) & V_ADP_PALETTE)
53339287Ssos
53448104Syokota#define ISSIGVALID(sig)	((sig) > 0 && (sig) < NSIG)
53539287Ssos
536162285Sscottl#define SC_VIDEO_LOCKINIT(sc)						\
537176259Sjhb		mtx_init(&(sc)->video_mtx, "syscons video lock", NULL,	\
538176259Sjhb		    MTX_SPIN | MTX_RECURSE);
539162285Sscottl#define SC_VIDEO_LOCK(sc)						\
540162285Sscottl		do {							\
541162285Sscottl			if (!cold)					\
542162285Sscottl				mtx_lock_spin(&(sc)->video_mtx);	\
543162285Sscottl		} while(0)
544162285Sscottl#define SC_VIDEO_UNLOCK(sc)						\
545162285Sscottl		do {							\
546162285Sscottl			if (!cold)					\
547162285Sscottl				mtx_unlock_spin(&(sc)->video_mtx);	\
548162285Sscottl		} while(0)
549162285Sscottl
55039287Ssos/* syscons.c */
551181905Sedextern int 	(*sc_user_ioctl)(struct tty *tp, u_long cmd, caddr_t data,
552181905Sed				 struct thread *td);
55342831Syokota
55448104Syokotaint		sc_probe_unit(int unit, int flags);
55548104Syokotaint		sc_attach_unit(int unit, int flags);
55639287Ssos
55748104Syokotaint		set_mode(scr_stat *scp);
55839287Ssos
55956043Syokotavoid		sc_set_border(scr_stat *scp, int color);
560150686Smariusvoid		sc_load_font(scr_stat *scp, int page, int size, int width,
561150686Smarius			     u_char *font, int base, int count);
562150686Smariusvoid		sc_save_font(scr_stat *scp, int page, int size, int width,
563150686Smarius			     u_char *font, int base, int count);
56456043Syokotavoid		sc_show_font(scr_stat *scp, int page);
56539287Ssos
56648104Syokotavoid		sc_touch_scrn_saver(void);
56756043Syokotavoid		sc_draw_cursor_image(scr_stat *scp);
56856043Syokotavoid		sc_remove_cursor_image(scr_stat *scp);
56948104Syokotavoid		sc_set_cursor_image(scr_stat *scp);
57081030Syokotavoid		sc_change_cursor_shape(scr_stat *scp, int flags,
57181030Syokota				       int base, int height);
57248104Syokotaint		sc_clean_up(scr_stat *scp);
57356043Syokotaint		sc_switch_scr(sc_softc_t *sc, u_int next_scr);
57448104Syokotavoid		sc_alloc_scr_buffer(scr_stat *scp, int wait, int discard);
57556043Syokotaint		sc_init_emulator(scr_stat *scp, char *name);
576186681Sedvoid		sc_paste(scr_stat *scp, const u_char *p, int count);
577197539Sedvoid		sc_respond(scr_stat *scp, const u_char *p,
578197539Sed			   int count, int wakeup);
57956043Syokotavoid		sc_bell(scr_stat *scp, int pitch, int duration);
58039287Ssos
58148104Syokota/* schistory.c */
58248104Syokota#ifndef SC_NO_HISTORY
58348667Syokotaint		sc_alloc_history_buffer(scr_stat *scp, int lines,
58448667Syokota					int prev_ysize, int wait);
58548667Syokotavoid		sc_free_history_buffer(scr_stat *scp, int prev_ysize);
58648104Syokotavoid		sc_hist_save(scr_stat *scp);
58748104Syokota#define		sc_hist_save_one_line(scp, from)	\
58848104Syokota		sc_vtb_append(&(scp)->vtb, (from), (scp)->history, (scp)->xsize)
58948104Syokotaint		sc_hist_restore(scr_stat *scp);
59048104Syokotavoid		sc_hist_home(scr_stat *scp);
59148104Syokotavoid		sc_hist_end(scr_stat *scp);
59248104Syokotaint		sc_hist_up_line(scr_stat *scp);
59348104Syokotaint		sc_hist_down_line(scr_stat *scp);
59448104Syokotaint		sc_hist_ioctl(struct tty *tp, u_long cmd, caddr_t data,
595181905Sed			      struct thread *td);
59648104Syokota#endif /* SC_NO_HISTORY */
59748104Syokota
59848104Syokota/* scmouse.c */
59948104Syokota#ifndef SC_NO_CUTPASTE
60048104Syokotavoid		sc_alloc_cut_buffer(scr_stat *scp, int wait);
60148104Syokotavoid		sc_draw_mouse_image(scr_stat *scp);
60248104Syokotavoid		sc_remove_mouse_image(scr_stat *scp);
60348104Syokotaint		sc_inside_cutmark(scr_stat *scp, int pos);
60448104Syokotavoid		sc_remove_cutmarking(scr_stat *scp);
60548104Syokotavoid		sc_remove_all_cutmarkings(sc_softc_t *scp);
60648104Syokotavoid		sc_remove_all_mouse(sc_softc_t *scp);
60774118Sachevoid		sc_mouse_paste(scr_stat *scp);
60848104Syokota#else
60958965Syokota#define		sc_draw_mouse_image(scp)
61058965Syokota#define		sc_remove_mouse_image(scp)
61148104Syokota#define		sc_inside_cutmark(scp, pos)	FALSE
61248104Syokota#define		sc_remove_cutmarking(scp)
61358965Syokota#define		sc_remove_all_cutmarkings(scp)
61458965Syokota#define		sc_remove_all_mouse(scp)
61574118Sache#define		sc_mouse_paste(scp)
61648104Syokota#endif /* SC_NO_CUTPASTE */
61748104Syokota#ifndef SC_NO_SYSMOUSE
61848104Syokotavoid		sc_mouse_move(scr_stat *scp, int x, int y);
61948104Syokotaint		sc_mouse_ioctl(struct tty *tp, u_long cmd, caddr_t data,
620181905Sed			       struct thread *td);
62148104Syokota#endif /* SC_NO_SYSMOUSE */
62248104Syokota
62339287Ssos/* scvidctl.c */
62448104Syokotaint		sc_set_text_mode(scr_stat *scp, struct tty *tp, int mode,
625149640Srodrigc				 int xsize, int ysize, int fontsize,
626149640Srodrigc				 int font_width);
62748104Syokotaint		sc_set_graphics_mode(scr_stat *scp, struct tty *tp, int mode);
628149640Srodrigcint		sc_set_pixel_mode(scr_stat *scp, struct tty *tp, int xsize,
629149640Srodrigc				  int ysize, int fontsize, int font_width);
630204281Sjkimint		sc_support_pixel_mode(void *arg);
631181905Sedint		sc_vid_ioctl(struct tty *tp, u_long cmd, caddr_t data,
63283366Sjulian			     struct thread *td);
63339287Ssos
63456043Syokotaint		sc_render_add(sc_renderer_t *rndr);
63556043Syokotaint		sc_render_remove(sc_renderer_t *rndr);
63656043Syokotasc_rndr_sw_t	*sc_render_match(scr_stat *scp, char *name, int mode);
63756043Syokota
63848104Syokota/* scvtb.c */
63948104Syokotavoid		sc_vtb_init(sc_vtb_t *vtb, int type, int cols, int rows,
64048104Syokota			    void *buffer, int wait);
64148104Syokotavoid		sc_vtb_destroy(sc_vtb_t *vtb);
64248104Syokotasize_t		sc_vtb_size(int cols, int rows);
64348104Syokotavoid		sc_vtb_clear(sc_vtb_t *vtb, int c, int attr);
64448104Syokota
64548104Syokotaint		sc_vtb_getc(sc_vtb_t *vtb, int at);
64648104Syokotaint		sc_vtb_geta(sc_vtb_t *vtb, int at);
64748104Syokotavoid		sc_vtb_putc(sc_vtb_t *vtb, int at, int c, int a);
64848104Syokotavm_offset_t	sc_vtb_putchar(sc_vtb_t *vtb, vm_offset_t p, int c, int a);
64948104Syokotavm_offset_t	sc_vtb_pointer(sc_vtb_t *vtb, int at);
65048104Syokotaint		sc_vtb_pos(sc_vtb_t *vtb, int pos, int offset);
65148104Syokota
65248104Syokota#define		sc_vtb_tail(vtb)	((vtb)->vtb_tail)
65348104Syokota#define		sc_vtb_rows(vtb)	((vtb)->vtb_rows)
65451394Syokota#define		sc_vtb_cols(vtb)	((vtb)->vtb_cols)
65548104Syokota
65648104Syokotavoid		sc_vtb_copy(sc_vtb_t *vtb1, int from, sc_vtb_t *vtb2, int to,
65748104Syokota			    int count);
65848104Syokotavoid		sc_vtb_append(sc_vtb_t *vtb1, int from, sc_vtb_t *vtb2,
65948104Syokota			      int count);
66048104Syokotavoid		sc_vtb_seek(sc_vtb_t *vtb, int pos);
66148104Syokotavoid		sc_vtb_erase(sc_vtb_t *vtb, int at, int count, int c, int attr);
66248189Syokotavoid		sc_vtb_move(sc_vtb_t *vtb, int from, int to, int count);
66348104Syokotavoid		sc_vtb_delete(sc_vtb_t *vtb, int at, int count, int c, int attr);
66448104Syokotavoid		sc_vtb_ins(sc_vtb_t *vtb, int at, int count, int c, int attr);
66548104Syokota
66656043Syokota/* sysmouse.c */
66756043Syokotaint		sysmouse_event(mouse_info_t *info);
66856043Syokota
66956043Syokota/* scterm.c */
67056043Syokotavoid		sc_move_cursor(scr_stat *scp, int x, int y);
67156043Syokotavoid		sc_clear_screen(scr_stat *scp);
67256043Syokotaint		sc_term_add(sc_term_sw_t *sw);
67356043Syokotaint		sc_term_remove(sc_term_sw_t *sw);
67456043Syokotasc_term_sw_t	*sc_term_match(char *name);
67556043Syokotasc_term_sw_t	*sc_term_match_by_number(int index);
67656043Syokota
67748104Syokota/* machine dependent functions */
67848104Syokotaint		sc_max_unit(void);
67948104Syokotasc_softc_t	*sc_get_softc(int unit, int flags);
68048104Syokotasc_softc_t	*sc_find_softc(struct video_adapter *adp, struct keyboard *kbd);
68148104Syokotaint		sc_get_cons_priority(int *unit, int *flags);
68248104Syokotavoid		sc_get_bios_values(bios_values_t *values);
68348104Syokotaint		sc_tone(int herz);
68448104Syokota
68542504Syokota#endif /* !_DEV_SYSCONS_SYSCONS_H_ */
686