Some additional changes. Things should be about to wind down on the vgabios front. Cirrus should be about done. For bochsvga, only vbe functions 04/08 remain to be ported. (Per Gerd's feedback, I don't think it's worth porting the 32bit vbe interface.)
-Kevin
Kevin O'Connor (6): vgabios: Compare PCI ids against pci rom struct instead of config settings. vgabios: Fix linelength calculations in bochsvga and vbe. vgabios: Rework bochsvga mode switching. vgabios: Simplify cirrus find mode code. vgabios: Minor - organize cirrus code so like functions are near each other. vgabios: Move bocshvga mode checking from runtime to init.
vgasrc/bochsvga.c | 206 +++++++++++++++++------------------------- vgasrc/bochsvga.h | 4 +- vgasrc/clext.c | 255 +++++++++++++++++++++------------------------------- vgasrc/clext.h | 4 +- vgasrc/vbe.c | 13 +-- vgasrc/vgabios.c | 6 +- 6 files changed, 199 insertions(+), 289 deletions(-)
QEMU can update the pci rom struct - so use that as the location to determine if the pci address passed into the option rom is accurate.
Signed-off-by: Kevin O'Connor kevin@koconnor.net --- vgasrc/vgabios.c | 6 ++++-- 1 files changed, 4 insertions(+), 2 deletions(-)
diff --git a/vgasrc/vgabios.c b/vgasrc/vgabios.c index 2f24e78..e69c6c5 100644 --- a/vgasrc/vgabios.c +++ b/vgasrc/vgabios.c @@ -1279,8 +1279,10 @@ vga_post(struct bregs *regs)
if (CONFIG_VGA_PCI) { u16 bdf = regs->ax; - if (pci_config_readw(bdf, PCI_VENDOR_ID) == CONFIG_VGA_VID - && pci_config_readw(bdf, PCI_DEVICE_ID) == CONFIG_VGA_DID) + if ((pci_config_readw(bdf, PCI_VENDOR_ID) + == GET_GLOBAL(rom_pci_data.vendor)) + && (pci_config_readw(bdf, PCI_DEVICE_ID) + == GET_GLOBAL(rom_pci_data.device))) SET_VGA(VgaBDF, bdf); }
Signed-off-by: Kevin O'Connor kevin@koconnor.net --- vgasrc/bochsvga.c | 3 ++- vgasrc/vbe.c | 13 ++++--------- 2 files changed, 6 insertions(+), 10 deletions(-)
diff --git a/vgasrc/bochsvga.c b/vgasrc/bochsvga.c index e40a1fd..3668832 100644 --- a/vgasrc/bochsvga.c +++ b/vgasrc/bochsvga.c @@ -171,7 +171,8 @@ static int mode_valid(struct vgamode_s *vmode_g) 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); + u32 mem = (height * DIV_ROUND_UP(width * vga_bpp(vmode_g), 8) + * 4 / stdvga_bpp_factor(vmode_g));
return width <= max_xres && depth <= max_bpp && mem <= max_mem; } diff --git a/vgasrc/vbe.c b/vgasrc/vbe.c index 55ad97e..77b0934 100644 --- a/vgasrc/vbe.c +++ b/vgasrc/vbe.c @@ -108,25 +108,20 @@ vbe_104f01(struct bregs *regs) , SEGOFF(get_global_seg(), (u32)entry_104f05)); int width = GET_GLOBAL(vmode_g->width); int height = GET_GLOBAL(vmode_g->height); - int linesize = width * DIV_ROUND_UP(depth, 8); + int linesize = DIV_ROUND_UP(width * vga_bpp(vmode_g), 8); 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, GET_GLOBAL(vmode_g->cwidth)); SET_FARVAR(seg, info->ycharsize, GET_GLOBAL(vmode_g->cheight)); - if (depth == 4) - SET_FARVAR(seg, info->planes, 4); - else - SET_FARVAR(seg, info->planes, 1); + int planes = (depth == 4) ? 4 : 1; + SET_FARVAR(seg, info->planes, planes); SET_FARVAR(seg, info->bits_per_pixel, depth); SET_FARVAR(seg, info->banks, 1); SET_FARVAR(seg, info->mem_model, GET_GLOBAL(vmode_g->memmodel)); SET_FARVAR(seg, info->bank_size, 0); 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); + SET_FARVAR(seg, info->pages, (pages / planes) - 1); SET_FARVAR(seg, info->reserved0, 1);
u8 r_size, r_pos, g_size, g_pos, b_size, b_pos, a_size, a_pos;
Make the bochsvga mode switch more similar to the original lgpl vgabios code.
Signed-off-by: Kevin O'Connor kevin@koconnor.net --- vgasrc/bochsvga.c | 42 ++++++------------------------------------ 1 files changed, 6 insertions(+), 36 deletions(-)
diff --git a/vgasrc/bochsvga.c b/vgasrc/bochsvga.c index 3668832..71f2cd4 100644 --- a/vgasrc/bochsvga.c +++ b/vgasrc/bochsvga.c @@ -205,17 +205,6 @@ bochsvga_list_modes(u16 seg, u16 *dest, u16 *last) stdvga_list_modes(seg, dest, last); }
-static void -bochsvga_hires_enable(int enable) -{ - u16 flags = enable ? - VBE_DISPI_ENABLED | - VBE_DISPI_LFB_ENABLED | - VBE_DISPI_NOCLEARMEM : 0; - - dispi_write(VBE_DISPI_INDEX_ENABLE, flags); -} - int bochsvga_get_window(struct vgamode_s *vmode_g, int window) { @@ -271,25 +260,12 @@ bochsvga_set_displaystart(struct vgamode_s *vmode_g, int val) return 0; }
-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(struct vgamode_s *vmode_g, int flags) { - if (! is_bochsvga_mode(vmode_g)) { - bochsvga_hires_enable(0); + dispi_write(VBE_DISPI_INDEX_ENABLE, VBE_DISPI_DISABLED); + if (! is_bochsvga_mode(vmode_g)) return stdvga_set_mode(vmode_g, flags); - } - - bochsvga_hires_enable(1);
u8 depth = GET_GLOBAL(vmode_g->depth); if (depth == 4) @@ -304,13 +280,15 @@ bochsvga_set_mode(struct vgamode_s *vmode_g, int flags) dispi_write(VBE_DISPI_INDEX_XRES, width); dispi_write(VBE_DISPI_INDEX_YRES, height); dispi_write(VBE_DISPI_INDEX_BANK, 0); + u16 bf = ((flags & MF_NOCLEARMEM ? VBE_DISPI_NOCLEARMEM : 0) + | (flags & MF_LINEARFB ? VBE_DISPI_LFB_ENABLED : 0)); + dispi_write(VBE_DISPI_INDEX_ENABLE, VBE_DISPI_ENABLED | bf);
/* VGA compat setup */ - //XXX: This probably needs some reverse engineering u16 crtc_addr = VGAREG_VGA_CRTC_ADDRESS; stdvga_crtc_write(crtc_addr, 0x11, 0x00); stdvga_crtc_write(crtc_addr, 0x01, width / 8 - 1); - dispi_write(VBE_DISPI_INDEX_VIRT_WIDTH, width); + stdvga_set_linelength(vmode_g, width); stdvga_crtc_write(crtc_addr, 0x12, height - 1); u8 v = 0; if ((height - 1) & 0x0100) @@ -331,13 +309,5 @@ bochsvga_set_mode(struct vgamode_s *vmode_g, int flags) stdvga_grdc_mask(0x05, 0x20, 0x40); }
- if (flags & MF_LINEARFB) { - /* Linear frame buffer */ - /* XXX: ??? */ - } - if (!(flags & MF_NOCLEARMEM)) { - bochsvga_clear_scr(); - } - return 0; }
Signed-off-by: Kevin O'Connor kevin@koconnor.net --- vgasrc/clext.c | 136 +++++++++++++++++--------------------------------------- vgasrc/clext.h | 2 +- 2 files changed, 42 insertions(+), 96 deletions(-)
diff --git a/vgasrc/clext.c b/vgasrc/clext.c index 45fab80..7508b12 100644 --- a/vgasrc/clext.c +++ b/vgasrc/clext.c @@ -16,7 +16,7 @@
/**************************************************************** - * tables + * Cirrus mode tables ****************************************************************/
/* VGA */ @@ -216,7 +216,7 @@ static u16 ccrtc_1600x1200x8[] VAR16 = { };
struct cirrus_mode_s { - u16 mode; + u16 mode, vesamode; struct vgamode_s info;
u16 hidden_dac; /* 0x3c6 */ @@ -226,87 +226,47 @@ struct cirrus_mode_s { };
static struct cirrus_mode_s cirrus_modes[] VAR16 = { - {0x5f,{MM_PACKED,640,480,8,8,16,SEG_GRAPH},0x00, + {0x5f,0x101,{MM_PACKED,640,480,8,8,16,SEG_GRAPH},0x00, cseq_640x480x8,cgraph_svgacolor,ccrtc_640x480x8}, - {0x64,{MM_DIRECT,640,480,16,8,16,SEG_GRAPH},0xe1, + {0x64,0x111,{MM_DIRECT,640,480,16,8,16,SEG_GRAPH},0xe1, cseq_640x480x16,cgraph_svgacolor,ccrtc_640x480x16}, - {0x66,{MM_DIRECT,640,480,15,8,16,SEG_GRAPH},0xf0, + {0x66,0x110,{MM_DIRECT,640,480,15,8,16,SEG_GRAPH},0xf0, cseq_640x480x16,cgraph_svgacolor,ccrtc_640x480x16}, - {0x71,{MM_DIRECT,640,480,24,8,16,SEG_GRAPH},0xe5, + {0x71,0x112,{MM_DIRECT,640,480,24,8,16,SEG_GRAPH},0xe5, cseq_640x480x24,cgraph_svgacolor,ccrtc_640x480x24},
- {0x5c,{MM_PACKED,800,600,8,8,16,SEG_GRAPH},0x00, + {0x5c,0x103,{MM_PACKED,800,600,8,8,16,SEG_GRAPH},0x00, cseq_800x600x8,cgraph_svgacolor,ccrtc_800x600x8}, - {0x65,{MM_DIRECT,800,600,16,8,16,SEG_GRAPH},0xe1, + {0x65,0x114,{MM_DIRECT,800,600,16,8,16,SEG_GRAPH},0xe1, cseq_800x600x16,cgraph_svgacolor,ccrtc_800x600x16}, - {0x67,{MM_DIRECT,800,600,15,8,16,SEG_GRAPH},0xf0, + {0x67,0x113,{MM_DIRECT,800,600,15,8,16,SEG_GRAPH},0xf0, cseq_800x600x16,cgraph_svgacolor,ccrtc_800x600x16},
- {0x60,{MM_PACKED,1024,768,8,8,16,SEG_GRAPH},0x00, + {0x60,0x105,{MM_PACKED,1024,768,8,8,16,SEG_GRAPH},0x00, cseq_1024x768x8,cgraph_svgacolor,ccrtc_1024x768x8}, - {0x74,{MM_DIRECT,1024,768,16,8,16,SEG_GRAPH},0xe1, + {0x74,0x117,{MM_DIRECT,1024,768,16,8,16,SEG_GRAPH},0xe1, cseq_1024x768x16,cgraph_svgacolor,ccrtc_1024x768x16}, - {0x68,{MM_DIRECT,1024,768,15,8,16,SEG_GRAPH},0xf0, + {0x68,0x116,{MM_DIRECT,1024,768,15,8,16,SEG_GRAPH},0xf0, cseq_1024x768x16,cgraph_svgacolor,ccrtc_1024x768x16},
- {0x78,{MM_DIRECT,800,600,24,8,16,SEG_GRAPH},0xe5, + {0x78,0x115,{MM_DIRECT,800,600,24,8,16,SEG_GRAPH},0xe5, cseq_800x600x24,cgraph_svgacolor,ccrtc_800x600x24}, - {0x79,{MM_DIRECT,1024,768,24,8,16,SEG_GRAPH},0xe5, + {0x79,0x118,{MM_DIRECT,1024,768,24,8,16,SEG_GRAPH},0xe5, cseq_1024x768x24,cgraph_svgacolor,ccrtc_1024x768x24},
- {0x6d,{MM_PACKED,1280,1024,8,8,16,SEG_GRAPH},0x00, + {0x6d,0x107,{MM_PACKED,1280,1024,8,8,16,SEG_GRAPH},0x00, cseq_1280x1024x8,cgraph_svgacolor,ccrtc_1280x1024x8}, - {0x69,{MM_DIRECT,1280,1024,15,8,16,SEG_GRAPH},0xf0, + {0x69,0x119,{MM_DIRECT,1280,1024,15,8,16,SEG_GRAPH},0xf0, cseq_1280x1024x16,cgraph_svgacolor,ccrtc_1280x1024x16}, - {0x75,{MM_DIRECT,1280,1024,16,8,16,SEG_GRAPH},0xe1, + {0x75,0x11a,{MM_DIRECT,1280,1024,16,8,16,SEG_GRAPH},0xe1, cseq_1280x1024x16,cgraph_svgacolor,ccrtc_1280x1024x16},
- {0x7b,{MM_PACKED,1600,1200,8,8,16,SEG_GRAPH},0x00, + {0x7b,0xffff,{MM_PACKED,1600,1200,8,8,16,SEG_GRAPH},0x00, cseq_1600x1200x8,cgraph_svgacolor,ccrtc_1600x1200x8}, };
static struct cirrus_mode_s mode_switchback VAR16 = - {0xfe,{0xff},0,cseq_vga,cgraph_vga,ccrtc_vga}; - -static struct { - u16 vesamode, mode; -} cirrus_vesa_modelist[] VAR16 = { - // 640x480x8 - { 0x101, 0x5f }, - // 640x480x15 - { 0x110, 0x66 }, - // 640x480x16 - { 0x111, 0x64 }, - // 640x480x24 - { 0x112, 0x71 }, - // 800x600x8 - { 0x103, 0x5c }, - // 800x600x15 - { 0x113, 0x67 }, - // 800x600x16 - { 0x114, 0x65 }, - // 800x600x24 - { 0x115, 0x78 }, - // 1024x768x8 - { 0x105, 0x60 }, - // 1024x768x15 - { 0x116, 0x68 }, - // 1024x768x16 - { 0x117, 0x74 }, - // 1024x768x24 - { 0x118, 0x79 }, - // 1280x1024x8 - { 0x107, 0x6d }, - // 1280x1024x15 - { 0x119, 0x69 }, - // 1280x1024x16 - { 0x11a, 0x75 }, -}; - - -/**************************************************************** - * helper functions - ****************************************************************/ + {0xfe,0xffff,{0xff},0,cseq_vga,cgraph_vga,ccrtc_vga};
int is_cirrus_mode(struct vgamode_s *vmode_g) @@ -315,51 +275,37 @@ is_cirrus_mode(struct vgamode_s *vmode_g) && vmode_g <= &cirrus_modes[ARRAY_SIZE(cirrus_modes)-1].info); }
+struct vgamode_s * +clext_find_mode(int mode) +{ + struct cirrus_mode_s *table_g = cirrus_modes; + while (table_g < &cirrus_modes[ARRAY_SIZE(cirrus_modes)]) { + if (GET_GLOBAL(table_g->mode) == mode + || GET_GLOBAL(table_g->vesamode) == mode) + return &table_g->info; + table_g++; + } + return stdvga_find_mode(mode); +} + void clext_list_modes(u16 seg, u16 *dest, u16 *last) { int i; - for (i=0; i<ARRAY_SIZE(cirrus_vesa_modelist) && dest<last; i++) { - SET_FARVAR(seg, *dest, GET_GLOBAL(cirrus_vesa_modelist[i].vesamode)); + for (i=0; i<ARRAY_SIZE(cirrus_modes) && dest<last; i++) { + u16 mode = GET_GLOBAL(cirrus_modes[i].vesamode); + if (mode == 0xffff) + continue; + SET_FARVAR(seg, *dest, mode); dest++; } stdvga_list_modes(seg, dest, last); }
-static u16 -cirrus_vesamode_to_mode(u16 vesamode) -{ - int i; - for (i=0; i<ARRAY_SIZE(cirrus_vesa_modelist); i++) - if (GET_GLOBAL(cirrus_vesa_modelist[i].vesamode) == vesamode) - return GET_GLOBAL(cirrus_vesa_modelist[i].mode); - return 0; -} - -static struct cirrus_mode_s * -cirrus_get_modeentry(int mode) -{ - int transmode = cirrus_vesamode_to_mode(mode); - if (transmode) - mode = transmode; - struct cirrus_mode_s *table_g = cirrus_modes; - while (table_g < &cirrus_modes[ARRAY_SIZE(cirrus_modes)]) { - u16 tmode = GET_GLOBAL(table_g->mode); - if (tmode == mode) - return table_g; - table_g++; - } - return NULL; -}
-struct vgamode_s * -clext_find_mode(int mode) -{ - struct cirrus_mode_s *table_g = cirrus_get_modeentry(mode); - if (table_g) - return &table_g->info; - return stdvga_find_mode(mode); -} +/**************************************************************** + * helper functions + ****************************************************************/
static void cirrus_switch_mode_setregs(u16 *data, u16 port) @@ -575,7 +521,7 @@ ASM16( static void clext_1012a0(struct bregs *regs) { - struct cirrus_mode_s *table_g = cirrus_get_modeentry(regs->al & 0x7f); + struct vgamode_s *table_g = clext_find_mode(regs->al & 0x7f); regs->ah = (table_g ? 1 : 0); regs->si = 0xffff; regs->di = regs->ds = regs->es = regs->bx = (u32)a0h_callback; diff --git a/vgasrc/clext.h b/vgasrc/clext.h index 1e4506c..2c4ceef 100644 --- a/vgasrc/clext.h +++ b/vgasrc/clext.h @@ -4,6 +4,7 @@ #include "types.h" // u16
struct vgamode_s *clext_find_mode(int mode); +void clext_list_modes(u16 seg, u16 *dest, u16 *last); int clext_get_window(struct vgamode_s *vmode_g, int window); int clext_set_window(struct vgamode_s *vmode_g, int window, int val); int clext_get_linelength(struct vgamode_s *vmode_g); @@ -11,7 +12,6 @@ int clext_set_linelength(struct vgamode_s *vmode_g, int val); int clext_get_displaystart(struct vgamode_s *vmode_g); int clext_set_displaystart(struct vgamode_s *vmode_g, int val); int clext_set_mode(struct vgamode_s *vmode_g, int flags); -void clext_list_modes(u16 seg, u16 *dest, u16 *last); int clext_init(void); struct bregs; void clext_1012(struct bregs *regs);
Signed-off-by: Kevin O'Connor kevin@koconnor.net --- vgasrc/clext.c | 125 +++++++++++++++++++++++++++++--------------------------- vgasrc/clext.h | 2 +- 2 files changed, 66 insertions(+), 61 deletions(-)
diff --git a/vgasrc/clext.c b/vgasrc/clext.c index 7508b12..26b34e0 100644 --- a/vgasrc/clext.c +++ b/vgasrc/clext.c @@ -307,56 +307,6 @@ clext_list_modes(u16 seg, u16 *dest, u16 *last) * helper functions ****************************************************************/
-static void -cirrus_switch_mode_setregs(u16 *data, u16 port) -{ - for (;;) { - u16 val = GET_GLOBAL(*data); - if (val == 0xffff) - return; - outw(val, port); - data++; - } -} - -static void -cirrus_switch_mode(struct cirrus_mode_s *table) -{ - // Unlock cirrus special - stdvga_sequ_write(0x06, 0x12); - cirrus_switch_mode_setregs(GET_GLOBAL(table->seq), VGAREG_SEQU_ADDRESS); - cirrus_switch_mode_setregs(GET_GLOBAL(table->graph), VGAREG_GRDC_ADDRESS); - cirrus_switch_mode_setregs(GET_GLOBAL(table->crtc), stdvga_get_crtc()); - - stdvga_pelmask_write(0x00); - stdvga_pelmask_read(); - stdvga_pelmask_read(); - stdvga_pelmask_read(); - stdvga_pelmask_read(); - stdvga_pelmask_write(GET_GLOBAL(table->hidden_dac)); - stdvga_pelmask_write(0xff); - - u8 memmodel = GET_GLOBAL(table->info.memmodel); - u8 on = 0; - if (memmodel == MM_PLANAR) - on = 0x41; - else if (memmodel != MM_TEXT) - on = 0x01; - stdvga_attr_mask(0x10, 0x01, on); -} - -static u8 -cirrus_get_memsize(void) -{ - // get DRAM band width - u8 v = stdvga_sequ_read(0x0f); - u8 x = (v >> 3) & 0x03; - if (x == 0x03 && v & 0x80) - // 4MB - return 0x40; - return 0x04 << x; -} - int clext_get_window(struct vgamode_s *vmode_g, int window) { @@ -418,6 +368,49 @@ clext_set_displaystart(struct vgamode_s *vmode_g, int val) return 0; }
+ +/**************************************************************** + * Mode setting + ****************************************************************/ + +static void +cirrus_switch_mode_setregs(u16 *data, u16 port) +{ + for (;;) { + u16 val = GET_GLOBAL(*data); + if (val == 0xffff) + return; + outw(val, port); + data++; + } +} + +static void +cirrus_switch_mode(struct cirrus_mode_s *table) +{ + // Unlock cirrus special + stdvga_sequ_write(0x06, 0x12); + cirrus_switch_mode_setregs(GET_GLOBAL(table->seq), VGAREG_SEQU_ADDRESS); + cirrus_switch_mode_setregs(GET_GLOBAL(table->graph), VGAREG_GRDC_ADDRESS); + cirrus_switch_mode_setregs(GET_GLOBAL(table->crtc), stdvga_get_crtc()); + + stdvga_pelmask_write(0x00); + stdvga_pelmask_read(); + stdvga_pelmask_read(); + stdvga_pelmask_read(); + stdvga_pelmask_read(); + stdvga_pelmask_write(GET_GLOBAL(table->hidden_dac)); + stdvga_pelmask_write(0xff); + + u8 memmodel = GET_GLOBAL(table->info.memmodel); + u8 on = 0; + if (memmodel == MM_PLANAR) + on = 0x41; + else if (memmodel != MM_TEXT) + on = 0x01; + stdvga_attr_mask(0x10, 0x01, on); +} + static void cirrus_enable_16k_granularity(void) { @@ -425,14 +418,14 @@ cirrus_enable_16k_granularity(void) }
static void -cirrus_clear_vram(u16 param) +cirrus_clear_vram(void) { cirrus_enable_16k_granularity(); u8 count = GET_GLOBAL(VBE_total_memory) / (16 * 1024); u8 i; for (i=0; i<count; i++) { stdvga_grdc_write(0x09, i); - memset16_far(SEG_GRAPH, 0, param, 16 * 1024); + memset16_far(SEG_GRAPH, 0, 0, 16 * 1024); } stdvga_grdc_write(0x09, 0x00); } @@ -451,17 +444,10 @@ clext_set_mode(struct vgamode_s *vmode_g, int flags) if (!(flags & MF_LINEARFB)) cirrus_enable_16k_granularity(); if (!(flags & MF_NOCLEARMEM)) - cirrus_clear_vram(0); + cirrus_clear_vram(); return 0; }
-static int -cirrus_check(void) -{ - stdvga_sequ_write(0x06, 0x92); - return stdvga_sequ_read(0x06) == 0x12; -} -
/**************************************************************** * extbios @@ -573,6 +559,25 @@ clext_1012(struct bregs *regs) * init ****************************************************************/
+static int +cirrus_check(void) +{ + stdvga_sequ_write(0x06, 0x92); + return stdvga_sequ_read(0x06) == 0x12; +} + +static u8 +cirrus_get_memsize(void) +{ + // get DRAM band width + u8 v = stdvga_sequ_read(0x0f); + u8 x = (v >> 3) & 0x03; + if (x == 0x03 && v & 0x80) + // 4MB + return 0x40; + return 0x04 << x; +} + int clext_init(void) { diff --git a/vgasrc/clext.h b/vgasrc/clext.h index 2c4ceef..3d83507 100644 --- a/vgasrc/clext.h +++ b/vgasrc/clext.h @@ -12,8 +12,8 @@ int clext_set_linelength(struct vgamode_s *vmode_g, int val); int clext_get_displaystart(struct vgamode_s *vmode_g); int clext_set_displaystart(struct vgamode_s *vmode_g, int val); int clext_set_mode(struct vgamode_s *vmode_g, int flags); -int clext_init(void); struct bregs; void clext_1012(struct bregs *regs); +int clext_init(void);
#endif // clext.h
Check mode validity at init.
Signed-off-by: Kevin O'Connor kevin@koconnor.net --- vgasrc/bochsvga.c | 179 +++++++++++++++++++++++++---------------------------- vgasrc/bochsvga.h | 4 +- 2 files changed, 87 insertions(+), 96 deletions(-)
diff --git a/vgasrc/bochsvga.c b/vgasrc/bochsvga.c index 71f2cd4..e6ab794 100644 --- a/vgasrc/bochsvga.c +++ b/vgasrc/bochsvga.c @@ -16,6 +16,11 @@ #include "pci.h" // pci_config_readl #include "pci_regs.h" // PCI_BASE_ADDRESS_0
+ +/**************************************************************** + * Mode tables + ****************************************************************/ + static struct bochsvga_mode { u16 mode; @@ -92,100 +97,12 @@ static int is_bochsvga_mode(struct vgamode_s *vmode_g) && vmode_g <= &bochsvga_modes[ARRAY_SIZE(bochsvga_modes)-1].info); }
-static u16 dispi_get_max_xres(void) -{ - u16 en; - u16 xres; - - en = dispi_read(VBE_DISPI_INDEX_ENABLE); - - dispi_write(VBE_DISPI_INDEX_ENABLE, en | VBE_DISPI_GETCAPS); - xres = dispi_read(VBE_DISPI_INDEX_XRES); - dispi_write(VBE_DISPI_INDEX_ENABLE, en); - - return xres; -} - -static u16 dispi_get_max_bpp(void) -{ - u16 en; - u16 bpp; - - en = dispi_read(VBE_DISPI_INDEX_ENABLE); - - dispi_write(VBE_DISPI_INDEX_ENABLE, en | VBE_DISPI_GETCAPS); - bpp = dispi_read(VBE_DISPI_INDEX_BPP); - dispi_write(VBE_DISPI_INDEX_ENABLE, en); - - return bpp; -} - -/* Called only during POST */ -int -bochsvga_init(void) -{ - int ret = stdvga_init(); - if (ret) - return ret; - - /* Sanity checks */ - dispi_write(VBE_DISPI_INDEX_ID, VBE_DISPI_ID0); - if (dispi_read(VBE_DISPI_INDEX_ID) != VBE_DISPI_ID0) { - dprintf(1, "No VBE DISPI interface detected\n"); - return -1; - } - - dispi_write(VBE_DISPI_INDEX_ID, VBE_DISPI_ID5); - - u32 lfb_addr = VBE_DISPI_LFB_PHYSICAL_ADDRESS; - int bdf = GET_GLOBAL(VgaBDF); - if (CONFIG_VGA_PCI && bdf >= 0) { - int barid = 0; - u32 bar = pci_config_readl(bdf, PCI_BASE_ADDRESS_0); - if ((bar & PCI_BASE_ADDRESS_SPACE) != PCI_BASE_ADDRESS_SPACE_MEMORY) { - barid = 1; - bar = pci_config_readl(bdf, PCI_BASE_ADDRESS_1); - } - lfb_addr = bar & PCI_BASE_ADDRESS_MEM_MASK; - dprintf(1, "VBE DISPI: bdf %02x:%02x.%x, bar %d\n", pci_bdf_to_bus(bdf) - , pci_bdf_to_dev(bdf), pci_bdf_to_fn(bdf), barid); - } - - 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: lfb_addr=%x, size %d MB\n", - lfb_addr, totalmem / 16); - - return 0; -} - -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 = GET_GLOBAL(VBE_total_memory); - - u16 width = GET_GLOBAL(vmode_g->width); - u16 height = GET_GLOBAL(vmode_g->height); - u8 depth = GET_GLOBAL(vmode_g->depth); - u32 mem = (height * DIV_ROUND_UP(width * vga_bpp(vmode_g), 8) - * 4 / stdvga_bpp_factor(vmode_g)); - - 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 (! mode_valid(&m->info)) - return NULL; + if (GET_GLOBAL(m->mode) == mode) return &m->info; - } return stdvga_find_mode(mode); }
@@ -194,17 +111,20 @@ bochsvga_list_modes(u16 seg, u16 *dest, u16 *last) { struct bochsvga_mode *m = bochsvga_modes; for (; m < &bochsvga_modes[ARRAY_SIZE(bochsvga_modes)] && dest<last; m++) { - if (!mode_valid(&m->info)) + u16 mode = GET_GLOBAL(m->mode); + if (mode == 0xffff) continue; - - dprintf(1, "VBE found mode %x valid.\n", GET_GLOBAL(m->mode)); - SET_FARVAR(seg, *dest, GET_GLOBAL(m->mode)); + SET_FARVAR(seg, *dest, mode); dest++; } - stdvga_list_modes(seg, dest, last); }
+ +/**************************************************************** + * Helper functions + ****************************************************************/ + int bochsvga_get_window(struct vgamode_s *vmode_g, int window) { @@ -260,6 +180,11 @@ bochsvga_set_displaystart(struct vgamode_s *vmode_g, int val) return 0; }
+ +/**************************************************************** + * Mode setting + ****************************************************************/ + int bochsvga_set_mode(struct vgamode_s *vmode_g, int flags) { @@ -311,3 +236,69 @@ bochsvga_set_mode(struct vgamode_s *vmode_g, int flags)
return 0; } + + +/**************************************************************** + * Init + ****************************************************************/ + +int +bochsvga_init(void) +{ + int ret = stdvga_init(); + if (ret) + return ret; + + /* Sanity checks */ + dispi_write(VBE_DISPI_INDEX_ID, VBE_DISPI_ID0); + if (dispi_read(VBE_DISPI_INDEX_ID) != VBE_DISPI_ID0) { + dprintf(1, "No VBE DISPI interface detected\n"); + return -1; + } + + dispi_write(VBE_DISPI_INDEX_ID, VBE_DISPI_ID5); + + u32 lfb_addr = VBE_DISPI_LFB_PHYSICAL_ADDRESS; + int bdf = GET_GLOBAL(VgaBDF); + if (CONFIG_VGA_PCI && bdf >= 0) { + int barid = 0; + u32 bar = pci_config_readl(bdf, PCI_BASE_ADDRESS_0); + if ((bar & PCI_BASE_ADDRESS_SPACE) != PCI_BASE_ADDRESS_SPACE_MEMORY) { + barid = 1; + bar = pci_config_readl(bdf, PCI_BASE_ADDRESS_1); + } + lfb_addr = bar & PCI_BASE_ADDRESS_MEM_MASK; + dprintf(1, "VBE DISPI: bdf %02x:%02x.%x, bar %d\n", pci_bdf_to_bus(bdf) + , pci_bdf_to_dev(bdf), pci_bdf_to_fn(bdf), barid); + } + + SET_VGA(VBE_framebuffer, lfb_addr); + u32 totalmem = dispi_read(VBE_DISPI_INDEX_VIDEO_MEMORY_64K) * 64 * 1024; + SET_VGA(VBE_total_memory, totalmem); + SET_VGA(VBE_capabilities, VBE_CAPABILITY_8BIT_DAC); + + dprintf(1, "VBE DISPI: lfb_addr=%x, size %d MB\n", + lfb_addr, totalmem / 16); + + // Validate modes + u16 en = dispi_read(VBE_DISPI_INDEX_ENABLE); + dispi_write(VBE_DISPI_INDEX_ENABLE, en | VBE_DISPI_GETCAPS); + u16 max_xres = dispi_read(VBE_DISPI_INDEX_XRES); + u16 max_bpp = dispi_read(VBE_DISPI_INDEX_BPP); + dispi_write(VBE_DISPI_INDEX_ENABLE, en); + struct bochsvga_mode *m = bochsvga_modes; + for (; m < &bochsvga_modes[ARRAY_SIZE(bochsvga_modes)]; m++) { + u16 width = GET_GLOBAL(m->info.width); + u16 height = GET_GLOBAL(m->info.height); + u8 depth = GET_GLOBAL(m->info.depth); + u32 mem = (height * DIV_ROUND_UP(width * vga_bpp(&m->info), 8) + * 4 / stdvga_bpp_factor(&m->info)); + + if (width > max_xres || depth > max_bpp || mem > totalmem) { + dprintf(1, "Removing mode %x\n", GET_GLOBAL(m->mode)); + SET_VGA(m->mode, 0xffff); + } + } + + return 0; +} diff --git a/vgasrc/bochsvga.h b/vgasrc/bochsvga.h index d36c92a..57b2b69 100644 --- a/vgasrc/bochsvga.h +++ b/vgasrc/bochsvga.h @@ -52,9 +52,8 @@ static inline void dispi_write(u16 reg, u16 val) outw(val, VBE_DISPI_IOPORT_DATA); }
-int bochsvga_init(void); -void bochsvga_list_modes(u16 seg, u16 *dest, u16 *last); struct vgamode_s *bochsvga_find_mode(int mode); +void bochsvga_list_modes(u16 seg, u16 *dest, u16 *last); int bochsvga_get_window(struct vgamode_s *vmode_g, int window); int bochsvga_set_window(struct vgamode_s *vmode_g, int window, int val); int bochsvga_get_linelength(struct vgamode_s *vmode_g); @@ -62,5 +61,6 @@ int bochsvga_set_linelength(struct vgamode_s *vmode_g, int val); int bochsvga_get_displaystart(struct vgamode_s *vmode_g); int bochsvga_set_displaystart(struct vgamode_s *vmode_g, int val); int bochsvga_set_mode(struct vgamode_s *vmode_g, int flags); +int bochsvga_init(void);
#endif // bochsvga.h