rdif_intc/
lib.rs

1#![no_std]
2
3extern crate alloc;
4
5use alloc::boxed::Box;
6use core::error::Error;
7
8use rdif_base::custom_type;
9pub use rdif_base::{DriverGeneric, DriverResult, IrqConfig, IrqId, Trigger};
10
11custom_type!(CpuId, usize, "{:#x}");
12
13pub type Hardware = Box<dyn Interface>;
14pub type HardwareCPU = Box<dyn InterfaceCPU>;
15
16/// Fdt 解析 `interrupts` 函数,一次解析一个`cell`
17pub type FdtParseConfigFn =
18    fn(prop_interrupts_one_cell: &[u32]) -> Result<IrqConfig, Box<dyn Error>>;
19
20pub struct FdtProbeInfo {
21    pub hardware: Hardware,
22    pub fdt_parse_config_fn: FdtParseConfigFn,
23}
24
25/// 在中断中调用,不会被打断,视为`Sync`
26pub trait InterfaceCPU: Send + Sync {
27    fn get_and_acknowledge_interrupt(&self) -> Option<IrqId>;
28    fn end_interrupt(&self, irq: IrqId);
29}
30
31pub trait Interface: DriverGeneric {
32    fn current_cpu_setup(&self) -> HardwareCPU;
33    fn irq_enable(&mut self, irq: IrqId);
34    fn irq_disable(&mut self, irq: IrqId);
35    fn set_priority(&mut self, irq: IrqId, priority: usize);
36    fn set_trigger(&mut self, irq: IrqId, trigger: Trigger);
37    fn set_target_cpu(&mut self, irq: IrqId, cpu: CpuId);
38}