1 /* SPDX-License-Identifier: LGPL-2.1-or-later */
2 /*
3  * Copyright © 2013 Intel Corporation
4  *   Authored by Joonas Lahtinen <joonas.lahtinen@linux.intel.com>
5  */
6 
7 #include <efi.h>
8 #include <efilib.h>
9 
10 #include "graphics.h"
11 #include "missing_efi.h"
12 #include "util.h"
13 
graphics_mode(BOOLEAN on)14 EFI_STATUS graphics_mode(BOOLEAN on) {
15         EFI_CONSOLE_CONTROL_PROTOCOL *ConsoleControl = NULL;
16         EFI_CONSOLE_CONTROL_SCREEN_MODE new;
17         EFI_CONSOLE_CONTROL_SCREEN_MODE current;
18         BOOLEAN uga_exists;
19         BOOLEAN stdin_locked;
20         EFI_STATUS err;
21 
22         err = LibLocateProtocol((EFI_GUID*) EFI_CONSOLE_CONTROL_GUID, (void **)&ConsoleControl);
23         if (EFI_ERROR(err))
24                 /* console control protocol is nonstandard and might not exist. */
25                 return err == EFI_NOT_FOUND ? EFI_SUCCESS : err;
26 
27         /* check current mode */
28         err =ConsoleControl->GetMode(ConsoleControl, &current, &uga_exists, &stdin_locked);
29         if (EFI_ERROR(err))
30                 return err;
31 
32         /* do not touch the mode */
33         new  = on ? EfiConsoleControlScreenGraphics : EfiConsoleControlScreenText;
34         if (new == current)
35                 return EFI_SUCCESS;
36 
37         err =ConsoleControl->SetMode(ConsoleControl, new);
38 
39         /* some firmware enables the cursor when switching modes */
40         ST->ConOut->EnableCursor(ST->ConOut, FALSE);
41 
42         return err;
43 }
44