diff mbox

[04/16] memory: remove MemoryRegion::backend_registered

Message ID 1325522015-503-5-git-send-email-avi@redhat.com
State New
Headers show

Commit Message

Avi Kivity Jan. 2, 2012, 4:33 p.m. UTC
backend_registered was used to lazify the process of registering an
mmio region, since the it is different for the I/O address space and
the memory address space.  However, it also makes registration dependent
on the region being visible in the address space.  This is not the case
for "fake" regions, like watchpoints or IO_MEM_UNASSIGNED.

Remove backend_registered and always initialize the region.  If it turns
out to be part of the I/O address space, we've wasted an I/O slot, but
that's not too bad.  In any case this will be optimized later on.

Signed-off-by: Avi Kivity <avi@redhat.com>
---
 memory.c |   26 ++++----------------------
 memory.h |    1 -
 2 files changed, 4 insertions(+), 23 deletions(-)
diff mbox

Patch

diff --git a/memory.c b/memory.c
index 5c46833..63dc3dc 100644
--- a/memory.c
+++ b/memory.c
@@ -303,14 +303,10 @@  static void access_with_adjusted_size(target_phys_addr_t addr,
     }
 }
 
-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
@@ -1032,19 +1028,6 @@  static void memory_region_write_thunk_l(void *mr, target_phys_addr_t addr,
     memory_region_write_thunk_l,
 };
 
-static void memory_region_prepare_ram_addr(MemoryRegion *mr)
-{
-    if (mr->backend_registered) {
-        return;
-    }
-
-    mr->destructor = memory_region_destructor_iomem;
-    mr->ram_addr = cpu_register_io_memory(memory_region_read_thunk,
-                                          memory_region_write_thunk,
-                                          mr);
-    mr->backend_registered = true;
-}
-
 void memory_region_init_io(MemoryRegion *mr,
                            const MemoryRegionOps *ops,
                            void *opaque,
@@ -1055,7 +1038,10 @@  void memory_region_init_io(MemoryRegion *mr,
     mr->ops = ops;
     mr->opaque = opaque;
     mr->terminates = true;
-    mr->backend_registered = false;
+    mr->destructor = memory_region_destructor_iomem;
+    mr->ram_addr = cpu_register_io_memory(memory_region_read_thunk,
+                                          memory_region_write_thunk,
+                                          mr);
 }
 
 void memory_region_init_ram(MemoryRegion *mr,
@@ -1067,7 +1053,6 @@  void memory_region_init_ram(MemoryRegion *mr,
     mr->terminates = true;
     mr->destructor = memory_region_destructor_ram;
     mr->ram_addr = qemu_ram_alloc(size, mr);
-    mr->backend_registered = true;
 }
 
 void memory_region_init_ram_ptr(MemoryRegion *mr,
@@ -1080,7 +1065,6 @@  void memory_region_init_ram_ptr(MemoryRegion *mr,
     mr->terminates = true;
     mr->destructor = memory_region_destructor_ram_from_ptr;
     mr->ram_addr = qemu_ram_alloc_from_ptr(size, ptr, mr);
-    mr->backend_registered = true;
 }
 
 void memory_region_init_alias(MemoryRegion *mr,
@@ -1110,7 +1094,6 @@  void memory_region_init_rom_device(MemoryRegion *mr,
                                            memory_region_write_thunk,
                                            mr);
     mr->ram_addr |= IO_MEM_ROMD;
-    mr->backend_registered = true;
 }
 
 void memory_region_destroy(MemoryRegion *mr)
@@ -1453,7 +1436,6 @@  void memory_region_set_alias_offset(MemoryRegion *mr, target_phys_addr_t offset)
 
 ram_addr_t memory_region_get_ram_addr(MemoryRegion *mr)
 {
-    assert(mr->backend_registered);
     return mr->ram_addr;
 }
 
diff --git a/memory.h b/memory.h
index 8041e90..77984bb 100644
--- a/memory.h
+++ b/memory.h
@@ -116,7 +116,6 @@  struct MemoryRegion {
     Int128 size;
     target_phys_addr_t addr;
     target_phys_addr_t offset;
-    bool backend_registered;
     void (*destructor)(MemoryRegion *mr);
     ram_addr_t ram_addr;
     IORange iorange;