hw/sysbus: Spring cleanups (part 1)
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
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
@@ -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
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.Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- hw/i386/microvm-dt.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)hw/i386/microvm-dt.c +2
-1@@ -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
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.Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- hw/i386/microvm-dt.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
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
@@ -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
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.Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- hw/i386/kvm/ioapic.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
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.Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- 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
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
@@ -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
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.0SysBusDevice::mmio[] is private data of SysBusDevice, use
sysbus_mmio_get_region()to access it.Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- hw/timer/hpet.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)hw/timer/hpet.c +1
-1@@ -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
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
@@ -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
Re: [PATCH v3 04/25] hw/acpi/cxl: Use proper SysBus accessors
Quoted 7 lines · Philippe Mathieu-Daudé
SysBusDevice::mmio[] is private data of SysBusDevice, use
sysbus_mmio_get_region()to access it.Signed-off-by Philippe Mathieu-Daudé<[email protected]>--- hw/acpi/cxl.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
r~
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.Signed-off-by Philippe Mathieu-Daudé <[email protected]>
Thanks,
Quoted 17 lines
--- hw/acpi/cxl.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)hw/acpi/cxl.c +1
-1@@ -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 );
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
@@ -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
Re: [PATCH v3 05/25] hw/ppc/e500: Use proper SysBus accessors
Quoted 7 lines · Philippe Mathieu-Daudé
SysBusDevice::mmio[] is private data of SysBusDevice, use
sysbus_mmio_get_region()to access it.Signed-off-by Philippe Mathieu-Daudé<[email protected]>--- hw/ppc/e500.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
r~
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
@@ -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
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.Signed-off-by Philippe Mathieu-Daudé <[email protected]>Reviewed-by BALATON Zoltan <[email protected]>
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@@ -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",
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
@@ -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
Re: [PATCH v3 07/25] hw/sysbus: Use memory_region_name()
Quoted 9 lines · Philippe Mathieu-Daudé
MemoryRegion::nameis private data of MemoryRegion. Use the propermemory_region_name()accessor, which might return a different name.Signed-off-by Philippe Mathieu-Daudé<[email protected]>Reviewed-by Marc-André Lureau<[email protected]>--- hw/core/sysbus.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
r~
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
@@ -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
Re: [PATCH v3 08/25] hw/nvme/ctrl: Use memory_region_size()
Quoted 7 lines · Philippe Mathieu-Daudé
MemoryRegion::sizeis private data of MemoryRegion, use the propermemory_region_size()getter to get it.Signed-off-by Philippe Mathieu-Daudé<[email protected]>--- hw/nvme/ctrl.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-)
r~
Re: [PATCH v3 08/25] hw/nvme/ctrl: Use memory_region_size()
In reply to Philippe Mathieu-DaudéQuoted 4 lines · Philippe Mathieu-Daudé
MemoryRegion::sizeis private data of MemoryRegion, use the propermemory_region_size()getter to get it.Signed-off-by Philippe Mathieu-Daudé <[email protected]>
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
@@ -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
Re: [PATCH v3 09/25] hw/s390x: Use memory_region_size()
Quoted 13 lines · Philippe Mathieu-Daudé
MemoryRegion::sizeis private data of MemoryRegion, use the propermemory_region_size()getter to get it.Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- hw/s390x/s390-pci-inst.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)hw/s390x/s390-pci-inst.c +0
-0
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;
Re: [PATCH v3 09/25] hw/s390x: Use memory_region_size()
In reply to Philippe Mathieu-DaudéQuoted 7 lines · Philippe Mathieu-Daudé
MemoryRegion::sizeis private data of MemoryRegion, use the propermemory_region_size()getter to get it.Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- hw/s390x/s390-pci-inst.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
r~
Re: [PATCH v3 09/25] hw/s390x: Use memory_region_size()
In reply to Philippe Mathieu-DaudéQuoted 13 lines · Philippe Mathieu-Daudé
MemoryRegion::sizeis private data of MemoryRegion, use the propermemory_region_size()getter to get it.Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- hw/s390x/s390-pci-inst.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)hw/s390x/s390-pci-inst.c +0
-0
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
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
@@ -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
@@ -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
Re: [PATCH v3 10/25] system/memory: Have memory_region_size() take a const argument
Quoted 3 lines · Philippe Mathieu-Daudé
Since the @mr argument is not modified, it can be const.
Signed-off-by Philippe Mathieu-Daudé <[email protected]>
Signature · 1 line
Peter Xu
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.
Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- include/system/memory.h | 2 +- system/memory.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)include/system/memory.h +1
-1@@ -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
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 ;
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.
Signed-off-by Philippe Mathieu-Daudé<[email protected]>--- include/system/memory.h | 2 +- system/memory.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
r~
Re: [PATCH v3 10/25] system/memory: Have memory_region_size() take a const argument
In reply to Philippe Mathieu-DaudéQuoted 4 lines · Philippe Mathieu-Daudé
Since the @mr argument is not modified, it can be const.
Signed-off-by Philippe Mathieu-Daudé <[email protected]>---
Signature · 3 lines
Cheers David / dhildenb
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
@@ -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
@@ -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
Re: [PATCH v3 11/25] system/memory: Introduce memory_region_get_address()
Quoted 6 lines · Philippe Mathieu-Daudé
MemoryRegion::addris private data of MemoryRegion. Introducememory_region_get_address()to get it, similar tomemory_region_set_address()to set it.Suggested-by Peter Maydell <[email protected]>Signed-off-by Philippe Mathieu-Daudé <[email protected]>
Signature · 1 line
Peter Xu
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::addris private data of MemoryRegion. Introducememory_region_get_address()to get it, similar tomemory_region_set_address()to set it.Suggested-by Peter Maydell <[email protected]>Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- include/system/memory.h | 7 +++++++ system/memory.c | 5 +++++ 2 files changed, 12 insertions(+)
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::addris private data of MemoryRegion. Introducememory_region_get_address()to get it, similar tomemory_region_set_address()to set it.Suggested-by Peter Maydell<[email protected]>Signed-off-by Philippe Mathieu-Daudé<[email protected]>--- 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~
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::addris private data of MemoryRegion. Introducememory_region_get_address()to get it, similar tomemory_region_set_address()to set it.Suggested-by Peter Maydell <[email protected]>Signed-off-by Philippe Mathieu-Daudé <[email protected]>---
Signature · 3 lines
Cheers David / dhildenb
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
@@ -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
Re: [PATCH v3 12/25] migration/ram: Use memory_region_get_address()
Quoted 4 lines · Philippe Mathieu-Daudé
MemoryRegion::addris private data of MemoryRegion, usememory_region_get_address()to access it.Signed-off-by Philippe Mathieu-Daudé <[email protected]>
Signature · 1 line
Peter Xu
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::addris private data of MemoryRegion, usememory_region_get_address()to access it.Signed-off-by Philippe Mathieu-Daudé<[email protected]>--- migration/ram.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-)
r~
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
@@ -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
@@ -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
@@ -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
Re: [PATCH v3 13/25] hw/acpi: Use memory_region_get_address()
Quoted 10 lines · Philippe Mathieu-Daudé
+++
b/hw/acpi/cxl.chw/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~
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::addris private data of MemoryRegion, usememory_region_get_address()to access it.Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- 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@@ -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 );
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
@@ -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
@@ -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
Re: [PATCH v3 14/25] hw/fdt: Use memory_region_get_address()
Quoted 8 lines · Philippe Mathieu-Daudé
MemoryRegion::addris private data of MemoryRegion, usememory_region_get_address()to access it.Signed-off-by Philippe Mathieu-Daudé<[email protected]>--- hw/i386/microvm-dt.c | 4 ++-- hw/loongarch/virt-fdt-build.c | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-)
r~
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
@@ -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
Re: [PATCH v3 15/25] hw/nvme: Use memory_region_get_address()
Quoted 7 lines · Philippe Mathieu-Daudé
MemoryRegion::addris private data of MemoryRegion, usememory_region_get_address()to access it.Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- hw/nvme/ctrl.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
r~
Re: [PATCH v3 15/25] hw/nvme: Use memory_region_get_address()
In reply to Philippe Mathieu-DaudéQuoted 4 lines · Philippe Mathieu-Daudé
MemoryRegion::addris private data of MemoryRegion, usememory_region_get_address()to access it.Signed-off-by Philippe Mathieu-Daudé <[email protected]>
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
@@ -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
Re: [PATCH v3 16/25] hw/s390x: Use memory_region_get_address()
Quoted 16 lines · Philippe Mathieu-Daudé
MemoryRegion::addris private data of MemoryRegion, usememory_region_get_address()to access it.Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- hw/s390x/s390-pci-inst.c | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-)hw/s390x/s390-pci-inst.c +0
-0@@ -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:
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
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_tfh;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
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
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
@@ -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
Re: [PATCH v3 17/25] hw/timer/hpet: Use memory_region_get_address()
Quoted 8 lines · Philippe Mathieu-Daudé
MemoryRegion::addris private data of MemoryRegion, usememory_region_get_address()to access it.Signed-off-by Philippe Mathieu-Daudé<[email protected]>--- hw/timer/hpet.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
r~
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: Usememory_region_get_address()
X-Mailer: git-send-email 2.51.0
Quoted 7 lines
MemoryRegion::addris private data of MemoryRegion, usememory_region_get_address()to access it.Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- hw/timer/hpet.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
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
@@ -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
Re: [PATCH v3 18/25] hw/watchdog/aspeed: Use memory_region_get_address()
Quoted 7 lines · Philippe Mathieu-Daudé
MemoryRegion::addris private data of MemoryRegion, usememory_region_get_address()to access it.Signed-off-by Philippe Mathieu-Daudé<[email protected]>--- hw/watchdog/wdt_aspeed.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
r~
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::addris private data of MemoryRegion, usememory_region_get_address()to access it.Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- hw/watchdog/wdt_aspeed.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)hw/watchdog/wdt_aspeed.c +0
-0
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.
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
@@ -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
Re: [PATCH v3 19/25] hw/pci-bridge: Use memory_region_get_address()
Quoted 7 lines · Philippe Mathieu-Daudé
MemoryRegion::addris private data of MemoryRegion, usememory_region_get_address()to access it.Signed-off-by Philippe Mathieu-Daudé<[email protected]>--- hw/pci-bridge/pci_expander_bridge.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
r~
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
@@ -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
Re: [PATCH v3 20/25] system/ioport: Use memory_region_get_address()
Quoted 7 lines · Philippe Mathieu-Daudé
MemoryRegion::addris private data of MemoryRegion, usememory_region_get_address()to access it.Signed-off-by Philippe Mathieu-Daudé<[email protected]>--- system/ioport.c | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-)
r~
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
@@ -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
Re: [PATCH v3 21/25] hw/sysbus: Use memory_region_get_address()
Quoted 7 lines · Philippe Mathieu-Daudé
MemoryRegion::addris private data of MemoryRegion, usememory_region_get_address()to access it.Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- 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@@ -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 ]);
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
@@ -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
Re: [PATCH v3 22/25] hw/sysbus: Hoist MemoryRegion in sysbus_mmio_map_common()
Quoted 7 lines · Philippe Mathieu-Daudé
In order to make the next commit easier to review, use the local @mr variable in
sysbus_mmio_map_common().Signed-off-by Philippe Mathieu-Daudé<[email protected]>--- hw/core/sysbus.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
r~
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
@@ -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
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 tomemory_region_add_subregion(). Just use the former to simplify.Signed-off-by Philippe Mathieu-Daudé<[email protected]>--- hw/core/sysbus.c | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-)
r~
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
@@ -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
@@ -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
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.
Suggested-by Marc-André Lureau<[email protected]>Signed-off-by Philippe Mathieu-Daudé<[email protected]>---
r~
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
@@ -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
@@ -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
Re: [PATCH v3 25/25] hw/sysbus: Simplify SysBusDevice::mmio
Quoted 8 lines · Philippe Mathieu-Daudé
Directly access the MemoryRegion array, removing
the need for the embedded structure.Signed-off-by Philippe Mathieu-Daudé<[email protected]>--- include/hw/sysbus.h | 4 +--- hw/core/sysbus.c | 8 ++++---- 2 files changed, 5 insertions(+), 7 deletions(-)
r~