From: Nick Hu <nick.hu@sifive.com>
To: opensbi@lists.infradead.org
Cc: Anup Patel <anup@brainfault.org>, Nick Hu <nick.hu@sifive.com>
Subject: [PATCH v7 11/12] lib: sbi: Add system_resume callback for restoring the system
Date: Mon, 20 Oct 2025 14:34:13 +0800 [thread overview]
Message-ID: <20251020-cache-upstream-v7-11-69a132447d8a@sifive.com> (raw)
In-Reply-To: <20251020-cache-upstream-v7-0-69a132447d8a@sifive.com>
The last core who performs the system suspend is responsible for
restoring the system after waking up. Add the system_resume callback for
restoring the system from suspend.
Suggested-by: Anup Patel <anup@brainfault.org>
Signed-off-by: Nick Hu <nick.hu@sifive.com>
---
include/sbi/sbi_system.h | 7 +++++++
lib/sbi/sbi_hsm.c | 5 ++++-
lib/sbi/sbi_system.c | 17 +++++++++++++++++
3 files changed, 28 insertions(+), 1 deletion(-)
diff --git a/include/sbi/sbi_system.h b/include/sbi/sbi_system.h
index 0fdcc98cce5dac43583e68ffa8c98e79fd95dad4..f48a019a06b6957b5ab9cb4b9ef795a899a34ff9 100644
--- a/include/sbi/sbi_system.h
+++ b/include/sbi/sbi_system.h
@@ -69,11 +69,18 @@ struct sbi_system_suspend_device {
* return from system_suspend() may ignore this parameter.
*/
int (*system_suspend)(u32 sleep_type, unsigned long mmode_resume_addr);
+
+ /**
+ * Resume the system from system suspend
+ */
+ void (*system_resume)(void);
};
const struct sbi_system_suspend_device *sbi_system_suspend_get_device(void);
void sbi_system_suspend_set_device(struct sbi_system_suspend_device *dev);
void sbi_system_suspend_test_enable(void);
+void sbi_system_resume(void);
+bool sbi_system_is_suspended(void);
bool sbi_system_suspend_supported(u32 sleep_type);
int sbi_system_suspend(u32 sleep_type, ulong resume_addr, ulong opaque);
diff --git a/lib/sbi/sbi_hsm.c b/lib/sbi/sbi_hsm.c
index 0d97b43e0cd8f7b4fc97407ef01007485e3f5a24..0a355f9c2372075aaf303cba2aa5683993c4c079 100644
--- a/lib/sbi/sbi_hsm.c
+++ b/lib/sbi/sbi_hsm.c
@@ -455,7 +455,10 @@ void sbi_hsm_hart_resume_start(struct sbi_scratch *scratch)
SBI_HSM_STATE_RESUME_PENDING))
sbi_hart_hang();
- hsm_device_hart_resume();
+ if (sbi_system_is_suspended())
+ sbi_system_resume();
+ else
+ hsm_device_hart_resume();
}
void __noreturn sbi_hsm_hart_resume_finish(struct sbi_scratch *scratch,
diff --git a/lib/sbi/sbi_system.c b/lib/sbi/sbi_system.c
index cd0f4ba42bbe67e606bc821870716f7342eaf0d2..5500b05d22882bd43d84a1b715529cd8a26bee3f 100644
--- a/lib/sbi/sbi_system.c
+++ b/lib/sbi/sbi_system.c
@@ -87,6 +87,7 @@ void __noreturn sbi_system_reset(u32 reset_type, u32 reset_reason)
}
static const struct sbi_system_suspend_device *suspend_dev = NULL;
+static bool system_suspended;
const struct sbi_system_suspend_device *sbi_system_suspend_get_device(void)
{
@@ -137,6 +138,19 @@ bool sbi_system_suspend_supported(u32 sleep_type)
suspend_dev->system_suspend_check(sleep_type) == 0;
}
+bool sbi_system_is_suspended(void)
+{
+ return system_suspended;
+}
+
+void sbi_system_resume(void)
+{
+ if (suspend_dev && suspend_dev->system_resume)
+ suspend_dev->system_resume();
+
+ system_suspended = false;
+}
+
int sbi_system_suspend(u32 sleep_type, ulong resume_addr, ulong opaque)
{
struct sbi_domain *dom = sbi_domain_thishart_ptr();
@@ -189,11 +203,14 @@ int sbi_system_suspend(u32 sleep_type, ulong resume_addr, ulong opaque)
__sbi_hsm_suspend_non_ret_save(scratch);
/* Suspend */
+ system_suspended = true;
ret = suspend_dev->system_suspend(sleep_type, scratch->warmboot_addr);
if (ret != SBI_OK) {
if (!sbi_hsm_hart_change_state(scratch, SBI_HSM_STATE_SUSPENDED,
SBI_HSM_STATE_STARTED))
sbi_hart_hang();
+
+ system_suspended = false;
return ret;
}
--
2.34.1
--
opensbi mailing list
opensbi@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/opensbi
next prev 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 ` [PATCH v7 10/12] lib: utils/timer: Expose timer update function Nick Hu
2025-10-20 6:34 ` Nick Hu [this message]
2025-10-28 5:01 ` [PATCH v7 11/12] lib: sbi: Add system_resume callback for restoring the system 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-11-69a132447d8a@sifive.com \
--to=nick.hu@sifive.com \
--cc=anup@brainfault.org \
--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