On Sun, 2026-11-01 at 11:15 +0800, Tan Chi wrote:
> riscv_create_fdt_socket_aplic() contains a direct reference to
> platform_bus_add_all_fdt_nodes(), even though fdt-common.c is
> built unconditionally and CONFIG_PLATFORM_BUS may be disabled.
> 
> This causes an undefined reference in minimal RISC-V builds
> without platform bus support.
> 
> Move platform bus FDT creation to the virt and server reference
> machines, which both select CONFIG_PLATFORM_BUS. Export a helper
> to obtain the APLIC node name and remove the platform bus fields
> from APLICFdtProps.
> 
> This removes the dependency from the common APLIC FDT helper
> while preserving the platform bus interrupt-parent configuration.
> 
> Signed-off-by: Tan Chi <[email protected]>

Reviewed-by: Alistair Francis <[email protected]>

Alistair

> ---
>  hw/riscv/fdt-common.c          | 13 ++-----------
>  hw/riscv/server_platform_ref.c |  9 +++++++--
>  hw/riscv/virt.c                | 11 +++++++++--
>  include/hw/riscv/fdt-common.h  |  3 +--
>  4 files changed, 19 insertions(+), 17 deletions(-)
> 
> diff --git a/hw/riscv/fdt-common.c b/hw/riscv/fdt-common.c
> index ce2dcb43b4..e90502b1bc 100644
> --- a/hw/riscv/fdt-common.c
> +++ b/hw/riscv/fdt-common.c
> @@ -11,7 +11,6 @@
>  #include "qemu/error-report.h"
>  #include "system/device_tree.h"
>  #include "hw/core/boards.h"
> -#include "hw/core/sysbus-fdt.h"
>  #include "hw/riscv/fdt-common.h"
>  #include "target/riscv/cpu_bits.h"
>  #include "hw/riscv/riscv-iommu-bits.h"
> @@ -599,7 +598,7 @@ void riscv_create_fdt_imsic(void *fdt,
> IMSICFdtProps *props,
>  }
>  
>  /* Caller must free string after use */
> -static char *fdt_get_aplic_nodename(hwaddr aplic_addr)
> +char *riscv_fdt_get_aplic_nodename(hwaddr aplic_addr)
>  {
>      return g_strdup_printf("/soc/interrupt-controller@%"HWADDR_PRIx,
>                             aplic_addr);
> @@ -613,7 +612,7 @@ static void create_fdt_one_aplic(void *fdt,
> APLICFdtProps *props,
>                                   uint32_t aplic_child_phandle,
>                                   bool m_mode)
>  {
> -    g_autofree char *aplic_name =
> fdt_get_aplic_nodename(aplic_addr);
> +    g_autofree char *aplic_name =
> riscv_fdt_get_aplic_nodename(aplic_addr);
>      g_autofree uint32_t *aplic_cells = g_new0(uint32_t, props-
> >num_harts * 2);
>      static const char * const aplic_compat[2] = {
>          "qemu,aplic", "riscv,aplic"
> @@ -695,14 +694,6 @@ void riscv_create_fdt_socket_aplic(void *fdt,
> APLICFdtProps *props,
>                           aplic_s_phandle, 0,
>                           false);
>  
> -    if (!props->socket && props->platform_bus_irq) {
> -        g_autofree char *aplic_name =
> fdt_get_aplic_nodename(aplic_addr);
> -        platform_bus_add_all_fdt_nodes(fdt, aplic_name,
> -                                       props->platform_bus->base,
> -                                       props->platform_bus->size,
> -                                       props->platform_bus_irq);
> -    }
> -
>      aplic_phandles[props->socket] = aplic_s_phandle;
>  }
>  
> diff --git a/hw/riscv/server_platform_ref.c
> b/hw/riscv/server_platform_ref.c
> index 5f485b1c79..3526c80d79 100644
> --- a/hw/riscv/server_platform_ref.c
> +++ b/hw/riscv/server_platform_ref.c
> @@ -192,6 +192,7 @@ static void
> create_fdt_sockets(RISCVServerRefMachineState *s,
>  {
>      int socket, phandle_pos;
>      MachineState *ms = MACHINE(s);
> +    g_autofree char *aplic_name = NULL;
>      uint32_t msi_m_phandle = 0, msi_s_phandle = 0;
>      uint32_t xplic_phandles[MAX_NODES];
>      g_autofree uint32_t *intc_phandles = NULL;
> @@ -251,8 +252,6 @@ static void
> create_fdt_sockets(RISCVServerRefMachineState *s,
>      aplic_fdt_props.aplic_m = !kvm_enabled()
>                                ? &memmap[RVSERVER_APLIC_M] : NULL;
>      aplic_fdt_props.aplic_s = &memmap[RVSERVER_APLIC_S];
> -    aplic_fdt_props.platform_bus = &memmap[RVSERVER_PLATFORM_BUS];
> -    aplic_fdt_props.platform_bus_irq = RVSERVER_PLATFORM_BUS_IRQ;
>      aplic_fdt_props.num_harts = ms->smp.cpus;
>      aplic_fdt_props.numa_enabled = numa_enabled;
>      aplic_fdt_props.irqchip_num_sources =
> RVSERVER_IRQCHIP_NUM_SOURCES;
> @@ -270,6 +269,12 @@ static void
> create_fdt_sockets(RISCVServerRefMachineState *s,
>                                        xplic_phandles);
>      }
>  
> +    aplic_name =
> riscv_fdt_get_aplic_nodename(memmap[RVSERVER_APLIC_S].base);
> +    platform_bus_add_all_fdt_nodes(ms->fdt, aplic_name,
> +                                  
> memmap[RVSERVER_PLATFORM_BUS].base,
> +                                  
> memmap[RVSERVER_PLATFORM_BUS].size,
> +                                   RVSERVER_PLATFORM_BUS_IRQ);
> +
>      for (socket = 0; socket < socket_count; socket++) {
>          if (socket == 0) {
>              *irq_mmio_phandle = xplic_phandles[socket];
> diff --git a/hw/riscv/virt.c b/hw/riscv/virt.c
> index d4b501802f..7ec7596b24 100644
> --- a/hw/riscv/virt.c
> +++ b/hw/riscv/virt.c
> @@ -290,8 +290,6 @@ static void create_fdt_sockets(RISCVVirtState *s,
>      if (s->aia_type != VIRT_AIA_TYPE_NONE) {
>          aplic_props.aplic_m = !kvm_enabled() ? &s-
> >memmap[VIRT_APLIC_M] : NULL;
>          aplic_props.aplic_s = &s->memmap[VIRT_APLIC_S];
> -        aplic_props.platform_bus = &s->memmap[VIRT_PLATFORM_BUS];
> -        aplic_props.platform_bus_irq = VIRT_PLATFORM_BUS_IRQ;
>          aplic_props.socket = 0;
>          aplic_props.num_harts = ms->smp.cpus;
>          aplic_props.numa_enabled = numa_enabled;
> @@ -347,6 +345,15 @@ static void create_fdt_sockets(RISCVVirtState
> *s,
>          }
>      }
>  
> +    if (s->aia_type != VIRT_AIA_TYPE_NONE) {
> +        g_autofree char *aplic_name =
> +            riscv_fdt_get_aplic_nodename(s-
> >memmap[VIRT_APLIC_S].base);
> +        platform_bus_add_all_fdt_nodes(ms->fdt, aplic_name,
> +                                       s-
> >memmap[VIRT_PLATFORM_BUS].base,
> +                                       s-
> >memmap[VIRT_PLATFORM_BUS].size,
> +                                       VIRT_PLATFORM_BUS_IRQ);
> +    }
> +
>      riscv_socket_fdt_write_distance_matrix(ms);
>  }
>  
> diff --git a/include/hw/riscv/fdt-common.h b/include/hw/riscv/fdt-
> common.h
> index eb9db8278d..b3b14ada0a 100644
> --- a/include/hw/riscv/fdt-common.h
> +++ b/include/hw/riscv/fdt-common.h
> @@ -54,8 +54,6 @@ typedef struct IMSICFdtProps {
>  typedef struct APLICFdtProps {
>      const MemMapEntry *aplic_m;
>      const MemMapEntry *aplic_s;
> -    const MemMapEntry *platform_bus;
> -    int platform_bus_irq;
>      int socket;
>      int num_harts;
>      bool numa_enabled;
> @@ -129,6 +127,7 @@ void riscv_create_fdt_socket_aplic(void *fdt,
> APLICFdtProps *props,
>  void riscv_create_fdt_socket_aclint(void *fdt, ACLINTFdtProps
> *props,
>                                      uint32_t *intc_phandles);
>  /* Caller must free the returned string.  */
> +char *riscv_fdt_get_aplic_nodename(hwaddr addr);
>  char *riscv_fdt_get_uart_nodename(hwaddr addr);
>  void riscv_create_fdt_uart(void *fdt, const MemMapEntry *uart_mem,
>                             int uart_irq, int aia_type,

Reply via email to