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>
17da58fb65SArd Biesheuvel
18da58fb65SArd Biesheuvel #ifdef CONFIG_EFI
19da58fb65SArd Biesheuvel void efi_init(void);
2069e377b2SArd Biesheuvel void arm_efi_init(void);
21da58fb65SArd Biesheuvel
22da58fb65SArd Biesheuvel int efi_create_mapping(struct mm_struct *mm, efi_memory_desc_t *md);
23*cf1d2ffcSArd Biesheuvel int efi_set_mapping_permissions(struct mm_struct *mm, efi_memory_desc_t *md, bool);
24da58fb65SArd Biesheuvel
25819fc126SMark Rutland #define arch_efi_call_virt_setup() efi_virtmap_load()
26819fc126SMark Rutland #define arch_efi_call_virt_teardown() efi_virtmap_unload()
27da58fb65SArd Biesheuvel
28207a90e5SMark Rutland #define ARCH_EFI_IRQ_FLAGS_MASK \
29207a90e5SMark Rutland (PSR_J_BIT | PSR_E_BIT | PSR_A_BIT | PSR_I_BIT | PSR_F_BIT | \
30207a90e5SMark Rutland PSR_T_BIT | MODE_MASK)
31207a90e5SMark Rutland
efi_set_pgd(struct mm_struct * mm)32da58fb65SArd Biesheuvel static inline void efi_set_pgd(struct mm_struct *mm)
33da58fb65SArd Biesheuvel {
34da58fb65SArd Biesheuvel check_and_switch_context(mm, NULL);
35da58fb65SArd Biesheuvel }
36da58fb65SArd Biesheuvel
37da58fb65SArd Biesheuvel void efi_virtmap_load(void);
38da58fb65SArd Biesheuvel void efi_virtmap_unload(void);
39da58fb65SArd Biesheuvel
40da58fb65SArd Biesheuvel #else
4169e377b2SArd Biesheuvel #define arm_efi_init()
42da58fb65SArd Biesheuvel #endif /* CONFIG_EFI */
43da58fb65SArd Biesheuvel
4481a0bc39SRoy Franz /* arch specific definitions used by the stub code */
4581a0bc39SRoy Franz
4681a0bc39SRoy Franz /*
4781a0bc39SRoy Franz * A reasonable upper bound for the uncompressed kernel size is 32 MBytes,
4881a0bc39SRoy Franz * so we will reserve that amount of memory. We have no easy way to tell what
4981a0bc39SRoy Franz * the actuall size of code + data the uncompressed kernel will use.
5081a0bc39SRoy Franz * If this is insufficient, the decompressor will relocate itself out of the
5181a0bc39SRoy Franz * way before performing the decompression.
5281a0bc39SRoy Franz */
5381a0bc39SRoy Franz #define MAX_UNCOMP_KERNEL_SIZE SZ_32M
5481a0bc39SRoy Franz
5581a0bc39SRoy Franz /*
56c0249238SArd Biesheuvel * phys-to-virt patching requires that the physical to virtual offset is a
57c0249238SArd Biesheuvel * multiple of 2 MiB. However, using an alignment smaller than TEXT_OFFSET
58c0249238SArd Biesheuvel * here throws off the memory allocation logic, so let's use the lowest power
59c0249238SArd Biesheuvel * of two greater than 2 MiB and greater than TEXT_OFFSET.
6081a0bc39SRoy Franz */
61d72c8b0eSArd Biesheuvel #define EFI_PHYS_ALIGN max(UL(SZ_2M), roundup_pow_of_two(TEXT_OFFSET))
62138728ddSArd Biesheuvel
63138728ddSArd Biesheuvel /* on ARM, the initrd should be loaded in a lowmem region */
efi_get_max_initrd_addr(unsigned long image_addr)646208857bSArd Biesheuvel static inline unsigned long efi_get_max_initrd_addr(unsigned long image_addr)
65138728ddSArd Biesheuvel {
66c0249238SArd Biesheuvel return round_down(image_addr, SZ_4M) + SZ_512M;
67138728ddSArd Biesheuvel }
6881a0bc39SRoy Franz
692a55280aSArd Biesheuvel struct efi_arm_entry_state {
702a55280aSArd Biesheuvel u32 cpsr_before_ebs;
712a55280aSArd Biesheuvel u32 sctlr_before_ebs;
722a55280aSArd Biesheuvel u32 cpsr_after_ebs;
732a55280aSArd Biesheuvel u32 sctlr_after_ebs;
742a55280aSArd Biesheuvel };
752a55280aSArd Biesheuvel
efi_capsule_flush_cache_range(void * addr,int size)764dbe44fbSArd Biesheuvel static inline void efi_capsule_flush_cache_range(void *addr, int size)
774dbe44fbSArd Biesheuvel {
784dbe44fbSArd Biesheuvel __cpuc_flush_dcache_area(addr, size);
794dbe44fbSArd Biesheuvel }
804dbe44fbSArd Biesheuvel
81da58fb65SArd Biesheuvel #endif /* _ASM_ARM_EFI_H */
82