From patchwork Tue Oct 30 12:16:31 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 1670131 Return-Path: X-Original-To: patchwork-kvm@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork1.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork1.kernel.org (Postfix) with ESMTP id 2DB3C3FD8C for ; Tue, 30 Oct 2012 12:17:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933493Ab2J3MQ7 (ORCPT ); Tue, 30 Oct 2012 08:16:59 -0400 Received: from mail-pb0-f46.google.com ([209.85.160.46]:42309 "EHLO mail-pb0-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933395Ab2J3MQz (ORCPT ); Tue, 30 Oct 2012 08:16:55 -0400 Received: by mail-pb0-f46.google.com with SMTP id rr4so143424pbb.19 for ; Tue, 30 Oct 2012 05:16:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:cc:subject:date:message-id:x-mailer:in-reply-to :references; bh=ruLgRqmP4b0NVk7+TGTvJ8fhsjSifGyv/ZhIqlTn2sg=; b=fMqzIKUEXF/hNQIW5lAm1dfLrIfG65c44RcLMiz4vQIE250neUfXlfF/iiA7Xug1to WQSuE8sucwZCWqVpc+3SSj/piV9EqvN12XBXBTTEUqWVq4dv/N4pcSt7ITvWrkG1GwZP jjZZI6yjToXLi7qd154JfSqbzbHvclCuOEgbUOrgTLKWkjKNF/KNWbab39UrdTeh/7gV zVM3Et4BNWY23McOYVgvniMXiSt+STj/58HOQzoAgniU4Sz8cYpxwdynrc6iFdd/yDSF g5ESAiPSgzmG3Ev0QQ77xApFLX50kz04cBfq0xZZqY220oSD0arAbKm67bC+yxs0OoGC P0MQ== Received: by 10.68.200.193 with SMTP id ju1mr44172378pbc.53.1351599415567; Tue, 30 Oct 2012 05:16:55 -0700 (PDT) Received: from yakj.usersys.redhat.com (93-34-169-1.ip50.fastwebnet.it. [93.34.169.1]) by mx.google.com with ESMTPS id o10sm319041paz.37.2012.10.30.05.16.51 (version=TLSv1/SSLv3 cipher=OTHER); Tue, 30 Oct 2012 05:16:54 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: avi@redhat.com, mtosatti@redhat.com, jan.kiszka@siemens.com, kvm@vger.kernel.org Subject: [PATCH 2/3] apic: add get/put methods Date: Tue, 30 Oct 2012 13:16:31 +0100 Message-Id: <1351599394-24876-3-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.7.12.1 In-Reply-To: <1351599394-24876-1-git-send-email-pbonzini@redhat.com> References: <1351599394-24876-1-git-send-email-pbonzini@redhat.com> Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Change the hard-coded references to kvm_get_apic_state and kvm_put_apic_state to methods in APICCommonClass. This makes it possible to reuse the methods in common code that cannot assume the presence of KVM. Signed-off-by: Paolo Bonzini --- hw/apic.h | 2 ++ hw/apic_common.c | 32 ++++++++++++++++++++++++++++++++ hw/apic_internal.h | 2 ++ hw/kvm/apic.c | 8 ++++---- kvm.h | 3 --- target-i386/kvm.c | 24 ++---------------------- 6 files changed, 42 insertions(+), 29 deletions(-) diff --git a/hw/apic.h b/hw/apic.h index 1d48e02..f15d100 100644 --- a/hw/apic.h +++ b/hw/apic.h @@ -12,6 +12,8 @@ void apic_deliver_nmi(DeviceState *d); int apic_get_interrupt(DeviceState *s); void apic_reset_irq_delivered(void); int apic_get_irq_delivered(void); +int cpu_get_apic_state(DeviceState *d); +int cpu_put_apic_state(DeviceState *d); void cpu_set_apic_base(DeviceState *s, uint64_t val); uint64_t cpu_get_apic_base(DeviceState *s); void cpu_set_apic_tpr(DeviceState *s, uint8_t val); diff --git a/hw/apic_common.c b/hw/apic_common.c index d68116d..f373ba8 100644 --- a/hw/apic_common.c +++ b/hw/apic_common.c @@ -312,6 +312,38 @@ static int apic_init_common(SysBusDevice *dev) return 0; } +int cpu_get_apic_state(DeviceState *apic) +{ + APICCommonState *s; + APICCommonClass *info; + if (!apic) { + return 0; + } + + s = APIC_COMMON(apic); + info = APIC_COMMON_GET_CLASS(s); + if (info->get) { + return info->get(s); + } + return 0; +} + +int cpu_put_apic_state(DeviceState *apic) +{ + APICCommonState *s; + APICCommonClass *info; + if (!apic) { + return 0; + } + + s = APIC_COMMON(apic); + info = APIC_COMMON_GET_CLASS(s); + if (info->put) { + return info->put(s); + } + return 0; +} + static void apic_dispatch_pre_save(void *opaque) { APICCommonState *s = APIC_COMMON(opaque); diff --git a/hw/apic_internal.h b/hw/apic_internal.h index 30932a3..256fb1a 100644 --- a/hw/apic_internal.h +++ b/hw/apic_internal.h @@ -89,6 +89,8 @@ typedef struct APICCommonClass void (*enable_tpr_reporting)(APICCommonState *s, bool enable); void (*vapic_base_update)(APICCommonState *s); void (*external_nmi)(APICCommonState *s); + int (*get)(APICCommonState *s); + int (*put)(APICCommonState *s); void (*pre_save)(APICCommonState *s); void (*post_load)(APICCommonState *s); } APICCommonClass; diff --git a/hw/kvm/apic.c b/hw/kvm/apic.c index ddf6b7d..35afe0c 100644 --- a/hw/kvm/apic.c +++ b/hw/kvm/apic.c @@ -25,9 +25,8 @@ static inline uint32_t kvm_apic_get_reg(struct kvm_lapic_state *kapic, return *((uint32_t *)(kapic->regs + (reg_id << 4))); } -int kvm_put_apic_state(DeviceState *d) +static int kvm_put_apic_state(APICCommonState *s) { - APICCommonState *s = DO_UPCAST(APICCommonState, busdev.qdev, d); struct kvm_lapic_state kapic; int i; @@ -54,9 +53,8 @@ int kvm_put_apic_state(DeviceState *d) return kvm_vcpu_ioctl(s->cpu_env, KVM_SET_LAPIC, &kapic); } -int kvm_get_apic_state(DeviceState *d) +static int kvm_get_apic_state(APICCommonState *s) { - APICCommonState *s = DO_UPCAST(APICCommonState, busdev.qdev, d); struct kvm_lapic_state kapic; int i, v, ret; @@ -202,6 +200,8 @@ static void kvm_apic_class_init(ObjectClass *klass, void *data) k->enable_tpr_reporting = kvm_apic_enable_tpr_reporting; k->vapic_base_update = kvm_apic_vapic_base_update; k->external_nmi = kvm_apic_external_nmi; + k->get = kvm_get_apic_state; + k->put = kvm_put_apic_state; } static TypeInfo kvm_apic_info = { diff --git a/kvm.h b/kvm.h index 0056f92..83f7b05 100644 --- a/kvm.h +++ b/kvm.h @@ -191,9 +191,6 @@ int kvm_irqchip_send_msi(KVMState *s, MSIMessage msg); void kvm_irqchip_add_irq_route(KVMState *s, int gsi, int irqchip, int pin); -int kvm_put_apic_state(DeviceState *d); -int kvm_get_apic_state(DeviceState *d); - struct kvm_guest_debug; struct kvm_debug_exit_arch; diff --git a/target-i386/kvm.c b/target-i386/kvm.c index 092d4f1..0912e15 100644 --- a/target-i386/kvm.c +++ b/target-i386/kvm.c @@ -1381,26 +1381,6 @@ static int kvm_get_mp_state(CPUX86State *env) return 0; } -static int kvm_get_apic(CPUX86State *env) -{ - DeviceState *apic = env->apic_state; - - if (apic && kvm_irqchip_in_kernel()) { - return kvm_get_apic_state(apic); - } - return 0; -} - -static int kvm_put_apic(CPUX86State *env) -{ - DeviceState *apic = env->apic_state; - - if (apic && kvm_irqchip_in_kernel()) { - return kvm_put_apic_state(apic); - } - return 0; -} - static int kvm_put_vcpu_events(CPUX86State *env, int level) { struct kvm_vcpu_events events; @@ -1576,7 +1556,7 @@ int kvm_arch_put_registers(CPUX86State *env, int level) if (ret < 0) { return ret; } - ret = kvm_put_apic(env); + ret = cpu_put_apic_state(env->apic_state); if (ret < 0) { return ret; } @@ -1627,7 +1607,7 @@ int kvm_arch_get_registers(CPUX86State *env) if (ret < 0) { return ret; } - ret = kvm_get_apic(env); + ret = cpu_get_apic_state(env->apic_state); if (ret < 0) { return ret; }