From: Balaji Selvanathan <balaji.selvanathan@oss.qualcomm.com>
To: u-boot@lists.denx.de, Sumit Garg <sumit.garg@kernel.org>,
u-boot-qcom@groups.io
Cc: Tom Rini <trini@konsulko.com>,
Kaustabh Chakraborty <kauschluss@disroot.org>,
Casey Connolly <casey.connolly@linaro.org>,
Neil Armstrong <neil.armstrong@linaro.org>,
Sughosh Ganu <sughosh.ganu@arm.com>,
Ilias Apalodimas <ilias.apalodimas@linaro.org>,
George Chan <gchan9527@gmail.com>,
Balaji Selvanathan <balaji.selvanathan@oss.qualcomm.com>
Subject: [PATCH 1/2] armv8: timer: Add option to use virtual counter at EL1
Date: Mon, 06 Apr 2026 16:25:36 +0530 [thread overview]
Message-ID: <20260406-timer-v1-1-f7c5a290c459@oss.qualcomm.com> (raw)
In-Reply-To: <20260406-timer-v1-0-f7c5a290c459@oss.qualcomm.com>
Add CONFIG_ARMV8_TIMER_USE_VIRTUAL_COUNTER to allow platforms to use
the virtual counter (CNTVCT_EL0) instead of the physical counter
(CNTPCT_EL0) when running at EL1.
This addresses platforms where the hypervisor or EL2 firmware does
not configure CNTHCTL_EL2.EL1PCTEN, causing EL1 access to CNTPCT_EL0
to trap. The virtual counter is typically accessible without trapping
and provides equivalent functionality when CNTVOFF_EL2 is zero, as is
typical in bootloader environments.
The new Kconfig option is disabled by default to maintain existing
behavior on platforms where physical counter access works correctly.
Signed-off-by: Balaji Selvanathan <balaji.selvanathan@oss.qualcomm.com>
---
arch/arm/cpu/armv8/Kconfig | 19 +++++++++++++++++++
arch/arm/cpu/armv8/generic_timer.c | 13 +++++++++++++
2 files changed, 32 insertions(+)
diff --git a/arch/arm/cpu/armv8/Kconfig b/arch/arm/cpu/armv8/Kconfig
index dfc4ce851c3..00c7303e09d 100644
--- a/arch/arm/cpu/armv8/Kconfig
+++ b/arch/arm/cpu/armv8/Kconfig
@@ -12,6 +12,25 @@ config ARMV8_CNTFRQ_BROKEN
does not set the CNTFRQ_EL0 frequency, and its not possible to
set it from U-Boot either.
+config ARMV8_TIMER_USE_VIRTUAL_COUNTER
+ bool "Use virtual counter (CNTVCT_EL0) at EL1"
+ depends on SYS_ARCH_TIMER
+ help
+ Say Y here if the platform's hypervisor/EL2 firmware does not
+ configure CNTHCTL_EL2.EL1PCTEN to allow EL1 access to the physical
+ counter (CNTPCT_EL0), causing traps when attempting to read it.
+
+ This option makes the generic timer use the virtual counter
+ (CNTVCT_EL0) when running at EL1, which is typically accessible
+ without trapping.
+
+ This is a workaround for platforms where the EL2 firmware cannot
+ properly configure CNTHCTL_EL2. In most cases, the
+ virtual counter provides equivalent functionality since CNTVOFF_EL2
+ is typically zero in bootloader environments.
+
+ If unsure, say N.
+
config ARMV8_SPL_EXCEPTION_VECTORS
bool "Install crash dump exception vectors"
depends on SPL
diff --git a/arch/arm/cpu/armv8/generic_timer.c b/arch/arm/cpu/armv8/generic_timer.c
index 744ab3b91e5..6dc98874504 100644
--- a/arch/arm/cpu/armv8/generic_timer.c
+++ b/arch/arm/cpu/armv8/generic_timer.c
@@ -86,7 +86,20 @@ unsigned long notrace timer_read_counter(void)
unsigned long cntpct;
isb();
+
+#ifdef CONFIG_ARMV8_TIMER_USE_VIRTUAL_COUNTER
+ /*
+ * Use virtual counter (CNTVCT_EL0) at EL1 if configured.
+ * This is a workaround for platforms where the hypervisor/EL2 firmware
+ * does not configure CNTHCTL_EL2.EL1PCTEN, causing EL1 access to
+ * CNTPCT_EL0 to trap. The virtual counter is typically accessible
+ * without trapping and provides equivalent functionality when
+ * CNTVOFF_EL2 is zero (as is typical in bootloader environments).
+ */
+ asm volatile("mrs %0, cntvct_el0" : "=r" (cntpct));
+#else
asm volatile("mrs %0, cntpct_el0" : "=r" (cntpct));
+#endif
return cntpct;
}
--
2.34.1
next prev parent reply other threads:[~2026-04-06 10:55 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-04-06 10:55 [PATCH 0/2] ARMv8 timer fixes for platforms without EL2 configuration Balaji Selvanathan
2026-04-06 10:55 ` Balaji Selvanathan [this message]
2026-04-06 10:55 ` [PATCH 2/2] snapdragon: Set timer frequency for ARMV8_CNTFRQ_BROKEN platforms Balaji Selvanathan
2026-04-13 9:22 ` [PATCH 0/2] ARMv8 timer fixes for platforms without EL2 configuration Sumit Garg
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=20260406-timer-v1-1-f7c5a290c459@oss.qualcomm.com \
--to=balaji.selvanathan@oss.qualcomm.com \
--cc=casey.connolly@linaro.org \
--cc=gchan9527@gmail.com \
--cc=ilias.apalodimas@linaro.org \
--cc=kauschluss@disroot.org \
--cc=neil.armstrong@linaro.org \
--cc=sughosh.ganu@arm.com \
--cc=sumit.garg@kernel.org \
--cc=trini@konsulko.com \
--cc=u-boot-qcom@groups.io \
--cc=u-boot@lists.denx.de \
/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