blob: 8f3043aba87307c9ebc3435277e3f4f933fd3278 [file] [log] [blame]
Mark Salterf84d0272014-04-15 21:59:30 -04001#ifndef _ASM_EFI_H
2#define _ASM_EFI_H
3
Ard Biesheuvel24d7c492017-04-04 17:02:39 +01004#include <asm/boot.h>
Catalin Marinas39bc88e2016-09-02 14:54:03 +01005#include <asm/cpufeature.h>
Mark Salterf84d0272014-04-15 21:59:30 -04006#include <asm/io.h>
Ard Biesheuvelf7d92482015-11-30 13:28:19 +01007#include <asm/mmu_context.h>
Ard Biesheuvele15dd492014-07-04 19:41:53 +02008#include <asm/neon.h>
Mark Rutlandee6cab52016-04-25 21:07:09 +01009#include <asm/ptrace.h>
Ard Biesheuvelf7d92482015-11-30 13:28:19 +010010#include <asm/tlbflush.h>
Mark Salterf84d0272014-04-15 21:59:30 -040011
12#ifdef CONFIG_EFI
13extern void efi_init(void);
Mark Salterf84d0272014-04-15 21:59:30 -040014#else
15#define efi_init()
Mark Salterf84d0272014-04-15 21:59:30 -040016#endif
17
Ard Biesheuvelf7d92482015-11-30 13:28:19 +010018int efi_create_mapping(struct mm_struct *mm, efi_memory_desc_t *md);
Ard Biesheuvelbd264d02016-06-29 14:51:27 +020019int efi_set_mapping_permissions(struct mm_struct *mm, efi_memory_desc_t *md);
Ard Biesheuvel789957e2016-04-25 21:06:46 +010020
Mark Rutland489f80f2016-04-25 21:07:04 +010021#define arch_efi_call_virt_setup() \
Ard Biesheuvele15dd492014-07-04 19:41:53 +020022({ \
Ard Biesheuvele15dd492014-07-04 19:41:53 +020023 kernel_neon_begin(); \
Ard Biesheuvelf3cdfd22014-10-20 16:27:26 +020024 efi_virtmap_load(); \
Ard Biesheuvele15dd492014-07-04 19:41:53 +020025})
26
Alex Thorlton80e75592016-06-25 08:20:27 +010027#define arch_efi_call_virt(p, f, args...) \
Ard Biesheuvele15dd492014-07-04 19:41:53 +020028({ \
Ard Biesheuvelf3cdfd22014-10-20 16:27:26 +020029 efi_##f##_t *__f; \
Alex Thorlton80e75592016-06-25 08:20:27 +010030 __f = p->f; \
Mark Rutland489f80f2016-04-25 21:07:04 +010031 __f(args); \
32})
33
34#define arch_efi_call_virt_teardown() \
35({ \
Ard Biesheuvelf3cdfd22014-10-20 16:27:26 +020036 efi_virtmap_unload(); \
Ard Biesheuvele15dd492014-07-04 19:41:53 +020037 kernel_neon_end(); \
38})
39
Mark Rutlandee6cab52016-04-25 21:07:09 +010040#define ARCH_EFI_IRQ_FLAGS_MASK (PSR_D_BIT | PSR_A_BIT | PSR_I_BIT | PSR_F_BIT)
41
Ard Biesheuvela13b0072014-07-02 14:54:41 +020042/* arch specific definitions used by the stub code */
43
44/*
45 * AArch64 requires the DTB to be 8-byte aligned in the first 512MiB from
46 * start of kernel and may not cross a 2MiB boundary. We set alignment to
47 * 2MiB so we know it won't cross a 2MiB boundary.
48 */
49#define EFI_FDT_ALIGN SZ_2M /* used by allocate_new_fdt_and_exit_boot() */
Ard Biesheuvel138728dd2017-04-04 17:02:37 +010050
51/* on arm64, the FDT may be located anywhere in system RAM */
52static inline unsigned long efi_get_max_fdt_addr(unsigned long dram_base)
53{
54 return ULONG_MAX;
55}
56
57/*
58 * On arm64, we have to ensure that the initrd ends up in the linear region,
59 * which is a 1 GB aligned region of size '1UL << (VA_BITS - 1)' that is
60 * guaranteed to cover the kernel Image.
61 *
62 * Since the EFI stub is part of the kernel Image, we can relax the
63 * usual requirements in Documentation/arm64/booting.txt, which still
64 * apply to other bootloaders, and are required for some kernel
65 * configurations.
66 */
67static inline unsigned long efi_get_max_initrd_addr(unsigned long dram_base,
68 unsigned long image_addr)
69{
70 return (image_addr & ~(SZ_1G - 1UL)) + (1UL << (VA_BITS - 1));
71}
Ard Biesheuvela13b0072014-07-02 14:54:41 +020072
Ard Biesheuvelfc372062016-04-25 21:06:49 +010073#define efi_call_early(f, ...) sys_table_arg->boottime->f(__VA_ARGS__)
74#define __efi_call_early(f, ...) f(__VA_ARGS__)
David Howells6d0ca4a2017-02-06 11:22:41 +000075#define efi_call_runtime(f, ...) sys_table_arg->runtime->f(__VA_ARGS__)
Ard Biesheuvelfc372062016-04-25 21:06:49 +010076#define efi_is_64bit() (true)
Ard Biesheuvela13b0072014-07-02 14:54:41 +020077
Lukas Wunner3552fdf2016-11-12 21:32:35 +000078#define efi_call_proto(protocol, f, instance, ...) \
79 ((protocol##_t *)instance)->f(instance, ##__VA_ARGS__)
80
Ard Biesheuvel57fdb89a2016-04-25 21:06:52 +010081#define alloc_screen_info(x...) &screen_info
82#define free_screen_info(x...)
83
Ard Biesheuvel98225042016-04-25 21:06:56 +010084static inline void efifb_setup_from_dmi(struct screen_info *si, const char *opt)
85{
86}
87
Ard Biesheuvel1bd0abb2014-11-17 13:50:21 +010088#define EFI_ALLOC_ALIGN SZ_64K
89
Ard Biesheuvelf3cdfd22014-10-20 16:27:26 +020090/*
Ard Biesheuvel60305db2015-01-22 10:01:40 +000091 * On ARM systems, virtually remapped UEFI runtime services are set up in two
Ard Biesheuvelf3cdfd22014-10-20 16:27:26 +020092 * distinct stages:
93 * - The stub retrieves the final version of the memory map from UEFI, populates
94 * the virt_addr fields and calls the SetVirtualAddressMap() [SVAM] runtime
95 * service to communicate the new mapping to the firmware (Note that the new
96 * mapping is not live at this time)
Ard Biesheuvel60305db2015-01-22 10:01:40 +000097 * - During an early initcall(), the EFI system table is permanently remapped
98 * and the virtual remapping of the UEFI Runtime Services regions is loaded
99 * into a private set of page tables. If this all succeeds, the Runtime
100 * Services are enabled and the EFI_RUNTIME_SERVICES bit set.
Ard Biesheuvelf3cdfd22014-10-20 16:27:26 +0200101 */
Ard Biesheuvelf3cdfd22014-10-20 16:27:26 +0200102
Ard Biesheuvelf7d92482015-11-30 13:28:19 +0100103static inline void efi_set_pgd(struct mm_struct *mm)
104{
Catalin Marinas39bc88e2016-09-02 14:54:03 +0100105 __switch_mm(mm);
106
107 if (system_uses_ttbr0_pan()) {
108 if (mm != current->active_mm) {
109 /*
110 * Update the current thread's saved ttbr0 since it is
111 * restored as part of a return from exception. Set
112 * the hardware TTBR0_EL1 using cpu_switch_mm()
113 * directly to enable potential errata workarounds.
114 */
115 update_saved_ttbr0(current, mm);
116 cpu_switch_mm(mm->pgd, mm);
117 } else {
118 /*
119 * Defer the switch to the current thread's TTBR0_EL1
120 * until uaccess_enable(). Restore the current
121 * thread's saved ttbr0 corresponding to its active_mm
122 * (if different from init_mm).
123 */
124 cpu_set_reserved_ttbr0();
125 if (current->active_mm != &init_mm)
126 update_saved_ttbr0(current, current->active_mm);
127 }
128 }
Ard Biesheuvelf7d92482015-11-30 13:28:19 +0100129}
130
Ard Biesheuvelf3cdfd22014-10-20 16:27:26 +0200131void efi_virtmap_load(void);
132void efi_virtmap_unload(void);
133
Mark Salterf84d0272014-04-15 21:59:30 -0400134#endif /* _ASM_EFI_H */