All of lore.kernel.org
 help / color / mirror / Atom feed
From: Chao Liu <chao.liu.zevorn@gmail.com>
To: Anton Johansson <anjo@rev.ng>
Cc: qemu-devel@nongnu.org, qemu-riscv@nongnu.org, philmd@linaro.org,
	 pierrick.bouvier@oss.qualcomm.com, palmer@dabbelt.com,
	alistair.francis@wdc.com
Subject: Re: [PATCH v3 07/14] target/riscv: Replace TYPE_RISCV_CPU_BASE
Date: Thu, 21 May 2026 16:32:27 +0800	[thread overview]
Message-ID: <ag7DDwAL-H59sMB2@ChaodeMacBook-Pro.local> (raw)
In-Reply-To: <20260520-hw-riscv-cpu-int-v3-7-d1123ea63d9c@rev.ng>

On Wed, May 20, 2026 at 03:12:59PM +0800, Anton Johansson via wrote:
> TYPE_RISCV_CPU_BASE is used only to initialize the correct default
> machine for 3 machines. Replace it with a runtime check.
> 
> Reviewed-by: Pierrick Bouvier <pierrick.bouvier@linaro.org>
> Signed-off-by: Anton Johansson <anjo@rev.ng>
Reviewed-by: Chao Liu <chao.liu.zevorn@gmail.com>

