blob: c4cd5081d78bc4b66e34f3c283d9b1f6ba48518c [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001/* SPDX-License-Identifier: GPL-2.0 */
Mark Salterf84d0272014-04-15 21:59:30 -04002#ifndef _ASM_EFI_H
3#define _ASM_EFI_H
4
Ard Biesheuvel24d7c492017-04-04 17:02:39 +01005#include <asm/boot.h>
Catalin Marinas39bc88e2016-09-02 14:54:03 +01006#include <asm/cpufeature.h>
Dave Martin4328825d2017-08-03 17:23:22 +01007#include <asm/fpsimd.h>
Mark Salterf84d0272014-04-15 21:59:30 -04008#include <asm/io.h>
Mark Rutland170976b2017-07-14 15:54:36 +01009#include <asm/memory.h>
Ard Biesheuvelf7d92482015-11-30 13:28:19 +010010#include <asm/mmu_context.h>
Ard Biesheuvele15dd492014-07-04 19:41:53 +020011#include <asm/neon.h>
Mark Rutlandee6cab52016-04-25 21:07:09 +010012#include <asm/ptrace.h>
Ard Biesheuvelf7d92482015-11-30 13:28:19 +010013#include <asm/tlbflush.h>
Mark Salterf84d0272014-04-15 21:59:30 -040014
15#ifdef CONFIG_EFI
16extern void efi_init(void);
Mark Salterf84d0272014-04-15 21:59:30 -040017#else
18#define efi_init()
Mark Salterf84d0272014-04-15 21:59:30 -040019#endif
20
Ard Biesheuvelf7d92482015-11-30 13:28:19 +010021int efi_create_mapping(struct mm_struct *mm, efi_memory_desc_t *md);
Ard Biesheuvelbd264d02016-06-29 14:51:27 +020022int efi_set_mapping_permissions(struct mm_struct *mm, efi_memory_desc_t *md);
Ard Biesheuvel789957e2016-04-25 21:06:46 +010023
Mark Rutland489f80f2016-04-25 21:07:04 +010024#define arch_efi_call_virt_setup() \
Ard Biesheuvele15dd492014-07-04 19:41:53 +020025({ \
Ard Biesheuvelf3cdfd22014-10-20 16:27:26 +020026 efi_virtmap_load(); \
Dave Martin4328825d2017-08-03 17:23:22 +010027 __efi_fpsimd_begin(); \
Ard Biesheuvele15dd492014-07-04 19:41:53 +020028})
29
Alex Thorlton80e75592016-06-25 08:20:27 +010030#define arch_efi_call_virt(p, f, args...) \
Ard Biesheuvele15dd492014-07-04 19:41:53 +020031({ \
Ard Biesheuvelf3cdfd22014-10-20 16:27:26 +020032 efi_##f##_t *__f; \
Alex Thorlton80e75592016-06-25 08:20:27 +010033 __f = p->f; \
Mark Rutland489f80f2016-04-25 21:07:04 +010034 __f(args); \
35})
36
37#define arch_efi_call_virt_teardown() \
38({ \
Dave Martin4328825d2017-08-03 17:23:22 +010039 __efi_fpsimd_end(); \
Ard Biesheuvelf3cdfd22014-10-20 16:27:26 +020040 efi_virtmap_unload(); \
Ard Biesheuvele15dd492014-07-04 19:41:53 +020041})
42
Mark Rutlandee6cab52016-04-25 21:07:09 +010043#define ARCH_EFI_IRQ_FLAGS_MASK (PSR_D_BIT | PSR_A_BIT | PSR_I_BIT | PSR_F_BIT)
44
Ard Biesheuvela13b0072014-07-02 14:54:41 +020045/* arch specific definitions used by the stub code */
46
47/*
48 * AArch64 requires the DTB to be 8-byte aligned in the first 512MiB from
49 * start of kernel and may not cross a 2MiB boundary. We set alignment to
50 * 2MiB so we know it won't cross a 2MiB boundary.
51 */
52#define EFI_FDT_ALIGN SZ_2M /* used by allocate_new_fdt_and_exit_boot() */
Ard Biesheuvel138728dd2017-04-04 17:02:37 +010053
Mark Rutlande3067862017-07-21 14:25:33 +010054/*
55 * In some configurations (e.g. VMAP_STACK && 64K pages), stacks built into the
56 * kernel need greater alignment than we require the segments to be padded to.
57 */
58#define EFI_KIMG_ALIGN \
59 (SEGMENT_ALIGN > THREAD_ALIGN ? SEGMENT_ALIGN : THREAD_ALIGN)
Mark Rutland170976b2017-07-14 15:54:36 +010060
Ard Biesheuvel138728dd2017-04-04 17:02:37 +010061/* on arm64, the FDT may be located anywhere in system RAM */
62static inline unsigned long efi_get_max_fdt_addr(unsigned long dram_base)
63{
64 return ULONG_MAX;
65}
66
67/*
68 * On arm64, we have to ensure that the initrd ends up in the linear region,
69 * which is a 1 GB aligned region of size '1UL << (VA_BITS - 1)' that is
70 * guaranteed to cover the kernel Image.
71 *
72 * Since the EFI stub is part of the kernel Image, we can relax the
73 * usual requirements in Documentation/arm64/booting.txt, which still
74 * apply to other bootloaders, and are required for some kernel
75 * configurations.
76 */
77static inline unsigned long efi_get_max_initrd_addr(unsigned long dram_base,
78 unsigned long image_addr)
79{
80 return (image_addr & ~(SZ_1G - 1UL)) + (1UL << (VA_BITS - 1));
81}
Ard Biesheuvela13b0072014-07-02 14:54:41 +020082
Ard Biesheuvelfc372062016-04-25 21:06:49 +010083#define efi_call_early(f, ...) sys_table_arg->boottime->f(__VA_ARGS__)
84#define __efi_call_early(f, ...) f(__VA_ARGS__)
David Howells6d0ca4a2017-02-06 11:22:41 +000085#define efi_call_runtime(f, ...) sys_table_arg->runtime->f(__VA_ARGS__)
Ard Biesheuvelfc372062016-04-25 21:06:49 +010086#define efi_is_64bit() (true)
Ard Biesheuvela13b0072014-07-02 14:54:41 +020087
Lukas Wunner3552fdf2016-11-12 21:32:35 +000088#define efi_call_proto(protocol, f, instance, ...) \
89 ((protocol##_t *)instance)->f(instance, ##__VA_ARGS__)
90
Ard Biesheuvel57fdb89a2016-04-25 21:06:52 +010091#define alloc_screen_info(x...) &screen_info
92#define free_screen_info(x...)
93
Ard Biesheuvel760b61d2017-08-18 20:49:35 +010094/* redeclare as 'hidden' so the compiler will generate relative references */
95extern struct screen_info screen_info __attribute__((__visibility__("hidden")));
96
Ard Biesheuvel98225042016-04-25 21:06:56 +010097static inline void efifb_setup_from_dmi(struct screen_info *si, const char *opt)
98{
99}
100
Ard Biesheuvel1bd0abb2014-11-17 13:50:21 +0100101#define EFI_ALLOC_ALIGN SZ_64K
102
Ard Biesheuvelf3cdfd22014-10-20 16:27:26 +0200103/*
Ard Biesheuvel60305db2015-01-22 10:01:40 +0000104 * On ARM systems, virtually remapped UEFI runtime services are set up in two
Ard Biesheuvelf3cdfd22014-10-20 16:27:26 +0200105 * distinct stages:
106 * - The stub retrieves the final version of the memory map from UEFI, populates
107 * the virt_addr fields and calls the SetVirtualAddressMap() [SVAM] runtime
108 * service to communicate the new mapping to the firmware (Note that the new
109 * mapping is not live at this time)
Ard Biesheuvel60305db2015-01-22 10:01:40 +0000110 * - During an early initcall(), the EFI system table is permanently remapped
111 * and the virtual remapping of the UEFI Runtime Services regions is loaded
112 * into a private set of page tables. If this all succeeds, the Runtime
113 * Services are enabled and the EFI_RUNTIME_SERVICES bit set.
Ard Biesheuvelf3cdfd22014-10-20 16:27:26 +0200114 */
Ard Biesheuvelf3cdfd22014-10-20 16:27:26 +0200115
Ard Biesheuvelf7d92482015-11-30 13:28:19 +0100116static inline void efi_set_pgd(struct mm_struct *mm)
117{
Catalin Marinas39bc88e2016-09-02 14:54:03 +0100118 __switch_mm(mm);
119
120 if (system_uses_ttbr0_pan()) {
121 if (mm != current->active_mm) {
122 /*
123 * Update the current thread's saved ttbr0 since it is
124 * restored as part of a return from exception. Set
125 * the hardware TTBR0_EL1 using cpu_switch_mm()
126 * directly to enable potential errata workarounds.
127 */
128 update_saved_ttbr0(current, mm);
129 cpu_switch_mm(mm->pgd, mm);
130 } else {
131 /*
132 * Defer the switch to the current thread's TTBR0_EL1
133 * until uaccess_enable(). Restore the current
134 * thread's saved ttbr0 corresponding to its active_mm
Catalin Marinas39bc88e2016-09-02 14:54:03 +0100135 */
136 cpu_set_reserved_ttbr0();
Will Deacon0adbdfd2017-12-06 10:42:10 +0000137 update_saved_ttbr0(current, current->active_mm);
Catalin Marinas39bc88e2016-09-02 14:54:03 +0100138 }
139 }
Ard Biesheuvelf7d92482015-11-30 13:28:19 +0100140}
141
Ard Biesheuvelf3cdfd22014-10-20 16:27:26 +0200142void efi_virtmap_load(void);
143void efi_virtmap_unload(void);
144
Mark Salterf84d0272014-04-15 21:59:30 -0400145#endif /* _ASM_EFI_H */