From patchwork Mon Apr 16 23:37:00 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Igor Mammedov X-Patchwork-Id: 153009 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id C1D68B7000 for ; Tue, 17 Apr 2012 09:38:16 +1000 (EST) Received: from localhost ([::1]:36667 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SJvUs-0004fh-Mn for incoming@patchwork.ozlabs.org; Mon, 16 Apr 2012 19:38:14 -0400 Received: from eggs.gnu.org ([208.118.235.92]:50177) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SJvTv-0001sr-0J for qemu-devel@nongnu.org; Mon, 16 Apr 2012 19:37:17 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SJvTs-0008HE-F6 for qemu-devel@nongnu.org; Mon, 16 Apr 2012 19:37:14 -0400 Received: from mx1.redhat.com ([209.132.183.28]:53702) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SJvTs-0008Gp-6P for qemu-devel@nongnu.org; Mon, 16 Apr 2012 19:37:12 -0400 Received: from int-mx01.intmail.prod.int.phx2.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id q3GNbAtL023842 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Mon, 16 Apr 2012 19:37:10 -0400 Received: from nial.brq.redhat.com (dhcp-1-247.brq.redhat.com [10.34.1.247]) by int-mx01.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id q3GNb3CO024642; Mon, 16 Apr 2012 19:37:09 -0400 From: Igor Mammedov To: qemu-devel@nongnu.org Date: Tue, 17 Apr 2012 01:37:00 +0200 Message-Id: <1334619423-13012-4-git-send-email-imammedo@redhat.com> In-Reply-To: <1334619423-13012-1-git-send-email-imammedo@redhat.com> References: <1334619423-13012-1-git-send-email-imammedo@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.11 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 209.132.183.28 Cc: pbonzini@redhat.com, aliguori@us.ibm.com, afaerber@suse.de, jan.kiszka@siemens.com Subject: [Qemu-devel] [PATCH RFC 3/6] pc: move apic_mapped intialization into common apic init code X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: Igor Mammedov and get rid of apic_init in pc.c Signed-off-by: Igor Mammedov --- hw/apic_common.c | 16 ++++++++++++++++ hw/msi.h | 2 ++ hw/pc.c | 41 +++++++++-------------------------------- 3 files changed, 27 insertions(+), 32 deletions(-) diff --git a/hw/apic_common.c b/hw/apic_common.c index 31b46ab..0c98b41 100644 --- a/hw/apic_common.c +++ b/hw/apic_common.c @@ -21,6 +21,7 @@ #include "apic_internal.h" #include "trace.h" #include "kvm.h" +#include "msi.h" static int apic_irq_delivered; bool apic_report_tpr_access; @@ -284,6 +285,7 @@ static int apic_init_common(SysBusDevice *dev) APICCommonClass *info; static DeviceState *vapic; static int apic_no; + static int apic_mapped; if (apic_no >= MAX_APICS) { return -1; @@ -295,6 +297,20 @@ static int apic_init_common(SysBusDevice *dev) sysbus_init_mmio(dev, &s->io_memory); + /* XXX: mapping more APICs at the same memory location */ + if (apic_mapped == 0) { + /* NOTE: the APIC is directly connected to the CPU - it is not + on the global memory bus. */ + /* XXX: what if the base changes? */ + sysbus_mmio_map(sysbus_from_qdev(&s->busdev.qdev), 0, MSI_ADDR_BASE); + apic_mapped = 1; + } + + /* KVM does not support MSI yet. */ + if (!kvm_irqchip_in_kernel()) { + msi_supported = true; + } + if (!vapic && s->vapic_control & VAPIC_ENABLE_MASK) { vapic = sysbus_create_simple("kvmvapic", -1, NULL); } diff --git a/hw/msi.h b/hw/msi.h index 3040bb0..abd52b6 100644 --- a/hw/msi.h +++ b/hw/msi.h @@ -40,4 +40,6 @@ static inline bool msi_present(const PCIDevice *dev) return dev->cap_present & QEMU_PCI_CAP_MSI; } +#define MSI_ADDR_BASE 0xfee00000 + #endif /* QEMU_MSI_H */ diff --git a/hw/pc.c b/hw/pc.c index 7f0de99..d00ca0f 100644 --- a/hw/pc.c +++ b/hw/pc.c @@ -878,37 +878,6 @@ DeviceState *cpu_get_current_apic(void) } } -static DeviceState *apic_init(void *env, uint8_t apic_id) -{ - DeviceState *dev; - static int apic_mapped; - - if (kvm_irqchip_in_kernel()) { - dev = qdev_create(NULL, "kvm-apic"); - } else { - dev = qdev_create(NULL, "apic"); - } - qdev_prop_set_uint8(dev, "id", apic_id); - qdev_prop_set_ptr(dev, "cpu_env", env); - qdev_init_nofail(dev); - - /* XXX: mapping more APICs at the same memory location */ - if (apic_mapped == 0) { - /* NOTE: the APIC is directly connected to the CPU - it is not - on the global memory bus. */ - /* XXX: what if the base changes? */ - sysbus_mmio_map(sysbus_from_qdev(dev), 0, MSI_ADDR_BASE); - apic_mapped = 1; - } - - /* KVM does not support MSI yet. */ - if (!kvm_irqchip_in_kernel()) { - msi_supported = true; - } - - return dev; -} - void pc_acpi_smi_interrupt(void *opaque, int irq, int level) { CPUX86State *s = opaque; @@ -934,7 +903,15 @@ static CPUX86State *pc_new_cpu(const char *cpu_model) exit(1); } if ((env->cpuid_features & CPUID_APIC) || smp_cpus > 1) { - env->apic_state = apic_init(env, env->cpuid_apic_id); + if (kvm_irqchip_in_kernel()) { + env->apic_state = qdev_create(NULL, "kvm-apic"); + } else { + env->apic_state = qdev_create(NULL, "apic"); + } + qdev_prop_set_uint8(env->apic_state, "id", env->cpuid_apic_id); + qdev_prop_set_ptr(env->apic_state, "cpu_env", env); + qdev_init_nofail(env->apic_state); + /* We hard-wire the BSP to the first CPU. */ if (env->cpu_index == 0) { apic_designate_bsp(env->apic_state);