Received: from eggs.gnu.org ([2001:4830:134:3::10]:35272) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Yi09x-0001Ce-Gj for qemu-devel@nongnu.org; Tue, 14 Apr 2015 08:41:46 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Yi09t-0004XH-FH for qemu-devel@nongnu.org; Tue, 14 Apr 2015 08:41:45 -0400 Received: from mx1.redhat.com ([209.132.183.28]:45526) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Yi09t-0004X9-84 for qemu-devel@nongnu.org; Tue, 14 Apr 2015 08:41:41 -0400 Date: Tue, 14 Apr 2015 14:41:29 +0200 From: Igor Mammedov Message-ID: <20150414144129.6ed55b5b@nial.brq.redhat.com> In-Reply-To: <3215703fb9a4b3cafb5f2b29b8f2349cc759c78a.1428653440.git.chen.fan.fnst@cn.fujitsu.com> References: <3215703fb9a4b3cafb5f2b29b8f2349cc759c78a.1428653440.git.chen.fan.fnst@cn.fujitsu.com> MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH v3 1/2] apic: move apic mmio register to each apic realizefn List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Chen Fan Cc: zhugh.fnst@cn.fujitsu.com, qemu-devel@nongnu.org, isimatu.yasuaki@jp.fujitsu.com, guz.fnst@cn.fujitsu.com, Paolo , afaerber@suse.de On Fri, 10 Apr 2015 16:18:05 +0800 Chen Fan wrote: > Due to local apic address is in view of CPU's address space, > so able to move apic mapping to each apic realizefn. > > Signed-off-by: Chen Fan > --- > hw/i386/pc.c | 7 ------- > hw/intc/apic_common.c | 11 +++++------ > 2 files changed, 5 insertions(+), 13 deletions(-) > > diff --git a/hw/i386/pc.c b/hw/i386/pc.c > index a8e6be1..a5e2a27 100644 > --- a/hw/i386/pc.c > +++ b/hw/i386/pc.c > @@ -1089,13 +1089,6 @@ void pc_cpus_init(const char *cpu_model, DeviceState *icc_bridge) > } > } > > - /* 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 042e960..004821a 100644 > --- a/hw/intc/apic_common.c > +++ b/hw/intc/apic_common.c > @@ -306,7 +306,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.", > @@ -317,11 +316,11 @@ 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; > - } > + > + memory_region_add_subregion_overlap(CPU(s->cpu)->as->root, if you look at AddressSpace declaration, root field is marked as private so you can't access it. Perhaps you need to add wrapper to get root, something like this: address_space_root_memory_region() > + APIC_DEFAULT_ADDRESS, use s->apicbase here and set its default value from CPU using cpu_set_apic_base() for example in: x86_cpu_apic_create() PS: we also probably need to teach kvm_apic_set_base()/apic_set_base() to remap APIC in case base changes but it's out of scope of this series. > + &s->io_memory, > + 0x1000); > > /* Note: We need at least 1M to map the VAPIC option ROM */ > if (!vapic && s->vapic_control & VAPIC_ENABLE_MASK &&