qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Avi Kivity <avi@redhat.com>
To: qemu-devel@nongnu.org
Cc: kvm@vger.kernel.org
Subject: [Qemu-devel] [PATCH 07/23] memory: late initialization of ram_addr
Date: Mon, 25 Jul 2011 17:02:48 +0300	[thread overview]
Message-ID: <1311602584-23409-8-git-send-email-avi@redhat.com> (raw)
In-Reply-To: <1311602584-23409-1-git-send-email-avi@redhat.com>

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 <avi@redhat.com>
---
 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;
-- 
1.7.5.3

  parent reply	other threads:[~2011-07-25 14:03 UTC|newest]

Thread overview: 66+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-07-25 14:02 [Qemu-devel] [PATCH 00/23] Memory API, batch 1 Avi Kivity
2011-07-25 14:02 ` [Qemu-devel] [PATCH 01/23] Hierarchical memory region API Avi Kivity
2011-07-25 18:41   ` Anthony Liguori
2011-07-26  9:35     ` Avi Kivity
2011-07-25 14:02 ` [Qemu-devel] [PATCH 02/23] memory: implement dirty tracking Avi Kivity
2011-07-25 18:43   ` Anthony Liguori
2011-07-25 14:02 ` [Qemu-devel] [PATCH 03/23] memory: merge adjacent segments of a single memory region Avi Kivity
2011-07-25 18:48   ` Anthony Liguori
2011-07-26  9:55     ` Avi Kivity
2011-07-25 14:02 ` [Qemu-devel] [PATCH 04/23] Internal interfaces for memory API Avi Kivity
2011-07-25 18:49   ` Anthony Liguori
2011-07-25 14:02 ` [Qemu-devel] [PATCH 05/23] memory: abstract address space operations Avi Kivity
2011-07-25 18:51   ` Anthony Liguori
2011-07-25 14:02 ` [Qemu-devel] [PATCH 06/23] memory: rename MemoryRegion::has_ram_addr to ::terminates Avi Kivity
2011-07-25 18:56   ` Anthony Liguori
2011-07-26  9:59     ` Avi Kivity
2011-07-25 14:02 ` Avi Kivity [this message]
2011-07-25 14:02 ` [Qemu-devel] [PATCH 08/23] memory: I/O address space support Avi Kivity
2011-07-25 19:00   ` Anthony Liguori
2011-07-25 14:02 ` [Qemu-devel] [PATCH 09/23] memory: add backward compatibility for old portio registration Avi Kivity
2011-07-25 19:01   ` Anthony Liguori
2011-07-25 14:02 ` [Qemu-devel] [PATCH 10/23] memory: add backward compatibility for old mmio registration Avi Kivity
2011-07-25 19:02   ` Anthony Liguori
2011-07-25 14:02 ` [Qemu-devel] [PATCH 11/23] memory: add ioeventfd support Avi Kivity
2011-07-25 15:16   ` malc
2011-07-25 15:17     ` Avi Kivity
2011-07-25 15:22       ` malc
2011-07-25 15:28         ` Avi Kivity
2011-07-25 15:38           ` malc
2011-07-25 15:43             ` Avi Kivity
2011-07-25 19:08   ` Anthony Liguori
2011-07-26 10:08     ` Avi Kivity
2011-07-25 14:02 ` [Qemu-devel] [PATCH 12/23] memory: separate building the final memory map into two steps Avi Kivity
2011-07-25 19:12   ` Anthony Liguori
2011-07-26 10:43     ` Avi Kivity
2011-07-25 14:02 ` [Qemu-devel] [PATCH 13/23] memory: document the memory API Avi Kivity
2011-07-25 19:15   ` Anthony Liguori
2011-07-26 10:44     ` Avi Kivity
2011-07-25 14:02 ` [Qemu-devel] [PATCH 14/23] memory: transaction API Avi Kivity
2011-07-25 19:16   ` Anthony Liguori
2011-07-26 10:48     ` Avi Kivity
2011-07-26 11:39       ` Avi Kivity
2011-07-25 14:02 ` [Qemu-devel] [PATCH 15/23] exec.c: initialize memory map Avi Kivity
2011-07-25 19:17   ` Anthony Liguori
2011-07-26 10:55     ` Avi Kivity
2011-07-25 14:02 ` [Qemu-devel] [PATCH 16/23] ioport: register ranges by byte aligned addresses always Avi Kivity
2011-07-25 19:20   ` Anthony Liguori
2011-07-26 10:59     ` Avi Kivity
2011-07-25 14:02 ` [Qemu-devel] [PATCH 17/23] pc: grab system_memory Avi Kivity
2011-07-25 19:22   ` Anthony Liguori
2011-07-25 14:02 ` [Qemu-devel] [PATCH 18/23] pc: convert pc_memory_init() to memory API Avi Kivity
2011-07-25 19:23   ` Anthony Liguori
2011-07-25 14:03 ` [Qemu-devel] [PATCH 19/23] pc: move global memory map out of pc_init1() and into its callers Avi Kivity
2011-07-25 20:02   ` Anthony Liguori
2011-07-26 11:02     ` Avi Kivity
2011-07-25 14:03 ` [Qemu-devel] [PATCH 20/23] pci: pass address space to pci bus when created Avi Kivity
2011-07-25 20:03   ` Anthony Liguori
2011-07-25 14:03 ` [Qemu-devel] [PATCH 21/23] pci: add MemoryRegion based BAR management API Avi Kivity
2011-07-25 20:20   ` Anthony Liguori
2011-07-26 11:06     ` Avi Kivity
2011-07-25 14:03 ` [Qemu-devel] [PATCH 22/23] sysbus: add MemoryRegion based memory " Avi Kivity
2011-07-25 20:21   ` Anthony Liguori
2011-07-25 14:03 ` [Qemu-devel] [PATCH 23/23] usb-ohci: convert to MemoryRegion Avi Kivity
2011-07-25 20:22   ` Anthony Liguori
2011-07-25 20:23 ` [Qemu-devel] [PATCH 00/23] Memory API, batch 1 Anthony Liguori
2011-07-26 11:32   ` Avi Kivity

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1311602584-23409-8-git-send-email-avi@redhat.com \
    --to=avi@redhat.com \
    --cc=kvm@vger.kernel.org \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).