reset.rs 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. use sbi_spec::binary::SbiRet;
  2. /// System Reset extension.
  3. ///
  4. /// Provides a function that allow the supervisor software to request system-level reboot or shutdown.
  5. ///
  6. /// The term "system" refers to the world-view of supervisor software and the underlying SBI implementation
  7. /// could be machine mode firmware or hypervisor.
  8. ///
  9. /// Ref: [Section 9, RISC-V Supervisor Binary Interface Specification](https://github.com/riscv-non-isa/riscv-sbi-doc/blob/master/riscv-sbi.adoc#9-system-reset-extension-eid-0x53525354-srst)
  10. pub trait Reset {
  11. /// Reset the system based on provided `reset_type` and `reset_reason`.
  12. ///
  13. /// This is a synchronous call and does not return if it succeeds.
  14. ///
  15. /// # Warm reboot and cold reboot
  16. ///
  17. /// When supervisor software is running natively, the SBI implementation is machine mode firmware.
  18. /// In this case, shutdown is equivalent to physical power down of the entire system and
  19. /// cold reboot is equivalent to physical power cycle of the entire system. Further, warm reboot
  20. /// is equivalent to a power cycle of main processor and parts of the system but not the entire system.
  21. ///
  22. /// For example, on a server class system with a BMC (board management controller),
  23. /// a warm reboot will not power cycle the BMC whereas a cold reboot will definitely power cycle the BMC.
  24. ///
  25. /// When supervisor software is running inside a virtual machine, the SBI implementation is a hypervisor.
  26. /// The shutdown, cold reboot and warm reboot will behave functionally the same as the native case but might
  27. /// not result in any physical power changes.
  28. ///
  29. /// # Return value
  30. ///
  31. /// The possible return error codes returned in `SbiRet.error` are shown in the table below:
  32. ///
  33. /// | Error code | Description
  34. /// |:--------------------------|:---------------
  35. /// | `SbiRet::invalid_param()` | `reset_type` or `reset_reason` is not valid.
  36. /// | `SbiRet::not_supported()` | `reset_type` is valid but not implemented.
  37. /// | `SbiRet::failed()` | Reset request failed for unknown reasons.
  38. fn system_reset(&self, reset_type: u32, reset_reason: u32) -> SbiRet;
  39. }
  40. impl<T: Reset> Reset for &T {
  41. #[inline]
  42. fn system_reset(&self, reset_type: u32, reset_reason: u32) -> SbiRet {
  43. T::system_reset(self, reset_type, reset_reason)
  44. }
  45. }