xref: /linux/arch/arm/include/asm/efi.h (revision c771600c6af14749609b49565ffb4cac2959710d)
1d2912cb1SThomas Gleixner /* SPDX-License-Identifier: GPL-2.0-only */
2da58fb65SArd Biesheuvel /*
3da58fb65SArd Biesheuvel  * Copyright (C) 2015 Linaro Ltd <ard.biesheuvel@linaro.org>
4da58fb65SArd Biesheuvel  */
5da58fb65SArd Biesheuvel 
6da58fb65SArd Biesheuvel #ifndef __ASM_ARM_EFI_H
7da58fb65SArd Biesheuvel #define __ASM_ARM_EFI_H
8da58fb65SArd Biesheuvel 
9da58fb65SArd Biesheuvel #include <asm/cacheflush.h>
10da58fb65SArd Biesheuvel #include <asm/cachetype.h>
11da58fb65SArd Biesheuvel #include <asm/early_ioremap.h>
12da58fb65SArd Biesheuvel #include <asm/fixmap.h>
13da58fb65SArd Biesheuvel #include <asm/highmem.h>
14da58fb65SArd Biesheuvel #include <asm/mach/map.h>
15da58fb65SArd Biesheuvel #include <asm/mmu_context.h>
16207a90e5SMark Rutland #include <asm/ptrace.h>
17*a1439d89SArd Biesheuvel #include <asm/uaccess.h>
18da58fb65SArd Biesheuvel 
19da58fb65SArd Biesheuvel #ifdef CONFIG_EFI
20da58fb65SArd Biesheuvel void efi_init(void);
2169e377b2SArd Biesheuvel void arm_efi_init(void);
22da58fb65SArd Biesheuvel 
23da58fb65SArd Biesheuvel int efi_create_mapping(struct mm_struct *mm, efi_memory_desc_t *md);
24cf1d2ffcSArd Biesheuvel int efi_set_mapping_permissions(struct mm_struct *mm, efi_memory_desc_t *md, bool);
25da58fb65SArd Biesheuvel 
26819fc126SMark Rutland #define arch_efi_call_virt_setup()	efi_virtmap_load()
27819fc126SMark Rutland #define arch_efi_call_virt_teardown()	efi_virtmap_unload()
28da58fb65SArd Biesheuvel 
29*a1439d89SArd Biesheuvel #ifdef CONFIG_CPU_TTBR0_PAN
30*a1439d89SArd Biesheuvel #undef arch_efi_call_virt
31*a1439d89SArd Biesheuvel #define arch_efi_call_virt(p, f, args...) ({				\
32*a1439d89SArd Biesheuvel 	unsigned int flags = uaccess_save_and_enable();			\
33*a1439d89SArd Biesheuvel 	efi_status_t res = _Generic((p)->f(args),			\
34*a1439d89SArd Biesheuvel 			efi_status_t:	(p)->f(args),			\
35*a1439d89SArd Biesheuvel 			default:	((p)->f(args), EFI_ABORTED));	\
36*a1439d89SArd Biesheuvel 	uaccess_restore(flags);						\
37*a1439d89SArd Biesheuvel 	res;								\
38*a1439d89SArd Biesheuvel })
39*a1439d89SArd Biesheuvel #endif
40*a1439d89SArd Biesheuvel 
41207a90e5SMark Rutland #define ARCH_EFI_IRQ_FLAGS_MASK \
42207a90e5SMark Rutland 	(PSR_J_BIT | PSR_E_BIT | PSR_A_BIT | PSR_I_BIT | PSR_F_BIT | \
43207a90e5SMark Rutland 	 PSR_T_BIT | MODE_MASK)
44207a90e5SMark Rutland 
45da58fb65SArd Biesheuvel static inline void efi_set_pgd(struct mm_struct *mm)
46da58fb65SArd Biesheuvel {
47da58fb65SArd Biesheuvel 	check_and_switch_context(mm, NULL);
48da58fb65SArd Biesheuvel }
49da58fb65SArd Biesheuvel 
50da58fb65SArd Biesheuvel void efi_virtmap_load(void);
51da58fb65SArd Biesheuvel void efi_virtmap_unload(void);
52da58fb65SArd Biesheuvel 
53da58fb65SArd Biesheuvel #else
5469e377b2SArd Biesheuvel #define arm_efi_init()
55da58fb65SArd Biesheuvel #endif /* CONFIG_EFI */
56da58fb65SArd Biesheuvel 
5781a0bc39SRoy Franz /* arch specific definitions used by the stub code */
5881a0bc39SRoy Franz 
5981a0bc39SRoy Franz /*
6081a0bc39SRoy Franz  * A reasonable upper bound for the uncompressed kernel size is 32 MBytes,
6181a0bc39SRoy Franz  * so we will reserve that amount of memory. We have no easy way to tell what
6281a0bc39SRoy Franz  * the actuall size of code + data the uncompressed kernel will use.
6381a0bc39SRoy Franz  * If this is insufficient, the decompressor will relocate itself out of the
6481a0bc39SRoy Franz  * way before performing the decompression.
6581a0bc39SRoy Franz  */
6681a0bc39SRoy Franz #define MAX_UNCOMP_KERNEL_SIZE	SZ_32M
6781a0bc39SRoy Franz 
6881a0bc39SRoy Franz /*
69c0249238SArd Biesheuvel  * phys-to-virt patching requires that the physical to virtual offset is a
70c0249238SArd Biesheuvel  * multiple of 2 MiB. However, using an alignment smaller than TEXT_OFFSET
71c0249238SArd Biesheuvel  * here throws off the memory allocation logic, so let's use the lowest power
72c0249238SArd Biesheuvel  * of two greater than 2 MiB and greater than TEXT_OFFSET.
7381a0bc39SRoy Franz  */
74d72c8b0eSArd Biesheuvel #define EFI_PHYS_ALIGN		max(UL(SZ_2M), roundup_pow_of_two(TEXT_OFFSET))
75138728ddSArd Biesheuvel 
76138728ddSArd Biesheuvel /* on ARM, the initrd should be loaded in a lowmem region */
776208857bSArd Biesheuvel static inline unsigned long efi_get_max_initrd_addr(unsigned long image_addr)
78138728ddSArd Biesheuvel {
79c0249238SArd Biesheuvel 	return round_down(image_addr, SZ_4M) + SZ_512M;
80138728ddSArd Biesheuvel }
8181a0bc39SRoy Franz 
822a55280aSArd Biesheuvel struct efi_arm_entry_state {
832a55280aSArd Biesheuvel 	u32	cpsr_before_ebs;
842a55280aSArd Biesheuvel 	u32	sctlr_before_ebs;
852a55280aSArd Biesheuvel 	u32	cpsr_after_ebs;
862a55280aSArd Biesheuvel 	u32	sctlr_after_ebs;
872a55280aSArd Biesheuvel };
882a55280aSArd Biesheuvel 
894dbe44fbSArd Biesheuvel static inline void efi_capsule_flush_cache_range(void *addr, int size)
904dbe44fbSArd Biesheuvel {
914dbe44fbSArd Biesheuvel 	__cpuc_flush_dcache_area(addr, size);
924dbe44fbSArd Biesheuvel }
934dbe44fbSArd Biesheuvel 
94da58fb65SArd Biesheuvel #endif /* _ASM_ARM_EFI_H */
95