vgabios: Use vesa style memory model flags in stdvga code.
[seabios.git] / vgasrc / bochsvga.c
index 3b5c71148c9e50ac627613c02966fd3df8c2ab0d..70ac449e16706200c6a4ff658c6c2faba4ea2a80 100644 (file)
@@ -1,7 +1,7 @@
 #include "vgabios.h" // struct vbe_modeinfo
-#include "vbe.h"
-#include "bochsvga.h"
-#include "util.h"
+#include "vbe.h" // VBE_MODE_VESA_DEFINED
+#include "bochsvga.h" // bochsvga_set_mode
+#include "util.h" // dprintf
 #include "config.h" // CONFIG_*
 #include "biosvar.h" // SET_BDA
 #include "stdvga.h" // VGAREG_SEQU_ADDRESS
@@ -83,11 +83,10 @@ static struct mode
 
 u32 pci_lfb_addr VAR16;
 
-static inline u32 pci_config_readl(u8 bus, u8 devfn, u16 addr)
+static inline u32 pci_config_readl(u16 bdf, u16 addr)
 {
     int status;
     u32 val;
-    u16 bdf = (bus << 16) | devfn;
 
     addr &= ~3;
 
@@ -136,12 +135,11 @@ static u16 dispi_get_max_bpp(void)
 
 /* Called only during POST */
 int
-bochsvga_init(u8 bus, u8 devfn)
+bochsvga_init(void)
 {
-    u32 lfb_addr;
-
-    if (!CONFIG_VGA_BOCHS)
-        return -1;
+    int ret = stdvga_init();
+    if (ret)
+        return ret;
 
     /* Sanity checks */
     dispi_write(VBE_DISPI_INDEX_ID, VBE_DISPI_ID0);
@@ -153,8 +151,9 @@ bochsvga_init(u8 bus, u8 devfn)
     SET_BDA(vbe_flag, 0x1);
     dispi_write(VBE_DISPI_INDEX_ID, VBE_DISPI_ID5);
 
+    u32 lfb_addr;
     if (CONFIG_VGA_PCI)
-        lfb_addr = pci_config_readl(bus, devfn, 0x10) & ~0xf;
+        lfb_addr = pci_config_readl(GET_GLOBAL(VgaBDF), 0x10) & ~0xf;
     else
         lfb_addr = VBE_DISPI_LFB_PHYSICAL_ADDRESS;
 
@@ -259,11 +258,26 @@ bochsvga_hires_enable(int enable)
     dispi_write(VBE_DISPI_INDEX_ENABLE, flags);
 }
 
-void
-bochsvga_set_mode(u16 mode, struct vbe_modeinfo *info)
+int
+bochsvga_set_mode(int mode, int flags)
 {
+    if (!(mode & VBE_MODE_VESA_DEFINED)) {
+        dprintf(1, "set VGA mode %x\n", mode);
+
+        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) {
+        dprintf(1, "VBE mode %x not found\n", mode);
+        return VBE_RETURN_STATUS_FAILED;
+    }
+    bochsvga_hires_enable(1);
+
     if (info->depth == 4)
-        vga_set_mode(0x6a, 0);
+        stdvga_set_mode(0x6a, 0);
     if (info->depth == 8)
         // XXX load_dac_palette(3);
         ;
@@ -315,6 +329,16 @@ bochsvga_set_mode(u16 mode, struct vbe_modeinfo *info)
     }
 
     SET_BDA(vbe_mode, mode);
+
+    if (flags & MF_LINEARFB) {
+        /* Linear frame buffer */
+        /* XXX: ??? */
+    }
+    if (!(mode & MF_NOCLEARMEM)) {
+        bochsvga_clear_scr();
+    }
+
+    return 0;
 }
 
 void