File tree Expand file tree Collapse file tree 1 file changed +12
-2
lines changed Expand file tree Collapse file tree 1 file changed +12
-2
lines changed Original file line number Diff line number Diff line change 33use crate :: arch:: { enable_irq, SpinLock } ;
44use alloc:: boxed:: Box ;
55use core:: mem:: MaybeUninit ;
6+ use kerla_utils:: bitmap:: BitMap ;
67
78fn empty_irq_handler ( ) { }
89
910type IrqHandler = dyn FnMut ( ) + Send + Sync ;
1011const UNINITIALIZED_IRQ_HANDLER : MaybeUninit < Box < IrqHandler > > = MaybeUninit :: uninit ( ) ;
1112static IRQ_HANDLERS : SpinLock < [ MaybeUninit < Box < IrqHandler > > ; 256 ] > =
1213 SpinLock :: new ( [ UNINITIALIZED_IRQ_HANDLER ; 256 ] ) ;
14+ static ATTACHED_IRQS : SpinLock < BitMap < 32 /* = 256 / 8 */ > > = SpinLock :: new ( BitMap :: zeroed ( ) ) ;
1315
1416pub fn init ( ) {
1517 let mut handlers = IRQ_HANDLERS . lock ( ) ;
@@ -19,8 +21,16 @@ pub fn init() {
1921}
2022
2123pub fn attach_irq < F : FnMut ( ) + Send + Sync + ' static > ( irq : u8 , f : F ) {
22- IRQ_HANDLERS . lock ( ) [ irq as usize ] . write ( Box :: new ( f) ) ;
23- enable_irq ( irq) ;
24+ let mut attached_irq_map = ATTACHED_IRQS . lock ( ) ;
25+ match attached_irq_map. get ( irq as usize ) {
26+ Some ( true ) => panic ! ( "handler for IRQ #{} is already attached" , irq) ,
27+ Some ( false ) => {
28+ attached_irq_map. set ( irq as usize ) ;
29+ IRQ_HANDLERS . lock ( ) [ irq as usize ] . write ( Box :: new ( f) ) ;
30+ enable_irq ( irq) ;
31+ }
32+ None => panic ! ( "IRQ #{} is out of bound" , irq) ,
33+ }
2434}
2535
2636pub fn handle_irq ( irq : u8 ) {
You can’t perform that action at this time.
0 commit comments