[PATCH v2 3/4] lib: utils: Simplify time_event_stop
Xiang W
wxjstz at 126.com
Tue May 27 22:53:52 PDT 2025
The code of time_event_stop is basically the same as time_event_start,
except for the values written into the registers. This patch
implements time_event_stop by calling time_event_start.
Signed-off-by: Xiang W <wxjstz at 126.com>
---
lib/utils/timer/aclint_mtimer.c | 21 +++++----------------
lib/utils/timer/andes_plmt.c | 21 +++++----------------
2 files changed, 10 insertions(+), 32 deletions(-)
diff --git a/lib/utils/timer/aclint_mtimer.c b/lib/utils/timer/aclint_mtimer.c
index 3db3c3be..ad4c10b3 100644
--- a/lib/utils/timer/aclint_mtimer.c
+++ b/lib/utils/timer/aclint_mtimer.c
@@ -69,22 +69,6 @@ static u64 mtimer_value(void)
return mt->time_rd((void *)mt->mtime_addr);
}
-static void mtimer_event_stop(void)
-{
- u32 target_hart = current_hartid();
- struct sbi_scratch *scratch = sbi_scratch_thishart_ptr();
- struct aclint_mtimer_data *mt;
- u64 *time_cmp;
-
- mt = mtimer_get_hart_data_ptr(scratch);
- if (!mt)
- return;
-
- /* Clear MTIMER Time Compare */
- time_cmp = (void *)mt->mtimecmp_addr;
- mt->time_wr(true, -1ULL, &time_cmp[target_hart - mt->first_hartid]);
-}
-
static void mtimer_event_start(u64 next_event)
{
u32 target_hart = current_hartid();
@@ -102,6 +86,11 @@ static void mtimer_event_start(u64 next_event)
&time_cmp[target_hart - mt->first_hartid]);
}
+static void mtimer_event_stop(void)
+{
+ mtimer_event_start(-1ULL);
+}
+
static struct sbi_timer_device mtimer = {
.name = "aclint-mtimer",
.timer_value = mtimer_value,
diff --git a/lib/utils/timer/andes_plmt.c b/lib/utils/timer/andes_plmt.c
index d034feb9..04206705 100644
--- a/lib/utils/timer/andes_plmt.c
+++ b/lib/utils/timer/andes_plmt.c
@@ -32,22 +32,6 @@ static u64 plmt_timer_value(void)
#endif
}
-static void plmt_timer_event_stop(void)
-{
- u32 target_hart = current_hartid();
-
- if (plmt.hart_count <= target_hart)
- ebreak();
-
- /* Clear PLMT Time Compare */
-#if __riscv_xlen == 64
- writeq_relaxed(-1ULL, &plmt.time_cmp[target_hart]);
-#else
- writel_relaxed(-1UL, &plmt.time_cmp[target_hart]);
- writel_relaxed(-1UL, (void *)(&plmt.time_cmp[target_hart]) + 0x04);
-#endif
-}
-
static void plmt_timer_event_start(u64 next_event)
{
u32 target_hart = current_hartid();
@@ -67,6 +51,11 @@ static void plmt_timer_event_start(u64 next_event)
#endif
}
+static void plmt_timer_event_stop(void)
+{
+ plmt_timer_event_start(-1ULL);
+}
+
static int plmt_warm_timer_init(void)
{
if (!plmt.time_val)
--
2.47.2
More information about the opensbi
mailing list