From e149b8d50335b647f3c9138551f3f3064b931a1f Mon Sep 17 00:00:00 2001 From: Quantum Date: Wed, 26 Jan 2022 18:31:40 -0500 Subject: [PATCH] OpenSBI: Added SRST(System Reset) extension --- kernel/drivers/opensbi/extensions/srst.cpp | 28 ++++++++++++++++++ .../opensbi/include/opensbi/extensions/srst.h | 29 +++++++++++++++++++ kernel/drivers/opensbi/meson.build | 3 +- 3 files changed, 59 insertions(+), 1 deletion(-) create mode 100644 kernel/drivers/opensbi/extensions/srst.cpp create mode 100644 kernel/drivers/opensbi/include/opensbi/extensions/srst.h diff --git a/kernel/drivers/opensbi/extensions/srst.cpp b/kernel/drivers/opensbi/extensions/srst.cpp new file mode 100644 index 0000000..24970e4 --- /dev/null +++ b/kernel/drivers/opensbi/extensions/srst.cpp @@ -0,0 +1,28 @@ +#include "opensbi/extensions/srst.h" + +namespace drivers { +namespace opensbi::srst { + + namespace { + enum class ExtensionId { + SRST = 0x53525354 + }; + + enum class FunctionId { + SYSTEM_RESET + }; + } + + SbiRet system_reset( + ResetType reset_type, + ResetReason reset_reason) { + return ecall( + static_cast(ExtensionId::SRST), + static_cast(FunctionId::SYSTEM_RESET), + static_cast(reset_type), + static_cast(reset_reason)); + } + +} // End namespace opensbi::srst +} // End namespace drivers + diff --git a/kernel/drivers/opensbi/include/opensbi/extensions/srst.h b/kernel/drivers/opensbi/include/opensbi/extensions/srst.h new file mode 100644 index 0000000..4ca9473 --- /dev/null +++ b/kernel/drivers/opensbi/include/opensbi/extensions/srst.h @@ -0,0 +1,29 @@ +#pragma once + +#include "opensbi/opensbi.h" + +namespace drivers { +namespace opensbi::srst { + + enum class ResetType : uint32_t { + SHUTDOWN, + COLD_REBOOT, + WARM_REBOOT + // 0x00000003 - 0xEFFFFFFF: Reserved + // 0xF0000000 - 0xFFFFFFFF: Vendor specific + }; + + enum class ResetReason : uint32_t { + NO_REASON, + SYSTEM_FAILURE + // 0x00000002 - 0xDFFFFFFF: Reserved + // 0xE0000000 - 0xEFFFFFFF: SBI implimentation specific + // 0xF0000000 - 0xFFFFFFFF: Vendor or platform specific + }; + + SbiRet system_reset( + ResetType reset_type, + ResetReason reset_reason); + +} // End namespace opensbi::srst +} // End namespace drivers diff --git a/kernel/drivers/opensbi/meson.build b/kernel/drivers/opensbi/meson.build index 9156f91..fcb45e3 100644 --- a/kernel/drivers/opensbi/meson.build +++ b/kernel/drivers/opensbi/meson.build @@ -6,7 +6,8 @@ kernel_sources += [ 'extensions/timer.cpp', 'extensions/ipi.cpp', 'extensions/rfence.cpp', - 'extensions/hsm.cpp' + 'extensions/hsm.cpp', + 'extensions/srst.cpp' ), ]