> ---
>  include/hw/riscv/machines-qom.h | 12 ++++++++++++
>  target/riscv/cpu.h              |  6 ------
>  hw/riscv/microblaze-v-generic.c |  2 +-
>  hw/riscv/spike.c                |  2 +-
>  hw/riscv/virt.c                 |  2 +-
>  5 files changed, 15 insertions(+), 9 deletions(-)
> 
> diff --git a/include/hw/riscv/machines-qom.h b/include/hw/riscv/machines-qom.h
> index 3459437d84..8396155373 100644
> --- a/include/hw/riscv/machines-qom.h
> +++ b/include/hw/riscv/machines-qom.h
> @@ -9,7 +9,9 @@
>  #ifndef HW_RISCV_MACHINES_QOM_H
>  #define HW_RISCV_MACHINES_QOM_H
>  
> +#include "qemu/target-info.h"
>  #include "hw/core/boards.h"
> +#include "target/riscv/cpu-qom.h"
>  
>  #define TYPE_TARGET_RISCV32_MACHINE \
>          "target-info-riscv32-machine"
> @@ -43,4 +45,14 @@ extern InterfaceInfo riscv32_64_machine_interfaces[];
>          DEFINE_MACHINE_WITH_INTERFACE_ARRAY(namestr, machine_initfn, \
>                                              riscv32_64_machine_interfaces)
>  
> +/* Default CPU type inferred from target info */
> +static inline const char *riscv_default_cpu_type(void)
> +{
> +    if (target_riscv64()) {
> +        return TYPE_RISCV_CPU_BASE64;
> +    } else {
> +        return TYPE_RISCV_CPU_BASE32;
> +    }
> +}
> +
>  #endif
> diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h
> index fb44f0485d..f521686c43 100644
> --- a/target/riscv/cpu.h
> +++ b/target/riscv/cpu.h
> @@ -39,12 +39,6 @@ typedef struct CPUArchState CPURISCVState;
>  
>  #define CPU_RESOLVING_TYPE TYPE_RISCV_CPU
>  
> -#if defined(TARGET_RISCV32)
> -# define TYPE_RISCV_CPU_BASE            TYPE_RISCV_CPU_BASE32
> -#elif defined(TARGET_RISCV64)
> -# define TYPE_RISCV_CPU_BASE            TYPE_RISCV_CPU_BASE64
> -#endif
> -
>  /*
>   * b0: Whether a instruction always raise a store AMO or not.
>   */
> diff --git a/hw/riscv/microblaze-v-generic.c b/hw/riscv/microblaze-v-generic.c
> index d33ac39a68..386c5dce9c 100644
> --- a/hw/riscv/microblaze-v-generic.c
> +++ b/hw/riscv/microblaze-v-generic.c
> @@ -183,7 +183,7 @@ static void mb_v_generic_machine_init(MachineClass *mc)
>      mc->init = mb_v_generic_init;
>      mc->min_cpus = 1;
>      mc->max_cpus = 1;
> -    mc->default_cpu_type = TYPE_RISCV_CPU_BASE;
> +    mc->default_cpu_type = riscv_default_cpu_type();
>      mc->default_cpus = 1;
>  }
>  
> diff --git a/hw/riscv/spike.c b/hw/riscv/spike.c
> index 08ef291b6b..b937cf0fa6 100644
> --- a/hw/riscv/spike.c
> +++ b/hw/riscv/spike.c
> @@ -343,7 +343,7 @@ static void spike_machine_class_init(ObjectClass *oc, const void *data)
>      mc->init = spike_board_init;
>      mc->max_cpus = SPIKE_CPUS_MAX;
>      mc->is_default = true;
> -    mc->default_cpu_type = TYPE_RISCV_CPU_BASE;
> +    mc->default_cpu_type = riscv_default_cpu_type();
>      mc->possible_cpu_arch_ids = riscv_numa_possible_cpu_arch_ids;
>      mc->cpu_index_to_instance_props = riscv_numa_cpu_index_to_props;
>      mc->get_default_cpu_node_id = riscv_numa_get_default_cpu_node_id;
> diff --git a/hw/riscv/virt.c b/hw/riscv/virt.c
> index 39caf37c01..e108e29f63 100644
> --- a/hw/riscv/virt.c
> +++ b/hw/riscv/virt.c
> @@ -1933,7 +1933,7 @@ static void virt_machine_class_init(ObjectClass *oc, const void *data)
>      mc->desc = "RISC-V VirtIO board";
>      mc->init = virt_machine_init;
>      mc->max_cpus = VIRT_CPUS_MAX;
> -    mc->default_cpu_type = TYPE_RISCV_CPU_BASE;
> +    mc->default_cpu_type = riscv_default_cpu_type();
>      mc->block_default_type = IF_VIRTIO;
>      mc->no_cdrom = 1;
>      mc->pci_allow_0_address = true;
> 
> -- 
> 2.52.0
> 
> 


  reply	other threads:[~2026-05-21  8:32 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-05-20 13:12 [PATCH v3 00/14] single-binary: Compile hw/riscv once Anton Johansson via qemu development
2026-05-20 13:12 ` [PATCH v3 01/14] hw/riscv: Register generic riscv[32|64] QOM interfaces Anton Johansson via qemu development
2026-05-22 22:40   ` Richard Henderson
2026-05-20 13:12 ` [PATCH v3 02/14] hw/riscv: Add macros and globals for simplifying machine definitions Anton Johansson via qemu development
2026-05-22 22:39   ` Richard Henderson
2026-05-20 13:12 ` [PATCH v3 03/14] hw/riscv: Filter machine types for qemu-system-riscv32/64 binaries Anton Johansson via qemu development
2026-05-20 13:12 ` [PATCH v3 04/14] hw/core: Add riscv[32|64] to "none" machine Anton Johansson via qemu development
2026-05-22 22:40   ` Richard Henderson
2026-05-20 13:12 ` [PATCH v3 05/14] configs/target: Implement per-binary TargetInfo structure for riscv Anton Johansson via qemu development
2026-05-22 22:41   ` Richard Henderson
2026-05-20 13:12 ` [PATCH v3 06/14] target-info: Add target_riscv64() Anton Johansson via qemu development
2026-05-21  8:19   ` Chao Liu
2026-05-26  9:46     ` Philippe Mathieu-Daudé
2026-05-26  9:36   ` Philippe Mathieu-Daudé
2026-05-20 13:12 ` [PATCH v3 07/14] target/riscv: Replace TYPE_RISCV_CPU_BASE Anton Johansson via qemu development
2026-05-21  8:32   ` Chao Liu [this message]
2026-05-20 13:13 ` [PATCH v3 08/14] target/riscv: Remove ifdefs in cpu.h Anton Johansson via qemu development
2026-05-20 13:13 ` [PATCH v3 09/14] target/riscv: Replace TARGET_LONG_BITS in header exposed to common code Anton Johansson via qemu development
2026-05-20 13:13 ` [PATCH v3 10/14] target/riscv: Move riscv_pmu_read_ctr() to internal csr.h header Anton Johansson via qemu development
2026-05-20 13:13 ` [PATCH v3 11/14] target/riscv: Stub out kvm functions Anton Johansson via qemu development
2026-05-20 19:28   ` Philippe Mathieu-Daudé
2026-05-20 13:13 ` [PATCH v3 12/14] target/riscv: Move target_long.h inclusion away from cpu.h Anton Johansson via qemu development
2026-05-20 15:06   ` Pierrick Bouvier
2026-05-20 13:13 ` [PATCH v3 13/14] hw/riscv: Define SiFive E/U CPUs using runtime conditions Anton Johansson via qemu development
2026-05-21  8:40   ` Chao Liu
2026-05-20 13:13 ` [PATCH v3 14/14] hw/riscv: Compile once Anton Johansson via qemu development
2026-05-26 23:44 ` [PATCH v3 00/14] single-binary: Compile hw/riscv once Alistair Francis
2026-05-26 23:45 ` Alistair Francis
2026-05-27  6:07 ` Philippe Mathieu-Daudé
2026-05-28 15:06   ` Anton Johansson via
2026-05-28 15:06     ` Anton Johansson via qemu development
2026-05-28 19:53     ` Philippe Mathieu-Daudé

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=ag7DDwAL-H59sMB2@ChaodeMacBook-Pro.local \
    --to=chao.liu.zevorn@gmail.com \
    --cc=alistair.francis@wdc.com \
    --cc=anjo@rev.ng \
    --cc=palmer@dabbelt.com \
    --cc=philmd@linaro.org \
    --cc=pierrick.bouvier@oss.qualcomm.com \
    --cc=qemu-devel@nongnu.org \
    --cc=qemu-riscv@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.