summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorAnup Patel <anup.patel@oss.qualcomm.com>2026-04-25 16:10:48 +0530
committerAnup Patel <anup@brainfault.org>2026-05-09 13:16:07 +0530
commit1932ee3f0ae2f200431c20018e2d75dbceb65695 (patch)
tree6ee68e4c69561126cd7ce2e37c5ac63a2f2b8f5a /include
parentb7fa8a246cba80d74c0993dd0275b3c1589ef8b6 (diff)
downloadopensbi-1932ee3f0ae2f200431c20018e2d75dbceb65695.tar.gz
opensbi-1932ee3f0ae2f200431c20018e2d75dbceb65695.zip
lib: sbi_timer: Introduce sbi_timer_compute_delta() and friends
The users of timer event have to compute next_event (aka timer value in the future) based on desired units and unit frequency. Introduce sbi_timer_compute_delta() and friends to simplify computing next_event for timer event users. Signed-off-by: Anup Patel <anup.patel@oss.qualcomm.com> Reviewed-by: Nicholas Piggin <npiggin@gmail.com> Link: https://lore.kernel.org/r/20260425104048.2335262-5-anup.patel@oss.qualcomm.com Signed-off-by: Anup Patel <anup@brainfault.org>
Diffstat (limited to 'include')
-rw-r--r--include/sbi/sbi_timer.h27
1 files changed, 27 insertions, 0 deletions
diff --git a/include/sbi/sbi_timer.h b/include/sbi/sbi_timer.h
index 914a5f12..2a040927 100644
--- a/include/sbi/sbi_timer.h
+++ b/include/sbi/sbi_timer.h
@@ -88,6 +88,21 @@ struct sbi_timer_device {
struct sbi_scratch;
+/** Compute timer value delta based on arbitary units */
+u64 sbi_timer_compute_delta(ulong units, u64 unit_freq);
+
+/** Compute timer value delta from milliseconds */
+static inline u64 sbi_timer_compute_mdelta(ulong msecs)
+{
+ return sbi_timer_compute_delta(msecs, 1000);
+}
+
+/** Compute timer value delta from microseconds */
+static inline u64 sbi_timer_compute_udelta(ulong usecs)
+{
+ return sbi_timer_compute_delta(usecs, 1000000);
+}
+
/** Generic delay loop of desired granularity */
void sbi_timer_delay_loop(ulong units, u64 unit_freq,
void (*delay_fn)(void *), void *opaque);
@@ -125,6 +140,18 @@ bool sbi_timer_waitms_until(bool (*predicate)(void *), void *arg,
/** Get timer value for current HART */
u64 sbi_timer_value(void);
+/** Compute timer value after specified milliseconds */
+static inline u64 sbi_timer_value_after_msecs(ulong msecs)
+{
+ return sbi_timer_value() + sbi_timer_compute_mdelta(msecs);
+}
+
+/** Compute timer value after specified microseconds */
+static inline u64 sbi_timer_value_after_usecs(ulong usecs)
+{
+ return sbi_timer_value() + sbi_timer_compute_udelta(usecs);
+}
+
/** Get virtualized timer value for current HART */
u64 sbi_timer_virt_value(void);