Received: from eggs.gnu.org ([2001:4830:134:3::10]:40344) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZbTcg-00085m-MA for qemu-devel@nongnu.org; Mon, 14 Sep 2015 09:16:47 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZbTcW-0004sj-T8 for qemu-devel@nongnu.org; Mon, 14 Sep 2015 09:16:42 -0400 Received: from mx1.redhat.com ([209.132.183.28]:33992) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZbTcW-0004sf-L4 for qemu-devel@nongnu.org; Mon, 14 Sep 2015 09:16:32 -0400 Date: Mon, 14 Sep 2015 15:16:26 +0200 From: Igor Mammedov Message-ID: <20150914151626.19f580ff@nial.brq.redhat.com> In-Reply-To: <7d7cc0433310f97cb295260d411d0017a041ad60.1441086002.git.zhugh.fnst@cn.fujitsu.com> References: <7d7cc0433310f97cb295260d411d0017a041ad60.1441086002.git.zhugh.fnst@cn.fujitsu.com> MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH v11 1/5] apic: move APIC's MMIO region mapping into APIC List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Zhu Guihua Cc: ehabkost@redhat.com, qemu-devel@nongnu.org, izumi.taku@jp.fujitsu.com, chen.fan.fnst@cn.fujitsu.com, pbonzini@redhat.com, afaerber@suse.de On Wed, 2 Sep 2015 17:36:18 +0800 Zhu Guihua wrote: > From: Chen Fan > > When ICC bus/bridge is removed, APIC MMIO will be left > unmapped since it was mapped into system's address space > indirectly by ICC bridge. > Fix it by moving mapping into APIC code, so it would be > possible to remove ICC bus/bridge code later. > > Signed-off-by: Chen Fan > Signed-off-by: Zhu Guihua > --- > hw/i386/pc.c | 7 ------- > hw/intc/apic_common.c | 6 ------ > target-i386/cpu.c | 15 +++++++++++++++ > 3 files changed, 15 insertions(+), 13 deletions(-) > > diff --git a/hw/i386/pc.c b/hw/i386/pc.c > index b1c96a8..e15971c 100644 > --- a/hw/i386/pc.c > +++ b/hw/i386/pc.c > @@ -1157,13 +1157,6 @@ void pc_cpus_init(PCMachineState *pcms, 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..c0b32eb 100644 > --- a/hw/intc/apic_common.c > +++ b/hw/intc/apic_common.c > @@ -296,7 +296,6 @@ static void apic_common_realize(DeviceState *dev, Error **errp) > APICCommonClass *info; > static DeviceState *vapic; > static int apic_no; > - static bool mmio_registered; > > if (apic_no >= MAX_APICS) { > error_setg(errp, "%s initialization failed.", > @@ -307,11 +306,6 @@ 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; > - } > > /* Note: We need at least 1M to map the VAPIC option ROM */ > if (!vapic && s->vapic_control & VAPIC_ENABLE_MASK && > diff --git a/target-i386/cpu.c b/target-i386/cpu.c > index cfb8aa7..66b6b0d 100644 > --- a/target-i386/cpu.c > +++ b/target-i386/cpu.c > @@ -2745,6 +2745,7 @@ static void x86_cpu_apic_create(X86CPU *cpu, Error **errp) > /* TODO: convert to link<> */ > apic = APIC_COMMON(cpu->apic_state); > apic->cpu = cpu; > + apic->apicbase = APIC_DEFAULT_ADDRESS | MSR_IA32_APICBASE_ENABLE; > } > > static void x86_cpu_apic_realize(X86CPU *cpu, Error **errp) > @@ -2789,8 +2790,10 @@ static void x86_cpu_realizefn(DeviceState *dev, Error **errp) > X86CPU *cpu = X86_CPU(dev); > X86CPUClass *xcc = X86_CPU_GET_CLASS(dev); > CPUX86State *env = &cpu->env; > + APICCommonState *apic; this and below hunks break build for *-linux-user targets, suggest to move it to x86_cpu_apic_realize() which is empty for user-only and softmmu builds. > Error *local_err = NULL; > static bool ht_warned; > + static bool apic_mmio_map_once; > > if (cpu->apic_id < 0) { > error_setg(errp, "apic-id property was not initialized properly"); > @@ -2877,6 +2880,18 @@ static void x86_cpu_realizefn(DeviceState *dev, Error **errp) > if (local_err != NULL) { > goto out; > } > + > + /* Map APIC MMIO area */ > + apic = APIC_COMMON(cpu->apic_state); > + if (!apic_mmio_map_once) { > + memory_region_add_subregion_overlap(get_system_memory(), > + apic->apicbase & > + MSR_IA32_APICBASE_BASE, > + &apic->io_memory, > + 0x1000); > + apic_mmio_map_once = true; > + } > + > cpu_reset(cs); > > xcc->parent_realize(dev, &local_err);