Skip to content

Commit 76f09aa

Browse files
committed
Merge branch 'x86-efi-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip
Pull EFI changes from Ingo Molnar: "Main changes in this cycle are: - arm64 efi stub fixes, preservation of FP/SIMD registers across firmware calls, and conversion of the EFI stub code into a static library - Ard Biesheuvel - Xen EFI support - Daniel Kiper - Support for autoloading the efivars driver - Lee, Chun-Yi - Use the PE/COFF headers in the x86 EFI boot stub to request that the stub be loaded with CONFIG_PHYSICAL_ALIGN alignment - Michael Brown - Consolidate all the x86 EFI quirks into one file - Saurabh Tangri - Additional error logging in x86 EFI boot stub - Ulf Winkelvos - Support loading initrd above 4G in EFI boot stub - Yinghai Lu - EFI reboot patches for ACPI hardware reduced platforms" * 'x86-efi-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip: (31 commits) efi/arm64: Handle missing virtual mapping for UEFI System Table arch/x86/xen: Silence compiler warnings xen: Silence compiler warnings x86/efi: Request desired alignment via the PE/COFF headers x86/efi: Add better error logging to EFI boot stub efi: Autoload efivars efi: Update stale locking comment for struct efivars arch/x86: Remove efi_set_rtc_mmss() arch/x86: Replace plain strings with constants xen: Put EFI machinery in place xen: Define EFI related stuff arch/x86: Remove redundant set_bit(EFI_MEMMAP) call arch/x86: Remove redundant set_bit(EFI_SYSTEM_TABLES) call efi: Introduce EFI_PARAVIRT flag arch/x86: Do not access EFI memory map if it is not available efi: Use early_mem*() instead of early_io*() arch/ia64: Define early_memunmap() x86/reboot: Add EFI reboot quirk for ACPI Hardware Reduced flag efi/reboot: Allow powering off machines using EFI efi/reboot: Add generic wrapper around EfiResetSystem() ...
2 parents e9c9eec + 99a5603 commit 76f09aa

40 files changed

Lines changed: 1508 additions & 622 deletions

File tree

‎arch/arm64/Kconfig‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -347,12 +347,18 @@ config CMDLINE_FORCE
347347
This is useful if you cannot or don't want to change the
348348
command-line options your boot loader passes to the kernel.
349349

350+
config EFI_STUB
351+
bool
352+
350353
config EFI
351354
bool "UEFI runtime support"
352355
depends on OF && !CPU_BIG_ENDIAN
353356
select LIBFDT
354357
select UCS2_STRING
355358
select EFI_PARAMS_FROM_FDT
359+
select EFI_RUNTIME_WRAPPERS
360+
select EFI_STUB
361+
select EFI_ARMSTUB
356362
default y
357363
help
358364
This option provides support for runtime services provided

‎arch/arm64/Makefile‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ core-$(CONFIG_XEN) += arch/arm64/xen/
5252
core-$(CONFIG_CRYPTO) += arch/arm64/crypto/
5353
libs-y := arch/arm64/lib/ $(libs-y)
5454
libs-y += $(LIBGCC)
55+
libs-$(CONFIG_EFI_STUB) += drivers/firmware/efi/libstub/
5556

5657
# Default target when executing plain make
5758
KBUILD_IMAGE := Image.gz

‎arch/arm64/include/asm/efi.h‎

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#define _ASM_EFI_H
33

44
#include <asm/io.h>
5+
#include <asm/neon.h>
56

67
#ifdef CONFIG_EFI
78
extern void efi_init(void);
@@ -11,4 +12,36 @@ extern void efi_idmap_init(void);
1112
#define efi_idmap_init()
1213
#endif
1314

15+
#define efi_call_virt(f, ...) \
16+
({ \
17+
efi_##f##_t *__f = efi.systab->runtime->f; \
18+
efi_status_t __s; \
19+
\
20+
kernel_neon_begin(); \
21+
__s = __f(__VA_ARGS__); \
22+
kernel_neon_end(); \
23+
__s; \
24+
})
25+
26+
#define __efi_call_virt(f, ...) \
27+
({ \
28+
efi_##f##_t *__f = efi.systab->runtime->f; \
29+
\
30+
kernel_neon_begin(); \
31+
__f(__VA_ARGS__); \
32+
kernel_neon_end(); \
33+
})
34+
35+
/* arch specific definitions used by the stub code */
36+
37+
/*
38+
* AArch64 requires the DTB to be 8-byte aligned in the first 512MiB from
39+
* start of kernel and may not cross a 2MiB boundary. We set alignment to
40+
* 2MiB so we know it won't cross a 2MiB boundary.
41+
*/
42+
#define EFI_FDT_ALIGN SZ_2M /* used by allocate_new_fdt_and_exit_boot() */
43+
#define MAX_FDT_OFFSET SZ_512M
44+
45+
#define efi_call_early(f, ...) sys_table_arg->boottime->f(__VA_ARGS__)
46+
1447
#endif /* _ASM_EFI_H */

