[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[RFC v7 42/42] target/arm: move TCG gt timer creation code in tcg/
From: |
Claudio Fontana |
Subject: |
[RFC v7 42/42] target/arm: move TCG gt timer creation code in tcg/ |
Date: |
Fri, 12 Mar 2021 18:22:43 +0100 |
we need to be careful not to use
if (tcg_enabled())
here, because of the VMSTATE definitions in machine.c,
which are only protected by CONFIG_TCG, and thus
it would break the --enable-tcg --enable-kvm build.
Signed-off-by: Claudio Fontana <cfontana@suse.de>
---
target/arm/tcg/tcg-cpu.h | 1 +
target/arm/cpu.c | 26 ++----------------------
target/arm/tcg/sysemu/tcg-cpu.c | 36 +++++++++++++++++++++++++++++++++
3 files changed, 39 insertions(+), 24 deletions(-)
diff --git a/target/arm/tcg/tcg-cpu.h b/target/arm/tcg/tcg-cpu.h
index dd08587949..3e4ce2c355 100644
--- a/target/arm/tcg/tcg-cpu.h
+++ b/target/arm/tcg/tcg-cpu.h
@@ -33,6 +33,7 @@ void tcg_arm_init_accel_cpu(AccelCPUClass *accel_cpu,
CPUClass *cc);
/* Do semihosting call and set the appropriate return value. */
void tcg_handle_semihosting(CPUState *cs);
bool tcg_cpu_realizefn(CPUState *cs, Error **errp);
+bool tcg_cpu_realize_gt_timers(CPUState *cs, Error **errp);
#endif /* !CONFIG_USER_ONLY */
diff --git a/target/arm/cpu.c b/target/arm/cpu.c
index 09c1db604a..61cd12527b 100644
--- a/target/arm/cpu.c
+++ b/target/arm/cpu.c
@@ -870,30 +870,8 @@ static void arm_cpu_realizefn(DeviceState *dev, Error
**errp)
bool no_aa32 = false;
#if defined(CONFIG_TCG) && !defined(CONFIG_USER_ONLY)
- {
- uint64_t scale;
-
- if (arm_feature(env, ARM_FEATURE_GENERIC_TIMER)) {
- if (!cpu->gt_cntfrq_hz) {
- error_setg(errp, "Invalid CNTFRQ: %"PRId64"Hz",
- cpu->gt_cntfrq_hz);
- return;
- }
- scale = gt_cntfrq_period_ns(cpu);
- } else {
- scale = GTIMER_SCALE;
- }
-
- cpu->gt_timer[GTIMER_PHYS] = timer_new(QEMU_CLOCK_VIRTUAL, scale,
- arm_gt_ptimer_cb, cpu);
- cpu->gt_timer[GTIMER_VIRT] = timer_new(QEMU_CLOCK_VIRTUAL, scale,
- arm_gt_vtimer_cb, cpu);
- cpu->gt_timer[GTIMER_HYP] = timer_new(QEMU_CLOCK_VIRTUAL, scale,
- arm_gt_htimer_cb, cpu);
- cpu->gt_timer[GTIMER_SEC] = timer_new(QEMU_CLOCK_VIRTUAL, scale,
- arm_gt_stimer_cb, cpu);
- cpu->gt_timer[GTIMER_HYPVIRT] = timer_new(QEMU_CLOCK_VIRTUAL, scale,
- arm_gt_hvtimer_cb, cpu);
+ if (!tcg_cpu_realize_gt_timers(cs, errp)) {
+ return;
}
#endif /* CONFIG_TCG && !CONFIG_USER_ONLY */
diff --git a/target/arm/tcg/sysemu/tcg-cpu.c b/target/arm/tcg/sysemu/tcg-cpu.c
index c5b8f136ee..97b57dec50 100644
--- a/target/arm/tcg/sysemu/tcg-cpu.c
+++ b/target/arm/tcg/sysemu/tcg-cpu.c
@@ -77,3 +77,39 @@ bool tcg_cpu_realizefn(CPUState *cs, Error **errp)
}
return true;
}
+
+/*
+ * we cannot use tcg_enabled() to condition the call to this function,
+ * due to the fields VMSTATE definitions in machine.c : it would break
+ * the --enable-tcg --enable-kvm build. We need to run this code whenever
+ * CONFIG_TCG is true, regardless of the chosen accelerator.
+ */
+bool tcg_cpu_realize_gt_timers(CPUState *cs, Error **errp)
+{
+ ARMCPU *cpu = ARM_CPU(cs);
+ CPUARMState *env = &cpu->env;
+ uint64_t scale;
+
+ if (arm_feature(env, ARM_FEATURE_GENERIC_TIMER)) {
+ if (!cpu->gt_cntfrq_hz) {
+ error_setg(errp, "Invalid CNTFRQ: %"PRId64"Hz",
+ cpu->gt_cntfrq_hz);
+ return false;
+ }
+ scale = gt_cntfrq_period_ns(cpu);
+ } else {
+ scale = GTIMER_SCALE;
+ }
+
+ cpu->gt_timer[GTIMER_PHYS] = timer_new(QEMU_CLOCK_VIRTUAL, scale,
+ arm_gt_ptimer_cb, cpu);
+ cpu->gt_timer[GTIMER_VIRT] = timer_new(QEMU_CLOCK_VIRTUAL, scale,
+ arm_gt_vtimer_cb, cpu);
+ cpu->gt_timer[GTIMER_HYP] = timer_new(QEMU_CLOCK_VIRTUAL, scale,
+ arm_gt_htimer_cb, cpu);
+ cpu->gt_timer[GTIMER_SEC] = timer_new(QEMU_CLOCK_VIRTUAL, scale,
+ arm_gt_stimer_cb, cpu);
+ cpu->gt_timer[GTIMER_HYPVIRT] = timer_new(QEMU_CLOCK_VIRTUAL, scale,
+ arm_gt_hvtimer_cb, cpu);
+ return true;
+}
--
2.26.2
- [RFC v7 37/42] target/arm: create kvm cpu accel class, (continued)
- [RFC v7 37/42] target/arm: create kvm cpu accel class, Claudio Fontana, 2021/03/12
- [RFC v7 41/42] target/arm: add tcg cpu accel class, Claudio Fontana, 2021/03/12
- [RFC v7 34/42] tests: device-introspect-test: cope with ARM TCG-only devices, Claudio Fontana, 2021/03/12
- [RFC v7 35/42] tests: do not run qom-test on all machines for ARM KVM-only, Claudio Fontana, 2021/03/12
- [RFC v7 39/42] accel: move call to accel_init_interfaces, Claudio Fontana, 2021/03/12
- [RFC v7 36/42] Revert "target/arm: Restrict v8M IDAU to TCG", Claudio Fontana, 2021/03/12
- [RFC v7 33/42] tests: do not run test-hmp on all machines for ARM KVM-only, Claudio Fontana, 2021/03/12
- [RFC v7 38/42] target/arm: move kvm cpu properties setting to kvm-cpu, Claudio Fontana, 2021/03/12
- [RFC v7 32/42] tests: restrict TCG-only arm-cpu-features tests to TCG builds, Claudio Fontana, 2021/03/12
- [RFC v7 42/42] target/arm: move TCG gt timer creation code in tcg/,
Claudio Fontana <=