From patchwork Tue Oct 30 12:16:30 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 1670111 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 5A2733FD8C for ; Tue, 30 Oct 2012 12:16:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933419Ab2J3MQ4 (ORCPT ); Tue, 30 Oct 2012 08:16:56 -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 S933424Ab2J3MQv (ORCPT ); Tue, 30 Oct 2012 08:16:51 -0400 Received: by mail-pb0-f46.google.com with SMTP id rr4so143424pbb.19 for ; Tue, 30 Oct 2012 05:16:51 -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=OY7eM//a2wMUmSHm/717wAiidjAI4mTky7boeS9RX9k=; b=cdil3ldO43V0eUzYileDuv02wC0pw/8iOy3HuNQ1CD/SxWB9J7ILBJttGSQkPdBPp2 gCXpQbI5xv+AdL6bg4+7iizZU79VLr09zEt3u9vvOQEXxxkT4VGfTRrNR7CFEvYEcDM+ z9ZZm9vaRXvaNTqIm+vjXkIxJwE63K4GWcVHzDqNnB5Cm4SenGr9LfA5pU+NaUBsiFjM Yx5f2a42xHRm1fbwSTet1qDI9ZdF62ABnNlLUir9fjFmK/tP43EpGTsTnh5p2E2zH+kH FbubEmUNs+Y2WwdbR2KicVi+JEkCMvp0TZnC9uice76sKc+F/KEID787M64sSiaCC5nw 0nHQ== Received: by 10.68.218.229 with SMTP id pj5mr8700686pbc.87.1351599411564; Tue, 30 Oct 2012 05:16:51 -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.47 (version=TLSv1/SSLv3 cipher=OTHER); Tue, 30 Oct 2012 05:16:50 -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 1/3] kvm: move KVM_GET_LAPIC/KVM_SET_LAPIC to hw/kvm/apic.c Date: Tue, 30 Oct 2012 13:16:30 +0100 Message-Id: <1351599394-24876-2-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 Leave knowledge of the KVM in-kernel LAPIC ioctls to hw/kvm/apic.c. The CPU doesn't need to know anything about kvm_lapic_state. Signed-off-by: Paolo Bonzini Acked-by: Jan Kiszka --- hw/kvm/apic.c | 76 ++++++++++++++++++++++++++++++----------------------- kvm.h | 4 +- target-i386/kvm.c | 14 +-------- 3 files changed, 47 insertions(+), 47 deletions(-) diff --git a/hw/kvm/apic.c b/hw/kvm/apic.c index dbac7ff..ddf6b7d 100644 --- a/hw/kvm/apic.c +++ b/hw/kvm/apic.c @@ -25,62 +25,72 @@ static inline uint32_t kvm_apic_get_reg(struct kvm_lapic_state *kapic, return *((uint32_t *)(kapic->regs + (reg_id << 4))); } -void kvm_put_apic_state(DeviceState *d, struct kvm_lapic_state *kapic) +int kvm_put_apic_state(DeviceState *d) { APICCommonState *s = DO_UPCAST(APICCommonState, busdev.qdev, d); + struct kvm_lapic_state kapic; int i; - memset(kapic, 0, sizeof(*kapic)); - kvm_apic_set_reg(kapic, 0x2, s->id << 24); - kvm_apic_set_reg(kapic, 0x8, s->tpr); - kvm_apic_set_reg(kapic, 0xd, s->log_dest << 24); - kvm_apic_set_reg(kapic, 0xe, s->dest_mode << 28 | 0x0fffffff); - kvm_apic_set_reg(kapic, 0xf, s->spurious_vec); + memset(&kapic, 0, sizeof(kapic)); + kvm_apic_set_reg(&kapic, 0x2, s->id << 24); + kvm_apic_set_reg(&kapic, 0x8, s->tpr); + kvm_apic_set_reg(&kapic, 0xd, s->log_dest << 24); + kvm_apic_set_reg(&kapic, 0xe, s->dest_mode << 28 | 0x0fffffff); + kvm_apic_set_reg(&kapic, 0xf, s->spurious_vec); for (i = 0; i < 8; i++) { - kvm_apic_set_reg(kapic, 0x10 + i, s->isr[i]); - kvm_apic_set_reg(kapic, 0x18 + i, s->tmr[i]); - kvm_apic_set_reg(kapic, 0x20 + i, s->irr[i]); + kvm_apic_set_reg(&kapic, 0x10 + i, s->isr[i]); + kvm_apic_set_reg(&kapic, 0x18 + i, s->tmr[i]); + kvm_apic_set_reg(&kapic, 0x20 + i, s->irr[i]); } - kvm_apic_set_reg(kapic, 0x28, s->esr); - kvm_apic_set_reg(kapic, 0x30, s->icr[0]); - kvm_apic_set_reg(kapic, 0x31, s->icr[1]); + kvm_apic_set_reg(&kapic, 0x28, s->esr); + kvm_apic_set_reg(&kapic, 0x30, s->icr[0]); + kvm_apic_set_reg(&kapic, 0x31, s->icr[1]); for (i = 0; i < APIC_LVT_NB; i++) { - kvm_apic_set_reg(kapic, 0x32 + i, s->lvt[i]); + kvm_apic_set_reg(&kapic, 0x32 + i, s->lvt[i]); } - kvm_apic_set_reg(kapic, 0x38, s->initial_count); - kvm_apic_set_reg(kapic, 0x3e, s->divide_conf); + kvm_apic_set_reg(&kapic, 0x38, s->initial_count); + kvm_apic_set_reg(&kapic, 0x3e, s->divide_conf); + + return kvm_vcpu_ioctl(s->cpu_env, KVM_SET_LAPIC, &kapic); } -void kvm_get_apic_state(DeviceState *d, struct kvm_lapic_state *kapic) +int kvm_get_apic_state(DeviceState *d) { APICCommonState *s = DO_UPCAST(APICCommonState, busdev.qdev, d); - int i, v; - - s->id = kvm_apic_get_reg(kapic, 0x2) >> 24; - s->tpr = kvm_apic_get_reg(kapic, 0x8); - s->arb_id = kvm_apic_get_reg(kapic, 0x9); - s->log_dest = kvm_apic_get_reg(kapic, 0xd) >> 24; - s->dest_mode = kvm_apic_get_reg(kapic, 0xe) >> 28; - s->spurious_vec = kvm_apic_get_reg(kapic, 0xf); + struct kvm_lapic_state kapic; + int i, v, ret; + + ret = kvm_vcpu_ioctl(s->cpu_env, KVM_GET_LAPIC, &kapic); + if (ret < 0) { + return ret; + } + + s->id = kvm_apic_get_reg(&kapic, 0x2) >> 24; + s->tpr = kvm_apic_get_reg(&kapic, 0x8); + s->arb_id = kvm_apic_get_reg(&kapic, 0x9); + s->log_dest = kvm_apic_get_reg(&kapic, 0xd) >> 24; + s->dest_mode = kvm_apic_get_reg(&kapic, 0xe) >> 28; + s->spurious_vec = kvm_apic_get_reg(&kapic, 0xf); for (i = 0; i < 8; i++) { - s->isr[i] = kvm_apic_get_reg(kapic, 0x10 + i); - s->tmr[i] = kvm_apic_get_reg(kapic, 0x18 + i); - s->irr[i] = kvm_apic_get_reg(kapic, 0x20 + i); + s->isr[i] = kvm_apic_get_reg(&kapic, 0x10 + i); + s->tmr[i] = kvm_apic_get_reg(&kapic, 0x18 + i); + s->irr[i] = kvm_apic_get_reg(&kapic, 0x20 + i); } - s->esr = kvm_apic_get_reg(kapic, 0x28); - s->icr[0] = kvm_apic_get_reg(kapic, 0x30); - s->icr[1] = kvm_apic_get_reg(kapic, 0x31); + s->esr = kvm_apic_get_reg(&kapic, 0x28); + s->icr[0] = kvm_apic_get_reg(&kapic, 0x30); + s->icr[1] = kvm_apic_get_reg(&kapic, 0x31); for (i = 0; i < APIC_LVT_NB; i++) { - s->lvt[i] = kvm_apic_get_reg(kapic, 0x32 + i); + s->lvt[i] = kvm_apic_get_reg(&kapic, 0x32 + i); } - s->initial_count = kvm_apic_get_reg(kapic, 0x38); - s->divide_conf = kvm_apic_get_reg(kapic, 0x3e); + s->initial_count = kvm_apic_get_reg(&kapic, 0x38); + s->divide_conf = kvm_apic_get_reg(&kapic, 0x3e); v = (s->divide_conf & 3) | ((s->divide_conf >> 1) & 4); s->count_shift = (v + 1) & 7; s->initial_count_load_time = qemu_get_clock_ns(vm_clock); apic_next_timer(s, s->initial_count_load_time); + return 0; } static void kvm_apic_set_base(APICCommonState *s, uint64_t val) diff --git a/kvm.h b/kvm.h index 2b26dcb..0056f92 100644 --- a/kvm.h +++ b/kvm.h @@ -191,8 +191,8 @@ int kvm_irqchip_send_msi(KVMState *s, MSIMessage msg); void kvm_irqchip_add_irq_route(KVMState *s, int gsi, int irqchip, int pin); -void kvm_put_apic_state(DeviceState *d, struct kvm_lapic_state *kapic); -void kvm_get_apic_state(DeviceState *d, struct kvm_lapic_state *kapic); +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 3aa62b2..092d4f1 100644 --- a/target-i386/kvm.c +++ b/target-i386/kvm.c @@ -1384,16 +1384,9 @@ static int kvm_get_mp_state(CPUX86State *env) static int kvm_get_apic(CPUX86State *env) { DeviceState *apic = env->apic_state; - struct kvm_lapic_state kapic; - int ret; if (apic && kvm_irqchip_in_kernel()) { - ret = kvm_vcpu_ioctl(env, KVM_GET_LAPIC, &kapic); - if (ret < 0) { - return ret; - } - - kvm_get_apic_state(apic, &kapic); + return kvm_get_apic_state(apic); } return 0; } @@ -1401,12 +1394,9 @@ static int kvm_get_apic(CPUX86State *env) static int kvm_put_apic(CPUX86State *env) { DeviceState *apic = env->apic_state; - struct kvm_lapic_state kapic; if (apic && kvm_irqchip_in_kernel()) { - kvm_put_apic_state(apic, &kapic); - - return kvm_vcpu_ioctl(env, KVM_SET_LAPIC, &kapic); + return kvm_put_apic_state(apic); } return 0; }