Marc Zyngier | f35a920 | 2012-10-26 15:40:05 +0100 | [diff] [blame] | 1 | /* |
| 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 Levand | ad72e59 | 2016-04-27 17:47:03 +0100 | [diff] [blame] | 21 | /* |
Marc Zyngier | 810c86e | 2017-04-03 19:37:38 +0100 | [diff] [blame] | 22 | * The arm64 hcall implementation uses x0 to specify the hcall |
| 23 | * number. A value less than HVC_STUB_HCALL_NR indicates a special |
| 24 | * hcall, such as set vector. Any other value is handled in a |
| 25 | * hypervisor specific way. |
| 26 | * |
| 27 | * The hypercall is allowed to clobber any of the caller-saved |
| 28 | * registers (x0-x18), so it is advisable to use it through the |
| 29 | * indirection of a function call (as implemented in hyp-stub.S). |
Geoff Levand | ad72e59 | 2016-04-27 17:47:03 +0100 | [diff] [blame] | 30 | */ |
| 31 | |
Geoff Levand | ad72e59 | 2016-04-27 17:47:03 +0100 | [diff] [blame] | 32 | /* |
| 33 | * HVC_SET_VECTORS - Set the value of the vbar_el2 register. |
| 34 | * |
| 35 | * @x1: Physical address of the new vector table. |
| 36 | */ |
Marc Zyngier | 0b51c54 | 2017-04-03 19:38:04 +0100 | [diff] [blame] | 37 | #define HVC_SET_VECTORS 0 |
Geoff Levand | ad72e59 | 2016-04-27 17:47:03 +0100 | [diff] [blame] | 38 | |
Geoff Levand | f9076ec | 2016-06-23 17:54:48 +0000 | [diff] [blame] | 39 | /* |
| 40 | * HVC_SOFT_RESTART - CPU soft reset, used by the cpu_soft_restart routine. |
| 41 | */ |
Marc Zyngier | 0b51c54 | 2017-04-03 19:38:04 +0100 | [diff] [blame] | 42 | #define HVC_SOFT_RESTART 1 |
Geoff Levand | f9076ec | 2016-06-23 17:54:48 +0000 | [diff] [blame] | 43 | |
Marc Zyngier | fd0e0c6 | 2017-04-03 19:37:39 +0100 | [diff] [blame] | 44 | /* |
| 45 | * HVC_RESET_VECTORS - Restore the vectors to the original HYP stubs |
| 46 | */ |
Marc Zyngier | 0b51c54 | 2017-04-03 19:38:04 +0100 | [diff] [blame] | 47 | #define HVC_RESET_VECTORS 2 |
Marc Zyngier | fd0e0c6 | 2017-04-03 19:37:39 +0100 | [diff] [blame] | 48 | |
| 49 | /* Max number of HYP stub hypercalls */ |
Marc Zyngier | 0b51c54 | 2017-04-03 19:38:04 +0100 | [diff] [blame] | 50 | #define HVC_STUB_HCALL_NR 3 |
Marc Zyngier | fd0e0c6 | 2017-04-03 19:37:39 +0100 | [diff] [blame] | 51 | |
Marc Zyngier | 4993fdc | 2017-04-03 19:37:37 +0100 | [diff] [blame] | 52 | /* Error returned when an invalid stub number is passed into x0 */ |
| 53 | #define HVC_STUB_ERR 0xbadca11 |
| 54 | |
Matthew Leach | 828e983 | 2013-10-11 14:52:16 +0100 | [diff] [blame] | 55 | #define BOOT_CPU_MODE_EL1 (0xe11) |
| 56 | #define BOOT_CPU_MODE_EL2 (0xe12) |
Marc Zyngier | f35a920 | 2012-10-26 15:40:05 +0100 | [diff] [blame] | 57 | |
| 58 | #ifndef __ASSEMBLY__ |
| 59 | |
Marc Zyngier | 82deae0 | 2014-06-09 19:47:09 +0100 | [diff] [blame] | 60 | #include <asm/ptrace.h> |
James Morse | ee78fdc | 2016-08-24 18:27:28 +0100 | [diff] [blame] | 61 | #include <asm/sections.h> |
Mark Rutland | 1f3d869 | 2016-09-08 13:55:37 +0100 | [diff] [blame] | 62 | #include <asm/sysreg.h> |
Jintack Lim | 488f94d | 2016-12-01 14:32:05 -0500 | [diff] [blame] | 63 | #include <asm/cpufeature.h> |
Marc Zyngier | 82deae0 | 2014-06-09 19:47:09 +0100 | [diff] [blame] | 64 | |
Marc Zyngier | f35a920 | 2012-10-26 15:40:05 +0100 | [diff] [blame] | 65 | /* |
| 66 | * __boot_cpu_mode records what mode CPUs were booted in. |
| 67 | * A correctly-implemented bootloader must start all CPUs in the same mode: |
| 68 | * In this case, both 32bit halves of __boot_cpu_mode will contain the |
| 69 | * same value (either 0 if booted in EL1, BOOT_CPU_MODE_EL2 if booted in EL2). |
| 70 | * |
| 71 | * Should the bootloader fail to do this, the two values will be different. |
| 72 | * This allows the kernel to flag an error when the secondaries have come up. |
| 73 | */ |
| 74 | extern u32 __boot_cpu_mode[2]; |
| 75 | |
Marc Zyngier | 712c6ff | 2012-10-19 17:46:27 +0100 | [diff] [blame] | 76 | void __hyp_set_vectors(phys_addr_t phys_vector_base); |
Marc Zyngier | fd0e0c6 | 2017-04-03 19:37:39 +0100 | [diff] [blame] | 77 | void __hyp_reset_vectors(void); |
Marc Zyngier | 712c6ff | 2012-10-19 17:46:27 +0100 | [diff] [blame] | 78 | |
Marc Zyngier | f35a920 | 2012-10-26 15:40:05 +0100 | [diff] [blame] | 79 | /* Reports the availability of HYP mode */ |
| 80 | static inline bool is_hyp_mode_available(void) |
| 81 | { |
| 82 | return (__boot_cpu_mode[0] == BOOT_CPU_MODE_EL2 && |
| 83 | __boot_cpu_mode[1] == BOOT_CPU_MODE_EL2); |
| 84 | } |
| 85 | |
| 86 | /* Check if the bootloader has booted CPUs in different modes */ |
| 87 | static inline bool is_hyp_mode_mismatched(void) |
| 88 | { |
Marc Zyngier | f35a920 | 2012-10-26 15:40:05 +0100 | [diff] [blame] | 89 | return __boot_cpu_mode[0] != __boot_cpu_mode[1]; |
| 90 | } |
| 91 | |
Marc Zyngier | 82deae0 | 2014-06-09 19:47:09 +0100 | [diff] [blame] | 92 | static inline bool is_kernel_in_hyp_mode(void) |
| 93 | { |
Mark Rutland | 1f3d869 | 2016-09-08 13:55:37 +0100 | [diff] [blame] | 94 | return read_sysreg(CurrentEL) == CurrentEL_EL2; |
Marc Zyngier | 82deae0 | 2014-06-09 19:47:09 +0100 | [diff] [blame] | 95 | } |
| 96 | |
Jintack Lim | 488f94d | 2016-12-01 14:32:05 -0500 | [diff] [blame] | 97 | static inline bool has_vhe(void) |
| 98 | { |
| 99 | if (cpus_have_const_cap(ARM64_HAS_VIRT_HOST_EXTN)) |
| 100 | return true; |
| 101 | |
| 102 | return false; |
| 103 | } |
| 104 | |
Suzuki K Poulose | ac1ad20 | 2016-04-13 14:41:33 +0100 | [diff] [blame] | 105 | #ifdef CONFIG_ARM64_VHE |
| 106 | extern void verify_cpu_run_el(void); |
| 107 | #else |
| 108 | static inline void verify_cpu_run_el(void) {} |
| 109 | #endif |
| 110 | |
Marc Zyngier | f35a920 | 2012-10-26 15:40:05 +0100 | [diff] [blame] | 111 | #endif /* __ASSEMBLY__ */ |
| 112 | |
| 113 | #endif /* ! __ASM__VIRT_H */ |