| 1 |
/* SPDX-License-Identifier: LGPL-2.1-or-later */ |
| 2 |
/* |
| 3 |
* Copyright © 2013 Intel Corporation |
| 4 |
* Authored by Joonas Lahtinen <[email protected]> |
| 5 |
*/ |
| 6 |
|
| 7 |
#include "efi-log.h" |
| 8 |
#include "graphics.h" |
| 9 |
#include "proto/console-control.h" |
| 10 |
#include "proto/simple-text-io.h" |
| 11 |
|
| 12 |
EFI_STATUS graphics_mode(bool on) { |
| 13 |
EFI_CONSOLE_CONTROL_PROTOCOL *ConsoleControl = NULL; |
| 14 |
EFI_CONSOLE_CONTROL_SCREEN_MODE new; |
| 15 |
EFI_CONSOLE_CONTROL_SCREEN_MODE current; |
| 16 |
bool uga_exists, stdin_locked; |
| 17 |
EFI_STATUS err; |
| 18 |
|
| 19 |
err = BS->LocateProtocol(MAKE_GUID_PTR(EFI_CONSOLE_CONTROL_PROTOCOL), NULL, (void **) &ConsoleControl); |
| 20 |
if (err != EFI_SUCCESS) |
| 21 |
/* console control protocol is nonstandard and might not exist. */ |
| 22 |
return err == EFI_NOT_FOUND ? EFI_SUCCESS : err; |
| 23 |
|
| 24 |
/* check current mode */ |
| 25 |
err = ConsoleControl->GetMode(ConsoleControl, ¤t, &uga_exists, &stdin_locked); |
| 26 |
if (err != EFI_SUCCESS) |
| 27 |
return err; |
| 28 |
|
| 29 |
/* do not touch the mode */ |
| 30 |
new = on ? EfiConsoleControlScreenGraphics : EfiConsoleControlScreenText; |
| 31 |
if (new == current) |
| 32 |
return EFI_SUCCESS; |
| 33 |
|
| 34 |
log_wait(); |
| 35 |
err = ConsoleControl->SetMode(ConsoleControl, new); |
| 36 |
|
| 37 |
/* some firmware enables the cursor when switching modes */ |
| 38 |
ST->ConOut->EnableCursor(ST->ConOut, false); |
| 39 |
|
| 40 |
return err; |
| 41 |
} |