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