1 /*- 2 * Copyright (c) 1999 Kazutaka YOKOTA <yokota@zodiac.mech.utsunomiya-u.ac.jp> 3 * Copyright (c) 1992-1998 S�ren Schmidt 4 * All rights reserved. 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: 9 * 1. Redistributions of source code must retain the above copyright 10 * notice, this list of conditions and the following disclaimer as 11 * the first lines of this file unmodified. 12 * 2. Redistributions in binary form must reproduce the above copyright 13 * notice, this list of conditions and the following disclaimer in the 14 * documentation and/or other materials provided with the distribution. 15 * 3. The name of the author may not be used to endorse or promote products 16 * derived from this software without specific prior written permission. 17 * 18 * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR 19 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 20 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 21 * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT, 22 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 23 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 27 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 * 29 */ 30 31 #include <sys/cdefs.h> 32 __FBSDID("$FreeBSD$"); 33 34 #include "opt_vga.h" 35 #include "opt_fb.h" 36 #include "opt_syscons.h" /* should be removed in the future, XXX */ 37 38 #include <sys/param.h> 39 #include <sys/systm.h> 40 #include <sys/kernel.h> 41 #include <sys/conf.h> 42 #include <sys/fcntl.h> 43 #include <sys/malloc.h> 44 #include <sys/fbio.h> 45 46 #include <vm/vm.h> 47 #include <vm/vm_param.h> 48 #include <vm/pmap.h> 49 50 #include <machine/md_var.h> 51 #if defined(__i386__) || defined(__amd64__) 52 #include <machine/pc/bios.h> 53 #endif 54 #include <machine/bus.h> 55 56 #include <dev/fb/fbreg.h> 57 #include <dev/fb/vgareg.h> 58 59 #include <isa/isareg.h> 60 61 #ifndef VGA_DEBUG 62 #define VGA_DEBUG 0 63 #endif 64 65 /* XXX machine/pc/bios.h has got too much i386-specific stuff in it */ 66 #ifndef BIOS_PADDRTOVADDR 67 #define BIOS_PADDRTOVADDR(x) (x) 68 #endif 69 70 int 71 vga_probe_unit(int unit, video_adapter_t *buf, int flags) 72 { 73 video_adapter_t *adp; 74 video_switch_t *sw; 75 int error; 76 77 sw = vid_get_switch(VGA_DRIVER_NAME); 78 if (sw == NULL) 79 return 0; 80 error = (*sw->probe)(unit, &adp, NULL, flags); 81 if (error) 82 return error; 83 bcopy(adp, buf, sizeof(*buf)); 84 return 0; 85 } 86 87 int 88 vga_attach_unit(int unit, vga_softc_t *sc, int flags) 89 { 90 video_switch_t *sw; 91 int error; 92 93 sw = vid_get_switch(VGA_DRIVER_NAME); 94 if (sw == NULL) 95 return ENXIO; 96 97 error = (*sw->probe)(unit, &sc->adp, NULL, flags); 98 if (error) 99 return error; 100 return (*sw->init)(unit, sc->adp, flags); 101 } 102 103 /* cdev driver functions */ 104 105 #ifdef FB_INSTALL_CDEV 106 107 int 108 vga_open(struct cdev *dev, vga_softc_t *sc, int flag, int mode, struct thread *td) 109 { 110 if (sc == NULL) 111 return ENXIO; 112 if (mode & (O_CREAT | O_APPEND | O_TRUNC)) 113 return ENODEV; 114 115 return genfbopen(&sc->gensc, sc->adp, flag, mode, td); 116 } 117 118 int 119 vga_close(struct cdev *dev, vga_softc_t *sc, int flag, int mode, struct thread *td) 120 { 121 return genfbclose(&sc->gensc, sc->adp, flag, mode, td); 122 } 123 124 int 125 vga_read(struct cdev *dev, vga_softc_t *sc, struct uio *uio, int flag) 126 { 127 return genfbread(&sc->gensc, sc->adp, uio, flag); 128 } 129 130 int 131 vga_write(struct cdev *dev, vga_softc_t *sc, struct uio *uio, int flag) 132 { 133 return genfbread(&sc->gensc, sc->adp, uio, flag); 134 } 135 136 int 137 vga_ioctl(struct cdev *dev, vga_softc_t *sc, u_long cmd, caddr_t arg, int flag, 138 struct thread *td) 139 { 140 return genfbioctl(&sc->gensc, sc->adp, cmd, arg, flag, td); 141 } 142 143 int 144 vga_mmap(struct cdev *dev, vga_softc_t *sc, vm_offset_t offset, vm_offset_t *paddr, 145 int prot) 146 { 147 return genfbmmap(&sc->gensc, sc->adp, offset, paddr, prot); 148 } 149 150 #endif /* FB_INSTALL_CDEV */ 151 152 /* LOW-LEVEL */ 153 154 #include <machine/clock.h> 155 #ifdef __i386__ 156 #include <machine/pc/vesa.h> 157 #endif 158 159 #define probe_done(adp) ((adp)->va_flags & V_ADP_PROBED) 160 #define init_done(adp) ((adp)->va_flags & V_ADP_INITIALIZED) 161 #define config_done(adp) ((adp)->va_flags & V_ADP_REGISTERED) 162 163 /* for compatibility with old kernel options */ 164 #ifdef SC_ALT_SEQACCESS 165 #undef SC_ALT_SEQACCESS 166 #undef VGA_ALT_SEQACCESS 167 #define VGA_ALT_SEQACCESS 1 168 #endif 169 170 #ifdef SLOW_VGA 171 #undef SLOW_VGA 172 #undef VGA_SLOW_IOACCESS 173 #define VGA_SLOW_IOACCESS 1 174 #endif 175 176 /* architecture dependent option */ 177 #ifndef __i386__ 178 #define VGA_NO_BIOS 1 179 #endif 180 181 /* this should really be in `rtc.h' */ 182 #define RTC_EQUIPMENT 0x14 183 184 /* various sizes */ 185 #define V_MODE_MAP_SIZE (M_VGA_CG320 + 1) 186 #define V_MODE_PARAM_SIZE 64 187 188 /* video adapter state buffer */ 189 struct adp_state { 190 int sig; 191 #define V_STATE_SIG 0x736f6962 192 u_char regs[V_MODE_PARAM_SIZE]; 193 }; 194 typedef struct adp_state adp_state_t; 195 196 /* video adapter information */ 197 #define DCC_MONO 0 198 #define DCC_CGA40 1 199 #define DCC_CGA80 2 200 #define DCC_EGAMONO 3 201 #define DCC_EGA40 4 202 #define DCC_EGA80 5 203 204 /* 205 * NOTE: `va_window' should have a virtual address, but is initialized 206 * with a physical address in the following table, as verify_adapter() 207 * will perform address conversion at run-time. 208 */ 209 static video_adapter_t adapter_init_value[] = { 210 /* DCC_MONO */ 211 { 0, KD_MONO, "mda", 0, 0, 0, IO_MDA, IO_MDASIZE, MONO_CRTC, 212 MDA_BUF_BASE, MDA_BUF_SIZE, MDA_BUF_BASE, MDA_BUF_SIZE, MDA_BUF_SIZE, 213 0, 0, 0, 0, 7, 0, }, 214 /* DCC_CGA40 */ 215 { 0, KD_CGA, "cga", 0, 0, V_ADP_COLOR, IO_CGA, IO_CGASIZE, COLOR_CRTC, 216 CGA_BUF_BASE, CGA_BUF_SIZE, CGA_BUF_BASE, CGA_BUF_SIZE, CGA_BUF_SIZE, 217 0, 0, 0, 0, 3, 0, }, 218 /* DCC_CGA80 */ 219 { 0, KD_CGA, "cga", 0, 0, V_ADP_COLOR, IO_CGA, IO_CGASIZE, COLOR_CRTC, 220 CGA_BUF_BASE, CGA_BUF_SIZE, CGA_BUF_BASE, CGA_BUF_SIZE, CGA_BUF_SIZE, 221 0, 0, 0, 0, 3, 0, }, 222 /* DCC_EGAMONO */ 223 { 0, KD_EGA, "ega", 0, 0, 0, IO_MDA, 48, MONO_CRTC, 224 EGA_BUF_BASE, EGA_BUF_SIZE, MDA_BUF_BASE, MDA_BUF_SIZE, MDA_BUF_SIZE, 225 0, 0, 0, 0, 7, 0, }, 226 /* DCC_EGA40 */ 227 { 0, KD_EGA, "ega", 0, 0, V_ADP_COLOR, IO_MDA, 48, COLOR_CRTC, 228 EGA_BUF_BASE, EGA_BUF_SIZE, CGA_BUF_BASE, CGA_BUF_SIZE, CGA_BUF_SIZE, 229 0, 0, 0, 0, 3, 0, }, 230 /* DCC_EGA80 */ 231 { 0, KD_EGA, "ega", 0, 0, V_ADP_COLOR, IO_MDA, 48, COLOR_CRTC, 232 EGA_BUF_BASE, EGA_BUF_SIZE, CGA_BUF_BASE, CGA_BUF_SIZE, CGA_BUF_SIZE, 233 0, 0, 0, 0, 3, 0, }, 234 }; 235 236 static video_adapter_t biosadapter[2]; 237 static int biosadapters = 0; 238 239 /* video driver declarations */ 240 static int vga_configure(int flags); 241 int (*vga_sub_configure)(int flags); 242 #if 0 243 static int vga_nop(void); 244 #endif 245 static int vga_error(void); 246 static vi_probe_t vga_probe; 247 static vi_init_t vga_init; 248 static vi_get_info_t vga_get_info; 249 static vi_query_mode_t vga_query_mode; 250 static vi_set_mode_t vga_set_mode; 251 static vi_save_font_t vga_save_font; 252 static vi_load_font_t vga_load_font; 253 static vi_show_font_t vga_show_font; 254 static vi_save_palette_t vga_save_palette; 255 static vi_load_palette_t vga_load_palette; 256 static vi_set_border_t vga_set_border; 257 static vi_save_state_t vga_save_state; 258 static vi_load_state_t vga_load_state; 259 static vi_set_win_org_t vga_set_origin; 260 static vi_read_hw_cursor_t vga_read_hw_cursor; 261 static vi_set_hw_cursor_t vga_set_hw_cursor; 262 static vi_set_hw_cursor_shape_t vga_set_hw_cursor_shape; 263 static vi_blank_display_t vga_blank_display; 264 static vi_mmap_t vga_mmap_buf; 265 static vi_ioctl_t vga_dev_ioctl; 266 #ifndef VGA_NO_MODE_CHANGE 267 static vi_clear_t vga_clear; 268 static vi_fill_rect_t vga_fill_rect; 269 static vi_bitblt_t vga_bitblt; 270 #else /* VGA_NO_MODE_CHANGE */ 271 #define vga_clear (vi_clear_t *)vga_error 272 #define vga_fill_rect (vi_fill_rect_t *)vga_error 273 #define vga_bitblt (vi_bitblt_t *)vga_error 274 #endif 275 static vi_diag_t vga_diag; 276 277 static video_switch_t vgavidsw = { 278 vga_probe, 279 vga_init, 280 vga_get_info, 281 vga_query_mode, 282 vga_set_mode, 283 vga_save_font, 284 vga_load_font, 285 vga_show_font, 286 vga_save_palette, 287 vga_load_palette, 288 vga_set_border, 289 vga_save_state, 290 vga_load_state, 291 vga_set_origin, 292 vga_read_hw_cursor, 293 vga_set_hw_cursor, 294 vga_set_hw_cursor_shape, 295 vga_blank_display, 296 vga_mmap_buf, 297 vga_dev_ioctl, 298 vga_clear, 299 vga_fill_rect, 300 vga_bitblt, 301 vga_error, 302 vga_error, 303 vga_diag, 304 }; 305 306 VIDEO_DRIVER(mda, vgavidsw, NULL); 307 VIDEO_DRIVER(cga, vgavidsw, NULL); 308 VIDEO_DRIVER(ega, vgavidsw, NULL); 309 VIDEO_DRIVER(vga, vgavidsw, vga_configure); 310 311 /* VGA BIOS standard video modes */ 312 #define EOT (-1) 313 #define NA (-2) 314 315 static video_info_t bios_vmode[] = { 316 /* CGA */ 317 { M_B40x25, V_INFO_COLOR, 40, 25, 8, 8, 2, 1, 318 CGA_BUF_BASE, CGA_BUF_SIZE, CGA_BUF_SIZE, 0, 0, V_INFO_MM_TEXT }, 319 { M_C40x25, V_INFO_COLOR, 40, 25, 8, 8, 4, 1, 320 CGA_BUF_BASE, CGA_BUF_SIZE, CGA_BUF_SIZE, 0, 0, V_INFO_MM_TEXT }, 321 { M_B80x25, V_INFO_COLOR, 80, 25, 8, 8, 2, 1, 322 CGA_BUF_BASE, CGA_BUF_SIZE, CGA_BUF_SIZE, 0, 0, V_INFO_MM_TEXT }, 323 { M_C80x25, V_INFO_COLOR, 80, 25, 8, 8, 4, 1, 324 CGA_BUF_BASE, CGA_BUF_SIZE, CGA_BUF_SIZE, 0, 0, V_INFO_MM_TEXT }, 325 /* EGA */ 326 { M_ENH_B40x25, V_INFO_COLOR, 40, 25, 8, 14, 2, 1, 327 CGA_BUF_BASE, CGA_BUF_SIZE, CGA_BUF_SIZE, 0, 0, V_INFO_MM_TEXT }, 328 { M_ENH_C40x25, V_INFO_COLOR, 40, 25, 8, 14, 4, 1, 329 CGA_BUF_BASE, CGA_BUF_SIZE, CGA_BUF_SIZE, 0, 0, V_INFO_MM_TEXT }, 330 { M_ENH_B80x25, V_INFO_COLOR, 80, 25, 8, 14, 2, 1, 331 CGA_BUF_BASE, CGA_BUF_SIZE, CGA_BUF_SIZE, 0, 0, V_INFO_MM_TEXT }, 332 { M_ENH_C80x25, V_INFO_COLOR, 80, 25, 8, 14, 4, 1, 333 CGA_BUF_BASE, CGA_BUF_SIZE, CGA_BUF_SIZE, 0, 0, V_INFO_MM_TEXT }, 334 /* VGA */ 335 { M_VGA_C40x25, V_INFO_COLOR, 40, 25, 8, 16, 4, 1, 336 CGA_BUF_BASE, CGA_BUF_SIZE, CGA_BUF_SIZE, 0, 0, V_INFO_MM_TEXT }, 337 { M_VGA_M80x25, 0, 80, 25, 8, 16, 2, 1, 338 MDA_BUF_BASE, MDA_BUF_SIZE, MDA_BUF_SIZE, 0, 0, V_INFO_MM_TEXT }, 339 { M_VGA_C80x25, V_INFO_COLOR, 80, 25, 8, 16, 4, 1, 340 CGA_BUF_BASE, CGA_BUF_SIZE, CGA_BUF_SIZE, 0, 0, V_INFO_MM_TEXT }, 341 /* MDA */ 342 { M_EGAMONO80x25, 0, 80, 25, 8, 14, 2, 1, 343 MDA_BUF_BASE, MDA_BUF_SIZE, MDA_BUF_SIZE, 0, 0, V_INFO_MM_TEXT }, 344 /* EGA */ 345 { M_ENH_B80x43, 0, 80, 43, 8, 8, 2, 1, 346 CGA_BUF_BASE, CGA_BUF_SIZE, CGA_BUF_SIZE, 0, 0, V_INFO_MM_TEXT }, 347 { M_ENH_C80x43, V_INFO_COLOR, 80, 43, 8, 8, 4, 1, 348 CGA_BUF_BASE, CGA_BUF_SIZE, CGA_BUF_SIZE, 0, 0, V_INFO_MM_TEXT }, 349 /* VGA */ 350 { M_VGA_M80x30, 0, 80, 30, 8, 16, 2, 1, 351 MDA_BUF_BASE, MDA_BUF_SIZE, MDA_BUF_SIZE, 0, 0, V_INFO_MM_TEXT }, 352 { M_VGA_C80x30, V_INFO_COLOR, 80, 30, 8, 16, 4, 1, 353 CGA_BUF_BASE, CGA_BUF_SIZE, CGA_BUF_SIZE, 0, 0, V_INFO_MM_TEXT }, 354 { M_VGA_M80x50, 0, 80, 50, 8, 8, 2, 1, 355 MDA_BUF_BASE, MDA_BUF_SIZE, MDA_BUF_SIZE, 0, 0, V_INFO_MM_TEXT }, 356 { M_VGA_C80x50, V_INFO_COLOR, 80, 50, 8, 8, 4, 1, 357 CGA_BUF_BASE, CGA_BUF_SIZE, CGA_BUF_SIZE, 0, 0, V_INFO_MM_TEXT }, 358 { M_VGA_M80x60, 0, 80, 60, 8, 8, 2, 1, 359 MDA_BUF_BASE, MDA_BUF_SIZE, MDA_BUF_SIZE, 0, 0, V_INFO_MM_TEXT }, 360 { M_VGA_C80x60, V_INFO_COLOR, 80, 60, 8, 8, 4, 1, 361 CGA_BUF_BASE, CGA_BUF_SIZE, CGA_BUF_SIZE, 0, 0, V_INFO_MM_TEXT }, 362 363 #ifndef VGA_NO_MODE_CHANGE 364 365 #ifdef VGA_WIDTH90 366 { M_VGA_M90x25, 0, 90, 25, 8, 16, 2, 1, 367 MDA_BUF_BASE, MDA_BUF_SIZE, MDA_BUF_SIZE, 0, 0, V_INFO_MM_TEXT }, 368 { M_VGA_C90x25, V_INFO_COLOR, 90, 25, 8, 16, 4, 1, 369 CGA_BUF_BASE, CGA_BUF_SIZE, CGA_BUF_SIZE, 0, 0, V_INFO_MM_TEXT }, 370 { M_VGA_M90x30, 0, 90, 30, 8, 16, 2, 1, 371 MDA_BUF_BASE, MDA_BUF_SIZE, MDA_BUF_SIZE, 0, 0, V_INFO_MM_TEXT }, 372 { M_VGA_C90x30, V_INFO_COLOR, 90, 30, 8, 16, 4, 1, 373 CGA_BUF_BASE, CGA_BUF_SIZE, CGA_BUF_SIZE, 0, 0, V_INFO_MM_TEXT }, 374 { M_VGA_M90x43, 0, 90, 43, 8, 8, 2, 1, 375 CGA_BUF_BASE, CGA_BUF_SIZE, CGA_BUF_SIZE, 0, 0, V_INFO_MM_TEXT }, 376 { M_VGA_C90x43, V_INFO_COLOR, 90, 43, 8, 8, 4, 1, 377 CGA_BUF_BASE, CGA_BUF_SIZE, CGA_BUF_SIZE, 0, 0, V_INFO_MM_TEXT }, 378 { M_VGA_M90x50, 0, 90, 50, 8, 8, 2, 1, 379 MDA_BUF_BASE, MDA_BUF_SIZE, MDA_BUF_SIZE, 0, 0, V_INFO_MM_TEXT }, 380 { M_VGA_C90x50, V_INFO_COLOR, 90, 50, 8, 8, 4, 1, 381 CGA_BUF_BASE, CGA_BUF_SIZE, CGA_BUF_SIZE, 0, 0, V_INFO_MM_TEXT }, 382 { M_VGA_M90x60, 0, 90, 60, 8, 8, 2, 1, 383 MDA_BUF_BASE, MDA_BUF_SIZE, MDA_BUF_SIZE, 0, 0, V_INFO_MM_TEXT }, 384 { M_VGA_C90x60, V_INFO_COLOR, 90, 60, 8, 8, 4, 1, 385 CGA_BUF_BASE, CGA_BUF_SIZE, CGA_BUF_SIZE, 0, 0, V_INFO_MM_TEXT }, 386 #endif /* VGA_WIDTH90 */ 387 388 /* CGA */ 389 { M_BG320, V_INFO_COLOR | V_INFO_GRAPHICS, 320, 200, 8, 8, 2, 1, 390 CGA_BUF_BASE, CGA_BUF_SIZE, CGA_BUF_SIZE, 0, 0, V_INFO_MM_CGA }, 391 { M_CG320, V_INFO_COLOR | V_INFO_GRAPHICS, 320, 200, 8, 8, 2, 1, 392 CGA_BUF_BASE, CGA_BUF_SIZE, CGA_BUF_SIZE, 0, 0, V_INFO_MM_CGA }, 393 { M_BG640, V_INFO_COLOR | V_INFO_GRAPHICS, 640, 200, 8, 8, 1, 1, 394 CGA_BUF_BASE, CGA_BUF_SIZE, CGA_BUF_SIZE, 0, 0, V_INFO_MM_CGA }, 395 /* EGA */ 396 { M_CG320_D, V_INFO_COLOR | V_INFO_GRAPHICS, 320, 200, 8, 8, 4, 4, 397 GRAPHICS_BUF_BASE, GRAPHICS_BUF_SIZE, GRAPHICS_BUF_SIZE, 0, 0, 398 V_INFO_MM_PLANAR }, 399 { M_CG640_E, V_INFO_COLOR | V_INFO_GRAPHICS, 640, 200, 8, 8, 4, 4, 400 GRAPHICS_BUF_BASE, GRAPHICS_BUF_SIZE, GRAPHICS_BUF_SIZE, 0, 0 , 401 V_INFO_MM_PLANAR }, 402 { M_EGAMONOAPA, V_INFO_GRAPHICS, 640, 350, 8, 14, 4, 4, 403 GRAPHICS_BUF_BASE, GRAPHICS_BUF_SIZE, 64*1024, 0, 0 , 404 V_INFO_MM_PLANAR }, 405 { M_ENHMONOAPA2,V_INFO_GRAPHICS, 640, 350, 8, 14, 4, 4, 406 GRAPHICS_BUF_BASE, GRAPHICS_BUF_SIZE, GRAPHICS_BUF_SIZE, 0, 0 , 407 V_INFO_MM_PLANAR }, 408 { M_CG640x350, V_INFO_COLOR | V_INFO_GRAPHICS, 640, 350, 8, 14, 2, 2, 409 GRAPHICS_BUF_BASE, GRAPHICS_BUF_SIZE, GRAPHICS_BUF_SIZE, 0, 0 , 410 V_INFO_MM_PLANAR }, 411 { M_ENH_CG640, V_INFO_COLOR | V_INFO_GRAPHICS, 640, 350, 8, 14, 4, 4, 412 GRAPHICS_BUF_BASE, GRAPHICS_BUF_SIZE, GRAPHICS_BUF_SIZE, 0, 0 , 413 V_INFO_MM_PLANAR }, 414 /* VGA */ 415 { M_BG640x480, V_INFO_COLOR | V_INFO_GRAPHICS, 640, 480, 8, 16, 4, 4, 416 GRAPHICS_BUF_BASE, GRAPHICS_BUF_SIZE, GRAPHICS_BUF_SIZE, 0, 0 , 417 V_INFO_MM_PLANAR }, 418 { M_CG640x480, V_INFO_COLOR | V_INFO_GRAPHICS, 640, 480, 8, 16, 4, 4, 419 GRAPHICS_BUF_BASE, GRAPHICS_BUF_SIZE, GRAPHICS_BUF_SIZE, 0, 0 , 420 V_INFO_MM_PLANAR }, 421 { M_VGA_CG320, V_INFO_COLOR | V_INFO_GRAPHICS, 320, 200, 8, 8, 8, 1, 422 GRAPHICS_BUF_BASE, GRAPHICS_BUF_SIZE, GRAPHICS_BUF_SIZE, 0, 0, 423 V_INFO_MM_PACKED, 1 }, 424 { M_VGA_MODEX, V_INFO_COLOR | V_INFO_GRAPHICS, 320, 240, 8, 8, 8, 4, 425 GRAPHICS_BUF_BASE, GRAPHICS_BUF_SIZE, GRAPHICS_BUF_SIZE, 0, 0, 426 V_INFO_MM_VGAX, 1 }, 427 #endif /* VGA_NO_MODE_CHANGE */ 428 429 { EOT }, 430 }; 431 432 static int vga_init_done = FALSE; 433 #if !defined(VGA_NO_BIOS) && !defined(VGA_NO_MODE_CHANGE) 434 static u_char *video_mode_ptr = NULL; /* EGA/VGA */ 435 static u_char *video_mode_ptr2 = NULL; /* CGA/MDA */ 436 #endif 437 static u_char *mode_map[V_MODE_MAP_SIZE]; 438 static adp_state_t adpstate; 439 static adp_state_t adpstate2; 440 static int rows_offset = 1; 441 442 /* local macros and functions */ 443 #define BIOS_SADDRTOLADDR(p) ((((p) & 0xffff0000) >> 12) + ((p) & 0x0000ffff)) 444 445 #if !defined(VGA_NO_BIOS) && !defined(VGA_NO_MODE_CHANGE) 446 static void map_mode_table(u_char *map[], u_char *table, int max); 447 #endif 448 static void clear_mode_map(video_adapter_t *adp, u_char *map[], int max, 449 int color); 450 #if !defined(VGA_NO_BIOS) && !defined(VGA_NO_MODE_CHANGE) 451 static int map_mode_num(int mode); 452 #endif 453 static int map_gen_mode_num(int type, int color, int mode); 454 static int map_bios_mode_num(int type, int color, int bios_mode); 455 static u_char *get_mode_param(int mode); 456 #ifndef VGA_NO_BIOS 457 static void fill_adapter_param(int code, video_adapter_t *adp); 458 #endif 459 static int verify_adapter(video_adapter_t *adp); 460 static void update_adapter_info(video_adapter_t *adp, video_info_t *info); 461 #if !defined(VGA_NO_BIOS) && !defined(VGA_NO_MODE_CHANGE) 462 #define COMP_IDENTICAL 0 463 #define COMP_SIMILAR 1 464 #define COMP_DIFFERENT 2 465 static int comp_adpregs(u_char *buf1, u_char *buf2); 466 #endif 467 static int probe_adapters(void); 468 static int set_line_length(video_adapter_t *adp, int pixel); 469 static int set_display_start(video_adapter_t *adp, int x, int y); 470 static void filll_io(int val, vm_offset_t d, size_t size); 471 472 #ifndef VGA_NO_MODE_CHANGE 473 #ifdef VGA_WIDTH90 474 static void set_width90(adp_state_t *params); 475 #endif 476 #endif /* !VGA_NO_MODE_CHANGE */ 477 478 #ifndef VGA_NO_FONT_LOADING 479 #define PARAM_BUFSIZE 6 480 static void set_font_mode(video_adapter_t *adp, u_char *buf); 481 static void set_normal_mode(video_adapter_t *adp, u_char *buf); 482 #endif 483 484 #ifndef VGA_NO_MODE_CHANGE 485 static void planar_fill(video_adapter_t *adp, int val); 486 static void packed_fill(video_adapter_t *adp, int val); 487 static void direct_fill(video_adapter_t *adp, int val); 488 #ifdef notyet 489 static void planar_fill_rect(video_adapter_t *adp, int val, int x, int y, 490 int cx, int cy); 491 static void packed_fill_rect(video_adapter_t *adp, int val, int x, int y, 492 int cx, int cy); 493 static void direct_fill_rect16(video_adapter_t *adp, int val, int x, int y, 494 int cx, int cy); 495 static void direct_fill_rect24(video_adapter_t *adp, int val, int x, int y, 496 int cx, int cy); 497 static void direct_fill_rect32(video_adapter_t *adp, int val, int x, int y, 498 int cx, int cy); 499 #endif /* notyet */ 500 #endif /* !VGA_NO_MODE_CHANGE */ 501 502 static void dump_buffer(u_char *buf, size_t len); 503 504 #define ISMAPPED(pa, width) \ 505 (((pa) <= (u_long)0x1000 - (width)) \ 506 || ((pa) >= ISA_HOLE_START && (pa) <= 0x100000 - (width))) 507 508 #define prologue(adp, flag, err) \ 509 if (!vga_init_done || !((adp)->va_flags & (flag))) \ 510 return (err) 511 512 /* a backdoor for the console driver */ 513 static int 514 vga_configure(int flags) 515 { 516 int i; 517 518 probe_adapters(); 519 for (i = 0; i < biosadapters; ++i) { 520 if (!probe_done(&biosadapter[i])) 521 continue; 522 biosadapter[i].va_flags |= V_ADP_INITIALIZED; 523 if (!config_done(&biosadapter[i])) { 524 if (vid_register(&biosadapter[i]) < 0) 525 continue; 526 biosadapter[i].va_flags |= V_ADP_REGISTERED; 527 } 528 } 529 if (vga_sub_configure != NULL) 530 (*vga_sub_configure)(flags); 531 532 return biosadapters; 533 } 534 535 /* local subroutines */ 536 537 #if !defined(VGA_NO_BIOS) && !defined(VGA_NO_MODE_CHANGE) 538 /* construct the mode parameter map */ 539 static void 540 map_mode_table(u_char *map[], u_char *table, int max) 541 { 542 int i; 543 544 for(i = 0; i < max; ++i) 545 map[i] = table + i*V_MODE_PARAM_SIZE; 546 for(; i < V_MODE_MAP_SIZE; ++i) 547 map[i] = NULL; 548 } 549 #endif /* !VGA_NO_BIOS && !VGA_NO_MODE_CHANGE */ 550 551 static void 552 clear_mode_map(video_adapter_t *adp, u_char *map[], int max, int color) 553 { 554 video_info_t info; 555 int i; 556 557 /* 558 * NOTE: we don't touch `bios_vmode[]' because it is shared 559 * by all adapters. 560 */ 561 for(i = 0; i < max; ++i) { 562 if (vga_get_info(adp, i, &info)) 563 continue; 564 if ((info.vi_flags & V_INFO_COLOR) != color) 565 map[i] = NULL; 566 } 567 } 568 569 #if !defined(VGA_NO_BIOS) && !defined(VGA_NO_MODE_CHANGE) 570 /* map the non-standard video mode to a known mode number */ 571 static int 572 map_mode_num(int mode) 573 { 574 static struct { 575 int from; 576 int to; 577 } mode_map[] = { 578 { M_ENH_B80x43, M_ENH_B80x25 }, 579 { M_ENH_C80x43, M_ENH_C80x25 }, 580 { M_VGA_M80x30, M_VGA_M80x25 }, 581 { M_VGA_C80x30, M_VGA_C80x25 }, 582 { M_VGA_M80x50, M_VGA_M80x25 }, 583 { M_VGA_C80x50, M_VGA_C80x25 }, 584 { M_VGA_M80x60, M_VGA_M80x25 }, 585 { M_VGA_C80x60, M_VGA_C80x25 }, 586 #ifdef VGA_WIDTH90 587 { M_VGA_M90x25, M_VGA_M80x25 }, 588 { M_VGA_C90x25, M_VGA_C80x25 }, 589 { M_VGA_M90x30, M_VGA_M80x25 }, 590 { M_VGA_C90x30, M_VGA_C80x25 }, 591 { M_VGA_M90x43, M_ENH_B80x25 }, 592 { M_VGA_C90x43, M_ENH_C80x25 }, 593 { M_VGA_M90x50, M_VGA_M80x25 }, 594 { M_VGA_C90x50, M_VGA_C80x25 }, 595 { M_VGA_M90x60, M_VGA_M80x25 }, 596 { M_VGA_C90x60, M_VGA_C80x25 }, 597 #endif 598 { M_VGA_MODEX, M_VGA_CG320 }, 599 }; 600 int i; 601 602 for (i = 0; i < sizeof(mode_map)/sizeof(mode_map[0]); ++i) { 603 if (mode_map[i].from == mode) 604 return mode_map[i].to; 605 } 606 return mode; 607 } 608 #endif /* !VGA_NO_BIOS && !VGA_NO_MODE_CHANGE */ 609 610 /* map a generic video mode to a known mode number */ 611 static int 612 map_gen_mode_num(int type, int color, int mode) 613 { 614 static struct { 615 int from; 616 int to_color; 617 int to_mono; 618 } mode_map[] = { 619 { M_TEXT_80x30, M_VGA_C80x30, M_VGA_M80x30, }, 620 { M_TEXT_80x43, M_ENH_C80x43, M_ENH_B80x43, }, 621 { M_TEXT_80x50, M_VGA_C80x50, M_VGA_M80x50, }, 622 { M_TEXT_80x60, M_VGA_C80x60, M_VGA_M80x60, }, 623 }; 624 int i; 625 626 if (mode == M_TEXT_80x25) { 627 switch (type) { 628 629 case KD_VGA: 630 if (color) 631 return M_VGA_C80x25; 632 else 633 return M_VGA_M80x25; 634 break; 635 636 case KD_EGA: 637 if (color) 638 return M_ENH_C80x25; 639 else 640 return M_EGAMONO80x25; 641 break; 642 643 case KD_CGA: 644 return M_C80x25; 645 646 case KD_MONO: 647 case KD_HERCULES: 648 return M_EGAMONO80x25; /* XXX: this name is confusing */ 649 650 default: 651 return -1; 652 } 653 } 654 655 for (i = 0; i < sizeof(mode_map)/sizeof(mode_map[0]); ++i) { 656 if (mode_map[i].from == mode) 657 return ((color) ? mode_map[i].to_color : mode_map[i].to_mono); 658 } 659 return mode; 660 } 661 662 /* turn the BIOS video number into our video mode number */ 663 static int 664 map_bios_mode_num(int type, int color, int bios_mode) 665 { 666 static int cga_modes[7] = { 667 M_B40x25, M_C40x25, /* 0, 1 */ 668 M_B80x25, M_C80x25, /* 2, 3 */ 669 M_BG320, M_CG320, 670 M_BG640, 671 }; 672 static int ega_modes[17] = { 673 M_ENH_B40x25, M_ENH_C40x25, /* 0, 1 */ 674 M_ENH_B80x25, M_ENH_C80x25, /* 2, 3 */ 675 M_BG320, M_CG320, 676 M_BG640, 677 M_EGAMONO80x25, /* 7 */ 678 8, 9, 10, 11, 12, 679 M_CG320_D, 680 M_CG640_E, 681 M_ENHMONOAPA2, /* XXX: video momery > 64K */ 682 M_ENH_CG640, /* XXX: video momery > 64K */ 683 }; 684 static int vga_modes[20] = { 685 M_VGA_C40x25, M_VGA_C40x25, /* 0, 1 */ 686 M_VGA_C80x25, M_VGA_C80x25, /* 2, 3 */ 687 M_BG320, M_CG320, 688 M_BG640, 689 M_VGA_M80x25, /* 7 */ 690 8, 9, 10, 11, 12, 691 M_CG320_D, 692 M_CG640_E, 693 M_ENHMONOAPA2, 694 M_ENH_CG640, 695 M_BG640x480, M_CG640x480, 696 M_VGA_CG320, 697 }; 698 699 switch (type) { 700 701 case KD_VGA: 702 if (bios_mode < sizeof(vga_modes)/sizeof(vga_modes[0])) 703 return vga_modes[bios_mode]; 704 else if (color) 705 return M_VGA_C80x25; 706 else 707 return M_VGA_M80x25; 708 break; 709 710 case KD_EGA: 711 if (bios_mode < sizeof(ega_modes)/sizeof(ega_modes[0])) 712 return ega_modes[bios_mode]; 713 else if (color) 714 return M_ENH_C80x25; 715 else 716 return M_EGAMONO80x25; 717 break; 718 719 case KD_CGA: 720 if (bios_mode < sizeof(cga_modes)/sizeof(cga_modes[0])) 721 return cga_modes[bios_mode]; 722 else 723 return M_C80x25; 724 break; 725 726 case KD_MONO: 727 case KD_HERCULES: 728 return M_EGAMONO80x25; /* XXX: this name is confusing */ 729 730 default: 731 break; 732 } 733 return -1; 734 } 735 736 /* look up a parameter table entry */ 737 static u_char 738 *get_mode_param(int mode) 739 { 740 #if !defined(VGA_NO_BIOS) && !defined(VGA_NO_MODE_CHANGE) 741 if (mode >= V_MODE_MAP_SIZE) 742 mode = map_mode_num(mode); 743 #endif 744 if ((mode >= 0) && (mode < V_MODE_MAP_SIZE)) 745 return mode_map[mode]; 746 else 747 return NULL; 748 } 749 750 #ifndef VGA_NO_BIOS 751 static void 752 fill_adapter_param(int code, video_adapter_t *adp) 753 { 754 static struct { 755 int primary; 756 int secondary; 757 } dcc[] = { 758 { DCC_MONO, DCC_EGA40 /* CGA monitor */ }, 759 { DCC_MONO, DCC_EGA80 /* CGA monitor */ }, 760 { DCC_MONO, DCC_EGA80 }, 761 { DCC_MONO, DCC_EGA80 }, 762 { DCC_CGA40, DCC_EGAMONO }, 763 { DCC_CGA80, DCC_EGAMONO }, 764 { DCC_EGA40 /* CGA monitor */, DCC_MONO}, 765 { DCC_EGA80 /* CGA monitor */, DCC_MONO}, 766 { DCC_EGA80, DCC_MONO }, 767 { DCC_EGA80, DCC_MONO }, 768 { DCC_EGAMONO, DCC_CGA40 }, 769 { DCC_EGAMONO, DCC_CGA80 }, 770 }; 771 772 if ((code < 0) || (code >= sizeof(dcc)/sizeof(dcc[0]))) { 773 adp[V_ADP_PRIMARY] = adapter_init_value[DCC_MONO]; 774 adp[V_ADP_SECONDARY] = adapter_init_value[DCC_CGA80]; 775 } else { 776 adp[V_ADP_PRIMARY] = adapter_init_value[dcc[code].primary]; 777 adp[V_ADP_SECONDARY] = adapter_init_value[dcc[code].secondary]; 778 } 779 } 780 #endif /* VGA_NO_BIOS */ 781 782 static int 783 verify_adapter(video_adapter_t *adp) 784 { 785 vm_offset_t buf; 786 u_int16_t v; 787 #if !defined(VGA_NO_BIOS) && !defined(VGA_NO_MODE_CHANGE) 788 u_int32_t p; 789 #endif 790 791 buf = BIOS_PADDRTOVADDR(adp->va_window); 792 v = readw(buf); 793 writew(buf, 0xA55A); 794 if (readw(buf) != 0xA55A) 795 return ENXIO; 796 writew(buf, v); 797 798 switch (adp->va_type) { 799 800 case KD_EGA: 801 outb(adp->va_crtc_addr, 7); 802 if (inb(adp->va_crtc_addr) == 7) { 803 adp->va_type = KD_VGA; 804 adp->va_name = "vga"; 805 adp->va_flags |= V_ADP_STATESAVE | V_ADP_PALETTE; 806 } 807 adp->va_flags |= V_ADP_STATELOAD | V_ADP_BORDER; 808 /* the color adapter may be in the 40x25 mode... XXX */ 809 810 #if !defined(VGA_NO_BIOS) && !defined(VGA_NO_MODE_CHANGE) 811 /* get the BIOS video mode pointer */ 812 p = *(u_int32_t *)BIOS_PADDRTOVADDR(0x4a8); 813 p = BIOS_SADDRTOLADDR(p); 814 if (ISMAPPED(p, sizeof(u_int32_t))) { 815 p = *(u_int32_t *)BIOS_PADDRTOVADDR(p); 816 p = BIOS_SADDRTOLADDR(p); 817 if (ISMAPPED(p, V_MODE_PARAM_SIZE)) 818 video_mode_ptr = (u_char *)BIOS_PADDRTOVADDR(p); 819 } 820 #endif 821 break; 822 823 case KD_CGA: 824 adp->va_flags |= V_ADP_COLOR | V_ADP_BORDER; 825 /* may be in the 40x25 mode... XXX */ 826 #if !defined(VGA_NO_BIOS) && !defined(VGA_NO_MODE_CHANGE) 827 /* get the BIOS video mode pointer */ 828 p = *(u_int32_t *)BIOS_PADDRTOVADDR(0x1d*4); 829 p = BIOS_SADDRTOLADDR(p); 830 video_mode_ptr2 = (u_char *)BIOS_PADDRTOVADDR(p); 831 #endif 832 break; 833 834 case KD_MONO: 835 #if !defined(VGA_NO_BIOS) && !defined(VGA_NO_MODE_CHANGE) 836 /* get the BIOS video mode pointer */ 837 p = *(u_int32_t *)BIOS_PADDRTOVADDR(0x1d*4); 838 p = BIOS_SADDRTOLADDR(p); 839 video_mode_ptr2 = (u_char *)BIOS_PADDRTOVADDR(p); 840 #endif 841 break; 842 } 843 844 return 0; 845 } 846 847 static void 848 update_adapter_info(video_adapter_t *adp, video_info_t *info) 849 { 850 adp->va_flags &= ~V_ADP_COLOR; 851 adp->va_flags |= 852 (info->vi_flags & V_INFO_COLOR) ? V_ADP_COLOR : 0; 853 adp->va_crtc_addr = 854 (adp->va_flags & V_ADP_COLOR) ? COLOR_CRTC : MONO_CRTC; 855 adp->va_window = BIOS_PADDRTOVADDR(info->vi_window); 856 adp->va_window_size = info->vi_window_size; 857 adp->va_window_gran = info->vi_window_gran; 858 adp->va_window_orig = 0; 859 /* XXX */ 860 adp->va_buffer = info->vi_buffer; 861 adp->va_buffer_size = info->vi_buffer_size; 862 if (info->vi_mem_model == V_INFO_MM_VGAX) { 863 adp->va_line_width = info->vi_width/2; 864 } else if (info->vi_flags & V_INFO_GRAPHICS) { 865 switch (info->vi_depth/info->vi_planes) { 866 case 1: 867 adp->va_line_width = info->vi_width/8; 868 break; 869 case 2: 870 adp->va_line_width = info->vi_width/4; 871 break; 872 case 4: 873 adp->va_line_width = info->vi_width/2; 874 break; 875 case 8: 876 default: /* shouldn't happen */ 877 adp->va_line_width = info->vi_width; 878 break; 879 } 880 } else { 881 adp->va_line_width = info->vi_width; 882 } 883 adp->va_disp_start.x = 0; 884 adp->va_disp_start.y = 0; 885 bcopy(info, &adp->va_info, sizeof(adp->va_info)); 886 } 887 888 #if !defined(VGA_NO_BIOS) && !defined(VGA_NO_MODE_CHANGE) 889 /* compare two parameter table entries */ 890 static int 891 comp_adpregs(u_char *buf1, u_char *buf2) 892 { 893 static struct { 894 u_char mask; 895 } params[V_MODE_PARAM_SIZE] = { 896 {0xff}, {0x00}, {0xff}, /* COLS}, ROWS}, POINTS */ 897 {0x00}, {0x00}, /* page length */ 898 {0xfe}, {0xff}, {0xff}, {0xff}, /* sequencer registers */ 899 {0xf3}, /* misc register */ 900 {0xff}, {0xff}, {0xff}, {0x7f}, {0xff}, /* CRTC */ 901 {0xff}, {0xff}, {0xff}, {0x7f}, {0xff}, 902 {0x00}, {0x00}, {0x00}, {0x00}, {0x00}, 903 {0x00}, {0xff}, {0x7f}, {0xff}, {0xff}, 904 {0x7f}, {0xff}, {0xff}, {0xef}, {0xff}, 905 {0xff}, {0xff}, {0xff}, {0xff}, {0xff}, /* attribute controller regs */ 906 {0xff}, {0xff}, {0xff}, {0xff}, {0xff}, 907 {0xff}, {0xff}, {0xff}, {0xff}, {0xff}, 908 {0xff}, {0xff}, {0xff}, {0xff}, {0xf0}, 909 {0xff}, {0xff}, {0xff}, {0xff}, {0xff}, /* GDC register */ 910 {0xff}, {0xff}, {0xff}, {0xff}, 911 }; 912 int identical = TRUE; 913 int i; 914 915 if ((buf1 == NULL) || (buf2 == NULL)) 916 return COMP_DIFFERENT; 917 918 for (i = 0; i < sizeof(params)/sizeof(params[0]); ++i) { 919 if (params[i].mask == 0) /* don't care */ 920 continue; 921 if ((buf1[i] & params[i].mask) != (buf2[i] & params[i].mask)) 922 return COMP_DIFFERENT; 923 if (buf1[i] != buf2[i]) 924 identical = FALSE; 925 } 926 return (identical) ? COMP_IDENTICAL : COMP_SIMILAR; 927 } 928 #endif /* !VGA_NO_BIOS && !VGA_NO_MODE_CHANGE */ 929 930 /* probe video adapters and return the number of detected adapters */ 931 static int 932 probe_adapters(void) 933 { 934 video_adapter_t *adp; 935 video_info_t info; 936 #if !defined(VGA_NO_BIOS) && !defined(VGA_NO_MODE_CHANGE) 937 u_char *mp; 938 #endif 939 int i; 940 941 /* do this test only once */ 942 if (vga_init_done) 943 return biosadapters; 944 vga_init_done = TRUE; 945 946 /* 947 * Locate display adapters. 948 * The AT architecture supports upto two adapters. `syscons' allows 949 * the following combinations of adapters: 950 * 1) MDA + CGA 951 * 2) MDA + EGA/VGA color 952 * 3) CGA + EGA/VGA mono 953 * Note that `syscons' doesn't bother with MCGA as it is only 954 * avaiable for low end PS/2 models which has 80286 or earlier CPUs, 955 * thus, they are not running FreeBSD! 956 * When there are two adapaters in the system, one becomes `primary' 957 * and the other `secondary'. The EGA adapter has a set of DIP 958 * switches on board for this information and the EGA BIOS copies 959 * it in the BIOS data area BIOSDATA_VIDEOSWITCH (40:88). 960 * The VGA BIOS has more sophisticated mechanism and has this 961 * information in BIOSDATA_DCCINDEX (40:8a), but it also maintains 962 * compatibility with the EGA BIOS by updating BIOSDATA_VIDEOSWITCH. 963 */ 964 965 /* 966 * Check rtc and BIOS data area. 967 * XXX: we don't use BIOSDATA_EQUIPMENT, since it is not a dead 968 * copy of RTC_EQUIPMENT. Bits 4 and 5 of ETC_EQUIPMENT are 969 * zeros for EGA and VGA. However, the EGA/VGA BIOS sets 970 * these bits in BIOSDATA_EQUIPMENT according to the monitor 971 * type detected. 972 */ 973 #ifndef VGA_NO_BIOS 974 if (*(u_int32_t *)BIOS_PADDRTOVADDR(0x4a8)) { 975 /* EGA/VGA BIOS is present */ 976 fill_adapter_param(readb(BIOS_PADDRTOVADDR(0x488)) & 0x0f, 977 biosadapter); 978 } else { 979 switch ((rtcin(RTC_EQUIPMENT) >> 4) & 3) { /* bit 4 and 5 */ 980 case 0: 981 /* EGA/VGA: shouldn't be happening */ 982 fill_adapter_param(readb(BIOS_PADDRTOVADDR(0x488)) & 0x0f, 983 biosadapter); 984 break; 985 case 1: 986 /* CGA 40x25 */ 987 /* FIXME: switch to the 80x25 mode? XXX */ 988 biosadapter[V_ADP_PRIMARY] = adapter_init_value[DCC_CGA40]; 989 biosadapter[V_ADP_SECONDARY] = adapter_init_value[DCC_MONO]; 990 break; 991 case 2: 992 /* CGA 80x25 */ 993 biosadapter[V_ADP_PRIMARY] = adapter_init_value[DCC_CGA80]; 994 biosadapter[V_ADP_SECONDARY] = adapter_init_value[DCC_MONO]; 995 break; 996 case 3: 997 /* MDA */ 998 biosadapter[V_ADP_PRIMARY] = adapter_init_value[DCC_MONO]; 999 biosadapter[V_ADP_SECONDARY] = adapter_init_value[DCC_CGA80]; 1000 break; 1001 } 1002 } 1003 #else 1004 /* assume EGA/VGA? XXX */ 1005 biosadapter[V_ADP_PRIMARY] = adapter_init_value[DCC_EGA80]; 1006 biosadapter[V_ADP_SECONDARY] = adapter_init_value[DCC_MONO]; 1007 #endif /* VGA_NO_BIOS */ 1008 1009 biosadapters = 0; 1010 if (verify_adapter(&biosadapter[V_ADP_SECONDARY]) == 0) { 1011 ++biosadapters; 1012 biosadapter[V_ADP_SECONDARY].va_flags |= V_ADP_PROBED; 1013 biosadapter[V_ADP_SECONDARY].va_mode = 1014 biosadapter[V_ADP_SECONDARY].va_initial_mode = 1015 map_bios_mode_num(biosadapter[V_ADP_SECONDARY].va_type, 1016 biosadapter[V_ADP_SECONDARY].va_flags 1017 & V_ADP_COLOR, 1018 biosadapter[V_ADP_SECONDARY].va_initial_bios_mode); 1019 } else { 1020 biosadapter[V_ADP_SECONDARY].va_type = -1; 1021 } 1022 if (verify_adapter(&biosadapter[V_ADP_PRIMARY]) == 0) { 1023 ++biosadapters; 1024 biosadapter[V_ADP_PRIMARY].va_flags |= V_ADP_PROBED; 1025 #ifndef VGA_NO_BIOS 1026 biosadapter[V_ADP_PRIMARY].va_initial_bios_mode = 1027 readb(BIOS_PADDRTOVADDR(0x449)); 1028 #else 1029 biosadapter[V_ADP_PRIMARY].va_initial_bios_mode = 3; /* XXX */ 1030 #endif 1031 biosadapter[V_ADP_PRIMARY].va_mode = 1032 biosadapter[V_ADP_PRIMARY].va_initial_mode = 1033 map_bios_mode_num(biosadapter[V_ADP_PRIMARY].va_type, 1034 biosadapter[V_ADP_PRIMARY].va_flags & V_ADP_COLOR, 1035 biosadapter[V_ADP_PRIMARY].va_initial_bios_mode); 1036 } else { 1037 biosadapter[V_ADP_PRIMARY] = biosadapter[V_ADP_SECONDARY]; 1038 biosadapter[V_ADP_SECONDARY].va_type = -1; 1039 } 1040 if (biosadapters == 0) 1041 return biosadapters; 1042 biosadapter[V_ADP_PRIMARY].va_unit = V_ADP_PRIMARY; 1043 biosadapter[V_ADP_SECONDARY].va_unit = V_ADP_SECONDARY; 1044 1045 #if 0 /* we don't need these... */ 1046 fb_init_struct(&biosadapter[V_ADP_PRIMARY], ...); 1047 fb_init_struct(&biosadapter[V_ADP_SECONDARY], ...); 1048 #endif 1049 1050 #if notyet 1051 /* 1052 * We cannot have two video adapter of the same type; there must be 1053 * only one of color or mono adapter, or one each of them. 1054 */ 1055 if (biosadapters > 1) { 1056 if (!((biosadapter[0].va_flags ^ biosadapter[1].va_flags) 1057 & V_ADP_COLOR)) 1058 /* we have two mono or color adapters!! */ 1059 return (biosadapters = 0); 1060 } 1061 #endif 1062 1063 /* 1064 * Ensure a zero start address. The registers are w/o 1065 * for old hardware so it's too hard to relocate the active screen 1066 * memory. 1067 * This must be done before vga_save_state() for VGA. 1068 */ 1069 outb(biosadapter[V_ADP_PRIMARY].va_crtc_addr, 12); 1070 outb(biosadapter[V_ADP_PRIMARY].va_crtc_addr + 1, 0); 1071 outb(biosadapter[V_ADP_PRIMARY].va_crtc_addr, 13); 1072 outb(biosadapter[V_ADP_PRIMARY].va_crtc_addr + 1, 0); 1073 1074 /* the video mode parameter table in EGA/VGA BIOS */ 1075 /* NOTE: there can be only one EGA/VGA, wheather color or mono, 1076 * recognized by the video BIOS. 1077 */ 1078 if ((biosadapter[V_ADP_PRIMARY].va_type == KD_EGA) || 1079 (biosadapter[V_ADP_PRIMARY].va_type == KD_VGA)) { 1080 adp = &biosadapter[V_ADP_PRIMARY]; 1081 } else if ((biosadapter[V_ADP_SECONDARY].va_type == KD_EGA) || 1082 (biosadapter[V_ADP_SECONDARY].va_type == KD_VGA)) { 1083 adp = &biosadapter[V_ADP_SECONDARY]; 1084 } else { 1085 adp = NULL; 1086 } 1087 bzero(mode_map, sizeof(mode_map)); 1088 if (adp != NULL) { 1089 if (adp->va_type == KD_VGA) { 1090 vga_save_state(adp, &adpstate, sizeof(adpstate)); 1091 #if defined(VGA_NO_BIOS) || defined(VGA_NO_MODE_CHANGE) 1092 mode_map[adp->va_initial_mode] = adpstate.regs; 1093 rows_offset = 1; 1094 #else /* VGA_NO_BIOS || VGA_NO_MODE_CHANGE */ 1095 if (video_mode_ptr == NULL) { 1096 mode_map[adp->va_initial_mode] = adpstate.regs; 1097 rows_offset = 1; 1098 } else { 1099 /* discard the table if we are not familiar with it... */ 1100 map_mode_table(mode_map, video_mode_ptr, M_VGA_CG320 + 1); 1101 mp = get_mode_param(adp->va_initial_mode); 1102 if (mp != NULL) 1103 bcopy(mp, adpstate2.regs, sizeof(adpstate2.regs)); 1104 switch (comp_adpregs(adpstate.regs, mp)) { 1105 case COMP_IDENTICAL: 1106 /* 1107 * OK, this parameter table looks reasonably familiar 1108 * to us... 1109 */ 1110 /* 1111 * This is a kludge for Toshiba DynaBook SS433 1112 * whose BIOS video mode table entry has the actual # 1113 * of rows at the offset 1; BIOSes from other 1114 * manufacturers store the # of rows - 1 there. XXX 1115 */ 1116 rows_offset = adpstate.regs[1] + 1 - mp[1]; 1117 break; 1118 1119 case COMP_SIMILAR: 1120 /* 1121 * Not exactly the same, but similar enough to be 1122 * trusted. However, use the saved register values 1123 * for the initial mode and other modes which are 1124 * based on the initial mode. 1125 */ 1126 mode_map[adp->va_initial_mode] = adpstate.regs; 1127 rows_offset = adpstate.regs[1] + 1 - mp[1]; 1128 adpstate.regs[1] -= rows_offset - 1; 1129 break; 1130 1131 case COMP_DIFFERENT: 1132 default: 1133 /* 1134 * Don't use the paramter table in BIOS. It doesn't 1135 * look familiar to us. Video mode switching is allowed 1136 * only if the new mode is the same as or based on 1137 * the initial mode. 1138 */ 1139 video_mode_ptr = NULL; 1140 bzero(mode_map, sizeof(mode_map)); 1141 mode_map[adp->va_initial_mode] = adpstate.regs; 1142 rows_offset = 1; 1143 break; 1144 } 1145 } 1146 #endif /* VGA_NO_BIOS || VGA_NO_MODE_CHANGE */ 1147 1148 #ifndef VGA_NO_MODE_CHANGE 1149 adp->va_flags |= V_ADP_MODECHANGE; 1150 #endif 1151 #ifndef VGA_NO_FONT_LOADING 1152 adp->va_flags |= V_ADP_FONT; 1153 #endif 1154 } else if (adp->va_type == KD_EGA) { 1155 #if defined(VGA_NO_BIOS) || defined(VGA_NO_MODE_CHANGE) 1156 rows_offset = 1; 1157 #else /* VGA_NO_BIOS || VGA_NO_MODE_CHANGE */ 1158 if (video_mode_ptr == NULL) { 1159 rows_offset = 1; 1160 } else { 1161 map_mode_table(mode_map, video_mode_ptr, M_ENH_C80x25 + 1); 1162 /* XXX how can one validate the EGA table... */ 1163 mp = get_mode_param(adp->va_initial_mode); 1164 if (mp != NULL) { 1165 adp->va_flags |= V_ADP_MODECHANGE; 1166 #ifndef VGA_NO_FONT_LOADING 1167 adp->va_flags |= V_ADP_FONT; 1168 #endif 1169 rows_offset = 1; 1170 } else { 1171 /* 1172 * This is serious. We will not be able to switch video 1173 * modes at all... 1174 */ 1175 video_mode_ptr = NULL; 1176 bzero(mode_map, sizeof(mode_map)); 1177 rows_offset = 1; 1178 } 1179 } 1180 #endif /* VGA_NO_BIOS || VGA_NO_MODE_CHANGE */ 1181 } 1182 } 1183 1184 /* remove conflicting modes if we have more than one adapter */ 1185 if (biosadapters > 0) { 1186 for (i = 0; i < biosadapters; ++i) { 1187 if (!(biosadapter[i].va_flags & V_ADP_MODECHANGE)) 1188 continue; 1189 clear_mode_map(&biosadapter[i], mode_map, M_VGA_CG320 + 1, 1190 (biosadapter[i].va_flags & V_ADP_COLOR) ? 1191 V_INFO_COLOR : 0); 1192 if ((biosadapter[i].va_type == KD_VGA) 1193 || (biosadapter[i].va_type == KD_EGA)) { 1194 biosadapter[i].va_io_base = 1195 (biosadapter[i].va_flags & V_ADP_COLOR) ? 1196 IO_VGA : IO_MDA; 1197 biosadapter[i].va_io_size = 32; 1198 } 1199 } 1200 } 1201 1202 /* buffer address */ 1203 vga_get_info(&biosadapter[V_ADP_PRIMARY], 1204 biosadapter[V_ADP_PRIMARY].va_initial_mode, &info); 1205 info.vi_flags &= ~V_INFO_LINEAR; /* XXX */ 1206 update_adapter_info(&biosadapter[V_ADP_PRIMARY], &info); 1207 1208 if (biosadapters > 1) { 1209 vga_get_info(&biosadapter[V_ADP_SECONDARY], 1210 biosadapter[V_ADP_SECONDARY].va_initial_mode, &info); 1211 info.vi_flags &= ~V_INFO_LINEAR; /* XXX */ 1212 update_adapter_info(&biosadapter[V_ADP_SECONDARY], &info); 1213 } 1214 1215 /* 1216 * XXX: we should verify the following values for the primary adapter... 1217 * crtc I/O port address: *(u_int16_t *)BIOS_PADDRTOVADDR(0x463); 1218 * color/mono display: (*(u_int8_t *)BIOS_PADDRTOVADDR(0x487) & 0x02) 1219 * ? 0 : V_ADP_COLOR; 1220 * columns: *(u_int8_t *)BIOS_PADDRTOVADDR(0x44a); 1221 * rows: *(u_int8_t *)BIOS_PADDRTOVADDR(0x484); 1222 * font size: *(u_int8_t *)BIOS_PADDRTOVADDR(0x485); 1223 * buffer size: *(u_int16_t *)BIOS_PADDRTOVADDR(0x44c); 1224 */ 1225 1226 return biosadapters; 1227 } 1228 1229 /* set the scan line length in pixel */ 1230 static int 1231 set_line_length(video_adapter_t *adp, int pixel) 1232 { 1233 u_char *mp; 1234 int ppw; /* pixels per word */ 1235 int bpl; /* bytes per line */ 1236 int count; 1237 1238 if ((adp->va_type != KD_VGA) && (adp->va_type != KD_EGA)) 1239 return ENODEV; 1240 mp = get_mode_param(adp->va_mode); 1241 if (mp == NULL) 1242 return EINVAL; 1243 1244 switch (adp->va_info.vi_mem_model) { 1245 case V_INFO_MM_PLANAR: 1246 ppw = 16/(adp->va_info.vi_depth/adp->va_info.vi_planes); 1247 count = (pixel + ppw - 1)/ppw/2; 1248 bpl = ((pixel + ppw - 1)/ppw/2)*4; 1249 break; 1250 case V_INFO_MM_PACKED: 1251 count = (pixel + 7)/8; 1252 bpl = ((pixel + 7)/8)*8; 1253 break; 1254 case V_INFO_MM_TEXT: 1255 count = (pixel + 7)/8; /* columns */ 1256 bpl = (pixel + 7)/8; /* columns */ 1257 break; 1258 default: 1259 return ENODEV; 1260 } 1261 1262 if (mp[10 + 0x17] & 0x40) /* CRTC mode control reg */ 1263 count *= 2; /* byte mode */ 1264 outb(adp->va_crtc_addr, 0x13); 1265 outb(adp->va_crtc_addr + 1, count); 1266 adp->va_line_width = bpl; 1267 1268 return 0; 1269 } 1270 1271 static int 1272 set_display_start(video_adapter_t *adp, int x, int y) 1273 { 1274 int off; /* byte offset (graphics mode)/word offset (text mode) */ 1275 int poff; /* pixel offset */ 1276 int roff; /* row offset */ 1277 int ppb; /* pixels per byte */ 1278 1279 if ((adp->va_type != KD_VGA) && (adp->va_type != KD_EGA)) 1280 x &= ~7; 1281 if (adp->va_info.vi_flags & V_INFO_GRAPHICS) { 1282 ppb = 8/(adp->va_info.vi_depth/adp->va_info.vi_planes); 1283 off = y*adp->va_line_width + x/ppb; 1284 roff = 0; 1285 poff = x%ppb; 1286 } else { 1287 if ((adp->va_type == KD_VGA) || (adp->va_type == KD_EGA)) { 1288 outb(TSIDX, 1); 1289 if (inb(TSREG) & 1) 1290 ppb = 9; 1291 else 1292 ppb = 8; 1293 } else { 1294 ppb = 8; 1295 } 1296 off = y/adp->va_info.vi_cheight*adp->va_line_width + x/ppb; 1297 roff = y%adp->va_info.vi_cheight; 1298 /* FIXME: is this correct? XXX */ 1299 if (ppb == 8) 1300 poff = x%ppb; 1301 else 1302 poff = (x + 8)%ppb; 1303 } 1304 1305 /* start address */ 1306 outb(adp->va_crtc_addr, 0xc); /* high */ 1307 outb(adp->va_crtc_addr + 1, off >> 8); 1308 outb(adp->va_crtc_addr, 0xd); /* low */ 1309 outb(adp->va_crtc_addr + 1, off & 0xff); 1310 1311 /* horizontal pel pan */ 1312 if ((adp->va_type == KD_VGA) || (adp->va_type == KD_EGA)) { 1313 inb(adp->va_crtc_addr + 6); 1314 outb(ATC, 0x13 | 0x20); 1315 outb(ATC, poff); 1316 inb(adp->va_crtc_addr + 6); 1317 outb(ATC, 0x20); 1318 } 1319 1320 /* preset raw scan */ 1321 outb(adp->va_crtc_addr, 8); 1322 outb(adp->va_crtc_addr + 1, roff); 1323 1324 adp->va_disp_start.x = x; 1325 adp->va_disp_start.y = y; 1326 return 0; 1327 } 1328 1329 #if defined(__i386__) || defined(__amd64__) /* XXX */ 1330 static void 1331 fill(int val, void *d, size_t size) 1332 { 1333 u_char *p = d; 1334 1335 while (size-- > 0) 1336 *p++ = val; 1337 } 1338 #endif /* __i386__ */ 1339 1340 static void 1341 filll_io(int val, vm_offset_t d, size_t size) 1342 { 1343 while (size-- > 0) { 1344 writel(d, val); 1345 d += sizeof(u_int32_t); 1346 } 1347 } 1348 1349 /* entry points */ 1350 1351 #if 0 1352 static int 1353 vga_nop(void) 1354 { 1355 return 0; 1356 } 1357 #endif 1358 1359 static int 1360 vga_error(void) 1361 { 1362 return ENODEV; 1363 } 1364 1365 static int 1366 vga_probe(int unit, video_adapter_t **adpp, void *arg, int flags) 1367 { 1368 probe_adapters(); 1369 if (unit >= biosadapters) 1370 return ENXIO; 1371 1372 *adpp = &biosadapter[unit]; 1373 1374 return 0; 1375 } 1376 1377 static int 1378 vga_init(int unit, video_adapter_t *adp, int flags) 1379 { 1380 if ((unit >= biosadapters) || (adp == NULL) || !probe_done(adp)) 1381 return ENXIO; 1382 1383 if (!init_done(adp)) { 1384 /* nothing to do really... */ 1385 adp->va_flags |= V_ADP_INITIALIZED; 1386 } 1387 1388 if (!config_done(adp)) { 1389 if (vid_register(adp) < 0) 1390 return ENXIO; 1391 adp->va_flags |= V_ADP_REGISTERED; 1392 } 1393 if (vga_sub_configure != NULL) 1394 (*vga_sub_configure)(0); 1395 1396 return 0; 1397 } 1398 1399 /* 1400 * get_info(): 1401 * Return the video_info structure of the requested video mode. 1402 * 1403 * all adapters 1404 */ 1405 static int 1406 vga_get_info(video_adapter_t *adp, int mode, video_info_t *info) 1407 { 1408 int i; 1409 1410 if (!vga_init_done) 1411 return ENXIO; 1412 1413 mode = map_gen_mode_num(adp->va_type, adp->va_flags & V_ADP_COLOR, mode); 1414 #ifndef VGA_NO_MODE_CHANGE 1415 if (adp->va_flags & V_ADP_MODECHANGE) { 1416 /* 1417 * If the parameter table entry for this mode is not found, 1418 * the mode is not supported... 1419 */ 1420 if (get_mode_param(mode) == NULL) 1421 return EINVAL; 1422 } else 1423 #endif /* VGA_NO_MODE_CHANGE */ 1424 { 1425 /* 1426 * Even if we don't support video mode switching on this adapter, 1427 * the information on the initial (thus current) video mode 1428 * should be made available. 1429 */ 1430 if (mode != adp->va_initial_mode) 1431 return EINVAL; 1432 } 1433 1434 for (i = 0; bios_vmode[i].vi_mode != EOT; ++i) { 1435 if (bios_vmode[i].vi_mode == NA) 1436 continue; 1437 if (mode == bios_vmode[i].vi_mode) { 1438 *info = bios_vmode[i]; 1439 /* XXX */ 1440 info->vi_buffer_size = info->vi_window_size*info->vi_planes; 1441 return 0; 1442 } 1443 } 1444 return EINVAL; 1445 } 1446 1447 /* 1448 * query_mode(): 1449 * Find a video mode matching the requested parameters. 1450 * Fields filled with 0 are considered "don't care" fields and 1451 * match any modes. 1452 * 1453 * all adapters 1454 */ 1455 static int 1456 vga_query_mode(video_adapter_t *adp, video_info_t *info) 1457 { 1458 int i; 1459 1460 if (!vga_init_done) 1461 return ENXIO; 1462 1463 for (i = 0; bios_vmode[i].vi_mode != EOT; ++i) { 1464 if (bios_vmode[i].vi_mode == NA) 1465 continue; 1466 1467 if ((info->vi_width != 0) 1468 && (info->vi_width != bios_vmode[i].vi_width)) 1469 continue; 1470 if ((info->vi_height != 0) 1471 && (info->vi_height != bios_vmode[i].vi_height)) 1472 continue; 1473 if ((info->vi_cwidth != 0) 1474 && (info->vi_cwidth != bios_vmode[i].vi_cwidth)) 1475 continue; 1476 if ((info->vi_cheight != 0) 1477 && (info->vi_cheight != bios_vmode[i].vi_cheight)) 1478 continue; 1479 if ((info->vi_depth != 0) 1480 && (info->vi_depth != bios_vmode[i].vi_depth)) 1481 continue; 1482 if ((info->vi_planes != 0) 1483 && (info->vi_planes != bios_vmode[i].vi_planes)) 1484 continue; 1485 /* XXX: should check pixel format, memory model */ 1486 if ((info->vi_flags != 0) 1487 && (info->vi_flags != bios_vmode[i].vi_flags)) 1488 continue; 1489 1490 /* verify if this mode is supported on this adapter */ 1491 if (vga_get_info(adp, bios_vmode[i].vi_mode, info)) 1492 continue; 1493 return 0; 1494 } 1495 return ENODEV; 1496 } 1497 1498 /* 1499 * set_mode(): 1500 * Change the video mode. 1501 * 1502 * EGA/VGA 1503 */ 1504 1505 #ifndef VGA_NO_MODE_CHANGE 1506 #ifdef VGA_WIDTH90 1507 static void 1508 set_width90(adp_state_t *params) 1509 { 1510 /* 1511 * Based on code submitted by Kelly Yancey (kbyanc@freedomnet.com) 1512 * and alexv@sui.gda.itesm.mx. 1513 */ 1514 params->regs[5] |= 1; /* toggle 8 pixel wide fonts */ 1515 params->regs[10+0x0] = 0x6b; 1516 params->regs[10+0x1] = 0x59; 1517 params->regs[10+0x2] = 0x5a; 1518 params->regs[10+0x3] = 0x8e; 1519 params->regs[10+0x4] = 0x5e; 1520 params->regs[10+0x5] = 0x8a; 1521 params->regs[10+0x13] = 45; 1522 params->regs[35+0x13] = 0; 1523 } 1524 #endif /* VGA_WIDTH90 */ 1525 #endif /* !VGA_NO_MODE_CHANGE */ 1526 1527 static int 1528 vga_set_mode(video_adapter_t *adp, int mode) 1529 { 1530 #ifndef VGA_NO_MODE_CHANGE 1531 video_info_t info; 1532 adp_state_t params; 1533 1534 prologue(adp, V_ADP_MODECHANGE, ENODEV); 1535 1536 mode = map_gen_mode_num(adp->va_type, 1537 adp->va_flags & V_ADP_COLOR, mode); 1538 if (vga_get_info(adp, mode, &info)) 1539 return EINVAL; 1540 1541 #if VGA_DEBUG > 1 1542 printf("vga_set_mode(): setting mode %d\n", mode); 1543 #endif 1544 1545 params.sig = V_STATE_SIG; 1546 bcopy(get_mode_param(mode), params.regs, sizeof(params.regs)); 1547 1548 switch (mode) { 1549 #ifdef VGA_WIDTH90 1550 case M_VGA_C90x60: case M_VGA_M90x60: 1551 set_width90(¶ms); 1552 /* FALLTHROUGH */ 1553 #endif 1554 case M_VGA_C80x60: case M_VGA_M80x60: 1555 params.regs[2] = 0x08; 1556 params.regs[19] = 0x47; 1557 goto special_480l; 1558 1559 #ifdef VGA_WIDTH90 1560 case M_VGA_C90x30: case M_VGA_M90x30: 1561 set_width90(¶ms); 1562 /* FALLTHROUGH */ 1563 #endif 1564 case M_VGA_C80x30: case M_VGA_M80x30: 1565 params.regs[19] = 0x4f; 1566 special_480l: 1567 params.regs[9] |= 0xc0; 1568 params.regs[16] = 0x08; 1569 params.regs[17] = 0x3e; 1570 params.regs[26] = 0xea; 1571 params.regs[28] = 0xdf; 1572 params.regs[31] = 0xe7; 1573 params.regs[32] = 0x04; 1574 goto setup_mode; 1575 1576 #ifdef VGA_WIDTH90 1577 case M_VGA_C90x43: case M_VGA_M90x43: 1578 set_width90(¶ms); 1579 /* FALLTHROUGH */ 1580 #endif 1581 case M_ENH_C80x43: case M_ENH_B80x43: 1582 params.regs[28] = 87; 1583 goto special_80x50; 1584 1585 #ifdef VGA_WIDTH90 1586 case M_VGA_C90x50: case M_VGA_M90x50: 1587 set_width90(¶ms); 1588 /* FALLTHROUGH */ 1589 #endif 1590 case M_VGA_C80x50: case M_VGA_M80x50: 1591 special_80x50: 1592 params.regs[2] = 8; 1593 params.regs[19] = 7; 1594 goto setup_mode; 1595 1596 #ifdef VGA_WIDTH90 1597 case M_VGA_C90x25: case M_VGA_M90x25: 1598 set_width90(¶ms); 1599 /* FALLTHROUGH */ 1600 #endif 1601 case M_VGA_C40x25: case M_VGA_C80x25: 1602 case M_VGA_M80x25: 1603 case M_B40x25: case M_C40x25: 1604 case M_B80x25: case M_C80x25: 1605 case M_ENH_B40x25: case M_ENH_C40x25: 1606 case M_ENH_B80x25: case M_ENH_C80x25: 1607 case M_EGAMONO80x25: 1608 1609 setup_mode: 1610 vga_load_state(adp, ¶ms); 1611 break; 1612 1613 case M_VGA_MODEX: 1614 /* "unchain" the VGA mode */ 1615 params.regs[5-1+0x04] &= 0xf7; 1616 params.regs[5-1+0x04] |= 0x04; 1617 /* turn off doubleword mode */ 1618 params.regs[10+0x14] &= 0xbf; 1619 /* turn off word addressing */ 1620 params.regs[10+0x17] |= 0x40; 1621 /* set logical screen width */ 1622 params.regs[10+0x13] = 80; 1623 /* set 240 lines */ 1624 params.regs[10+0x11] = 0x2c; 1625 params.regs[10+0x06] = 0x0d; 1626 params.regs[10+0x07] = 0x3e; 1627 params.regs[10+0x10] = 0xea; 1628 params.regs[10+0x11] = 0xac; 1629 params.regs[10+0x12] = 0xdf; 1630 params.regs[10+0x15] = 0xe7; 1631 params.regs[10+0x16] = 0x06; 1632 /* set vertical sync polarity to reflect aspect ratio */ 1633 params.regs[9] = 0xe3; 1634 goto setup_grmode; 1635 1636 case M_BG320: case M_CG320: case M_BG640: 1637 case M_CG320_D: case M_CG640_E: 1638 case M_CG640x350: case M_ENH_CG640: 1639 case M_BG640x480: case M_CG640x480: case M_VGA_CG320: 1640 1641 setup_grmode: 1642 vga_load_state(adp, ¶ms); 1643 break; 1644 1645 default: 1646 return EINVAL; 1647 } 1648 1649 adp->va_mode = mode; 1650 info.vi_flags &= ~V_INFO_LINEAR; /* XXX */ 1651 update_adapter_info(adp, &info); 1652 1653 /* move hardware cursor out of the way */ 1654 (*vidsw[adp->va_index]->set_hw_cursor)(adp, -1, -1); 1655 1656 return 0; 1657 #else /* VGA_NO_MODE_CHANGE */ 1658 return ENODEV; 1659 #endif /* VGA_NO_MODE_CHANGE */ 1660 } 1661 1662 #ifndef VGA_NO_FONT_LOADING 1663 1664 static void 1665 set_font_mode(video_adapter_t *adp, u_char *buf) 1666 { 1667 u_char *mp; 1668 int s; 1669 1670 s = splhigh(); 1671 1672 /* save register values */ 1673 if (adp->va_type == KD_VGA) { 1674 outb(TSIDX, 0x02); buf[0] = inb(TSREG); 1675 outb(TSIDX, 0x04); buf[1] = inb(TSREG); 1676 outb(GDCIDX, 0x04); buf[2] = inb(GDCREG); 1677 outb(GDCIDX, 0x05); buf[3] = inb(GDCREG); 1678 outb(GDCIDX, 0x06); buf[4] = inb(GDCREG); 1679 inb(adp->va_crtc_addr + 6); 1680 outb(ATC, 0x10); buf[5] = inb(ATC + 1); 1681 } else /* if (adp->va_type == KD_EGA) */ { 1682 /* 1683 * EGA cannot be read; copy parameters from the mode parameter 1684 * table. 1685 */ 1686 mp = get_mode_param(adp->va_mode); 1687 buf[0] = mp[5 + 0x02 - 1]; 1688 buf[1] = mp[5 + 0x04 - 1]; 1689 buf[2] = mp[55 + 0x04]; 1690 buf[3] = mp[55 + 0x05]; 1691 buf[4] = mp[55 + 0x06]; 1692 buf[5] = mp[35 + 0x10]; 1693 } 1694 1695 /* setup vga for loading fonts */ 1696 inb(adp->va_crtc_addr + 6); /* reset flip-flop */ 1697 outb(ATC, 0x10); outb(ATC, buf[5] & ~0x01); 1698 inb(adp->va_crtc_addr + 6); /* reset flip-flop */ 1699 outb(ATC, 0x20); /* enable palette */ 1700 1701 #if VGA_SLOW_IOACCESS 1702 #ifdef VGA_ALT_SEQACCESS 1703 outb(TSIDX, 0x00); outb(TSREG, 0x01); 1704 #endif 1705 outb(TSIDX, 0x02); outb(TSREG, 0x04); 1706 outb(TSIDX, 0x04); outb(TSREG, 0x07); 1707 #ifdef VGA_ALT_SEQACCESS 1708 outb(TSIDX, 0x00); outb(TSREG, 0x03); 1709 #endif 1710 outb(GDCIDX, 0x04); outb(GDCREG, 0x02); 1711 outb(GDCIDX, 0x05); outb(GDCREG, 0x00); 1712 outb(GDCIDX, 0x06); outb(GDCREG, 0x04); 1713 #else /* VGA_SLOW_IOACCESS */ 1714 #ifdef VGA_ALT_SEQACCESS 1715 outw(TSIDX, 0x0100); 1716 #endif 1717 outw(TSIDX, 0x0402); 1718 outw(TSIDX, 0x0704); 1719 #ifdef VGA_ALT_SEQACCESS 1720 outw(TSIDX, 0x0300); 1721 #endif 1722 outw(GDCIDX, 0x0204); 1723 outw(GDCIDX, 0x0005); 1724 outw(GDCIDX, 0x0406); /* addr = a0000, 64kb */ 1725 #endif /* VGA_SLOW_IOACCESS */ 1726 1727 splx(s); 1728 } 1729 1730 static void 1731 set_normal_mode(video_adapter_t *adp, u_char *buf) 1732 { 1733 int s; 1734 1735 s = splhigh(); 1736 1737 /* setup vga for normal operation mode again */ 1738 inb(adp->va_crtc_addr + 6); /* reset flip-flop */ 1739 outb(ATC, 0x10); outb(ATC, buf[5]); 1740 inb(adp->va_crtc_addr + 6); /* reset flip-flop */ 1741 outb(ATC, 0x20); /* enable palette */ 1742 1743 #if VGA_SLOW_IOACCESS 1744 #ifdef VGA_ALT_SEQACCESS 1745 outb(TSIDX, 0x00); outb(TSREG, 0x01); 1746 #endif 1747 outb(TSIDX, 0x02); outb(TSREG, buf[0]); 1748 outb(TSIDX, 0x04); outb(TSREG, buf[1]); 1749 #ifdef VGA_ALT_SEQACCESS 1750 outb(TSIDX, 0x00); outb(TSREG, 0x03); 1751 #endif 1752 outb(GDCIDX, 0x04); outb(GDCREG, buf[2]); 1753 outb(GDCIDX, 0x05); outb(GDCREG, buf[3]); 1754 if (adp->va_crtc_addr == MONO_CRTC) { 1755 outb(GDCIDX, 0x06); outb(GDCREG,(buf[4] & 0x03) | 0x08); 1756 } else { 1757 outb(GDCIDX, 0x06); outb(GDCREG,(buf[4] & 0x03) | 0x0c); 1758 } 1759 #else /* VGA_SLOW_IOACCESS */ 1760 #ifdef VGA_ALT_SEQACCESS 1761 outw(TSIDX, 0x0100); 1762 #endif 1763 outw(TSIDX, 0x0002 | (buf[0] << 8)); 1764 outw(TSIDX, 0x0004 | (buf[1] << 8)); 1765 #ifdef VGA_ALT_SEQACCESS 1766 outw(TSIDX, 0x0300); 1767 #endif 1768 outw(GDCIDX, 0x0004 | (buf[2] << 8)); 1769 outw(GDCIDX, 0x0005 | (buf[3] << 8)); 1770 if (adp->va_crtc_addr == MONO_CRTC) 1771 outw(GDCIDX, 0x0006 | (((buf[4] & 0x03) | 0x08)<<8)); 1772 else 1773 outw(GDCIDX, 0x0006 | (((buf[4] & 0x03) | 0x0c)<<8)); 1774 #endif /* VGA_SLOW_IOACCESS */ 1775 1776 splx(s); 1777 } 1778 1779 #endif /* VGA_NO_FONT_LOADING */ 1780 1781 /* 1782 * save_font(): 1783 * Read the font data in the requested font page from the video adapter. 1784 * 1785 * EGA/VGA 1786 */ 1787 static int 1788 vga_save_font(video_adapter_t *adp, int page, int fontsize, u_char *data, 1789 int ch, int count) 1790 { 1791 #ifndef VGA_NO_FONT_LOADING 1792 u_char buf[PARAM_BUFSIZE]; 1793 vm_offset_t segment; 1794 int c; 1795 #ifdef VGA_ALT_SEQACCESS 1796 int s; 1797 u_char val = 0; 1798 #endif 1799 1800 prologue(adp, V_ADP_FONT, ENODEV); 1801 1802 if (fontsize < 14) { 1803 /* FONT_8 */ 1804 fontsize = 8; 1805 } else if (fontsize >= 32) { 1806 fontsize = 32; 1807 } else if (fontsize >= 16) { 1808 /* FONT_16 */ 1809 fontsize = 16; 1810 } else { 1811 /* FONT_14 */ 1812 fontsize = 14; 1813 } 1814 1815 if (page < 0 || page >= 8) 1816 return EINVAL; 1817 segment = FONT_BUF + 0x4000*page; 1818 if (page > 3) 1819 segment -= 0xe000; 1820 1821 #ifdef VGA_ALT_SEQACCESS 1822 if (adp->va_type == KD_VGA) { /* what about EGA? XXX */ 1823 s = splhigh(); 1824 outb(TSIDX, 0x00); outb(TSREG, 0x01); 1825 outb(TSIDX, 0x01); val = inb(TSREG); /* disable screen */ 1826 outb(TSIDX, 0x01); outb(TSREG, val | 0x20); 1827 outb(TSIDX, 0x00); outb(TSREG, 0x03); 1828 splx(s); 1829 } 1830 #endif 1831 1832 set_font_mode(adp, buf); 1833 if (fontsize == 32) { 1834 bcopy_fromio((uintptr_t)segment + ch*32, data, fontsize*count); 1835 } else { 1836 for (c = ch; count > 0; ++c, --count) { 1837 bcopy_fromio((uintptr_t)segment + c*32, data, fontsize); 1838 data += fontsize; 1839 } 1840 } 1841 set_normal_mode(adp, buf); 1842 1843 #ifdef VGA_ALT_SEQACCESS 1844 if (adp->va_type == KD_VGA) { 1845 s = splhigh(); 1846 outb(TSIDX, 0x00); outb(TSREG, 0x01); 1847 outb(TSIDX, 0x01); outb(TSREG, val & 0xdf); /* enable screen */ 1848 outb(TSIDX, 0x00); outb(TSREG, 0x03); 1849 splx(s); 1850 } 1851 #endif 1852 1853 return 0; 1854 #else /* VGA_NO_FONT_LOADING */ 1855 return ENODEV; 1856 #endif /* VGA_NO_FONT_LOADING */ 1857 } 1858 1859 /* 1860 * load_font(): 1861 * Set the font data in the requested font page. 1862 * NOTE: it appears that some recent video adapters do not support 1863 * the font page other than 0... XXX 1864 * 1865 * EGA/VGA 1866 */ 1867 static int 1868 vga_load_font(video_adapter_t *adp, int page, int fontsize, u_char *data, 1869 int ch, int count) 1870 { 1871 #ifndef VGA_NO_FONT_LOADING 1872 u_char buf[PARAM_BUFSIZE]; 1873 vm_offset_t segment; 1874 int c; 1875 #ifdef VGA_ALT_SEQACCESS 1876 int s; 1877 u_char val = 0; 1878 #endif 1879 1880 prologue(adp, V_ADP_FONT, ENODEV); 1881 1882 if (fontsize < 14) { 1883 /* FONT_8 */ 1884 fontsize = 8; 1885 } else if (fontsize >= 32) { 1886 fontsize = 32; 1887 } else if (fontsize >= 16) { 1888 /* FONT_16 */ 1889 fontsize = 16; 1890 } else { 1891 /* FONT_14 */ 1892 fontsize = 14; 1893 } 1894 1895 if (page < 0 || page >= 8) 1896 return EINVAL; 1897 segment = FONT_BUF + 0x4000*page; 1898 if (page > 3) 1899 segment -= 0xe000; 1900 1901 #ifdef VGA_ALT_SEQACCESS 1902 if (adp->va_type == KD_VGA) { /* what about EGA? XXX */ 1903 s = splhigh(); 1904 outb(TSIDX, 0x00); outb(TSREG, 0x01); 1905 outb(TSIDX, 0x01); val = inb(TSREG); /* disable screen */ 1906 outb(TSIDX, 0x01); outb(TSREG, val | 0x20); 1907 outb(TSIDX, 0x00); outb(TSREG, 0x03); 1908 splx(s); 1909 } 1910 #endif 1911 1912 set_font_mode(adp, buf); 1913 if (fontsize == 32) { 1914 bcopy_toio(data, (uintptr_t)segment + ch*32, fontsize*count); 1915 } else { 1916 for (c = ch; count > 0; ++c, --count) { 1917 bcopy_toio(data, (uintptr_t)segment + c*32, fontsize); 1918 data += fontsize; 1919 } 1920 } 1921 set_normal_mode(adp, buf); 1922 1923 #ifdef VGA_ALT_SEQACCESS 1924 if (adp->va_type == KD_VGA) { 1925 s = splhigh(); 1926 outb(TSIDX, 0x00); outb(TSREG, 0x01); 1927 outb(TSIDX, 0x01); outb(TSREG, val & 0xdf); /* enable screen */ 1928 outb(TSIDX, 0x00); outb(TSREG, 0x03); 1929 splx(s); 1930 } 1931 #endif 1932 1933 return 0; 1934 #else /* VGA_NO_FONT_LOADING */ 1935 return ENODEV; 1936 #endif /* VGA_NO_FONT_LOADING */ 1937 } 1938 1939 /* 1940 * show_font(): 1941 * Activate the requested font page. 1942 * NOTE: it appears that some recent video adapters do not support 1943 * the font page other than 0... XXX 1944 * 1945 * EGA/VGA 1946 */ 1947 static int 1948 vga_show_font(video_adapter_t *adp, int page) 1949 { 1950 #ifndef VGA_NO_FONT_LOADING 1951 static u_char cg[] = { 0x00, 0x05, 0x0a, 0x0f, 0x30, 0x35, 0x3a, 0x3f }; 1952 int s; 1953 1954 prologue(adp, V_ADP_FONT, ENODEV); 1955 if (page < 0 || page >= 8) 1956 return EINVAL; 1957 1958 s = splhigh(); 1959 outb(TSIDX, 0x03); outb(TSREG, cg[page]); 1960 splx(s); 1961 1962 return 0; 1963 #else /* VGA_NO_FONT_LOADING */ 1964 return ENODEV; 1965 #endif /* VGA_NO_FONT_LOADING */ 1966 } 1967 1968 /* 1969 * save_palette(): 1970 * Read DAC values. The values have expressed in 8 bits. 1971 * 1972 * VGA 1973 */ 1974 static int 1975 vga_save_palette(video_adapter_t *adp, u_char *palette) 1976 { 1977 int i; 1978 1979 prologue(adp, V_ADP_PALETTE, ENODEV); 1980 1981 /* 1982 * We store 8 bit values in the palette buffer, while the standard 1983 * VGA has 6 bit DAC . 1984 */ 1985 outb(PALRADR, 0x00); 1986 for (i = 0; i < 256*3; ++i) 1987 palette[i] = inb(PALDATA) << 2; 1988 inb(adp->va_crtc_addr + 6); /* reset flip/flop */ 1989 return 0; 1990 } 1991 1992 static int 1993 vga_save_palette2(video_adapter_t *adp, int base, int count, 1994 u_char *r, u_char *g, u_char *b) 1995 { 1996 int i; 1997 1998 prologue(adp, V_ADP_PALETTE, ENODEV); 1999 2000 outb(PALRADR, base); 2001 for (i = 0; i < count; ++i) { 2002 r[i] = inb(PALDATA) << 2; 2003 g[i] = inb(PALDATA) << 2; 2004 b[i] = inb(PALDATA) << 2; 2005 } 2006 inb(adp->va_crtc_addr + 6); /* reset flip/flop */ 2007 return 0; 2008 } 2009 2010 /* 2011 * load_palette(): 2012 * Set DAC values. 2013 * 2014 * VGA 2015 */ 2016 static int 2017 vga_load_palette(video_adapter_t *adp, u_char *palette) 2018 { 2019 int i; 2020 2021 prologue(adp, V_ADP_PALETTE, ENODEV); 2022 2023 outb(PIXMASK, 0xff); /* no pixelmask */ 2024 outb(PALWADR, 0x00); 2025 for (i = 0; i < 256*3; ++i) 2026 outb(PALDATA, palette[i] >> 2); 2027 inb(adp->va_crtc_addr + 6); /* reset flip/flop */ 2028 outb(ATC, 0x20); /* enable palette */ 2029 return 0; 2030 } 2031 2032 static int 2033 vga_load_palette2(video_adapter_t *adp, int base, int count, 2034 u_char *r, u_char *g, u_char *b) 2035 { 2036 int i; 2037 2038 prologue(adp, V_ADP_PALETTE, ENODEV); 2039 2040 outb(PIXMASK, 0xff); /* no pixelmask */ 2041 outb(PALWADR, base); 2042 for (i = 0; i < count; ++i) { 2043 outb(PALDATA, r[i] >> 2); 2044 outb(PALDATA, g[i] >> 2); 2045 outb(PALDATA, b[i] >> 2); 2046 } 2047 inb(adp->va_crtc_addr + 6); /* reset flip/flop */ 2048 outb(ATC, 0x20); /* enable palette */ 2049 return 0; 2050 } 2051 2052 /* 2053 * set_border(): 2054 * Change the border color. 2055 * 2056 * CGA/EGA/VGA 2057 */ 2058 static int 2059 vga_set_border(video_adapter_t *adp, int color) 2060 { 2061 prologue(adp, V_ADP_BORDER, ENODEV); 2062 2063 switch (adp->va_type) { 2064 case KD_EGA: 2065 case KD_VGA: 2066 inb(adp->va_crtc_addr + 6); /* reset flip-flop */ 2067 outb(ATC, 0x31); outb(ATC, color & 0xff); 2068 break; 2069 case KD_CGA: 2070 outb(adp->va_crtc_addr + 5, color & 0x0f); /* color select register */ 2071 break; 2072 case KD_MONO: 2073 case KD_HERCULES: 2074 default: 2075 break; 2076 } 2077 return 0; 2078 } 2079 2080 /* 2081 * save_state(): 2082 * Read video register values. 2083 * NOTE: this function only reads the standard EGA/VGA registers. 2084 * any extra/extended registers of SVGA adapters are not saved. 2085 * 2086 * VGA 2087 */ 2088 static int 2089 vga_save_state(video_adapter_t *adp, void *p, size_t size) 2090 { 2091 video_info_t info; 2092 u_char *buf; 2093 int crtc_addr; 2094 int i, j; 2095 int s; 2096 2097 if (size == 0) { 2098 /* return the required buffer size */ 2099 prologue(adp, V_ADP_STATESAVE, 0); 2100 return sizeof(adp_state_t); 2101 } else { 2102 prologue(adp, V_ADP_STATESAVE, ENODEV); 2103 if (size < sizeof(adp_state_t)) 2104 return EINVAL; 2105 } 2106 2107 ((adp_state_t *)p)->sig = V_STATE_SIG; 2108 buf = ((adp_state_t *)p)->regs; 2109 bzero(buf, V_MODE_PARAM_SIZE); 2110 crtc_addr = adp->va_crtc_addr; 2111 2112 s = splhigh(); 2113 2114 outb(TSIDX, 0x00); outb(TSREG, 0x01); /* stop sequencer */ 2115 for (i = 0, j = 5; i < 4; i++) { 2116 outb(TSIDX, i + 1); 2117 buf[j++] = inb(TSREG); 2118 } 2119 buf[9] = inb(MISC + 10); /* dot-clock */ 2120 outb(TSIDX, 0x00); outb(TSREG, 0x03); /* start sequencer */ 2121 2122 for (i = 0, j = 10; i < 25; i++) { /* crtc */ 2123 outb(crtc_addr, i); 2124 buf[j++] = inb(crtc_addr + 1); 2125 } 2126 for (i = 0, j = 35; i < 20; i++) { /* attribute ctrl */ 2127 inb(crtc_addr + 6); /* reset flip-flop */ 2128 outb(ATC, i); 2129 buf[j++] = inb(ATC + 1); 2130 } 2131 for (i = 0, j = 55; i < 9; i++) { /* graph data ctrl */ 2132 outb(GDCIDX, i); 2133 buf[j++] = inb(GDCREG); 2134 } 2135 inb(crtc_addr + 6); /* reset flip-flop */ 2136 outb(ATC, 0x20); /* enable palette */ 2137 2138 splx(s); 2139 2140 #if 1 2141 if (vga_get_info(adp, adp->va_mode, &info) == 0) { 2142 if (info.vi_flags & V_INFO_GRAPHICS) { 2143 buf[0] = info.vi_width/info.vi_cwidth; /* COLS */ 2144 buf[1] = info.vi_height/info.vi_cheight - 1; /* ROWS */ 2145 } else { 2146 buf[0] = info.vi_width; /* COLS */ 2147 buf[1] = info.vi_height - 1; /* ROWS */ 2148 } 2149 buf[2] = info.vi_cheight; /* POINTS */ 2150 } else { 2151 /* XXX: shouldn't be happening... */ 2152 printf("vga%d: %s: failed to obtain mode info. (vga_save_state())\n", 2153 adp->va_unit, adp->va_name); 2154 } 2155 #else 2156 buf[0] = readb(BIOS_PADDRTOVADDR(0x44a)); /* COLS */ 2157 buf[1] = readb(BIOS_PADDRTOVADDR(0x484)); /* ROWS */ 2158 buf[2] = readb(BIOS_PADDRTOVADDR(0x485)); /* POINTS */ 2159 buf[3] = readb(BIOS_PADDRTOVADDR(0x44c)); 2160 buf[4] = readb(BIOS_PADDRTOVADDR(0x44d)); 2161 #endif 2162 2163 return 0; 2164 } 2165 2166 /* 2167 * load_state(): 2168 * Set video registers at once. 2169 * NOTE: this function only updates the standard EGA/VGA registers. 2170 * any extra/extended registers of SVGA adapters are not changed. 2171 * 2172 * EGA/VGA 2173 */ 2174 static int 2175 vga_load_state(video_adapter_t *adp, void *p) 2176 { 2177 u_char *buf; 2178 int crtc_addr; 2179 int s; 2180 int i; 2181 2182 prologue(adp, V_ADP_STATELOAD, ENODEV); 2183 if (((adp_state_t *)p)->sig != V_STATE_SIG) 2184 return EINVAL; 2185 2186 buf = ((adp_state_t *)p)->regs; 2187 crtc_addr = adp->va_crtc_addr; 2188 2189 #if VGA_DEBUG > 1 2190 dump_buffer(buf, V_MODE_PARAM_SIZE); 2191 #endif 2192 2193 s = splhigh(); 2194 2195 outb(TSIDX, 0x00); outb(TSREG, 0x01); /* stop sequencer */ 2196 for (i = 0; i < 4; ++i) { /* program sequencer */ 2197 outb(TSIDX, i + 1); 2198 outb(TSREG, buf[i + 5]); 2199 } 2200 outb(MISC, buf[9]); /* set dot-clock */ 2201 outb(TSIDX, 0x00); outb(TSREG, 0x03); /* start sequencer */ 2202 outb(crtc_addr, 0x11); 2203 outb(crtc_addr + 1, inb(crtc_addr + 1) & 0x7F); 2204 for (i = 0; i < 25; ++i) { /* program crtc */ 2205 outb(crtc_addr, i); 2206 outb(crtc_addr + 1, buf[i + 10]); 2207 } 2208 inb(crtc_addr+6); /* reset flip-flop */ 2209 for (i = 0; i < 20; ++i) { /* program attribute ctrl */ 2210 outb(ATC, i); 2211 outb(ATC, buf[i + 35]); 2212 } 2213 for (i = 0; i < 9; ++i) { /* program graph data ctrl */ 2214 outb(GDCIDX, i); 2215 outb(GDCREG, buf[i + 55]); 2216 } 2217 inb(crtc_addr + 6); /* reset flip-flop */ 2218 outb(ATC, 0x20); /* enable palette */ 2219 2220 #if notyet /* a temporary workaround for kernel panic, XXX */ 2221 #ifndef VGA_NO_BIOS 2222 if (adp->va_unit == V_ADP_PRIMARY) { 2223 writeb(BIOS_PADDRTOVADDR(0x44a), buf[0]); /* COLS */ 2224 writeb(BIOS_PADDRTOVADDR(0x484), buf[1] + rows_offset - 1); /* ROWS */ 2225 writeb(BIOS_PADDRTOVADDR(0x485), buf[2]); /* POINTS */ 2226 #if 0 2227 writeb(BIOS_PADDRTOVADDR(0x44c), buf[3]); 2228 writeb(BIOS_PADDRTOVADDR(0x44d), buf[4]); 2229 #endif 2230 } 2231 #endif /* VGA_NO_BIOS */ 2232 #endif /* notyet */ 2233 2234 splx(s); 2235 return 0; 2236 } 2237 2238 /* 2239 * set_origin(): 2240 * Change the origin (window mapping) of the banked frame buffer. 2241 */ 2242 static int 2243 vga_set_origin(video_adapter_t *adp, off_t offset) 2244 { 2245 /* 2246 * The standard video modes do not require window mapping; 2247 * always return error. 2248 */ 2249 return ENODEV; 2250 } 2251 2252 /* 2253 * read_hw_cursor(): 2254 * Read the position of the hardware text cursor. 2255 * 2256 * all adapters 2257 */ 2258 static int 2259 vga_read_hw_cursor(video_adapter_t *adp, int *col, int *row) 2260 { 2261 u_int16_t off; 2262 int s; 2263 2264 if (!vga_init_done) 2265 return ENXIO; 2266 2267 if (adp->va_info.vi_flags & V_INFO_GRAPHICS) 2268 return ENODEV; 2269 2270 s = spltty(); 2271 outb(adp->va_crtc_addr, 14); 2272 off = inb(adp->va_crtc_addr + 1); 2273 outb(adp->va_crtc_addr, 15); 2274 off = (off << 8) | inb(adp->va_crtc_addr + 1); 2275 splx(s); 2276 2277 *row = off / adp->va_info.vi_width; 2278 *col = off % adp->va_info.vi_width; 2279 2280 return 0; 2281 } 2282 2283 /* 2284 * set_hw_cursor(): 2285 * Move the hardware text cursor. If col and row are both -1, 2286 * the cursor won't be shown. 2287 * 2288 * all adapters 2289 */ 2290 static int 2291 vga_set_hw_cursor(video_adapter_t *adp, int col, int row) 2292 { 2293 u_int16_t off; 2294 int s; 2295 2296 if (!vga_init_done) 2297 return ENXIO; 2298 2299 if ((col == -1) && (row == -1)) { 2300 off = -1; 2301 } else { 2302 if (adp->va_info.vi_flags & V_INFO_GRAPHICS) 2303 return ENODEV; 2304 off = row*adp->va_info.vi_width + col; 2305 } 2306 2307 s = spltty(); 2308 outb(adp->va_crtc_addr, 14); 2309 outb(adp->va_crtc_addr + 1, off >> 8); 2310 outb(adp->va_crtc_addr, 15); 2311 outb(adp->va_crtc_addr + 1, off & 0x00ff); 2312 splx(s); 2313 2314 return 0; 2315 } 2316 2317 /* 2318 * set_hw_cursor_shape(): 2319 * Change the shape of the hardware text cursor. If the height is 2320 * zero or negative, the cursor won't be shown. 2321 * 2322 * all adapters 2323 */ 2324 static int 2325 vga_set_hw_cursor_shape(video_adapter_t *adp, int base, int height, 2326 int celsize, int blink) 2327 { 2328 int s; 2329 2330 if (!vga_init_done) 2331 return ENXIO; 2332 2333 s = spltty(); 2334 switch (adp->va_type) { 2335 case KD_VGA: 2336 case KD_CGA: 2337 case KD_MONO: 2338 case KD_HERCULES: 2339 default: 2340 if (height <= 0) { 2341 /* make the cursor invisible */ 2342 outb(adp->va_crtc_addr, 10); 2343 outb(adp->va_crtc_addr + 1, 32); 2344 outb(adp->va_crtc_addr, 11); 2345 outb(adp->va_crtc_addr + 1, 0); 2346 } else { 2347 outb(adp->va_crtc_addr, 10); 2348 outb(adp->va_crtc_addr + 1, celsize - base - height); 2349 outb(adp->va_crtc_addr, 11); 2350 outb(adp->va_crtc_addr + 1, celsize - base - 1); 2351 } 2352 break; 2353 case KD_EGA: 2354 if (height <= 0) { 2355 /* make the cursor invisible */ 2356 outb(adp->va_crtc_addr, 10); 2357 outb(adp->va_crtc_addr + 1, celsize); 2358 outb(adp->va_crtc_addr, 11); 2359 outb(adp->va_crtc_addr + 1, 0); 2360 } else { 2361 outb(adp->va_crtc_addr, 10); 2362 outb(adp->va_crtc_addr + 1, celsize - base - height); 2363 outb(adp->va_crtc_addr, 11); 2364 outb(adp->va_crtc_addr + 1, celsize - base); 2365 } 2366 break; 2367 } 2368 splx(s); 2369 2370 return 0; 2371 } 2372 2373 /* 2374 * blank_display() 2375 * Put the display in power save/power off mode. 2376 * 2377 * all adapters 2378 */ 2379 static int 2380 vga_blank_display(video_adapter_t *adp, int mode) 2381 { 2382 u_char val; 2383 int s; 2384 2385 s = splhigh(); 2386 switch (adp->va_type) { 2387 case KD_VGA: 2388 switch (mode) { 2389 case V_DISPLAY_SUSPEND: 2390 case V_DISPLAY_STAND_BY: 2391 outb(TSIDX, 0x01); 2392 val = inb(TSREG); 2393 outb(TSIDX, 0x01); 2394 outb(TSREG, val | 0x20); 2395 outb(adp->va_crtc_addr, 0x17); 2396 val = inb(adp->va_crtc_addr + 1); 2397 outb(adp->va_crtc_addr + 1, val & ~0x80); 2398 break; 2399 case V_DISPLAY_BLANK: 2400 outb(TSIDX, 0x01); 2401 val = inb(TSREG); 2402 outb(TSIDX, 0x01); 2403 outb(TSREG, val | 0x20); 2404 break; 2405 case V_DISPLAY_ON: 2406 outb(TSIDX, 0x01); 2407 val = inb(TSREG); 2408 outb(TSIDX, 0x01); 2409 outb(TSREG, val & 0xDF); 2410 outb(adp->va_crtc_addr, 0x17); 2411 val = inb(adp->va_crtc_addr + 1); 2412 outb(adp->va_crtc_addr + 1, val | 0x80); 2413 break; 2414 } 2415 break; 2416 2417 case KD_EGA: 2418 /* no support yet */ 2419 splx(s); 2420 return ENODEV; 2421 2422 case KD_CGA: 2423 switch (mode) { 2424 case V_DISPLAY_SUSPEND: 2425 case V_DISPLAY_STAND_BY: 2426 case V_DISPLAY_BLANK: 2427 outb(adp->va_crtc_addr + 4, 0x25); 2428 break; 2429 case V_DISPLAY_ON: 2430 outb(adp->va_crtc_addr + 4, 0x2d); 2431 break; 2432 } 2433 break; 2434 2435 case KD_MONO: 2436 case KD_HERCULES: 2437 switch (mode) { 2438 case V_DISPLAY_SUSPEND: 2439 case V_DISPLAY_STAND_BY: 2440 case V_DISPLAY_BLANK: 2441 outb(adp->va_crtc_addr + 4, 0x21); 2442 break; 2443 case V_DISPLAY_ON: 2444 outb(adp->va_crtc_addr + 4, 0x29); 2445 break; 2446 } 2447 break; 2448 default: 2449 break; 2450 } 2451 splx(s); 2452 2453 return 0; 2454 } 2455 2456 /* 2457 * mmap(): 2458 * Mmap frame buffer. 2459 * 2460 * all adapters 2461 */ 2462 static int 2463 vga_mmap_buf(video_adapter_t *adp, vm_offset_t offset, vm_paddr_t *paddr, 2464 int prot) 2465 { 2466 if (adp->va_info.vi_flags & V_INFO_LINEAR) 2467 return -1; 2468 2469 #if VGA_DEBUG > 0 2470 printf("vga_mmap_buf(): window:0x%jx, offset:0x%jx\n", 2471 (uintmax_t)adp->va_info.vi_window, (uintmax_t)offset); 2472 #endif 2473 2474 /* XXX: is this correct? */ 2475 if (offset > adp->va_window_size - PAGE_SIZE) 2476 return -1; 2477 2478 *paddr = adp->va_info.vi_window + offset; 2479 return 0; 2480 } 2481 2482 #ifndef VGA_NO_MODE_CHANGE 2483 2484 static void 2485 planar_fill(video_adapter_t *adp, int val) 2486 { 2487 int length; 2488 int at; /* position in the frame buffer */ 2489 int l; 2490 2491 outw(GDCIDX, 0x0005); /* read mode 0, write mode 0 */ 2492 outw(GDCIDX, 0x0003); /* data rotate/function select */ 2493 outw(GDCIDX, 0x0f01); /* set/reset enable */ 2494 outw(GDCIDX, 0xff08); /* bit mask */ 2495 outw(GDCIDX, (val << 8) | 0x00); /* set/reset */ 2496 at = 0; 2497 length = adp->va_line_width*adp->va_info.vi_height; 2498 while (length > 0) { 2499 l = imin(length, adp->va_window_size); 2500 (*vidsw[adp->va_index]->set_win_org)(adp, at); 2501 bzero_io(adp->va_window, l); 2502 length -= l; 2503 at += l; 2504 } 2505 outw(GDCIDX, 0x0000); /* set/reset */ 2506 outw(GDCIDX, 0x0001); /* set/reset enable */ 2507 } 2508 2509 static void 2510 packed_fill(video_adapter_t *adp, int val) 2511 { 2512 int length; 2513 int at; /* position in the frame buffer */ 2514 int l; 2515 2516 at = 0; 2517 length = adp->va_line_width*adp->va_info.vi_height; 2518 while (length > 0) { 2519 l = imin(length, adp->va_window_size); 2520 (*vidsw[adp->va_index]->set_win_org)(adp, at); 2521 fill_io(val, adp->va_window, l); 2522 length -= l; 2523 at += l; 2524 } 2525 } 2526 2527 static void 2528 direct_fill(video_adapter_t *adp, int val) 2529 { 2530 int length; 2531 int at; /* position in the frame buffer */ 2532 int l; 2533 2534 at = 0; 2535 length = adp->va_line_width*adp->va_info.vi_height; 2536 while (length > 0) { 2537 l = imin(length, adp->va_window_size); 2538 (*vidsw[adp->va_index]->set_win_org)(adp, at); 2539 switch (adp->va_info.vi_pixel_size) { 2540 case sizeof(u_int16_t): 2541 fillw_io(val, adp->va_window, l/sizeof(u_int16_t)); 2542 break; 2543 case 3: 2544 /* FIXME */ 2545 break; 2546 case sizeof(u_int32_t): 2547 filll_io(val, adp->va_window, l/sizeof(u_int32_t)); 2548 break; 2549 } 2550 length -= l; 2551 at += l; 2552 } 2553 } 2554 2555 static int 2556 vga_clear(video_adapter_t *adp) 2557 { 2558 switch (adp->va_info.vi_mem_model) { 2559 case V_INFO_MM_TEXT: 2560 /* do nothing? XXX */ 2561 break; 2562 case V_INFO_MM_PLANAR: 2563 planar_fill(adp, 0); 2564 break; 2565 case V_INFO_MM_PACKED: 2566 packed_fill(adp, 0); 2567 break; 2568 case V_INFO_MM_DIRECT: 2569 direct_fill(adp, 0); 2570 break; 2571 } 2572 return 0; 2573 } 2574 2575 #ifdef notyet 2576 static void 2577 planar_fill_rect(video_adapter_t *adp, int val, int x, int y, int cx, int cy) 2578 { 2579 int banksize; 2580 int bank; 2581 int pos; 2582 int offset; /* offset within window */ 2583 int bx; 2584 int l; 2585 2586 outw(GDCIDX, 0x0005); /* read mode 0, write mode 0 */ 2587 outw(GDCIDX, 0x0003); /* data rotate/function select */ 2588 outw(GDCIDX, 0x0f01); /* set/reset enable */ 2589 outw(GDCIDX, 0xff08); /* bit mask */ 2590 outw(GDCIDX, (val << 8) | 0x00); /* set/reset */ 2591 2592 banksize = adp->va_window_size; 2593 bank = -1; 2594 while (cy > 0) { 2595 pos = adp->va_line_width*y + x/8; 2596 if (bank != pos/banksize) { 2597 (*vidsw[adp->va_index]->set_win_org)(adp, pos); 2598 bank = pos/banksize; 2599 } 2600 offset = pos%banksize; 2601 bx = (x + cx)/8 - x/8; 2602 if (x % 8) { 2603 outw(GDCIDX, ((0xff00 >> (x % 8)) & 0xff00) | 0x08); 2604 writeb(adp->va_window + offset, 0); 2605 ++offset; 2606 --bx; 2607 if (offset >= banksize) { 2608 offset = 0; 2609 ++bank; /* next bank */ 2610 (*vidsw[adp->va_index]->set_win_org)(adp, bank*banksize); 2611 } 2612 outw(GDCIDX, 0xff08); /* bit mask */ 2613 } 2614 while (bx > 0) { 2615 l = imin(bx, banksize); 2616 bzero_io(adp->va_window + offset, l); 2617 offset += l; 2618 bx -= l; 2619 if (offset >= banksize) { 2620 offset = 0; 2621 ++bank; /* next bank */ 2622 (*vidsw[adp->va_index]->set_win_org)(adp, bank*banksize); 2623 } 2624 } 2625 if ((x + cx) % 8) { 2626 outw(GDCIDX, (~(0xff00 >> ((x + cx) % 8)) & 0xff00) | 0x08); 2627 writeb(adp->va_window + offset, 0); 2628 ++offset; 2629 if (offset >= banksize) { 2630 offset = 0; 2631 ++bank; /* next bank */ 2632 (*vidsw[adp->va_index]->set_win_org)(adp, bank*banksize); 2633 } 2634 outw(GDCIDX, 0xff08); /* bit mask */ 2635 } 2636 ++y; 2637 --cy; 2638 } 2639 2640 outw(GDCIDX, 0xff08); /* bit mask */ 2641 outw(GDCIDX, 0x0000); /* set/reset */ 2642 outw(GDCIDX, 0x0001); /* set/reset enable */ 2643 } 2644 2645 static void 2646 packed_fill_rect(video_adapter_t *adp, int val, int x, int y, int cx, int cy) 2647 { 2648 int banksize; 2649 int bank; 2650 int pos; 2651 int offset; /* offset within window */ 2652 int end; 2653 2654 banksize = adp->va_window_size; 2655 bank = -1; 2656 cx *= adp->va_info.vi_pixel_size; 2657 while (cy > 0) { 2658 pos = adp->va_line_width*y + x*adp->va_info.vi_pixel_size; 2659 if (bank != pos/banksize) { 2660 (*vidsw[adp->va_index]->set_win_org)(adp, pos); 2661 bank = pos/banksize; 2662 } 2663 offset = pos%banksize; 2664 end = imin(offset + cx, banksize); 2665 fill_io(val, adp->va_window + offset, 2666 (end - offset)/adp->va_info.vi_pixel_size); 2667 /* the line may cross the window boundary */ 2668 if (offset + cx > banksize) { 2669 ++bank; /* next bank */ 2670 (*vidsw[adp->va_index]->set_win_org)(adp, bank*banksize); 2671 end = offset + cx - banksize; 2672 fill_io(val, adp->va_window, end/adp->va_info.vi_pixel_size); 2673 } 2674 ++y; 2675 --cy; 2676 } 2677 } 2678 2679 static void 2680 direct_fill_rect16(video_adapter_t *adp, int val, int x, int y, int cx, int cy) 2681 { 2682 int banksize; 2683 int bank; 2684 int pos; 2685 int offset; /* offset within window */ 2686 int end; 2687 2688 /* 2689 * XXX: the function assumes that banksize is a muliple of 2690 * sizeof(u_int16_t). 2691 */ 2692 banksize = adp->va_window_size; 2693 bank = -1; 2694 cx *= sizeof(u_int16_t); 2695 while (cy > 0) { 2696 pos = adp->va_line_width*y + x*sizeof(u_int16_t); 2697 if (bank != pos/banksize) { 2698 (*vidsw[adp->va_index]->set_win_org)(adp, pos); 2699 bank = pos/banksize; 2700 } 2701 offset = pos%banksize; 2702 end = imin(offset + cx, banksize); 2703 fillw_io(val, adp->va_window + offset, 2704 (end - offset)/sizeof(u_int16_t)); 2705 /* the line may cross the window boundary */ 2706 if (offset + cx > banksize) { 2707 ++bank; /* next bank */ 2708 (*vidsw[adp->va_index]->set_win_org)(adp, bank*banksize); 2709 end = offset + cx - banksize; 2710 fillw_io(val, adp->va_window, end/sizeof(u_int16_t)); 2711 } 2712 ++y; 2713 --cy; 2714 } 2715 } 2716 2717 static void 2718 direct_fill_rect24(video_adapter_t *adp, int val, int x, int y, int cx, int cy) 2719 { 2720 int banksize; 2721 int bank; 2722 int pos; 2723 int offset; /* offset within window */ 2724 int end; 2725 int i; 2726 int j; 2727 u_int8_t b[3]; 2728 2729 b[0] = val & 0x0000ff; 2730 b[1] = (val >> 8) & 0x0000ff; 2731 b[2] = (val >> 16) & 0x0000ff; 2732 banksize = adp->va_window_size; 2733 bank = -1; 2734 cx *= 3; 2735 while (cy > 0) { 2736 pos = adp->va_line_width*y + x*3; 2737 if (bank != pos/banksize) { 2738 (*vidsw[adp->va_index]->set_win_org)(adp, pos); 2739 bank = pos/banksize; 2740 } 2741 offset = pos%banksize; 2742 end = imin(offset + cx, banksize); 2743 for (i = 0, j = offset; j < end; i = (++i)%3, ++j) { 2744 writeb(adp->va_window + j, b[i]); 2745 } 2746 /* the line may cross the window boundary */ 2747 if (offset + cx >= banksize) { 2748 ++bank; /* next bank */ 2749 (*vidsw[adp->va_index]->set_win_org)(adp, bank*banksize); 2750 j = 0; 2751 end = offset + cx - banksize; 2752 for (; j < end; i = (++i)%3, ++j) { 2753 writeb(adp->va_window + j, b[i]); 2754 } 2755 } 2756 ++y; 2757 --cy; 2758 } 2759 } 2760 2761 static void 2762 direct_fill_rect32(video_adapter_t *adp, int val, int x, int y, int cx, int cy) 2763 { 2764 int banksize; 2765 int bank; 2766 int pos; 2767 int offset; /* offset within window */ 2768 int end; 2769 2770 /* 2771 * XXX: the function assumes that banksize is a muliple of 2772 * sizeof(u_int32_t). 2773 */ 2774 banksize = adp->va_window_size; 2775 bank = -1; 2776 cx *= sizeof(u_int32_t); 2777 while (cy > 0) { 2778 pos = adp->va_line_width*y + x*sizeof(u_int32_t); 2779 if (bank != pos/banksize) { 2780 (*vidsw[adp->va_index]->set_win_org)(adp, pos); 2781 bank = pos/banksize; 2782 } 2783 offset = pos%banksize; 2784 end = imin(offset + cx, banksize); 2785 filll_io(val, adp->va_window + offset, 2786 (end - offset)/sizeof(u_int32_t)); 2787 /* the line may cross the window boundary */ 2788 if (offset + cx > banksize) { 2789 ++bank; /* next bank */ 2790 (*vidsw[adp->va_index]->set_win_org)(adp, bank*banksize); 2791 end = offset + cx - banksize; 2792 filll_io(val, adp->va_window, end/sizeof(u_int32_t)); 2793 } 2794 ++y; 2795 --cy; 2796 } 2797 } 2798 2799 static int 2800 vga_fill_rect(video_adapter_t *adp, int val, int x, int y, int cx, int cy) 2801 { 2802 switch (adp->va_info.vi_mem_model) { 2803 case V_INFO_MM_TEXT: 2804 /* do nothing? XXX */ 2805 break; 2806 case V_INFO_MM_PLANAR: 2807 planar_fill_rect(adp, val, x, y, cx, cy); 2808 break; 2809 case V_INFO_MM_PACKED: 2810 packed_fill_rect(adp, val, x, y, cx, cy); 2811 break; 2812 case V_INFO_MM_DIRECT: 2813 switch (adp->va_info.vi_pixel_size) { 2814 case sizeof(u_int16_t): 2815 direct_fill_rect16(adp, val, x, y, cx, cy); 2816 break; 2817 case 3: 2818 direct_fill_rect24(adp, val, x, y, cx, cy); 2819 break; 2820 case sizeof(u_int32_t): 2821 direct_fill_rect32(adp, val, x, y, cx, cy); 2822 break; 2823 } 2824 break; 2825 } 2826 return 0; 2827 } 2828 #else /* !notyet */ 2829 static int 2830 vga_fill_rect(video_adapter_t *adp, int val, int x, int y, int cx, int cy) 2831 { 2832 return ENODEV; 2833 } 2834 #endif /* notyet */ 2835 2836 static int 2837 vga_bitblt(video_adapter_t *adp,...) 2838 { 2839 /* FIXME */ 2840 return ENODEV; 2841 } 2842 2843 #endif /* !VGA_NO_MODE_CHANGE */ 2844 2845 static int 2846 get_palette(video_adapter_t *adp, int base, int count, 2847 u_char *red, u_char *green, u_char *blue, u_char *trans) 2848 { 2849 u_char *r; 2850 u_char *g; 2851 u_char *b; 2852 2853 if (count < 0 || base < 0 || count > 256 || base > 256 || 2854 base + count > 256) 2855 return EINVAL; 2856 2857 r = malloc(count*3, M_DEVBUF, M_WAITOK); 2858 g = r + count; 2859 b = g + count; 2860 if (vga_save_palette2(adp, base, count, r, g, b)) { 2861 free(r, M_DEVBUF); 2862 return ENODEV; 2863 } 2864 copyout(r, red, count); 2865 copyout(g, green, count); 2866 copyout(b, blue, count); 2867 if (trans != NULL) { 2868 bzero(r, count); 2869 copyout(r, trans, count); 2870 } 2871 free(r, M_DEVBUF); 2872 2873 return 0; 2874 } 2875 2876 static int 2877 set_palette(video_adapter_t *adp, int base, int count, 2878 u_char *red, u_char *green, u_char *blue, u_char *trans) 2879 { 2880 u_char *r; 2881 u_char *g; 2882 u_char *b; 2883 int err; 2884 2885 if (count < 0 || base < 0 || count > 256 || base > 256 || 2886 base + count > 256) 2887 return EINVAL; 2888 2889 r = malloc(count*3, M_DEVBUF, M_WAITOK); 2890 g = r + count; 2891 b = g + count; 2892 copyin(red, r, count); 2893 copyin(green, g, count); 2894 copyin(blue, b, count); 2895 err = vga_load_palette2(adp, base, count, r, g, b); 2896 free(r, M_DEVBUF); 2897 2898 return (err ? ENODEV : 0); 2899 } 2900 2901 static int 2902 vga_dev_ioctl(video_adapter_t *adp, u_long cmd, caddr_t arg) 2903 { 2904 switch (cmd) { 2905 case FBIO_GETWINORG: /* get frame buffer window origin */ 2906 *(u_int *)arg = 0; 2907 return 0; 2908 2909 case FBIO_SETWINORG: /* set frame buffer window origin */ 2910 return ENODEV; 2911 2912 case FBIO_SETDISPSTART: /* set display start address */ 2913 return (set_display_start(adp, 2914 ((video_display_start_t *)arg)->x, 2915 ((video_display_start_t *)arg)->y) 2916 ? ENODEV : 0); 2917 2918 case FBIO_SETLINEWIDTH: /* set scan line length in pixel */ 2919 return (set_line_length(adp, *(u_int *)arg) ? ENODEV : 0); 2920 2921 case FBIO_GETPALETTE: /* get color palette */ 2922 return get_palette(adp, ((video_color_palette_t *)arg)->index, 2923 ((video_color_palette_t *)arg)->count, 2924 ((video_color_palette_t *)arg)->red, 2925 ((video_color_palette_t *)arg)->green, 2926 ((video_color_palette_t *)arg)->blue, 2927 ((video_color_palette_t *)arg)->transparent); 2928 2929 case FBIO_SETPALETTE: /* set color palette */ 2930 return set_palette(adp, ((video_color_palette_t *)arg)->index, 2931 ((video_color_palette_t *)arg)->count, 2932 ((video_color_palette_t *)arg)->red, 2933 ((video_color_palette_t *)arg)->green, 2934 ((video_color_palette_t *)arg)->blue, 2935 ((video_color_palette_t *)arg)->transparent); 2936 2937 case FBIOGTYPE: /* get frame buffer type info. */ 2938 ((struct fbtype *)arg)->fb_type = fb_type(adp->va_type); 2939 ((struct fbtype *)arg)->fb_height = adp->va_info.vi_height; 2940 ((struct fbtype *)arg)->fb_width = adp->va_info.vi_width; 2941 ((struct fbtype *)arg)->fb_depth = adp->va_info.vi_depth; 2942 if ((adp->va_info.vi_depth <= 1) || (adp->va_info.vi_depth > 8)) 2943 ((struct fbtype *)arg)->fb_cmsize = 0; 2944 else 2945 ((struct fbtype *)arg)->fb_cmsize = 1 << adp->va_info.vi_depth; 2946 ((struct fbtype *)arg)->fb_size = adp->va_buffer_size; 2947 return 0; 2948 2949 case FBIOGETCMAP: /* get color palette */ 2950 return get_palette(adp, ((struct fbcmap *)arg)->index, 2951 ((struct fbcmap *)arg)->count, 2952 ((struct fbcmap *)arg)->red, 2953 ((struct fbcmap *)arg)->green, 2954 ((struct fbcmap *)arg)->blue, NULL); 2955 2956 case FBIOPUTCMAP: /* set color palette */ 2957 return set_palette(adp, ((struct fbcmap *)arg)->index, 2958 ((struct fbcmap *)arg)->count, 2959 ((struct fbcmap *)arg)->red, 2960 ((struct fbcmap *)arg)->green, 2961 ((struct fbcmap *)arg)->blue, NULL); 2962 2963 default: 2964 return fb_commonioctl(adp, cmd, arg); 2965 } 2966 } 2967 2968 static void 2969 dump_buffer(u_char *buf, size_t len) 2970 { 2971 int i; 2972 2973 for(i = 0; i < len;) { 2974 printf("%02x ", buf[i]); 2975 if ((++i % 16) == 0) 2976 printf("\n"); 2977 } 2978 } 2979 2980 /* 2981 * diag(): 2982 * Print some information about the video adapter and video modes, 2983 * with requested level of details. 2984 * 2985 * all adapters 2986 */ 2987 static int 2988 vga_diag(video_adapter_t *adp, int level) 2989 { 2990 u_char *mp; 2991 #if FB_DEBUG > 1 2992 video_info_t info; 2993 int i; 2994 #endif 2995 2996 if (!vga_init_done) 2997 return ENXIO; 2998 2999 #if FB_DEBUG > 1 3000 #ifndef VGA_NO_BIOS 3001 printf("vga: RTC equip. code:0x%02x, DCC code:0x%02x\n", 3002 rtcin(RTC_EQUIPMENT), readb(BIOS_PADDRTOVADDR(0x488))); 3003 printf("vga: CRTC:0x%x, video option:0x%02x, ", 3004 readw(BIOS_PADDRTOVADDR(0x463)), 3005 readb(BIOS_PADDRTOVADDR(0x487))); 3006 printf("rows:%d, cols:%d, font height:%d\n", 3007 readb(BIOS_PADDRTOVADDR(0x44a)), 3008 readb(BIOS_PADDRTOVADDR(0x484)) + 1, 3009 readb(BIOS_PADDRTOVADDR(0x485))); 3010 #endif /* VGA_NO_BIOS */ 3011 #if !defined(VGA_NO_BIOS) && !defined(VGA_NO_MODE_CHANGE) 3012 printf("vga: param table EGA/VGA:%p", video_mode_ptr); 3013 printf(", CGA/MDA:%p\n", video_mode_ptr2); 3014 printf("vga: rows_offset:%d\n", rows_offset); 3015 #endif 3016 #endif /* FB_DEBUG > 1 */ 3017 3018 fb_dump_adp_info(VGA_DRIVER_NAME, adp, level); 3019 3020 #if FB_DEBUG > 1 3021 if (adp->va_flags & V_ADP_MODECHANGE) { 3022 for (i = 0; bios_vmode[i].vi_mode != EOT; ++i) { 3023 if (bios_vmode[i].vi_mode == NA) 3024 continue; 3025 if (get_mode_param(bios_vmode[i].vi_mode) == NULL) 3026 continue; 3027 fb_dump_mode_info(VGA_DRIVER_NAME, adp, &bios_vmode[i], level); 3028 } 3029 } else { 3030 vga_get_info(adp, adp->va_initial_mode, &info); /* shouldn't fail */ 3031 fb_dump_mode_info(VGA_DRIVER_NAME, adp, &info, level); 3032 } 3033 #endif /* FB_DEBUG > 1 */ 3034 3035 if ((adp->va_type != KD_EGA) && (adp->va_type != KD_VGA)) 3036 return 0; 3037 #if !defined(VGA_NO_BIOS) && !defined(VGA_NO_MODE_CHANGE) 3038 if (video_mode_ptr == NULL) 3039 printf("vga%d: %s: WARNING: video mode switching is not " 3040 "fully supported on this adapter\n", 3041 adp->va_unit, adp->va_name); 3042 #endif 3043 if (level <= 0) 3044 return 0; 3045 3046 if (adp->va_type == KD_VGA) { 3047 printf("VGA parameters upon power-up\n"); 3048 dump_buffer(adpstate.regs, sizeof(adpstate.regs)); 3049 printf("VGA parameters in BIOS for mode %d\n", adp->va_initial_mode); 3050 dump_buffer(adpstate2.regs, sizeof(adpstate2.regs)); 3051 } 3052 3053 mp = get_mode_param(adp->va_initial_mode); 3054 if (mp == NULL) /* this shouldn't be happening */ 3055 return 0; 3056 printf("EGA/VGA parameters to be used for mode %d\n", adp->va_initial_mode); 3057 dump_buffer(mp, V_MODE_PARAM_SIZE); 3058 3059 return 0; 3060 } 3061