Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 */
0002 #ifndef _ASM_EFI_H
0003 #define _ASM_EFI_H
0004 
0005 #include <asm/boot.h>
0006 #include <asm/cpufeature.h>
0007 #include <asm/fpsimd.h>
0008 #include <asm/io.h>
0009 #include <asm/memory.h>
0010 #include <asm/mmu_context.h>
0011 #include <asm/neon.h>
0012 #include <asm/ptrace.h>
0013 #include <asm/tlbflush.h>
0014 
0015 #ifdef CONFIG_EFI
0016 extern void efi_init(void);
0017 #else
0018 #define efi_init()
0019 #endif
0020 
0021 int efi_create_mapping(struct mm_struct *mm, efi_memory_desc_t *md);
0022 int efi_set_mapping_permissions(struct mm_struct *mm, efi_memory_desc_t *md);
0023 
0024 #define arch_efi_call_virt_setup()                  \
0025 ({                                  \
0026     efi_virtmap_load();                     \
0027     __efi_fpsimd_begin();                       \
0028 })
0029 
0030 #undef arch_efi_call_virt
0031 #define arch_efi_call_virt(p, f, args...)               \
0032     __efi_rt_asm_wrapper((p)->f, #f, args)
0033 
0034 #define arch_efi_call_virt_teardown()                   \
0035 ({                                  \
0036     __efi_fpsimd_end();                     \
0037     efi_virtmap_unload();                       \
0038 })
0039 
0040 efi_status_t __efi_rt_asm_wrapper(void *, const char *, ...);
0041 
0042 #define ARCH_EFI_IRQ_FLAGS_MASK (PSR_D_BIT | PSR_A_BIT | PSR_I_BIT | PSR_F_BIT)
0043 
0044 /*
0045  * Even when Linux uses IRQ priorities for IRQ disabling, EFI does not.
0046  * And EFI shouldn't really play around with priority masking as it is not aware
0047  * which priorities the OS has assigned to its interrupts.
0048  */
0049 #define arch_efi_save_flags(state_flags)        \
0050     ((void)((state_flags) = read_sysreg(daif)))
0051 
0052 #define arch_efi_restore_flags(state_flags) write_sysreg(state_flags, daif)
0053 
0054 
0055 /* arch specific definitions used by the stub code */
0056 
0057 /*
0058  * In some configurations (e.g. VMAP_STACK && 64K pages), stacks built into the
0059  * kernel need greater alignment than we require the segments to be padded to.
0060  */
0061 #define EFI_KIMG_ALIGN  \
0062     (SEGMENT_ALIGN > THREAD_ALIGN ? SEGMENT_ALIGN : THREAD_ALIGN)
0063 
0064 /*
0065  * On arm64, we have to ensure that the initrd ends up in the linear region,
0066  * which is a 1 GB aligned region of size '1UL << (VA_BITS_MIN - 1)' that is
0067  * guaranteed to cover the kernel Image.
0068  *
0069  * Since the EFI stub is part of the kernel Image, we can relax the
0070  * usual requirements in Documentation/arm64/booting.rst, which still
0071  * apply to other bootloaders, and are required for some kernel
0072  * configurations.
0073  */
0074 static inline unsigned long efi_get_max_initrd_addr(unsigned long image_addr)
0075 {
0076     return (image_addr & ~(SZ_1G - 1UL)) + (1UL << (VA_BITS_MIN - 1));
0077 }
0078 
0079 #define alloc_screen_info(x...)     &screen_info
0080 
0081 static inline void free_screen_info(struct screen_info *si)
0082 {
0083 }
0084 
0085 #define EFI_ALLOC_ALIGN     SZ_64K
0086 
0087 /*
0088  * On ARM systems, virtually remapped UEFI runtime services are set up in two
0089  * distinct stages:
0090  * - The stub retrieves the final version of the memory map from UEFI, populates
0091  *   the virt_addr fields and calls the SetVirtualAddressMap() [SVAM] runtime
0092  *   service to communicate the new mapping to the firmware (Note that the new
0093  *   mapping is not live at this time)
0094  * - During an early initcall(), the EFI system table is permanently remapped
0095  *   and the virtual remapping of the UEFI Runtime Services regions is loaded
0096  *   into a private set of page tables. If this all succeeds, the Runtime
0097  *   Services are enabled and the EFI_RUNTIME_SERVICES bit set.
0098  */
0099 
0100 static inline void efi_set_pgd(struct mm_struct *mm)
0101 {
0102     __switch_mm(mm);
0103 
0104     if (system_uses_ttbr0_pan()) {
0105         if (mm != current->active_mm) {
0106             /*
0107              * Update the current thread's saved ttbr0 since it is
0108              * restored as part of a return from exception. Enable
0109              * access to the valid TTBR0_EL1 and invoke the errata
0110              * workaround directly since there is no return from
0111              * exception when invoking the EFI run-time services.
0112              */
0113             update_saved_ttbr0(current, mm);
0114             uaccess_ttbr0_enable();
0115             post_ttbr_update_workaround();
0116         } else {
0117             /*
0118              * Defer the switch to the current thread's TTBR0_EL1
0119              * until uaccess_enable(). Restore the current
0120              * thread's saved ttbr0 corresponding to its active_mm
0121              */
0122             uaccess_ttbr0_disable();
0123             update_saved_ttbr0(current, current->active_mm);
0124         }
0125     }
0126 }
0127 
0128 void efi_virtmap_load(void);
0129 void efi_virtmap_unload(void);
0130 
0131 static inline void efi_capsule_flush_cache_range(void *addr, int size)
0132 {
0133     dcache_clean_inval_poc((unsigned long)addr, (unsigned long)addr + size);
0134 }
0135 
0136 #endif /* _ASM_EFI_H */