blob: ea06f3fcf83462e4e65c9ac765beacae1adf56f2 [file] [log] [blame]
Mark Salterf84d0272014-04-15 21:59:30 -04001#ifndef _ASM_EFI_H
2#define _ASM_EFI_H
3
Catalin Marinasbe6383d2016-09-02 14:54:03 +01004#include <asm/cpufeature.h>
Mark Salterf84d0272014-04-15 21:59:30 -04005#include <asm/io.h>
Ard Biesheuvelf7d92482015-11-30 13:28:19 +01006#include <asm/mmu_context.h>
Ard Biesheuvele15dd492014-07-04 19:41:53 +02007#include <asm/neon.h>
Mark Rutlandee6cab52016-04-25 21:07:09 +01008#include <asm/ptrace.h>
Ard Biesheuvelf7d92482015-11-30 13:28:19 +01009#include <asm/tlbflush.h>
Mark Salterf84d0272014-04-15 21:59:30 -040010
11#ifdef CONFIG_EFI
12extern void efi_init(void);
Mark Salterf84d0272014-04-15 21:59:30 -040013#else
14#define efi_init()
Mark Salterf84d0272014-04-15 21:59:30 -040015#endif
16
Ard Biesheuvelf7d92482015-11-30 13:28:19 +010017int efi_create_mapping(struct mm_struct *mm, efi_memory_desc_t *md);
Ard Biesheuvelbd264d02016-06-29 14:51:27 +020018int efi_set_mapping_permissions(struct mm_struct *mm, efi_memory_desc_t *md);
Ard Biesheuvel789957e2016-04-25 21:06:46 +010019
Mark Rutland489f80f2016-04-25 21:07:04 +010020#define arch_efi_call_virt_setup() \
Ard Biesheuvele15dd492014-07-04 19:41:53 +020021({ \
Ard Biesheuvele15dd492014-07-04 19:41:53 +020022 kernel_neon_begin(); \
Ard Biesheuvelf3cdfd22014-10-20 16:27:26 +020023 efi_virtmap_load(); \
Ard Biesheuvele15dd492014-07-04 19:41:53 +020024})
25
Alex Thorlton80e75592016-06-25 08:20:27 +010026#define arch_efi_call_virt(p, f, args...) \
Ard Biesheuvele15dd492014-07-04 19:41:53 +020027({ \
Ard Biesheuvelf3cdfd22014-10-20 16:27:26 +020028 efi_##f##_t *__f; \
Alex Thorlton80e75592016-06-25 08:20:27 +010029 __f = p->f; \
Mark Rutland489f80f2016-04-25 21:07:04 +010030 __f(args); \
31})
32
33#define arch_efi_call_virt_teardown() \
34({ \
Ard Biesheuvelf3cdfd22014-10-20 16:27:26 +020035 efi_virtmap_unload(); \
Ard Biesheuvele15dd492014-07-04 19:41:53 +020036 kernel_neon_end(); \
37})
38
Mark Rutlandee6cab52016-04-25 21:07:09 +010039#define ARCH_EFI_IRQ_FLAGS_MASK (PSR_D_BIT | PSR_A_BIT | PSR_I_BIT | PSR_F_BIT)
40
Ard Biesheuvela13b0072014-07-02 14:54:41 +020041/* arch specific definitions used by the stub code */
42
43/*
44 * AArch64 requires the DTB to be 8-byte aligned in the first 512MiB from
45 * start of kernel and may not cross a 2MiB boundary. We set alignment to
46 * 2MiB so we know it won't cross a 2MiB boundary.
47 */
48#define EFI_FDT_ALIGN SZ_2M /* used by allocate_new_fdt_and_exit_boot() */
49#define MAX_FDT_OFFSET SZ_512M
50
Ard Biesheuvelfc372062016-04-25 21:06:49 +010051#define efi_call_early(f, ...) sys_table_arg->boottime->f(__VA_ARGS__)
52#define __efi_call_early(f, ...) f(__VA_ARGS__)
53#define efi_is_64bit() (true)
Ard Biesheuvela13b0072014-07-02 14:54:41 +020054
Ard Biesheuvel57fdb89a2016-04-25 21:06:52 +010055#define alloc_screen_info(x...) &screen_info
56#define free_screen_info(x...)
57
Ard Biesheuvel98225042016-04-25 21:06:56 +010058static inline void efifb_setup_from_dmi(struct screen_info *si, const char *opt)
59{
60}
61
Ard Biesheuvel1bd0abb2014-11-17 13:50:21 +010062#define EFI_ALLOC_ALIGN SZ_64K
63
Ard Biesheuvelf3cdfd22014-10-20 16:27:26 +020064/*
Ard Biesheuvel60305db2015-01-22 10:01:40 +000065 * On ARM systems, virtually remapped UEFI runtime services are set up in two
Ard Biesheuvelf3cdfd22014-10-20 16:27:26 +020066 * distinct stages:
67 * - The stub retrieves the final version of the memory map from UEFI, populates
68 * the virt_addr fields and calls the SetVirtualAddressMap() [SVAM] runtime
69 * service to communicate the new mapping to the firmware (Note that the new
70 * mapping is not live at this time)
Ard Biesheuvel60305db2015-01-22 10:01:40 +000071 * - During an early initcall(), the EFI system table is permanently remapped
72 * and the virtual remapping of the UEFI Runtime Services regions is loaded
73 * into a private set of page tables. If this all succeeds, the Runtime
74 * Services are enabled and the EFI_RUNTIME_SERVICES bit set.
Ard Biesheuvelf3cdfd22014-10-20 16:27:26 +020075 */
Ard Biesheuvelf3cdfd22014-10-20 16:27:26 +020076
Ard Biesheuvelf7d92482015-11-30 13:28:19 +010077static inline void efi_set_pgd(struct mm_struct *mm)
78{
Catalin Marinasbe6383d2016-09-02 14:54:03 +010079 __switch_mm(mm);
80
81 if (system_uses_ttbr0_pan()) {
82 if (mm != current->active_mm) {
83 /*
84 * Update the current thread's saved ttbr0 since it is
Catalin Marinas874f7782018-01-10 13:18:30 +000085 * restored as part of a return from exception. Enable
86 * access to the valid TTBR0_EL1 and invoke the errata
87 * workaround directly since there is no return from
88 * exception when invoking the EFI run-time services.
Catalin Marinasbe6383d2016-09-02 14:54:03 +010089 */
90 update_saved_ttbr0(current, mm);
Catalin Marinas874f7782018-01-10 13:18:30 +000091 uaccess_ttbr0_enable();
92 post_ttbr_update_workaround();
Catalin Marinasbe6383d2016-09-02 14:54:03 +010093 } else {
94 /*
95 * Defer the switch to the current thread's TTBR0_EL1
96 * until uaccess_enable(). Restore the current
97 * thread's saved ttbr0 corresponding to its active_mm
Catalin Marinasbe6383d2016-09-02 14:54:03 +010098 */
Catalin Marinas874f7782018-01-10 13:18:30 +000099 uaccess_ttbr0_disable();
Will Deacon7bec5cb2017-12-06 10:42:10 +0000100 update_saved_ttbr0(current, current->active_mm);
Catalin Marinasbe6383d2016-09-02 14:54:03 +0100101 }
102 }
Ard Biesheuvelf7d92482015-11-30 13:28:19 +0100103}
104
Ard Biesheuvelf3cdfd22014-10-20 16:27:26 +0200105void efi_virtmap_load(void);
106void efi_virtmap_unload(void);
107
Mark Salterf84d0272014-04-15 21:59:30 -0400108#endif /* _ASM_EFI_H */