aboutsummaryrefslogtreecommitdiffstats
path: root/arch/arm64
diff options
context:
space:
mode:
authorMarc Zyngier <marc.zyngier@arm.com>2013-02-12 07:40:22 -0500
committerMarc Zyngier <marc.zyngier@arm.com>2013-11-07 14:09:04 -0500
commit6d89d2d9b5bac9dbe40ee106ceda9307b6265234 (patch)
treedc2f8fad0be6afabbbfccca1311be40298449cd2 /arch/arm64
parentd241aac798eb042e605f78c31a4122e583b2cd13 (diff)
arm/arm64: KVM: MMIO support for BE guest
Do the necessary byteswap when host and guest have different views of the universe. Actually, the only case we need to take care of is when the guest is BE. All the other cases are naturally handled. Also be careful about endianness when the data is being memcopy-ed from/to the run buffer. Acked-by: Christoffer Dall <christoffer.dall@linaro.org> Signed-off-by: Marc Zyngier <marc.zyngier@arm.com>
Diffstat (limited to 'arch/arm64')
-rw-r--r--arch/arm64/include/asm/kvm_emulate.h48
1 files changed, 48 insertions, 0 deletions
diff --git a/arch/arm64/include/asm/kvm_emulate.h b/arch/arm64/include/asm/kvm_emulate.h
index eec073875218..b016577e37a4 100644
--- a/arch/arm64/include/asm/kvm_emulate.h
+++ b/arch/arm64/include/asm/kvm_emulate.h
@@ -177,4 +177,52 @@ 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
180static inline bool kvm_vcpu_is_be(struct kvm_vcpu *vcpu)
181{
182 if (vcpu_mode_is_32bit(vcpu))
183 return !!(*vcpu_cpsr(vcpu) & COMPAT_PSR_E_BIT);
184
185 return !!(vcpu_sys_reg(vcpu, SCTLR_EL1) & (1 << 25));
186}
187
188static inline unsigned long vcpu_data_guest_to_host(struct kvm_vcpu *vcpu,
189 unsigned long data,
190 unsigned int len)
191{
192 if (kvm_vcpu_is_be(vcpu)) {
193 switch (len) {
194 case 1:
195 return data & 0xff;
196 case 2:
197 return be16_to_cpu(data & 0xffff);
198 case 4:
199 return be32_to_cpu(data & 0xffffffff);
200 default:
201 return be64_to_cpu(data);
202 }
203 }
204
205 return data; /* Leave LE untouched */
206}
207
208static inline unsigned long vcpu_data_host_to_guest(struct kvm_vcpu *vcpu,
209 unsigned long data,
210 unsigned int len)
211{
212 if (kvm_vcpu_is_be(vcpu)) {
213 switch (len) {
214 case 1:
215 return data & 0xff;
216 case 2:
217 return cpu_to_be16(data & 0xffff);
218 case 4:
219 return cpu_to_be32(data & 0xffffffff);
220 default:
221 return cpu_to_be64(data);
222 }
223 }
224
225 return data; /* Leave LE untouched */
226}
227
180#endif /* __ARM64_KVM_EMULATE_H__ */ 228#endif /* __ARM64_KVM_EMULATE_H__ */