xref: /freebsd/sys/dev/fb/fbreg.h (revision f5f47d5068fb97df18eb114a66ae8ef51a0b3c8c)
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(__ia64__) || defined(__sparc64__)
53 #if defined(__ia64__)
54 #include <machine/bus.h>
55 #define	bcopy_fromio(s, d, c)	\
56 	bus_space_read_region_1(IA64_BUS_SPACE_MEM, s, 0, (void*)(d), c)
57 #define	bcopy_io(s, d, c)	\
58 	bus_space_copy_region_1(IA64_BUS_SPACE_MEM, s, 0, d, 0, c)
59 #define	bcopy_toio(s, d, c)	\
60 	bus_space_write_region_1(IA64_BUS_SPACE_MEM, d, 0, (void*)(s), c)
61 #define	bzero_io(d, c)		\
62 	bus_space_set_region_1(IA64_BUS_SPACE_MEM, (intptr_t)(d), 0, 0, c)
63 #define	fill_io(p, d, c)	\
64 	bus_space_set_region_1(IA64_BUS_SPACE_MEM, (intptr_t)(d), 0, p, c)
65 #define	fillw_io(p, d, c)	\
66 	bus_space_set_region_2(IA64_BUS_SPACE_MEM, (intptr_t)(d), 0, p, c)
67 #define	readb(a)		bus_space_read_1(IA64_BUS_SPACE_MEM, a, 0)
68 #define	readw(a)		bus_space_read_2(IA64_BUS_SPACE_MEM, a, 0)
69 #define	writeb(a, v)		bus_space_write_1(IA64_BUS_SPACE_MEM, a, 0, v)
70 #define	writew(a, v)		bus_space_write_2(IA64_BUS_SPACE_MEM, a, 0, v)
71 #define	writel(a, v)		bus_space_write_4(IA64_BUS_SPACE_MEM, a, 0, v)
72 #endif /* __ia64__ */
73 static __inline void
74 fillw(int val, uint16_t *buf, size_t size)
75 {
76 	while (size--)
77 		*buf++ = val;
78 }
79 #elif defined(__powerpc__)
80 
81 #define bcopy_io(s, d, c)	ofwfb_bcopy((void *)(s), (void *)(d), (c))
82 #define bcopy_toio(s, d, c)	ofwfb_bcopy((void *)(s), (void *)(d), (c))
83 #define bcopy_fromio(s, d, c)	ofwfb_bcopy((void *)(s), (void *)(d), (c))
84 #define bzero_io(d, c)		ofwfb_bzero((void *)(d), (c))
85 #define fillw(p, d, c)		ofwfb_fillw((p), (void *)(d), (c))
86 #define fillw_io(p, d, c)	ofwfb_fillw((p), (void *)(d), (c))
87 #define	readw(a)		ofwfb_readw((u_int16_t *)(a))
88 #define	writew(a, v)		ofwfb_writew((u_int16_t *)(a), (v))
89 void ofwfb_bcopy(const void *s, void *d, size_t c);
90 void ofwfb_bzero(void *d, size_t c);
91 void ofwfb_fillw(int pat, void *base, size_t cnt);
92 u_int16_t ofwfb_readw(u_int16_t *addr);
93 void ofwfb_writew(u_int16_t *addr, u_int16_t val);
94 
95 #elif defined(__mips__) || defined(__arm__)
96 
97 /*
98  * Use amd64/i386-like settings under the assumption that MIPS-based display
99  * drivers will have to add a level of indirection between a syscons-managed
100  * frame buffer and the actual video hardware.  We are forced to do this
101  * because syscons doesn't carry around required busspace handles and tags to
102  * use here.  This is only really a problem for true VGA devices hooked up to
103  * MIPS, as others will be performing a translation anyway.
104  */
105 #define bcopy_io(s, d, c)	memcpy((void *)(d), (void *)(s), (c))
106 #define bcopy_toio(s, d, c)	memcpy((void *)(d), (void *)(s), (c))
107 #define bcopy_fromio(s, d, c)	memcpy((void *)(d), (void *)(s), (c))
108 #define bzero_io(d, c)		memset((void *)(d), 0, (c))
109 #define fill_io(p, d, c)	memset((void *)(d), (p), (c))
110 static __inline void
111 fillw(int val, uint16_t *buf, size_t size)
112 {
113 	while (size--)
114 		*buf++ = val;
115 }
116 #define fillw_io(p, d, c)	fillw((p), (void *)(d), (c))
117 
118 #if defined(__arm__)
119 #define	readw(a)		(*(uint16_t*)(a))
120 #define	writew(a, v)		(*(uint16_t*)(a) = (v))
121 #endif
122 
123 #else /* !__i386__ && !__amd64__ && !__ia64__ && !__sparc64__ && !__powerpc__ */
124 #define bcopy_io(s, d, c)	memcpy_io((d), (s), (c))
125 #define bcopy_toio(s, d, c)	memcpy_toio((d), (void *)(s), (c))
126 #define bcopy_fromio(s, d, c)	memcpy_fromio((void *)(d), (s), (c))
127 #define bzero_io(d, c)		memset_io((d), 0, (c))
128 #define fill_io(p, d, c)	memset_io((d), (p), (c))
129 #define fillw(p, d, c)		memsetw((d), (p), (c))
130 #define fillw_io(p, d, c)	memsetw_io((d), (p), (c))
131 #endif /* !__i386__ */
132 
133 /* video function table */
134 typedef int vi_probe_t(int unit, video_adapter_t **adpp, void *arg, int flags);
135 typedef int vi_init_t(int unit, video_adapter_t *adp, int flags);
136 typedef int vi_get_info_t(video_adapter_t *adp, int mode, video_info_t *info);
137 typedef int vi_query_mode_t(video_adapter_t *adp, video_info_t *info);
138 typedef int vi_set_mode_t(video_adapter_t *adp, int mode);
139 typedef int vi_save_font_t(video_adapter_t *adp, int page, int size, int width,
140 			   u_char *data, int c, int count);
141 typedef int vi_load_font_t(video_adapter_t *adp, int page, int size, int width,
142 			   u_char *data, int c, int count);
143 typedef int vi_show_font_t(video_adapter_t *adp, int page);
144 typedef int vi_save_palette_t(video_adapter_t *adp, u_char *palette);
145 typedef int vi_load_palette_t(video_adapter_t *adp, u_char *palette);
146 typedef int vi_set_border_t(video_adapter_t *adp, int border);
147 typedef int vi_save_state_t(video_adapter_t *adp, void *p, size_t size);
148 typedef int vi_load_state_t(video_adapter_t *adp, void *p);
149 typedef int vi_set_win_org_t(video_adapter_t *adp, off_t offset);
150 typedef int vi_read_hw_cursor_t(video_adapter_t *adp, int *col, int *row);
151 typedef int vi_set_hw_cursor_t(video_adapter_t *adp, int col, int row);
152 typedef int vi_set_hw_cursor_shape_t(video_adapter_t *adp, int base,
153 				     int height, int celsize, int blink);
154 typedef int vi_blank_display_t(video_adapter_t *adp, int mode);
155 /* defined in sys/fbio.h
156 #define V_DISPLAY_ON		0
157 #define V_DISPLAY_BLANK		1
158 #define V_DISPLAY_STAND_BY	2
159 #define V_DISPLAY_SUSPEND	3
160 */
161 typedef int vi_mmap_t(video_adapter_t *adp, vm_ooffset_t offset,
162 		      vm_paddr_t *paddr, int prot, vm_memattr_t *memattr);
163 typedef int vi_ioctl_t(video_adapter_t *adp, u_long cmd, caddr_t data);
164 typedef int vi_clear_t(video_adapter_t *adp);
165 typedef int vi_fill_rect_t(video_adapter_t *adp, int val, int x, int y,
166 			   int cx, int cy);
167 typedef int vi_bitblt_t(video_adapter_t *adp, ...);
168 typedef int vi_diag_t(video_adapter_t *adp, int level);
169 typedef int vi_save_cursor_palette_t(video_adapter_t *adp, u_char *palette);
170 typedef int vi_load_cursor_palette_t(video_adapter_t *adp, u_char *palette);
171 typedef int vi_copy_t(video_adapter_t *adp, vm_offset_t src, vm_offset_t dst,
172 		      int n);
173 typedef int vi_putp_t(video_adapter_t *adp, vm_offset_t off, u_int32_t p,
174 		       u_int32_t a, int size, int bpp, int bit_ltor,
175 		       int byte_ltor);
176 typedef int vi_putc_t(video_adapter_t *adp, vm_offset_t off, u_int8_t c,
177 		      u_int8_t a);
178 typedef int vi_puts_t(video_adapter_t *adp, vm_offset_t off, u_int16_t *s,
179 		       int len);
180 typedef int vi_putm_t(video_adapter_t *adp, int x, int y, u_int8_t *pixel_image,
181 		      u_int32_t pixel_mask, int size, int width);
182 
183 typedef struct video_switch {
184     vi_probe_t		*probe;
185     vi_init_t		*init;
186     vi_get_info_t	*get_info;
187     vi_query_mode_t	*query_mode;
188     vi_set_mode_t	*set_mode;
189     vi_save_font_t	*save_font;
190     vi_load_font_t	*load_font;
191     vi_show_font_t	*show_font;
192     vi_save_palette_t	*save_palette;
193     vi_load_palette_t	*load_palette;
194     vi_set_border_t	*set_border;
195     vi_save_state_t	*save_state;
196     vi_load_state_t	*load_state;
197     vi_set_win_org_t	*set_win_org;
198     vi_read_hw_cursor_t	*read_hw_cursor;
199     vi_set_hw_cursor_t	*set_hw_cursor;
200     vi_set_hw_cursor_shape_t *set_hw_cursor_shape;
201     vi_blank_display_t	*blank_display;
202     vi_mmap_t		*mmap;
203     vi_ioctl_t		*ioctl;
204     vi_clear_t		*clear;
205     vi_fill_rect_t	*fill_rect;
206     vi_bitblt_t		*bitblt;
207     int			(*reserved1)(void);
208     int			(*reserved2)(void);
209     vi_diag_t		*diag;
210     vi_save_cursor_palette_t	*save_cursor_palette;
211     vi_load_cursor_palette_t	*load_cursor_palette;
212     vi_copy_t		*copy;
213     vi_putp_t		*putp;
214     vi_putc_t		*putc;
215     vi_puts_t		*puts;
216     vi_putm_t		*putm;
217 } video_switch_t;
218 
219 #define vidd_probe(unit, adpp, arg, flags)				\
220 	(*vidsw[(adp)->va_index]->probe)((unit), (adpp), (arg), (flags))
221 #define vidd_init(unit, adp, flags)					\
222 	(*vidsw[(adp)->va_index]->init)((unit), (adp), (flags))
223 #define vidd_get_info(adp, mode, info)					\
224 	(*vidsw[(adp)->va_index]->get_info)((adp), (mode), (info))
225 #define vidd_query_mode(adp, mode)					\
226 	(*vidsw[(adp)->va_index]->query_mode)((adp), (mode))
227 #define vidd_set_mode(adp, mode)					\
228 	(*vidsw[(adp)->va_index]->set_mode)((adp), (mode))
229 #define vidd_save_font(adp, page, size, width, data, c, count)		\
230 	(*vidsw[(adp)->va_index]->save_font)((adp), (page), (size),	\
231 	    (width), (data), (c), (count))
232 #define vidd_load_font(adp, page, size, width, data, c, count)		\
233 	(*vidsw[(adp)->va_index]->load_font)((adp), (page), (size),	\
234 	    (width), (data), (c), (count))
235 #define vidd_show_font(adp, page)					\
236 	(*vidsw[(adp)->va_index]->show_font)((adp), (page))
237 #define vidd_save_palette(adp, pallete)					\
238 	(*vidsw[(adp)->va_index]->save_palette)((adp), (pallete))
239 #define vidd_load_palette(adp, pallete)					\
240 	(*vidsw[(adp)->va_index]->load_palette)((adp), (pallete))
241 #define vidd_set_border(adp, border)					\
242 	(*vidsw[(adp)->va_index]->set_border)((adp), (border))
243 #define vidd_save_state(adp, p, size)					\
244 	(*vidsw[(adp)->va_index]->save_state)((adp), (p), (size))
245 #define vidd_load_state(adp, p)						\
246 	(*vidsw[(adp)->va_index]->load_state)((adp), (p))
247 #define vidd_set_win_org(adp, offset)					\
248 	(*vidsw[(adp)->va_index]->set_win_org)((adp), (offset))
249 #define vidd_read_hw_cursor(adp, col, row)				\
250 	(*vidsw[(adp)->va_index]->read_hw_cursor)((adp), (col), (row))
251 #define vidd_set_hw_cursor(adp, col, row)				\
252 	(*vidsw[(adp)->va_index]->set_hw_cursor)((adp), (col), (row))
253 #define vidd_set_hw_cursor_shape(adp, base, height, celsize, blink)	\
254 	(*vidsw[(adp)->va_index]->set_hw_cursor_shape)((adp), (base),	\
255 	    (height), (celsize), (blink))
256 #define vidd_blank_display(adp, mode)					\
257 	(*vidsw[(adp)->va_index]->blank_display)((adp), (mode))
258 #define vidd_mmap(adp, offset, paddr, prot, memattr)			\
259 	(*vidsw[(adp)->va_index]->mmap)((adp), (offset), (paddr),	\
260 	    (prot), (memattr))
261 #define vidd_ioctl(adp, cmd, data)					\
262 	(*vidsw[(adp)->va_index]->ioctl)((adp), (cmd), (data))
263 #define vidd_clear(adp)							\
264 	(*vidsw[(adp)->va_index]->clear)((adp))
265 #define vidd_fill_rect(adp, val, x, y, cx, cy)				\
266 	(*vidsw[(adp)->va_index]->fill_rect)((adp), (val), (x), (y),	\
267 	    (cx), (cy))
268 #define vidd_bitblt(adp, ...)						\
269 	(*vidsw[(adp)->va_index]->bitblt)(adp, __VA_ARGS__)
270 #define vidd_diag(adp, level)						\
271 	(*vidsw[(adp)->va_index]->diag)((adp), (level))
272 #define vidd_save_cursor_palette(adp, palette)				\
273 	(*vidsw[(adp)->va_index]->save_cursor_palette)((adp), (palette))
274 #define vidd_load_cursor_palette(adp, palette)				\
275 	(*vidsw[(adp)->va_index]->load_cursor_palette)((adp), (palette))
276 #define vidd_copy(adp, src, dst, n)					\
277 	(*vidsw[(adp)->va_index]->copy)((adp), (src), (dst), (n))
278 #define vidd_putp(adp, offset, p, a, size, bpp, bit_ltor1, byte_ltor2)	\
279 	(*vidsw[(adp)->va_index]->putp)((adp), (offset), (p), (a), 	\
280 	    (size), (bpp), (bit_ltor1), (bit_ltor2))
281 #define vidd_putc(adp, offset, c, a)					\
282 	(*vidsw[(adp)->va_index]->putc)((adp), (offset), (c), (a))
283 #define vidd_puts(adp, offset, s, len)					\
284 	(*vidsw[(adp)->va_index]->puts)((adp), (offset), (s), (len))
285 #define vidd_putm(adp, x, y, pixel_image, pixel_mask, size, width)	\
286 	(*vidsw[(adp)->va_index]->putm)((adp), (x), (y), (pixel_image),	\
287 	    (pixel_mask), (size), (width))
288 
289 /* video driver */
290 typedef struct video_driver {
291     char		*name;
292     video_switch_t	*vidsw;
293     int			(*configure)(int); /* backdoor for the console driver */
294 } video_driver_t;
295 
296 #define VIDEO_DRIVER(name, sw, config)			\
297 	static struct video_driver name##_driver = {	\
298 		#name, &sw, config			\
299 	};						\
300 	DATA_SET(videodriver_set, name##_driver);
301 
302 /* global variables */
303 extern struct video_switch **vidsw;
304 
305 /* functions for the video card driver */
306 int		vid_register(video_adapter_t *adp);
307 int		vid_unregister(video_adapter_t *adp);
308 video_switch_t	*vid_get_switch(char *name);
309 void		vid_init_struct(video_adapter_t *adp, char *name, int type,
310 				int unit);
311 
312 /* functions for the video card client */
313 int		vid_allocate(char *driver, int unit, void *id);
314 int		vid_release(video_adapter_t *adp, void *id);
315 int		vid_find_adapter(char *driver, int unit);
316 video_adapter_t	*vid_get_adapter(int index);
317 
318 /* a backdoor for the console driver to tickle the video driver XXX */
319 int		vid_configure(int flags);
320 #define VIO_PROBE_ONLY	(1 << 0)	/* probe only, don't initialize */
321 
322 #ifdef FB_INSTALL_CDEV
323 
324 /* virtual frame buffer driver functions */
325 int		fb_attach(int unit, video_adapter_t *adp,
326 			  struct cdevsw *cdevsw);
327 int		fb_detach(int unit, video_adapter_t *adp,
328 			  struct cdevsw *cdevsw);
329 
330 /* generic frame buffer cdev driver functions */
331 
332 typedef struct genfb_softc {
333 	int		gfb_flags;	/* flag/status bits */
334 #define FB_OPEN		(1 << 0)
335 } genfb_softc_t;
336 
337 int		genfbopen(genfb_softc_t *sc, video_adapter_t *adp,
338 			  int flag, int mode, struct thread *td);
339 int		genfbclose(genfb_softc_t *sc, video_adapter_t *adp,
340 			   int flag, int mode, struct thread *td);
341 int		genfbread(genfb_softc_t *sc, video_adapter_t *adp,
342 			  struct uio *uio, int flag);
343 int		genfbwrite(genfb_softc_t *sc, video_adapter_t *adp,
344 			   struct uio *uio, int flag);
345 int		genfbioctl(genfb_softc_t *sc, video_adapter_t *adp,
346 			   u_long cmd, caddr_t arg, int flag, struct thread *td);
347 int		genfbmmap(genfb_softc_t *sc, video_adapter_t *adp,
348 			  vm_ooffset_t offset, vm_offset_t *paddr,
349 			  int prot, vm_memattr_t *memattr);
350 
351 #endif /* FB_INSTALL_CDEV */
352 
353 /* generic low-level driver functions */
354 
355 void		fb_dump_adp_info(char *driver, video_adapter_t *adp, int level);
356 void		fb_dump_mode_info(char *driver, video_adapter_t *adp,
357 				  video_info_t *info, int level);
358 int		fb_type(int adp_type);
359 int		fb_commonioctl(video_adapter_t *adp, u_long cmd, caddr_t arg);
360 
361 #endif /* _KERNEL */
362 
363 #endif /* !_DEV_FB_FBREG_H_ */
364