1 // SPDX-License-Identifier: GPL-2.0-only
7 #include <asm/shared/tdx.h>
10 * accept_memory() and process_unaccepted_memory() called from EFI stub which
11 * runs before decompressor and its early_tdx_detect().
13 * Enumerate TDX directly from the early users.
15 static bool early_is_tdx_guest(void)
20 if (!IS_ENABLED(CONFIG_INTEL_TDX_GUEST))
26 cpuid_count(TDX_CPUID_LEAF_ID, 0, &eax,
27 &sig[0], &sig[2], &sig[1]);
28 is_tdx = !memcmp(TDX_IDENT, sig, sizeof(sig));
35 void arch_accept_memory(phys_addr_t start, phys_addr_t end)
37 /* Platform-specific memory-acceptance call goes here */
38 if (early_is_tdx_guest()) {
39 if (!tdx_accept_memory(start, end))
40 panic("TDX: Failed to accept memory\n");
41 } else if (sev_snp_enabled()) {
42 snp_accept_memory(start, end);
44 error("Cannot accept memory: unknown platform\n");
48 bool init_unaccepted_memory(void)
50 guid_t guid = LINUX_EFI_UNACCEPTED_MEM_TABLE_GUID;
51 struct efi_unaccepted_memory *table;
52 unsigned long cfg_table_pa;
53 unsigned int cfg_table_len;
57 et = efi_get_type(boot_params_ptr);
58 if (et == EFI_TYPE_NONE)
61 ret = efi_get_conf_table(boot_params_ptr, &cfg_table_pa, &cfg_table_len);
63 warn("EFI config table not found.");
67 table = (void *)efi_find_vendor_table(boot_params_ptr, cfg_table_pa,
72 if (table->version != 1)
73 error("Unknown version of unaccepted memory table\n");
76 * In many cases unaccepted_table is already set by EFI stub, but it
77 * has to be initialized again to cover cases when the table is not
78 * allocated by EFI stub or EFI stub copied the kernel image with
79 * efi_relocate_kernel() before the variable is set.
81 * It must be initialized before the first usage of accept_memory().
83 unaccepted_table = table;