1 /*- 2 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD 3 * 4 * Copyright (c) 1999 Kazutaka YOKOTA <yokota@zodiac.mech.utsunomiya-u.ac.jp> 5 * All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions 9 * are met: 10 * 1. Redistributions of source code must retain the above copyright 11 * notice, this list of conditions and the following disclaimer as 12 * the first lines of this file unmodified. 13 * 2. Redistributions in binary form must reproduce the above copyright 14 * notice, this list of conditions and the following disclaimer in the 15 * documentation and/or other materials provided with the distribution. 16 * 17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 * 28 * $FreeBSD$ 29 */ 30 31 #ifndef _DEV_FB_FBREG_H_ 32 #define _DEV_FB_FBREG_H_ 33 34 #ifdef _KERNEL 35 36 #define V_MAX_ADAPTERS 8 /* XXX */ 37 38 /* some macros */ 39 #if defined(__amd64__) || defined(__i386__) 40 41 static __inline void 42 copyw(uint16_t *src, uint16_t *dst, size_t size) 43 { 44 size >>= 1; 45 while (size--) 46 *dst++ = *src++; 47 } 48 #define bcopy_io(s, d, c) copyw((void*)(s), (void*)(d), (c)) 49 #define bcopy_toio(s, d, c) copyw((void*)(s), (void*)(d), (c)) 50 #define bcopy_fromio(s, d, c) copyw((void*)(s), (void*)(d), (c)) 51 #define bzero_io(d, c) bzero((void *)(d), (c)) 52 #define fill_io(p, d, c) fill((p), (void *)(d), (c)) 53 #define fillw_io(p, d, c) fillw((p), (void *)(d), (c)) 54 #elif defined(__sparc64__) 55 static __inline void 56 fillw(int val, uint16_t *buf, size_t size) 57 { 58 while (size--) 59 *buf++ = val; 60 } 61 #elif defined(__powerpc__) 62 63 #define bcopy_io(s, d, c) ofwfb_bcopy((void *)(s), (void *)(d), (c)) 64 #define bcopy_toio(s, d, c) ofwfb_bcopy((void *)(s), (void *)(d), (c)) 65 #define bcopy_fromio(s, d, c) ofwfb_bcopy((void *)(s), (void *)(d), (c)) 66 #define bzero_io(d, c) ofwfb_bzero((void *)(d), (c)) 67 #define fillw(p, d, c) ofwfb_fillw((p), (void *)(d), (c)) 68 #define fillw_io(p, d, c) ofwfb_fillw((p), (void *)(d), (c)) 69 #define readw(a) ofwfb_readw((u_int16_t *)(a)) 70 #define writew(a, v) ofwfb_writew((u_int16_t *)(a), (v)) 71 void ofwfb_bcopy(const void *s, void *d, size_t c); 72 void ofwfb_bzero(void *d, size_t c); 73 void ofwfb_fillw(int pat, void *base, size_t cnt); 74 u_int16_t ofwfb_readw(u_int16_t *addr); 75 void ofwfb_writew(u_int16_t *addr, u_int16_t val); 76 77 #elif defined(__mips__) || defined(__arm__) 78 79 /* 80 * Use amd64/i386-like settings under the assumption that MIPS-based display 81 * drivers will have to add a level of indirection between a syscons-managed 82 * frame buffer and the actual video hardware. We are forced to do this 83 * because syscons doesn't carry around required busspace handles and tags to 84 * use here. This is only really a problem for true VGA devices hooked up to 85 * MIPS, as others will be performing a translation anyway. 86 */ 87 #define bcopy_io(s, d, c) memcpy((void *)(d), (void *)(s), (c)) 88 #define bcopy_toio(s, d, c) memcpy((void *)(d), (void *)(s), (c)) 89 #define bcopy_fromio(s, d, c) memcpy((void *)(d), (void *)(s), (c)) 90 #define bzero_io(d, c) memset((void *)(d), 0, (c)) 91 #define fill_io(p, d, c) memset((void *)(d), (p), (c)) 92 static __inline void 93 fillw(int val, uint16_t *buf, size_t size) 94 { 95 while (size--) 96 *buf++ = val; 97 } 98 #define fillw_io(p, d, c) fillw((p), (void *)(d), (c)) 99 100 #if defined(__arm__) 101 #define readw(a) (*(uint16_t*)(a)) 102 #define writew(a, v) (*(uint16_t*)(a) = (v)) 103 #endif 104 105 #else /* !__i386__ && !__amd64__ && !__sparc64__ && !__powerpc__ */ 106 #define bcopy_io(s, d, c) memcpy_io((d), (s), (c)) 107 #define bcopy_toio(s, d, c) memcpy_toio((d), (void *)(s), (c)) 108 #define bcopy_fromio(s, d, c) memcpy_fromio((void *)(d), (s), (c)) 109 #define bzero_io(d, c) memset_io((d), 0, (c)) 110 #define fill_io(p, d, c) memset_io((d), (p), (c)) 111 #define fillw(p, d, c) memsetw((d), (p), (c)) 112 #define fillw_io(p, d, c) memsetw_io((d), (p), (c)) 113 #endif /* !__i386__ */ 114 115 /* video function table */ 116 typedef int vi_probe_t(int unit, video_adapter_t **adpp, void *arg, int flags); 117 typedef int vi_init_t(int unit, video_adapter_t *adp, int flags); 118 typedef int vi_get_info_t(video_adapter_t *adp, int mode, video_info_t *info); 119 typedef int vi_query_mode_t(video_adapter_t *adp, video_info_t *info); 120 typedef int vi_set_mode_t(video_adapter_t *adp, int mode); 121 typedef int vi_save_font_t(video_adapter_t *adp, int page, int size, int width, 122 u_char *data, int c, int count); 123 typedef int vi_load_font_t(video_adapter_t *adp, int page, int size, int width, 124 u_char *data, int c, int count); 125 typedef int vi_show_font_t(video_adapter_t *adp, int page); 126 typedef int vi_save_palette_t(video_adapter_t *adp, u_char *palette); 127 typedef int vi_load_palette_t(video_adapter_t *adp, u_char *palette); 128 typedef int vi_set_border_t(video_adapter_t *adp, int border); 129 typedef int vi_save_state_t(video_adapter_t *adp, void *p, size_t size); 130 typedef int vi_load_state_t(video_adapter_t *adp, void *p); 131 typedef int vi_set_win_org_t(video_adapter_t *adp, off_t offset); 132 typedef int vi_read_hw_cursor_t(video_adapter_t *adp, int *col, int *row); 133 typedef int vi_set_hw_cursor_t(video_adapter_t *adp, int col, int row); 134 typedef int vi_set_hw_cursor_shape_t(video_adapter_t *adp, int base, 135 int height, int celsize, int blink); 136 typedef int vi_blank_display_t(video_adapter_t *adp, int mode); 137 /* defined in sys/fbio.h 138 #define V_DISPLAY_ON 0 139 #define V_DISPLAY_BLANK 1 140 #define V_DISPLAY_STAND_BY 2 141 #define V_DISPLAY_SUSPEND 3 142 */ 143 typedef int vi_mmap_t(video_adapter_t *adp, vm_ooffset_t offset, 144 vm_paddr_t *paddr, int prot, vm_memattr_t *memattr); 145 typedef int vi_ioctl_t(video_adapter_t *adp, u_long cmd, caddr_t data); 146 typedef int vi_clear_t(video_adapter_t *adp); 147 typedef int vi_fill_rect_t(video_adapter_t *adp, int val, int x, int y, 148 int cx, int cy); 149 typedef int vi_bitblt_t(video_adapter_t *adp, ...); 150 typedef int vi_diag_t(video_adapter_t *adp, int level); 151 typedef int vi_save_cursor_palette_t(video_adapter_t *adp, u_char *palette); 152 typedef int vi_load_cursor_palette_t(video_adapter_t *adp, u_char *palette); 153 typedef int vi_copy_t(video_adapter_t *adp, vm_offset_t src, vm_offset_t dst, 154 int n); 155 typedef int vi_putp_t(video_adapter_t *adp, vm_offset_t off, u_int32_t p, 156 u_int32_t a, int size, int bpp, int bit_ltor, 157 int byte_ltor); 158 typedef int vi_putc_t(video_adapter_t *adp, vm_offset_t off, u_int8_t c, 159 u_int8_t a); 160 typedef int vi_puts_t(video_adapter_t *adp, vm_offset_t off, u_int16_t *s, 161 int len); 162 typedef int vi_putm_t(video_adapter_t *adp, int x, int y, u_int8_t *pixel_image, 163 u_int32_t pixel_mask, int size, int width); 164 165 typedef struct video_switch { 166 vi_probe_t *probe; 167 vi_init_t *init; 168 vi_get_info_t *get_info; 169 vi_query_mode_t *query_mode; 170 vi_set_mode_t *set_mode; 171 vi_save_font_t *save_font; 172 vi_load_font_t *load_font; 173 vi_show_font_t *show_font; 174 vi_save_palette_t *save_palette; 175 vi_load_palette_t *load_palette; 176 vi_set_border_t *set_border; 177 vi_save_state_t *save_state; 178 vi_load_state_t *load_state; 179 vi_set_win_org_t *set_win_org; 180 vi_read_hw_cursor_t *read_hw_cursor; 181 vi_set_hw_cursor_t *set_hw_cursor; 182 vi_set_hw_cursor_shape_t *set_hw_cursor_shape; 183 vi_blank_display_t *blank_display; 184 vi_mmap_t *mmap; 185 vi_ioctl_t *ioctl; 186 vi_clear_t *clear; 187 vi_fill_rect_t *fill_rect; 188 vi_bitblt_t *bitblt; 189 int (*reserved1)(void); 190 int (*reserved2)(void); 191 vi_diag_t *diag; 192 vi_save_cursor_palette_t *save_cursor_palette; 193 vi_load_cursor_palette_t *load_cursor_palette; 194 vi_copy_t *copy; 195 vi_putp_t *putp; 196 vi_putc_t *putc; 197 vi_puts_t *puts; 198 vi_putm_t *putm; 199 } video_switch_t; 200 201 #define vidd_probe(unit, adpp, arg, flags) \ 202 (*vidsw[(adp)->va_index]->probe)((unit), (adpp), (arg), (flags)) 203 #define vidd_init(unit, adp, flags) \ 204 (*vidsw[(adp)->va_index]->init)((unit), (adp), (flags)) 205 #define vidd_get_info(adp, mode, info) \ 206 (*vidsw[(adp)->va_index]->get_info)((adp), (mode), (info)) 207 #define vidd_query_mode(adp, mode) \ 208 (*vidsw[(adp)->va_index]->query_mode)((adp), (mode)) 209 #define vidd_set_mode(adp, mode) \ 210 (*vidsw[(adp)->va_index]->set_mode)((adp), (mode)) 211 #define vidd_save_font(adp, page, size, width, data, c, count) \ 212 (*vidsw[(adp)->va_index]->save_font)((adp), (page), (size), \ 213 (width), (data), (c), (count)) 214 #define vidd_load_font(adp, page, size, width, data, c, count) \ 215 (*vidsw[(adp)->va_index]->load_font)((adp), (page), (size), \ 216 (width), (data), (c), (count)) 217 #define vidd_show_font(adp, page) \ 218 (*vidsw[(adp)->va_index]->show_font)((adp), (page)) 219 #define vidd_save_palette(adp, pallete) \ 220 (*vidsw[(adp)->va_index]->save_palette)((adp), (pallete)) 221 #define vidd_load_palette(adp, pallete) \ 222 (*vidsw[(adp)->va_index]->load_palette)((adp), (pallete)) 223 #define vidd_set_border(adp, border) \ 224 (*vidsw[(adp)->va_index]->set_border)((adp), (border)) 225 #define vidd_save_state(adp, p, size) \ 226 (*vidsw[(adp)->va_index]->save_state)((adp), (p), (size)) 227 #define vidd_load_state(adp, p) \ 228 (*vidsw[(adp)->va_index]->load_state)((adp), (p)) 229 #define vidd_set_win_org(adp, offset) \ 230 (*vidsw[(adp)->va_index]->set_win_org)((adp), (offset)) 231 #define vidd_read_hw_cursor(adp, col, row) \ 232 (*vidsw[(adp)->va_index]->read_hw_cursor)((adp), (col), (row)) 233 #define vidd_set_hw_cursor(adp, col, row) \ 234 (*vidsw[(adp)->va_index]->set_hw_cursor)((adp), (col), (row)) 235 #define vidd_set_hw_cursor_shape(adp, base, height, celsize, blink) \ 236 (*vidsw[(adp)->va_index]->set_hw_cursor_shape)((adp), (base), \ 237 (height), (celsize), (blink)) 238 #define vidd_blank_display(adp, mode) \ 239 (*vidsw[(adp)->va_index]->blank_display)((adp), (mode)) 240 #define vidd_mmap(adp, offset, paddr, prot, memattr) \ 241 (*vidsw[(adp)->va_index]->mmap)((adp), (offset), (paddr), \ 242 (prot), (memattr)) 243 #define vidd_ioctl(adp, cmd, data) \ 244 (*vidsw[(adp)->va_index]->ioctl)((adp), (cmd), (data)) 245 #define vidd_clear(adp) \ 246 (*vidsw[(adp)->va_index]->clear)((adp)) 247 #define vidd_fill_rect(adp, val, x, y, cx, cy) \ 248 (*vidsw[(adp)->va_index]->fill_rect)((adp), (val), (x), (y), \ 249 (cx), (cy)) 250 #define vidd_bitblt(adp, ...) \ 251 (*vidsw[(adp)->va_index]->bitblt)(adp, __VA_ARGS__) 252 #define vidd_diag(adp, level) \ 253 (*vidsw[(adp)->va_index]->diag)((adp), (level)) 254 #define vidd_save_cursor_palette(adp, palette) \ 255 (*vidsw[(adp)->va_index]->save_cursor_palette)((adp), (palette)) 256 #define vidd_load_cursor_palette(adp, palette) \ 257 (*vidsw[(adp)->va_index]->load_cursor_palette)((adp), (palette)) 258 #define vidd_copy(adp, src, dst, n) \ 259 (*vidsw[(adp)->va_index]->copy)((adp), (src), (dst), (n)) 260 #define vidd_putp(adp, offset, p, a, size, bpp, bit_ltor1, byte_ltor2) \ 261 (*vidsw[(adp)->va_index]->putp)((adp), (offset), (p), (a), \ 262 (size), (bpp), (bit_ltor1), (bit_ltor2)) 263 #define vidd_putc(adp, offset, c, a) \ 264 (*vidsw[(adp)->va_index]->putc)((adp), (offset), (c), (a)) 265 #define vidd_puts(adp, offset, s, len) \ 266 (*vidsw[(adp)->va_index]->puts)((adp), (offset), (s), (len)) 267 #define vidd_putm(adp, x, y, pixel_image, pixel_mask, size, width) \ 268 (*vidsw[(adp)->va_index]->putm)((adp), (x), (y), (pixel_image), \ 269 (pixel_mask), (size), (width)) 270 271 /* video driver */ 272 typedef struct video_driver { 273 char *name; 274 video_switch_t *vidsw; 275 int (*configure)(int); /* backdoor for the console driver */ 276 } video_driver_t; 277 278 #define VIDEO_DRIVER(name, sw, config) \ 279 static struct video_driver name##_driver = { \ 280 #name, &sw, config \ 281 }; \ 282 DATA_SET(videodriver_set, name##_driver); 283 284 /* global variables */ 285 extern struct video_switch **vidsw; 286 287 /* functions for the video card driver */ 288 int vid_register(video_adapter_t *adp); 289 int vid_unregister(video_adapter_t *adp); 290 video_switch_t *vid_get_switch(char *name); 291 void vid_init_struct(video_adapter_t *adp, char *name, int type, 292 int unit); 293 294 /* functions for the video card client */ 295 int vid_allocate(char *driver, int unit, void *id); 296 int vid_release(video_adapter_t *adp, void *id); 297 int vid_find_adapter(char *driver, int unit); 298 video_adapter_t *vid_get_adapter(int index); 299 300 /* a backdoor for the console driver to tickle the video driver XXX */ 301 int vid_configure(int flags); 302 #define VIO_PROBE_ONLY (1 << 0) /* probe only, don't initialize */ 303 304 #ifdef FB_INSTALL_CDEV 305 306 /* virtual frame buffer driver functions */ 307 int fb_attach(int unit, video_adapter_t *adp, 308 struct cdevsw *cdevsw); 309 int fb_detach(int unit, video_adapter_t *adp, 310 struct cdevsw *cdevsw); 311 312 /* generic frame buffer cdev driver functions */ 313 314 typedef struct genfb_softc { 315 int gfb_flags; /* flag/status bits */ 316 #define FB_OPEN (1 << 0) 317 } genfb_softc_t; 318 319 int genfbopen(genfb_softc_t *sc, video_adapter_t *adp, 320 int flag, int mode, struct thread *td); 321 int genfbclose(genfb_softc_t *sc, video_adapter_t *adp, 322 int flag, int mode, struct thread *td); 323 int genfbread(genfb_softc_t *sc, video_adapter_t *adp, 324 struct uio *uio, int flag); 325 int genfbwrite(genfb_softc_t *sc, video_adapter_t *adp, 326 struct uio *uio, int flag); 327 int genfbioctl(genfb_softc_t *sc, video_adapter_t *adp, 328 u_long cmd, caddr_t arg, int flag, struct thread *td); 329 int genfbmmap(genfb_softc_t *sc, video_adapter_t *adp, 330 vm_ooffset_t offset, vm_offset_t *paddr, 331 int prot, vm_memattr_t *memattr); 332 333 #endif /* FB_INSTALL_CDEV */ 334 335 /* generic low-level driver functions */ 336 337 void fb_dump_adp_info(char *driver, video_adapter_t *adp, int level); 338 void fb_dump_mode_info(char *driver, video_adapter_t *adp, 339 video_info_t *info, int level); 340 int fb_type(int adp_type); 341 int fb_commonioctl(video_adapter_t *adp, u_long cmd, caddr_t arg); 342 343 #endif /* _KERNEL */ 344 345 #endif /* !_DEV_FB_FBREG_H_ */ 346