xref: /linux/arch/arm64/include/asm/virt.h (revision 712c6ff4dba4917a440be601dc312506322bffe8)
1f35a9205SMarc Zyngier /*
2f35a9205SMarc Zyngier  * Copyright (C) 2012 ARM Ltd.
3f35a9205SMarc Zyngier  * Author: Marc Zyngier <marc.zyngier@arm.com>
4f35a9205SMarc Zyngier  *
5f35a9205SMarc Zyngier  * This program is free software: you can redistribute it and/or modify
6f35a9205SMarc Zyngier  * it under the terms of the GNU General Public License version 2 as
7f35a9205SMarc Zyngier  * published by the Free Software Foundation.
8f35a9205SMarc Zyngier  *
9f35a9205SMarc Zyngier  * This program is distributed in the hope that it will be useful,
10f35a9205SMarc Zyngier  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11f35a9205SMarc Zyngier  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12f35a9205SMarc Zyngier  * GNU General Public License for more details.
13f35a9205SMarc Zyngier  *
14f35a9205SMarc Zyngier  * You should have received a copy of the GNU General Public License
15f35a9205SMarc Zyngier  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
16f35a9205SMarc Zyngier  */
17f35a9205SMarc Zyngier 
18f35a9205SMarc Zyngier #ifndef __ASM__VIRT_H
19f35a9205SMarc Zyngier #define __ASM__VIRT_H
20f35a9205SMarc Zyngier 
21f35a9205SMarc Zyngier #define BOOT_CPU_MODE_EL2	(0x0e12b007)
22f35a9205SMarc Zyngier 
23f35a9205SMarc Zyngier #ifndef __ASSEMBLY__
24f35a9205SMarc Zyngier 
25f35a9205SMarc Zyngier /*
26f35a9205SMarc Zyngier  * __boot_cpu_mode records what mode CPUs were booted in.
27f35a9205SMarc Zyngier  * A correctly-implemented bootloader must start all CPUs in the same mode:
28f35a9205SMarc Zyngier  * In this case, both 32bit halves of __boot_cpu_mode will contain the
29f35a9205SMarc Zyngier  * same value (either 0 if booted in EL1, BOOT_CPU_MODE_EL2 if booted in EL2).
30f35a9205SMarc Zyngier  *
31f35a9205SMarc Zyngier  * Should the bootloader fail to do this, the two values will be different.
32f35a9205SMarc Zyngier  * This allows the kernel to flag an error when the secondaries have come up.
33f35a9205SMarc Zyngier  */
34f35a9205SMarc Zyngier extern u32 __boot_cpu_mode[2];
35f35a9205SMarc Zyngier 
36*712c6ff4SMarc Zyngier void __hyp_set_vectors(phys_addr_t phys_vector_base);
37*712c6ff4SMarc Zyngier phys_addr_t __hyp_get_vectors(void);
38*712c6ff4SMarc Zyngier 
39f35a9205SMarc Zyngier /* Reports the availability of HYP mode */
40f35a9205SMarc Zyngier static inline bool is_hyp_mode_available(void)
41f35a9205SMarc Zyngier {
42f35a9205SMarc Zyngier 	return (__boot_cpu_mode[0] == BOOT_CPU_MODE_EL2 &&
43f35a9205SMarc Zyngier 		__boot_cpu_mode[1] == BOOT_CPU_MODE_EL2);
44f35a9205SMarc Zyngier }
45f35a9205SMarc Zyngier 
46f35a9205SMarc Zyngier /* Check if the bootloader has booted CPUs in different modes */
47f35a9205SMarc Zyngier static inline bool is_hyp_mode_mismatched(void)
48f35a9205SMarc Zyngier {
49f35a9205SMarc Zyngier 	return __boot_cpu_mode[0] != __boot_cpu_mode[1];
50f35a9205SMarc Zyngier }
51f35a9205SMarc Zyngier 
52f35a9205SMarc Zyngier #endif /* __ASSEMBLY__ */
53f35a9205SMarc Zyngier 
54f35a9205SMarc Zyngier #endif /* ! __ASM__VIRT_H */
55