hw/riscv/virt.c: use s->memmap in create_fdt_virtio()

create_fdt_virtio() can use s->memmap instead of having an extra
argument for it.

While we're at it rewrite it a little bit to avoid the clunky line in
'name' and code repetition:

- declare 'virtio_base' out of the loop since it never changes;
- declare a 'size' variable. Use it to calculate the address of the
  virtio device in an 'addr' variable;
- use 'addr' in the 'name' g_strdup_printf();
- use 'addr' and 'size' when creating the 'reg' property.

Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
Message-ID: <20250429125811.224803-8-dbarboza@ventanamicro.com>
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
This commit is contained in:
Daniel Henrique Barboza 2025-04-29 09:58:09 -03:00 committed by Alistair Francis
parent 04c4f8d1ee
commit a51a88fd5d

View file

@ -842,21 +842,24 @@ static void create_fdt_sockets(RISCVVirtState *s,
riscv_socket_fdt_write_distance_matrix(ms); riscv_socket_fdt_write_distance_matrix(ms);
} }
static void create_fdt_virtio(RISCVVirtState *s, const MemMapEntry *memmap, static void create_fdt_virtio(RISCVVirtState *s, uint32_t irq_virtio_phandle)
uint32_t irq_virtio_phandle)
{ {
int i; int i;
MachineState *ms = MACHINE(s); MachineState *ms = MACHINE(s);
hwaddr virtio_base = s->memmap[VIRT_VIRTIO].base;
for (i = 0; i < VIRTIO_COUNT; i++) { for (i = 0; i < VIRTIO_COUNT; i++) {
g_autofree char *name = g_strdup_printf("/soc/virtio_mmio@%lx", g_autofree char *name = NULL;
(long)(memmap[VIRT_VIRTIO].base + i * memmap[VIRT_VIRTIO].size)); uint64_t size = s->memmap[VIRT_VIRTIO].size;
hwaddr addr = virtio_base + i * size;
name = g_strdup_printf("/soc/virtio_mmio@%"HWADDR_PRIx, addr);
qemu_fdt_add_subnode(ms->fdt, name); qemu_fdt_add_subnode(ms->fdt, name);
qemu_fdt_setprop_string(ms->fdt, name, "compatible", "virtio,mmio"); qemu_fdt_setprop_string(ms->fdt, name, "compatible", "virtio,mmio");
qemu_fdt_setprop_cells(ms->fdt, name, "reg", qemu_fdt_setprop_cells(ms->fdt, name, "reg",
0x0, memmap[VIRT_VIRTIO].base + i * memmap[VIRT_VIRTIO].size, 0x0, addr,
0x0, memmap[VIRT_VIRTIO].size); 0x0, size);
qemu_fdt_setprop_cell(ms->fdt, name, "interrupt-parent", qemu_fdt_setprop_cell(ms->fdt, name, "interrupt-parent",
irq_virtio_phandle); irq_virtio_phandle);
if (s->aia_type == VIRT_AIA_TYPE_NONE) { if (s->aia_type == VIRT_AIA_TYPE_NONE) {
@ -1135,7 +1138,7 @@ static void finalize_fdt(RISCVVirtState *s)
&irq_pcie_phandle, &irq_virtio_phandle, &irq_pcie_phandle, &irq_virtio_phandle,
&msi_pcie_phandle); &msi_pcie_phandle);
create_fdt_virtio(s, s->memmap, irq_virtio_phandle); create_fdt_virtio(s, irq_virtio_phandle);
if (virt_is_iommu_sys_enabled(s)) { if (virt_is_iommu_sys_enabled(s)) {
create_fdt_iommu_sys(s, irq_mmio_phandle, msi_pcie_phandle, create_fdt_iommu_sys(s, irq_mmio_phandle, msi_pcie_phandle,