Check the region is mapped in the global system memory
with memory_region_is_mapped().

SysBusDevice::mmio[].addr is left unused, remove it.

Suggested-by: Marc-André Lureau <[email protected]>
Signed-off-by: Philippe Mathieu-Daudé <[email protected]>
---

RFC: Are we sysbus-mapping containers?

system/memory.c:2835:bool memory_region_is_mapped(MemoryRegion *mr)
system/memory.c-2836-{
system/memory.c-2837-    return !!mr->container || mr->mapped_via_alias;
system/memory.c-2838-}
---
 include/hw/sysbus.h | 1 -
 hw/core/sysbus.c    | 8 +-------
 2 files changed, 1 insertion(+), 8 deletions(-)

diff --git a/include/hw/sysbus.h b/include/hw/sysbus.h
index 69eb62e29c8..b2a2ea507ea 100644
--- a/include/hw/sysbus.h
+++ b/include/hw/sysbus.h
@@ -60,7 +60,6 @@ struct SysBusDevice {
 
     int num_mmio;
     struct {
-        hwaddr addr;
         MemoryRegion *memory;
     } mmio[QDEV_MAX_MMIO];
     int num_pio;
diff --git a/hw/core/sysbus.c b/hw/core/sysbus.c
index e6acf8dba3b..b3060e02484 100644
--- a/hw/core/sysbus.c
+++ b/hw/core/sysbus.c
@@ -127,15 +127,10 @@ static void sysbus_mmio_map_common(SysBusDevice *dev, int 
n, hwaddr addr,
     assert(n >= 0 && n < dev->num_mmio);
     mr = dev->mmio[n].memory;
 
-    if (dev->mmio[n].addr == addr) {
-        /* ??? region already mapped here.  */
-        return;
-    }
-    if (dev->mmio[n].addr != (hwaddr)-1) {
+    if (memory_region_is_mapped(mr)) {
         /* Unregister previous mapping.  */
         memory_region_del_subregion(get_system_memory(), mr);
     }
-    dev->mmio[n].addr = addr;
     memory_region_add_subregion_overlap(get_system_memory(),
                                         addr, mr, priority);
 }
@@ -180,7 +175,6 @@ void sysbus_init_mmio(SysBusDevice *dev, MemoryRegion 
*memory)
 
     assert(dev->num_mmio < QDEV_MAX_MMIO);
     n = dev->num_mmio++;
-    dev->mmio[n].addr = -1;
     dev->mmio[n].memory = memory;
 }
 
-- 
2.51.0


Reply via email to