blob: 0e8cc3b85bb879d359751cbc4508669b867b2e74 [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>
Mark Rutland170976b2017-07-14 15:54:36 +01007#include <asm/memory.h>
Ard Biesheuvelf7d92482015-11-30 13:28:19 +01008#include <asm/mmu_context.h>
Ard Biesheuvele15dd492014-07-04 19:41:53 +02009#include <asm/neon.h>
Mark Rutlandee6cab52016-04-25 21:07:09 +010010#include <asm/ptrace.h>
Ard Biesheuvelf7d92482015-11-30 13:28:19 +010011#include <asm/tlbflush.h>
Mark Salterf84d0272014-04-15 21:59:30 -040012
13#ifdef CONFIG_EFI
14extern void efi_init(void);
Mark Salterf84d0272014-04-15 21:59:30 -040015#else
16#define efi_init()
Mark Salterf84d0272014-04-15 21:59:30 -040017#endif
18
Ard Biesheuvelf7d92482015-11-30 13:28:19 +010019int efi_create_mapping(struct mm_struct *mm, efi_memory_desc_t *md);
Ard Biesheuvelbd264d02016-06-29 14:51:27 +020020int efi_set_mapping_permissions(struct mm_struct *mm, efi_memory_desc_t *md);
Ard Biesheuvel789957e2016-04-25 21:06:46 +010021
Mark Rutland489f80f2016-04-25 21:07:04 +010022#define arch_efi_call_virt_setup() \
Ard Biesheuvele15dd492014-07-04 19:41:53 +020023({ \
Ard Biesheuvele15dd492014-07-04 19:41:53 +020024 kernel_neon_begin(); \
Ard Biesheuvelf3cdfd22014-10-20 16:27:26 +020025 efi_virtmap_load(); \
Ard Biesheuvele15dd492014-07-04 19:41:53 +020026})
27
Alex Thorlton80e75592016-06-25 08:20:27 +010028#define arch_efi_call_virt(p, f, args...) \
Ard Biesheuvele15dd492014-07-04 19:41:53 +020029({ \
Ard Biesheuvelf3cdfd22014-10-20 16:27:26 +020030 efi_##f##_t *__f; \
Alex Thorlton80e75592016-06-25 08:20:27 +010031 __f = p->f; \
Mark Rutland489f80f2016-04-25 21:07:04 +010032 __f(args); \
33})
34
35#define arch_efi_call_virt_teardown() \
36({ \
Ard Biesheuvelf3cdfd22014-10-20 16:27:26 +020037 efi_virtmap_unload(); \
Ard Biesheuvele15dd492014-07-04 19:41:53 +020038 kernel_neon_end(); \
39})
40
Mark Rutlandee6cab52016-04-25 21:07:09 +010041#define ARCH_EFI_IRQ_FLAGS_MASK (PSR_D_BIT | PSR_A_BIT | PSR_I_BIT | PSR_F_BIT)
42
Ard Biesheuvela13b0072014-07-02 14:54:41 +020043/* arch specific definitions used by the stub code */
44
45/*
46 * AArch64 requires the DTB to be 8-byte aligned in the first 512MiB from
47 * start of kernel and may not cross a 2MiB boundary. We set alignment to
48 * 2MiB so we know it won't cross a 2MiB boundary.
49 */
50#define EFI_FDT_ALIGN SZ_2M /* used by allocate_new_fdt_and_exit_boot() */
Ard Biesheuvel138728dd2017-04-04 17:02:37 +010051
Mark Rutland170976b2017-07-14 15:54:36 +010052#define EFI_KIMG_ALIGN SEGMENT_ALIGN
53
Ard Biesheuvel138728dd2017-04-04 17:02:37 +010054/* on arm64, the FDT may be located anywhere in system RAM */
55static inline unsigned long efi_get_max_fdt_addr(unsigned long dram_base)
56{
57 return ULONG_MAX;
58}
59
60/*
61 * On arm64, we have to ensure that the initrd ends up in the linear region,
62 * which is a 1 GB aligned region of size '1UL << (VA_BITS - 1)' that is
63 * guaranteed to cover the kernel Image.
64 *
65 * Since the EFI stub is part of the kernel Image, we can relax the
66 * usual requirements in Documentation/arm64/booting.txt, which still
67 * apply to other bootloaders, and are required for some kernel
68 * configurations.
69 */
70static inline unsigned long efi_get_max_initrd_addr(unsigned long dram_base,
71 unsigned long image_addr)
72{
73 return (image_addr & ~(SZ_1G - 1UL)) + (1UL << (VA_BITS - 1));
74}
Ard Biesheuvela13b0072014-07-02 14:54:41 +020075
Ard Biesheuvelfc372062016-04-25 21:06:49 +010076#define efi_call_early(f, ...) sys_table_arg->boottime->f(__VA_ARGS__)
77#define __efi_call_early(f, ...) f(__VA_ARGS__)
David Howells6d0ca4a2017-02-06 11:22:41 +000078#define efi_call_runtime(f, ...) sys_table_arg->runtime->f(__VA_ARGS__)
Ard Biesheuvelfc372062016-04-25 21:06:49 +010079#define efi_is_64bit() (true)
Ard Biesheuvela13b0072014-07-02 14:54:41 +020080
Lukas Wunner3552fdf2016-11-12 21:32:35 +000081#define efi_call_proto(protocol, f, instance, ...) \
82 ((protocol##_t *)instance)->f(instance, ##__VA_ARGS__)
83
Ard Biesheuvel57fdb89a2016-04-25 21:06:52 +010084#define alloc_screen_info(x...) &screen_info
85#define free_screen_info(x...)
86
Ard Biesheuvel98225042016-04-25 21:06:56 +010087static inline void efifb_setup_from_dmi(struct screen_info *si, const char *opt)
88{
89}
90
Ard Biesheuvel1bd0abb2014-11-17 13:50:21 +010091#define EFI_ALLOC_ALIGN SZ_64K
92
Ard Biesheuvelf3cdfd22014-10-20 16:27:26 +020093/*
Ard Biesheuvel60305db2015-01-22 10:01:40 +000094 * On ARM systems, virtually remapped UEFI runtime services are set up in two
Ard Biesheuvelf3cdfd22014-10-20 16:27:26 +020095 * distinct stages:
96 * - The stub retrieves the final version of the memory map from UEFI, populates
97 * the virt_addr fields and calls the SetVirtualAddressMap() [SVAM] runtime
98 * service to communicate the new mapping to the firmware (Note that the new
99 * mapping is not live at this time)
Ard Biesheuvel60305db2015-01-22 10:01:40 +0000100 * - During an early initcall(), the EFI system table is permanently remapped
101 * and the virtual remapping of the UEFI Runtime Services regions is loaded
102 * into a private set of page tables. If this all succeeds, the Runtime
103 * Services are enabled and the EFI_RUNTIME_SERVICES bit set.
Ard Biesheuvelf3cdfd22014-10-20 16:27:26 +0200104 */
Ard Biesheuvelf3cdfd22014-10-20 16:27:26 +0200105
Ard Biesheuvelf7d92482015-11-30 13:28:19 +0100106static inline void efi_set_pgd(struct mm_struct *mm)
107{
Catalin Marinas39bc88e2016-09-02 14:54:03 +0100108 __switch_mm(mm);
109
110 if (system_uses_ttbr0_pan()) {
111 if (mm != current->active_mm) {
112 /*
113 * Update the current thread's saved ttbr0 since it is
114 * restored as part of a return from exception. Set
115 * the hardware TTBR0_EL1 using cpu_switch_mm()
116 * directly to enable potential errata workarounds.
117 */
118 update_saved_ttbr0(current, mm);
119 cpu_switch_mm(mm->pgd, mm);
120 } else {
121 /*
122 * Defer the switch to the current thread's TTBR0_EL1
123 * until uaccess_enable(). Restore the current
124 * thread's saved ttbr0 corresponding to its active_mm
125 * (if different from init_mm).
126 */
127 cpu_set_reserved_ttbr0();
128 if (current->active_mm != &init_mm)
129 update_saved_ttbr0(current, current->active_mm);
130 }
131 }
Ard Biesheuvelf7d92482015-11-30 13:28:19 +0100132}
133
Ard Biesheuvelf3cdfd22014-10-20 16:27:26 +0200134void efi_virtmap_load(void);
135void efi_virtmap_unload(void);
136
Mark Salterf84d0272014-04-15 21:59:30 -0400137#endif /* _ASM_EFI_H */