xref: /illumos-gate/usr/src/uts/common/sys/visual_io.h (revision fa9eb22261c7b7a35c7a6957acb3c2b26c39e15b)
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 #ifndef _SYS_VISUAL_IO_H
28 #define	_SYS_VISUAL_IO_H
29 
30 #ifdef __cplusplus
31 extern "C" {
32 #endif
33 
34 #define	VIOC	('V' << 8)
35 #define	VIOCF	('F' << 8)
36 
37 
38 /*
39  * Device Identification
40  *
41  * VIS_GETIDENTIFIER returns an identifier string to uniquely identify
42  * a device type used in the Solaris VISUAL environment.  The identifier
43  * must be unique.  We suggest the convention:
44  *
45  *	<companysymbol><devicetype>
46  *
47  * for example: SUNWcg6
48  */
49 
50 #define	VIS_MAXNAMELEN 128
51 
52 struct vis_identifier {
53 	char name[VIS_MAXNAMELEN];	/* <companysymbol><devicename>	*/
54 };
55 
56 #define	VIS_GETIDENTIFIER	(VIOC | 0)
57 
58 
59 
60 /*
61  * Hardware Cursor Control
62  *
63  * Devices with hardware cursors may implement these ioctls in their
64  * kernel device drivers.
65  */
66 
67 
68 struct vis_cursorpos {
69 	short x;		/* cursor x coordinate	*/
70 	short y;		/* cursor y coordinate	*/
71 };
72 
73 struct vis_cursorcmap {
74 	int		version;	/* version			*/
75 	int		reserved;
76 	unsigned char	*red;		/* red color map elements	*/
77 	unsigned char	*green;		/* green color map elements	*/
78 	unsigned char	*blue;		/* blue color map elements	*/
79 };
80 
81 
82 /*
83  * These ioctls fetch and set various cursor attributes, using the
84  * vis_cursor struct.
85  */
86 
87 #define	VIS_SETCURSOR	(VIOCF|24)
88 #define	VIS_GETCURSOR	(VIOCF|25)
89 
90 struct vis_cursor {
91 	short			set;		/* what to set		*/
92 	short			enable;		/* cursor on/off	*/
93 	struct vis_cursorpos	pos;		/* cursor position	*/
94 	struct vis_cursorpos	hot;		/* cursor hot spot	*/
95 	struct vis_cursorcmap	cmap;		/* color map info	*/
96 	struct vis_cursorpos	size;		/* cursor bit map size	*/
97 	char			*image;		/* cursor image bits	*/
98 	char			*mask;		/* cursor mask bits	*/
99 };
100 
101 #define	VIS_CURSOR_SETCURSOR	0x01		/* set cursor		*/
102 #define	VIS_CURSOR_SETPOSITION	0x02		/* set cursor position	*/
103 #define	VIS_CURSOR_SETHOTSPOT	0x04		/* set cursor hot spot	*/
104 #define	VIS_CURSOR_SETCOLORMAP	0x08		/* set cursor colormap	*/
105 #define	VIS_CURSOR_SETSHAPE	0x10		/* set cursor shape	*/
106 
107 #define	VIS_CURSOR_SETALL	(VIS_CURSOR_SETCURSOR | \
108     VIS_CURSOR_SETPOSITION	| \
109     VIS_CURSOR_SETHOTSPOT	| \
110     VIS_CURSOR_SETCOLORMAP	| \
111     VIS_CURSOR_SETSHAPE)
112 
113 
114 /*
115  * These ioctls fetch and move the current cursor position, using the
116  * vis_cursorposition struct.
117  */
118 
119 #define	VIS_MOVECURSOR		(VIOCF|26)
120 #define	VIS_GETCURSORPOS	(VIOCF|27)
121 
122 /*
123  * VIS_SETCMAP:
124  * VIS_GETCMAP:
125  * Set/Get the indicated color map entries.  The index states the first
126  * color to be update and count specifies the number of entries to be
127  * updated from index.  red, green, and blue are arrays of color
128  * values.  The length of the arrays is count.
129  */
130 #define	VIS_GETCMAP	(VIOC|9)
131 #define	VIS_PUTCMAP	(VIOC|10)
132 struct vis_cmap {
133 	int		index; /* Index into colormap to start updating */
134 	int		count; /* Number of entries to update */
135 	unsigned char	*red; /* List of red values */
136 	unsigned char	*green; /* List of green values */
137 	unsigned char	*blue; /* List of blue values */
138 };
139 
140 
141 #if defined(_KERNEL) || defined(_STANDALONE)
142 /*
143  * The following ioctls are used for communication between the layered
144  * device and the framebuffer.  The layered driver calls the framebuffer
145  * with these ioctls.
146  *
147  * On machines that don't have a prom, kmdb uses the kernel to display
148  * characters.  The kernel in turn will use the routines returned by
149  * VIS_DEVINIT to ask the framebuffer driver to display the data.  The
150  * framebuffer driver CANNOT use any DDI services to display this data.  It
151  * must just dump the data to the framebuffer.  In particular, the mutex and
152  * copy routines do not work.
153  *
154  * On machines without a prom, the framebuffer driver must implement all
155  * of these ioctls to be a console.  On machines with a prom, the
156  * framebuffer driver can set vis_devinit.polledio to NULL.
157  */
158 typedef short screen_pos_t;
159 typedef short screen_size_t;
160 
161 /*
162  * Union of pixel depths
163  */
164 typedef union {
165 	unsigned char mono;		/* one-bit */
166 	unsigned char four;		/* four bit */
167 	unsigned char eight;		/* eight bit */
168 	unsigned char sixteen[2];	/* 16 bit */
169 	unsigned char twentyfour[3];	/* 24 bit */
170 	unsigned char thirtytwo[4];	/* 32 bit */
171 } color_t;
172 
173 /*
174  * VIS_DEVINIT:
175  * Initialize the framebuffer as a console device.  The terminal emulator
176  * will provide the following structure to the device driver to be filled in.
177  * The driver is expected to fill it in.
178  *
179  * ioctl(fd, VIS_DEVINIT, struct vis_devinit *)
180  */
181 #define	VIS_DEVINIT	(VIOC|1)
182 #define	VIS_CONS_REV		5 /* Console IO interface version */
183 /* Modes */
184 #define	VIS_TEXT		0 /* Use text mode when displaying data */
185 #define	VIS_PIXEL		1 /* Use pixel mode when displaying data */
186 
187 /*
188  * VIS_DEVFINI:
189  * Tells the framebuffer that it is no longer being used as a console.
190  *
191  * ioctl(fd, VIS_DEVFINI, unused)
192  */
193 #define	VIS_DEVFINI	(VIOC|2)
194 
195 /*
196  * VIS_CONSCURSOR:
197  * Display/Hide cursor on the screen.  The layered driver uses this ioctl to
198  * display, hide, and move the cursor on the console.  The framebuffer driver
199  * is expected to draw a cursor at position (col,row) of size width x height.
200  *
201  * ioctl(fd, VIS_CONSCURSOR, struct vis_conscursor *)
202  */
203 #define	VIS_CONSCURSOR		(VIOC|3)
204 /* Cursor action - Either display or hide cursor */
205 #define	VIS_HIDE_CURSOR		0
206 #define	VIS_DISPLAY_CURSOR	1
207 #define	VIS_GET_CURSOR		2
208 
209 /*
210  * VIS_CONSDISPLAY:
211  * Display data on the framebuffer.  The data will be in the form specified
212  * by the driver during console initialization (see VIS_CONSDEVINIT above).
213  * The driver is expected to display the data at location (row,col).  Width
214  * and height specify the size of the data.
215  *
216  * ioctl(fd, VIS_CONSDISPLAY, struct vis_consdisplay *)
217  */
218 
219 #define	VIS_CONSDISPLAY		(VIOC|5)
220 
221 /*
222  * VIS_CONSCOPY:
223  * Move data on the framebuffer.  Used to scroll the screen by the terminal
224  * emulator or to move data by applications.  The driver must copy the data
225  * specified by the rectangle (s_col,s_row),(e_col,e_row) to the location
226  * which starts at (t_col,t_row), handling overlapping copies correctly.
227  *
228  * ioctl(fd, VIS_CONSCOPY, struct vis_conscopy *)
229  */
230 #define	VIS_CONSCOPY		(VIOC|7)
231 
232 /*
233  * VIS_CONSCLEAR:
234  * Clear the screen using provided color. Used on VIS_PIXEL mode.
235  *
236  * ioctl(fd, VIS_CONSCLEAR, struct vis_consclear *)
237  */
238 #define	VIS_CONSCLEAR		(VIOC|8)
239 
240 struct vis_consclear {
241 	color_t	bg_color; /* Background color */
242 };
243 
244 struct vis_consdisplay {
245 	screen_pos_t	row; /* Row to display data at */
246 	screen_pos_t	col; /* Col to display data at */
247 	screen_size_t	width; /* Width of data */
248 	screen_size_t	height; /* Height of data */
249 	unsigned char	*data; /* Data to display */
250 	color_t		fg_color; /* Foreground color */
251 	color_t		bg_color; /* Background color */
252 };
253 
254 struct vis_conscopy {
255 	screen_pos_t	s_row; /* Starting row */
256 	screen_pos_t	s_col; /* Starting col */
257 	screen_pos_t	e_row; /* Ending row */
258 	screen_pos_t	e_col; /* Ending col */
259 	screen_pos_t	t_row; /* Row to move to */
260 	screen_pos_t	t_col; /* Col to move to */
261 };
262 
263 struct vis_conscursor {
264 	screen_pos_t	row; /* Row to display cursor at */
265 	screen_pos_t	col; /* Col to display cursor at */
266 	screen_size_t	width; /* Width of cursor */
267 	screen_size_t	height; /* Height of cursor */
268 	color_t		fg_color; /* Foreground color */
269 	color_t		bg_color; /* Background color */
270 	short		action; /* Hide or show cursor */
271 };
272 
273 /*
274  * Each software-console-capable frame buffer driver defines its own
275  * instance of this (with its own name!) and casts to/from this at the
276  * interface with the terminal emulator.  These yield somewhat better
277  * type checking than "void *".
278  */
279 struct vis_polledio_arg;
280 struct vis_modechg_arg;
281 
282 /*
283  * Each software-console-capable frame buffer driver supplies these routines
284  * for I/O from "polled" contexts - kmdb, OBP, etc.  No system services are
285  * available.
286  */
287 struct vis_polledio {
288 	struct vis_polledio_arg	*arg;
289 	void	(*display)(struct vis_polledio_arg *, struct vis_consdisplay *);
290 	void	(*copy)(struct vis_polledio_arg *, struct vis_conscopy *);
291 	void	(*cursor)(struct vis_polledio_arg *, struct vis_conscursor *);
292 };
293 
294 struct vis_devinit; /* forward decl. for typedef */
295 
296 typedef void (*vis_modechg_cb_t)(struct vis_modechg_arg *,
297     struct vis_devinit *);
298 
299 typedef uint32_t (*color_map_fn_t)(uint8_t color);
300 
301 struct vis_devinit {
302 	/*
303 	 * This set of fields are used as parameters passed from the
304 	 * layered framebuffer driver to the terminal emulator.
305 	 */
306 	int		version;	/* Console IO interface version */
307 	screen_size_t	width;		/* Width of the device */
308 	screen_size_t	height;		/* Height of the device */
309 	screen_size_t	linebytes;	/* Bytes per scan line */
310 	int		depth;		/* Device depth */
311 	color_map_fn_t	color_map;	/* Color map tem -> fb */
312 	short		mode;		/* Mode to use when displaying data */
313 	struct vis_polledio *polledio;	/* Polled output routines */
314 
315 	/*
316 	 * The following fields are used as parameters passed from the
317 	 * terminal emulator to the underlying framebuffer driver.
318 	 */
319 	vis_modechg_cb_t modechg_cb;	/* Video mode change callback */
320 	struct vis_modechg_arg *modechg_arg; /* Mode change cb arg */
321 };
322 
323 struct visual_ops {
324 	const struct vis_identifier *ident;
325 	int (*kdsetmode)(int);
326 	int (*devinit)(struct vis_devinit *);
327 	void (*cons_copy)(struct vis_conscopy *);
328 	void (*cons_display)(struct vis_consdisplay *);
329 	void (*cons_cursor)(struct vis_conscursor *);
330 	int (*cons_clear)(struct vis_consclear *);
331 	int (*cons_put_cmap)(struct vis_cmap *);
332 };
333 
334 #endif	/* _KERNEL || _STANDALONE */
335 
336 #ifdef __cplusplus
337 }
338 #endif
339 
340 #endif	/* !_SYS_VISUAL_IO_H */
341