mirror of
https://github.com/riscv-software-src/opensbi.git
synced 2026-05-23 14:21:32 +01:00
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>
This commit is contained in:
@@ -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);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user