From f34c37f6c43b7c0031acc37816346dc64da6a35e Mon Sep 17 00:00:00 2001 From: Yuke Peng Date: Sat, 26 Jul 2025 09:56:52 +0800 Subject: [PATCH] Acquire IoMem only when r/w happened --- kernel/comps/pci/src/cfg_space.rs | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/kernel/comps/pci/src/cfg_space.rs b/kernel/comps/pci/src/cfg_space.rs index d86b3f850..f907a4638 100644 --- a/kernel/comps/pci/src/cfg_space.rs +++ b/kernel/comps/pci/src/cfg_space.rs @@ -13,6 +13,7 @@ use ostd::{ mm::{PodOnce, VmIoOnce}, Error, Result, }; +use spin::Once; use super::PciDeviceLocation; @@ -194,13 +195,13 @@ impl Bar { } /// Memory BAR -#[derive(Debug, Clone)] +#[derive(Debug)] pub struct MemoryBar { base: u64, size: u64, prefetchable: bool, address_length: AddrLen, - io_memory: IoMem, + io_memory: Once, } impl MemoryBar { @@ -227,7 +228,9 @@ impl MemoryBar { /// Grants I/O memory access pub fn io_mem(&self) -> &IoMem { - &self.io_memory + self.io_memory.call_once(|| { + IoMem::acquire((self.base as usize)..((self.base + self.size) as usize)).unwrap() + }) } /// Creates a memory BAR structure. @@ -327,7 +330,7 @@ impl MemoryBar { size, prefetchable, address_length, - io_memory: IoMem::acquire((base as usize)..((base + size) as usize)).unwrap(), + io_memory: Once::new(), }) } }