ipi.rs 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. use crate::hart_mask::HartMask;
  2. use sbi_spec::binary::SbiRet;
  3. #[cfg(feature = "singleton")]
  4. use crate::util::AmoOnceRef;
  5. /// Inter-processor interrupt support
  6. pub trait Ipi: Send + Sync {
  7. /// Send an inter-processor interrupt to all the harts defined in `hart_mask`.
  8. ///
  9. /// Inter-processor interrupts manifest at the receiving harts as the supervisor software interrupts.
  10. ///
  11. /// # Return value
  12. ///
  13. /// Should return `SbiRet::success()` if IPI was sent to all the targeted harts successfully.
  14. fn send_ipi(&self, hart_mask: HartMask) -> SbiRet;
  15. }
  16. #[cfg(feature = "singleton")]
  17. static IPI: AmoOnceRef<dyn Ipi> = AmoOnceRef::new();
  18. /// Init singleton IPI module
  19. #[cfg(feature = "singleton")]
  20. pub fn init_ipi(ipi: &'static dyn Ipi) {
  21. if !IPI.try_call_once(ipi) {
  22. panic!("load sbi module when already loaded")
  23. }
  24. }
  25. #[cfg(feature = "singleton")]
  26. #[inline]
  27. pub(crate) fn probe_ipi() -> bool {
  28. IPI.get().is_some()
  29. }
  30. #[cfg(feature = "singleton")]
  31. #[inline]
  32. pub(crate) fn send_ipi(hart_mask: HartMask) -> SbiRet {
  33. if let Some(ipi) = IPI.get() {
  34. return ipi.send_ipi(hart_mask);
  35. }
  36. SbiRet::not_supported()
  37. }