forked from ~ljy/RK356X_SDK_RELEASE

hc
2024-01-04 1543e317f1da31b75942316931e8f491a8920811
kernel/arch/arm64/include/asm/virt.h
....@@ -1,18 +1,7 @@
1
+/* SPDX-License-Identifier: GPL-2.0-only */
12 /*
23 * Copyright (C) 2012 ARM Ltd.
34 * 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/>.
165 */
176
187 #ifndef __ASM__VIRT_H
....@@ -46,8 +35,13 @@
4635 */
4736 #define HVC_RESET_VECTORS 2
4837
38
+/*
39
+ * HVC_VHE_RESTART - Upgrade the CPU from EL1 to EL2, if possible
40
+ */
41
+#define HVC_VHE_RESTART 3
42
+
4943 /* Max number of HYP stub hypercalls */
50
-#define HVC_STUB_HCALL_NR 3
44
+#define HVC_STUB_HCALL_NR 4
5145
5246 /* Error returned when an invalid stub number is passed into x0 */
5347 #define HVC_STUB_ERR 0xbadca11
....@@ -76,9 +70,19 @@
7670 void __hyp_set_vectors(phys_addr_t phys_vector_base);
7771 void __hyp_reset_vectors(void);
7872
73
+DECLARE_STATIC_KEY_FALSE(kvm_protected_mode_initialized);
74
+
7975 /* Reports the availability of HYP mode */
8076 static inline bool is_hyp_mode_available(void)
8177 {
78
+ /*
79
+ * If KVM protected mode is initialized, all CPUs must have been booted
80
+ * in EL2. Avoid checking __boot_cpu_mode as CPUs now come up in EL1.
81
+ */
82
+ if (IS_ENABLED(CONFIG_KVM) &&
83
+ static_branch_likely(&kvm_protected_mode_initialized))
84
+ return true;
85
+
8286 return (__boot_cpu_mode[0] == BOOT_CPU_MODE_EL2 &&
8387 __boot_cpu_mode[1] == BOOT_CPU_MODE_EL2);
8488 }
....@@ -86,6 +90,14 @@
8690 /* Check if the bootloader has booted CPUs in different modes */
8791 static inline bool is_hyp_mode_mismatched(void)
8892 {
93
+ /*
94
+ * If KVM protected mode is initialized, all CPUs must have been booted
95
+ * in EL2. Avoid checking __boot_cpu_mode as CPUs now come up in EL1.
96
+ */
97
+ if (IS_ENABLED(CONFIG_KVM) &&
98
+ static_branch_likely(&kvm_protected_mode_initialized))
99
+ return false;
100
+
89101 return __boot_cpu_mode[0] != __boot_cpu_mode[1];
90102 }
91103
....@@ -94,12 +106,26 @@
94106 return read_sysreg(CurrentEL) == CurrentEL_EL2;
95107 }
96108
97
-static inline bool has_vhe(void)
109
+static __always_inline bool has_vhe(void)
98110 {
99
- if (cpus_have_const_cap(ARM64_HAS_VIRT_HOST_EXTN))
111
+ /*
112
+ * Code only run in VHE/NVHE hyp context can assume VHE is present or
113
+ * absent. Otherwise fall back to caps.
114
+ */
115
+ if (is_vhe_hyp_code())
100116 return true;
117
+ else if (is_nvhe_hyp_code())
118
+ return false;
119
+ else
120
+ return cpus_have_final_cap(ARM64_HAS_VIRT_HOST_EXTN);
121
+}
101122
102
- return false;
123
+static __always_inline bool is_protected_kvm_enabled(void)
124
+{
125
+ if (is_vhe_hyp_code())
126
+ return false;
127
+ else
128
+ return cpus_have_final_cap(ARM64_KVM_PROTECTED_MODE);
103129 }
104130
105131 #endif /* __ASSEMBLY__ */