From patchwork Thu Jun 25 02:17:08 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhu Guihua X-Patchwork-Id: 488268 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id CC0911402DE for ; Thu, 25 Jun 2015 12:19:03 +1000 (AEST) Received: from localhost ([::1]:53609 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Z7wkm-0005xW-NJ for incoming@patchwork.ozlabs.org; Wed, 24 Jun 2015 22:19:00 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43567) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Z7wkF-000524-NX for qemu-devel@nongnu.org; Wed, 24 Jun 2015 22:18:28 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Z7wkB-0001x4-2Y for qemu-devel@nongnu.org; Wed, 24 Jun 2015 22:18:27 -0400 Received: from [59.151.112.132] (port=12138 helo=heian.cn.fujitsu.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Z7wk9-0001vm-8j for qemu-devel@nongnu.org; Wed, 24 Jun 2015 22:18:22 -0400 X-IronPort-AV: E=Sophos;i="5.13,665,1427731200"; d="scan'208";a="97725359" Received: from unknown (HELO edo.cn.fujitsu.com) ([10.167.33.5]) by heian.cn.fujitsu.com with ESMTP; 25 Jun 2015 10:22:20 +0800 Received: from G08CNEXCHPEKD02.g08.fujitsu.local (localhost.localdomain [127.0.0.1]) by edo.cn.fujitsu.com (8.14.3/8.13.1) with ESMTP id t5P2GcKr026240; Thu, 25 Jun 2015 10:16:38 +0800 Received: from G08FNSTD140041.g08.fujitsu.local (10.167.226.252) by G08CNEXCHPEKD02.g08.fujitsu.local (10.167.33.89) with Microsoft SMTP Server (TLS) id 14.3.181.6; Thu, 25 Jun 2015 10:18:16 +0800 From: Zhu Guihua To: , , , , Date: Thu, 25 Jun 2015 10:17:08 +0800 Message-ID: <4b8fc4d985de6c4f44509b9c47a6152add36d832.1435195913.git.zhugh.fnst@cn.fujitsu.com> X-Mailer: git-send-email 1.9.3 In-Reply-To: References: MIME-Version: 1.0 X-Originating-IP: [10.167.226.252] X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 59.151.112.132 Cc: chen.fan.fnst@cn.fujitsu.com, izumi.taku@jp.fujitsu.com, Zhu Guihua Subject: [Qemu-devel] [RESEND PATCH v8 1/4] apic: map APIC's MMIO region at each CPU's address space 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: Chen Fan Replace mapping APIC at global system address space with mapping it at per-CPU address spaces. Signed-off-by: Chen Fan Signed-off-by: Zhu Guihua --- exec.c | 5 +++++ hw/i386/pc.c | 7 ------- hw/intc/apic_common.c | 14 ++++++++------ include/exec/memory.h | 5 +++++ target-i386/cpu.c | 2 ++ 5 files changed, 20 insertions(+), 13 deletions(-) diff --git a/exec.c b/exec.c index f7883d2..1cd2e74 100644 --- a/exec.c +++ b/exec.c @@ -2710,6 +2710,11 @@ void address_space_unmap(AddressSpace *as, void *buffer, hwaddr len, cpu_notify_map_clients(); } +MemoryRegion *address_space_root_memory_region(AddressSpace *as) +{ + return as->root; +} + void *cpu_physical_memory_map(hwaddr addr, hwaddr *plen, int is_write) diff --git a/hw/i386/pc.c b/hw/i386/pc.c index 7072930..9f16128 100644 --- a/hw/i386/pc.c +++ b/hw/i386/pc.c @@ -1076,13 +1076,6 @@ void pc_cpus_init(const char *cpu_model, DeviceState *icc_bridge) object_unref(OBJECT(cpu)); } - /* map APIC MMIO area if CPU has APIC */ - if (cpu && cpu->apic_state) { - /* XXX: what if the base changes? */ - sysbus_mmio_map_overlap(SYS_BUS_DEVICE(icc_bridge), 0, - APIC_DEFAULT_ADDRESS, 0x1000); - } - /* tell smbios about cpuid version and features */ smbios_set_cpuid(cpu->env.cpuid_version, cpu->env.features[FEAT_1_EDX]); } diff --git a/hw/intc/apic_common.c b/hw/intc/apic_common.c index 0032b97..cf105f5 100644 --- a/hw/intc/apic_common.c +++ b/hw/intc/apic_common.c @@ -296,7 +296,8 @@ static void apic_common_realize(DeviceState *dev, Error **errp) APICCommonClass *info; static DeviceState *vapic; static int apic_no; - static bool mmio_registered; + CPUState *cpu = CPU(s->cpu); + MemoryRegion *root; if (apic_no >= MAX_APICS) { error_setg(errp, "%s initialization failed.", @@ -307,11 +308,12 @@ static void apic_common_realize(DeviceState *dev, Error **errp) info = APIC_COMMON_GET_CLASS(s); info->realize(dev, errp); - if (!mmio_registered) { - ICCBus *b = ICC_BUS(qdev_get_parent_bus(dev)); - memory_region_add_subregion(b->apic_address_space, 0, &s->io_memory); - mmio_registered = true; - } + + root = address_space_root_memory_region(cpu->as); + memory_region_add_subregion_overlap(root, + s->apicbase & MSR_IA32_APICBASE_BASE, + &s->io_memory, + 0x1000); /* Note: We need at least 1M to map the VAPIC option ROM */ if (!vapic && s->vapic_control & VAPIC_ENABLE_MASK && diff --git a/include/exec/memory.h b/include/exec/memory.h index 8ae004e..811f027 100644 --- a/include/exec/memory.h +++ b/include/exec/memory.h @@ -1308,6 +1308,11 @@ void *address_space_map(AddressSpace *as, hwaddr addr, void address_space_unmap(AddressSpace *as, void *buffer, hwaddr len, int is_write, hwaddr access_len); +/* address_space_root_memory_region: get root memory region + * + * @as: #AddressSpace to be accessed + */ +MemoryRegion *address_space_root_memory_region(AddressSpace *as); #endif diff --git a/target-i386/cpu.c b/target-i386/cpu.c index 36b07f9..1fb88f6 100644 --- a/target-i386/cpu.c +++ b/target-i386/cpu.c @@ -2741,6 +2741,8 @@ static void x86_cpu_apic_create(X86CPU *cpu, Error **errp) /* TODO: convert to link<> */ apic = APIC_COMMON(cpu->apic_state); apic->cpu = cpu; + cpu_set_apic_base(cpu->apic_state, + APIC_DEFAULT_ADDRESS | MSR_IA32_APICBASE_ENABLE); } static void x86_cpu_apic_realize(X86CPU *cpu, Error **errp)