[PATCH 4/7] KVM: ARM: selftest: Add handy MMIO macros for the guests

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



We use a lot of MMIO operations as a way to invoke functionality
from the host, so add macros so we don't have to repeat ourselves.
---
 tools/testing/selftests/kvm/arm/cp15-guest.c |    8 ++++----
 tools/testing/selftests/kvm/arm/guest.h      |    6 ++++++
 tools/testing/selftests/kvm/arm/vfp-guest.c  |   12 ++++++------
 3 files changed, 16 insertions(+), 10 deletions(-)

diff --git a/tools/testing/selftests/kvm/arm/cp15-guest.c b/tools/testing/selftests/kvm/arm/cp15-guest.c
index 95b546a..b83b747 100644
--- a/tools/testing/selftests/kvm/arm/cp15-guest.c
+++ b/tools/testing/selftests/kvm/arm/cp15-guest.c
@@ -494,11 +494,11 @@ int test(void)
 
 	/* Host should see the right value. */
 	val = 0xdeadbeef;
-	asm volatile("ldr %0, [%1]" : "=r"(val) : "r"(CP15_TTBR0));
+	read(CP15_TTBR0, val);
 	assert(val == 0x80000000);
 
 	/* Host change should make us see the right value. */
-	asm volatile("str %0, [%1]" : : "r"(0x90000000), "r"(CP15_TTBR0));
+	write(CP15_TTBR0, 0x90000000);
 	val = 0xdeadbeef;
 	assert(cp15_read(0, 2, 0, 0, &val));
 	assert(val == 0x90000000);
@@ -507,12 +507,12 @@ int test(void)
 	assert(cp15_write(0, 6, 0, 2, 0x98765432));
 	
 	val = 0xdeadbeef;
-	asm volatile("ldr %0, [%1]" : "=r"(val) : "r"(CP15_IFAR));
+	read(CP15_IFAR, val);
 	/* Check it sees value we expect. */
 	assert(val == 0x98765432);
 
 	/* Now set it. */
-	asm volatile("str %0, [%1]" : : "r"(0x80000000), "r"(CP15_IFAR));
+	write(CP15_IFAR, 0x80000000);
 	val = 0xdeadbeef;
 	assert(cp15_read(0, 6, 0, 2, &val));
 	assert(val == 0x80000000);
diff --git a/tools/testing/selftests/kvm/arm/guest.h b/tools/testing/selftests/kvm/arm/guest.h
index 40a2eb2..b6068d0 100644
--- a/tools/testing/selftests/kvm/arm/guest.h
+++ b/tools/testing/selftests/kvm/arm/guest.h
@@ -29,6 +29,12 @@ static inline void print(const char *p)
 			ok();						\
 	} while(0)
 
+/* Handy MMIO read/write macros since we use those a lot */
+#define read(token, val) \
+	asm volatile("ldr %0, [%1]" : "=r"(val) : "r"(token));
+#define write(token, val) \
+	asm volatile("str %0, [%1]" : : "r"(val), "r"(token));
+
 typedef uint32_t u32;
 
 /* Each guest needs to write this. */
diff --git a/tools/testing/selftests/kvm/arm/vfp-guest.c b/tools/testing/selftests/kvm/arm/vfp-guest.c
index 075d4f7..b82e393 100644
--- a/tools/testing/selftests/kvm/arm/vfp-guest.c
+++ b/tools/testing/selftests/kvm/arm/vfp-guest.c
@@ -55,28 +55,28 @@ int test(void)
 	/* Now, try loading 2.0 and make sure host doesn't interfere! */
 	d0 = 2.0;
 	assert(d0 == 2.0);
-	asm volatile("ldr %0, [%1]" : "=r"(val) : "r"(VFP_USE_REG));
+	read(VFP_USE_REG, val);
 	assert(d0 == 2.0);
 
 	/* Same thing with upper 16 registers. */
 	d16 = 2.0;
 	assert(d16 == 2.0);
-	asm volatile("ldr %0, [%1]" : "=r"(val) : "r"(VFP_USE_REG + 16));
+	read(VFP_USE_REG + 16, val);
 	assert(d16 == 2.0);
 
 	/* Now check host ioctl sees register correctly. */
 	d0 = 2.0;
- 	asm volatile("ldr %0, [%1]" : "=r"(val) : "r"(VFP_CHECK_REG));
+	read(VFP_CHECK_REG, val);
 
 	d0 = 2.0;
- 	asm volatile("ldr %0, [%1]" : "=r"(val) : "r"(VFP_SET_REG));
+	read(VFP_SET_REG, val);
 	assert(d0 == 3.0);
 
 	d16 = 2.0;
- 	asm volatile("ldr %0, [%1]" : "=r"(val) : "r"(VFP_CHECK_REG+16));
+	read(VFP_CHECK_REG + 16, val);
 
 	d16 = 2.0;
- 	asm volatile("ldr %0, [%1]" : "=r"(val) : "r"(VFP_SET_REG+16));
+	read(VFP_SET_REG + 16, val);
 	assert(d16 == 3.0);
 
 	return 0;
-- 
1.7.9.5

_______________________________________________
kvmarm mailing list
kvmarm@xxxxxxxxxxxxxxxxxxxxx
https://lists.cs.columbia.edu/cucslists/listinfo/kvmarm


[Index of Archives]     [Linux KVM]     [Spice Development]     [Libvirt]     [Libvirt Users]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux