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>
36 #include <sys/systm.h>
37 #include <sys/kernel.h>
38 #include <sys/module.h>
39 #include <sys/malloc.h>
43 #include <vm/vm_extern.h>
44 #include <vm/vm_kern.h>
45 #include <vm/vm_param.h>
48 #include <dev/fb/vesa.h>
50 #include <dev/fb/fbreg.h>
51 #include <dev/fb/vgareg.h>
53 #include <isa/isareg.h>
54 #include <machine/cpufunc.h>
56 #include <contrib/x86emu/x86emu.h>
57 #include <contrib/x86emu/x86emu_regs.h>
59 #define VESA_VIA_CLE266 "VIA CLE266\r\n"
65 /* VESA video adapter state buffer stub */
68 #define V_STATE_SIG 0x61736576
71 typedef struct adp_state adp_state_t;
73 /* VESA video adapter */
74 static video_adapter_t *vesa_adp = NULL;
75 static int vesa_state_buf_size = 0;
76 #define VESA_X86EMU_BUFSIZE (3 * PAGE_SIZE)
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);
109 static struct x86emu vesa_emu;
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_get_mode(int mode, struct vesa_mode *vmode);
167 static int vesa_bios_set_mode(int mode);
168 static int vesa_bios_get_dac(void);
169 static int vesa_bios_set_dac(int bits);
170 static int vesa_bios_save_palette(int start, int colors, u_char *palette,
172 static int vesa_bios_save_palette2(int start, int colors, u_char *r, u_char *g,
173 u_char *b, int bits);
174 static int vesa_bios_load_palette(int start, int colors, u_char *palette,
177 static int vesa_bios_load_palette2(int start, int colors, u_char *r, u_char *g,
178 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 int vesa_bios_state_buf_size(void);
190 static int vesa_bios_save_restore(int code, void *p, size_t size);
191 static int vesa_bios_get_line_length(void);
192 static int vesa_bios_set_line_length(int pixel, int *bytes, int *lines);
194 static int vesa_bios_get_start(int *x, int *y);
196 static int vesa_bios_set_start(int x, int y);
197 static int vesa_map_gen_mode_num(int type, int color, int mode);
198 static int vesa_translate_flags(u_int16_t vflags);
199 static int vesa_translate_mmodel(u_int8_t vmodel);
200 static int vesa_bios_init(void);
201 static void vesa_clear_modes(video_info_t *info, int color);
202 static vm_offset_t vesa_map_buffer(u_int paddr, size_t size);
203 static void vesa_unmap_buffer(vm_offset_t vaddr, size_t size);
206 static int vesa_get_origin(video_adapter_t *adp, off_t *offset);
209 #define SEG_ADDR(x) (((x) >> 4) & 0x00F000)
210 #define SEG_OFF(x) ((x) & 0x0FFFF)
212 #if _BYTE_ORDER == _LITTLE_ENDIAN
216 #define B_O16(x) ((((x) & 0xff) << 8) | (((x) & 0xff) >> 8))
217 #define B_O32(x) ((((x) & 0xff) << 24) | (((x) & 0xff00) << 8) \
218 | (((x) & 0xff0000) >> 8) | (((x) & 0xff000000) >> 24))
221 #define L_ADD(x) (B_O32(x) & 0xffff) + ((B_O32(x) >> 12) & 0xffff00)
222 #define FARP(p) (((unsigned)(p & 0xffff0000) >> 12) | (p & 0xffff))
224 #define REALOFF(x) (x*4096)
226 static unsigned char *emumem = NULL;
229 vm86_emu_inb(struct x86emu *emu, uint16_t port)
231 if (port == 0xb2) /* APM scratch register */
233 if (port >= 0x80 && port < 0x88) /* POST status register */
239 vm86_emu_inw(struct x86emu *emu, uint16_t port)
241 if (port >= 0x80 && port < 0x88) /* POST status register */
247 vm86_emu_inl(struct x86emu *emu, uint16_t port)
249 if (port >= 0x80 && port < 0x88) /* POST status register */
255 vm86_emu_outb(struct x86emu *emu, uint16_t port, uint8_t val)
257 if (port == 0xb2) /* APM scratch register */
259 if (port >= 0x80 && port < 0x88) /* POST status register */
265 vm86_emu_outw(struct x86emu *emu, uint16_t port, uint16_t val)
267 if (port >= 0x80 && port < 0x88) /* POST status register */
273 vm86_emu_outl(struct x86emu *emu, uint16_t port, uint32_t val)
275 if (port >= 0x80 && port < 0x88) /* POST status register */
281 dump_buffer(u_char *buf, size_t len)
285 for(i = 0; i < len;) {
286 printf("%02x ", buf[i]);
292 /* INT 10 BIOS calls */
294 int10_set_mode(int mode)
296 vesa_emu.x86.R_EAX = 0x0000 | mode;
297 x86emu_exec_intr(&vesa_emu, 0x10);
302 /* VESA BIOS calls */
304 vesa_bios_get_mode(int mode, struct vesa_mode *vmode)
308 vesa_emu.x86.R_EAX = 0x4f01;
309 vesa_emu.x86.R_ECX = mode;
311 buf = (emumem + REALOFF(3));
312 vesa_emu.x86.R_ES = SEG_ADDR(REALOFF(3));
313 vesa_emu.x86.R_DI = SEG_OFF(REALOFF(3));
315 x86emu_exec_intr(&vesa_emu, 0x10);
317 if ((vesa_emu.x86.R_AX & 0xff) != 0x4f)
320 bcopy(buf, vmode, sizeof(*vmode));
326 vesa_bios_set_mode(int mode)
328 vesa_emu.x86.R_EAX = 0x4f02;
329 vesa_emu.x86.R_EBX = mode;
331 x86emu_exec_intr(&vesa_emu, 0x10);
333 return ((vesa_emu.x86.R_AX & 0xff) != 0x4f);
337 vesa_bios_get_dac(void)
339 vesa_emu.x86.R_EAX = 0x4f08;
340 vesa_emu.x86.R_EBX = 1;
342 x86emu_exec_intr(&vesa_emu, 0x10);
344 if ((vesa_emu.x86.R_AX & 0xff) != 0x4f)
347 return ((vesa_emu.x86.R_EBX >> 8) & 0x00ff);
351 vesa_bios_set_dac(int bits)
353 vesa_emu.x86.R_EAX = 0x4f08;
354 vesa_emu.x86.R_EBX = (bits << 8);
356 x86emu_exec_intr(&vesa_emu, 0x10);
358 if ((vesa_emu.x86.R_AX & 0xff) != 0x4f)
361 return ((vesa_emu.x86.R_EBX >> 8) & 0x00ff);
365 vesa_bios_save_palette(int start, int colors, u_char *palette, int bits)
370 vesa_emu.x86.R_EAX = 0x4f09;
371 vesa_emu.x86.R_EBX = 1;
372 vesa_emu.x86.R_ECX = colors;
373 vesa_emu.x86.R_EDX = start;
375 vesa_emu.x86.R_ES = SEG_ADDR(REALOFF(2));
376 vesa_emu.x86.R_DI = SEG_OFF(REALOFF(2));
378 p = emumem + REALOFF(2);
380 x86emu_exec_intr(&vesa_emu, 0x10);
382 if ((vesa_emu.x86.R_AX & 0xff) != 0x4f)
386 for (i = 0; i < colors; ++i) {
387 palette[i*3] = p[i*4 + 2] << bits;
388 palette[i*3 + 1] = p[i*4 + 1] << bits;
389 palette[i*3 + 2] = p[i*4] << bits;
395 vesa_bios_save_palette2(int start, int colors, u_char *r, u_char *g, u_char *b,
401 vesa_emu.x86.R_EAX = 0x4f09;
402 vesa_emu.x86.R_EBX = 1;
403 vesa_emu.x86.R_ECX = colors;
404 vesa_emu.x86.R_EDX = start;
406 vesa_emu.x86.R_ES = SEG_ADDR(REALOFF(2));
407 vesa_emu.x86.R_DI = SEG_OFF(REALOFF(2));
409 p = emumem + REALOFF(2);
411 x86emu_exec_intr(&vesa_emu, 0x10);
413 if ((vesa_emu.x86.R_AX & 0xff) != 0x4f)
417 for (i = 0; i < colors; ++i) {
418 r[i] = p[i*4 + 2] << bits;
419 g[i] = p[i*4 + 1] << bits;
420 b[i] = p[i*4] << bits;
426 vesa_bios_load_palette(int start, int colors, u_char *palette, int bits)
431 p = (emumem + REALOFF(2));
434 for (i = 0; i < colors; ++i) {
435 p[i*4] = palette[i*3 + 2] >> bits;
436 p[i*4 + 1] = palette[i*3 + 1] >> bits;
437 p[i*4 + 2] = palette[i*3] >> bits;
441 vesa_emu.x86.R_EAX = 0x4f09;
442 vesa_emu.x86.R_EBX = 0;
443 vesa_emu.x86.R_ECX = colors;
444 vesa_emu.x86.R_EDX = start;
446 vesa_emu.x86.R_ES = SEG_ADDR(REALOFF(2));
447 vesa_emu.x86.R_DI = SEG_OFF(REALOFF(2));
449 x86emu_exec_intr(&vesa_emu, 0x10);
451 return ((vesa_emu.x86.R_AX & 0xff) != 0x4f);
456 vesa_bios_load_palette2(int start, int colors, u_char *r, u_char *g, u_char *b,
462 p = (emumem + REALOFF(2));
465 for (i = 0; i < colors; ++i) {
466 p[i*4] = b[i] >> bits;
467 p[i*4 + 1] = g[i] >> bits;
468 p[i*4 + 2] = r[i] >> bits;
472 vesa_emu.x86.R_EAX = 0x4f09;
473 vesa_emu.x86.R_EBX = 0;
474 vesa_emu.x86.R_ECX = colors;
475 vesa_emu.x86.R_EDX = start;
477 vesa_emu.x86.R_ES = SEG_ADDR(REALOFF(2));
478 vesa_emu.x86.R_DI = SEG_OFF(REALOFF(2));
480 x86emu_exec_intr(&vesa_emu, 0x10);
482 return ((vesa_emu.x86.R_AX & 0xff) != 0x4f)
487 vesa_bios_state_buf_size(void)
489 vesa_emu.x86.R_EAX = 0x4f04;
490 vesa_emu.x86.R_ECX = STATE_ALL;
491 vesa_emu.x86.R_EDX = STATE_SIZE;
493 x86emu_exec_intr(&vesa_emu, 0x10);
495 if ((vesa_emu.x86.R_AX & 0xff) != 0x4f)
498 return vesa_emu.x86.R_BX*64;
502 vesa_bios_save_restore(int code, void *p, size_t size)
506 if (size > VESA_X86EMU_BUFSIZE)
509 vesa_emu.x86.R_EAX = 0x4f04;
510 vesa_emu.x86.R_ECX = STATE_ALL;
511 vesa_emu.x86.R_EDX = code;
513 buf = emumem + REALOFF(2);
515 vesa_emu.x86.R_ES = SEG_ADDR(REALOFF(2));
516 vesa_emu.x86.R_DI = SEG_OFF(REALOFF(2));
520 x86emu_exec_intr(&vesa_emu, 0x10);
524 return ((vesa_emu.x86.R_AX & 0xff) != 0x4f);
528 vesa_bios_get_line_length(void)
530 vesa_emu.x86.R_EAX = 0x4f06;
531 vesa_emu.x86.R_EBX = 1;
533 x86emu_exec_intr(&vesa_emu, 0x10);
535 if ((vesa_emu.x86.R_AX & 0xff) != 0x4f)
537 return vesa_emu.x86.R_BX;
541 vesa_bios_set_line_length(int pixel, int *bytes, int *lines)
543 vesa_emu.x86.R_EAX = 0x4f06;
544 vesa_emu.x86.R_EBX = 0;
545 vesa_emu.x86.R_ECX = pixel;
547 x86emu_exec_intr(&vesa_emu, 0x10);
550 printf("bx:%d, cx:%d, dx:%d\n", vesa_emu.x86.R_BX, vesa_emu.x86.R_CX, vesa_emu.x86.R_DX);
552 if ((vesa_emu.x86.R_AX & 0xff) != 0x4f)
556 *bytes = vesa_emu.x86.R_BX;
558 *lines = vesa_emu.x86.R_DX;
565 vesa_bios_get_start(int *x, int *y)
567 vesa_emu.x86.R_EAX = 0x4f07;
568 vesa_emu.x86.R_EBX = 1;
570 x86emu_exec_intr(&vesa_emu, 0x10);
572 if ((vesa_emu.x86.R_AX & 0xff) != 0x4f)
575 *x = vesa_emu.x86.R_CX;
576 *y = vesa_emu.x86.R_DX;
583 vesa_bios_set_start(int x, int y)
585 vesa_emu.x86.R_EAX = 0x4f07;
586 vesa_emu.x86.R_EBX = 0x80;
587 vesa_emu.x86.R_EDX = y;
588 vesa_emu.x86.R_ECX = x;
590 x86emu_exec_intr(&vesa_emu, 0x10);
592 return ((vesa_emu.x86.R_AX & 0xff) != 0x4f);
595 /* map a generic video mode to a known mode */
597 vesa_map_gen_mode_num(int type, int color, int mode)
603 { M_TEXT_132x25, M_VESA_C132x25 },
604 { M_TEXT_132x43, M_VESA_C132x43 },
605 { M_TEXT_132x50, M_VESA_C132x50 },
606 { M_TEXT_132x60, M_VESA_C132x60 },
610 for (i = 0; i < sizeof(mode_map)/sizeof(mode_map[0]); ++i) {
611 if (mode_map[i].from == mode)
612 return mode_map[i].to;
618 vesa_translate_flags(u_int16_t vflags)
625 { V_MODECOLOR, V_INFO_COLOR, 0 },
626 { V_MODEGRAPHICS, V_INFO_GRAPHICS, 0 },
627 { V_MODELFB, V_INFO_LINEAR, 0 },
632 for (flags = 0, i = 0; i < sizeof(ftable)/sizeof(ftable[0]); ++i) {
633 flags |= (vflags & ftable[i].mask) ?
634 ftable[i].set : ftable[i].reset;
640 vesa_translate_mmodel(u_int8_t vmodel)
646 { V_MMTEXT, V_INFO_MM_TEXT },
647 { V_MMCGA, V_INFO_MM_CGA },
648 { V_MMHGC, V_INFO_MM_HGC },
649 { V_MMEGA, V_INFO_MM_PLANAR },
650 { V_MMPACKED, V_INFO_MM_PACKED },
651 { V_MMDIRCOLOR, V_INFO_MM_DIRECT },
655 for (i = 0; mtable[i].mmodel >= 0; ++i) {
656 if (mtable[i].vmodel == vmodel)
657 return mtable[i].mmodel;
659 return V_INFO_MM_OTHER;
665 static struct vesa_info buf;
666 struct vesa_mode vmode;
676 has_vesa_bios = FALSE;
677 vesa_adp_info = NULL;
679 vesa_vmode[0].vi_mode = EOT;
681 vmbuf = (emumem + REALOFF(2));
682 bcopy("VBE2", vmbuf, 4); /* try for VBE2 data */
684 vesa_emu.x86.R_EAX = 0x4f00;
685 vesa_emu.x86.R_ES = SEG_ADDR(REALOFF(2));
686 vesa_emu.x86.R_DI = SEG_OFF(REALOFF(2));
688 x86emu_exec_intr(&vesa_emu, 0x10);
690 if (((vesa_emu.x86.R_AX & 0xff) != 0x4f) || bcmp("VESA", vmbuf, 4))
693 bcopy(vmbuf, &buf, sizeof(buf));
695 vesa_adp_info = &buf;
697 printf("VESA: information block\n");
698 dump_buffer((u_char *)&buf, sizeof(buf));
700 if (vesa_adp_info->v_version < 0x0102) {
701 printf("VESA: VBE version %d.%d is not supported; "
702 "version 1.2 or later is required.\n",
703 ((vesa_adp_info->v_version & 0xf000) >> 12) * 10
704 + ((vesa_adp_info->v_version & 0x0f00) >> 8),
705 ((vesa_adp_info->v_version & 0x00f0) >> 4) * 10
706 + (vesa_adp_info->v_version & 0x000f));
710 vesa_oemstr = (char *)(emumem + L_ADD(vesa_adp_info->v_oemstr));
712 is_via_cle266 = strcmp(vesa_oemstr, VESA_VIA_CLE266) == 0;
714 if (vesa_adp_info->v_version >= 0x0200) {
715 vesa_venderstr = (char *)(emumem+L_ADD(vesa_adp_info->v_venderstr));
716 vesa_prodstr = (char *)(emumem+L_ADD(vesa_adp_info->v_prodstr));
717 vesa_revstr = (char *)(emumem+L_ADD(vesa_adp_info->v_revstr));
720 vesa_vmodetab = (u_int16_t *)(emumem+L_ADD(vesa_adp_info->v_modetable));
722 if (vesa_vmodetab == NULL)
725 for (i = 0, modes = 0;
726 (i < (M_VESA_MODE_MAX - M_VESA_BASE + 1))
727 && (vesa_vmodetab[i] != 0xffff); ++i) {
728 if (vesa_bios_get_mode(vesa_vmodetab[i], &vmode))
731 /* reject unsupported modes */
733 if ((vmode.v_modeattr & (V_MODESUPP | V_MODEOPTINFO
735 != (V_MODESUPP | V_MODEOPTINFO))
738 if ((vmode.v_modeattr & V_MODEOPTINFO) == 0) {
741 "Rejecting VESA %s mode: %d x %d x %d bpp attr = %x\n",
742 vmode.v_modeattr & V_MODEGRAPHICS ? "graphics" : "text",
743 vmode.v_width, vmode.v_height, vmode.v_bpp,
750 /* expand the array if necessary */
751 if (modes >= vesa_vmode_max) {
752 vesa_vmode_max += MODE_TABLE_DELTA;
753 p = malloc(sizeof(*vesa_vmode)*(vesa_vmode_max + 1),
756 printf("vesa_bios_init(): modes:%d, vesa_mode_max:%d\n",
757 modes, vesa_vmode_max);
760 bcopy(vesa_vmode, p, sizeof(*vesa_vmode)*modes);
761 free(vesa_vmode, M_DEVBUF);
767 printf("Found VESA %s mode: %d x %d x %d bpp\n",
768 vmode.v_modeattr & V_MODEGRAPHICS ? "graphics" : "text",
769 vmode.v_width, vmode.v_height, vmode.v_bpp);
772 if ((vmode.v_width & 0xff00) >> 8 == vmode.v_height - 1) {
773 vmode.v_width &= 0xff;
774 vmode.v_waseg = 0xb8000 >> 4;
778 /* copy some fields */
779 bzero(&vesa_vmode[modes], sizeof(vesa_vmode[modes]));
780 vesa_vmode[modes].vi_mode = vesa_vmodetab[i];
781 vesa_vmode[modes].vi_width = vmode.v_width;
782 vesa_vmode[modes].vi_height = vmode.v_height;
783 vesa_vmode[modes].vi_depth = vmode.v_bpp;
784 vesa_vmode[modes].vi_planes = vmode.v_planes;
785 vesa_vmode[modes].vi_cwidth = vmode.v_cwidth;
786 vesa_vmode[modes].vi_cheight = vmode.v_cheight;
787 vesa_vmode[modes].vi_window = (u_int)vmode.v_waseg << 4;
789 vesa_vmode[modes].vi_window_size = vmode.v_wsize*1024;
790 vesa_vmode[modes].vi_window_gran = vmode.v_wgran*1024;
791 if (vmode.v_modeattr & V_MODELFB)
792 vesa_vmode[modes].vi_buffer = vmode.v_lfb;
794 vesa_vmode[modes].vi_buffer = 0;
796 vesa_vmode[modes].vi_buffer_size
797 = vesa_adp_info->v_memsize*64*1024;
799 if (vmode.v_offscreen > vmode.v_lfb)
800 vesa_vmode[modes].vi_buffer_size
801 = vmode.v_offscreen + vmode.v_offscreensize*1024
804 vesa_vmode[modes].vi_buffer_size
805 = vmode.v_offscreen + vmode.v_offscreensize*1024
807 vesa_vmode[modes].vi_mem_model
808 = vesa_translate_mmodel(vmode.v_memmodel);
809 vesa_vmode[modes].vi_pixel_fields[0] = 0;
810 vesa_vmode[modes].vi_pixel_fields[1] = 0;
811 vesa_vmode[modes].vi_pixel_fields[2] = 0;
812 vesa_vmode[modes].vi_pixel_fields[3] = 0;
813 vesa_vmode[modes].vi_pixel_fsizes[0] = 0;
814 vesa_vmode[modes].vi_pixel_fsizes[1] = 0;
815 vesa_vmode[modes].vi_pixel_fsizes[2] = 0;
816 vesa_vmode[modes].vi_pixel_fsizes[3] = 0;
817 if (vesa_vmode[modes].vi_mem_model == V_INFO_MM_PACKED) {
818 vesa_vmode[modes].vi_pixel_size = (vmode.v_bpp + 7)/8;
819 } else if (vesa_vmode[modes].vi_mem_model == V_INFO_MM_DIRECT) {
820 vesa_vmode[modes].vi_pixel_size = (vmode.v_bpp + 7)/8;
821 vesa_vmode[modes].vi_pixel_fields[0]
822 = vmode.v_redfieldpos;
823 vesa_vmode[modes].vi_pixel_fields[1]
824 = vmode.v_greenfieldpos;
825 vesa_vmode[modes].vi_pixel_fields[2]
826 = vmode.v_bluefieldpos;
827 vesa_vmode[modes].vi_pixel_fields[3]
828 = vmode.v_resfieldpos;
829 vesa_vmode[modes].vi_pixel_fsizes[0]
830 = vmode.v_redmasksize;
831 vesa_vmode[modes].vi_pixel_fsizes[1]
832 = vmode.v_greenmasksize;
833 vesa_vmode[modes].vi_pixel_fsizes[2]
834 = vmode.v_bluemasksize;
835 vesa_vmode[modes].vi_pixel_fsizes[3]
836 = vmode.v_resmasksize;
838 vesa_vmode[modes].vi_pixel_size = 0;
841 vesa_vmode[modes].vi_flags
842 = vesa_translate_flags(vmode.v_modeattr) | V_INFO_VESA;
845 vesa_vmode[modes].vi_mode = EOT;
847 printf("VESA: %d mode(s) found\n", modes);
849 has_vesa_bios = (modes > 0);
857 vesa_clear_modes(video_info_t *info, int color)
859 while (info->vi_mode != EOT) {
860 if ((info->vi_flags & V_INFO_COLOR) != color)
867 vesa_map_buffer(u_int paddr, size_t size)
872 off = paddr - trunc_page(paddr);
873 vaddr = (vm_offset_t)pmap_mapdev(paddr - off, size + off);
875 printf("vesa_map_buffer: paddr:%x vaddr:%tx size:%zx off:%x\n",
876 paddr, vaddr, size, off);
878 return (vaddr + off);
882 vesa_unmap_buffer(vm_offset_t vaddr, size_t size)
885 printf("vesa_unmap_buffer: vaddr:%tx size:%zx\n", vaddr, size);
887 kmem_free(kernel_map, vaddr, size);
893 vesa_configure(int flags)
895 video_adapter_t *adp;
902 if (flags & VIO_PROBE_ONLY)
906 * If the VESA module has already been loaded, abort loading
907 * the module this time.
909 for (i = 0; (adp = vid_get_adapter(i)) != NULL; ++i) {
910 if (adp->va_flags & V_ADP_VESA)
912 if (adp->va_type == KD_VGA)
916 * The VGA adapter is not found. This is because either
917 * 1) the VGA driver has not been initialized, or 2) the VGA card
918 * is not present. If 1) is the case, we shall defer
919 * initialization for now and try again later.
922 vga_sub_configure = vesa_configure;
926 /* count number of registered adapters */
927 for (++i; vid_get_adapter(i) != NULL; ++i)
933 if (vesa_bios_init()) {
937 vesa_adp->va_flags |= V_ADP_VESA;
939 /* remove conflicting modes if we have more than one adapter */
941 vesa_clear_modes(vesa_vmode,
942 (vesa_adp->va_flags & V_ADP_COLOR) ?
946 if ((error = vesa_load_ioctl()) == 0) {
947 prevvidsw = vidsw[vesa_adp->va_index];
948 vidsw[vesa_adp->va_index] = &vesavidsw;
949 vesa_init_done = TRUE;
973 vesa_probe(int unit, video_adapter_t **adpp, void *arg, int flags)
975 return (*prevvidsw->probe)(unit, adpp, arg, flags);
979 vesa_init(int unit, video_adapter_t *adp, int flags)
981 return (*prevvidsw->init)(unit, adp, flags);
985 vesa_get_info(video_adapter_t *adp, int mode, video_info_t *info)
989 if ((*prevvidsw->get_info)(adp, mode, info) == 0)
995 mode = vesa_map_gen_mode_num(vesa_adp->va_type,
996 vesa_adp->va_flags & V_ADP_COLOR, mode);
997 for (i = 0; vesa_vmode[i].vi_mode != EOT; ++i) {
998 if (vesa_vmode[i].vi_mode == NA)
1000 if (vesa_vmode[i].vi_mode == mode) {
1001 *info = vesa_vmode[i];
1009 vesa_query_mode(video_adapter_t *adp, video_info_t *info)
1013 if ((*prevvidsw->query_mode)(adp, info) == 0)
1015 if (adp != vesa_adp)
1018 for (i = 0; vesa_vmode[i].vi_mode != EOT; ++i) {
1019 if ((info->vi_width != 0)
1020 && (info->vi_width != vesa_vmode[i].vi_width))
1022 if ((info->vi_height != 0)
1023 && (info->vi_height != vesa_vmode[i].vi_height))
1025 if ((info->vi_cwidth != 0)
1026 && (info->vi_cwidth != vesa_vmode[i].vi_cwidth))
1028 if ((info->vi_cheight != 0)
1029 && (info->vi_cheight != vesa_vmode[i].vi_cheight))
1031 if ((info->vi_depth != 0)
1032 && (info->vi_depth != vesa_vmode[i].vi_depth))
1034 if ((info->vi_planes != 0)
1035 && (info->vi_planes != vesa_vmode[i].vi_planes))
1037 /* pixel format, memory model */
1038 if ((info->vi_flags != 0)
1039 && (info->vi_flags != vesa_vmode[i].vi_flags))
1041 *info = vesa_vmode[i];
1048 vesa_set_mode(video_adapter_t *adp, int mode)
1053 if (adp != vesa_adp)
1054 return (*prevvidsw->set_mode)(adp, mode);
1056 mode = vesa_map_gen_mode_num(adp->va_type,
1057 adp->va_flags & V_ADP_COLOR, mode);
1059 printf("VESA: set_mode(): %d(%x) -> %d(%x)\n",
1060 adp->va_mode, adp->va_mode, mode, mode);
1063 * If the current mode is a VESA mode and the new mode is not,
1064 * restore the state of the adapter first by setting one of the
1065 * standard VGA mode, so that non-standard, extended SVGA registers
1066 * are set to the state compatible with the standard VGA modes.
1067 * Otherwise (*prevvidsw->set_mode)() may not be able to set up
1068 * the new mode correctly.
1070 if (VESA_MODE(adp->va_mode)) {
1071 if ((*prevvidsw->get_info)(adp, mode, &info) == 0) {
1072 int10_set_mode(adp->va_initial_bios_mode);
1073 if (adp->va_info.vi_flags & V_INFO_LINEAR)
1074 vesa_unmap_buffer(adp->va_buffer,
1075 vesa_adp_info->v_memsize*64*1024);
1077 * Once (*prevvidsw->get_info)() succeeded,
1078 * (*prevvidsw->set_mode)() below won't fail...
1083 /* we may not need to handle this mode after all... */
1084 if ((*prevvidsw->set_mode)(adp, mode) == 0)
1087 /* is the new mode supported? */
1088 if (vesa_get_info(adp, mode, &info))
1090 /* assert(VESA_MODE(mode)); */
1093 printf("VESA: about to set a VESA mode...\n");
1095 /* don't use the linear frame buffer for text modes. XXX */
1096 if (!(info.vi_flags & V_INFO_GRAPHICS))
1097 info.vi_flags &= ~V_INFO_LINEAR;
1099 if (vesa_bios_set_mode(mode | ((info.vi_flags & V_INFO_LINEAR) ? 0x4000 : 0)))
1102 if (adp->va_info.vi_flags & V_INFO_LINEAR)
1103 vesa_unmap_buffer(adp->va_buffer,
1104 vesa_adp_info->v_memsize*64*1024);
1107 printf("VESA: mode set!\n");
1109 vesa_adp->va_mode = mode;
1110 vesa_adp->va_flags &= ~V_ADP_COLOR;
1111 vesa_adp->va_flags |=
1112 (info.vi_flags & V_INFO_COLOR) ? V_ADP_COLOR : 0;
1113 vesa_adp->va_crtc_addr =
1114 (vesa_adp->va_flags & V_ADP_COLOR) ? COLOR_CRTC : MONO_CRTC;
1115 if (info.vi_flags & V_INFO_LINEAR) {
1117 printf("VESA: setting up LFB\n");
1119 vesa_adp->va_buffer =
1120 vesa_map_buffer(info.vi_buffer,
1121 vesa_adp_info->v_memsize*64*1024);
1122 vesa_adp->va_buffer_size = info.vi_buffer_size;
1123 vesa_adp->va_window = vesa_adp->va_buffer;
1124 vesa_adp->va_window_size = info.vi_buffer_size/info.vi_planes;
1125 vesa_adp->va_window_gran = info.vi_buffer_size/info.vi_planes;
1127 vesa_adp->va_buffer = 0;
1128 vesa_adp->va_buffer_size = info.vi_buffer_size;
1129 vesa_adp->va_window = (vm_offset_t)(emumem+L_ADD(info.vi_window));
1130 vesa_adp->va_window_size = info.vi_window_size;
1131 vesa_adp->va_window_gran = info.vi_window_gran;
1133 vesa_adp->va_window_orig = 0;
1134 len = vesa_bios_get_line_length();
1136 vesa_adp->va_line_width = len;
1137 } else if (info.vi_flags & V_INFO_GRAPHICS) {
1138 switch (info.vi_depth/info.vi_planes) {
1140 vesa_adp->va_line_width = info.vi_width/8;
1143 vesa_adp->va_line_width = info.vi_width/4;
1146 vesa_adp->va_line_width = info.vi_width/2;
1149 default: /* shouldn't happen */
1150 vesa_adp->va_line_width = info.vi_width;
1154 vesa_adp->va_line_width = info.vi_width*2;
1158 vesa_adp->va_line_width = info.vi_width*4;
1162 vesa_adp->va_line_width = info.vi_width;
1164 vesa_adp->va_disp_start.x = 0;
1165 vesa_adp->va_disp_start.y = 0;
1167 printf("vesa_set_mode(): vi_width:%d, len:%d, line_width:%d\n",
1168 info.vi_width, len, vesa_adp->va_line_width);
1170 bcopy(&info, &vesa_adp->va_info, sizeof(vesa_adp->va_info));
1172 /* move hardware cursor out of the way */
1173 (*vidsw[vesa_adp->va_index]->set_hw_cursor)(vesa_adp, -1, -1);
1179 vesa_save_font(video_adapter_t *adp, int page, int fontsize, int fontwidth,
1180 u_char *data, int ch, int count)
1182 return (*prevvidsw->save_font)(adp, page, fontsize, fontwidth, data,
1187 vesa_load_font(video_adapter_t *adp, int page, int fontsize, int fontwidth,
1188 u_char *data, int ch, int count)
1190 return (*prevvidsw->load_font)(adp, page, fontsize, fontwidth, data,
1195 vesa_show_font(video_adapter_t *adp, int page)
1197 return (*prevvidsw->show_font)(adp, page);
1201 vesa_save_palette(video_adapter_t *adp, u_char *palette)
1206 if ((adp == vesa_adp) && (vesa_adp_info->v_flags & V_DAC8)
1207 && VESA_MODE(adp->va_mode)) {
1208 bits = vesa_bios_get_dac();
1209 error = vesa_bios_save_palette(0, 256, palette, bits);
1216 return (*prevvidsw->save_palette)(adp, palette);
1220 vesa_load_palette(video_adapter_t *adp, u_char *palette)
1226 if ((adp == vesa_adp) && (vesa_adp_info->v_flags & V_DAC8)
1227 && VESA_MODE(adp->va_mode) && ((bits = vesa_bios_set_dac(8)) > 6)) {
1228 error = vesa_bios_load_palette(0, 256, palette, bits);
1231 if (vesa_bios_set_dac(6) != 6)
1236 return (*prevvidsw->load_palette)(adp, palette);
1240 vesa_set_border(video_adapter_t *adp, int color)
1242 return (*prevvidsw->set_border)(adp, color);
1246 vesa_save_state(video_adapter_t *adp, void *p, size_t size)
1248 if (adp != vesa_adp)
1249 return (*prevvidsw->save_state)(adp, p, size);
1251 if (vesa_state_buf_size == 0)
1252 vesa_state_buf_size = vesa_bios_state_buf_size();
1254 return (sizeof(int) + vesa_state_buf_size);
1255 else if (size < (sizeof(int) + vesa_state_buf_size))
1258 ((adp_state_t *)p)->sig = V_STATE_SIG;
1259 bzero(((adp_state_t *)p)->regs, vesa_state_buf_size);
1260 return vesa_bios_save_restore(STATE_SAVE, ((adp_state_t *)p)->regs,
1261 vesa_state_buf_size);
1265 vesa_load_state(video_adapter_t *adp, void *p)
1267 if ((adp != vesa_adp) || (((adp_state_t *)p)->sig != V_STATE_SIG))
1268 return (*prevvidsw->load_state)(adp, p);
1270 return vesa_bios_save_restore(STATE_LOAD, ((adp_state_t *)p)->regs,
1271 vesa_state_buf_size);
1276 vesa_get_origin(video_adapter_t *adp, off_t *offset)
1278 vesa_emu.x86.R_EAX = 0x4f05;
1279 vesa_emu.x86.R_EBX = 0x10;
1281 x86emu_exec_intr(&vesa_emu, 0x10);
1283 if ((vesa_emu.x86.R_AX & 0xff) != 0x4f)
1285 *offset = vesa_emu.x86.DX*adp->va_window_gran;
1292 vesa_set_origin(video_adapter_t *adp, off_t offset)
1295 * This function should return as quickly as possible to
1296 * maintain good performance of the system. For this reason,
1297 * error checking is kept minimal and let the VESA BIOS to
1300 if (adp != vesa_adp)
1301 return (*prevvidsw->set_win_org)(adp, offset);
1303 /* if this is a linear frame buffer, do nothing */
1304 if (adp->va_info.vi_flags & V_INFO_LINEAR)
1307 if (adp->va_window_gran == 0)
1310 vesa_emu.x86.R_EAX = 0x4f05;
1311 vesa_emu.x86.R_EBX = 0;
1312 vesa_emu.x86.R_EDX = offset/adp->va_window_gran;
1313 x86emu_exec_intr(&vesa_emu, 0x10);
1315 if ((vesa_emu.x86.R_AX & 0xff) != 0x4f)
1318 vesa_emu.x86.R_EAX = 0x4f05;
1319 vesa_emu.x86.R_EBX = 1;
1320 vesa_emu.x86.R_EDX = offset/adp->va_window_gran;
1321 x86emu_exec_intr(&vesa_emu, 0x10);
1323 adp->va_window_orig = (offset/adp->va_window_gran)*adp->va_window_gran;
1328 vesa_read_hw_cursor(video_adapter_t *adp, int *col, int *row)
1330 return (*prevvidsw->read_hw_cursor)(adp, col, row);
1334 vesa_set_hw_cursor(video_adapter_t *adp, int col, int row)
1336 return (*prevvidsw->set_hw_cursor)(adp, col, row);
1340 vesa_set_hw_cursor_shape(video_adapter_t *adp, int base, int height,
1341 int celsize, int blink)
1343 return (*prevvidsw->set_hw_cursor_shape)(adp, base, height, celsize,
1348 vesa_blank_display(video_adapter_t *adp, int mode)
1350 /* XXX: use VESA DPMS */
1351 return (*prevvidsw->blank_display)(adp, mode);
1355 vesa_mmap(video_adapter_t *adp, vm_offset_t offset, vm_paddr_t *paddr,
1359 printf("vesa_mmap(): window:0x%tx, buffer:0x%tx, offset:0x%tx\n",
1360 adp->va_info.vi_window, adp->va_info.vi_buffer, offset);
1363 if ((adp == vesa_adp) && (adp->va_info.vi_flags & V_INFO_LINEAR)) {
1364 /* va_window_size == va_buffer_size/vi_planes */
1365 /* XXX: is this correct? */
1366 if (offset > adp->va_window_size - PAGE_SIZE)
1368 *paddr = adp->va_info.vi_buffer + offset;
1371 return (*prevvidsw->mmap)(adp, offset, paddr, prot);
1376 vesa_clear(video_adapter_t *adp)
1378 return (*prevvidsw->clear)(adp);
1382 vesa_fill_rect(video_adapter_t *adp, int val, int x, int y, int cx, int cy)
1384 return (*prevvidsw->fill_rect)(adp, val, x, y, cx, cy);
1388 vesa_bitblt(video_adapter_t *adp,...)
1395 get_palette(video_adapter_t *adp, int base, int count,
1396 u_char *red, u_char *green, u_char *blue, u_char *trans)
1404 if ((base < 0) || (base >= 256) || (count < 0) || (count > 256))
1406 if ((base + count) > 256)
1408 if (!(vesa_adp_info->v_flags & V_DAC8) || !VESA_MODE(adp->va_mode))
1411 bits = vesa_bios_get_dac();
1415 r = malloc(count*3, M_DEVBUF, M_WAITOK);
1418 error = vesa_bios_save_palette2(base, count, r, g, b, bits);
1420 copyout(r, red, count);
1421 copyout(g, green, count);
1422 copyout(b, blue, count);
1423 if (trans != NULL) {
1425 copyout(r, trans, count);
1430 /* if error && bits != 6 at this point, we are in trouble... XXX */
1435 set_palette(video_adapter_t *adp, int base, int count,
1436 u_char *red, u_char *green, u_char *blue, u_char *trans)
1446 if ((base < 0) || (base >= 256) || (base + count > 256))
1448 if (!(vesa_adp_info->v_flags & V_DAC8) || !VESA_MODE(adp->va_mode)
1449 || ((bits = vesa_bios_set_dac(8)) <= 6))
1452 r = malloc(count*3, M_DEVBUF, M_WAITOK);
1455 copyin(red, r, count);
1456 copyin(green, g, count);
1457 copyin(blue, b, count);
1459 error = vesa_bios_load_palette2(base, count, r, g, b, bits);
1464 /* if the following call fails, we are in trouble... XXX */
1465 vesa_bios_set_dac(6);
1471 vesa_ioctl(video_adapter_t *adp, u_long cmd, caddr_t arg)
1475 if (adp != vesa_adp)
1476 return (*prevvidsw->ioctl)(adp, cmd, arg);
1479 case FBIO_SETWINORG: /* set frame buffer window origin */
1480 if (!VESA_MODE(adp->va_mode))
1481 return (*prevvidsw->ioctl)(adp, cmd, arg);
1482 return (vesa_set_origin(adp, *(off_t *)arg) ? ENODEV : 0);
1484 case FBIO_SETDISPSTART: /* set display start address */
1485 if (!VESA_MODE(adp->va_mode))
1486 return (*prevvidsw->ioctl)(adp, cmd, arg);
1487 if (vesa_bios_set_start(((video_display_start_t *)arg)->x,
1488 ((video_display_start_t *)arg)->y))
1490 adp->va_disp_start.x = ((video_display_start_t *)arg)->x;
1491 adp->va_disp_start.y = ((video_display_start_t *)arg)->y;
1494 case FBIO_SETLINEWIDTH: /* set line length in pixel */
1495 if (!VESA_MODE(adp->va_mode))
1496 return (*prevvidsw->ioctl)(adp, cmd, arg);
1497 if (vesa_bios_set_line_length(*(u_int *)arg, &bytes, NULL))
1499 adp->va_line_width = bytes;
1501 printf("new line width:%d\n", adp->va_line_width);
1505 case FBIO_GETPALETTE: /* get color palette */
1506 if (get_palette(adp, ((video_color_palette_t *)arg)->index,
1507 ((video_color_palette_t *)arg)->count,
1508 ((video_color_palette_t *)arg)->red,
1509 ((video_color_palette_t *)arg)->green,
1510 ((video_color_palette_t *)arg)->blue,
1511 ((video_color_palette_t *)arg)->transparent))
1512 return (*prevvidsw->ioctl)(adp, cmd, arg);
1516 case FBIO_SETPALETTE: /* set color palette */
1517 if (set_palette(adp, ((video_color_palette_t *)arg)->index,
1518 ((video_color_palette_t *)arg)->count,
1519 ((video_color_palette_t *)arg)->red,
1520 ((video_color_palette_t *)arg)->green,
1521 ((video_color_palette_t *)arg)->blue,
1522 ((video_color_palette_t *)arg)->transparent))
1523 return (*prevvidsw->ioctl)(adp, cmd, arg);
1526 case FBIOGETCMAP: /* get color palette */
1527 if (get_palette(adp, ((struct fbcmap *)arg)->index,
1528 ((struct fbcmap *)arg)->count,
1529 ((struct fbcmap *)arg)->red,
1530 ((struct fbcmap *)arg)->green,
1531 ((struct fbcmap *)arg)->blue, NULL))
1532 return (*prevvidsw->ioctl)(adp, cmd, arg);
1535 case FBIOPUTCMAP: /* set color palette */
1536 if (set_palette(adp, ((struct fbcmap *)arg)->index,
1537 ((struct fbcmap *)arg)->count,
1538 ((struct fbcmap *)arg)->red,
1539 ((struct fbcmap *)arg)->green,
1540 ((struct fbcmap *)arg)->blue, NULL))
1541 return (*prevvidsw->ioctl)(adp, cmd, arg);
1545 return (*prevvidsw->ioctl)(adp, cmd, arg);
1550 vesa_diag(video_adapter_t *adp, int level)
1554 /* call the previous handler first */
1555 error = (*prevvidsw->diag)(adp, level);
1559 if (adp != vesa_adp)
1569 vesa_bios_info(int level)
1572 struct vesa_mode vmode;
1577 /* general adapter information */
1579 "VESA: v%d.%d, %dk memory, flags:0x%x, mode table:%p (%x)\n",
1580 ((vesa_adp_info->v_version & 0xf000) >> 12) * 10 +
1581 ((vesa_adp_info->v_version & 0x0f00) >> 8),
1582 ((vesa_adp_info->v_version & 0x00f0) >> 4) * 10 +
1583 (vesa_adp_info->v_version & 0x000f),
1584 vesa_adp_info->v_memsize * 64, vesa_adp_info->v_flags,
1585 vesa_vmodetab, vesa_adp_info->v_modetable);
1588 if (vesa_oemstr != NULL)
1589 printf("VESA: %s\n", vesa_oemstr);
1595 if (vesa_adp_info->v_version >= 0x0200 && bootverbose) {
1596 /* vender name, product name, product revision */
1597 printf("VESA: %s %s %s\n",
1598 (vesa_venderstr != NULL) ? vesa_venderstr : "unknown",
1599 (vesa_prodstr != NULL) ? vesa_prodstr : "unknown",
1600 (vesa_revstr != NULL) ? vesa_revstr : "?");
1604 /* mode information */
1606 (i < (M_VESA_MODE_MAX - M_VESA_BASE + 1))
1607 && (vesa_vmodetab[i] != 0xffff); ++i) {
1608 if (vesa_bios_get_mode(vesa_vmodetab[i], &vmode))
1611 /* print something for diagnostic purpose */
1612 printf("VESA: mode:0x%03x, flags:0x%04x",
1613 vesa_vmodetab[i], vmode.v_modeattr);
1614 if (vmode.v_modeattr & V_MODEOPTINFO) {
1615 if (vmode.v_modeattr & V_MODEGRAPHICS) {
1616 printf(", G %dx%dx%d %d, ",
1617 vmode.v_width, vmode.v_height,
1618 vmode.v_bpp, vmode.v_planes);
1620 printf(", T %dx%d, ",
1621 vmode.v_width, vmode.v_height);
1623 printf("font:%dx%d, ",
1624 vmode.v_cwidth, vmode.v_cheight);
1625 printf("pages:%d, mem:%d",
1626 vmode.v_ipages + 1, vmode.v_memmodel);
1628 if (vmode.v_modeattr & V_MODELFB) {
1629 printf("\nVESA: LFB:0x%x, off:0x%x, off_size:0x%x",
1630 vmode.v_lfb, vmode.v_offscreen,
1631 vmode.v_offscreensize*1024);
1634 printf("VESA: window A:0x%x (%x), window B:0x%x (%x), ",
1635 vmode.v_waseg, vmode.v_waattr,
1636 vmode.v_wbseg, vmode.v_wbattr);
1637 printf("size:%dk, gran:%dk\n",
1638 vmode.v_wsize, vmode.v_wgran);
1640 #endif /* VESA_DEBUG > 1 */
1645 /* module loading */
1656 /* Can `emumem' be NULL here? */
1657 emumem = pmap_mapbios(0x0, 0xc00000);
1659 memset(&vesa_emu, 0, sizeof(vesa_emu));
1660 x86emu_init_default(&vesa_emu);
1662 vesa_emu.emu_inb = vm86_emu_inb;
1663 vesa_emu.emu_inw = vm86_emu_inw;
1664 vesa_emu.emu_inl = vm86_emu_inl;
1665 vesa_emu.emu_outb = vm86_emu_outb;
1666 vesa_emu.emu_outw = vm86_emu_outw;
1667 vesa_emu.emu_outl = vm86_emu_outl;
1669 vesa_emu.mem_base = (char *)emumem;
1670 vesa_emu.mem_size = 1024 * 1024;
1672 /* locate a VGA adapter */
1675 error = vesa_configure(0);
1679 vesa_bios_info(bootverbose);
1687 u_char palette[256*3];
1692 /* if the adapter is currently in a VESA mode, don't unload */
1693 if ((vesa_adp != NULL) && VESA_MODE(vesa_adp->va_mode))
1696 * FIXME: if there is at least one vty which is in a VESA mode,
1697 * we shouldn't be unloading! XXX
1701 if ((error = vesa_unload_ioctl()) == 0) {
1702 if (vesa_adp != NULL) {
1703 if (vesa_adp_info->v_flags & V_DAC8) {
1704 bits = vesa_bios_get_dac();
1706 vesa_bios_save_palette(0, 256,
1708 vesa_bios_set_dac(6);
1709 vesa_bios_load_palette(0, 256,
1713 vesa_adp->va_flags &= ~V_ADP_VESA;
1714 vidsw[vesa_adp->va_index] = prevvidsw;
1720 pmap_unmapdev((vm_offset_t)emumem, 0xc00000);
1726 vesa_mod_event(module_t mod, int type, void *data)
1732 return vesa_unload();
1739 static moduledata_t vesa_mod = {
1745 DECLARE_MODULE(vesa, vesa_mod, SI_SUB_DRIVERS, SI_ORDER_MIDDLE);
1746 MODULE_DEPEND(vesa, x86emu, 1, 1, 1);
1748 #endif /* VGA_NO_MODE_CHANGE */