From 03fcf4dbb27736e5a2d05b550bc34366b9047ada Mon Sep 17 00:00:00 2001 From: Quantum Date: Wed, 26 Jan 2022 18:16:29 -0500 Subject: [PATCH] OpenSBI: Added HSM(Hart State Management) extension --- kernel/drivers/opensbi/extensions/hsm.cpp | 58 +++++++++++++++++++ .../opensbi/include/opensbi/extensions/hsm.h | 32 ++++++++++ kernel/drivers/opensbi/meson.build | 3 +- 3 files changed, 92 insertions(+), 1 deletion(-) create mode 100644 kernel/drivers/opensbi/extensions/hsm.cpp create mode 100644 kernel/drivers/opensbi/include/opensbi/extensions/hsm.h diff --git a/kernel/drivers/opensbi/extensions/hsm.cpp b/kernel/drivers/opensbi/extensions/hsm.cpp new file mode 100644 index 0000000..d0f7d2d --- /dev/null +++ b/kernel/drivers/opensbi/extensions/hsm.cpp @@ -0,0 +1,58 @@ +#include "opensbi/extensions/hsm.h" + +namespace drivers { +namespace opensbi::hsm { + + namespace { + enum class ExtensionId { + HSM = 0x48534D + }; + + enum class FunctionId { + HART_START, + HART_STOP, + HART_GET_STATUS, + HART_SUSPEND + }; + } + + SbiRet set_hsm( + unsigned long hartid, + unsigned long start_addr, + unsigned long opaque) { + return ecall( + static_cast(ExtensionId::HSM), + static_cast(FunctionId::HART_START), + hartid, + start_addr, + opaque); + } + + SbiRet hart_stop() { + return ecall( + static_cast(ExtensionId::HSM), + static_cast(FunctionId::HART_STOP)); + } + + SbiRet hart_get_status(unsigned long hartid) { + return ecall( + static_cast(ExtensionId::HSM), + static_cast(FunctionId::HART_GET_STATUS), + hartid); + } + + SbiRet hart_suspend( + SuspendType suspend_type, + unsigned long resume_addr, + unsigned long opaque) { + return ecall( + static_cast(ExtensionId::HSM), + static_cast(FunctionId::HART_SUSPEND), + static_cast(suspend_type), + resume_addr, + opaque); + } + +} // End namespace opensbi::hsm +} // End namespace drivers + diff --git a/kernel/drivers/opensbi/include/opensbi/extensions/hsm.h b/kernel/drivers/opensbi/include/opensbi/extensions/hsm.h new file mode 100644 index 0000000..bcf2918 --- /dev/null +++ b/kernel/drivers/opensbi/include/opensbi/extensions/hsm.h @@ -0,0 +1,32 @@ +#pragma once + +#include "opensbi/opensbi.h" + +namespace drivers { +namespace opensbi::hsm { + + enum class SuspendType : uint32_t { + RETENTIVE = 0, + // 0x00000001 - 0x0FFFFFFF: Reserved + // 0x10000000 - 0x7FFFFFFF: Platform specific retentive + NON_RETENTIVE = 0x80000000 + // 0x80000001 - 0x8FFFFFFF: Reserved + // 0x90000000 - 0xFFFFFFFF: Platform specific non-retentive + }; + + SbiRet hart_start( + unsigned long hartid, + unsigned long start_addr, + unsigned long opaque); + + SbiRet hart_stop(); + + SbiRet hart_get_status(unsigned long hartid); + + SbiRet hart_suspend( + SuspendType suspend_type, + unsigned long resume_addr, + unsigned long opaque); + +} // End namespace opensbi::hsm +} // End namespace drivers diff --git a/kernel/drivers/opensbi/meson.build b/kernel/drivers/opensbi/meson.build index c01bed1..9156f91 100644 --- a/kernel/drivers/opensbi/meson.build +++ b/kernel/drivers/opensbi/meson.build @@ -5,7 +5,8 @@ kernel_sources += [ 'extensions/base.cpp', 'extensions/timer.cpp', 'extensions/ipi.cpp', - 'extensions/rfence.cpp' + 'extensions/rfence.cpp', + 'extensions/hsm.cpp' ), ]