xref: /titanic_50/usr/src/uts/common/sys/tem_impl.h (revision c5c4113dfcabb1eed3d4bdf7609de5170027a794)
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 2007 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 #pragma ident	"%Z%%M%	%I%	%E% SMI"
36 
37 #ifdef __cplusplus
38 extern "C" {
39 #endif
40 
41 #include <sys/types.h>
42 #include <sys/sunddi.h>
43 #include <sys/sunldi.h>
44 #include <sys/visual_io.h>
45 #include <sys/font.h>
46 #include <sys/tem.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 #ifdef _HAVE_TEM_FIRMWARE
97 #define	DEFAULT_ANSI_FOREGROUND	ANSI_COLOR_BLACK
98 #define	DEFAULT_ANSI_BACKGROUND	ANSI_COLOR_WHITE
99 #else /* _HAVE_TEM_FIRMWARE */
100 #define	DEFAULT_ANSI_FOREGROUND	ANSI_COLOR_WHITE
101 #define	DEFAULT_ANSI_BACKGROUND	ANSI_COLOR_BLACK
102 #endif
103 
104 #define	BUF_LEN		160 /* Two lines of data can be processed at a time */
105 
106 typedef uint8_t text_color_t;
107 
108 typedef struct tem_color {
109 	text_color_t	fg_color;
110 	text_color_t	bg_color;
111 	unsigned short	a_flags;
112 } tem_color_t;
113 
114 struct tem_pix_pos {
115 	screen_pos_t	x;
116 	screen_pos_t	y;
117 };
118 
119 struct tem_char_pos {
120 	screen_pos_t	col;
121 	screen_pos_t	row;
122 };
123 
124 struct tem_size {
125 	screen_size_t	width;
126 	screen_size_t	height;
127 };
128 
129 typedef struct {
130 	uint8_t red[16];
131 	uint8_t green[16];
132 	uint8_t blue[16];
133 } text_cmap_t;
134 
135 extern text_cmap_t cmap4_to_24;
136 
137 struct tem;	/* Forward declare */
138 
139 enum called_from { CALLED_FROM_NORMAL, CALLED_FROM_STANDALONE };
140 
141 struct in_func_ptrs {
142 	void (*f_display)(struct tem *, unsigned char *, int,
143 	    screen_pos_t, screen_pos_t, unsigned char, unsigned char,
144 	    cred_t *, enum called_from);
145 	void (*f_copy)(struct tem *,
146 	    screen_pos_t, screen_pos_t, screen_pos_t, screen_pos_t,
147 	    screen_pos_t, screen_pos_t, cred_t *, enum called_from);
148 	void (*f_cursor)(struct tem *, short, cred_t *,
149 	    enum called_from);
150 	void (*f_bit2pix)(struct tem *, unsigned char,
151 	    unsigned char, unsigned char);
152 	void (*f_cls)(struct tem *, int,
153 	    screen_pos_t, screen_pos_t, cred_t *, enum called_from);
154 };
155 
156 /*
157  * State structure for terminal emulator
158  */
159 typedef struct tem_state {		/* state for tem x3.64 emulator */
160 	int	display_mode;		/* What mode we are in */
161 	screen_size_t	linebytes;	/* Layered on bytes per scan line */
162 	unsigned short	a_flags;	/* flags for this x3.64 terminal */
163 	int	a_state;	/* state in output esc seq processing */
164 	boolean_t	a_gotparam;	/* does output esc seq have a param */
165 	int	a_curparam;	/* current param # of output esc seq */
166 	int	a_paramval;	/* value of current param */
167 	int	a_params[TEM_MAXPARAMS];  /* parameters of output esc seq */
168 	screen_pos_t	a_tabs[TEM_MAXTAB];	/* tab stops */
169 	int	a_ntabs;		/* number of tabs used */
170 	int	a_nscroll;		/* number of lines to scroll */
171 	struct tem_char_pos a_s_cursor;	/* start cursor position */
172 	struct tem_char_pos a_c_cursor;	/* current cursor position */
173 	struct tem_char_pos a_r_cursor;	/* remembered cursor position */
174 	struct tem_size a_c_dimension;	/* window dimensions in characters */
175 	struct tem_size a_p_dimension;	/* screen dimensions in pixels */
176 	struct tem_pix_pos a_p_offset;	/* pix offset to center the display */
177 	unsigned char	*a_outbuf;	/* place to keep incomplete lines */
178 	unsigned char	*a_blank_line;	/* a blank line for scrolling */
179 	int	a_outindex;	/* index into a_outbuf */
180 	struct in_func_ptrs	in_fp;	/* internal output functions */
181 	struct font	a_font;	/* font table */
182 	int	a_pdepth;	/* pixel depth */
183 	int	a_initialized;	/* initialization flag */
184 	void   *a_pix_data;	/* pointer to tmp bitmap area */
185 	int	a_pix_data_size; /* size of bitmap data areas */
186 	text_color_t fg_color;
187 	text_color_t bg_color;
188 	int	first_line;	/* kernel console output begins */
189 } tem_state_t;
190 
191 /*
192  * State structure for terminal emulator
193  */
194 typedef struct tem {
195 #ifdef	_HAVE_TEM_FIRMWARE
196 	void (*cons_wrtvec)	/* PROM output gets redirected thru this vec. */
197 	    (struct tem *, uchar_t *, ssize_t, cred_t *);
198 #endif /* _HAVE_TEM_FIRMWARE */
199 	ldi_handle_t		hdl; /* Framework handle for layered on dev */
200 	dev_info_t		*dip; /* Our dip */
201 	kmutex_t		lock;
202 	struct vis_polledio	*fb_polledio;
203 	tem_state_t		*state;
204 	tem_modechg_cb_t	modechg_cb;
205 	tem_modechg_cb_arg_t	modechg_arg;
206 	tem_color_t		init_color; /* initial color and attributes */
207 } tem_t;
208 
209 void	tem_check_first_time(tem_t *tem, cred_t *, enum called_from);
210 void	tem_reset_colormap(tem_t *, cred_t *, enum called_from);
211 void	tem_align_cursor(tem_t *);
212 void	tem_reset_emulator(tem_t *, cred_t *, enum called_from, tem_color_t *);
213 void	tem_reset_display(tem_t *, cred_t *, enum called_from, int,
214 			tem_color_t *);
215 void	tem_display_layered(tem_t *, struct vis_consdisplay *, cred_t *);
216 void	tem_copy_layered(tem_t *, struct vis_conscopy *, cred_t *);
217 void	tem_cursor_layered(tem_t *, struct vis_conscursor *, cred_t *);
218 void	tem_terminal_emulate(tem_t *, uchar_t *, int, cred_t *,
219 			enum called_from);
220 void	tem_text_display(tem_t *, uchar_t *,
221 			int, screen_pos_t, screen_pos_t,
222 			text_color_t, text_color_t,
223 			cred_t *, enum called_from);
224 void	tem_text_copy(tem_t *,
225 			screen_pos_t, screen_pos_t,
226 			screen_pos_t, screen_pos_t,
227 			screen_pos_t, screen_pos_t,
228 			cred_t *, enum called_from);
229 void	tem_text_cursor(tem_t *, short, cred_t *, enum called_from);
230 void	tem_text_cls(tem_t *,
231 			int count, screen_pos_t row, screen_pos_t col,
232 			cred_t *credp, enum called_from called_from);
233 void	tem_pix_display(tem_t *, uchar_t *,
234 			int, screen_pos_t, screen_pos_t,
235 			text_color_t, text_color_t,
236 			cred_t *, enum called_from);
237 void	tem_pix_copy(tem_t *,
238 			screen_pos_t, screen_pos_t,
239 			screen_pos_t, screen_pos_t,
240 			screen_pos_t, screen_pos_t,
241 			cred_t *, enum called_from);
242 void	tem_copy(tem_t *,
243 			struct vis_conscopy *,
244 			cred_t *, enum called_from);
245 void	tem_pix_cursor(tem_t *, short, cred_t *, enum called_from);
246 void	tem_pix_cls(tem_t *, int, screen_pos_t, screen_pos_t,
247 			cred_t *, enum called_from);
248 void	tem_pix_cls_range(tem_t *,
249 			screen_pos_t, int, int,
250 			screen_pos_t, int, int,
251 			boolean_t, cred_t *, enum called_from);
252 
253 void	bit_to_pix24(tem_t *, uchar_t, text_color_t, text_color_t);
254 void	bit_to_pix8(tem_t *, uchar_t, text_color_t, text_color_t);
255 void	bit_to_pix4(tem_t *, uchar_t, text_color_t, text_color_t);
256 
257 text_color_t ansi_bg_to_solaris(tem_t *, int);
258 text_color_t ansi_fg_to_solaris(tem_t *, int);
259 
260 void	set_font(struct font *, short *, short *, short, short);
261 
262 #ifdef __cplusplus
263 }
264 #endif
265 
266 #endif /* _SYS_TEM_IMPL_H */
267