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