[PATCH] riscv: pass system-failure to restart SBI call on emergency restart

Jimmy Ho <[email protected]>
Newsgroups org.infradead.lists.linux-riscv,org.kernel.vger.linux-kernel
Message-ID <[email protected]>
Let the restart SBI call pass the restart reason as system-failure
when an emergency restart occurs.

Signed-off-by: Jimmy Ho <[email protected]>
---
 arch/riscv/include/asm/emergency-restart.h | 13 +++++++++++++
 arch/riscv/include/asm/sbi.h               |  2 ++
 arch/riscv/kernel/sbi.c                    |  8 +++++++-
 3 files changed, 22 insertions(+), 1 deletion(-)
 create mode 100644 arch/riscv/include/asm/emergency-restart.h

diff --git a/arch/riscv/include/asm/emergency-restart.h b/arch/riscv/include/asm/emergency-restart.h
new file mode 100644
index 000000000000..14c8da0f7ea2
--- /dev/null
+++ b/arch/riscv/include/asm/emergency-restart.h
@@ -0,0 +1,13 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+
+#ifndef _ASM_RISCV_EMERGENCY_RESTART_H
+#define _ASM_RISCV_EMERGENCY_RESTART_H
+
+#include <asm/sbi.h>
+
+static inline void machine_emergency_restart(void)
+{
+	machine_restart(RISCV_EMERGENCY_RESTART_REASON);
+}
+
+#endif /* _ASM_RISCV_EMERGENCY_RESTART_H */
diff --git a/arch/riscv/include/asm/sbi.h b/arch/riscv/include/asm/sbi.h
index 5725e0ca4dda..c8dceefa677d 100644
--- a/arch/riscv/include/asm/sbi.h
+++ b/arch/riscv/include/asm/sbi.h
@@ -121,6 +121,8 @@ enum sbi_srst_reset_reason {
 	SBI_SRST_RESET_REASON_SYS_FAILURE,
 };
 
+#define RISCV_EMERGENCY_RESTART_REASON "system-failure"
+
 enum sbi_ext_susp_fid {
 	SBI_EXT_SUSP_SYSTEM_SUSPEND = 0,
 };
diff --git a/arch/riscv/kernel/sbi.c b/arch/riscv/kernel/sbi.c
index c443337056ab..dae147420f1a 100644
--- a/arch/riscv/kernel/sbi.c
+++ b/arch/riscv/kernel/sbi.c
@@ -10,6 +10,7 @@
 #include <linux/mm.h>
 #include <linux/pm.h>
 #include <linux/reboot.h>
+#include <linux/string.h>
 #include <asm/sbi.h>
 #include <asm/smp.h>
 #include <asm/tlbflush.h>
@@ -519,10 +520,15 @@ static void sbi_srst_reset(unsigned long type, unsigned long reason)
 static int sbi_srst_reboot(struct notifier_block *this,
 			   unsigned long mode, void *cmd)
 {
+	unsigned long reason = SBI_SRST_RESET_REASON_NONE;
+
+	if (cmd && !strcmp(cmd, RISCV_EMERGENCY_RESTART_REASON))
+		reason = SBI_SRST_RESET_REASON_SYS_FAILURE;
+
 	sbi_srst_reset((mode == REBOOT_WARM || mode == REBOOT_SOFT) ?
 		       SBI_SRST_RESET_TYPE_WARM_REBOOT :
 		       SBI_SRST_RESET_TYPE_COLD_REBOOT,
-		       SBI_SRST_RESET_REASON_NONE);
+		       reason);
 	return NOTIFY_DONE;
 }
 
-- 
2.43.7


_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.