1/* $OpenBSD: wsdisplayvar.h,v 1.38 2020/09/13 10:05:46 fcambus Exp $ */
2/* $NetBSD: wsdisplayvar.h,v 1.30 2005/02/04 02:10:49 perry Exp $ */
3
4/*
5 * Copyright (c) 1996, 1997 Christopher G. Demetriou.  All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 *    notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 *    notice, this list of conditions and the following disclaimer in the
14 *    documentation and/or other materials provided with the distribution.
15 * 3. All advertising materials mentioning features or use of this software
16 *    must display the following acknowledgement:
17 *      This product includes software developed by Christopher G. Demetriou
18 *	for the NetBSD Project.
19 * 4. The name of the author may not be used to endorse or promote products
20 *    derived from this software without specific prior written permission
21 *
22 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
23 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
24 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
25 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
26 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
27 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
31 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 */
33
34/*
35 * Default to white on black except on Sun hardware, where we default
36 * to black on white to match the firmware console.
37 */
38#ifndef WS_DEFAULT_FG
39#if defined(__sparc64__)
40#define WS_DEFAULT_FG WSCOL_BLACK
41#else
42#define WS_DEFAULT_FG WSCOL_WHITE
43#endif
44#endif
45#ifndef WS_DEFAULT_BG
46#if defined(__sparc64__)
47#define WS_DEFAULT_BG WSCOL_WHITE
48#else
49#define WS_DEFAULT_BG WSCOL_BLACK
50#endif
51#endif
52
53struct device;
54
55/*
56 * WSDISPLAY interfaces
57 */
58
59#define WSDISPLAY_MAXSCREEN	12
60
61/*
62 * Emulation functions, for displays that can support glass-tty terminal
63 * emulations.  These are character oriented, with row and column
64 * numbers starting at zero in the upper left hand corner of the
65 * screen.
66 *
67 * These are used only when emulating a terminal.  Therefore, displays
68 * drivers which cannot emulate terminals do not have to provide them.
69 *
70 * There is a "void *" cookie provided by the display driver associated
71 * with these functions, which is passed to them when they are invoked.
72 */
73struct wsdisplay_emulops {
74	int	(*cursor)(void *c, int on, int row, int col);
75	int	(*mapchar)(void *, int, unsigned int *);
76	int	(*putchar)(void *c, int row, int col, u_int uc, uint32_t attr);
77	int	(*copycols)(void *c, int row, int srccol, int dstcol,
78		    int ncols);
79	int	(*erasecols)(void *c, int row, int startcol, int ncols,
80		    uint32_t);
81	int	(*copyrows)(void *c, int srcrow, int dstrow, int nrows);
82	int	(*eraserows)(void *c, int row, int nrows, uint32_t attr);
83	int	(*pack_attr)(void *c, int fg, int bg, int flags,
84		    uint32_t *attrp);
85	void	(*unpack_attr)(void *c, uint32_t attr, int *fg, int *bg,
86		    int *ul);
87/* fg / bg values. Made identical to ANSI terminal color codes. */
88#define WSCOL_BLACK	0
89#define WSCOL_RED	1
90#define WSCOL_GREEN	2
91#define WSCOL_BROWN	3
92#define WSCOL_BLUE	4
93#define WSCOL_MAGENTA	5
94#define WSCOL_CYAN	6
95#define WSCOL_WHITE	7
96/* flag values: */
97#define WSATTR_REVERSE	1
98#define WSATTR_HILIT	2
99#define WSATTR_BLINK	4
100#define WSATTR_UNDERLINE 8
101#define WSATTR_WSCOLORS 16
102};
103
104#define	WSSCREEN_NAME_SIZE	16
105
106struct wsscreen_descr {
107	char name[WSSCREEN_NAME_SIZE];
108	int ncols, nrows;
109	const struct wsdisplay_emulops *textops;
110	int fontwidth, fontheight;
111	int capabilities;
112#define WSSCREEN_WSCOLORS	1	/* minimal color capability */
113#define WSSCREEN_REVERSE	2	/* can display reversed */
114#define WSSCREEN_HILIT		4	/* can highlight (however) */
115#define WSSCREEN_BLINK		8	/* can blink */
116#define WSSCREEN_UNDERLINE	16	/* can underline */
117};
118
119/*
120 * Character cell description (for emulation mode).
121 */
122struct wsdisplay_charcell {
123	u_int		uc;
124	uint32_t	attr;
125};
126
127struct wsdisplay_font;
128/*
129 * Display access functions, invoked by user-land programs which require
130 * direct device access, such as X11.
131 *
132 * There is a "void *" cookie provided by the display driver associated
133 * with these functions, which is passed to them when they are invoked.
134 */
135struct wsdisplay_accessops {
136	int	(*ioctl)(void *v, u_long cmd, caddr_t data, int flag,
137		    struct proc *p);
138	paddr_t	(*mmap)(void *v, off_t off, int prot);
139	int	(*alloc_screen)(void *, const struct wsscreen_descr *,
140				     void **, int *, int *, uint32_t *);
141	void	(*free_screen)(void *, void *);
142	int	(*show_screen)(void *, void *, int,
143			       void (*) (void *, int, int), void *);
144	int	(*load_font)(void *, void *, struct wsdisplay_font *);
145	int	(*list_font)(void *, struct wsdisplay_font *);
146	void	(*scrollback)(void *, void *, int);
147	int	(*getchar)(void *, int, int, struct wsdisplay_charcell *);
148	void	(*burn_screen)(void *, u_int, u_int);
149	void	(*pollc)(void *, int);
150	void	(*enter_ddb)(void *, void *);
151};
152
153/* passed to wscons by the video driver to tell about its capabilities */
154struct wsscreen_list {
155	int nscreens;
156	const struct wsscreen_descr **screens;
157};
158
159/*
160 * Attachment information provided by wsemuldisplaydev devices when attaching
161 * wsdisplay units.
162 */
163struct wsemuldisplaydev_attach_args {
164	int	console;				/* is it console? */
165	int	primary;				/* is it primary? */
166	const struct wsscreen_list *scrdata;		/* screen cfg info */
167	const struct wsdisplay_accessops *accessops;	/* access ops */
168	void	*accesscookie;				/* access cookie */
169	u_int	defaultscreens;				/* screens to create */
170};
171
172#define	WSEMULDISPLAYDEVCF_CONSOLE	0
173#define	wsemuldisplaydevcf_console	cf_loc[WSEMULDISPLAYDEVCF_CONSOLE]	/* spec'd as console? */
174#define	WSEMULDISPLAYDEVCF_CONSOLE_UNK	-1
175#define WSEMULDISPLAYDEVCF_PRIMARY	1
176#define	wsemuldisplaydevcf_primary	cf_loc[WSEMULDISPLAYDEVCF_PRIMARY]	/* spec'd as primary? */
177#define	WSEMULDISPLAYDEVCF_PRIMARY_UNK	-1
178#define	WSEMULDISPLAYDEVCF_MUX		2
179#define	wsemuldisplaydevcf_mux		cf_loc[WSEMULDISPLAYDEVCF_MUX]
180#define	WSDISPLAYDEVCF_MUX		0
181#define	wsdisplaydevcf_mux		cf_loc[WSDISPLAYDEVCF_MUX]
182
183struct wscons_syncops {
184	int (*detach)(void *, int, void (*)(void *, int, int), void *);
185	int (*attach)(void *, int, void (*)(void *, int, int), void *);
186	int (*check)(void *);
187	void (*destroy)(void *);
188};
189
190/*
191 * Autoconfiguration helper functions.
192 */
193void	wsdisplay_cnattach(const struct wsscreen_descr *, void *,
194				int, int, uint32_t);
195int	wsemuldisplaydevprint(void *, const char *);
196int	wsemuldisplaydevsubmatch(struct device *, void *, void *);
197
198/*
199 * Console interface.
200 */
201void	wsdisplay_cnputc(dev_t dev, int i);
202
203/*
204 * for use by compatibility code
205 */
206struct wsdisplay_softc;
207struct wsscreen;
208int wsscreen_attach_sync(struct wsscreen *,
209			      const struct wscons_syncops *, void *);
210int wsscreen_detach_sync(struct wsscreen *);
211int wsscreen_lookup_sync(struct wsscreen *,
212			      const struct wscons_syncops *, void **);
213
214int wsdisplay_maxscreenidx(struct wsdisplay_softc *);
215int wsdisplay_screenstate(struct wsdisplay_softc *, int);
216int wsdisplay_getactivescreen(struct wsdisplay_softc *);
217int wsscreen_switchwait(struct wsdisplay_softc *, int);
218
219int wsdisplay_internal_ioctl(struct wsdisplay_softc *sc,
220				  struct wsscreen *,
221				  u_long cmd, caddr_t data,
222				  int flag, struct proc *p);
223
224int wsdisplay_usl_ioctl1(struct wsdisplay_softc *,
225			     u_long, caddr_t, int, struct proc *);
226
227int wsdisplay_usl_ioctl2(struct wsdisplay_softc *, struct wsscreen *,
228			     u_long, caddr_t, int, struct proc *);
229
230int wsdisplay_cfg_ioctl(struct wsdisplay_softc *sc,
231			     u_long cmd, caddr_t data,
232			     int flag, struct proc *p);
233
234/*
235 * for general use
236 */
237#define WSDISPLAY_NULLSCREEN	-1
238void wsdisplay_switchtoconsole(void);
239void wsdisplay_enter_ddb(void);
240void wsdisplay_suspend(void);
241void wsdisplay_resume(void);
242const struct wsscreen_descr *
243    wsdisplay_screentype_pick(const struct wsscreen_list *, const char *);
244
245struct wsdisplay_param;
246extern int (*ws_get_param)(struct wsdisplay_param *);
247extern int (*ws_set_param)(struct wsdisplay_param *);
248
249void wsdisplay_brightness_step(struct device *, int);
250void wsdisplay_brightness_zero(struct device *);
251void wsdisplay_brightness_cycle(struct device *);
252
253/*
254 * for use by wskbd
255 */
256void wsdisplay_burn(void *v, u_int flags);
257void wsscrollback(void *v, int op);
258
259#define WSDISPLAY_SCROLL_BACKWARD	0
260#define WSDISPLAY_SCROLL_FORWARD	1
261#define WSDISPLAY_SCROLL_RESET		2
262
263/*
264 * screen burner
265 */
266#define	WSDISPLAY_DEFBURNOUT_MSEC	0	/* disabled */
267#define	WSDISPLAY_DEFBURNIN_MSEC	250	/* milliseconds */
268