From: "Philippe Mathieu-Daudé" <philmd@linaro.org>
To: qemu-devel@nongnu.org
Cc: qemu-arm@nongnu.org,
"Mohamed Mediouni" <mohamed@unpredictable.fr>,
"Phil Dennis-Jordan" <phil@philjordan.eu>,
"Roman Bolshakov" <rbolshakov@ddn.com>,
"Peter Maydell" <peter.maydell@linaro.org>,
"Paolo Bonzini" <pbonzini@redhat.com>,
"Alexander Graf" <agraf@csgraf.de>,
"Mads Ynddal" <mads@ynddal.dk>,
"Cameron Esfahani" <dirty@apple.com>,
"Richard Henderson" <richard.henderson@linaro.org>,
"Philippe Mathieu-Daudé" <philmd@linaro.org>
Subject: [PATCH-for-10.1 v4 4/4] target/arm/hvf: Really set Generic Timer counter frequency
Date: Wed, 23 Jul 2025 15:51:56 +0200 [thread overview]
Message-ID: <20250723135156.85426-5-philmd@linaro.org> (raw)
In-Reply-To: <20250723135156.85426-1-philmd@linaro.org>
Setting ARMCPU::gt_cntfrq_hz in hvf_arch_init_vcpu() is
not correct because the timers have already be initialized
with the default frequency.
Set it earlier in the AccelOpsClass::cpu_target_realize()
handler instead, and assert the value is correct when
reaching hvf_arch_init_vcpu().
Fixes: a1477da3dde ("hvf: Add Apple Silicon support")
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
---
target/arm/hvf/hvf.c | 15 ++++++++++++++-
1 file changed, 14 insertions(+), 1 deletion(-)
diff --git a/target/arm/hvf/hvf.c b/target/arm/hvf/hvf.c
index 7de770da4f3..ea9e6b1c0c6 100644
--- a/target/arm/hvf/hvf.c
+++ b/target/arm/hvf/hvf.c
@@ -1007,6 +1007,13 @@ cleanup:
return ret;
}
+static uint64_t get_cntfrq_el0(void)
+{
+ uint64_t freq_hz = 0;
+ asm volatile("mrs %0, cntfrq_el0" : "=r"(freq_hz));
+ return freq_hz;
+}
+
int hvf_arch_init_vcpu(CPUState *cpu)
{
ARMCPU *arm_cpu = ARM_CPU(cpu);
@@ -1018,7 +1025,9 @@ int hvf_arch_init_vcpu(CPUState *cpu)
int i;
env->aarch64 = true;
- asm volatile("mrs %0, cntfrq_el0" : "=r"(arm_cpu->gt_cntfrq_hz));
+
+ /* system count frequency sanity check */
+ assert(arm_cpu->gt_cntfrq_hz == get_cntfrq_el0());
/* Allocate enough space for our sysreg sync */
arm_cpu->cpreg_indexes = g_renew(uint64_t, arm_cpu->cpreg_indexes,
@@ -1083,6 +1092,10 @@ int hvf_arch_init_vcpu(CPUState *cpu)
bool hvf_arch_cpu_realize(CPUState *cs, Error **errp)
{
+ ARMCPU *cpu = ARM_CPU(cs);
+
+ cpu->gt_cntfrq_hz = get_cntfrq_el0();
+
return true;
}
--
2.49.0
next prev parent reply other threads:[~2025-07-23 13:58 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-07-23 13:51 [PATCH-for-10.1 v4 0/4] target/arm/hvf: Correctly set Generic Timer frequency Philippe Mathieu-Daudé
2025-07-23 13:51 ` [PATCH-for-10.1 v4 1/4] accel: Introduce AccelOpsClass::cpu_target_realize() hook Philippe Mathieu-Daudé
2025-07-23 15:49 ` Peter Maydell
2025-07-23 16:18 ` Philippe Mathieu-Daudé
2025-07-23 13:51 ` [PATCH-for-10.1 v4 2/4] accel/hvf: Add hvf_arch_cpu_realize() stubs Philippe Mathieu-Daudé
2025-07-23 16:06 ` Peter Maydell
2025-07-23 13:51 ` [PATCH-for-10.1 v4 3/4] target/arm: Create GTimers *after* features finalized / accel realized Philippe Mathieu-Daudé
2025-07-23 16:00 ` Peter Maydell
2025-07-23 16:19 ` Philippe Mathieu-Daudé
2025-07-23 13:51 ` Philippe Mathieu-Daudé [this message]
2025-07-23 16:06 ` [PATCH-for-10.1 v4 4/4] target/arm/hvf: Really set Generic Timer counter frequency Peter Maydell
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=20250723135156.85426-5-philmd@linaro.org \
--to=philmd@linaro.org \
--cc=agraf@csgraf.de \
--cc=dirty@apple.com \
--cc=mads@ynddal.dk \
--cc=mohamed@unpredictable.fr \
--cc=pbonzini@redhat.com \
--cc=peter.maydell@linaro.org \
--cc=phil@philjordan.eu \
--cc=qemu-arm@nongnu.org \
--cc=qemu-devel@nongnu.org \
--cc=rbolshakov@ddn.com \
--cc=richard.henderson@linaro.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).