1use core::{error::Error, fmt::Debug};
2
3use crate::{DriverGeneric, custom_type};
4use alloc::boxed::Box;
5
6custom_type!(IrqId, usize, "{:#x}");
7custom_type!(CpuId, usize, "{:#x}");
8
9pub type Hardware = Box<dyn Interface>;
10pub type OnProbeFdt = fn(node: crate::fdt::Node<'_>) -> Result<FdtProbeInfo, Box<dyn Error>>;
11pub type HardwareCPU = Box<dyn InterfaceCPU>;
12
13pub type FdtParseConfigFn =
15 fn(prop_interrupts_one_cell: &[u32]) -> Result<IrqConfig, Box<dyn Error>>;
16
17pub struct FdtProbeInfo {
18 pub hardware: Hardware,
19 pub fdt_parse_config_fn: FdtParseConfigFn,
20}
21
22pub trait InterfaceCPU: Send + Sync {
23 fn get_and_acknowledge_interrupt(&self) -> Option<IrqId>;
24 fn end_interrupt(&self, irq: IrqId);
25}
26
27pub trait Interface: DriverGeneric {
28 fn current_cpu_setup(&self) -> HardwareCPU;
29 fn irq_enable(&mut self, irq: IrqId);
30 fn irq_disable(&mut self, irq: IrqId);
31 fn set_priority(&mut self, irq: IrqId, priority: usize);
32 fn set_trigger(&mut self, irq: IrqId, trigger: Trigger);
33 fn set_target_cpu(&mut self, irq: IrqId, cpu: CpuId);
34}
35
36#[derive(Copy, Clone, Debug, Eq, PartialEq)]
38pub enum Trigger {
39 EdgeBoth,
40 EdgeRising,
41 EdgeFailling,
42 LevelHigh,
43 LevelLow,
44}
45
46#[derive(Debug, Clone)]
47pub struct IrqConfig {
48 pub irq: IrqId,
49 pub trigger: Trigger,
50}