2 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
4 * Copyright (c) 1998 Kazutaka YOKOTA and Michael Smith
5 * Copyright (c) 2009-2013 Jung-uk Kim <jkim@FreeBSD.org>
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer as
13 * the first lines of this file unmodified.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
18 * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR
19 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21 * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT,
22 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
23 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 #include <sys/cdefs.h>
31 __FBSDID("$FreeBSD$");
36 #ifndef VGA_NO_MODE_CHANGE
38 #include <sys/param.h>
40 #include <sys/systm.h>
41 #include <sys/kernel.h>
43 #include <sys/module.h>
44 #include <sys/malloc.h>
45 #include <sys/mutex.h>
47 #include <sys/sysctl.h>
50 #include <vm/vm_extern.h>
51 #include <vm/vm_kern.h>
52 #include <vm/vm_param.h>
55 #include <machine/pc/bios.h>
56 #include <dev/fb/vesa.h>
58 #include <dev/fb/fbreg.h>
59 #include <dev/fb/vgareg.h>
61 #include <dev/pci/pcivar.h>
63 #include <isa/isareg.h>
65 #include <compat/x86bios/x86bios.h>
67 #define VESA_BIOS_OFFSET 0xc0000
68 #define VESA_PALETTE_SIZE (256 * 4)
69 #define VESA_VIA_CLE266 "VIA CLE266\r\n"
75 /* VESA video adapter state buffer stub */
78 #define V_STATE_SIG 0x61736576
81 typedef struct adp_state adp_state_t;
83 static struct mtx vesa_lock;
84 MTX_SYSINIT(vesa_lock, &vesa_lock, "VESA lock", MTX_DEF);
86 static int vesa_state;
87 static void *vesa_state_buf;
88 static uint32_t vesa_state_buf_offs;
89 static size_t vesa_state_buf_size;
91 static u_char *vesa_palette;
92 static uint32_t vesa_palette_offs;
94 static void *vesa_vmem_buf;
95 static size_t vesa_vmem_max;
97 static void *vesa_bios;
98 static uint32_t vesa_bios_offs;
99 static uint32_t vesa_bios_int10;
100 static size_t vesa_bios_size;
102 /* VESA video adapter */
103 static video_adapter_t *vesa_adp;
105 static SYSCTL_NODE(_debug, OID_AUTO, vesa, CTLFLAG_RD, NULL, "VESA debugging");
106 static int vesa_shadow_rom;
107 SYSCTL_INT(_debug_vesa, OID_AUTO, shadow_rom, CTLFLAG_RDTUN, &vesa_shadow_rom,
108 0, "Enable video BIOS shadow");
112 static int vesa_nop(void);
114 static int vesa_error(void);
115 static vi_probe_t vesa_probe;
116 static vi_init_t vesa_init;
117 static vi_get_info_t vesa_get_info;
118 static vi_query_mode_t vesa_query_mode;
119 static vi_set_mode_t vesa_set_mode;
120 static vi_save_font_t vesa_save_font;
121 static vi_load_font_t vesa_load_font;
122 static vi_show_font_t vesa_show_font;
123 static vi_save_palette_t vesa_save_palette;
124 static vi_load_palette_t vesa_load_palette;
125 static vi_set_border_t vesa_set_border;
126 static vi_save_state_t vesa_save_state;
127 static vi_load_state_t vesa_load_state;
128 static vi_set_win_org_t vesa_set_origin;
129 static vi_read_hw_cursor_t vesa_read_hw_cursor;
130 static vi_set_hw_cursor_t vesa_set_hw_cursor;
131 static vi_set_hw_cursor_shape_t vesa_set_hw_cursor_shape;
132 static vi_blank_display_t vesa_blank_display;
133 static vi_mmap_t vesa_mmap;
134 static vi_ioctl_t vesa_ioctl;
135 static vi_clear_t vesa_clear;
136 static vi_fill_rect_t vesa_fill_rect;
137 static vi_bitblt_t vesa_bitblt;
138 static vi_diag_t vesa_diag;
139 static int vesa_bios_info(int level);
141 static video_switch_t vesavidsw = {
158 vesa_set_hw_cursor_shape,
170 static video_switch_t *prevvidsw;
172 /* VESA BIOS video modes */
173 #define VESA_MAXMODES 64
177 #define MODE_TABLE_DELTA 8
179 static int vesa_vmode_max;
180 static video_info_t *vesa_vmode;
182 static int vesa_init_done;
183 static struct vesa_info *vesa_adp_info;
184 static u_int16_t *vesa_vmodetab;
185 static char *vesa_oemstr;
186 static char *vesa_venderstr;
187 static char *vesa_prodstr;
188 static char *vesa_revstr;
190 /* local macros and functions */
191 #define BIOS_SADDRTOLADDR(p) ((((p) & 0xffff0000) >> 12) + ((p) & 0x0000ffff))
193 static int int10_set_mode(int mode);
194 static int vesa_bios_post(void);
195 static int vesa_bios_get_mode(int mode, struct vesa_mode *vmode, int flags);
196 static int vesa_bios_set_mode(int mode);
198 static int vesa_bios_get_dac(void);
200 static int vesa_bios_set_dac(int bits);
201 static int vesa_bios_save_palette(int start, int colors, u_char *palette,
203 static int vesa_bios_save_palette2(int start, int colors, u_char *r, u_char *g,
204 u_char *b, int bits);
205 static int vesa_bios_load_palette(int start, int colors, u_char *palette,
207 static int vesa_bios_load_palette2(int start, int colors, u_char *r, u_char *g,
208 u_char *b, int bits);
212 static size_t vesa_bios_state_buf_size(int);
213 static int vesa_bios_save_restore(int code, void *p);
214 #ifdef MODE_TABLE_BROKEN
215 static int vesa_bios_get_line_length(void);
217 static int vesa_bios_set_line_length(int pixel, int *bytes, int *lines);
219 static int vesa_bios_get_start(int *x, int *y);
221 static int vesa_bios_set_start(int x, int y);
222 static int vesa_map_gen_mode_num(int type, int color, int mode);
223 static int vesa_translate_flags(u_int16_t vflags);
224 static int vesa_translate_mmodel(u_int8_t vmodel);
225 static int vesa_get_bpscanline(struct vesa_mode *vmode);
226 static int vesa_bios_init(void);
227 static void vesa_bios_uninit(void);
228 static void vesa_clear_modes(video_info_t *info, int color);
231 static int vesa_get_origin(video_adapter_t *adp, off_t *offset);
234 /* INT 10 BIOS calls */
236 int10_set_mode(int mode)
240 x86bios_init_regs(®s);
243 x86bios_intr(®s, 0x10);
255 int count, i, is_pci;
257 if (x86bios_get_orm(vesa_bios_offs) == NULL)
263 /* Find the matching PCI video controller. */
264 dc = devclass_find("vgapci");
265 if (dc != NULL && devclass_get_devices(dc, &devs, &count) == 0) {
266 for (i = 0; i < count; i++)
267 if (device_get_flags(devs[i]) != 0 &&
268 x86bios_match_device(vesa_bios_offs, devs[i])) {
276 /* Try VGA if a PCI device is not found. */
278 dc = devclass_find(VGA_DRIVER_NAME);
280 dev = devclass_get_device(dc, 0);
284 printf("%s: calling BIOS POST\n",
285 dev == NULL ? "VESA" : device_get_nameunit(dev));
287 x86bios_init_regs(®s);
289 regs.R_AH = pci_get_bus(dev);
290 regs.R_AL = (pci_get_slot(dev) << 3) |
291 (pci_get_function(dev) & 0x07);
294 x86bios_call(®s, X86BIOS_PHYSTOSEG(vesa_bios_offs + 3),
295 X86BIOS_PHYSTOOFF(vesa_bios_offs + 3));
297 if (x86bios_get_intr(0x10) == 0)
303 /* VESA BIOS calls */
305 vesa_bios_get_mode(int mode, struct vesa_mode *vmode, int flags)
311 buf = x86bios_alloc(&offs, sizeof(*vmode), flags);
315 x86bios_init_regs(®s);
319 regs.R_ES = X86BIOS_PHYSTOSEG(offs);
320 regs.R_DI = X86BIOS_PHYSTOOFF(offs);
322 x86bios_intr(®s, 0x10);
324 if (regs.R_AX != 0x004f) {
325 x86bios_free(buf, sizeof(*vmode));
329 bcopy(buf, vmode, sizeof(*vmode));
330 x86bios_free(buf, sizeof(*vmode));
336 vesa_bios_set_mode(int mode)
340 x86bios_init_regs(®s);
344 x86bios_intr(®s, 0x10);
346 return (regs.R_AX != 0x004f);
351 vesa_bios_get_dac(void)
355 x86bios_init_regs(®s);
359 x86bios_intr(®s, 0x10);
361 if (regs.R_AX != 0x004f)
369 vesa_bios_set_dac(int bits)
373 x86bios_init_regs(®s);
378 x86bios_intr(®s, 0x10);
380 if (regs.R_AX != 0x004f)
387 vesa_bios_save_palette(int start, int colors, u_char *palette, int bits)
392 x86bios_init_regs(®s);
398 regs.R_ES = X86BIOS_PHYSTOSEG(vesa_palette_offs);
399 regs.R_DI = X86BIOS_PHYSTOOFF(vesa_palette_offs);
402 mtx_lock(&vesa_lock);
403 x86bios_intr(®s, 0x10);
404 if (regs.R_AX != 0x004f) {
405 mtx_unlock(&vesa_lock);
408 for (i = 0; i < colors; ++i) {
409 palette[i * 3] = vesa_palette[i * 4 + 2] << bits;
410 palette[i * 3 + 1] = vesa_palette[i * 4 + 1] << bits;
411 palette[i * 3 + 2] = vesa_palette[i * 4] << bits;
413 mtx_unlock(&vesa_lock);
419 vesa_bios_save_palette2(int start, int colors, u_char *r, u_char *g, u_char *b,
425 x86bios_init_regs(®s);
431 regs.R_ES = X86BIOS_PHYSTOSEG(vesa_palette_offs);
432 regs.R_DI = X86BIOS_PHYSTOOFF(vesa_palette_offs);
435 mtx_lock(&vesa_lock);
436 x86bios_intr(®s, 0x10);
437 if (regs.R_AX != 0x004f) {
438 mtx_unlock(&vesa_lock);
441 for (i = 0; i < colors; ++i) {
442 r[i] = vesa_palette[i * 4 + 2] << bits;
443 g[i] = vesa_palette[i * 4 + 1] << bits;
444 b[i] = vesa_palette[i * 4] << bits;
446 mtx_unlock(&vesa_lock);
452 vesa_bios_load_palette(int start, int colors, u_char *palette, int bits)
457 x86bios_init_regs(®s);
463 regs.R_ES = X86BIOS_PHYSTOSEG(vesa_palette_offs);
464 regs.R_DI = X86BIOS_PHYSTOOFF(vesa_palette_offs);
467 mtx_lock(&vesa_lock);
468 for (i = 0; i < colors; ++i) {
469 vesa_palette[i * 4] = palette[i * 3 + 2] >> bits;
470 vesa_palette[i * 4 + 1] = palette[i * 3 + 1] >> bits;
471 vesa_palette[i * 4 + 2] = palette[i * 3] >> bits;
472 vesa_palette[i * 4 + 3] = 0;
474 x86bios_intr(®s, 0x10);
475 mtx_unlock(&vesa_lock);
477 return (regs.R_AX != 0x004f);
481 vesa_bios_load_palette2(int start, int colors, u_char *r, u_char *g, u_char *b,
487 x86bios_init_regs(®s);
493 regs.R_ES = X86BIOS_PHYSTOSEG(vesa_palette_offs);
494 regs.R_DI = X86BIOS_PHYSTOOFF(vesa_palette_offs);
497 mtx_lock(&vesa_lock);
498 for (i = 0; i < colors; ++i) {
499 vesa_palette[i * 4] = b[i] >> bits;
500 vesa_palette[i * 4 + 1] = g[i] >> bits;
501 vesa_palette[i * 4 + 2] = r[i] >> bits;
502 vesa_palette[i * 4 + 3] = 0;
504 x86bios_intr(®s, 0x10);
505 mtx_unlock(&vesa_lock);
507 return (regs.R_AX != 0x004f);
511 vesa_bios_state_buf_size(int state)
515 x86bios_init_regs(®s);
517 /* regs.R_DL = STATE_SIZE; */
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)
533 if (code != STATE_SAVE && code != STATE_LOAD)
536 x86bios_init_regs(®s);
539 regs.R_CX = vesa_state;
541 regs.R_ES = X86BIOS_PHYSTOSEG(vesa_state_buf_offs);
542 regs.R_BX = X86BIOS_PHYSTOOFF(vesa_state_buf_offs);
544 mtx_lock(&vesa_lock);
547 x86bios_intr(®s, 0x10);
548 if (regs.R_AX == 0x004f)
549 bcopy(vesa_state_buf, p, vesa_state_buf_size);
552 bcopy(p, vesa_state_buf, vesa_state_buf_size);
553 x86bios_intr(®s, 0x10);
556 mtx_unlock(&vesa_lock);
558 return (regs.R_AX != 0x004f);
561 #ifdef MODE_TABLE_BROKEN
563 vesa_bios_get_line_length(void)
567 x86bios_init_regs(®s);
571 x86bios_intr(®s, 0x10);
573 if (regs.R_AX != 0x004f)
581 vesa_bios_set_line_length(int pixel, int *bytes, int *lines)
585 x86bios_init_regs(®s);
590 x86bios_intr(®s, 0x10);
593 printf("bx:%d, cx:%d, dx:%d\n", regs.R_BX, regs.R_CX, regs.R_DX);
595 if (regs.R_AX != 0x004f)
608 vesa_bios_get_start(int *x, int *y)
612 x86bios_init_regs(®s);
616 x86bios_intr(®s, 0x10);
618 if (regs.R_AX != 0x004f)
629 vesa_bios_set_start(int x, int y)
633 x86bios_init_regs(®s);
639 x86bios_intr(®s, 0x10);
641 return (regs.R_AX != 0x004f);
644 /* map a generic video mode to a known mode */
646 vesa_map_gen_mode_num(int type, int color, int mode)
652 { M_TEXT_132x25, M_VESA_C132x25 },
653 { M_TEXT_132x43, M_VESA_C132x43 },
654 { M_TEXT_132x50, M_VESA_C132x50 },
655 { M_TEXT_132x60, M_VESA_C132x60 },
659 for (i = 0; i < nitems(mode_map); ++i) {
660 if (mode_map[i].from == mode)
661 return (mode_map[i].to);
667 vesa_translate_flags(u_int16_t vflags)
674 { V_MODECOLOR, V_INFO_COLOR, 0 },
675 { V_MODEGRAPHICS, V_INFO_GRAPHICS, 0 },
676 { V_MODELFB, V_INFO_LINEAR, 0 },
677 { V_MODENONVGA, V_INFO_NONVGA, 0 },
682 for (flags = 0, i = 0; i < nitems(ftable); ++i) {
683 flags |= (vflags & ftable[i].mask) ?
684 ftable[i].set : ftable[i].reset;
690 vesa_translate_mmodel(u_int8_t vmodel)
696 { V_MMTEXT, V_INFO_MM_TEXT },
697 { V_MMCGA, V_INFO_MM_CGA },
698 { V_MMHGC, V_INFO_MM_HGC },
699 { V_MMEGA, V_INFO_MM_PLANAR },
700 { V_MMPACKED, V_INFO_MM_PACKED },
701 { V_MMDIRCOLOR, V_INFO_MM_DIRECT },
705 for (i = 0; mtable[i].mmodel >= 0; ++i) {
706 if (mtable[i].vmodel == vmodel)
707 return (mtable[i].mmodel);
709 return (V_INFO_MM_OTHER);
713 vesa_get_bpscanline(struct vesa_mode *vmode)
717 if ((vmode->v_modeattr & V_MODEGRAPHICS) != 0) {
718 /* Find the minimum length. */
719 switch (vmode->v_bpp / vmode->v_planes) {
721 bpsl = vmode->v_width / 8;
724 bpsl = vmode->v_width / 4;
727 bpsl = vmode->v_width / 2;
730 bpsl = vmode->v_width * ((vmode->v_bpp + 7) / 8);
731 bpsl /= vmode->v_planes;
735 /* Use VBE 3.0 information if it looks sane. */
736 if ((vmode->v_modeattr & V_MODELFB) != 0 &&
737 vesa_adp_info->v_version >= 0x0300 &&
738 vmode->v_linbpscanline > bpsl)
739 return (vmode->v_linbpscanline);
741 /* Return the minimum if the mode table looks absurd. */
742 if (vmode->v_bpscanline < bpsl)
746 return (vmode->v_bpscanline);
749 #define VESA_MAXSTR 256
751 #define VESA_STRCPY(dst, src) do { \
754 dst = malloc(VESA_MAXSTR, M_DEVBUF, M_WAITOK); \
755 str = x86bios_offset(BIOS_SADDRTOLADDR(src)); \
756 for (i = 0; i < VESA_MAXSTR - 1 && str[i] != '\0'; i++) \
764 struct vesa_mode vmode;
765 struct vesa_info *buf;
781 vesa_bios_offs = VESA_BIOS_OFFSET;
784 * If the VBE real mode interrupt vector is not found, try BIOS POST.
786 vesa_bios_int10 = x86bios_get_intr(0x10);
787 if (vesa_bios_int10 == 0) {
788 if (vesa_bios_post() != 0)
790 vesa_bios_int10 = x86bios_get_intr(0x10);
791 if (vesa_bios_int10 == 0)
798 offs = vesa_bios_int10;
799 if (vesa_shadow_rom) {
800 vbios = x86bios_get_orm(vesa_bios_offs);
802 vesa_bios_size = vbios[2] * 512;
803 if (((VESA_BIOS_OFFSET << 12) & 0xffff0000) ==
804 (vesa_bios_int10 & 0xffff0000) &&
805 vesa_bios_size > (vesa_bios_int10 & 0xffff)) {
806 vesa_bios = x86bios_alloc(&vesa_bios_offs,
807 vesa_bios_size, M_WAITOK);
808 bcopy(vbios, vesa_bios, vesa_bios_size);
809 offs = ((vesa_bios_offs << 12) & 0xffff0000) +
810 (vesa_bios_int10 & 0xffff);
811 x86bios_set_intr(0x10, offs);
814 if (vesa_bios == NULL)
815 printf("VESA: failed to shadow video ROM\n");
818 printf("VESA: INT 0x10 vector 0x%04x:0x%04x\n",
819 (offs >> 16) & 0xffff, offs & 0xffff);
821 x86bios_init_regs(®s);
824 vmbuf = x86bios_alloc(&offs, sizeof(*buf), M_WAITOK);
826 regs.R_ES = X86BIOS_PHYSTOSEG(offs);
827 regs.R_DI = X86BIOS_PHYSTOOFF(offs);
829 bcopy("VBE2", vmbuf, 4); /* try for VBE2 data */
830 x86bios_intr(®s, 0x10);
832 if (regs.R_AX != 0x004f || bcmp("VESA", vmbuf, 4) != 0)
835 vesa_adp_info = buf = malloc(sizeof(*buf), M_DEVBUF, M_WAITOK);
836 bcopy(vmbuf, buf, sizeof(*buf));
839 printf("VESA: information block\n");
840 hexdump(buf, sizeof(*buf), NULL, HD_OMIT_CHARS);
843 vers = buf->v_version = le16toh(buf->v_version);
844 buf->v_oemstr = le32toh(buf->v_oemstr);
845 buf->v_flags = le32toh(buf->v_flags);
846 buf->v_modetable = le32toh(buf->v_modetable);
847 buf->v_memsize = le16toh(buf->v_memsize);
848 buf->v_revision = le16toh(buf->v_revision);
849 buf->v_venderstr = le32toh(buf->v_venderstr);
850 buf->v_prodstr = le32toh(buf->v_prodstr);
851 buf->v_revstr = le32toh(buf->v_revstr);
854 printf("VESA: VBE version %d.%d is not supported; "
855 "version 1.2 or later is required.\n",
856 ((vers & 0xf000) >> 12) * 10 + ((vers & 0x0f00) >> 8),
857 ((vers & 0x00f0) >> 4) * 10 + (vers & 0x000f));
861 VESA_STRCPY(vesa_oemstr, buf->v_oemstr);
862 if (vers >= 0x0200) {
863 VESA_STRCPY(vesa_venderstr, buf->v_venderstr);
864 VESA_STRCPY(vesa_prodstr, buf->v_prodstr);
865 VESA_STRCPY(vesa_revstr, buf->v_revstr);
867 is_via_cle266 = strncmp(vesa_oemstr, VESA_VIA_CLE266,
868 sizeof(VESA_VIA_CLE266)) == 0;
870 if (buf->v_modetable == 0)
873 msize = (size_t)buf->v_memsize * 64 * 1024;
875 vesa_vmodetab = x86bios_offset(BIOS_SADDRTOLADDR(buf->v_modetable));
877 for (i = 0, modes = 0; (i < (M_VESA_MODE_MAX - M_VESA_BASE + 1)) &&
878 (vesa_vmodetab[i] != 0xffff); ++i) {
879 vesa_vmodetab[i] = le16toh(vesa_vmodetab[i]);
880 if (vesa_bios_get_mode(vesa_vmodetab[i], &vmode, M_WAITOK))
883 vmode.v_modeattr = le16toh(vmode.v_modeattr);
884 vmode.v_wgran = le16toh(vmode.v_wgran);
885 vmode.v_wsize = le16toh(vmode.v_wsize);
886 vmode.v_waseg = le16toh(vmode.v_waseg);
887 vmode.v_wbseg = le16toh(vmode.v_wbseg);
888 vmode.v_posfunc = le32toh(vmode.v_posfunc);
889 vmode.v_bpscanline = le16toh(vmode.v_bpscanline);
890 vmode.v_width = le16toh(vmode.v_width);
891 vmode.v_height = le16toh(vmode.v_height);
892 vmode.v_lfb = le32toh(vmode.v_lfb);
893 vmode.v_offscreen = le32toh(vmode.v_offscreen);
894 vmode.v_offscreensize = le16toh(vmode.v_offscreensize);
895 vmode.v_linbpscanline = le16toh(vmode.v_linbpscanline);
896 vmode.v_maxpixelclock = le32toh(vmode.v_maxpixelclock);
898 /* reject unsupported modes */
900 if ((vmode.v_modeattr &
901 (V_MODESUPP | V_MODEOPTINFO | V_MODENONVGA)) !=
902 (V_MODESUPP | V_MODEOPTINFO))
905 if ((vmode.v_modeattr & V_MODEOPTINFO) == 0) {
907 printf("Rejecting VESA %s mode: %d x %d x %d bpp "
909 vmode.v_modeattr & V_MODEGRAPHICS ?
911 vmode.v_width, vmode.v_height, vmode.v_bpp,
918 bsize = vesa_get_bpscanline(&vmode) * vmode.v_height;
919 if ((vmode.v_modeattr & V_MODEGRAPHICS) != 0)
920 bsize *= vmode.v_planes;
922 /* Does it have enough memory to support this mode? */
925 printf("Rejecting VESA %s mode: %d x %d x %d bpp "
926 " attr = %x, not enough memory\n",
927 vmode.v_modeattr & V_MODEGRAPHICS ?
929 vmode.v_width, vmode.v_height, vmode.v_bpp,
934 if (bsize > vesa_vmem_max)
935 vesa_vmem_max = bsize;
937 /* expand the array if necessary */
938 if (modes >= vesa_vmode_max) {
939 vesa_vmode_max += MODE_TABLE_DELTA;
940 p = malloc(sizeof(*vesa_vmode) * (vesa_vmode_max + 1),
943 printf("vesa_bios_init(): modes:%d, vesa_mode_max:%d\n",
944 modes, vesa_vmode_max);
947 bcopy(vesa_vmode, p, sizeof(*vesa_vmode)*modes);
948 free(vesa_vmode, M_DEVBUF);
954 printf("Found VESA %s mode: %d x %d x %d bpp\n",
955 vmode.v_modeattr & V_MODEGRAPHICS ? "graphics" : "text",
956 vmode.v_width, vmode.v_height, vmode.v_bpp);
959 if ((vmode.v_width & 0xff00) >> 8 == vmode.v_height - 1) {
960 vmode.v_width &= 0xff;
961 vmode.v_waseg = 0xb8000 >> 4;
965 /* copy some fields */
966 bzero(&vesa_vmode[modes], sizeof(vesa_vmode[modes]));
967 vesa_vmode[modes].vi_mode = vesa_vmodetab[i];
968 vesa_vmode[modes].vi_width = vmode.v_width;
969 vesa_vmode[modes].vi_height = vmode.v_height;
970 vesa_vmode[modes].vi_depth = vmode.v_bpp;
971 vesa_vmode[modes].vi_planes = vmode.v_planes;
972 vesa_vmode[modes].vi_cwidth = vmode.v_cwidth;
973 vesa_vmode[modes].vi_cheight = vmode.v_cheight;
974 vesa_vmode[modes].vi_window = (vm_offset_t)vmode.v_waseg << 4;
976 vesa_vmode[modes].vi_window_size = vmode.v_wsize * 1024;
977 vesa_vmode[modes].vi_window_gran = vmode.v_wgran * 1024;
978 if (vmode.v_modeattr & V_MODELFB)
979 vesa_vmode[modes].vi_buffer = vmode.v_lfb;
980 vesa_vmode[modes].vi_buffer_size = bsize;
981 vesa_vmode[modes].vi_mem_model =
982 vesa_translate_mmodel(vmode.v_memmodel);
983 switch (vesa_vmode[modes].vi_mem_model) {
984 case V_INFO_MM_DIRECT:
985 if ((vmode.v_modeattr & V_MODELFB) != 0 &&
987 vesa_vmode[modes].vi_pixel_fields[0] =
988 vmode.v_linredfieldpos;
989 vesa_vmode[modes].vi_pixel_fields[1] =
990 vmode.v_lingreenfieldpos;
991 vesa_vmode[modes].vi_pixel_fields[2] =
992 vmode.v_linbluefieldpos;
993 vesa_vmode[modes].vi_pixel_fields[3] =
994 vmode.v_linresfieldpos;
995 vesa_vmode[modes].vi_pixel_fsizes[0] =
996 vmode.v_linredmasksize;
997 vesa_vmode[modes].vi_pixel_fsizes[1] =
998 vmode.v_lingreenmasksize;
999 vesa_vmode[modes].vi_pixel_fsizes[2] =
1000 vmode.v_linbluemasksize;
1001 vesa_vmode[modes].vi_pixel_fsizes[3] =
1002 vmode.v_linresmasksize;
1004 vesa_vmode[modes].vi_pixel_fields[0] =
1005 vmode.v_redfieldpos;
1006 vesa_vmode[modes].vi_pixel_fields[1] =
1007 vmode.v_greenfieldpos;
1008 vesa_vmode[modes].vi_pixel_fields[2] =
1009 vmode.v_bluefieldpos;
1010 vesa_vmode[modes].vi_pixel_fields[3] =
1011 vmode.v_resfieldpos;
1012 vesa_vmode[modes].vi_pixel_fsizes[0] =
1013 vmode.v_redmasksize;
1014 vesa_vmode[modes].vi_pixel_fsizes[1] =
1015 vmode.v_greenmasksize;
1016 vesa_vmode[modes].vi_pixel_fsizes[2] =
1017 vmode.v_bluemasksize;
1018 vesa_vmode[modes].vi_pixel_fsizes[3] =
1019 vmode.v_resmasksize;
1022 case V_INFO_MM_PACKED:
1023 vesa_vmode[modes].vi_pixel_size = (vmode.v_bpp + 7) / 8;
1026 vesa_vmode[modes].vi_flags =
1027 vesa_translate_flags(vmode.v_modeattr) | V_INFO_VESA;
1031 if (vesa_vmode != NULL)
1032 vesa_vmode[modes].vi_mode = EOT;
1035 printf("VESA: %d mode(s) found\n", modes);
1040 x86bios_free(vmbuf, sizeof(*buf));
1042 /* Probe supported save/restore states. */
1043 for (i = 0; i < 4; i++)
1044 if (vesa_bios_state_buf_size(1 << i) > 0)
1045 vesa_state |= 1 << i;
1046 if (vesa_state != 0)
1047 vesa_state_buf_size = vesa_bios_state_buf_size(vesa_state);
1048 vesa_palette = x86bios_alloc(&vesa_palette_offs,
1049 VESA_PALETTE_SIZE + vesa_state_buf_size, M_WAITOK);
1050 if (vesa_state_buf_size > 0) {
1051 vesa_state_buf = vesa_palette + VESA_PALETTE_SIZE;
1052 vesa_state_buf_offs = vesa_palette_offs + VESA_PALETTE_SIZE;
1058 x86bios_free(vmbuf, sizeof(buf));
1064 vesa_bios_uninit(void)
1067 if (vesa_bios != NULL) {
1068 x86bios_set_intr(0x10, vesa_bios_int10);
1069 vesa_bios_offs = VESA_BIOS_OFFSET;
1070 x86bios_free(vesa_bios, vesa_bios_size);
1073 if (vesa_adp_info != NULL) {
1074 free(vesa_adp_info, M_DEVBUF);
1075 vesa_adp_info = NULL;
1077 if (vesa_oemstr != NULL) {
1078 free(vesa_oemstr, M_DEVBUF);
1081 if (vesa_venderstr != NULL) {
1082 free(vesa_venderstr, M_DEVBUF);
1083 vesa_venderstr = NULL;
1085 if (vesa_prodstr != NULL) {
1086 free(vesa_prodstr, M_DEVBUF);
1087 vesa_prodstr = NULL;
1089 if (vesa_revstr != NULL) {
1090 free(vesa_revstr, M_DEVBUF);
1093 if (vesa_vmode != NULL) {
1094 free(vesa_vmode, M_DEVBUF);
1097 if (vesa_palette != NULL) {
1098 x86bios_free(vesa_palette,
1099 VESA_PALETTE_SIZE + vesa_state_buf_size);
1100 vesa_palette = NULL;
1105 vesa_clear_modes(video_info_t *info, int color)
1107 while (info->vi_mode != EOT) {
1108 if ((info->vi_flags & V_INFO_COLOR) != color)
1117 vesa_configure(int flags)
1119 video_adapter_t *adp;
1126 if (flags & VIO_PROBE_ONLY)
1130 * If the VESA module has already been loaded, abort loading
1131 * the module this time.
1133 for (i = 0; (adp = vid_get_adapter(i)) != NULL; ++i) {
1134 if (adp->va_flags & V_ADP_VESA)
1136 if (adp->va_type == KD_VGA)
1141 * The VGA adapter is not found. This is because either
1142 * 1) the VGA driver has not been initialized, or 2) the VGA card
1143 * is not present. If 1) is the case, we shall defer
1144 * initialization for now and try again later.
1147 vga_sub_configure = vesa_configure;
1151 /* count number of registered adapters */
1152 for (++i; vid_get_adapter(i) != NULL; ++i)
1156 /* call VESA BIOS */
1158 if (vesa_bios_init()) {
1162 vesa_adp->va_flags |= V_ADP_VESA;
1164 /* remove conflicting modes if we have more than one adapter */
1166 vesa_clear_modes(vesa_vmode,
1167 (vesa_adp->va_flags & V_ADP_COLOR) ?
1171 if ((error = vesa_load_ioctl()) == 0) {
1172 prevvidsw = vidsw[vesa_adp->va_index];
1173 vidsw[vesa_adp->va_index] = &vesavidsw;
1174 vesa_init_done = TRUE;
1200 vesa_probe(int unit, video_adapter_t **adpp, void *arg, int flags)
1203 return ((*prevvidsw->probe)(unit, adpp, arg, flags));
1207 vesa_init(int unit, video_adapter_t *adp, int flags)
1210 return ((*prevvidsw->init)(unit, adp, flags));
1214 vesa_get_info(video_adapter_t *adp, int mode, video_info_t *info)
1218 if ((*prevvidsw->get_info)(adp, mode, info) == 0)
1221 if (adp != vesa_adp)
1224 mode = vesa_map_gen_mode_num(vesa_adp->va_type,
1225 vesa_adp->va_flags & V_ADP_COLOR, mode);
1226 for (i = 0; vesa_vmode[i].vi_mode != EOT; ++i) {
1227 if (vesa_vmode[i].vi_mode == NA)
1229 if (vesa_vmode[i].vi_mode == mode) {
1230 *info = vesa_vmode[i];
1238 vesa_query_mode(video_adapter_t *adp, video_info_t *info)
1242 if ((*prevvidsw->query_mode)(adp, info) == 0)
1244 if (adp != vesa_adp)
1247 for (i = 0; vesa_vmode[i].vi_mode != EOT; ++i) {
1248 if ((info->vi_width != 0)
1249 && (info->vi_width != vesa_vmode[i].vi_width))
1251 if ((info->vi_height != 0)
1252 && (info->vi_height != vesa_vmode[i].vi_height))
1254 if ((info->vi_cwidth != 0)
1255 && (info->vi_cwidth != vesa_vmode[i].vi_cwidth))
1257 if ((info->vi_cheight != 0)
1258 && (info->vi_cheight != vesa_vmode[i].vi_cheight))
1260 if ((info->vi_depth != 0)
1261 && (info->vi_depth != vesa_vmode[i].vi_depth))
1263 if ((info->vi_planes != 0)
1264 && (info->vi_planes != vesa_vmode[i].vi_planes))
1266 /* pixel format, memory model */
1267 if ((info->vi_flags != 0)
1268 && (info->vi_flags != vesa_vmode[i].vi_flags))
1270 *info = vesa_vmode[i];
1277 vesa_set_mode(video_adapter_t *adp, int mode)
1281 if (adp != vesa_adp)
1282 return ((*prevvidsw->set_mode)(adp, mode));
1284 mode = vesa_map_gen_mode_num(adp->va_type,
1285 adp->va_flags & V_ADP_COLOR, mode);
1287 printf("VESA: set_mode(): %d(%x) -> %d(%x)\n",
1288 adp->va_mode, adp->va_mode, mode, mode);
1291 * If the current mode is a VESA mode and the new mode is not,
1292 * restore the state of the adapter first by setting one of the
1293 * standard VGA mode, so that non-standard, extended SVGA registers
1294 * are set to the state compatible with the standard VGA modes.
1295 * Otherwise (*prevvidsw->set_mode)() may not be able to set up
1296 * the new mode correctly.
1298 if (VESA_MODE(adp->va_mode)) {
1299 if (!VESA_MODE(mode) &&
1300 (*prevvidsw->get_info)(adp, mode, &info) == 0) {
1301 if ((adp->va_flags & V_ADP_DAC8) != 0) {
1302 vesa_bios_set_dac(6);
1303 adp->va_flags &= ~V_ADP_DAC8;
1305 int10_set_mode(adp->va_initial_bios_mode);
1306 if (adp->va_info.vi_flags & V_INFO_LINEAR)
1307 pmap_unmapdev(adp->va_buffer, vesa_vmem_max);
1309 * Once (*prevvidsw->get_info)() succeeded,
1310 * (*prevvidsw->set_mode)() below won't fail...
1315 /* we may not need to handle this mode after all... */
1316 if (!VESA_MODE(mode) && (*prevvidsw->set_mode)(adp, mode) == 0)
1319 /* is the new mode supported? */
1320 if (vesa_get_info(adp, mode, &info))
1322 /* assert(VESA_MODE(mode)); */
1325 printf("VESA: about to set a VESA mode...\n");
1328 * The mode change should reset the palette format to 6 bits, so
1329 * we must reset V_ADP_DAC8. Some BIOSes do an incomplete reset
1330 * if we call them with an 8-bit palette, so reset directly.
1332 if (adp->va_flags & V_ADP_DAC8) {
1333 vesa_bios_set_dac(6);
1334 adp->va_flags &= ~V_ADP_DAC8;
1337 /* don't use the linear frame buffer for text modes. XXX */
1338 if (!(info.vi_flags & V_INFO_GRAPHICS))
1339 info.vi_flags &= ~V_INFO_LINEAR;
1341 if ((info.vi_flags & V_INFO_LINEAR) != 0)
1343 if (vesa_bios_set_mode(mode | 0x8000))
1346 if ((vesa_adp_info->v_flags & V_DAC8) != 0 &&
1347 (info.vi_flags & V_INFO_GRAPHICS) != 0 &&
1348 vesa_bios_set_dac(8) > 6)
1349 adp->va_flags |= V_ADP_DAC8;
1351 if (adp->va_info.vi_flags & V_INFO_LINEAR)
1352 pmap_unmapdev(adp->va_buffer, vesa_vmem_max);
1355 printf("VESA: mode set!\n");
1357 vesa_adp->va_mode = mode & 0x1ff; /* Mode number is 9-bit. */
1358 vesa_adp->va_flags &= ~V_ADP_COLOR;
1359 vesa_adp->va_flags |=
1360 (info.vi_flags & V_INFO_COLOR) ? V_ADP_COLOR : 0;
1361 vesa_adp->va_crtc_addr =
1362 (vesa_adp->va_flags & V_ADP_COLOR) ? COLOR_CRTC : MONO_CRTC;
1364 vesa_adp->va_flags &= ~V_ADP_CWIDTH9;
1365 vesa_adp->va_line_width = info.vi_buffer_size / info.vi_height;
1366 if ((info.vi_flags & V_INFO_GRAPHICS) != 0)
1367 vesa_adp->va_line_width /= info.vi_planes;
1369 #ifdef MODE_TABLE_BROKEN
1370 /* If VBE function returns bigger bytes per scan line, use it. */
1372 int bpsl = vesa_bios_get_line_length();
1373 if (bpsl > vesa_adp->va_line_width) {
1374 vesa_adp->va_line_width = bpsl;
1375 info.vi_buffer_size = bpsl * info.vi_height;
1376 if ((info.vi_flags & V_INFO_GRAPHICS) != 0)
1377 info.vi_buffer_size *= info.vi_planes;
1382 if (info.vi_flags & V_INFO_LINEAR) {
1384 printf("VESA: setting up LFB\n");
1386 vesa_adp->va_buffer =
1387 (vm_offset_t)pmap_mapdev_attr(info.vi_buffer,
1388 vesa_vmem_max, PAT_WRITE_COMBINING);
1389 vesa_adp->va_window = vesa_adp->va_buffer;
1390 vesa_adp->va_window_size = info.vi_buffer_size / info.vi_planes;
1391 vesa_adp->va_window_gran = info.vi_buffer_size / info.vi_planes;
1393 vesa_adp->va_buffer = 0;
1394 vesa_adp->va_window = (vm_offset_t)x86bios_offset(info.vi_window);
1395 vesa_adp->va_window_size = info.vi_window_size;
1396 vesa_adp->va_window_gran = info.vi_window_gran;
1398 vesa_adp->va_buffer_size = info.vi_buffer_size;
1399 vesa_adp->va_window_orig = 0;
1400 vesa_adp->va_disp_start.x = 0;
1401 vesa_adp->va_disp_start.y = 0;
1403 printf("vesa_set_mode(): vi_width:%d, line_width:%d\n",
1404 info.vi_width, vesa_adp->va_line_width);
1406 bcopy(&info, &vesa_adp->va_info, sizeof(vesa_adp->va_info));
1408 /* move hardware cursor out of the way */
1409 (*vidsw[vesa_adp->va_index]->set_hw_cursor)(vesa_adp, -1, -1);
1415 vesa_save_font(video_adapter_t *adp, int page, int fontsize, int fontwidth,
1416 u_char *data, int ch, int count)
1419 return ((*prevvidsw->save_font)(adp, page, fontsize, fontwidth, data,
1424 vesa_load_font(video_adapter_t *adp, int page, int fontsize, int fontwidth,
1425 u_char *data, int ch, int count)
1428 return ((*prevvidsw->load_font)(adp, page, fontsize, fontwidth, data,
1433 vesa_show_font(video_adapter_t *adp, int page)
1436 return ((*prevvidsw->show_font)(adp, page));
1440 vesa_save_palette(video_adapter_t *adp, u_char *palette)
1444 if (adp == vesa_adp && VESA_MODE(adp->va_mode)) {
1445 bits = (adp->va_flags & V_ADP_DAC8) != 0 ? 8 : 6;
1446 if (vesa_bios_save_palette(0, 256, palette, bits) == 0)
1450 return ((*prevvidsw->save_palette)(adp, palette));
1454 vesa_load_palette(video_adapter_t *adp, u_char *palette)
1458 if (adp == vesa_adp && VESA_MODE(adp->va_mode)) {
1459 bits = (adp->va_flags & V_ADP_DAC8) != 0 ? 8 : 6;
1460 if (vesa_bios_load_palette(0, 256, palette, bits) == 0)
1464 return ((*prevvidsw->load_palette)(adp, palette));
1468 vesa_set_border(video_adapter_t *adp, int color)
1471 return ((*prevvidsw->set_border)(adp, color));
1475 vesa_save_state(video_adapter_t *adp, void *p, size_t size)
1480 if (adp != vesa_adp || (size == 0 && vesa_state_buf_size == 0))
1481 return ((*prevvidsw->save_state)(adp, p, size));
1483 bsize = offsetof(adp_state_t, regs) + vesa_state_buf_size;
1486 if (vesa_state_buf_size > 0 && size < bsize)
1489 if (vesa_vmem_buf != NULL) {
1490 free(vesa_vmem_buf, M_DEVBUF);
1491 vesa_vmem_buf = NULL;
1493 if (VESA_MODE(adp->va_mode)) {
1494 buf = (void *)adp->va_buffer;
1496 bsize = adp->va_buffer_size;
1497 vesa_vmem_buf = malloc(bsize, M_DEVBUF, M_NOWAIT);
1498 if (vesa_vmem_buf != NULL)
1499 bcopy(buf, vesa_vmem_buf, bsize);
1502 if (vesa_state_buf_size == 0)
1503 return ((*prevvidsw->save_state)(adp, p, size));
1504 ((adp_state_t *)p)->sig = V_STATE_SIG;
1505 return (vesa_bios_save_restore(STATE_SAVE, ((adp_state_t *)p)->regs));
1509 vesa_load_state(video_adapter_t *adp, void *p)
1515 if (adp != vesa_adp)
1516 return ((*prevvidsw->load_state)(adp, p));
1518 /* Try BIOS POST to restore a sane state. */
1519 (void)vesa_bios_post();
1520 bsize = adp->va_buffer_size;
1521 mode = adp->va_mode;
1522 error = vesa_set_mode(adp, adp->va_initial_mode);
1523 if (mode != adp->va_initial_mode)
1524 error = vesa_set_mode(adp, mode);
1526 if (vesa_vmem_buf != NULL) {
1527 if (error == 0 && VESA_MODE(mode)) {
1528 buf = (void *)adp->va_buffer;
1530 bcopy(vesa_vmem_buf, buf, bsize);
1532 free(vesa_vmem_buf, M_DEVBUF);
1533 vesa_vmem_buf = NULL;
1535 if (((adp_state_t *)p)->sig != V_STATE_SIG)
1536 return ((*prevvidsw->load_state)(adp, p));
1537 return (vesa_bios_save_restore(STATE_LOAD, ((adp_state_t *)p)->regs));
1542 vesa_get_origin(video_adapter_t *adp, off_t *offset)
1546 x86bios_init_regs(®s);
1550 x86bios_intr(®s, 0x10);
1552 if (regs.R_AX != 0x004f)
1554 *offset = regs.DX * adp->va_window_gran;
1561 vesa_set_origin(video_adapter_t *adp, off_t offset)
1566 * This function should return as quickly as possible to
1567 * maintain good performance of the system. For this reason,
1568 * error checking is kept minimal and let the VESA BIOS to
1571 if (adp != vesa_adp)
1572 return ((*prevvidsw->set_win_org)(adp, offset));
1574 /* if this is a linear frame buffer, do nothing */
1575 if (adp->va_info.vi_flags & V_INFO_LINEAR)
1578 if (adp->va_window_gran == 0)
1581 x86bios_init_regs(®s);
1583 regs.R_DX = offset / adp->va_window_gran;
1585 x86bios_intr(®s, 0x10);
1587 if (regs.R_AX != 0x004f)
1590 x86bios_init_regs(®s);
1593 regs.R_DX = offset / adp->va_window_gran;
1594 x86bios_intr(®s, 0x10);
1596 adp->va_window_orig = rounddown(offset, adp->va_window_gran);
1597 return (0); /* XXX */
1601 vesa_read_hw_cursor(video_adapter_t *adp, int *col, int *row)
1604 return ((*prevvidsw->read_hw_cursor)(adp, col, row));
1608 vesa_set_hw_cursor(video_adapter_t *adp, int col, int row)
1611 return ((*prevvidsw->set_hw_cursor)(adp, col, row));
1615 vesa_set_hw_cursor_shape(video_adapter_t *adp, int base, int height,
1616 int celsize, int blink)
1619 return ((*prevvidsw->set_hw_cursor_shape)(adp, base, height, celsize,
1624 vesa_blank_display(video_adapter_t *adp, int mode)
1627 /* XXX: use VESA DPMS */
1628 return ((*prevvidsw->blank_display)(adp, mode));
1632 vesa_mmap(video_adapter_t *adp, vm_ooffset_t offset, vm_paddr_t *paddr,
1633 int prot, vm_memattr_t *memattr)
1637 printf("vesa_mmap(): window:0x%tx, buffer:0x%tx, offset:0x%jx\n",
1638 adp->va_info.vi_window, adp->va_info.vi_buffer, offset);
1641 if ((adp == vesa_adp) &&
1642 (adp->va_info.vi_flags & V_INFO_LINEAR) != 0) {
1643 /* va_window_size == va_buffer_size/vi_planes */
1644 /* XXX: is this correct? */
1645 if (offset > adp->va_window_size - PAGE_SIZE)
1647 *paddr = adp->va_info.vi_buffer + offset;
1648 #ifdef VM_MEMATTR_WRITE_COMBINING
1649 *memattr = VM_MEMATTR_WRITE_COMBINING;
1653 return ((*prevvidsw->mmap)(adp, offset, paddr, prot, memattr));
1657 vesa_clear(video_adapter_t *adp)
1660 return ((*prevvidsw->clear)(adp));
1664 vesa_fill_rect(video_adapter_t *adp, int val, int x, int y, int cx, int cy)
1667 return ((*prevvidsw->fill_rect)(adp, val, x, y, cx, cy));
1671 vesa_bitblt(video_adapter_t *adp,...)
1679 get_palette(video_adapter_t *adp, int base, int count,
1680 u_char *red, u_char *green, u_char *blue, u_char *trans)
1688 if (base < 0 || base >= 256 || count < 0 || count > 256)
1690 if ((base + count) > 256)
1692 if (!VESA_MODE(adp->va_mode))
1695 bits = (adp->va_flags & V_ADP_DAC8) != 0 ? 8 : 6;
1696 r = malloc(count * 3, M_DEVBUF, M_WAITOK);
1699 error = vesa_bios_save_palette2(base, count, r, g, b, bits);
1701 copyout(r, red, count);
1702 copyout(g, green, count);
1703 copyout(b, blue, count);
1704 if (trans != NULL) {
1706 copyout(r, trans, count);
1715 set_palette(video_adapter_t *adp, int base, int count,
1716 u_char *red, u_char *green, u_char *blue, u_char *trans)
1724 if (base < 0 || base >= 256 || count < 0 || count > 256)
1726 if ((base + count) > 256)
1728 if (!VESA_MODE(adp->va_mode))
1731 bits = (adp->va_flags & V_ADP_DAC8) != 0 ? 8 : 6;
1732 r = malloc(count * 3, M_DEVBUF, M_WAITOK);
1735 copyin(red, r, count);
1736 copyin(green, g, count);
1737 copyin(blue, b, count);
1739 error = vesa_bios_load_palette2(base, count, r, g, b, bits);
1746 vesa_ioctl(video_adapter_t *adp, u_long cmd, caddr_t arg)
1750 if (adp != vesa_adp)
1751 return ((*prevvidsw->ioctl)(adp, cmd, arg));
1754 case FBIO_SETWINORG: /* set frame buffer window origin */
1755 if (!VESA_MODE(adp->va_mode))
1756 return (*prevvidsw->ioctl)(adp, cmd, arg);
1757 return (vesa_set_origin(adp, *(off_t *)arg) ? ENODEV : 0);
1759 case FBIO_SETDISPSTART: /* set display start address */
1760 if (!VESA_MODE(adp->va_mode))
1761 return ((*prevvidsw->ioctl)(adp, cmd, arg));
1762 if (vesa_bios_set_start(((video_display_start_t *)arg)->x,
1763 ((video_display_start_t *)arg)->y))
1765 adp->va_disp_start.x = ((video_display_start_t *)arg)->x;
1766 adp->va_disp_start.y = ((video_display_start_t *)arg)->y;
1769 case FBIO_SETLINEWIDTH: /* set line length in pixel */
1770 if (!VESA_MODE(adp->va_mode))
1771 return ((*prevvidsw->ioctl)(adp, cmd, arg));
1772 if (vesa_bios_set_line_length(*(u_int *)arg, &bytes, NULL))
1774 adp->va_line_width = bytes;
1776 printf("new line width:%d\n", adp->va_line_width);
1780 case FBIO_GETPALETTE: /* get color palette */
1781 if (get_palette(adp, ((video_color_palette_t *)arg)->index,
1782 ((video_color_palette_t *)arg)->count,
1783 ((video_color_palette_t *)arg)->red,
1784 ((video_color_palette_t *)arg)->green,
1785 ((video_color_palette_t *)arg)->blue,
1786 ((video_color_palette_t *)arg)->transparent))
1787 return ((*prevvidsw->ioctl)(adp, cmd, arg));
1791 case FBIO_SETPALETTE: /* set color palette */
1792 if (set_palette(adp, ((video_color_palette_t *)arg)->index,
1793 ((video_color_palette_t *)arg)->count,
1794 ((video_color_palette_t *)arg)->red,
1795 ((video_color_palette_t *)arg)->green,
1796 ((video_color_palette_t *)arg)->blue,
1797 ((video_color_palette_t *)arg)->transparent))
1798 return ((*prevvidsw->ioctl)(adp, cmd, arg));
1801 case FBIOGETCMAP: /* get color palette */
1802 if (get_palette(adp, ((struct fbcmap *)arg)->index,
1803 ((struct fbcmap *)arg)->count,
1804 ((struct fbcmap *)arg)->red,
1805 ((struct fbcmap *)arg)->green,
1806 ((struct fbcmap *)arg)->blue, NULL))
1807 return ((*prevvidsw->ioctl)(adp, cmd, arg));
1810 case FBIOPUTCMAP: /* set color palette */
1811 if (set_palette(adp, ((struct fbcmap *)arg)->index,
1812 ((struct fbcmap *)arg)->count,
1813 ((struct fbcmap *)arg)->red,
1814 ((struct fbcmap *)arg)->green,
1815 ((struct fbcmap *)arg)->blue, NULL))
1816 return ((*prevvidsw->ioctl)(adp, cmd, arg));
1820 return ((*prevvidsw->ioctl)(adp, cmd, arg));
1825 vesa_diag(video_adapter_t *adp, int level)
1829 /* call the previous handler first */
1830 error = (*prevvidsw->diag)(adp, level);
1834 if (adp != vesa_adp)
1844 vesa_bios_info(int level)
1847 struct vesa_mode vmode;
1852 vers = vesa_adp_info->v_version;
1855 /* general adapter information */
1857 "VESA: v%d.%d, %dk memory, flags:0x%x, mode table:%p (%x)\n",
1858 (vers >> 12) * 10 + ((vers & 0x0f00) >> 8),
1859 ((vers & 0x00f0) >> 4) * 10 + (vers & 0x000f),
1860 vesa_adp_info->v_memsize * 64, vesa_adp_info->v_flags,
1861 vesa_vmodetab, vesa_adp_info->v_modetable);
1864 if (vesa_oemstr != NULL)
1865 printf("VESA: %s\n", vesa_oemstr);
1871 if (vers >= 0x0200 && bootverbose) {
1872 /* vender name, product name, product revision */
1873 printf("VESA: %s %s %s\n",
1874 (vesa_venderstr != NULL) ? vesa_venderstr : "unknown",
1875 (vesa_prodstr != NULL) ? vesa_prodstr : "unknown",
1876 (vesa_revstr != NULL) ? vesa_revstr : "?");
1880 /* mode information */
1882 (i < (M_VESA_MODE_MAX - M_VESA_BASE + 1))
1883 && (vesa_vmodetab[i] != 0xffff); ++i) {
1884 if (vesa_bios_get_mode(vesa_vmodetab[i], &vmode, M_NOWAIT))
1887 /* print something for diagnostic purpose */
1888 printf("VESA: mode:0x%03x, flags:0x%04x",
1889 vesa_vmodetab[i], vmode.v_modeattr);
1890 if (vmode.v_modeattr & V_MODEOPTINFO) {
1891 if (vmode.v_modeattr & V_MODEGRAPHICS) {
1892 printf(", G %dx%dx%d %d, ",
1893 vmode.v_width, vmode.v_height,
1894 vmode.v_bpp, vmode.v_planes);
1896 printf(", T %dx%d, ",
1897 vmode.v_width, vmode.v_height);
1899 printf("font:%dx%d, ",
1900 vmode.v_cwidth, vmode.v_cheight);
1901 printf("pages:%d, mem:%d",
1902 vmode.v_ipages + 1, vmode.v_memmodel);
1904 if (vmode.v_modeattr & V_MODELFB) {
1905 printf("\nVESA: LFB:0x%x, off:0x%x, off_size:0x%x",
1906 vmode.v_lfb, vmode.v_offscreen,
1907 vmode.v_offscreensize*1024);
1910 printf("VESA: window A:0x%x (%x), window B:0x%x (%x), ",
1911 vmode.v_waseg, vmode.v_waattr,
1912 vmode.v_wbseg, vmode.v_wbattr);
1913 printf("size:%dk, gran:%dk\n",
1914 vmode.v_wsize, vmode.v_wgran);
1916 #endif /* VESA_DEBUG > 1 */
1921 /* module loading */
1931 /* locate a VGA adapter */
1933 error = vesa_configure(0);
1936 vesa_bios_info(bootverbose);
1946 /* if the adapter is currently in a VESA mode, don't unload */
1947 if ((vesa_adp != NULL) && VESA_MODE(vesa_adp->va_mode))
1950 * FIXME: if there is at least one vty which is in a VESA mode,
1951 * we shouldn't be unloading! XXX
1954 if ((error = vesa_unload_ioctl()) == 0) {
1955 if (vesa_adp != NULL) {
1956 if ((vesa_adp->va_flags & V_ADP_DAC8) != 0) {
1957 vesa_bios_set_dac(6);
1958 vesa_adp->va_flags &= ~V_ADP_DAC8;
1960 vesa_adp->va_flags &= ~V_ADP_VESA;
1961 vidsw[vesa_adp->va_index] = prevvidsw;
1971 vesa_mod_event(module_t mod, int type, void *data)
1976 return (vesa_load());
1978 return (vesa_unload());
1980 return (EOPNOTSUPP);
1983 static moduledata_t vesa_mod = {
1989 DECLARE_MODULE(vesa, vesa_mod, SI_SUB_DRIVERS, SI_ORDER_MIDDLE);
1990 MODULE_DEPEND(vesa, x86bios, 1, 1, 1);
1992 #endif /* VGA_NO_MODE_CHANGE */