xref: /freebsd/sys/dev/fb/fbreg.h (revision e0c4386e7e71d93b0edc0c8fa156263fc4a8b0b6)
1 /*-
2  * SPDX-License-Identifier: BSD-2-Clause
3  *
4  * Copyright (c) 1999 Kazutaka YOKOTA <yokota@zodiac.mech.utsunomiya-u.ac.jp>
5  * 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 as
12  *    the first lines of this file unmodified.
13  * 2. Redistributions in binary form must reproduce the above copyright
14  *    notice, this list of conditions and the following disclaimer in the
15  *    documentation and/or other materials provided with the distribution.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27  */
28 
29 #ifndef _DEV_FB_FBREG_H_
30 #define _DEV_FB_FBREG_H_
31 
32 #ifdef _KERNEL
33 
34 #define V_MAX_ADAPTERS		8		/* XXX */
35 
36 /* some macros */
37 #if defined(__amd64__) || defined(__i386__)
38 
39 static __inline void
40 copyw(uint16_t *src, uint16_t *dst, size_t size)
41 {
42 	size >>= 1;
43 	while (size--)
44 		*dst++ = *src++;
45 }
46 #define bcopy_io(s, d, c)	copyw((void*)(s), (void*)(d), (c))
47 #define bcopy_toio(s, d, c)	copyw((void*)(s), (void*)(d), (c))
48 #define bcopy_fromio(s, d, c)	copyw((void*)(s), (void*)(d), (c))
49 #define bzero_io(d, c)		bzero((void *)(d), (c))
50 #define fill_io(p, d, c)	fill((p), (void *)(d), (c))
51 #define fillw_io(p, d, c)	fillw((p), (void *)(d), (c))
52 #elif defined(__powerpc__)
53 
54 #define bcopy_io(s, d, c)	ofwfb_bcopy((void *)(s), (void *)(d), (c))
55 #define bcopy_toio(s, d, c)	ofwfb_bcopy((void *)(s), (void *)(d), (c))
56 #define bcopy_fromio(s, d, c)	ofwfb_bcopy((void *)(s), (void *)(d), (c))
57 #define bzero_io(d, c)		ofwfb_bzero((void *)(d), (c))
58 #define fillw(p, d, c)		ofwfb_fillw((p), (void *)(d), (c))
59 #define fillw_io(p, d, c)	ofwfb_fillw((p), (void *)(d), (c))
60 #define	readw(a)		ofwfb_readw((u_int16_t *)(a))
61 #define	writew(a, v)		ofwfb_writew((u_int16_t *)(a), (v))
62 void ofwfb_bcopy(const void *s, void *d, size_t c);
63 void ofwfb_bzero(void *d, size_t c);
64 void ofwfb_fillw(int pat, void *base, size_t cnt);
65 u_int16_t ofwfb_readw(u_int16_t *addr);
66 void ofwfb_writew(u_int16_t *addr, u_int16_t val);
67 
68 #elif defined(__arm__)
69 
70 #define bcopy_io(s, d, c)	memcpy((void *)(d), (void *)(s), (c))
71 #define bcopy_toio(s, d, c)	memcpy((void *)(d), (void *)(s), (c))
72 #define bcopy_fromio(s, d, c)	memcpy((void *)(d), (void *)(s), (c))
73 #define bzero_io(d, c)		memset((void *)(d), 0, (c))
74 #define fill_io(p, d, c)	memset((void *)(d), (p), (c))
75 static __inline void
76 fillw(int val, uint16_t *buf, size_t size)
77 {
78 	while (size--)
79 		*buf++ = val;
80 }
81 #define fillw_io(p, d, c)	fillw((p), (void *)(d), (c))
82 
83 #define	readw(a)		(*(uint16_t*)(a))
84 #define	writew(a, v)		(*(uint16_t*)(a) = (v))
85 
86 #else /* !__i386__ && !__amd64__ && !__powerpc__ */
87 #define bcopy_io(s, d, c)	memcpy_io((d), (s), (c))
88 #define bcopy_toio(s, d, c)	memcpy_toio((d), (void *)(s), (c))
89 #define bcopy_fromio(s, d, c)	memcpy_fromio((void *)(d), (s), (c))
90 #define bzero_io(d, c)		memset_io((d), 0, (c))
91 #define fill_io(p, d, c)	memset_io((d), (p), (c))
92 #define fillw(p, d, c)		memsetw((d), (p), (c))
93 #define fillw_io(p, d, c)	memsetw_io((d), (p), (c))
94 #endif /* !__i386__ */
95 
96 /* video function table */
97 typedef int vi_probe_t(int unit, video_adapter_t **adpp, void *arg, int flags);
98 typedef int vi_init_t(int unit, video_adapter_t *adp, int flags);
99 typedef int vi_get_info_t(video_adapter_t *adp, int mode, video_info_t *info);
100 typedef int vi_query_mode_t(video_adapter_t *adp, video_info_t *info);
101 typedef int vi_set_mode_t(video_adapter_t *adp, int mode);
102 typedef int vi_save_font_t(video_adapter_t *adp, int page, int size, int width,
103 			   u_char *data, int c, int count);
104 typedef int vi_load_font_t(video_adapter_t *adp, int page, int size, int width,
105 			   u_char *data, int c, int count);
106 typedef int vi_show_font_t(video_adapter_t *adp, int page);
107 typedef int vi_save_palette_t(video_adapter_t *adp, u_char *palette);
108 typedef int vi_load_palette_t(video_adapter_t *adp, u_char *palette);
109 typedef int vi_set_border_t(video_adapter_t *adp, int border);
110 typedef int vi_save_state_t(video_adapter_t *adp, void *p, size_t size);
111 typedef int vi_load_state_t(video_adapter_t *adp, void *p);
112 typedef int vi_set_win_org_t(video_adapter_t *adp, off_t offset);
113 typedef int vi_read_hw_cursor_t(video_adapter_t *adp, int *col, int *row);
114 typedef int vi_set_hw_cursor_t(video_adapter_t *adp, int col, int row);
115 typedef int vi_set_hw_cursor_shape_t(video_adapter_t *adp, int base,
116 				     int height, int celsize, int blink);
117 typedef int vi_blank_display_t(video_adapter_t *adp, int mode);
118 /* defined in sys/fbio.h
119 #define V_DISPLAY_ON		0
120 #define V_DISPLAY_BLANK		1
121 #define V_DISPLAY_STAND_BY	2
122 #define V_DISPLAY_SUSPEND	3
123 */
124 typedef int vi_mmap_t(video_adapter_t *adp, vm_ooffset_t offset,
125 		      vm_paddr_t *paddr, int prot, vm_memattr_t *memattr);
126 typedef int vi_ioctl_t(video_adapter_t *adp, u_long cmd, caddr_t data);
127 typedef int vi_clear_t(video_adapter_t *adp);
128 typedef int vi_fill_rect_t(video_adapter_t *adp, int val, int x, int y,
129 			   int cx, int cy);
130 typedef int vi_bitblt_t(video_adapter_t *adp, ...);
131 typedef int vi_diag_t(video_adapter_t *adp, int level);
132 typedef int vi_save_cursor_palette_t(video_adapter_t *adp, u_char *palette);
133 typedef int vi_load_cursor_palette_t(video_adapter_t *adp, u_char *palette);
134 typedef int vi_copy_t(video_adapter_t *adp, vm_offset_t src, vm_offset_t dst,
135 		      int n);
136 typedef int vi_putp_t(video_adapter_t *adp, vm_offset_t off, u_int32_t p,
137 		       u_int32_t a, int size, int bpp, int bit_ltor,
138 		       int byte_ltor);
139 typedef int vi_putc_t(video_adapter_t *adp, vm_offset_t off, u_int8_t c,
140 		      u_int8_t a);
141 typedef int vi_puts_t(video_adapter_t *adp, vm_offset_t off, u_int16_t *s,
142 		       int len);
143 typedef int vi_putm_t(video_adapter_t *adp, int x, int y, u_int8_t *pixel_image,
144 		      u_int32_t pixel_mask, int size, int width);
145 
146 typedef struct video_switch {
147     vi_probe_t		*probe;
148     vi_init_t		*init;
149     vi_get_info_t	*get_info;
150     vi_query_mode_t	*query_mode;
151     vi_set_mode_t	*set_mode;
152     vi_save_font_t	*save_font;
153     vi_load_font_t	*load_font;
154     vi_show_font_t	*show_font;
155     vi_save_palette_t	*save_palette;
156     vi_load_palette_t	*load_palette;
157     vi_set_border_t	*set_border;
158     vi_save_state_t	*save_state;
159     vi_load_state_t	*load_state;
160     vi_set_win_org_t	*set_win_org;
161     vi_read_hw_cursor_t	*read_hw_cursor;
162     vi_set_hw_cursor_t	*set_hw_cursor;
163     vi_set_hw_cursor_shape_t *set_hw_cursor_shape;
164     vi_blank_display_t	*blank_display;
165     vi_mmap_t		*mmap;
166     vi_ioctl_t		*ioctl;
167     vi_clear_t		*clear;
168     vi_fill_rect_t	*fill_rect;
169     vi_bitblt_t		*bitblt;
170     int			(*reserved1)(void);
171     int			(*reserved2)(void);
172     vi_diag_t		*diag;
173     vi_save_cursor_palette_t	*save_cursor_palette;
174     vi_load_cursor_palette_t	*load_cursor_palette;
175     vi_copy_t		*copy;
176     vi_putp_t		*putp;
177     vi_putc_t		*putc;
178     vi_puts_t		*puts;
179     vi_putm_t		*putm;
180 } video_switch_t;
181 
182 #define vidd_probe(unit, adpp, arg, flags)				\
183 	(*vidsw[(adp)->va_index]->probe)((unit), (adpp), (arg), (flags))
184 #define vidd_init(unit, adp, flags)					\
185 	(*vidsw[(adp)->va_index]->init)((unit), (adp), (flags))
186 #define vidd_get_info(adp, mode, info)					\
187 	(*vidsw[(adp)->va_index]->get_info)((adp), (mode), (info))
188 #define vidd_query_mode(adp, mode)					\
189 	(*vidsw[(adp)->va_index]->query_mode)((adp), (mode))
190 #define vidd_set_mode(adp, mode)					\
191 	(*vidsw[(adp)->va_index]->set_mode)((adp), (mode))
192 #define vidd_save_font(adp, page, size, width, data, c, count)		\
193 	(*vidsw[(adp)->va_index]->save_font)((adp), (page), (size),	\
194 	    (width), (data), (c), (count))
195 #define vidd_load_font(adp, page, size, width, data, c, count)		\
196 	(*vidsw[(adp)->va_index]->load_font)((adp), (page), (size),	\
197 	    (width), (data), (c), (count))
198 #define vidd_show_font(adp, page)					\
199 	(*vidsw[(adp)->va_index]->show_font)((adp), (page))
200 #define vidd_save_palette(adp, pallete)					\
201 	(*vidsw[(adp)->va_index]->save_palette)((adp), (pallete))
202 #define vidd_load_palette(adp, pallete)					\
203 	(*vidsw[(adp)->va_index]->load_palette)((adp), (pallete))
204 #define vidd_set_border(adp, border)					\
205 	(*vidsw[(adp)->va_index]->set_border)((adp), (border))
206 #define vidd_save_state(adp, p, size)					\
207 	(*vidsw[(adp)->va_index]->save_state)((adp), (p), (size))
208 #define vidd_load_state(adp, p)						\
209 	(*vidsw[(adp)->va_index]->load_state)((adp), (p))
210 #define vidd_set_win_org(adp, offset)					\
211 	(*vidsw[(adp)->va_index]->set_win_org)((adp), (offset))
212 #define vidd_read_hw_cursor(adp, col, row)				\
213 	(*vidsw[(adp)->va_index]->read_hw_cursor)((adp), (col), (row))
214 #define vidd_set_hw_cursor(adp, col, row)				\
215 	(*vidsw[(adp)->va_index]->set_hw_cursor)((adp), (col), (row))
216 #define vidd_set_hw_cursor_shape(adp, base, height, celsize, blink)	\
217 	(*vidsw[(adp)->va_index]->set_hw_cursor_shape)((adp), (base),	\
218 	    (height), (celsize), (blink))
219 #define vidd_blank_display(adp, mode)					\
220 	(*vidsw[(adp)->va_index]->blank_display)((adp), (mode))
221 #define vidd_mmap(adp, offset, paddr, prot, memattr)			\
222 	(*vidsw[(adp)->va_index]->mmap)((adp), (offset), (paddr),	\
223 	    (prot), (memattr))
224 #define vidd_ioctl(adp, cmd, data)					\
225 	(*vidsw[(adp)->va_index]->ioctl)((adp), (cmd), (data))
226 #define vidd_clear(adp)							\
227 	(*vidsw[(adp)->va_index]->clear)((adp))
228 #define vidd_fill_rect(adp, val, x, y, cx, cy)				\
229 	(*vidsw[(adp)->va_index]->fill_rect)((adp), (val), (x), (y),	\
230 	    (cx), (cy))
231 #define vidd_bitblt(adp, ...)						\
232 	(*vidsw[(adp)->va_index]->bitblt)(adp, __VA_ARGS__)
233 #define vidd_diag(adp, level)						\
234 	(*vidsw[(adp)->va_index]->diag)((adp), (level))
235 #define vidd_save_cursor_palette(adp, palette)				\
236 	(*vidsw[(adp)->va_index]->save_cursor_palette)((adp), (palette))
237 #define vidd_load_cursor_palette(adp, palette)				\
238 	(*vidsw[(adp)->va_index]->load_cursor_palette)((adp), (palette))
239 #define vidd_copy(adp, src, dst, n)					\
240 	(*vidsw[(adp)->va_index]->copy)((adp), (src), (dst), (n))
241 #define vidd_putp(adp, offset, p, a, size, bpp, bit_ltor1, byte_ltor2)	\
242 	(*vidsw[(adp)->va_index]->putp)((adp), (offset), (p), (a), 	\
243 	    (size), (bpp), (bit_ltor1), (bit_ltor2))
244 #define vidd_putc(adp, offset, c, a)					\
245 	(*vidsw[(adp)->va_index]->putc)((adp), (offset), (c), (a))
246 #define vidd_puts(adp, offset, s, len)					\
247 	(*vidsw[(adp)->va_index]->puts)((adp), (offset), (s), (len))
248 #define vidd_putm(adp, x, y, pixel_image, pixel_mask, size, width)	\
249 	(*vidsw[(adp)->va_index]->putm)((adp), (x), (y), (pixel_image),	\
250 	    (pixel_mask), (size), (width))
251 
252 /* video driver */
253 typedef struct video_driver {
254     char		*name;
255     video_switch_t	*vidsw;
256     int			(*configure)(int); /* backdoor for the console driver */
257 } video_driver_t;
258 
259 #define VIDEO_DRIVER(name, sw, config)			\
260 	static struct video_driver name##_driver = {	\
261 		#name, &sw, config			\
262 	};						\
263 	DATA_SET(videodriver_set, name##_driver);
264 
265 /* global variables */
266 extern struct video_switch **vidsw;
267 
268 /* functions for the video card driver */
269 int		vid_register(video_adapter_t *adp);
270 int		vid_unregister(video_adapter_t *adp);
271 video_switch_t	*vid_get_switch(char *name);
272 void		vid_init_struct(video_adapter_t *adp, char *name, int type,
273 				int unit);
274 
275 /* functions for the video card client */
276 int		vid_allocate(char *driver, int unit, void *id);
277 int		vid_release(video_adapter_t *adp, void *id);
278 int		vid_find_adapter(char *driver, int unit);
279 video_adapter_t	*vid_get_adapter(int index);
280 
281 /* a backdoor for the console driver to tickle the video driver XXX */
282 int		vid_configure(int flags);
283 #define VIO_PROBE_ONLY	(1 << 0)	/* probe only, don't initialize */
284 
285 /* generic low-level driver functions */
286 
287 void		fb_dump_adp_info(char *driver, video_adapter_t *adp, int level);
288 void		fb_dump_mode_info(char *driver, video_adapter_t *adp,
289 				  video_info_t *info, int level);
290 int		fb_type(int adp_type);
291 int		fb_commonioctl(video_adapter_t *adp, u_long cmd, caddr_t arg);
292 
293 #endif /* _KERNEL */
294 
295 #endif /* !_DEV_FB_FBREG_H_ */
296