From patchwork Tue Apr 23 08:29:51 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Igor Mammedov X-Patchwork-Id: 238830 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 E6BFC2C0114 for ; Tue, 23 Apr 2013 19:25:45 +1000 (EST) Received: from localhost ([::1]:58938 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UUYlx-000693-0b for incoming@patchwork.ozlabs.org; Tue, 23 Apr 2013 04:40:21 -0400 Received: from eggs.gnu.org ([208.118.235.92]:57334) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UUYg3-0007Oj-LA for qemu-devel@nongnu.org; Tue, 23 Apr 2013 04:34:17 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UUYg2-000241-4x for qemu-devel@nongnu.org; Tue, 23 Apr 2013 04:34:15 -0400 Received: from mx1.redhat.com ([209.132.183.28]:31181) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UUYg1-00023u-U3 for qemu-devel@nongnu.org; Tue, 23 Apr 2013 04:34:14 -0400 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id r3N8XbAx009778 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Tue, 23 Apr 2013 04:33:37 -0400 Received: from dell-pet610-01.lab.eng.brq.redhat.com (dell-pet610-01.lab.eng.brq.redhat.com [10.34.42.20]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id r3N8W6je017193; Tue, 23 Apr 2013 04:33:32 -0400 From: Igor Mammedov To: qemu-devel@nongnu.org Date: Tue, 23 Apr 2013 10:29:51 +0200 Message-Id: <1366705795-24732-18-git-send-email-imammedo@redhat.com> In-Reply-To: <1366705795-24732-1-git-send-email-imammedo@redhat.com> References: <1366705795-24732-1-git-send-email-imammedo@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: peter.maydell@linaro.org, gleb@redhat.com, mst@redhat.com, jan.kiszka@siemens.com, lcapitulino@redhat.com, blauwirbel@gmail.com, kraxel@redhat.com, quintela@redhat.com, armbru@redhat.com, yang.z.zhang@intel.com, ehabkost@redhat.com, stefano.stabellini@eu.citrix.com, aderumier@odiso.com, anthony.perard@citrix.com, alex.williamson@redhat.com, rth@twiddle.net, kwolf@redhat.com, aliguori@us.ibm.com, claudio.fontana@huawei.com, pbonzini@redhat.com, afaerber@suse.de Subject: [Qemu-devel] [PATCH 17/21] introduce memory_region_get_address() and use it in kvm/ioapic 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 kvm/ioapic is relying on the fact that SysBus device maps mmio regions with offset counted from start of system memory. But if ioapic's region is moved to another sub-region which doesn't start at the beginning of system memory then using offset isn't correct. Fix kvm/ioapic by providing and using helper function that returns absolute region address in respective address space. Signed-off-by: Igor Mammedov --- Note: next patch "move IOAPIC to ICC bus" converts IOAPICs to ICCDevice and breaks SysBus device assumption used by kvm/ioapic. --- hw/i386/kvm/ioapic.c | 2 +- include/exec/memory.h | 10 ++++++++++ memory.c | 11 +++++++++++ 3 files changed, 22 insertions(+), 1 deletions(-) diff --git a/hw/i386/kvm/ioapic.c b/hw/i386/kvm/ioapic.c index a3bd519..b80d41a 100644 --- a/hw/i386/kvm/ioapic.c +++ b/hw/i386/kvm/ioapic.c @@ -96,7 +96,7 @@ static void kvm_ioapic_put(IOAPICCommonState *s) kioapic->id = s->id; kioapic->ioregsel = s->ioregsel; - kioapic->base_address = s->busdev.mmio[0].addr; + kioapic->base_address = memory_region_get_address(&s->io_memory); kioapic->irr = s->irr; for (i = 0; i < IOAPIC_NUM_PINS; i++) { kioapic->redirtbl[i].bits = s->ioredtbl[i]; diff --git a/include/exec/memory.h b/include/exec/memory.h index 9e88320..954f353 100644 --- a/include/exec/memory.h +++ b/include/exec/memory.h @@ -706,6 +706,16 @@ void memory_region_set_enabled(MemoryRegion *mr, bool enabled); void memory_region_set_address(MemoryRegion *mr, hwaddr addr); /* + * memory_region_get_address: get current the address of a region + * + * Returns the absolute address of a region. + * May be used on regions that are currently part of a memory hierarchy. + * + * @mr: the region being queried + */ +hwaddr memory_region_get_address(MemoryRegion *mr); + +/* * memory_region_set_alias_offset: dynamically update a memory alias's offset * * Dynamically updates the offset into the target region that an alias points diff --git a/memory.c b/memory.c index 75ca281..0651050 100644 --- a/memory.c +++ b/memory.c @@ -1413,6 +1413,17 @@ void memory_region_set_address(MemoryRegion *mr, hwaddr addr) memory_region_transaction_commit(); } +hwaddr memory_region_get_address(MemoryRegion *mr) +{ + hwaddr addr = mr->addr; + + while (mr->parent) { + mr = mr->parent; + addr += mr->addr; + } + return addr; +} + void memory_region_set_alias_offset(MemoryRegion *mr, hwaddr offset) { assert(mr->alias);