public inbox for opensbi@lists.infradead.org
 help / color / mirror / Atom feed
From: Nick Hu <nick.hu@sifive.com>
To: opensbi@lists.infradead.org
Cc: Cyan Yang <cyan.yang@sifive.com>,
	Anup Patel <anup@brainfault.org>,  Nick Hu <nick.hu@sifive.com>
Subject: [PATCH v7 10/12] lib: utils/timer: Expose timer update function
Date: Mon, 20 Oct 2025 14:34:12 +0800	[thread overview]
Message-ID: <20251020-cache-upstream-v7-10-69a132447d8a@sifive.com> (raw)
In-Reply-To: <20251020-cache-upstream-v7-0-69a132447d8a@sifive.com>

Exposing the ACLINT timer update APIs so the user can update the mtimer
after waking up from the non-retentive suspend.

Reviewed-by: Cyan Yang <cyan.yang@sifive.com>
Reviewed-by: Anup Patel <anup@brainfault.org>
Signed-off-by: Nick Hu <nick.hu@sifive.com>
---
 include/sbi_utils/timer/aclint_mtimer.h |  5 +++++
 lib/utils/timer/aclint_mtimer.c         | 28 +++++++++++++++++++++-------
 2 files changed, 26 insertions(+), 7 deletions(-)

diff --git a/include/sbi_utils/timer/aclint_mtimer.h b/include/sbi_utils/timer/aclint_mtimer.h
index a245e13e285f2ad658fce7db6366fe8b7bae8c2a..f8d2e5b4c210164c8a737e82643e5e49807753c4 100644
--- a/include/sbi_utils/timer/aclint_mtimer.h
+++ b/include/sbi_utils/timer/aclint_mtimer.h
@@ -42,6 +42,11 @@ struct aclint_mtimer_data {
 	void (*time_wr)(bool timecmp, u64 value, volatile u64 *addr);
 };
 
+struct aclint_mtimer_data *aclint_get_mtimer_data(void);
+
+void aclint_mtimer_update(struct aclint_mtimer_data *mt,
+			  struct aclint_mtimer_data *ref);
+
 void aclint_mtimer_sync(struct aclint_mtimer_data *mt);
 
 void aclint_mtimer_set_reference(struct aclint_mtimer_data *mt,
diff --git a/lib/utils/timer/aclint_mtimer.c b/lib/utils/timer/aclint_mtimer.c
index 3db3c3be2575e4ddd0180c90f254f7733b7c1daa..fd6189aaa52ad92ca28330fcf0f701ac0b8c337f 100644
--- a/lib/utils/timer/aclint_mtimer.c
+++ b/lib/utils/timer/aclint_mtimer.c
@@ -109,28 +109,42 @@ static struct sbi_timer_device mtimer = {
 	.timer_event_stop = mtimer_event_stop
 };
 
-void aclint_mtimer_sync(struct aclint_mtimer_data *mt)
+struct aclint_mtimer_data *aclint_get_mtimer_data(void)
+{
+	return mtimer_get_hart_data_ptr(sbi_scratch_thishart_ptr());
+}
+
+void aclint_mtimer_update(struct aclint_mtimer_data *mt,
+			  struct aclint_mtimer_data *ref)
 {
 	u64 v1, v2, mv, delta;
 	u64 *mt_time_val, *ref_time_val;
-	struct aclint_mtimer_data *reference;
 
-	/* Sync-up non-shared MTIME if reference is available */
-	if (mt->has_shared_mtime || !mt->time_delta_reference)
+	if (!mt || !ref || !mt->time_rd || !mt->time_wr || !ref->time_rd)
 		return;
 
-	reference = mt->time_delta_reference;
 	mt_time_val = (void *)mt->mtime_addr;
-	ref_time_val = (void *)reference->mtime_addr;
+	ref_time_val = (void *)ref->mtime_addr;
 	if (!atomic_raw_xchg_ulong(&mt->time_delta_computed, 1)) {
 		v1 = mt->time_rd(mt_time_val);
-		mv = reference->time_rd(ref_time_val);
+		mv = ref->time_rd(ref_time_val);
 		v2 = mt->time_rd(mt_time_val);
 		delta = mv - ((v1 / 2) + (v2 / 2));
 		mt->time_wr(false, mt->time_rd(mt_time_val) + delta,
 			    mt_time_val);
 	}
+}
 
+void aclint_mtimer_sync(struct aclint_mtimer_data *mt)
+{
+	struct aclint_mtimer_data *reference;
+
+	/* Sync-up non-shared MTIME if reference is available */
+	if (mt->has_shared_mtime || !mt->time_delta_reference)
+		return;
+
+	reference = mt->time_delta_reference;
+	aclint_mtimer_update(mt, reference);
 }
 
 void aclint_mtimer_set_reference(struct aclint_mtimer_data *mt,

-- 
2.34.1


-- 
opensbi mailing list
opensbi@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/opensbi

  parent reply	other threads:[~2025-10-20  6:27 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-10-20  6:34 [PATCH v7 00/12] Add SiFive TMC0 and SMC0 driver Nick Hu
2025-10-20  6:34 ` [PATCH v7 01/12] lib: utils: Add cache flush library Nick Hu
2025-10-20  6:34 ` [PATCH v7 02/12] lib: utils: Add FDT cache library Nick Hu
2025-10-20  6:34 ` [PATCH v7 03/12] utils: cache: Add SiFive ccache controller Nick Hu
2025-10-20  6:34 ` [PATCH v7 04/12] lib: utils/cache: Add fdt cmo helpers Nick Hu
2025-10-28  5:54   ` Anup Patel
2025-10-20  6:34 ` [PATCH v7 05/12] lib: sbi: Add SiFive proprietary xsfcflushdlone Nick Hu
2025-10-20  6:34 ` [PATCH v7 06/12] lib: sbi: Add SiFive proprietary xsfcease Nick Hu
2025-10-20  6:34 ` [PATCH v7 07/12] lib: utils/irqchip: Add APLIC restore function Nick Hu
2025-10-20  6:34 ` [PATCH v7 08/12] lib: sbi: Extends sbi_ipi_raw_send() to use all available IPI devices Nick Hu
2025-10-28  4:59   ` Anup Patel
2025-10-20  6:34 ` [PATCH v7 09/12] lib: utils/hsm: Add SiFive TMC0 driver Nick Hu
2025-10-28  5:00   ` Anup Patel
2025-10-20  6:34 ` Nick Hu [this message]
2025-10-20  6:34 ` [PATCH v7 11/12] lib: sbi: Add system_resume callback for restoring the system Nick Hu
2025-10-28  5:01   ` Anup Patel
2025-10-20  6:34 ` [PATCH v7 12/12] lib: utils/suspend: Add SiFive SMC0 driver Nick Hu
2025-10-28  6:02 ` [PATCH v7 00/12] Add SiFive TMC0 and " Anup Patel

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20251020-cache-upstream-v7-10-69a132447d8a@sifive.com \
    --to=nick.hu@sifive.com \
    --cc=anup@brainfault.org \
    --cc=cyan.yang@sifive.com \
    --cc=opensbi@lists.infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox