xref: /dragonfly/sys/dev/video/fb/fbreg.h (revision e0a1e7ab)
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: src/sys/dev/fb/fbreg.h,v 1.6 1999/12/29 04:35:36 peter Exp $
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 #define bcopy_io(s, d, c)	bcopy((void *)(s), (void *)(d), (c))
38 #define bcopy_toio(s, d, c)	bcopy((void *)(s), (void *)(d), (c))
39 #define bcopy_fromio(s, d, c)	bcopy((void *)(s), (void *)(d), (c))
40 #define bzero_io(d, c)		bzero((void *)(d), (c))
41 #define fill_io(p, d, c)	fill((p), (void *)(d), (c))
42 #define fillw_io(p, d, c)	fillw((p), (void *)(d), (c))
43 
44 /* video function table */
45 typedef int vi_probe_t(int unit, video_adapter_t **adpp, void *arg, int flags);
46 typedef int vi_init_t(int unit, video_adapter_t *adp, int flags);
47 typedef int vi_get_info_t(video_adapter_t *adp, int mode, video_info_t *info);
48 typedef int vi_query_mode_t(video_adapter_t *adp, video_info_t *info);
49 typedef int vi_set_mode_t(video_adapter_t *adp, int mode);
50 typedef int vi_save_font_t(video_adapter_t *adp, int page, int size,
51 			   u_char *data, int c, int count);
52 typedef int vi_load_font_t(video_adapter_t *adp, int page, int size,
53 			   u_char *data, int c, int count);
54 typedef int vi_show_font_t(video_adapter_t *adp, int page);
55 typedef int vi_save_palette_t(video_adapter_t *adp, u_char *palette);
56 typedef int vi_load_palette_t(video_adapter_t *adp, const u_char *palette);
57 typedef int vi_set_border_t(video_adapter_t *adp, int border);
58 typedef int vi_save_state_t(video_adapter_t *adp, void *p, size_t size);
59 typedef int vi_load_state_t(video_adapter_t *adp, void *p);
60 typedef int vi_set_win_org_t(video_adapter_t *adp, off_t offset);
61 typedef int vi_read_hw_cursor_t(video_adapter_t *adp, int *col, int *row);
62 typedef int vi_set_hw_cursor_t(video_adapter_t *adp, int col, int row);
63 typedef int vi_set_hw_cursor_shape_t(video_adapter_t *adp, int base,
64 				     int height, int celsize, int blink);
65 typedef int vi_blank_display_t(video_adapter_t *adp, int mode);
66 typedef int vi_mmap_t(video_adapter_t *adp, vm_offset_t offset, int prot);
67 typedef int vi_ioctl_t(video_adapter_t *adp, u_long cmd, caddr_t data);
68 typedef int vi_clear_t(video_adapter_t *adp);
69 typedef int vi_fill_rect_t(video_adapter_t *adp, int val, int x, int y,
70 			   int cx, int cy);
71 typedef int vi_bitblt_t(video_adapter_t *adp,...);
72 typedef int vi_diag_t(video_adapter_t *adp, int level);
73 
74 typedef struct video_switch {
75     vi_probe_t		*probe;
76     vi_init_t		*init;
77     vi_get_info_t	*get_info;
78     vi_query_mode_t	*query_mode;
79     vi_set_mode_t	*set_mode;
80     vi_save_font_t	*save_font;
81     vi_load_font_t	*load_font;
82     vi_show_font_t	*show_font;
83     vi_save_palette_t	*save_palette;
84     vi_load_palette_t	*load_palette;
85     vi_set_border_t	*set_border;
86     vi_save_state_t	*save_state;
87     vi_load_state_t	*load_state;
88     vi_set_win_org_t	*set_win_org;
89     vi_read_hw_cursor_t	*read_hw_cursor;
90     vi_set_hw_cursor_t	*set_hw_cursor;
91     vi_set_hw_cursor_shape_t *set_hw_cursor_shape;
92     vi_blank_display_t	*blank_display;
93     vi_mmap_t		*mmap;
94     vi_ioctl_t		*ioctl;
95     vi_clear_t		*clear;
96     vi_fill_rect_t	*fill_rect;
97     vi_bitblt_t		*bitblt;
98     int			(*reserved1)(void);
99     int			(*reserved2)(void);
100     vi_diag_t		*diag;
101 } video_switch_t;
102 
103 #define save_palette(adp, pal)				\
104 	do {						\
105 		lwkt_gettoken(&tty_token);		\
106 		(*vidsw[(adp)->va_index]->save_palette)((adp), (pal)); \
107 		lwkt_reltoken(&tty_token);		\
108 	} while (0)
109 
110 #define load_palette(adp, pal)				\
111 	do {						\
112 		lwkt_gettoken(&tty_token);		\
113 		(*vidsw[(adp)->va_index]->load_palette)((adp), (pal)); \
114 		lwkt_reltoken(&tty_token);		\
115 	} while (0)
116 
117 #define get_mode_info(adp, mode, buf)			\
118 	(*vidsw[(adp)->va_index]->get_info)((adp), (mode), (buf))
119 
120 #define set_video_mode(adp, mode)			\
121 	(*vidsw[(adp)->va_index]->set_mode)((adp), (mode))
122 
123 #if 0 /* XXX conflicts with syscons' set_border() */
124 #define set_border(adp, border)				\
125 	do {						\
126 		lwkt_gettoken(&tty_token);		\
127 		(*vidsw[(adp)->va_index]->set_border)((adp), (border)); \
128 		lwkt_reltoken(&tty_token);		\
129 	} while (0)
130 #endif
131 
132 #define set_origin(adp, o)				\
133 	do {						\
134 		lwkt_gettoken(&tty_token);		\
135 		(*vidsw[(adp)->va_index]->set_win_org)(adp, o); \
136 		lwkt_reltoken(&tty_token);		\
137 	} while (0)
138 
139 /* XXX - add more macros */
140 
141 /* video driver */
142 typedef struct video_driver {
143     char		*name;
144     video_switch_t	*vidsw;
145     int			(*configure)(int); /* backdoor for the console driver */
146 } video_driver_t;
147 
148 #define VIDEO_DRIVER(name, sw, config)			\
149 	static struct video_driver name##_driver = {	\
150 		#name, &sw, config			\
151 	};						\
152 	DATA_SET(videodriver_set, name##_driver)
153 
154 /* global variables */
155 extern struct video_switch **vidsw;
156 
157 /* functions for the video card driver */
158 int		vid_register(video_adapter_t *adp);
159 int		vid_unregister(video_adapter_t *adp);
160 video_switch_t	*vid_get_switch(char *name);
161 void		vid_init_struct(video_adapter_t *adp, char *name, int type,
162 				int unit);
163 
164 /* functions for the video card client */
165 int		vid_allocate(char *driver, int unit, void *id);
166 int		vid_release(video_adapter_t *adp, void *id);
167 int		vid_find_adapter(char *driver, int unit);
168 video_adapter_t	*vid_get_adapter(int index);
169 
170 /* a backdoor for the console driver to tickle the video driver XXX */
171 int		vid_configure(int flags);
172 #define VIO_PROBE_ONLY	(1 << 0)	/* probe only, don't initialize */
173 
174 #ifdef FB_INSTALL_CDEV
175 
176 /* virtual frame buffer driver functions */
177 int		fb_attach(cdev_t dev, video_adapter_t *adp);
178 int		fb_detach(cdev_t dev, video_adapter_t *adp);
179 
180 /* generic frame buffer cdev driver functions */
181 
182 typedef struct genfb_softc {
183 	int		gfb_flags;	/* flag/status bits */
184 #define FB_OPEN		(1 << 0)
185 } genfb_softc_t;
186 
187 int		genfbopen(genfb_softc_t *sc, video_adapter_t *adp,
188 			  int flag, int mode, struct ucred *cred);
189 int		genfbclose(genfb_softc_t *sc, video_adapter_t *adp,
190 			   int flag, int mode);
191 int		genfbread(genfb_softc_t *sc, video_adapter_t *adp,
192 			  struct uio *uio, int flag);
193 int		genfbwrite(genfb_softc_t *sc, video_adapter_t *adp,
194 			   struct uio *uio, int flag);
195 int		genfbioctl(genfb_softc_t *sc, video_adapter_t *adp,
196 			   u_long cmd, caddr_t arg, int flag,
197 			   struct ucred *cred);
198 int		genfbmmap(genfb_softc_t *sc, video_adapter_t *adp,
199 			  vm_offset_t offset, int prot);
200 
201 #endif /* FB_INSTALL_CDEV */
202 
203 /* generic low-level driver functions */
204 
205 void		fb_dump_adp_info(char *driver, video_adapter_t *adp, int level);
206 void		fb_dump_mode_info(char *driver, video_adapter_t *adp,
207 				  video_info_t *info, int level);
208 int		fb_type(int adp_type);
209 int		fb_commonioctl(video_adapter_t *adp, u_long cmd, caddr_t arg);
210 
211 #endif /* _KERNEL */
212 
213 #endif /* !_DEV_FB_FBREG_H_ */
214