Browse Source

rt: add SBI firmware features extension support (#110)

* rt: add SBI firmware features extension support

This commit implements the SBI Firmware Features Extension (EID #0x46574654 FWFT),
as defined in the RISC-V SBI Specification chapter 18.

The extension provides two main functions:
- fwft_set: Sets the value of a specific firmware feature.
- fwft_get: Retrieves the value of a specific firmware feature.

Signed-off-by: joeschmo456 <[email protected]>
Xiangbo Zhang 1 month ago
parent
commit
3cc1e7fc2c
3 changed files with 61 additions and 0 deletions
  1. 1 0
      library/sbi-rt/CHANGELOG.md
  2. 57 0
      library/sbi-rt/src/fwft.rs
  3. 3 0
      library/sbi-rt/src/lib.rs

+ 1 - 0
library/sbi-rt/CHANGELOG.md

@@ -12,6 +12,7 @@ to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
 - pmu: add missing `pmu_snapshot_set_shmem` function.
 - pmu: `pmu_snapshot_set_shmem` function signature, documents and implementation
 - lib: re-export `sbi_spec::base::CounterMask` on crate root.
+- rt: add FWFT extension support to SBI implementation.
 
 ### Modified
 

+ 57 - 0
library/sbi-rt/src/fwft.rs

@@ -0,0 +1,57 @@
+//! Chapter 18. SBI Firmware Features Extension (EID #0x46574654 "FWFT").
+
+use crate::binary::{sbi_call_1, sbi_call_3};
+use sbi_spec::{
+    binary::SbiRet,
+    fwft::{EID_FWFT, GET, SET},
+};
+
+/// Set the configuration value of a specific firmware feature.
+///
+/// # Parameters
+///
+/// - `feature`: The identifier of the feature to set.
+/// - `value`: The value to set for the feature.
+/// - `flags`: Flags to modify the behavior of the set operation.
+///
+/// # Return value
+///
+/// A successful return results in the requested firmware feature to be set according to the `value` and `flags` parameters. In case of failure, `feature` value is not modified and the possible error codes returned in `SbiRet.error` are shown in the table below:
+///
+/// | Error code                  | Description
+/// |:----------------------------|:---------------------------------
+/// | `SbiRet::success()`         | `feature` was set successfully.
+/// | `SbiRet::not_supported()`   | `feature` is not reserved and valid, but the platform does not support it due to one or more missing dependencies (Hardware or SBI implementation).
+/// | `SbiRet::invalid_param()`   | Provided `value` or `flags` parameter is invalid.
+/// | `SbiRet::denied()`          | `feature` set operation failed because either it was denied by the SBI implementation, or`feature` is reserved or is platform-specific and unimplemented.
+/// | `SbiRet::denied_locked()`   | `feature` set operation failed because the `feature` is locked.
+/// | `SbiRet::failed()`          | The set operation failed for unspecified or unknown other reasons.
+///
+/// This function is defined in RISC-V SBI Specification chapter 18.1.
+#[inline]
+pub fn fwft_set(feature: u32, value: usize, flags: usize) -> SbiRet {
+    sbi_call_3(EID_FWFT, SET, feature as _, value, flags)
+}
+
+/// Get the configuration value of a specific firmware feature.
+///
+/// # Parameters
+///
+/// - `feature`: The identifier of the feature to get.
+///
+/// # Return value
+///
+/// A successful return results in the firmware feature configuration value to be returned in `SbiRet.value`. In case of failure, the content of `SbiRet.value` is zero and the possible error codes returned in `SbiRet.error` are shown in the table below:
+///
+/// | Error code                  | Description
+/// |:----------------------------|:---------------------------------
+/// | `SbiRet::success()`         | Feature status was retrieved successfully.
+/// | `SbiRet::not_supported()`   | `feature` is not reserved and valid, but the platform does not support it due to one or more missing dependencies (Hardware or SBI implementation).
+/// | `SbiRet::denied()`          | `feature` is reserved or is platform-specific and unimplemented.
+/// | `SbiRet::failed()`          | The get operation failed for unspecified or unknown other reasons.
+///
+/// This function is defined in RISC-V SBI Specification chapter 18.2.
+#[inline]
+pub fn fwft_get(feature: u32) -> SbiRet {
+    sbi_call_1(EID_FWFT, GET, feature as _)
+}

+ 3 - 0
library/sbi-rt/src/lib.rs

@@ -40,6 +40,8 @@ mod cppc;
 mod nacl;
 // §16
 mod sta;
+// §18
+mod fwft;
 
 pub use sbi_spec::{
     base::Version,
@@ -52,6 +54,7 @@ pub use sbi_spec::{
 pub use base::*;
 pub use cppc::*;
 pub use dbcn::*;
+pub use fwft::*;
 pub use hsm::*;
 pub use nacl::*;
 pub use pmu::*;