Function sbi_rt::hart_suspend

source ·
pub fn hart_suspend<T>(
    suspend_type: T,
    resume_addr: usize,
    opaque: usize
) -> SbiRet
where T: SuspendType,
Expand description

Put the calling hart into suspend or platform specific lower power states.

This function requests the SBI implementation to put the calling hart in a platform specfic suspend (or low power) state specified by the suspend_type parameter.

The hart will automatically come out of suspended state and resume normal execution when it receives an interrupt or platform specific hardware event.

§Suspend behavior

The platform-specific suspend states for a hart can be either retentive or non-retentive in nature.

A retentive suspend state will preserve hart register and CSR values for all privilege modes, whereas a non-retentive suspend state will not preserve hart register and CSR values.

§Resuming

Resuming from a retentive suspend state is straight forward, and the supervisor-mode software will see SBI suspend call return without any failures.

Resuming from a non-retentive suspend state is relatively more involved, and it requires software to restore various hart registers and CSRs for all privilege modes. Upon resuming from non-retentive suspend state, the hart will jump to supervisor-mode at address specified by resume_addr with specific registers values described in the table below:

Register NameRegister Value
satp0
sstatus.SIE0
a0hartid
a1opaque parameter

§Parameters

The suspend_type parameter is 32 bits wide, and the possible values are shown in the table below:

ValueDescription
0x00000000Default retentive suspend
0x00000001 - 0x0FFFFFFFReserved for future use
0x10000000 - 0x7FFFFFFFPlatform specific retentive suspend
0x80000000Default non-retentive suspend
0x80000001 - 0x8FFFFFFFReserved for future use
0x90000000 - 0xFFFFFFFFPlatform specific non-retentive suspend
> 0xFFFFFFFFReserved

The resume_addr parameter points to a runtime-specified physical address, where the hart can resume execution in supervisor-mode after a non-retentive suspend.

NOTE: A single usize parameter is sufficient as resume_addr, because the hart will resume execution in the supervisor-mode with MMU off, hence the resume_addr must be less than XLEN bits wide.

The opaque parameter is an XLEN-bit value that will be set in the a1 register when the hart resumes execution at resume_addr after a non-retentive suspend.

§Return value

The possible return error codes returned in SbiRet.error are shown in the table below:

Error codeDescription
SbiRet::success()Hart has been suspended and resumed back successfully from a retentive suspend state.
SbiRet::invalid_param()suspend_type is not valid.
SbiRet::not_supported()suspend_type is valid but not implemented.
SbiRet::invalid_address()resume_addr is not valid, possibly due to the following reasons: it is not a valid physical address, or the address is prohibited by PMP or H-extension G-stage to run in supervisor-mode.
SbiRet::failed()The suspend request failed for unknown reasons.

This function is defined in RISC-V SBI Specification chapter 9.4.