aboutsummaryrefslogtreecommitdiffstats
path: root/arch/arm/include
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/arm/include
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/arm/include')
-rw-r--r--arch/arm/include/asm/kvm_emulate.h41
1 files changed, 41 insertions, 0 deletions
diff --git a/arch/arm/include/asm/kvm_emulate.h b/arch/arm/include/asm/kvm_emulate.h
index a464e8d7b6c5..8a6be05a46d7 100644
--- a/arch/arm/include/asm/kvm_emulate.h
+++ b/arch/arm/include/asm/kvm_emulate.h
@@ -157,4 +157,45 @@ static inline u32 kvm_vcpu_hvc_get_imm(struct kvm_vcpu *vcpu)
157 return kvm_vcpu_get_hsr(vcpu) & HSR_HVC_IMM_MASK; 157 return kvm_vcpu_get_hsr(vcpu) & HSR_HVC_IMM_MASK;
158} 158}
159 159
160static inline bool kvm_vcpu_is_be(struct kvm_vcpu *vcpu)
161{
162 return !!(*vcpu_cpsr(vcpu) & PSR_E_BIT);
163}
164
165static inline unsigned long vcpu_data_guest_to_host(struct kvm_vcpu *vcpu,
166 unsigned long data,
167 unsigned int len)
168{
169 if (kvm_vcpu_is_be(vcpu)) {
170 switch (len) {
171 case 1:
172 return data & 0xff;
173 case 2:
174 return be16_to_cpu(data & 0xffff);
175 default:
176 return be32_to_cpu(data);
177 }
178 }
179
180 return data; /* Leave LE untouched */
181}
182
183static inline unsigned long vcpu_data_host_to_guest(struct kvm_vcpu *vcpu,
184 unsigned long data,
185 unsigned int len)
186{
187 if (kvm_vcpu_is_be(vcpu)) {
188 switch (len) {
189 case 1:
190 return data & 0xff;
191 case 2:
192 return cpu_to_be16(data & 0xffff);
193 default:
194 return cpu_to_be32(data);
195 }
196 }
197
198 return data; /* Leave LE untouched */
199}
200
160#endif /* __ARM_KVM_EMULATE_H__ */ 201#endif /* __ARM_KVM_EMULATE_H__ */