@@ -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)
@@ -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);
apic and x2apic have different formats for the ID register, so we need an accessor for it. Signed-off-by: Avi Kivity <avi@redhat.com> --- kvm/user/test/lib/x86/apic.c | 18 ++++++++++++++++++ kvm/user/test/lib/x86/apic.h | 1 + 2 files changed, 19 insertions(+), 0 deletions(-)