@@ -16,6 +16,7 @@ use crate::acpi::madt::{Ics, MADT};
16
16
use crate :: error:: { Error , Result } ;
17
17
use crate :: lock:: ro_after_init:: RoAfterInit ;
18
18
use core:: convert:: TryFrom ;
19
+ use core:: ops:: Range ;
19
20
use core:: fmt;
20
21
use core:: ptr;
21
22
@@ -49,10 +50,8 @@ static IOAPICS: RoAfterInit<ArrayVec<[IoApic; MAX_IOAPIC_COUNT]>> =
49
50
// TODO(alschwalm): Support InterruptSourceOverride
50
51
fn ioapic_for_gsi ( gsi : u32 ) -> Option < ( & ' static IoApic , u8 ) > {
51
52
for ioapic in IOAPICS . iter ( ) {
52
- let entries = ioapic. max_redirection_entry ( ) as u32 ;
53
- let base = ioapic. gsi_base ;
54
- if gsi > base && gsi < base + entries {
55
- return Some ( ( ioapic, ( gsi - base) as u8 ) ) ;
53
+ if ioapic. get_ivec_range ( ) . contains ( & gsi) {
54
+ return Some ( ( ioapic, ( gsi - ioapic. gsi_base ) as u8 ) ) ;
56
55
}
57
56
}
58
57
None
@@ -285,6 +284,13 @@ impl IoApic {
285
284
Ok ( ( ) )
286
285
}
287
286
}
287
+
288
+ /// convenience function to get a Range of the interrupt vectors
289
+ /// that should be associated with this IoApic.
290
+ pub fn get_ivec_range ( & self ) -> Range < u32 > {
291
+ return Range { start : self . gsi_base , end : self . gsi_base +
292
+ ( self . max_redirection_entry ( ) as u32 ) } ;
293
+ }
288
294
}
289
295
290
296
impl TryFrom < Ics > for IoApic {
0 commit comments