aboutsummaryrefslogtreecommitdiff
path: root/memory.c
diff options
context:
space:
mode:
authorPeter Crosthwaite <peter.crosthwaite@xilinx.com>2014-06-05 23:15:18 -0700
committerPaolo Bonzini <pbonzini@redhat.com>2014-06-17 17:11:13 +0200
commit67891b8a85cd8238b8c55ef438b87146ff3646aa (patch)
tree5fd5f4ec384b4e7e8401d152ef11301f4af4c05e /memory.c
parent0598701a4947ddbc19391e008cf753f8f22f3c25 (diff)
memory: MemoryRegion: factor out memory region re-adder
memory_region_set_address is mostly just a function that deletes and re-adds a memory region. Factor this generic functionality out into a re-usable function. This prepares support for further QOMification of MemoryRegion. Signed-off-by: Peter Crosthwaite <peter.crosthwaite@xilinx.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Diffstat (limited to 'memory.c')
-rw-r--r--memory.c26
1 files changed, 16 insertions, 10 deletions
diff --git a/memory.c b/memory.c
index 15f63e8b99..06a4af7aa7 100644
--- a/memory.c
+++ b/memory.c
@@ -1517,21 +1517,27 @@ void memory_region_set_enabled(MemoryRegion *mr, bool enabled)
memory_region_transaction_commit();
}
-void memory_region_set_address(MemoryRegion *mr, hwaddr addr)
+static void memory_region_readd_subregion(MemoryRegion *mr)
{
MemoryRegion *parent = mr->parent;
- if (addr == mr->addr || !parent) {
- mr->addr = addr;
- return;
+ if (parent) {
+ memory_region_transaction_begin();
+ memory_region_ref(mr);
+ memory_region_del_subregion(parent, mr);
+ mr->parent = parent;
+ memory_region_update_parent_subregions(mr);
+ memory_region_unref(mr);
+ memory_region_transaction_commit();
}
+}
- memory_region_transaction_begin();
- memory_region_ref(mr);
- memory_region_del_subregion(parent, mr);
- memory_region_add_subregion_common(parent, addr, mr);
- memory_region_unref(mr);
- memory_region_transaction_commit();
+void memory_region_set_address(MemoryRegion *mr, hwaddr addr)
+{
+ if (addr != mr->addr) {
+ mr->addr = addr;
+ memory_region_readd_subregion(mr);
+ }
}
void memory_region_set_alias_offset(MemoryRegion *mr, hwaddr offset)