From b08ac4817cba7c49be3d9aca8b9afad5da8106d4 Mon Sep 17 00:00:00 2001 From: Quantum Date: Sun, 23 Jan 2022 22:40:21 -0500 Subject: [PATCH] OpenSBI: Added base extension General notes: For now im just going to leave all the responses as SbiRet but once I decide how I want to handle returning errors I would like to return more useful values. In the cpp file I define a enum class "ExtensionId" with only one member. For now the thought is that its descriptive and is consistent with how the legacy extension is written. I'll also do the same thing with FunctionId in the legacy extension after this commit for consistency. --- kernel/drivers/opensbi/extensions/base.cpp | 67 +++++++++++++++++++ .../opensbi/include/opensbi/extensions/base.h | 32 +++++++++ 2 files changed, 99 insertions(+) create mode 100644 kernel/drivers/opensbi/extensions/base.cpp create mode 100644 kernel/drivers/opensbi/include/opensbi/extensions/base.h diff --git a/kernel/drivers/opensbi/extensions/base.cpp b/kernel/drivers/opensbi/extensions/base.cpp new file mode 100644 index 0000000..273984a --- /dev/null +++ b/kernel/drivers/opensbi/extensions/base.cpp @@ -0,0 +1,67 @@ +#include "opensbi/extensions/base.h" + +namespace drivers { +namespace opensbi::base { + + namespace { + enum class ExtensionId { + BASE = 0x10 + }; + + enum class FunctionId { + GET_SPEC_VERSION, + GET_IMPL_ID, + GET_IMPL_VERSION, + PROBE_EXTENSION, + GET_MVENDORID, + GET_MARCHID, + GET_MIMPID + }; + } + + SbiRet get_spec_version() { + return ecall( + static_cast(ExtensionId::BASE), + static_cast(FunctionId::GET_SPEC_VERSION)); + } + + SbiRet get_impl_id() { + return ecall( + static_cast(ExtensionId::BASE), + static_cast(FunctionId::GET_IMPL_ID)); + } + + SbiRet get_impl_version() { + return ecall( + static_cast(ExtensionId::BASE), + static_cast(FunctionId::GET_IMPL_VERSION)); + } + + SbiRet probe_extension(long extension_id) { + return ecall( + static_cast(ExtensionId::BASE), + static_cast(FunctionId::PROBE_EXTENSION), + extension_id); + } + + SbiRet get_mvendor_id() { + return ecall( + static_cast(ExtensionId::BASE), + static_cast(FunctionId::GET_MVENDORID)); + } + + SbiRet get_march_id() { + return ecall( + static_cast(ExtensionId::BASE), + static_cast(FunctionId::GET_MARCHID)); + } + + SbiRet get_mimp_id() { + return ecall( + static_cast(ExtensionId::BASE), + static_cast(FunctionId::GET_MIMPID)); + } + +} // End namespace opensbi::base +} // End namespace drivers + diff --git a/kernel/drivers/opensbi/include/opensbi/extensions/base.h b/kernel/drivers/opensbi/include/opensbi/extensions/base.h new file mode 100644 index 0000000..2e4fd2b --- /dev/null +++ b/kernel/drivers/opensbi/include/opensbi/extensions/base.h @@ -0,0 +1,32 @@ +#pragma once + +#include "opensbi/opensbi.h" + +namespace drivers { +namespace opensbi::base { + + enum class ImplId { + BBL, + OPENSBI, + XVISOR, + KVM, + RUSTSBI, + DIOSIX + }; + + SbiRet get_spec_version(); + + SbiRet get_impl_id(); + + SbiRet get_impl_version(); + + SbiRet probe_extension(long extension_id); + + SbiRet get_mvendor_id(); + + SbiRet get_march_id(); + + SbiRet get_mimp_id(); + +} // End namespace opensbi::base +} // End namespace drivers