From patchwork Mon Sep 14 13:02:26 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Avi Kivity X-Patchwork-Id: 47315 Received: from vger.kernel.org (vger.kernel.org [209.132.176.167]) by demeter.kernel.org (8.14.2/8.14.2) with ESMTP id n8ED3F8D020868 for ; Mon, 14 Sep 2009 13:03:15 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754543AbZINNCa (ORCPT ); Mon, 14 Sep 2009 09:02:30 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1754527AbZINNC3 (ORCPT ); Mon, 14 Sep 2009 09:02:29 -0400 Received: from mx1.redhat.com ([209.132.183.28]:37267 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753577AbZINNC0 (ORCPT ); Mon, 14 Sep 2009 09:02:26 -0400 Received: from int-mx02.intmail.prod.int.phx2.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id n8ED2UD5000820 for ; Mon, 14 Sep 2009 09:02:30 -0400 Received: from cleopatra.tlv.redhat.com (cleopatra.tlv.redhat.com [10.35.255.11]) by int-mx02.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id n8ED2TMJ031104; Mon, 14 Sep 2009 09:02:29 -0400 Received: from localhost.localdomain (cleopatra.tlv.redhat.com [10.35.255.11]) by cleopatra.tlv.redhat.com (Postfix) with ESMTP id 60FF725004D; Mon, 14 Sep 2009 16:02:28 +0300 (IDT) From: Avi Kivity To: Marcelo Tosatti Cc: kvm@vger.kernel.org Subject: [PATCH 1/3] test: Use function table for APIC access Date: Mon, 14 Sep 2009 16:02:26 +0300 Message-Id: <1252933348-17002-2-git-send-email-avi@redhat.com> In-Reply-To: <1252933348-17002-1-git-send-email-avi@redhat.com> References: <1252933348-17002-1-git-send-email-avi@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.12 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Prepare for x2apic. Signed-off-by: Avi Kivity --- kvm/user/test/x86/apic.c | 41 +++++++++++++++++++++++++++++++++++++++-- 1 files changed, 39 insertions(+), 2 deletions(-) diff --git a/kvm/user/test/x86/apic.c b/kvm/user/test/x86/apic.c index b712ef8..72dd963 100644 --- a/kvm/user/test/x86/apic.c +++ b/kvm/user/test/x86/apic.c @@ -102,6 +102,12 @@ static idt_entry_t idt[256]; static int g_fail; static int g_tests; +struct apic_ops { + u32 (*reg_read)(unsigned reg); + void (*reg_write)(unsigned reg, u32 val); + void (*icr_write)(u32 val, u32 dest); +}; + static void outb(unsigned char data, unsigned short port) { asm volatile ("out %0, %1" : : "a"(data), "d"(port)); @@ -115,16 +121,47 @@ static void report(const char *msg, int pass) ++g_fail; } -static u32 apic_read(unsigned reg) +static u32 xapic_read(unsigned reg) { return *(volatile u32 *)(g_apic + reg); } -static void apic_write(unsigned reg, u32 val) +static void xapic_write(unsigned reg, u32 val) { *(volatile u32 *)(g_apic + reg) = val; } +static void xapic_icr_write(u32 val, u32 dest) +{ + while (xapic_read(APIC_ICR) & APIC_ICR_BUSY) + ; + xapic_write(APIC_ICR2, dest << 24); + xapic_write(APIC_ICR, val); +} + +static const struct apic_ops xapic_ops = { + .reg_read = xapic_read, + .reg_write = xapic_write, + .icr_write = xapic_icr_write, +}; + +static const struct apic_ops *apic_ops = &xapic_ops; + +static u32 apic_read(unsigned reg) +{ + return apic_ops->reg_read(reg); +} + +static void apic_write(unsigned reg, u32 val) +{ + apic_ops->reg_write(reg, val); +} + +static void apic_icr_write(u32 val, u32 dest) +{ + apic_ops->icr_write(val, dest); +} + static void test_lapic_existence(void) { u32 lvr;