Skip to contentSkip to conversation

hw/sysbus: Spring cleanups (part 1)

PATCH Superseded Philippe Mathieu-Daudé 4 participants 14 messages Oct 28, 2025

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

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

- Use proper SysBus accessors

Since v1:
- Reduce series

Philippe Mathieu-Daudé (7):
hw/sysbus: Use memory_region_name()
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/pci_expander_bridge: Use proper SysBus accessors

 hw/acpi/cxl.c                       | 2 +-
 hw/core/sysbus.c                    | 2 +-
 hw/i386/kvm/ioapic.c                | 3 ++-
 hw/i386/microvm-dt.c                | 6 ++++--
 hw/pci-bridge/pci_expander_bridge.c | 6 +++---
 hw/ppc/e500.c                       | 2 +-
 hw/timer/hpet.c                     | 3 ++-
 7 files changed, 14 insertions(+), 10 deletions(-)
Signature · 1 line
2.51.0
#1 lore raw

PATCH v2 1/7 hw/sysbus: Use memory_region_name()

MemoryRegion::name is kind of internal. 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 v2 1/7
#2 lore raw

Re: [PATCH v2 1/7] hw/sysbus: Use memory_region_name()

Quoted 6 lines · Philippe Mathieu-Daudé

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

Quoted 18 lines
---
 hw/core/sysbus.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
hw/core/sysbus.c +1 -2
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;
         }
--
Quoted 3 lines

2.51.0

--
Marc-André Lureau

#3 lore raw

PATCH v2 2/7 hw/i386/microvm: Use proper SysBus accessors

In reply to Philippe Mathieu-Daudé

SysBusDevice::mmio[] is kind of internal. Use the proper sysbus_mmio_get_region() accessor.

---
 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
#4 lore raw

PATCH v2 3/7 hw/i386/ioapic: Use proper SysBus accessors

In reply to Philippe Mathieu-Daudé

SysBusDevice::mmio[] is kind of internal. Use the proper sysbus_mmio_get_region() accessor.

---
 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
#5 lore raw

PATCH v2 4/7 hw/timer/hpet: Use proper SysBus accessors

In reply to Philippe Mathieu-Daudé

SysBusDevice::mmio[] is kind of internal. Use the proper sysbus_mmio_get_region() accessor.

---
 hw/timer/hpet.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
