Patchwork [2/3] Remove may_overlap flag from MemoryRegion structure

login
register
mail settings
Submitter Alexey Korolev
Date Feb. 18, 2013, 11:12 p.m.
Message ID <1361229171-23902-3-git-send-email-akorolex@gmail.com>
Download mbox | patch
Permalink /patch/221552/
State New
Headers show

Comments

Alexey Korolev - Feb. 18, 2013, 11:12 p.m.
This patch removes may_overlap flag from MemoryRegion structure as it is
no longer used. If we want to add a region which must never be overlapped
we can set memory region priority to MR_PRIORITY_EXCLUSIVE.
Warning will be printed if two memory regions are competing for the same
address range and have exclusive priority.
Since may_overlap is abandoned, memory_region_add_subregion and
memory_region_add_subregion_common become equvalent so
memory_region_add_subregion_common is removed.

Signed-off-by: Alexey Korolev <akorolex@gmail.com>
---
 include/exec/memory.h |    1 -
 memory.c              |   21 +++++----------------
 2 files changed, 5 insertions(+), 17 deletions(-)

Patch

diff --git a/include/exec/memory.h b/include/exec/memory.h
index 162bdba..203318a 100644
--- a/include/exec/memory.h
+++ b/include/exec/memory.h
@@ -142,7 +142,6 @@  struct MemoryRegion {
     MemoryRegion *alias;
     hwaddr alias_offset;
     unsigned priority;
-    bool may_overlap;
     QTAILQ_HEAD(subregions, MemoryRegion) subregions;
     QTAILQ_ENTRY(MemoryRegion) subregions_link;
     QTAILQ_HEAD(coalesced_ranges, CoalescedMemoryRange) coalesced;
diff --git a/memory.c b/memory.c
index ec5aa57..d151f8d 100644
--- a/memory.c
+++ b/memory.c
@@ -806,7 +806,6 @@  void memory_region_init(MemoryRegion *mr,
     mr->rom_device = false;
     mr->destructor = memory_region_destructor_none;
     mr->priority = MR_PRIORITY_LOW;
-    mr->may_overlap = false;
     mr->alias = NULL;
     QTAILQ_INIT(&mr->subregions);
     memset(&mr->subregions_link, 0, sizeof mr->subregions_link);
@@ -1306,9 +1305,9 @@  void memory_region_del_eventfd(MemoryRegion *mr,
     memory_region_transaction_commit();
 }
 
-static void memory_region_add_subregion_common(MemoryRegion *mr,
-                                               hwaddr offset,
-                                               MemoryRegion *subregion)
+void memory_region_add_subregion(MemoryRegion *mr,
+                                 hwaddr offset,
+                                 MemoryRegion *subregion)
 {
     MemoryRegion *other;
 
@@ -1318,7 +1317,8 @@  static void memory_region_add_subregion_common(MemoryRegion *mr,
     subregion->parent = mr;
     subregion->addr = offset;
     QTAILQ_FOREACH(other, &mr->subregions, subregions_link) {
-        if (subregion->may_overlap || other->may_overlap) {
+        if (other->priority != MR_PRIORITY_EXCLUSIVE
+            || subregion->priority != MR_PRIORITY_EXCLUSIVE) {
             continue;
         }
         if (int128_gt(int128_make64(offset),
@@ -1327,7 +1327,6 @@  static void memory_region_add_subregion_common(MemoryRegion *mr,
                          int128_make64(other->addr))) {
             continue;
         }
-#if 0
         printf("warning: subregion collision %llx/%llx (%s) "
                "vs %llx/%llx (%s)\n",
                (unsigned long long)offset,
@@ -1336,7 +1335,6 @@  static void memory_region_add_subregion_common(MemoryRegion *mr,
                (unsigned long long)other->addr,
                (unsigned long long)int128_get64(other->size),
                other->name);
-#endif
     }
     QTAILQ_FOREACH(other, &mr->subregions, subregions_link) {
         if (subregion->priority >= other->priority) {
@@ -1350,15 +1348,6 @@  done:
     memory_region_transaction_commit();
 }
 
-
-void memory_region_add_subregion(MemoryRegion *mr,
-                                 hwaddr offset,
-                                 MemoryRegion *subregion)
-{
-    subregion->may_overlap = false;
-    subregion->priority = 0;
-    memory_region_add_subregion_common(mr, offset, subregion);
-}
 void memory_region_del_subregion(MemoryRegion *mr,
                                  MemoryRegion *subregion)
 {