xref: /DragonOS/kernel/src/exception/ipi.rs (revision 338f6903262c5031abad3c8e361813355a27fcdb)
1 use alloc::sync::Arc;
2 use system_error::SystemError;
3 
4 use crate::{
5     arch::{sched::sched, MMArch},
6     mm::MemoryManagementArch,
7     smp::cpu::ProcessorId,
8 };
9 
10 use super::{
11     irqdata::IrqHandlerData,
12     irqdesc::{IrqHandler, IrqReturn},
13     HardwareIrqNumber, IrqNumber,
14 };
15 
16 #[allow(dead_code)]
17 #[derive(Debug, Copy, Clone, Eq, PartialEq)]
18 pub enum IpiKind {
19     KickCpu,
20     FlushTLB,
21     /// 指定中断向量号
22     SpecVector(HardwareIrqNumber),
23 }
24 
25 /// IPI投递目标
26 #[derive(Debug, Copy, Clone, Eq, PartialEq)]
27 #[allow(dead_code)]
28 pub enum IpiTarget {
29     /// 当前CPU
30     Current,
31     /// 所有CPU
32     All,
33     /// 除了当前CPU以外的所有CPU
34     Other,
35     /// 指定的CPU
36     Specified(ProcessorId),
37 }
38 
39 /// 处理跨核心CPU唤醒的IPI
40 #[derive(Debug)]
41 pub struct KickCpuIpiHandler;
42 
43 impl IrqHandler for KickCpuIpiHandler {
44     fn handle(
45         &self,
46         _irq: IrqNumber,
47         _static_data: Option<&dyn IrqHandlerData>,
48         _dynamic_data: Option<Arc<dyn IrqHandlerData>>,
49     ) -> Result<IrqReturn, SystemError> {
50         sched();
51         Ok(IrqReturn::Handled)
52     }
53 }
54 
55 /// 处理TLB刷新的IPI
56 #[derive(Debug)]
57 pub struct FlushTLBIpiHandler;
58 
59 impl IrqHandler for FlushTLBIpiHandler {
60     fn handle(
61         &self,
62         _irq: IrqNumber,
63         _static_data: Option<&dyn IrqHandlerData>,
64         _dynamic_data: Option<Arc<dyn IrqHandlerData>>,
65     ) -> Result<IrqReturn, SystemError> {
66         unsafe { MMArch::invalidate_all() };
67 
68         Ok(IrqReturn::Handled)
69     }
70 }
71