xref: /freebsd/sys/dev/fb/fbreg.h (revision fcb560670601b2a4d87bb31d7531c8dcc37ee71b)
1 /*-
2  * Copyright (c) 1999 Kazutaka YOKOTA <yokota@zodiac.mech.utsunomiya-u.ac.jp>
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer as
10  *    the first lines of this file unmodified.
11  * 2. Redistributions in binary form must reproduce the above copyright
12  *    notice, this list of conditions and the following disclaimer in the
13  *    documentation and/or other materials provided with the distribution.
14  *
15  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25  *
26  * $FreeBSD$
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(__sparc64__)
53 static __inline void
54 fillw(int val, uint16_t *buf, size_t size)
55 {
56 	while (size--)
57 		*buf++ = val;
58 }
59 #elif defined(__powerpc__)
60 
61 #define bcopy_io(s, d, c)	ofwfb_bcopy((void *)(s), (void *)(d), (c))
62 #define bcopy_toio(s, d, c)	ofwfb_bcopy((void *)(s), (void *)(d), (c))
63 #define bcopy_fromio(s, d, c)	ofwfb_bcopy((void *)(s), (void *)(d), (c))
64 #define bzero_io(d, c)		ofwfb_bzero((void *)(d), (c))
65 #define fillw(p, d, c)		ofwfb_fillw((p), (void *)(d), (c))
66 #define fillw_io(p, d, c)	ofwfb_fillw((p), (void *)(d), (c))
67 #define	readw(a)		ofwfb_readw((u_int16_t *)(a))
68 #define	writew(a, v)		ofwfb_writew((u_int16_t *)(a), (v))
69 void ofwfb_bcopy(const void *s, void *d, size_t c);
70 void ofwfb_bzero(void *d, size_t c);
71 void ofwfb_fillw(int pat, void *base, size_t cnt);
72 u_int16_t ofwfb_readw(u_int16_t *addr);
73 void ofwfb_writew(u_int16_t *addr, u_int16_t val);
74 
75 #elif defined(__mips__) || defined(__arm__)
76 
77 /*
78  * Use amd64/i386-like settings under the assumption that MIPS-based display
79  * drivers will have to add a level of indirection between a syscons-managed
80  * frame buffer and the actual video hardware.  We are forced to do this
81  * because syscons doesn't carry around required busspace handles and tags to
82  * use here.  This is only really a problem for true VGA devices hooked up to
83  * MIPS, as others will be performing a translation anyway.
84  */
85 #define bcopy_io(s, d, c)	memcpy((void *)(d), (void *)(s), (c))
86 #define bcopy_toio(s, d, c)	memcpy((void *)(d), (void *)(s), (c))
87 #define bcopy_fromio(s, d, c)	memcpy((void *)(d), (void *)(s), (c))
88 #define bzero_io(d, c)		memset((void *)(d), 0, (c))
89 #define fill_io(p, d, c)	memset((void *)(d), (p), (c))
90 static __inline void
91 fillw(int val, uint16_t *buf, size_t size)
92 {
93 	while (size--)
94 		*buf++ = val;
95 }
96 #define fillw_io(p, d, c)	fillw((p), (void *)(d), (c))
97 
98 #if defined(__arm__)
99 #define	readw(a)		(*(uint16_t*)(a))
100 #define	writew(a, v)		(*(uint16_t*)(a) = (v))
101 #endif
102 
103 #else /* !__i386__ && !__amd64__ && !__sparc64__ && !__powerpc__ */
104 #define bcopy_io(s, d, c)	memcpy_io((d), (s), (c))
105 #define bcopy_toio(s, d, c)	memcpy_toio((d), (void *)(s), (c))
106 #define bcopy_fromio(s, d, c)	memcpy_fromio((void *)(d), (s), (c))
107 #define bzero_io(d, c)		memset_io((d), 0, (c))
108 #define fill_io(p, d, c)	memset_io((d), (p), (c))
109 #define fillw(p, d, c)		memsetw((d), (p), (c))
110 #define fillw_io(p, d, c)	memsetw_io((d), (p), (c))
111 #endif /* !__i386__ */
112 
113 /* video function table */
114 typedef int vi_probe_t(int unit, video_adapter_t **adpp, void *arg, int flags);
115 typedef int vi_init_t(int unit, video_adapter_t *adp, int flags);
116 typedef int vi_get_info_t(video_adapter_t *adp, int mode, video_info_t *info);
117 typedef int vi_query_mode_t(video_adapter_t *adp, video_info_t *info);
118 typedef int vi_set_mode_t(video_adapter_t *adp, int mode);
119 typedef int vi_save_font_t(video_adapter_t *adp, int page, int size, int width,
120 			   u_char *data, int c, int count);
121 typedef int vi_load_font_t(video_adapter_t *adp, int page, int size, int width,
122 			   u_char *data, int c, int count);
123 typedef int vi_show_font_t(video_adapter_t *adp, int page);
124 typedef int vi_save_palette_t(video_adapter_t *adp, u_char *palette);
125 typedef int vi_load_palette_t(video_adapter_t *adp, u_char *palette);
126 typedef int vi_set_border_t(video_adapter_t *adp, int border);
127 typedef int vi_save_state_t(video_adapter_t *adp, void *p, size_t size);
128 typedef int vi_load_state_t(video_adapter_t *adp, void *p);
129 typedef int vi_set_win_org_t(video_adapter_t *adp, off_t offset);
130 typedef int vi_read_hw_cursor_t(video_adapter_t *adp, int *col, int *row);
131 typedef int vi_set_hw_cursor_t(video_adapter_t *adp, int col, int row);
132 typedef int vi_set_hw_cursor_shape_t(video_adapter_t *adp, int base,
133 				     int height, int celsize, int blink);
134 typedef int vi_blank_display_t(video_adapter_t *adp, int mode);
135 /* defined in sys/fbio.h
136 #define V_DISPLAY_ON		0
137 #define V_DISPLAY_BLANK		1
138 #define V_DISPLAY_STAND_BY	2
139 #define V_DISPLAY_SUSPEND	3
140 */
141 typedef int vi_mmap_t(video_adapter_t *adp, vm_ooffset_t offset,
142 		      vm_paddr_t *paddr, int prot, vm_memattr_t *memattr);
143 typedef int vi_ioctl_t(video_adapter_t *adp, u_long cmd, caddr_t data);
144 typedef int vi_clear_t(video_adapter_t *adp);
145 typedef int vi_fill_rect_t(video_adapter_t *adp, int val, int x, int y,
146 			   int cx, int cy);
147 typedef int vi_bitblt_t(video_adapter_t *adp, ...);
148 typedef int vi_diag_t(video_adapter_t *adp, int level);
149 typedef int vi_save_cursor_palette_t(video_adapter_t *adp, u_char *palette);
150 typedef int vi_load_cursor_palette_t(video_adapter_t *adp, u_char *palette);
151 typedef int vi_copy_t(video_adapter_t *adp, vm_offset_t src, vm_offset_t dst,
152 		      int n);
153 typedef int vi_putp_t(video_adapter_t *adp, vm_offset_t off, u_int32_t p,
154 		       u_int32_t a, int size, int bpp, int bit_ltor,
155 		       int byte_ltor);
156 typedef int vi_putc_t(video_adapter_t *adp, vm_offset_t off, u_int8_t c,
157 		      u_int8_t a);
158 typedef int vi_puts_t(video_adapter_t *adp, vm_offset_t off, u_int16_t *s,
159 		       int len);
160 typedef int vi_putm_t(video_adapter_t *adp, int x, int y, u_int8_t *pixel_image,
161 		      u_int32_t pixel_mask, int size, int width);
162 
163 typedef struct video_switch {
164     vi_probe_t		*probe;
165     vi_init_t		*init;
166     vi_get_info_t	*get_info;
167     vi_query_mode_t	*query_mode;
168     vi_set_mode_t	*set_mode;
169     vi_save_font_t	*save_font;
170     vi_load_font_t	*load_font;
171     vi_show_font_t	*show_font;
172     vi_save_palette_t	*save_palette;
173     vi_load_palette_t	*load_palette;
174     vi_set_border_t	*set_border;
175     vi_save_state_t	*save_state;
176     vi_load_state_t	*load_state;
177     vi_set_win_org_t	*set_win_org;
178     vi_read_hw_cursor_t	*read_hw_cursor;
179     vi_set_hw_cursor_t	*set_hw_cursor;
180     vi_set_hw_cursor_shape_t *set_hw_cursor_shape;
181     vi_blank_display_t	*blank_display;
182     vi_mmap_t		*mmap;
183     vi_ioctl_t		*ioctl;
184     vi_clear_t		*clear;
185     vi_fill_rect_t	*fill_rect;
186     vi_bitblt_t		*bitblt;
187     int			(*reserved1)(void);
188     int			(*reserved2)(void);
189     vi_diag_t		*diag;
190     vi_save_cursor_palette_t	*save_cursor_palette;
191     vi_load_cursor_palette_t	*load_cursor_palette;
192     vi_copy_t		*copy;
193     vi_putp_t		*putp;
194     vi_putc_t		*putc;
195     vi_puts_t		*puts;
196     vi_putm_t		*putm;
197 } video_switch_t;
198 
199 #define vidd_probe(unit, adpp, arg, flags)				\
200 	(*vidsw[(adp)->va_index]->probe)((unit), (adpp), (arg), (flags))
201 #define vidd_init(unit, adp, flags)					\
202 	(*vidsw[(adp)->va_index]->init)((unit), (adp), (flags))
203 #define vidd_get_info(adp, mode, info)					\
204 	(*vidsw[(adp)->va_index]->get_info)((adp), (mode), (info))
205 #define vidd_query_mode(adp, mode)					\
206 	(*vidsw[(adp)->va_index]->query_mode)((adp), (mode))
207 #define vidd_set_mode(adp, mode)					\
208 	(*vidsw[(adp)->va_index]->set_mode)((adp), (mode))
209 #define vidd_save_font(adp, page, size, width, data, c, count)		\
210 	(*vidsw[(adp)->va_index]->save_font)((adp), (page), (size),	\
211 	    (width), (data), (c), (count))
212 #define vidd_load_font(adp, page, size, width, data, c, count)		\
213 	(*vidsw[(adp)->va_index]->load_font)((adp), (page), (size),	\
214 	    (width), (data), (c), (count))
215 #define vidd_show_font(adp, page)					\
216 	(*vidsw[(adp)->va_index]->show_font)((adp), (page))
217 #define vidd_save_palette(adp, pallete)					\
218 	(*vidsw[(adp)->va_index]->save_palette)((adp), (pallete))
219 #define vidd_load_palette(adp, pallete)					\
220 	(*vidsw[(adp)->va_index]->load_palette)((adp), (pallete))
221 #define vidd_set_border(adp, border)					\
222 	(*vidsw[(adp)->va_index]->set_border)((adp), (border))
223 #define vidd_save_state(adp, p, size)					\
224 	(*vidsw[(adp)->va_index]->save_state)((adp), (p), (size))
225 #define vidd_load_state(adp, p)						\
226 	(*vidsw[(adp)->va_index]->load_state)((adp), (p))
227 #define vidd_set_win_org(adp, offset)					\
228 	(*vidsw[(adp)->va_index]->set_win_org)((adp), (offset))
229 #define vidd_read_hw_cursor(adp, col, row)				\
230 	(*vidsw[(adp)->va_index]->read_hw_cursor)((adp), (col), (row))
231 #define vidd_set_hw_cursor(adp, col, row)				\
232 	(*vidsw[(adp)->va_index]->set_hw_cursor)((adp), (col), (row))
233 #define vidd_set_hw_cursor_shape(adp, base, height, celsize, blink)	\
234 	(*vidsw[(adp)->va_index]->set_hw_cursor_shape)((adp), (base),	\
235 	    (height), (celsize), (blink))
236 #define vidd_blank_display(adp, mode)					\
237 	(*vidsw[(adp)->va_index]->blank_display)((adp), (mode))
238 #define vidd_mmap(adp, offset, paddr, prot, memattr)			\
239 	(*vidsw[(adp)->va_index]->mmap)((adp), (offset), (paddr),	\
240 	    (prot), (memattr))
241 #define vidd_ioctl(adp, cmd, data)					\
242 	(*vidsw[(adp)->va_index]->ioctl)((adp), (cmd), (data))
243 #define vidd_clear(adp)							\
244 	(*vidsw[(adp)->va_index]->clear)((adp))
245 #define vidd_fill_rect(adp, val, x, y, cx, cy)				\
246 	(*vidsw[(adp)->va_index]->fill_rect)((adp), (val), (x), (y),	\
247 	    (cx), (cy))
248 #define vidd_bitblt(adp, ...)						\
249 	(*vidsw[(adp)->va_index]->bitblt)(adp, __VA_ARGS__)
250 #define vidd_diag(adp, level)						\
251 	(*vidsw[(adp)->va_index]->diag)((adp), (level))
252 #define vidd_save_cursor_palette(adp, palette)				\
253 	(*vidsw[(adp)->va_index]->save_cursor_palette)((adp), (palette))
254 #define vidd_load_cursor_palette(adp, palette)				\
255 	(*vidsw[(adp)->va_index]->load_cursor_palette)((adp), (palette))
256 #define vidd_copy(adp, src, dst, n)					\
257 	(*vidsw[(adp)->va_index]->copy)((adp), (src), (dst), (n))
258 #define vidd_putp(adp, offset, p, a, size, bpp, bit_ltor1, byte_ltor2)	\
259 	(*vidsw[(adp)->va_index]->putp)((adp), (offset), (p), (a), 	\
260 	    (size), (bpp), (bit_ltor1), (bit_ltor2))
261 #define vidd_putc(adp, offset, c, a)					\
262 	(*vidsw[(adp)->va_index]->putc)((adp), (offset), (c), (a))
263 #define vidd_puts(adp, offset, s, len)					\
264 	(*vidsw[(adp)->va_index]->puts)((adp), (offset), (s), (len))
265 #define vidd_putm(adp, x, y, pixel_image, pixel_mask, size, width)	\
266 	(*vidsw[(adp)->va_index]->putm)((adp), (x), (y), (pixel_image),	\
267 	    (pixel_mask), (size), (width))
268 
269 /* video driver */
270 typedef struct video_driver {
271     char		*name;
272     video_switch_t	*vidsw;
273     int			(*configure)(int); /* backdoor for the console driver */
274 } video_driver_t;
275 
276 #define VIDEO_DRIVER(name, sw, config)			\
277 	static struct video_driver name##_driver = {	\
278 		#name, &sw, config			\
279 	};						\
280 	DATA_SET(videodriver_set, name##_driver);
281 
282 /* global variables */
283 extern struct video_switch **vidsw;
284 
285 /* functions for the video card driver */
286 int		vid_register(video_adapter_t *adp);
287 int		vid_unregister(video_adapter_t *adp);
288 video_switch_t	*vid_get_switch(char *name);
289 void		vid_init_struct(video_adapter_t *adp, char *name, int type,
290 				int unit);
291 
292 /* functions for the video card client */
293 int		vid_allocate(char *driver, int unit, void *id);
294 int		vid_release(video_adapter_t *adp, void *id);
295 int		vid_find_adapter(char *driver, int unit);
296 video_adapter_t	*vid_get_adapter(int index);
297 
298 /* a backdoor for the console driver to tickle the video driver XXX */
299 int		vid_configure(int flags);
300 #define VIO_PROBE_ONLY	(1 << 0)	/* probe only, don't initialize */
301 
302 #ifdef FB_INSTALL_CDEV
303 
304 /* virtual frame buffer driver functions */
305 int		fb_attach(int unit, video_adapter_t *adp,
306 			  struct cdevsw *cdevsw);
307 int		fb_detach(int unit, video_adapter_t *adp,
308 			  struct cdevsw *cdevsw);
309 
310 /* generic frame buffer cdev driver functions */
311 
312 typedef struct genfb_softc {
313 	int		gfb_flags;	/* flag/status bits */
314 #define FB_OPEN		(1 << 0)
315 } genfb_softc_t;
316 
317 int		genfbopen(genfb_softc_t *sc, video_adapter_t *adp,
318 			  int flag, int mode, struct thread *td);
319 int		genfbclose(genfb_softc_t *sc, video_adapter_t *adp,
320 			   int flag, int mode, struct thread *td);
321 int		genfbread(genfb_softc_t *sc, video_adapter_t *adp,
322 			  struct uio *uio, int flag);
323 int		genfbwrite(genfb_softc_t *sc, video_adapter_t *adp,
324 			   struct uio *uio, int flag);
325 int		genfbioctl(genfb_softc_t *sc, video_adapter_t *adp,
326 			   u_long cmd, caddr_t arg, int flag, struct thread *td);
327 int		genfbmmap(genfb_softc_t *sc, video_adapter_t *adp,
328 			  vm_ooffset_t offset, vm_offset_t *paddr,
329 			  int prot, vm_memattr_t *memattr);
330 
331 #endif /* FB_INSTALL_CDEV */
332 
333 /* generic low-level driver functions */
334 
335 void		fb_dump_adp_info(char *driver, video_adapter_t *adp, int level);
336 void		fb_dump_mode_info(char *driver, video_adapter_t *adp,
337 				  video_info_t *info, int level);
338 int		fb_type(int adp_type);
339 int		fb_commonioctl(video_adapter_t *adp, u_long cmd, caddr_t arg);
340 
341 #endif /* _KERNEL */
342 
343 #endif /* !_DEV_FB_FBREG_H_ */
344