On Tue, Apr 29, 2025 at 11:01 PM Daniel Henrique Barboza
<dbarb...@ventanamicro.com> wrote:
>
> create_fdt_sockets() and all its fdt helpers (create_fdt_socket_aplic(),
> create_fdt_imsic(), create_fdt_socket_plic(), create_fdt_socket_aclint()
> and create_fdt_socket_memory()) can use s->memmap from their
> RISCVVirtState pointer instead of having an extra memmap argument.
>
> Signed-off-by: Daniel Henrique Barboza <dbarb...@ventanamicro.com>

Reviewed-by: Alistair Francis <alistair.fran...@wdc.com>

Alistair

> ---
>  hw/riscv/virt.c | 89 ++++++++++++++++++++++++++-----------------------
>  1 file changed, 47 insertions(+), 42 deletions(-)
>
> diff --git a/hw/riscv/virt.c b/hw/riscv/virt.c
> index 5f31c95955..2383a557bd 100644
> --- a/hw/riscv/virt.c
> +++ b/hw/riscv/virt.c
> @@ -300,14 +300,13 @@ static void create_fdt_socket_cpus(RISCVVirtState *s, 
> int socket,
>      }
>  }
>
> -static void create_fdt_socket_memory(RISCVVirtState *s,
> -                                     const MemMapEntry *memmap, int socket)
> +static void create_fdt_socket_memory(RISCVVirtState *s, int socket)
>  {
>      g_autofree char *mem_name = NULL;
>      uint64_t addr, size;
>      MachineState *ms = MACHINE(s);
>
> -    addr = memmap[VIRT_DRAM].base + riscv_socket_mem_offset(ms, socket);
> +    addr = s->memmap[VIRT_DRAM].base + riscv_socket_mem_offset(ms, socket);
>      size = riscv_socket_mem_size(ms, socket);
>      mem_name = g_strdup_printf("/memory@%lx", (long)addr);
>      qemu_fdt_add_subnode(ms->fdt, mem_name);
> @@ -318,7 +317,7 @@ static void create_fdt_socket_memory(RISCVVirtState *s,
>  }
>
>  static void create_fdt_socket_clint(RISCVVirtState *s,
> -                                    const MemMapEntry *memmap, int socket,
> +                                    int socket,
>                                      uint32_t *intc_phandles)
>  {
>      int cpu;
> @@ -339,21 +338,22 @@ static void create_fdt_socket_clint(RISCVVirtState *s,
>          clint_cells[cpu * 4 + 3] = cpu_to_be32(IRQ_M_TIMER);
>      }
>
> -    clint_addr = memmap[VIRT_CLINT].base + (memmap[VIRT_CLINT].size * 
> socket);
> +    clint_addr = s->memmap[VIRT_CLINT].base +
> +                 (s->memmap[VIRT_CLINT].size * socket);
>      clint_name = g_strdup_printf("/soc/clint@%lx", clint_addr);
>      qemu_fdt_add_subnode(ms->fdt, clint_name);
>      qemu_fdt_setprop_string_array(ms->fdt, clint_name, "compatible",
>                                    (char **)&clint_compat,
>                                    ARRAY_SIZE(clint_compat));
>      qemu_fdt_setprop_cells(ms->fdt, clint_name, "reg",
> -        0x0, clint_addr, 0x0, memmap[VIRT_CLINT].size);
> +        0x0, clint_addr, 0x0, s->memmap[VIRT_CLINT].size);
>      qemu_fdt_setprop(ms->fdt, clint_name, "interrupts-extended",
>          clint_cells, s->soc[socket].num_harts * sizeof(uint32_t) * 4);
>      riscv_socket_fdt_write_id(ms, clint_name, socket);
>  }
>
>  static void create_fdt_socket_aclint(RISCVVirtState *s,
> -                                     const MemMapEntry *memmap, int socket,
> +                                     int socket,
>                                       uint32_t *intc_phandles)
>  {
>      int cpu;
> @@ -380,8 +380,10 @@ static void create_fdt_socket_aclint(RISCVVirtState *s,
>      aclint_cells_size = s->soc[socket].num_harts * sizeof(uint32_t) * 2;
>
>      if (s->aia_type != VIRT_AIA_TYPE_APLIC_IMSIC) {
> -        addr = memmap[VIRT_CLINT].base + (memmap[VIRT_CLINT].size * socket);
> +        addr = s->memmap[VIRT_CLINT].base +
> +               (s->memmap[VIRT_CLINT].size * socket);
>          name = g_strdup_printf("/soc/mswi@%lx", addr);
> +
>          qemu_fdt_add_subnode(ms->fdt, name);
>          qemu_fdt_setprop_string(ms->fdt, name, "compatible",
>              "riscv,aclint-mswi");
> @@ -396,13 +398,13 @@ static void create_fdt_socket_aclint(RISCVVirtState *s,
>      }
>
>      if (s->aia_type == VIRT_AIA_TYPE_APLIC_IMSIC) {
> -        addr = memmap[VIRT_CLINT].base +
> +        addr = s->memmap[VIRT_CLINT].base +
>                 (RISCV_ACLINT_DEFAULT_MTIMER_SIZE * socket);
>          size = RISCV_ACLINT_DEFAULT_MTIMER_SIZE;
>      } else {
> -        addr = memmap[VIRT_CLINT].base + RISCV_ACLINT_SWI_SIZE +
> -            (memmap[VIRT_CLINT].size * socket);
> -        size = memmap[VIRT_CLINT].size - RISCV_ACLINT_SWI_SIZE;
> +        addr = s->memmap[VIRT_CLINT].base + RISCV_ACLINT_SWI_SIZE +
> +               (s->memmap[VIRT_CLINT].size * socket);
> +        size = s->memmap[VIRT_CLINT].size - RISCV_ACLINT_SWI_SIZE;
>      }
>      name = g_strdup_printf("/soc/mtimer@%lx", addr);
>      qemu_fdt_add_subnode(ms->fdt, name);
> @@ -419,14 +421,15 @@ static void create_fdt_socket_aclint(RISCVVirtState *s,
>      g_free(name);
>
>      if (s->aia_type != VIRT_AIA_TYPE_APLIC_IMSIC) {
> -        addr = memmap[VIRT_ACLINT_SSWI].base +
> -            (memmap[VIRT_ACLINT_SSWI].size * socket);
> +        addr = s->memmap[VIRT_ACLINT_SSWI].base +
> +               (s->memmap[VIRT_ACLINT_SSWI].size * socket);
> +
>          name = g_strdup_printf("/soc/sswi@%lx", addr);
>          qemu_fdt_add_subnode(ms->fdt, name);
>          qemu_fdt_setprop_string(ms->fdt, name, "compatible",
>              "riscv,aclint-sswi");
>          qemu_fdt_setprop_cells(ms->fdt, name, "reg",
> -            0x0, addr, 0x0, memmap[VIRT_ACLINT_SSWI].size);
> +            0x0, addr, 0x0, s->memmap[VIRT_ACLINT_SSWI].size);
>          qemu_fdt_setprop(ms->fdt, name, "interrupts-extended",
>              aclint_sswi_cells, aclint_cells_size);
>          qemu_fdt_setprop(ms->fdt, name, "interrupt-controller", NULL, 0);
> @@ -437,7 +440,7 @@ static void create_fdt_socket_aclint(RISCVVirtState *s,
>  }
>
>  static void create_fdt_socket_plic(RISCVVirtState *s,
> -                                   const MemMapEntry *memmap, int socket,
> +                                   int socket,
>                                     uint32_t *phandle, uint32_t 
> *intc_phandles,
>                                     uint32_t *plic_phandles)
>  {
> @@ -451,7 +454,8 @@ static void create_fdt_socket_plic(RISCVVirtState *s,
>      };
>
>      plic_phandles[socket] = (*phandle)++;
> -    plic_addr = memmap[VIRT_PLIC].base + (memmap[VIRT_PLIC].size * socket);
> +    plic_addr = s->memmap[VIRT_PLIC].base +
> +                (s->memmap[VIRT_PLIC].size * socket);
>      plic_name = g_strdup_printf("/soc/plic@%lx", plic_addr);
>      qemu_fdt_add_subnode(ms->fdt, plic_name);
>      qemu_fdt_setprop_cell(ms->fdt, plic_name,
> @@ -490,7 +494,7 @@ static void create_fdt_socket_plic(RISCVVirtState *s,
>      }
>
>      qemu_fdt_setprop_cells(ms->fdt, plic_name, "reg",
> -        0x0, plic_addr, 0x0, memmap[VIRT_PLIC].size);
> +        0x0, plic_addr, 0x0, s->memmap[VIRT_PLIC].size);
>      qemu_fdt_setprop_cell(ms->fdt, plic_name, "riscv,ndev",
>                            VIRT_IRQCHIP_NUM_SOURCES - 1);
>      riscv_socket_fdt_write_id(ms, plic_name, socket);
> @@ -499,8 +503,8 @@ static void create_fdt_socket_plic(RISCVVirtState *s,
>
>      if (!socket) {
>          platform_bus_add_all_fdt_nodes(ms->fdt, plic_name,
> -                                       memmap[VIRT_PLATFORM_BUS].base,
> -                                       memmap[VIRT_PLATFORM_BUS].size,
> +                                       s->memmap[VIRT_PLATFORM_BUS].base,
> +                                       s->memmap[VIRT_PLATFORM_BUS].size,
>                                         VIRT_PLATFORM_BUS_IRQ);
>      }
>  }
> @@ -587,7 +591,7 @@ static void create_fdt_one_imsic(RISCVVirtState *s, 
> hwaddr base_addr,
>      qemu_fdt_setprop_cell(ms->fdt, imsic_name, "phandle", msi_phandle);
>  }
>
> -static void create_fdt_imsic(RISCVVirtState *s, const MemMapEntry *memmap,
> +static void create_fdt_imsic(RISCVVirtState *s,
>                               uint32_t *phandle, uint32_t *intc_phandles,
>                               uint32_t *msi_m_phandle, uint32_t 
> *msi_s_phandle)
>  {
> @@ -596,12 +600,12 @@ static void create_fdt_imsic(RISCVVirtState *s, const 
> MemMapEntry *memmap,
>
>      if (!kvm_enabled()) {
>          /* M-level IMSIC node */
> -        create_fdt_one_imsic(s, memmap[VIRT_IMSIC_M].base, intc_phandles,
> +        create_fdt_one_imsic(s, s->memmap[VIRT_IMSIC_M].base, intc_phandles,
>                               *msi_m_phandle, true, 0);
>      }
>
>      /* S-level IMSIC node */
> -    create_fdt_one_imsic(s, memmap[VIRT_IMSIC_S].base, intc_phandles,
> +    create_fdt_one_imsic(s, s->memmap[VIRT_IMSIC_S].base, intc_phandles,
>                           *msi_s_phandle, false,
>                           imsic_num_bits(s->aia_guests + 1));
>
> @@ -678,7 +682,7 @@ static void create_fdt_one_aplic(RISCVVirtState *s, int 
> socket,
>  }
>
>  static void create_fdt_socket_aplic(RISCVVirtState *s,
> -                                    const MemMapEntry *memmap, int socket,
> +                                    int socket,
>                                      uint32_t msi_m_phandle,
>                                      uint32_t msi_s_phandle,
>                                      uint32_t *phandle,
> @@ -695,18 +699,19 @@ static void create_fdt_socket_aplic(RISCVVirtState *s,
>
>      if (!kvm_enabled()) {
>          /* M-level APLIC node */
> -        aplic_addr = memmap[VIRT_APLIC_M].base +
> -                     (memmap[VIRT_APLIC_M].size * socket);
> -        create_fdt_one_aplic(s, socket, aplic_addr, 
> memmap[VIRT_APLIC_M].size,
> +        aplic_addr = s->memmap[VIRT_APLIC_M].base +
> +                     (s->memmap[VIRT_APLIC_M].size * socket);
> +        create_fdt_one_aplic(s, socket, aplic_addr,
> +                             s->memmap[VIRT_APLIC_M].size,
>                               msi_m_phandle, intc_phandles,
>                               aplic_m_phandle, aplic_s_phandle,
>                               true, num_harts);
>      }
>
>      /* S-level APLIC node */
> -    aplic_addr = memmap[VIRT_APLIC_S].base +
> -                 (memmap[VIRT_APLIC_S].size * socket);
> -    create_fdt_one_aplic(s, socket, aplic_addr, memmap[VIRT_APLIC_S].size,
> +    aplic_addr = s->memmap[VIRT_APLIC_S].base +
> +                 (s->memmap[VIRT_APLIC_S].size * socket);
> +    create_fdt_one_aplic(s, socket, aplic_addr, s->memmap[VIRT_APLIC_S].size,
>                           msi_s_phandle, intc_phandles,
>                           aplic_s_phandle, 0,
>                           false, num_harts);
> @@ -714,8 +719,8 @@ static void create_fdt_socket_aplic(RISCVVirtState *s,
>      if (!socket) {
>          g_autofree char *aplic_name = fdt_get_aplic_nodename(aplic_addr);
>          platform_bus_add_all_fdt_nodes(ms->fdt, aplic_name,
> -                                       memmap[VIRT_PLATFORM_BUS].base,
> -                                       memmap[VIRT_PLATFORM_BUS].size,
> +                                       s->memmap[VIRT_PLATFORM_BUS].base,
> +                                       s->memmap[VIRT_PLATFORM_BUS].size,
>                                         VIRT_PLATFORM_BUS_IRQ);
>      }
>
> @@ -733,7 +738,7 @@ static void create_fdt_pmu(RISCVVirtState *s)
>      riscv_pmu_generate_fdt_node(ms->fdt, hart.pmu_avail_ctrs, pmu_name);
>  }
>
> -static void create_fdt_sockets(RISCVVirtState *s, const MemMapEntry *memmap,
> +static void create_fdt_sockets(RISCVVirtState *s,
>                                 uint32_t *phandle,
>                                 uint32_t *irq_mmio_phandle,
>                                 uint32_t *irq_pcie_phandle,
> @@ -769,20 +774,20 @@ static void create_fdt_sockets(RISCVVirtState *s, const 
> MemMapEntry *memmap,
>          create_fdt_socket_cpus(s, socket, clust_name, phandle,
>                                 &intc_phandles[phandle_pos]);
>
> -        create_fdt_socket_memory(s, memmap, socket);
> +        create_fdt_socket_memory(s, socket);
>
>          if (virt_aclint_allowed() && s->have_aclint) {
> -            create_fdt_socket_aclint(s, memmap, socket,
> +            create_fdt_socket_aclint(s, socket,
>                                       &intc_phandles[phandle_pos]);
>          } else if (tcg_enabled()) {
> -            create_fdt_socket_clint(s, memmap, socket,
> +            create_fdt_socket_clint(s, socket,
>                                      &intc_phandles[phandle_pos]);
>          }
>      }
>
>      if (s->aia_type == VIRT_AIA_TYPE_APLIC_IMSIC) {
> -        create_fdt_imsic(s, memmap, phandle, intc_phandles,
> -            &msi_m_phandle, &msi_s_phandle);
> +        create_fdt_imsic(s, phandle, intc_phandles,
> +                         &msi_m_phandle, &msi_s_phandle);
>          *msi_pcie_phandle = msi_s_phandle;
>      }
>
> @@ -791,7 +796,7 @@ static void create_fdt_sockets(RISCVVirtState *s, const 
> MemMapEntry *memmap,
>       * mode, we'll use only one APLIC instance.
>       */
>      if (!virt_use_emulated_aplic(s->aia_type)) {
> -        create_fdt_socket_aplic(s, memmap, 0,
> +        create_fdt_socket_aplic(s, 0,
>                                  msi_m_phandle, msi_s_phandle, phandle,
>                                  &intc_phandles[0], xplic_phandles,
>                                  ms->smp.cpus);
> @@ -805,11 +810,11 @@ static void create_fdt_sockets(RISCVVirtState *s, const 
> MemMapEntry *memmap,
>              phandle_pos -= s->soc[socket].num_harts;
>
>              if (s->aia_type == VIRT_AIA_TYPE_NONE) {
> -                create_fdt_socket_plic(s, memmap, socket, phandle,
> +                create_fdt_socket_plic(s, socket, phandle,
>                                         &intc_phandles[phandle_pos],
>                                         xplic_phandles);
>              } else {
> -                create_fdt_socket_aplic(s, memmap, socket,
> +                create_fdt_socket_aplic(s, socket,
>                                          msi_m_phandle, msi_s_phandle, 
> phandle,
>                                          &intc_phandles[phandle_pos],
>                                          xplic_phandles,
> @@ -1125,7 +1130,7 @@ static void finalize_fdt(RISCVVirtState *s)
>      uint32_t irq_pcie_phandle = 1, irq_virtio_phandle = 1;
>      uint32_t iommu_sys_phandle = 1;
>
> -    create_fdt_sockets(s, s->memmap, &phandle, &irq_mmio_phandle,
> +    create_fdt_sockets(s, &phandle, &irq_mmio_phandle,
>                         &irq_pcie_phandle, &irq_virtio_phandle,
>                         &msi_pcie_phandle);
>
> --
> 2.49.0
>
>

Reply via email to