^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) /* SPDX-License-Identifier: GPL-2.0 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) #ifndef _ASM_EFI_H
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) #define _ASM_EFI_H
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) #include <asm/boot.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) #include <asm/cpufeature.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) #include <asm/fpsimd.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) #include <asm/io.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) #include <asm/memory.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #include <asm/mmu_context.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include <asm/neon.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <asm/ptrace.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <asm/tlbflush.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #ifdef CONFIG_EFI
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) extern void efi_init(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #define efi_init()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) int efi_create_mapping(struct mm_struct *mm, efi_memory_desc_t *md);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) int efi_set_mapping_permissions(struct mm_struct *mm, efi_memory_desc_t *md);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) #define arch_efi_call_virt_setup() \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) ({ \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) efi_virtmap_load(); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) __efi_fpsimd_begin(); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) })
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) #define arch_efi_call_virt(p, f, args...) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) ({ \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) efi_##f##_t *__f; \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) __f = p->f; \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) __efi_rt_asm_wrapper(__f, #f, args); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) })
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) #define arch_efi_call_virt_teardown() \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) ({ \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) __efi_fpsimd_end(); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) efi_virtmap_unload(); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) })
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) efi_status_t __efi_rt_asm_wrapper(void *, const char *, ...);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) #define ARCH_EFI_IRQ_FLAGS_MASK (PSR_D_BIT | PSR_A_BIT | PSR_I_BIT | PSR_F_BIT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) * Even when Linux uses IRQ priorities for IRQ disabling, EFI does not.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) * And EFI shouldn't really play around with priority masking as it is not aware
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) * which priorities the OS has assigned to its interrupts.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) #define arch_efi_save_flags(state_flags) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) ((void)((state_flags) = read_sysreg(daif)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) #define arch_efi_restore_flags(state_flags) write_sysreg(state_flags, daif)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) /* arch specific definitions used by the stub code */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) * In some configurations (e.g. VMAP_STACK && 64K pages), stacks built into the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) * kernel need greater alignment than we require the segments to be padded to.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) #define EFI_KIMG_ALIGN \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) (SEGMENT_ALIGN > THREAD_ALIGN ? SEGMENT_ALIGN : THREAD_ALIGN)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) /* on arm64, the FDT may be located anywhere in system RAM */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) static inline unsigned long efi_get_max_fdt_addr(unsigned long image_addr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) return ULONG_MAX;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) * On arm64, we have to ensure that the initrd ends up in the linear region,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) * which is a 1 GB aligned region of size '1UL << (VA_BITS_MIN - 1)' that is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) * guaranteed to cover the kernel Image.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) * Since the EFI stub is part of the kernel Image, we can relax the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) * usual requirements in Documentation/arm64/booting.rst, which still
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) * apply to other bootloaders, and are required for some kernel
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) * configurations.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) static inline unsigned long efi_get_max_initrd_addr(unsigned long image_addr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) return (image_addr & ~(SZ_1G - 1UL)) + (1UL << (VA_BITS_MIN - 1));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) #define alloc_screen_info(x...) &screen_info
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) static inline void free_screen_info(struct screen_info *si)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) static inline void efifb_setup_from_dmi(struct screen_info *si, const char *opt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) #define EFI_ALLOC_ALIGN SZ_64K
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) * On ARM systems, virtually remapped UEFI runtime services are set up in two
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) * distinct stages:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) * - The stub retrieves the final version of the memory map from UEFI, populates
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) * the virt_addr fields and calls the SetVirtualAddressMap() [SVAM] runtime
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) * service to communicate the new mapping to the firmware (Note that the new
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) * mapping is not live at this time)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) * - During an early initcall(), the EFI system table is permanently remapped
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) * and the virtual remapping of the UEFI Runtime Services regions is loaded
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) * into a private set of page tables. If this all succeeds, the Runtime
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) * Services are enabled and the EFI_RUNTIME_SERVICES bit set.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) static inline void efi_set_pgd(struct mm_struct *mm)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) __switch_mm(mm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) if (system_uses_ttbr0_pan()) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) if (mm != current->active_mm) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) * Update the current thread's saved ttbr0 since it is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) * restored as part of a return from exception. Enable
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) * access to the valid TTBR0_EL1 and invoke the errata
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) * workaround directly since there is no return from
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) * exception when invoking the EFI run-time services.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) update_saved_ttbr0(current, mm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) uaccess_ttbr0_enable();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) post_ttbr_update_workaround();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) * Defer the switch to the current thread's TTBR0_EL1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) * until uaccess_enable(). Restore the current
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) * thread's saved ttbr0 corresponding to its active_mm
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) uaccess_ttbr0_disable();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) update_saved_ttbr0(current, current->active_mm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) void efi_virtmap_load(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) void efi_virtmap_unload(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) #endif /* _ASM_EFI_H */