From: Avi Kivity <avi@redhat.com>
To: Marcelo Tosatti <mtosatti@redhat.com>
Cc: kvm@vger.kernel.org
Subject: [PATCH 3/3] test: add x2apic test
Date: Mon, 14 Sep 2009 16:02:28 +0300 [thread overview]
Message-ID: <1252933348-17002-4-git-send-email-avi@redhat.com> (raw)
In-Reply-To: <1252933348-17002-1-git-send-email-avi@redhat.com>
Signed-off-by: Avi Kivity <avi@redhat.com>
---
kvm/user/test/x86/apic.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 46 insertions(+), 0 deletions(-)
diff --git a/kvm/user/test/x86/apic.c b/kvm/user/test/x86/apic.c
index fdeec4c..504def2 100644
--- a/kvm/user/test/x86/apic.c
+++ b/kvm/user/test/x86/apic.c
@@ -9,6 +9,7 @@ typedef unsigned char u8;
typedef unsigned short u16;
typedef unsigned u32;
typedef unsigned long ulong;
+typedef unsigned long long u64;
typedef struct {
unsigned short offset0;
@@ -147,6 +148,31 @@ static const struct apic_ops xapic_ops = {
static const struct apic_ops *apic_ops = &xapic_ops;
+static u32 x2apic_read(unsigned reg)
+{
+ unsigned a, d;
+
+ asm volatile ("rdmsr" : "=a"(a), "=d"(d) : "c"(APIC_BASE_MSR + reg/16));
+ return a | (u64)d << 32;
+}
+
+static void x2apic_write(unsigned reg, u32 val)
+{
+ asm volatile ("wrmsr" : : "a"(val), "d"(0), "c"(APIC_BASE_MSR + reg/16));
+}
+
+static void x2apic_icr_write(u32 val, u32 dest)
+{
+ asm volatile ("wrmsr" : : "a"(val), "d"(dest),
+ "c"(APIC_BASE_MSR + APIC_ICR/16));
+}
+
+static const struct apic_ops x2apic_ops = {
+ .reg_read = x2apic_read,
+ .reg_write = x2apic_write,
+ .icr_write = x2apic_icr_write,
+};
+
static u32 apic_read(unsigned reg)
{
return apic_ops->reg_read(reg);
@@ -171,6 +197,25 @@ static void test_lapic_existence(void)
report("apic existence", (u16)lvr == 0x14);
}
+#define MSR_APIC_BASE 0x0000001b
+
+static void enable_x2apic(void)
+{
+ unsigned a, b, c, d;
+
+ asm ("cpuid" : "=a"(a), "=b"(b), "=c"(c), "=d"(d) : "0"(1));
+
+ if (c & (1 << 21)) {
+ asm ("rdmsr" : "=a"(a), "=d"(d) : "c"(MSR_APIC_BASE));
+ a |= 1 << 10;
+ asm ("wrmsr" : : "a"(a), "d"(d), "c"(MSR_APIC_BASE));
+ apic_ops = &x2apic_ops;
+ printf("x2apic enabled\n");
+ } else {
+ printf("x2apic not detected\n");
+ }
+}
+
static u16 read_cs(void)
{
u16 v;
@@ -388,6 +433,7 @@ int main()
mask_pic_interrupts();
enable_apic();
+ enable_x2apic();
init_idt();
test_self_ipi();
--
1.6.4.1
prev parent reply other threads:[~2009-09-14 13:02 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-09-14 13:02 [PATCH 0/3] Add x2apic mode to apic test Avi Kivity
2009-09-14 13:02 ` [PATCH 1/3] test: Use function table for APIC access Avi Kivity
2009-09-14 13:02 ` [PATCH 2/3] test: use new apic_icr_write() to issue IPI Avi Kivity
2009-09-14 13:02 ` Avi Kivity [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1252933348-17002-4-git-send-email-avi@redhat.com \
--to=avi@redhat.com \
--cc=kvm@vger.kernel.org \
--cc=mtosatti@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.