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