xref: /titanic_51/usr/src/uts/common/sys/tem_impl.h (revision 1e49577a7fcde812700ded04431b49d67cc57d6d)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 
22 /*
23  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 /*	Copyright (c) 1990, 1991 UNIX System Laboratories, Inc.	*/
28 
29 /*	Copyright (c) 1984, 1986, 1987, 1988, 1989, 1990 AT&T	*/
30 /*	  All Rights Reserved  	*/
31 
32 #ifndef	_SYS_TEM_IMPL_H
33 #define	_SYS_TEM_IMPL_H
34 
35 #ifdef __cplusplus
36 extern "C" {
37 #endif
38 
39 #include <sys/types.h>
40 #include <sys/sunddi.h>
41 #include <sys/sunldi.h>
42 #include <sys/visual_io.h>
43 #include <sys/font.h>
44 #include <sys/list.h>
45 #include <sys/tem.h>
46 #include <sys/note.h>
47 
48 /*
49  * definitions for ANSI x3.64 terminal control language parser
50  */
51 
52 #define	TEM_MAXPARAMS	5	/* maximum number of ANSI paramters */
53 #define	TEM_MAXTAB	40	/* maximum number of tab stops */
54 #define	TEM_MAXFKEY	30	/* max length of function key with <ESC>Q */
55 #define	MAX_TEM		2	/* max number of loadable terminal emulators */
56 
57 #define	TEM_SCROLL_UP		0
58 #define	TEM_SCROLL_DOWN		1
59 #define	TEM_SHIFT_LEFT		0
60 #define	TEM_SHIFT_RIGHT		1
61 
62 #define	TEM_ATTR_NORMAL		0x0000
63 #define	TEM_ATTR_REVERSE	0x0001
64 #define	TEM_ATTR_BOLD		0x0002
65 #define	TEM_ATTR_BLINK		0x0004
66 #define	TEM_ATTR_TRANSPARENT	0x0008
67 #define	TEM_ATTR_SCREEN_REVERSE	0x0010
68 
69 #define	ANSI_COLOR_BLACK	0
70 #define	ANSI_COLOR_WHITE	7
71 
72 #define	TEM_TEXT_WHITE		0
73 #define	TEM_TEXT_BLACK		1
74 #define	TEM_TEXT_BLACK24_RED	0x00
75 #define	TEM_TEXT_BLACK24_GREEN	0x00
76 #define	TEM_TEXT_BLACK24_BLUE	0x00
77 #define	TEM_TEXT_WHITE24_RED	0xff
78 #define	TEM_TEXT_WHITE24_GREEN	0xff
79 #define	TEM_TEXT_WHITE24_BLUE	0xff
80 
81 #define	A_STATE_START			0
82 #define	A_STATE_ESC			1
83 #define	A_STATE_CSI			2
84 #define	A_STATE_CSI_QMARK		3
85 #define	A_STATE_CSI_EQUAL		4
86 
87 /*
88  * Default number of rows and columns
89  */
90 #define	TEM_DEFAULT_ROWS	34
91 #define	TEM_DEFAULT_COLS	80
92 
93 /*
94  * Default foreground/background color
95  */
96 
97 #ifdef _HAVE_TEM_FIRMWARE
98 #define	DEFAULT_ANSI_FOREGROUND	ANSI_COLOR_BLACK
99 #define	DEFAULT_ANSI_BACKGROUND	ANSI_COLOR_WHITE
100 #else /* _HAVE_TEM_FIRMWARE */
101 #define	DEFAULT_ANSI_FOREGROUND	ANSI_COLOR_WHITE
102 #define	DEFAULT_ANSI_BACKGROUND	ANSI_COLOR_BLACK
103 #endif
104 
105 
106 #define	BUF_LEN		160 /* Two lines of data can be processed at a time */
107 
108 typedef uint8_t text_color_t;
109 
110 typedef struct tem_color {
111 	text_color_t	fg_color;
112 	text_color_t	bg_color;
113 	unsigned short	a_flags;
114 } tem_color_t;
115 
116 enum called_from { CALLED_FROM_NORMAL, CALLED_FROM_STANDALONE };
117 
118 struct tem_pix_pos {
119 	screen_pos_t	x;
120 	screen_pos_t	y;
121 };
122 
123 struct tem_char_pos {
124 	screen_pos_t	col;
125 	screen_pos_t	row;
126 };
127 
128 struct tem_size {
129 	screen_size_t	width;
130 	screen_size_t	height;
131 };
132 
133 typedef struct {
134 	uint8_t red[16];
135 	uint8_t green[16];
136 	uint8_t blue[16];
137 } text_cmap_t;
138 
139 extern text_cmap_t cmap4_to_24;
140 
141 /*
142  * State structure for each virtual terminal emulator
143  */
144 struct tem_vt_state {
145 	kmutex_t	tvs_lock;
146 	uchar_t		tvs_fbmode;	/* framebuffer mode */
147 	unsigned short	tvs_flags;	/* flags for this x3.64 terminal */
148 	int		tvs_state;	/* state in output esc seq processing */
149 	boolean_t	tvs_gotparam;	/* does output esc seq have a param */
150 
151 	int	tvs_curparam;	/* current param # of output esc seq */
152 	int	tvs_paramval;	/* value of current param */
153 	int	tvs_params[TEM_MAXPARAMS];  /* parameters of output esc seq */
154 	screen_pos_t	tvs_tabs[TEM_MAXTAB];	/* tab stops */
155 	int	tvs_ntabs;		/* number of tabs used */
156 	int	tvs_nscroll;		/* number of lines to scroll */
157 
158 	struct tem_char_pos tvs_s_cursor;	/* start cursor position */
159 	struct tem_char_pos tvs_c_cursor;	/* current cursor position */
160 	struct tem_char_pos tvs_r_cursor;	/* remembered cursor position */
161 
162 	unsigned char	*tvs_outbuf;	/* place to keep incomplete lines */
163 	int		tvs_outbuf_size;
164 	int		tvs_outindex;	/* index into a_outbuf */
165 	void   		*tvs_pix_data;	/* pointer to tmp bitmap area */
166 	int		tvs_pix_data_size;
167 	text_color_t	tvs_fg_color;
168 	text_color_t	tvs_bg_color;
169 	int		tvs_first_line;	/* kernel console output begins */
170 
171 	unsigned char	*tvs_screen_buf;	/* whole screen buffer */
172 	int		tvs_screen_buf_size;
173 	text_color_t	*tvs_fg_buf;	/* fg_color attribute cache */
174 	text_color_t	*tvs_bg_buf;	/* bg_color attribute cache */
175 	int		tvs_color_buf_size;
176 
177 	boolean_t	tvs_isactive;
178 	int		tvs_initialized;	/* initialization flag */
179 
180 	list_node_t	tvs_list_node;
181 };
182 _NOTE(MUTEX_PROTECTS_DATA(tem_vt_state::tvs_lock, tem_vt_state))
183 
184 typedef struct tem_safe_callbacks {
185 	void (*tsc_display)(struct tem_vt_state *, unsigned char *, int,
186 	    screen_pos_t, screen_pos_t, unsigned char, unsigned char,
187 	    cred_t *, enum called_from);
188 	void (*tsc_copy)(struct tem_vt_state *,
189 	    screen_pos_t, screen_pos_t, screen_pos_t, screen_pos_t,
190 	    screen_pos_t, screen_pos_t, cred_t *, enum called_from);
191 	void (*tsc_cursor)(struct tem_vt_state *, short, cred_t *,
192 	    enum called_from);
193 	void (*tsc_bit2pix)(struct tem_vt_state *, unsigned char,
194 	    unsigned char, unsigned char);
195 	void (*tsc_cls)(struct tem_vt_state *, int,
196 	    screen_pos_t, screen_pos_t, cred_t *, enum called_from);
197 } tem_safe_callbacks_t;
198 
199 /*
200  * common term soft state structure shared by all virtual terminal emulators
201  */
202 typedef struct tem_state {
203 	ldi_handle_t	ts_hdl;	/* Framework handle for layered on dev */
204 	screen_size_t	ts_linebytes;	/* Layered on bytes per scan line */
205 
206 	int	ts_display_mode;	/* What mode we are in */
207 	struct	vis_polledio	*ts_fb_polledio;
208 
209 	struct tem_size ts_c_dimension;	/* window dimensions in characters */
210 	struct tem_size ts_p_dimension;	/* screen dimensions in pixels */
211 	struct tem_pix_pos ts_p_offset;	/* pix offset to center the display */
212 
213 	int	ts_pix_data_size;	/* size of bitmap data areas */
214 	int	ts_pdepth;		/* pixel depth */
215 	struct font	ts_font;	/* font table */
216 
217 	unsigned char	*ts_blank_line;	/* a blank line for scrolling */
218 	tem_safe_callbacks_t	*ts_callbacks;	/* internal output functions */
219 
220 	int	ts_initialized;		/* initialization flag */
221 
222 	tem_modechg_cb_t	ts_modechg_cb;
223 	tem_modechg_cb_arg_t	ts_modechg_arg;
224 
225 	tem_color_t	ts_init_color; /* initial color and attributes */
226 
227 	struct tem_vt_state	*ts_active;
228 	kmutex_t	ts_lock;
229 	list_t		ts_list;	/* chain of all tems */
230 } tem_state_t;
231 
232 extern tem_state_t tems;
233 extern tem_safe_callbacks_t tem_safe_text_callbacks;
234 extern tem_safe_callbacks_t tem_safe_pix_callbacks;
235 
236 
237 /*
238  * tems_* fuctions mean that they just operate on the common soft state
239  * (tem_state_t), and tem_* functions mean that they operate on the
240  * per-tem structure (tem_vt_state). All "safe" interfaces are in tem_safe.c.
241  */
242 void	tems_display_layered(struct vis_consdisplay *, cred_t *);
243 void	tems_copy_layered(struct vis_conscopy *, cred_t *);
244 void	tems_cursor_layered(struct vis_conscursor *, cred_t *);
245 void	tems_safe_copy(struct vis_conscopy *, cred_t *, enum called_from);
246 
247 void	tem_pix_align(struct tem_vt_state *, cred_t *, enum called_from);
248 void	tem_safe_check_first_time(struct tem_vt_state *tem, cred_t *,
249 	    enum called_from);
250 void	tem_safe_reset_display(struct tem_vt_state *, cred_t *,
251 	    enum called_from, boolean_t, boolean_t);
252 void	tem_safe_terminal_emulate(struct tem_vt_state *, uchar_t *, int,
253 	    cred_t *, enum called_from);
254 void	tem_safe_text_display(struct tem_vt_state *, uchar_t *,
255 	    int, screen_pos_t, screen_pos_t,
256 	    text_color_t, text_color_t,
257 	    cred_t *, enum called_from);
258 void	tem_safe_text_copy(struct tem_vt_state *,
259 	    screen_pos_t, screen_pos_t,
260 	    screen_pos_t, screen_pos_t,
261 	    screen_pos_t, screen_pos_t,
262 	    cred_t *, enum called_from);
263 void	tem_safe_text_cursor(struct tem_vt_state *, short, cred_t *,
264 	    enum called_from);
265 void	tem_safe_text_cls(struct tem_vt_state *,
266 	    int count, screen_pos_t row, screen_pos_t col,
267 	    cred_t *credp, enum called_from called_from);
268 void	tem_safe_pix_display(struct tem_vt_state *, uchar_t *,
269 	    int, screen_pos_t, screen_pos_t,
270 	    text_color_t, text_color_t,
271 	    cred_t *, enum called_from);
272 void	tem_safe_pix_copy(struct tem_vt_state *,
273 	    screen_pos_t, screen_pos_t,
274 	    screen_pos_t, screen_pos_t,
275 	    screen_pos_t, screen_pos_t,
276 	    cred_t *, enum called_from);
277 void	tem_safe_pix_cursor(struct tem_vt_state *, short, cred_t *,
278 	    enum called_from);
279 void	tem_safe_pix_bit2pix(struct tem_vt_state *, unsigned char,
280 	    unsigned char, unsigned char);
281 void	tem_safe_pix_cls(struct tem_vt_state *, int, screen_pos_t, screen_pos_t,
282 	    cred_t *, enum called_from);
283 void	tem_safe_pix_cls_range(struct tem_vt_state *,
284 	    screen_pos_t, int, int,
285 	    screen_pos_t, int, int,
286 	    boolean_t, cred_t *, enum called_from);
287 
288 void	tem_safe_pix_clear_entire_screen(struct tem_vt_state *,
289 	    cred_t *, enum called_from);
290 
291 void	tem_safe_get_color(struct tem_vt_state *, text_color_t *,
292 	    text_color_t *, uint8_t);
293 void	set_font(struct font *, short *, short *, short, short);
294 
295 void	tem_safe_blank_screen(struct tem_vt_state *, cred_t *,
296 	    enum called_from);
297 void	tem_safe_unblank_screen(struct tem_vt_state *, cred_t *,
298 	    enum called_from);
299 
300 #ifdef __cplusplus
301 }
302 #endif
303 
304 #endif /* _SYS_TEM_IMPL_H */
305