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