[PATCH v7 33/38] KVM: arm64: selftests: Add helpers to extract a field of ID registers

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

 



Introduce a couple of helpers to extract a field of ID registers.

Signed-off-by: Reiji Watanabe <reijiw@xxxxxxxxxx>
---
 .../selftests/kvm/include/aarch64/processor.h |  5 ++++
 .../selftests/kvm/lib/aarch64/processor.c     | 27 +++++++++++++++++++
 2 files changed, 32 insertions(+)

diff --git a/tools/testing/selftests/kvm/include/aarch64/processor.h b/tools/testing/selftests/kvm/include/aarch64/processor.h
index 8f9f46979a00..e12411fec822 100644
--- a/tools/testing/selftests/kvm/include/aarch64/processor.h
+++ b/tools/testing/selftests/kvm/include/aarch64/processor.h
@@ -185,4 +185,9 @@ static inline void local_irq_disable(void)
 	asm volatile("msr daifset, #3" : : : "memory");
 }
 
+int extract_signed_field(uint64_t val, int field, int width);
+unsigned int extract_unsigned_field(uint64_t val, int field, int width);
+int cpuid_extract_ftr(uint64_t val, int field, bool sign);
+int cpuid_extract_sftr(uint64_t val, int field);
+unsigned int cpuid_extract_uftr(uint64_t val, int field);
 #endif /* SELFTEST_KVM_PROCESSOR_H */
diff --git a/tools/testing/selftests/kvm/lib/aarch64/processor.c b/tools/testing/selftests/kvm/lib/aarch64/processor.c
index 9343d82519b4..c55f7dfc8567 100644
--- a/tools/testing/selftests/kvm/lib/aarch64/processor.c
+++ b/tools/testing/selftests/kvm/lib/aarch64/processor.c
@@ -500,3 +500,30 @@ void __attribute__((constructor)) init_guest_modes(void)
 {
        guest_modes_append_default();
 }
+
+/* Helpers to get a feature field from ID register value */
+int extract_signed_field(uint64_t val, int field, int width)
+{
+	return (int64_t)(val << (64 - width - field)) >> (64 - width);
+}
+
+unsigned int extract_unsigned_field(uint64_t val, int field, int width)
+{
+	return (uint64_t)(val << (64 - width - field)) >> (64 - width);
+}
+
+int cpuid_extract_ftr(uint64_t val, int field, bool sign)
+{
+	return (sign) ? extract_signed_field(val, field, 4) :
+			extract_unsigned_field(val, field, 4);
+}
+
+int cpuid_extract_sftr(uint64_t val, int field)
+{
+	return cpuid_extract_ftr(val, field, true);
+}
+
+unsigned int cpuid_extract_uftr(uint64_t val, int field)
+{
+	return cpuid_extract_ftr(val, field, false);
+}
-- 
2.36.0.rc0.470.gd361397f0d-goog




[Index of Archives]     [KVM ARM]     [KVM ia64]     [KVM ppc]     [Virtualization Tools]     [Spice Development]     [Libvirt]     [Libvirt Users]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite Questions]     [Linux Kernel]     [Linux SCSI]     [XFree86]

  Powered by Linux