| 1 | /*- |
| 2 | * Copyright (c) 1998 Kazutaka YOKOTA and Michael Smith |
| 3 | * All rights reserved. |
| 4 | * |
| 5 | * Redistribution and use in source and binary forms, with or without |
| 6 | * modification, are permitted provided that the following conditions |
| 7 | * are met: |
| 8 | * 1. Redistributions of source code must retain the above copyright |
| 9 | * notice, this list of conditions and the following disclaimer as |
| 10 | * the first lines of this file unmodified. |
| 11 | * 2. Redistributions in binary form must reproduce the above copyright |
| 12 | * notice, this list of conditions and the following disclaimer in the |
| 13 | * documentation and/or other materials provided with the distribution. |
| 14 | * |
| 15 | * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR |
| 16 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
| 17 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
| 18 | * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT, |
| 19 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
| 20 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 21 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 22 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 23 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
| 24 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 25 | * |
| 26 | * $FreeBSD: src/sys/i386/isa/vesa.c,v 1.32.2.1 2002/08/13 02:42:33 rwatson Exp $ |
| 27 | * $DragonFly: src/sys/dev/video/i386/vesa/vesa.c,v 1.4 2003/09/08 18:36:04 dillon Exp $ |
| 28 | */ |
| 29 | |
| 30 | #include "opt_vga.h" |
| 31 | |
| 32 | #ifndef VGA_NO_MODE_CHANGE |
| 33 | |
| 34 | #include <sys/param.h> |
| 35 | #include <sys/systm.h> |
| 36 | #include <sys/kernel.h> |
| 37 | #include <sys/module.h> |
| 38 | #include <sys/malloc.h> |
| 39 | #include <sys/fbio.h> |
| 40 | |
| 41 | #include <vm/vm.h> |
| 42 | #include <vm/vm_extern.h> |
| 43 | #include <vm/vm_kern.h> |
| 44 | #include <vm/pmap.h> |
| 45 | |
| 46 | #include <machine/md_var.h> |
| 47 | #include <machine/vm86.h> |
| 48 | #include <machine/pc/bios.h> |
| 49 | #include <machine/pc/vesa.h> |
| 50 | |
| 51 | #include <dev/video/fb/fbreg.h> |
| 52 | #include <dev/video/fb/vgareg.h> |
| 53 | |
| 54 | #ifndef __i386__ |
| 55 | #include <bus/isa/isareg.h> |
| 56 | #else |
| 57 | #include <bus/isa/i386/isa.h> |
| 58 | #endif |
| 59 | |
| 60 | #ifndef VESA_DEBUG |
| 61 | #define VESA_DEBUG 0 |
| 62 | #endif |
| 63 | |
| 64 | /* VESA video adapter state buffer stub */ |
| 65 | struct adp_state { |
| 66 | int sig; |
| 67 | #define V_STATE_SIG 0x61736576 |
| 68 | u_char regs[1]; |
| 69 | }; |
| 70 | typedef struct adp_state adp_state_t; |
| 71 | |
| 72 | /* VESA video adapter */ |
| 73 | static video_adapter_t *vesa_adp = NULL; |
| 74 | static int vesa_state_buf_size = 0; |
| 75 | |
| 76 | /* VESA functions */ |
| 77 | #if 0 |
| 78 | static int vesa_nop(void); |
| 79 | #endif |
| 80 | static int vesa_error(void); |
| 81 | static vi_probe_t vesa_probe; |
| 82 | static vi_init_t vesa_init; |
| 83 | static vi_get_info_t vesa_get_info; |
| 84 | static vi_query_mode_t vesa_query_mode; |
| 85 | static vi_set_mode_t vesa_set_mode; |
| 86 | static vi_save_font_t vesa_save_font; |
| 87 | static vi_load_font_t vesa_load_font; |
| 88 | static vi_show_font_t vesa_show_font; |
| 89 | static vi_save_palette_t vesa_save_palette; |
| 90 | static vi_load_palette_t vesa_load_palette; |
| 91 | static vi_set_border_t vesa_set_border; |
| 92 | static vi_save_state_t vesa_save_state; |
| 93 | static vi_load_state_t vesa_load_state; |
| 94 | static vi_set_win_org_t vesa_set_origin; |
| 95 | static vi_read_hw_cursor_t vesa_read_hw_cursor; |
| 96 | static vi_set_hw_cursor_t vesa_set_hw_cursor; |
| 97 | static vi_set_hw_cursor_shape_t vesa_set_hw_cursor_shape; |
| 98 | static vi_blank_display_t vesa_blank_display; |
| 99 | static vi_mmap_t vesa_mmap; |
| 100 | static vi_ioctl_t vesa_ioctl; |
| 101 | static vi_clear_t vesa_clear; |
| 102 | static vi_fill_rect_t vesa_fill_rect; |
| 103 | static vi_bitblt_t vesa_bitblt; |
| 104 | static vi_diag_t vesa_diag; |
| 105 | static int vesa_bios_info(int level); |
| 106 | static struct vm86context vesa_vmcontext; |
| 107 | |
| 108 | static video_switch_t vesavidsw = { |
| 109 | vesa_probe, |
| 110 | vesa_init, |
| 111 | vesa_get_info, |
| 112 | vesa_query_mode, |
| 113 | vesa_set_mode, |
| 114 | vesa_save_font, |
| 115 | vesa_load_font, |
| 116 | vesa_show_font, |
| 117 | vesa_save_palette, |
| 118 | vesa_load_palette, |
| 119 | vesa_set_border, |
| 120 | vesa_save_state, |
| 121 | vesa_load_state, |
| 122 | vesa_set_origin, |
| 123 | vesa_read_hw_cursor, |
| 124 | vesa_set_hw_cursor, |
| 125 | vesa_set_hw_cursor_shape, |
| 126 | vesa_blank_display, |
| 127 | vesa_mmap, |
| 128 | vesa_ioctl, |
| 129 | vesa_clear, |
| 130 | vesa_fill_rect, |
| 131 | vesa_bitblt, |
| 132 | vesa_error, |
| 133 | vesa_error, |
| 134 | vesa_diag, |
| 135 | }; |
| 136 | |
| 137 | static video_switch_t *prevvidsw; |
| 138 | |
| 139 | /* VESA BIOS video modes */ |
| 140 | #define VESA_MAXMODES 64 |
| 141 | #define EOT (-1) |
| 142 | #define NA (-2) |
| 143 | |
| 144 | #define MODE_TABLE_DELTA 8 |
| 145 | |
| 146 | static int vesa_vmode_max = 0; |
| 147 | static video_info_t vesa_vmode_empty = { EOT }; |
| 148 | static video_info_t *vesa_vmode = &vesa_vmode_empty; |
| 149 | |
| 150 | static int vesa_init_done = FALSE; |
| 151 | static int has_vesa_bios = FALSE; |
| 152 | static struct vesa_info *vesa_adp_info = NULL; |
| 153 | static u_int16_t *vesa_vmodetab = NULL; |
| 154 | static char *vesa_oemstr = NULL; |
| 155 | static char *vesa_venderstr = NULL; |
| 156 | static char *vesa_prodstr = NULL; |
| 157 | static char *vesa_revstr = NULL; |
| 158 | |
| 159 | /* local macros and functions */ |
| 160 | #define BIOS_SADDRTOLADDR(p) ((((p) & 0xffff0000) >> 12) + ((p) & 0x0000ffff)) |
| 161 | |
| 162 | static int int10_set_mode(int mode); |
| 163 | static int vesa_bios_get_mode(int mode, struct vesa_mode *vmode); |
| 164 | static int vesa_bios_set_mode(int mode); |
| 165 | static int vesa_bios_get_dac(void); |
| 166 | static int vesa_bios_set_dac(int bits); |
| 167 | static int vesa_bios_save_palette(int start, int colors, u_char *palette, |
| 168 | int bits); |
| 169 | static int vesa_bios_save_palette2(int start, int colors, u_char *r, u_char *g, |
| 170 | u_char *b, int bits); |
| 171 | static int vesa_bios_load_palette(int start, int colors, u_char *palette, |
| 172 | int bits); |
| 173 | #ifdef notyet |
| 174 | static int vesa_bios_load_palette2(int start, int colors, u_char *r, u_char *g, |
| 175 | u_char *b, int bits); |
| 176 | #endif |
| 177 | #define STATE_SIZE 0 |
| 178 | #define STATE_SAVE 1 |
| 179 | #define STATE_LOAD 2 |
| 180 | #define STATE_HW (1<<0) |
| 181 | #define STATE_DATA (1<<1) |
| 182 | #define STATE_DAC (1<<2) |
| 183 | #define STATE_REG (1<<3) |
| 184 | #define STATE_MOST (STATE_HW | STATE_DATA | STATE_REG) |
| 185 | #define STATE_ALL (STATE_HW | STATE_DATA | STATE_DAC | STATE_REG) |
| 186 | static int vesa_bios_state_buf_size(void); |
| 187 | static int vesa_bios_save_restore(int code, void *p, size_t size); |
| 188 | static int vesa_bios_get_line_length(void); |
| 189 | static int vesa_bios_set_line_length(int pixel, int *bytes, int *lines); |
| 190 | #if 0 |
| 191 | static int vesa_bios_get_start(int *x, int *y); |
| 192 | #endif |
| 193 | static int vesa_bios_set_start(int x, int y); |
| 194 | static int vesa_map_gen_mode_num(int type, int color, int mode); |
| 195 | static int vesa_translate_flags(u_int16_t vflags); |
| 196 | static int vesa_translate_mmodel(u_int8_t vmodel); |
| 197 | static void *vesa_fix_ptr(u_int32_t p, u_int16_t seg, u_int16_t off, |
| 198 | u_char *buf); |
| 199 | static int vesa_bios_init(void); |
| 200 | static void vesa_clear_modes(video_info_t *info, int color); |
| 201 | static vm_offset_t vesa_map_buffer(u_int paddr, size_t size); |
| 202 | static void vesa_unmap_buffer(vm_offset_t vaddr, size_t size); |
| 203 | |
| 204 | #if 0 |
| 205 | static int vesa_get_origin(video_adapter_t *adp, off_t *offset); |
| 206 | #endif |
| 207 | |
| 208 | static void |
| 209 | dump_buffer(u_char *buf, size_t len) |
| 210 | { |
| 211 | int i; |
| 212 | |
| 213 | for(i = 0; i < len;) { |
| 214 | printf("%02x ", buf[i]); |
| 215 | if ((++i % 16) == 0) |
| 216 | printf("\n"); |
| 217 | } |
| 218 | } |
| 219 | |
| 220 | /* INT 10 BIOS calls */ |
| 221 | static int |
| 222 | int10_set_mode(int mode) |
| 223 | { |
| 224 | struct vm86frame vmf; |
| 225 | |
| 226 | bzero(&vmf, sizeof(vmf)); |
| 227 | vmf.vmf_eax = 0x0000 | mode; |
| 228 | vm86_intcall(0x10, &vmf); |
| 229 | return 0; |
| 230 | } |
| 231 | |
| 232 | /* VESA BIOS calls */ |
| 233 | static int |
| 234 | vesa_bios_get_mode(int mode, struct vesa_mode *vmode) |
| 235 | { |
| 236 | struct vm86frame vmf; |
| 237 | u_char *buf; |
| 238 | int err; |
| 239 | |
| 240 | bzero(&vmf, sizeof(vmf)); |
| 241 | vmf.vmf_eax = 0x4f01; |
| 242 | vmf.vmf_ecx = mode; |
| 243 | buf = (u_char *)vm86_getpage(&vesa_vmcontext, 1); |
| 244 | vm86_getptr(&vesa_vmcontext, (vm_offset_t)buf, &vmf.vmf_es, &vmf.vmf_di); |
| 245 | |
| 246 | err = vm86_datacall(0x10, &vmf, &vesa_vmcontext); |
| 247 | if ((err != 0) || (vmf.vmf_ax != 0x4f)) |
| 248 | return 1; |
| 249 | bcopy(buf, vmode, sizeof(*vmode)); |
| 250 | return 0; |
| 251 | } |
| 252 | |
| 253 | static int |
| 254 | vesa_bios_set_mode(int mode) |
| 255 | { |
| 256 | struct vm86frame vmf; |
| 257 | int err; |
| 258 | |
| 259 | bzero(&vmf, sizeof(vmf)); |
| 260 | vmf.vmf_eax = 0x4f02; |
| 261 | vmf.vmf_ebx = mode; |
| 262 | err = vm86_intcall(0x10, &vmf); |
| 263 | return ((err != 0) || (vmf.vmf_ax != 0x4f)); |
| 264 | } |
| 265 | |
| 266 | static int |
| 267 | vesa_bios_get_dac(void) |
| 268 | { |
| 269 | struct vm86frame vmf; |
| 270 | int err; |
| 271 | |
| 272 | bzero(&vmf, sizeof(vmf)); |
| 273 | vmf.vmf_eax = 0x4f08; |
| 274 | vmf.vmf_ebx = 1; /* get DAC width */ |
| 275 | err = vm86_intcall(0x10, &vmf); |
| 276 | if ((err != 0) || (vmf.vmf_ax != 0x4f)) |
| 277 | return 6; /* XXX */ |
| 278 | return ((vmf.vmf_ebx >> 8) & 0x00ff); |
| 279 | } |
| 280 | |
| 281 | static int |
| 282 | vesa_bios_set_dac(int bits) |
| 283 | { |
| 284 | struct vm86frame vmf; |
| 285 | int err; |
| 286 | |
| 287 | bzero(&vmf, sizeof(vmf)); |
| 288 | vmf.vmf_eax = 0x4f08; |
| 289 | vmf.vmf_ebx = (bits << 8); |
| 290 | err = vm86_intcall(0x10, &vmf); |
| 291 | if ((err != 0) || (vmf.vmf_ax != 0x4f)) |
| 292 | return 6; /* XXX */ |
| 293 | return ((vmf.vmf_ebx >> 8) & 0x00ff); |
| 294 | } |
| 295 | |
| 296 | static int |
| 297 | vesa_bios_save_palette(int start, int colors, u_char *palette, int bits) |
| 298 | { |
| 299 | struct vm86frame vmf; |
| 300 | u_char *p; |
| 301 | int err; |
| 302 | int i; |
| 303 | |
| 304 | bzero(&vmf, sizeof(vmf)); |
| 305 | vmf.vmf_eax = 0x4f09; |
| 306 | vmf.vmf_ebx = 1; /* get primary palette data */ |
| 307 | vmf.vmf_ecx = colors; |
| 308 | vmf.vmf_edx = start; |
| 309 | p = (u_char *)vm86_getpage(&vesa_vmcontext, 1); |
| 310 | vm86_getptr(&vesa_vmcontext, (vm_offset_t)p, &vmf.vmf_es, &vmf.vmf_di); |
| 311 | |
| 312 | err = vm86_datacall(0x10, &vmf, &vesa_vmcontext); |
| 313 | if ((err != 0) || (vmf.vmf_ax != 0x4f)) |
| 314 | return 1; |
| 315 | |
| 316 | bits = 8 - bits; |
| 317 | for (i = 0; i < colors; ++i) { |
| 318 | palette[i*3] = p[i*4 + 2] << bits; |
| 319 | palette[i*3 + 1] = p[i*4 + 1] << bits; |
| 320 | palette[i*3 + 2] = p[i*4] << bits; |
| 321 | } |
| 322 | return 0; |
| 323 | } |
| 324 | |
| 325 | static int |
| 326 | vesa_bios_save_palette2(int start, int colors, u_char *r, u_char *g, u_char *b, |
| 327 | int bits) |
| 328 | { |
| 329 | struct vm86frame vmf; |
| 330 | u_char *p; |
| 331 | int err; |
| 332 | int i; |
| 333 | |
| 334 | bzero(&vmf, sizeof(vmf)); |
| 335 | vmf.vmf_eax = 0x4f09; |
| 336 | vmf.vmf_ebx = 1; /* get primary palette data */ |
| 337 | vmf.vmf_ecx = colors; |
| 338 | vmf.vmf_edx = start; |
| 339 | p = (u_char *)vm86_getpage(&vesa_vmcontext, 1); |
| 340 | vm86_getptr(&vesa_vmcontext, (vm_offset_t)p, &vmf.vmf_es, &vmf.vmf_di); |
| 341 | |
| 342 | err = vm86_datacall(0x10, &vmf, &vesa_vmcontext); |
| 343 | if ((err != 0) || (vmf.vmf_ax != 0x4f)) |
| 344 | return 1; |
| 345 | |
| 346 | bits = 8 - bits; |
| 347 | for (i = 0; i < colors; ++i) { |
| 348 | r[i] = p[i*4 + 2] << bits; |
| 349 | g[i] = p[i*4 + 1] << bits; |
| 350 | b[i] = p[i*4] << bits; |
| 351 | } |
| 352 | return 0; |
| 353 | } |
| 354 | |
| 355 | static int |
| 356 | vesa_bios_load_palette(int start, int colors, u_char *palette, int bits) |
| 357 | { |
| 358 | struct vm86frame vmf; |
| 359 | u_char *p; |
| 360 | int err; |
| 361 | int i; |
| 362 | |
| 363 | p = (u_char *)vm86_getpage(&vesa_vmcontext, 1); |
| 364 | bits = 8 - bits; |
| 365 | for (i = 0; i < colors; ++i) { |
| 366 | p[i*4] = palette[i*3 + 2] >> bits; |
| 367 | p[i*4 + 1] = palette[i*3 + 1] >> bits; |
| 368 | p[i*4 + 2] = palette[i*3] >> bits; |
| 369 | p[i*4 + 3] = 0; |
| 370 | } |
| 371 | |
| 372 | bzero(&vmf, sizeof(vmf)); |
| 373 | vmf.vmf_eax = 0x4f09; |
| 374 | vmf.vmf_ebx = 0; /* set primary palette data */ |
| 375 | vmf.vmf_ecx = colors; |
| 376 | vmf.vmf_edx = start; |
| 377 | vm86_getptr(&vesa_vmcontext, (vm_offset_t)p, &vmf.vmf_es, &vmf.vmf_di); |
| 378 | |
| 379 | err = vm86_datacall(0x10, &vmf, &vesa_vmcontext); |
| 380 | return ((err != 0) || (vmf.vmf_ax != 0x4f)); |
| 381 | } |
| 382 | |
| 383 | #ifdef notyet |
| 384 | static int |
| 385 | vesa_bios_load_palette2(int start, int colors, u_char *r, u_char *g, u_char *b, |
| 386 | int bits) |
| 387 | { |
| 388 | struct vm86frame vmf; |
| 389 | u_char *p; |
| 390 | int err; |
| 391 | int i; |
| 392 | |
| 393 | p = (u_char *)vm86_getpage(&vesa_vmcontext, 1); |
| 394 | bits = 8 - bits; |
| 395 | for (i = 0; i < colors; ++i) { |
| 396 | p[i*4] = b[i] >> bits; |
| 397 | p[i*4 + 1] = g[i] >> bits; |
| 398 | p[i*4 + 2] = r[i] >> bits; |
| 399 | p[i*4 + 3] = 0; |
| 400 | } |
| 401 | |
| 402 | bzero(&vmf, sizeof(vmf)); |
| 403 | vmf.vmf_eax = 0x4f09; |
| 404 | vmf.vmf_ebx = 0; /* set primary palette data */ |
| 405 | vmf.vmf_ecx = colors; |
| 406 | vmf.vmf_edx = start; |
| 407 | vm86_getptr(&vesa_vmcontext, (vm_offset_t)p, &vmf.vmf_es, &vmf.vmf_di); |
| 408 | |
| 409 | err = vm86_datacall(0x10, &vmf, &vesa_vmcontext); |
| 410 | return ((err != 0) || (vmf.vmf_ax != 0x4f)); |
| 411 | } |
| 412 | #endif |
| 413 | |
| 414 | static int |
| 415 | vesa_bios_state_buf_size(void) |
| 416 | { |
| 417 | struct vm86frame vmf; |
| 418 | int err; |
| 419 | |
| 420 | bzero(&vmf, sizeof(vmf)); |
| 421 | vmf.vmf_eax = 0x4f04; |
| 422 | vmf.vmf_ecx = STATE_MOST; |
| 423 | vmf.vmf_edx = STATE_SIZE; |
| 424 | err = vm86_intcall(0x10, &vmf); |
| 425 | if ((err != 0) || (vmf.vmf_ax != 0x4f)) |
| 426 | return 0; |
| 427 | return vmf.vmf_bx*64; |
| 428 | } |
| 429 | |
| 430 | static int |
| 431 | vesa_bios_save_restore(int code, void *p, size_t size) |
| 432 | { |
| 433 | struct vm86frame vmf; |
| 434 | u_char *buf; |
| 435 | int err; |
| 436 | |
| 437 | bzero(&vmf, sizeof(vmf)); |
| 438 | vmf.vmf_eax = 0x4f04; |
| 439 | vmf.vmf_ecx = STATE_MOST; |
| 440 | vmf.vmf_edx = code; /* STATE_SAVE/STATE_LOAD */ |
| 441 | buf = (u_char *)vm86_getpage(&vesa_vmcontext, 1); |
| 442 | vm86_getptr(&vesa_vmcontext, (vm_offset_t)buf, &vmf.vmf_es, &vmf.vmf_di); |
| 443 | bcopy(p, buf, size); |
| 444 | |
| 445 | err = vm86_datacall(0x10, &vmf, &vesa_vmcontext); |
| 446 | return ((err != 0) || (vmf.vmf_ax != 0x4f)); |
| 447 | } |
| 448 | |
| 449 | static int |
| 450 | vesa_bios_get_line_length(void) |
| 451 | { |
| 452 | struct vm86frame vmf; |
| 453 | int err; |
| 454 | |
| 455 | bzero(&vmf, sizeof(vmf)); |
| 456 | vmf.vmf_eax = 0x4f06; |
| 457 | vmf.vmf_ebx = 1; /* get scan line length */ |
| 458 | err = vm86_intcall(0x10, &vmf); |
| 459 | if ((err != 0) || (vmf.vmf_ax != 0x4f)) |
| 460 | return -1; |
| 461 | return vmf.vmf_bx; /* line length in bytes */ |
| 462 | } |
| 463 | |
| 464 | static int |
| 465 | vesa_bios_set_line_length(int pixel, int *bytes, int *lines) |
| 466 | { |
| 467 | struct vm86frame vmf; |
| 468 | int err; |
| 469 | |
| 470 | bzero(&vmf, sizeof(vmf)); |
| 471 | vmf.vmf_eax = 0x4f06; |
| 472 | vmf.vmf_ebx = 0; /* set scan line length in pixel */ |
| 473 | vmf.vmf_ecx = pixel; |
| 474 | err = vm86_intcall(0x10, &vmf); |
| 475 | #if VESA_DEBUG > 1 |
| 476 | printf("bx:%d, cx:%d, dx:%d\n", vmf.vmf_bx, vmf.vmf_cx, vmf.vmf_dx); |
| 477 | #endif |
| 478 | if ((err != 0) || (vmf.vmf_ax != 0x4f)) |
| 479 | return 1; |
| 480 | if (bytes) |
| 481 | *bytes = vmf.vmf_bx; |
| 482 | if (lines) |
| 483 | *lines = vmf.vmf_dx; |
| 484 | return 0; |
| 485 | } |
| 486 | |
| 487 | #if 0 |
| 488 | static int |
| 489 | vesa_bios_get_start(int *x, int *y) |
| 490 | { |
| 491 | struct vm86frame vmf; |
| 492 | int err; |
| 493 | |
| 494 | bzero(&vmf, sizeof(vmf)); |
| 495 | vmf.vmf_eax = 0x4f07; |
| 496 | vmf.vmf_ebx = 1; /* get display start */ |
| 497 | err = vm86_intcall(0x10, &vmf); |
| 498 | if ((err != 0) || (vmf.vmf_ax != 0x4f)) |
| 499 | return 1; |
| 500 | *x = vmf.vmf_cx; |
| 501 | *y = vmf.vmf_dx; |
| 502 | return 0; |
| 503 | } |
| 504 | #endif |
| 505 | |
| 506 | static int |
| 507 | vesa_bios_set_start(int x, int y) |
| 508 | { |
| 509 | struct vm86frame vmf; |
| 510 | int err; |
| 511 | |
| 512 | bzero(&vmf, sizeof(vmf)); |
| 513 | vmf.vmf_eax = 0x4f07; |
| 514 | vmf.vmf_ebx = 0x80; /* set display start */ |
| 515 | vmf.vmf_edx = y; |
| 516 | vmf.vmf_ecx = x; |
| 517 | err = vm86_intcall(0x10, &vmf); |
| 518 | return ((err != 0) || (vmf.vmf_ax != 0x4f)); |
| 519 | } |
| 520 | |
| 521 | /* map a generic video mode to a known mode */ |
| 522 | static int |
| 523 | vesa_map_gen_mode_num(int type, int color, int mode) |
| 524 | { |
| 525 | static struct { |
| 526 | int from; |
| 527 | int to; |
| 528 | } mode_map[] = { |
| 529 | { M_TEXT_132x25, M_VESA_C132x25 }, |
| 530 | { M_TEXT_132x43, M_VESA_C132x43 }, |
| 531 | { M_TEXT_132x50, M_VESA_C132x50 }, |
| 532 | { M_TEXT_132x60, M_VESA_C132x60 }, |
| 533 | }; |
| 534 | int i; |
| 535 | |
| 536 | for (i = 0; i < sizeof(mode_map)/sizeof(mode_map[0]); ++i) { |
| 537 | if (mode_map[i].from == mode) |
| 538 | return mode_map[i].to; |
| 539 | } |
| 540 | return mode; |
| 541 | } |
| 542 | |
| 543 | static int |
| 544 | vesa_translate_flags(u_int16_t vflags) |
| 545 | { |
| 546 | static struct { |
| 547 | u_int16_t mask; |
| 548 | int set; |
| 549 | int reset; |
| 550 | } ftable[] = { |
| 551 | { V_MODECOLOR, V_INFO_COLOR, 0 }, |
| 552 | { V_MODEGRAPHICS, V_INFO_GRAPHICS, 0 }, |
| 553 | { V_MODELFB, V_INFO_LINEAR, 0 }, |
| 554 | }; |
| 555 | int flags; |
| 556 | int i; |
| 557 | |
| 558 | for (flags = 0, i = 0; i < sizeof(ftable)/sizeof(ftable[0]); ++i) { |
| 559 | flags |= (vflags & ftable[i].mask) ? |
| 560 | ftable[i].set : ftable[i].reset; |
| 561 | } |
| 562 | return flags; |
| 563 | } |
| 564 | |
| 565 | static int |
| 566 | vesa_translate_mmodel(u_int8_t vmodel) |
| 567 | { |
| 568 | static struct { |
| 569 | u_int8_t vmodel; |
| 570 | int mmodel; |
| 571 | } mtable[] = { |
| 572 | { V_MMTEXT, V_INFO_MM_TEXT }, |
| 573 | { V_MMCGA, V_INFO_MM_CGA }, |
| 574 | { V_MMHGC, V_INFO_MM_HGC }, |
| 575 | { V_MMEGA, V_INFO_MM_PLANAR }, |
| 576 | { V_MMPACKED, V_INFO_MM_PACKED }, |
| 577 | { V_MMDIRCOLOR, V_INFO_MM_DIRECT }, |
| 578 | }; |
| 579 | int i; |
| 580 | |
| 581 | for (i = 0; mtable[i].mmodel >= 0; ++i) { |
| 582 | if (mtable[i].vmodel == vmodel) |
| 583 | return mtable[i].mmodel; |
| 584 | } |
| 585 | return V_INFO_MM_OTHER; |
| 586 | } |
| 587 | |
| 588 | static void |
| 589 | *vesa_fix_ptr(u_int32_t p, u_int16_t seg, u_int16_t off, u_char *buf) |
| 590 | { |
| 591 | if (p == 0) |
| 592 | return NULL; |
| 593 | if (((p >> 16) == seg) && ((p & 0xffff) >= off)) |
| 594 | return (void *)(buf + ((p & 0xffff) - off)); |
| 595 | else { |
| 596 | p = BIOS_SADDRTOLADDR(p); |
| 597 | return (void *)BIOS_PADDRTOVADDR(p); |
| 598 | } |
| 599 | } |
| 600 | |
| 601 | static int |
| 602 | vesa_bios_init(void) |
| 603 | { |
| 604 | static u_char buf[512]; |
| 605 | struct vm86frame vmf; |
| 606 | struct vesa_mode vmode; |
| 607 | video_info_t *p; |
| 608 | u_char *vmbuf; |
| 609 | int modes; |
| 610 | int err; |
| 611 | int i; |
| 612 | |
| 613 | if (vesa_init_done) |
| 614 | return 0; |
| 615 | |
| 616 | has_vesa_bios = FALSE; |
| 617 | vesa_adp_info = NULL; |
| 618 | vesa_vmode_max = 0; |
| 619 | vesa_vmode[0].vi_mode = EOT; |
| 620 | |
| 621 | vmbuf = (u_char *)vm86_addpage(&vesa_vmcontext, 1, 0); |
| 622 | bzero(&vmf, sizeof(vmf)); /* paranoia */ |
| 623 | bcopy("VBE2", vmbuf, 4); /* try for VBE2 data */ |
| 624 | vmf.vmf_eax = 0x4f00; |
| 625 | vm86_getptr(&vesa_vmcontext, (vm_offset_t)vmbuf, &vmf.vmf_es, &vmf.vmf_di); |
| 626 | |
| 627 | err = vm86_datacall(0x10, &vmf, &vesa_vmcontext); |
| 628 | if ((err != 0) || (vmf.vmf_ax != 0x4f) || bcmp("VESA", vmbuf, 4)) |
| 629 | return 1; |
| 630 | bcopy(vmbuf, buf, sizeof(buf)); |
| 631 | vesa_adp_info = (struct vesa_info *)buf; |
| 632 | if (bootverbose) { |
| 633 | printf("VESA: information block\n"); |
| 634 | dump_buffer(buf, 64); |
| 635 | } |
| 636 | if (vesa_adp_info->v_flags & V_NONVGA) |
| 637 | return 1; |
| 638 | if (vesa_adp_info->v_version < 0x0102) { |
| 639 | printf("VESA: VBE version %d.%d is not supported; " |
| 640 | "version 1.2 or later is required.\n", |
| 641 | ((vesa_adp_info->v_version & 0xf000) >> 12) * 10 |
| 642 | + ((vesa_adp_info->v_version & 0x0f00) >> 8), |
| 643 | ((vesa_adp_info->v_version & 0x00f0) >> 4) * 10 |
| 644 | + (vesa_adp_info->v_version & 0x000f)); |
| 645 | return 1; |
| 646 | } |
| 647 | |
| 648 | /* fix string ptrs */ |
| 649 | vesa_oemstr = (char *)vesa_fix_ptr(vesa_adp_info->v_oemstr, |
| 650 | vmf.vmf_es, vmf.vmf_di, buf); |
| 651 | if (vesa_adp_info->v_version >= 0x0200) { |
| 652 | vesa_venderstr = |
| 653 | (char *)vesa_fix_ptr(vesa_adp_info->v_venderstr, |
| 654 | vmf.vmf_es, vmf.vmf_di, buf); |
| 655 | vesa_prodstr = |
| 656 | (char *)vesa_fix_ptr(vesa_adp_info->v_prodstr, |
| 657 | vmf.vmf_es, vmf.vmf_di, buf); |
| 658 | vesa_revstr = |
| 659 | (char *)vesa_fix_ptr(vesa_adp_info->v_revstr, |
| 660 | vmf.vmf_es, vmf.vmf_di, buf); |
| 661 | } |
| 662 | |
| 663 | /* obtain video mode information */ |
| 664 | vesa_vmodetab = (u_int16_t *)vesa_fix_ptr(vesa_adp_info->v_modetable, |
| 665 | vmf.vmf_es, vmf.vmf_di, buf); |
| 666 | if (vesa_vmodetab == NULL) |
| 667 | return 1; |
| 668 | for (i = 0, modes = 0; |
| 669 | (i < (M_VESA_MODE_MAX - M_VESA_BASE + 1)) |
| 670 | && (vesa_vmodetab[i] != 0xffff); ++i) { |
| 671 | if (vesa_bios_get_mode(vesa_vmodetab[i], &vmode)) |
| 672 | continue; |
| 673 | |
| 674 | /* reject unsupported modes */ |
| 675 | #if 0 |
| 676 | if ((vmode.v_modeattr & (V_MODESUPP | V_MODEOPTINFO |
| 677 | | V_MODENONVGA)) |
| 678 | != (V_MODESUPP | V_MODEOPTINFO)) |
| 679 | continue; |
| 680 | #else |
| 681 | if ((vmode.v_modeattr & (V_MODEOPTINFO | V_MODENONVGA)) |
| 682 | != (V_MODEOPTINFO)) |
| 683 | continue; |
| 684 | #endif |
| 685 | |
| 686 | /* expand the array if necessary */ |
| 687 | if (modes >= vesa_vmode_max) { |
| 688 | vesa_vmode_max += MODE_TABLE_DELTA; |
| 689 | p = malloc(sizeof(*vesa_vmode)*(vesa_vmode_max + 1), |
| 690 | M_DEVBUF, M_WAITOK); |
| 691 | #if VESA_DEBUG > 1 |
| 692 | printf("vesa_bios_init(): modes:%d, vesa_mode_max:%d\n", |
| 693 | modes, vesa_vmode_max); |
| 694 | #endif |
| 695 | if (modes > 0) { |
| 696 | bcopy(vesa_vmode, p, sizeof(*vesa_vmode)*modes); |
| 697 | free(vesa_vmode, M_DEVBUF); |
| 698 | } |
| 699 | vesa_vmode = p; |
| 700 | } |
| 701 | |
| 702 | /* copy some fields */ |
| 703 | bzero(&vesa_vmode[modes], sizeof(vesa_vmode[modes])); |
| 704 | vesa_vmode[modes].vi_mode = vesa_vmodetab[i]; |
| 705 | vesa_vmode[modes].vi_width = vmode.v_width; |
| 706 | vesa_vmode[modes].vi_height = vmode.v_height; |
| 707 | vesa_vmode[modes].vi_depth = vmode.v_bpp; |
| 708 | vesa_vmode[modes].vi_planes = vmode.v_planes; |
| 709 | vesa_vmode[modes].vi_cwidth = vmode.v_cwidth; |
| 710 | vesa_vmode[modes].vi_cheight = vmode.v_cheight; |
| 711 | vesa_vmode[modes].vi_window = (u_int)vmode.v_waseg << 4; |
| 712 | /* XXX window B */ |
| 713 | vesa_vmode[modes].vi_window_size = vmode.v_wsize*1024; |
| 714 | vesa_vmode[modes].vi_window_gran = vmode.v_wgran*1024; |
| 715 | if (vmode.v_modeattr & V_MODELFB) |
| 716 | vesa_vmode[modes].vi_buffer = vmode.v_lfb; |
| 717 | else |
| 718 | vesa_vmode[modes].vi_buffer = 0; |
| 719 | /* XXX */ |
| 720 | vesa_vmode[modes].vi_buffer_size |
| 721 | = vesa_adp_info->v_memsize*64*1024; |
| 722 | #if 0 |
| 723 | if (vmode.v_offscreen > vmode.v_lfb) |
| 724 | vesa_vmode[modes].vi_buffer_size |
| 725 | = vmode.v_offscreen + vmode.v_offscreensize*1024 |
| 726 | - vmode.v_lfb; |
| 727 | else |
| 728 | vesa_vmode[modes].vi_buffer_size |
| 729 | = vmode.v_offscreen + vmode.v_offscreensize*1024 |
| 730 | #endif |
| 731 | vesa_vmode[modes].vi_mem_model |
| 732 | = vesa_translate_mmodel(vmode.v_memmodel); |
| 733 | vesa_vmode[modes].vi_pixel_fields[0] = 0; |
| 734 | vesa_vmode[modes].vi_pixel_fields[1] = 0; |
| 735 | vesa_vmode[modes].vi_pixel_fields[2] = 0; |
| 736 | vesa_vmode[modes].vi_pixel_fields[3] = 0; |
| 737 | vesa_vmode[modes].vi_pixel_fsizes[0] = 0; |
| 738 | vesa_vmode[modes].vi_pixel_fsizes[1] = 0; |
| 739 | vesa_vmode[modes].vi_pixel_fsizes[2] = 0; |
| 740 | vesa_vmode[modes].vi_pixel_fsizes[3] = 0; |
| 741 | if (vesa_vmode[modes].vi_mem_model == V_INFO_MM_PACKED) { |
| 742 | vesa_vmode[modes].vi_pixel_size = (vmode.v_bpp + 7)/8; |
| 743 | } else if (vesa_vmode[modes].vi_mem_model == V_INFO_MM_DIRECT) { |
| 744 | vesa_vmode[modes].vi_pixel_size = (vmode.v_bpp + 7)/8; |
| 745 | vesa_vmode[modes].vi_pixel_fields[0] |
| 746 | = vmode.v_redfieldpos; |
| 747 | vesa_vmode[modes].vi_pixel_fields[1] |
| 748 | = vmode.v_greenfieldpos; |
| 749 | vesa_vmode[modes].vi_pixel_fields[2] |
| 750 | = vmode.v_bluefieldpos; |
| 751 | vesa_vmode[modes].vi_pixel_fields[3] |
| 752 | = vmode.v_resfieldpos; |
| 753 | vesa_vmode[modes].vi_pixel_fsizes[0] |
| 754 | = vmode.v_redmasksize; |
| 755 | vesa_vmode[modes].vi_pixel_fsizes[1] |
| 756 | = vmode.v_greenmasksize; |
| 757 | vesa_vmode[modes].vi_pixel_fsizes[2] |
| 758 | = vmode.v_bluemasksize; |
| 759 | vesa_vmode[modes].vi_pixel_fsizes[3] |
| 760 | = vmode.v_resmasksize; |
| 761 | } else { |
| 762 | vesa_vmode[modes].vi_pixel_size = 0; |
| 763 | } |
| 764 | |
| 765 | vesa_vmode[modes].vi_flags |
| 766 | = vesa_translate_flags(vmode.v_modeattr) | V_INFO_VESA; |
| 767 | ++modes; |
| 768 | } |
| 769 | vesa_vmode[modes].vi_mode = EOT; |
| 770 | if (bootverbose) |
| 771 | printf("VESA: %d mode(s) found\n", modes); |
| 772 | |
| 773 | has_vesa_bios = (modes > 0); |
| 774 | return (has_vesa_bios ? 0 : 1); |
| 775 | } |
| 776 | |
| 777 | static void |
| 778 | vesa_clear_modes(video_info_t *info, int color) |
| 779 | { |
| 780 | while (info->vi_mode != EOT) { |
| 781 | if ((info->vi_flags & V_INFO_COLOR) != color) |
| 782 | info->vi_mode = NA; |
| 783 | ++info; |
| 784 | } |
| 785 | } |
| 786 | |
| 787 | static vm_offset_t |
| 788 | vesa_map_buffer(u_int paddr, size_t size) |
| 789 | { |
| 790 | vm_offset_t vaddr; |
| 791 | u_int off; |
| 792 | |
| 793 | off = paddr - trunc_page(paddr); |
| 794 | vaddr = (vm_offset_t)pmap_mapdev(paddr - off, size + off); |
| 795 | #if VESA_DEBUG > 1 |
| 796 | printf("vesa_map_buffer: paddr:%x vaddr:%x size:%x off:%x\n", |
| 797 | paddr, vaddr, size, off); |
| 798 | #endif |
| 799 | return (vaddr + off); |
| 800 | } |
| 801 | |
| 802 | static void |
| 803 | vesa_unmap_buffer(vm_offset_t vaddr, size_t size) |
| 804 | { |
| 805 | #if VESA_DEBUG > 1 |
| 806 | printf("vesa_unmap_buffer: vaddr:%x size:%x\n", vaddr, size); |
| 807 | #endif |
| 808 | kmem_free(kernel_map, vaddr, size); |
| 809 | } |
| 810 | |
| 811 | /* entry points */ |
| 812 | |
| 813 | static int |
| 814 | vesa_configure(int flags) |
| 815 | { |
| 816 | video_adapter_t *adp; |
| 817 | int adapters; |
| 818 | int error; |
| 819 | int i; |
| 820 | |
| 821 | if (vesa_init_done) |
| 822 | return 0; |
| 823 | if (flags & VIO_PROBE_ONLY) |
| 824 | return 0; /* XXX */ |
| 825 | |
| 826 | /* |
| 827 | * If the VESA module has already been loaded, abort loading |
| 828 | * the module this time. |
| 829 | */ |
| 830 | for (i = 0; (adp = vid_get_adapter(i)) != NULL; ++i) { |
| 831 | if (adp->va_flags & V_ADP_VESA) |
| 832 | return ENXIO; |
| 833 | if (adp->va_type == KD_VGA) |
| 834 | break; |
| 835 | } |
| 836 | /* |
| 837 | * The VGA adapter is not found. This is because either |
| 838 | * 1) the VGA driver has not been initialized, or 2) the VGA card |
| 839 | * is not present. If 1) is the case, we shall defer |
| 840 | * initialization for now and try again later. |
| 841 | */ |
| 842 | if (adp == NULL) { |
| 843 | vga_sub_configure = vesa_configure; |
| 844 | return ENODEV; |
| 845 | } |
| 846 | |
| 847 | /* count number of registered adapters */ |
| 848 | for (++i; vid_get_adapter(i) != NULL; ++i) |
| 849 | ; |
| 850 | adapters = i; |
| 851 | |
| 852 | /* call VESA BIOS */ |
| 853 | vesa_adp = adp; |
| 854 | if (vesa_bios_init()) { |
| 855 | vesa_adp = NULL; |
| 856 | return ENXIO; |
| 857 | } |
| 858 | vesa_adp->va_flags |= V_ADP_VESA; |
| 859 | |
| 860 | /* remove conflicting modes if we have more than one adapter */ |
| 861 | if (adapters > 1) { |
| 862 | vesa_clear_modes(vesa_vmode, |
| 863 | (vesa_adp->va_flags & V_ADP_COLOR) ? |
| 864 | V_INFO_COLOR : 0); |
| 865 | } |
| 866 | |
| 867 | if ((error = vesa_load_ioctl()) == 0) { |
| 868 | prevvidsw = vidsw[vesa_adp->va_index]; |
| 869 | vidsw[vesa_adp->va_index] = &vesavidsw; |
| 870 | vesa_init_done = TRUE; |
| 871 | } else { |
| 872 | vesa_adp = NULL; |
| 873 | return error; |
| 874 | } |
| 875 | |
| 876 | return 0; |
| 877 | } |
| 878 | |
| 879 | #if 0 |
| 880 | static int |
| 881 | vesa_nop(void) |
| 882 | { |
| 883 | return 0; |
| 884 | } |
| 885 | #endif |
| 886 | |
| 887 | static int |
| 888 | vesa_error(void) |
| 889 | { |
| 890 | return 1; |
| 891 | } |
| 892 | |
| 893 | static int |
| 894 | vesa_probe(int unit, video_adapter_t **adpp, void *arg, int flags) |
| 895 | { |
| 896 | return (*prevvidsw->probe)(unit, adpp, arg, flags); |
| 897 | } |
| 898 | |
| 899 | static int |
| 900 | vesa_init(int unit, video_adapter_t *adp, int flags) |
| 901 | { |
| 902 | return (*prevvidsw->init)(unit, adp, flags); |
| 903 | } |
| 904 | |
| 905 | static int |
| 906 | vesa_get_info(video_adapter_t *adp, int mode, video_info_t *info) |
| 907 | { |
| 908 | int i; |
| 909 | |
| 910 | if ((*prevvidsw->get_info)(adp, mode, info) == 0) |
| 911 | return 0; |
| 912 | |
| 913 | if (adp != vesa_adp) |
| 914 | return 1; |
| 915 | |
| 916 | mode = vesa_map_gen_mode_num(vesa_adp->va_type, |
| 917 | vesa_adp->va_flags & V_ADP_COLOR, mode); |
| 918 | for (i = 0; vesa_vmode[i].vi_mode != EOT; ++i) { |
| 919 | if (vesa_vmode[i].vi_mode == NA) |
| 920 | continue; |
| 921 | if (vesa_vmode[i].vi_mode == mode) { |
| 922 | *info = vesa_vmode[i]; |
| 923 | return 0; |
| 924 | } |
| 925 | } |
| 926 | return 1; |
| 927 | } |
| 928 | |
| 929 | static int |
| 930 | vesa_query_mode(video_adapter_t *adp, video_info_t *info) |
| 931 | { |
| 932 | int i; |
| 933 | |
| 934 | if ((*prevvidsw->query_mode)(adp, info) == 0) |
| 935 | return 0; |
| 936 | if (adp != vesa_adp) |
| 937 | return ENODEV; |
| 938 | |
| 939 | for (i = 0; vesa_vmode[i].vi_mode != EOT; ++i) { |
| 940 | if ((info->vi_width != 0) |
| 941 | && (info->vi_width != vesa_vmode[i].vi_width)) |
| 942 | continue; |
| 943 | if ((info->vi_height != 0) |
| 944 | && (info->vi_height != vesa_vmode[i].vi_height)) |
| 945 | continue; |
| 946 | if ((info->vi_cwidth != 0) |
| 947 | && (info->vi_cwidth != vesa_vmode[i].vi_cwidth)) |
| 948 | continue; |
| 949 | if ((info->vi_cheight != 0) |
| 950 | && (info->vi_cheight != vesa_vmode[i].vi_cheight)) |
| 951 | continue; |
| 952 | if ((info->vi_depth != 0) |
| 953 | && (info->vi_depth != vesa_vmode[i].vi_depth)) |
| 954 | continue; |
| 955 | if ((info->vi_planes != 0) |
| 956 | && (info->vi_planes != vesa_vmode[i].vi_planes)) |
| 957 | continue; |
| 958 | /* pixel format, memory model */ |
| 959 | if ((info->vi_flags != 0) |
| 960 | && (info->vi_flags != vesa_vmode[i].vi_flags)) |
| 961 | continue; |
| 962 | *info = vesa_vmode[i]; |
| 963 | return 0; |
| 964 | } |
| 965 | return ENODEV; |
| 966 | } |
| 967 | |
| 968 | static int |
| 969 | vesa_set_mode(video_adapter_t *adp, int mode) |
| 970 | { |
| 971 | video_info_t info; |
| 972 | int len; |
| 973 | |
| 974 | if (adp != vesa_adp) |
| 975 | return (*prevvidsw->set_mode)(adp, mode); |
| 976 | |
| 977 | mode = vesa_map_gen_mode_num(adp->va_type, |
| 978 | adp->va_flags & V_ADP_COLOR, mode); |
| 979 | #if VESA_DEBUG > 0 |
| 980 | printf("VESA: set_mode(): %d(%x) -> %d(%x)\n", |
| 981 | adp->va_mode, adp->va_mode, mode, mode); |
| 982 | #endif |
| 983 | /* |
| 984 | * If the current mode is a VESA mode and the new mode is not, |
| 985 | * restore the state of the adapter first by setting one of the |
| 986 | * standard VGA mode, so that non-standard, extended SVGA registers |
| 987 | * are set to the state compatible with the standard VGA modes. |
| 988 | * Otherwise (*prevvidsw->set_mode)() may not be able to set up |
| 989 | * the new mode correctly. |
| 990 | */ |
| 991 | if (VESA_MODE(adp->va_mode)) { |
| 992 | if ((*prevvidsw->get_info)(adp, mode, &info) == 0) { |
| 993 | int10_set_mode(adp->va_initial_bios_mode); |
| 994 | if (adp->va_info.vi_flags & V_INFO_LINEAR) |
| 995 | vesa_unmap_buffer(adp->va_buffer, |
| 996 | vesa_adp_info->v_memsize*64*1024); |
| 997 | /* |
| 998 | * Once (*prevvidsw->get_info)() succeeded, |
| 999 | * (*prevvidsw->set_mode)() below won't fail... |
| 1000 | */ |
| 1001 | } |
| 1002 | } |
| 1003 | |
| 1004 | /* we may not need to handle this mode after all... */ |
| 1005 | if ((*prevvidsw->set_mode)(adp, mode) == 0) |
| 1006 | return 0; |
| 1007 | |
| 1008 | /* is the new mode supported? */ |
| 1009 | if (vesa_get_info(adp, mode, &info)) |
| 1010 | return 1; |
| 1011 | /* assert(VESA_MODE(mode)); */ |
| 1012 | |
| 1013 | #if VESA_DEBUG > 0 |
| 1014 | printf("VESA: about to set a VESA mode...\n"); |
| 1015 | #endif |
| 1016 | /* don't use the linear frame buffer for text modes. XXX */ |
| 1017 | if (!(info.vi_flags & V_INFO_GRAPHICS)) |
| 1018 | info.vi_flags &= ~V_INFO_LINEAR; |
| 1019 | |
| 1020 | if (vesa_bios_set_mode(mode | ((info.vi_flags & V_INFO_LINEAR) ? 0x4000 : 0))) |
| 1021 | return 1; |
| 1022 | |
| 1023 | if (adp->va_info.vi_flags & V_INFO_LINEAR) |
| 1024 | vesa_unmap_buffer(adp->va_buffer, |
| 1025 | vesa_adp_info->v_memsize*64*1024); |
| 1026 | |
| 1027 | #if VESA_DEBUG > 0 |
| 1028 | printf("VESA: mode set!\n"); |
| 1029 | #endif |
| 1030 | vesa_adp->va_mode = mode; |
| 1031 | vesa_adp->va_flags &= ~V_ADP_COLOR; |
| 1032 | vesa_adp->va_flags |= |
| 1033 | (info.vi_flags & V_INFO_COLOR) ? V_ADP_COLOR : 0; |
| 1034 | vesa_adp->va_crtc_addr = |
| 1035 | (vesa_adp->va_flags & V_ADP_COLOR) ? COLOR_CRTC : MONO_CRTC; |
| 1036 | if (info.vi_flags & V_INFO_LINEAR) { |
| 1037 | #if VESA_DEBUG > 1 |
| 1038 | printf("VESA: setting up LFB\n"); |
| 1039 | #endif |
| 1040 | vesa_adp->va_buffer = |
| 1041 | vesa_map_buffer(info.vi_buffer, |
| 1042 | vesa_adp_info->v_memsize*64*1024); |
| 1043 | vesa_adp->va_buffer_size = info.vi_buffer_size; |
| 1044 | vesa_adp->va_window = vesa_adp->va_buffer; |
| 1045 | vesa_adp->va_window_size = info.vi_buffer_size/info.vi_planes; |
| 1046 | vesa_adp->va_window_gran = info.vi_buffer_size/info.vi_planes; |
| 1047 | } else { |
| 1048 | vesa_adp->va_buffer = 0; |
| 1049 | vesa_adp->va_buffer_size = info.vi_buffer_size; |
| 1050 | vesa_adp->va_window = BIOS_PADDRTOVADDR(info.vi_window); |
| 1051 | vesa_adp->va_window_size = info.vi_window_size; |
| 1052 | vesa_adp->va_window_gran = info.vi_window_gran; |
| 1053 | } |
| 1054 | vesa_adp->va_window_orig = 0; |
| 1055 | len = vesa_bios_get_line_length(); |
| 1056 | if (len > 0) { |
| 1057 | vesa_adp->va_line_width = len; |
| 1058 | } else if (info.vi_flags & V_INFO_GRAPHICS) { |
| 1059 | switch (info.vi_depth/info.vi_planes) { |
| 1060 | case 1: |
| 1061 | vesa_adp->va_line_width = info.vi_width/8; |
| 1062 | break; |
| 1063 | case 2: |
| 1064 | vesa_adp->va_line_width = info.vi_width/4; |
| 1065 | break; |
| 1066 | case 4: |
| 1067 | vesa_adp->va_line_width = info.vi_width/2; |
| 1068 | break; |
| 1069 | case 8: |
| 1070 | default: /* shouldn't happen */ |
| 1071 | vesa_adp->va_line_width = info.vi_width; |
| 1072 | break; |
| 1073 | } |
| 1074 | } else { |
| 1075 | vesa_adp->va_line_width = info.vi_width; |
| 1076 | } |
| 1077 | vesa_adp->va_disp_start.x = 0; |
| 1078 | vesa_adp->va_disp_start.y = 0; |
| 1079 | #if VESA_DEBUG > 0 |
| 1080 | printf("vesa_set_mode(): vi_width:%d, len:%d, line_width:%d\n", |
| 1081 | info.vi_width, len, vesa_adp->va_line_width); |
| 1082 | #endif |
| 1083 | bcopy(&info, &vesa_adp->va_info, sizeof(vesa_adp->va_info)); |
| 1084 | |
| 1085 | /* move hardware cursor out of the way */ |
| 1086 | (*vidsw[vesa_adp->va_index]->set_hw_cursor)(vesa_adp, -1, -1); |
| 1087 | |
| 1088 | return 0; |
| 1089 | } |
| 1090 | |
| 1091 | static int |
| 1092 | vesa_save_font(video_adapter_t *adp, int page, int fontsize, u_char *data, |
| 1093 | int ch, int count) |
| 1094 | { |
| 1095 | return (*prevvidsw->save_font)(adp, page, fontsize, data, ch, count); |
| 1096 | } |
| 1097 | |
| 1098 | static int |
| 1099 | vesa_load_font(video_adapter_t *adp, int page, int fontsize, u_char *data, |
| 1100 | int ch, int count) |
| 1101 | { |
| 1102 | return (*prevvidsw->load_font)(adp, page, fontsize, data, ch, count); |
| 1103 | } |
| 1104 | |
| 1105 | static int |
| 1106 | vesa_show_font(video_adapter_t *adp, int page) |
| 1107 | { |
| 1108 | return (*prevvidsw->show_font)(adp, page); |
| 1109 | } |
| 1110 | |
| 1111 | static int |
| 1112 | vesa_save_palette(video_adapter_t *adp, u_char *palette) |
| 1113 | { |
| 1114 | int bits; |
| 1115 | int error; |
| 1116 | |
| 1117 | if ((adp == vesa_adp) && (vesa_adp_info->v_flags & V_DAC8) |
| 1118 | && VESA_MODE(adp->va_mode)) { |
| 1119 | bits = vesa_bios_get_dac(); |
| 1120 | error = vesa_bios_save_palette(0, 256, palette, bits); |
| 1121 | if (error == 0) |
| 1122 | return 0; |
| 1123 | if (bits != 6) |
| 1124 | return error; |
| 1125 | } |
| 1126 | |
| 1127 | return (*prevvidsw->save_palette)(adp, palette); |
| 1128 | } |
| 1129 | |
| 1130 | static int |
| 1131 | vesa_load_palette(video_adapter_t *adp, u_char *palette) |
| 1132 | { |
| 1133 | #if notyet |
| 1134 | int bits; |
| 1135 | int error; |
| 1136 | |
| 1137 | if ((adp == vesa_adp) && (vesa_adp_info->v_flags & V_DAC8) |
| 1138 | && VESA_MODE(adp->va_mode) && ((bits = vesa_bios_set_dac(8)) > 6)) { |
| 1139 | error = vesa_bios_load_palette(0, 256, palette, bits); |
| 1140 | if (error == 0) |
| 1141 | return 0; |
| 1142 | if (vesa_bios_set_dac(6) != 6) |
| 1143 | return 1; |
| 1144 | } |
| 1145 | #endif /* notyet */ |
| 1146 | |
| 1147 | return (*prevvidsw->load_palette)(adp, palette); |
| 1148 | } |
| 1149 | |
| 1150 | static int |
| 1151 | vesa_set_border(video_adapter_t *adp, int color) |
| 1152 | { |
| 1153 | return (*prevvidsw->set_border)(adp, color); |
| 1154 | } |
| 1155 | |
| 1156 | static int |
| 1157 | vesa_save_state(video_adapter_t *adp, void *p, size_t size) |
| 1158 | { |
| 1159 | if (adp != vesa_adp) |
| 1160 | return (*prevvidsw->save_state)(adp, p, size); |
| 1161 | |
| 1162 | if (vesa_state_buf_size == 0) |
| 1163 | vesa_state_buf_size = vesa_bios_state_buf_size(); |
| 1164 | if (size == 0) |
| 1165 | return (sizeof(int) + vesa_state_buf_size); |
| 1166 | else if (size < (sizeof(int) + vesa_state_buf_size)) |
| 1167 | return 1; |
| 1168 | |
| 1169 | ((adp_state_t *)p)->sig = V_STATE_SIG; |
| 1170 | bzero(((adp_state_t *)p)->regs, vesa_state_buf_size); |
| 1171 | return vesa_bios_save_restore(STATE_SAVE, ((adp_state_t *)p)->regs, |
| 1172 | vesa_state_buf_size); |
| 1173 | } |
| 1174 | |
| 1175 | static int |
| 1176 | vesa_load_state(video_adapter_t *adp, void *p) |
| 1177 | { |
| 1178 | if ((adp != vesa_adp) || (((adp_state_t *)p)->sig != V_STATE_SIG)) |
| 1179 | return (*prevvidsw->load_state)(adp, p); |
| 1180 | |
| 1181 | return vesa_bios_save_restore(STATE_LOAD, ((adp_state_t *)p)->regs, |
| 1182 | vesa_state_buf_size); |
| 1183 | } |
| 1184 | |
| 1185 | #if 0 |
| 1186 | static int |
| 1187 | vesa_get_origin(video_adapter_t *adp, off_t *offset) |
| 1188 | { |
| 1189 | struct vm86frame vmf; |
| 1190 | int err; |
| 1191 | |
| 1192 | bzero(&vmf, sizeof(vmf)); |
| 1193 | vmf.vmf_eax = 0x4f05; |
| 1194 | vmf.vmf_ebx = 0x10; /* WINDOW_A, XXX */ |
| 1195 | err = vm86_intcall(0x10, &vmf); |
| 1196 | if ((err != 0) || (vmf.vmf_ax != 0x4f)) |
| 1197 | return 1; |
| 1198 | *offset = vmf.vmf_dx*adp->va_window_gran; |
| 1199 | return 0; |
| 1200 | } |
| 1201 | #endif |
| 1202 | |
| 1203 | static int |
| 1204 | vesa_set_origin(video_adapter_t *adp, off_t offset) |
| 1205 | { |
| 1206 | struct vm86frame vmf; |
| 1207 | int err; |
| 1208 | |
| 1209 | /* |
| 1210 | * This function should return as quickly as possible to |
| 1211 | * maintain good performance of the system. For this reason, |
| 1212 | * error checking is kept minimal and let the VESA BIOS to |
| 1213 | * detect error. |
| 1214 | */ |
| 1215 | if (adp != vesa_adp) |
| 1216 | return (*prevvidsw->set_win_org)(adp, offset); |
| 1217 | |
| 1218 | /* if this is a linear frame buffer, do nothing */ |
| 1219 | if (adp->va_info.vi_flags & V_INFO_LINEAR) |
| 1220 | return 0; |
| 1221 | /* XXX */ |
| 1222 | if (adp->va_window_gran == 0) |
| 1223 | return 1; |
| 1224 | |
| 1225 | bzero(&vmf, sizeof(vmf)); |
| 1226 | vmf.vmf_eax = 0x4f05; |
| 1227 | vmf.vmf_ebx = 0; /* WINDOW_A, XXX */ |
| 1228 | vmf.vmf_edx = offset/adp->va_window_gran; |
| 1229 | err = vm86_intcall(0x10, &vmf); |
| 1230 | if ((err != 0) || (vmf.vmf_ax != 0x4f)) |
| 1231 | return 1; |
| 1232 | bzero(&vmf, sizeof(vmf)); |
| 1233 | vmf.vmf_eax = 0x4f05; |
| 1234 | vmf.vmf_ebx = 1; /* WINDOW_B, XXX */ |
| 1235 | vmf.vmf_edx = offset/adp->va_window_gran; |
| 1236 | err = vm86_intcall(0x10, &vmf); |
| 1237 | adp->va_window_orig = (offset/adp->va_window_gran)*adp->va_window_gran; |
| 1238 | return 0; /* XXX */ |
| 1239 | } |
| 1240 | |
| 1241 | static int |
| 1242 | vesa_read_hw_cursor(video_adapter_t *adp, int *col, int *row) |
| 1243 | { |
| 1244 | return (*prevvidsw->read_hw_cursor)(adp, col, row); |
| 1245 | } |
| 1246 | |
| 1247 | static int |
| 1248 | vesa_set_hw_cursor(video_adapter_t *adp, int col, int row) |
| 1249 | { |
| 1250 | return (*prevvidsw->set_hw_cursor)(adp, col, row); |
| 1251 | } |
| 1252 | |
| 1253 | static int |
| 1254 | vesa_set_hw_cursor_shape(video_adapter_t *adp, int base, int height, |
| 1255 | int celsize, int blink) |
| 1256 | { |
| 1257 | return (*prevvidsw->set_hw_cursor_shape)(adp, base, height, celsize, |
| 1258 | blink); |
| 1259 | } |
| 1260 | |
| 1261 | static int |
| 1262 | vesa_blank_display(video_adapter_t *adp, int mode) |
| 1263 | { |
| 1264 | /* XXX: use VESA DPMS */ |
| 1265 | return (*prevvidsw->blank_display)(adp, mode); |
| 1266 | } |
| 1267 | |
| 1268 | static int |
| 1269 | vesa_mmap(video_adapter_t *adp, vm_offset_t offset, int prot) |
| 1270 | { |
| 1271 | #if VESA_DEBUG > 0 |
| 1272 | printf("vesa_mmap(): window:0x%x, buffer:0x%x, offset:0x%x\n", |
| 1273 | adp->va_info.vi_window, adp->va_info.vi_buffer, offset); |
| 1274 | #endif |
| 1275 | |
| 1276 | if ((adp == vesa_adp) && (adp->va_info.vi_flags & V_INFO_LINEAR)) { |
| 1277 | /* va_window_size == va_buffer_size/vi_planes */ |
| 1278 | /* XXX: is this correct? */ |
| 1279 | if (offset > adp->va_window_size - PAGE_SIZE) |
| 1280 | return -1; |
| 1281 | #ifdef __i386__ |
| 1282 | return i386_btop(adp->va_info.vi_buffer + offset); |
| 1283 | #endif |
| 1284 | #ifdef __alpha__ /* XXX */ |
| 1285 | return alpha_btop(adp->va_info.vi_buffer + offset); |
| 1286 | #endif |
| 1287 | } else { |
| 1288 | return (*prevvidsw->mmap)(adp, offset, prot); |
| 1289 | } |
| 1290 | } |
| 1291 | |
| 1292 | static int |
| 1293 | vesa_clear(video_adapter_t *adp) |
| 1294 | { |
| 1295 | return (*prevvidsw->clear)(adp); |
| 1296 | } |
| 1297 | |
| 1298 | static int |
| 1299 | vesa_fill_rect(video_adapter_t *adp, int val, int x, int y, int cx, int cy) |
| 1300 | { |
| 1301 | return (*prevvidsw->fill_rect)(adp, val, x, y, cx, cy); |
| 1302 | } |
| 1303 | |
| 1304 | static int |
| 1305 | vesa_bitblt(video_adapter_t *adp,...) |
| 1306 | { |
| 1307 | /* FIXME */ |
| 1308 | return 1; |
| 1309 | } |
| 1310 | |
| 1311 | static int |
| 1312 | get_palette(video_adapter_t *adp, int base, int count, |
| 1313 | u_char *red, u_char *green, u_char *blue, u_char *trans) |
| 1314 | { |
| 1315 | u_char *r; |
| 1316 | u_char *g; |
| 1317 | u_char *b; |
| 1318 | int bits; |
| 1319 | int error; |
| 1320 | |
| 1321 | if ((base < 0) || (base >= 256) || (count < 0) || (count > 256)) |
| 1322 | return 1; |
| 1323 | if (base + count > 256) |
| 1324 | return 1; |
| 1325 | if (!(vesa_adp_info->v_flags & V_DAC8) || !VESA_MODE(adp->va_mode)) |
| 1326 | return 1; |
| 1327 | |
| 1328 | bits = vesa_bios_get_dac(); |
| 1329 | if (bits <= 6) |
| 1330 | return 1; |
| 1331 | |
| 1332 | r = malloc(count*3, M_DEVBUF, M_WAITOK); |
| 1333 | g = r + count; |
| 1334 | b = g + count; |
| 1335 | error = vesa_bios_save_palette2(base, count, r, g, b, bits); |
| 1336 | if (error == 0) { |
| 1337 | copyout(r, red, count); |
| 1338 | copyout(g, green, count); |
| 1339 | copyout(b, blue, count); |
| 1340 | if (trans != NULL) { |
| 1341 | bzero(r, count); |
| 1342 | copyout(r, trans, count); |
| 1343 | } |
| 1344 | } |
| 1345 | free(r, M_DEVBUF); |
| 1346 | |
| 1347 | /* if error && bits != 6 at this point, we are in in trouble... XXX */ |
| 1348 | return error; |
| 1349 | } |
| 1350 | |
| 1351 | static int |
| 1352 | set_palette(video_adapter_t *adp, int base, int count, |
| 1353 | u_char *red, u_char *green, u_char *blue, u_char *trans) |
| 1354 | { |
| 1355 | return 1; |
| 1356 | #if notyet |
| 1357 | u_char *r; |
| 1358 | u_char *g; |
| 1359 | u_char *b; |
| 1360 | int bits; |
| 1361 | int error; |
| 1362 | |
| 1363 | if ((base < 0) || (base >= 256) || (base + count > 256)) |
| 1364 | return 1; |
| 1365 | if (!(vesa_adp_info->v_flags & V_DAC8) || !VESA_MODE(adp->va_mode) |
| 1366 | || ((bits = vesa_bios_set_dac(8)) <= 6)) |
| 1367 | return 1; |
| 1368 | |
| 1369 | r = malloc(count*3, M_DEVBUF, M_WAITOK); |
| 1370 | g = r + count; |
| 1371 | b = g + count; |
| 1372 | copyin(red, r, count); |
| 1373 | copyin(green, g, count); |
| 1374 | copyin(blue, b, count); |
| 1375 | |
| 1376 | error = vesa_bios_load_palette2(base, count, r, g, b, bits); |
| 1377 | free(r, M_DEVBUF); |
| 1378 | if (error == 0) |
| 1379 | return 0; |
| 1380 | |
| 1381 | /* if the following call fails, we are in trouble... XXX */ |
| 1382 | vesa_bios_set_dac(6); |
| 1383 | return 1; |
| 1384 | #endif /* notyet */ |
| 1385 | } |
| 1386 | |
| 1387 | static int |
| 1388 | vesa_ioctl(video_adapter_t *adp, u_long cmd, caddr_t arg) |
| 1389 | { |
| 1390 | int bytes; |
| 1391 | |
| 1392 | if (adp != vesa_adp) |
| 1393 | return (*prevvidsw->ioctl)(adp, cmd, arg); |
| 1394 | |
| 1395 | switch (cmd) { |
| 1396 | case FBIO_SETWINORG: /* set frame buffer window origin */ |
| 1397 | if (!VESA_MODE(adp->va_mode)) |
| 1398 | return (*prevvidsw->ioctl)(adp, cmd, arg); |
| 1399 | return (vesa_set_origin(adp, *(off_t *)arg) ? ENODEV : 0); |
| 1400 | |
| 1401 | case FBIO_SETDISPSTART: /* set display start address */ |
| 1402 | if (!VESA_MODE(adp->va_mode)) |
| 1403 | return (*prevvidsw->ioctl)(adp, cmd, arg); |
| 1404 | if (vesa_bios_set_start(((video_display_start_t *)arg)->x, |
| 1405 | ((video_display_start_t *)arg)->y)) |
| 1406 | return ENODEV; |
| 1407 | adp->va_disp_start.x = ((video_display_start_t *)arg)->x; |
| 1408 | adp->va_disp_start.y = ((video_display_start_t *)arg)->y; |
| 1409 | return 0; |
| 1410 | |
| 1411 | case FBIO_SETLINEWIDTH: /* set line length in pixel */ |
| 1412 | if (!VESA_MODE(adp->va_mode)) |
| 1413 | return (*prevvidsw->ioctl)(adp, cmd, arg); |
| 1414 | if (vesa_bios_set_line_length(*(u_int *)arg, &bytes, NULL)) |
| 1415 | return ENODEV; |
| 1416 | adp->va_line_width = bytes; |
| 1417 | #if VESA_DEBUG > 1 |
| 1418 | printf("new line width:%d\n", adp->va_line_width); |
| 1419 | #endif |
| 1420 | return 0; |
| 1421 | |
| 1422 | case FBIO_GETPALETTE: /* get color palette */ |
| 1423 | if (get_palette(adp, ((video_color_palette_t *)arg)->index, |
| 1424 | ((video_color_palette_t *)arg)->count, |
| 1425 | ((video_color_palette_t *)arg)->red, |
| 1426 | ((video_color_palette_t *)arg)->green, |
| 1427 | ((video_color_palette_t *)arg)->blue, |
| 1428 | ((video_color_palette_t *)arg)->transparent)) |
| 1429 | return (*prevvidsw->ioctl)(adp, cmd, arg); |
| 1430 | return 0; |
| 1431 | |
| 1432 | |
| 1433 | case FBIO_SETPALETTE: /* set color palette */ |
| 1434 | if (set_palette(adp, ((video_color_palette_t *)arg)->index, |
| 1435 | ((video_color_palette_t *)arg)->count, |
| 1436 | ((video_color_palette_t *)arg)->red, |
| 1437 | ((video_color_palette_t *)arg)->green, |
| 1438 | ((video_color_palette_t *)arg)->blue, |
| 1439 | ((video_color_palette_t *)arg)->transparent)) |
| 1440 | return (*prevvidsw->ioctl)(adp, cmd, arg); |
| 1441 | return 0; |
| 1442 | |
| 1443 | case FBIOGETCMAP: /* get color palette */ |
| 1444 | if (get_palette(adp, ((struct fbcmap *)arg)->index, |
| 1445 | ((struct fbcmap *)arg)->count, |
| 1446 | ((struct fbcmap *)arg)->red, |
| 1447 | ((struct fbcmap *)arg)->green, |
| 1448 | ((struct fbcmap *)arg)->blue, NULL)) |
| 1449 | return (*prevvidsw->ioctl)(adp, cmd, arg); |
| 1450 | return 0; |
| 1451 | |
| 1452 | case FBIOPUTCMAP: /* set color palette */ |
| 1453 | if (set_palette(adp, ((struct fbcmap *)arg)->index, |
| 1454 | ((struct fbcmap *)arg)->count, |
| 1455 | ((struct fbcmap *)arg)->red, |
| 1456 | ((struct fbcmap *)arg)->green, |
| 1457 | ((struct fbcmap *)arg)->blue, NULL)) |
| 1458 | return (*prevvidsw->ioctl)(adp, cmd, arg); |
| 1459 | return 0; |
| 1460 | |
| 1461 | default: |
| 1462 | return (*prevvidsw->ioctl)(adp, cmd, arg); |
| 1463 | } |
| 1464 | } |
| 1465 | |
| 1466 | static int |
| 1467 | vesa_diag(video_adapter_t *adp, int level) |
| 1468 | { |
| 1469 | int error; |
| 1470 | |
| 1471 | /* call the previous handler first */ |
| 1472 | error = (*prevvidsw->diag)(adp, level); |
| 1473 | if (error) |
| 1474 | return error; |
| 1475 | |
| 1476 | if (adp != vesa_adp) |
| 1477 | return 1; |
| 1478 | |
| 1479 | if (level <= 0) |
| 1480 | return 0; |
| 1481 | |
| 1482 | return 0; |
| 1483 | } |
| 1484 | |
| 1485 | static int |
| 1486 | vesa_bios_info(int level) |
| 1487 | { |
| 1488 | #if VESA_DEBUG > 1 |
| 1489 | struct vesa_mode vmode; |
| 1490 | int i; |
| 1491 | #endif |
| 1492 | |
| 1493 | /* general adapter information */ |
| 1494 | printf("VESA: v%d.%d, %dk memory, flags:0x%x, mode table:%p (%x)\n", |
| 1495 | ((vesa_adp_info->v_version & 0xf000) >> 12) * 10 |
| 1496 | + ((vesa_adp_info->v_version & 0x0f00) >> 8), |
| 1497 | ((vesa_adp_info->v_version & 0x00f0) >> 4) * 10 |
| 1498 | + (vesa_adp_info->v_version & 0x000f), |
| 1499 | vesa_adp_info->v_memsize * 64, vesa_adp_info->v_flags, |
| 1500 | vesa_vmodetab, vesa_adp_info->v_modetable); |
| 1501 | /* OEM string */ |
| 1502 | if (vesa_oemstr != NULL) |
| 1503 | printf("VESA: %s\n", vesa_oemstr); |
| 1504 | |
| 1505 | if (level <= 0) |
| 1506 | return 0; |
| 1507 | |
| 1508 | if (vesa_adp_info->v_version >= 0x0200) { |
| 1509 | /* vender name, product name, product revision */ |
| 1510 | printf("VESA: %s %s %s\n", |
| 1511 | (vesa_venderstr != NULL) ? vesa_venderstr : "unknown", |
| 1512 | (vesa_prodstr != NULL) ? vesa_prodstr : "unknown", |
| 1513 | (vesa_revstr != NULL) ? vesa_revstr : "?"); |
| 1514 | } |
| 1515 | |
| 1516 | #if VESA_DEBUG > 1 |
| 1517 | /* mode information */ |
| 1518 | for (i = 0; |
| 1519 | (i < (M_VESA_MODE_MAX - M_VESA_BASE + 1)) |
| 1520 | && (vesa_vmodetab[i] != 0xffff); ++i) { |
| 1521 | if (vesa_bios_get_mode(vesa_vmodetab[i], &vmode)) |
| 1522 | continue; |
| 1523 | |
| 1524 | /* print something for diagnostic purpose */ |
| 1525 | printf("VESA: mode:0x%03x, flags:0x%04x", |
| 1526 | vesa_vmodetab[i], vmode.v_modeattr); |
| 1527 | if (vmode.v_modeattr & V_MODEOPTINFO) { |
| 1528 | if (vmode.v_modeattr & V_MODEGRAPHICS) { |
| 1529 | printf(", G %dx%dx%d %d, ", |
| 1530 | vmode.v_width, vmode.v_height, |
| 1531 | vmode.v_bpp, vmode.v_planes); |
| 1532 | } else { |
| 1533 | printf(", T %dx%d, ", |
| 1534 | vmode.v_width, vmode.v_height); |
| 1535 | } |
| 1536 | printf("font:%dx%d, ", |
| 1537 | vmode.v_cwidth, vmode.v_cheight); |
| 1538 | printf("pages:%d, mem:%d", |
| 1539 | vmode.v_ipages + 1, vmode.v_memmodel); |
| 1540 | } |
| 1541 | if (vmode.v_modeattr & V_MODELFB) { |
| 1542 | printf("\nVESA: LFB:0x%x, off:0x%x, off_size:0x%x", |
| 1543 | vmode.v_lfb, vmode.v_offscreen, |
| 1544 | vmode.v_offscreensize*1024); |
| 1545 | } |
| 1546 | printf("\n"); |
| 1547 | printf("VESA: window A:0x%x (%x), window B:0x%x (%x), ", |
| 1548 | vmode.v_waseg, vmode.v_waattr, |
| 1549 | vmode.v_wbseg, vmode.v_wbattr); |
| 1550 | printf("size:%dk, gran:%dk\n", |
| 1551 | vmode.v_wsize, vmode.v_wgran); |
| 1552 | } |
| 1553 | #endif /* VESA_DEBUG > 1 */ |
| 1554 | |
| 1555 | return 0; |
| 1556 | } |
| 1557 | |
| 1558 | /* module loading */ |
| 1559 | |
| 1560 | static int |
| 1561 | vesa_load(void) |
| 1562 | { |
| 1563 | int error; |
| 1564 | int s; |
| 1565 | |
| 1566 | if (vesa_init_done) |
| 1567 | return 0; |
| 1568 | |
| 1569 | /* locate a VGA adapter */ |
| 1570 | s = spltty(); |
| 1571 | vesa_adp = NULL; |
| 1572 | error = vesa_configure(0); |
| 1573 | splx(s); |
| 1574 | |
| 1575 | if (error == 0) |
| 1576 | vesa_bios_info(bootverbose); |
| 1577 | |
| 1578 | return error; |
| 1579 | } |
| 1580 | |
| 1581 | static int |
| 1582 | vesa_unload(void) |
| 1583 | { |
| 1584 | u_char palette[256*3]; |
| 1585 | int error; |
| 1586 | int bits; |
| 1587 | int s; |
| 1588 | |
| 1589 | /* if the adapter is currently in a VESA mode, don't unload */ |
| 1590 | if ((vesa_adp != NULL) && VESA_MODE(vesa_adp->va_mode)) |
| 1591 | return EBUSY; |
| 1592 | /* |
| 1593 | * FIXME: if there is at least one vty which is in a VESA mode, |
| 1594 | * we shouldn't be unloading! XXX |
| 1595 | */ |
| 1596 | |
| 1597 | s = spltty(); |
| 1598 | if ((error = vesa_unload_ioctl()) == 0) { |
| 1599 | if (vesa_adp != NULL) { |
| 1600 | if (vesa_adp_info->v_flags & V_DAC8) { |
| 1601 | bits = vesa_bios_get_dac(); |
| 1602 | if (bits > 6) { |
| 1603 | vesa_bios_save_palette(0, 256, |
| 1604 | palette, bits); |
| 1605 | vesa_bios_set_dac(6); |
| 1606 | vesa_bios_load_palette(0, 256, |
| 1607 | palette, 6); |
| 1608 | } |
| 1609 | } |
| 1610 | vesa_adp->va_flags &= ~V_ADP_VESA; |
| 1611 | vidsw[vesa_adp->va_index] = prevvidsw; |
| 1612 | } |
| 1613 | } |
| 1614 | splx(s); |
| 1615 | |
| 1616 | return error; |
| 1617 | } |
| 1618 | |
| 1619 | static int |
| 1620 | vesa_mod_event(module_t mod, int type, void *data) |
| 1621 | { |
| 1622 | switch (type) { |
| 1623 | case MOD_LOAD: |
| 1624 | return vesa_load(); |
| 1625 | case MOD_UNLOAD: |
| 1626 | return vesa_unload(); |
| 1627 | default: |
| 1628 | break; |
| 1629 | } |
| 1630 | return 0; |
| 1631 | } |
| 1632 | |
| 1633 | static moduledata_t vesa_mod = { |
| 1634 | "vesa", |
| 1635 | vesa_mod_event, |
| 1636 | NULL, |
| 1637 | }; |
| 1638 | |
| 1639 | DECLARE_MODULE(vesa, vesa_mod, SI_SUB_DRIVERS, SI_ORDER_MIDDLE); |
| 1640 | |
| 1641 | #endif /* VGA_NO_MODE_CHANGE */ |