From 40838c8251953a8f4a97af9f1dcc03a5eb0def41 Mon Sep 17 00:00:00 2001 From: Anton Johansson Date: Wed, 30 Apr 2025 13:44:17 +0200 Subject: [PATCH] hw/riscv: Add macros and globals for simplifying machine definitions MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Adds macros and global interfaces for defining machines available only in qemu-system-riscv32, qemu-system-riscv64, or both. Reviewed-by: Pierrick Bouvier Signed-off-by: Anton Johansson Reviewed-by: Richard Henderson Acked-by: Alistair Francis Message-Id: <20260520-hw-riscv-cpu-int-v3-3-d1123ea63d9c@rev.ng> [PMD: Constify InterfaceInfo] Signed-off-by: Philippe Mathieu-Daudé --- include/hw/riscv/machines-qom.h | 26 ++++++++++++++++++++++++++ target/riscv/machine.c | 19 ++++++++++++++++++- 2 files changed, 44 insertions(+), 1 deletion(-) diff --git a/include/hw/riscv/machines-qom.h b/include/hw/riscv/machines-qom.h index 69fcf61fd7..ee346227bb 100644 --- a/include/hw/riscv/machines-qom.h +++ b/include/hw/riscv/machines-qom.h @@ -17,4 +17,30 @@ #define TYPE_TARGET_RISCV64_MACHINE \ "target-info-riscv64-machine" +/* + * Interfaces specifying whether a given QOM object is available in + * qemu-system-riscv32, qemu-system-riscv64, or both. + */ + +extern const InterfaceInfo riscv32_machine_interfaces[]; +extern const InterfaceInfo riscv64_machine_interfaces[]; +extern const InterfaceInfo riscv32_64_machine_interfaces[]; + +/* + * Helper macros for defining machines available in qemu-system-riscv32, + * qemu-system-riscv64, or both. + */ + +#define DEFINE_MACHINE_RISCV32(namestr, machine_initfn) \ + DEFINE_MACHINE_WITH_INTERFACE_ARRAY(namestr, machine_initfn, \ + riscv32_machine_interfaces) + +#define DEFINE_MACHINE_RISCV64(namestr, machine_initfn) \ + DEFINE_MACHINE_WITH_INTERFACE_ARRAY(namestr, machine_initfn, \ + riscv64_machine_interfaces) + +#define DEFINE_MACHINE_RISCV32_64(namestr, machine_initfn) \ + DEFINE_MACHINE_WITH_INTERFACE_ARRAY(namestr, machine_initfn, \ + riscv32_64_machine_interfaces) + #endif diff --git a/target/riscv/machine.c b/target/riscv/machine.c index 6776e7bf5a..b92e38b11a 100644 --- a/target/riscv/machine.c +++ b/target/riscv/machine.c @@ -22,7 +22,8 @@ #include "system/kvm.h" #include "migration/cpu.h" #include "exec/icount.h" -#include "debug.h" +#include "target/riscv/debug.h" +#include "hw/riscv/machines-qom.h" static bool pmp_needed(void *opaque) { @@ -522,3 +523,19 @@ const VMStateDescription vmstate_riscv_cpu = { NULL } }; + +const InterfaceInfo riscv32_machine_interfaces[] = { + { TYPE_TARGET_RISCV32_MACHINE }, + { } +}; + +const InterfaceInfo riscv64_machine_interfaces[] = { + { TYPE_TARGET_RISCV64_MACHINE }, + { } +}; + +const InterfaceInfo riscv32_64_machine_interfaces[] = { + { TYPE_TARGET_RISCV32_MACHINE }, + { TYPE_TARGET_RISCV64_MACHINE }, + { } +};