diff options
author | Mark Kettenis <kettenis@cvs.openbsd.org> | 2024-03-29 22:11:35 +0000 |
---|---|---|
committer | Mark Kettenis <kettenis@cvs.openbsd.org> | 2024-03-29 22:11:35 +0000 |
commit | b7b936634542dcea66098975f40e1216952e50dd (patch) | |
tree | 8aa90770d0a5a5568d6516b572d1bd9b89bb4741 /sys/arch/riscv64 | |
parent | fe0ec10ac77ff60ed7f1e5500e6ca94b8c48ca0b (diff) |
Use SBI calls to reboot or power down the machine when the firmware
supports them.
ok jca@
Diffstat (limited to 'sys/arch/riscv64')
-rw-r--r-- | sys/arch/riscv64/include/sbi.h | 9 | ||||
-rw-r--r-- | sys/arch/riscv64/riscv64/sbi.c | 28 |
2 files changed, 35 insertions, 2 deletions
diff --git a/sys/arch/riscv64/include/sbi.h b/sys/arch/riscv64/include/sbi.h index 802ae7f68a0..e5117ed752a 100644 --- a/sys/arch/riscv64/include/sbi.h +++ b/sys/arch/riscv64/include/sbi.h @@ -1,4 +1,4 @@ -/* $OpenBSD: sbi.h,v 1.5 2022/08/29 02:01:18 jsg Exp $ */ +/* $OpenBSD: sbi.h,v 1.6 2024/03/29 22:11:34 kettenis Exp $ */ /*- * Copyright (c) 2016-2017 Ruslan Bukin <br@bsdpad.com> @@ -76,6 +76,13 @@ #define SBI_HSM_STATUS_START_PENDING 2 #define SBI_HSM_STATUS_STOP_PENDING 3 +/* System Reset Extension */ +#define SBI_EXT_ID_SRST 0x53525354 +#define SBI_SRST_RESET 0 +#define SBI_SRST_RESET_SHUTDOWN 0 +#define SBI_SRST_RESET_COLD_REBOOT 1 +#define SBI_SRST_RESET_WARM_REBOOT 2 + /* Legacy Extensions */ #define SBI_SET_TIMER 0 #define SBI_CONSOLE_PUTCHAR 1 diff --git a/sys/arch/riscv64/riscv64/sbi.c b/sys/arch/riscv64/riscv64/sbi.c index 57b90aad434..b7c86900695 100644 --- a/sys/arch/riscv64/riscv64/sbi.c +++ b/sys/arch/riscv64/riscv64/sbi.c @@ -1,4 +1,4 @@ -/* $OpenBSD: sbi.c,v 1.7 2022/12/06 00:11:23 jca Exp $ */ +/* $OpenBSD: sbi.c,v 1.8 2024/03/29 22:11:34 kettenis Exp $ */ /*- * SPDX-License-Identifier: BSD-2-Clause-FreeBSD @@ -35,6 +35,9 @@ #include <dev/cons.h> +extern void (*cpuresetfn)(void); +extern void (*powerdownfn)(void); + /* SBI Implementation-Specific Definitions */ #define OPENSBI_VERSION_MAJOR_OFFSET 16 #define OPENSBI_VERSION_MINOR_MASK 0xFFFF @@ -125,6 +128,20 @@ sbi_hsm_hart_status(u_long hart) #endif void +sbi_reset(void) +{ + SBI_CALL2(SBI_EXT_ID_SRST, SBI_SRST_RESET, + SBI_SRST_RESET_WARM_REBOOT, 0); +} + +void +sbi_powerdown(void) +{ + SBI_CALL2(SBI_EXT_ID_SRST, SBI_SRST_RESET, + SBI_SRST_RESET_SHUTDOWN, 0); +} + +void sbi_init(void) { struct sbi_ret sret; @@ -167,6 +184,15 @@ sbi_init(void) "SBI doesn't implement sbi_remote_sfence_vma_asid()"); KASSERTMSG(sbi_probe_extension(SBI_SHUTDOWN) != 0, "SBI doesn't implement sbi_shutdown()"); + + /* + * Implement reboot and power down if the System Reset + * Extension is implemented. + */ + if (sbi_probe_extension(SBI_EXT_ID_SRST) != 0) { + cpuresetfn = sbi_reset; + powerdownfn = sbi_powerdown; + } } /* |