2 * Copyright (c) 1998 Kazutaka YOKOTA and Michael Smith
3 * Copyright (c) 2009-2010 Jung-uk Kim <jkim@FreeBSD.org>
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer as
11 * the first lines of this file unmodified.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR
17 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19 * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT,
20 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 #include <sys/cdefs.h>
29 __FBSDID("$FreeBSD$");
34 #ifndef VGA_NO_MODE_CHANGE
36 #include <sys/param.h>
38 #include <sys/systm.h>
39 #include <sys/kernel.h>
40 #include <sys/module.h>
41 #include <sys/malloc.h>
45 #include <vm/vm_extern.h>
46 #include <vm/vm_kern.h>
47 #include <vm/vm_param.h>
50 #include <machine/pc/bios.h>
51 #include <dev/fb/vesa.h>
53 #include <dev/fb/fbreg.h>
54 #include <dev/fb/vgareg.h>
56 #include <dev/pci/pcivar.h>
58 #include <isa/isareg.h>
60 #include <compat/x86bios/x86bios.h>
62 #define VESA_VIA_CLE266 "VIA CLE266\r\n"
68 /* VESA video adapter state buffer stub */
71 #define V_STATE_SIG 0x61736576
74 typedef struct adp_state adp_state_t;
76 /* VESA video adapter */
77 static video_adapter_t *vesa_adp = NULL;
78 static ssize_t vesa_state_buf_size = -1;
82 static int vesa_nop(void);
84 static int vesa_error(void);
85 static vi_probe_t vesa_probe;
86 static vi_init_t vesa_init;
87 static vi_get_info_t vesa_get_info;
88 static vi_query_mode_t vesa_query_mode;
89 static vi_set_mode_t vesa_set_mode;
90 static vi_save_font_t vesa_save_font;
91 static vi_load_font_t vesa_load_font;
92 static vi_show_font_t vesa_show_font;
93 static vi_save_palette_t vesa_save_palette;
94 static vi_load_palette_t vesa_load_palette;
95 static vi_set_border_t vesa_set_border;
96 static vi_save_state_t vesa_save_state;
97 static vi_load_state_t vesa_load_state;
98 static vi_set_win_org_t vesa_set_origin;
99 static vi_read_hw_cursor_t vesa_read_hw_cursor;
100 static vi_set_hw_cursor_t vesa_set_hw_cursor;
101 static vi_set_hw_cursor_shape_t vesa_set_hw_cursor_shape;
102 static vi_blank_display_t vesa_blank_display;
103 static vi_mmap_t vesa_mmap;
104 static vi_ioctl_t vesa_ioctl;
105 static vi_clear_t vesa_clear;
106 static vi_fill_rect_t vesa_fill_rect;
107 static vi_bitblt_t vesa_bitblt;
108 static vi_diag_t vesa_diag;
109 static int vesa_bios_info(int level);
111 static video_switch_t vesavidsw = {
128 vesa_set_hw_cursor_shape,
140 static video_switch_t *prevvidsw;
142 /* VESA BIOS video modes */
143 #define VESA_MAXMODES 64
147 #define MODE_TABLE_DELTA 8
149 static int vesa_vmode_max = 0;
150 static video_info_t vesa_vmode_empty = { EOT };
151 static video_info_t *vesa_vmode = &vesa_vmode_empty;
153 static int vesa_init_done = FALSE;
154 static int has_vesa_bios = FALSE;
155 static struct vesa_info *vesa_adp_info = NULL;
156 static u_int16_t *vesa_vmodetab = NULL;
157 static char *vesa_oemstr = NULL;
158 static char *vesa_venderstr = NULL;
159 static char *vesa_prodstr = NULL;
160 static char *vesa_revstr = NULL;
162 /* local macros and functions */
163 #define BIOS_SADDRTOLADDR(p) ((((p) & 0xffff0000) >> 12) + ((p) & 0x0000ffff))
165 static int int10_set_mode(int mode);
166 static int vesa_bios_post(void);
167 static int vesa_bios_get_mode(int mode, struct vesa_mode *vmode);
168 static int vesa_bios_set_mode(int mode);
170 static int vesa_bios_get_dac(void);
172 static int vesa_bios_set_dac(int bits);
173 static int vesa_bios_save_palette(int start, int colors, u_char *palette,
175 static int vesa_bios_save_palette2(int start, int colors, u_char *r, u_char *g,
176 u_char *b, int bits);
177 static int vesa_bios_load_palette(int start, int colors, u_char *palette,
179 static int vesa_bios_load_palette2(int start, int colors, u_char *r, u_char *g,
180 u_char *b, int bits);
184 #define STATE_HW (1<<0)
185 #define STATE_DATA (1<<1)
186 #define STATE_DAC (1<<2)
187 #define STATE_REG (1<<3)
188 #define STATE_MOST (STATE_HW | STATE_DATA | STATE_REG)
189 #define STATE_ALL (STATE_HW | STATE_DATA | STATE_DAC | STATE_REG)
190 static ssize_t vesa_bios_state_buf_size(void);
191 static int vesa_bios_save_restore(int code, void *p, size_t size);
192 #ifdef MODE_TABLE_BROKEN
193 static int vesa_bios_get_line_length(void);
195 static int vesa_bios_set_line_length(int pixel, int *bytes, int *lines);
197 static int vesa_bios_get_start(int *x, int *y);
199 static int vesa_bios_set_start(int x, int y);
200 static int vesa_map_gen_mode_num(int type, int color, int mode);
201 static int vesa_translate_flags(u_int16_t vflags);
202 static int vesa_translate_mmodel(u_int8_t vmodel);
203 static int vesa_get_bpscanline(struct vesa_mode *vmode);
204 static int vesa_bios_init(void);
205 static void vesa_clear_modes(video_info_t *info, int color);
208 static int vesa_get_origin(video_adapter_t *adp, off_t *offset);
211 /* INT 10 BIOS calls */
213 int10_set_mode(int mode)
217 x86bios_init_regs(®s);
220 x86bios_intr(®s, 0x10);
232 int count, i, is_pci;
234 if (x86bios_get_orm(0xc0000) == NULL)
240 /* Find the matching PCI video controller. */
241 dc = devclass_find("vgapci");
242 if (dc != NULL && devclass_get_devices(dc, &devs, &count) == 0) {
243 for (i = 0; i < count; i++)
244 if (device_get_flags(devs[i]) != 0 &&
245 x86bios_match_device(0xc0000, devs[i])) {
253 /* Try VGA if a PCI device is not found. */
255 dc = devclass_find(VGA_DRIVER_NAME);
257 dev = devclass_get_device(dc, 0);
261 printf("%s: calling BIOS POST\n",
262 dev == NULL ? "VESA" : device_get_nameunit(dev));
264 x86bios_init_regs(®s);
266 regs.R_AH = pci_get_bus(dev);
267 regs.R_AL = (pci_get_slot(dev) << 3) |
268 (pci_get_function(dev) & 0x07);
271 x86bios_call(®s, 0xc000, 0x0003);
273 if (x86bios_get_intr(0x10) == 0)
279 /* VESA BIOS calls */
281 vesa_bios_get_mode(int mode, struct vesa_mode *vmode)
287 buf = x86bios_alloc(&offs, sizeof(*vmode));
291 x86bios_init_regs(®s);
295 regs.R_ES = X86BIOS_PHYSTOSEG(offs);
296 regs.R_DI = X86BIOS_PHYSTOOFF(offs);
298 x86bios_intr(®s, 0x10);
300 if (regs.R_AX != 0x004f) {
301 x86bios_free(buf, sizeof(*vmode));
305 bcopy(buf, vmode, sizeof(*vmode));
306 x86bios_free(buf, sizeof(*vmode));
312 vesa_bios_set_mode(int mode)
316 x86bios_init_regs(®s);
320 x86bios_intr(®s, 0x10);
322 return (regs.R_AX != 0x004f);
327 vesa_bios_get_dac(void)
331 x86bios_init_regs(®s);
335 x86bios_intr(®s, 0x10);
337 if (regs.R_AX != 0x004f)
345 vesa_bios_set_dac(int bits)
349 x86bios_init_regs(®s);
354 x86bios_intr(®s, 0x10);
356 if (regs.R_AX != 0x004f)
363 vesa_bios_save_palette(int start, int colors, u_char *palette, int bits)
370 p = (u_char *)x86bios_alloc(&offs, colors * 4);
374 x86bios_init_regs(®s);
380 regs.R_ES = X86BIOS_PHYSTOSEG(offs);
381 regs.R_DI = X86BIOS_PHYSTOOFF(offs);
383 x86bios_intr(®s, 0x10);
385 if (regs.R_AX != 0x004f) {
386 x86bios_free(p, colors * 4);
391 for (i = 0; i < colors; ++i) {
392 palette[i * 3] = p[i * 4 + 2] << bits;
393 palette[i * 3 + 1] = p[i * 4 + 1] << bits;
394 palette[i * 3 + 2] = p[i * 4] << bits;
396 x86bios_free(p, colors * 4);
402 vesa_bios_save_palette2(int start, int colors, u_char *r, u_char *g, u_char *b,
410 p = (u_char *)x86bios_alloc(&offs, colors * 4);
414 x86bios_init_regs(®s);
420 regs.R_ES = X86BIOS_PHYSTOSEG(offs);
421 regs.R_DI = X86BIOS_PHYSTOOFF(offs);
423 x86bios_intr(®s, 0x10);
425 if (regs.R_AX != 0x004f) {
426 x86bios_free(p, colors * 4);
431 for (i = 0; i < colors; ++i) {
432 r[i] = p[i * 4 + 2] << bits;
433 g[i] = p[i * 4 + 1] << bits;
434 b[i] = p[i * 4] << bits;
436 x86bios_free(p, colors * 4);
442 vesa_bios_load_palette(int start, int colors, u_char *palette, int bits)
449 p = (u_char *)x86bios_alloc(&offs, colors * 4);
453 x86bios_init_regs(®s);
459 regs.R_ES = X86BIOS_PHYSTOSEG(offs);
460 regs.R_DI = X86BIOS_PHYSTOOFF(offs);
463 for (i = 0; i < colors; ++i) {
464 p[i * 4] = palette[i * 3 + 2] >> bits;
465 p[i * 4 + 1] = palette[i * 3 + 1] >> bits;
466 p[i * 4 + 2] = palette[i * 3] >> bits;
469 x86bios_intr(®s, 0x10);
470 x86bios_free(p, colors * 4);
472 return (regs.R_AX != 0x004f);
476 vesa_bios_load_palette2(int start, int colors, u_char *r, u_char *g, u_char *b,
484 p = (u_char *)x86bios_alloc(&offs, colors * 4);
488 x86bios_init_regs(®s);
494 regs.R_ES = X86BIOS_PHYSTOSEG(offs);
495 regs.R_DI = X86BIOS_PHYSTOOFF(offs);
498 for (i = 0; i < colors; ++i) {
499 p[i * 4] = b[i] >> bits;
500 p[i * 4 + 1] = g[i] >> bits;
501 p[i * 4 + 2] = r[i] >> bits;
504 x86bios_intr(®s, 0x10);
505 x86bios_free(p, colors * 4);
507 return (regs.R_AX != 0x004f);
511 vesa_bios_state_buf_size(void)
515 x86bios_init_regs(®s);
517 /* regs.R_DL = STATE_SIZE; */
518 regs.R_CX = STATE_ALL;
520 x86bios_intr(®s, 0x10);
522 if (regs.R_AX != 0x004f)
525 return (regs.R_BX * 64);
529 vesa_bios_save_restore(int code, void *p, size_t size)
535 if (code != STATE_SAVE && code != STATE_LOAD)
538 buf = x86bios_alloc(&offs, size);
540 x86bios_init_regs(®s);
543 regs.R_CX = STATE_ALL;
545 regs.R_ES = X86BIOS_PHYSTOSEG(offs);
546 regs.R_BX = X86BIOS_PHYSTOOFF(offs);
550 x86bios_intr(®s, 0x10);
555 x86bios_intr(®s, 0x10);
558 x86bios_free(buf, size);
560 return (regs.R_AX != 0x004f);
563 #ifdef MODE_TABLE_BROKEN
565 vesa_bios_get_line_length(void)
569 x86bios_init_regs(®s);
573 x86bios_intr(®s, 0x10);
575 if (regs.R_AX != 0x004f)
583 vesa_bios_set_line_length(int pixel, int *bytes, int *lines)
587 x86bios_init_regs(®s);
592 x86bios_intr(®s, 0x10);
595 printf("bx:%d, cx:%d, dx:%d\n", regs.R_BX, regs.R_CX, regs.R_DX);
597 if (regs.R_AX != 0x004f)
610 vesa_bios_get_start(int *x, int *y)
614 x86bios_init_regs(®s);
618 x86bios_intr(®s, 0x10);
620 if (regs.R_AX != 0x004f)
631 vesa_bios_set_start(int x, int y)
635 x86bios_init_regs(®s);
641 x86bios_intr(®s, 0x10);
643 return (regs.R_AX != 0x004f);
646 /* map a generic video mode to a known mode */
648 vesa_map_gen_mode_num(int type, int color, int mode)
654 { M_TEXT_132x25, M_VESA_C132x25 },
655 { M_TEXT_132x43, M_VESA_C132x43 },
656 { M_TEXT_132x50, M_VESA_C132x50 },
657 { M_TEXT_132x60, M_VESA_C132x60 },
661 for (i = 0; i < sizeof(mode_map)/sizeof(mode_map[0]); ++i) {
662 if (mode_map[i].from == mode)
663 return (mode_map[i].to);
669 vesa_translate_flags(u_int16_t vflags)
676 { V_MODECOLOR, V_INFO_COLOR, 0 },
677 { V_MODEGRAPHICS, V_INFO_GRAPHICS, 0 },
678 { V_MODELFB, V_INFO_LINEAR, 0 },
679 { V_MODENONVGA, V_INFO_NONVGA, 0 },
684 for (flags = 0, i = 0; i < sizeof(ftable)/sizeof(ftable[0]); ++i) {
685 flags |= (vflags & ftable[i].mask) ?
686 ftable[i].set : ftable[i].reset;
692 vesa_translate_mmodel(u_int8_t vmodel)
698 { V_MMTEXT, V_INFO_MM_TEXT },
699 { V_MMCGA, V_INFO_MM_CGA },
700 { V_MMHGC, V_INFO_MM_HGC },
701 { V_MMEGA, V_INFO_MM_PLANAR },
702 { V_MMPACKED, V_INFO_MM_PACKED },
703 { V_MMDIRCOLOR, V_INFO_MM_DIRECT },
707 for (i = 0; mtable[i].mmodel >= 0; ++i) {
708 if (mtable[i].vmodel == vmodel)
709 return (mtable[i].mmodel);
711 return (V_INFO_MM_OTHER);
715 vesa_get_bpscanline(struct vesa_mode *vmode)
719 if ((vmode->v_modeattr & V_MODEGRAPHICS) != 0) {
720 /* Find the minimum length. */
721 switch (vmode->v_bpp / vmode->v_planes) {
723 bpsl = vmode->v_width / 8;
726 bpsl = vmode->v_width / 4;
729 bpsl = vmode->v_width / 2;
732 bpsl = vmode->v_width * ((vmode->v_bpp + 7) / 8);
733 bpsl /= vmode->v_planes;
737 /* Use VBE 3.0 information if it looks sane. */
738 if ((vmode->v_modeattr & V_MODELFB) != 0 &&
739 vesa_adp_info->v_version >= 0x0300 &&
740 vmode->v_linbpscanline > bpsl)
741 return (vmode->v_linbpscanline);
743 /* Return the minimum if the mode table looks absurd. */
744 if (vmode->v_bpscanline < bpsl)
748 return (vmode->v_bpscanline);
751 #define VESA_MAXSTR 256
753 #define VESA_STRCPY(dst, src) do { \
756 dst = malloc(VESA_MAXSTR, M_DEVBUF, M_WAITOK); \
757 str = x86bios_offset(BIOS_SADDRTOLADDR(src)); \
758 for (i = 0; i < VESA_MAXSTR - 1 && str[i] != '\0'; i++) \
766 struct vesa_mode vmode;
767 struct vesa_info *buf;
782 has_vesa_bios = FALSE;
783 vesa_adp_info = NULL;
785 vesa_vmode[0].vi_mode = EOT;
788 * If the VBE real mode interrupt vector is not found, try BIOS POST.
790 if (x86bios_get_intr(0x10) == 0) {
791 if (vesa_bios_post() != 0)
794 offs = x86bios_get_intr(0x10);
795 printf("VESA: interrupt vector installed (0x%x)\n",
796 BIOS_SADDRTOLADDR(offs));
800 x86bios_init_regs(®s);
803 vmbuf = x86bios_alloc(&offs, sizeof(*buf));
807 regs.R_ES = X86BIOS_PHYSTOSEG(offs);
808 regs.R_DI = X86BIOS_PHYSTOOFF(offs);
810 bcopy("VBE2", vmbuf, 4); /* try for VBE2 data */
811 x86bios_intr(®s, 0x10);
813 if (regs.R_AX != 0x004f || bcmp("VESA", vmbuf, 4) != 0)
816 vesa_adp_info = buf = malloc(sizeof(*buf), M_DEVBUF, M_WAITOK);
817 bcopy(vmbuf, buf, sizeof(*buf));
820 printf("VESA: information block\n");
821 hexdump(buf, sizeof(*buf), NULL, HD_OMIT_CHARS);
824 vers = buf->v_version = le16toh(buf->v_version);
825 buf->v_oemstr = le32toh(buf->v_oemstr);
826 buf->v_flags = le32toh(buf->v_flags);
827 buf->v_modetable = le32toh(buf->v_modetable);
828 buf->v_memsize = le16toh(buf->v_memsize);
829 buf->v_revision = le16toh(buf->v_revision);
830 buf->v_venderstr = le32toh(buf->v_venderstr);
831 buf->v_prodstr = le32toh(buf->v_prodstr);
832 buf->v_revstr = le32toh(buf->v_revstr);
835 printf("VESA: VBE version %d.%d is not supported; "
836 "version 1.2 or later is required.\n",
837 ((vers & 0xf000) >> 12) * 10 + ((vers & 0x0f00) >> 8),
838 ((vers & 0x00f0) >> 4) * 10 + (vers & 0x000f));
842 VESA_STRCPY(vesa_oemstr, buf->v_oemstr);
843 if (vers >= 0x0200) {
844 VESA_STRCPY(vesa_venderstr, buf->v_venderstr);
845 VESA_STRCPY(vesa_prodstr, buf->v_prodstr);
846 VESA_STRCPY(vesa_revstr, buf->v_revstr);
848 is_via_cle266 = strncmp(vesa_oemstr, VESA_VIA_CLE266,
849 sizeof(VESA_VIA_CLE266)) == 0;
851 if (buf->v_modetable == 0)
854 msize = (size_t)buf->v_memsize * 64 * 1024;
856 vesa_vmodetab = x86bios_offset(BIOS_SADDRTOLADDR(buf->v_modetable));
858 for (i = 0, modes = 0; (i < (M_VESA_MODE_MAX - M_VESA_BASE + 1)) &&
859 (vesa_vmodetab[i] != 0xffff); ++i) {
860 vesa_vmodetab[i] = le16toh(vesa_vmodetab[i]);
861 if (vesa_bios_get_mode(vesa_vmodetab[i], &vmode))
864 vmode.v_modeattr = le16toh(vmode.v_modeattr);
865 vmode.v_wgran = le16toh(vmode.v_wgran);
866 vmode.v_wsize = le16toh(vmode.v_wsize);
867 vmode.v_waseg = le16toh(vmode.v_waseg);
868 vmode.v_wbseg = le16toh(vmode.v_wbseg);
869 vmode.v_posfunc = le32toh(vmode.v_posfunc);
870 vmode.v_bpscanline = le16toh(vmode.v_bpscanline);
871 vmode.v_width = le16toh(vmode.v_width);
872 vmode.v_height = le16toh(vmode.v_height);
873 vmode.v_lfb = le32toh(vmode.v_lfb);
874 vmode.v_offscreen = le32toh(vmode.v_offscreen);
875 vmode.v_offscreensize = le16toh(vmode.v_offscreensize);
876 vmode.v_linbpscanline = le16toh(vmode.v_linbpscanline);
877 vmode.v_maxpixelclock = le32toh(vmode.v_maxpixelclock);
879 /* reject unsupported modes */
881 if ((vmode.v_modeattr &
882 (V_MODESUPP | V_MODEOPTINFO | V_MODENONVGA)) !=
883 (V_MODESUPP | V_MODEOPTINFO))
886 if ((vmode.v_modeattr & V_MODEOPTINFO) == 0) {
888 printf("Rejecting VESA %s mode: %d x %d x %d bpp "
890 vmode.v_modeattr & V_MODEGRAPHICS ?
892 vmode.v_width, vmode.v_height, vmode.v_bpp,
899 bsize = vesa_get_bpscanline(&vmode) * vmode.v_height;
900 if ((vmode.v_modeattr & V_MODEGRAPHICS) != 0)
901 bsize *= vmode.v_planes;
903 /* Does it have enough memory to support this mode? */
906 printf("Rejecting VESA %s mode: %d x %d x %d bpp "
907 " attr = %x, not enough memory\n",
908 vmode.v_modeattr & V_MODEGRAPHICS ?
910 vmode.v_width, vmode.v_height, vmode.v_bpp,
916 /* expand the array if necessary */
917 if (modes >= vesa_vmode_max) {
918 vesa_vmode_max += MODE_TABLE_DELTA;
919 p = malloc(sizeof(*vesa_vmode) * (vesa_vmode_max + 1),
922 printf("vesa_bios_init(): modes:%d, vesa_mode_max:%d\n",
923 modes, vesa_vmode_max);
926 bcopy(vesa_vmode, p, sizeof(*vesa_vmode)*modes);
927 free(vesa_vmode, M_DEVBUF);
933 printf("Found VESA %s mode: %d x %d x %d bpp\n",
934 vmode.v_modeattr & V_MODEGRAPHICS ? "graphics" : "text",
935 vmode.v_width, vmode.v_height, vmode.v_bpp);
938 if ((vmode.v_width & 0xff00) >> 8 == vmode.v_height - 1) {
939 vmode.v_width &= 0xff;
940 vmode.v_waseg = 0xb8000 >> 4;
944 /* copy some fields */
945 bzero(&vesa_vmode[modes], sizeof(vesa_vmode[modes]));
946 vesa_vmode[modes].vi_mode = vesa_vmodetab[i];
947 vesa_vmode[modes].vi_width = vmode.v_width;
948 vesa_vmode[modes].vi_height = vmode.v_height;
949 vesa_vmode[modes].vi_depth = vmode.v_bpp;
950 vesa_vmode[modes].vi_planes = vmode.v_planes;
951 vesa_vmode[modes].vi_cwidth = vmode.v_cwidth;
952 vesa_vmode[modes].vi_cheight = vmode.v_cheight;
953 vesa_vmode[modes].vi_window = (vm_offset_t)vmode.v_waseg << 4;
955 vesa_vmode[modes].vi_window_size = vmode.v_wsize * 1024;
956 vesa_vmode[modes].vi_window_gran = vmode.v_wgran * 1024;
957 if (vmode.v_modeattr & V_MODELFB)
958 vesa_vmode[modes].vi_buffer = vmode.v_lfb;
959 vesa_vmode[modes].vi_buffer_size = bsize;
960 vesa_vmode[modes].vi_mem_model =
961 vesa_translate_mmodel(vmode.v_memmodel);
962 switch (vesa_vmode[modes].vi_mem_model) {
963 case V_INFO_MM_DIRECT:
964 if ((vmode.v_modeattr & V_MODELFB) != 0 &&
966 vesa_vmode[modes].vi_pixel_fields[0] =
967 vmode.v_linredfieldpos;
968 vesa_vmode[modes].vi_pixel_fields[1] =
969 vmode.v_lingreenfieldpos;
970 vesa_vmode[modes].vi_pixel_fields[2] =
971 vmode.v_linbluefieldpos;
972 vesa_vmode[modes].vi_pixel_fields[3] =
973 vmode.v_linresfieldpos;
974 vesa_vmode[modes].vi_pixel_fsizes[0] =
975 vmode.v_linredmasksize;
976 vesa_vmode[modes].vi_pixel_fsizes[1] =
977 vmode.v_lingreenmasksize;
978 vesa_vmode[modes].vi_pixel_fsizes[2] =
979 vmode.v_linbluemasksize;
980 vesa_vmode[modes].vi_pixel_fsizes[3] =
981 vmode.v_linresmasksize;
983 vesa_vmode[modes].vi_pixel_fields[0] =
985 vesa_vmode[modes].vi_pixel_fields[1] =
986 vmode.v_greenfieldpos;
987 vesa_vmode[modes].vi_pixel_fields[2] =
988 vmode.v_bluefieldpos;
989 vesa_vmode[modes].vi_pixel_fields[3] =
991 vesa_vmode[modes].vi_pixel_fsizes[0] =
993 vesa_vmode[modes].vi_pixel_fsizes[1] =
994 vmode.v_greenmasksize;
995 vesa_vmode[modes].vi_pixel_fsizes[2] =
996 vmode.v_bluemasksize;
997 vesa_vmode[modes].vi_pixel_fsizes[3] =
1001 case V_INFO_MM_PACKED:
1002 vesa_vmode[modes].vi_pixel_size = (vmode.v_bpp + 7) / 8;
1005 vesa_vmode[modes].vi_flags =
1006 vesa_translate_flags(vmode.v_modeattr) | V_INFO_VESA;
1010 vesa_vmode[modes].vi_mode = EOT;
1013 printf("VESA: %d mode(s) found\n", modes);
1015 has_vesa_bios = (modes > 0);
1019 x86bios_free(vmbuf, sizeof(*buf));
1024 x86bios_free(vmbuf, sizeof(buf));
1025 if (vesa_adp_info != NULL) {
1026 free(vesa_adp_info, M_DEVBUF);
1027 vesa_adp_info = NULL;
1029 if (vesa_oemstr != NULL) {
1030 free(vesa_oemstr, M_DEVBUF);
1033 if (vesa_venderstr != NULL) {
1034 free(vesa_venderstr, M_DEVBUF);
1035 vesa_venderstr = NULL;
1037 if (vesa_prodstr != NULL) {
1038 free(vesa_prodstr, M_DEVBUF);
1039 vesa_prodstr = NULL;
1041 if (vesa_revstr != NULL) {
1042 free(vesa_revstr, M_DEVBUF);
1049 vesa_clear_modes(video_info_t *info, int color)
1051 while (info->vi_mode != EOT) {
1052 if ((info->vi_flags & V_INFO_COLOR) != color)
1061 vesa_configure(int flags)
1063 video_adapter_t *adp;
1070 if (flags & VIO_PROBE_ONLY)
1074 * If the VESA module has already been loaded, abort loading
1075 * the module this time.
1077 for (i = 0; (adp = vid_get_adapter(i)) != NULL; ++i) {
1078 if (adp->va_flags & V_ADP_VESA)
1080 if (adp->va_type == KD_VGA)
1085 * The VGA adapter is not found. This is because either
1086 * 1) the VGA driver has not been initialized, or 2) the VGA card
1087 * is not present. If 1) is the case, we shall defer
1088 * initialization for now and try again later.
1091 vga_sub_configure = vesa_configure;
1095 /* count number of registered adapters */
1096 for (++i; vid_get_adapter(i) != NULL; ++i)
1100 /* call VESA BIOS */
1102 if (vesa_bios_init()) {
1106 vesa_adp->va_flags |= V_ADP_VESA;
1108 /* remove conflicting modes if we have more than one adapter */
1110 vesa_clear_modes(vesa_vmode,
1111 (vesa_adp->va_flags & V_ADP_COLOR) ?
1115 if ((error = vesa_load_ioctl()) == 0) {
1116 prevvidsw = vidsw[vesa_adp->va_index];
1117 vidsw[vesa_adp->va_index] = &vesavidsw;
1118 vesa_init_done = TRUE;
1144 vesa_probe(int unit, video_adapter_t **adpp, void *arg, int flags)
1147 return ((*prevvidsw->probe)(unit, adpp, arg, flags));
1151 vesa_init(int unit, video_adapter_t *adp, int flags)
1154 return ((*prevvidsw->init)(unit, adp, flags));
1158 vesa_get_info(video_adapter_t *adp, int mode, video_info_t *info)
1162 if ((*prevvidsw->get_info)(adp, mode, info) == 0)
1165 if (adp != vesa_adp)
1168 mode = vesa_map_gen_mode_num(vesa_adp->va_type,
1169 vesa_adp->va_flags & V_ADP_COLOR, mode);
1170 for (i = 0; vesa_vmode[i].vi_mode != EOT; ++i) {
1171 if (vesa_vmode[i].vi_mode == NA)
1173 if (vesa_vmode[i].vi_mode == mode) {
1174 *info = vesa_vmode[i];
1182 vesa_query_mode(video_adapter_t *adp, video_info_t *info)
1186 if ((*prevvidsw->query_mode)(adp, info) == 0)
1188 if (adp != vesa_adp)
1191 for (i = 0; vesa_vmode[i].vi_mode != EOT; ++i) {
1192 if ((info->vi_width != 0)
1193 && (info->vi_width != vesa_vmode[i].vi_width))
1195 if ((info->vi_height != 0)
1196 && (info->vi_height != vesa_vmode[i].vi_height))
1198 if ((info->vi_cwidth != 0)
1199 && (info->vi_cwidth != vesa_vmode[i].vi_cwidth))
1201 if ((info->vi_cheight != 0)
1202 && (info->vi_cheight != vesa_vmode[i].vi_cheight))
1204 if ((info->vi_depth != 0)
1205 && (info->vi_depth != vesa_vmode[i].vi_depth))
1207 if ((info->vi_planes != 0)
1208 && (info->vi_planes != vesa_vmode[i].vi_planes))
1210 /* pixel format, memory model */
1211 if ((info->vi_flags != 0)
1212 && (info->vi_flags != vesa_vmode[i].vi_flags))
1214 *info = vesa_vmode[i];
1221 vesa_set_mode(video_adapter_t *adp, int mode)
1225 if (adp != vesa_adp)
1226 return ((*prevvidsw->set_mode)(adp, mode));
1228 mode = vesa_map_gen_mode_num(adp->va_type,
1229 adp->va_flags & V_ADP_COLOR, mode);
1231 printf("VESA: set_mode(): %d(%x) -> %d(%x)\n",
1232 adp->va_mode, adp->va_mode, mode, mode);
1235 * If the current mode is a VESA mode and the new mode is not,
1236 * restore the state of the adapter first by setting one of the
1237 * standard VGA mode, so that non-standard, extended SVGA registers
1238 * are set to the state compatible with the standard VGA modes.
1239 * Otherwise (*prevvidsw->set_mode)() may not be able to set up
1240 * the new mode correctly.
1242 if (VESA_MODE(adp->va_mode)) {
1243 if (!VESA_MODE(mode) &&
1244 (*prevvidsw->get_info)(adp, mode, &info) == 0) {
1245 if ((adp->va_flags & V_ADP_DAC8) != 0) {
1246 vesa_bios_set_dac(6);
1247 adp->va_flags &= ~V_ADP_DAC8;
1249 int10_set_mode(adp->va_initial_bios_mode);
1250 if (adp->va_info.vi_flags & V_INFO_LINEAR)
1251 pmap_unmapdev(adp->va_buffer,
1252 vesa_adp_info->v_memsize * 64 * 1024);
1254 * Once (*prevvidsw->get_info)() succeeded,
1255 * (*prevvidsw->set_mode)() below won't fail...
1260 /* we may not need to handle this mode after all... */
1261 if (!VESA_MODE(mode) && (*prevvidsw->set_mode)(adp, mode) == 0)
1264 /* is the new mode supported? */
1265 if (vesa_get_info(adp, mode, &info))
1267 /* assert(VESA_MODE(mode)); */
1270 printf("VESA: about to set a VESA mode...\n");
1272 /* don't use the linear frame buffer for text modes. XXX */
1273 if (!(info.vi_flags & V_INFO_GRAPHICS))
1274 info.vi_flags &= ~V_INFO_LINEAR;
1276 if (vesa_bios_set_mode(mode | ((info.vi_flags & V_INFO_LINEAR) ? 0x4000 : 0)))
1279 /* Palette format is reset by the above VBE function call. */
1280 adp->va_flags &= ~V_ADP_DAC8;
1282 if ((vesa_adp_info->v_flags & V_DAC8) != 0 &&
1283 (info.vi_flags & V_INFO_GRAPHICS) != 0 &&
1284 vesa_bios_set_dac(8) > 6)
1285 adp->va_flags |= V_ADP_DAC8;
1287 if (adp->va_info.vi_flags & V_INFO_LINEAR)
1288 pmap_unmapdev(adp->va_buffer,
1289 vesa_adp_info->v_memsize * 64 * 1024);
1292 printf("VESA: mode set!\n");
1294 vesa_adp->va_mode = mode;
1295 vesa_adp->va_flags &= ~V_ADP_COLOR;
1296 vesa_adp->va_flags |=
1297 (info.vi_flags & V_INFO_COLOR) ? V_ADP_COLOR : 0;
1298 vesa_adp->va_crtc_addr =
1299 (vesa_adp->va_flags & V_ADP_COLOR) ? COLOR_CRTC : MONO_CRTC;
1301 vesa_adp->va_line_width = info.vi_buffer_size / info.vi_height;
1302 if ((info.vi_flags & V_INFO_GRAPHICS) != 0)
1303 vesa_adp->va_line_width /= info.vi_planes;
1305 #ifdef MODE_TABLE_BROKEN
1306 /* If VBE function returns bigger bytes per scan line, use it. */
1308 int bpsl = vesa_bios_get_line_length();
1309 if (bpsl > vesa_adp->va_line_width) {
1310 vesa_adp->va_line_width = bpsl;
1311 info.vi_buffer_size = bpsl * info.vi_height;
1312 if ((info.vi_flags & V_INFO_GRAPHICS) != 0)
1313 info.vi_buffer_size *= info.vi_planes;
1318 if (info.vi_flags & V_INFO_LINEAR) {
1320 printf("VESA: setting up LFB\n");
1322 vesa_adp->va_buffer =
1323 (vm_offset_t)pmap_mapdev_attr(info.vi_buffer,
1324 vesa_adp_info->v_memsize * 64 * 1024, PAT_WRITE_COMBINING);
1325 vesa_adp->va_window = vesa_adp->va_buffer;
1326 vesa_adp->va_window_size = info.vi_buffer_size / info.vi_planes;
1327 vesa_adp->va_window_gran = info.vi_buffer_size / info.vi_planes;
1329 vesa_adp->va_buffer = 0;
1330 vesa_adp->va_window = (vm_offset_t)x86bios_offset(info.vi_window);
1331 vesa_adp->va_window_size = info.vi_window_size;
1332 vesa_adp->va_window_gran = info.vi_window_gran;
1334 vesa_adp->va_buffer_size = info.vi_buffer_size;
1335 vesa_adp->va_window_orig = 0;
1336 vesa_adp->va_disp_start.x = 0;
1337 vesa_adp->va_disp_start.y = 0;
1339 printf("vesa_set_mode(): vi_width:%d, line_width:%d\n",
1340 info.vi_width, vesa_adp->va_line_width);
1342 bcopy(&info, &vesa_adp->va_info, sizeof(vesa_adp->va_info));
1344 /* move hardware cursor out of the way */
1345 (*vidsw[vesa_adp->va_index]->set_hw_cursor)(vesa_adp, -1, -1);
1351 vesa_save_font(video_adapter_t *adp, int page, int fontsize, int fontwidth,
1352 u_char *data, int ch, int count)
1355 return ((*prevvidsw->save_font)(adp, page, fontsize, fontwidth, data,
1360 vesa_load_font(video_adapter_t *adp, int page, int fontsize, int fontwidth,
1361 u_char *data, int ch, int count)
1364 return ((*prevvidsw->load_font)(adp, page, fontsize, fontwidth, data,
1369 vesa_show_font(video_adapter_t *adp, int page)
1372 return ((*prevvidsw->show_font)(adp, page));
1376 vesa_save_palette(video_adapter_t *adp, u_char *palette)
1380 if (adp == vesa_adp && VESA_MODE(adp->va_mode)) {
1381 bits = (adp->va_flags & V_ADP_DAC8) != 0 ? 8 : 6;
1382 if (vesa_bios_save_palette(0, 256, palette, bits) == 0)
1386 return ((*prevvidsw->save_palette)(adp, palette));
1390 vesa_load_palette(video_adapter_t *adp, u_char *palette)
1394 if (adp == vesa_adp && VESA_MODE(adp->va_mode)) {
1395 bits = (adp->va_flags & V_ADP_DAC8) != 0 ? 8 : 6;
1396 if (vesa_bios_load_palette(0, 256, palette, bits) == 0)
1400 return ((*prevvidsw->load_palette)(adp, palette));
1404 vesa_set_border(video_adapter_t *adp, int color)
1407 return ((*prevvidsw->set_border)(adp, color));
1411 vesa_save_state(video_adapter_t *adp, void *p, size_t size)
1414 if (adp != vesa_adp)
1415 return ((*prevvidsw->save_state)(adp, p, size));
1417 if (vesa_state_buf_size == -1) {
1418 vesa_state_buf_size = vesa_bios_state_buf_size();
1419 if (vesa_state_buf_size == 0)
1423 return (offsetof(adp_state_t, regs) + vesa_state_buf_size);
1424 else if (size < (offsetof(adp_state_t, regs) + vesa_state_buf_size))
1427 ((adp_state_t *)p)->sig = V_STATE_SIG;
1428 bzero(((adp_state_t *)p)->regs, vesa_state_buf_size);
1429 return (vesa_bios_save_restore(STATE_SAVE, ((adp_state_t *)p)->regs,
1430 vesa_state_buf_size));
1434 vesa_load_state(video_adapter_t *adp, void *p)
1437 if ((adp != vesa_adp) || (((adp_state_t *)p)->sig != V_STATE_SIG))
1438 return ((*prevvidsw->load_state)(adp, p));
1440 if (vesa_state_buf_size <= 0)
1443 /* Try BIOS POST to restore a sane state. */
1444 (void)vesa_bios_post();
1445 (void)int10_set_mode(adp->va_initial_bios_mode);
1446 (void)vesa_set_mode(adp, adp->va_mode);
1448 return (vesa_bios_save_restore(STATE_LOAD, ((adp_state_t *)p)->regs,
1449 vesa_state_buf_size));
1454 vesa_get_origin(video_adapter_t *adp, off_t *offset)
1458 x86bios_init_regs(®s);
1462 x86bios_intr(®s, 0x10);
1464 if (regs.R_AX != 0x004f)
1466 *offset = regs.DX * adp->va_window_gran;
1473 vesa_set_origin(video_adapter_t *adp, off_t offset)
1478 * This function should return as quickly as possible to
1479 * maintain good performance of the system. For this reason,
1480 * error checking is kept minimal and let the VESA BIOS to
1483 if (adp != vesa_adp)
1484 return ((*prevvidsw->set_win_org)(adp, offset));
1486 /* if this is a linear frame buffer, do nothing */
1487 if (adp->va_info.vi_flags & V_INFO_LINEAR)
1490 if (adp->va_window_gran == 0)
1493 x86bios_init_regs(®s);
1495 regs.R_DX = offset / adp->va_window_gran;
1497 x86bios_intr(®s, 0x10);
1499 if (regs.R_AX != 0x004f)
1502 x86bios_init_regs(®s);
1505 regs.R_DX = offset / adp->va_window_gran;
1506 x86bios_intr(®s, 0x10);
1508 adp->va_window_orig = (offset/adp->va_window_gran)*adp->va_window_gran;
1509 return (0); /* XXX */
1513 vesa_read_hw_cursor(video_adapter_t *adp, int *col, int *row)
1516 return ((*prevvidsw->read_hw_cursor)(adp, col, row));
1520 vesa_set_hw_cursor(video_adapter_t *adp, int col, int row)
1523 return ((*prevvidsw->set_hw_cursor)(adp, col, row));
1527 vesa_set_hw_cursor_shape(video_adapter_t *adp, int base, int height,
1528 int celsize, int blink)
1531 return ((*prevvidsw->set_hw_cursor_shape)(adp, base, height, celsize,
1536 vesa_blank_display(video_adapter_t *adp, int mode)
1539 /* XXX: use VESA DPMS */
1540 return ((*prevvidsw->blank_display)(adp, mode));
1544 vesa_mmap(video_adapter_t *adp, vm_offset_t offset, vm_paddr_t *paddr,
1549 printf("vesa_mmap(): window:0x%tx, buffer:0x%tx, offset:0x%tx\n",
1550 adp->va_info.vi_window, adp->va_info.vi_buffer, offset);
1553 if ((adp == vesa_adp) &&
1554 (adp->va_info.vi_flags & V_INFO_LINEAR) != 0) {
1555 /* va_window_size == va_buffer_size/vi_planes */
1556 /* XXX: is this correct? */
1557 if (offset > adp->va_window_size - PAGE_SIZE)
1559 *paddr = adp->va_info.vi_buffer + offset;
1562 return ((*prevvidsw->mmap)(adp, offset, paddr, prot));
1566 vesa_clear(video_adapter_t *adp)
1569 return ((*prevvidsw->clear)(adp));
1573 vesa_fill_rect(video_adapter_t *adp, int val, int x, int y, int cx, int cy)
1576 return ((*prevvidsw->fill_rect)(adp, val, x, y, cx, cy));
1580 vesa_bitblt(video_adapter_t *adp,...)
1588 get_palette(video_adapter_t *adp, int base, int count,
1589 u_char *red, u_char *green, u_char *blue, u_char *trans)
1597 if (base < 0 || base >= 256 || count < 0 || count > 256)
1599 if ((base + count) > 256)
1601 if (!VESA_MODE(adp->va_mode))
1604 bits = (adp->va_flags & V_ADP_DAC8) != 0 ? 8 : 6;
1605 r = malloc(count * 3, M_DEVBUF, M_WAITOK);
1608 error = vesa_bios_save_palette2(base, count, r, g, b, bits);
1610 copyout(r, red, count);
1611 copyout(g, green, count);
1612 copyout(b, blue, count);
1613 if (trans != NULL) {
1615 copyout(r, trans, count);
1624 set_palette(video_adapter_t *adp, int base, int count,
1625 u_char *red, u_char *green, u_char *blue, u_char *trans)
1633 if (base < 0 || base >= 256 || count < 0 || count > 256)
1635 if ((base + count) > 256)
1637 if (!VESA_MODE(adp->va_mode))
1640 bits = (adp->va_flags & V_ADP_DAC8) != 0 ? 8 : 6;
1641 r = malloc(count * 3, M_DEVBUF, M_WAITOK);
1644 copyin(red, r, count);
1645 copyin(green, g, count);
1646 copyin(blue, b, count);
1648 error = vesa_bios_load_palette2(base, count, r, g, b, bits);
1655 vesa_ioctl(video_adapter_t *adp, u_long cmd, caddr_t arg)
1659 if (adp != vesa_adp)
1660 return ((*prevvidsw->ioctl)(adp, cmd, arg));
1663 case FBIO_SETWINORG: /* set frame buffer window origin */
1664 if (!VESA_MODE(adp->va_mode))
1665 return (*prevvidsw->ioctl)(adp, cmd, arg);
1666 return (vesa_set_origin(adp, *(off_t *)arg) ? ENODEV : 0);
1668 case FBIO_SETDISPSTART: /* set display start address */
1669 if (!VESA_MODE(adp->va_mode))
1670 return ((*prevvidsw->ioctl)(adp, cmd, arg));
1671 if (vesa_bios_set_start(((video_display_start_t *)arg)->x,
1672 ((video_display_start_t *)arg)->y))
1674 adp->va_disp_start.x = ((video_display_start_t *)arg)->x;
1675 adp->va_disp_start.y = ((video_display_start_t *)arg)->y;
1678 case FBIO_SETLINEWIDTH: /* set line length in pixel */
1679 if (!VESA_MODE(adp->va_mode))
1680 return ((*prevvidsw->ioctl)(adp, cmd, arg));
1681 if (vesa_bios_set_line_length(*(u_int *)arg, &bytes, NULL))
1683 adp->va_line_width = bytes;
1685 printf("new line width:%d\n", adp->va_line_width);
1689 case FBIO_GETPALETTE: /* get color palette */
1690 if (get_palette(adp, ((video_color_palette_t *)arg)->index,
1691 ((video_color_palette_t *)arg)->count,
1692 ((video_color_palette_t *)arg)->red,
1693 ((video_color_palette_t *)arg)->green,
1694 ((video_color_palette_t *)arg)->blue,
1695 ((video_color_palette_t *)arg)->transparent))
1696 return ((*prevvidsw->ioctl)(adp, cmd, arg));
1700 case FBIO_SETPALETTE: /* set color palette */
1701 if (set_palette(adp, ((video_color_palette_t *)arg)->index,
1702 ((video_color_palette_t *)arg)->count,
1703 ((video_color_palette_t *)arg)->red,
1704 ((video_color_palette_t *)arg)->green,
1705 ((video_color_palette_t *)arg)->blue,
1706 ((video_color_palette_t *)arg)->transparent))
1707 return ((*prevvidsw->ioctl)(adp, cmd, arg));
1710 case FBIOGETCMAP: /* get color palette */
1711 if (get_palette(adp, ((struct fbcmap *)arg)->index,
1712 ((struct fbcmap *)arg)->count,
1713 ((struct fbcmap *)arg)->red,
1714 ((struct fbcmap *)arg)->green,
1715 ((struct fbcmap *)arg)->blue, NULL))
1716 return ((*prevvidsw->ioctl)(adp, cmd, arg));
1719 case FBIOPUTCMAP: /* set color palette */
1720 if (set_palette(adp, ((struct fbcmap *)arg)->index,
1721 ((struct fbcmap *)arg)->count,
1722 ((struct fbcmap *)arg)->red,
1723 ((struct fbcmap *)arg)->green,
1724 ((struct fbcmap *)arg)->blue, NULL))
1725 return ((*prevvidsw->ioctl)(adp, cmd, arg));
1729 return ((*prevvidsw->ioctl)(adp, cmd, arg));
1734 vesa_diag(video_adapter_t *adp, int level)
1738 /* call the previous handler first */
1739 error = (*prevvidsw->diag)(adp, level);
1743 if (adp != vesa_adp)
1753 vesa_bios_info(int level)
1756 struct vesa_mode vmode;
1761 vers = vesa_adp_info->v_version;
1764 /* general adapter information */
1766 "VESA: v%d.%d, %dk memory, flags:0x%x, mode table:%p (%x)\n",
1767 (vers >> 12) * 10 + ((vers & 0x0f00) >> 8),
1768 ((vers & 0x00f0) >> 4) * 10 + (vers & 0x000f),
1769 vesa_adp_info->v_memsize * 64, vesa_adp_info->v_flags,
1770 vesa_vmodetab, vesa_adp_info->v_modetable);
1773 if (vesa_oemstr != NULL)
1774 printf("VESA: %s\n", vesa_oemstr);
1780 if (vers >= 0x0200 && bootverbose) {
1781 /* vender name, product name, product revision */
1782 printf("VESA: %s %s %s\n",
1783 (vesa_venderstr != NULL) ? vesa_venderstr : "unknown",
1784 (vesa_prodstr != NULL) ? vesa_prodstr : "unknown",
1785 (vesa_revstr != NULL) ? vesa_revstr : "?");
1789 /* mode information */
1791 (i < (M_VESA_MODE_MAX - M_VESA_BASE + 1))
1792 && (vesa_vmodetab[i] != 0xffff); ++i) {
1793 if (vesa_bios_get_mode(vesa_vmodetab[i], &vmode))
1796 /* print something for diagnostic purpose */
1797 printf("VESA: mode:0x%03x, flags:0x%04x",
1798 vesa_vmodetab[i], vmode.v_modeattr);
1799 if (vmode.v_modeattr & V_MODEOPTINFO) {
1800 if (vmode.v_modeattr & V_MODEGRAPHICS) {
1801 printf(", G %dx%dx%d %d, ",
1802 vmode.v_width, vmode.v_height,
1803 vmode.v_bpp, vmode.v_planes);
1805 printf(", T %dx%d, ",
1806 vmode.v_width, vmode.v_height);
1808 printf("font:%dx%d, ",
1809 vmode.v_cwidth, vmode.v_cheight);
1810 printf("pages:%d, mem:%d",
1811 vmode.v_ipages + 1, vmode.v_memmodel);
1813 if (vmode.v_modeattr & V_MODELFB) {
1814 printf("\nVESA: LFB:0x%x, off:0x%x, off_size:0x%x",
1815 vmode.v_lfb, vmode.v_offscreen,
1816 vmode.v_offscreensize*1024);
1819 printf("VESA: window A:0x%x (%x), window B:0x%x (%x), ",
1820 vmode.v_waseg, vmode.v_waattr,
1821 vmode.v_wbseg, vmode.v_wbattr);
1822 printf("size:%dk, gran:%dk\n",
1823 vmode.v_wsize, vmode.v_wgran);
1825 #endif /* VESA_DEBUG > 1 */
1830 /* module loading */
1841 /* locate a VGA adapter */
1844 error = vesa_configure(0);
1848 vesa_bios_info(bootverbose);
1856 u_char palette[256*3];
1860 /* if the adapter is currently in a VESA mode, don't unload */
1861 if ((vesa_adp != NULL) && VESA_MODE(vesa_adp->va_mode))
1864 * FIXME: if there is at least one vty which is in a VESA mode,
1865 * we shouldn't be unloading! XXX
1869 if ((error = vesa_unload_ioctl()) == 0) {
1870 if (vesa_adp != NULL) {
1871 if ((vesa_adp->va_flags & V_ADP_DAC8) != 0) {
1872 vesa_bios_save_palette(0, 256, palette, 8);
1873 vesa_bios_set_dac(6);
1874 vesa_adp->va_flags &= ~V_ADP_DAC8;
1875 vesa_bios_load_palette(0, 256, palette, 6);
1877 vesa_adp->va_flags &= ~V_ADP_VESA;
1878 vidsw[vesa_adp->va_index] = prevvidsw;
1883 if (vesa_adp_info != NULL)
1884 free(vesa_adp_info, M_DEVBUF);
1885 if (vesa_oemstr != NULL)
1886 free(vesa_oemstr, M_DEVBUF);
1887 if (vesa_venderstr != NULL)
1888 free(vesa_venderstr, M_DEVBUF);
1889 if (vesa_prodstr != NULL)
1890 free(vesa_prodstr, M_DEVBUF);
1891 if (vesa_revstr != NULL)
1892 free(vesa_revstr, M_DEVBUF);
1893 if (vesa_vmode != &vesa_vmode_empty)
1894 free(vesa_vmode, M_DEVBUF);
1899 vesa_mod_event(module_t mod, int type, void *data)
1904 return (vesa_load());
1906 return (vesa_unload());
1908 return (EOPNOTSUPP);
1911 static moduledata_t vesa_mod = {
1917 DECLARE_MODULE(vesa, vesa_mod, SI_SUB_DRIVERS, SI_ORDER_MIDDLE);
1918 MODULE_DEPEND(vesa, x86bios, 1, 1, 1);
1920 #endif /* VGA_NO_MODE_CHANGE */