hw/timer/hpet.c +2 -1
index 1acba4fa9db..4ed79d72620 100644
@@ -655,6 +655,7 @@ static void hpet_reset(DeviceState *d)
 {
     HPETState *s = HPET(d);
     SysBusDevice *sbd = SYS_BUS_DEVICE(d);
+    MemoryRegion *mr = sysbus_mmio_get_region(sbd, 0);
     int i;
 
     for (i = 0; i < s->num_timers; i++) {
@@ -677,7 +678,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
#6 lore raw

PATCH v2 5/7 hw/acpi/cxl: Use proper SysBus accessors

In reply to Philippe Mathieu-Daudé

SysBusDevice::mmio[] is kind of internal. Use the proper sysbus_mmio_get_region() accessor.

---
 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
#7 lore raw

PATCH v2 6/7 hw/ppc/e500: Use proper SysBus accessors

In reply to Philippe Mathieu-Daudé

SysBusDevice::mmio[] is kind of internal. Use the proper sysbus_mmio_get_region() accessor.

---
 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
Reviewed-by on v2 6/7
#8 lore raw

Re: [PATCH v2 6/7] hw/ppc/e500: Use proper SysBus accessors

Quoted 4 lines · Philippe Mathieu-Daudé

SysBusDevice::mmio[] is kind of internal. Use the proper sysbus_mmio_get_region() accessor.

Quoted 18 lines

---
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;
 }
#9 lore raw

PATCH v2 7/7 hw/pci-bridge/pci_expander_bridge: Use proper SysBus accessors

In reply to Philippe Mathieu-Daudé

SysBusDevice::mmio[] is kind of internal. Use the proper sysbus_mmio_get_region() accessor.

---
 hw/pci-bridge/pci_expander_bridge.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
hw/pci-bridge/pci_expander_bridge.c +3 -3
index 1bcceddbc4d..b4e2c95ae4c 100644
@@ -157,9 +157,9 @@ 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) {
-        return g_strdup_printf(HWADDR_FMT_plx ",%x",
-                               main_host_sbd->mmio[0].addr, position + 1);
+    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", mr->addr, position + 1);
     }
     if (main_host_sbd->num_pio > 0) {
         return g_strdup_printf("i%04x,%x",
Signature · 1 line
2.51.0
#10 lore raw
In reply to Philippe Mathieu-Daudé

Hi

Quoted 6 lines · Philippe Mathieu-Daudé

- Use proper SysBus accessors

Since v1:
- Reduce series

Quoted 9 lines

Philippe Mathieu-Daudé (7):
hw/sysbus: Use memory_region_name()
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/pci_expander_bridge: Use proper SysBus accessors

There are a bunch of compilation issues that I will let you address for v3.

It looks like it should be possible to remove the "addr" field from SysBusDevice.mmio. On the surface it looks redundante with MemoryRegion.addr. I might be missing something.

Quoted 13 lines
 hw/acpi/cxl.c                       | 2 +-
 hw/core/sysbus.c                    | 2 +-
 hw/i386/kvm/ioapic.c                | 3 ++-
 hw/i386/microvm-dt.c                | 6 ++++--
 hw/pci-bridge/pci_expander_bridge.c | 6 +++---
 hw/ppc/e500.c                       | 2 +-
 hw/timer/hpet.c                     | 3 ++-
 7 files changed, 14 insertions(+), 10 deletions(-)

--
2.51.0

Signature · 1 line
Marc-André Lureau
#11 lore raw
Quoted 21 lines · Marc-André Lureau

Hi

Quoted 6 lines · Philippe Mathieu-Daudé

- Use proper SysBus accessors

Since v1:
- Reduce series

Quoted 9 lines

Philippe Mathieu-Daudé (7):
hw/sysbus: Use memory_region_name()
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/pci_expander_bridge: Use proper SysBus accessors

Quoted 5 lines

There are a bunch of compilation issues that I will let you address for v3.

It looks like it should be possible to remove the "addr" field from SysBusDevice.mmio. On the surface it looks redundante with MemoryRegion.addr. I might be missing something.

Yes, I think they'll always be the same value. But MemoryRegion::addr is private data of MemoryRegion and there's no 'get' function provided; SysBus shouldn't be reaching inside an MR struct to look at its internals.

(There is a memory_region_set_address(), so we could I guess provide a memory_region_get_address() ?)

-- PMM

#12 lore raw
Quoted 29 lines · Peter Maydell
Quoted 21 lines · Marc-André Lureau

Hi

Quoted 6 lines · Philippe Mathieu-Daudé

- Use proper SysBus accessors

Since v1:
- Reduce series

Quoted 9 lines

Philippe Mathieu-Daudé (7):
hw/sysbus: Use memory_region_name()
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/pci_expander_bridge: Use proper SysBus accessors

Quoted 5 lines

There are a bunch of compilation issues that I will let you address for v3.

It looks like it should be possible to remove the "addr" field from SysBusDevice.mmio. On the surface it looks redundante with MemoryRegion.addr. I might be missing something.

Quoted 7 lines

Yes, I think they'll always be the same value. But MemoryRegion::addr is private data of MemoryRegion and there's no 'get' function provided; SysBus shouldn't be reaching inside an MR struct to look at its internals.

(There is a memory_region_set_address(), so we could I guess provide a memory_region_get_address() ?)

OK, thanks!

#13 lore raw
In reply to Marc-André Lureau
Quoted 20 lines · Marc-André Lureau

Hi

Quoted 6 lines · Philippe Mathieu-Daudé

- Use proper SysBus accessors

Since v1:
- Reduce series

Quoted 9 lines

Philippe Mathieu-Daudé (7):
hw/sysbus: Use memory_region_name()
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/pci_expander_bridge: Use proper SysBus accessors

Quoted 1 line

There are a bunch of compilation issues that I will let you address for v3.

Sorry, this is based on my latest PR:
https://github.com/philmd/qemu/releases/tag/hw-misc-20251028
Based-on: <[email protected]>