Skip to content

Commit da58fb6

Browse files
author
Ard Biesheuvel
committed
ARM: wire up UEFI init and runtime support
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>
1 parent 09414d0 commit da58fb6

6 files changed

Lines changed: 104 additions & 1 deletion

File tree

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

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
/*
2+
* Copyright (C) 2015 Linaro Ltd <ard.biesheuvel@linaro.org>
3+
*
4+
* This program is free software; you can redistribute it and/or modify
5+
* it under the terms of the GNU General Public License version 2 as
6+
* published by the Free Software Foundation.
7+
*/
8+
9+
#ifndef __ASM_ARM_EFI_H
10+
#define __ASM_ARM_EFI_H
11+
12+
#include <asm/cacheflush.h>
13+
#include <asm/cachetype.h>
14+
#include <asm/early_ioremap.h>
15+
#include <asm/fixmap.h>
16+
#include <asm/highmem.h>
17+
#include <asm/mach/map.h>
18+
#include <asm/mmu_context.h>
19+
#include <asm/pgtable.h>
20+
21+
#ifdef CONFIG_EFI
22+
void efi_init(void);
23+
24+
int efi_create_mapping(struct mm_struct *mm, efi_memory_desc_t *md);
25+
26+
#define efi_call_virt(f, ...) \
27+
({ \
28+
efi_##f##_t *__f; \
29+
efi_status_t __s; \
30+
\
31+
efi_virtmap_load(); \
32+
__f = efi.systab->runtime->f; \
33+
__s = __f(__VA_ARGS__); \
34+
efi_virtmap_unload(); \
35+
__s; \
36+
})
37+
38+
#define __efi_call_virt(f, ...) \
39+
({ \
40+
efi_##f##_t *__f; \
41+
\
42+
efi_virtmap_load(); \
43+
__f = efi.systab->runtime->f; \
44+
__f(__VA_ARGS__); \
45+
efi_virtmap_unload(); \
46+
})
47+
48+
static inline void efi_set_pgd(struct mm_struct *mm)
49+
{
50+
check_and_switch_context(mm, NULL);
51+
}
52+
53+
void efi_virtmap_load(void);
54+
void efi_virtmap_unload(void);
55+
56+
#else
57+
#define efi_init()
58+
#endif /* CONFIG_EFI */
59+
60+
#endif /* _ASM_ARM_EFI_H */

‎arch/arm/include/asm/mmu_context.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ void __check_vmalloc_seq(struct mm_struct *mm);
2626
#ifdef CONFIG_CPU_HAS_ASID
2727

2828
void check_and_switch_context(struct mm_struct *mm, struct task_struct *tsk);
29-
#define init_new_context(tsk,mm) ({ atomic64_set(&mm->context.id, 0); 0; })
29+
#define init_new_context(tsk,mm) ({ atomic64_set(&(mm)->context.id, 0); 0; })
3030

3131
#ifdef CONFIG_ARM_ERRATA_798181
3232
void a15_erratum_get_cpumask(int this_cpu, struct mm_struct *mm,

‎arch/arm/kernel/Makefile‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ CFLAGS_pj4-cp0.o := -marm
7777
AFLAGS_iwmmxt.o := -Wa,-mcpu=iwmmxt
7878
obj-$(CONFIG_ARM_CPU_TOPOLOGY) += topology.o
7979
obj-$(CONFIG_VDSO) += vdso.o
80+
obj-$(CONFIG_EFI) += efi.o
8081

8182
ifneq ($(CONFIG_ARCH_EBSA110),y)
8283
obj-y += io.o

‎arch/arm/kernel/efi.c‎

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*
2+
* Copyright (C) 2015 Linaro Ltd <ard.biesheuvel@linaro.org>
3+
*
4+
* This program is free software; you can redistribute it and/or modify
5+
* it under the terms of the GNU General Public License version 2 as
6+
* published by the Free Software Foundation.
7+
*/
8+
9+
#include <linux/efi.h>
10+
#include <asm/efi.h>
11+
#include <asm/mach/map.h>
12+
#include <asm/mmu_context.h>
13+
14+
int __init efi_create_mapping(struct mm_struct *mm, efi_memory_desc_t *md)
15+
{
16+
struct map_desc desc = {
17+
.virtual = md->virt_addr,
18+
.pfn = __phys_to_pfn(md->phys_addr),
19+
.length = md->num_pages * EFI_PAGE_SIZE,
20+
};
21+
22+
/*
23+
* Order is important here: memory regions may have all of the
24+
* bits below set (and usually do), so we check them in order of
25+
* preference.
26+
*/
27+
if (md->attribute & EFI_MEMORY_WB)
28+
desc.type = MT_MEMORY_RWX;
29+
else if (md->attribute & EFI_MEMORY_WT)
30+
desc.type = MT_MEMORY_RWX_NONCACHED;
31+
else if (md->attribute & EFI_MEMORY_WC)
32+
desc.type = MT_DEVICE_WC;
33+
else
34+
desc.type = MT_DEVICE;
35+
36+
create_mapping_late(mm, &desc, true);
37+
return 0;
38+
}

‎arch/arm/kernel/setup.c‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
* it under the terms of the GNU General Public License version 2 as
88
* published by the Free Software Foundation.
99
*/
10+
#include <linux/efi.h>
1011
#include <linux/export.h>
1112
#include <linux/kernel.h>
1213
#include <linux/stddef.h>
@@ -37,6 +38,7 @@
3738
#include <asm/cp15.h>
3839
#include <asm/cpu.h>
3940
#include <asm/cputype.h>
41+
#include <asm/efi.h>
4042
#include <asm/elf.h>
4143
#include <asm/early_ioremap.h>
4244
#include <asm/fixmap.h>
@@ -966,6 +968,7 @@ void __init setup_arch(char **cmdline_p)
966968
early_paging_init(mdesc);
967969
#endif
968970
setup_dma_zone(mdesc);
971+
efi_init();
969972
sanity_check_meminfo();
970973
arm_memblock_init(mdesc);
971974

‎drivers/firmware/efi/Makefile‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,5 @@ obj-$(CONFIG_EFI_STUB) += libstub/
2020
obj-$(CONFIG_EFI_FAKE_MEMMAP) += fake_mem.o
2121

2222
arm-obj-$(CONFIG_EFI) := arm-init.o arm-runtime.o
23+
obj-$(CONFIG_ARM) += $(arm-obj-y)
2324
obj-$(CONFIG_ARM64) += $(arm-obj-y)

0 commit comments

Comments
 (0)