[PATCH] armv8: implement workaround for broken CNTFRQ_EL0 value
Ahmad Fatoum
a.fatoum at pengutronix.de
Thu Oct 16 17:15:42 CEST 2025
Hello Kaustabh,
On 10/16/25 4:59 PM, Kaustabh Chakraborty wrote:
> On 2025-10-15 07:48, Ahmad Fatoum wrote:
>>> Thus, the only solution is to add a config option which, when enabled,
>>> returns a hard coded value (CONFIG_COUNTER_FREQUENCY) instead of
>>> querying
>>> CNTFRQ_EL0.
>>
>> Why not read it from the clock-frequency property in the device tree?
>>
>> This is what barebox is now doing, incidentally also for Samsung
>> support, see:
>> https://lore.kernel.org/barebox/20250729203659.1858575-3-
>> ivo.ivanov.ivanov1 at gmail.com/
>
> In barebox, the timer is a device driver, like in linux. In U-Boot
> however, it is
> instead part of the ARM architecture specific code. And it is being
> accessed by
> a single function, not dependent on others.
Ah, I wasn't aware of this.
> However, in U-Boot i found gd->arch.timer_rate_hz, which can be used,
> like so:
>
> if (gd->arch.timer_rate_hz)
> return gd->arch.timer_rate_hz;
>
> This property needs to be set in board file – in timer_init(). So I will do
> that instead.
:)
Cheers,
Ahmad
>
>>
>> Cheers,
>> Ahmad
>>
>>>
>>> Signed-off-by: Kaustabh Chakraborty <kauschluss at disroot.org>
>>> ---
>>> arch/arm/cpu/armv8/Kconfig | 9 +++++++++
>>> arch/arm/cpu/armv8/generic_timer.c | 4 ++++
>>> 2 files changed, 13 insertions(+)
>>>
>>> diff --git a/arch/arm/cpu/armv8/Kconfig b/arch/arm/cpu/armv8/Kconfig
>>> index
>>> 199335cd6040d30a355a7fd5448a449fa7f550fb..d54d874b7caea200e1c05f522d8affe6d239a102 100644
>>> --- a/arch/arm/cpu/armv8/Kconfig
>>> +++ b/arch/arm/cpu/armv8/Kconfig
>>> @@ -4,6 +4,15 @@ config CMO_BY_VA_ONLY
>>> bool "Force cache maintenance to be exclusively by VA"
>>> depends on !SYS_DISABLE_DCACHE_OPS
>>>
>>> +config ARMV8_CNTFRQ_BROKEN
>>> + bool "Fix broken ARMv8 generic timer"
>>> + depends on COUNTER_FREQUENCY > 0
>>> + depends on SYS_ARCH_TIMER
>>> + help
>>> + Say Y here if there is no trustable firmware present which sets
>>> + CNTFRQ_EL0 frequency before U-Boot. U-Boot will use the
>>> + CONFIG_COUNTER_FREQUENCY value as the reported frequency.
>>> +
>>> 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
>>> 1de7ec596fc7cbbc3e78a241f163bc0a4fcad6b6..409570cf6fda79527e296b958368b552900524b1 100644
>>> --- a/arch/arm/cpu/armv8/generic_timer.c
>>> +++ b/arch/arm/cpu/armv8/generic_timer.c
>>> @@ -19,6 +19,10 @@ DECLARE_GLOBAL_DATA_PTR;
>>> unsigned long notrace get_tbclk(void)
>>> {
>>> unsigned long cntfrq;
>>> +
>>> + if (IS_ENABLED(CONFIG_ARMV8_CNTFRQ_BROKEN))
>>> + return CONFIG_COUNTER_FREQUENCY;
>>> +
>>> asm volatile("mrs %0, cntfrq_el0" : "=r" (cntfrq));
>>> return cntfrq;
>>> }
>>>
>>> ---
>>> base-commit: a5b3be1a37e19646b9d36c91f11b23f568be4f21
>>> change-id: 20251014-armv8-broken-cntfrq-f350f68fbf6e
>>>
>>> Best regards,
>>
>>
>> --
>> Pengutronix e.K. |
>> |
>> Steuerwalder Str. 21 | http://
>> www.pengutronix.de/ |
>> 31137 Hildesheim, Germany | Phone:
>> +49-5121-206917-0 |
>> Amtsgericht Hildesheim, HRA 2686 | Fax:
>> +49-5121-206917-5555 |
>
--
Pengutronix e.K. | |
Steuerwalder Str. 21 | http://www.pengutronix.de/ |
31137 Hildesheim, Germany | Phone: +49-5121-206917-0 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
More information about the U-Boot
mailing list