1 /* SPDX-License-Identifier: LGPL-2.1+ */
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.
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.
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>
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 } };
29 struct _EFI_CONSOLE_CONTROL_PROTOCOL
;
32 EfiConsoleControlScreenText
,
33 EfiConsoleControlScreenGraphics
,
34 EfiConsoleControlScreenMaxValue
,
35 } EFI_CONSOLE_CONTROL_SCREEN_MODE
;
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
,
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
49 typedef EFI_STATUS (EFIAPI
*EFI_CONSOLE_CONTROL_PROTOCOL_LOCK_STD_IN
)(
50 struct _EFI_CONSOLE_CONTROL_PROTOCOL
*This
,
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
;
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
;
68 err
= LibLocateProtocol(&ConsoleControlProtocolGuid
, (VOID
**)&ConsoleControl
);
70 /* console control protocol is nonstandard and might not exist. */
71 return err
== EFI_NOT_FOUND
? EFI_SUCCESS
: err
;
73 /* check current mode */
74 err
= uefi_call_wrapper(ConsoleControl
->GetMode
, 4, ConsoleControl
, ¤t
, &uga_exists
, &stdin_locked
);
78 /* do not touch the mode */
79 new = on
? EfiConsoleControlScreenGraphics
: EfiConsoleControlScreenText
;
83 err
= uefi_call_wrapper(ConsoleControl
->SetMode
, 2, ConsoleControl
, new);
85 /* some firmware enables the cursor when switching modes */
86 uefi_call_wrapper(ST
->ConOut
->EnableCursor
, 2, ST
->ConOut
, FALSE
);