[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v16 70/99] target/arm: move TCG gt timer creation code in tcg/
From: |
Alex Bennée |
Subject: |
[PATCH v16 70/99] target/arm: move TCG gt timer creation code in tcg/ |
Date: |
Fri, 4 Jun 2021 16:52:43 +0100 |
From: Claudio Fontana <cfontana@suse.de>
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>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
---
target/arm/tcg/tcg-cpu.h | 1 +
target/arm/cpu.c | 30 ++++---------------------
target/arm/tcg/sysemu/tcg-cpu.c | 40 +++++++++++++++++++++++++++++++++
3 files changed, 45 insertions(+), 26 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 945dfbbe9d..2fef8ca471 100644
--- a/target/arm/cpu.c
+++ b/target/arm/cpu.c
@@ -859,32 +859,10 @@ 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);
- }
-#endif /* CONFIG_TCG && !CONFIG_USER_ONLY */
+ if (!tcg_cpu_realize_gt_timers(cs, errp)) {
+ return;
+ }
+#endif
cpu_exec_realizefn(cs, &local_err);
if (local_err != NULL) {
diff --git a/target/arm/tcg/sysemu/tcg-cpu.c b/target/arm/tcg/sysemu/tcg-cpu.c
index 115ac523dc..1c6df15092 100644
--- a/target/arm/tcg/sysemu/tcg-cpu.c
+++ b/target/arm/tcg/sysemu/tcg-cpu.c
@@ -54,6 +54,46 @@ void tcg_handle_semihosting(CPUState *cs)
}
}
+/*
+ * 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.
+ *
+ * So we cannot call this from tcg_cpu_realizefn, as this needs to
+ * be called whenever TCG is built-in, regardless of whether it is
+ * enabled or not.
+ */
+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;
+}
+
bool tcg_cpu_realizefn(CPUState *cs, Error **errp)
{
ARMCPU *cpu = ARM_CPU(cs);
--
2.20.1
- Re: [PATCH v16 78/99] target/arm: cpu-exceptions, cpu-exceptions-aa64: new modules, (continued)
Re: [PATCH v16 78/99] target/arm: cpu-exceptions, cpu-exceptions-aa64: new modules, Richard Henderson, 2021/06/05
[PATCH v16 52/99] target/arm: rename handle_semihosting to tcg_handle_semihosting, Alex Bennée, 2021/06/04
[PATCH v16 94/99] target/arm: move CONFIG_V7M out of default-devices, Alex Bennée, 2021/06/04
[PATCH v16 26/99] target/arm: move physical address translation to cpu-mmu, Alex Bennée, 2021/06/04
[PATCH v16 70/99] target/arm: move TCG gt timer creation code in tcg/,
Alex Bennée <=
[PATCH v16 32/99] target/arm: move cpsr_read, cpsr_write to cpu_common, Alex Bennée, 2021/06/04
[PATCH v16 18/99] target/arm: tcg: add sysemu and user subdirs, Alex Bennée, 2021/06/04
[PATCH v16 64/99] tests: do not run test-hmp on all machines for ARM KVM-only, Alex Bennée, 2021/06/04
[PATCH v16 28/99] target/arm: split cpregs from tcg/helper.c, Alex Bennée, 2021/06/04
[PATCH v16 39/99] target/arm: move arm_cpu_list to common_cpu, Alex Bennée, 2021/06/04
[PATCH v16 43/99] target/arm: move a15 cpu model away from the TCG-only models, Alex Bennée, 2021/06/04