2 * Copyright (c) 1998 Kazutaka YOKOTA and Michael Smith
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
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.
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.
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.29 2008/10/03 09:25:18 swildner Exp $
33 #ifndef VGA_NO_MODE_CHANGE
35 #include <sys/param.h>
36 #include <sys/systm.h>
37 #include <sys/kernel.h>
38 #include <sys/module.h>
39 #include <sys/malloc.h>
41 #include <sys/thread2.h>
44 #include <vm/vm_extern.h>
45 #include <vm/vm_kern.h>
48 #include <machine/md_var.h>
49 #include <machine/vm86.h>
50 #include <machine/pc/bios.h>
51 #include <machine/pc/vesa.h>
53 #include <dev/video/fb/fbreg.h>
54 #include <dev/video/fb/vgareg.h>
56 #include <bus/isa/isa.h>
58 #define VESA_VIA_CLE266 "VIA CLE266\r\n"
64 /* VESA video adapter state buffer stub */
67 #define V_STATE_SIG 0x61736576
70 typedef struct adp_state adp_state_t;
72 /* VESA video adapter */
73 static video_adapter_t *vesa_adp = NULL;
74 static int vesa_state_buf_size = 0;
75 #define VESA_VM86_BUFSIZE (3 * PAGE_SIZE)
76 static void *vesa_vm86_buf;
80 static int vesa_nop(void);
82 static int vesa_error(void);
83 static vi_probe_t vesa_probe;
84 static vi_init_t vesa_init;
85 static vi_get_info_t vesa_get_info;
86 static vi_query_mode_t vesa_query_mode;
87 static vi_set_mode_t vesa_set_mode;
88 static vi_save_font_t vesa_save_font;
89 static vi_load_font_t vesa_load_font;
90 static vi_show_font_t vesa_show_font;
91 static vi_save_palette_t vesa_save_palette;
92 static vi_load_palette_t vesa_load_palette;
93 static vi_set_border_t vesa_set_border;
94 static vi_save_state_t vesa_save_state;
95 static vi_load_state_t vesa_load_state;
96 static vi_set_win_org_t vesa_set_origin;
97 static vi_read_hw_cursor_t vesa_read_hw_cursor;
98 static vi_set_hw_cursor_t vesa_set_hw_cursor;
99 static vi_set_hw_cursor_shape_t vesa_set_hw_cursor_shape;
100 static vi_blank_display_t vesa_blank_display;
101 static vi_mmap_t vesa_mmap;
102 static vi_ioctl_t vesa_ioctl;
103 static vi_clear_t vesa_clear;
104 static vi_fill_rect_t vesa_fill_rect;
105 static vi_bitblt_t vesa_bitblt;
106 static vi_diag_t vesa_diag;
107 static int vesa_bios_info(int level);
108 static struct vm86context vesa_vmcontext;
110 static video_switch_t vesavidsw = {
127 vesa_set_hw_cursor_shape,
139 static video_switch_t *prevvidsw;
141 /* VESA BIOS video modes */
145 #define MODE_TABLE_DELTA 8
147 static int vesa_vmode_max = 0;
148 static video_info_t vesa_vmode_empty = { EOT };
149 static video_info_t *vesa_vmode = &vesa_vmode_empty;
151 static int vesa_init_done = FALSE;
152 static int has_vesa_bios = FALSE;
153 static int dpms_states;
154 static struct vesa_info *vesa_adp_info = NULL;
155 static uint16_t *vesa_vmodetab = NULL;
156 static char *vesa_oemstr = NULL;
157 static char *vesa_vendorstr = NULL;
158 static char *vesa_prodstr = NULL;
159 static char *vesa_revstr = NULL;
161 /* local macros and functions */
162 #define BIOS_SADDRTOLADDR(p) ((((p) & 0xffff0000) >> 12) + ((p) & 0x0000ffff))
164 static int int10_set_mode(int mode);
165 static int vesa_bios_get_mode(int mode, struct vesa_mode *vmode);
166 static int vesa_bios_set_mode(int mode);
167 static int vesa_bios_get_dac(void);
168 static int vesa_bios_set_dac(int bits);
169 static int vesa_bios_save_palette(int start, int colors, u_char *palette,
171 static int vesa_bios_save_palette2(int start, int colors, u_char *r, u_char *g,
172 u_char *b, int bits);
173 static int vesa_bios_load_palette(int start, int colors, const u_char *palette,
176 static int vesa_bios_load_palette2(int start, int colors, u_char *r, u_char *g,
177 u_char *b, int bits);
182 #define STATE_HW (1<<0)
183 #define STATE_DATA (1<<1)
184 #define STATE_DAC (1<<2)
185 #define STATE_REG (1<<3)
186 #define STATE_MOST (STATE_HW | STATE_DATA | STATE_REG)
187 #define STATE_ALL (STATE_HW | STATE_DATA | STATE_DAC | STATE_REG)
188 static int vesa_bios_state_buf_size(void);
189 static int vesa_bios_save_restore(int code, void *p, size_t size);
190 static int vesa_bios_get_line_length(void);
191 static int vesa_bios_set_line_length(int pixel, int *bytes, int *lines);
193 static int vesa_bios_get_start(int *x, int *y);
195 static int vesa_bios_set_start(int x, int y);
196 static int vesa_translate_flags(uint16_t vflags);
197 static int vesa_translate_mmodel(uint8_t vmodel);
198 static void *vesa_fix_ptr(uint32_t p, uint16_t seg, uint16_t off,
200 static int vesa_bios_init(void);
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 static int vesa_probe_dpms(void);
206 static int vesa_get_origin(video_adapter_t *adp, off_t *offset);
210 dump_buffer(u_char *buf, size_t len)
214 for (i = 0; i < len;) {
215 kprintf("%02x ", buf[i]);
221 /* INT 10 BIOS calls */
223 int10_set_mode(int mode)
225 struct vm86frame vmf;
227 bzero(&vmf, sizeof(vmf));
228 vmf.vmf_eax = 0x0000 | mode;
229 vm86_intcall(0x10, &vmf);
233 /* VESA BIOS calls */
235 vesa_bios_get_mode(int mode, struct vesa_mode *vmode)
237 struct vm86frame vmf;
241 bzero(&vmf, sizeof(vmf));
242 vmf.vmf_eax = 0x4f01;
245 vm86_getptr(&vesa_vmcontext, (vm_offset_t)buf, &vmf.vmf_es, &vmf.vmf_di);
247 err = vm86_datacall(0x10, &vmf, &vesa_vmcontext);
248 if ((err != 0) || (vmf.vmf_ax != 0x4f))
250 bcopy(buf, vmode, sizeof(*vmode));
255 vesa_bios_set_mode(int mode)
257 struct vm86frame vmf;
260 bzero(&vmf, sizeof(vmf));
261 vmf.vmf_eax = 0x4f02;
263 err = vm86_intcall(0x10, &vmf);
264 return ((err != 0) || (vmf.vmf_ax != 0x4f));
268 vesa_bios_get_dac(void)
270 struct vm86frame vmf;
273 bzero(&vmf, sizeof(vmf));
274 vmf.vmf_eax = 0x4f08;
275 vmf.vmf_ebx = 1; /* get DAC width */
276 err = vm86_intcall(0x10, &vmf);
277 if ((err != 0) || (vmf.vmf_ax != 0x4f))
279 return ((vmf.vmf_ebx >> 8) & 0x00ff);
283 vesa_bios_set_dac(int bits)
285 struct vm86frame vmf;
288 bzero(&vmf, sizeof(vmf));
289 vmf.vmf_eax = 0x4f08;
290 vmf.vmf_ebx = (bits << 8);
291 err = vm86_intcall(0x10, &vmf);
292 if ((err != 0) || (vmf.vmf_ax != 0x4f))
294 return ((vmf.vmf_ebx >> 8) & 0x00ff);
298 vesa_bios_save_palette(int start, int colors, u_char *palette, int bits)
300 struct vm86frame vmf;
305 bzero(&vmf, sizeof(vmf));
306 vmf.vmf_eax = 0x4f09;
307 vmf.vmf_ebx = 1; /* get primary palette data */
308 vmf.vmf_ecx = colors;
311 vm86_getptr(&vesa_vmcontext, (vm_offset_t)p, &vmf.vmf_es, &vmf.vmf_di);
313 err = vm86_datacall(0x10, &vmf, &vesa_vmcontext);
314 if ((err != 0) || (vmf.vmf_ax != 0x4f))
318 for (i = 0; i < colors; ++i) {
319 palette[i*3] = p[i*4 + 2] << bits;
320 palette[i*3 + 1] = p[i*4 + 1] << bits;
321 palette[i*3 + 2] = p[i*4] << bits;
327 vesa_bios_save_palette2(int start, int colors, u_char *r, u_char *g, u_char *b,
330 struct vm86frame vmf;
335 bzero(&vmf, sizeof(vmf));
336 vmf.vmf_eax = 0x4f09;
337 vmf.vmf_ebx = 1; /* get primary palette data */
338 vmf.vmf_ecx = colors;
341 vm86_getptr(&vesa_vmcontext, (vm_offset_t)p, &vmf.vmf_es, &vmf.vmf_di);
343 err = vm86_datacall(0x10, &vmf, &vesa_vmcontext);
344 if ((err != 0) || (vmf.vmf_ax != 0x4f))
348 for (i = 0; i < colors; ++i) {
349 r[i] = p[i*4 + 2] << bits;
350 g[i] = p[i*4 + 1] << bits;
351 b[i] = p[i*4] << bits;
357 vesa_bios_load_palette(int start, int colors, const u_char *palette, int bits)
359 struct vm86frame vmf;
366 for (i = 0; i < colors; ++i) {
367 p[i*4] = palette[i*3 + 2] >> bits;
368 p[i*4 + 1] = palette[i*3 + 1] >> bits;
369 p[i*4 + 2] = palette[i*3] >> bits;
373 bzero(&vmf, sizeof(vmf));
374 vmf.vmf_eax = 0x4f09;
375 vmf.vmf_ebx = 0; /* set primary palette data */
376 vmf.vmf_ecx = colors;
378 vm86_getptr(&vesa_vmcontext, (vm_offset_t)p, &vmf.vmf_es, &vmf.vmf_di);
380 err = vm86_datacall(0x10, &vmf, &vesa_vmcontext);
381 return ((err != 0) || (vmf.vmf_ax != 0x4f));
386 vesa_bios_load_palette2(int start, int colors, u_char *r, u_char *g, u_char *b,
389 struct vm86frame vmf;
396 for (i = 0; i < colors; ++i) {
397 p[i*4] = b[i] >> bits;
398 p[i*4 + 1] = g[i] >> bits;
399 p[i*4 + 2] = r[i] >> bits;
403 bzero(&vmf, sizeof(vmf));
404 vmf.vmf_eax = 0x4f09;
405 vmf.vmf_ebx = 0; /* set primary palette data */
406 vmf.vmf_ecx = colors;
408 vm86_getptr(&vesa_vmcontext, (vm_offset_t)p, &vmf.vmf_es, &vmf.vmf_di);
410 err = vm86_datacall(0x10, &vmf, &vesa_vmcontext);
411 return ((err != 0) || (vmf.vmf_ax != 0x4f));
416 vesa_bios_state_buf_size(void)
418 struct vm86frame vmf;
421 bzero(&vmf, sizeof(vmf));
422 vmf.vmf_eax = 0x4f04;
423 vmf.vmf_ecx = STATE_ALL;
424 vmf.vmf_edx = STATE_SIZE;
425 err = vm86_intcall(0x10, &vmf);
426 if ((err != 0) || (vmf.vmf_ax != 0x4f))
428 return vmf.vmf_bx*64;
432 vesa_bios_save_restore(int code, void *p, size_t size)
434 struct vm86frame vmf;
438 if (size > VESA_VM86_BUFSIZE)
441 bzero(&vmf, sizeof(vmf));
442 vmf.vmf_eax = 0x4f04;
443 vmf.vmf_ecx = STATE_ALL;
444 vmf.vmf_edx = code; /* STATE_SAVE/STATE_LOAD */
446 vm86_getptr(&vesa_vmcontext, (vm_offset_t)buf, &vmf.vmf_es, &vmf.vmf_bx);
449 err = vm86_datacall(0x10, &vmf, &vesa_vmcontext);
451 return ((err != 0) || (vmf.vmf_ax != 0x4f));
455 vesa_bios_get_line_length(void)
457 struct vm86frame vmf;
460 bzero(&vmf, sizeof(vmf));
461 vmf.vmf_eax = 0x4f06;
462 vmf.vmf_ebx = 1; /* get scan line length */
463 err = vm86_intcall(0x10, &vmf);
464 if ((err != 0) || (vmf.vmf_ax != 0x4f))
466 return vmf.vmf_bx; /* line length in bytes */
470 vesa_bios_set_line_length(int pixel, int *bytes, int *lines)
472 struct vm86frame vmf;
475 bzero(&vmf, sizeof(vmf));
476 vmf.vmf_eax = 0x4f06;
477 vmf.vmf_ebx = 0; /* set scan line length in pixel */
479 err = vm86_intcall(0x10, &vmf);
481 kprintf("bx:%d, cx:%d, dx:%d\n", vmf.vmf_bx, vmf.vmf_cx, vmf.vmf_dx);
483 if ((err != 0) || (vmf.vmf_ax != 0x4f))
494 vesa_bios_get_start(int *x, int *y)
496 struct vm86frame vmf;
499 bzero(&vmf, sizeof(vmf));
500 vmf.vmf_eax = 0x4f07;
501 vmf.vmf_ebx = 1; /* get display start */
502 err = vm86_intcall(0x10, &vmf);
503 if ((err != 0) || (vmf.vmf_ax != 0x4f))
512 vesa_bios_set_start(int x, int y)
514 struct vm86frame vmf;
517 bzero(&vmf, sizeof(vmf));
518 vmf.vmf_eax = 0x4f07;
519 vmf.vmf_ebx = 0x80; /* set display start */
522 err = vm86_intcall(0x10, &vmf);
523 return ((err != 0) || (vmf.vmf_ax != 0x4f));
527 vesa_translate_flags(uint16_t vflags)
534 { V_MODECOLOR, V_INFO_COLOR, 0 },
535 { V_MODEGRAPHICS, V_INFO_GRAPHICS, 0 },
536 { V_MODELFB, V_INFO_LINEAR, 0 },
541 for (flags = 0, i = 0; i < sizeof(ftable)/sizeof(ftable[0]); ++i) {
542 flags |= (vflags & ftable[i].mask) ?
543 ftable[i].set : ftable[i].reset;
549 vesa_translate_mmodel(uint8_t vmodel)
555 { V_MMTEXT, V_INFO_MM_TEXT },
556 { V_MMCGA, V_INFO_MM_CGA },
557 { V_MMHGC, V_INFO_MM_HGC },
558 { V_MMEGA, V_INFO_MM_PLANAR },
559 { V_MMPACKED, V_INFO_MM_PACKED },
560 { V_MMDIRCOLOR, V_INFO_MM_DIRECT },
564 for (i = 0; mtable[i].mmodel >= 0; ++i) {
565 if (mtable[i].vmodel == vmodel)
566 return mtable[i].mmodel;
568 return V_INFO_MM_OTHER;
572 vesa_fix_ptr(uint32_t p, uint16_t seg, uint16_t off, u_char *buf)
576 if (((p >> 16) == seg) && ((p & 0xffff) >= off))
577 return (void *)(buf + ((p & 0xffff) - off));
579 p = BIOS_SADDRTOLADDR(p);
580 return (void *)BIOS_PADDRTOVADDR(p);
587 static u_char buf[512];
588 struct vm86frame vmf;
589 struct vesa_mode vmode;
600 has_vesa_bios = FALSE;
601 vesa_adp_info = NULL;
603 vesa_vmode[0].vi_mode = EOT;
605 /* Allocate a buffer and add each page to the vm86 context. */
606 vesa_vm86_buf = kmalloc(VESA_VM86_BUFSIZE, M_DEVBUF, M_WAITOK | M_ZERO);
607 KASSERT(((vm_offset_t)vesa_vm86_buf & PAGE_MASK) == 0,
608 ("bad vesa_vm86_buf alignment"));
609 for (i = 0; i < howmany(VESA_VM86_BUFSIZE, PAGE_SIZE); i++)
610 vm86_addpage(&vesa_vmcontext, i + 1,
611 (vm_offset_t)vesa_vm86_buf + PAGE_SIZE * i);
613 vmbuf = vesa_vm86_buf;
614 bzero(&vmf, sizeof(vmf)); /* paranoia */
615 bcopy("VBE2", vmbuf, 4); /* try for VBE2 data */
616 vmf.vmf_eax = 0x4f00;
617 vm86_getptr(&vesa_vmcontext, (vm_offset_t)vmbuf, &vmf.vmf_es, &vmf.vmf_di);
619 err = vm86_datacall(0x10, &vmf, &vesa_vmcontext);
620 if ((err != 0) || (vmf.vmf_ax != 0x4f) || bcmp("VESA", vmbuf, 4))
622 bcopy(vmbuf, buf, sizeof(buf));
623 vesa_adp_info = (struct vesa_info *)buf;
625 kprintf("VESA: information block\n");
626 dump_buffer(buf, 64);
628 if (vesa_adp_info->v_version < 0x0102) {
629 kprintf("VESA: VBE version %d.%d is not supported; "
630 "version 1.2 or later is required.\n",
631 bcd2bin((vesa_adp_info->v_version & 0xff00) >> 8),
632 bcd2bin(vesa_adp_info->v_version & 0x00ff));
636 /* fix string ptrs */
637 vesa_oemstr = (char *)vesa_fix_ptr(vesa_adp_info->v_oemstr,
638 vmf.vmf_es, vmf.vmf_di, buf);
639 is_via_cle266 = strcmp(vesa_oemstr, VESA_VIA_CLE266) == 0;
641 if (vesa_adp_info->v_version >= 0x0200) {
643 (char *)vesa_fix_ptr(vesa_adp_info->v_vendorstr,
644 vmf.vmf_es, vmf.vmf_di, buf);
646 (char *)vesa_fix_ptr(vesa_adp_info->v_prodstr,
647 vmf.vmf_es, vmf.vmf_di, buf);
649 (char *)vesa_fix_ptr(vesa_adp_info->v_revstr,
650 vmf.vmf_es, vmf.vmf_di, buf);
653 /* obtain video mode information */
654 vesa_vmodetab = (uint16_t *)vesa_fix_ptr(vesa_adp_info->v_modetable,
655 vmf.vmf_es, vmf.vmf_di, buf);
656 if (vesa_vmodetab == NULL)
658 for (i = 0, modes = 0;
659 (i < (M_VESA_MODE_MAX - M_VESA_BASE + 1))
660 && (vesa_vmodetab[i] != 0xffff); ++i) {
661 if (vesa_bios_get_mode(vesa_vmodetab[i], &vmode))
664 /* reject unsupported modes */
665 if ((vmode.v_modeattr & (V_MODESUPP | V_MODEOPTINFO)) !=
666 (V_MODESUPP | V_MODEOPTINFO)) {
668 kprintf("Rejecting VESA %s mode: %d x %d x %d bpp attr = 0x%x\n",
669 vmode.v_modeattr & V_MODEGRAPHICS ? "graphics" : "text",
670 vmode.v_width, vmode.v_height, vmode.v_bpp,
676 /* expand the array if necessary */
677 if (modes >= vesa_vmode_max) {
678 vesa_vmode_max += MODE_TABLE_DELTA;
679 p = kmalloc(sizeof(*vesa_vmode)*(vesa_vmode_max + 1),
682 kprintf("vesa_bios_init(): modes:%d, vesa_mode_max:%d\n",
683 modes, vesa_vmode_max);
686 bcopy(vesa_vmode, p, sizeof(*vesa_vmode)*modes);
687 kfree(vesa_vmode, M_DEVBUF);
693 kprintf("Found VESA %s mode: %d x %d x %d bpp\n",
694 vmode.v_modeattr & V_MODEGRAPHICS ? "graphics" : "text",
695 vmode.v_width, vmode.v_height, vmode.v_bpp);
698 if ((vmode.v_width & 0xff00) >> 8 == vmode.v_height - 1) {
699 vmode.v_width &= 0xff;
700 vmode.v_waseg = 0xb8000 >> 4;
704 /* copy some fields */
705 bzero(&vesa_vmode[modes], sizeof(vesa_vmode[modes]));
706 vesa_vmode[modes].vi_mode = vesa_vmodetab[i];
707 vesa_vmode[modes].vi_width = vmode.v_width;
708 vesa_vmode[modes].vi_height = vmode.v_height;
709 vesa_vmode[modes].vi_depth = vmode.v_bpp;
710 vesa_vmode[modes].vi_planes = vmode.v_planes;
711 vesa_vmode[modes].vi_cwidth = vmode.v_cwidth;
712 vesa_vmode[modes].vi_cheight = vmode.v_cheight;
713 vesa_vmode[modes].vi_window = (u_int)vmode.v_waseg << 4;
715 vesa_vmode[modes].vi_window_size = vmode.v_wsize*1024;
716 vesa_vmode[modes].vi_window_gran = vmode.v_wgran*1024;
717 if (vmode.v_modeattr & V_MODELFB)
718 vesa_vmode[modes].vi_buffer = vmode.v_lfb;
720 vesa_vmode[modes].vi_buffer = 0;
722 vesa_vmode[modes].vi_buffer_size
723 = vesa_adp_info->v_memsize*64*1024;
725 if (vmode.v_offscreen > vmode.v_lfb)
726 vesa_vmode[modes].vi_buffer_size
727 = vmode.v_offscreen + vmode.v_offscreensize*1024
730 vesa_vmode[modes].vi_buffer_size
731 = vmode.v_offscreen + vmode.v_offscreensize*1024
733 vesa_vmode[modes].vi_mem_model
734 = vesa_translate_mmodel(vmode.v_memmodel);
735 vesa_vmode[modes].vi_pixel_fields[0] = 0;
736 vesa_vmode[modes].vi_pixel_fields[1] = 0;
737 vesa_vmode[modes].vi_pixel_fields[2] = 0;
738 vesa_vmode[modes].vi_pixel_fields[3] = 0;
739 vesa_vmode[modes].vi_pixel_fsizes[0] = 0;
740 vesa_vmode[modes].vi_pixel_fsizes[1] = 0;
741 vesa_vmode[modes].vi_pixel_fsizes[2] = 0;
742 vesa_vmode[modes].vi_pixel_fsizes[3] = 0;
743 if (vesa_vmode[modes].vi_mem_model == V_INFO_MM_PACKED) {
744 vesa_vmode[modes].vi_pixel_size = (vmode.v_bpp + 7)/8;
745 } else if (vesa_vmode[modes].vi_mem_model == V_INFO_MM_DIRECT) {
746 vesa_vmode[modes].vi_pixel_size = (vmode.v_bpp + 7)/8;
747 vesa_vmode[modes].vi_pixel_fields[0]
748 = vmode.v_redfieldpos;
749 vesa_vmode[modes].vi_pixel_fields[1]
750 = vmode.v_greenfieldpos;
751 vesa_vmode[modes].vi_pixel_fields[2]
752 = vmode.v_bluefieldpos;
753 vesa_vmode[modes].vi_pixel_fields[3]
754 = vmode.v_resfieldpos;
755 vesa_vmode[modes].vi_pixel_fsizes[0]
756 = vmode.v_redmasksize;
757 vesa_vmode[modes].vi_pixel_fsizes[1]
758 = vmode.v_greenmasksize;
759 vesa_vmode[modes].vi_pixel_fsizes[2]
760 = vmode.v_bluemasksize;
761 vesa_vmode[modes].vi_pixel_fsizes[3]
762 = vmode.v_resmasksize;
764 vesa_vmode[modes].vi_pixel_size = 0;
767 vesa_vmode[modes].vi_flags
768 = vesa_translate_flags(vmode.v_modeattr) | V_INFO_VESA;
771 vesa_vmode[modes].vi_mode = EOT;
773 kprintf("VESA: %d mode(s) found\n", modes);
775 has_vesa_bios = (modes > 0);
779 dpms_states = vesa_probe_dpms();
780 if (dpms_states != 0 && bootverbose)
781 kprintf("VESA: DPMS support (states:0x%x)\n", dpms_states);
787 vesa_map_buffer(u_int paddr, size_t size)
792 off = paddr - trunc_page(paddr);
793 vaddr = (vm_offset_t)pmap_mapdev(paddr - off, size + off);
795 kprintf("vesa_map_buffer: paddr:0x%x vaddr:0x%x size:0x%x off:0x%x\n",
796 paddr, vaddr, size, off);
798 return (vaddr + off);
802 vesa_unmap_buffer(vm_offset_t vaddr, size_t size)
805 kprintf("vesa_unmap_buffer: vaddr:0x%x size:0x%x\n", vaddr, size);
807 pmap_unmapdev(vaddr, size);
813 * Probe DPMS support and return the supported states.
817 vesa_probe_dpms(void)
819 struct vm86frame vmf;
822 bzero(&vmf, sizeof(vmf));
823 vmf.vmf_eax = 0x4f10;
825 err = vm86_intcall(0x10, &vmf);
826 if ((err != 0) || (vmf.vmf_ax != 0x4f))
827 return -1; /* no support */
829 return (vmf.vmf_ebx >> 8);
835 vesa_configure(int flags)
837 video_adapter_t *adp;
842 if (flags & VIO_PROBE_ONLY)
846 * If the VESA module has already been loaded, abort loading
847 * the module this time.
849 for (i = 0; (adp = vid_get_adapter(i)) != NULL; ++i) {
850 if (adp->va_flags & V_ADP_VESA)
852 if (adp->va_type == KD_VGA)
856 * The VGA adapter is not found. This is because either
857 * 1) the VGA driver has not been initialized, or 2) the VGA card
858 * is not present. If 1) is the case, we shall defer
859 * initialization for now and try again later.
862 vga_sub_configure = vesa_configure;
868 if (vesa_bios_init()) {
872 vesa_adp->va_flags |= V_ADP_VESA | V_ADP_COLOR;
874 prevvidsw = vidsw[vesa_adp->va_index];
875 vidsw[vesa_adp->va_index] = &vesavidsw;
876 vesa_init_done = TRUE;
895 vesa_probe(int unit, video_adapter_t **adpp, void *arg, int flags)
897 return (*prevvidsw->probe)(unit, adpp, arg, flags);
901 vesa_init(int unit, video_adapter_t *adp, int flags)
903 return (*prevvidsw->init)(unit, adp, flags);
907 vesa_get_info(video_adapter_t *adp, int mode, video_info_t *info)
911 if ((*prevvidsw->get_info)(adp, mode, info) == 0)
917 for (i = 0; vesa_vmode[i].vi_mode != EOT; ++i) {
918 if (vesa_vmode[i].vi_mode == NA)
920 if (vesa_vmode[i].vi_mode == mode) {
921 *info = vesa_vmode[i];
929 vesa_query_mode(video_adapter_t *adp, video_info_t *info)
933 if ((*prevvidsw->query_mode)(adp, info) == 0)
938 for (i = 0; vesa_vmode[i].vi_mode != EOT; ++i) {
939 if ((info->vi_width != 0)
940 && (info->vi_width != vesa_vmode[i].vi_width))
942 if ((info->vi_height != 0)
943 && (info->vi_height != vesa_vmode[i].vi_height))
945 if ((info->vi_cwidth != 0)
946 && (info->vi_cwidth != vesa_vmode[i].vi_cwidth))
948 if ((info->vi_cheight != 0)
949 && (info->vi_cheight != vesa_vmode[i].vi_cheight))
951 if ((info->vi_depth != 0)
952 && (info->vi_depth != vesa_vmode[i].vi_depth))
954 if ((info->vi_planes != 0)
955 && (info->vi_planes != vesa_vmode[i].vi_planes))
957 /* pixel format, memory model */
958 if ((info->vi_flags != 0)
959 && (info->vi_flags != vesa_vmode[i].vi_flags))
961 *info = vesa_vmode[i];
968 vesa_set_mode(video_adapter_t *adp, int mode)
974 return (*prevvidsw->set_mode)(adp, mode);
977 kprintf("VESA: set_mode(): %d(0x%x) -> %d(0x%x)\n",
978 adp->va_mode, adp->va_mode, mode, mode);
981 * If the current mode is a VESA mode and the new mode is not,
982 * restore the state of the adapter first by setting one of the
983 * standard VGA mode, so that non-standard, extended SVGA registers
984 * are set to the state compatible with the standard VGA modes.
985 * Otherwise (*prevvidsw->set_mode)() may not be able to set up
986 * the new mode correctly.
988 if (VESA_MODE(adp->va_mode)) {
989 if ((*prevvidsw->get_info)(adp, mode, &info) == 0) {
990 int10_set_mode(adp->va_initial_bios_mode);
991 if (adp->va_info.vi_flags & V_INFO_LINEAR)
992 vesa_unmap_buffer(adp->va_buffer,
993 vesa_adp_info->v_memsize*64*1024);
995 * Once (*prevvidsw->get_info)() succeeded,
996 * (*prevvidsw->set_mode)() below won't fail...
1001 /* we may not need to handle this mode after all... */
1002 if ((*prevvidsw->set_mode)(adp, mode) == 0)
1005 /* is the new mode supported? */
1006 if (vesa_get_info(adp, mode, &info))
1008 /* assert(VESA_MODE(mode)); */
1011 kprintf("VESA: about to set a VESA mode...\n");
1013 /* don't use the linear frame buffer for text modes. XXX */
1014 if (!(info.vi_flags & V_INFO_GRAPHICS))
1015 info.vi_flags &= ~V_INFO_LINEAR;
1017 if (vesa_bios_set_mode(mode | ((info.vi_flags & V_INFO_LINEAR) ? 0x4000 : 0)))
1020 if (adp->va_info.vi_flags & V_INFO_LINEAR)
1021 vesa_unmap_buffer(adp->va_buffer,
1022 vesa_adp_info->v_memsize*64*1024);
1025 kprintf("VESA: mode set!\n");
1027 vesa_adp->va_mode = mode;
1028 if (info.vi_flags & V_INFO_LINEAR) {
1030 kprintf("VESA: setting up LFB\n");
1032 vesa_adp->va_buffer =
1033 vesa_map_buffer(info.vi_buffer,
1034 vesa_adp_info->v_memsize*64*1024);
1035 vesa_adp->va_buffer_size = info.vi_buffer_size;
1036 vesa_adp->va_window = vesa_adp->va_buffer;
1037 vesa_adp->va_window_size = info.vi_buffer_size/info.vi_planes;
1038 vesa_adp->va_window_gran = info.vi_buffer_size/info.vi_planes;
1040 vesa_adp->va_buffer = 0;
1041 vesa_adp->va_buffer_size = info.vi_buffer_size;
1042 vesa_adp->va_window = BIOS_PADDRTOVADDR(info.vi_window);
1043 vesa_adp->va_window_size = info.vi_window_size;
1044 vesa_adp->va_window_gran = info.vi_window_gran;
1046 vesa_adp->va_window_orig = 0;
1047 len = vesa_bios_get_line_length();
1049 vesa_adp->va_line_width = len;
1050 } else if (info.vi_flags & V_INFO_GRAPHICS) {
1051 switch (info.vi_depth/info.vi_planes) {
1053 vesa_adp->va_line_width = info.vi_width/8;
1056 vesa_adp->va_line_width = info.vi_width/4;
1059 vesa_adp->va_line_width = info.vi_width/2;
1062 default: /* shouldn't happen */
1063 vesa_adp->va_line_width = info.vi_width;
1067 vesa_adp->va_line_width = info.vi_width*2;
1071 vesa_adp->va_line_width = info.vi_width*4;
1075 vesa_adp->va_line_width = info.vi_width;
1077 vesa_adp->va_disp_start.x = 0;
1078 vesa_adp->va_disp_start.y = 0;
1080 kprintf("vesa_set_mode(): vi_width:%d, len:%d, line_width:%d\n",
1081 info.vi_width, len, vesa_adp->va_line_width);
1083 bcopy(&info, &vesa_adp->va_info, sizeof(vesa_adp->va_info));
1085 /* move hardware cursor out of the way */
1086 (*vidsw[vesa_adp->va_index]->set_hw_cursor)(vesa_adp, -1, -1);
1092 vesa_save_font(video_adapter_t *adp, int page, int fontsize, u_char *data,
1095 return (*prevvidsw->save_font)(adp, page, fontsize, data, ch, count);
1099 vesa_load_font(video_adapter_t *adp, int page, int fontsize, u_char *data,
1102 return (*prevvidsw->load_font)(adp, page, fontsize, data, ch, count);
1106 vesa_show_font(video_adapter_t *adp, int page)
1108 return (*prevvidsw->show_font)(adp, page);
1112 vesa_save_palette(video_adapter_t *adp, u_char *palette)
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);
1127 return (*prevvidsw->save_palette)(adp, palette);
1131 vesa_load_palette(video_adapter_t *adp, const u_char *palette)
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);
1142 if (vesa_bios_set_dac(6) != 6)
1147 return (*prevvidsw->load_palette)(adp, palette);
1151 vesa_set_border(video_adapter_t *adp, int color)
1153 return (*prevvidsw->set_border)(adp, color);
1157 vesa_save_state(video_adapter_t *adp, void *p, size_t size)
1159 if (adp != vesa_adp)
1160 return (*prevvidsw->save_state)(adp, p, size);
1162 if (vesa_state_buf_size == 0)
1163 vesa_state_buf_size = vesa_bios_state_buf_size();
1165 return (sizeof(int) + vesa_state_buf_size);
1166 else if (size < (sizeof(int) + vesa_state_buf_size))
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);
1176 vesa_load_state(video_adapter_t *adp, void *p)
1178 if ((adp != vesa_adp) || (((adp_state_t *)p)->sig != V_STATE_SIG))
1179 return (*prevvidsw->load_state)(adp, p);
1181 return vesa_bios_save_restore(STATE_LOAD, ((adp_state_t *)p)->regs,
1182 vesa_state_buf_size);
1187 vesa_get_origin(video_adapter_t *adp, off_t *offset)
1189 struct vm86frame vmf;
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))
1198 *offset = vmf.vmf_dx*adp->va_window_gran;
1204 vesa_set_origin(video_adapter_t *adp, off_t offset)
1206 struct vm86frame vmf;
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
1215 if (adp != vesa_adp)
1216 return (*prevvidsw->set_win_org)(adp, offset);
1218 /* if this is a linear frame buffer, do nothing */
1219 if (adp->va_info.vi_flags & V_INFO_LINEAR)
1222 if (adp->va_window_gran == 0)
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))
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;
1242 vesa_read_hw_cursor(video_adapter_t *adp, int *col, int *row)
1244 return (*prevvidsw->read_hw_cursor)(adp, col, row);
1248 vesa_set_hw_cursor(video_adapter_t *adp, int col, int row)
1250 return (*prevvidsw->set_hw_cursor)(adp, col, row);
1254 vesa_set_hw_cursor_shape(video_adapter_t *adp, int base, int height,
1255 int celsize, int blink)
1257 return (*prevvidsw->set_hw_cursor_shape)(adp, base, height, celsize,
1262 * vesa_blank_display
1264 * Use DPMS if it is supported by the adapter and supports the requested
1265 * state, else use the traditional VGA method. When unblanking, use both
1266 * methods because either might have put us into the blanked state previously.
1270 vesa_blank_display(video_adapter_t *adp, int mode)
1272 struct vm86frame vmf;
1275 if (mode == V_DISPLAY_ON) {
1276 err = (*prevvidsw->blank_display)(adp, V_DISPLAY_ON);
1277 if (dpms_states == 0) {
1280 bzero(&vmf, sizeof(vmf));
1281 vmf.vmf_eax = 0x4f10;
1283 err = vm86_intcall(0x10, &vmf);
1284 return ((err != 0) || (vmf.vmf_ax != 0x4f));
1286 } else if (dpms_states & mode) {
1287 bzero(&vmf, sizeof(vmf));
1288 vmf.vmf_eax = 0x4f10;
1289 vmf.vmf_ebx = (mode << 8) | 1;
1290 err = vm86_intcall(0x10, &vmf);
1291 return ((err != 0) || (vmf.vmf_ax != 0x4f));
1294 return (*prevvidsw->blank_display)(adp, mode);
1298 vesa_mmap(video_adapter_t *adp, vm_offset_t offset, int prot)
1301 kprintf("vesa_mmap(): window:0x%x, buffer:0x%x, offset:0x%x\n",
1302 adp->va_info.vi_window, adp->va_info.vi_buffer, offset);
1305 if ((adp == vesa_adp) && (adp->va_info.vi_flags & V_INFO_LINEAR)) {
1306 /* va_window_size == va_buffer_size/vi_planes */
1307 /* XXX: is this correct? */
1308 if (offset > adp->va_window_size - PAGE_SIZE)
1311 return i386_btop(adp->va_info.vi_buffer + offset);
1314 return (*prevvidsw->mmap)(adp, offset, prot);
1319 vesa_clear(video_adapter_t *adp)
1321 return (*prevvidsw->clear)(adp);
1325 vesa_fill_rect(video_adapter_t *adp, int val, int x, int y, int cx, int cy)
1327 return (*prevvidsw->fill_rect)(adp, val, x, y, cx, cy);
1331 vesa_bitblt(video_adapter_t *adp,...)
1338 get_palette(video_adapter_t *adp, int base, int count,
1339 u_char *red, u_char *green, u_char *blue, u_char *trans)
1347 if ((base < 0) || (base >= 256) || (count < 0) || (count > 256))
1349 if ((base + count) > 256)
1351 if (!(vesa_adp_info->v_flags & V_DAC8) || !VESA_MODE(adp->va_mode))
1354 bits = vesa_bios_get_dac();
1358 r = kmalloc(count*3, M_DEVBUF, M_WAITOK);
1361 error = vesa_bios_save_palette2(base, count, r, g, b, bits);
1363 copyout(r, red, count);
1364 copyout(g, green, count);
1365 copyout(b, blue, count);
1366 if (trans != NULL) {
1368 copyout(r, trans, count);
1373 /* if error && bits != 6 at this point, we are in in trouble... XXX */
1378 set_palette(video_adapter_t *adp, int base, int count,
1379 u_char *red, u_char *green, u_char *blue, u_char *trans)
1389 if ((base < 0) || (base >= 256) || (base + count > 256))
1391 if (!(vesa_adp_info->v_flags & V_DAC8) || !VESA_MODE(adp->va_mode)
1392 || ((bits = vesa_bios_set_dac(8)) <= 6))
1395 r = kmalloc(count*3, M_DEVBUF, M_WAITOK);
1398 copyin(red, r, count);
1399 copyin(green, g, count);
1400 copyin(blue, b, count);
1402 error = vesa_bios_load_palette2(base, count, r, g, b, bits);
1407 /* if the following call fails, we are in trouble... XXX */
1408 vesa_bios_set_dac(6);
1414 vesa_ioctl(video_adapter_t *adp, u_long cmd, caddr_t arg)
1418 if (adp != vesa_adp)
1419 return (*prevvidsw->ioctl)(adp, cmd, arg);
1422 case FBIO_SETWINORG: /* set frame buffer window origin */
1423 if (!VESA_MODE(adp->va_mode))
1424 return (*prevvidsw->ioctl)(adp, cmd, arg);
1425 return (vesa_set_origin(adp, *(off_t *)arg) ? ENODEV : 0);
1427 case FBIO_SETDISPSTART: /* set display start address */
1428 if (!VESA_MODE(adp->va_mode))
1429 return (*prevvidsw->ioctl)(adp, cmd, arg);
1430 if (vesa_bios_set_start(((video_display_start_t *)arg)->x,
1431 ((video_display_start_t *)arg)->y))
1433 adp->va_disp_start.x = ((video_display_start_t *)arg)->x;
1434 adp->va_disp_start.y = ((video_display_start_t *)arg)->y;
1437 case FBIO_SETLINEWIDTH: /* set line length in pixel */
1438 if (!VESA_MODE(adp->va_mode))
1439 return (*prevvidsw->ioctl)(adp, cmd, arg);
1440 if (vesa_bios_set_line_length(*(u_int *)arg, &bytes, NULL))
1442 adp->va_line_width = bytes;
1444 kprintf("new line width:%d\n", adp->va_line_width);
1448 case FBIO_GETPALETTE: /* get color palette */
1449 if (get_palette(adp, ((video_color_palette_t *)arg)->index,
1450 ((video_color_palette_t *)arg)->count,
1451 ((video_color_palette_t *)arg)->red,
1452 ((video_color_palette_t *)arg)->green,
1453 ((video_color_palette_t *)arg)->blue,
1454 ((video_color_palette_t *)arg)->transparent))
1455 return (*prevvidsw->ioctl)(adp, cmd, arg);
1459 case FBIO_SETPALETTE: /* set color palette */
1460 if (set_palette(adp, ((video_color_palette_t *)arg)->index,
1461 ((video_color_palette_t *)arg)->count,
1462 ((video_color_palette_t *)arg)->red,
1463 ((video_color_palette_t *)arg)->green,
1464 ((video_color_palette_t *)arg)->blue,
1465 ((video_color_palette_t *)arg)->transparent))
1466 return (*prevvidsw->ioctl)(adp, cmd, arg);
1469 case FBIOGETCMAP: /* get color palette */
1470 if (get_palette(adp, ((struct fbcmap *)arg)->index,
1471 ((struct fbcmap *)arg)->count,
1472 ((struct fbcmap *)arg)->red,
1473 ((struct fbcmap *)arg)->green,
1474 ((struct fbcmap *)arg)->blue, NULL))
1475 return (*prevvidsw->ioctl)(adp, cmd, arg);
1478 case FBIOPUTCMAP: /* set color palette */
1479 if (set_palette(adp, ((struct fbcmap *)arg)->index,
1480 ((struct fbcmap *)arg)->count,
1481 ((struct fbcmap *)arg)->red,
1482 ((struct fbcmap *)arg)->green,
1483 ((struct fbcmap *)arg)->blue, NULL))
1484 return (*prevvidsw->ioctl)(adp, cmd, arg);
1488 return (*prevvidsw->ioctl)(adp, cmd, arg);
1493 vesa_diag(video_adapter_t *adp, int level)
1497 /* call the previous handler first */
1498 error = (*prevvidsw->diag)(adp, level);
1502 if (adp != vesa_adp)
1512 vesa_bios_info(int level)
1515 struct vesa_mode vmode;
1520 /* general adapter information */
1521 kprintf("VESA: v%d.%d, %dk memory, flags:0x%x, mode table:%p (0x%x)\n",
1522 bcd2bin((vesa_adp_info->v_version & 0xff00) >> 8),
1523 bcd2bin(vesa_adp_info->v_version & 0x00ff),
1524 vesa_adp_info->v_memsize * 64, vesa_adp_info->v_flags,
1525 vesa_vmodetab, vesa_adp_info->v_modetable);
1528 if (vesa_oemstr != NULL)
1529 kprintf("VESA: %s\n", vesa_oemstr);
1535 if (vesa_adp_info->v_version >= 0x0200 && bootverbose) {
1536 /* vendor name, product name, product revision */
1537 kprintf("VESA: %s %s %s\n",
1538 (vesa_vendorstr != NULL) ? vesa_vendorstr : "unknown",
1539 (vesa_prodstr != NULL) ? vesa_prodstr : "unknown",
1540 (vesa_revstr != NULL) ? vesa_revstr : "?");
1544 /* mode information */
1546 (i < (M_VESA_MODE_MAX - M_VESA_BASE + 1))
1547 && (vesa_vmodetab[i] != 0xffff); ++i) {
1548 if (vesa_bios_get_mode(vesa_vmodetab[i], &vmode))
1551 /* print something for diagnostic purpose */
1552 kprintf("VESA: mode:0x%03x, flags:0x%04x",
1553 vesa_vmodetab[i], vmode.v_modeattr);
1554 if (vmode.v_modeattr & V_MODEOPTINFO) {
1555 if (vmode.v_modeattr & V_MODEGRAPHICS) {
1556 kprintf(", G %dx%dx%d %d, ",
1557 vmode.v_width, vmode.v_height,
1558 vmode.v_bpp, vmode.v_planes);
1560 kprintf(", T %dx%d, ",
1561 vmode.v_width, vmode.v_height);
1563 kprintf("font:%dx%d, ",
1564 vmode.v_cwidth, vmode.v_cheight);
1565 kprintf("pages:%d, mem:%d",
1566 vmode.v_ipages + 1, vmode.v_memmodel);
1568 if (vmode.v_modeattr & V_MODELFB) {
1569 kprintf("\nVESA: LFB:0x%x, off:0x%x, off_size:0x%x",
1570 vmode.v_lfb, vmode.v_offscreen,
1571 vmode.v_offscreensize*1024);
1574 kprintf("VESA: window A:0x%x (0x%x), window B:0x%x (0x%x), ",
1575 vmode.v_waseg, vmode.v_waattr,
1576 vmode.v_wbseg, vmode.v_wbattr);
1577 kprintf("size:%dk, gran:%dk\n",
1578 vmode.v_wsize, vmode.v_wgran);
1580 #endif /* VESA_DEBUG > 1 */
1585 /* module loading */
1595 /* locate a VGA adapter */
1598 error = vesa_configure(0);
1602 vesa_bios_info(bootverbose);
1610 u_char palette[256*3];
1613 /* if the adapter is currently in a VESA mode, don't unload */
1614 if ((vesa_adp != NULL) && VESA_MODE(vesa_adp->va_mode))
1617 * FIXME: if there is at least one vty which is in a VESA mode,
1618 * we shouldn't be unloading! XXX
1622 if (vesa_adp != NULL) {
1623 if (vesa_adp_info->v_flags & V_DAC8) {
1624 bits = vesa_bios_get_dac();
1626 vesa_bios_save_palette(0, 256, palette, bits);
1627 vesa_bios_set_dac(6);
1628 vesa_bios_load_palette(0, 256, palette, 6);
1631 vesa_adp->va_flags &= ~V_ADP_VESA;
1632 vidsw[vesa_adp->va_index] = prevvidsw;
1636 if (vesa_vm86_buf != NULL)
1637 kfree(vesa_vm86_buf, M_DEVBUF);
1643 vesa_mod_event(module_t mod, int type, void *data)
1649 return vesa_unload();
1656 static moduledata_t vesa_mod = {
1662 DECLARE_MODULE(vesa, vesa_mod, SI_SUB_DRIVERS, SI_ORDER_MIDDLE);
1664 #endif /* VGA_NO_MODE_CHANGE */