xref: /onnv-gate/usr/src/uts/common/sys/tem_impl.h (revision 7688:2757e6e1bb2a)
10Sstevel@tonic-gate /*
20Sstevel@tonic-gate  * CDDL HEADER START
30Sstevel@tonic-gate  *
40Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
51253Slq150181  * Common Development and Distribution License (the "License").
61253Slq150181  * You may not use this file except in compliance with the License.
70Sstevel@tonic-gate  *
80Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
100Sstevel@tonic-gate  * See the License for the specific language governing permissions
110Sstevel@tonic-gate  * and limitations under the License.
120Sstevel@tonic-gate  *
130Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
140Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
160Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
170Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
180Sstevel@tonic-gate  *
190Sstevel@tonic-gate  * CDDL HEADER END
200Sstevel@tonic-gate  */
211253Slq150181 
220Sstevel@tonic-gate /*
23*7688SAaron.Zang@Sun.COM  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
240Sstevel@tonic-gate  * Use is subject to license terms.
250Sstevel@tonic-gate  */
260Sstevel@tonic-gate 
270Sstevel@tonic-gate /*	Copyright (c) 1990, 1991 UNIX System Laboratories, Inc.	*/
280Sstevel@tonic-gate 
290Sstevel@tonic-gate /*	Copyright (c) 1984, 1986, 1987, 1988, 1989, 1990 AT&T	*/
300Sstevel@tonic-gate /*	  All Rights Reserved  	*/
310Sstevel@tonic-gate 
320Sstevel@tonic-gate #ifndef	_SYS_TEM_IMPL_H
330Sstevel@tonic-gate #define	_SYS_TEM_IMPL_H
340Sstevel@tonic-gate 
350Sstevel@tonic-gate #ifdef __cplusplus
360Sstevel@tonic-gate extern "C" {
370Sstevel@tonic-gate #endif
380Sstevel@tonic-gate 
391253Slq150181 #include <sys/types.h>
401253Slq150181 #include <sys/sunddi.h>
410Sstevel@tonic-gate #include <sys/sunldi.h>
420Sstevel@tonic-gate #include <sys/visual_io.h>
431253Slq150181 #include <sys/font.h>
44*7688SAaron.Zang@Sun.COM #include <sys/list.h>
451253Slq150181 #include <sys/tem.h>
46*7688SAaron.Zang@Sun.COM #include <sys/note.h>
470Sstevel@tonic-gate 
480Sstevel@tonic-gate /*
490Sstevel@tonic-gate  * definitions for ANSI x3.64 terminal control language parser
500Sstevel@tonic-gate  */
510Sstevel@tonic-gate 
520Sstevel@tonic-gate #define	TEM_MAXPARAMS	5	/* maximum number of ANSI paramters */
530Sstevel@tonic-gate #define	TEM_MAXTAB	40	/* maximum number of tab stops */
540Sstevel@tonic-gate #define	TEM_MAXFKEY	30	/* max length of function key with <ESC>Q */
550Sstevel@tonic-gate #define	MAX_TEM		2	/* max number of loadable terminal emulators */
560Sstevel@tonic-gate 
570Sstevel@tonic-gate #define	TEM_SCROLL_UP		0
580Sstevel@tonic-gate #define	TEM_SCROLL_DOWN		1
590Sstevel@tonic-gate #define	TEM_SHIFT_LEFT		0
600Sstevel@tonic-gate #define	TEM_SHIFT_RIGHT		1
610Sstevel@tonic-gate 
620Sstevel@tonic-gate #define	TEM_ATTR_NORMAL		0x0000
630Sstevel@tonic-gate #define	TEM_ATTR_REVERSE	0x0001
640Sstevel@tonic-gate #define	TEM_ATTR_BOLD		0x0002
650Sstevel@tonic-gate #define	TEM_ATTR_BLINK		0x0004
660Sstevel@tonic-gate #define	TEM_ATTR_TRANSPARENT	0x0008
670Sstevel@tonic-gate #define	TEM_ATTR_SCREEN_REVERSE	0x0010
680Sstevel@tonic-gate 
690Sstevel@tonic-gate #define	ANSI_COLOR_BLACK	0
700Sstevel@tonic-gate #define	ANSI_COLOR_WHITE	7
710Sstevel@tonic-gate 
720Sstevel@tonic-gate #define	TEM_TEXT_WHITE		0
730Sstevel@tonic-gate #define	TEM_TEXT_BLACK		1
740Sstevel@tonic-gate #define	TEM_TEXT_BLACK24_RED	0x00
750Sstevel@tonic-gate #define	TEM_TEXT_BLACK24_GREEN	0x00
760Sstevel@tonic-gate #define	TEM_TEXT_BLACK24_BLUE	0x00
770Sstevel@tonic-gate #define	TEM_TEXT_WHITE24_RED	0xff
780Sstevel@tonic-gate #define	TEM_TEXT_WHITE24_GREEN	0xff
790Sstevel@tonic-gate #define	TEM_TEXT_WHITE24_BLUE	0xff
800Sstevel@tonic-gate 
810Sstevel@tonic-gate #define	A_STATE_START			0
820Sstevel@tonic-gate #define	A_STATE_ESC			1
832216Slt200341 #define	A_STATE_CSI			2
842216Slt200341 #define	A_STATE_CSI_QMARK		3
852216Slt200341 #define	A_STATE_CSI_EQUAL		4
860Sstevel@tonic-gate 
870Sstevel@tonic-gate /*
880Sstevel@tonic-gate  * Default number of rows and columns
890Sstevel@tonic-gate  */
900Sstevel@tonic-gate #define	TEM_DEFAULT_ROWS	34
910Sstevel@tonic-gate #define	TEM_DEFAULT_COLS	80
920Sstevel@tonic-gate 
933994Slq150181 /*
943994Slq150181  * Default foreground/background color
953994Slq150181  */
96*7688SAaron.Zang@Sun.COM 
973994Slq150181 #ifdef _HAVE_TEM_FIRMWARE
983994Slq150181 #define	DEFAULT_ANSI_FOREGROUND	ANSI_COLOR_BLACK
993994Slq150181 #define	DEFAULT_ANSI_BACKGROUND	ANSI_COLOR_WHITE
1003994Slq150181 #else /* _HAVE_TEM_FIRMWARE */
1013994Slq150181 #define	DEFAULT_ANSI_FOREGROUND	ANSI_COLOR_WHITE
1023994Slq150181 #define	DEFAULT_ANSI_BACKGROUND	ANSI_COLOR_BLACK
1033994Slq150181 #endif
1043994Slq150181 
105*7688SAaron.Zang@Sun.COM 
1060Sstevel@tonic-gate #define	BUF_LEN		160 /* Two lines of data can be processed at a time */
1070Sstevel@tonic-gate 
1080Sstevel@tonic-gate typedef uint8_t text_color_t;
1090Sstevel@tonic-gate 
1103994Slq150181 typedef struct tem_color {
1113994Slq150181 	text_color_t	fg_color;
1123994Slq150181 	text_color_t	bg_color;
1133994Slq150181 	unsigned short	a_flags;
1143994Slq150181 } tem_color_t;
1153994Slq150181 
116*7688SAaron.Zang@Sun.COM enum called_from { CALLED_FROM_NORMAL, CALLED_FROM_STANDALONE };
117*7688SAaron.Zang@Sun.COM 
1180Sstevel@tonic-gate struct tem_pix_pos {
1190Sstevel@tonic-gate 	screen_pos_t	x;
1200Sstevel@tonic-gate 	screen_pos_t	y;
1210Sstevel@tonic-gate };
1220Sstevel@tonic-gate 
1230Sstevel@tonic-gate struct tem_char_pos {
1240Sstevel@tonic-gate 	screen_pos_t	col;
1250Sstevel@tonic-gate 	screen_pos_t	row;
1260Sstevel@tonic-gate };
1270Sstevel@tonic-gate 
1280Sstevel@tonic-gate struct tem_size {
1290Sstevel@tonic-gate 	screen_size_t	width;
1300Sstevel@tonic-gate 	screen_size_t	height;
1310Sstevel@tonic-gate };
1320Sstevel@tonic-gate 
1331253Slq150181 typedef struct {
1341253Slq150181 	uint8_t red[16];
1351253Slq150181 	uint8_t green[16];
1361253Slq150181 	uint8_t blue[16];
1371253Slq150181 } text_cmap_t;
1381253Slq150181 
1391253Slq150181 extern text_cmap_t cmap4_to_24;
1401253Slq150181 
141*7688SAaron.Zang@Sun.COM /*
142*7688SAaron.Zang@Sun.COM  * State structure for each virtual terminal emulator
143*7688SAaron.Zang@Sun.COM  */
144*7688SAaron.Zang@Sun.COM struct tem_vt_state {
145*7688SAaron.Zang@Sun.COM 	kmutex_t	tvs_lock;
146*7688SAaron.Zang@Sun.COM 	uchar_t		tvs_fbmode;	/* framebuffer mode */
147*7688SAaron.Zang@Sun.COM 	unsigned short	tvs_flags;	/* flags for this x3.64 terminal */
148*7688SAaron.Zang@Sun.COM 	int		tvs_state;	/* state in output esc seq processing */
149*7688SAaron.Zang@Sun.COM 	boolean_t	tvs_gotparam;	/* does output esc seq have a param */
150*7688SAaron.Zang@Sun.COM 
151*7688SAaron.Zang@Sun.COM 	int	tvs_curparam;	/* current param # of output esc seq */
152*7688SAaron.Zang@Sun.COM 	int	tvs_paramval;	/* value of current param */
153*7688SAaron.Zang@Sun.COM 	int	tvs_params[TEM_MAXPARAMS];  /* parameters of output esc seq */
154*7688SAaron.Zang@Sun.COM 	screen_pos_t	tvs_tabs[TEM_MAXTAB];	/* tab stops */
155*7688SAaron.Zang@Sun.COM 	int	tvs_ntabs;		/* number of tabs used */
156*7688SAaron.Zang@Sun.COM 	int	tvs_nscroll;		/* number of lines to scroll */
157*7688SAaron.Zang@Sun.COM 
158*7688SAaron.Zang@Sun.COM 	struct tem_char_pos tvs_s_cursor;	/* start cursor position */
159*7688SAaron.Zang@Sun.COM 	struct tem_char_pos tvs_c_cursor;	/* current cursor position */
160*7688SAaron.Zang@Sun.COM 	struct tem_char_pos tvs_r_cursor;	/* remembered cursor position */
1610Sstevel@tonic-gate 
162*7688SAaron.Zang@Sun.COM 	unsigned char	*tvs_outbuf;	/* place to keep incomplete lines */
163*7688SAaron.Zang@Sun.COM 	int		tvs_outbuf_size;
164*7688SAaron.Zang@Sun.COM 	int		tvs_outindex;	/* index into a_outbuf */
165*7688SAaron.Zang@Sun.COM 	void   		*tvs_pix_data;	/* pointer to tmp bitmap area */
166*7688SAaron.Zang@Sun.COM 	int		tvs_pix_data_size;
167*7688SAaron.Zang@Sun.COM 	text_color_t	tvs_fg_color;
168*7688SAaron.Zang@Sun.COM 	text_color_t	tvs_bg_color;
169*7688SAaron.Zang@Sun.COM 	int		tvs_first_line;	/* kernel console output begins */
1700Sstevel@tonic-gate 
171*7688SAaron.Zang@Sun.COM 	unsigned char	*tvs_screen_buf;	/* whole screen buffer */
172*7688SAaron.Zang@Sun.COM 	int		tvs_screen_buf_size;
173*7688SAaron.Zang@Sun.COM 	text_color_t	*tvs_fg_buf;	/* fg_color attribute cache */
174*7688SAaron.Zang@Sun.COM 	text_color_t	*tvs_bg_buf;	/* bg_color attribute cache */
175*7688SAaron.Zang@Sun.COM 	int		tvs_color_buf_size;
176*7688SAaron.Zang@Sun.COM 
177*7688SAaron.Zang@Sun.COM 	boolean_t	tvs_isactive;
178*7688SAaron.Zang@Sun.COM 	int		tvs_initialized;	/* initialization flag */
179*7688SAaron.Zang@Sun.COM 
180*7688SAaron.Zang@Sun.COM 	list_node_t	tvs_list_node;
181*7688SAaron.Zang@Sun.COM };
182*7688SAaron.Zang@Sun.COM _NOTE(MUTEX_PROTECTS_DATA(tem_vt_state::tvs_lock, tem_vt_state))
183*7688SAaron.Zang@Sun.COM 
184*7688SAaron.Zang@Sun.COM typedef struct tem_safe_callbacks {
185*7688SAaron.Zang@Sun.COM 	void (*tsc_display)(struct tem_vt_state *, unsigned char *, int,
1860Sstevel@tonic-gate 	    screen_pos_t, screen_pos_t, unsigned char, unsigned char,
1870Sstevel@tonic-gate 	    cred_t *, enum called_from);
188*7688SAaron.Zang@Sun.COM 	void (*tsc_copy)(struct tem_vt_state *,
1890Sstevel@tonic-gate 	    screen_pos_t, screen_pos_t, screen_pos_t, screen_pos_t,
1900Sstevel@tonic-gate 	    screen_pos_t, screen_pos_t, cred_t *, enum called_from);
191*7688SAaron.Zang@Sun.COM 	void (*tsc_cursor)(struct tem_vt_state *, short, cred_t *,
1920Sstevel@tonic-gate 	    enum called_from);
193*7688SAaron.Zang@Sun.COM 	void (*tsc_bit2pix)(struct tem_vt_state *, unsigned char,
1940Sstevel@tonic-gate 	    unsigned char, unsigned char);
195*7688SAaron.Zang@Sun.COM 	void (*tsc_cls)(struct tem_vt_state *, int,
1960Sstevel@tonic-gate 	    screen_pos_t, screen_pos_t, cred_t *, enum called_from);
197*7688SAaron.Zang@Sun.COM } tem_safe_callbacks_t;
1981253Slq150181 
1991253Slq150181 /*
200*7688SAaron.Zang@Sun.COM  * common term soft state structure shared by all virtual terminal emulators
2011253Slq150181  */
202*7688SAaron.Zang@Sun.COM typedef struct tem_state {
203*7688SAaron.Zang@Sun.COM 	ldi_handle_t	ts_hdl;	/* Framework handle for layered on dev */
204*7688SAaron.Zang@Sun.COM 	screen_size_t	ts_linebytes;	/* Layered on bytes per scan line */
205*7688SAaron.Zang@Sun.COM 
206*7688SAaron.Zang@Sun.COM 	int	ts_display_mode;	/* What mode we are in */
207*7688SAaron.Zang@Sun.COM 	struct	vis_polledio	*ts_fb_polledio;
208*7688SAaron.Zang@Sun.COM 
209*7688SAaron.Zang@Sun.COM 	struct tem_size ts_c_dimension;	/* window dimensions in characters */
210*7688SAaron.Zang@Sun.COM 	struct tem_size ts_p_dimension;	/* screen dimensions in pixels */
211*7688SAaron.Zang@Sun.COM 	struct tem_pix_pos ts_p_offset;	/* pix offset to center the display */
212*7688SAaron.Zang@Sun.COM 
213*7688SAaron.Zang@Sun.COM 	int	ts_pix_data_size;	/* size of bitmap data areas */
214*7688SAaron.Zang@Sun.COM 	int	ts_pdepth;		/* pixel depth */
215*7688SAaron.Zang@Sun.COM 	struct font	ts_font;	/* font table */
216*7688SAaron.Zang@Sun.COM 
217*7688SAaron.Zang@Sun.COM 	unsigned char	*ts_blank_line;	/* a blank line for scrolling */
218*7688SAaron.Zang@Sun.COM 	tem_safe_callbacks_t	*ts_callbacks;	/* internal output functions */
219*7688SAaron.Zang@Sun.COM 
220*7688SAaron.Zang@Sun.COM 	int	ts_initialized;		/* initialization flag */
221*7688SAaron.Zang@Sun.COM 
222*7688SAaron.Zang@Sun.COM 	tem_modechg_cb_t	ts_modechg_cb;
223*7688SAaron.Zang@Sun.COM 	tem_modechg_cb_arg_t	ts_modechg_arg;
224*7688SAaron.Zang@Sun.COM 
225*7688SAaron.Zang@Sun.COM 	tem_color_t	ts_init_color; /* initial color and attributes */
226*7688SAaron.Zang@Sun.COM 
227*7688SAaron.Zang@Sun.COM 	struct tem_vt_state	*ts_active;
228*7688SAaron.Zang@Sun.COM 	kmutex_t	ts_lock;
229*7688SAaron.Zang@Sun.COM 	list_t		ts_list;	/* chain of all tems */
230*7688SAaron.Zang@Sun.COM } tem_state_t;
231*7688SAaron.Zang@Sun.COM 
232*7688SAaron.Zang@Sun.COM extern tem_state_t tems;
233*7688SAaron.Zang@Sun.COM extern tem_safe_callbacks_t tem_safe_text_callbacks;
234*7688SAaron.Zang@Sun.COM extern tem_safe_callbacks_t tem_safe_pix_callbacks;
235*7688SAaron.Zang@Sun.COM 
236*7688SAaron.Zang@Sun.COM 
237*7688SAaron.Zang@Sun.COM /*
238*7688SAaron.Zang@Sun.COM  * tems_* fuctions mean that they just operate on the common soft state
239*7688SAaron.Zang@Sun.COM  * (tem_state_t), and tem_* functions mean that they operate on the
240*7688SAaron.Zang@Sun.COM  * per-tem structure (tem_vt_state). All "safe" interfaces are in tem_safe.c.
241*7688SAaron.Zang@Sun.COM  */
242*7688SAaron.Zang@Sun.COM void	tems_display_layered(struct vis_consdisplay *, cred_t *);
243*7688SAaron.Zang@Sun.COM void	tems_copy_layered(struct vis_conscopy *, cred_t *);
244*7688SAaron.Zang@Sun.COM void	tems_cursor_layered(struct vis_conscursor *, cred_t *);
245*7688SAaron.Zang@Sun.COM void	tems_safe_copy(struct vis_conscopy *, cred_t *, enum called_from);
2461253Slq150181 
247*7688SAaron.Zang@Sun.COM void	tem_pix_align(struct tem_vt_state *, cred_t *, enum called_from);
248*7688SAaron.Zang@Sun.COM void	tem_safe_check_first_time(struct tem_vt_state *tem, cred_t *,
249*7688SAaron.Zang@Sun.COM 	    enum called_from);
250*7688SAaron.Zang@Sun.COM void	tem_safe_reset_display(struct tem_vt_state *, cred_t *,
251*7688SAaron.Zang@Sun.COM 	    enum called_from, boolean_t, boolean_t);
252*7688SAaron.Zang@Sun.COM void	tem_safe_terminal_emulate(struct tem_vt_state *, uchar_t *, int,
253*7688SAaron.Zang@Sun.COM 	    cred_t *, enum called_from);
254*7688SAaron.Zang@Sun.COM void	tem_safe_text_display(struct tem_vt_state *, uchar_t *,
255*7688SAaron.Zang@Sun.COM 	    int, screen_pos_t, screen_pos_t,
256*7688SAaron.Zang@Sun.COM 	    text_color_t, text_color_t,
257*7688SAaron.Zang@Sun.COM 	    cred_t *, enum called_from);
258*7688SAaron.Zang@Sun.COM void	tem_safe_text_copy(struct tem_vt_state *,
259*7688SAaron.Zang@Sun.COM 	    screen_pos_t, screen_pos_t,
260*7688SAaron.Zang@Sun.COM 	    screen_pos_t, screen_pos_t,
261*7688SAaron.Zang@Sun.COM 	    screen_pos_t, screen_pos_t,
262*7688SAaron.Zang@Sun.COM 	    cred_t *, enum called_from);
263*7688SAaron.Zang@Sun.COM void	tem_safe_text_cursor(struct tem_vt_state *, short, cred_t *,
264*7688SAaron.Zang@Sun.COM 	    enum called_from);
265*7688SAaron.Zang@Sun.COM void	tem_safe_text_cls(struct tem_vt_state *,
266*7688SAaron.Zang@Sun.COM 	    int count, screen_pos_t row, screen_pos_t col,
267*7688SAaron.Zang@Sun.COM 	    cred_t *credp, enum called_from called_from);
268*7688SAaron.Zang@Sun.COM void	tem_safe_pix_display(struct tem_vt_state *, uchar_t *,
269*7688SAaron.Zang@Sun.COM 	    int, screen_pos_t, screen_pos_t,
270*7688SAaron.Zang@Sun.COM 	    text_color_t, text_color_t,
271*7688SAaron.Zang@Sun.COM 	    cred_t *, enum called_from);
272*7688SAaron.Zang@Sun.COM void	tem_safe_pix_copy(struct tem_vt_state *,
273*7688SAaron.Zang@Sun.COM 	    screen_pos_t, screen_pos_t,
274*7688SAaron.Zang@Sun.COM 	    screen_pos_t, screen_pos_t,
275*7688SAaron.Zang@Sun.COM 	    screen_pos_t, screen_pos_t,
276*7688SAaron.Zang@Sun.COM 	    cred_t *, enum called_from);
277*7688SAaron.Zang@Sun.COM void	tem_safe_pix_cursor(struct tem_vt_state *, short, cred_t *,
278*7688SAaron.Zang@Sun.COM 	    enum called_from);
279*7688SAaron.Zang@Sun.COM void	tem_safe_pix_bit2pix(struct tem_vt_state *, unsigned char,
280*7688SAaron.Zang@Sun.COM 	    unsigned char, unsigned char);
281*7688SAaron.Zang@Sun.COM void	tem_safe_pix_cls(struct tem_vt_state *, int, screen_pos_t, screen_pos_t,
282*7688SAaron.Zang@Sun.COM 	    cred_t *, enum called_from);
283*7688SAaron.Zang@Sun.COM void	tem_safe_pix_cls_range(struct tem_vt_state *,
284*7688SAaron.Zang@Sun.COM 	    screen_pos_t, int, int,
285*7688SAaron.Zang@Sun.COM 	    screen_pos_t, int, int,
286*7688SAaron.Zang@Sun.COM 	    boolean_t, cred_t *, enum called_from);
2871253Slq150181 
288*7688SAaron.Zang@Sun.COM void	tem_safe_pix_clear_entire_screen(struct tem_vt_state *,
289*7688SAaron.Zang@Sun.COM 	    cred_t *, enum called_from);
2901253Slq150181 
291*7688SAaron.Zang@Sun.COM void	tem_safe_get_color(struct tem_vt_state *, text_color_t *,
292*7688SAaron.Zang@Sun.COM 	    text_color_t *, uint8_t);
293*7688SAaron.Zang@Sun.COM void	set_font(struct font *, short *, short *, short, short);
2941253Slq150181 
295*7688SAaron.Zang@Sun.COM void	tem_safe_blank_screen(struct tem_vt_state *, cred_t *,
296*7688SAaron.Zang@Sun.COM 	    enum called_from);
297*7688SAaron.Zang@Sun.COM void	tem_safe_unblank_screen(struct tem_vt_state *, cred_t *,
298*7688SAaron.Zang@Sun.COM 	    enum called_from);
2990Sstevel@tonic-gate 
3000Sstevel@tonic-gate #ifdef __cplusplus
3010Sstevel@tonic-gate }
3020Sstevel@tonic-gate #endif
3030Sstevel@tonic-gate 
3040Sstevel@tonic-gate #endif /* _SYS_TEM_IMPL_H */
305