summaryrefslogtreecommitdiff
path: root/arch/arm/cpu/armv8/generic_timer.c
diff options
context:
space:
mode:
authorTom Rini <trini@konsulko.com>2024-05-14 07:46:33 -0600
committerTom Rini <trini@konsulko.com>2024-05-14 07:46:33 -0600
commite7992828adcd5fad75bce9e6c41dfa9277ab93b0 (patch)
treedcb6356b6af294979f388c78c6821a63c91d3275 /arch/arm/cpu/armv8/generic_timer.c
parentc67199962b2a819a4b0ae8d57dc68b7cadee0c9e (diff)
parent42826664e4452304bdadc909d7c5f791d4abc552 (diff)
Merge branch '2024-05-13-assorted-updates' into next
- A few zfs fixes, ARMv8 timer cleanups, support more algorithms with the nuvoton crypto driver, virtio + env in filesystem fix, K3 code cleanup and warning fix in gen_compile_commands.
Diffstat (limited to 'arch/arm/cpu/armv8/generic_timer.c')
-rw-r--r--arch/arm/cpu/armv8/generic_timer.c27
1 files changed, 27 insertions, 0 deletions
diff --git a/arch/arm/cpu/armv8/generic_timer.c b/arch/arm/cpu/armv8/generic_timer.c
index e4aa5a47455..1de7ec596fc 100644
--- a/arch/arm/cpu/armv8/generic_timer.c
+++ b/arch/arm/cpu/armv8/generic_timer.c
@@ -114,3 +114,30 @@ ulong timer_get_boot_us(void)
return val / get_tbclk();
}
+
+#if CONFIG_IS_ENABLED(ARMV8_UDELAY_EVENT_STREAM)
+void __udelay(unsigned long usec)
+{
+ u64 target = get_ticks() + usec_to_tick(usec);
+
+ /* At EL2 or above, use the event stream to avoid polling CNTPCT_EL0 so often */
+ if (current_el() >= 2) {
+ u32 cnthctl_val;
+ const u8 event_period = 0x7;
+
+ asm volatile("mrs %0, cnthctl_el2" : "=r" (cnthctl_val));
+ asm volatile("msr cnthctl_el2, %0" : : "r"
+ (cnthctl_val | CNTHCTL_EL2_EVNT_EN | CNTHCTL_EL2_EVNT_I(event_period)));
+
+ while (get_ticks() + (1ULL << event_period) <= target)
+ wfe();
+
+ /* Reset the event stream */
+ asm volatile("msr cnthctl_el2, %0" : : "r" (cnthctl_val));
+ }
+
+ /* Fall back to polling CNTPCT_EL0 */
+ while (get_ticks() <= target)
+ ;
+}
+#endif