blob: 6c4f9e8febf3235e0063bfffe40e620ce768f409 [file] [log] [blame]
Mark Salterf84d0272014-04-15 21:59:30 -04001#ifndef _ASM_EFI_H
2#define _ASM_EFI_H
3
Catalin Marinascfa93772016-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 Biesheuvel19445a02017-08-18 20:49:35 +010058/* redeclare as 'hidden' so the compiler will generate relative references */
59extern struct screen_info screen_info __attribute__((__visibility__("hidden")));
60
Ard Biesheuvel98225042016-04-25 21:06:56 +010061static inline void efifb_setup_from_dmi(struct screen_info *si, const char *opt)
62{
63}
64
Ard Biesheuvel1bd0abb2014-11-17 13:50:21 +010065#define EFI_ALLOC_ALIGN SZ_64K
66
Ard Biesheuvelf3cdfd22014-10-20 16:27:26 +020067/*
Ard Biesheuvel60305db2015-01-22 10:01:40 +000068 * On ARM systems, virtually remapped UEFI runtime services are set up in two
Ard Biesheuvelf3cdfd22014-10-20 16:27:26 +020069 * distinct stages:
70 * - The stub retrieves the final version of the memory map from UEFI, populates
71 * the virt_addr fields and calls the SetVirtualAddressMap() [SVAM] runtime
72 * service to communicate the new mapping to the firmware (Note that the new
73 * mapping is not live at this time)
Ard Biesheuvel60305db2015-01-22 10:01:40 +000074 * - During an early initcall(), the EFI system table is permanently remapped
75 * and the virtual remapping of the UEFI Runtime Services regions is loaded
76 * into a private set of page tables. If this all succeeds, the Runtime
77 * Services are enabled and the EFI_RUNTIME_SERVICES bit set.
Ard Biesheuvelf3cdfd22014-10-20 16:27:26 +020078 */
Ard Biesheuvelf3cdfd22014-10-20 16:27:26 +020079
Ard Biesheuvelf7d92482015-11-30 13:28:19 +010080static inline void efi_set_pgd(struct mm_struct *mm)
81{
Catalin Marinascfa93772016-09-02 14:54:03 +010082 __switch_mm(mm);
83
84 if (system_uses_ttbr0_pan()) {
85 if (mm != current->active_mm) {
86 /*
87 * Update the current thread's saved ttbr0 since it is
Catalin Marinas87883132018-01-10 13:18:30 +000088 * restored as part of a return from exception. Enable
89 * access to the valid TTBR0_EL1 and invoke the errata
90 * workaround directly since there is no return from
91 * exception when invoking the EFI run-time services.
Catalin Marinascfa93772016-09-02 14:54:03 +010092 */
93 update_saved_ttbr0(current, mm);
Catalin Marinas87883132018-01-10 13:18:30 +000094 uaccess_ttbr0_enable();
95 post_ttbr_update_workaround();
Catalin Marinascfa93772016-09-02 14:54:03 +010096 } else {
97 /*
98 * Defer the switch to the current thread's TTBR0_EL1
99 * until uaccess_enable(). Restore the current
100 * thread's saved ttbr0 corresponding to its active_mm
101 * (if different from init_mm).
102 */
Catalin Marinas87883132018-01-10 13:18:30 +0000103 uaccess_ttbr0_disable();
Catalin Marinascfa93772016-09-02 14:54:03 +0100104 if (current->active_mm != &init_mm)
105 update_saved_ttbr0(current, current->active_mm);
106 }
107 }
Ard Biesheuvelf7d92482015-11-30 13:28:19 +0100108}
109
Ard Biesheuvelf3cdfd22014-10-20 16:27:26 +0200110void efi_virtmap_load(void);
111void efi_virtmap_unload(void);
112
Mark Salterf84d0272014-04-15 21:59:30 -0400113#endif /* _ASM_EFI_H */