1 use alloc::sync::Arc;
2 use system_error::SystemError;
3
4 use crate::arch::CurrentIrqArch;
5
6 use super::{
7 irqchip::{IrqChip, IrqChipFlags},
8 irqdata::IrqData,
9 InterruptArch,
10 };
11
12 static mut NO_IRQ_CHIP: Option<Arc<NoIrqChip>> = None;
13 static mut DUMMY_IRQ_CHIP: Option<Arc<DummyIrqChip>> = None;
14
15 #[inline(never)]
no_irq_chip() -> Arc<dyn IrqChip>16 pub fn no_irq_chip() -> Arc<dyn IrqChip> {
17 unsafe { NO_IRQ_CHIP.as_ref().unwrap().clone() }
18 }
19
20 #[allow(dead_code)]
21 #[inline(never)]
dummy_irq_chip() -> Arc<dyn IrqChip>22 pub fn dummy_irq_chip() -> Arc<dyn IrqChip> {
23 unsafe { DUMMY_IRQ_CHIP.as_ref().unwrap().clone() }
24 }
25
ack_bad(irq_data: &Arc<IrqData>)26 fn ack_bad(irq_data: &Arc<IrqData>) {
27 // todo: print_irq_desc
28 CurrentIrqArch::ack_bad_irq(irq_data.irq());
29 }
30
31 #[derive(Debug)]
32 struct NoIrqChip;
33
34 impl NoIrqChip {
new() -> Self35 pub const fn new() -> Self {
36 NoIrqChip
37 }
38 }
39
40 impl IrqChip for NoIrqChip {
name(&self) -> &'static str41 fn name(&self) -> &'static str {
42 "none"
43 }
44
can_mask_ack(&self) -> bool45 fn can_mask_ack(&self) -> bool {
46 false
47 }
48
irq_enable(&self, _irq: &Arc<IrqData>) -> Result<(), SystemError>49 fn irq_enable(&self, _irq: &Arc<IrqData>) -> Result<(), SystemError> {
50 Ok(())
51 }
52
can_set_affinity(&self) -> bool53 fn can_set_affinity(&self) -> bool {
54 false
55 }
56
can_set_flow_type(&self) -> bool57 fn can_set_flow_type(&self) -> bool {
58 false
59 }
60
irq_disable(&self, _irq: &Arc<IrqData>)61 fn irq_disable(&self, _irq: &Arc<IrqData>) {}
62
irq_ack(&self, irq: &Arc<IrqData>)63 fn irq_ack(&self, irq: &Arc<IrqData>) {
64 ack_bad(irq);
65 }
66
irq_startup(&self, _irq: &Arc<IrqData>) -> Result<(), SystemError>67 fn irq_startup(&self, _irq: &Arc<IrqData>) -> Result<(), SystemError> {
68 Ok(())
69 }
70
irq_shutdown(&self, _irq: &Arc<IrqData>) -> Result<(), SystemError>71 fn irq_shutdown(&self, _irq: &Arc<IrqData>) -> Result<(), SystemError> {
72 Ok(())
73 }
74
flags(&self) -> IrqChipFlags75 fn flags(&self) -> IrqChipFlags {
76 IrqChipFlags::IRQCHIP_SKIP_SET_WAKE
77 }
78 }
79
80 #[derive(Debug)]
81 struct DummyIrqChip;
82
83 impl DummyIrqChip {
new() -> Self84 pub const fn new() -> Self {
85 DummyIrqChip
86 }
87 }
88
89 impl IrqChip for DummyIrqChip {
name(&self) -> &'static str90 fn name(&self) -> &'static str {
91 "dummy"
92 }
93
can_mask_ack(&self) -> bool94 fn can_mask_ack(&self) -> bool {
95 false
96 }
97
irq_enable(&self, _irq: &Arc<IrqData>) -> Result<(), SystemError>98 fn irq_enable(&self, _irq: &Arc<IrqData>) -> Result<(), SystemError> {
99 Ok(())
100 }
101
can_set_flow_type(&self) -> bool102 fn can_set_flow_type(&self) -> bool {
103 false
104 }
105
can_set_affinity(&self) -> bool106 fn can_set_affinity(&self) -> bool {
107 false
108 }
109
irq_disable(&self, _irq: &Arc<IrqData>)110 fn irq_disable(&self, _irq: &Arc<IrqData>) {}
111
irq_ack(&self, _irq: &Arc<IrqData>)112 fn irq_ack(&self, _irq: &Arc<IrqData>) {}
113
irq_startup(&self, _irq: &Arc<IrqData>) -> Result<(), SystemError>114 fn irq_startup(&self, _irq: &Arc<IrqData>) -> Result<(), SystemError> {
115 Ok(())
116 }
117
irq_shutdown(&self, _irq: &Arc<IrqData>) -> Result<(), SystemError>118 fn irq_shutdown(&self, _irq: &Arc<IrqData>) -> Result<(), SystemError> {
119 Ok(())
120 }
121
flags(&self) -> IrqChipFlags122 fn flags(&self) -> IrqChipFlags {
123 IrqChipFlags::IRQCHIP_SKIP_SET_WAKE
124 }
125 }
126
127 #[inline(never)]
dummy_chip_init()128 pub fn dummy_chip_init() {
129 unsafe {
130 NO_IRQ_CHIP = Some(Arc::new(NoIrqChip::new()));
131 DUMMY_IRQ_CHIP = Some(Arc::new(DummyIrqChip::new()));
132 }
133 }
134