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