ARM: wire up UEFI init and runtime support
authorArd Biesheuvel <ard.biesheuvel@linaro.org>
Thu, 24 Sep 2015 20:49:52 +0000 (13:49 -0700)
committerard <ard.biesheuvel@linaro.org>
Sun, 13 Dec 2015 18:18:30 +0000 (19:18 +0100)
This adds support to the kernel proper for booting via UEFI. It shares
most of the code with arm64, so this patch mostly just wires it up for
use with ARM.

Note that this does not include the EFI stub, it is added in a subsequent
patch.

Tested-by: Ryan Harkin <ryan.harkin@linaro.org>
Reviewed-by: Matt Fleming <matt@codeblueprint.co.uk>
Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
arch/arm/include/asm/efi.h [new file with mode: 0644]
arch/arm/include/asm/mmu_context.h
arch/arm/kernel/Makefile
arch/arm/kernel/efi.c [new file with mode: 0644]
arch/arm/kernel/setup.c
drivers/firmware/efi/Makefile

diff --git a/arch/arm/include/asm/efi.h b/arch/arm/include/asm/efi.h
new file mode 100644 (file)
index 0000000..c91e330
--- /dev/null
@@ -0,0 +1,60 @@
+/*
+ * Copyright (C) 2015 Linaro Ltd <ard.biesheuvel@linaro.org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+
+#ifndef __ASM_ARM_EFI_H
+#define __ASM_ARM_EFI_H
+
+#include <asm/cacheflush.h>
+#include <asm/cachetype.h>
+#include <asm/early_ioremap.h>
+#include <asm/fixmap.h>
+#include <asm/highmem.h>
+#include <asm/mach/map.h>
+#include <asm/mmu_context.h>
+#include <asm/pgtable.h>
+
+#ifdef CONFIG_EFI
+void efi_init(void);
+
+int efi_create_mapping(struct mm_struct *mm, efi_memory_desc_t *md);
+
+#define efi_call_virt(f, ...)                                          \
+({                                                                     \
+       efi_##f##_t *__f;                                               \
+       efi_status_t __s;                                               \
+                                                                       \
+       efi_virtmap_load();                                             \
+       __f = efi.systab->runtime->f;                                   \
+       __s = __f(__VA_ARGS__);                                         \
+       efi_virtmap_unload();                                           \
+       __s;                                                            \
+})
+
+#define __efi_call_virt(f, ...)                                                \
+({                                                                     \
+       efi_##f##_t *__f;                                               \
+                                                                       \
+       efi_virtmap_load();                                             \
+       __f = efi.systab->runtime->f;                                   \
+       __f(__VA_ARGS__);                                               \
+       efi_virtmap_unload();                                           \
+})
+
+static inline void efi_set_pgd(struct mm_struct *mm)
+{
+       check_and_switch_context(mm, NULL);
+}
+
+void efi_virtmap_load(void);
+void efi_virtmap_unload(void);
+
+#else
+#define efi_init()
+#endif /* CONFIG_EFI */
+
+#endif /* _ASM_ARM_EFI_H */
index 9b32f76..432ce81 100644 (file)
@@ -26,7 +26,7 @@ void __check_vmalloc_seq(struct mm_struct *mm);
 #ifdef CONFIG_CPU_HAS_ASID
 
 void check_and_switch_context(struct mm_struct *mm, struct task_struct *tsk);
-#define init_new_context(tsk,mm)       ({ atomic64_set(&mm->context.id, 0); 0; })
+#define init_new_context(tsk,mm)       ({ atomic64_set(&(mm)->context.id, 0); 0; })
 
 #ifdef CONFIG_ARM_ERRATA_798181
 void a15_erratum_get_cpumask(int this_cpu, struct mm_struct *mm,
index af9e59b..c90f4a7 100644 (file)
@@ -77,6 +77,7 @@ CFLAGS_pj4-cp0.o              := -marm
 AFLAGS_iwmmxt.o                        := -Wa,-mcpu=iwmmxt
 obj-$(CONFIG_ARM_CPU_TOPOLOGY)  += topology.o
 obj-$(CONFIG_VDSO)             += vdso.o
+obj-$(CONFIG_EFI)              += efi.o
 
 ifneq ($(CONFIG_ARCH_EBSA110),y)
   obj-y                += io.o
diff --git a/arch/arm/kernel/efi.c b/arch/arm/kernel/efi.c
new file mode 100644 (file)
index 0000000..ff8a9d8
--- /dev/null
@@ -0,0 +1,38 @@
+/*
+ * Copyright (C) 2015 Linaro Ltd <ard.biesheuvel@linaro.org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+
+#include <linux/efi.h>
+#include <asm/efi.h>
+#include <asm/mach/map.h>
+#include <asm/mmu_context.h>
+
+int __init efi_create_mapping(struct mm_struct *mm, efi_memory_desc_t *md)
+{
+       struct map_desc desc = {
+               .virtual        = md->virt_addr,
+               .pfn            = __phys_to_pfn(md->phys_addr),
+               .length         = md->num_pages * EFI_PAGE_SIZE,
+       };
+
+       /*
+        * Order is important here: memory regions may have all of the
+        * bits below set (and usually do), so we check them in order of
+        * preference.
+        */
+       if (md->attribute & EFI_MEMORY_WB)
+               desc.type = MT_MEMORY_RWX;
+       else if (md->attribute & EFI_MEMORY_WT)
+               desc.type = MT_MEMORY_RWX_NONCACHED;
+       else if (md->attribute & EFI_MEMORY_WC)
+               desc.type = MT_DEVICE_WC;
+       else
+               desc.type = MT_DEVICE;
+
+       create_mapping_late(mm, &desc, true);
+       return 0;
+}
index 5df2bca..b341b1c 100644 (file)
@@ -7,6 +7,7 @@
  * it under the terms of the GNU General Public License version 2 as
  * published by the Free Software Foundation.
  */
+#include <linux/efi.h>
 #include <linux/export.h>
 #include <linux/kernel.h>
 #include <linux/stddef.h>
@@ -37,6 +38,7 @@
 #include <asm/cp15.h>
 #include <asm/cpu.h>
 #include <asm/cputype.h>
+#include <asm/efi.h>
 #include <asm/elf.h>
 #include <asm/early_ioremap.h>
 #include <asm/fixmap.h>
@@ -966,6 +968,7 @@ void __init setup_arch(char **cmdline_p)
        early_paging_init(mdesc);
 #endif
        setup_dma_zone(mdesc);
+       efi_init();
        sanity_check_meminfo();
        arm_memblock_init(mdesc);
 
index f292917..62e654f 100644 (file)
@@ -20,4 +20,5 @@ obj-$(CONFIG_EFI_STUB)                        += libstub/
 obj-$(CONFIG_EFI_FAKE_MEMMAP)          += fake_mem.o
 
 arm-obj-$(CONFIG_EFI)                  := arm-init.o arm-runtime.o
+obj-$(CONFIG_ARM)                      += $(arm-obj-y)
 obj-$(CONFIG_ARM64)                    += $(arm-obj-y)