From 8547813b6ddc364a7febe2523e47f46eeb4b3b0d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B6nke=20Holz?= Date: Thu, 4 Jan 2024 19:00:14 +0100 Subject: [PATCH] Kernel/riscv64: Implement arch_specific_{reboot,shutdown} using the SBI We first try to use the newer "SRST" extension for rebooting and shutting down and if that fails, we try to shutdown using the legacy "System Shutdown" extension (which can't reboot, so we always shutdown). The kernel will halt, if we return from here due to all attempts at rebooting / shutting down failing. --- Kernel/Arch/riscv64/PowerState.cpp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/Kernel/Arch/riscv64/PowerState.cpp b/Kernel/Arch/riscv64/PowerState.cpp index 153a9367a1..e7c339cc1f 100644 --- a/Kernel/Arch/riscv64/PowerState.cpp +++ b/Kernel/Arch/riscv64/PowerState.cpp @@ -5,17 +5,24 @@ */ #include +#include namespace Kernel { void arch_specific_reboot() { - TODO_RISCV64(); + auto ret = SBI::SystemReset::system_reset(SBI::SystemReset::ResetType::ColdReboot, SBI::SystemReset::ResetReason::NoReason); + dbgln("SBI: Failed to reboot: {}", ret); + dbgln("SBI: Attempting to shut down using the legacy extension..."); + SBI::Legacy::shutdown(); } void arch_specific_poweroff() { - TODO_RISCV64(); + auto ret = SBI::SystemReset::system_reset(SBI::SystemReset::ResetType::Shutdown, SBI::SystemReset::ResetReason::NoReason); + dbgln("SBI: Failed to shut down: {}", ret); + dbgln("SBI: Attempting to shut down using the legacy extension..."); + SBI::Legacy::shutdown(); } }