]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/boot/efi/graphics.c
Merge pull request #7198 from poettering/stdin-stdout
[thirdparty/systemd.git] / src / boot / efi / graphics.c
1 /* SPDX-License-Identifier: LGPL-2.1+ */
2 /*
3 * This program is free software; you can redistribute it and/or modify it
4 * under the terms of the GNU Lesser General Public License as published by
5 * the Free Software Foundation; either version 2.1 of the License, or
6 * (at your option) any later version.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * Lesser General Public License for more details.
12 *
13 * Copyright (C) 2012-2013 Kay Sievers <kay@vrfy.org>
14 * Copyright (C) 2012 Harald Hoyer <harald@redhat.com>
15 * Copyright (C) 2013 Intel Corporation
16 * Authored by Joonas Lahtinen <joonas.lahtinen@linux.intel.com>
17 */
18
19 #include <efi.h>
20 #include <efilib.h>
21
22 #include "graphics.h"
23 #include "util.h"
24
25 EFI_STATUS graphics_mode(BOOLEAN on) {
26 #define EFI_CONSOLE_CONTROL_PROTOCOL_GUID \
27 { 0xf42f7782, 0x12e, 0x4c12, { 0x99, 0x56, 0x49, 0xf9, 0x43, 0x4, 0xf7, 0x21 } };
28
29 struct _EFI_CONSOLE_CONTROL_PROTOCOL;
30
31 typedef enum {
32 EfiConsoleControlScreenText,
33 EfiConsoleControlScreenGraphics,
34 EfiConsoleControlScreenMaxValue,
35 } EFI_CONSOLE_CONTROL_SCREEN_MODE;
36
37 typedef EFI_STATUS (EFIAPI *EFI_CONSOLE_CONTROL_PROTOCOL_GET_MODE)(
38 struct _EFI_CONSOLE_CONTROL_PROTOCOL *This,
39 EFI_CONSOLE_CONTROL_SCREEN_MODE *Mode,
40 BOOLEAN *UgaExists,
41 BOOLEAN *StdInLocked
42 );
43
44 typedef EFI_STATUS (EFIAPI *EFI_CONSOLE_CONTROL_PROTOCOL_SET_MODE)(
45 struct _EFI_CONSOLE_CONTROL_PROTOCOL *This,
46 EFI_CONSOLE_CONTROL_SCREEN_MODE Mode
47 );
48
49 typedef EFI_STATUS (EFIAPI *EFI_CONSOLE_CONTROL_PROTOCOL_LOCK_STD_IN)(
50 struct _EFI_CONSOLE_CONTROL_PROTOCOL *This,
51 CHAR16 *Password
52 );
53
54 typedef struct _EFI_CONSOLE_CONTROL_PROTOCOL {
55 EFI_CONSOLE_CONTROL_PROTOCOL_GET_MODE GetMode;
56 EFI_CONSOLE_CONTROL_PROTOCOL_SET_MODE SetMode;
57 EFI_CONSOLE_CONTROL_PROTOCOL_LOCK_STD_IN LockStdIn;
58 } EFI_CONSOLE_CONTROL_PROTOCOL;
59
60 EFI_GUID ConsoleControlProtocolGuid = EFI_CONSOLE_CONTROL_PROTOCOL_GUID;
61 EFI_CONSOLE_CONTROL_PROTOCOL *ConsoleControl = NULL;
62 EFI_CONSOLE_CONTROL_SCREEN_MODE new;
63 EFI_CONSOLE_CONTROL_SCREEN_MODE current;
64 BOOLEAN uga_exists;
65 BOOLEAN stdin_locked;
66 EFI_STATUS err;
67
68 err = LibLocateProtocol(&ConsoleControlProtocolGuid, (VOID **)&ConsoleControl);
69 if (EFI_ERROR(err))
70 /* console control protocol is nonstandard and might not exist. */
71 return err == EFI_NOT_FOUND ? EFI_SUCCESS : err;
72
73 /* check current mode */
74 err = uefi_call_wrapper(ConsoleControl->GetMode, 4, ConsoleControl, &current, &uga_exists, &stdin_locked);
75 if (EFI_ERROR(err))
76 return err;
77
78 /* do not touch the mode */
79 new = on ? EfiConsoleControlScreenGraphics : EfiConsoleControlScreenText;
80 if (new == current)
81 return EFI_SUCCESS;
82
83 err = uefi_call_wrapper(ConsoleControl->SetMode, 2, ConsoleControl, new);
84
85 /* some firmware enables the cursor when switching modes */
86 uefi_call_wrapper(ST->ConOut->EnableCursor, 2, ST->ConOut, FALSE);
87
88 return err;
89 }