xref: /linux/drivers/firmware/efi/libstub/screen_info.c (revision 0526b56cbc3c489642bd6a5fe4b718dea7ef0ee8)
1 // SPDX-License-Identifier: GPL-2.0
2 
3 #include <linux/efi.h>
4 #include <asm/efi.h>
5 
6 #include "efistub.h"
7 
8 /*
9  * There are two ways of populating the core kernel's struct screen_info via the stub:
10  * - using a configuration table, like below, which relies on the EFI init code
11  *   to locate the table and copy the contents;
12  * - by linking directly to the core kernel's copy of the global symbol.
13  *
14  * The latter is preferred because it makes the EFIFB earlycon available very
15  * early, but it only works if the EFI stub is part of the core kernel image
16  * itself. The zboot decompressor can only use the configuration table
17  * approach.
18  */
19 
20 static efi_guid_t screen_info_guid = LINUX_EFI_SCREEN_INFO_TABLE_GUID;
21 
22 struct screen_info *__alloc_screen_info(void)
23 {
24 	struct screen_info *si;
25 	efi_status_t status;
26 
27 	status = efi_bs_call(allocate_pool, EFI_ACPI_RECLAIM_MEMORY,
28 			     sizeof(*si), (void **)&si);
29 
30 	if (status != EFI_SUCCESS)
31 		return NULL;
32 
33 	status = efi_bs_call(install_configuration_table,
34 			     &screen_info_guid, si);
35 	if (status == EFI_SUCCESS)
36 		return si;
37 
38 	efi_bs_call(free_pool, si);
39 	return NULL;
40 }
41 
42 void free_screen_info(struct screen_info *si)
43 {
44 	if (!si)
45 		return;
46 
47 	efi_bs_call(install_configuration_table, &screen_info_guid, NULL);
48 	efi_bs_call(free_pool, si);
49 }
50