1*3bc96fa4SLoGin use alloc::sync::Arc; 2*3bc96fa4SLoGin use system_error::SystemError; 3*3bc96fa4SLoGin 4*3bc96fa4SLoGin use crate::arch::CurrentIrqArch; 5*3bc96fa4SLoGin 6*3bc96fa4SLoGin use super::{ 7*3bc96fa4SLoGin irqchip::{IrqChip, IrqChipFlags}, 8*3bc96fa4SLoGin irqdata::IrqData, 9*3bc96fa4SLoGin InterruptArch, 10*3bc96fa4SLoGin }; 11*3bc96fa4SLoGin 12*3bc96fa4SLoGin static mut NO_IRQ_CHIP: Option<Arc<NoIrqChip>> = None; 13*3bc96fa4SLoGin static mut DUMMY_IRQ_CHIP: Option<Arc<DummyIrqChip>> = None; 14*3bc96fa4SLoGin 15*3bc96fa4SLoGin #[inline(never)] 16*3bc96fa4SLoGin pub fn no_irq_chip() -> Arc<dyn IrqChip> { 17*3bc96fa4SLoGin unsafe { NO_IRQ_CHIP.as_ref().unwrap().clone() } 18*3bc96fa4SLoGin } 19*3bc96fa4SLoGin 20*3bc96fa4SLoGin #[allow(dead_code)] 21*3bc96fa4SLoGin #[inline(never)] 22*3bc96fa4SLoGin pub fn dummy_irq_chip() -> Arc<dyn IrqChip> { 23*3bc96fa4SLoGin unsafe { DUMMY_IRQ_CHIP.as_ref().unwrap().clone() } 24*3bc96fa4SLoGin } 25*3bc96fa4SLoGin 26*3bc96fa4SLoGin fn ack_bad(irq_data: &Arc<IrqData>) { 27*3bc96fa4SLoGin // todo: print_irq_desc 28*3bc96fa4SLoGin CurrentIrqArch::ack_bad_irq(irq_data.irq()); 29*3bc96fa4SLoGin } 30*3bc96fa4SLoGin 31*3bc96fa4SLoGin #[derive(Debug)] 32*3bc96fa4SLoGin struct NoIrqChip; 33*3bc96fa4SLoGin 34*3bc96fa4SLoGin impl NoIrqChip { 35*3bc96fa4SLoGin pub const fn new() -> Self { 36*3bc96fa4SLoGin NoIrqChip 37*3bc96fa4SLoGin } 38*3bc96fa4SLoGin } 39*3bc96fa4SLoGin 40*3bc96fa4SLoGin impl IrqChip for NoIrqChip { 41*3bc96fa4SLoGin fn name(&self) -> &'static str { 42*3bc96fa4SLoGin "none" 43*3bc96fa4SLoGin } 44*3bc96fa4SLoGin fn irq_enable(&self, _irq: &Arc<IrqData>) -> Result<(), SystemError> { 45*3bc96fa4SLoGin Ok(()) 46*3bc96fa4SLoGin } 47*3bc96fa4SLoGin 48*3bc96fa4SLoGin fn irq_disable(&self, _irq: &Arc<IrqData>) {} 49*3bc96fa4SLoGin 50*3bc96fa4SLoGin fn irq_ack(&self, irq: &Arc<IrqData>) { 51*3bc96fa4SLoGin ack_bad(irq); 52*3bc96fa4SLoGin } 53*3bc96fa4SLoGin 54*3bc96fa4SLoGin fn irq_startup(&self, _irq: &Arc<IrqData>) -> Result<(), SystemError> { 55*3bc96fa4SLoGin Ok(()) 56*3bc96fa4SLoGin } 57*3bc96fa4SLoGin 58*3bc96fa4SLoGin fn irq_shutdown(&self, _irq: &Arc<IrqData>) -> Result<(), SystemError> { 59*3bc96fa4SLoGin Ok(()) 60*3bc96fa4SLoGin } 61*3bc96fa4SLoGin 62*3bc96fa4SLoGin fn flags(&self) -> IrqChipFlags { 63*3bc96fa4SLoGin IrqChipFlags::IRQCHIP_SKIP_SET_WAKE 64*3bc96fa4SLoGin } 65*3bc96fa4SLoGin } 66*3bc96fa4SLoGin 67*3bc96fa4SLoGin #[derive(Debug)] 68*3bc96fa4SLoGin struct DummyIrqChip; 69*3bc96fa4SLoGin 70*3bc96fa4SLoGin impl DummyIrqChip { 71*3bc96fa4SLoGin pub const fn new() -> Self { 72*3bc96fa4SLoGin DummyIrqChip 73*3bc96fa4SLoGin } 74*3bc96fa4SLoGin } 75*3bc96fa4SLoGin 76*3bc96fa4SLoGin impl IrqChip for DummyIrqChip { 77*3bc96fa4SLoGin fn name(&self) -> &'static str { 78*3bc96fa4SLoGin "dummy" 79*3bc96fa4SLoGin } 80*3bc96fa4SLoGin 81*3bc96fa4SLoGin fn irq_enable(&self, _irq: &Arc<IrqData>) -> Result<(), SystemError> { 82*3bc96fa4SLoGin Ok(()) 83*3bc96fa4SLoGin } 84*3bc96fa4SLoGin 85*3bc96fa4SLoGin fn irq_disable(&self, _irq: &Arc<IrqData>) {} 86*3bc96fa4SLoGin 87*3bc96fa4SLoGin fn irq_ack(&self, _irq: &Arc<IrqData>) {} 88*3bc96fa4SLoGin 89*3bc96fa4SLoGin fn irq_mask(&self, _irq: &Arc<IrqData>) {} 90*3bc96fa4SLoGin fn irq_unmask(&self, _irq: &Arc<IrqData>) {} 91*3bc96fa4SLoGin 92*3bc96fa4SLoGin fn irq_startup(&self, _irq: &Arc<IrqData>) -> Result<(), SystemError> { 93*3bc96fa4SLoGin Ok(()) 94*3bc96fa4SLoGin } 95*3bc96fa4SLoGin 96*3bc96fa4SLoGin fn irq_shutdown(&self, _irq: &Arc<IrqData>) -> Result<(), SystemError> { 97*3bc96fa4SLoGin Ok(()) 98*3bc96fa4SLoGin } 99*3bc96fa4SLoGin 100*3bc96fa4SLoGin fn flags(&self) -> IrqChipFlags { 101*3bc96fa4SLoGin IrqChipFlags::IRQCHIP_SKIP_SET_WAKE 102*3bc96fa4SLoGin } 103*3bc96fa4SLoGin } 104*3bc96fa4SLoGin 105*3bc96fa4SLoGin #[inline(never)] 106*3bc96fa4SLoGin pub fn dummy_chip_init() { 107*3bc96fa4SLoGin unsafe { 108*3bc96fa4SLoGin NO_IRQ_CHIP = Some(Arc::new(NoIrqChip::new())); 109*3bc96fa4SLoGin DUMMY_IRQ_CHIP = Some(Arc::new(DummyIrqChip::new())); 110*3bc96fa4SLoGin } 111*3bc96fa4SLoGin } 112