‎arch/arm64/kernel/Makefile‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@
44

55
CPPFLAGS_vmlinux.lds := -DTEXT_OFFSET=$(TEXT_OFFSET)
66
AFLAGS_head.o := -DTEXT_OFFSET=$(TEXT_OFFSET)
7-
CFLAGS_efi-stub.o := -DTEXT_OFFSET=$(TEXT_OFFSET) \
8-
-I$(src)/../../../scripts/dtc/libfdt
7+
CFLAGS_efi-stub.o := -DTEXT_OFFSET=$(TEXT_OFFSET)
98

109
CFLAGS_REMOVE_ftrace.o = -pg
1110
CFLAGS_REMOVE_insn.o = -pg

‎arch/arm64/kernel/efi-stub.c‎

Lines changed: 9 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -10,46 +10,16 @@
1010
*
1111
*/
1212
#include <linux/efi.h>
13-
#include <linux/libfdt.h>
13+
#include <asm/efi.h>
1414
#include <asm/sections.h>
1515

16-
/*
17-
* AArch64 requires the DTB to be 8-byte aligned in the first 512MiB from
18-
* start of kernel and may not cross a 2MiB boundary. We set alignment to
19-
* 2MiB so we know it won't cross a 2MiB boundary.
20-
*/
21-
#define EFI_FDT_ALIGN SZ_2M /* used by allocate_new_fdt_and_exit_boot() */
22-
#define MAX_FDT_OFFSET SZ_512M
23-
24-
#define efi_call_early(f, ...) sys_table_arg->boottime->f(__VA_ARGS__)
25-
26-
static void efi_char16_printk(efi_system_table_t *sys_table_arg,
27-
efi_char16_t *str);
28-
29-
static efi_status_t efi_open_volume(efi_system_table_t *sys_table,
30-
void *__image, void **__fh);
31-
static efi_status_t efi_file_close(void *handle);
32-
33-
static efi_status_t
34-
efi_file_read(void *handle, unsigned long *size, void *addr);
35-
36-
static efi_status_t
37-
efi_file_size(efi_system_table_t *sys_table, void *__fh,
38-
efi_char16_t *filename_16, void **handle, u64 *file_sz);
39-
40-
/* Include shared EFI stub code */
41-
#include "../../../drivers/firmware/efi/efi-stub-helper.c"
42-
#include "../../../drivers/firmware/efi/fdt.c"
43-
#include "../../../drivers/firmware/efi/arm-stub.c"
44-
45-
46-
static efi_status_t handle_kernel_image(efi_system_table_t *sys_table,
47-
unsigned long *image_addr,
48-
unsigned long *image_size,
49-
unsigned long *reserve_addr,
50-
unsigned long *reserve_size,
51-
unsigned long dram_base,
52-
efi_loaded_image_t *image)
16+
efi_status_t handle_kernel_image(efi_system_table_t *sys_table,
17+
unsigned long *image_addr,
18+
unsigned long *image_size,
19+
unsigned long *reserve_addr,
20+
unsigned long *reserve_size,
21+
unsigned long dram_base,
22+
efi_loaded_image_t *image)
5323
{
5424
efi_status_t status;
5525
unsigned long kernel_size, kernel_memsize = 0;
@@ -69,7 +39,7 @@ static efi_status_t handle_kernel_image(efi_system_table_t *sys_table,
6939
if (*image_addr != (dram_base + TEXT_OFFSET)) {
7040
pr_efi_err(sys_table, "Failed to alloc kernel memory\n");
7141
efi_free(sys_table, kernel_memsize, *image_addr);
72-
return EFI_ERROR;
42+
return EFI_LOAD_ERROR;
7343
}
7444
*image_size = kernel_memsize;
7545
}

‎arch/arm64/kernel/efi.c‎

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -414,13 +414,24 @@ static int __init arm64_enter_virtual_mode(void)
414414
for_each_efi_memory_desc(&memmap, md) {
415415
if (!(md->attribute & EFI_MEMORY_RUNTIME))
416416
continue;
417-
if (remap_region(md, &virt_md))
418-
++count;
417+
if (!remap_region(md, &virt_md))
418+
goto err_unmap;
419+
++count;
419420
}
420421

421422
efi.systab = (__force void *)efi_lookup_mapped_addr(efi_system_table);
422-
if (efi.systab)
423-
set_bit(EFI_SYSTEM_TABLES, &efi.flags);
423+
if (!efi.systab) {
424+
/*
425+
* If we have no virtual mapping for the System Table at this
426+
* point, the memory map doesn't cover the physical offset where
427+
* it resides. This means the System Table will be inaccessible
428+
* to Runtime Services themselves once the virtual mapping is
429+
* installed.
430+
*/
431+
pr_err("Failed to remap EFI System Table -- buggy firmware?\n");
432+
goto err_unmap;
433+
}
434+
set_bit(EFI_SYSTEM_TABLES, &efi.flags);
424435

425436
local_irq_save(flags);
426437
cpu_switch_mm(idmap_pg_dir, &init_mm);
@@ -449,21 +460,18 @@ static int __init arm64_enter_virtual_mode(void)
449460

450461
/* Set up runtime services function pointers */
451462
runtime = efi.systab->runtime;
452-
efi.get_time = runtime->get_time;
453-
efi.set_time = runtime->set_time;
454-
efi.get_wakeup_time = runtime->get_wakeup_time;
455-
efi.set_wakeup_time = runtime->set_wakeup_time;
456-
efi.get_variable = runtime->get_variable;
457-
efi.get_next_variable = runtime->get_next_variable;
458-
efi.set_variable = runtime->set_variable;
459-
efi.query_variable_info = runtime->query_variable_info;
460-
efi.update_capsule = runtime->update_capsule;
461-
efi.query_capsule_caps = runtime->query_capsule_caps;
462-
efi.get_next_high_mono_count = runtime->get_next_high_mono_count;
463-
efi.reset_system = runtime->reset_system;
464-
463+
efi_native_runtime_setup();
465464
set_bit(EFI_RUNTIME_SERVICES, &efi.flags);
466465

467466
return 0;
467+
468+
err_unmap:
469+
/* unmap all mappings that succeeded: there are 'count' of those */
470+
for (virt_md = virtmap; count--; virt_md += memmap.desc_size) {
471+
md = virt_md;
472+
iounmap((__force void __iomem *)md->virt_addr);
473+
}
474+
kfree(virtmap);
475+
return -1;
468476
}
469477
early_initcall(arm64_enter_virtual_mode);

