1 #ifndef _ASM_EFI_H 2 #define _ASM_EFI_H 3 4 #include <asm/boot.h> 5 #include <asm/cpufeature.h> 6 #include <asm/io.h> 7 #include <asm/mmu_context.h> 8 #include <asm/neon.h> 9 #include <asm/ptrace.h> 10 #include <asm/tlbflush.h> 11 12 #ifdef CONFIG_EFI 13 extern void efi_init(void); 14 #else 15 #define efi_init() 16 #endif 17 18 int efi_create_mapping(struct mm_struct *mm, efi_memory_desc_t *md); 19 int efi_set_mapping_permissions(struct mm_struct *mm, efi_memory_desc_t *md); 20 21 #define arch_efi_call_virt_setup() \ 22 ({ \ 23 kernel_neon_begin(); \ 24 efi_virtmap_load(); \ 25 }) 26 27 #define arch_efi_call_virt(p, f, args...) \ 28 ({ \ 29 efi_##f##_t *__f; \ 30 __f = p->f; \ 31 __f(args); \ 32 }) 33 34 #define arch_efi_call_virt_teardown() \ 35 ({ \ 36 efi_virtmap_unload(); \ 37 kernel_neon_end(); \ 38 }) 39 40 #define ARCH_EFI_IRQ_FLAGS_MASK (PSR_D_BIT | PSR_A_BIT | PSR_I_BIT | PSR_F_BIT) 41 42 /* 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() */ 50 51 /* on arm64, the FDT may be located anywhere in system RAM */ 52 static 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 */ 67 static 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 } 72 73 #define efi_call_early(f, ...) sys_table_arg->boottime->f(__VA_ARGS__) 74 #define __efi_call_early(f, ...) f(__VA_ARGS__) 75 #define efi_call_runtime(f, ...) sys_table_arg->runtime->f(__VA_ARGS__) 76 #define efi_is_64bit() (true) 77 78 #define efi_call_proto(protocol, f, instance, ...) \ 79 ((protocol##_t *)instance)->f(instance, ##__VA_ARGS__) 80 81 #define alloc_screen_info(x...) &screen_info 82 #define free_screen_info(x...) 83 84 static inline void efifb_setup_from_dmi(struct screen_info *si, const char *opt) 85 { 86 } 87 88 #define EFI_ALLOC_ALIGN SZ_64K 89 90 /* 91 * On ARM systems, virtually remapped UEFI runtime services are set up in two 92 * 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) 97 * - 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. 101 */ 102 103 static inline void efi_set_pgd(struct mm_struct *mm) 104 { 105 __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 } 129 } 130 131 void efi_virtmap_load(void); 132 void efi_virtmap_unload(void); 133 134 #endif /* _ASM_EFI_H */ 135