Skip to contentSkip to conversation

hw/sysbus: Spring cleanups (part 1)

PATCH In review Philippe Mathieu-Daudé 10 participants 71 messages Oct 28, 2025 – Oct 30, 2025 Arm/Aspeed machine support

lore
Share & tools
lore
#0 lore raw

v3 cover hw/sysbus: Spring cleanups (part 1)

- Use sysbus_mmio_get_region() instead of SysBusDevice::mmio[].memory
- Use memory_region_name() instead of MemoryRegion::name
- Use memory_region_size() instead of int128_get64(MemoryRegion::size)
- Add memory_region_get_address()
- Use memory_region_get_address() instead of MemoryRegion::addr
- Remove SysBusDevice::mmio[].addr
- Simplify SysBusDevice::mmio[]

Philippe Mathieu-Daudé (25):
hw/i386/microvm: Use proper SysBus accessors hw/i386/ioapic: Use proper SysBus accessors hw/timer/hpet: Use proper SysBus accessors
hw/acpi/cxl: Use proper SysBus accessors
hw/ppc/e500: Use proper SysBus accessors
hw/pci-bridge: Use proper SysBus accessors
hw/sysbus: Use memory_region_name()
hw/nvme/ctrl: Use memory_region_size()
hw/s390x: Use memory_region_size()
system/memory: Have memory_region_size() take a const argument system/memory: Introduce memory_region_get_address() migration/ram: Use memory_region_get_address()
hw/acpi: Use memory_region_get_address()
hw/fdt: Use memory_region_get_address()
hw/nvme: Use memory_region_get_address()
hw/s390x: Use memory_region_get_address()
hw/timer/hpet: Use memory_region_get_address() hw/watchdog/aspeed: Use memory_region_get_address() hw/pci-bridge: Use memory_region_get_address() system/ioport: Use memory_region_get_address() hw/sysbus: Use memory_region_get_address()
hw/sysbus: Hoist MemoryRegion in sysbus_mmio_map_common() hw/sysbus: Remove sysbus_mmio_map_common() @may_overlap argument hw/sysbus: Use memory_region_is_mapped() to check for mapped region hw/sysbus: Simplify SysBusDevice::mmio

 include/hw/sysbus.h                 |  5 +--
 include/system/memory.h             |  9 ++++-
 hw/acpi/cxl.c                       | 10 +++--
 hw/core/sysbus.c                    | 57 ++++++++++++-----------------
 hw/i386/acpi-build.c                |  8 ++--
 hw/i386/kvm/ioapic.c                |  3 +-
 hw/i386/microvm-dt.c                |  6 ++-
 hw/loongarch/virt-acpi-build.c      |  4 +-
 hw/loongarch/virt-fdt-build.c       |  4 +-
 hw/nvme/ctrl.c                      | 15 +++++---
 hw/pci-bridge/pci_expander_bridge.c |  6 ++-
 hw/ppc/e500.c                       |  2 +-
 hw/s390x/s390-pci-inst.c            | 23 ++++++++----
 hw/timer/hpet.c                     |  4 +-
 hw/watchdog/wdt_aspeed.c            |  2 +-
 migration/ram.c                     | 11 +++---
 system/ioport.c                     | 21 +++++++----
 system/memory.c                     |  7 +++-
 18 files changed, 113 insertions(+), 84 deletions(-)
Signature · 1 line
2.51.0
#1 lore raw

PATCH v3 1/25 hw/i386/microvm: Use proper SysBus accessors

SysBusDevice::mmio[] is private data of SysBusDevice, use sysbus_mmio_get_region() to access it.

---
 hw/i386/microvm-dt.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
hw/i386/microvm-dt.c +4 -2
index cb27dfd732e..d7f49bc1b5f 100644
@@ -71,7 +71,8 @@ static void dt_add_virtio(MicrovmMachineState *mms, VirtIOMMIOProxy *mmio)
         return;
     }
 
-    hwaddr base = dev->mmio[0].addr;
+    MemoryRegion *mr = sysbus_mmio_get_region(dev, 0);
+    hwaddr base = mr->addr;
     hwaddr size = 512;
     unsigned index = (base - VIRTIO_MMIO_BASE) / size;
     uint32_t irq = mms->virtio_irq_base + index;
@@ -150,7 +151,8 @@ static void dt_add_pcie(MicrovmMachineState *mms)
 
 static void dt_add_ioapic(MicrovmMachineState *mms, SysBusDevice *dev)
 {
-    hwaddr base = dev->mmio[0].addr;
+    MemoryRegion *mr = sysbus_mmio_get_region(dev, 0);
+    hwaddr base = mr->addr;
     char *nodename;
     uint32_t ph;
     int index;
Signature · 1 line
2.51.0
#2 lore raw

Re: [PATCH v3 01/25] hw/i386/microvm: Use proper SysBus accessors

Quoted 23 lines · Philippe Mathieu-Daudé

SysBusDevice::mmio[] is private data of SysBusDevice, use sysbus_mmio_get_region() to access it.

---
  hw/i386/microvm-dt.c | 6 ++++--
  1 file changed, 4 insertions(+), 2 deletions(-)
hw/i386/microvm-dt.c +2 -1
index cb27dfd732e..d7f49bc1b5f 100644
@@ -71,7 +71,8 @@ static void dt_add_virtio(MicrovmMachineState *mms, VirtIOMMIOProxy *mmio)
          return;
      }
 
-    hwaddr base = dev->mmio[0].addr;
+    MemoryRegion *mr = sysbus_mmio_get_region(dev, 0);
+    hwaddr base = mr->addr;
      hwaddr size = 512;
      unsigned index = (base - VIRTIO_MMIO_BASE) / size;
      uint32_t irq = mms->virtio_irq_base + index;

hw/i386/microvm-dt.c static void dt_add_pcie(MicrovmMachineState *mms) · line 158