‎arch/ia64/include/asm/io.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -426,6 +426,7 @@ extern void iounmap (volatile void __iomem *addr);
426426
extern void __iomem * early_ioremap (unsigned long phys_addr, unsigned long size);
427427
#define early_memremap(phys_addr, size) early_ioremap(phys_addr, size)
428428
extern void early_iounmap (volatile void __iomem *addr, unsigned long size);
429+
#define early_memunmap(addr, size) early_iounmap(addr, size)
429430
static inline void __iomem * ioremap_cache (unsigned long phys_addr, unsigned long size)
430431
{
431432
return ioremap(phys_addr, size);

‎arch/ia64/kernel/process.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -662,7 +662,7 @@ void
662662
machine_restart (char *restart_cmd)
663663
{
664664
(void) notify_die(DIE_MACHINE_RESTART, restart_cmd, NULL, 0, 0, 0);
665-
(*efi.reset_system)(EFI_RESET_WARM, 0, 0, NULL);
665+
efi_reboot(REBOOT_WARM, NULL);
666666
}
667667

668668
void

‎arch/x86/Kconfig‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1522,6 +1522,7 @@ config EFI
15221522
bool "EFI runtime service support"
15231523
depends on ACPI
15241524
select UCS2_STRING
1525+
select EFI_RUNTIME_WRAPPERS
15251526
---help---
15261527
This enables the kernel to use EFI runtime services that are
15271528
available (such as the EFI variable services).

‎arch/x86/boot/compressed/Makefile‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ VMLINUX_OBJS = $(obj)/vmlinux.lds $(obj)/head_$(BITS).o $(obj)/misc.o \
3333
$(obj)/eboot.o: KBUILD_CFLAGS += -fshort-wchar -mno-red-zone
3434

3535
ifeq ($(CONFIG_EFI_STUB), y)
36-
VMLINUX_OBJS += $(obj)/eboot.o $(obj)/efi_stub_$(BITS).o
36+
VMLINUX_OBJS += $(obj)/eboot.o $(obj)/efi_stub_$(BITS).o \
37+
$(objtree)/drivers/firmware/efi/libstub/lib.a
3738
endif
3839

3940
$(obj)/vmlinux: $(VMLINUX_OBJS) FORCE

0 commit comments

Comments
 (0)