xref: /linux/arch/x86/boot/compressed/mem.c (revision bb29b957eaaa15be33243550d9ee576c2d601669)
1 // SPDX-License-Identifier: GPL-2.0-only
2 
3 #include "error.h"
4 #include "misc.h"
5 
6 bool init_unaccepted_memory(void)
7 {
8 	guid_t guid = LINUX_EFI_UNACCEPTED_MEM_TABLE_GUID;
9 	struct efi_unaccepted_memory *table;
10 	unsigned long cfg_table_pa;
11 	unsigned int cfg_table_len;
12 	enum efi_type et;
13 	int ret;
14 
15 	et = efi_get_type(boot_params_ptr);
16 	if (et == EFI_TYPE_NONE)
17 		return false;
18 
19 	ret = efi_get_conf_table(boot_params_ptr, &cfg_table_pa, &cfg_table_len);
20 	if (ret) {
21 		warn("EFI config table not found.");
22 		return false;
23 	}
24 
25 	table = (void *)efi_find_vendor_table(boot_params_ptr, cfg_table_pa,
26 					      cfg_table_len, guid);
27 	if (!table)
28 		return false;
29 
30 	if (table->version != 1)
31 		error("Unknown version of unaccepted memory table\n");
32 
33 	/*
34 	 * In many cases unaccepted_table is already set by EFI stub, but it
35 	 * has to be initialized again to cover cases when the table is not
36 	 * allocated by EFI stub or EFI stub copied the kernel image with
37 	 * efi_relocate_kernel() before the variable is set.
38 	 *
39 	 * It must be initialized before the first usage of accept_memory().
40 	 */
41 	unaccepted_table = table;
42 
43 	return true;
44 }
45