mirror of
https://mirrors.bfsu.edu.cn/git/linux.git
synced 2024-11-15 08:14:15 +08:00
x86/compressed/acpi: Move EFI vendor table lookup to helper
Future patches for SEV-SNP-validated CPUID will also require early parsing of the EFI configuration. Incrementally move the related code into a set of helpers that can be re-used for that purpose. [ bp: Unbreak unnecessarily broken lines. ] Signed-off-by: Michael Roth <michael.roth@amd.com> Signed-off-by: Brijesh Singh <brijesh.singh@amd.com> Signed-off-by: Borislav Petkov <bp@suse.de> Link: https://lore.kernel.org/r/20220307213356.2797205-28-brijesh.singh@amd.com
This commit is contained in:
parent
61c14ceda8
commit
dee602dd5d
@ -20,48 +20,31 @@
|
||||
*/
|
||||
struct mem_vector immovable_mem[MAX_NUMNODES*2];
|
||||
|
||||
/*
|
||||
* Search EFI system tables for RSDP. If both ACPI_20_TABLE_GUID and
|
||||
* ACPI_TABLE_GUID are found, take the former, which has more features.
|
||||
*/
|
||||
static acpi_physical_address
|
||||
__efi_get_rsdp_addr(unsigned long config_tables, unsigned int nr_tables,
|
||||
bool efi_64)
|
||||
__efi_get_rsdp_addr(unsigned long cfg_tbl_pa, unsigned int cfg_tbl_len)
|
||||
{
|
||||
acpi_physical_address rsdp_addr = 0;
|
||||
|
||||
#ifdef CONFIG_EFI
|
||||
int i;
|
||||
unsigned long rsdp_addr;
|
||||
int ret;
|
||||
|
||||
/* Get EFI tables from systab. */
|
||||
for (i = 0; i < nr_tables; i++) {
|
||||
acpi_physical_address table;
|
||||
efi_guid_t guid;
|
||||
/*
|
||||
* Search EFI system tables for RSDP. Preferred is ACPI_20_TABLE_GUID to
|
||||
* ACPI_TABLE_GUID because it has more features.
|
||||
*/
|
||||
rsdp_addr = efi_find_vendor_table(boot_params, cfg_tbl_pa, cfg_tbl_len,
|
||||
ACPI_20_TABLE_GUID);
|
||||
if (rsdp_addr)
|
||||
return (acpi_physical_address)rsdp_addr;
|
||||
|
||||
if (efi_64) {
|
||||
efi_config_table_64_t *tbl = (efi_config_table_64_t *)config_tables + i;
|
||||
/* No ACPI_20_TABLE_GUID found, fallback to ACPI_TABLE_GUID. */
|
||||
rsdp_addr = efi_find_vendor_table(boot_params, cfg_tbl_pa, cfg_tbl_len,
|
||||
ACPI_TABLE_GUID);
|
||||
if (rsdp_addr)
|
||||
return (acpi_physical_address)rsdp_addr;
|
||||
|
||||
guid = tbl->guid;
|
||||
table = tbl->table;
|
||||
|
||||
if (!IS_ENABLED(CONFIG_X86_64) && table >> 32) {
|
||||
debug_putstr("Error getting RSDP address: EFI config table located above 4GB.\n");
|
||||
return 0;
|
||||
}
|
||||
} else {
|
||||
efi_config_table_32_t *tbl = (efi_config_table_32_t *)config_tables + i;
|
||||
|
||||
guid = tbl->guid;
|
||||
table = tbl->table;
|
||||
}
|
||||
|
||||
if (!(efi_guidcmp(guid, ACPI_TABLE_GUID)))
|
||||
rsdp_addr = table;
|
||||
else if (!(efi_guidcmp(guid, ACPI_20_TABLE_GUID)))
|
||||
return table;
|
||||
}
|
||||
debug_putstr("Error getting RSDP address.\n");
|
||||
#endif
|
||||
return rsdp_addr;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* EFI/kexec support is 64-bit only. */
|
||||
@ -109,7 +92,7 @@ static acpi_physical_address kexec_get_rsdp_addr(void)
|
||||
if (!systab)
|
||||
error("EFI system table not found in kexec boot_params.");
|
||||
|
||||
return __efi_get_rsdp_addr((unsigned long)esd->tables, systab->nr_tables, true);
|
||||
return __efi_get_rsdp_addr((unsigned long)esd->tables, systab->nr_tables);
|
||||
}
|
||||
#else
|
||||
static acpi_physical_address kexec_get_rsdp_addr(void) { return 0; }
|
||||
@ -123,15 +106,10 @@ static acpi_physical_address efi_get_rsdp_addr(void)
|
||||
unsigned long systab_pa;
|
||||
unsigned int nr_tables;
|
||||
enum efi_type et;
|
||||
bool efi_64;
|
||||
int ret;
|
||||
|
||||
et = efi_get_type(boot_params);
|
||||
if (et == EFI_TYPE_64)
|
||||
efi_64 = true;
|
||||
else if (et == EFI_TYPE_32)
|
||||
efi_64 = false;
|
||||
else
|
||||
if (et == EFI_TYPE_NONE)
|
||||
return 0;
|
||||
|
||||
systab_pa = efi_get_system_table(boot_params);
|
||||
@ -142,7 +120,7 @@ static acpi_physical_address efi_get_rsdp_addr(void)
|
||||
if (ret || !cfg_tbl_pa)
|
||||
error("EFI config table not found.");
|
||||
|
||||
return __efi_get_rsdp_addr(cfg_tbl_pa, cfg_tbl_len, efi_64);
|
||||
return __efi_get_rsdp_addr(cfg_tbl_pa, cfg_tbl_len);
|
||||
#else
|
||||
return 0;
|
||||
#endif
|
||||
|
@ -120,3 +120,73 @@ int efi_get_conf_table(struct boot_params *bp, unsigned long *cfg_tbl_pa,
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Get vendor table address/guid from EFI config table at the given index */
|
||||
static int get_vendor_table(void *cfg_tbl, unsigned int idx,
|
||||
unsigned long *vendor_tbl_pa,
|
||||
efi_guid_t *vendor_tbl_guid,
|
||||
enum efi_type et)
|
||||
{
|
||||
if (et == EFI_TYPE_64) {
|
||||
efi_config_table_64_t *tbl_entry = (efi_config_table_64_t *)cfg_tbl + idx;
|
||||
|
||||
if (!IS_ENABLED(CONFIG_X86_64) && tbl_entry->table >> 32) {
|
||||
debug_putstr("Error: EFI config table entry located above 4GB.\n");
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
*vendor_tbl_pa = tbl_entry->table;
|
||||
*vendor_tbl_guid = tbl_entry->guid;
|
||||
|
||||
} else if (et == EFI_TYPE_32) {
|
||||
efi_config_table_32_t *tbl_entry = (efi_config_table_32_t *)cfg_tbl + idx;
|
||||
|
||||
*vendor_tbl_pa = tbl_entry->table;
|
||||
*vendor_tbl_guid = tbl_entry->guid;
|
||||
} else {
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* efi_find_vendor_table - Given EFI config table, search it for the physical
|
||||
* address of the vendor table associated with GUID.
|
||||
*
|
||||
* @bp: pointer to boot_params
|
||||
* @cfg_tbl_pa: pointer to EFI configuration table
|
||||
* @cfg_tbl_len: number of entries in EFI configuration table
|
||||
* @guid: GUID of vendor table
|
||||
*
|
||||
* Return: vendor table address on success. On error, return 0.
|
||||
*/
|
||||
unsigned long efi_find_vendor_table(struct boot_params *bp,
|
||||
unsigned long cfg_tbl_pa,
|
||||
unsigned int cfg_tbl_len,
|
||||
efi_guid_t guid)
|
||||
{
|
||||
enum efi_type et;
|
||||
unsigned int i;
|
||||
|
||||
et = efi_get_type(bp);
|
||||
if (et == EFI_TYPE_NONE)
|
||||
return 0;
|
||||
|
||||
for (i = 0; i < cfg_tbl_len; i++) {
|
||||
unsigned long vendor_tbl_pa;
|
||||
efi_guid_t vendor_tbl_guid;
|
||||
int ret;
|
||||
|
||||
ret = get_vendor_table((void *)cfg_tbl_pa, i,
|
||||
&vendor_tbl_pa,
|
||||
&vendor_tbl_guid, et);
|
||||
if (ret)
|
||||
return 0;
|
||||
|
||||
if (!efi_guidcmp(guid, vendor_tbl_guid))
|
||||
return vendor_tbl_pa;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -23,6 +23,7 @@
|
||||
#include <linux/screen_info.h>
|
||||
#include <linux/elf.h>
|
||||
#include <linux/io.h>
|
||||
#include <linux/efi.h>
|
||||
#include <asm/page.h>
|
||||
#include <asm/boot.h>
|
||||
#include <asm/bootparam.h>
|
||||
@ -188,6 +189,10 @@ enum efi_type efi_get_type(struct boot_params *bp);
|
||||
unsigned long efi_get_system_table(struct boot_params *bp);
|
||||
int efi_get_conf_table(struct boot_params *bp, unsigned long *cfg_tbl_pa,
|
||||
unsigned int *cfg_tbl_len);
|
||||
unsigned long efi_find_vendor_table(struct boot_params *bp,
|
||||
unsigned long cfg_tbl_pa,
|
||||
unsigned int cfg_tbl_len,
|
||||
efi_guid_t guid);
|
||||
#else
|
||||
static inline enum efi_type efi_get_type(struct boot_params *bp)
|
||||
{
|
||||
@ -205,6 +210,14 @@ static inline int efi_get_conf_table(struct boot_params *bp,
|
||||
{
|
||||
return -ENOENT;
|
||||
}
|
||||
|
||||
static inline unsigned long efi_find_vendor_table(struct boot_params *bp,
|
||||
unsigned long cfg_tbl_pa,
|
||||
unsigned int cfg_tbl_len,
|
||||
efi_guid_t guid)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
#endif /* CONFIG_EFI */
|
||||
|
||||
#endif /* BOOT_COMPRESSED_MISC_H */
|
||||
|
Loading…
Reference in New Issue
Block a user