From 1c1692795a6502a226fa8da559af7d6a9b4313c0 Mon Sep 17 00:00:00 2001 From: Kyle Evans Date: Sat, 24 Mar 2018 01:53:43 +0000 Subject: [PATCH] efi loader: Choose a console mode instead if hw.vga.textmode is set Not all systems use efifb; pull hw.vga.textmode and choose a good console mode instead if it's set to something non-zero. This is basically a revival of the code that used to live in boot1, but instead rebased onto this different way of doing mode selection in loader.efi. Interestingly enough, the regression that was previously introduced where GOP would not reflect the console setting does not seem to exist when console mode selection is done here. I've not done any investigation as to why this is the case. Nevertheless, boot1.efi is still not the best place to do mode selection. --- stand/efi/loader/framebuffer.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/stand/efi/loader/framebuffer.c b/stand/efi/loader/framebuffer.c index 9f95f92a5682..1118345b2625 100644 --- a/stand/efi/loader/framebuffer.c +++ b/stand/efi/loader/framebuffer.c @@ -587,6 +587,29 @@ gop_autoresize(EFI_GRAPHICS_OUTPUT *gop) return (CMD_OK); } +static int +text_autoresize() +{ + SIMPLE_TEXT_OUTPUT_INTERFACE *conout; + EFI_STATUS status; + UINTN i, max_dim, best_mode, cols, rows; + + conout = ST->ConOut; + max_dim = best_mode = 0; + for (i = 0; i < conout->Mode->MaxMode; i++) { + status = conout->QueryMode(conout, i, &cols, &rows); + if (EFI_ERROR(status)) + continue; + if (cols * rows > max_dim) { + max_dim = cols * rows; + best_mode = i; + } + } + if (max_dim > 0) + conout->SetMode(conout, best_mode); + return (CMD_OK); +} + static int uga_autoresize(EFI_UGA_DRAW_PROTOCOL *gop) { @@ -601,9 +624,15 @@ command_autoresize(int argc, char *argv[]) { EFI_GRAPHICS_OUTPUT *gop; EFI_UGA_DRAW_PROTOCOL *uga; + char *textmode; EFI_STATUS status; u_int mode; + textmode = getenv("hw.vga.textmode"); + /* If it's set and non-zero, we'll select a console mode instead */ + if (textmode != NULL && strcmp(textmode, "0") != 0) + return (text_autoresize()); + gop = NULL; uga = NULL; status = BS->LocateProtocol(&gop_guid, NULL, (VOID **)&gop);