Thomas Gleixner | 1621633 | 2019-05-19 15:51:31 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-or-later */ |
Dave Martin | 80c59da | 2012-02-09 08:47:17 -0800 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (c) 2012 Linaro Limited. |
Dave Martin | 80c59da | 2012-02-09 08:47:17 -0800 | [diff] [blame] | 4 | */ |
| 5 | |
| 6 | #ifndef VIRT_H |
| 7 | #define VIRT_H |
| 8 | |
| 9 | #include <asm/ptrace.h> |
| 10 | |
| 11 | /* |
| 12 | * Flag indicating that the kernel was not entered in the same mode on every |
| 13 | * CPU. The zImage loader stashes this value in an SPSR, so we need an |
Will Deacon | 4e3c194 | 2012-12-02 17:44:36 +0000 | [diff] [blame] | 14 | * architecturally defined flag bit here. |
Dave Martin | 80c59da | 2012-02-09 08:47:17 -0800 | [diff] [blame] | 15 | */ |
Will Deacon | 4e3c194 | 2012-12-02 17:44:36 +0000 | [diff] [blame] | 16 | #define BOOT_CPU_MODE_MISMATCH PSR_N_BIT |
Dave Martin | 80c59da | 2012-02-09 08:47:17 -0800 | [diff] [blame] | 17 | |
| 18 | #ifndef __ASSEMBLY__ |
Mark Rutland | 8fbac21 | 2013-07-18 17:20:33 +0100 | [diff] [blame] | 19 | #include <asm/cacheflush.h> |
Dave Martin | 80c59da | 2012-02-09 08:47:17 -0800 | [diff] [blame] | 20 | |
| 21 | #ifdef CONFIG_ARM_VIRT_EXT |
| 22 | /* |
| 23 | * __boot_cpu_mode records what mode the primary CPU was booted in. |
| 24 | * A correctly-implemented bootloader must start all CPUs in the same mode: |
| 25 | * if it fails to do this, the flag BOOT_CPU_MODE_MISMATCH is set to indicate |
| 26 | * that some CPU(s) were booted in a different mode. |
| 27 | * |
| 28 | * This allows the kernel to flag an error when the secondaries have come up. |
| 29 | */ |
| 30 | extern int __boot_cpu_mode; |
| 31 | |
Mark Rutland | 8fbac21 | 2013-07-18 17:20:33 +0100 | [diff] [blame] | 32 | static inline void sync_boot_mode(void) |
| 33 | { |
| 34 | /* |
| 35 | * As secondaries write to __boot_cpu_mode with caches disabled, we |
| 36 | * must flush the corresponding cache entries to ensure the visibility |
| 37 | * of their writes. |
| 38 | */ |
| 39 | sync_cache_r(&__boot_cpu_mode); |
| 40 | } |
| 41 | |
Dave Martin | 80c59da | 2012-02-09 08:47:17 -0800 | [diff] [blame] | 42 | void __hyp_set_vectors(unsigned long phys_vector_base); |
Marc Zyngier | bc845e4 | 2017-04-03 19:37:53 +0100 | [diff] [blame] | 43 | void __hyp_reset_vectors(void); |
Dave Martin | 80c59da | 2012-02-09 08:47:17 -0800 | [diff] [blame] | 44 | #else |
| 45 | #define __boot_cpu_mode (SVC_MODE) |
Mark Rutland | 8fbac21 | 2013-07-18 17:20:33 +0100 | [diff] [blame] | 46 | #define sync_boot_mode() |
Dave Martin | 80c59da | 2012-02-09 08:47:17 -0800 | [diff] [blame] | 47 | #endif |
| 48 | |
Dave Martin | 4588c34 | 2012-02-17 16:54:28 +0000 | [diff] [blame] | 49 | #ifndef ZIMAGE |
| 50 | void hyp_mode_check(void); |
| 51 | |
| 52 | /* Reports the availability of HYP mode */ |
| 53 | static inline bool is_hyp_mode_available(void) |
| 54 | { |
| 55 | return ((__boot_cpu_mode & MODE_MASK) == HYP_MODE && |
| 56 | !(__boot_cpu_mode & BOOT_CPU_MODE_MISMATCH)); |
| 57 | } |
| 58 | |
| 59 | /* Check if the bootloader has booted CPUs in different modes */ |
| 60 | static inline bool is_hyp_mode_mismatched(void) |
| 61 | { |
| 62 | return !!(__boot_cpu_mode & BOOT_CPU_MODE_MISMATCH); |
| 63 | } |
Marc Zyngier | 1a61ae7 | 2016-01-02 13:57:18 +0000 | [diff] [blame] | 64 | |
Marc Zyngier | 82deae0 | 2014-06-09 19:47:09 +0100 | [diff] [blame] | 65 | static inline bool is_kernel_in_hyp_mode(void) |
| 66 | { |
| 67 | return false; |
| 68 | } |
| 69 | |
Jintack Lim | 488f94d | 2016-12-01 14:32:05 -0500 | [diff] [blame] | 70 | static inline bool has_vhe(void) |
| 71 | { |
| 72 | return false; |
| 73 | } |
| 74 | |
Marc Zyngier | 1df3e23 | 2016-06-30 18:40:41 +0100 | [diff] [blame] | 75 | /* The section containing the hypervisor idmap text */ |
| 76 | extern char __hyp_idmap_text_start[]; |
| 77 | extern char __hyp_idmap_text_end[]; |
| 78 | |
Marc Zyngier | 1a61ae7 | 2016-01-02 13:57:18 +0000 | [diff] [blame] | 79 | /* The section containing the hypervisor text */ |
| 80 | extern char __hyp_text_start[]; |
| 81 | extern char __hyp_text_end[]; |
Dave Martin | 4588c34 | 2012-02-17 16:54:28 +0000 | [diff] [blame] | 82 | #endif |
| 83 | |
Marc Zyngier | 467f97b | 2017-04-03 19:37:47 +0100 | [diff] [blame] | 84 | #else |
| 85 | |
| 86 | /* Only assembly code should need those */ |
| 87 | |
Marc Zyngier | ecb5d61 | 2017-04-03 19:38:03 +0100 | [diff] [blame] | 88 | #define HVC_SET_VECTORS 0 |
| 89 | #define HVC_SOFT_RESTART 1 |
| 90 | #define HVC_RESET_VECTORS 2 |
Marc Zyngier | 7d1bf4e | 2017-04-03 19:37:52 +0100 | [diff] [blame] | 91 | |
Marc Zyngier | ecb5d61 | 2017-04-03 19:38:03 +0100 | [diff] [blame] | 92 | #define HVC_STUB_HCALL_NR 3 |
Marc Zyngier | 467f97b | 2017-04-03 19:37:47 +0100 | [diff] [blame] | 93 | |
Dave Martin | 80c59da | 2012-02-09 08:47:17 -0800 | [diff] [blame] | 94 | #endif /* __ASSEMBLY__ */ |
| 95 | |
Marc Zyngier | 4c70cf0 | 2017-04-03 19:37:51 +0100 | [diff] [blame] | 96 | #define HVC_STUB_ERR 0xbadca11 |
| 97 | |
Dave Martin | 80c59da | 2012-02-09 08:47:17 -0800 | [diff] [blame] | 98 | #endif /* ! VIRT_H */ |