1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
use crate::hart_mask::HartMask;
use crate::ecall::SbiRet;
pub trait Ipi: Send {
fn max_hart_id(&self) -> usize;
fn send_ipi_many(&mut self, hart_mask: HartMask) -> SbiRet;
}
use alloc::boxed::Box;
use spin::Mutex;
lazy_static::lazy_static! {
static ref IPI: Mutex<Option<Box<dyn Ipi>>> = Mutex::new(None);
}
#[doc(hidden)]
pub fn init_ipi<T: Ipi + Send + 'static>(ipi: T) {
*IPI.lock() = Some(Box::new(ipi));
}
#[inline]
pub(crate) fn probe_ipi() -> bool {
IPI.lock().as_ref().is_some()
}
pub(crate) fn send_ipi_many(hart_mask: HartMask) -> SbiRet {
if let Some(ipi) = IPI.lock().as_mut() {
ipi.send_ipi_many(hart_mask)
} else {
SbiRet::not_supported()
}
}
pub(crate) fn max_hart_id() -> Option<usize> {
if let Some(ipi) = IPI.lock().as_ref() {
Some(ipi.max_hart_id())
} else {
None
}
}