Index: sys/riscv/include/sbi.h =================================================================== --- sys/riscv/include/sbi.h +++ sys/riscv/include/sbi.h @@ -99,6 +99,15 @@ #define SBI_HSM_STATUS_START_PENDING 2 #define SBI_HSM_STATUS_STOP_PENDING 3 +/* System Reset (SRST) Extension */ +#define SBI_EXT_ID_SRST 0x53525354 +#define SBI_SRST_SYSTEM_RESET 0 +#define SBI_SRST_TYPE_SHUTDOWN 0x00000000 +#define SBI_SRST_TYPE_COLD_REBOOT 0x00000001 +#define SBI_SRST_TYPE_WARM_REBOOT 0x00000002 +#define SBI_SRST_REASON_NONE 0x00000000 +#define SBI_SRST_REASON_SYSTEM_FAILURE 0x00000001 + /* Legacy Extensions */ #define SBI_SET_TIMER 0 #define SBI_CONSOLE_PUTCHAR 1 @@ -199,6 +208,8 @@ */ int sbi_hsm_hart_status(u_long hart); +void sbi_system_reset(u_long reset_type, u_long reset_reason); + /* Legacy extension functions. */ static __inline void sbi_console_putchar(int ch) @@ -218,13 +229,6 @@ return (SBI_CALL0(SBI_CONSOLE_GETCHAR, 0).error); } -static __inline void -sbi_shutdown(void) -{ - - (void)SBI_CALL0(SBI_SHUTDOWN, 0); -} - void sbi_print_version(void); void sbi_init(void); Index: sys/riscv/riscv/sbi.c =================================================================== --- sys/riscv/riscv/sbi.c +++ sys/riscv/riscv/sbi.c @@ -49,6 +49,7 @@ static bool has_time_extension = false; static bool has_ipi_extension = false; static bool has_rfnc_extension = false; +static bool has_srst_extension = false; static struct sbi_ret sbi_get_spec_version(void) @@ -90,7 +91,24 @@ sbi_shutdown_final(void *dummy __unused, int howto) { if ((howto & RB_POWEROFF) != 0) - sbi_shutdown(); + sbi_system_reset(SBI_SRST_TYPE_SHUTDOWN, SBI_SRST_REASON_NONE); +} + +void +sbi_system_reset(u_long reset_type, u_long reset_reason) +{ + struct sbi_ret ret; + + /* Use the SRST extension, if available. */ + if (has_srst_extension) { + ret = SBI_CALL2(SBI_EXT_ID_SRST, SBI_SRST_SYSTEM_RESET, reset_type, + reset_reason); + if(ret.error != SBI_SUCCESS) { + printf("SBI System Reset Error"); + } + } else { + (void)SBI_CALL0(SBI_SHUTDOWN, 0); + } } void @@ -273,6 +291,8 @@ has_ipi_extension = true; if (sbi_probe_extension(SBI_EXT_ID_RFNC) != 0) has_rfnc_extension = true; + if (sbi_probe_extension(SBI_EXT_ID_SRST) != 0) + has_srst_extension = true; /* * Probe for legacy extensions. We still rely on many of them to be @@ -295,8 +315,8 @@ KASSERT(has_rfnc_extension || sbi_probe_extension(SBI_REMOTE_SFENCE_VMA_ASID) != 0, ("SBI doesn't implement sbi_remote_sfence_vma_asid()")); - KASSERT(sbi_probe_extension(SBI_SHUTDOWN) != 0, - ("SBI doesn't implement sbi_shutdown()")); + KASSERT(has_srst_extension || sbi_probe_extension(SBI_SHUTDOWN) != 0, + ("SBI doesn't implement sbi_shutdown() or sbi_system_reset()")); } static void Index: sys/riscv/riscv/vm_machdep.c =================================================================== --- sys/riscv/riscv/vm_machdep.c +++ sys/riscv/riscv/vm_machdep.c @@ -110,7 +110,7 @@ cpu_reset(void) { - sbi_shutdown(); + sbi_system_reset(SBI_SRST_TYPE_COLD_REBOOT, SBI_SRST_REASON_NONE); while(1); }