diff --git a/src/arch/aarch64/smmu.rs b/src/arch/aarch64/smmu.rs index 67e87f132523d75080a8bc97693ad4bd37d2ceaa..d57b4edc91380065df97b20dea45217745d0867e 100644 --- a/src/arch/aarch64/smmu.rs +++ b/src/arch/aarch64/smmu.rs @@ -484,10 +484,11 @@ impl SmmuV2 { ) as u16 } - pub fn alloc_smr(&self) -> Option { - let alloc_bitmap = self.smr_alloc_bitmap.as_ref().unwrap(); - for i in 0..alloc_bitmap.vec_len() { + pub fn alloc_smr(&mut self) -> Option { + let alloc_bitmap = self.smr_alloc_bitmap.as_mut().unwrap(); + for i in 0..alloc_bitmap.vec_len() * 8 { if alloc_bitmap.get(i) == 0 { + alloc_bitmap.set(i, true); return Some(i); } } @@ -523,7 +524,7 @@ impl SmmuV2 { } pub fn write_smr(&mut self, smr: usize, mask: u16, id: u16, group: bool) { - if self.smr_alloc_bitmap.as_ref().unwrap().get(smr) != 0 { + if self.smr_alloc_bitmap.as_ref().unwrap().get(smr) == 0 { panic!("smmu: trying to write unallocated smr {}", smr); } else { let mut val: usize = (mask as usize) << SMMU_SMR_MASK_OFF; @@ -538,7 +539,7 @@ impl SmmuV2 { // Stream-to-Context pub fn write_s2c(&mut self, smr: usize, context_id: usize) { - if self.smr_alloc_bitmap.as_ref().unwrap().get(smr) != 0 { + if self.smr_alloc_bitmap.as_ref().unwrap().get(smr) == 0 { panic!("smmu: trying to write unallocated s2c {}", smr); } else { let mut s2cr: usize = self.glb_rs0.as_ref().unwrap().S2CR[smr].get() as usize;