hsm.rs 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. //! hsm extension
  2. use super::SbiRet;
  3. const FUNCTION_HSM_HART_START: usize = 0x0;
  4. const FUNCTION_HSM_HART_STOP: usize = 0x1;
  5. const FUNCTION_HSM_HART_GET_STATUS: usize = 0x2;
  6. const FUNCTION_HSM_HART_SUSPEND: usize = 0x3;
  7. #[inline]
  8. pub fn handle_ecall_hsm(function: usize, param0: usize, param1: usize, param2: usize) -> SbiRet {
  9. match function {
  10. FUNCTION_HSM_HART_START => hart_start(param0, param1, param2),
  11. FUNCTION_HSM_HART_STOP => hart_stop(param0),
  12. FUNCTION_HSM_HART_GET_STATUS => hart_get_status(param0),
  13. FUNCTION_HSM_HART_SUSPEND => hart_suspend(param0, param1, param2),
  14. _ => SbiRet::not_supported(),
  15. }
  16. }
  17. #[inline]
  18. fn hart_start(hartid: usize, start_addr: usize, opaque: usize) -> SbiRet {
  19. crate::hsm::hart_start(hartid, start_addr, opaque)
  20. }
  21. #[inline]
  22. fn hart_stop(hartid: usize) -> SbiRet {
  23. crate::hsm::hart_stop(hartid)
  24. }
  25. #[inline]
  26. fn hart_get_status(hartid: usize) -> SbiRet {
  27. crate::hsm::hart_get_status(hartid)
  28. }
  29. #[inline]
  30. fn hart_suspend(suspend_type: usize, resume_addr: usize, opaque: usize) -> SbiRet {
  31. if suspend_type > u32::MAX as usize { // valid suspend type should be a `u32` typed value
  32. return SbiRet::invalid_param()
  33. }
  34. crate::hsm::hart_suspend(suspend_type as u32, resume_addr, opaque)
  35. }