@@ -16,6 +16,7 @@ use crate::acpi::madt::{Ics, MADT};
1616use crate :: error:: { Error , Result } ;
1717use crate :: lock:: ro_after_init:: RoAfterInit ;
1818use core:: convert:: TryFrom ;
19+ use core:: ops:: Range ;
1920use core:: fmt;
2021use core:: ptr;
2122
@@ -49,10 +50,8 @@ static IOAPICS: RoAfterInit<ArrayVec<[IoApic; MAX_IOAPIC_COUNT]>> =
4950// TODO(alschwalm): Support InterruptSourceOverride
5051fn ioapic_for_gsi ( gsi : u32 ) -> Option < ( & ' static IoApic , u8 ) > {
5152 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 ) ) ;
5655 }
5756 }
5857 None
@@ -285,6 +284,13 @@ impl IoApic {
285284 Ok ( ( ) )
286285 }
287286 }
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+ }
288294}
289295
290296impl TryFrom < Ics > for IoApic {
0 commit comments