OpenSBI Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Ben Zong-You Xie <ben717@andestech.com>
To: <opensbi@lists.infradead.org>
Subject: [PATCH 3/7] platform: generic/andes: pair non-retentive CSR save/restore with a flag
Date: Tue, 28 Jul 2026 16:10:37 +0800	[thread overview]
Message-ID: <20260728081041.2724668-4-ben717@andestech.com> (raw)
In-Reply-To: <20260728081041.2724668-1-ben717@andestech.com>

The restore was gated on sbi_init_count() and the current sleep type,
which is only a proxy for "did this hart actually save its CSRs". Track
it explicitly instead, so restore is self-guarding and the call site
needs no conditions.

Signed-off-by: Ben Zong-You Xie <ben717@andestech.com>
---
 platform/generic/andes/ae350.c         | 18 ++++++++++++------
 platform/generic/include/andes/andes.h |  3 +++
 2 files changed, 15 insertions(+), 6 deletions(-)

diff --git a/platform/generic/andes/ae350.c b/platform/generic/andes/ae350.c
index 4cf7e26def54..4a053f434272 100644
--- a/platform/generic/andes/ae350.c
+++ b/platform/generic/andes/ae350.c
@@ -34,6 +34,8 @@ void ae350_non_ret_save(struct sbi_scratch *scratch)
 	andes_hdata->pmacfg2 = csr_read_num(CSR_PMACFG0 + 2);
 	for (int i = 0; i < 16; i++)
 		andes_hdata->pmaaddrX[i] = csr_read_num(CSR_PMAADDR0 + i);
+
+	andes_hdata->saved = true;
 }
 
 void ae350_non_ret_restore(struct sbi_scratch *scratch)
@@ -41,6 +43,9 @@ void ae350_non_ret_restore(struct sbi_scratch *scratch)
 	struct andes_hart_data *andes_hdata = sbi_scratch_offset_ptr(scratch,
 								     andes_hart_data_offset);
 
+	if (!andes_hdata->saved)
+		return;
+
 	csr_write(CSR_MCACHE_CTL, andes_hdata->mcache_ctl);
 	csr_write(CSR_MMISC_CTL, andes_hdata->mmisc_ctl);
 	csr_write(CSR_MPFT_CTL, andes_hdata->mpft_ctl);
@@ -52,6 +57,8 @@ void ae350_non_ret_restore(struct sbi_scratch *scratch)
 	csr_write_num(CSR_PMACFG0 + 2, andes_hdata->pmacfg2);
 	for (int i = 0; i < 16; i++)
 		csr_write_num(CSR_PMAADDR0 + i, andes_hdata->pmaaddrX[i]);
+
+	andes_hdata->saved = false;
 }
 
 void ae350_enable_coherency_warmboot(void)
@@ -62,18 +69,17 @@ void ae350_enable_coherency_warmboot(void)
 
 static int ae350_early_init(bool cold_boot)
 {
-	u32 hartid = current_hartid();
-	u32 sleep_type = atcsmu_get_sleep_type(hartid);
-
 	if (cold_boot) {
 		andes_hart_data_offset = sbi_scratch_alloc_offset(sizeof(struct andes_hart_data));
 		if (!andes_hart_data_offset)
 			return SBI_ENOMEM;
 	}
 
-	/* Don't restore Andes CSRs during boot or wake up from light sleep */
-	if (sbi_init_count(current_hartindex()) && sleep_type == SBI_SUSP_SLEEP_TYPE_SUSPEND)
-		ae350_non_ret_restore(sbi_scratch_thishart_ptr());
+	/*
+	 * This is a no-op unless this hart actually saved them, so it is safe
+	 * to call on every path.
+	 */
+	ae350_non_ret_restore(sbi_scratch_thishart_ptr());
 
 	return generic_early_init(cold_boot);
 }
diff --git a/platform/generic/include/andes/andes.h b/platform/generic/include/andes/andes.h
index dd2451718d00..dae112ce741f 100644
--- a/platform/generic/include/andes/andes.h
+++ b/platform/generic/include/andes/andes.h
@@ -96,6 +96,9 @@ struct andes_hart_data {
 	unsigned long pmacfg0;
 	unsigned long pmacfg2;
 	unsigned long pmaaddrX[16];
+
+	/* Set when the CSRs above hold a saved copy awaiting restore */
+	bool saved;
 };
 
 void ae350_non_ret_save(struct sbi_scratch *scratch);
-- 
2.34.1


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

  parent reply	other threads:[~2026-07-28  8:11 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-28  8:10 [PATCH 0/7] Fix and improve the Andes ATCSMU and LLC drivers Ben Zong-You Xie
2026-07-28  8:10 ` [PATCH 1/7] lib: utils/cache: fix andes_llcache_enable() return value Ben Zong-You Xie
2026-07-28  8:10 ` [PATCH 2/7] lib: utils/andes: add the SMU and LLC registers to the root domain Ben Zong-You Xie
2026-07-28  8:10 ` Ben Zong-You Xie [this message]
2026-07-28  8:10 ` [PATCH 4/7] lib: utils/suspend: restore Andes CSRs on system-suspend resume Ben Zong-You Xie
2026-07-28  8:10 ` [PATCH 5/7] lib: utils/hsm: wake sleeping Andes harts with an IPI Ben Zong-You Xie
2026-07-28  8:10 ` [PATCH 6/7] lib: utils/suspend: wait for the secondary Andes harts to sleep Ben Zong-You Xie
2026-07-28  8:10 ` [PATCH 7/7] lib: utils/andes: arm the SMU sleep command last Ben Zong-You Xie

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=20260728081041.2724668-4-ben717@andestech.com \
    --to=ben717@andestech.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