aboutsummaryrefslogtreecommitdiff
path: root/target
diff options
context:
space:
mode:
authorDaniel Henrique Barboza <dbarboza@ventanamicro.com>2023-09-25 14:57:01 -0300
committerAlistair Francis <alistair.francis@wdc.com>2023-10-12 12:19:06 +1000
commitd86c25b292bf9685615cbb93d7b07f33a9b63104 (patch)
treeec861e6e3d4946cbd9e819285a5232ab7dd009e2 /target
parent5c67bc73be9f896809b8ab4eb64020faa66ed491 (diff)
downloadqemu-d86c25b292bf9685615cbb93d7b07f33a9b63104.zip
qemu-d86c25b292bf9685615cbb93d7b07f33a9b63104.tar.gz
qemu-d86c25b292bf9685615cbb93d7b07f33a9b63104.tar.bz2
target/riscv: introduce KVM AccelCPUClass
Add a KVM accelerator class like we did with TCG. The difference is that, at least for now, we won't be using a realize() implementation for this accelerator. We'll start by assiging kvm_riscv_cpu_add_kvm_properties(), renamed to kvm_cpu_instance_init(), as a 'cpu_instance_init' implementation. Change riscv_cpu_post_init() to invoke accel_cpu_instance_init(), which will go through the 'cpu_instance_init' impl of the current acceleration (if available) and execute it. The end result is that the KVM initial setup, i.e. starting registers and adding its specific properties, will be done via this hook. Add a 'tcg_enabled()' condition in riscv_cpu_post_init() to avoid calling riscv_cpu_add_user_properties() when running KVM. We'll remove this condition when the TCG accel class get its own 'cpu_instance_init' implementation. Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> Reviewed-by: Andrew Jones <ajones@ventanamicro.com> Reviewed-by: LIU Zhiwei <zhiwei_liu@linux.alibaba.com> Reviewed-by: Alistair Francis <alistair.francis@wdc.com> Message-ID: <20230925175709.35696-12-dbarboza@ventanamicro.com> Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
Diffstat (limited to 'target')
-rw-r--r--target/riscv/cpu.c8
-rw-r--r--target/riscv/kvm.c26
-rw-r--r--target/riscv/kvm_riscv.h1
3 files changed, 27 insertions, 8 deletions
diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c
index 143fbc1..648b9f7 100644
--- a/target/riscv/cpu.c
+++ b/target/riscv/cpu.c
@@ -1219,7 +1219,9 @@ static bool riscv_cpu_has_user_properties(Object *cpu_obj)
static void riscv_cpu_post_init(Object *obj)
{
- if (riscv_cpu_has_user_properties(obj)) {
+ accel_cpu_instance_init(CPU(obj));
+
+ if (tcg_enabled() && riscv_cpu_has_user_properties(obj)) {
riscv_cpu_add_user_properties(obj);
}
@@ -1585,10 +1587,6 @@ static void riscv_cpu_add_multiext_prop_array(Object *obj,
static void riscv_cpu_add_user_properties(Object *obj)
{
#ifndef CONFIG_USER_ONLY
- if (kvm_enabled()) {
- kvm_riscv_cpu_add_kvm_properties(obj);
- return;
- }
riscv_add_satp_mode_properties(obj);
#endif
diff --git a/target/riscv/kvm.c b/target/riscv/kvm.c
index e5e9571..606fdab 100644
--- a/target/riscv/kvm.c
+++ b/target/riscv/kvm.c
@@ -31,6 +31,7 @@
#include "sysemu/kvm_int.h"
#include "cpu.h"
#include "trace.h"
+#include "hw/core/accel-cpu.h"
#include "hw/pci/pci.h"
#include "exec/memattrs.h"
#include "exec/address-spaces.h"
@@ -1318,8 +1319,9 @@ void kvm_riscv_aia_create(MachineState *machine, uint64_t group_shift,
kvm_msi_via_irqfd_allowed = kvm_irqfds_enabled();
}
-void kvm_riscv_cpu_add_kvm_properties(Object *obj)
+static void kvm_cpu_instance_init(CPUState *cs)
{
+ Object *obj = OBJECT(RISCV_CPU(cs));
DeviceState *dev = DEVICE(obj);
riscv_init_user_properties(obj);
@@ -1331,7 +1333,7 @@ void kvm_riscv_cpu_add_kvm_properties(Object *obj)
riscv_cpu_add_kvm_unavail_prop_array(obj, riscv_cpu_experimental_exts);
for (Property *prop = riscv_cpu_options; prop && prop->name; prop++) {
- /* Check if KVM created the property already */
+ /* Check if we have a specific KVM handler for the option */
if (object_property_find(obj, prop->name)) {
continue;
}
@@ -1339,6 +1341,26 @@ void kvm_riscv_cpu_add_kvm_properties(Object *obj)
}
}
+static void kvm_cpu_accel_class_init(ObjectClass *oc, void *data)
+{
+ AccelCPUClass *acc = ACCEL_CPU_CLASS(oc);
+
+ acc->cpu_instance_init = kvm_cpu_instance_init;
+}
+
+static const TypeInfo kvm_cpu_accel_type_info = {
+ .name = ACCEL_CPU_NAME("kvm"),
+
+ .parent = TYPE_ACCEL_CPU,
+ .class_init = kvm_cpu_accel_class_init,
+ .abstract = true,
+};
+static void kvm_cpu_accel_register_types(void)
+{
+ type_register_static(&kvm_cpu_accel_type_info);
+}
+type_init(kvm_cpu_accel_register_types);
+
static void riscv_host_cpu_init(Object *obj)
{
CPURISCVState *env = &RISCV_CPU(obj)->env;
diff --git a/target/riscv/kvm_riscv.h b/target/riscv/kvm_riscv.h
index da9630c4..8329cfa 100644
--- a/target/riscv/kvm_riscv.h
+++ b/target/riscv/kvm_riscv.h
@@ -19,7 +19,6 @@
#ifndef QEMU_KVM_RISCV_H
#define QEMU_KVM_RISCV_H
-void kvm_riscv_cpu_add_kvm_properties(Object *obj);
void kvm_riscv_reset_vcpu(RISCVCPU *cpu);
void kvm_riscv_set_irq(RISCVCPU *cpu, int irq, int level);
void kvm_riscv_aia_create(MachineState *machine, uint64_t group_shift,