Commit 06c0bd93 authored by Ard Biesheuvel's avatar Ard Biesheuvel

efi: Clean up config_parse_tables()

config_parse_tables() is a jumble of pointer arithmetic, due to the
fact that on x86, we may be dealing with firmware whose native word
size differs from the kernel's.

This is not a concern on other architectures, and doesn't quite
justify the state of the code, so let's clean it up by adding a
non-x86 code path, constifying statically allocated tables and
replacing preprocessor conditionals with IS_ENABLED() checks.

Tested-by: Tony Luck <tony.luck@intel.com> # arch/ia64
Signed-off-by: default avatarArd Biesheuvel <ardb@kernel.org>
parent 3a0701dc
...@@ -56,7 +56,7 @@ unsigned long __initdata esi_phys = EFI_INVALID_TABLE_ADDR; ...@@ -56,7 +56,7 @@ unsigned long __initdata esi_phys = EFI_INVALID_TABLE_ADDR;
unsigned long hcdp_phys = EFI_INVALID_TABLE_ADDR; unsigned long hcdp_phys = EFI_INVALID_TABLE_ADDR;
unsigned long sal_systab_phys = EFI_INVALID_TABLE_ADDR; unsigned long sal_systab_phys = EFI_INVALID_TABLE_ADDR;
static __initdata efi_config_table_type_t arch_tables[] = { static const efi_config_table_type_t arch_tables[] __initconst = {
{ESI_TABLE_GUID, "ESI", &esi_phys}, {ESI_TABLE_GUID, "ESI", &esi_phys},
{HCDP_TABLE_GUID, "HCDP", &hcdp_phys}, {HCDP_TABLE_GUID, "HCDP", &hcdp_phys},
{MPS_TABLE_GUID, "MPS", &mps_phys}, {MPS_TABLE_GUID, "MPS", &mps_phys},
...@@ -533,7 +533,6 @@ efi_init (void) ...@@ -533,7 +533,6 @@ efi_init (void)
if (efi_config_parse_tables(__va(efi_systab->tables), if (efi_config_parse_tables(__va(efi_systab->tables),
efi_systab->nr_tables, efi_systab->nr_tables,
sizeof(efi_config_table_t),
arch_tables) != 0) arch_tables) != 0)
return; return;
......
...@@ -60,7 +60,7 @@ static u64 efi_systab_phys __initdata; ...@@ -60,7 +60,7 @@ static u64 efi_systab_phys __initdata;
static unsigned long prop_phys = EFI_INVALID_TABLE_ADDR; static unsigned long prop_phys = EFI_INVALID_TABLE_ADDR;
static unsigned long uga_phys = EFI_INVALID_TABLE_ADDR; static unsigned long uga_phys = EFI_INVALID_TABLE_ADDR;
static efi_config_table_type_t arch_tables[] __initdata = { static const efi_config_table_type_t arch_tables[] __initconst = {
{EFI_PROPERTIES_TABLE_GUID, "PROP", &prop_phys}, {EFI_PROPERTIES_TABLE_GUID, "PROP", &prop_phys},
{UGA_IO_PROTOCOL_GUID, "UGA", &uga_phys}, {UGA_IO_PROTOCOL_GUID, "UGA", &uga_phys},
#ifdef CONFIG_X86_UV #ifdef CONFIG_X86_UV
...@@ -431,7 +431,7 @@ static int __init efi_systab_init(u64 phys) ...@@ -431,7 +431,7 @@ static int __init efi_systab_init(u64 phys)
return 0; return 0;
} }
static int __init efi_config_init(efi_config_table_type_t *arch_tables) static int __init efi_config_init(const efi_config_table_type_t *arch_tables)
{ {
void *config_tables; void *config_tables;
int sz, ret; int sz, ret;
...@@ -454,7 +454,7 @@ static int __init efi_config_init(efi_config_table_type_t *arch_tables) ...@@ -454,7 +454,7 @@ static int __init efi_config_init(efi_config_table_type_t *arch_tables)
return -ENOMEM; return -ENOMEM;
} }
ret = efi_config_parse_tables(config_tables, efi.systab->nr_tables, sz, ret = efi_config_parse_tables(config_tables, efi.systab->nr_tables,
arch_tables); arch_tables);
early_memunmap(config_tables, efi.systab->nr_tables * sz); early_memunmap(config_tables, efi.systab->nr_tables * sz);
......
...@@ -55,7 +55,7 @@ static phys_addr_t efi_to_phys(unsigned long addr) ...@@ -55,7 +55,7 @@ static phys_addr_t efi_to_phys(unsigned long addr)
static __initdata unsigned long screen_info_table = EFI_INVALID_TABLE_ADDR; static __initdata unsigned long screen_info_table = EFI_INVALID_TABLE_ADDR;
static __initdata efi_config_table_type_t arch_tables[] = { static const efi_config_table_type_t arch_tables[] __initconst = {
{LINUX_EFI_ARM_SCREEN_INFO_TABLE_GUID, NULL, &screen_info_table}, {LINUX_EFI_ARM_SCREEN_INFO_TABLE_GUID, NULL, &screen_info_table},
{NULL_GUID, NULL, NULL} {NULL_GUID, NULL, NULL}
}; };
...@@ -85,7 +85,7 @@ static void __init init_screen_info(void) ...@@ -85,7 +85,7 @@ static void __init init_screen_info(void)
static int __init uefi_init(void) static int __init uefi_init(void)
{ {
void *config_tables; efi_config_table_t *config_tables;
size_t table_size; size_t table_size;
int retval; int retval;
...@@ -118,7 +118,6 @@ static int __init uefi_init(void) ...@@ -118,7 +118,6 @@ static int __init uefi_init(void)
goto out; goto out;
} }
retval = efi_config_parse_tables(config_tables, efi.systab->nr_tables, retval = efi_config_parse_tables(config_tables, efi.systab->nr_tables,
sizeof(efi_config_table_t),
arch_tables); arch_tables);
if (!retval) if (!retval)
......
...@@ -460,7 +460,7 @@ void __init efi_mem_reserve(phys_addr_t addr, u64 size) ...@@ -460,7 +460,7 @@ void __init efi_mem_reserve(phys_addr_t addr, u64 size)
efi_arch_mem_reserve(addr, size); efi_arch_mem_reserve(addr, size);
} }
static __initdata efi_config_table_type_t common_tables[] = { static const efi_config_table_type_t common_tables[] __initconst = {
{ACPI_20_TABLE_GUID, "ACPI 2.0", &efi.acpi20}, {ACPI_20_TABLE_GUID, "ACPI 2.0", &efi.acpi20},
{ACPI_TABLE_GUID, "ACPI", &efi.acpi}, {ACPI_TABLE_GUID, "ACPI", &efi.acpi},
{SMBIOS_TABLE_GUID, "SMBIOS", &efi.smbios}, {SMBIOS_TABLE_GUID, "SMBIOS", &efi.smbios},
...@@ -477,9 +477,9 @@ static __initdata efi_config_table_type_t common_tables[] = { ...@@ -477,9 +477,9 @@ static __initdata efi_config_table_type_t common_tables[] = {
{NULL_GUID, NULL, NULL}, {NULL_GUID, NULL, NULL},
}; };
static __init int match_config_table(efi_guid_t *guid, static __init int match_config_table(const efi_guid_t *guid,
unsigned long table, unsigned long table,
efi_config_table_type_t *table_types) const efi_config_table_type_t *table_types)
{ {
int i; int i;
...@@ -498,39 +498,38 @@ static __init int match_config_table(efi_guid_t *guid, ...@@ -498,39 +498,38 @@ static __init int match_config_table(efi_guid_t *guid,
return 0; return 0;
} }
int __init efi_config_parse_tables(void *config_tables, int count, int sz, int __init efi_config_parse_tables(const efi_config_table_t *config_tables,
efi_config_table_type_t *arch_tables) int count,
const efi_config_table_type_t *arch_tables)
{ {
void *tablep; const efi_config_table_64_t *tbl64 = (void *)config_tables;
const efi_config_table_32_t *tbl32 = (void *)config_tables;
const efi_guid_t *guid;
unsigned long table;
int i; int i;
tablep = config_tables;
pr_info(""); pr_info("");
for (i = 0; i < count; i++) { for (i = 0; i < count; i++) {
efi_guid_t guid; if (!IS_ENABLED(CONFIG_X86)) {
unsigned long table; guid = &config_tables[i].guid;
table = (unsigned long)config_tables[i].table;
if (efi_enabled(EFI_64BIT)) { } else if (efi_enabled(EFI_64BIT)) {
u64 table64; guid = &tbl64[i].guid;
guid = ((efi_config_table_64_t *)tablep)->guid; table = tbl64[i].table;
table64 = ((efi_config_table_64_t *)tablep)->table;
table = table64; if (IS_ENABLED(CONFIG_X86_32) &&
#ifndef CONFIG_64BIT tbl64[i].table > U32_MAX) {
if (table64 >> 32) {
pr_cont("\n"); pr_cont("\n");
pr_err("Table located above 4GB, disabling EFI.\n"); pr_err("Table located above 4GB, disabling EFI.\n");
return -EINVAL; return -EINVAL;
} }
#endif
} else { } else {
guid = ((efi_config_table_32_t *)tablep)->guid; guid = &tbl32[i].guid;
table = ((efi_config_table_32_t *)tablep)->table; table = tbl32[i].table;
} }
if (!match_config_table(&guid, table, common_tables)) if (!match_config_table(guid, table, common_tables))
match_config_table(&guid, table, arch_tables); match_config_table(guid, table, arch_tables);
tablep += sz;
} }
pr_cont("\n"); pr_cont("\n");
set_bit(EFI_CONFIG_TABLES, &efi.flags); set_bit(EFI_CONFIG_TABLES, &efi.flags);
......
...@@ -613,8 +613,9 @@ extern void __init efi_esrt_init(void); ...@@ -613,8 +613,9 @@ extern void __init efi_esrt_init(void);
#else #else
static inline void efi_esrt_init(void) { } static inline void efi_esrt_init(void) { }
#endif #endif
extern int efi_config_parse_tables(void *config_tables, int count, int sz, extern int efi_config_parse_tables(const efi_config_table_t *config_tables,
efi_config_table_type_t *arch_tables); int count,
const efi_config_table_type_t *arch_tables);
extern int efi_systab_check_header(const efi_table_hdr_t *systab_hdr, extern int efi_systab_check_header(const efi_table_hdr_t *systab_hdr,
int min_major_version); int min_major_version);
extern void efi_systab_report_header(const efi_table_hdr_t *systab_hdr, extern void efi_systab_report_header(const efi_table_hdr_t *systab_hdr,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment