On Sun, 2026-11-01 at 11:15 +0800, Tan Chi wrote:
> hw/riscv/aia.c is built unconditionally, but riscv_create_aia()
> references the APLIC and IMSIC device implementations, which are
> only built when their respective Kconfig options are enabled.
> 
> This causes undefined references to riscv_aplic_create() in
> minimal RISC-V builds that do not include APLIC.
> 
> Build aia.c only when both CONFIG_RISCV_APLIC and
> CONFIG_RISCV_IMSIC are enabled. Move imsic_num_bits() to aia.h
> as a static inline helper, since it is also used by FDT and
> ACPI code independently of the AIA device creation helper.
> 
> Signed-off-by: Tan Chi <[email protected]>

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

Alistair

> ---
>  hw/riscv/aia.c       | 11 -----------
>  hw/riscv/aia.h       | 12 +++++++++++-
>  hw/riscv/meson.build |  3 ++-
>  3 files changed, 13 insertions(+), 13 deletions(-)
> 
> diff --git a/hw/riscv/aia.c b/hw/riscv/aia.c
> index 56fc064533..4463ea2be8 100644
> --- a/hw/riscv/aia.c
> +++ b/hw/riscv/aia.c
> @@ -13,17 +13,6 @@
>  
>  #include "aia.h"
>  
> -uint32_t imsic_num_bits(uint32_t count)
> -{
> -    uint32_t ret = 0;
> -
> -    while (BIT(ret) < count) {
> -        ret++;
> -    }
> -
> -    return ret;
> -}
> -
>  DeviceState *riscv_create_aia(MemoryRegion *container,
>                               bool msimode, int aia_guests,
>                               uint32_t m_imsic_stride,
> diff --git a/hw/riscv/aia.h b/hw/riscv/aia.h
> index 5df3292610..e4dcc5aae0 100644
> --- a/hw/riscv/aia.h
> +++ b/hw/riscv/aia.h
> @@ -10,8 +10,18 @@
>  #define HW_RISCV_AIA_H
>  
>  #include "exec/hwaddr.h"
> +#include "qemu/bitops.h"
>  
> -uint32_t imsic_num_bits(uint32_t count);
> +static inline uint32_t imsic_num_bits(uint32_t count)
> +{
> +    uint32_t ret = 0;
> +
> +    while (BIT(ret) < count) {
> +        ret++;
> +    }
> +
> +    return ret;
> +}
>  
>  DeviceState *riscv_create_aia(MemoryRegion *container,
>                               bool msimode, int aia_guests,
> diff --git a/hw/riscv/meson.build b/hw/riscv/meson.build
> index 6bdabb9544..957031c07d 100644
> --- a/hw/riscv/meson.build
> +++ b/hw/riscv/meson.build
> @@ -1,5 +1,6 @@
>  riscv_ss = ss.source_set()
> -riscv_ss.add(files('aia.c'))
> +riscv_ss.add(when: ['CONFIG_RISCV_APLIC', 'CONFIG_RISCV_IMSIC'],
> +             if_true: files('aia.c'))
>  riscv_ss.add(files('boot.c'))
>  riscv_ss.add(files('device-common.c'))
>  riscv_ss.add(files('fdt-common.c'))

Reply via email to