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