Quoted 9 lines
hw/i386/microvm-dt.c +2 -1
@@ -150,7 +151,8 @@ static void dt_add_pcie(MicrovmMachineState *mms)
 
  static void dt_add_ioapic(MicrovmMachineState *mms, SysBusDevice *dev)
  {
-    hwaddr base = dev->mmio[0].addr;
+    MemoryRegion *mr = sysbus_mmio_get_region(dev, 0);
+    hwaddr base = mr->addr;
      char *nodename;
      uint32_t ph;
      int index;

Wouldn't it make sense to move patch 11 before this patch, and then to use memory_region_get_address() here directly?

Thomas

Reviewed-by on v3 1/25
#3 lore raw

Re: [PATCH v3 01/25] hw/i386/microvm: Use proper SysBus accessors

In reply to Philippe Mathieu-Daudé
Quoted 5 lines · Philippe Mathieu-Daudé

Date: Tue, 28 Oct 2025 19:12:35 +0100
From: Philippe Mathieu-Daudé <[email protected]>
Subject: [PATCH v3 01/25] hw/i386/microvm: Use proper SysBus accessors
X-Mailer: git-send-email 2.51.0

Quoted 7 lines

SysBusDevice::mmio[] is private data of SysBusDevice, use sysbus_mmio_get_region() to access it.

---
 hw/i386/microvm-dt.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
#4 lore raw

PATCH v3 2/25 hw/i386/ioapic: Use proper SysBus accessors

In reply to Philippe Mathieu-Daudé

SysBusDevice::mmio[] is private data of SysBusDevice, use sysbus_mmio_get_region() to access it.

---
 hw/i386/kvm/ioapic.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
hw/i386/kvm/ioapic.c +2 -1
index 693ee978a12..0519432edbe 100644
@@ -80,6 +80,7 @@ static void kvm_ioapic_put(IOAPICCommonState *s)
 {
     struct kvm_irqchip chip;
     struct kvm_ioapic_state *kioapic;
+    MemoryRegion *mr = sysbus_mmio_get_region(s->busdev, 0);
     int ret, i;
 
     chip.chip_id = KVM_IRQCHIP_IOAPIC;
@@ -87,7 +88,7 @@ static void kvm_ioapic_put(IOAPICCommonState *s)
 
     kioapic->id = s->id;
     kioapic->ioregsel = s->ioregsel;
-    kioapic->base_address = s->busdev.mmio[0].addr;
+    kioapic->base_address = mr->addr;
     kioapic->irr = s->irr;
     for (i = 0; i < IOAPIC_NUM_PINS; i++) {
         kioapic->redirtbl[i].bits = s->ioredtbl[i];
Signature · 1 line
2.51.0
Reviewed-by on v3 2/25
#5 lore raw

Re: [PATCH v3 02/25] hw/i386/ioapic: Use proper SysBus accessors

Quoted 5 lines · Philippe Mathieu-Daudé

Date: Tue, 28 Oct 2025 19:12:36 +0100
From: Philippe Mathieu-Daudé <[email protected]>
Subject: [PATCH v3 02/25] hw/i386/ioapic: Use proper SysBus accessors
X-Mailer: git-send-email 2.51.0

Quoted 7 lines

SysBusDevice::mmio[] is private data of SysBusDevice, use sysbus_mmio_get_region() to access it.

---
 hw/i386/kvm/ioapic.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
#6 lore raw

Re: [PATCH v3 02/25] hw/i386/ioapic: Use proper SysBus accessors

In reply to Philippe Mathieu-Daudé
Quoted 5 lines · Philippe Mathieu-Daudé

Date: Tue, 28 Oct 2025 19:12:36 +0100
From: Philippe Mathieu-Daudé <[email protected]>
Subject: [PATCH v3 02/25] hw/i386/ioapic: Use proper SysBus accessors
X-Mailer: git-send-email 2.51.0

Quoted 7 lines

SysBusDevice::mmio[] is private data of SysBusDevice, use sysbus_mmio_get_region() to access it.

---
 hw/i386/kvm/ioapic.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

BTW, it seems ioapic & microvm could also use memory_region_get_address(mr) as the follow up cleanup, just like hpet did.

Regards,
Zhao

#7 lore raw

PATCH v3 3/25 hw/timer/hpet: Use proper SysBus accessors

In reply to Philippe Mathieu-Daudé

SysBusDevice::mmio[] is private data of SysBusDevice, use sysbus_mmio_get_region() to access it.

---
 hw/timer/hpet.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
hw/timer/hpet.c +2 -2
index 1acba4fa9db..c1b96d0a89f 100644
@@ -654,7 +654,7 @@ static const MemoryRegionOps hpet_ram_ops = {
 static void hpet_reset(DeviceState *d)
 {
     HPETState *s = HPET(d);
-    SysBusDevice *sbd = SYS_BUS_DEVICE(d);
+    MemoryRegion *mr = sysbus_mmio_get_region(SYS_BUS_DEVICE(d), 0);
     int i;
 
     for (i = 0; i < s->num_timers; i++) {
@@ -677,7 +677,7 @@ static void hpet_reset(DeviceState *d)
     s->hpet_offset = 0ULL;
     s->config = 0ULL;
     hpet_fw_cfg.hpet[s->hpet_id].event_timer_block_id = (uint32_t)s->capability;
-    hpet_fw_cfg.hpet[s->hpet_id].address = sbd->mmio[0].addr;
+    hpet_fw_cfg.hpet[s->hpet_id].address = mr->addr;
 
     /* to document that the RTC lowers its output on reset as well */
     s->rtc_irq_level = 0;
Signature · 1 line
2.51.0
Reviewed-by on v3 3/25
#8 lore raw

Re: [PATCH v3 03/25] hw/timer/hpet: Use proper SysBus accessors

Quoted 27 lines · Philippe Mathieu-Daudé

Date: Tue, 28 Oct 2025 19:12:37 +0100
From: Philippe Mathieu-Daudé <[email protected]>
Subject: [PATCH v3 03/25] hw/timer/hpet: Use proper SysBus accessors
X-Mailer: git-send-email 2.51.0

SysBusDevice::mmio[] is private data of SysBusDevice, use sysbus_mmio_get_region() to access it.

---
 hw/timer/hpet.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
hw/timer/hpet.c +1 -1
index 1acba4fa9db..c1b96d0a89f 100644
@@ -654,7 +654,7 @@ static const MemoryRegionOps hpet_ram_ops = {
 static void hpet_reset(DeviceState *d)
 {
     HPETState *s = HPET(d);
-    SysBusDevice *sbd = SYS_BUS_DEVICE(d);
+    MemoryRegion *mr = sysbus_mmio_get_region(SYS_BUS_DEVICE(d), 0);
     int i;
 
     for (i = 0; i < s->num_timers; i++) {

hw/timer/hpet.c static void hpet_reset(DeviceState *d) · line 680

Quoted 5 lines
hw/timer/hpet.c +1 -1
@@ -677,7 +677,7 @@ static void hpet_reset(DeviceState *d)
     s->hpet_offset = 0ULL;
     s->config = 0ULL;
     hpet_fw_cfg.hpet[s->hpet_id].event_timer_block_id = (uint32_t)s->capability;
-    hpet_fw_cfg.hpet[s->hpet_id].address = sbd->mmio[0].addr;
+    hpet_fw_cfg.hpet[s->hpet_id].address = mr->addr;

Rust's sysbus has a method "mmio_addr". Maybe Rust side should also split it into two methods similar to sysbus_mmio_get_region and memory_region_get_address, to align with the C interfaces.

For this patch,

Quoted 6 lines
hw/timer/hpet.c +0 -0
     /* to document that the RTC lowers its output on reset as well */
     s->rtc_irq_level = 0;
Signature · 1 line
2.51.0
#9 lore raw

PATCH v3 4/25 hw/acpi/cxl: Use proper SysBus accessors

In reply to Philippe Mathieu-Daudé

SysBusDevice::mmio[] is private data of SysBusDevice, use sysbus_mmio_get_region() to access it.

---
 hw/acpi/cxl.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
hw/acpi/cxl.c +1 -1
index 75d5b30bb8b..77c99dfb184 100644
@@ -104,7 +104,7 @@ static void cedt_build_chbs(GArray *table_data, PXBCXLDev *cxl)
 {
     PXBDev *pxb = PXB_DEV(cxl);
     SysBusDevice *sbd = SYS_BUS_DEVICE(cxl->cxl_host_bridge);
-    struct MemoryRegion *mr = sbd->mmio[0].memory;
+    MemoryRegion *mr = sysbus_mmio_get_region(sbd, 0);
 
     /* Type */
     build_append_int_noprefix(table_data, 0, 1);
Signature · 1 line
2.51.0
Acked-by Jonathan Cameron on v3 4/25
#11 lore raw

Re: [PATCH v3 04/25] hw/acpi/cxl: Use proper SysBus accessors

In reply to Philippe Mathieu-Daudé
Quoted 4 lines · On Tue, 28 Oct 2025 19:12:38 +0100 Philippe Mathieu-Daudé <[email protected]>…

SysBusDevice::mmio[] is private data of SysBusDevice, use sysbus_mmio_get_region() to access it.

Thanks,

Quoted 17 lines
---
 hw/acpi/cxl.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
hw/acpi/cxl.c +1 -1
index 75d5b30bb8b..77c99dfb184 100644
@@ -104,7 +104,7 @@ static void cedt_build_chbs(GArray *table_data, PXBCXLDev *cxl)
 {
     PXBDev *pxb = PXB_DEV(cxl);
     SysBusDevice *sbd = SYS_BUS_DEVICE(cxl->cxl_host_bridge);
-    struct MemoryRegion *mr = sbd->mmio[0].memory;
+    MemoryRegion *mr = sysbus_mmio_get_region(sbd, 0);
 
     /* Type */
     build_append_int_noprefix(table_data, 0, 1);
#12 lore raw

PATCH v3 5/25 hw/ppc/e500: Use proper SysBus accessors

In reply to Philippe Mathieu-Daudé

SysBusDevice::mmio[] is private data of SysBusDevice, use sysbus_mmio_get_region() to access it.

---
 hw/ppc/e500.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
hw/ppc/e500.c +1 -1
index 8842f7f6b88..fe1aeffe676 100644
@@ -887,7 +887,7 @@ static DeviceState *ppce500_init_mpic(PPCE500MachineState *pms,
 
     s = SYS_BUS_DEVICE(dev);
     memory_region_add_subregion(ccsr, MPC8544_MPIC_REGS_OFFSET,
-                                s->mmio[0].memory);
+                                sysbus_mmio_get_region(s, 0));
 
     return dev;
 }
Signature · 1 line
2.51.0
#14 lore raw

PATCH v3 6/25 hw/pci-bridge: Use proper SysBus accessors

In reply to Philippe Mathieu-Daudé

SysBusDevice::mmio[] is private data of SysBusDevice, use sysbus_mmio_get_region() to access it.

---
 hw/pci-bridge/pci_expander_bridge.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
hw/pci-bridge/pci_expander_bridge.c +4 -2
index 1bcceddbc4d..aa55749954a 100644
@@ -157,9 +157,11 @@ static char *pxb_host_ofw_unit_address(const SysBusDevice *dev)
     main_host = PCI_HOST_BRIDGE(pxb_dev_base->parent_bus->parent);
     main_host_sbd = SYS_BUS_DEVICE(main_host);
 
-    if (main_host_sbd->num_mmio > 0) {
+    if (sysbus_has_mmio(main_host_sbd, 0)) {
+        MemoryRegion *mr = sysbus_mmio_get_region(main_host_sbd, 0);
+
         return g_strdup_printf(HWADDR_FMT_plx ",%x",
-                               main_host_sbd->mmio[0].addr, position + 1);
+                               mr->addr, position + 1);
     }
     if (main_host_sbd->num_pio > 0) {
         return g_strdup_printf("i%04x,%x",
Signature · 1 line
2.51.0
#15 lore raw

Re: [PATCH v3 06/25] hw/pci-bridge: Use proper SysBus accessors

Quoted 5 lines · Philippe Mathieu-Daudé

SysBusDevice::mmio[] is private data of SysBusDevice, use sysbus_mmio_get_region() to access it.

I haven't reviewed this patch but the e500 one.

Regards,
BALATON Zoltan

Quoted 23 lines

---
hw/pci-bridge/pci_expander_bridge.c | 6 ++++--

1 file changed, 4 insertions(+), 2 deletions(-)
hw/pci-bridge/pci_expander_bridge.c +4 -2
index 1bcceddbc4d..aa55749954a 100644
@@ -157,9 +157,11 @@ static char *pxb_host_ofw_unit_address(const SysBusDevice *dev)
    main_host = PCI_HOST_BRIDGE(pxb_dev_base->parent_bus->parent);
    main_host_sbd = SYS_BUS_DEVICE(main_host);
 
-    if (main_host_sbd->num_mmio > 0) {
+    if (sysbus_has_mmio(main_host_sbd, 0)) {
+        MemoryRegion *mr = sysbus_mmio_get_region(main_host_sbd, 0);
+
        return g_strdup_printf(HWADDR_FMT_plx ",%x",
-                               main_host_sbd->mmio[0].addr, position + 1);
+                               mr->addr, position + 1);
    }
    if (main_host_sbd->num_pio > 0) {
        return g_strdup_printf("i%04x,%x",
#16 lore raw

PATCH v3 7/25 hw/sysbus: Use memory_region_name()

In reply to Philippe Mathieu-Daudé

MemoryRegion::name is private data of MemoryRegion. Use the proper memory_region_name() accessor, which might return a different name.

---
 hw/core/sysbus.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
hw/core/sysbus.c +1 -1
index ae447c1196a..d33be6b2b52 100644
@@ -154,7 +154,7 @@ void sysbus_mmio_map(SysBusDevice *dev, int n, hwaddr addr)
 int sysbus_mmio_map_name(SysBusDevice *dev, const char *name, hwaddr addr)
 {
     for (int i = 0; i < dev->num_mmio; i++) {
-        if (!strcmp(dev->mmio[i].memory->name, name)) {
+        if (!strcmp(memory_region_name(dev->mmio[i].memory), name)) {
             sysbus_mmio_map(dev, i, addr);
             return i;
         }
Signature · 1 line
2.51.0
Reviewed-by on v3 7/25
#17 lore raw

Re: [PATCH v3 07/25] hw/sysbus: Use memory_region_name()

Quoted 9 lines · Philippe Mathieu-Daudé

MemoryRegion::name is private data of MemoryRegion. Use the proper memory_region_name() accessor, which might return a different name.

---
  hw/core/sysbus.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)

r~

#18 lore raw

PATCH v3 8/25 hw/nvme/ctrl: Use memory_region_size()

In reply to Philippe Mathieu-Daudé

MemoryRegion::size is private data of MemoryRegion, use the proper memory_region_size() getter to get it.

---
 hw/nvme/ctrl.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
hw/nvme/ctrl.c +5 -3
index cd81f739975..9505f291f62 100644
@@ -514,14 +514,16 @@ static bool nvme_update_ruh(NvmeCtrl *n, NvmeNamespace *ns, uint16_t pid)
 
 static bool nvme_addr_is_cmb(NvmeCtrl *n, hwaddr addr)
 {
+    MemoryRegion *mr;
     hwaddr hi, lo;
 
     if (!n->cmb.cmse) {
         return false;
     }
 
+    mr = &n->cmb.mem;
     lo = n->params.legacy_cmb ? n->cmb.mem.addr : n->cmb.cba;
-    hi = lo + int128_get64(n->cmb.mem.size);
+    hi = lo + memory_region_size(mr);
 
     return addr >= lo && addr < hi;
 }
@@ -540,7 +542,7 @@ static bool nvme_addr_is_pmr(NvmeCtrl *n, hwaddr addr)
         return false;
     }
 
-    hi = n->pmr.cba + int128_get64(n->pmr.dev->mr.size);
+    hi = n->pmr.cba + memory_region_size(&n->pmr.dev->mr);
 
     return addr >= n->pmr.cba && addr < hi;
 }
@@ -563,7 +565,7 @@ static inline bool nvme_addr_is_iomem(NvmeCtrl *n, hwaddr addr)
      * in BAR0 as well, then this must be changed.
      */
     lo = n->bar0.addr;
-    hi = lo + int128_get64(n->bar0.size);
+    hi = lo + memory_region_size(&n->bar0);
 
     return addr >= lo && addr < hi;
 }
Signature · 1 line
2.51.0
#21 lore raw

PATCH v3 9/25 hw/s390x: Use memory_region_size()

In reply to Philippe Mathieu-Daudé

MemoryRegion::size is private data of MemoryRegion, use the proper memory_region_size() getter to get it.

---
 hw/s390x/s390-pci-inst.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
hw/s390x/s390-pci-inst.c +1 -1
index a3bb5aa2216..5841dfc4fec 100644
@@ -396,7 +396,7 @@ static MemoryRegion *s390_get_subregion(MemoryRegion *mr, uint64_t offset,
     uint64_t subregion_size;
 
     QTAILQ_FOREACH(subregion, &mr->subregions, subregions_link) {
-        subregion_size = int128_get64(subregion->size);
+        subregion_size = memory_region_size(subregion);
         if ((offset >= subregion->addr) &&
             (offset + len) <= (subregion->addr + subregion_size)) {
             mr = subregion;
Signature · 1 line
2.51.0
Reviewed-by on v3 9/25
#22 lore raw

Re: [PATCH v3 09/25] hw/s390x: Use memory_region_size()

Quoted 13 lines · Philippe Mathieu-Daudé

MemoryRegion::size is private data of MemoryRegion, use the proper memory_region_size() getter to get it.

---
  hw/s390x/s390-pci-inst.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
hw/s390x/s390-pci-inst.c +0 -0
index a3bb5aa2216..5841dfc4fec 100644

hw/s390x/s390-pci-inst.c static MemoryRegion *s390_get_subregion(MemoryRegion *mr, uint64_t offset, · line 402

Quoted 8 lines
hw/s390x/s390-pci-inst.c +1 -1
@@ -396,7 +396,7 @@ static MemoryRegion *s390_get_subregion(MemoryRegion *mr, uint64_t offset,
      uint64_t subregion_size;
 
      QTAILQ_FOREACH(subregion, &mr->subregions, subregions_link) {
-        subregion_size = int128_get64(subregion->size);
+        subregion_size = memory_region_size(subregion);
          if ((offset >= subregion->addr) &&
              (offset + len) <= (subregion->addr + subregion_size)) {
              mr = subregion;
Reviewed-by on v3 9/25
#23 lore raw

Re: [PATCH v3 09/25] hw/s390x: Use memory_region_size()

In reply to Philippe Mathieu-Daudé
Quoted 7 lines · Philippe Mathieu-Daudé

MemoryRegion::size is private data of MemoryRegion, use the proper memory_region_size() getter to get it.

---
  hw/s390x/s390-pci-inst.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)

r~

Reviewed-by on v3 9/25
#24 lore raw

Re: [PATCH v3 09/25] hw/s390x: Use memory_region_size()

In reply to Philippe Mathieu-Daudé
Quoted 13 lines · Philippe Mathieu-Daudé

MemoryRegion::size is private data of MemoryRegion, use the proper memory_region_size() getter to get it.

---
  hw/s390x/s390-pci-inst.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
hw/s390x/s390-pci-inst.c +0 -0
index a3bb5aa2216..5841dfc4fec 100644

hw/s390x/s390-pci-inst.c static MemoryRegion *s390_get_subregion(MemoryRegion *mr, uint64_t offset, · line 402

Quoted 8 lines
hw/s390x/s390-pci-inst.c +1 -1
@@ -396,7 +396,7 @@ static MemoryRegion *s390_get_subregion(MemoryRegion *mr, uint64_t offset,
      uint64_t subregion_size;
 
      QTAILQ_FOREACH(subregion, &mr->subregions, subregions_link) {
-        subregion_size = int128_get64(subregion->size);
+        subregion_size = memory_region_size(subregion);
          if ((offset >= subregion->addr) &&
              (offset + len) <= (subregion->addr + subregion_size)) {
              mr = subregion;
Signature · 3 lines
Cheers

David / dhildenb
#25 lore raw

PATCH v3 10/25 system/memory: Have memory_region_size() take a const argument

In reply to Philippe Mathieu-Daudé

Since the @mr argument is not modified, it can be const.

---
 include/system/memory.h | 2 +-
 system/memory.c         | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
include/system/memory.h +1 -1
index 3bd5ffa5e0d..45de6946812 100644
@@ -1776,7 +1776,7 @@ Object *memory_region_owner(MemoryRegion *mr);
  *
  * @mr: the memory region being queried.
  */
-uint64_t memory_region_size(MemoryRegion *mr);
+uint64_t memory_region_size(const MemoryRegion *mr);
 
 /**
  * memory_region_is_ram: check whether a memory region is random access
system/memory.c +1 -1
index 8b84661ae36..d1c060b2b50 100644
@@ -1870,7 +1870,7 @@ void memory_region_unref(MemoryRegion *mr)
     }
 }
 
-uint64_t memory_region_size(MemoryRegion *mr)
+uint64_t memory_region_size(const MemoryRegion *mr)
 {
     if (int128_eq(mr->size, int128_2_64())) {
         return UINT64_MAX;
Signature · 1 line
2.51.0
Reviewed-by on v3 10/25
#27 lore raw

Re: [PATCH v3 10/25] system/memory: Have memory_region_size() take a const argument

In reply to Philippe Mathieu-Daudé
Quoted 26 lines · Philippe Mathieu-Daudé

Since the @mr argument is not modified, it can be const.

---
  include/system/memory.h | 2 +-
  system/memory.c         | 2 +-
  2 files changed, 2 insertions(+), 2 deletions(-)
include/system/memory.h +1 -1
index 3bd5ffa5e0d..45de6946812 100644
@@ -1776,7 +1776,7 @@ Object *memory_region_owner(MemoryRegion *mr);
   *
   * @mr: the memory region being queried.
   */
-uint64_t memory_region_size(MemoryRegion *mr);
+uint64_t memory_region_size(const MemoryRegion *mr);
 
  /**
   * memory_region_is_ram: check whether a memory region is random access
system/memory.c +0 -0
index 8b84661ae36..d1c060b2b50 100644

system/memory.c void memory_region_unref(MemoryRegion *mr) · line 1876

Quoted 8 lines
system/memory.c +1 -1
@@ -1870,7 +1870,7 @@ void memory_region_unref(MemoryRegion *mr)
      }
  }
 
-uint64_t memory_region_size(MemoryRegion *mr)
+uint64_t memory_region_size(const MemoryRegion *mr)
  {
      if (int128_eq(mr->size, int128_2_64())) {
          return UINT64_MAX;
Reviewed-by on v3 10/25
#28 lore raw

Re: [PATCH v3 10/25] system/memory: Have memory_region_size() take a const argument

In reply to Philippe Mathieu-Daudé
Quoted 7 lines · Philippe Mathieu-Daudé

Since the @mr argument is not modified, it can be const.

---
  include/system/memory.h | 2 +-
  system/memory.c         | 2 +-
  2 files changed, 2 insertions(+), 2 deletions(-)

r~

#30 lore raw

PATCH v3 11/25 system/memory: Introduce memory_region_get_address()

In reply to Philippe Mathieu-Daudé

MemoryRegion::addr is private data of MemoryRegion. Introduce memory_region_get_address() to get it, similar to memory_region_set_address() to set it.

---
 include/system/memory.h | 7 +++++++
 system/memory.c         | 5 +++++
 2 files changed, 12 insertions(+)
include/system/memory.h +7 -0
index 45de6946812..d2a5850a360 100644
@@ -2481,6 +2481,13 @@ void memory_region_set_enabled(MemoryRegion *mr, bool enabled);
  */
 void memory_region_set_address(MemoryRegion *mr, hwaddr addr);
 
+/**
+ * memory_region_get_address: Get the base address of a memory region
+ *
+ * @mr: the region to be queried
+ */
+hwaddr memory_region_get_address(const MemoryRegion *mr);
+
 /*
  * memory_region_set_size: dynamically update the size of a region.
  *
system/memory.c +5 -0
index d1c060b2b50..f48b586122d 100644
@@ -2777,6 +2777,11 @@ void memory_region_set_address(MemoryRegion *mr, hwaddr addr)
     }
 }
 
+hwaddr memory_region_get_address(const MemoryRegion *mr)
+{
+    return mr->addr;
+}
+
 void memory_region_set_alias_offset(MemoryRegion *mr, hwaddr offset)
 {
     assert(mr->alias);
Signature · 1 line
2.51.0
Acked-by on v3 11/25
#31 lore raw

Re: [PATCH v3 11/25] system/memory: Introduce memory_region_get_address()

Quoted 6 lines · Philippe Mathieu-Daudé

MemoryRegion::addr is private data of MemoryRegion. Introduce memory_region_get_address() to get it, similar to memory_region_set_address() to set it.

Signature · 1 line
Peter Xu
Reviewed-by on v3 11/25
#32 lore raw

Re: [PATCH v3 11/25] system/memory: Introduce memory_region_get_address()

In reply to Philippe Mathieu-Daudé
Quoted 10 lines · Philippe Mathieu-Daudé

MemoryRegion::addr is private data of MemoryRegion. Introduce memory_region_get_address() to get it, similar to memory_region_set_address() to set it.

---
  include/system/memory.h | 7 +++++++
  system/memory.c         | 5 +++++
  2 files changed, 12 insertions(+)
Reviewed-by on v3 11/25
#33 lore raw

Re: [PATCH v3 11/25] system/memory: Introduce memory_region_get_address()

In reply to Philippe Mathieu-Daudé
Quoted 10 lines · Philippe Mathieu-Daudé

MemoryRegion::addr is private data of MemoryRegion. Introduce memory_region_get_address() to get it, similar to memory_region_set_address() to set it.

---
  include/system/memory.h | 7 +++++++
  system/memory.c         | 5 +++++
  2 files changed, 12 insertions(+)

I agree with Thomas that this should come first, and no new uses of mr->addr should be added in the first couple of patches.

r~

Reviewed-by on v3 11/25
#34 lore raw

Re: [PATCH v3 11/25] system/memory: Introduce memory_region_get_address()

In reply to Philippe Mathieu-Daudé
Quoted 7 lines · Philippe Mathieu-Daudé

MemoryRegion::addr is private data of MemoryRegion. Introduce memory_region_get_address() to get it, similar to memory_region_set_address() to set it.

---

Signature · 3 lines
Cheers

David / dhildenb
#35 lore raw

PATCH v3 12/25 migration/ram: Use memory_region_get_address()

In reply to Philippe Mathieu-Daudé

MemoryRegion::addr is private data of MemoryRegion, use memory_region_get_address() to access it.

---
 migration/ram.c | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)
migration/ram.c +6 -5
index 5eef2efc781..3330c102977 100644
@@ -3144,7 +3144,7 @@ static int ram_save_setup(QEMUFile *f, void *opaque, Error **errp)
                 qemu_put_be64(f, block->page_size);
             }
             if (migrate_ignore_shared()) {
-                qemu_put_be64(f, block->mr->addr);
+                qemu_put_be64(f, memory_region_get_address(block->mr));
             }
 
             if (migrate_mapped_ram()) {
@@ -4190,11 +4190,12 @@ static int parse_ramblock(QEMUFile *f, RAMBlock *block, ram_addr_t length)
     }
     if (migrate_ignore_shared()) {
         hwaddr addr = qemu_get_be64(f);
-        if (migrate_ram_is_ignored(block) &&
-            block->mr->addr != addr) {
+        hwaddr block_addr = memory_region_get_address(block->mr);
+
+        if (migrate_ram_is_ignored(block) && block_addr != addr) {
             error_report("Mismatched GPAs for block %s "
-                         "%" PRId64 "!= %" PRId64, block->idstr,
-                         (uint64_t)addr, (uint64_t)block->mr->addr);
+                         "0x" HWADDR_FMT_plx "!= 0x" HWADDR_FMT_plx,
+                         block->idstr, addr, block_addr);
             return -EINVAL;
         }
     }
Signature · 1 line
2.51.0
Reviewed-by on v3 12/25
#37 lore raw

Re: [PATCH v3 12/25] migration/ram: Use memory_region_get_address()

In reply to Philippe Mathieu-Daudé
Quoted 7 lines · Philippe Mathieu-Daudé

MemoryRegion::addr is private data of MemoryRegion, use memory_region_get_address() to access it.

---
  migration/ram.c | 11 ++++++-----
  1 file changed, 6 insertions(+), 5 deletions(-)

r~

#38 lore raw

PATCH v3 13/25 hw/acpi: Use memory_region_get_address()

In reply to Philippe Mathieu-Daudé

MemoryRegion::addr is private data of MemoryRegion, use memory_region_get_address() to access it.

---
 hw/acpi/cxl.c                  | 8 ++++++--
 hw/i386/acpi-build.c           | 8 +++++---
 hw/loongarch/virt-acpi-build.c | 4 ++--
 3 files changed, 13 insertions(+), 7 deletions(-)
hw/acpi/cxl.c +6 -2
index 77c99dfb184..92c032851cc 100644
@@ -105,6 +105,7 @@ static void cedt_build_chbs(GArray *table_data, PXBCXLDev *cxl)
     PXBDev *pxb = PXB_DEV(cxl);
     SysBusDevice *sbd = SYS_BUS_DEVICE(cxl->cxl_host_bridge);
     MemoryRegion *mr = sysbus_mmio_get_region(sbd, 0);
+    hwaddr container_base_addr = memory_region_get_address(mr->container);
 
     /* Type */
     build_append_int_noprefix(table_data, 0, 1);
@@ -125,7 +126,9 @@ static void cedt_build_chbs(GArray *table_data, PXBCXLDev *cxl)
     build_append_int_noprefix(table_data, 0, 4);
 
     /* Base - subregion within a container that is in PA space */
-    build_append_int_noprefix(table_data, mr->container->addr + mr->addr, 8);
+    build_append_int_noprefix(table_data,
+                              container_base_addr
+                              + memory_region_get_address(mr), 8);
 
     /* Length */
     build_append_int_noprefix(table_data, memory_region_size(mr), 8);
@@ -154,7 +157,8 @@ static void cedt_build_cfmws(CXLFixedWindow *fw, Aml *cedt)
     build_append_int_noprefix(table_data, 0, 4);
 
     /* Base HPA */
-    build_append_int_noprefix(table_data, fw->mr.addr, 8);
+    build_append_int_noprefix(table_data,
+                              memory_region_get_address(&fw->mr), 8);
 
     /* Window Size */
     build_append_int_noprefix(table_data, fw->size, 8);
hw/i386/acpi-build.c +5 -3
index 9446a9f862c..201fdbb39f0 100644
@@ -1039,7 +1039,7 @@ build_dsdt(GArray *table_data, BIOSLinker *linker,
             /* Handle the ranges for the PXB expanders */
             if (pci_bus_is_cxl(bus)) {
                 MemoryRegion *mr = &pcms->cxl_devices_state.host_mr;
-                uint64_t base = mr->addr;
+                hwaddr base = memory_region_get_address(mr);
 
                 cxl_present = true;
                 crs_range_insert(crs_range_set.mem_ranges, base,
@@ -1822,7 +1822,8 @@ build_amd_iommu(GArray *table_data, BIOSLinker *linker, const char *oem_id,
     /* Capability offset */
     build_append_int_noprefix(table_data, s->pci->capab_offset, 2);
     /* IOMMU base address */
-    build_append_int_noprefix(table_data, s->mr_mmio.addr, 8);
+    build_append_int_noprefix(table_data,
+                              memory_region_get_address(&s->mr_mmio), 8);
     /* PCI Segment Group */
     build_append_int_noprefix(table_data, 0, 2);
     /* IOMMU info */
@@ -1857,7 +1858,8 @@ build_amd_iommu(GArray *table_data, BIOSLinker *linker, const char *oem_id,
     /* Capability offset */
     build_append_int_noprefix(table_data, s->pci->capab_offset, 2);
     /* IOMMU base address */
-    build_append_int_noprefix(table_data, s->mr_mmio.addr, 8);
+    build_append_int_noprefix(table_data,
+                              memory_region_get_address(&s->mr_mmio), 8);
     /* PCI Segment Group */
     build_append_int_noprefix(table_data, 0, 2);
     /* IOMMU info */
hw/loongarch/virt-acpi-build.c +2 -2
index 3694c9827f0..101d083ae6a 100644
@@ -409,11 +409,11 @@ static void build_flash_aml(Aml *scope, LoongArchVirtMachineState *lvms)
     hwaddr flash1_size;
 
     flash_mem = pflash_cfi01_get_memory(lvms->flash[0]);
-    flash0_base = flash_mem->addr;
+    flash0_base = memory_region_get_address(flash_mem);
     flash0_size = memory_region_size(flash_mem);
 
     flash_mem = pflash_cfi01_get_memory(lvms->flash[1]);
-    flash1_base = flash_mem->addr;
+    flash1_base = memory_region_get_address(flash_mem);
     flash1_size = memory_region_size(flash_mem);
 
     dev = aml_device("FLS0");
Signature · 1 line
2.51.0
#39 lore raw

Re: [PATCH v3 13/25] hw/acpi: Use memory_region_get_address()

Quoted 10 lines · Philippe Mathieu-Daudé

+++ b/hw/acpi/cxl.c

hw/acpi/cxl.c +1 -0
@@ -105,6 +105,7 @@ static void cedt_build_chbs(GArray *table_data, PXBCXLDev *cxl)
      PXBDev *pxb = PXB_DEV(cxl);
      SysBusDevice *sbd = SYS_BUS_DEVICE(cxl->cxl_host_bridge);
      MemoryRegion *mr = sysbus_mmio_get_region(sbd, 0);
+    hwaddr container_base_addr = memory_region_get_address(mr->container);
 
      /* Type */
      build_append_int_noprefix(table_data, 0, 1);

hw/acpi/cxl.c static void cedt_build_chbs(GArray *table_data, PXBCXLDev *cxl) · line 131

Quoted 7 lines
hw/acpi/cxl.c +3 -1
@@ -125,7 +126,9 @@ static void cedt_build_chbs(GArray *table_data, PXBCXLDev *cxl)
      build_append_int_noprefix(table_data, 0, 4);
 
      /* Base - subregion within a container that is in PA space */
-    build_append_int_noprefix(table_data, mr->container->addr + mr->addr, 8);
+    build_append_int_noprefix(table_data,
+                              container_base_addr
+                              + memory_region_get_address(mr), 8);

Why the single-use variable, instead of expanding here, like what you're replacing?

r~

Acked-by Jonathan Cameron on v3 13/25
#40 lore raw

Re: [PATCH v3 13/25] hw/acpi: Use memory_region_get_address()

In reply to Philippe Mathieu-Daudé
Quoted 6 lines · On Tue, 28 Oct 2025 19:12:47 +0100 Philippe Mathieu-Daudé <[email protected]>…

MemoryRegion::addr is private data of MemoryRegion, use memory_region_get_address() to access it.

---
 hw/acpi/cxl.c                  | 8 ++++++--
Quoted 37 lines
 hw/i386/acpi-build.c           | 8 +++++---
 hw/loongarch/virt-acpi-build.c | 4 ++--
 3 files changed, 13 insertions(+), 7 deletions(-)
hw/acpi/cxl.c +6 -2
index 77c99dfb184..92c032851cc 100644
@@ -105,6 +105,7 @@ static void cedt_build_chbs(GArray *table_data, PXBCXLDev *cxl)
     PXBDev *pxb = PXB_DEV(cxl);
     SysBusDevice *sbd = SYS_BUS_DEVICE(cxl->cxl_host_bridge);
     MemoryRegion *mr = sysbus_mmio_get_region(sbd, 0);
+    hwaddr container_base_addr = memory_region_get_address(mr->container);
 
     /* Type */
     build_append_int_noprefix(table_data, 0, 1);
@@ -125,7 +126,9 @@ static void cedt_build_chbs(GArray *table_data, PXBCXLDev *cxl)
     build_append_int_noprefix(table_data, 0, 4);
 
     /* Base - subregion within a container that is in PA space */
-    build_append_int_noprefix(table_data, mr->container->addr + mr->addr, 8);
+    build_append_int_noprefix(table_data,
+                              container_base_addr
+                              + memory_region_get_address(mr), 8);
 
     /* Length */
     build_append_int_noprefix(table_data, memory_region_size(mr), 8);
@@ -154,7 +157,8 @@ static void cedt_build_cfmws(CXLFixedWindow *fw, Aml *cedt)
     build_append_int_noprefix(table_data, 0, 4);
 
     /* Base HPA */
-    build_append_int_noprefix(table_data, fw->mr.addr, 8);
+    build_append_int_noprefix(table_data,
+                              memory_region_get_address(&fw->mr), 8);
 
     /* Window Size */
     build_append_int_noprefix(table_data, fw->size, 8);
#41 lore raw

PATCH v3 14/25 hw/fdt: Use memory_region_get_address()

In reply to Philippe Mathieu-Daudé

MemoryRegion::addr is private data of MemoryRegion, use memory_region_get_address() to access it.

---
 hw/i386/microvm-dt.c          | 4 ++--
 hw/loongarch/virt-fdt-build.c | 4 ++--
 2 files changed, 4 insertions(+), 4 deletions(-)
hw/i386/microvm-dt.c +2 -2
index d7f49bc1b5f..5b64f5b7f30 100644
@@ -72,7 +72,7 @@ static void dt_add_virtio(MicrovmMachineState *mms, VirtIOMMIOProxy *mmio)
     }
 
     MemoryRegion *mr = sysbus_mmio_get_region(dev, 0);
-    hwaddr base = mr->addr;
+    hwaddr base = memory_region_get_address(mr);
     hwaddr size = 512;
     unsigned index = (base - VIRTIO_MMIO_BASE) / size;
     uint32_t irq = mms->virtio_irq_base + index;
@@ -152,7 +152,7 @@ static void dt_add_pcie(MicrovmMachineState *mms)
 static void dt_add_ioapic(MicrovmMachineState *mms, SysBusDevice *dev)
 {
     MemoryRegion *mr = sysbus_mmio_get_region(dev, 0);
-    hwaddr base = mr->addr;
+    hwaddr base = memory_region_get_address(mr);
     char *nodename;
     uint32_t ph;
     int index;
hw/loongarch/virt-fdt-build.c +2 -2
index 1f0ba01f711..54524e5aca9 100644
@@ -195,11 +195,11 @@ static void fdt_add_flash_node(LoongArchVirtMachineState *lvms)
     hwaddr flash1_size;
 
     flash_mem = pflash_cfi01_get_memory(lvms->flash[0]);
-    flash0_base = flash_mem->addr;
+    flash0_base = memory_region_get_address(flash_mem);
     flash0_size = memory_region_size(flash_mem);
 
     flash_mem = pflash_cfi01_get_memory(lvms->flash[1]);
-    flash1_base = flash_mem->addr;
+    flash1_base = memory_region_get_address(flash_mem);
     flash1_size = memory_region_size(flash_mem);
 
     nodename = g_strdup_printf("/flash@%" PRIx64, flash0_base);
Signature · 1 line
2.51.0
Reviewed-by on v3 14/25
#42 lore raw

Re: [PATCH v3 14/25] hw/fdt: Use memory_region_get_address()

Quoted 8 lines · Philippe Mathieu-Daudé

MemoryRegion::addr is private data of MemoryRegion, use memory_region_get_address() to access it.

---
  hw/i386/microvm-dt.c          | 4 ++--
  hw/loongarch/virt-fdt-build.c | 4 ++--
  2 files changed, 4 insertions(+), 4 deletions(-)

r~

#43 lore raw

PATCH v3 15/25 hw/nvme: Use memory_region_get_address()

In reply to Philippe Mathieu-Daudé

MemoryRegion::addr is private data of MemoryRegion, use memory_region_get_address() to access it.

---
 hw/nvme/ctrl.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
hw/nvme/ctrl.c +4 -3
index 9505f291f62..65cc1c8ee52 100644
@@ -522,7 +522,7 @@ static bool nvme_addr_is_cmb(NvmeCtrl *n, hwaddr addr)
     }
 
     mr = &n->cmb.mem;
-    lo = n->params.legacy_cmb ? n->cmb.mem.addr : n->cmb.cba;
+    lo = n->params.legacy_cmb ? memory_region_get_address(mr) : n->cmb.cba;
     hi = lo + memory_region_size(mr);
 
     return addr >= lo && addr < hi;
@@ -530,7 +530,8 @@ static bool nvme_addr_is_cmb(NvmeCtrl *n, hwaddr addr)
 
 static inline void *nvme_addr_to_cmb(NvmeCtrl *n, hwaddr addr)
 {
-    hwaddr base = n->params.legacy_cmb ? n->cmb.mem.addr : n->cmb.cba;
+    hwaddr base = n->params.legacy_cmb ? memory_region_get_address(&n->cmb.mem)
+                                       : n->cmb.cba;
     return &n->cmb.buf[addr - base];
 }
 
@@ -564,7 +565,7 @@ static inline bool nvme_addr_is_iomem(NvmeCtrl *n, hwaddr addr)
      * that if the device model is ever changed to allow the CMB to be located
      * in BAR0 as well, then this must be changed.
      */
-    lo = n->bar0.addr;
+    lo = memory_region_get_address(&n->bar0);
     hi = lo + memory_region_size(&n->bar0);
 
     return addr >= lo && addr < hi;
Signature · 1 line
2.51.0
#46 lore raw

PATCH v3 16/25 hw/s390x: Use memory_region_get_address()

In reply to Philippe Mathieu-Daudé

MemoryRegion::addr is private data of MemoryRegion, use memory_region_get_address() to access it.

---
 hw/s390x/s390-pci-inst.c | 21 ++++++++++++++-------
 1 file changed, 14 insertions(+), 7 deletions(-)
hw/s390x/s390-pci-inst.c +14 -7
index 5841dfc4fec..d4adf782ca1 100644
@@ -394,11 +394,14 @@ static MemoryRegion *s390_get_subregion(MemoryRegion *mr, uint64_t offset,
 {
     MemoryRegion *subregion;
     uint64_t subregion_size;
+    hwaddr subregion_addr;
 
     QTAILQ_FOREACH(subregion, &mr->subregions, subregions_link) {
         subregion_size = memory_region_size(subregion);
-        if ((offset >= subregion->addr) &&
-            (offset + len) <= (subregion->addr + subregion_size)) {
+        subregion_addr = memory_region_get_address(subregion);
+
+        if ((offset >= subregion_addr) &&
+            (offset + len) <= (subregion_addr + subregion_size)) {
             mr = subregion;
             break;
         }
@@ -410,11 +413,12 @@ static MemTxResult zpci_read_bar(S390PCIBusDevice *pbdev, uint8_t pcias,
                                  uint64_t offset, uint64_t *data, uint8_t len)
 {
     MemoryRegion *mr;
+    hwaddr subregion_base_addr;
 
     mr = pbdev->pdev->io_regions[pcias].memory;
     mr = s390_get_subregion(mr, offset, len);
-    offset -= mr->addr;
-    return memory_region_dispatch_read(mr, offset, data,
+    subregion_base_addr = memory_region_get_address(mr);
+    return memory_region_dispatch_read(mr, offset - subregion_base_addr, data,
                                        size_memop(len) | MO_BE,
                                        MEMTXATTRS_UNSPECIFIED);
 }
@@ -510,11 +514,12 @@ static MemTxResult zpci_write_bar(S390PCIBusDevice *pbdev, uint8_t pcias,
                                   uint64_t offset, uint64_t data, uint8_t len)
 {
     MemoryRegion *mr;
+    hwaddr subregion_base_addr;
 
     mr = pbdev->pdev->io_regions[pcias].memory;
     mr = s390_get_subregion(mr, offset, len);
-    offset -= mr->addr;
-    return memory_region_dispatch_write(mr, offset, data,
+    subregion_base_addr = memory_region_get_address(mr);
+    return memory_region_dispatch_write(mr, offset - subregion_base_addr, data,
                                         size_memop(len) | MO_BE,
                                         MEMTXATTRS_UNSPECIFIED);
 }
@@ -832,6 +837,7 @@ int pcistb_service_call(S390CPU *cpu, uint8_t r1, uint8_t r3, uint64_t gaddr,
     S390PCIBusDevice *pbdev;
     MemoryRegion *mr;
     MemTxResult result;
+    hwaddr subregion_base_addr;
     uint64_t offset;
     int i;
     uint32_t fh;
@@ -900,7 +906,8 @@ int pcistb_service_call(S390CPU *cpu, uint8_t r1, uint8_t r3, uint64_t gaddr,
 
     mr = pbdev->pdev->io_regions[pcias].memory;
     mr = s390_get_subregion(mr, offset, len);
-    offset -= mr->addr;
+    subregion_base_addr = memory_region_get_address(mr);
+    offset -= subregion_base_addr;
 
     for (i = 0; i < len; i += 8) {
         if (!memory_region_access_valid(mr, offset + i, 8, true,
Signature · 1 line
2.51.0
Reviewed-by on v3 16/25
#47 lore raw

Re: [PATCH v3 16/25] hw/s390x: Use memory_region_get_address()

Quoted 16 lines · Philippe Mathieu-Daudé

MemoryRegion::addr is private data of MemoryRegion, use memory_region_get_address() to access it.

---
  hw/s390x/s390-pci-inst.c | 21 ++++++++++++++-------
  1 file changed, 14 insertions(+), 7 deletions(-)
hw/s390x/s390-pci-inst.c +0 -0
index 5841dfc4fec..d4adf782ca1 100644
@@ -394,11 +394,14 @@ static MemoryRegion *s390_get_subregion(MemoryRegion *mr, uint64_t offset,
  {
      MemoryRegion *subregion;
      uint64_t subregion_size;

hw/s390x/s390-pci-inst.c static MemoryRegion *s390_get_subregion(MemoryRegion *mr, uint64_t offset, · line 404

Quoted 10 lines
hw/s390x/s390-pci-inst.c +5 -2
+    hwaddr subregion_addr;
 
      QTAILQ_FOREACH(subregion, &mr->subregions, subregions_link) {
          subregion_size = memory_region_size(subregion);
-        if ((offset >= subregion->addr) &&
-            (offset + len) <= (subregion->addr + subregion_size)) {
+        subregion_addr = memory_region_get_address(subregion);
+
+        if ((offset >= subregion_addr) &&
+            (offset + len) <= (subregion_addr + subregion_size)) {

While you're at it, you could also drop the superfluous parentheses here.

Anyway:

#48 lore raw

Re: [PATCH v3 16/25] hw/s390x: Use memory_region_get_address()

In reply to Philippe Mathieu-Daudé

hw/s390x/s390-pci-inst.c static MemTxResult zpci_write_bar(S390PCIBusDevice *pbdev, uint8_t pcias, · line 521

Quoted 12 lines
hw/s390x/s390-pci-inst.c +2 -2
@@ -510,11 +514,12 @@ static MemTxResult zpci_write_bar(S390PCIBusDevice *pbdev, uint8_t pcias,
                                    uint64_t offset, uint64_t data, uint8_t len)
  {
      MemoryRegion *mr;
+    hwaddr subregion_base_addr;
 
      mr = pbdev->pdev->io_regions[pcias].memory;
      mr = s390_get_subregion(mr, offset, len);
-    offset -= mr->addr;
-    return memory_region_dispatch_write(mr, offset, data,
+    subregion_base_addr = memory_region_get_address(mr);

Any partixular reason for the temp variable?

Quoted 13 lines
hw/s390x/s390-pci-inst.c +2 -0
+    return memory_region_dispatch_write(mr, offset - subregion_base_addr, data,
                                          size_memop(len) | MO_BE,
                                          MEMTXATTRS_UNSPECIFIED);
  }
@@ -832,6 +837,7 @@ int pcistb_service_call(S390CPU *cpu, uint8_t r1, uint8_t r3, uint64_t gaddr,
      S390PCIBusDevice *pbdev;
      MemoryRegion *mr;
      MemTxResult result;
+    hwaddr subregion_base_addr;
      uint64_t offset;
      int i;
      uint32_t fh;

hw/s390x/s390-pci-inst.c int pcistb_service_call(S390CPU *cpu, uint8_t r1, uint8_t r3, uint64_t gaddr, · line 909

Quoted 5 lines
hw/s390x/s390-pci-inst.c +1 -1
@@ -900,7 +906,8 @@ int pcistb_service_call(S390CPU *cpu, uint8_t r1, uint8_t r3, uint64_t gaddr,
 
      mr = pbdev->pdev->io_regions[pcias].memory;
      mr = s390_get_subregion(mr, offset, len);
-    offset -= mr->addr;
+    subregion_base_addr = memory_region_get_address(mr);

Dito

Signature · 3 lines
Cheers

David / dhildenb
#49 lore raw

Re: [PATCH v3 16/25] hw/s390x: Use memory_region_get_address()

Quoted 14 lines · David Hildenbrand

hw/s390x/s390-pci-inst.c static MemTxResult · line 521

Quoted 12 lines
hw/s390x/s390-pci-inst.c +2 -2
@@ -510,11 +514,12 @@ static MemTxResult 
 zpci_write_bar(S390PCIBusDevice *pbdev, uint8_t pcias,
                                     uint64_t offset, uint64_t data, uint8_t len)
   {
       MemoryRegion *mr;
+    hwaddr subregion_base_addr;
       mr = pbdev->pdev->io_regions[pcias].memory;
       mr = s390_get_subregion(mr, offset, len);
-    offset -= mr->addr;
-    return memory_region_dispatch_write(mr, offset, data,
+    subregion_base_addr = memory_region_get_address(mr);

Any partixular reason for the temp variable?

To fit the 72-80 chars per line limit. Since various people asked the same, I'll just replace in place, ignoring the checkpatch.pl warnings.

Quoted 25 lines
Quoted 16 lines
hw/s390x/s390-pci-inst.c +1 -0
+    return memory_region_dispatch_write(mr, offset - 
 subregion_base_addr, data,
                                           size_memop(len) | MO_BE,
                                           MEMTXATTRS_UNSPECIFIED);

  }

hw/s390x/s390-pci-inst.c +1 -0
@@ -832,6 +837,7 @@ int pcistb_service_call(S390CPU *cpu, uint8_t r1, 
 uint8_t r3, uint64_t gaddr,
       S390PCIBusDevice *pbdev;
       MemoryRegion *mr;
       MemTxResult result;
+    hwaddr subregion_base_addr;
       uint64_t offset;
       int i;

      uint32_t fh;

hw/s390x/s390-pci-inst.c int pcistb_service_call(S390CPU *cpu, uint8_t r1, · line 909

Quoted 5 lines
hw/s390x/s390-pci-inst.c +1 -1
@@ -900,7 +906,8 @@ int pcistb_service_call(S390CPU *cpu, uint8_t r1, 
 uint8_t r3, uint64_t gaddr,
       mr = pbdev->pdev->io_regions[pcias].memory;
       mr = s390_get_subregion(mr, offset, len);
-    offset -= mr->addr;
+    subregion_base_addr = memory_region_get_address(mr);

Dito

#50 lore raw

Re: [PATCH v3 16/25] hw/s390x: Use memory_region_get_address()

Quoted 17 lines · Philippe Mathieu-Daudé
Quoted 15 lines · David Hildenbrand

hw/s390x/s390-pci-inst.c static MemTxResult · line 522

Quoted 13 lines
hw/s390x/s390-pci-inst.c +2 -2
@@ -510,11 +514,12 @@ static MemTxResult
 zpci_write_bar(S390PCIBusDevice *pbdev, uint8_t pcias,
                                     uint64_t offset, uint64_t data,
 uint8_t len)
   {
       MemoryRegion *mr;
+    hwaddr subregion_base_addr;
       mr = pbdev->pdev->io_regions[pcias].memory;
       mr = s390_get_subregion(mr, offset, len);
-    offset -= mr->addr;
-    return memory_region_dispatch_write(mr, offset, data,
+    subregion_base_addr = memory_region_get_address(mr);

Any partixular reason for the temp variable?

Quoted 3 lines

To fit the 72-80 chars per line limit. Since various people asked the same, I'll just replace in place, ignoring the checkpatch.pl warnings.

I was wondering about a simple

	offset -= memory_region_get_address(mr);

by minimizing changes to surrounding code.

Anyhow, I was just wondering about that.

Signature · 3 lines
Cheers

David / dhildenb
#51 lore raw

PATCH v3 17/25 hw/timer/hpet: Use memory_region_get_address()

In reply to Philippe Mathieu-Daudé

MemoryRegion::addr is private data of MemoryRegion, use memory_region_get_address() to access it.

---
 hw/timer/hpet.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
hw/timer/hpet.c +1 -1
index c1b96d0a89f..e2cd0c9cccb 100644
@@ -677,7 +677,7 @@ static void hpet_reset(DeviceState *d)
     s->hpet_offset = 0ULL;
     s->config = 0ULL;
     hpet_fw_cfg.hpet[s->hpet_id].event_timer_block_id = (uint32_t)s->capability;
-    hpet_fw_cfg.hpet[s->hpet_id].address = mr->addr;
+    hpet_fw_cfg.hpet[s->hpet_id].address = memory_region_get_address(mr);
 
     /* to document that the RTC lowers its output on reset as well */
     s->rtc_irq_level = 0;
Signature · 1 line
2.51.0
Reviewed-by on v3 17/25
#53 lore raw

Re: [PATCH v3 17/25] hw/timer/hpet: Use memory_region_get_address()

In reply to Philippe Mathieu-Daudé
Quoted 5 lines · Philippe Mathieu-Daudé

Date: Tue, 28 Oct 2025 19:12:51 +0100
From: Philippe Mathieu-Daudé <[email protected]>
Subject: [PATCH v3 17/25] hw/timer/hpet: Use memory_region_get_address()
X-Mailer: git-send-email 2.51.0

Quoted 7 lines

MemoryRegion::addr is private data of MemoryRegion, use memory_region_get_address() to access it.

---
 hw/timer/hpet.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
#54 lore raw

PATCH v3 18/25 hw/watchdog/aspeed: Use memory_region_get_address()

In reply to Philippe Mathieu-Daudé

MemoryRegion::addr is private data of MemoryRegion, use memory_region_get_address() to access it.

---
 hw/watchdog/wdt_aspeed.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
hw/watchdog/wdt_aspeed.c +1 -1
index 30226435efc..f842d8e973a 100644
@@ -274,7 +274,7 @@ static void aspeed_wdt_timer_expired(void *dev)
     }
 
     qemu_log_mask(CPU_LOG_RESET, "Watchdog timer %" HWADDR_PRIx " expired.\n",
-                  s->iomem.addr);
+                  memory_region_get_address(&s->iomem));
     watchdog_perform_action();
     timer_del(s->timer);
 }
Signature · 1 line
2.51.0
Reviewed-by on v3 18/25
#56 lore raw

Re: [PATCH v3 18/25] hw/watchdog/aspeed: Use memory_region_get_address()

In reply to Philippe Mathieu-Daudé
Quoted 13 lines · Philippe Mathieu-Daudé

MemoryRegion::addr is private data of MemoryRegion, use memory_region_get_address() to access it.

---
  hw/watchdog/wdt_aspeed.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
hw/watchdog/wdt_aspeed.c +0 -0
index 30226435efc..f842d8e973a 100644

hw/watchdog/wdt_aspeed.c static void aspeed_wdt_timer_expired(void *dev) · line 280

Quoted 8 lines
hw/watchdog/wdt_aspeed.c +1 -1
@@ -274,7 +274,7 @@ static void aspeed_wdt_timer_expired(void *dev)
      }
 
      qemu_log_mask(CPU_LOG_RESET, "Watchdog timer %" HWADDR_PRIx " expired.\n",
-                  s->iomem.addr);
+                  memory_region_get_address(&s->iomem));
      watchdog_perform_action();
      timer_del(s->timer);
  }

Thanks,

C.

#57 lore raw

PATCH v3 19/25 hw/pci-bridge: Use memory_region_get_address()

In reply to Philippe Mathieu-Daudé

MemoryRegion::addr is private data of MemoryRegion, use memory_region_get_address() to access it.

---
 hw/pci-bridge/pci_expander_bridge.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
hw/pci-bridge/pci_expander_bridge.c +1 -1
index aa55749954a..0cb94fca9c0 100644
@@ -161,7 +161,7 @@ static char *pxb_host_ofw_unit_address(const SysBusDevice *dev)
         MemoryRegion *mr = sysbus_mmio_get_region(main_host_sbd, 0);
 
         return g_strdup_printf(HWADDR_FMT_plx ",%x",
-                               mr->addr, position + 1);
+                               memory_region_get_address(mr), position + 1);
     }
     if (main_host_sbd->num_pio > 0) {
         return g_strdup_printf("i%04x,%x",
Signature · 1 line
2.51.0
#59 lore raw

PATCH v3 20/25 system/ioport: Use memory_region_get_address()

In reply to Philippe Mathieu-Daudé

MemoryRegion::addr is private data of MemoryRegion, use memory_region_get_address() to access it.

---
 system/ioport.c | 21 ++++++++++++++-------
 1 file changed, 14 insertions(+), 7 deletions(-)
system/ioport.c +14 -7
index 4f96e9119fc..9bb8df5e757 100644
@@ -177,17 +177,19 @@ static uint64_t portio_read(void *opaque, hwaddr addr, unsigned size)
 {
     MemoryRegionPortioList *mrpio = opaque;
     const MemoryRegionPortio *mrp = find_portio(mrpio, addr, size, false);
+    hwaddr pio_base_addr = memory_region_get_address(&mrpio->mr);
     uint64_t data;
 
     data = ((uint64_t)1 << (size * 8)) - 1;
     if (mrp) {
-        data = mrp->read(mrpio->portio_opaque, mrpio->mr.addr + addr);
+        data = mrp->read(mrpio->portio_opaque, pio_base_addr + addr);
     } else if (size == 2) {
         mrp = find_portio(mrpio, addr, 1, false);
         if (mrp) {
-            data = mrp->read(mrpio->portio_opaque, mrpio->mr.addr + addr);
+            data = mrp->read(mrpio->portio_opaque, pio_base_addr + addr);
             if (addr + 1 < mrp->offset + mrp->len) {
-                data |= mrp->read(mrpio->portio_opaque, mrpio->mr.addr + addr + 1) << 8;
+                data |= mrp->read(mrpio->portio_opaque,
+                                  pio_base_addr + addr + 1) << 8;
             } else {
                 data |= 0xff00;
             }
@@ -201,15 +203,17 @@ static void portio_write(void *opaque, hwaddr addr, uint64_t data,
 {
     MemoryRegionPortioList *mrpio = opaque;
     const MemoryRegionPortio *mrp = find_portio(mrpio, addr, size, true);
+    hwaddr pio_base_addr = memory_region_get_address(&mrpio->mr);
 
     if (mrp) {
-        mrp->write(mrpio->portio_opaque, mrpio->mr.addr + addr, data);
+        mrp->write(mrpio->portio_opaque, pio_base_addr + addr, data);
     } else if (size == 2) {
         mrp = find_portio(mrpio, addr, 1, true);
         if (mrp) {
-            mrp->write(mrpio->portio_opaque, mrpio->mr.addr + addr, data & 0xff);
+            mrp->write(mrpio->portio_opaque, pio_base_addr + addr, data & 0xff);
             if (addr + 1 < mrp->offset + mrp->len) {
-                mrp->write(mrpio->portio_opaque, mrpio->mr.addr + addr + 1, data >> 8);
+                mrp->write(mrpio->portio_opaque,
+                           pio_base_addr + addr + 1, data >> 8);
             }
         }
     }
@@ -335,12 +339,15 @@ void portio_list_set_enabled(PortioList *piolist, bool enabled)
 void portio_list_set_address(PortioList *piolist, uint32_t addr)
 {
     MemoryRegionPortioList *mrpio;
+    hwaddr pio_base_addr;
     unsigned i, j;
 
     for (i = 0; i < piolist->nr; ++i) {
         mrpio = container_of(piolist->regions[i], MemoryRegionPortioList, mr);
+        pio_base_addr = memory_region_get_address(&mrpio->mr);
+
         memory_region_set_address(&mrpio->mr,
-                                  mrpio->mr.addr - piolist->addr + addr);
+                                  pio_base_addr - piolist->addr + addr);
         for (j = 0; mrpio->ports[j].size; ++j) {
             mrpio->ports[j].offset += addr - piolist->addr;
         }
Signature · 1 line
2.51.0
#61 lore raw

PATCH v3 21/25 hw/sysbus: Use memory_region_get_address()

In reply to Philippe Mathieu-Daudé

MemoryRegion::addr is private data of MemoryRegion, use memory_region_get_address() to access it.

---
 hw/core/sysbus.c | 17 ++++++++++-------
 1 file changed, 10 insertions(+), 7 deletions(-)
hw/core/sysbus.c +10 -7
index d33be6b2b52..414b3f806d1 100644
@@ -257,13 +257,14 @@ bool sysbus_realize_and_unref(SysBusDevice *dev, Error **errp)
 static void sysbus_dev_print(Monitor *mon, DeviceState *dev, int indent)
 {
     SysBusDevice *s = SYS_BUS_DEVICE(dev);
-    hwaddr size;
-    int i;
 
-    for (i = 0; i < s->num_mmio; i++) {
-        size = memory_region_size(s->mmio[i].memory);
-        monitor_printf(mon, "%*smmio " HWADDR_FMT_plx "/" HWADDR_FMT_plx "\n",
-                       indent, "", s->mmio[i].addr, size);
+    for (int i = 0; i < s->num_mmio; i++) {
+        MemoryRegion *mr = sysbus_mmio_get_region(s, i);
+        hwaddr addr = memory_region_get_address(mr);
+        uint64_t size = memory_region_size(mr);
+
+        monitor_printf(mon, "%*smmio " HWADDR_FMT_plx "/%016" PRIx64 "\n",
+                       indent, "", addr, size);
     }
 }
 
@@ -282,8 +283,10 @@ static char *sysbus_get_fw_dev_path(DeviceState *dev)
         }
     }
     if (s->num_mmio) {
+        MemoryRegion *mr = sysbus_mmio_get_region(s, 0);
+
         return g_strdup_printf("%s@" HWADDR_FMT_plx, qdev_fw_name(dev),
-                               s->mmio[0].addr);
+                               memory_region_get_address(mr));
     }
     if (s->num_pio) {
         return g_strdup_printf("%s@i%04x", qdev_fw_name(dev), s->pio[0]);
Signature · 1 line
2.51.0
Reviewed-by on v3 21/25
#62 lore raw

Re: [PATCH v3 21/25] hw/sysbus: Use memory_region_get_address()

Quoted 7 lines · Philippe Mathieu-Daudé

MemoryRegion::addr is private data of MemoryRegion, use memory_region_get_address() to access it.

---
  hw/core/sysbus.c | 17 ++++++++++-------
  1 file changed, 10 insertions(+), 7 deletions(-)

The patch description is incomplete for these changes, but the changes themselves are good.

r~

Quoted 38 lines
hw/core/sysbus.c +10 -7
index d33be6b2b52..414b3f806d1 100644
@@ -257,13 +257,14 @@ bool sysbus_realize_and_unref(SysBusDevice *dev, Error **errp)
  static void sysbus_dev_print(Monitor *mon, DeviceState *dev, int indent)
  {
      SysBusDevice *s = SYS_BUS_DEVICE(dev);
-    hwaddr size;
-    int i;
 
-    for (i = 0; i < s->num_mmio; i++) {
-        size = memory_region_size(s->mmio[i].memory);
-        monitor_printf(mon, "%*smmio " HWADDR_FMT_plx "/" HWADDR_FMT_plx "\n",
-                       indent, "", s->mmio[i].addr, size);
+    for (int i = 0; i < s->num_mmio; i++) {
+        MemoryRegion *mr = sysbus_mmio_get_region(s, i);
+        hwaddr addr = memory_region_get_address(mr);
+        uint64_t size = memory_region_size(mr);
+
+        monitor_printf(mon, "%*smmio " HWADDR_FMT_plx "/%016" PRIx64 "\n",
+                       indent, "", addr, size);
      }
  }
 
@@ -282,8 +283,10 @@ static char *sysbus_get_fw_dev_path(DeviceState *dev)
          }
      }
      if (s->num_mmio) {
+        MemoryRegion *mr = sysbus_mmio_get_region(s, 0);
+
          return g_strdup_printf("%s@" HWADDR_FMT_plx, qdev_fw_name(dev),
-                               s->mmio[0].addr);
+                               memory_region_get_address(mr));
      }
      if (s->num_pio) {
          return g_strdup_printf("%s@i%04x", qdev_fw_name(dev), s->pio[0]);
#63 lore raw

PATCH v3 22/25 hw/sysbus: Hoist MemoryRegion in sysbus_mmio_map_common()

In reply to Philippe Mathieu-Daudé

In order to make the next commit easier to review, use the local @mr variable in sysbus_mmio_map_common().

---
 hw/core/sysbus.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
hw/core/sysbus.c +5 -2
index 414b3f806d1..dca6e67a92d 100644
@@ -122,7 +122,10 @@ bool sysbus_has_mmio(const SysBusDevice *dev, unsigned int n)
 static void sysbus_mmio_map_common(SysBusDevice *dev, int n, hwaddr addr,
                                    bool may_overlap, int priority)
 {
+    MemoryRegion *mr;
+
     assert(n >= 0 && n < dev->num_mmio);
+    mr = dev->mmio[n].memory;
 
     if (dev->mmio[n].addr == addr) {
         /* ??? region already mapped here.  */
@@ -130,13 +133,13 @@ static void sysbus_mmio_map_common(SysBusDevice *dev, int n, hwaddr addr,
     }
     if (dev->mmio[n].addr != (hwaddr)-1) {
         /* Unregister previous mapping.  */
-        memory_region_del_subregion(get_system_memory(), dev->mmio[n].memory);
+        memory_region_del_subregion(get_system_memory(), mr);
     }
     dev->mmio[n].addr = addr;
     if (may_overlap) {
         memory_region_add_subregion_overlap(get_system_memory(),
                                             addr,
-                                            dev->mmio[n].memory,
+                                            mr,
                                             priority);
     }
     else {
Signature · 1 line
2.51.0
#65 lore raw

PATCH v3 23/25 hw/sysbus: Remove sysbus_mmio_map_common() @may_overlap argument

In reply to Philippe Mathieu-Daudé

memory_region_add_subregion_overlap(priority=0) is identical to memory_region_add_subregion(). Just use the former to simplify.

---
 hw/core/sysbus.c | 19 +++++--------------
 1 file changed, 5 insertions(+), 14 deletions(-)
hw/core/sysbus.c +5 -14
index dca6e67a92d..e6acf8dba3b 100644
@@ -120,7 +120,7 @@ bool sysbus_has_mmio(const SysBusDevice *dev, unsigned int n)
 }
 
 static void sysbus_mmio_map_common(SysBusDevice *dev, int n, hwaddr addr,
-                                   bool may_overlap, int priority)
+                                   int priority)
 {
     MemoryRegion *mr;
 
@@ -136,22 +136,13 @@ static void sysbus_mmio_map_common(SysBusDevice *dev, int n, hwaddr addr,
         memory_region_del_subregion(get_system_memory(), mr);
     }
     dev->mmio[n].addr = addr;
-    if (may_overlap) {
-        memory_region_add_subregion_overlap(get_system_memory(),
-                                            addr,
-                                            mr,
-                                            priority);
-    }
-    else {
-        memory_region_add_subregion(get_system_memory(),
-                                    addr,
-                                    dev->mmio[n].memory);
-    }
+    memory_region_add_subregion_overlap(get_system_memory(),
+                                        addr, mr, priority);
 }
 
 void sysbus_mmio_map(SysBusDevice *dev, int n, hwaddr addr)
 {
-    sysbus_mmio_map_common(dev, n, addr, false, 0);
+    sysbus_mmio_map_common(dev, n, addr, 0);
 }
 
 int sysbus_mmio_map_name(SysBusDevice *dev, const char *name, hwaddr addr)
@@ -168,7 +159,7 @@ int sysbus_mmio_map_name(SysBusDevice *dev, const char *name, hwaddr addr)
 void sysbus_mmio_map_overlap(SysBusDevice *dev, int n, hwaddr addr,
                              int priority)
 {
-    sysbus_mmio_map_common(dev, n, addr, true, priority);
+    sysbus_mmio_map_common(dev, n, addr, priority);
 }
 
 /* Request an IRQ source.  The actual IRQ object may be populated later.  */
Signature · 1 line
2.51.0
Reviewed-by on v3 23/25
#66 lore raw

Re: [PATCH v3 23/25] hw/sysbus: Remove sysbus_mmio_map_common() @may_overlap argument

Quoted 8 lines · Philippe Mathieu-Daudé

memory_region_add_subregion_overlap(priority=0) is identical to memory_region_add_subregion(). Just use the former to simplify.

---
  hw/core/sysbus.c | 19 +++++--------------
  1 file changed, 5 insertions(+), 14 deletions(-)

r~

#67 lore raw

PATCH v3 24/25 hw/sysbus: Use memory_region_is_mapped() to check for mapped region

In reply to Philippe Mathieu-Daudé

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

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

---

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(-)
include/hw/sysbus.h +0 -1
index 69eb62e29c8..b2a2ea507ea 100644
@@ -60,7 +60,6 @@ struct SysBusDevice {
 
     int num_mmio;
     struct {
-        hwaddr addr;
         MemoryRegion *memory;
     } mmio[QDEV_MAX_MMIO];
     int num_pio;
hw/core/sysbus.c +1 -7
index e6acf8dba3b..b3060e02484 100644
@@ -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;
 }
 
Signature · 1 line
2.51.0
Reviewed-by on v3 24/25
#68 lore raw

Re: [PATCH v3 24/25] hw/sysbus: Use memory_region_is_mapped() to check for mapped region

Quoted 8 lines · Philippe Mathieu-Daudé

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

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

---

r~

#69 lore raw

PATCH v3 25/25 hw/sysbus: Simplify SysBusDevice::mmio

In reply to Philippe Mathieu-Daudé

Directly access the MemoryRegion array, removing
the need for the embedded structure.

---
 include/hw/sysbus.h | 4 +---
 hw/core/sysbus.c    | 8 ++++----
 2 files changed, 5 insertions(+), 7 deletions(-)
include/hw/sysbus.h +1 -3
index b2a2ea507ea..2cee5bcd44f 100644
@@ -59,9 +59,7 @@ struct SysBusDevice {
     /*< public >*/
 
     int num_mmio;
-    struct {
-        MemoryRegion *memory;
-    } mmio[QDEV_MAX_MMIO];
+    MemoryRegion *mmio[QDEV_MAX_MMIO];
     int num_pio;
     uint32_t pio[QDEV_MAX_PIO];
 };
hw/core/sysbus.c +4 -4
index b3060e02484..188a6ab055e 100644
@@ -125,7 +125,7 @@ static void sysbus_mmio_map_common(SysBusDevice *dev, int n, hwaddr addr,
     MemoryRegion *mr;
 
     assert(n >= 0 && n < dev->num_mmio);
-    mr = dev->mmio[n].memory;
+    mr = dev->mmio[n];
 
     if (memory_region_is_mapped(mr)) {
         /* Unregister previous mapping.  */
@@ -143,7 +143,7 @@ void sysbus_mmio_map(SysBusDevice *dev, int n, hwaddr addr)
 int sysbus_mmio_map_name(SysBusDevice *dev, const char *name, hwaddr addr)
 {
     for (int i = 0; i < dev->num_mmio; i++) {
-        if (!strcmp(memory_region_name(dev->mmio[i].memory), name)) {
+        if (!strcmp(memory_region_name(dev->mmio[i]), name)) {
             sysbus_mmio_map(dev, i, addr);
             return i;
         }
@@ -175,13 +175,13 @@ void sysbus_init_mmio(SysBusDevice *dev, MemoryRegion *memory)
 
     assert(dev->num_mmio < QDEV_MAX_MMIO);
     n = dev->num_mmio++;
-    dev->mmio[n].memory = memory;
+    dev->mmio[n] = memory;
 }
 
 MemoryRegion *sysbus_mmio_get_region(const SysBusDevice *dev, int n)
 {
     assert(n >= 0 && n < QDEV_MAX_MMIO);
-    return dev->mmio[n].memory;
+    return dev->mmio[n];
 }
 
 void sysbus_init_ioports(SysBusDevice *dev, uint32_t ioport, uint32_t size)
Signature · 1 line
2.51.0