Skip to content

Commit 14fb420

Browse files
committed
efi: Merge EFI system table revision and vendor checks
We have three different versions of the code that checks the EFI system table revision and copies the firmware vendor string, and they are mostly equivalent, with the exception of the use of early_memremap_ro vs. __va() and the lowest major revision to warn about. Let's move this into common code and factor out the commonalities. Tested-by: Tony Luck <tony.luck@intel.com> # arch/ia64 Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
1 parent b7846e6 commit 14fb420

5 files changed

Lines changed: 83 additions & 83 deletions

File tree

‎arch/ia64/kernel/efi.c‎

Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -479,10 +479,8 @@ void __init
479479
efi_init (void)
480480
{
481481
void *efi_map_start, *efi_map_end;
482-
efi_char16_t *c16;
483482
u64 efi_desc_size;
484-
char *cp, vendor[100] = "unknown";
485-
int i;
483+
char *cp;
486484

487485
set_bit(EFI_BOOT, &efi.flags);
488486
set_bit(EFI_64BIT, &efi.flags);
@@ -519,25 +517,10 @@ efi_init (void)
519517
*/
520518
if (efi.systab == NULL)
521519
panic("Whoa! Can't find EFI system table.\n");
522-
if (efi.systab->hdr.signature != EFI_SYSTEM_TABLE_SIGNATURE)
520+
if (efi_systab_check_header(&efi.systab->hdr, 1))
523521
panic("Whoa! EFI system table signature incorrect\n");
524-
if ((efi.systab->hdr.revision >> 16) == 0)
525-
printk(KERN_WARNING "Warning: EFI system table version "
526-
"%d.%02d, expected 1.00 or greater\n",
527-
efi.systab->hdr.revision >> 16,
528-
efi.systab->hdr.revision & 0xffff);
529-
530-
/* Show what we know for posterity */
531-
c16 = __va(efi.systab->fw_vendor);
532-
if (c16) {
533-
for (i = 0;i < (int) sizeof(vendor) - 1 && *c16; ++i)
534-
vendor[i] = *c16++;
535-
vendor[i] = '\0';
536-
}
537522

538-
printk(KERN_INFO "EFI v%u.%.02u by %s:",
539-
efi.systab->hdr.revision >> 16,
540-
efi.systab->hdr.revision & 0xffff, vendor);
523+
efi_systab_report_header(&efi.systab->hdr, efi.systab->fw_vendor);
541524

542525
palo_phys = EFI_INVALID_TABLE_ADDR;
543526

‎arch/x86/platform/efi/efi.c‎

Lines changed: 10 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -336,15 +336,23 @@ static int __init efi_systab_init(u64 phys)
336336
{
337337
int size = efi_enabled(EFI_64BIT) ? sizeof(efi_system_table_64_t)
338338
: sizeof(efi_system_table_32_t);
339+
const efi_table_hdr_t *hdr;
339340
bool over4g = false;
340341
void *p;
342+
int ret;
341343

342-
p = early_memremap_ro(phys, size);
344+
hdr = p = early_memremap_ro(phys, size);
343345
if (p == NULL) {
344346
pr_err("Couldn't map the system table!\n");
345347
return -ENOMEM;
346348
}
347349

350+
ret = efi_systab_check_header(hdr, 1);
351+
if (ret) {
352+
early_memunmap(p, size);
353+
return ret;
354+
}
355+
348356
if (efi_enabled(EFI_64BIT)) {
349357
const efi_system_table_64_t *systab64 = p;
350358

@@ -411,6 +419,7 @@ static int __init efi_systab_init(u64 phys)
411419
efi_systab.tables = systab32->tables;
412420
}
413421

422+
efi_systab_report_header(hdr, efi_systab.fw_vendor);
414423
early_memunmap(p, size);
415424

416425
if (IS_ENABLED(CONFIG_X86_32) && over4g) {
@@ -419,28 +428,11 @@ static int __init efi_systab_init(u64 phys)
419428
}
420429

421430
efi.systab = &efi_systab;
422-
423-
/*
424-
* Verify the EFI Table
425-
*/
426-
if (efi.systab->hdr.signature != EFI_SYSTEM_TABLE_SIGNATURE) {
427-
pr_err("System table signature incorrect!\n");
428-
return -EINVAL;
429-
}
430-
if ((efi.systab->hdr.revision >> 16) == 0)
431-
pr_err("Warning: System table version %d.%02d, expected 1.00 or greater!\n",
432-
efi.systab->hdr.revision >> 16,
433-
efi.systab->hdr.revision & 0xffff);
434-
435431
return 0;
436432
}
437433

438434
void __init efi_init(void)
439435
{
440-
efi_char16_t *c16;
441-
char vendor[100] = "unknown";
442-
int i = 0;
443-
444436
if (IS_ENABLED(CONFIG_X86_32) &&
445437
(boot_params.efi_info.efi_systab_hi ||
446438
boot_params.efi_info.efi_memmap_hi)) {
@@ -458,24 +450,6 @@ void __init efi_init(void)
458450
efi.fw_vendor = (unsigned long)efi.systab->fw_vendor;
459451
efi.runtime = (unsigned long)efi.systab->runtime;
460452

461-
/*
462-
* Show what we know for posterity
463-
*/
464-
c16 = early_memremap_ro(efi.systab->fw_vendor,
465-
sizeof(vendor) * sizeof(efi_char16_t));
466-
if (c16) {
467-
for (i = 0; i < sizeof(vendor) - 1 && c16[i]; ++i)
468-
vendor[i] = c16[i];
469-
vendor[i] = '\0';
470-
early_memunmap(c16, sizeof(vendor) * sizeof(efi_char16_t));
471-
} else {
472-
pr_err("Could not map the firmware vendor!\n");
473-
}
474-
475-
pr_info("EFI v%u.%.02u by %s\n",
476-
efi.systab->hdr.revision >> 16,
477-
efi.systab->hdr.revision & 0xffff, vendor);
478-
479453
if (efi_reuse_config(efi.systab->tables, efi.systab->nr_tables))
480454
return;
481455

‎drivers/firmware/efi/arm-init.c‎

Lines changed: 5 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -85,11 +85,9 @@ static void __init init_screen_info(void)
8585

8686
static int __init uefi_init(void)
8787
{
88-
efi_char16_t *c16;
8988
void *config_tables;
9089
size_t table_size;
91-
char vendor[100] = "unknown";
92-
int i, retval;
90+
int retval;
9391

9492
efi.systab = early_memremap_ro(efi_system_table,
9593
sizeof(efi_system_table_t));
@@ -102,34 +100,14 @@ static int __init uefi_init(void)
102100
if (IS_ENABLED(CONFIG_64BIT))
103101
set_bit(EFI_64BIT, &efi.flags);
104102

105-
/*
106-
* Verify the EFI Table
107-
*/
108-
if (efi.systab->hdr.signature != EFI_SYSTEM_TABLE_SIGNATURE) {
109-
pr_err("System table signature incorrect\n");
110-
retval = -EINVAL;
103+
retval = efi_systab_check_header(&efi.systab->hdr, 2);
104+
if (retval)
111105
goto out;
112-
}
113-
if ((efi.systab->hdr.revision >> 16) < 2)
114-
pr_warn("Warning: EFI system table version %d.%02d, expected 2.00 or greater\n",
115-
efi.systab->hdr.revision >> 16,
116-
efi.systab->hdr.revision & 0xffff);
117106

118107
efi.runtime_version = efi.systab->hdr.revision;
119108

120-
/* Show what we know for posterity */
121-
c16 = early_memremap_ro(efi_to_phys(efi.systab->fw_vendor),
122-
sizeof(vendor) * sizeof(efi_char16_t));
123-
if (c16) {
124-
for (i = 0; i < (int) sizeof(vendor) - 1 && *c16; ++i)
125-
vendor[i] = c16[i];
126-
vendor[i] = '\0';
127-
early_memunmap(c16, sizeof(vendor) * sizeof(efi_char16_t));
128-
}
129-
130-
pr_info("EFI v%u.%.02u by %s\n",
131-
efi.systab->hdr.revision >> 16,
132-
efi.systab->hdr.revision & 0xffff, vendor);
109+
efi_systab_report_header(&efi.systab->hdr,
110+
efi_to_phys(efi.systab->fw_vendor));
133111

134112
table_size = sizeof(efi_config_table_64_t) * efi.systab->nr_tables;
135113
config_tables = early_memremap_ro(efi_to_phys(efi.systab->tables),

‎drivers/firmware/efi/efi.c‎

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -631,6 +631,67 @@ int __init efi_config_init(efi_config_table_type_t *arch_tables)
631631
return ret;
632632
}
633633

634+
635+
int __init efi_systab_check_header(const efi_table_hdr_t *systab_hdr,
636+
int min_major_version)
637+
{
638+
if (systab_hdr->signature != EFI_SYSTEM_TABLE_SIGNATURE) {
639+
pr_err("System table signature incorrect!\n");
640+
return -EINVAL;
641+
}
642+
643+
if ((systab_hdr->revision >> 16) < min_major_version)
644+
pr_err("Warning: System table version %d.%02d, expected %d.00 or greater!\n",
645+
systab_hdr->revision >> 16,
646+
systab_hdr->revision & 0xffff,
647+
min_major_version);
648+
649+
return 0;
650+
}
651+
652+
#ifndef CONFIG_IA64
653+
static const efi_char16_t *__init map_fw_vendor(unsigned long fw_vendor,
654+
size_t size)
655+
{
656+
const efi_char16_t *ret;
657+
658+
ret = early_memremap_ro(fw_vendor, size);
659+
if (!ret)
660+
pr_err("Could not map the firmware vendor!\n");
661+
return ret;
662+
}
663+
664+
static void __init unmap_fw_vendor(const void *fw_vendor, size_t size)
665+
{
666+
early_memunmap((void *)fw_vendor, size);
667+
}
668+
#else
669+
#define map_fw_vendor(p, s) __va(p)
670+
#define unmap_fw_vendor(v, s)
671+
#endif
672+
673+
void __init efi_systab_report_header(const efi_table_hdr_t *systab_hdr,
674+
unsigned long fw_vendor)
675+
{
676+
char vendor[100] = "unknown";
677+
const efi_char16_t *c16;
678+
size_t i;
679+
680+
c16 = map_fw_vendor(fw_vendor, sizeof(vendor) * sizeof(efi_char16_t));
681+
if (c16) {
682+
for (i = 0; i < sizeof(vendor) - 1 && c16[i]; ++i)
683+
vendor[i] = c16[i];
684+
vendor[i] = '\0';
685+
686+
unmap_fw_vendor(c16, sizeof(vendor) * sizeof(efi_char16_t));
687+
}
688+
689+
pr_info("EFI v%u.%.02u by %s\n",
690+
systab_hdr->revision >> 16,
691+
systab_hdr->revision & 0xffff,
692+
vendor);
693+
}
694+
634695
#ifdef CONFIG_EFI_VARS_MODULE
635696
static int __init efi_load_efivars(void)
636697
{

‎include/linux/efi.h‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -616,6 +616,10 @@ static inline void efi_esrt_init(void) { }
616616
#endif
617617
extern int efi_config_parse_tables(void *config_tables, int count, int sz,
618618
efi_config_table_type_t *arch_tables);
619+
extern int efi_systab_check_header(const efi_table_hdr_t *systab_hdr,
620+
int min_major_version);
621+
extern void efi_systab_report_header(const efi_table_hdr_t *systab_hdr,
622+
unsigned long fw_vendor);
619623
extern u64 efi_get_iobase (void);
620624
extern int efi_mem_type(unsigned long phys_addr);
621625
extern u64 efi_mem_attributes (unsigned long phys_addr);

0 commit comments

Comments
 (0)