浏览代码

Function `num_counters` now returns `usize`

luojia65 3 年之前
父节点
当前提交
ba210aa04d
共有 2 个文件被更改,包括 8 次插入4 次删除
  1. 1 0
      CHANGELOG.md
  2. 7 4
      src/pmu.rs

+ 1 - 0
CHANGELOG.md

@@ -28,6 +28,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
 - Dump all trap frame registers when exception happened in reference implementations
 - Use `embedded-hal` dependency version `0.2.6`
 - Change to asynchronous lock structure trait style
+- Function `num_counters` returns `usize` and its SBI call must return `SBI_SUCCESS`
 
 ### Fixed
 - Test kernel console now will lock before `println` line is finished

+ 7 - 4
src/pmu.rs

@@ -38,9 +38,10 @@ use alloc::boxed::Box;
 ///    event_idx[15:0] = code;
 /// ```
 pub trait Pmu: Send {
-    /// Returns the number of counters (both hardware and firmware) in return `SbiRet.value`
-    /// and always returns SBI_SUCCESS in `SbiRet.error`.
-    fn num_counters(&self) -> SbiRet;
+    /// Returns the number of counters (both hardware and firmware).
+    /// 
+    /// The value is returned in `SbiRet.value`; this call always returns SBI_SUCCESS in `SbiRet.error`.
+    fn num_counters(&self) -> usize;
     /// Get details about the specified counter such as underlying CSR number, width of the counter, 
     /// type of counter hardware/firmware, etc.
     ///
@@ -212,7 +213,9 @@ pub(crate) fn probe_pmu() -> bool {
 #[inline] 
 pub(crate) fn num_counters() -> SbiRet {
     if let Some(obj) = PMU.get() {
-        return obj.num_counters();
+        // Returns the number of counters (both hardware and firmware) in sbiret.value 
+        // and always returns SBI_SUCCESS in sbiret.error.
+        return SbiRet::ok(obj.num_counters());
     }
     SbiRet::not_supported()
 }