diff options
Diffstat (limited to 'arch/arm64/include/asm/kvm_emulate.h')
-rw-r--r-- | arch/arm64/include/asm/kvm_emulate.h | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/arch/arm64/include/asm/kvm_emulate.h b/arch/arm64/include/asm/kvm_emulate.h index eec073875218..dd8ecfc3f995 100644 --- a/arch/arm64/include/asm/kvm_emulate.h +++ b/arch/arm64/include/asm/kvm_emulate.h | |||
@@ -177,4 +177,65 @@ static inline u8 kvm_vcpu_trap_get_fault(const struct kvm_vcpu *vcpu) | |||
177 | return kvm_vcpu_get_hsr(vcpu) & ESR_EL2_FSC_TYPE; | 177 | return kvm_vcpu_get_hsr(vcpu) & ESR_EL2_FSC_TYPE; |
178 | } | 178 | } |
179 | 179 | ||
180 | static inline unsigned long kvm_vcpu_get_mpidr(struct kvm_vcpu *vcpu) | ||
181 | { | ||
182 | return vcpu_sys_reg(vcpu, MPIDR_EL1); | ||
183 | } | ||
184 | |||
185 | static inline void kvm_vcpu_set_be(struct kvm_vcpu *vcpu) | ||
186 | { | ||
187 | if (vcpu_mode_is_32bit(vcpu)) | ||
188 | *vcpu_cpsr(vcpu) |= COMPAT_PSR_E_BIT; | ||
189 | else | ||
190 | vcpu_sys_reg(vcpu, SCTLR_EL1) |= (1 << 25); | ||
191 | } | ||
192 | |||
193 | static inline bool kvm_vcpu_is_be(struct kvm_vcpu *vcpu) | ||
194 | { | ||
195 | if (vcpu_mode_is_32bit(vcpu)) | ||
196 | return !!(*vcpu_cpsr(vcpu) & COMPAT_PSR_E_BIT); | ||
197 | |||
198 | return !!(vcpu_sys_reg(vcpu, SCTLR_EL1) & (1 << 25)); | ||
199 | } | ||
200 | |||
201 | static inline unsigned long vcpu_data_guest_to_host(struct kvm_vcpu *vcpu, | ||
202 | unsigned long data, | ||
203 | unsigned int len) | ||
204 | { | ||
205 | if (kvm_vcpu_is_be(vcpu)) { | ||
206 | switch (len) { | ||
207 | case 1: | ||
208 | return data & 0xff; | ||
209 | case 2: | ||
210 | return be16_to_cpu(data & 0xffff); | ||
211 | case 4: | ||
212 | return be32_to_cpu(data & 0xffffffff); | ||
213 | default: | ||
214 | return be64_to_cpu(data); | ||
215 | } | ||
216 | } | ||
217 | |||
218 | return data; /* Leave LE untouched */ | ||
219 | } | ||
220 | |||
221 | static inline unsigned long vcpu_data_host_to_guest(struct kvm_vcpu *vcpu, | ||
222 | unsigned long data, | ||
223 | unsigned int len) | ||
224 | { | ||
225 | if (kvm_vcpu_is_be(vcpu)) { | ||
226 | switch (len) { | ||
227 | case 1: | ||
228 | return data & 0xff; | ||
229 | case 2: | ||
230 | return cpu_to_be16(data & 0xffff); | ||
231 | case 4: | ||
232 | return cpu_to_be32(data & 0xffffffff); | ||
233 | default: | ||
234 | return cpu_to_be64(data); | ||
235 | } | ||
236 | } | ||
237 | |||
238 | return data; /* Leave LE untouched */ | ||
239 | } | ||
240 | |||
180 | #endif /* __ARM64_KVM_EMULATE_H__ */ | 241 | #endif /* __ARM64_KVM_EMULATE_H__ */ |