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>
This commit is contained in:
Peter Crosthwaite 2014-06-05 23:15:18 -07:00 committed by Paolo Bonzini
parent 0598701a49
commit 67891b8a85

View File

@ -1517,21 +1517,27 @@ void memory_region_set_enabled(MemoryRegion *mr, bool enabled)
memory_region_transaction_commit(); 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; MemoryRegion *parent = mr->parent;
if (addr == mr->addr || !parent) { if (parent) {
mr->addr = addr; memory_region_transaction_begin();
return; 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(); void memory_region_set_address(MemoryRegion *mr, hwaddr addr)
memory_region_ref(mr); {
memory_region_del_subregion(parent, mr); if (addr != mr->addr) {
memory_region_add_subregion_common(parent, addr, mr); mr->addr = addr;
memory_region_unref(mr); memory_region_readd_subregion(mr);
memory_region_transaction_commit(); }
} }
void memory_region_set_alias_offset(MemoryRegion *mr, hwaddr offset) void memory_region_set_alias_offset(MemoryRegion *mr, hwaddr offset)