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