diff --git a/stand/efi/boot1/boot1.c b/stand/efi/boot1/boot1.c index 112ca5439522..61087dc08954 100644 --- a/stand/efi/boot1/boot1.c +++ b/stand/efi/boot1/boot1.c @@ -391,7 +391,7 @@ efi_main(EFI_HANDLE Ximage, EFI_SYSTEM_TABLE *Xsystab) EFI_STATUS status; EFI_CONSOLE_CONTROL_PROTOCOL *ConsoleControl = NULL; SIMPLE_TEXT_OUTPUT_INTERFACE *conout = NULL; - UINTN i, max_dim, best_mode, cols, rows, hsize, nhandles; + UINTN i, hsize, nhandles; CHAR16 *text; UINT16 boot_current; size_t sz; @@ -410,22 +410,11 @@ efi_main(EFI_HANDLE Ximage, EFI_SYSTEM_TABLE *Xsystab) (void)ConsoleControl->SetMode(ConsoleControl, EfiConsoleControlScreenText); /* - * Reset the console and find the best text mode. + * Reset the console enable the cursor. Later we'll choose a better + * console size through GOP/UGA. */ conout = ST->ConOut; conout->Reset(conout, TRUE); - 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); conout->EnableCursor(conout, TRUE); conout->ClearScreen(conout); diff --git a/stand/efi/loader/framebuffer.c b/stand/efi/loader/framebuffer.c index 37999ea1d372..7b3d46ca90e3 100644 --- a/stand/efi/loader/framebuffer.c +++ b/stand/efi/loader/framebuffer.c @@ -462,6 +462,72 @@ print_efifb(int mode, struct efi_fb *efifb, int verbose) } } +static int +gop_autoresize(EFI_GRAPHICS_OUTPUT *gop) +{ + struct efi_fb efifb; + EFI_GRAPHICS_OUTPUT_MODE_INFORMATION *info; + EFI_STATUS status; + UINTN infosz; + UINT32 best_mode, currdim, maxdim, mode; + + best_mode = maxdim = 0; + for (mode = 0; mode < gop->Mode->MaxMode; mode++) { + status = gop->QueryMode(gop, mode, &infosz, &info); + if (EFI_ERROR(status)) + continue; + efifb_from_gop(&efifb, gop->Mode, info); + currdim = info->HorizontalResolution * info->VerticalResolution; + /* XXX TODO: Allow tunable or something for max resolution */ + if (currdim > maxdim) { + maxdim = currdim; + best_mode = mode; + } + } + + status = gop->SetMode(gop, best_mode); + if (EFI_ERROR(status)) { + snprintf(command_errbuf, sizeof(command_errbuf), + "gop_autoresize: Unable to set mode to %u (error=%lu)", + mode, EFI_ERROR_CODE(status)); + return (CMD_ERROR); + } + return (CMD_OK); +} + +static int +uga_autoresize(EFI_UGA_DRAW_PROTOCOL *gop) +{ + + return (CMD_OK); +} + +COMMAND_SET(efi_autoresize, "efi-autoresizecons", "EFI Auto-resize Console", command_autoresize); + +static int +command_autoresize(int argc, char *argv[]) +{ + EFI_GRAPHICS_OUTPUT *gop; + EFI_UGA_DRAW_PROTOCOL *uga; + EFI_STATUS status; + u_int mode; + + gop = NULL; + uga = NULL; + status = BS->LocateProtocol(&gop_guid, NULL, (VOID **)&gop); + if (EFI_ERROR(status) == 0) + return (gop_autoresize(gop)); + + status = BS->LocateProtocol(&uga_guid, NULL, (VOID **)&uga); + if (EFI_ERROR(status) == 0) + return (uga_autoresize(uga)); + + snprintf(command_errbuf, sizeof(command_errbuf), + "%s: Neither Graphics Output Protocol nor Universal Graphics Adapter present", + argv[0]); + return (CMD_ERROR); +} + COMMAND_SET(gop, "gop", "graphics output protocol", command_gop); static int diff --git a/stand/lua/core.lua b/stand/lua/core.lua index d38822deab5f..b3d5308bf1cd 100644 --- a/stand/lua/core.lua +++ b/stand/lua/core.lua @@ -274,6 +274,12 @@ function core.isSingleUserBoot() return single_user ~= nil and single_user:lower() == "yes" end +function core.isUEFIBoot() + local efiver = loader.getenv("efi-version") + + return efiver ~= nil +end + function core.isZFSBoot() local c = loader.getenv("currdev") diff --git a/stand/lua/loader.lua b/stand/lua/loader.lua index b406ba4969e9..2486193af031 100644 --- a/stand/lua/loader.lua +++ b/stand/lua/loader.lua @@ -50,6 +50,9 @@ if result ~= nil then end config.load() +if core.isUEFIBoot() then + loader.perform("efi-autoresizecons") +end -- Our console may have been setup for a different color scheme before we get -- here, so make sure we set the default. if color.isEnabled() then