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