xref: /openbmc/linux/arch/arm/include/asm/efi.h (revision 2bdd5238)
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 /*
3  * Copyright (C) 2015 Linaro Ltd <ard.biesheuvel@linaro.org>
4  */
5 
6 #ifndef __ASM_ARM_EFI_H
7 #define __ASM_ARM_EFI_H
8 
9 #include <asm/cacheflush.h>
10 #include <asm/cachetype.h>
11 #include <asm/early_ioremap.h>
12 #include <asm/fixmap.h>
13 #include <asm/highmem.h>
14 #include <asm/mach/map.h>
15 #include <asm/mmu_context.h>
16 #include <asm/ptrace.h>
17 
18 #ifdef CONFIG_EFI
19 void efi_init(void);
20 extern void efifb_setup_from_dmi(struct screen_info *si, const char *opt);
21 
22 int efi_create_mapping(struct mm_struct *mm, efi_memory_desc_t *md);
23 int efi_set_mapping_permissions(struct mm_struct *mm, efi_memory_desc_t *md);
24 
25 #define arch_efi_call_virt_setup()	efi_virtmap_load()
26 #define arch_efi_call_virt_teardown()	efi_virtmap_unload()
27 
28 #define arch_efi_call_virt(p, f, args...)				\
29 ({									\
30 	efi_##f##_t *__f;						\
31 	__f = p->f;							\
32 	__f(args);							\
33 })
34 
35 #define ARCH_EFI_IRQ_FLAGS_MASK \
36 	(PSR_J_BIT | PSR_E_BIT | PSR_A_BIT | PSR_I_BIT | PSR_F_BIT | \
37 	 PSR_T_BIT | MODE_MASK)
38 
39 static inline void efi_set_pgd(struct mm_struct *mm)
40 {
41 	check_and_switch_context(mm, NULL);
42 }
43 
44 void efi_virtmap_load(void);
45 void efi_virtmap_unload(void);
46 
47 #else
48 #define efi_init()
49 #endif /* CONFIG_EFI */
50 
51 /* arch specific definitions used by the stub code */
52 
53 struct screen_info *alloc_screen_info(void);
54 void free_screen_info(struct screen_info *si);
55 
56 /*
57  * A reasonable upper bound for the uncompressed kernel size is 32 MBytes,
58  * so we will reserve that amount of memory. We have no easy way to tell what
59  * the actuall size of code + data the uncompressed kernel will use.
60  * If this is insufficient, the decompressor will relocate itself out of the
61  * way before performing the decompression.
62  */
63 #define MAX_UNCOMP_KERNEL_SIZE	SZ_32M
64 
65 /*
66  * phys-to-virt patching requires that the physical to virtual offset is a
67  * multiple of 2 MiB. However, using an alignment smaller than TEXT_OFFSET
68  * here throws off the memory allocation logic, so let's use the lowest power
69  * of two greater than 2 MiB and greater than TEXT_OFFSET.
70  */
71 #define EFI_PHYS_ALIGN		max(UL(SZ_2M), roundup_pow_of_two(TEXT_OFFSET))
72 
73 /* on ARM, the initrd should be loaded in a lowmem region */
74 static inline unsigned long efi_get_max_initrd_addr(unsigned long image_addr)
75 {
76 	return round_down(image_addr, SZ_4M) + SZ_512M;
77 }
78 
79 struct efi_arm_entry_state {
80 	u32	cpsr_before_ebs;
81 	u32	sctlr_before_ebs;
82 	u32	cpsr_after_ebs;
83 	u32	sctlr_after_ebs;
84 };
85 
86 static inline void efi_capsule_flush_cache_range(void *addr, int size)
87 {
88 	__cpuc_flush_dcache_area(addr, size);
89 }
90 
91 #endif /* _ASM_ARM_EFI_H */
92