[systemd-devel] [PATCH v2 5/8] make console_text_mode into more generic function

Joonas Lahtinen joonas.lahtinen at linux.intel.com
Tue Dec 10 01:23:29 PST 2013


Convert console_text_mode function into console_mode function
which is able to switch back and forth between graphics and text
mode.

Signed-off-by: Joonas Lahtinen <joonas.lahtinen at linux.intel.com>
Reviewed-by: Darren Hart <dvhart at linux.intel.com>
Reviewed-by: Mikko Ylinen <mikko.ylinen at intel.com>
---
 src/efi/gummiboot.c | 32 +++++++++++++++++++++++++++++---
 1 file changed, 29 insertions(+), 3 deletions(-)

diff --git a/src/efi/gummiboot.c b/src/efi/gummiboot.c
index 062865d..6c66f63 100644
--- a/src/efi/gummiboot.c
+++ b/src/efi/gummiboot.c
@@ -54,6 +54,11 @@ enum loader_type {
         LOADER_LINUX
 };
 
+enum console_mode {
+        CONSOLE_TEXT,
+        CONSOLE_GRAPHICS,
+};
+
 typedef struct {
         CHAR16 *file;
         CHAR16 *title_show;
@@ -736,7 +741,7 @@ static VOID print_status(Config *config, CHAR16 *loaded_image_path) {
         uefi_call_wrapper(ST->ConOut->ClearScreen, 1, ST->ConOut);
 }
 
-static EFI_STATUS console_text_mode(VOID) {
+static EFI_STATUS console_mode(enum console_mode request) {
         #define EFI_CONSOLE_CONTROL_PROTOCOL_GUID \
                 { 0xf42f7782, 0x12e, 0x4c12, { 0x99, 0x56, 0x49, 0xf9, 0x43, 0x4, 0xf7, 0x21 } };
 
@@ -773,12 +778,33 @@ static EFI_STATUS console_text_mode(VOID) {
 
         EFI_GUID ConsoleControlProtocolGuid = EFI_CONSOLE_CONTROL_PROTOCOL_GUID;
         EFI_CONSOLE_CONTROL_PROTOCOL *ConsoleControl = NULL;
+        EFI_CONSOLE_CONTROL_SCREEN_MODE new;
+        EFI_CONSOLE_CONTROL_SCREEN_MODE current;
+        BOOLEAN uga_exists;
+        BOOLEAN stdin_locked;
         EFI_STATUS err;
 
         err = LibLocateProtocol(&ConsoleControlProtocolGuid, (VOID **)&ConsoleControl);
         if (EFI_ERROR(err))
                 return err;
-        return uefi_call_wrapper(ConsoleControl->SetMode, 2, ConsoleControl, EfiConsoleControlScreenText);
+
+        /* be extra cautious about not causing mode switch */
+        err = uefi_call_wrapper(ConsoleControl->GetMode, 4, ConsoleControl, &current, &uga_exists, &stdin_locked);
+        if (err == EFI_SUCCESS) {
+                switch (request) {
+                        case CONSOLE_GRAPHICS:
+                                new = EfiConsoleControlScreenGraphics;
+                                break;
+                        case CONSOLE_TEXT:
+                                new = EfiConsoleControlScreenText;
+                                break;
+                }
+
+                if (new == current)
+                        return EFI_SUCCESS;
+        }
+
+        return uefi_call_wrapper(ConsoleControl->SetMode, 2, ConsoleControl, new);
 }
 
 static BOOLEAN menu_run(Config *config, ConfigEntry **chosen_entry, CHAR16 *loaded_image_path) {
@@ -805,7 +831,7 @@ static BOOLEAN menu_run(Config *config, ConfigEntry **chosen_entry, CHAR16 *load
         BOOLEAN run = TRUE;
         BOOLEAN wait = FALSE;
 
-        console_text_mode();
+        console_mode(CONSOLE_TEXT);
         uefi_call_wrapper(ST->ConIn->Reset, 2, ST->ConIn, FALSE);
         uefi_call_wrapper(ST->ConOut->EnableCursor, 2, ST->ConOut, FALSE);
         uefi_call_wrapper(ST->ConOut->SetAttribute, 2, ST->ConOut, EFI_LIGHTGRAY|EFI_BACKGROUND_BLACK);
-- 
1.8.1.4



More information about the systemd-devel mailing list