blob: bbc6a8cf83f1f5e123b309e31f3bf9ff6445fb43 [file] [log] [blame]
Marc Zyngierf35a9202012-10-26 15:40:05 +01001/*
2 * Copyright (C) 2012 ARM Ltd.
3 * Author: Marc Zyngier <marc.zyngier@arm.com>
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2 as
7 * published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18#ifndef __ASM__VIRT_H
19#define __ASM__VIRT_H
20
Geoff Levandad72e592016-04-27 17:47:03 +010021/*
22 * The arm64 hcall implementation uses x0 to specify the hcall type. A value
23 * less than 0xfff indicates a special hcall, such as get/set vector.
24 * Any other value is used as a pointer to the function to call.
25 */
26
27/* HVC_GET_VECTORS - Return the value of the vbar_el2 register. */
28#define HVC_GET_VECTORS 0
29
30/*
31 * HVC_SET_VECTORS - Set the value of the vbar_el2 register.
32 *
33 * @x1: Physical address of the new vector table.
34 */
35#define HVC_SET_VECTORS 1
36
Geoff Levandf9076ec2016-06-23 17:54:48 +000037/*
38 * HVC_SOFT_RESTART - CPU soft reset, used by the cpu_soft_restart routine.
39 */
40#define HVC_SOFT_RESTART 2
41
Matthew Leach828e9832013-10-11 14:52:16 +010042#define BOOT_CPU_MODE_EL1 (0xe11)
43#define BOOT_CPU_MODE_EL2 (0xe12)
Marc Zyngierf35a9202012-10-26 15:40:05 +010044
45#ifndef __ASSEMBLY__
46
Marc Zyngier82deae02014-06-09 19:47:09 +010047#include <asm/ptrace.h>
48
Marc Zyngierf35a9202012-10-26 15:40:05 +010049/*
50 * __boot_cpu_mode records what mode CPUs were booted in.
51 * A correctly-implemented bootloader must start all CPUs in the same mode:
52 * In this case, both 32bit halves of __boot_cpu_mode will contain the
53 * same value (either 0 if booted in EL1, BOOT_CPU_MODE_EL2 if booted in EL2).
54 *
55 * Should the bootloader fail to do this, the two values will be different.
56 * This allows the kernel to flag an error when the secondaries have come up.
57 */
58extern u32 __boot_cpu_mode[2];
59
Marc Zyngier712c6ff2012-10-19 17:46:27 +010060void __hyp_set_vectors(phys_addr_t phys_vector_base);
61phys_addr_t __hyp_get_vectors(void);
62
Marc Zyngierf35a9202012-10-26 15:40:05 +010063/* Reports the availability of HYP mode */
64static inline bool is_hyp_mode_available(void)
65{
66 return (__boot_cpu_mode[0] == BOOT_CPU_MODE_EL2 &&
67 __boot_cpu_mode[1] == BOOT_CPU_MODE_EL2);
68}
69
70/* Check if the bootloader has booted CPUs in different modes */
71static inline bool is_hyp_mode_mismatched(void)
72{
Marc Zyngierf35a9202012-10-26 15:40:05 +010073 return __boot_cpu_mode[0] != __boot_cpu_mode[1];
74}
75
Marc Zyngier82deae02014-06-09 19:47:09 +010076static inline bool is_kernel_in_hyp_mode(void)
77{
78 u64 el;
79
80 asm("mrs %0, CurrentEL" : "=r" (el));
81 return el == CurrentEL_EL2;
82}
83
Suzuki K Pouloseac1ad202016-04-13 14:41:33 +010084#ifdef CONFIG_ARM64_VHE
85extern void verify_cpu_run_el(void);
86#else
87static inline void verify_cpu_run_el(void) {}
88#endif
89
Marc Zyngier45451912013-06-26 15:16:40 +010090/* The section containing the hypervisor text */
91extern char __hyp_text_start[];
92extern char __hyp_text_end[];
93
Marc Zyngierf35a9202012-10-26 15:40:05 +010094#endif /* __ASSEMBLY__ */
95
96#endif /* ! __ASM__VIRT_H */