xref: /freebsd/sys/dev/fb/fbreg.h (revision ae83180158c4c937f170e31eff311b18c0286a93)
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 #else /* !__i386__ */
47 #define bcopy_io(s, d, c)	memcpy_io((d), (s), (c))
48 #define bcopy_toio(s, d, c)	memcpy_toio((d), (void *)(s), (c))
49 #define bcopy_fromio(s, d, c)	memcpy_fromio((void *)(d), (s), (c))
50 #define bzero_io(d, c)		memset_io((d), 0, (c))
51 #define fill_io(p, d, c)	memset_io((d), (p), (c))
52 #define fillw(p, d, c)		memsetw((d), (p), (c))
53 #define fillw_io(p, d, c)	memsetw_io((d), (p), (c))
54 #endif /* !__i386__ */
55 
56 /* video function table */
57 typedef int vi_probe_t(int unit, video_adapter_t **adpp, void *arg, int flags);
58 typedef int vi_init_t(int unit, video_adapter_t *adp, int flags);
59 typedef int vi_get_info_t(video_adapter_t *adp, int mode, video_info_t *info);
60 typedef int vi_query_mode_t(video_adapter_t *adp, video_info_t *info);
61 typedef int vi_set_mode_t(video_adapter_t *adp, int mode);
62 typedef int vi_save_font_t(video_adapter_t *adp, int page, int size,
63 			   u_char *data, int c, int count);
64 typedef int vi_load_font_t(video_adapter_t *adp, int page, int size,
65 			   u_char *data, int c, int count);
66 typedef int vi_show_font_t(video_adapter_t *adp, int page);
67 typedef int vi_save_palette_t(video_adapter_t *adp, u_char *palette);
68 typedef int vi_load_palette_t(video_adapter_t *adp, u_char *palette);
69 typedef int vi_set_border_t(video_adapter_t *adp, int border);
70 typedef int vi_save_state_t(video_adapter_t *adp, void *p, size_t size);
71 typedef int vi_load_state_t(video_adapter_t *adp, void *p);
72 typedef int vi_set_win_org_t(video_adapter_t *adp, off_t offset);
73 typedef int vi_read_hw_cursor_t(video_adapter_t *adp, int *col, int *row);
74 typedef int vi_set_hw_cursor_t(video_adapter_t *adp, int col, int row);
75 typedef int vi_set_hw_cursor_shape_t(video_adapter_t *adp, int base,
76 				     int height, int celsize, int blink);
77 typedef int vi_blank_display_t(video_adapter_t *adp, int mode);
78 /* defined in sys/fbio.h
79 #define V_DISPLAY_ON		0
80 #define V_DISPLAY_BLANK		1
81 #define V_DISPLAY_STAND_BY	2
82 #define V_DISPLAY_SUSPEND	3
83 */
84 typedef int vi_mmap_t(video_adapter_t *adp, vm_offset_t offset, int prot);
85 typedef int vi_ioctl_t(video_adapter_t *adp, u_long cmd, caddr_t data);
86 typedef int vi_clear_t(video_adapter_t *adp);
87 typedef int vi_fill_rect_t(video_adapter_t *adp, int val, int x, int y,
88 			   int cx, int cy);
89 typedef int vi_bitblt_t(video_adapter_t *adp, ...);
90 typedef int vi_diag_t(video_adapter_t *adp, int level);
91 typedef int vi_save_cursor_palette_t(video_adapter_t *adp, u_char *palette);
92 typedef int vi_load_cursor_palette_t(video_adapter_t *adp, u_char *palette);
93 typedef int vi_copy_t(video_adapter_t *adp, vm_offset_t src, vm_offset_t dst,
94 		      int n);
95 typedef int vi_putp_t(video_adapter_t *adp, vm_offset_t off, u_int32_t p,
96 		       u_int32_t a, int size, int bpp, int bit_ltor,
97 		       int byte_ltor);
98 typedef int vi_putc_t(video_adapter_t *adp, vm_offset_t off, u_int8_t c,
99 		      u_int8_t a);
100 typedef int vi_puts_t(video_adapter_t *adp, vm_offset_t off, u_int16_t *s,
101 		       int len);
102 typedef int vi_putm_t(video_adapter_t *adp, int x, int y,
103 		      u_int8_t *pixel_image, u_int32_t pixel_mask, int size);
104 
105 typedef struct video_switch {
106     vi_probe_t		*probe;
107     vi_init_t		*init;
108     vi_get_info_t	*get_info;
109     vi_query_mode_t	*query_mode;
110     vi_set_mode_t	*set_mode;
111     vi_save_font_t	*save_font;
112     vi_load_font_t	*load_font;
113     vi_show_font_t	*show_font;
114     vi_save_palette_t	*save_palette;
115     vi_load_palette_t	*load_palette;
116     vi_set_border_t	*set_border;
117     vi_save_state_t	*save_state;
118     vi_load_state_t	*load_state;
119     vi_set_win_org_t	*set_win_org;
120     vi_read_hw_cursor_t	*read_hw_cursor;
121     vi_set_hw_cursor_t	*set_hw_cursor;
122     vi_set_hw_cursor_shape_t *set_hw_cursor_shape;
123     vi_blank_display_t	*blank_display;
124     vi_mmap_t		*mmap;
125     vi_ioctl_t		*ioctl;
126     vi_clear_t		*clear;
127     vi_fill_rect_t	*fill_rect;
128     vi_bitblt_t		*bitblt;
129     int			(*reserved1)(void);
130     int			(*reserved2)(void);
131     vi_diag_t		*diag;
132     vi_save_cursor_palette_t	*save_cursor_palette;
133     vi_load_cursor_palette_t	*load_cursor_palette;
134     vi_copy_t		*copy;
135     vi_putp_t		*putp;
136     vi_putc_t		*putc;
137     vi_puts_t		*puts;
138     vi_putm_t		*putm;
139 } video_switch_t;
140 
141 #define save_palette(adp, pal)				\
142 	(*vidsw[(adp)->va_index]->save_palette)((adp), (pal))
143 #define load_palette(adp, pal)				\
144 	(*vidsw[(adp)->va_index]->load_palette)((adp), (pal))
145 #define get_mode_info(adp, mode, buf)			\
146 	(*vidsw[(adp)->va_index]->get_info)((adp), (mode), (buf))
147 #define set_video_mode(adp, mode)			\
148 	(*vidsw[(adp)->va_index]->set_mode)((adp), (mode))
149 #define set_border(adp, border)				\
150 	(*vidsw[(adp)->va_index]->set_border)((adp), (border))
151 #define set_origin(adp, o)				\
152 	(*vidsw[(adp)->va_index]->set_win_org)(adp, o)
153 
154 /* XXX - add more macros */
155 
156 /* video driver */
157 typedef struct video_driver {
158     char		*name;
159     video_switch_t	*vidsw;
160     int			(*configure)(int); /* backdoor for the console driver */
161 } video_driver_t;
162 
163 #define VIDEO_DRIVER(name, sw, config)			\
164 	static struct video_driver name##_driver = {	\
165 		#name, &sw, config			\
166 	};						\
167 	DATA_SET(videodriver_set, name##_driver);
168 
169 /* global variables */
170 extern struct video_switch **vidsw;
171 
172 /* functions for the video card driver */
173 int		vid_register(video_adapter_t *adp);
174 int		vid_unregister(video_adapter_t *adp);
175 video_switch_t	*vid_get_switch(char *name);
176 void		vid_init_struct(video_adapter_t *adp, char *name, int type,
177 				int unit);
178 
179 /* functions for the video card client */
180 int		vid_allocate(char *driver, int unit, void *id);
181 int		vid_release(video_adapter_t *adp, void *id);
182 int		vid_find_adapter(char *driver, int unit);
183 video_adapter_t	*vid_get_adapter(int index);
184 
185 /* a backdoor for the console driver to tickle the video driver XXX */
186 int		vid_configure(int flags);
187 #define VIO_PROBE_ONLY	(1 << 0)	/* probe only, don't initialize */
188 
189 #ifdef FB_INSTALL_CDEV
190 
191 /* virtual frame buffer driver functions */
192 int		fb_attach(dev_t dev, video_adapter_t *adp,
193 			  struct cdevsw *cdevsw);
194 int		fb_detach(dev_t dev, video_adapter_t *adp,
195 			  struct cdevsw *cdevsw);
196 
197 /* generic frame buffer cdev driver functions */
198 
199 typedef struct genfb_softc {
200 	int		gfb_flags;	/* flag/status bits */
201 #define FB_OPEN		(1 << 0)
202 } genfb_softc_t;
203 
204 int		genfbopen(genfb_softc_t *sc, video_adapter_t *adp,
205 			  int flag, int mode, struct thread *td);
206 int		genfbclose(genfb_softc_t *sc, video_adapter_t *adp,
207 			   int flag, int mode, struct thread *td);
208 int		genfbread(genfb_softc_t *sc, video_adapter_t *adp,
209 			  struct uio *uio, int flag);
210 int		genfbwrite(genfb_softc_t *sc, video_adapter_t *adp,
211 			   struct uio *uio, int flag);
212 int		genfbioctl(genfb_softc_t *sc, video_adapter_t *adp,
213 			   u_long cmd, caddr_t arg, int flag, struct thread *td);
214 int		genfbmmap(genfb_softc_t *sc, video_adapter_t *adp,
215 			  vm_offset_t offset, int prot);
216 
217 #endif /* FB_INSTALL_CDEV */
218 
219 /* generic low-level driver functions */
220 
221 void		fb_dump_adp_info(char *driver, video_adapter_t *adp, int level);
222 void		fb_dump_mode_info(char *driver, video_adapter_t *adp,
223 				  video_info_t *info, int level);
224 int		fb_type(int adp_type);
225 int		fb_commonioctl(video_adapter_t *adp, u_long cmd, caddr_t arg);
226 
227 #endif /* _KERNEL */
228 
229 #endif /* !_DEV_FB_FBREG_H_ */
230