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.
27 #include <sys/cdefs.h>
28 __FBSDID("$FreeBSD$");
33 #ifndef VGA_NO_MODE_CHANGE
35 #include <sys/param.h>
37 #include <sys/systm.h>
38 #include <sys/kernel.h>
39 #include <sys/module.h>
40 #include <sys/malloc.h>
44 #include <vm/vm_extern.h>
45 #include <vm/vm_kern.h>
46 #include <vm/vm_param.h>
49 #include <machine/pc/bios.h>
50 #include <dev/fb/vesa.h>
52 #include <dev/fb/fbreg.h>
53 #include <dev/fb/vgareg.h>
55 #include <dev/pci/pcivar.h>
57 #include <isa/isareg.h>
59 #include <compat/x86bios/x86bios.h>
61 #define VESA_VIA_CLE266 "VIA CLE266\r\n"
67 /* VESA video adapter state buffer stub */
70 #define V_STATE_SIG 0x61736576
73 typedef struct adp_state adp_state_t;
75 /* VESA video adapter */
76 static video_adapter_t *vesa_adp = NULL;
77 static ssize_t vesa_state_buf_size = -1;
81 static int vesa_nop(void);
83 static int vesa_error(void);
84 static vi_probe_t vesa_probe;
85 static vi_init_t vesa_init;
86 static vi_get_info_t vesa_get_info;
87 static vi_query_mode_t vesa_query_mode;
88 static vi_set_mode_t vesa_set_mode;
89 static vi_save_font_t vesa_save_font;
90 static vi_load_font_t vesa_load_font;
91 static vi_show_font_t vesa_show_font;
92 static vi_save_palette_t vesa_save_palette;
93 static vi_load_palette_t vesa_load_palette;
94 static vi_set_border_t vesa_set_border;
95 static vi_save_state_t vesa_save_state;
96 static vi_load_state_t vesa_load_state;
97 static vi_set_win_org_t vesa_set_origin;
98 static vi_read_hw_cursor_t vesa_read_hw_cursor;
99 static vi_set_hw_cursor_t vesa_set_hw_cursor;
100 static vi_set_hw_cursor_shape_t vesa_set_hw_cursor_shape;
101 static vi_blank_display_t vesa_blank_display;
102 static vi_mmap_t vesa_mmap;
103 static vi_ioctl_t vesa_ioctl;
104 static vi_clear_t vesa_clear;
105 static vi_fill_rect_t vesa_fill_rect;
106 static vi_bitblt_t vesa_bitblt;
107 static vi_diag_t vesa_diag;
108 static int vesa_bios_info(int level);
110 static video_switch_t vesavidsw = {
127 vesa_set_hw_cursor_shape,
139 static video_switch_t *prevvidsw;
141 /* VESA BIOS video modes */
142 #define VESA_MAXMODES 64
146 #define MODE_TABLE_DELTA 8
148 static int vesa_vmode_max = 0;
149 static video_info_t vesa_vmode_empty = { EOT };
150 static video_info_t *vesa_vmode = &vesa_vmode_empty;
152 static int vesa_init_done = FALSE;
153 static int has_vesa_bios = FALSE;
154 static struct vesa_info *vesa_adp_info = NULL;
155 static u_int16_t *vesa_vmodetab = NULL;
156 static char *vesa_oemstr = NULL;
157 static char *vesa_venderstr = 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_post(void);
166 static int vesa_bios_get_mode(int mode, struct vesa_mode *vmode);
167 static int vesa_bios_set_mode(int mode);
169 static int vesa_bios_get_dac(void);
171 static int vesa_bios_set_dac(int bits);
172 static int vesa_bios_save_palette(int start, int colors, u_char *palette,
174 static int vesa_bios_save_palette2(int start, int colors, u_char *r, u_char *g,
175 u_char *b, int bits);
176 static int vesa_bios_load_palette(int start, int colors, u_char *palette,
178 static int vesa_bios_load_palette2(int start, int colors, u_char *r, u_char *g,
179 u_char *b, int bits);
183 #define STATE_HW (1<<0)
184 #define STATE_DATA (1<<1)
185 #define STATE_DAC (1<<2)
186 #define STATE_REG (1<<3)
187 #define STATE_MOST (STATE_HW | STATE_DATA | STATE_REG)
188 #define STATE_ALL (STATE_HW | STATE_DATA | STATE_DAC | STATE_REG)
189 static ssize_t vesa_bios_state_buf_size(void);
190 static int vesa_bios_save_restore(int code, void *p, size_t size);
192 static int vesa_bios_get_line_length(void);
194 static int vesa_bios_set_line_length(int pixel, int *bytes, int *lines);
196 static int vesa_bios_get_start(int *x, int *y);
198 static int vesa_bios_set_start(int x, int y);
199 static int vesa_map_gen_mode_num(int type, int color, int mode);
200 static int vesa_translate_flags(u_int16_t vflags);
201 static int vesa_translate_mmodel(u_int8_t vmodel);
202 static int vesa_bios_init(void);
203 static void vesa_clear_modes(video_info_t *info, int color);
206 static int vesa_get_origin(video_adapter_t *adp, off_t *offset);
209 /* INT 10 BIOS calls */
211 int10_set_mode(int mode)
215 x86bios_init_regs(®s);
218 x86bios_intr(®s, 0x10);
230 int count, i, is_pci;
232 if (x86bios_get_orm(0xc0000) == NULL)
238 /* Find the matching PCI video controller. */
239 dc = devclass_find("vgapci");
240 if (dc != NULL && devclass_get_devices(dc, &devs, &count) == 0) {
241 for (dev = NULL, i = 0; dev == NULL && i < count; devs++, i++)
242 if (device_get_flags(*devs) != 0 &&
243 x86bios_match_device(0xc0000, *devs)) {
251 /* Try VGA if a PCI device is not found. */
253 dc = devclass_find(VGA_DRIVER_NAME);
255 dev = devclass_get_device(dc, 0);
259 printf("%s: calling BIOS POST\n",
260 dev == NULL ? "VESA" : device_get_nameunit(dev));
262 x86bios_init_regs(®s);
264 regs.R_AH = pci_get_bus(dev);
265 regs.R_AL = (pci_get_slot(dev) << 3) |
266 (pci_get_function(dev) & 0x07);
269 x86bios_call(®s, 0xc000, 0x0003);
271 if (x86bios_get_intr(0x10) == 0)
277 /* VESA BIOS calls */
279 vesa_bios_get_mode(int mode, struct vesa_mode *vmode)
285 buf = x86bios_alloc(&offs, sizeof(*vmode));
289 x86bios_init_regs(®s);
293 regs.R_ES = X86BIOS_PHYSTOSEG(offs);
294 regs.R_DI = X86BIOS_PHYSTOOFF(offs);
296 x86bios_intr(®s, 0x10);
298 if (regs.R_AX != 0x004f) {
299 x86bios_free(buf, sizeof(*vmode));
303 bcopy(buf, vmode, sizeof(*vmode));
304 x86bios_free(buf, sizeof(*vmode));
310 vesa_bios_set_mode(int mode)
314 x86bios_init_regs(®s);
318 x86bios_intr(®s, 0x10);
320 return (regs.R_AX != 0x004f);
325 vesa_bios_get_dac(void)
329 x86bios_init_regs(®s);
333 x86bios_intr(®s, 0x10);
335 if (regs.R_AX != 0x004f)
343 vesa_bios_set_dac(int bits)
347 x86bios_init_regs(®s);
352 x86bios_intr(®s, 0x10);
354 if (regs.R_AX != 0x004f)
361 vesa_bios_save_palette(int start, int colors, u_char *palette, int bits)
368 p = (u_char *)x86bios_alloc(&offs, colors * 4);
372 x86bios_init_regs(®s);
378 regs.R_ES = X86BIOS_PHYSTOSEG(offs);
379 regs.R_DI = X86BIOS_PHYSTOOFF(offs);
381 x86bios_intr(®s, 0x10);
383 if (regs.R_AX != 0x004f) {
384 x86bios_free(p, colors * 4);
389 for (i = 0; i < colors; ++i) {
390 palette[i * 3] = p[i * 4 + 2] << bits;
391 palette[i * 3 + 1] = p[i * 4 + 1] << bits;
392 palette[i * 3 + 2] = p[i * 4] << bits;
394 x86bios_free(p, colors * 4);
400 vesa_bios_save_palette2(int start, int colors, u_char *r, u_char *g, u_char *b,
408 p = (u_char *)x86bios_alloc(&offs, colors * 4);
412 x86bios_init_regs(®s);
418 regs.R_ES = X86BIOS_PHYSTOSEG(offs);
419 regs.R_DI = X86BIOS_PHYSTOOFF(offs);
421 x86bios_intr(®s, 0x10);
423 if (regs.R_AX != 0x004f) {
424 x86bios_free(p, colors * 4);
429 for (i = 0; i < colors; ++i) {
430 r[i] = p[i * 4 + 2] << bits;
431 g[i] = p[i * 4 + 1] << bits;
432 b[i] = p[i * 4] << bits;
434 x86bios_free(p, colors * 4);
440 vesa_bios_load_palette(int start, int colors, u_char *palette, int bits)
447 p = (u_char *)x86bios_alloc(&offs, colors * 4);
451 x86bios_init_regs(®s);
457 regs.R_ES = X86BIOS_PHYSTOSEG(offs);
458 regs.R_DI = X86BIOS_PHYSTOOFF(offs);
461 for (i = 0; i < colors; ++i) {
462 p[i * 4] = palette[i * 3 + 2] >> bits;
463 p[i * 4 + 1] = palette[i * 3 + 1] >> bits;
464 p[i * 4 + 2] = palette[i * 3] >> bits;
467 x86bios_intr(®s, 0x10);
468 x86bios_free(p, colors * 4);
470 return (regs.R_AX != 0x004f);
474 vesa_bios_load_palette2(int start, int colors, u_char *r, u_char *g, u_char *b,
482 p = (u_char *)x86bios_alloc(&offs, colors * 4);
486 x86bios_init_regs(®s);
492 regs.R_ES = X86BIOS_PHYSTOSEG(offs);
493 regs.R_DI = X86BIOS_PHYSTOOFF(offs);
496 for (i = 0; i < colors; ++i) {
497 p[i * 4] = b[i] >> bits;
498 p[i * 4 + 1] = g[i] >> bits;
499 p[i * 4 + 2] = r[i] >> bits;
502 x86bios_intr(®s, 0x10);
503 x86bios_free(p, colors * 4);
505 return (regs.R_AX != 0x004f);
509 vesa_bios_state_buf_size(void)
513 x86bios_init_regs(®s);
515 /* regs.R_DL = STATE_SIZE; */
516 regs.R_CX = STATE_ALL;
518 x86bios_intr(®s, 0x10);
520 if (regs.R_AX != 0x004f)
523 return (regs.R_BX * 64);
527 vesa_bios_save_restore(int code, void *p, size_t size)
533 if (code != STATE_SAVE && code != STATE_LOAD)
536 buf = x86bios_alloc(&offs, size);
538 x86bios_init_regs(®s);
541 regs.R_CX = STATE_ALL;
543 regs.R_ES = X86BIOS_PHYSTOSEG(offs);
544 regs.R_BX = X86BIOS_PHYSTOOFF(offs);
548 x86bios_intr(®s, 0x10);
553 x86bios_intr(®s, 0x10);
556 x86bios_free(buf, size);
558 return (regs.R_AX != 0x004f);
563 vesa_bios_get_line_length(void)
567 x86bios_init_regs(®s);
571 x86bios_intr(®s, 0x10);
573 if (regs.R_AX != 0x004f)
581 vesa_bios_set_line_length(int pixel, int *bytes, int *lines)
585 x86bios_init_regs(®s);
590 x86bios_intr(®s, 0x10);
593 printf("bx:%d, cx:%d, dx:%d\n", regs.R_BX, regs.R_CX, regs.R_DX);
595 if (regs.R_AX != 0x004f)
608 vesa_bios_get_start(int *x, int *y)
612 x86bios_init_regs(®s);
616 x86bios_intr(®s, 0x10);
618 if (regs.R_AX != 0x004f)
629 vesa_bios_set_start(int x, int y)
633 x86bios_init_regs(®s);
639 x86bios_intr(®s, 0x10);
641 return (regs.R_AX != 0x004f);
644 /* map a generic video mode to a known mode */
646 vesa_map_gen_mode_num(int type, int color, int mode)
652 { M_TEXT_132x25, M_VESA_C132x25 },
653 { M_TEXT_132x43, M_VESA_C132x43 },
654 { M_TEXT_132x50, M_VESA_C132x50 },
655 { M_TEXT_132x60, M_VESA_C132x60 },
659 for (i = 0; i < sizeof(mode_map)/sizeof(mode_map[0]); ++i) {
660 if (mode_map[i].from == mode)
661 return (mode_map[i].to);
667 vesa_translate_flags(u_int16_t vflags)
674 { V_MODECOLOR, V_INFO_COLOR, 0 },
675 { V_MODEGRAPHICS, V_INFO_GRAPHICS, 0 },
676 { V_MODELFB, V_INFO_LINEAR, 0 },
677 { V_MODENONVGA, V_INFO_NONVGA, 0 },
682 for (flags = 0, i = 0; i < sizeof(ftable)/sizeof(ftable[0]); ++i) {
683 flags |= (vflags & ftable[i].mask) ?
684 ftable[i].set : ftable[i].reset;
690 vesa_translate_mmodel(u_int8_t vmodel)
696 { V_MMTEXT, V_INFO_MM_TEXT },
697 { V_MMCGA, V_INFO_MM_CGA },
698 { V_MMHGC, V_INFO_MM_HGC },
699 { V_MMEGA, V_INFO_MM_PLANAR },
700 { V_MMPACKED, V_INFO_MM_PACKED },
701 { V_MMDIRCOLOR, V_INFO_MM_DIRECT },
705 for (i = 0; mtable[i].mmodel >= 0; ++i) {
706 if (mtable[i].vmodel == vmodel)
707 return (mtable[i].mmodel);
709 return (V_INFO_MM_OTHER);
712 #define VESA_MAXSTR 256
714 #define VESA_STRCPY(dst, src) do { \
717 dst = malloc(VESA_MAXSTR, M_DEVBUF, M_WAITOK); \
718 str = x86bios_offset(BIOS_SADDRTOLADDR(src)); \
719 for (i = 0; i < VESA_MAXSTR - 1 && str[i] != '\0'; i++) \
727 static struct vesa_info buf;
728 struct vesa_mode vmode;
744 has_vesa_bios = FALSE;
745 vesa_adp_info = NULL;
747 vesa_vmode[0].vi_mode = EOT;
750 * If the VBE real mode interrupt vector is not found, try BIOS POST.
752 if (x86bios_get_intr(0x10) == 0) {
753 if (vesa_bios_post() != 0)
756 offs = x86bios_get_intr(0x10);
757 printf("VESA: interrupt vector installed (0x%x)\n",
758 BIOS_SADDRTOLADDR(offs));
762 x86bios_init_regs(®s);
765 vmbuf = x86bios_alloc(&offs, sizeof(buf));
769 regs.R_ES = X86BIOS_PHYSTOSEG(offs);
770 regs.R_DI = X86BIOS_PHYSTOOFF(offs);
772 bcopy("VBE2", vmbuf, 4); /* try for VBE2 data */
773 x86bios_intr(®s, 0x10);
775 if (regs.R_AX != 0x004f || bcmp("VESA", vmbuf, 4) != 0)
778 bcopy(vmbuf, &buf, sizeof(buf));
780 vesa_adp_info = &buf;
782 printf("VESA: information block\n");
783 hexdump(&buf, sizeof(buf), NULL, HD_OMIT_CHARS);
786 vers = buf.v_version = le16toh(buf.v_version);
787 buf.v_oemstr = le32toh(buf.v_oemstr);
788 buf.v_flags = le32toh(buf.v_flags);
789 buf.v_modetable = le32toh(buf.v_modetable);
790 buf.v_memsize = le16toh(buf.v_memsize);
791 buf.v_revision = le16toh(buf.v_revision);
792 buf.v_venderstr = le32toh(buf.v_venderstr);
793 buf.v_prodstr = le32toh(buf.v_prodstr);
794 buf.v_revstr = le32toh(buf.v_revstr);
797 printf("VESA: VBE version %d.%d is not supported; "
798 "version 1.2 or later is required.\n",
799 ((vers & 0xf000) >> 12) * 10 + ((vers & 0x0f00) >> 8),
800 ((vers & 0x00f0) >> 4) * 10 + (vers & 0x000f));
804 VESA_STRCPY(vesa_oemstr, buf.v_oemstr);
805 if (vers >= 0x0200) {
806 VESA_STRCPY(vesa_venderstr, buf.v_venderstr);
807 VESA_STRCPY(vesa_prodstr, buf.v_prodstr);
808 VESA_STRCPY(vesa_revstr, buf.v_revstr);
810 is_via_cle266 = strncmp(vesa_oemstr, VESA_VIA_CLE266,
811 sizeof(VESA_VIA_CLE266)) == 0;
813 if (buf.v_modetable == 0)
816 msize = (size_t)buf.v_memsize * 64 * 1024;
818 vesa_vmodetab = x86bios_offset(BIOS_SADDRTOLADDR(buf.v_modetable));
820 for (i = 0, modes = 0; (i < (M_VESA_MODE_MAX - M_VESA_BASE + 1)) &&
821 (vesa_vmodetab[i] != 0xffff); ++i) {
822 vesa_vmodetab[i] = le16toh(vesa_vmodetab[i]);
823 if (vesa_bios_get_mode(vesa_vmodetab[i], &vmode))
826 vmode.v_modeattr = le16toh(vmode.v_modeattr);
827 vmode.v_wgran = le16toh(vmode.v_wgran);
828 vmode.v_wsize = le16toh(vmode.v_wsize);
829 vmode.v_waseg = le16toh(vmode.v_waseg);
830 vmode.v_wbseg = le16toh(vmode.v_wbseg);
831 vmode.v_posfunc = le32toh(vmode.v_posfunc);
832 vmode.v_bpscanline = le16toh(vmode.v_bpscanline);
833 vmode.v_width = le16toh(vmode.v_width);
834 vmode.v_height = le16toh(vmode.v_height);
835 vmode.v_lfb = le32toh(vmode.v_lfb);
836 vmode.v_offscreen = le32toh(vmode.v_offscreen);
837 vmode.v_offscreensize = le16toh(vmode.v_offscreensize);
838 vmode.v_linbpscanline = le16toh(vmode.v_linbpscanline);
839 vmode.v_maxpixelclock = le32toh(vmode.v_maxpixelclock);
841 /* reject unsupported modes */
843 if ((vmode.v_modeattr &
844 (V_MODESUPP | V_MODEOPTINFO | V_MODENONVGA)) !=
845 (V_MODESUPP | V_MODEOPTINFO))
848 if ((vmode.v_modeattr & V_MODEOPTINFO) == 0) {
850 printf("Rejecting VESA %s mode: %d x %d x %d bpp "
852 vmode.v_modeattr & V_MODEGRAPHICS ?
854 vmode.v_width, vmode.v_height, vmode.v_bpp,
861 bpsl = (vmode.v_modeattr & V_MODELFB) != 0 && vers >= 0x0300 ?
862 vmode.v_linbpscanline : vmode.v_bpscanline;
863 bsize = bpsl * vmode.v_height;
864 if ((vmode.v_modeattr & V_MODEGRAPHICS) != 0)
865 bsize *= vmode.v_planes;
867 /* Does it have enough memory to support this mode? */
870 printf("Rejecting VESA %s mode: %d x %d x %d bpp "
871 " attr = %x, not enough memory\n",
872 vmode.v_modeattr & V_MODEGRAPHICS ?
874 vmode.v_width, vmode.v_height, vmode.v_bpp,
880 /* expand the array if necessary */
881 if (modes >= vesa_vmode_max) {
882 vesa_vmode_max += MODE_TABLE_DELTA;
883 p = malloc(sizeof(*vesa_vmode) * (vesa_vmode_max + 1),
886 printf("vesa_bios_init(): modes:%d, vesa_mode_max:%d\n",
887 modes, vesa_vmode_max);
890 bcopy(vesa_vmode, p, sizeof(*vesa_vmode)*modes);
891 free(vesa_vmode, M_DEVBUF);
897 printf("Found VESA %s mode: %d x %d x %d bpp\n",
898 vmode.v_modeattr & V_MODEGRAPHICS ? "graphics" : "text",
899 vmode.v_width, vmode.v_height, vmode.v_bpp);
902 if ((vmode.v_width & 0xff00) >> 8 == vmode.v_height - 1) {
903 vmode.v_width &= 0xff;
904 vmode.v_waseg = 0xb8000 >> 4;
908 /* copy some fields */
909 bzero(&vesa_vmode[modes], sizeof(vesa_vmode[modes]));
910 vesa_vmode[modes].vi_mode = vesa_vmodetab[i];
911 vesa_vmode[modes].vi_width = vmode.v_width;
912 vesa_vmode[modes].vi_height = vmode.v_height;
913 vesa_vmode[modes].vi_depth = vmode.v_bpp;
914 vesa_vmode[modes].vi_planes = vmode.v_planes;
915 vesa_vmode[modes].vi_cwidth = vmode.v_cwidth;
916 vesa_vmode[modes].vi_cheight = vmode.v_cheight;
917 vesa_vmode[modes].vi_window = (vm_offset_t)vmode.v_waseg << 4;
919 vesa_vmode[modes].vi_window_size = vmode.v_wsize * 1024;
920 vesa_vmode[modes].vi_window_gran = vmode.v_wgran * 1024;
921 if (vmode.v_modeattr & V_MODELFB)
922 vesa_vmode[modes].vi_buffer = vmode.v_lfb;
923 vesa_vmode[modes].vi_buffer_size = bsize;
924 vesa_vmode[modes].vi_mem_model =
925 vesa_translate_mmodel(vmode.v_memmodel);
926 switch (vesa_vmode[modes].vi_mem_model) {
927 case V_INFO_MM_DIRECT:
928 if ((vmode.v_modeattr & V_MODELFB) != 0 &&
930 vesa_vmode[modes].vi_pixel_fields[0] =
931 vmode.v_linredfieldpos;
932 vesa_vmode[modes].vi_pixel_fields[1] =
933 vmode.v_lingreenfieldpos;
934 vesa_vmode[modes].vi_pixel_fields[2] =
935 vmode.v_linbluefieldpos;
936 vesa_vmode[modes].vi_pixel_fields[3] =
937 vmode.v_linresfieldpos;
938 vesa_vmode[modes].vi_pixel_fsizes[0] =
939 vmode.v_linredmasksize;
940 vesa_vmode[modes].vi_pixel_fsizes[1] =
941 vmode.v_lingreenmasksize;
942 vesa_vmode[modes].vi_pixel_fsizes[2] =
943 vmode.v_linbluemasksize;
944 vesa_vmode[modes].vi_pixel_fsizes[3] =
945 vmode.v_linresmasksize;
947 vesa_vmode[modes].vi_pixel_fields[0] =
949 vesa_vmode[modes].vi_pixel_fields[1] =
950 vmode.v_greenfieldpos;
951 vesa_vmode[modes].vi_pixel_fields[2] =
952 vmode.v_bluefieldpos;
953 vesa_vmode[modes].vi_pixel_fields[3] =
955 vesa_vmode[modes].vi_pixel_fsizes[0] =
957 vesa_vmode[modes].vi_pixel_fsizes[1] =
958 vmode.v_greenmasksize;
959 vesa_vmode[modes].vi_pixel_fsizes[2] =
960 vmode.v_bluemasksize;
961 vesa_vmode[modes].vi_pixel_fsizes[3] =
965 case V_INFO_MM_PACKED:
966 vesa_vmode[modes].vi_pixel_size = (vmode.v_bpp + 7) / 8;
969 vesa_vmode[modes].vi_flags =
970 vesa_translate_flags(vmode.v_modeattr) | V_INFO_VESA;
974 vesa_vmode[modes].vi_mode = EOT;
977 printf("VESA: %d mode(s) found\n", modes);
979 has_vesa_bios = (modes > 0);
983 x86bios_free(vmbuf, sizeof(buf));
988 x86bios_free(vmbuf, sizeof(buf));
989 if (vesa_oemstr != NULL) {
990 free(vesa_oemstr, M_DEVBUF);
993 if (vesa_venderstr != NULL) {
994 free(vesa_venderstr, M_DEVBUF);
995 vesa_venderstr = NULL;
997 if (vesa_prodstr != NULL) {
998 free(vesa_prodstr, M_DEVBUF);
1001 if (vesa_revstr != NULL) {
1002 free(vesa_revstr, M_DEVBUF);
1009 vesa_clear_modes(video_info_t *info, int color)
1011 while (info->vi_mode != EOT) {
1012 if ((info->vi_flags & V_INFO_COLOR) != color)
1021 vesa_configure(int flags)
1023 video_adapter_t *adp;
1030 if (flags & VIO_PROBE_ONLY)
1034 * If the VESA module has already been loaded, abort loading
1035 * the module this time.
1037 for (i = 0; (adp = vid_get_adapter(i)) != NULL; ++i) {
1038 if (adp->va_flags & V_ADP_VESA)
1040 if (adp->va_type == KD_VGA)
1045 * The VGA adapter is not found. This is because either
1046 * 1) the VGA driver has not been initialized, or 2) the VGA card
1047 * is not present. If 1) is the case, we shall defer
1048 * initialization for now and try again later.
1051 vga_sub_configure = vesa_configure;
1055 /* count number of registered adapters */
1056 for (++i; vid_get_adapter(i) != NULL; ++i)
1060 /* call VESA BIOS */
1062 if (vesa_bios_init()) {
1066 vesa_adp->va_flags |= V_ADP_VESA;
1068 /* remove conflicting modes if we have more than one adapter */
1070 vesa_clear_modes(vesa_vmode,
1071 (vesa_adp->va_flags & V_ADP_COLOR) ?
1075 if ((error = vesa_load_ioctl()) == 0) {
1076 prevvidsw = vidsw[vesa_adp->va_index];
1077 vidsw[vesa_adp->va_index] = &vesavidsw;
1078 vesa_init_done = TRUE;
1104 vesa_probe(int unit, video_adapter_t **adpp, void *arg, int flags)
1107 return ((*prevvidsw->probe)(unit, adpp, arg, flags));
1111 vesa_init(int unit, video_adapter_t *adp, int flags)
1114 return ((*prevvidsw->init)(unit, adp, flags));
1118 vesa_get_info(video_adapter_t *adp, int mode, video_info_t *info)
1122 if ((*prevvidsw->get_info)(adp, mode, info) == 0)
1125 if (adp != vesa_adp)
1128 mode = vesa_map_gen_mode_num(vesa_adp->va_type,
1129 vesa_adp->va_flags & V_ADP_COLOR, mode);
1130 for (i = 0; vesa_vmode[i].vi_mode != EOT; ++i) {
1131 if (vesa_vmode[i].vi_mode == NA)
1133 if (vesa_vmode[i].vi_mode == mode) {
1134 *info = vesa_vmode[i];
1142 vesa_query_mode(video_adapter_t *adp, video_info_t *info)
1146 if ((*prevvidsw->query_mode)(adp, info) == 0)
1148 if (adp != vesa_adp)
1151 for (i = 0; vesa_vmode[i].vi_mode != EOT; ++i) {
1152 if ((info->vi_width != 0)
1153 && (info->vi_width != vesa_vmode[i].vi_width))
1155 if ((info->vi_height != 0)
1156 && (info->vi_height != vesa_vmode[i].vi_height))
1158 if ((info->vi_cwidth != 0)
1159 && (info->vi_cwidth != vesa_vmode[i].vi_cwidth))
1161 if ((info->vi_cheight != 0)
1162 && (info->vi_cheight != vesa_vmode[i].vi_cheight))
1164 if ((info->vi_depth != 0)
1165 && (info->vi_depth != vesa_vmode[i].vi_depth))
1167 if ((info->vi_planes != 0)
1168 && (info->vi_planes != vesa_vmode[i].vi_planes))
1170 /* pixel format, memory model */
1171 if ((info->vi_flags != 0)
1172 && (info->vi_flags != vesa_vmode[i].vi_flags))
1174 *info = vesa_vmode[i];
1181 vesa_set_mode(video_adapter_t *adp, int mode)
1185 if (adp != vesa_adp)
1186 return ((*prevvidsw->set_mode)(adp, mode));
1188 mode = vesa_map_gen_mode_num(adp->va_type,
1189 adp->va_flags & V_ADP_COLOR, mode);
1191 printf("VESA: set_mode(): %d(%x) -> %d(%x)\n",
1192 adp->va_mode, adp->va_mode, mode, mode);
1195 * If the current mode is a VESA mode and the new mode is not,
1196 * restore the state of the adapter first by setting one of the
1197 * standard VGA mode, so that non-standard, extended SVGA registers
1198 * are set to the state compatible with the standard VGA modes.
1199 * Otherwise (*prevvidsw->set_mode)() may not be able to set up
1200 * the new mode correctly.
1202 if (VESA_MODE(adp->va_mode)) {
1203 if (!VESA_MODE(mode) &&
1204 (*prevvidsw->get_info)(adp, mode, &info) == 0) {
1205 if ((adp->va_flags & V_ADP_DAC8) != 0) {
1206 vesa_bios_set_dac(6);
1207 adp->va_flags &= ~V_ADP_DAC8;
1209 int10_set_mode(adp->va_initial_bios_mode);
1210 if (adp->va_info.vi_flags & V_INFO_LINEAR)
1211 pmap_unmapdev(adp->va_buffer,
1212 adp->va_buffer_size);
1214 * Once (*prevvidsw->get_info)() succeeded,
1215 * (*prevvidsw->set_mode)() below won't fail...
1220 /* we may not need to handle this mode after all... */
1221 if (!VESA_MODE(mode) && (*prevvidsw->set_mode)(adp, mode) == 0)
1224 /* is the new mode supported? */
1225 if (vesa_get_info(adp, mode, &info))
1227 /* assert(VESA_MODE(mode)); */
1230 printf("VESA: about to set a VESA mode...\n");
1232 /* don't use the linear frame buffer for text modes. XXX */
1233 if (!(info.vi_flags & V_INFO_GRAPHICS))
1234 info.vi_flags &= ~V_INFO_LINEAR;
1236 if (vesa_bios_set_mode(mode | ((info.vi_flags & V_INFO_LINEAR) ? 0x4000 : 0)))
1239 /* Palette format is reset by the above VBE function call. */
1240 adp->va_flags &= ~V_ADP_DAC8;
1242 if ((vesa_adp_info->v_flags & V_DAC8) != 0 &&
1243 (info.vi_flags & V_INFO_GRAPHICS) != 0 &&
1244 (info.vi_flags & V_INFO_NONVGA) != 0 &&
1245 vesa_bios_set_dac(8) > 6)
1246 adp->va_flags |= V_ADP_DAC8;
1248 if (adp->va_info.vi_flags & V_INFO_LINEAR)
1249 pmap_unmapdev(adp->va_buffer, adp->va_buffer_size);
1252 printf("VESA: mode set!\n");
1254 vesa_adp->va_mode = mode;
1255 vesa_adp->va_flags &= ~V_ADP_COLOR;
1256 vesa_adp->va_flags |=
1257 (info.vi_flags & V_INFO_COLOR) ? V_ADP_COLOR : 0;
1258 vesa_adp->va_crtc_addr =
1259 (vesa_adp->va_flags & V_ADP_COLOR) ? COLOR_CRTC : MONO_CRTC;
1260 if (info.vi_flags & V_INFO_LINEAR) {
1262 printf("VESA: setting up LFB\n");
1264 vesa_adp->va_buffer =
1265 (vm_offset_t)pmap_mapdev_attr(info.vi_buffer,
1266 info.vi_buffer_size, PAT_WRITE_COMBINING);
1267 vesa_adp->va_window = vesa_adp->va_buffer;
1268 vesa_adp->va_window_size = info.vi_buffer_size / info.vi_planes;
1269 vesa_adp->va_window_gran = info.vi_buffer_size / info.vi_planes;
1271 vesa_adp->va_buffer = 0;
1272 vesa_adp->va_window = (vm_offset_t)x86bios_offset(info.vi_window);
1273 vesa_adp->va_window_size = info.vi_window_size;
1274 vesa_adp->va_window_gran = info.vi_window_gran;
1276 vesa_adp->va_buffer_size = info.vi_buffer_size;
1277 vesa_adp->va_window_orig = 0;
1278 vesa_adp->va_line_width = info.vi_buffer_size / info.vi_height;
1279 if ((info.vi_flags & V_INFO_GRAPHICS) != 0)
1280 vesa_adp->va_line_width /= info.vi_planes;
1281 vesa_adp->va_disp_start.x = 0;
1282 vesa_adp->va_disp_start.y = 0;
1284 printf("vesa_set_mode(): vi_width:%d, line_width:%d\n",
1285 info.vi_width, vesa_adp->va_line_width);
1287 bcopy(&info, &vesa_adp->va_info, sizeof(vesa_adp->va_info));
1289 /* move hardware cursor out of the way */
1290 (*vidsw[vesa_adp->va_index]->set_hw_cursor)(vesa_adp, -1, -1);
1296 vesa_save_font(video_adapter_t *adp, int page, int fontsize, int fontwidth,
1297 u_char *data, int ch, int count)
1300 return ((*prevvidsw->save_font)(adp, page, fontsize, fontwidth, data,
1305 vesa_load_font(video_adapter_t *adp, int page, int fontsize, int fontwidth,
1306 u_char *data, int ch, int count)
1309 return ((*prevvidsw->load_font)(adp, page, fontsize, fontwidth, data,
1314 vesa_show_font(video_adapter_t *adp, int page)
1317 return ((*prevvidsw->show_font)(adp, page));
1321 vesa_save_palette(video_adapter_t *adp, u_char *palette)
1325 if (adp == vesa_adp && VESA_MODE(adp->va_mode) &&
1326 (adp->va_info.vi_flags & V_INFO_NONVGA) != 0) {
1327 bits = (adp->va_flags & V_ADP_DAC8) != 0 ? 8 : 6;
1328 return (vesa_bios_save_palette(0, 256, palette, bits));
1331 return ((*prevvidsw->save_palette)(adp, palette));
1335 vesa_load_palette(video_adapter_t *adp, u_char *palette)
1339 if (adp == vesa_adp && VESA_MODE(adp->va_mode) &&
1340 (adp->va_info.vi_flags & V_INFO_NONVGA) != 0) {
1341 bits = (adp->va_flags & V_ADP_DAC8) != 0 ? 8 : 6;
1342 return (vesa_bios_load_palette(0, 256, palette, bits));
1345 return ((*prevvidsw->load_palette)(adp, palette));
1349 vesa_set_border(video_adapter_t *adp, int color)
1352 return ((*prevvidsw->set_border)(adp, color));
1356 vesa_save_state(video_adapter_t *adp, void *p, size_t size)
1359 if (adp != vesa_adp)
1360 return ((*prevvidsw->save_state)(adp, p, size));
1362 if (vesa_state_buf_size == -1) {
1363 vesa_state_buf_size = vesa_bios_state_buf_size();
1364 if (vesa_state_buf_size == 0)
1368 return (offsetof(adp_state_t, regs) + vesa_state_buf_size);
1369 else if (size < (offsetof(adp_state_t, regs) + vesa_state_buf_size))
1372 ((adp_state_t *)p)->sig = V_STATE_SIG;
1373 bzero(((adp_state_t *)p)->regs, vesa_state_buf_size);
1374 return (vesa_bios_save_restore(STATE_SAVE, ((adp_state_t *)p)->regs,
1375 vesa_state_buf_size));
1379 vesa_load_state(video_adapter_t *adp, void *p)
1382 if ((adp != vesa_adp) || (((adp_state_t *)p)->sig != V_STATE_SIG))
1383 return ((*prevvidsw->load_state)(adp, p));
1385 if (vesa_state_buf_size <= 0)
1388 /* Try BIOS POST to restore a sane state. */
1389 (void)vesa_bios_post();
1390 (void)int10_set_mode(adp->va_initial_bios_mode);
1392 return (vesa_bios_save_restore(STATE_LOAD, ((adp_state_t *)p)->regs,
1393 vesa_state_buf_size));
1398 vesa_get_origin(video_adapter_t *adp, off_t *offset)
1402 x86bios_init_regs(®s);
1406 x86bios_intr(®s, 0x10);
1408 if (regs.R_AX != 0x004f)
1410 *offset = regs.DX * adp->va_window_gran;
1417 vesa_set_origin(video_adapter_t *adp, off_t offset)
1422 * This function should return as quickly as possible to
1423 * maintain good performance of the system. For this reason,
1424 * error checking is kept minimal and let the VESA BIOS to
1427 if (adp != vesa_adp)
1428 return ((*prevvidsw->set_win_org)(adp, offset));
1430 /* if this is a linear frame buffer, do nothing */
1431 if (adp->va_info.vi_flags & V_INFO_LINEAR)
1434 if (adp->va_window_gran == 0)
1437 x86bios_init_regs(®s);
1439 regs.R_DX = offset / adp->va_window_gran;
1441 x86bios_intr(®s, 0x10);
1443 if (regs.R_AX != 0x004f)
1446 x86bios_init_regs(®s);
1449 regs.R_DX = offset / adp->va_window_gran;
1450 x86bios_intr(®s, 0x10);
1452 adp->va_window_orig = (offset/adp->va_window_gran)*adp->va_window_gran;
1453 return (0); /* XXX */
1457 vesa_read_hw_cursor(video_adapter_t *adp, int *col, int *row)
1460 return ((*prevvidsw->read_hw_cursor)(adp, col, row));
1464 vesa_set_hw_cursor(video_adapter_t *adp, int col, int row)
1467 return ((*prevvidsw->set_hw_cursor)(adp, col, row));
1471 vesa_set_hw_cursor_shape(video_adapter_t *adp, int base, int height,
1472 int celsize, int blink)
1475 return ((*prevvidsw->set_hw_cursor_shape)(adp, base, height, celsize,
1480 vesa_blank_display(video_adapter_t *adp, int mode)
1483 /* XXX: use VESA DPMS */
1484 return ((*prevvidsw->blank_display)(adp, mode));
1488 vesa_mmap(video_adapter_t *adp, vm_offset_t offset, vm_paddr_t *paddr,
1493 printf("vesa_mmap(): window:0x%tx, buffer:0x%tx, offset:0x%tx\n",
1494 adp->va_info.vi_window, adp->va_info.vi_buffer, offset);
1497 if ((adp == vesa_adp) &&
1498 (adp->va_info.vi_flags & V_INFO_LINEAR) != 0) {
1499 /* va_window_size == va_buffer_size/vi_planes */
1500 /* XXX: is this correct? */
1501 if (offset > adp->va_window_size - PAGE_SIZE)
1503 *paddr = adp->va_info.vi_buffer + offset;
1506 return ((*prevvidsw->mmap)(adp, offset, paddr, prot));
1510 vesa_clear(video_adapter_t *adp)
1513 return ((*prevvidsw->clear)(adp));
1517 vesa_fill_rect(video_adapter_t *adp, int val, int x, int y, int cx, int cy)
1520 return ((*prevvidsw->fill_rect)(adp, val, x, y, cx, cy));
1524 vesa_bitblt(video_adapter_t *adp,...)
1532 get_palette(video_adapter_t *adp, int base, int count,
1533 u_char *red, u_char *green, u_char *blue, u_char *trans)
1541 if (base < 0 || base >= 256 || count < 0 || count > 256)
1543 if ((base + count) > 256)
1545 if (!VESA_MODE(adp->va_mode))
1547 if ((adp->va_info.vi_flags & V_INFO_NONVGA) == 0)
1550 bits = (adp->va_flags & V_ADP_DAC8) != 0 ? 8 : 6;
1551 r = malloc(count * 3, M_DEVBUF, M_WAITOK);
1554 error = vesa_bios_save_palette2(base, count, r, g, b, bits);
1556 copyout(r, red, count);
1557 copyout(g, green, count);
1558 copyout(b, blue, count);
1559 if (trans != NULL) {
1561 copyout(r, trans, count);
1570 set_palette(video_adapter_t *adp, int base, int count,
1571 u_char *red, u_char *green, u_char *blue, u_char *trans)
1579 if (base < 0 || base >= 256 || count < 0 || count > 256)
1581 if ((base + count) > 256)
1583 if (!VESA_MODE(adp->va_mode))
1585 if ((adp->va_info.vi_flags & V_INFO_NONVGA) == 0)
1588 bits = (adp->va_flags & V_ADP_DAC8) != 0 ? 8 : 6;
1589 r = malloc(count * 3, M_DEVBUF, M_WAITOK);
1592 copyin(red, r, count);
1593 copyin(green, g, count);
1594 copyin(blue, b, count);
1596 error = vesa_bios_load_palette2(base, count, r, g, b, bits);
1603 vesa_ioctl(video_adapter_t *adp, u_long cmd, caddr_t arg)
1607 if (adp != vesa_adp)
1608 return ((*prevvidsw->ioctl)(adp, cmd, arg));
1611 case FBIO_SETWINORG: /* set frame buffer window origin */
1612 if (!VESA_MODE(adp->va_mode))
1613 return (*prevvidsw->ioctl)(adp, cmd, arg);
1614 return (vesa_set_origin(adp, *(off_t *)arg) ? ENODEV : 0);
1616 case FBIO_SETDISPSTART: /* set display start address */
1617 if (!VESA_MODE(adp->va_mode))
1618 return ((*prevvidsw->ioctl)(adp, cmd, arg));
1619 if (vesa_bios_set_start(((video_display_start_t *)arg)->x,
1620 ((video_display_start_t *)arg)->y))
1622 adp->va_disp_start.x = ((video_display_start_t *)arg)->x;
1623 adp->va_disp_start.y = ((video_display_start_t *)arg)->y;
1626 case FBIO_SETLINEWIDTH: /* set line length in pixel */
1627 if (!VESA_MODE(adp->va_mode))
1628 return ((*prevvidsw->ioctl)(adp, cmd, arg));
1629 if (vesa_bios_set_line_length(*(u_int *)arg, &bytes, NULL))
1631 adp->va_line_width = bytes;
1633 printf("new line width:%d\n", adp->va_line_width);
1637 case FBIO_GETPALETTE: /* get color palette */
1638 if (get_palette(adp, ((video_color_palette_t *)arg)->index,
1639 ((video_color_palette_t *)arg)->count,
1640 ((video_color_palette_t *)arg)->red,
1641 ((video_color_palette_t *)arg)->green,
1642 ((video_color_palette_t *)arg)->blue,
1643 ((video_color_palette_t *)arg)->transparent))
1644 return ((*prevvidsw->ioctl)(adp, cmd, arg));
1648 case FBIO_SETPALETTE: /* set color palette */
1649 if (set_palette(adp, ((video_color_palette_t *)arg)->index,
1650 ((video_color_palette_t *)arg)->count,
1651 ((video_color_palette_t *)arg)->red,
1652 ((video_color_palette_t *)arg)->green,
1653 ((video_color_palette_t *)arg)->blue,
1654 ((video_color_palette_t *)arg)->transparent))
1655 return ((*prevvidsw->ioctl)(adp, cmd, arg));
1658 case FBIOGETCMAP: /* get color palette */
1659 if (get_palette(adp, ((struct fbcmap *)arg)->index,
1660 ((struct fbcmap *)arg)->count,
1661 ((struct fbcmap *)arg)->red,
1662 ((struct fbcmap *)arg)->green,
1663 ((struct fbcmap *)arg)->blue, NULL))
1664 return ((*prevvidsw->ioctl)(adp, cmd, arg));
1667 case FBIOPUTCMAP: /* set color palette */
1668 if (set_palette(adp, ((struct fbcmap *)arg)->index,
1669 ((struct fbcmap *)arg)->count,
1670 ((struct fbcmap *)arg)->red,
1671 ((struct fbcmap *)arg)->green,
1672 ((struct fbcmap *)arg)->blue, NULL))
1673 return ((*prevvidsw->ioctl)(adp, cmd, arg));
1677 return ((*prevvidsw->ioctl)(adp, cmd, arg));
1682 vesa_diag(video_adapter_t *adp, int level)
1686 /* call the previous handler first */
1687 error = (*prevvidsw->diag)(adp, level);
1691 if (adp != vesa_adp)
1701 vesa_bios_info(int level)
1704 struct vesa_mode vmode;
1709 vers = vesa_adp_info->v_version;
1712 /* general adapter information */
1714 "VESA: v%d.%d, %dk memory, flags:0x%x, mode table:%p (%x)\n",
1715 (vers >> 12) * 10 + ((vers & 0x0f00) >> 8),
1716 ((vers & 0x00f0) >> 4) * 10 + (vers & 0x000f),
1717 vesa_adp_info->v_memsize * 64, vesa_adp_info->v_flags,
1718 vesa_vmodetab, vesa_adp_info->v_modetable);
1721 if (vesa_oemstr != NULL)
1722 printf("VESA: %s\n", vesa_oemstr);
1728 if (vers >= 0x0200 && bootverbose) {
1729 /* vender name, product name, product revision */
1730 printf("VESA: %s %s %s\n",
1731 (vesa_venderstr != NULL) ? vesa_venderstr : "unknown",
1732 (vesa_prodstr != NULL) ? vesa_prodstr : "unknown",
1733 (vesa_revstr != NULL) ? vesa_revstr : "?");
1737 /* mode information */
1739 (i < (M_VESA_MODE_MAX - M_VESA_BASE + 1))
1740 && (vesa_vmodetab[i] != 0xffff); ++i) {
1741 if (vesa_bios_get_mode(vesa_vmodetab[i], &vmode))
1744 /* print something for diagnostic purpose */
1745 printf("VESA: mode:0x%03x, flags:0x%04x",
1746 vesa_vmodetab[i], vmode.v_modeattr);
1747 if (vmode.v_modeattr & V_MODEOPTINFO) {
1748 if (vmode.v_modeattr & V_MODEGRAPHICS) {
1749 printf(", G %dx%dx%d %d, ",
1750 vmode.v_width, vmode.v_height,
1751 vmode.v_bpp, vmode.v_planes);
1753 printf(", T %dx%d, ",
1754 vmode.v_width, vmode.v_height);
1756 printf("font:%dx%d, ",
1757 vmode.v_cwidth, vmode.v_cheight);
1758 printf("pages:%d, mem:%d",
1759 vmode.v_ipages + 1, vmode.v_memmodel);
1761 if (vmode.v_modeattr & V_MODELFB) {
1762 printf("\nVESA: LFB:0x%x, off:0x%x, off_size:0x%x",
1763 vmode.v_lfb, vmode.v_offscreen,
1764 vmode.v_offscreensize*1024);
1767 printf("VESA: window A:0x%x (%x), window B:0x%x (%x), ",
1768 vmode.v_waseg, vmode.v_waattr,
1769 vmode.v_wbseg, vmode.v_wbattr);
1770 printf("size:%dk, gran:%dk\n",
1771 vmode.v_wsize, vmode.v_wgran);
1773 #endif /* VESA_DEBUG > 1 */
1778 /* module loading */
1789 /* locate a VGA adapter */
1792 error = vesa_configure(0);
1796 vesa_bios_info(bootverbose);
1804 u_char palette[256*3];
1808 /* if the adapter is currently in a VESA mode, don't unload */
1809 if ((vesa_adp != NULL) && VESA_MODE(vesa_adp->va_mode))
1812 * FIXME: if there is at least one vty which is in a VESA mode,
1813 * we shouldn't be unloading! XXX
1817 if ((error = vesa_unload_ioctl()) == 0) {
1818 if (vesa_adp != NULL) {
1819 if ((vesa_adp->va_flags & V_ADP_DAC8) != 0) {
1820 vesa_bios_save_palette(0, 256, palette, 8);
1821 vesa_bios_set_dac(6);
1822 vesa_adp->va_flags &= ~V_ADP_DAC8;
1823 vesa_bios_load_palette(0, 256, palette, 6);
1825 vesa_adp->va_flags &= ~V_ADP_VESA;
1826 vidsw[vesa_adp->va_index] = prevvidsw;
1831 if (vesa_oemstr != NULL)
1832 free(vesa_oemstr, M_DEVBUF);
1833 if (vesa_venderstr != NULL)
1834 free(vesa_venderstr, M_DEVBUF);
1835 if (vesa_prodstr != NULL)
1836 free(vesa_prodstr, M_DEVBUF);
1837 if (vesa_revstr != NULL)
1838 free(vesa_revstr, M_DEVBUF);
1839 if (vesa_vmode != &vesa_vmode_empty)
1840 free(vesa_vmode, M_DEVBUF);
1845 vesa_mod_event(module_t mod, int type, void *data)
1850 return (vesa_load());
1852 return (vesa_unload());
1854 return (EOPNOTSUPP);
1857 static moduledata_t vesa_mod = {
1863 DECLARE_MODULE(vesa, vesa_mod, SI_SUB_DRIVERS, SI_ORDER_MIDDLE);
1864 MODULE_DEPEND(vesa, x86bios, 1, 1, 1);
1866 #endif /* VGA_NO_MODE_CHANGE */