2 * Copyright (c) 1998 Kazutaka YOKOTA and Michael Smith
3 * Copyright (c) 2009-2012 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>
41 #include <sys/module.h>
42 #include <sys/malloc.h>
43 #include <sys/mutex.h>
45 #include <sys/sysctl.h>
48 #include <vm/vm_extern.h>
49 #include <vm/vm_kern.h>
50 #include <vm/vm_param.h>
53 #include <machine/pc/bios.h>
54 #include <dev/fb/vesa.h>
56 #include <dev/fb/fbreg.h>
57 #include <dev/fb/vgareg.h>
59 #include <dev/pci/pcivar.h>
61 #include <isa/isareg.h>
63 #include <compat/x86bios/x86bios.h>
65 #define VESA_BIOS_OFFSET 0xc0000
66 #define VESA_PALETTE_SIZE (256 * 4)
67 #define VESA_VIA_CLE266 "VIA CLE266\r\n"
73 /* VESA video adapter state buffer stub */
76 #define V_STATE_SIG 0x61736576
79 typedef struct adp_state adp_state_t;
81 static struct mtx vesa_lock;
82 MTX_SYSINIT(vesa_lock, &vesa_lock, "VESA lock", MTX_DEF);
84 static int vesa_state;
85 static void *vesa_state_buf;
86 static uint32_t vesa_state_buf_offs;
87 static ssize_t vesa_state_buf_size;
89 static u_char *vesa_palette;
90 static uint32_t vesa_palette_offs;
92 static void *vesa_vmem_buf;
93 static size_t vesa_vmem_max;
95 static void *vesa_bios;
96 static uint32_t vesa_bios_offs;
97 static uint32_t vesa_bios_int10;
98 static size_t vesa_bios_size;
100 /* VESA video adapter */
101 static video_adapter_t *vesa_adp;
103 static SYSCTL_NODE(_debug, OID_AUTO, vesa, CTLFLAG_RD, NULL, "VESA debugging");
104 static int vesa_shadow_rom;
105 TUNABLE_INT("debug.vesa.shadow_rom", &vesa_shadow_rom);
106 SYSCTL_INT(_debug_vesa, OID_AUTO, shadow_rom, CTLFLAG_RDTUN, &vesa_shadow_rom,
107 0, "Enable video BIOS shadow");
111 static int vesa_nop(void);
113 static int vesa_error(void);
114 static vi_probe_t vesa_probe;
115 static vi_init_t vesa_init;
116 static vi_get_info_t vesa_get_info;
117 static vi_query_mode_t vesa_query_mode;
118 static vi_set_mode_t vesa_set_mode;
119 static vi_save_font_t vesa_save_font;
120 static vi_load_font_t vesa_load_font;
121 static vi_show_font_t vesa_show_font;
122 static vi_save_palette_t vesa_save_palette;
123 static vi_load_palette_t vesa_load_palette;
124 static vi_set_border_t vesa_set_border;
125 static vi_save_state_t vesa_save_state;
126 static vi_load_state_t vesa_load_state;
127 static vi_set_win_org_t vesa_set_origin;
128 static vi_read_hw_cursor_t vesa_read_hw_cursor;
129 static vi_set_hw_cursor_t vesa_set_hw_cursor;
130 static vi_set_hw_cursor_shape_t vesa_set_hw_cursor_shape;
131 static vi_blank_display_t vesa_blank_display;
132 static vi_mmap_t vesa_mmap;
133 static vi_ioctl_t vesa_ioctl;
134 static vi_clear_t vesa_clear;
135 static vi_fill_rect_t vesa_fill_rect;
136 static vi_bitblt_t vesa_bitblt;
137 static vi_diag_t vesa_diag;
138 static int vesa_bios_info(int level);
140 static video_switch_t vesavidsw = {
157 vesa_set_hw_cursor_shape,
169 static video_switch_t *prevvidsw;
171 /* VESA BIOS video modes */
172 #define VESA_MAXMODES 64
176 #define MODE_TABLE_DELTA 8
178 static int vesa_vmode_max;
179 static video_info_t *vesa_vmode;
181 static int vesa_init_done;
182 static struct vesa_info *vesa_adp_info;
183 static u_int16_t *vesa_vmodetab;
184 static char *vesa_oemstr;
185 static char *vesa_venderstr;
186 static char *vesa_prodstr;
187 static char *vesa_revstr;
189 /* local macros and functions */
190 #define BIOS_SADDRTOLADDR(p) ((((p) & 0xffff0000) >> 12) + ((p) & 0x0000ffff))
192 static int int10_set_mode(int mode);
193 static int vesa_bios_post(void);
194 static int vesa_bios_get_mode(int mode, struct vesa_mode *vmode, int flags);
195 static int vesa_bios_set_mode(int mode);
197 static int vesa_bios_get_dac(void);
199 static int vesa_bios_set_dac(int bits);
200 static int vesa_bios_save_palette(int start, int colors, u_char *palette,
202 static int vesa_bios_save_palette2(int start, int colors, u_char *r, u_char *g,
203 u_char *b, int bits);
204 static int vesa_bios_load_palette(int start, int colors, u_char *palette,
206 static int vesa_bios_load_palette2(int start, int colors, u_char *r, u_char *g,
207 u_char *b, int bits);
211 static ssize_t vesa_bios_state_buf_size(int);
212 static int vesa_bios_save_restore(int code, void *p);
213 #ifdef MODE_TABLE_BROKEN
214 static int vesa_bios_get_line_length(void);
216 static int vesa_bios_set_line_length(int pixel, int *bytes, int *lines);
218 static int vesa_bios_get_start(int *x, int *y);
220 static int vesa_bios_set_start(int x, int y);
221 static int vesa_map_gen_mode_num(int type, int color, int mode);
222 static int vesa_translate_flags(u_int16_t vflags);
223 static int vesa_translate_mmodel(u_int8_t vmodel);
224 static int vesa_get_bpscanline(struct vesa_mode *vmode);
225 static int vesa_bios_init(void);
226 static void vesa_bios_uninit(void);
227 static void vesa_clear_modes(video_info_t *info, int color);
230 static int vesa_get_origin(video_adapter_t *adp, off_t *offset);
233 /* INT 10 BIOS calls */
235 int10_set_mode(int mode)
239 x86bios_init_regs(®s);
242 x86bios_intr(®s, 0x10);
254 int count, i, is_pci;
256 if (x86bios_get_orm(vesa_bios_offs) == NULL)
262 /* Find the matching PCI video controller. */
263 dc = devclass_find("vgapci");
264 if (dc != NULL && devclass_get_devices(dc, &devs, &count) == 0) {
265 for (i = 0; i < count; i++)
266 if (device_get_flags(devs[i]) != 0 &&
267 x86bios_match_device(vesa_bios_offs, devs[i])) {
275 /* Try VGA if a PCI device is not found. */
277 dc = devclass_find(VGA_DRIVER_NAME);
279 dev = devclass_get_device(dc, 0);
283 printf("%s: calling BIOS POST\n",
284 dev == NULL ? "VESA" : device_get_nameunit(dev));
286 x86bios_init_regs(®s);
288 regs.R_AH = pci_get_bus(dev);
289 regs.R_AL = (pci_get_slot(dev) << 3) |
290 (pci_get_function(dev) & 0x07);
293 x86bios_call(®s, X86BIOS_PHYSTOSEG(vesa_bios_offs + 3),
294 X86BIOS_PHYSTOOFF(vesa_bios_offs + 3));
296 if (x86bios_get_intr(0x10) == 0)
302 /* VESA BIOS calls */
304 vesa_bios_get_mode(int mode, struct vesa_mode *vmode, int flags)
310 buf = x86bios_alloc(&offs, sizeof(*vmode), flags);
314 x86bios_init_regs(®s);
318 regs.R_ES = X86BIOS_PHYSTOSEG(offs);
319 regs.R_DI = X86BIOS_PHYSTOOFF(offs);
321 x86bios_intr(®s, 0x10);
323 if (regs.R_AX != 0x004f) {
324 x86bios_free(buf, sizeof(*vmode));
328 bcopy(buf, vmode, sizeof(*vmode));
329 x86bios_free(buf, sizeof(*vmode));
335 vesa_bios_set_mode(int mode)
339 x86bios_init_regs(®s);
343 x86bios_intr(®s, 0x10);
345 return (regs.R_AX != 0x004f);
350 vesa_bios_get_dac(void)
354 x86bios_init_regs(®s);
358 x86bios_intr(®s, 0x10);
360 if (regs.R_AX != 0x004f)
368 vesa_bios_set_dac(int bits)
372 x86bios_init_regs(®s);
377 x86bios_intr(®s, 0x10);
379 if (regs.R_AX != 0x004f)
386 vesa_bios_save_palette(int start, int colors, u_char *palette, int bits)
391 x86bios_init_regs(®s);
397 regs.R_ES = X86BIOS_PHYSTOSEG(vesa_palette_offs);
398 regs.R_DI = X86BIOS_PHYSTOOFF(vesa_palette_offs);
401 mtx_lock(&vesa_lock);
402 x86bios_intr(®s, 0x10);
403 if (regs.R_AX != 0x004f) {
404 mtx_unlock(&vesa_lock);
407 for (i = 0; i < colors; ++i) {
408 palette[i * 3] = vesa_palette[i * 4 + 2] << bits;
409 palette[i * 3 + 1] = vesa_palette[i * 4 + 1] << bits;
410 palette[i * 3 + 2] = vesa_palette[i * 4] << bits;
412 mtx_unlock(&vesa_lock);
418 vesa_bios_save_palette2(int start, int colors, u_char *r, u_char *g, u_char *b,
424 x86bios_init_regs(®s);
430 regs.R_ES = X86BIOS_PHYSTOSEG(vesa_palette_offs);
431 regs.R_DI = X86BIOS_PHYSTOOFF(vesa_palette_offs);
434 mtx_lock(&vesa_lock);
435 x86bios_intr(®s, 0x10);
436 if (regs.R_AX != 0x004f) {
437 mtx_unlock(&vesa_lock);
440 for (i = 0; i < colors; ++i) {
441 r[i] = vesa_palette[i * 4 + 2] << bits;
442 g[i] = vesa_palette[i * 4 + 1] << bits;
443 b[i] = vesa_palette[i * 4] << bits;
445 mtx_unlock(&vesa_lock);
451 vesa_bios_load_palette(int start, int colors, u_char *palette, int bits)
456 x86bios_init_regs(®s);
462 regs.R_ES = X86BIOS_PHYSTOSEG(vesa_palette_offs);
463 regs.R_DI = X86BIOS_PHYSTOOFF(vesa_palette_offs);
466 mtx_lock(&vesa_lock);
467 for (i = 0; i < colors; ++i) {
468 vesa_palette[i * 4] = palette[i * 3 + 2] >> bits;
469 vesa_palette[i * 4 + 1] = palette[i * 3 + 1] >> bits;
470 vesa_palette[i * 4 + 2] = palette[i * 3] >> bits;
471 vesa_palette[i * 4 + 3] = 0;
473 x86bios_intr(®s, 0x10);
474 mtx_unlock(&vesa_lock);
476 return (regs.R_AX != 0x004f);
480 vesa_bios_load_palette2(int start, int colors, u_char *r, u_char *g, u_char *b,
486 x86bios_init_regs(®s);
492 regs.R_ES = X86BIOS_PHYSTOSEG(vesa_palette_offs);
493 regs.R_DI = X86BIOS_PHYSTOOFF(vesa_palette_offs);
496 mtx_lock(&vesa_lock);
497 for (i = 0; i < colors; ++i) {
498 vesa_palette[i * 4] = b[i] >> bits;
499 vesa_palette[i * 4 + 1] = g[i] >> bits;
500 vesa_palette[i * 4 + 2] = r[i] >> bits;
501 vesa_palette[i * 4 + 3] = 0;
503 x86bios_intr(®s, 0x10);
504 mtx_unlock(&vesa_lock);
506 return (regs.R_AX != 0x004f);
510 vesa_bios_state_buf_size(int state)
514 x86bios_init_regs(®s);
516 /* regs.R_DL = STATE_SIZE; */
519 x86bios_intr(®s, 0x10);
521 if (regs.R_AX != 0x004f)
524 return (regs.R_BX * 64);
528 vesa_bios_save_restore(int code, void *p)
532 if (code != STATE_SAVE && code != STATE_LOAD)
535 x86bios_init_regs(®s);
538 regs.R_CX = vesa_state;
540 regs.R_ES = X86BIOS_PHYSTOSEG(vesa_state_buf_offs);
541 regs.R_BX = X86BIOS_PHYSTOOFF(vesa_state_buf_offs);
543 mtx_lock(&vesa_lock);
546 x86bios_intr(®s, 0x10);
547 bcopy(vesa_state_buf, p, vesa_state_buf_size);
550 bcopy(p, vesa_state_buf, vesa_state_buf_size);
551 x86bios_intr(®s, 0x10);
554 mtx_unlock(&vesa_lock);
556 return (regs.R_AX != 0x004f);
559 #ifdef MODE_TABLE_BROKEN
561 vesa_bios_get_line_length(void)
565 x86bios_init_regs(®s);
569 x86bios_intr(®s, 0x10);
571 if (regs.R_AX != 0x004f)
579 vesa_bios_set_line_length(int pixel, int *bytes, int *lines)
583 x86bios_init_regs(®s);
588 x86bios_intr(®s, 0x10);
591 printf("bx:%d, cx:%d, dx:%d\n", regs.R_BX, regs.R_CX, regs.R_DX);
593 if (regs.R_AX != 0x004f)
606 vesa_bios_get_start(int *x, int *y)
610 x86bios_init_regs(®s);
614 x86bios_intr(®s, 0x10);
616 if (regs.R_AX != 0x004f)
627 vesa_bios_set_start(int x, int y)
631 x86bios_init_regs(®s);
637 x86bios_intr(®s, 0x10);
639 return (regs.R_AX != 0x004f);
642 /* map a generic video mode to a known mode */
644 vesa_map_gen_mode_num(int type, int color, int mode)
650 { M_TEXT_132x25, M_VESA_C132x25 },
651 { M_TEXT_132x43, M_VESA_C132x43 },
652 { M_TEXT_132x50, M_VESA_C132x50 },
653 { M_TEXT_132x60, M_VESA_C132x60 },
657 for (i = 0; i < sizeof(mode_map)/sizeof(mode_map[0]); ++i) {
658 if (mode_map[i].from == mode)
659 return (mode_map[i].to);
665 vesa_translate_flags(u_int16_t vflags)
672 { V_MODECOLOR, V_INFO_COLOR, 0 },
673 { V_MODEGRAPHICS, V_INFO_GRAPHICS, 0 },
674 { V_MODELFB, V_INFO_LINEAR, 0 },
675 { V_MODENONVGA, V_INFO_NONVGA, 0 },
680 for (flags = 0, i = 0; i < sizeof(ftable)/sizeof(ftable[0]); ++i) {
681 flags |= (vflags & ftable[i].mask) ?
682 ftable[i].set : ftable[i].reset;
688 vesa_translate_mmodel(u_int8_t vmodel)
694 { V_MMTEXT, V_INFO_MM_TEXT },
695 { V_MMCGA, V_INFO_MM_CGA },
696 { V_MMHGC, V_INFO_MM_HGC },
697 { V_MMEGA, V_INFO_MM_PLANAR },
698 { V_MMPACKED, V_INFO_MM_PACKED },
699 { V_MMDIRCOLOR, V_INFO_MM_DIRECT },
703 for (i = 0; mtable[i].mmodel >= 0; ++i) {
704 if (mtable[i].vmodel == vmodel)
705 return (mtable[i].mmodel);
707 return (V_INFO_MM_OTHER);
711 vesa_get_bpscanline(struct vesa_mode *vmode)
715 if ((vmode->v_modeattr & V_MODEGRAPHICS) != 0) {
716 /* Find the minimum length. */
717 switch (vmode->v_bpp / vmode->v_planes) {
719 bpsl = vmode->v_width / 8;
722 bpsl = vmode->v_width / 4;
725 bpsl = vmode->v_width / 2;
728 bpsl = vmode->v_width * ((vmode->v_bpp + 7) / 8);
729 bpsl /= vmode->v_planes;
733 /* Use VBE 3.0 information if it looks sane. */
734 if ((vmode->v_modeattr & V_MODELFB) != 0 &&
735 vesa_adp_info->v_version >= 0x0300 &&
736 vmode->v_linbpscanline > bpsl)
737 return (vmode->v_linbpscanline);
739 /* Return the minimum if the mode table looks absurd. */
740 if (vmode->v_bpscanline < bpsl)
744 return (vmode->v_bpscanline);
747 #define VESA_MAXSTR 256
749 #define VESA_STRCPY(dst, src) do { \
752 dst = malloc(VESA_MAXSTR, M_DEVBUF, M_WAITOK); \
753 str = x86bios_offset(BIOS_SADDRTOLADDR(src)); \
754 for (i = 0; i < VESA_MAXSTR - 1 && str[i] != '\0'; i++) \
762 struct vesa_mode vmode;
763 struct vesa_info *buf;
779 vesa_bios_offs = VESA_BIOS_OFFSET;
782 * If the VBE real mode interrupt vector is not found, try BIOS POST.
784 vesa_bios_int10 = x86bios_get_intr(0x10);
785 if (vesa_bios_int10 == 0) {
786 if (vesa_bios_post() != 0)
788 vesa_bios_int10 = x86bios_get_intr(0x10);
789 if (vesa_bios_int10 == 0)
796 offs = vesa_bios_int10;
797 if (vesa_shadow_rom) {
798 vbios = x86bios_get_orm(vesa_bios_offs);
800 vesa_bios_size = vbios[2] * 512;
801 if (((VESA_BIOS_OFFSET << 12) & 0xffff0000) ==
802 (vesa_bios_int10 & 0xffff0000) &&
803 vesa_bios_size > (vesa_bios_int10 & 0xffff)) {
804 vesa_bios = x86bios_alloc(&vesa_bios_offs,
805 vesa_bios_size, M_WAITOK);
806 bcopy(vbios, vesa_bios, vesa_bios_size);
807 offs = ((vesa_bios_offs << 12) & 0xffff0000) +
808 (vesa_bios_int10 & 0xffff);
809 x86bios_set_intr(0x10, offs);
812 if (vesa_bios == NULL)
813 printf("VESA: failed to shadow video ROM\n");
816 printf("VESA: INT 0x10 vector 0x%04x:0x%04x\n",
817 (offs >> 16) & 0xffff, offs & 0xffff);
819 x86bios_init_regs(®s);
822 vmbuf = x86bios_alloc(&offs, sizeof(*buf), M_WAITOK);
824 regs.R_ES = X86BIOS_PHYSTOSEG(offs);
825 regs.R_DI = X86BIOS_PHYSTOOFF(offs);
827 bcopy("VBE2", vmbuf, 4); /* try for VBE2 data */
828 x86bios_intr(®s, 0x10);
830 if (regs.R_AX != 0x004f || bcmp("VESA", vmbuf, 4) != 0)
833 vesa_adp_info = buf = malloc(sizeof(*buf), M_DEVBUF, M_WAITOK);
834 bcopy(vmbuf, buf, sizeof(*buf));
837 printf("VESA: information block\n");
838 hexdump(buf, sizeof(*buf), NULL, HD_OMIT_CHARS);
841 vers = buf->v_version = le16toh(buf->v_version);
842 buf->v_oemstr = le32toh(buf->v_oemstr);
843 buf->v_flags = le32toh(buf->v_flags);
844 buf->v_modetable = le32toh(buf->v_modetable);
845 buf->v_memsize = le16toh(buf->v_memsize);
846 buf->v_revision = le16toh(buf->v_revision);
847 buf->v_venderstr = le32toh(buf->v_venderstr);
848 buf->v_prodstr = le32toh(buf->v_prodstr);
849 buf->v_revstr = le32toh(buf->v_revstr);
852 printf("VESA: VBE version %d.%d is not supported; "
853 "version 1.2 or later is required.\n",
854 ((vers & 0xf000) >> 12) * 10 + ((vers & 0x0f00) >> 8),
855 ((vers & 0x00f0) >> 4) * 10 + (vers & 0x000f));
859 VESA_STRCPY(vesa_oemstr, buf->v_oemstr);
860 if (vers >= 0x0200) {
861 VESA_STRCPY(vesa_venderstr, buf->v_venderstr);
862 VESA_STRCPY(vesa_prodstr, buf->v_prodstr);
863 VESA_STRCPY(vesa_revstr, buf->v_revstr);
865 is_via_cle266 = strncmp(vesa_oemstr, VESA_VIA_CLE266,
866 sizeof(VESA_VIA_CLE266)) == 0;
868 if (buf->v_modetable == 0)
871 msize = (size_t)buf->v_memsize * 64 * 1024;
873 vesa_vmodetab = x86bios_offset(BIOS_SADDRTOLADDR(buf->v_modetable));
875 for (i = 0, modes = 0; (i < (M_VESA_MODE_MAX - M_VESA_BASE + 1)) &&
876 (vesa_vmodetab[i] != 0xffff); ++i) {
877 vesa_vmodetab[i] = le16toh(vesa_vmodetab[i]);
878 if (vesa_bios_get_mode(vesa_vmodetab[i], &vmode, M_WAITOK))
881 vmode.v_modeattr = le16toh(vmode.v_modeattr);
882 vmode.v_wgran = le16toh(vmode.v_wgran);
883 vmode.v_wsize = le16toh(vmode.v_wsize);
884 vmode.v_waseg = le16toh(vmode.v_waseg);
885 vmode.v_wbseg = le16toh(vmode.v_wbseg);
886 vmode.v_posfunc = le32toh(vmode.v_posfunc);
887 vmode.v_bpscanline = le16toh(vmode.v_bpscanline);
888 vmode.v_width = le16toh(vmode.v_width);
889 vmode.v_height = le16toh(vmode.v_height);
890 vmode.v_lfb = le32toh(vmode.v_lfb);
891 vmode.v_offscreen = le32toh(vmode.v_offscreen);
892 vmode.v_offscreensize = le16toh(vmode.v_offscreensize);
893 vmode.v_linbpscanline = le16toh(vmode.v_linbpscanline);
894 vmode.v_maxpixelclock = le32toh(vmode.v_maxpixelclock);
896 /* reject unsupported modes */
898 if ((vmode.v_modeattr &
899 (V_MODESUPP | V_MODEOPTINFO | V_MODENONVGA)) !=
900 (V_MODESUPP | V_MODEOPTINFO))
903 if ((vmode.v_modeattr & V_MODEOPTINFO) == 0) {
905 printf("Rejecting VESA %s mode: %d x %d x %d bpp "
907 vmode.v_modeattr & V_MODEGRAPHICS ?
909 vmode.v_width, vmode.v_height, vmode.v_bpp,
916 bsize = vesa_get_bpscanline(&vmode) * vmode.v_height;
917 if ((vmode.v_modeattr & V_MODEGRAPHICS) != 0)
918 bsize *= vmode.v_planes;
920 /* Does it have enough memory to support this mode? */
923 printf("Rejecting VESA %s mode: %d x %d x %d bpp "
924 " attr = %x, not enough memory\n",
925 vmode.v_modeattr & V_MODEGRAPHICS ?
927 vmode.v_width, vmode.v_height, vmode.v_bpp,
932 if (bsize > vesa_vmem_max)
933 vesa_vmem_max = bsize;
935 /* expand the array if necessary */
936 if (modes >= vesa_vmode_max) {
937 vesa_vmode_max += MODE_TABLE_DELTA;
938 p = malloc(sizeof(*vesa_vmode) * (vesa_vmode_max + 1),
941 printf("vesa_bios_init(): modes:%d, vesa_mode_max:%d\n",
942 modes, vesa_vmode_max);
945 bcopy(vesa_vmode, p, sizeof(*vesa_vmode)*modes);
946 free(vesa_vmode, M_DEVBUF);
952 printf("Found VESA %s mode: %d x %d x %d bpp\n",
953 vmode.v_modeattr & V_MODEGRAPHICS ? "graphics" : "text",
954 vmode.v_width, vmode.v_height, vmode.v_bpp);
957 if ((vmode.v_width & 0xff00) >> 8 == vmode.v_height - 1) {
958 vmode.v_width &= 0xff;
959 vmode.v_waseg = 0xb8000 >> 4;
963 /* copy some fields */
964 bzero(&vesa_vmode[modes], sizeof(vesa_vmode[modes]));
965 vesa_vmode[modes].vi_mode = vesa_vmodetab[i];
966 vesa_vmode[modes].vi_width = vmode.v_width;
967 vesa_vmode[modes].vi_height = vmode.v_height;
968 vesa_vmode[modes].vi_depth = vmode.v_bpp;
969 vesa_vmode[modes].vi_planes = vmode.v_planes;
970 vesa_vmode[modes].vi_cwidth = vmode.v_cwidth;
971 vesa_vmode[modes].vi_cheight = vmode.v_cheight;
972 vesa_vmode[modes].vi_window = (vm_offset_t)vmode.v_waseg << 4;
974 vesa_vmode[modes].vi_window_size = vmode.v_wsize * 1024;
975 vesa_vmode[modes].vi_window_gran = vmode.v_wgran * 1024;
976 if (vmode.v_modeattr & V_MODELFB)
977 vesa_vmode[modes].vi_buffer = vmode.v_lfb;
978 vesa_vmode[modes].vi_buffer_size = bsize;
979 vesa_vmode[modes].vi_mem_model =
980 vesa_translate_mmodel(vmode.v_memmodel);
981 switch (vesa_vmode[modes].vi_mem_model) {
982 case V_INFO_MM_DIRECT:
983 if ((vmode.v_modeattr & V_MODELFB) != 0 &&
985 vesa_vmode[modes].vi_pixel_fields[0] =
986 vmode.v_linredfieldpos;
987 vesa_vmode[modes].vi_pixel_fields[1] =
988 vmode.v_lingreenfieldpos;
989 vesa_vmode[modes].vi_pixel_fields[2] =
990 vmode.v_linbluefieldpos;
991 vesa_vmode[modes].vi_pixel_fields[3] =
992 vmode.v_linresfieldpos;
993 vesa_vmode[modes].vi_pixel_fsizes[0] =
994 vmode.v_linredmasksize;
995 vesa_vmode[modes].vi_pixel_fsizes[1] =
996 vmode.v_lingreenmasksize;
997 vesa_vmode[modes].vi_pixel_fsizes[2] =
998 vmode.v_linbluemasksize;
999 vesa_vmode[modes].vi_pixel_fsizes[3] =
1000 vmode.v_linresmasksize;
1002 vesa_vmode[modes].vi_pixel_fields[0] =
1003 vmode.v_redfieldpos;
1004 vesa_vmode[modes].vi_pixel_fields[1] =
1005 vmode.v_greenfieldpos;
1006 vesa_vmode[modes].vi_pixel_fields[2] =
1007 vmode.v_bluefieldpos;
1008 vesa_vmode[modes].vi_pixel_fields[3] =
1009 vmode.v_resfieldpos;
1010 vesa_vmode[modes].vi_pixel_fsizes[0] =
1011 vmode.v_redmasksize;
1012 vesa_vmode[modes].vi_pixel_fsizes[1] =
1013 vmode.v_greenmasksize;
1014 vesa_vmode[modes].vi_pixel_fsizes[2] =
1015 vmode.v_bluemasksize;
1016 vesa_vmode[modes].vi_pixel_fsizes[3] =
1017 vmode.v_resmasksize;
1020 case V_INFO_MM_PACKED:
1021 vesa_vmode[modes].vi_pixel_size = (vmode.v_bpp + 7) / 8;
1024 vesa_vmode[modes].vi_flags =
1025 vesa_translate_flags(vmode.v_modeattr) | V_INFO_VESA;
1029 vesa_vmode[modes].vi_mode = EOT;
1032 printf("VESA: %d mode(s) found\n", modes);
1037 x86bios_free(vmbuf, sizeof(*buf));
1039 /* Probe supported save/restore states. */
1040 for (i = 0; i < 4; i++)
1041 if (vesa_bios_state_buf_size(1 << i) > 0)
1042 vesa_state |= 1 << i;
1043 if (vesa_state != 0)
1044 vesa_state_buf_size = vesa_bios_state_buf_size(vesa_state);
1045 vesa_palette = x86bios_alloc(&vesa_palette_offs,
1046 VESA_PALETTE_SIZE + vesa_state_buf_size, M_WAITOK);
1047 if (vesa_state_buf_size > 0) {
1048 vesa_state_buf = vesa_palette + VESA_PALETTE_SIZE;
1049 vesa_state_buf_offs = vesa_palette_offs + VESA_PALETTE_SIZE;
1055 x86bios_free(vmbuf, sizeof(buf));
1061 vesa_bios_uninit(void)
1064 if (vesa_bios != NULL) {
1065 x86bios_set_intr(0x10, vesa_bios_int10);
1066 vesa_bios_offs = VESA_BIOS_OFFSET;
1067 x86bios_free(vesa_bios, vesa_bios_size);
1070 if (vesa_adp_info != NULL) {
1071 free(vesa_adp_info, M_DEVBUF);
1072 vesa_adp_info = NULL;
1074 if (vesa_oemstr != NULL) {
1075 free(vesa_oemstr, M_DEVBUF);
1078 if (vesa_venderstr != NULL) {
1079 free(vesa_venderstr, M_DEVBUF);
1080 vesa_venderstr = NULL;
1082 if (vesa_prodstr != NULL) {
1083 free(vesa_prodstr, M_DEVBUF);
1084 vesa_prodstr = NULL;
1086 if (vesa_revstr != NULL) {
1087 free(vesa_revstr, M_DEVBUF);
1090 if (vesa_vmode != NULL) {
1091 free(vesa_vmode, M_DEVBUF);
1094 if (vesa_palette != NULL) {
1095 x86bios_free(vesa_palette,
1096 VESA_PALETTE_SIZE + vesa_state_buf_size);
1097 vesa_palette = NULL;
1102 vesa_clear_modes(video_info_t *info, int color)
1104 while (info->vi_mode != EOT) {
1105 if ((info->vi_flags & V_INFO_COLOR) != color)
1114 vesa_configure(int flags)
1116 video_adapter_t *adp;
1123 if (flags & VIO_PROBE_ONLY)
1127 * If the VESA module has already been loaded, abort loading
1128 * the module this time.
1130 for (i = 0; (adp = vid_get_adapter(i)) != NULL; ++i) {
1131 if (adp->va_flags & V_ADP_VESA)
1133 if (adp->va_type == KD_VGA)
1138 * The VGA adapter is not found. This is because either
1139 * 1) the VGA driver has not been initialized, or 2) the VGA card
1140 * is not present. If 1) is the case, we shall defer
1141 * initialization for now and try again later.
1144 vga_sub_configure = vesa_configure;
1148 /* count number of registered adapters */
1149 for (++i; vid_get_adapter(i) != NULL; ++i)
1153 /* call VESA BIOS */
1155 if (vesa_bios_init()) {
1159 vesa_adp->va_flags |= V_ADP_VESA;
1161 /* remove conflicting modes if we have more than one adapter */
1163 vesa_clear_modes(vesa_vmode,
1164 (vesa_adp->va_flags & V_ADP_COLOR) ?
1168 if ((error = vesa_load_ioctl()) == 0) {
1169 prevvidsw = vidsw[vesa_adp->va_index];
1170 vidsw[vesa_adp->va_index] = &vesavidsw;
1171 vesa_init_done = TRUE;
1197 vesa_probe(int unit, video_adapter_t **adpp, void *arg, int flags)
1200 return ((*prevvidsw->probe)(unit, adpp, arg, flags));
1204 vesa_init(int unit, video_adapter_t *adp, int flags)
1207 return ((*prevvidsw->init)(unit, adp, flags));
1211 vesa_get_info(video_adapter_t *adp, int mode, video_info_t *info)
1215 if ((*prevvidsw->get_info)(adp, mode, info) == 0)
1218 if (adp != vesa_adp)
1221 mode = vesa_map_gen_mode_num(vesa_adp->va_type,
1222 vesa_adp->va_flags & V_ADP_COLOR, mode);
1223 for (i = 0; vesa_vmode[i].vi_mode != EOT; ++i) {
1224 if (vesa_vmode[i].vi_mode == NA)
1226 if (vesa_vmode[i].vi_mode == mode) {
1227 *info = vesa_vmode[i];
1235 vesa_query_mode(video_adapter_t *adp, video_info_t *info)
1239 if ((*prevvidsw->query_mode)(adp, info) == 0)
1241 if (adp != vesa_adp)
1244 for (i = 0; vesa_vmode[i].vi_mode != EOT; ++i) {
1245 if ((info->vi_width != 0)
1246 && (info->vi_width != vesa_vmode[i].vi_width))
1248 if ((info->vi_height != 0)
1249 && (info->vi_height != vesa_vmode[i].vi_height))
1251 if ((info->vi_cwidth != 0)
1252 && (info->vi_cwidth != vesa_vmode[i].vi_cwidth))
1254 if ((info->vi_cheight != 0)
1255 && (info->vi_cheight != vesa_vmode[i].vi_cheight))
1257 if ((info->vi_depth != 0)
1258 && (info->vi_depth != vesa_vmode[i].vi_depth))
1260 if ((info->vi_planes != 0)
1261 && (info->vi_planes != vesa_vmode[i].vi_planes))
1263 /* pixel format, memory model */
1264 if ((info->vi_flags != 0)
1265 && (info->vi_flags != vesa_vmode[i].vi_flags))
1267 *info = vesa_vmode[i];
1274 vesa_set_mode(video_adapter_t *adp, int mode)
1278 if (adp != vesa_adp)
1279 return ((*prevvidsw->set_mode)(adp, mode));
1281 mode = vesa_map_gen_mode_num(adp->va_type,
1282 adp->va_flags & V_ADP_COLOR, mode);
1284 printf("VESA: set_mode(): %d(%x) -> %d(%x)\n",
1285 adp->va_mode, adp->va_mode, mode, mode);
1288 * If the current mode is a VESA mode and the new mode is not,
1289 * restore the state of the adapter first by setting one of the
1290 * standard VGA mode, so that non-standard, extended SVGA registers
1291 * are set to the state compatible with the standard VGA modes.
1292 * Otherwise (*prevvidsw->set_mode)() may not be able to set up
1293 * the new mode correctly.
1295 if (VESA_MODE(adp->va_mode)) {
1296 if (!VESA_MODE(mode) &&
1297 (*prevvidsw->get_info)(adp, mode, &info) == 0) {
1298 if ((adp->va_flags & V_ADP_DAC8) != 0) {
1299 vesa_bios_set_dac(6);
1300 adp->va_flags &= ~V_ADP_DAC8;
1302 int10_set_mode(adp->va_initial_bios_mode);
1303 if (adp->va_info.vi_flags & V_INFO_LINEAR)
1304 pmap_unmapdev(adp->va_buffer, vesa_vmem_max);
1306 * Once (*prevvidsw->get_info)() succeeded,
1307 * (*prevvidsw->set_mode)() below won't fail...
1312 /* we may not need to handle this mode after all... */
1313 if (!VESA_MODE(mode) && (*prevvidsw->set_mode)(adp, mode) == 0)
1316 /* is the new mode supported? */
1317 if (vesa_get_info(adp, mode, &info))
1319 /* assert(VESA_MODE(mode)); */
1322 printf("VESA: about to set a VESA mode...\n");
1324 /* don't use the linear frame buffer for text modes. XXX */
1325 if (!(info.vi_flags & V_INFO_GRAPHICS))
1326 info.vi_flags &= ~V_INFO_LINEAR;
1328 if ((info.vi_flags & V_INFO_LINEAR) != 0)
1330 if (vesa_bios_set_mode(mode | 0x8000))
1333 /* Palette format is reset by the above VBE function call. */
1334 adp->va_flags &= ~V_ADP_DAC8;
1336 if ((vesa_adp_info->v_flags & V_DAC8) != 0 &&
1337 (info.vi_flags & V_INFO_GRAPHICS) != 0 &&
1338 vesa_bios_set_dac(8) > 6)
1339 adp->va_flags |= V_ADP_DAC8;
1341 if (adp->va_info.vi_flags & V_INFO_LINEAR)
1342 pmap_unmapdev(adp->va_buffer, vesa_vmem_max);
1345 printf("VESA: mode set!\n");
1347 vesa_adp->va_mode = mode & 0x1ff; /* Mode number is 9-bit. */
1348 vesa_adp->va_flags &= ~V_ADP_COLOR;
1349 vesa_adp->va_flags |=
1350 (info.vi_flags & V_INFO_COLOR) ? V_ADP_COLOR : 0;
1351 vesa_adp->va_crtc_addr =
1352 (vesa_adp->va_flags & V_ADP_COLOR) ? COLOR_CRTC : MONO_CRTC;
1354 vesa_adp->va_line_width = info.vi_buffer_size / info.vi_height;
1355 if ((info.vi_flags & V_INFO_GRAPHICS) != 0)
1356 vesa_adp->va_line_width /= info.vi_planes;
1358 #ifdef MODE_TABLE_BROKEN
1359 /* If VBE function returns bigger bytes per scan line, use it. */
1361 int bpsl = vesa_bios_get_line_length();
1362 if (bpsl > vesa_adp->va_line_width) {
1363 vesa_adp->va_line_width = bpsl;
1364 info.vi_buffer_size = bpsl * info.vi_height;
1365 if ((info.vi_flags & V_INFO_GRAPHICS) != 0)
1366 info.vi_buffer_size *= info.vi_planes;
1371 if (info.vi_flags & V_INFO_LINEAR) {
1373 printf("VESA: setting up LFB\n");
1375 vesa_adp->va_buffer =
1376 (vm_offset_t)pmap_mapdev_attr(info.vi_buffer,
1377 vesa_vmem_max, PAT_WRITE_COMBINING);
1378 vesa_adp->va_window = vesa_adp->va_buffer;
1379 vesa_adp->va_window_size = info.vi_buffer_size / info.vi_planes;
1380 vesa_adp->va_window_gran = info.vi_buffer_size / info.vi_planes;
1382 vesa_adp->va_buffer = 0;
1383 vesa_adp->va_window = (vm_offset_t)x86bios_offset(info.vi_window);
1384 vesa_adp->va_window_size = info.vi_window_size;
1385 vesa_adp->va_window_gran = info.vi_window_gran;
1387 vesa_adp->va_buffer_size = info.vi_buffer_size;
1388 vesa_adp->va_window_orig = 0;
1389 vesa_adp->va_disp_start.x = 0;
1390 vesa_adp->va_disp_start.y = 0;
1392 printf("vesa_set_mode(): vi_width:%d, line_width:%d\n",
1393 info.vi_width, vesa_adp->va_line_width);
1395 bcopy(&info, &vesa_adp->va_info, sizeof(vesa_adp->va_info));
1397 /* move hardware cursor out of the way */
1398 (*vidsw[vesa_adp->va_index]->set_hw_cursor)(vesa_adp, -1, -1);
1404 vesa_save_font(video_adapter_t *adp, int page, int fontsize, int fontwidth,
1405 u_char *data, int ch, int count)
1408 return ((*prevvidsw->save_font)(adp, page, fontsize, fontwidth, data,
1413 vesa_load_font(video_adapter_t *adp, int page, int fontsize, int fontwidth,
1414 u_char *data, int ch, int count)
1417 return ((*prevvidsw->load_font)(adp, page, fontsize, fontwidth, data,
1422 vesa_show_font(video_adapter_t *adp, int page)
1425 return ((*prevvidsw->show_font)(adp, page));
1429 vesa_save_palette(video_adapter_t *adp, u_char *palette)
1433 if (adp == vesa_adp && VESA_MODE(adp->va_mode)) {
1434 bits = (adp->va_flags & V_ADP_DAC8) != 0 ? 8 : 6;
1435 if (vesa_bios_save_palette(0, 256, palette, bits) == 0)
1439 return ((*prevvidsw->save_palette)(adp, palette));
1443 vesa_load_palette(video_adapter_t *adp, u_char *palette)
1447 if (adp == vesa_adp && VESA_MODE(adp->va_mode)) {
1448 bits = (adp->va_flags & V_ADP_DAC8) != 0 ? 8 : 6;
1449 if (vesa_bios_load_palette(0, 256, palette, bits) == 0)
1453 return ((*prevvidsw->load_palette)(adp, palette));
1457 vesa_set_border(video_adapter_t *adp, int color)
1460 return ((*prevvidsw->set_border)(adp, color));
1464 vesa_save_state(video_adapter_t *adp, void *p, size_t size)
1469 if (adp != vesa_adp || vesa_state_buf_size == 0)
1470 return ((*prevvidsw->save_state)(adp, p, size));
1473 return (offsetof(adp_state_t, regs) + vesa_state_buf_size);
1474 if (size < (offsetof(adp_state_t, regs) + vesa_state_buf_size))
1477 buf = adp->va_buffer;
1479 bsize = adp->va_buffer_size;
1480 vesa_vmem_buf = malloc(bsize, M_DEVBUF, M_NOWAIT);
1481 if (vesa_vmem_buf != NULL)
1482 bcopy((void *)buf, vesa_vmem_buf, bsize);
1484 vesa_vmem_buf = NULL;
1485 ((adp_state_t *)p)->sig = V_STATE_SIG;
1486 bzero(((adp_state_t *)p)->regs, vesa_state_buf_size);
1487 return (vesa_bios_save_restore(STATE_SAVE, ((adp_state_t *)p)->regs));
1491 vesa_load_state(video_adapter_t *adp, void *p)
1497 if (adp != vesa_adp)
1498 return ((*prevvidsw->load_state)(adp, p));
1500 /* Try BIOS POST to restore a sane state. */
1501 (void)vesa_bios_post();
1502 bsize = adp->va_buffer_size;
1503 mode = adp->va_mode;
1504 (void)vesa_set_mode(adp, adp->va_initial_mode);
1505 if (mode != adp->va_initial_mode)
1506 (void)vesa_set_mode(adp, mode);
1508 if (((adp_state_t *)p)->sig != V_STATE_SIG)
1509 return ((*prevvidsw->load_state)(adp, p));
1510 if (vesa_vmem_buf != NULL) {
1511 buf = adp->va_buffer;
1513 bcopy(vesa_vmem_buf, (void *)buf, bsize);
1514 free(vesa_vmem_buf, M_DEVBUF);
1516 return (vesa_bios_save_restore(STATE_LOAD, ((adp_state_t *)p)->regs));
1521 vesa_get_origin(video_adapter_t *adp, off_t *offset)
1525 x86bios_init_regs(®s);
1529 x86bios_intr(®s, 0x10);
1531 if (regs.R_AX != 0x004f)
1533 *offset = regs.DX * adp->va_window_gran;
1540 vesa_set_origin(video_adapter_t *adp, off_t offset)
1545 * This function should return as quickly as possible to
1546 * maintain good performance of the system. For this reason,
1547 * error checking is kept minimal and let the VESA BIOS to
1550 if (adp != vesa_adp)
1551 return ((*prevvidsw->set_win_org)(adp, offset));
1553 /* if this is a linear frame buffer, do nothing */
1554 if (adp->va_info.vi_flags & V_INFO_LINEAR)
1557 if (adp->va_window_gran == 0)
1560 x86bios_init_regs(®s);
1562 regs.R_DX = offset / adp->va_window_gran;
1564 x86bios_intr(®s, 0x10);
1566 if (regs.R_AX != 0x004f)
1569 x86bios_init_regs(®s);
1572 regs.R_DX = offset / adp->va_window_gran;
1573 x86bios_intr(®s, 0x10);
1575 adp->va_window_orig = (offset/adp->va_window_gran)*adp->va_window_gran;
1576 return (0); /* XXX */
1580 vesa_read_hw_cursor(video_adapter_t *adp, int *col, int *row)
1583 return ((*prevvidsw->read_hw_cursor)(adp, col, row));
1587 vesa_set_hw_cursor(video_adapter_t *adp, int col, int row)
1590 return ((*prevvidsw->set_hw_cursor)(adp, col, row));
1594 vesa_set_hw_cursor_shape(video_adapter_t *adp, int base, int height,
1595 int celsize, int blink)
1598 return ((*prevvidsw->set_hw_cursor_shape)(adp, base, height, celsize,
1603 vesa_blank_display(video_adapter_t *adp, int mode)
1606 /* XXX: use VESA DPMS */
1607 return ((*prevvidsw->blank_display)(adp, mode));
1611 vesa_mmap(video_adapter_t *adp, vm_ooffset_t offset, vm_paddr_t *paddr,
1612 int prot, vm_memattr_t *memattr)
1616 printf("vesa_mmap(): window:0x%tx, buffer:0x%tx, offset:0x%jx\n",
1617 adp->va_info.vi_window, adp->va_info.vi_buffer, offset);
1620 if ((adp == vesa_adp) &&
1621 (adp->va_info.vi_flags & V_INFO_LINEAR) != 0) {
1622 /* va_window_size == va_buffer_size/vi_planes */
1623 /* XXX: is this correct? */
1624 if (offset > adp->va_window_size - PAGE_SIZE)
1626 *paddr = adp->va_info.vi_buffer + offset;
1629 return ((*prevvidsw->mmap)(adp, offset, paddr, prot, memattr));
1633 vesa_clear(video_adapter_t *adp)
1636 return ((*prevvidsw->clear)(adp));
1640 vesa_fill_rect(video_adapter_t *adp, int val, int x, int y, int cx, int cy)
1643 return ((*prevvidsw->fill_rect)(adp, val, x, y, cx, cy));
1647 vesa_bitblt(video_adapter_t *adp,...)
1655 get_palette(video_adapter_t *adp, int base, int count,
1656 u_char *red, u_char *green, u_char *blue, u_char *trans)
1664 if (base < 0 || base >= 256 || count < 0 || count > 256)
1666 if ((base + count) > 256)
1668 if (!VESA_MODE(adp->va_mode))
1671 bits = (adp->va_flags & V_ADP_DAC8) != 0 ? 8 : 6;
1672 r = malloc(count * 3, M_DEVBUF, M_WAITOK);
1675 error = vesa_bios_save_palette2(base, count, r, g, b, bits);
1677 copyout(r, red, count);
1678 copyout(g, green, count);
1679 copyout(b, blue, count);
1680 if (trans != NULL) {
1682 copyout(r, trans, count);
1691 set_palette(video_adapter_t *adp, int base, int count,
1692 u_char *red, u_char *green, u_char *blue, u_char *trans)
1700 if (base < 0 || base >= 256 || count < 0 || count > 256)
1702 if ((base + count) > 256)
1704 if (!VESA_MODE(adp->va_mode))
1707 bits = (adp->va_flags & V_ADP_DAC8) != 0 ? 8 : 6;
1708 r = malloc(count * 3, M_DEVBUF, M_WAITOK);
1711 copyin(red, r, count);
1712 copyin(green, g, count);
1713 copyin(blue, b, count);
1715 error = vesa_bios_load_palette2(base, count, r, g, b, bits);
1722 vesa_ioctl(video_adapter_t *adp, u_long cmd, caddr_t arg)
1726 if (adp != vesa_adp)
1727 return ((*prevvidsw->ioctl)(adp, cmd, arg));
1730 case FBIO_SETWINORG: /* set frame buffer window origin */
1731 if (!VESA_MODE(adp->va_mode))
1732 return (*prevvidsw->ioctl)(adp, cmd, arg);
1733 return (vesa_set_origin(adp, *(off_t *)arg) ? ENODEV : 0);
1735 case FBIO_SETDISPSTART: /* set display start address */
1736 if (!VESA_MODE(adp->va_mode))
1737 return ((*prevvidsw->ioctl)(adp, cmd, arg));
1738 if (vesa_bios_set_start(((video_display_start_t *)arg)->x,
1739 ((video_display_start_t *)arg)->y))
1741 adp->va_disp_start.x = ((video_display_start_t *)arg)->x;
1742 adp->va_disp_start.y = ((video_display_start_t *)arg)->y;
1745 case FBIO_SETLINEWIDTH: /* set line length in pixel */
1746 if (!VESA_MODE(adp->va_mode))
1747 return ((*prevvidsw->ioctl)(adp, cmd, arg));
1748 if (vesa_bios_set_line_length(*(u_int *)arg, &bytes, NULL))
1750 adp->va_line_width = bytes;
1752 printf("new line width:%d\n", adp->va_line_width);
1756 case FBIO_GETPALETTE: /* get color palette */
1757 if (get_palette(adp, ((video_color_palette_t *)arg)->index,
1758 ((video_color_palette_t *)arg)->count,
1759 ((video_color_palette_t *)arg)->red,
1760 ((video_color_palette_t *)arg)->green,
1761 ((video_color_palette_t *)arg)->blue,
1762 ((video_color_palette_t *)arg)->transparent))
1763 return ((*prevvidsw->ioctl)(adp, cmd, arg));
1767 case FBIO_SETPALETTE: /* set color palette */
1768 if (set_palette(adp, ((video_color_palette_t *)arg)->index,
1769 ((video_color_palette_t *)arg)->count,
1770 ((video_color_palette_t *)arg)->red,
1771 ((video_color_palette_t *)arg)->green,
1772 ((video_color_palette_t *)arg)->blue,
1773 ((video_color_palette_t *)arg)->transparent))
1774 return ((*prevvidsw->ioctl)(adp, cmd, arg));
1777 case FBIOGETCMAP: /* get color palette */
1778 if (get_palette(adp, ((struct fbcmap *)arg)->index,
1779 ((struct fbcmap *)arg)->count,
1780 ((struct fbcmap *)arg)->red,
1781 ((struct fbcmap *)arg)->green,
1782 ((struct fbcmap *)arg)->blue, NULL))
1783 return ((*prevvidsw->ioctl)(adp, cmd, arg));
1786 case FBIOPUTCMAP: /* set color palette */
1787 if (set_palette(adp, ((struct fbcmap *)arg)->index,
1788 ((struct fbcmap *)arg)->count,
1789 ((struct fbcmap *)arg)->red,
1790 ((struct fbcmap *)arg)->green,
1791 ((struct fbcmap *)arg)->blue, NULL))
1792 return ((*prevvidsw->ioctl)(adp, cmd, arg));
1796 return ((*prevvidsw->ioctl)(adp, cmd, arg));
1801 vesa_diag(video_adapter_t *adp, int level)
1805 /* call the previous handler first */
1806 error = (*prevvidsw->diag)(adp, level);
1810 if (adp != vesa_adp)
1820 vesa_bios_info(int level)
1823 struct vesa_mode vmode;
1828 vers = vesa_adp_info->v_version;
1831 /* general adapter information */
1833 "VESA: v%d.%d, %dk memory, flags:0x%x, mode table:%p (%x)\n",
1834 (vers >> 12) * 10 + ((vers & 0x0f00) >> 8),
1835 ((vers & 0x00f0) >> 4) * 10 + (vers & 0x000f),
1836 vesa_adp_info->v_memsize * 64, vesa_adp_info->v_flags,
1837 vesa_vmodetab, vesa_adp_info->v_modetable);
1840 if (vesa_oemstr != NULL)
1841 printf("VESA: %s\n", vesa_oemstr);
1847 if (vers >= 0x0200 && bootverbose) {
1848 /* vender name, product name, product revision */
1849 printf("VESA: %s %s %s\n",
1850 (vesa_venderstr != NULL) ? vesa_venderstr : "unknown",
1851 (vesa_prodstr != NULL) ? vesa_prodstr : "unknown",
1852 (vesa_revstr != NULL) ? vesa_revstr : "?");
1856 /* mode information */
1858 (i < (M_VESA_MODE_MAX - M_VESA_BASE + 1))
1859 && (vesa_vmodetab[i] != 0xffff); ++i) {
1860 if (vesa_bios_get_mode(vesa_vmodetab[i], &vmode, M_NOWAIT))
1863 /* print something for diagnostic purpose */
1864 printf("VESA: mode:0x%03x, flags:0x%04x",
1865 vesa_vmodetab[i], vmode.v_modeattr);
1866 if (vmode.v_modeattr & V_MODEOPTINFO) {
1867 if (vmode.v_modeattr & V_MODEGRAPHICS) {
1868 printf(", G %dx%dx%d %d, ",
1869 vmode.v_width, vmode.v_height,
1870 vmode.v_bpp, vmode.v_planes);
1872 printf(", T %dx%d, ",
1873 vmode.v_width, vmode.v_height);
1875 printf("font:%dx%d, ",
1876 vmode.v_cwidth, vmode.v_cheight);
1877 printf("pages:%d, mem:%d",
1878 vmode.v_ipages + 1, vmode.v_memmodel);
1880 if (vmode.v_modeattr & V_MODELFB) {
1881 printf("\nVESA: LFB:0x%x, off:0x%x, off_size:0x%x",
1882 vmode.v_lfb, vmode.v_offscreen,
1883 vmode.v_offscreensize*1024);
1886 printf("VESA: window A:0x%x (%x), window B:0x%x (%x), ",
1887 vmode.v_waseg, vmode.v_waattr,
1888 vmode.v_wbseg, vmode.v_wbattr);
1889 printf("size:%dk, gran:%dk\n",
1890 vmode.v_wsize, vmode.v_wgran);
1892 #endif /* VESA_DEBUG > 1 */
1897 /* module loading */
1907 /* locate a VGA adapter */
1909 error = vesa_configure(0);
1912 vesa_bios_info(bootverbose);
1920 u_char palette[256*3];
1923 /* if the adapter is currently in a VESA mode, don't unload */
1924 if ((vesa_adp != NULL) && VESA_MODE(vesa_adp->va_mode))
1927 * FIXME: if there is at least one vty which is in a VESA mode,
1928 * we shouldn't be unloading! XXX
1931 if ((error = vesa_unload_ioctl()) == 0) {
1932 if (vesa_adp != NULL) {
1933 if ((vesa_adp->va_flags & V_ADP_DAC8) != 0) {
1934 vesa_bios_save_palette(0, 256, palette, 8);
1935 vesa_bios_set_dac(6);
1936 vesa_adp->va_flags &= ~V_ADP_DAC8;
1937 vesa_bios_load_palette(0, 256, palette, 6);
1939 vesa_adp->va_flags &= ~V_ADP_VESA;
1940 vidsw[vesa_adp->va_index] = prevvidsw;
1950 vesa_mod_event(module_t mod, int type, void *data)
1955 return (vesa_load());
1957 return (vesa_unload());
1959 return (EOPNOTSUPP);
1962 static moduledata_t vesa_mod = {
1968 DECLARE_MODULE(vesa, vesa_mod, SI_SUB_DRIVERS, SI_ORDER_MIDDLE);
1969 MODULE_DEPEND(vesa, x86bios, 1, 1, 1);
1971 #endif /* VGA_NO_MODE_CHANGE */