From patchwork Sun Jul 10 18:14:20 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Avi Kivity X-Patchwork-Id: 104072 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [140.186.70.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 617B0B6F85 for ; Mon, 11 Jul 2011 04:31:15 +1000 (EST) Received: from localhost ([::1]:48492 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Qfymd-0007gE-KM for incoming@patchwork.ozlabs.org; Sun, 10 Jul 2011 14:31:12 -0400 Received: from eggs.gnu.org ([140.186.70.92]:46889) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QfyXM-0004G9-GX for qemu-devel@nongnu.org; Sun, 10 Jul 2011 14:15:40 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1QfyXE-0007XF-Av for qemu-devel@nongnu.org; Sun, 10 Jul 2011 14:15:18 -0400 Received: from mx1.redhat.com ([209.132.183.28]:37619) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QfyXD-0007Vu-7a for qemu-devel@nongnu.org; Sun, 10 Jul 2011 14:15:15 -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 p6AIFD3q012318 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Sun, 10 Jul 2011 14:15:14 -0400 Received: from cleopatra.tlv.redhat.com (cleopatra.tlv.redhat.com [10.35.255.11]) by int-mx01.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id p6AIFDx7032724; Sun, 10 Jul 2011 14:15:13 -0400 Received: from s01.tlv.redhat.com (s01.tlv.redhat.com [10.35.255.8]) by cleopatra.tlv.redhat.com (Postfix) with ESMTP id 1D019250B36; Sun, 10 Jul 2011 21:15:11 +0300 (IDT) From: Avi Kivity To: qemu-devel@nongnu.org Date: Sun, 10 Jul 2011 21:14:20 +0300 Message-Id: <1310321709-30770-8-git-send-email-avi@redhat.com> In-Reply-To: <1310321709-30770-1-git-send-email-avi@redhat.com> References: <1310321709-30770-1-git-send-email-avi@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: kvm@vger.kernel.org Subject: [Qemu-devel] [RFC v3 07/56] memory: late initialization of ram_addr 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 For non-RAM memory regions, we cannot tell whether this is an I/O region or an MMIO region. Since the qemu backing registration is different for the two, we have to defer initialization until we know which address space we are in. These shenanigans will be removed once the backing registration is unified with the memory API. Signed-off-by: Avi Kivity --- memory.c | 24 ++++++++++++++++++++---- memory.h | 1 + 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/memory.c b/memory.c index 5fda4a0..bc8bfa2 100644 --- a/memory.c +++ b/memory.c @@ -158,10 +158,14 @@ static void flatview_simplify(FlatView *view) } } +static void memory_region_prepare_ram_addr(MemoryRegion *mr); + static void as_memory_range_add(AddressSpace *as, FlatRange *fr) { ram_addr_t phys_offset, region_offset; + memory_region_prepare_ram_addr(fr->mr); + phys_offset = fr->mr->ram_addr; region_offset = fr->offset_in_region; /* cpu_register_physical_memory_log() wants region_offset for @@ -512,6 +516,19 @@ static CPUWriteMemoryFunc * const memory_region_write_thunk[] = { memory_region_write_thunk_l, }; +static void memory_region_prepare_ram_addr(MemoryRegion *mr) +{ + if (mr->backend_registered) { + return; + } + + mr->ram_addr = cpu_register_io_memory(memory_region_read_thunk, + memory_region_write_thunk, + mr, + mr->ops->endianness); + mr->backend_registered = true; +} + void memory_region_init_io(MemoryRegion *mr, const MemoryRegionOps *ops, void *opaque, @@ -522,10 +539,7 @@ void memory_region_init_io(MemoryRegion *mr, mr->ops = ops; mr->opaque = opaque; mr->terminates = true; - mr->ram_addr = cpu_register_io_memory(memory_region_read_thunk, - memory_region_write_thunk, - mr, - mr->ops->endianness); + mr->backend_registered = false; } void memory_region_init_ram(MemoryRegion *mr, @@ -536,6 +550,7 @@ void memory_region_init_ram(MemoryRegion *mr, memory_region_init(mr, name, size); mr->terminates = true; mr->ram_addr = qemu_ram_alloc(dev, name, size); + mr->backend_registered = true; } void memory_region_init_ram_ptr(MemoryRegion *mr, @@ -547,6 +562,7 @@ void memory_region_init_ram_ptr(MemoryRegion *mr, memory_region_init(mr, name, size); mr->terminates = true; mr->ram_addr = qemu_ram_alloc_from_ptr(dev, name, size, ptr); + mr->backend_registered = true; } void memory_region_init_alias(MemoryRegion *mr, diff --git a/memory.h b/memory.h index 2ad7202..0994b18 100644 --- a/memory.h +++ b/memory.h @@ -76,6 +76,7 @@ struct MemoryRegion { uint64_t size; target_phys_addr_t addr; target_phys_addr_t offset; + bool backend_registered; ram_addr_t ram_addr; bool terminates; MemoryRegion *alias;