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 3
3
use crate :: arch:: { enable_irq, SpinLock } ;
4
4
use alloc:: boxed:: Box ;
5
5
use core:: mem:: MaybeUninit ;
6
+ use kerla_utils:: bitmap:: BitMap ;
6
7
7
8
fn empty_irq_handler ( ) { }
8
9
9
10
type IrqHandler = dyn FnMut ( ) + Send + Sync ;
10
11
const UNINITIALIZED_IRQ_HANDLER : MaybeUninit < Box < IrqHandler > > = MaybeUninit :: uninit ( ) ;
11
12
static IRQ_HANDLERS : SpinLock < [ MaybeUninit < Box < IrqHandler > > ; 256 ] > =
12
13
SpinLock :: new ( [ UNINITIALIZED_IRQ_HANDLER ; 256 ] ) ;
14
+ static ATTACHED_IRQS : SpinLock < BitMap < 32 /* = 256 / 8 */ > > = SpinLock :: new ( BitMap :: zeroed ( ) ) ;
13
15
14
16
pub fn init ( ) {
15
17
let mut handlers = IRQ_HANDLERS . lock ( ) ;
@@ -19,8 +21,16 @@ pub fn init() {
19
21
}
20
22
21
23
pub 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
+ }
24
34
}
25
35
26
36
pub fn handle_irq ( irq : u8 ) {
You can’t perform that action at this time.
0 commit comments