axplat/
irq.rs

1//! Interrupt request (IRQ) handling.
2
3pub use handler_table::HandlerTable;
4
5/// The type if an IRQ handler.
6pub type IrqHandler = handler_table::Handler;
7
8/// Target specification for inter-processor interrupts (IPIs).
9pub enum IpiTarget {
10    /// Send to the current CPU.
11    Current {
12        /// The CPU ID of the current CPU.
13        cpu_id: usize,
14    },
15    /// Send to a specific CPU.
16    Other {
17        /// The CPU ID of the target CPU.
18        cpu_id: usize,
19    },
20    /// Send to all other CPUs.
21    AllExceptCurrent {
22        /// The CPU ID of the current CPU.
23        cpu_id: usize,
24        /// The total number of CPUs.
25        cpu_num: usize,
26    },
27}
28
29/// IRQ management interface.
30#[def_plat_interface]
31pub trait IrqIf {
32    /// Enables or disables the given IRQ.
33    fn set_enable(irq: usize, enabled: bool);
34
35    /// Registers an IRQ handler for the given IRQ.
36    ///
37    /// It also enables the IRQ if the registration succeeds. It returns `false`
38    /// if the registration failed.
39    fn register(irq: usize, handler: IrqHandler) -> bool;
40
41    /// Unregisters the IRQ handler for the given IRQ.
42    ///
43    /// It also disables the IRQ if the unregistration succeeds. It returns the
44    /// existing handler if it is registered, `None` otherwise.
45    fn unregister(irq: usize) -> Option<IrqHandler>;
46
47    /// Handles the IRQ.
48    ///
49    /// It is called by the common interrupt handler. It should look up in the
50    /// IRQ handler table and calls the corresponding handler. If necessary, it
51    /// also acknowledges the interrupt controller after handling.
52    fn handle(irq: usize);
53
54    /// Sends an inter-processor interrupt (IPI) to the specified target CPU or all CPUs.
55    fn send_ipi(irq_num: usize, target: IpiTarget);
56}