diff mbox

[RFC,v1,05/25] memory: MemoryRegion: Add contained flag

Message ID b65546ec395b5b46a2ada7772e0d99eb2129d501.1400204799.git.peter.crosthwaite@xilinx.com
State New
Headers show

Commit Message

Peter Crosthwaite May 16, 2014, 1:52 a.m. UTC
Rather than use the .parent == NULL check to determine if a memory
region is contained, add a purpose specific boolean flag. This allows
for .parent to be easily converted to a link property while preserving
all the semantics of the legacy API.

Signed-off-by: Peter Crosthwaite <peter.crosthwaite@xilinx.com>
---

 include/exec/memory.h | 1 +
 memory.c              | 9 +++++----
 2 files changed, 6 insertions(+), 4 deletions(-)

Comments

Peter Crosthwaite May 27, 2014, 8:51 a.m. UTC | #1
On Fri, May 16, 2014 at 11:52 AM, Peter Crosthwaite
<peter.crosthwaite@xilinx.com> wrote:
> Rather than use the .parent == NULL check to determine if a memory
> region is contained, add a purpose specific boolean flag. This allows
> for .parent to be easily converted to a link property while preserving
> all the semantics of the legacy API.
>
> Signed-off-by: Peter Crosthwaite <peter.crosthwaite@xilinx.com>

With the fixup of the container link property setter, this is obsoleted.

Dropped.

Regards,
Peter
diff mbox

Patch

diff --git a/include/exec/memory.h b/include/exec/memory.h
index 371c066..2bb074f 100644
--- a/include/exec/memory.h
+++ b/include/exec/memory.h
@@ -142,6 +142,7 @@  struct MemoryRegion {
     void *opaque;
     struct Object *owner;
     MemoryRegion *parent;
+    bool contained;
     Int128 size;
     hwaddr addr;
     void (*destructor)(MemoryRegion *mr);
diff --git a/memory.c b/memory.c
index 3c32d5a..a37fdd2 100644
--- a/memory.c
+++ b/memory.c
@@ -1451,6 +1451,7 @@  static void do_memory_region_add_subregion_common(MemoryRegion *subregion)
     QTAILQ_INSERT_TAIL(&mr->subregions, subregion, subregions_link);
 done:
     memory_region_update_pending |= mr->enabled && subregion->enabled;
+    subregion->contained = true;
     memory_region_transaction_commit();
 }
 
@@ -1487,8 +1488,8 @@  void memory_region_del_subregion(MemoryRegion *mr,
                                  MemoryRegion *subregion)
 {
     memory_region_transaction_begin();
-    assert(subregion->parent == mr);
-    subregion->parent = NULL;
+    assert(subregion->parent == mr && subregion->contained);
+    subregion->contained = false;
     QTAILQ_REMOVE(&mr->subregions, subregion, subregions_link);
     memory_region_unref(subregion);
     memory_region_update_pending |= mr->enabled && subregion->enabled;
@@ -1510,7 +1511,7 @@  void memory_region_set_address(MemoryRegion *mr, hwaddr addr)
 {
     MemoryRegion *parent = mr->parent;
 
-    if (addr == mr->addr || !parent) {
+    if (addr == mr->addr || !mr->contained) {
         mr->addr = addr;
         return;
     }
@@ -1518,7 +1519,7 @@  void memory_region_set_address(MemoryRegion *mr, hwaddr addr)
     memory_region_transaction_begin();
     memory_region_ref(mr);
     memory_region_del_subregion(parent, mr);
-    memory_region_add_subregion_common(parent, addr, mr);
+    do_memory_region_add_subregion_common(mr);
     memory_region_unref(mr);
     memory_region_transaction_commit();
 }