:: commit 3674ce3af978083214fc26950d58153de5f55a08

mintsuki <mintsuki@protonmail.com> — 2021-03-14 02:03

parents: d6cda61fb9

gop: Implement fallback resolutions like for VBE

diff --git a/stage23/drivers/gop.c b/stage23/drivers/gop.c
index 884e8a73..6a29d790 100644
--- a/stage23/drivers/gop.c
+++ b/stage23/drivers/gop.c
@@ -81,7 +81,9 @@ bool init_gop(struct fb_info *ret,
 
     UINTN modes_count = gop->Mode->MaxMode;
 
-    // Find our mode
+    size_t current_fallback = 0;
+
+retry:
     for (size_t i = 0; i < modes_count; i++) {
         status = uefi_call_wrapper(gop->QueryMode, 4,
             gop, i, &mode_info_size, &mode_info);
@@ -126,7 +128,6 @@ bool init_gop(struct fb_info *ret,
                 break;
             default:
                 panic("gop: Invalid PixelFormat");
-
         }
 
         if (mode_info->HorizontalResolution != target_width
@@ -142,15 +143,25 @@ bool init_gop(struct fb_info *ret,
             print("gop: Failed to set video mode %x, moving on...\n", i);
             continue;
         }
+
+        ret->memory_model = 0x06;
+        ret->framebuffer_addr = gop->Mode->FrameBufferBase;
+        ret->framebuffer_pitch = gop->Mode->Info->PixelsPerScanLine * 4;
+        ret->framebuffer_width = gop->Mode->Info->HorizontalResolution;
+        ret->framebuffer_height = gop->Mode->Info->VerticalResolution;
+
+        return true;
     }
 
-    ret->memory_model = 0x06;
-    ret->framebuffer_addr = gop->Mode->FrameBufferBase;
-    ret->framebuffer_pitch = gop->Mode->Info->PixelsPerScanLine * 4;
-    ret->framebuffer_width = gop->Mode->Info->HorizontalResolution;
-    ret->framebuffer_height = gop->Mode->Info->VerticalResolution;
+    if (current_fallback < SIZEOF_ARRAY(fallback_resolutions)) {
+        target_width  = fallback_resolutions[current_fallback].width;
+        target_height = fallback_resolutions[current_fallback].height;
+        target_bpp    = fallback_resolutions[current_fallback].bpp;
+        current_fallback++;
+        goto retry;
+    }
 
-    return true;
+    return false;
 }
 
 #endif
diff --git a/stage23/drivers/vbe.c b/stage23/drivers/vbe.c
index 44f11526..669e6511 100644
--- a/stage23/drivers/vbe.c
+++ b/stage23/drivers/vbe.c
@@ -115,18 +115,6 @@ static int set_vbe_mode(uint16_t mode) {
     return r.eax & 0xff;
 }
 
-struct resolution {
-    uint16_t width;
-    uint16_t height;
-    uint16_t bpp;
-};
-
-static struct resolution fallback_resolutions[] = {
-    { 1024, 768, 32 },
-    { 800,  600, 32 },
-    { 640,  480, 32 }
-};
-
 bool init_vbe(struct fb_info *ret,
               uint16_t target_width, uint16_t target_height, uint16_t target_bpp) {
     print("vbe: Initialising...\n");
diff --git a/stage23/lib/fb.h b/stage23/lib/fb.h
index e00cc51c..66641269 100644
--- a/stage23/lib/fb.h
+++ b/stage23/lib/fb.h
@@ -3,6 +3,19 @@
 
 #include <stdint.h>
 
+struct resolution {
+    uint16_t width;
+    uint16_t height;
+    uint16_t bpp;
+};
+
+__attribute__((unused))
+static struct resolution fallback_resolutions[] = {
+    { 1024, 768, 32 },
+    { 800,  600, 32 },
+    { 640,  480, 32 }
+};
+
 struct fb_info {
     uint8_t  memory_model;
     uint32_t framebuffer_addr;
tab: 248 wrap: offon