From 498490b1b1dfd54c5b9c795b33d77236f8b72244 Mon Sep 17 00:00:00 2001 From: moce0627 <491745115@qq.com> Date: Thu, 31 Aug 2023 17:16:09 +0800 Subject: [PATCH] fix: smmu error --- src/arch/aarch64/smmu.rs | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/arch/aarch64/smmu.rs b/src/arch/aarch64/smmu.rs index 67e87f1..d57b4ed 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; -- Gitee