Skip to content

Commit c352b04

Browse files
yf13anchao
authored andcommitted
risc-v/sbi: add SRST extenstion usage in S-mode
This adds SBI specfication v0.3 based `riscv_sbi_system_reset()` to support SBI firmware based system reset in kernel mode. Signed-off-by: Yanfeng Liu <[email protected]>
1 parent 908814a commit c352b04

File tree

3 files changed

+26
-2
lines changed

3 files changed

+26
-2
lines changed

arch/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ config ARCH_RISCV
9292
select ARCH_HAVE_RDWR_MEM_CPU_RUN
9393
select ARCH_HAVE_TCBINFO
9494
select ARCH_HAVE_THREAD_LOCAL
95+
select ARCH_HAVE_POWEROFF
9596
select ARCH_HAVE_LAZYFPU if ARCH_HAVE_FPU
9697
---help---
9798
RISC-V 32 and 64-bit RV32 / RV64 architectures.

arch/risc-v/src/common/riscv_internal.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,7 @@
173173
#define SBI_EXT_HSM 0x48534D
174174
#define SBI_EXT_IPI 0x735049
175175
#define SBI_EXT_TIME 0x54494D45
176+
#define SBI_EXT_SRST 0x53525354
176177

177178
/* SBI function IDs for TIME extension */
178179

@@ -186,6 +187,21 @@
186187

187188
#define SBI_EXT_IPI_SEND_IPI 0x0
188189

190+
/* SBI function IDs for SRST extension */
191+
192+
#define SBI_EXT_SRST_SYS_RESET 0x0
193+
194+
/* SBI system reset type */
195+
196+
#define SBI_SRST_TYPE_SHUTDOWN 0
197+
#define SBI_SRST_TYPE_REBOOT_COLD 1
198+
#define SBI_SRST_TYPE_REBOOT_WARM 1
199+
200+
/* SBI system reset reason */
201+
202+
#define SBI_SRST_REASON_NONE 0
203+
#define SBI_SRST_REASON_FAILURE 1
204+
189205
/****************************************************************************
190206
* Public Types
191207
****************************************************************************/
@@ -335,6 +351,7 @@ void riscv_sbi_set_timer(uint64_t stime_value);
335351
uint64_t riscv_sbi_get_time(void);
336352
uintptr_t riscv_sbi_boot_secondary(uint32_t hartid, uintptr_t addr,
337353
uintptr_t a1);
354+
uintptr_t riscv_sbi_system_reset(uint32_t type, uint32_t reason);
338355
#endif
339356

340357
/* Power management *********************************************************/

arch/risc-v/src/common/supervisor/riscv_sbi.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,14 +128,20 @@ uint64_t riscv_sbi_get_time(void)
128128
uintptr_t riscv_sbi_send_ipi(uint32_t hmask, uintptr_t hbase)
129129
{
130130
return sbi_ecall(SBI_EXT_IPI, SBI_EXT_IPI_SEND_IPI,
131-
hmask, hbase, 0, 0, 0, 0);
131+
hmask, hbase, 0, 0, 0, 0);
132132
}
133133

134134
#ifndef CONFIG_NUTTSBI
135+
uintptr_t riscv_sbi_system_reset(uint32_t type, uint32_t reason)
136+
{
137+
return sbi_ecall(SBI_EXT_SRST, SBI_EXT_SRST_SYS_RESET,
138+
type, reason, 0, 0, 0, 0);
139+
}
140+
135141
uintptr_t riscv_sbi_boot_secondary(uint32_t hartid, uintptr_t addr,
136142
uintptr_t a1)
137143
{
138144
return sbi_ecall(SBI_EXT_HSM, SBI_EXT_HSM_HART_START,
139-
hartid, addr, a1, 0, 0, 0);
145+
hartid, addr, a1, 0, 0, 0);
140146
}
141147
#endif /* CONFIG_NUTTSBI */

0 commit comments

Comments
 (0)