Skip to content
This repository has been archived by the owner on Jan 10, 2024. It is now read-only.

Commit

Permalink
hsm: rearrange HSM constants into modules
Browse files Browse the repository at this point in the history
fix link on changelog

Signed-off-by: Zhouqi Jiang <luojia@hust.edu.cn>
  • Loading branch information
luojia65 committed Dec 2, 2023
1 parent 35cd34d commit d6415b6
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 44 deletions.
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),

### Modified

- Rearrange `HSM` constants into modules.

### Fixed

- Remove redundant prefixes in `PMU`
Expand Down Expand Up @@ -92,7 +94,8 @@ This is the first release of sbi-spec crate. This crate includes definition of R

- Adapt to SBI specification version 1.0.0 ratified

[Unreleased]: https://github.com/rustsbi/sbi-spec/compare/v0.0.5...HEAD
[Unreleased]: https://github.com/rustsbi/sbi-spec/compare/v0.0.6...HEAD
[0.0.6]: https://github.com/rustsbi/sbi-spec/compare/v0.0.5...v0.0.6
[0.0.5]: https://github.com/rustsbi/sbi-spec/compare/v0.0.4...v0.0.5
[0.0.4]: https://github.com/rustsbi/sbi-spec/compare/v0.0.3...v0.0.4
[0.0.3]: https://github.com/rustsbi/sbi-spec/compare/v0.0.2...v0.0.3
Expand Down
76 changes: 42 additions & 34 deletions src/hsm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,42 +4,50 @@
pub const EID_HSM: usize = crate::eid_from_str("HSM") as _;
pub use fid::*;

/// The hart is physically powered-up and executing normally.
pub const HART_STATE_STARTED: usize = 0;
/// The hart is not executing in supervisor-mode or any lower privilege mode.
/// Hart states.
///
/// It is probably powered-down by the SBI implementation if the underlying platform
/// has a mechanism to physically power-down harts.
pub const HART_STATE_STOPPED: usize = 1;
/// The hart is pending before being started
///
/// Some other hart has requested to start (or power-up) the hart from the STOPPED state
/// and the SBI implementation is still working to get the hart in the STARTED state.
pub const HART_STATE_START_PENDING: usize = 2;
/// The hart is pending before being stopped.
///
/// The hart has requested to stop (or power-down) itself from the STARTED state
/// and the SBI implementation is still working to get the hart in the STOPPED state.
pub const HART_STATE_STOP_PENDING: usize = 3;
/// The hart is in a platform specific suspend (or low power) state.
pub const HART_STATE_SUSPENDED: usize = 4;
/// The hart is pending before being suspended.
///
/// The hart has requested to put itself in a platform specific low power state
/// from the STARTED state and the SBI implementation is still working to get
/// the hart in the platform specific SUSPENDED state.
pub const HART_STATE_SUSPEND_PENDING: usize = 5;
/// The hart is pending before being resumed.
///
/// An interrupt or platform specific hardware event has caused the hart to resume
/// normal execution from the SUSPENDED state and the SBI implementation is still
/// working to get the hart in the STARTED state.
pub const HART_STATE_RESUME_PENDING: usize = 6;
/// Declared in Table 1 at §9.
pub mod hart_state {
/// The hart is physically powered-up and executing normally.
pub const STARTED: usize = 0;
/// The hart is not executing in supervisor-mode or any lower privilege mode.
///
/// It is probably powered-down by the SBI implementation if the underlying platform
/// has a mechanism to physically power-down harts.
pub const STOPPED: usize = 1;
/// The hart is pending before being started
///
/// Some other hart has requested to start (or power-up) the hart from the STOPPED state
/// and the SBI implementation is still working to get the hart in the STARTED state.
pub const START_PENDING: usize = 2;
/// The hart is pending before being stopped.
///
/// The hart has requested to stop (or power-down) itself from the STARTED state
/// and the SBI implementation is still working to get the hart in the STOPPED state.
pub const STOP_PENDING: usize = 3;
/// The hart is in a platform specific suspend (or low power) state.
pub const SUSPENDED: usize = 4;
/// The hart is pending before being suspended.
///
/// The hart has requested to put itself in a platform specific low power state
/// from the STARTED state and the SBI implementation is still working to get
/// the hart in the platform specific SUSPENDED state.
pub const SUSPEND_PENDING: usize = 5;
/// The hart is pending before being resumed.
///
/// An interrupt or platform specific hardware event has caused the hart to resume
/// normal execution from the SUSPENDED state and the SBI implementation is still
/// working to get the hart in the STARTED state.
pub const RESUME_PENDING: usize = 6;
}

/// Default retentive hart suspend type.
pub const HART_SUSPEND_TYPE_RETENTIVE: u32 = 0;
/// Default non-retentive hart suspend type.
pub const HART_SUSPEND_TYPE_NON_RETENTIVE: u32 = 0x8000_0000;
/// Hart suspend types.
pub mod suspend_type {
/// Default retentive hart suspend type.
pub const RETENTIVE: u32 = 0;
/// Default non-retentive hart suspend type.
pub const NON_RETENTIVE: u32 = 0x8000_0000;
}

/// Declared in §9.5.
mod fid {
Expand Down
18 changes: 9 additions & 9 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,15 +151,15 @@ mod tests {
fn test_hsm() {
use crate::hsm::*;
const_assert_eq!(0x48534D, EID_HSM);
const_assert_eq!(0, HART_STATE_STARTED);
const_assert_eq!(1, HART_STATE_STOPPED);
const_assert_eq!(2, HART_STATE_START_PENDING);
const_assert_eq!(3, HART_STATE_STOP_PENDING);
const_assert_eq!(4, HART_STATE_SUSPENDED);
const_assert_eq!(5, HART_STATE_SUSPEND_PENDING);
const_assert_eq!(6, HART_STATE_RESUME_PENDING);
const_assert_eq!(0x0000_0000, HART_SUSPEND_TYPE_RETENTIVE);
const_assert_eq!(0x8000_0000, HART_SUSPEND_TYPE_NON_RETENTIVE);
const_assert_eq!(0, hart_state::STARTED);
const_assert_eq!(1, hart_state::STOPPED);
const_assert_eq!(2, hart_state::START_PENDING);
const_assert_eq!(3, hart_state::STOP_PENDING);
const_assert_eq!(4, hart_state::SUSPENDED);
const_assert_eq!(5, hart_state::SUSPEND_PENDING);
const_assert_eq!(6, hart_state::RESUME_PENDING);
const_assert_eq!(0x0000_0000, suspend_type::RETENTIVE);
const_assert_eq!(0x8000_0000, suspend_type::NON_RETENTIVE);
const_assert_eq!(0, HART_START);
const_assert_eq!(1, HART_STOP);
const_assert_eq!(2, HART_GET_STATUS);
Expand Down

0 comments on commit d6415b6

Please sign in to comment.