From patchwork Wed Sep 16 09:26:00 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Avi Kivity X-Patchwork-Id: 47896 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 n8G9R4g0009775 for ; Wed, 16 Sep 2009 09:27:04 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1758451AbZIPJ07 (ORCPT ); Wed, 16 Sep 2009 05:26:59 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1758337AbZIPJ04 (ORCPT ); Wed, 16 Sep 2009 05:26:56 -0400 Received: from mx1.redhat.com ([209.132.183.28]:60903 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1758366AbZIPJ0M (ORCPT ); Wed, 16 Sep 2009 05:26:12 -0400 Received: from int-mx04.intmail.prod.int.phx2.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.17]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id n8G9QG3L023622 for ; Wed, 16 Sep 2009 05:26:16 -0400 Received: from cleopatra.tlv.redhat.com (cleopatra.tlv.redhat.com [10.35.255.11]) by int-mx04.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id n8G9QEvk005539; Wed, 16 Sep 2009 05:26:15 -0400 Received: from localhost.localdomain (cleopatra.tlv.redhat.com [10.35.255.11]) by cleopatra.tlv.redhat.com (Postfix) with ESMTP id D9293250ADD; Wed, 16 Sep 2009 12:26:11 +0300 (IDT) From: Avi Kivity To: Marcelo Tosatti Cc: kvm@vger.kernel.org Subject: [PATCH QEMU-KVM 25/34] test: add apic_id() accessor Date: Wed, 16 Sep 2009 12:26:00 +0300 Message-Id: <1253093169-1423-26-git-send-email-avi@redhat.com> In-Reply-To: <1253093169-1423-1-git-send-email-avi@redhat.com> References: <1253093169-1423-1-git-send-email-avi@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.17 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org apic and x2apic have different formats for the ID register, so we need an accessor for it. Signed-off-by: Avi Kivity --- 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);