1f45c063aSXin LI /*- 2f45c063aSXin LI * Copyright (c) 1998 Kazutaka YOKOTA and Michael Smith 3f45c063aSXin LI * All rights reserved. 4f45c063aSXin LI * 5f45c063aSXin LI * Redistribution and use in source and binary forms, with or without 6f45c063aSXin LI * modification, are permitted provided that the following conditions 7f45c063aSXin LI * are met: 8f45c063aSXin LI * 1. Redistributions of source code must retain the above copyright 9f45c063aSXin LI * notice, this list of conditions and the following disclaimer as 10f45c063aSXin LI * the first lines of this file unmodified. 11f45c063aSXin LI * 2. Redistributions in binary form must reproduce the above copyright 12f45c063aSXin LI * notice, this list of conditions and the following disclaimer in the 13f45c063aSXin LI * documentation and/or other materials provided with the distribution. 14f45c063aSXin LI * 15f45c063aSXin LI * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR 16f45c063aSXin LI * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 17f45c063aSXin LI * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 18f45c063aSXin LI * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT, 19f45c063aSXin LI * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 20f45c063aSXin LI * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 21f45c063aSXin LI * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 22f45c063aSXin LI * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23f45c063aSXin LI * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 24f45c063aSXin LI * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25f45c063aSXin LI */ 26f45c063aSXin LI 27f45c063aSXin LI #include <sys/cdefs.h> 28f45c063aSXin LI __FBSDID("$FreeBSD$"); 29f45c063aSXin LI 30f45c063aSXin LI #include "opt_vga.h" 31f45c063aSXin LI #include "opt_vesa.h" 32f45c063aSXin LI 33f45c063aSXin LI #ifndef VGA_NO_MODE_CHANGE 34f45c063aSXin LI 35f45c063aSXin LI #include <sys/param.h> 36f45c063aSXin LI #include <sys/systm.h> 37f45c063aSXin LI #include <sys/kernel.h> 38f45c063aSXin LI #include <sys/module.h> 39f45c063aSXin LI #include <sys/malloc.h> 40f45c063aSXin LI #include <sys/fbio.h> 41f45c063aSXin LI 42f45c063aSXin LI #include <vm/vm.h> 43f45c063aSXin LI #include <vm/vm_extern.h> 44f45c063aSXin LI #include <vm/vm_kern.h> 45f45c063aSXin LI #include <vm/vm_param.h> 46f45c063aSXin LI #include <vm/pmap.h> 47f45c063aSXin LI 48205d67b0SXin LI #include <machine/pc/bios.h> 49ee5e90daSXin LI #include <dev/fb/vesa.h> 50f45c063aSXin LI 51f45c063aSXin LI #include <dev/fb/fbreg.h> 52f45c063aSXin LI #include <dev/fb/vgareg.h> 53f45c063aSXin LI 54f45c063aSXin LI #include <isa/isareg.h> 55ee5e90daSXin LI 5619de5df5SJung-uk Kim #include <compat/x86bios/x86bios.h> 57f45c063aSXin LI 58f45c063aSXin LI #define VESA_VIA_CLE266 "VIA CLE266\r\n" 59f45c063aSXin LI 60f45c063aSXin LI #ifndef VESA_DEBUG 61f45c063aSXin LI #define VESA_DEBUG 0 62f45c063aSXin LI #endif 63f45c063aSXin LI 64f45c063aSXin LI /* VESA video adapter state buffer stub */ 65f45c063aSXin LI struct adp_state { 66f45c063aSXin LI int sig; 67f45c063aSXin LI #define V_STATE_SIG 0x61736576 68f45c063aSXin LI u_char regs[1]; 69f45c063aSXin LI }; 70f45c063aSXin LI typedef struct adp_state adp_state_t; 71f45c063aSXin LI 72f45c063aSXin LI /* VESA video adapter */ 73f45c063aSXin LI static video_adapter_t *vesa_adp = NULL; 74f45c063aSXin LI static int vesa_state_buf_size = 0; 75205d67b0SXin LI #define VESA_BIOS_BUFSIZE (3 * PAGE_SIZE) 76f45c063aSXin LI 77f45c063aSXin LI /* VESA functions */ 78f45c063aSXin LI #if 0 79f45c063aSXin LI static int vesa_nop(void); 80f45c063aSXin LI #endif 81f45c063aSXin LI static int vesa_error(void); 82f45c063aSXin LI static vi_probe_t vesa_probe; 83f45c063aSXin LI static vi_init_t vesa_init; 84f45c063aSXin LI static vi_get_info_t vesa_get_info; 85f45c063aSXin LI static vi_query_mode_t vesa_query_mode; 86f45c063aSXin LI static vi_set_mode_t vesa_set_mode; 87f45c063aSXin LI static vi_save_font_t vesa_save_font; 88f45c063aSXin LI static vi_load_font_t vesa_load_font; 89f45c063aSXin LI static vi_show_font_t vesa_show_font; 90f45c063aSXin LI static vi_save_palette_t vesa_save_palette; 91f45c063aSXin LI static vi_load_palette_t vesa_load_palette; 92f45c063aSXin LI static vi_set_border_t vesa_set_border; 93f45c063aSXin LI static vi_save_state_t vesa_save_state; 94f45c063aSXin LI static vi_load_state_t vesa_load_state; 95f45c063aSXin LI static vi_set_win_org_t vesa_set_origin; 96f45c063aSXin LI static vi_read_hw_cursor_t vesa_read_hw_cursor; 97f45c063aSXin LI static vi_set_hw_cursor_t vesa_set_hw_cursor; 98f45c063aSXin LI static vi_set_hw_cursor_shape_t vesa_set_hw_cursor_shape; 99f45c063aSXin LI static vi_blank_display_t vesa_blank_display; 100f45c063aSXin LI static vi_mmap_t vesa_mmap; 101f45c063aSXin LI static vi_ioctl_t vesa_ioctl; 102f45c063aSXin LI static vi_clear_t vesa_clear; 103f45c063aSXin LI static vi_fill_rect_t vesa_fill_rect; 104f45c063aSXin LI static vi_bitblt_t vesa_bitblt; 105f45c063aSXin LI static vi_diag_t vesa_diag; 106f45c063aSXin LI static int vesa_bios_info(int level); 107ee5e90daSXin LI 108f45c063aSXin LI static video_switch_t vesavidsw = { 109f45c063aSXin LI vesa_probe, 110f45c063aSXin LI vesa_init, 111f45c063aSXin LI vesa_get_info, 112f45c063aSXin LI vesa_query_mode, 113f45c063aSXin LI vesa_set_mode, 114f45c063aSXin LI vesa_save_font, 115f45c063aSXin LI vesa_load_font, 116f45c063aSXin LI vesa_show_font, 117f45c063aSXin LI vesa_save_palette, 118f45c063aSXin LI vesa_load_palette, 119f45c063aSXin LI vesa_set_border, 120f45c063aSXin LI vesa_save_state, 121f45c063aSXin LI vesa_load_state, 122f45c063aSXin LI vesa_set_origin, 123f45c063aSXin LI vesa_read_hw_cursor, 124f45c063aSXin LI vesa_set_hw_cursor, 125f45c063aSXin LI vesa_set_hw_cursor_shape, 126f45c063aSXin LI vesa_blank_display, 127f45c063aSXin LI vesa_mmap, 128f45c063aSXin LI vesa_ioctl, 129f45c063aSXin LI vesa_clear, 130f45c063aSXin LI vesa_fill_rect, 131f45c063aSXin LI vesa_bitblt, 132f45c063aSXin LI vesa_error, 133f45c063aSXin LI vesa_error, 134f45c063aSXin LI vesa_diag, 135f45c063aSXin LI }; 136f45c063aSXin LI 137f45c063aSXin LI static video_switch_t *prevvidsw; 138f45c063aSXin LI 139f45c063aSXin LI /* VESA BIOS video modes */ 140f45c063aSXin LI #define VESA_MAXMODES 64 141f45c063aSXin LI #define EOT (-1) 142f45c063aSXin LI #define NA (-2) 143f45c063aSXin LI 144f45c063aSXin LI #define MODE_TABLE_DELTA 8 145f45c063aSXin LI 146f45c063aSXin LI static int vesa_vmode_max = 0; 147f45c063aSXin LI static video_info_t vesa_vmode_empty = { EOT }; 148f45c063aSXin LI static video_info_t *vesa_vmode = &vesa_vmode_empty; 149f45c063aSXin LI 150f45c063aSXin LI static int vesa_init_done = FALSE; 151f45c063aSXin LI static int has_vesa_bios = FALSE; 152f45c063aSXin LI static struct vesa_info *vesa_adp_info = NULL; 153f45c063aSXin LI static u_int16_t *vesa_vmodetab = NULL; 154f45c063aSXin LI static char *vesa_oemstr = NULL; 155f45c063aSXin LI static char *vesa_venderstr = NULL; 156f45c063aSXin LI static char *vesa_prodstr = NULL; 157f45c063aSXin LI static char *vesa_revstr = NULL; 158f45c063aSXin LI 159f45c063aSXin LI /* local macros and functions */ 160f45c063aSXin LI #define BIOS_SADDRTOLADDR(p) ((((p) & 0xffff0000) >> 12) + ((p) & 0x0000ffff)) 161f45c063aSXin LI 162f45c063aSXin LI static int int10_set_mode(int mode); 163f45c063aSXin LI static int vesa_bios_get_mode(int mode, struct vesa_mode *vmode); 164f45c063aSXin LI static int vesa_bios_set_mode(int mode); 165f45c063aSXin LI static int vesa_bios_get_dac(void); 166f45c063aSXin LI static int vesa_bios_set_dac(int bits); 167f45c063aSXin LI static int vesa_bios_save_palette(int start, int colors, u_char *palette, 168f45c063aSXin LI int bits); 169f45c063aSXin LI static int vesa_bios_save_palette2(int start, int colors, u_char *r, u_char *g, 170f45c063aSXin LI u_char *b, int bits); 171f45c063aSXin LI static int vesa_bios_load_palette(int start, int colors, u_char *palette, 172f45c063aSXin LI int bits); 173f45c063aSXin LI #ifdef notyet 174f45c063aSXin LI static int vesa_bios_load_palette2(int start, int colors, u_char *r, u_char *g, 175f45c063aSXin LI u_char *b, int bits); 176f45c063aSXin LI #endif 177f45c063aSXin LI #define STATE_SIZE 0 178f45c063aSXin LI #define STATE_SAVE 1 179f45c063aSXin LI #define STATE_LOAD 2 180f45c063aSXin LI #define STATE_HW (1<<0) 181f45c063aSXin LI #define STATE_DATA (1<<1) 182f45c063aSXin LI #define STATE_DAC (1<<2) 183f45c063aSXin LI #define STATE_REG (1<<3) 184f45c063aSXin LI #define STATE_MOST (STATE_HW | STATE_DATA | STATE_REG) 185f45c063aSXin LI #define STATE_ALL (STATE_HW | STATE_DATA | STATE_DAC | STATE_REG) 186f45c063aSXin LI static int vesa_bios_state_buf_size(void); 187f45c063aSXin LI static int vesa_bios_save_restore(int code, void *p, size_t size); 188f45c063aSXin LI static int vesa_bios_get_line_length(void); 189f45c063aSXin LI static int vesa_bios_set_line_length(int pixel, int *bytes, int *lines); 190f45c063aSXin LI #if 0 191f45c063aSXin LI static int vesa_bios_get_start(int *x, int *y); 192f45c063aSXin LI #endif 193f45c063aSXin LI static int vesa_bios_set_start(int x, int y); 194f45c063aSXin LI static int vesa_map_gen_mode_num(int type, int color, int mode); 195f45c063aSXin LI static int vesa_translate_flags(u_int16_t vflags); 196f45c063aSXin LI static int vesa_translate_mmodel(u_int8_t vmodel); 19754680451SJung-uk Kim static int vesa_get_line_width(video_info_t *info); 198f45c063aSXin LI static int vesa_bios_init(void); 199f45c063aSXin LI static void vesa_clear_modes(video_info_t *info, int color); 200f45c063aSXin LI static vm_offset_t vesa_map_buffer(u_int paddr, size_t size); 201f45c063aSXin LI static void vesa_unmap_buffer(vm_offset_t vaddr, size_t size); 202f45c063aSXin LI 203f45c063aSXin LI #if 0 204f45c063aSXin LI static int vesa_get_origin(video_adapter_t *adp, off_t *offset); 205f45c063aSXin LI #endif 206f45c063aSXin LI 207f45c063aSXin LI static void 208f45c063aSXin LI dump_buffer(u_char *buf, size_t len) 209f45c063aSXin LI { 210f45c063aSXin LI int i; 211f45c063aSXin LI 212f45c063aSXin LI for(i = 0; i < len;) { 213f45c063aSXin LI printf("%02x ", buf[i]); 214f45c063aSXin LI if ((++i % 16) == 0) 215f45c063aSXin LI printf("\n"); 216f45c063aSXin LI } 217f45c063aSXin LI } 218f45c063aSXin LI 219f45c063aSXin LI /* INT 10 BIOS calls */ 220f45c063aSXin LI static int 221f45c063aSXin LI int10_set_mode(int mode) 222f45c063aSXin LI { 223205d67b0SXin LI x86regs_t regs; 224205d67b0SXin LI 225f27b147eSXin LI bzero(®s, sizeof(regs)); 226205d67b0SXin LI regs.R_EAX = 0x0000 | mode; 227205d67b0SXin LI 228a8672748SJung-uk Kim x86bios_intr(®s, 0x10); 229f45c063aSXin LI 230f45c063aSXin LI return 0; 231f45c063aSXin LI } 232f45c063aSXin LI 233f45c063aSXin LI /* VESA BIOS calls */ 234f45c063aSXin LI static int 235f45c063aSXin LI vesa_bios_get_mode(int mode, struct vesa_mode *vmode) 236f45c063aSXin LI { 237205d67b0SXin LI x86regs_t regs; 238205d67b0SXin LI int offs; 239f45c063aSXin LI u_char *buf; 240f45c063aSXin LI 241f27b147eSXin LI bzero(®s, sizeof(regs)); 242205d67b0SXin LI regs.R_EAX = 0x4f01; 243205d67b0SXin LI regs.R_ECX = mode; 244f45c063aSXin LI 245a8672748SJung-uk Kim buf = (u_char *)x86bios_alloc(1, &offs); 246ee5e90daSXin LI 247205d67b0SXin LI regs.R_ES = SEG_ADDR(offs); 248205d67b0SXin LI regs.R_DI = SEG_OFF(offs); 249ee5e90daSXin LI 250a8672748SJung-uk Kim x86bios_intr(®s, 0x10); 251205d67b0SXin LI 252205d67b0SXin LI if ((regs.R_AX & 0xff) != 0x4f) 253205d67b0SXin LI { 254a8672748SJung-uk Kim x86bios_free(buf, 1); 255f45c063aSXin LI return 1; 256205d67b0SXin LI } 257ee5e90daSXin LI 258f45c063aSXin LI bcopy(buf, vmode, sizeof(*vmode)); 259a8672748SJung-uk Kim x86bios_free(buf, 1); 260ee5e90daSXin LI 261f45c063aSXin LI return 0; 262f45c063aSXin LI } 263f45c063aSXin LI 264f45c063aSXin LI static int 265f45c063aSXin LI vesa_bios_set_mode(int mode) 266f45c063aSXin LI { 267205d67b0SXin LI x86regs_t regs; 268f45c063aSXin LI 269f27b147eSXin LI bzero(®s, sizeof(regs)); 270205d67b0SXin LI regs.R_EAX = 0x4f02; 271205d67b0SXin LI regs.R_EBX = mode; 272ee5e90daSXin LI 273a8672748SJung-uk Kim x86bios_intr(®s, 0x10); 274205d67b0SXin LI 275205d67b0SXin LI return ((regs.R_AX & 0xff) != 0x4f); 276f45c063aSXin LI } 277f45c063aSXin LI 278f45c063aSXin LI static int 279f45c063aSXin LI vesa_bios_get_dac(void) 280f45c063aSXin LI { 281205d67b0SXin LI x86regs_t regs; 282f45c063aSXin LI 283f27b147eSXin LI bzero(®s, sizeof(regs)); 284205d67b0SXin LI regs.R_EAX = 0x4f08; 285205d67b0SXin LI regs.R_EBX = 1; 286ee5e90daSXin LI 287a8672748SJung-uk Kim x86bios_intr(®s, 0x10); 288205d67b0SXin LI 289205d67b0SXin LI if ((regs.R_AX & 0xff) != 0x4f) 290ee5e90daSXin LI return 6; 291ee5e90daSXin LI 292205d67b0SXin LI return ((regs.R_EBX >> 8) & 0x00ff); 293f45c063aSXin LI } 294f45c063aSXin LI 295f45c063aSXin LI static int 296f45c063aSXin LI vesa_bios_set_dac(int bits) 297f45c063aSXin LI { 298205d67b0SXin LI x86regs_t regs; 299f45c063aSXin LI 300f27b147eSXin LI bzero(®s, sizeof(regs)); 301205d67b0SXin LI regs.R_EAX = 0x4f08; 302205d67b0SXin LI regs.R_EBX = (bits << 8); 303ee5e90daSXin LI 304a8672748SJung-uk Kim x86bios_intr(®s, 0x10); 305205d67b0SXin LI 306205d67b0SXin LI if ((regs.R_AX & 0xff) != 0x4f) 307ee5e90daSXin LI return 6; 308ee5e90daSXin LI 309205d67b0SXin LI return ((regs.R_EBX >> 8) & 0x00ff); 310f45c063aSXin LI } 311f45c063aSXin LI 312f45c063aSXin LI static int 313f45c063aSXin LI vesa_bios_save_palette(int start, int colors, u_char *palette, int bits) 314f45c063aSXin LI { 315205d67b0SXin LI x86regs_t regs; 316205d67b0SXin LI int offs; 317f45c063aSXin LI u_char *p; 318f45c063aSXin LI int i; 319f45c063aSXin LI 320f27b147eSXin LI bzero(®s, sizeof(regs)); 321205d67b0SXin LI regs.R_EAX = 0x4f09; 322205d67b0SXin LI regs.R_EBX = 1; 323205d67b0SXin LI regs.R_ECX = colors; 324205d67b0SXin LI regs.R_EDX = start; 325f45c063aSXin LI 326a8672748SJung-uk Kim p = (u_char *)x86bios_alloc(1, &offs); 327ee5e90daSXin LI 328205d67b0SXin LI regs.R_ES = SEG_ADDR(offs); 329205d67b0SXin LI regs.R_DI = SEG_OFF(offs); 330ee5e90daSXin LI 331a8672748SJung-uk Kim x86bios_intr(®s, 0x10); 332ee5e90daSXin LI 333205d67b0SXin LI if ((regs.R_AX & 0xff) != 0x4f) 334205d67b0SXin LI { 335a8672748SJung-uk Kim x86bios_free(p, 1); 336f45c063aSXin LI return 1; 337205d67b0SXin LI } 338f45c063aSXin LI 339f45c063aSXin LI bits = 8 - bits; 340f45c063aSXin LI for (i = 0; i < colors; ++i) { 341f45c063aSXin LI palette[i*3] = p[i*4 + 2] << bits; 342f45c063aSXin LI palette[i*3 + 1] = p[i*4 + 1] << bits; 343f45c063aSXin LI palette[i*3 + 2] = p[i*4] << bits; 344f45c063aSXin LI } 345205d67b0SXin LI 346a8672748SJung-uk Kim x86bios_free(p, 1); 347f45c063aSXin LI return 0; 348f45c063aSXin LI } 349f45c063aSXin LI 350f45c063aSXin LI static int 351f45c063aSXin LI vesa_bios_save_palette2(int start, int colors, u_char *r, u_char *g, u_char *b, 352f45c063aSXin LI int bits) 353f45c063aSXin LI { 354205d67b0SXin LI x86regs_t regs; 355205d67b0SXin LI int offs; 356f45c063aSXin LI u_char *p; 357f45c063aSXin LI int i; 358f45c063aSXin LI 359f27b147eSXin LI bzero(®s, sizeof(regs)); 360205d67b0SXin LI regs.R_EAX = 0x4f09; 361205d67b0SXin LI regs.R_EBX = 1; 362205d67b0SXin LI regs.R_ECX = colors; 363205d67b0SXin LI regs.R_EDX = start; 364f45c063aSXin LI 365a8672748SJung-uk Kim p = (u_char *)x86bios_alloc(1, &offs); 366ee5e90daSXin LI 367205d67b0SXin LI regs.R_ES = SEG_ADDR(offs); 368205d67b0SXin LI regs.R_DI = SEG_OFF(offs); 369ee5e90daSXin LI 370a8672748SJung-uk Kim x86bios_intr(®s, 0x10); 371ee5e90daSXin LI 372205d67b0SXin LI if ((regs.R_AX & 0xff) != 0x4f) 373205d67b0SXin LI { 374a8672748SJung-uk Kim x86bios_free(p, 1); 375f45c063aSXin LI return 1; 376205d67b0SXin LI } 377f45c063aSXin LI 378f45c063aSXin LI bits = 8 - bits; 379f45c063aSXin LI for (i = 0; i < colors; ++i) { 380f45c063aSXin LI r[i] = p[i*4 + 2] << bits; 381f45c063aSXin LI g[i] = p[i*4 + 1] << bits; 382f45c063aSXin LI b[i] = p[i*4] << bits; 383f45c063aSXin LI } 384205d67b0SXin LI 385a8672748SJung-uk Kim x86bios_free(p, 1); 386f45c063aSXin LI return 0; 387f45c063aSXin LI } 388f45c063aSXin LI 389f45c063aSXin LI static int 390f45c063aSXin LI vesa_bios_load_palette(int start, int colors, u_char *palette, int bits) 391f45c063aSXin LI { 392205d67b0SXin LI x86regs_t regs; 393205d67b0SXin LI int offs; 394f45c063aSXin LI u_char *p; 395f45c063aSXin LI int i; 396f45c063aSXin LI 397a8672748SJung-uk Kim p = (u_char *)x86bios_alloc(1, &offs); 398ee5e90daSXin LI 399f45c063aSXin LI bits = 8 - bits; 400f45c063aSXin LI for (i = 0; i < colors; ++i) { 401f45c063aSXin LI p[i*4] = palette[i*3 + 2] >> bits; 402f45c063aSXin LI p[i*4 + 1] = palette[i*3 + 1] >> bits; 403f45c063aSXin LI p[i*4 + 2] = palette[i*3] >> bits; 404f45c063aSXin LI p[i*4 + 3] = 0; 405f45c063aSXin LI } 406f45c063aSXin LI 407f27b147eSXin LI bzero(®s, sizeof(regs)); 408205d67b0SXin LI regs.R_EAX = 0x4f09; 409205d67b0SXin LI regs.R_EBX = 0; 410205d67b0SXin LI regs.R_ECX = colors; 411205d67b0SXin LI regs.R_EDX = start; 412f45c063aSXin LI 413205d67b0SXin LI regs.R_ES = SEG_ADDR(offs); 414205d67b0SXin LI regs.R_DI = SEG_OFF(offs); 415ee5e90daSXin LI 416a8672748SJung-uk Kim x86bios_intr(®s, 0x10); 417ee5e90daSXin LI 418a8672748SJung-uk Kim x86bios_free(p, 1); 419205d67b0SXin LI 420205d67b0SXin LI return ((regs.R_AX & 0xff) != 0x4f); 421f45c063aSXin LI } 422f45c063aSXin LI 423f45c063aSXin LI #ifdef notyet 424f45c063aSXin LI static int 425f45c063aSXin LI vesa_bios_load_palette2(int start, int colors, u_char *r, u_char *g, u_char *b, 426f45c063aSXin LI int bits) 427f45c063aSXin LI { 428205d67b0SXin LI x86regs_t regs; 429205d67b0SXin LI int offs; 430f45c063aSXin LI u_char *p; 431f45c063aSXin LI int i; 432f45c063aSXin LI 433a8672748SJung-uk Kim p = (u_char *)x86bios_alloc(1, &offs); 434ee5e90daSXin LI 435f45c063aSXin LI bits = 8 - bits; 436f45c063aSXin LI for (i = 0; i < colors; ++i) { 437f45c063aSXin LI p[i*4] = b[i] >> bits; 438f45c063aSXin LI p[i*4 + 1] = g[i] >> bits; 439f45c063aSXin LI p[i*4 + 2] = r[i] >> bits; 440f45c063aSXin LI p[i*4 + 3] = 0; 441f45c063aSXin LI } 442f45c063aSXin LI 443f27b147eSXin LI bzero(®s, sizeof(regs)); 444205d67b0SXin LI regs.R_EAX = 0x4f09; 445205d67b0SXin LI regs.R_EBX = 0; 446205d67b0SXin LI regs.R_ECX = colors; 447205d67b0SXin LI regs.R_EDX = start; 448f45c063aSXin LI 449205d67b0SXin LI regs.R_ES = SEG_ADDR(offs); 450205d67b0SXin LI regs.R_DI = SEG_OFF(offs); 451ee5e90daSXin LI 452a8672748SJung-uk Kim x86bios_intr(®s, 0x10); 453ee5e90daSXin LI 454a8672748SJung-uk Kim x86bios_free(p, 1); 455205d67b0SXin LI 456205d67b0SXin LI return ((regs.R_AX & 0xff) != 0x4f); 457f45c063aSXin LI } 458f45c063aSXin LI #endif 459f45c063aSXin LI 460f45c063aSXin LI static int 461f45c063aSXin LI vesa_bios_state_buf_size(void) 462f45c063aSXin LI { 463205d67b0SXin LI x86regs_t regs; 464f45c063aSXin LI 465f27b147eSXin LI bzero(®s, sizeof(regs)); 466205d67b0SXin LI regs.R_EAX = 0x4f04; 467205d67b0SXin LI regs.R_ECX = STATE_ALL; 468205d67b0SXin LI regs.R_EDX = STATE_SIZE; 469ee5e90daSXin LI 470a8672748SJung-uk Kim x86bios_intr(®s, 0x10); 471205d67b0SXin LI 472205d67b0SXin LI if ((regs.R_AX & 0xff) != 0x4f) 473f45c063aSXin LI return 0; 474ee5e90daSXin LI 475205d67b0SXin LI return regs.R_BX * 64; 476f45c063aSXin LI } 477f45c063aSXin LI 478f45c063aSXin LI static int 479f45c063aSXin LI vesa_bios_save_restore(int code, void *p, size_t size) 480f45c063aSXin LI { 481205d67b0SXin LI x86regs_t regs; 482205d67b0SXin LI int offs; 483f45c063aSXin LI u_char *buf; 484f45c063aSXin LI 485205d67b0SXin LI if (size > VESA_BIOS_BUFSIZE) 486f45c063aSXin LI return (1); 487f45c063aSXin LI 488f27b147eSXin LI bzero(®s, sizeof(regs)); 489205d67b0SXin LI regs.R_EAX = 0x4f04; 490205d67b0SXin LI regs.R_ECX = STATE_ALL; 491205d67b0SXin LI regs.R_EDX = code; 492ee5e90daSXin LI 493a8672748SJung-uk Kim buf = (u_char *)x86bios_alloc(1, &offs); 494ee5e90daSXin LI 495205d67b0SXin LI regs.R_ES = SEG_ADDR(offs); 496205d67b0SXin LI regs.R_DI = SEG_OFF(offs); 497ee5e90daSXin LI 498f45c063aSXin LI bcopy(p, buf, size); 499f45c063aSXin LI 500a8672748SJung-uk Kim x86bios_intr(®s, 0x10); 501ee5e90daSXin LI 502f45c063aSXin LI bcopy(buf, p, size); 503ee5e90daSXin LI 504a8672748SJung-uk Kim x86bios_free(p, 1); 505205d67b0SXin LI 506205d67b0SXin LI return ((regs.R_AX & 0xff) != 0x4f); 507f45c063aSXin LI } 508f45c063aSXin LI 509f45c063aSXin LI static int 510f45c063aSXin LI vesa_bios_get_line_length(void) 511f45c063aSXin LI { 512205d67b0SXin LI x86regs_t regs; 513f45c063aSXin LI 514f27b147eSXin LI bzero(®s, sizeof(regs)); 515205d67b0SXin LI regs.R_EAX = 0x4f06; 516205d67b0SXin LI regs.R_EBX = 1; 517ee5e90daSXin LI 518a8672748SJung-uk Kim x86bios_intr(®s, 0x10); 519205d67b0SXin LI 520205d67b0SXin LI if ((regs.R_AX & 0xff) != 0x4f) 521f45c063aSXin LI return -1; 522205d67b0SXin LI 523205d67b0SXin LI return regs.R_BX; 524f45c063aSXin LI } 525f45c063aSXin LI 526f45c063aSXin LI static int 527f45c063aSXin LI vesa_bios_set_line_length(int pixel, int *bytes, int *lines) 528f45c063aSXin LI { 529205d67b0SXin LI x86regs_t regs; 530f45c063aSXin LI 531f27b147eSXin LI bzero(®s, sizeof(regs)); 532205d67b0SXin LI regs.R_EAX = 0x4f06; 533205d67b0SXin LI regs.R_EBX = 0; 534205d67b0SXin LI regs.R_ECX = pixel; 535205d67b0SXin LI 536a8672748SJung-uk Kim x86bios_intr(®s, 0x10); 537ee5e90daSXin LI 538f45c063aSXin LI #if VESA_DEBUG > 1 539205d67b0SXin LI printf("bx:%d, cx:%d, dx:%d\n", regs.R_BX, regs.R_CX, regs.R_DX); 540f45c063aSXin LI #endif 541205d67b0SXin LI if ((regs.R_AX & 0xff) != 0x4f) 542ee5e90daSXin LI return -1; 543ee5e90daSXin LI 544f45c063aSXin LI if (bytes) 545205d67b0SXin LI *bytes = regs.R_BX; 546f45c063aSXin LI if (lines) 547205d67b0SXin LI *lines = regs.R_DX; 548ee5e90daSXin LI 549f45c063aSXin LI return 0; 550f45c063aSXin LI } 551f45c063aSXin LI 552f45c063aSXin LI #if 0 553f45c063aSXin LI static int 554f45c063aSXin LI vesa_bios_get_start(int *x, int *y) 555f45c063aSXin LI { 556205d67b0SXin LI x86regs_t regs; 557f45c063aSXin LI 558f27b147eSXin LI bzero(®s, sizeof(regs)); 559205d67b0SXin LI regs.R_EAX = 0x4f07; 560205d67b0SXin LI regs.R_EBX = 1; 561ee5e90daSXin LI 562a8672748SJung-uk Kim x86bios_intr(®s, 0x10); 563205d67b0SXin LI 564205d67b0SXin LI if ((regs.R_AX & 0xff) != 0x4f) 565ee5e90daSXin LI return -1; 566ee5e90daSXin LI 567205d67b0SXin LI *x = regs.R_CX; 568205d67b0SXin LI *y = regs.R_DX; 569ee5e90daSXin LI 570f45c063aSXin LI return 0; 571f45c063aSXin LI } 572f45c063aSXin LI #endif 573f45c063aSXin LI 574f45c063aSXin LI static int 575f45c063aSXin LI vesa_bios_set_start(int x, int y) 576f45c063aSXin LI { 577205d67b0SXin LI x86regs_t regs; 578f45c063aSXin LI 579f27b147eSXin LI bzero(®s, sizeof(regs)); 580205d67b0SXin LI regs.R_EAX = 0x4f07; 581205d67b0SXin LI regs.R_EBX = 0x80; 582205d67b0SXin LI regs.R_EDX = y; 583205d67b0SXin LI regs.R_ECX = x; 584ee5e90daSXin LI 585a8672748SJung-uk Kim x86bios_intr(®s, 0x10); 586205d67b0SXin LI 587205d67b0SXin LI return ((regs.R_AX & 0xff) != 0x4f); 588f45c063aSXin LI } 589f45c063aSXin LI 590f45c063aSXin LI /* map a generic video mode to a known mode */ 591f45c063aSXin LI static int 592f45c063aSXin LI vesa_map_gen_mode_num(int type, int color, int mode) 593f45c063aSXin LI { 594f45c063aSXin LI static struct { 595f45c063aSXin LI int from; 596f45c063aSXin LI int to; 597f45c063aSXin LI } mode_map[] = { 598f45c063aSXin LI { M_TEXT_132x25, M_VESA_C132x25 }, 599f45c063aSXin LI { M_TEXT_132x43, M_VESA_C132x43 }, 600f45c063aSXin LI { M_TEXT_132x50, M_VESA_C132x50 }, 601f45c063aSXin LI { M_TEXT_132x60, M_VESA_C132x60 }, 602f45c063aSXin LI }; 603f45c063aSXin LI int i; 604f45c063aSXin LI 605f45c063aSXin LI for (i = 0; i < sizeof(mode_map)/sizeof(mode_map[0]); ++i) { 606f45c063aSXin LI if (mode_map[i].from == mode) 607f45c063aSXin LI return mode_map[i].to; 608f45c063aSXin LI } 609f45c063aSXin LI return mode; 610f45c063aSXin LI } 611f45c063aSXin LI 612f45c063aSXin LI static int 613f45c063aSXin LI vesa_translate_flags(u_int16_t vflags) 614f45c063aSXin LI { 615f45c063aSXin LI static struct { 616f45c063aSXin LI u_int16_t mask; 617f45c063aSXin LI int set; 618f45c063aSXin LI int reset; 619f45c063aSXin LI } ftable[] = { 620f45c063aSXin LI { V_MODECOLOR, V_INFO_COLOR, 0 }, 621f45c063aSXin LI { V_MODEGRAPHICS, V_INFO_GRAPHICS, 0 }, 622f45c063aSXin LI { V_MODELFB, V_INFO_LINEAR, 0 }, 623f45c063aSXin LI }; 624f45c063aSXin LI int flags; 625f45c063aSXin LI int i; 626f45c063aSXin LI 627f45c063aSXin LI for (flags = 0, i = 0; i < sizeof(ftable)/sizeof(ftable[0]); ++i) { 628f45c063aSXin LI flags |= (vflags & ftable[i].mask) ? 629f45c063aSXin LI ftable[i].set : ftable[i].reset; 630f45c063aSXin LI } 631f45c063aSXin LI return flags; 632f45c063aSXin LI } 633f45c063aSXin LI 634f45c063aSXin LI static int 635f45c063aSXin LI vesa_translate_mmodel(u_int8_t vmodel) 636f45c063aSXin LI { 637f45c063aSXin LI static struct { 638f45c063aSXin LI u_int8_t vmodel; 639f45c063aSXin LI int mmodel; 640f45c063aSXin LI } mtable[] = { 641f45c063aSXin LI { V_MMTEXT, V_INFO_MM_TEXT }, 642f45c063aSXin LI { V_MMCGA, V_INFO_MM_CGA }, 643f45c063aSXin LI { V_MMHGC, V_INFO_MM_HGC }, 644f45c063aSXin LI { V_MMEGA, V_INFO_MM_PLANAR }, 645f45c063aSXin LI { V_MMPACKED, V_INFO_MM_PACKED }, 646f45c063aSXin LI { V_MMDIRCOLOR, V_INFO_MM_DIRECT }, 647f45c063aSXin LI }; 648f45c063aSXin LI int i; 649f45c063aSXin LI 650f45c063aSXin LI for (i = 0; mtable[i].mmodel >= 0; ++i) { 651f45c063aSXin LI if (mtable[i].vmodel == vmodel) 652f45c063aSXin LI return mtable[i].mmodel; 653f45c063aSXin LI } 654f45c063aSXin LI return V_INFO_MM_OTHER; 655f45c063aSXin LI } 656f45c063aSXin LI 657f45c063aSXin LI static int 65854680451SJung-uk Kim vesa_get_line_width(video_info_t *info) 65954680451SJung-uk Kim { 66054680451SJung-uk Kim int len; 66154680451SJung-uk Kim int width; 66254680451SJung-uk Kim 66354680451SJung-uk Kim width = info->vi_width; 66454680451SJung-uk Kim 66554680451SJung-uk Kim if (info->vi_flags & V_INFO_GRAPHICS) 66654680451SJung-uk Kim switch (info->vi_depth / info->vi_planes) { 66754680451SJung-uk Kim case 1: 66854680451SJung-uk Kim return (width / 8); 66954680451SJung-uk Kim case 2: 67054680451SJung-uk Kim return (width / 4); 67154680451SJung-uk Kim case 4: 67254680451SJung-uk Kim return (width / 2); 67354680451SJung-uk Kim case 8: 67454680451SJung-uk Kim return (width); 67554680451SJung-uk Kim case 15: 67654680451SJung-uk Kim case 16: 67754680451SJung-uk Kim return (width * 2); 67854680451SJung-uk Kim case 24: 67954680451SJung-uk Kim case 32: 68054680451SJung-uk Kim return (width * 4); 68154680451SJung-uk Kim } 68254680451SJung-uk Kim 68354680451SJung-uk Kim len = vesa_bios_get_line_length(); 68454680451SJung-uk Kim 68554680451SJung-uk Kim return (len > 0 ? len : width); 68654680451SJung-uk Kim } 68754680451SJung-uk Kim 68854680451SJung-uk Kim static int 689f45c063aSXin LI vesa_bios_init(void) 690f45c063aSXin LI { 691ee5e90daSXin LI static struct vesa_info buf; 692f45c063aSXin LI struct vesa_mode vmode; 693f45c063aSXin LI video_info_t *p; 694205d67b0SXin LI x86regs_t regs; 69554680451SJung-uk Kim size_t bsize; 696205d67b0SXin LI int offs; 697f45c063aSXin LI u_char *vmbuf; 698f45c063aSXin LI int is_via_cle266; 699f45c063aSXin LI int modes; 700f45c063aSXin LI int i; 701f45c063aSXin LI 702f45c063aSXin LI if (vesa_init_done) 703f45c063aSXin LI return 0; 704f45c063aSXin LI 705f45c063aSXin LI has_vesa_bios = FALSE; 706f45c063aSXin LI vesa_adp_info = NULL; 707f45c063aSXin LI vesa_vmode_max = 0; 708f45c063aSXin LI vesa_vmode[0].vi_mode = EOT; 709f45c063aSXin LI 710a8672748SJung-uk Kim vmbuf = (u_char *)x86bios_alloc(1, &offs); 711f45c063aSXin LI bcopy("VBE2", vmbuf, 4); /* try for VBE2 data */ 712f45c063aSXin LI 713f27b147eSXin LI bzero(®s, sizeof(regs)); 714205d67b0SXin LI regs.R_EAX = 0x4f00; 715205d67b0SXin LI regs.R_ES = SEG_ADDR(offs); 716205d67b0SXin LI regs.R_DI = SEG_OFF(offs); 717ee5e90daSXin LI 718a8672748SJung-uk Kim x86bios_intr(®s, 0x10); 719ee5e90daSXin LI 720205d67b0SXin LI if (((regs.R_AX & 0xff) != 0x4f) || bcmp("VESA", vmbuf, 4)) 721f45c063aSXin LI return 1; 722ee5e90daSXin LI 723ee5e90daSXin LI bcopy(vmbuf, &buf, sizeof(buf)); 724ee5e90daSXin LI 725ee5e90daSXin LI vesa_adp_info = &buf; 726f45c063aSXin LI if (bootverbose) { 727f45c063aSXin LI printf("VESA: information block\n"); 728ee5e90daSXin LI dump_buffer((u_char *)&buf, sizeof(buf)); 729f45c063aSXin LI } 730f45c063aSXin LI if (vesa_adp_info->v_version < 0x0102) { 731f45c063aSXin LI printf("VESA: VBE version %d.%d is not supported; " 732f45c063aSXin LI "version 1.2 or later is required.\n", 733f45c063aSXin LI ((vesa_adp_info->v_version & 0xf000) >> 12) * 10 734f45c063aSXin LI + ((vesa_adp_info->v_version & 0x0f00) >> 8), 735f45c063aSXin LI ((vesa_adp_info->v_version & 0x00f0) >> 4) * 10 736f45c063aSXin LI + (vesa_adp_info->v_version & 0x000f)); 737f45c063aSXin LI return 1; 738f45c063aSXin LI } 739f45c063aSXin LI 740a8672748SJung-uk Kim vesa_oemstr = (char *)x86bios_offset(FARP(vesa_adp_info->v_oemstr)); 741ee5e90daSXin LI 742f45c063aSXin LI is_via_cle266 = strcmp(vesa_oemstr, VESA_VIA_CLE266) == 0; 743f45c063aSXin LI 744f45c063aSXin LI if (vesa_adp_info->v_version >= 0x0200) { 745a8672748SJung-uk Kim vesa_venderstr = (char *)x86bios_offset(FARP(vesa_adp_info->v_venderstr)); 746a8672748SJung-uk Kim vesa_prodstr = (char *)x86bios_offset(FARP(vesa_adp_info->v_prodstr)); 747a8672748SJung-uk Kim vesa_revstr = (char *)x86bios_offset(FARP(vesa_adp_info->v_revstr)); 748f45c063aSXin LI } 749f45c063aSXin LI 750a8672748SJung-uk Kim vesa_vmodetab = (uint16_t *)x86bios_offset(FARP(vesa_adp_info->v_modetable)); 751ee5e90daSXin LI 752f45c063aSXin LI if (vesa_vmodetab == NULL) 753f45c063aSXin LI return 1; 754ee5e90daSXin LI 755f45c063aSXin LI for (i = 0, modes = 0; 756f45c063aSXin LI (i < (M_VESA_MODE_MAX - M_VESA_BASE + 1)) 757f45c063aSXin LI && (vesa_vmodetab[i] != 0xffff); ++i) { 758f45c063aSXin LI if (vesa_bios_get_mode(vesa_vmodetab[i], &vmode)) 759f45c063aSXin LI continue; 760f45c063aSXin LI 761f45c063aSXin LI /* reject unsupported modes */ 762f45c063aSXin LI #if 0 763f45c063aSXin LI if ((vmode.v_modeattr & (V_MODESUPP | V_MODEOPTINFO 764f45c063aSXin LI | V_MODENONVGA)) 765f45c063aSXin LI != (V_MODESUPP | V_MODEOPTINFO)) 766f45c063aSXin LI continue; 767f45c063aSXin LI #else 768f45c063aSXin LI if ((vmode.v_modeattr & V_MODEOPTINFO) == 0) { 769f45c063aSXin LI #if VESA_DEBUG > 1 770f45c063aSXin LI printf( 771f45c063aSXin LI "Rejecting VESA %s mode: %d x %d x %d bpp attr = %x\n", 772f45c063aSXin LI vmode.v_modeattr & V_MODEGRAPHICS ? "graphics" : "text", 773f45c063aSXin LI vmode.v_width, vmode.v_height, vmode.v_bpp, 774f45c063aSXin LI vmode.v_modeattr); 775f45c063aSXin LI #endif 776f45c063aSXin LI continue; 777f45c063aSXin LI } 778f45c063aSXin LI #endif 779f45c063aSXin LI 780f45c063aSXin LI /* expand the array if necessary */ 781f45c063aSXin LI if (modes >= vesa_vmode_max) { 782f45c063aSXin LI vesa_vmode_max += MODE_TABLE_DELTA; 783f45c063aSXin LI p = malloc(sizeof(*vesa_vmode)*(vesa_vmode_max + 1), 784f45c063aSXin LI M_DEVBUF, M_WAITOK); 785f45c063aSXin LI #if VESA_DEBUG > 1 786f45c063aSXin LI printf("vesa_bios_init(): modes:%d, vesa_mode_max:%d\n", 787f45c063aSXin LI modes, vesa_vmode_max); 788f45c063aSXin LI #endif 789f45c063aSXin LI if (modes > 0) { 790f45c063aSXin LI bcopy(vesa_vmode, p, sizeof(*vesa_vmode)*modes); 791f45c063aSXin LI free(vesa_vmode, M_DEVBUF); 792f45c063aSXin LI } 793f45c063aSXin LI vesa_vmode = p; 794f45c063aSXin LI } 795f45c063aSXin LI 796f45c063aSXin LI #if VESA_DEBUG > 1 797f45c063aSXin LI printf("Found VESA %s mode: %d x %d x %d bpp\n", 798f45c063aSXin LI vmode.v_modeattr & V_MODEGRAPHICS ? "graphics" : "text", 799f45c063aSXin LI vmode.v_width, vmode.v_height, vmode.v_bpp); 800f45c063aSXin LI #endif 801f45c063aSXin LI if (is_via_cle266) { 802f45c063aSXin LI if ((vmode.v_width & 0xff00) >> 8 == vmode.v_height - 1) { 803f45c063aSXin LI vmode.v_width &= 0xff; 804f45c063aSXin LI vmode.v_waseg = 0xb8000 >> 4; 805f45c063aSXin LI } 806f45c063aSXin LI } 807f45c063aSXin LI 808f45c063aSXin LI /* copy some fields */ 809f45c063aSXin LI bzero(&vesa_vmode[modes], sizeof(vesa_vmode[modes])); 810f45c063aSXin LI vesa_vmode[modes].vi_mode = vesa_vmodetab[i]; 811f45c063aSXin LI vesa_vmode[modes].vi_width = vmode.v_width; 812f45c063aSXin LI vesa_vmode[modes].vi_height = vmode.v_height; 813f45c063aSXin LI vesa_vmode[modes].vi_depth = vmode.v_bpp; 814f45c063aSXin LI vesa_vmode[modes].vi_planes = vmode.v_planes; 815f45c063aSXin LI vesa_vmode[modes].vi_cwidth = vmode.v_cwidth; 816f45c063aSXin LI vesa_vmode[modes].vi_cheight = vmode.v_cheight; 817f45c063aSXin LI vesa_vmode[modes].vi_window = (u_int)vmode.v_waseg << 4; 818f45c063aSXin LI /* XXX window B */ 819f45c063aSXin LI vesa_vmode[modes].vi_window_size = vmode.v_wsize*1024; 820f45c063aSXin LI vesa_vmode[modes].vi_window_gran = vmode.v_wgran*1024; 821f45c063aSXin LI if (vmode.v_modeattr & V_MODELFB) 822f45c063aSXin LI vesa_vmode[modes].vi_buffer = vmode.v_lfb; 823f45c063aSXin LI else 824f45c063aSXin LI vesa_vmode[modes].vi_buffer = 0; 825f45c063aSXin LI /* XXX */ 826f45c063aSXin LI vesa_vmode[modes].vi_buffer_size 827f45c063aSXin LI = vesa_adp_info->v_memsize*64*1024; 828f45c063aSXin LI #if 0 829f45c063aSXin LI if (vmode.v_offscreen > vmode.v_lfb) 830f45c063aSXin LI vesa_vmode[modes].vi_buffer_size 831f45c063aSXin LI = vmode.v_offscreen + vmode.v_offscreensize*1024 832f45c063aSXin LI - vmode.v_lfb; 833f45c063aSXin LI else 834f45c063aSXin LI vesa_vmode[modes].vi_buffer_size 835205d67b0SXin LI = vmode.v_offscreen + vmode.v_offscreensize * 1024; 836f45c063aSXin LI #endif 837f45c063aSXin LI vesa_vmode[modes].vi_mem_model 838f45c063aSXin LI = vesa_translate_mmodel(vmode.v_memmodel); 839f45c063aSXin LI vesa_vmode[modes].vi_pixel_fields[0] = 0; 840f45c063aSXin LI vesa_vmode[modes].vi_pixel_fields[1] = 0; 841f45c063aSXin LI vesa_vmode[modes].vi_pixel_fields[2] = 0; 842f45c063aSXin LI vesa_vmode[modes].vi_pixel_fields[3] = 0; 843f45c063aSXin LI vesa_vmode[modes].vi_pixel_fsizes[0] = 0; 844f45c063aSXin LI vesa_vmode[modes].vi_pixel_fsizes[1] = 0; 845f45c063aSXin LI vesa_vmode[modes].vi_pixel_fsizes[2] = 0; 846f45c063aSXin LI vesa_vmode[modes].vi_pixel_fsizes[3] = 0; 847f45c063aSXin LI if (vesa_vmode[modes].vi_mem_model == V_INFO_MM_PACKED) { 848f45c063aSXin LI vesa_vmode[modes].vi_pixel_size = (vmode.v_bpp + 7)/8; 849f45c063aSXin LI } else if (vesa_vmode[modes].vi_mem_model == V_INFO_MM_DIRECT) { 850f45c063aSXin LI vesa_vmode[modes].vi_pixel_size = (vmode.v_bpp + 7)/8; 851f45c063aSXin LI vesa_vmode[modes].vi_pixel_fields[0] 852f45c063aSXin LI = vmode.v_redfieldpos; 853f45c063aSXin LI vesa_vmode[modes].vi_pixel_fields[1] 854f45c063aSXin LI = vmode.v_greenfieldpos; 855f45c063aSXin LI vesa_vmode[modes].vi_pixel_fields[2] 856f45c063aSXin LI = vmode.v_bluefieldpos; 857f45c063aSXin LI vesa_vmode[modes].vi_pixel_fields[3] 858f45c063aSXin LI = vmode.v_resfieldpos; 859f45c063aSXin LI vesa_vmode[modes].vi_pixel_fsizes[0] 860f45c063aSXin LI = vmode.v_redmasksize; 861f45c063aSXin LI vesa_vmode[modes].vi_pixel_fsizes[1] 862f45c063aSXin LI = vmode.v_greenmasksize; 863f45c063aSXin LI vesa_vmode[modes].vi_pixel_fsizes[2] 864f45c063aSXin LI = vmode.v_bluemasksize; 865f45c063aSXin LI vesa_vmode[modes].vi_pixel_fsizes[3] 866f45c063aSXin LI = vmode.v_resmasksize; 867f45c063aSXin LI } else { 868f45c063aSXin LI vesa_vmode[modes].vi_pixel_size = 0; 869f45c063aSXin LI } 870f45c063aSXin LI 871f45c063aSXin LI vesa_vmode[modes].vi_flags 872f45c063aSXin LI = vesa_translate_flags(vmode.v_modeattr) | V_INFO_VESA; 87354680451SJung-uk Kim 87454680451SJung-uk Kim /* Does it have enough memory to support this mode? */ 87554680451SJung-uk Kim bsize = vesa_get_line_width(&vesa_vmode[modes]); 87654680451SJung-uk Kim bsize *= vesa_vmode[modes].vi_height; 87754680451SJung-uk Kim if (bsize > vesa_vmode[modes].vi_buffer_size) { 87854680451SJung-uk Kim #if VESA_DEBUG > 1 87954680451SJung-uk Kim printf( 88054680451SJung-uk Kim "Rejecting VESA %s mode: %d x %d x %d bpp attr = %x, not enough memory\n", 88154680451SJung-uk Kim (vmode.v_modeattr & V_MODEGRAPHICS) != 0 ? "graphics" : "text", 88254680451SJung-uk Kim vmode.v_width, vmode.v_height, vmode.v_bpp, vmode.v_modeattr); 88354680451SJung-uk Kim #endif 88454680451SJung-uk Kim continue; 88554680451SJung-uk Kim } 88654680451SJung-uk Kim 887f45c063aSXin LI ++modes; 888f45c063aSXin LI } 889f45c063aSXin LI vesa_vmode[modes].vi_mode = EOT; 890205d67b0SXin LI 891a8672748SJung-uk Kim x86bios_free(vmbuf, 1); 892205d67b0SXin LI 893f45c063aSXin LI if (bootverbose) 894f45c063aSXin LI printf("VESA: %d mode(s) found\n", modes); 895f45c063aSXin LI 896f45c063aSXin LI has_vesa_bios = (modes > 0); 897f45c063aSXin LI if (!has_vesa_bios) 898f45c063aSXin LI return (1); 899f45c063aSXin LI 900f45c063aSXin LI return (0); 901f45c063aSXin LI } 902f45c063aSXin LI 903f45c063aSXin LI static void 904f45c063aSXin LI vesa_clear_modes(video_info_t *info, int color) 905f45c063aSXin LI { 906f45c063aSXin LI while (info->vi_mode != EOT) { 907f45c063aSXin LI if ((info->vi_flags & V_INFO_COLOR) != color) 908f45c063aSXin LI info->vi_mode = NA; 909f45c063aSXin LI ++info; 910f45c063aSXin LI } 911f45c063aSXin LI } 912f45c063aSXin LI 913f45c063aSXin LI static vm_offset_t 914f45c063aSXin LI vesa_map_buffer(u_int paddr, size_t size) 915f45c063aSXin LI { 916f45c063aSXin LI vm_offset_t vaddr; 917f45c063aSXin LI u_int off; 918f45c063aSXin LI 919f45c063aSXin LI off = paddr - trunc_page(paddr); 920afb9e5cfSJung-uk Kim vaddr = (vm_offset_t)pmap_mapdev_attr(paddr - off, size + off, 921afb9e5cfSJung-uk Kim PAT_WRITE_COMBINING); 922f45c063aSXin LI #if VESA_DEBUG > 1 923ee5e90daSXin LI printf("vesa_map_buffer: paddr:%x vaddr:%tx size:%zx off:%x\n", 924f45c063aSXin LI paddr, vaddr, size, off); 925f45c063aSXin LI #endif 926f45c063aSXin LI return (vaddr + off); 927f45c063aSXin LI } 928f45c063aSXin LI 929f45c063aSXin LI static void 930f45c063aSXin LI vesa_unmap_buffer(vm_offset_t vaddr, size_t size) 931f45c063aSXin LI { 932f45c063aSXin LI #if VESA_DEBUG > 1 933ee5e90daSXin LI printf("vesa_unmap_buffer: vaddr:%tx size:%zx\n", vaddr, size); 934f45c063aSXin LI #endif 935f45c063aSXin LI kmem_free(kernel_map, vaddr, size); 936f45c063aSXin LI } 937f45c063aSXin LI 938f45c063aSXin LI /* entry points */ 939f45c063aSXin LI 940f45c063aSXin LI static int 941f45c063aSXin LI vesa_configure(int flags) 942f45c063aSXin LI { 943f45c063aSXin LI video_adapter_t *adp; 944f45c063aSXin LI int adapters; 945f45c063aSXin LI int error; 946f45c063aSXin LI int i; 947f45c063aSXin LI 948f45c063aSXin LI if (vesa_init_done) 949f45c063aSXin LI return 0; 950f45c063aSXin LI if (flags & VIO_PROBE_ONLY) 951f45c063aSXin LI return 0; /* XXX */ 952f45c063aSXin LI 953f45c063aSXin LI /* 954f45c063aSXin LI * If the VESA module has already been loaded, abort loading 955f45c063aSXin LI * the module this time. 956f45c063aSXin LI */ 957f45c063aSXin LI for (i = 0; (adp = vid_get_adapter(i)) != NULL; ++i) { 958f45c063aSXin LI if (adp->va_flags & V_ADP_VESA) 959f45c063aSXin LI return ENXIO; 960f45c063aSXin LI if (adp->va_type == KD_VGA) 961f45c063aSXin LI break; 962f45c063aSXin LI } 963f45c063aSXin LI /* 964f45c063aSXin LI * The VGA adapter is not found. This is because either 965f45c063aSXin LI * 1) the VGA driver has not been initialized, or 2) the VGA card 966f45c063aSXin LI * is not present. If 1) is the case, we shall defer 967f45c063aSXin LI * initialization for now and try again later. 968f45c063aSXin LI */ 969f45c063aSXin LI if (adp == NULL) { 970f45c063aSXin LI vga_sub_configure = vesa_configure; 971f45c063aSXin LI return ENODEV; 972f45c063aSXin LI } 973f45c063aSXin LI 974f45c063aSXin LI /* count number of registered adapters */ 975f45c063aSXin LI for (++i; vid_get_adapter(i) != NULL; ++i) 976f45c063aSXin LI ; 977f45c063aSXin LI adapters = i; 978f45c063aSXin LI 979f45c063aSXin LI /* call VESA BIOS */ 980f45c063aSXin LI vesa_adp = adp; 981f45c063aSXin LI if (vesa_bios_init()) { 982f45c063aSXin LI vesa_adp = NULL; 983f45c063aSXin LI return ENXIO; 984f45c063aSXin LI } 985f45c063aSXin LI vesa_adp->va_flags |= V_ADP_VESA; 986f45c063aSXin LI 987f45c063aSXin LI /* remove conflicting modes if we have more than one adapter */ 988f45c063aSXin LI if (adapters > 1) { 989f45c063aSXin LI vesa_clear_modes(vesa_vmode, 990f45c063aSXin LI (vesa_adp->va_flags & V_ADP_COLOR) ? 991f45c063aSXin LI V_INFO_COLOR : 0); 992f45c063aSXin LI } 993f45c063aSXin LI 994f45c063aSXin LI if ((error = vesa_load_ioctl()) == 0) { 995f45c063aSXin LI prevvidsw = vidsw[vesa_adp->va_index]; 996f45c063aSXin LI vidsw[vesa_adp->va_index] = &vesavidsw; 997f45c063aSXin LI vesa_init_done = TRUE; 998f45c063aSXin LI } else { 999f45c063aSXin LI vesa_adp = NULL; 1000f45c063aSXin LI return error; 1001f45c063aSXin LI } 1002f45c063aSXin LI 1003f45c063aSXin LI return 0; 1004f45c063aSXin LI } 1005f45c063aSXin LI 1006f45c063aSXin LI #if 0 1007f45c063aSXin LI static int 1008f45c063aSXin LI vesa_nop(void) 1009f45c063aSXin LI { 1010f45c063aSXin LI return 0; 1011f45c063aSXin LI } 1012f45c063aSXin LI #endif 1013f45c063aSXin LI 1014f45c063aSXin LI static int 1015f45c063aSXin LI vesa_error(void) 1016f45c063aSXin LI { 1017f45c063aSXin LI return 1; 1018f45c063aSXin LI } 1019f45c063aSXin LI 1020f45c063aSXin LI static int 1021f45c063aSXin LI vesa_probe(int unit, video_adapter_t **adpp, void *arg, int flags) 1022f45c063aSXin LI { 1023f45c063aSXin LI return (*prevvidsw->probe)(unit, adpp, arg, flags); 1024f45c063aSXin LI } 1025f45c063aSXin LI 1026f45c063aSXin LI static int 1027f45c063aSXin LI vesa_init(int unit, video_adapter_t *adp, int flags) 1028f45c063aSXin LI { 1029f45c063aSXin LI return (*prevvidsw->init)(unit, adp, flags); 1030f45c063aSXin LI } 1031f45c063aSXin LI 1032f45c063aSXin LI static int 1033f45c063aSXin LI vesa_get_info(video_adapter_t *adp, int mode, video_info_t *info) 1034f45c063aSXin LI { 1035f45c063aSXin LI int i; 1036f45c063aSXin LI 1037f45c063aSXin LI if ((*prevvidsw->get_info)(adp, mode, info) == 0) 1038f45c063aSXin LI return 0; 1039f45c063aSXin LI 1040f45c063aSXin LI if (adp != vesa_adp) 1041f45c063aSXin LI return 1; 1042f45c063aSXin LI 1043f45c063aSXin LI mode = vesa_map_gen_mode_num(vesa_adp->va_type, 1044f45c063aSXin LI vesa_adp->va_flags & V_ADP_COLOR, mode); 1045f45c063aSXin LI for (i = 0; vesa_vmode[i].vi_mode != EOT; ++i) { 1046f45c063aSXin LI if (vesa_vmode[i].vi_mode == NA) 1047f45c063aSXin LI continue; 1048f45c063aSXin LI if (vesa_vmode[i].vi_mode == mode) { 1049f45c063aSXin LI *info = vesa_vmode[i]; 1050f45c063aSXin LI return 0; 1051f45c063aSXin LI } 1052f45c063aSXin LI } 1053f45c063aSXin LI return 1; 1054f45c063aSXin LI } 1055f45c063aSXin LI 1056f45c063aSXin LI static int 1057f45c063aSXin LI vesa_query_mode(video_adapter_t *adp, video_info_t *info) 1058f45c063aSXin LI { 1059f45c063aSXin LI int i; 1060f45c063aSXin LI 1061f45c063aSXin LI if ((*prevvidsw->query_mode)(adp, info) == 0) 1062f45c063aSXin LI return 0; 1063f45c063aSXin LI if (adp != vesa_adp) 1064f45c063aSXin LI return ENODEV; 1065f45c063aSXin LI 1066f45c063aSXin LI for (i = 0; vesa_vmode[i].vi_mode != EOT; ++i) { 1067f45c063aSXin LI if ((info->vi_width != 0) 1068f45c063aSXin LI && (info->vi_width != vesa_vmode[i].vi_width)) 1069f45c063aSXin LI continue; 1070f45c063aSXin LI if ((info->vi_height != 0) 1071f45c063aSXin LI && (info->vi_height != vesa_vmode[i].vi_height)) 1072f45c063aSXin LI continue; 1073f45c063aSXin LI if ((info->vi_cwidth != 0) 1074f45c063aSXin LI && (info->vi_cwidth != vesa_vmode[i].vi_cwidth)) 1075f45c063aSXin LI continue; 1076f45c063aSXin LI if ((info->vi_cheight != 0) 1077f45c063aSXin LI && (info->vi_cheight != vesa_vmode[i].vi_cheight)) 1078f45c063aSXin LI continue; 1079f45c063aSXin LI if ((info->vi_depth != 0) 1080f45c063aSXin LI && (info->vi_depth != vesa_vmode[i].vi_depth)) 1081f45c063aSXin LI continue; 1082f45c063aSXin LI if ((info->vi_planes != 0) 1083f45c063aSXin LI && (info->vi_planes != vesa_vmode[i].vi_planes)) 1084f45c063aSXin LI continue; 1085f45c063aSXin LI /* pixel format, memory model */ 1086f45c063aSXin LI if ((info->vi_flags != 0) 1087f45c063aSXin LI && (info->vi_flags != vesa_vmode[i].vi_flags)) 1088f45c063aSXin LI continue; 1089f45c063aSXin LI *info = vesa_vmode[i]; 1090f45c063aSXin LI return 0; 1091f45c063aSXin LI } 1092f45c063aSXin LI return ENODEV; 1093f45c063aSXin LI } 1094f45c063aSXin LI 1095f45c063aSXin LI static int 1096f45c063aSXin LI vesa_set_mode(video_adapter_t *adp, int mode) 1097f45c063aSXin LI { 1098f45c063aSXin LI video_info_t info; 1099f45c063aSXin LI 1100f45c063aSXin LI if (adp != vesa_adp) 1101f45c063aSXin LI return (*prevvidsw->set_mode)(adp, mode); 1102f45c063aSXin LI 1103f45c063aSXin LI mode = vesa_map_gen_mode_num(adp->va_type, 1104f45c063aSXin LI adp->va_flags & V_ADP_COLOR, mode); 1105f45c063aSXin LI #if VESA_DEBUG > 0 1106f45c063aSXin LI printf("VESA: set_mode(): %d(%x) -> %d(%x)\n", 1107f45c063aSXin LI adp->va_mode, adp->va_mode, mode, mode); 1108f45c063aSXin LI #endif 1109f45c063aSXin LI /* 1110f45c063aSXin LI * If the current mode is a VESA mode and the new mode is not, 1111f45c063aSXin LI * restore the state of the adapter first by setting one of the 1112f45c063aSXin LI * standard VGA mode, so that non-standard, extended SVGA registers 1113f45c063aSXin LI * are set to the state compatible with the standard VGA modes. 1114f45c063aSXin LI * Otherwise (*prevvidsw->set_mode)() may not be able to set up 1115f45c063aSXin LI * the new mode correctly. 1116f45c063aSXin LI */ 1117f45c063aSXin LI if (VESA_MODE(adp->va_mode)) { 1118f45c063aSXin LI if ((*prevvidsw->get_info)(adp, mode, &info) == 0) { 1119f45c063aSXin LI int10_set_mode(adp->va_initial_bios_mode); 1120f45c063aSXin LI if (adp->va_info.vi_flags & V_INFO_LINEAR) 1121f45c063aSXin LI vesa_unmap_buffer(adp->va_buffer, 1122f45c063aSXin LI vesa_adp_info->v_memsize*64*1024); 1123f45c063aSXin LI /* 1124f45c063aSXin LI * Once (*prevvidsw->get_info)() succeeded, 1125f45c063aSXin LI * (*prevvidsw->set_mode)() below won't fail... 1126f45c063aSXin LI */ 1127f45c063aSXin LI } 1128f45c063aSXin LI } 1129f45c063aSXin LI 1130f45c063aSXin LI /* we may not need to handle this mode after all... */ 1131f45c063aSXin LI if ((*prevvidsw->set_mode)(adp, mode) == 0) 1132f45c063aSXin LI return 0; 1133f45c063aSXin LI 1134f45c063aSXin LI /* is the new mode supported? */ 1135f45c063aSXin LI if (vesa_get_info(adp, mode, &info)) 1136f45c063aSXin LI return 1; 1137f45c063aSXin LI /* assert(VESA_MODE(mode)); */ 1138f45c063aSXin LI 1139f45c063aSXin LI #if VESA_DEBUG > 0 1140f45c063aSXin LI printf("VESA: about to set a VESA mode...\n"); 1141f45c063aSXin LI #endif 1142f45c063aSXin LI /* don't use the linear frame buffer for text modes. XXX */ 1143f45c063aSXin LI if (!(info.vi_flags & V_INFO_GRAPHICS)) 1144f45c063aSXin LI info.vi_flags &= ~V_INFO_LINEAR; 1145f45c063aSXin LI 1146f45c063aSXin LI if (vesa_bios_set_mode(mode | ((info.vi_flags & V_INFO_LINEAR) ? 0x4000 : 0))) 1147f45c063aSXin LI return 1; 1148f45c063aSXin LI 1149f45c063aSXin LI if (adp->va_info.vi_flags & V_INFO_LINEAR) 1150f45c063aSXin LI vesa_unmap_buffer(adp->va_buffer, 1151f45c063aSXin LI vesa_adp_info->v_memsize*64*1024); 1152f45c063aSXin LI 1153f45c063aSXin LI #if VESA_DEBUG > 0 1154f45c063aSXin LI printf("VESA: mode set!\n"); 1155f45c063aSXin LI #endif 1156f45c063aSXin LI vesa_adp->va_mode = mode; 1157f45c063aSXin LI vesa_adp->va_flags &= ~V_ADP_COLOR; 1158f45c063aSXin LI vesa_adp->va_flags |= 1159f45c063aSXin LI (info.vi_flags & V_INFO_COLOR) ? V_ADP_COLOR : 0; 1160f45c063aSXin LI vesa_adp->va_crtc_addr = 1161f45c063aSXin LI (vesa_adp->va_flags & V_ADP_COLOR) ? COLOR_CRTC : MONO_CRTC; 1162f45c063aSXin LI if (info.vi_flags & V_INFO_LINEAR) { 1163f45c063aSXin LI #if VESA_DEBUG > 1 1164f45c063aSXin LI printf("VESA: setting up LFB\n"); 1165f45c063aSXin LI #endif 1166f45c063aSXin LI vesa_adp->va_buffer = 1167f45c063aSXin LI vesa_map_buffer(info.vi_buffer, 1168f45c063aSXin LI vesa_adp_info->v_memsize*64*1024); 1169f45c063aSXin LI vesa_adp->va_buffer_size = info.vi_buffer_size; 1170f45c063aSXin LI vesa_adp->va_window = vesa_adp->va_buffer; 1171f45c063aSXin LI vesa_adp->va_window_size = info.vi_buffer_size/info.vi_planes; 1172f45c063aSXin LI vesa_adp->va_window_gran = info.vi_buffer_size/info.vi_planes; 1173f45c063aSXin LI } else { 1174f45c063aSXin LI vesa_adp->va_buffer = 0; 1175f45c063aSXin LI vesa_adp->va_buffer_size = info.vi_buffer_size; 1176205d67b0SXin LI vesa_adp->va_window = BIOS_PADDRTOVADDR(info.vi_window); 1177f45c063aSXin LI vesa_adp->va_window_size = info.vi_window_size; 1178f45c063aSXin LI vesa_adp->va_window_gran = info.vi_window_gran; 1179f45c063aSXin LI } 1180f45c063aSXin LI vesa_adp->va_window_orig = 0; 118154680451SJung-uk Kim vesa_adp->va_line_width = vesa_get_line_width(&info); 1182f45c063aSXin LI vesa_adp->va_disp_start.x = 0; 1183f45c063aSXin LI vesa_adp->va_disp_start.y = 0; 1184f45c063aSXin LI #if VESA_DEBUG > 0 118554680451SJung-uk Kim printf("vesa_set_mode(): vi_width:%d, line_width:%d\n", 118654680451SJung-uk Kim info.vi_width, vesa_adp->va_line_width); 1187f45c063aSXin LI #endif 1188f45c063aSXin LI bcopy(&info, &vesa_adp->va_info, sizeof(vesa_adp->va_info)); 1189f45c063aSXin LI 1190f45c063aSXin LI /* move hardware cursor out of the way */ 1191f45c063aSXin LI (*vidsw[vesa_adp->va_index]->set_hw_cursor)(vesa_adp, -1, -1); 1192f45c063aSXin LI 1193f45c063aSXin LI return 0; 1194f45c063aSXin LI } 1195f45c063aSXin LI 1196f45c063aSXin LI static int 1197f45c063aSXin LI vesa_save_font(video_adapter_t *adp, int page, int fontsize, int fontwidth, 1198f45c063aSXin LI u_char *data, int ch, int count) 1199f45c063aSXin LI { 1200f45c063aSXin LI return (*prevvidsw->save_font)(adp, page, fontsize, fontwidth, data, 1201f45c063aSXin LI ch, count); 1202f45c063aSXin LI } 1203f45c063aSXin LI 1204f45c063aSXin LI static int 1205f45c063aSXin LI vesa_load_font(video_adapter_t *adp, int page, int fontsize, int fontwidth, 1206f45c063aSXin LI u_char *data, int ch, int count) 1207f45c063aSXin LI { 1208f45c063aSXin LI return (*prevvidsw->load_font)(adp, page, fontsize, fontwidth, data, 1209f45c063aSXin LI ch, count); 1210f45c063aSXin LI } 1211f45c063aSXin LI 1212f45c063aSXin LI static int 1213f45c063aSXin LI vesa_show_font(video_adapter_t *adp, int page) 1214f45c063aSXin LI { 1215f45c063aSXin LI return (*prevvidsw->show_font)(adp, page); 1216f45c063aSXin LI } 1217f45c063aSXin LI 1218f45c063aSXin LI static int 1219f45c063aSXin LI vesa_save_palette(video_adapter_t *adp, u_char *palette) 1220f45c063aSXin LI { 1221f45c063aSXin LI int bits; 1222f45c063aSXin LI int error; 1223f45c063aSXin LI 1224f45c063aSXin LI if ((adp == vesa_adp) && (vesa_adp_info->v_flags & V_DAC8) 1225f45c063aSXin LI && VESA_MODE(adp->va_mode)) { 1226f45c063aSXin LI bits = vesa_bios_get_dac(); 1227f45c063aSXin LI error = vesa_bios_save_palette(0, 256, palette, bits); 1228f45c063aSXin LI if (error == 0) 1229f45c063aSXin LI return 0; 1230f45c063aSXin LI if (bits != 6) 1231f45c063aSXin LI return error; 1232f45c063aSXin LI } 1233f45c063aSXin LI 1234f45c063aSXin LI return (*prevvidsw->save_palette)(adp, palette); 1235f45c063aSXin LI } 1236f45c063aSXin LI 1237f45c063aSXin LI static int 1238f45c063aSXin LI vesa_load_palette(video_adapter_t *adp, u_char *palette) 1239f45c063aSXin LI { 1240f45c063aSXin LI #ifdef notyet 1241f45c063aSXin LI int bits; 1242f45c063aSXin LI int error; 1243f45c063aSXin LI 1244f45c063aSXin LI if ((adp == vesa_adp) && (vesa_adp_info->v_flags & V_DAC8) 1245f45c063aSXin LI && VESA_MODE(adp->va_mode) && ((bits = vesa_bios_set_dac(8)) > 6)) { 1246f45c063aSXin LI error = vesa_bios_load_palette(0, 256, palette, bits); 1247f45c063aSXin LI if (error == 0) 1248f45c063aSXin LI return 0; 1249f45c063aSXin LI if (vesa_bios_set_dac(6) != 6) 1250f45c063aSXin LI return 1; 1251f45c063aSXin LI } 1252f45c063aSXin LI #endif /* notyet */ 1253f45c063aSXin LI 1254f45c063aSXin LI return (*prevvidsw->load_palette)(adp, palette); 1255f45c063aSXin LI } 1256f45c063aSXin LI 1257f45c063aSXin LI static int 1258f45c063aSXin LI vesa_set_border(video_adapter_t *adp, int color) 1259f45c063aSXin LI { 1260f45c063aSXin LI return (*prevvidsw->set_border)(adp, color); 1261f45c063aSXin LI } 1262f45c063aSXin LI 1263f45c063aSXin LI static int 1264f45c063aSXin LI vesa_save_state(video_adapter_t *adp, void *p, size_t size) 1265f45c063aSXin LI { 1266f45c063aSXin LI if (adp != vesa_adp) 1267f45c063aSXin LI return (*prevvidsw->save_state)(adp, p, size); 1268f45c063aSXin LI 1269f45c063aSXin LI if (vesa_state_buf_size == 0) 1270f45c063aSXin LI vesa_state_buf_size = vesa_bios_state_buf_size(); 1271f45c063aSXin LI if (size == 0) 1272f45c063aSXin LI return (sizeof(int) + vesa_state_buf_size); 1273f45c063aSXin LI else if (size < (sizeof(int) + vesa_state_buf_size)) 1274f45c063aSXin LI return 1; 1275f45c063aSXin LI 1276f45c063aSXin LI ((adp_state_t *)p)->sig = V_STATE_SIG; 1277f45c063aSXin LI bzero(((adp_state_t *)p)->regs, vesa_state_buf_size); 1278f45c063aSXin LI return vesa_bios_save_restore(STATE_SAVE, ((adp_state_t *)p)->regs, 1279f45c063aSXin LI vesa_state_buf_size); 1280f45c063aSXin LI } 1281f45c063aSXin LI 1282f45c063aSXin LI static int 1283f45c063aSXin LI vesa_load_state(video_adapter_t *adp, void *p) 1284f45c063aSXin LI { 1285f45c063aSXin LI if ((adp != vesa_adp) || (((adp_state_t *)p)->sig != V_STATE_SIG)) 1286f45c063aSXin LI return (*prevvidsw->load_state)(adp, p); 1287f45c063aSXin LI 1288f45c063aSXin LI return vesa_bios_save_restore(STATE_LOAD, ((adp_state_t *)p)->regs, 1289f45c063aSXin LI vesa_state_buf_size); 1290f45c063aSXin LI } 1291f45c063aSXin LI 1292f45c063aSXin LI #if 0 1293f45c063aSXin LI static int 1294f45c063aSXin LI vesa_get_origin(video_adapter_t *adp, off_t *offset) 1295f45c063aSXin LI { 1296205d67b0SXin LI x86regs_t regs; 1297f45c063aSXin LI 1298f27b147eSXin LI bzero(®s, sizeof(regs)); 1299205d67b0SXin LI regs.R_EAX = 0x4f05; 1300205d67b0SXin LI regs.R_EBX = 0x10; 1301ee5e90daSXin LI 1302a8672748SJung-uk Kim x86bios_intr(®s, 0x10); 1303205d67b0SXin LI 1304205d67b0SXin LI if ((regs.R_AX & 0xff) != 0x4f) 1305f45c063aSXin LI return 1; 1306205d67b0SXin LI *offset = regs.DX * adp->va_window_gran; 1307ee5e90daSXin LI 1308f45c063aSXin LI return 0; 1309f45c063aSXin LI } 1310f45c063aSXin LI #endif 1311f45c063aSXin LI 1312f45c063aSXin LI static int 1313f45c063aSXin LI vesa_set_origin(video_adapter_t *adp, off_t offset) 1314f45c063aSXin LI { 1315205d67b0SXin LI x86regs_t regs; 1316205d67b0SXin LI 1317f45c063aSXin LI /* 1318f45c063aSXin LI * This function should return as quickly as possible to 1319f45c063aSXin LI * maintain good performance of the system. For this reason, 1320f45c063aSXin LI * error checking is kept minimal and let the VESA BIOS to 1321f45c063aSXin LI * detect error. 1322f45c063aSXin LI */ 1323f45c063aSXin LI if (adp != vesa_adp) 1324f45c063aSXin LI return (*prevvidsw->set_win_org)(adp, offset); 1325f45c063aSXin LI 1326f45c063aSXin LI /* if this is a linear frame buffer, do nothing */ 1327f45c063aSXin LI if (adp->va_info.vi_flags & V_INFO_LINEAR) 1328f45c063aSXin LI return 0; 1329f45c063aSXin LI /* XXX */ 1330f45c063aSXin LI if (adp->va_window_gran == 0) 1331f45c063aSXin LI return 1; 1332f45c063aSXin LI 1333f27b147eSXin LI bzero(®s, sizeof(regs)); 1334205d67b0SXin LI regs.R_EAX = 0x4f05; 1335205d67b0SXin LI regs.R_EBX = 0; 1336205d67b0SXin LI regs.R_EDX = offset / adp->va_window_gran; 1337a8672748SJung-uk Kim x86bios_intr(®s, 0x10); 1338ee5e90daSXin LI 1339205d67b0SXin LI if ((regs.R_AX & 0xff) != 0x4f) 1340f45c063aSXin LI return 1; 1341ee5e90daSXin LI 1342f27b147eSXin LI bzero(®s, sizeof(regs)); 1343205d67b0SXin LI regs.R_EAX = 0x4f05; 1344205d67b0SXin LI regs.R_EBX = 1; 1345205d67b0SXin LI regs.R_EDX = offset / adp->va_window_gran; 1346a8672748SJung-uk Kim x86bios_intr(®s, 0x10); 1347ee5e90daSXin LI 1348f45c063aSXin LI adp->va_window_orig = (offset/adp->va_window_gran)*adp->va_window_gran; 1349f45c063aSXin LI return 0; /* XXX */ 1350f45c063aSXin LI } 1351f45c063aSXin LI 1352f45c063aSXin LI static int 1353f45c063aSXin LI vesa_read_hw_cursor(video_adapter_t *adp, int *col, int *row) 1354f45c063aSXin LI { 1355f45c063aSXin LI return (*prevvidsw->read_hw_cursor)(adp, col, row); 1356f45c063aSXin LI } 1357f45c063aSXin LI 1358f45c063aSXin LI static int 1359f45c063aSXin LI vesa_set_hw_cursor(video_adapter_t *adp, int col, int row) 1360f45c063aSXin LI { 1361f45c063aSXin LI return (*prevvidsw->set_hw_cursor)(adp, col, row); 1362f45c063aSXin LI } 1363f45c063aSXin LI 1364f45c063aSXin LI static int 1365f45c063aSXin LI vesa_set_hw_cursor_shape(video_adapter_t *adp, int base, int height, 1366f45c063aSXin LI int celsize, int blink) 1367f45c063aSXin LI { 1368f45c063aSXin LI return (*prevvidsw->set_hw_cursor_shape)(adp, base, height, celsize, 1369f45c063aSXin LI blink); 1370f45c063aSXin LI } 1371f45c063aSXin LI 1372f45c063aSXin LI static int 1373f45c063aSXin LI vesa_blank_display(video_adapter_t *adp, int mode) 1374f45c063aSXin LI { 1375f45c063aSXin LI /* XXX: use VESA DPMS */ 1376f45c063aSXin LI return (*prevvidsw->blank_display)(adp, mode); 1377f45c063aSXin LI } 1378f45c063aSXin LI 1379f45c063aSXin LI static int 1380f45c063aSXin LI vesa_mmap(video_adapter_t *adp, vm_offset_t offset, vm_paddr_t *paddr, 1381f45c063aSXin LI int prot) 1382f45c063aSXin LI { 1383f45c063aSXin LI #if VESA_DEBUG > 0 1384ee5e90daSXin LI printf("vesa_mmap(): window:0x%tx, buffer:0x%tx, offset:0x%tx\n", 1385f45c063aSXin LI adp->va_info.vi_window, adp->va_info.vi_buffer, offset); 1386f45c063aSXin LI #endif 1387f45c063aSXin LI 1388f45c063aSXin LI if ((adp == vesa_adp) && (adp->va_info.vi_flags & V_INFO_LINEAR)) { 1389f45c063aSXin LI /* va_window_size == va_buffer_size/vi_planes */ 1390f45c063aSXin LI /* XXX: is this correct? */ 1391f45c063aSXin LI if (offset > adp->va_window_size - PAGE_SIZE) 1392f45c063aSXin LI return -1; 1393f45c063aSXin LI *paddr = adp->va_info.vi_buffer + offset; 1394f45c063aSXin LI return 0; 1395f45c063aSXin LI } else { 1396f45c063aSXin LI return (*prevvidsw->mmap)(adp, offset, paddr, prot); 1397f45c063aSXin LI } 1398f45c063aSXin LI } 1399f45c063aSXin LI 1400f45c063aSXin LI static int 1401f45c063aSXin LI vesa_clear(video_adapter_t *adp) 1402f45c063aSXin LI { 1403f45c063aSXin LI return (*prevvidsw->clear)(adp); 1404f45c063aSXin LI } 1405f45c063aSXin LI 1406f45c063aSXin LI static int 1407f45c063aSXin LI vesa_fill_rect(video_adapter_t *adp, int val, int x, int y, int cx, int cy) 1408f45c063aSXin LI { 1409f45c063aSXin LI return (*prevvidsw->fill_rect)(adp, val, x, y, cx, cy); 1410f45c063aSXin LI } 1411f45c063aSXin LI 1412f45c063aSXin LI static int 1413f45c063aSXin LI vesa_bitblt(video_adapter_t *adp,...) 1414f45c063aSXin LI { 1415f45c063aSXin LI /* FIXME */ 1416f45c063aSXin LI return 1; 1417f45c063aSXin LI } 1418f45c063aSXin LI 1419f45c063aSXin LI static int 1420f45c063aSXin LI get_palette(video_adapter_t *adp, int base, int count, 1421f45c063aSXin LI u_char *red, u_char *green, u_char *blue, u_char *trans) 1422f45c063aSXin LI { 1423f45c063aSXin LI u_char *r; 1424f45c063aSXin LI u_char *g; 1425f45c063aSXin LI u_char *b; 1426f45c063aSXin LI int bits; 1427f45c063aSXin LI int error; 1428f45c063aSXin LI 1429f45c063aSXin LI if ((base < 0) || (base >= 256) || (count < 0) || (count > 256)) 1430f45c063aSXin LI return 1; 1431f45c063aSXin LI if ((base + count) > 256) 1432f45c063aSXin LI return 1; 1433f45c063aSXin LI if (!(vesa_adp_info->v_flags & V_DAC8) || !VESA_MODE(adp->va_mode)) 1434f45c063aSXin LI return 1; 1435f45c063aSXin LI 1436f45c063aSXin LI bits = vesa_bios_get_dac(); 1437f45c063aSXin LI if (bits <= 6) 1438f45c063aSXin LI return 1; 1439f45c063aSXin LI 1440f45c063aSXin LI r = malloc(count*3, M_DEVBUF, M_WAITOK); 1441f45c063aSXin LI g = r + count; 1442f45c063aSXin LI b = g + count; 1443f45c063aSXin LI error = vesa_bios_save_palette2(base, count, r, g, b, bits); 1444f45c063aSXin LI if (error == 0) { 1445f45c063aSXin LI copyout(r, red, count); 1446f45c063aSXin LI copyout(g, green, count); 1447f45c063aSXin LI copyout(b, blue, count); 1448f45c063aSXin LI if (trans != NULL) { 1449f45c063aSXin LI bzero(r, count); 1450f45c063aSXin LI copyout(r, trans, count); 1451f45c063aSXin LI } 1452f45c063aSXin LI } 1453f45c063aSXin LI free(r, M_DEVBUF); 1454f45c063aSXin LI 1455f45c063aSXin LI /* if error && bits != 6 at this point, we are in trouble... XXX */ 1456f45c063aSXin LI return error; 1457f45c063aSXin LI } 1458f45c063aSXin LI 1459f45c063aSXin LI static int 1460f45c063aSXin LI set_palette(video_adapter_t *adp, int base, int count, 1461f45c063aSXin LI u_char *red, u_char *green, u_char *blue, u_char *trans) 1462f45c063aSXin LI { 1463f45c063aSXin LI return 1; 1464f45c063aSXin LI #ifdef notyet 1465f45c063aSXin LI u_char *r; 1466f45c063aSXin LI u_char *g; 1467f45c063aSXin LI u_char *b; 1468f45c063aSXin LI int bits; 1469f45c063aSXin LI int error; 1470f45c063aSXin LI 1471f45c063aSXin LI if ((base < 0) || (base >= 256) || (base + count > 256)) 1472f45c063aSXin LI return 1; 1473f45c063aSXin LI if (!(vesa_adp_info->v_flags & V_DAC8) || !VESA_MODE(adp->va_mode) 1474f45c063aSXin LI || ((bits = vesa_bios_set_dac(8)) <= 6)) 1475f45c063aSXin LI return 1; 1476f45c063aSXin LI 1477f45c063aSXin LI r = malloc(count*3, M_DEVBUF, M_WAITOK); 1478f45c063aSXin LI g = r + count; 1479f45c063aSXin LI b = g + count; 1480f45c063aSXin LI copyin(red, r, count); 1481f45c063aSXin LI copyin(green, g, count); 1482f45c063aSXin LI copyin(blue, b, count); 1483f45c063aSXin LI 1484f45c063aSXin LI error = vesa_bios_load_palette2(base, count, r, g, b, bits); 1485f45c063aSXin LI free(r, M_DEVBUF); 1486f45c063aSXin LI if (error == 0) 1487f45c063aSXin LI return 0; 1488f45c063aSXin LI 1489f45c063aSXin LI /* if the following call fails, we are in trouble... XXX */ 1490f45c063aSXin LI vesa_bios_set_dac(6); 1491f45c063aSXin LI return 1; 1492f45c063aSXin LI #endif /* notyet */ 1493f45c063aSXin LI } 1494f45c063aSXin LI 1495f45c063aSXin LI static int 1496f45c063aSXin LI vesa_ioctl(video_adapter_t *adp, u_long cmd, caddr_t arg) 1497f45c063aSXin LI { 1498f45c063aSXin LI int bytes; 1499f45c063aSXin LI 1500f45c063aSXin LI if (adp != vesa_adp) 1501f45c063aSXin LI return (*prevvidsw->ioctl)(adp, cmd, arg); 1502f45c063aSXin LI 1503f45c063aSXin LI switch (cmd) { 1504f45c063aSXin LI case FBIO_SETWINORG: /* set frame buffer window origin */ 1505f45c063aSXin LI if (!VESA_MODE(adp->va_mode)) 1506f45c063aSXin LI return (*prevvidsw->ioctl)(adp, cmd, arg); 1507f45c063aSXin LI return (vesa_set_origin(adp, *(off_t *)arg) ? ENODEV : 0); 1508f45c063aSXin LI 1509f45c063aSXin LI case FBIO_SETDISPSTART: /* set display start address */ 1510f45c063aSXin LI if (!VESA_MODE(adp->va_mode)) 1511f45c063aSXin LI return (*prevvidsw->ioctl)(adp, cmd, arg); 1512f45c063aSXin LI if (vesa_bios_set_start(((video_display_start_t *)arg)->x, 1513f45c063aSXin LI ((video_display_start_t *)arg)->y)) 1514f45c063aSXin LI return ENODEV; 1515f45c063aSXin LI adp->va_disp_start.x = ((video_display_start_t *)arg)->x; 1516f45c063aSXin LI adp->va_disp_start.y = ((video_display_start_t *)arg)->y; 1517f45c063aSXin LI return 0; 1518f45c063aSXin LI 1519f45c063aSXin LI case FBIO_SETLINEWIDTH: /* set line length in pixel */ 1520f45c063aSXin LI if (!VESA_MODE(adp->va_mode)) 1521f45c063aSXin LI return (*prevvidsw->ioctl)(adp, cmd, arg); 1522f45c063aSXin LI if (vesa_bios_set_line_length(*(u_int *)arg, &bytes, NULL)) 1523f45c063aSXin LI return ENODEV; 1524f45c063aSXin LI adp->va_line_width = bytes; 1525f45c063aSXin LI #if VESA_DEBUG > 1 1526f45c063aSXin LI printf("new line width:%d\n", adp->va_line_width); 1527f45c063aSXin LI #endif 1528f45c063aSXin LI return 0; 1529f45c063aSXin LI 1530f45c063aSXin LI case FBIO_GETPALETTE: /* get color palette */ 1531f45c063aSXin LI if (get_palette(adp, ((video_color_palette_t *)arg)->index, 1532f45c063aSXin LI ((video_color_palette_t *)arg)->count, 1533f45c063aSXin LI ((video_color_palette_t *)arg)->red, 1534f45c063aSXin LI ((video_color_palette_t *)arg)->green, 1535f45c063aSXin LI ((video_color_palette_t *)arg)->blue, 1536f45c063aSXin LI ((video_color_palette_t *)arg)->transparent)) 1537f45c063aSXin LI return (*prevvidsw->ioctl)(adp, cmd, arg); 1538f45c063aSXin LI return 0; 1539f45c063aSXin LI 1540f45c063aSXin LI 1541f45c063aSXin LI case FBIO_SETPALETTE: /* set color palette */ 1542f45c063aSXin LI if (set_palette(adp, ((video_color_palette_t *)arg)->index, 1543f45c063aSXin LI ((video_color_palette_t *)arg)->count, 1544f45c063aSXin LI ((video_color_palette_t *)arg)->red, 1545f45c063aSXin LI ((video_color_palette_t *)arg)->green, 1546f45c063aSXin LI ((video_color_palette_t *)arg)->blue, 1547f45c063aSXin LI ((video_color_palette_t *)arg)->transparent)) 1548f45c063aSXin LI return (*prevvidsw->ioctl)(adp, cmd, arg); 1549f45c063aSXin LI return 0; 1550f45c063aSXin LI 1551f45c063aSXin LI case FBIOGETCMAP: /* get color palette */ 1552f45c063aSXin LI if (get_palette(adp, ((struct fbcmap *)arg)->index, 1553f45c063aSXin LI ((struct fbcmap *)arg)->count, 1554f45c063aSXin LI ((struct fbcmap *)arg)->red, 1555f45c063aSXin LI ((struct fbcmap *)arg)->green, 1556f45c063aSXin LI ((struct fbcmap *)arg)->blue, NULL)) 1557f45c063aSXin LI return (*prevvidsw->ioctl)(adp, cmd, arg); 1558f45c063aSXin LI return 0; 1559f45c063aSXin LI 1560f45c063aSXin LI case FBIOPUTCMAP: /* set color palette */ 1561f45c063aSXin LI if (set_palette(adp, ((struct fbcmap *)arg)->index, 1562f45c063aSXin LI ((struct fbcmap *)arg)->count, 1563f45c063aSXin LI ((struct fbcmap *)arg)->red, 1564f45c063aSXin LI ((struct fbcmap *)arg)->green, 1565f45c063aSXin LI ((struct fbcmap *)arg)->blue, NULL)) 1566f45c063aSXin LI return (*prevvidsw->ioctl)(adp, cmd, arg); 1567f45c063aSXin LI return 0; 1568f45c063aSXin LI 1569f45c063aSXin LI default: 1570f45c063aSXin LI return (*prevvidsw->ioctl)(adp, cmd, arg); 1571f45c063aSXin LI } 1572f45c063aSXin LI } 1573f45c063aSXin LI 1574f45c063aSXin LI static int 1575f45c063aSXin LI vesa_diag(video_adapter_t *adp, int level) 1576f45c063aSXin LI { 1577f45c063aSXin LI int error; 1578f45c063aSXin LI 1579f45c063aSXin LI /* call the previous handler first */ 1580f45c063aSXin LI error = (*prevvidsw->diag)(adp, level); 1581f45c063aSXin LI if (error) 1582f45c063aSXin LI return error; 1583f45c063aSXin LI 1584f45c063aSXin LI if (adp != vesa_adp) 1585f45c063aSXin LI return 1; 1586f45c063aSXin LI 1587f45c063aSXin LI if (level <= 0) 1588f45c063aSXin LI return 0; 1589f45c063aSXin LI 1590f45c063aSXin LI return 0; 1591f45c063aSXin LI } 1592f45c063aSXin LI 1593f45c063aSXin LI static int 1594f45c063aSXin LI vesa_bios_info(int level) 1595f45c063aSXin LI { 1596f45c063aSXin LI #if VESA_DEBUG > 1 1597f45c063aSXin LI struct vesa_mode vmode; 1598f45c063aSXin LI int i; 1599f45c063aSXin LI #endif 1600f45c063aSXin LI 1601f45c063aSXin LI if (bootverbose) { 1602f45c063aSXin LI /* general adapter information */ 1603f45c063aSXin LI printf( 1604f45c063aSXin LI "VESA: v%d.%d, %dk memory, flags:0x%x, mode table:%p (%x)\n", 1605f45c063aSXin LI ((vesa_adp_info->v_version & 0xf000) >> 12) * 10 + 1606f45c063aSXin LI ((vesa_adp_info->v_version & 0x0f00) >> 8), 1607f45c063aSXin LI ((vesa_adp_info->v_version & 0x00f0) >> 4) * 10 + 1608f45c063aSXin LI (vesa_adp_info->v_version & 0x000f), 1609f45c063aSXin LI vesa_adp_info->v_memsize * 64, vesa_adp_info->v_flags, 1610f45c063aSXin LI vesa_vmodetab, vesa_adp_info->v_modetable); 1611f45c063aSXin LI 1612f45c063aSXin LI /* OEM string */ 1613f45c063aSXin LI if (vesa_oemstr != NULL) 1614f45c063aSXin LI printf("VESA: %s\n", vesa_oemstr); 1615f45c063aSXin LI } 1616f45c063aSXin LI 1617f45c063aSXin LI if (level <= 0) 1618f45c063aSXin LI return 0; 1619f45c063aSXin LI 1620f45c063aSXin LI if (vesa_adp_info->v_version >= 0x0200 && bootverbose) { 1621f45c063aSXin LI /* vender name, product name, product revision */ 1622f45c063aSXin LI printf("VESA: %s %s %s\n", 1623f45c063aSXin LI (vesa_venderstr != NULL) ? vesa_venderstr : "unknown", 1624f45c063aSXin LI (vesa_prodstr != NULL) ? vesa_prodstr : "unknown", 1625f45c063aSXin LI (vesa_revstr != NULL) ? vesa_revstr : "?"); 1626f45c063aSXin LI } 1627f45c063aSXin LI 1628f45c063aSXin LI #if VESA_DEBUG > 1 1629f45c063aSXin LI /* mode information */ 1630f45c063aSXin LI for (i = 0; 1631f45c063aSXin LI (i < (M_VESA_MODE_MAX - M_VESA_BASE + 1)) 1632f45c063aSXin LI && (vesa_vmodetab[i] != 0xffff); ++i) { 1633f45c063aSXin LI if (vesa_bios_get_mode(vesa_vmodetab[i], &vmode)) 1634f45c063aSXin LI continue; 1635f45c063aSXin LI 1636f45c063aSXin LI /* print something for diagnostic purpose */ 1637f45c063aSXin LI printf("VESA: mode:0x%03x, flags:0x%04x", 1638f45c063aSXin LI vesa_vmodetab[i], vmode.v_modeattr); 1639f45c063aSXin LI if (vmode.v_modeattr & V_MODEOPTINFO) { 1640f45c063aSXin LI if (vmode.v_modeattr & V_MODEGRAPHICS) { 1641f45c063aSXin LI printf(", G %dx%dx%d %d, ", 1642f45c063aSXin LI vmode.v_width, vmode.v_height, 1643f45c063aSXin LI vmode.v_bpp, vmode.v_planes); 1644f45c063aSXin LI } else { 1645f45c063aSXin LI printf(", T %dx%d, ", 1646f45c063aSXin LI vmode.v_width, vmode.v_height); 1647f45c063aSXin LI } 1648f45c063aSXin LI printf("font:%dx%d, ", 1649f45c063aSXin LI vmode.v_cwidth, vmode.v_cheight); 1650f45c063aSXin LI printf("pages:%d, mem:%d", 1651f45c063aSXin LI vmode.v_ipages + 1, vmode.v_memmodel); 1652f45c063aSXin LI } 1653f45c063aSXin LI if (vmode.v_modeattr & V_MODELFB) { 1654f45c063aSXin LI printf("\nVESA: LFB:0x%x, off:0x%x, off_size:0x%x", 1655f45c063aSXin LI vmode.v_lfb, vmode.v_offscreen, 1656f45c063aSXin LI vmode.v_offscreensize*1024); 1657f45c063aSXin LI } 1658f45c063aSXin LI printf("\n"); 1659f45c063aSXin LI printf("VESA: window A:0x%x (%x), window B:0x%x (%x), ", 1660f45c063aSXin LI vmode.v_waseg, vmode.v_waattr, 1661f45c063aSXin LI vmode.v_wbseg, vmode.v_wbattr); 1662f45c063aSXin LI printf("size:%dk, gran:%dk\n", 1663f45c063aSXin LI vmode.v_wsize, vmode.v_wgran); 1664f45c063aSXin LI } 1665f45c063aSXin LI #endif /* VESA_DEBUG > 1 */ 1666f45c063aSXin LI 1667f45c063aSXin LI return 0; 1668f45c063aSXin LI } 1669f45c063aSXin LI 1670f45c063aSXin LI /* module loading */ 1671f45c063aSXin LI 1672f45c063aSXin LI static int 1673f45c063aSXin LI vesa_load(void) 1674f45c063aSXin LI { 1675f45c063aSXin LI int error; 1676f45c063aSXin LI int s; 1677f45c063aSXin LI 1678f45c063aSXin LI if (vesa_init_done) 1679f45c063aSXin LI return 0; 1680f45c063aSXin LI 1681f45c063aSXin LI /* locate a VGA adapter */ 1682f45c063aSXin LI s = spltty(); 1683f45c063aSXin LI vesa_adp = NULL; 1684f45c063aSXin LI error = vesa_configure(0); 1685f45c063aSXin LI splx(s); 1686f45c063aSXin LI 1687f45c063aSXin LI if (error == 0) 1688f45c063aSXin LI vesa_bios_info(bootverbose); 1689f45c063aSXin LI 1690f45c063aSXin LI return error; 1691f45c063aSXin LI } 1692f45c063aSXin LI 1693f45c063aSXin LI static int 1694f45c063aSXin LI vesa_unload(void) 1695f45c063aSXin LI { 1696f45c063aSXin LI u_char palette[256*3]; 1697f45c063aSXin LI int error; 1698f45c063aSXin LI int bits; 1699f45c063aSXin LI int s; 1700f45c063aSXin LI 1701f45c063aSXin LI /* if the adapter is currently in a VESA mode, don't unload */ 1702f45c063aSXin LI if ((vesa_adp != NULL) && VESA_MODE(vesa_adp->va_mode)) 1703f45c063aSXin LI return EBUSY; 1704f45c063aSXin LI /* 1705f45c063aSXin LI * FIXME: if there is at least one vty which is in a VESA mode, 1706f45c063aSXin LI * we shouldn't be unloading! XXX 1707f45c063aSXin LI */ 1708f45c063aSXin LI 1709f45c063aSXin LI s = spltty(); 1710f45c063aSXin LI if ((error = vesa_unload_ioctl()) == 0) { 1711f45c063aSXin LI if (vesa_adp != NULL) { 1712f45c063aSXin LI if (vesa_adp_info->v_flags & V_DAC8) { 1713f45c063aSXin LI bits = vesa_bios_get_dac(); 1714f45c063aSXin LI if (bits > 6) { 1715f45c063aSXin LI vesa_bios_save_palette(0, 256, 1716f45c063aSXin LI palette, bits); 1717f45c063aSXin LI vesa_bios_set_dac(6); 1718f45c063aSXin LI vesa_bios_load_palette(0, 256, 1719f45c063aSXin LI palette, 6); 1720f45c063aSXin LI } 1721f45c063aSXin LI } 1722f45c063aSXin LI vesa_adp->va_flags &= ~V_ADP_VESA; 1723f45c063aSXin LI vidsw[vesa_adp->va_index] = prevvidsw; 1724f45c063aSXin LI } 1725f45c063aSXin LI } 1726f45c063aSXin LI splx(s); 1727f45c063aSXin LI 1728f45c063aSXin LI return error; 1729f45c063aSXin LI } 1730f45c063aSXin LI 1731f45c063aSXin LI static int 1732f45c063aSXin LI vesa_mod_event(module_t mod, int type, void *data) 1733f45c063aSXin LI { 1734f45c063aSXin LI switch (type) { 1735f45c063aSXin LI case MOD_LOAD: 1736f45c063aSXin LI return vesa_load(); 1737f45c063aSXin LI case MOD_UNLOAD: 1738f45c063aSXin LI return vesa_unload(); 1739f45c063aSXin LI default: 1740f45c063aSXin LI return EOPNOTSUPP; 1741f45c063aSXin LI } 1742f45c063aSXin LI return 0; 1743f45c063aSXin LI } 1744f45c063aSXin LI 1745f45c063aSXin LI static moduledata_t vesa_mod = { 1746f45c063aSXin LI "vesa", 1747f45c063aSXin LI vesa_mod_event, 1748f45c063aSXin LI NULL, 1749f45c063aSXin LI }; 1750f45c063aSXin LI 1751f45c063aSXin LI DECLARE_MODULE(vesa, vesa_mod, SI_SUB_DRIVERS, SI_ORDER_MIDDLE); 1752205d67b0SXin LI MODULE_DEPEND(vesa, x86bios, 1, 1, 1); 1753f45c063aSXin LI 1754f45c063aSXin LI #endif /* VGA_NO_MODE_CHANGE */ 1755