From: Kevin O'Connor Date: Sat, 14 Jan 2012 01:00:35 +0000 (-0500) Subject: vgabios: Make VBE code independent of bochsvga. X-Git-Url: http://wien.tomnetworks.com/gitweb/?p=seabios.git;a=commitdiff_plain;h=3339c05f19468f87da84ab059cf4ee5375abfa55 vgabios: Make VBE code independent of bochsvga. Introduce new global variables (VBE_enabled, VBE_total_memory, VBE_capabilities, VBE_framebuffer) to replace the need for function calls that were specific to bochsvga. Replace info received from bochsvga_mode_info with info found in vgahw_find_mode. Signed-off-by: Kevin O'Connor --- diff --git a/vgasrc/bochsvga.c b/vgasrc/bochsvga.c index 5ab1bc2..d9858c2 100644 --- a/vgasrc/bochsvga.c +++ b/vgasrc/bochsvga.c @@ -76,10 +76,6 @@ static struct bochsvga_mode { 0x18c, { MM_DIRECT, 2560, 1600, 32 } }, }; -#define BYTES_PER_PIXEL(m) ((GET_GLOBAL((m)->depth) + 7) / 8) - -u32 pci_lfb_addr VAR16; - static inline u32 pci_config_readl(u16 bdf, u16 addr) { int status; @@ -101,7 +97,6 @@ static inline u32 pci_config_readl(u16 bdf, u16 addr) return val; } - static u16 dispi_get_max_xres(void) { u16 en; @@ -145,7 +140,7 @@ bochsvga_init(void) return -1; } - SET_BDA(vbe_flag, 0x1); + SET_VGA(VBE_enabled, 1); dispi_write(VBE_DISPI_INDEX_ID, VBE_DISPI_ID5); u32 lfb_addr; @@ -154,51 +149,42 @@ bochsvga_init(void) else lfb_addr = VBE_DISPI_LFB_PHYSICAL_ADDRESS; - SET_FARVAR(get_global_seg(), pci_lfb_addr, lfb_addr); + SET_VGA(VBE_framebuffer, lfb_addr); + u16 totalmem = dispi_read(VBE_DISPI_INDEX_VIDEO_MEMORY_64K); + SET_VGA(VBE_total_memory, totalmem * 64 * 1024); + SET_VGA(VBE_capabilities, VBE_CAPABILITY_8BIT_DAC); - dprintf(1, "VBE DISPI detected. lfb_addr=%x\n", GET_GLOBAL(pci_lfb_addr)); + dprintf(1, "VBE DISPI detected. lfb_addr=%x\n", lfb_addr); return 0; } -int -bochsvga_enabled(void) +static int mode_valid(struct vgamode_s *vmode_g) { - return GET_BDA(vbe_flag); -} + u16 max_xres = dispi_get_max_xres(); + u16 max_bpp = dispi_get_max_bpp(); + u32 max_mem = GET_GLOBAL(VBE_total_memory); -u16 -bochsvga_total_mem(void) -{ - return dispi_read(VBE_DISPI_INDEX_VIDEO_MEMORY_64K); + u16 width = GET_GLOBAL(vmode_g->width); + u16 height = GET_GLOBAL(vmode_g->height); + u8 depth = GET_GLOBAL(vmode_g->depth); + u32 mem = width * height * DIV_ROUND_UP(depth, 8); + + return width <= max_xres && depth <= max_bpp && mem <= max_mem; } struct vgamode_s *bochsvga_find_mode(int mode) { struct bochsvga_mode *m = bochsvga_modes; for (; m < &bochsvga_modes[ARRAY_SIZE(bochsvga_modes)]; m++) - if (GET_GLOBAL(m->mode) == mode) + if (GET_GLOBAL(m->mode) == mode) { + if (! mode_valid(&m->info)) + return NULL; return &m->info; + } return stdvga_find_mode(mode); } -static int mode_valid(struct vgamode_s *vmode_g) -{ - u16 max_xres = dispi_get_max_xres(); - u16 max_bpp = dispi_get_max_bpp(); - u32 max_mem = bochsvga_total_mem() * 64 * 1024; - - u32 mem = GET_GLOBAL(vmode_g->width) * GET_GLOBAL(vmode_g->height) * - BYTES_PER_PIXEL(vmode_g); - - if (GET_GLOBAL(vmode_g->width) > max_xres || - GET_GLOBAL(vmode_g->depth) > max_bpp || - mem > max_mem) - return 0; - - return 1; -} - void bochsvga_list_modes(u16 seg, u16 *dest, u16 *last) { @@ -215,25 +201,7 @@ bochsvga_list_modes(u16 seg, u16 *dest, u16 *last) stdvga_list_modes(seg, dest, last); } -int -bochsvga_mode_info(u16 mode, struct vbe_modeinfo *info) -{ - struct vgamode_s *vmode_g = bochsvga_find_mode(mode); - if (!vmode_g || !mode_valid(vmode_g)) - return -1; - - info->width = GET_GLOBAL(vmode_g->width); - info->height = GET_GLOBAL(vmode_g->height); - info->depth = GET_GLOBAL(vmode_g->depth); - - info->linesize = info->width * ((info->depth + 7) / 8); - info->phys_base = GET_GLOBAL(pci_lfb_addr); - info->vram_size = bochsvga_total_mem() * 64 * 1024; - - return 0; -} - -void +static void bochsvga_hires_enable(int enable) { u16 flags = enable ? @@ -244,43 +212,56 @@ bochsvga_hires_enable(int enable) dispi_write(VBE_DISPI_INDEX_ENABLE, flags); } +static void +bochsvga_clear_scr(void) +{ + u16 en; + + en = dispi_read(VBE_DISPI_INDEX_ENABLE); + en &= ~VBE_DISPI_NOCLEARMEM; + dispi_write(VBE_DISPI_INDEX_ENABLE, en); +} + int bochsvga_set_mode(int mode, int flags) { if (!(mode & VBE_MODE_VESA_DEFINED)) { dprintf(1, "set VGA mode %x\n", mode); + SET_BDA(vbe_mode, 0); bochsvga_hires_enable(0); return stdvga_set_mode(mode, flags); } - struct vbe_modeinfo modeinfo, *info = &modeinfo; - int ret = bochsvga_mode_info(mode, &modeinfo); - if (ret) { + struct vgamode_s *vmode_g = bochsvga_find_mode(mode); + if (!vmode_g) { dprintf(1, "VBE mode %x not found\n", mode); return VBE_RETURN_STATUS_FAILED; } bochsvga_hires_enable(1); - if (info->depth == 4) + u8 depth = GET_GLOBAL(vmode_g->depth); + if (depth == 4) stdvga_set_mode(0x6a, 0); - if (info->depth == 8) + if (depth == 8) // XXX load_dac_palette(3); ; - dispi_write(VBE_DISPI_INDEX_BPP, info->depth); - dispi_write(VBE_DISPI_INDEX_XRES, info->width); - dispi_write(VBE_DISPI_INDEX_YRES, info->height); + dispi_write(VBE_DISPI_INDEX_BPP, depth); + u16 width = GET_GLOBAL(vmode_g->width); + u16 height = GET_GLOBAL(vmode_g->height); + dispi_write(VBE_DISPI_INDEX_XRES, width); + dispi_write(VBE_DISPI_INDEX_YRES, height); dispi_write(VBE_DISPI_INDEX_BANK, 0); /* VGA compat setup */ //XXX: This probably needs some reverse engineering u8 v; outw(0x0011, VGAREG_VGA_CRTC_ADDRESS); - outw(((info->width * 4 - 1) << 8) | 0x1, VGAREG_VGA_CRTC_ADDRESS); - dispi_write(VBE_DISPI_INDEX_VIRT_WIDTH, info->width); - outw(((info->height - 1) << 8) | 0x12, VGAREG_VGA_CRTC_ADDRESS); - outw(((info->height - 1) & 0xff00) | 0x7, VGAREG_VGA_CRTC_ADDRESS); + outw(((width * 4 - 1) << 8) | 0x1, VGAREG_VGA_CRTC_ADDRESS); + dispi_write(VBE_DISPI_INDEX_VIRT_WIDTH, width); + outw(((height - 1) << 8) | 0x12, VGAREG_VGA_CRTC_ADDRESS); + outw(((height - 1) & 0xff00) | 0x7, VGAREG_VGA_CRTC_ADDRESS); v = inb(VGAREG_VGA_CRTC_DATA) & 0xbd; if (v & 0x1) v |= 0x2; @@ -298,7 +279,7 @@ bochsvga_set_mode(int mode, int flags) outb(0x20, VGAREG_ACTL_ADDRESS); outw(0x0506, VGAREG_GRDC_ADDRESS); outw(0x0f02, VGAREG_SEQU_ADDRESS); - if (info->depth >= 8) { + if (depth >= 8) { outb(0x14, VGAREG_VGA_CRTC_ADDRESS); outb(inb(VGAREG_VGA_CRTC_DATA) | 0x40, VGAREG_VGA_CRTC_DATA); v = inb(VGAREG_ACTL_RESET); @@ -314,7 +295,7 @@ bochsvga_set_mode(int mode, int flags) outb(v | 0x40, VGAREG_GRDC_DATA); } - SET_BDA(vbe_mode, mode); + SET_BDA(vbe_mode, mode | flags); if (flags & MF_LINEARFB) { /* Linear frame buffer */ @@ -326,25 +307,3 @@ bochsvga_set_mode(int mode, int flags) return 0; } - -void -bochsvga_clear_scr(void) -{ - u16 en; - - en = dispi_read(VBE_DISPI_INDEX_ENABLE); - en &= ~VBE_DISPI_NOCLEARMEM; - dispi_write(VBE_DISPI_INDEX_ENABLE, en); -} - -int -bochsvga_hires_enabled(void) -{ - return dispi_read(VBE_DISPI_INDEX_ENABLE) & VBE_DISPI_ENABLED; -} - -u16 -bochsvga_curr_mode(void) -{ - return GET_BDA(vbe_mode); -} diff --git a/vgasrc/bochsvga.h b/vgasrc/bochsvga.h index c08f103..a9cedbf 100644 --- a/vgasrc/bochsvga.h +++ b/vgasrc/bochsvga.h @@ -53,16 +53,8 @@ static inline void dispi_write(u16 reg, u16 val) } int bochsvga_init(void); -int bochsvga_enabled(void); -u16 bochsvga_total_mem(void); void bochsvga_list_modes(u16 seg, u16 *dest, u16 *last); -struct vbe_modeinfo; -int bochsvga_mode_info(u16 mode, struct vbe_modeinfo *info); -void bochsvga_hires_enable(int enable); struct vgamode_s *bochsvga_find_mode(int mode); int bochsvga_set_mode(int mode, int flags); -void bochsvga_clear_scr(void); -int bochsvga_hires_enabled(void); -u16 bochsvga_curr_mode(void); #endif // bochsvga.h diff --git a/vgasrc/vbe.c b/vgasrc/vbe.c index daf8c51..d764a0c 100644 --- a/vgasrc/vbe.c +++ b/vgasrc/vbe.c @@ -11,9 +11,13 @@ #include "vbe.h" // struct vbe_info #include "util.h" // dprintf #include "biosvar.h" // get_global_set -#include "bochsvga.h" // bochsvga_hires_enabled #include "vgahw.h" // vgahw_set_mode +int VBE_enabled VAR16; +u32 VBE_total_memory VAR16 = 256 * 1024; +u32 VBE_capabilities VAR16; +u32 VBE_framebuffer VAR16; + static void vbe_104f00(struct bregs *regs) { @@ -36,14 +40,15 @@ vbe_104f00(struct bregs *regs) SET_FARVAR(seg, info->oem_string, SEGOFF(get_global_seg(), (u32)VBE_OEM_STRING)); - SET_FARVAR(seg, info->capabilities, 0x1); /* 8BIT DAC */ + SET_FARVAR(seg, info->capabilities, GET_GLOBAL(VBE_capabilities)); /* We generate our mode list in the reserved field of the info block */ u16 *destmode = (void*)info->reserved; SET_FARVAR(seg, info->video_mode, SEGOFF(seg, (u32)destmode)); /* Total memory (in 64 blocks) */ - SET_FARVAR(seg, info->total_memory, bochsvga_total_mem()); + SET_FARVAR(seg, info->total_memory + , GET_GLOBAL(VBE_total_memory) / (64*1024)); SET_FARVAR(seg, info->oem_vendor_string, SEGOFF(get_global_seg(), (u32)VBE_VENDOR_STRING)); @@ -56,8 +61,7 @@ vbe_104f00(struct bregs *regs) u16 *last = (void*)&info->reserved[sizeof(info->reserved)]; vgahw_list_modes(seg, destmode, last - 1); - regs->al = regs->ah; /* 0x4F, Function supported */ - regs->ah = 0x0; /* 0x0, Function call successful */ + regs->ax = 0x004f; } static void @@ -66,15 +70,13 @@ vbe_104f01(struct bregs *regs) u16 seg = regs->es; struct vbe_mode_info *info = (void*)(regs->di+0); u16 mode = regs->cx; - struct vbe_modeinfo modeinfo; - int rc; dprintf(1, "VBE mode info request: %x\n", mode); - rc = bochsvga_mode_info(mode, &modeinfo); - if (rc) { + struct vgamode_s *vmode_g = vgahw_find_mode(mode); + if (! vmode_g) { dprintf(1, "VBE mode %x not found\n", mode); - regs->ax = 0x100; + regs->ax = 0x0100; return; } @@ -82,7 +84,8 @@ vbe_104f01(struct bregs *regs) VBE_MODE_ATTRIBUTE_EXTENDED_INFORMATION_AVAILABLE | VBE_MODE_ATTRIBUTE_COLOR_MODE | VBE_MODE_ATTRIBUTE_GRAPHICS_MODE; - if (modeinfo.depth == 4) + int depth = GET_GLOBAL(vmode_g->depth); + if (depth == 4) mode_attr |= VBE_MODE_ATTRIBUTE_TTY_BIOS_SUPPORT; else mode_attr |= VBE_MODE_ATTRIBUTE_LINEAR_FRAME_BUFFER_MODE; @@ -97,27 +100,29 @@ vbe_104f01(struct bregs *regs) SET_FARVAR(seg, info->winA_seg, 0xA000); SET_FARVAR(seg, info->winB_seg, 0x0); SET_FARVAR(seg, info->win_func_ptr.segoff, 0x0); - SET_FARVAR(seg, info->bytes_per_scanline, modeinfo.linesize); - SET_FARVAR(seg, info->xres, modeinfo.width); - SET_FARVAR(seg, info->yres, modeinfo.height); + int width = GET_GLOBAL(vmode_g->width); + int height = GET_GLOBAL(vmode_g->height); + int linesize = width * DIV_ROUND_UP(depth, 8); // XXX - not always true + SET_FARVAR(seg, info->bytes_per_scanline, linesize); + SET_FARVAR(seg, info->xres, width); + SET_FARVAR(seg, info->yres, height); SET_FARVAR(seg, info->xcharsize, 8); SET_FARVAR(seg, info->ycharsize, 16); - if (modeinfo.depth == 4) + if (depth == 4) SET_FARVAR(seg, info->planes, 4); else SET_FARVAR(seg, info->planes, 1); - SET_FARVAR(seg, info->bits_per_pixel, modeinfo.depth); - SET_FARVAR(seg, info->banks, - (modeinfo.linesize * modeinfo.height + 65535) / 65536); - if (modeinfo.depth == 4) + SET_FARVAR(seg, info->bits_per_pixel, depth); + SET_FARVAR(seg, info->banks, DIV_ROUND_UP(linesize * height, 64*1024)); + if (depth == 4) SET_FARVAR(seg, info->mem_model, VBE_MEMORYMODEL_PLANAR); - else if (modeinfo.depth == 8) + else if (depth == 8) SET_FARVAR(seg, info->mem_model, VBE_MEMORYMODEL_PACKED_PIXEL); else SET_FARVAR(seg, info->mem_model, VBE_MEMORYMODEL_DIRECT_COLOR); SET_FARVAR(seg, info->bank_size, 0); - u32 pages = modeinfo.vram_size / (modeinfo.height * modeinfo.linesize); - if (modeinfo.depth == 4) + u32 pages = GET_GLOBAL(VBE_total_memory) / (height * linesize); + if (depth == 4) SET_FARVAR(seg, info->pages, (pages / 4) - 1); else SET_FARVAR(seg, info->pages, pages - 1); @@ -125,7 +130,7 @@ vbe_104f01(struct bregs *regs) u8 r_size, r_pos, g_size, g_pos, b_size, b_pos, a_size, a_pos; - switch (modeinfo.depth) { + switch (depth) { case 15: r_size = 5; r_pos = 10; g_size = 5; g_pos = 5; b_size = 5; b_pos = 0; a_size = 1; a_pos = 15; break; case 16: r_size = 5; r_pos = 11; g_size = 6; g_pos = 5; @@ -147,20 +152,20 @@ vbe_104f01(struct bregs *regs) SET_FARVAR(seg, info->alpha_size, a_size); SET_FARVAR(seg, info->alpha_pos, a_pos); - if (modeinfo.depth == 32) + if (depth == 32) SET_FARVAR(seg, info->directcolor_info, VBE_DIRECTCOLOR_RESERVED_BITS_AVAILABLE); else SET_FARVAR(seg, info->directcolor_info, 0); - if (modeinfo.depth > 4) - SET_FARVAR(seg, info->phys_base, modeinfo.phys_base); + if (depth > 4) + SET_FARVAR(seg, info->phys_base, GET_GLOBAL(VBE_framebuffer)); else SET_FARVAR(seg, info->phys_base, 0); SET_FARVAR(seg, info->reserved1, 0); SET_FARVAR(seg, info->reserved2, 0); - SET_FARVAR(seg, info->linear_bytes_per_scanline, modeinfo.linesize); + SET_FARVAR(seg, info->linear_bytes_per_scanline, linesize); SET_FARVAR(seg, info->bank_pages, 0); SET_FARVAR(seg, info->linear_pages, 0); SET_FARVAR(seg, info->linear_red_size, r_size); @@ -173,8 +178,7 @@ vbe_104f01(struct bregs *regs) SET_FARVAR(seg, info->linear_alpha_pos, a_pos); SET_FARVAR(seg, info->pixclock_max, 0); - regs->al = regs->ah; /* 0x4F, Function supported */ - regs->ah = 0x0; /* 0x0, Function call successful */ + regs->ax = 0x004f; } static void @@ -193,16 +197,13 @@ vbe_104f02(struct bregs *regs) static void vbe_104f03(struct bregs *regs) { - if (!bochsvga_hires_enabled()) { + u16 mode = GET_BDA(vbe_mode); + if (!mode) regs->bx = GET_BDA(video_mode); - } else { - regs->bx = bochsvga_curr_mode(); - } dprintf(1, "VBE current mode=%x\n", regs->bx); - regs->al = regs->ah; /* 0x4F, Function supported */ - regs->ah = 0x0; /* 0x0, Function call successful */ + regs->ax = 0x004f; } static void @@ -257,7 +258,7 @@ vbe_104fXX(struct bregs *regs) void handle_104f(struct bregs *regs) { - if (!bochsvga_enabled()) { + if (!GET_GLOBAL(VBE_enabled)) { vbe_104fXX(regs); return; } diff --git a/vgasrc/vgabios.h b/vgasrc/vgabios.h index 3416b98..464100b 100644 --- a/vgasrc/vgabios.h +++ b/vgasrc/vgabios.h @@ -83,21 +83,14 @@ void vgafb_write_pixel(u8 color, u16 x, u16 y); u8 vgafb_read_pixel(u16 x, u16 y); // vbe.c +int VBE_enabled; +u32 VBE_total_memory; +u32 VBE_capabilities; +u32 VBE_framebuffer; #define VBE_OEM_STRING "SeaBIOS VBE(C) 2011" #define VBE_VENDOR_STRING "SeaBIOS Developers" #define VBE_PRODUCT_STRING "SeaBIOS VBE Adapter" #define VBE_REVISION_STRING "Rev. 1" - -struct vbe_modeinfo -{ - u16 width; - u16 height; - u8 depth; - u16 linesize; - u32 phys_base; - u32 vram_size; -}; - struct bregs; void handle_104f(struct bregs *regs);