[PATCH QEMU-KVM 25/34] test: add apic_id() accessor

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

 



apic and x2apic have different formats for the ID register, so we need an
accessor for it.

Signed-off-by: Avi Kivity <avi@xxxxxxxxxx>
---
 kvm/user/test/lib/x86/apic.c |   18 ++++++++++++++++++
 kvm/user/test/lib/x86/apic.h |    1 +
 2 files changed, 19 insertions(+), 0 deletions(-)

diff --git a/kvm/user/test/lib/x86/apic.c b/kvm/user/test/lib/x86/apic.c
index 25517ef..16e51bc 100644
--- a/kvm/user/test/lib/x86/apic.c
+++ b/kvm/user/test/lib/x86/apic.c
@@ -14,6 +14,7 @@ struct apic_ops {
     u32 (*reg_read)(unsigned reg);
     void (*reg_write)(unsigned reg, u32 val);
     void (*icr_write)(u32 val, u32 dest);
+    u32 (*id)(void);
 };
 
 static void outb(unsigned char data, unsigned short port)
@@ -39,10 +40,16 @@ static void xapic_icr_write(u32 val, u32 dest)
     xapic_write(APIC_ICR, val);
 }
 
+static uint32_t xapic_id(void)
+{
+    return xapic_read(APIC_ID) >> 24;
+}
+
 static const struct apic_ops xapic_ops = {
     .reg_read = xapic_read,
     .reg_write = xapic_write,
     .icr_write = xapic_icr_write,
+    .id = xapic_id,
 };
 
 static const struct apic_ops *apic_ops = &xapic_ops;
@@ -66,10 +73,16 @@ static void x2apic_icr_write(u32 val, u32 dest)
                   "c"(APIC_BASE_MSR + APIC_ICR/16));
 }
 
+static uint32_t x2apic_id(void)
+{
+    return xapic_read(APIC_ID);
+}
+
 static const struct apic_ops x2apic_ops = {
     .reg_read = x2apic_read,
     .reg_write = x2apic_write,
     .icr_write = x2apic_icr_write,
+    .id = x2apic_id,
 };
 
 u32 apic_read(unsigned reg)
@@ -87,6 +100,11 @@ void apic_icr_write(u32 val, u32 dest)
     apic_ops->icr_write(val, dest);
 }
 
+uint32_t apic_id(void)
+{
+    return apic_ops->id();
+}
+
 #define MSR_APIC_BASE 0x0000001b
 
 int enable_x2apic(void)
diff --git a/kvm/user/test/lib/x86/apic.h b/kvm/user/test/lib/x86/apic.h
index 0115ba4..e325e9a 100644
--- a/kvm/user/test/lib/x86/apic.h
+++ b/kvm/user/test/lib/x86/apic.h
@@ -27,6 +27,7 @@ void enable_apic(void);
 uint32_t apic_read(unsigned reg);
 void apic_write(unsigned reg, uint32_t val);
 void apic_icr_write(uint32_t val, uint32_t dest);
+uint32_t apic_id(void);
 
 int enable_x2apic(void);
 
-- 
1.6.4.1

--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[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