From a599a2c563b857c8c69ab512d3405c8fa6a12932 Mon Sep 17 00:00:00 2001 From: Ruihan Li Date: Fri, 23 Jan 2026 14:52:46 +0800 Subject: [PATCH] Disable BAR decoding when sizing PCI BARs --- kernel/comps/pci/src/common_device.rs | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/kernel/comps/pci/src/common_device.rs b/kernel/comps/pci/src/common_device.rs index 0ad8c76b0..9fd2ed334 100644 --- a/kernel/comps/pci/src/common_device.rs +++ b/kernel/comps/pci/src/common_device.rs @@ -103,10 +103,14 @@ impl PciCommonDevice { capabilities, }; - device.write_command( - device.read_command() | Command::MEMORY_SPACE | Command::BUS_MASTER | Command::IO_SPACE, - ); + // While setting up the BARs, we need to ensure that + // "Decode (I/O or memory) of the appropriate address space is disabled via the Command + // Register before sizing a Base Address register." + let command_val = device.read_command() | Command::BUS_MASTER; + device.write_command(command_val - (Command::MEMORY_SPACE | Command::IO_SPACE)); device.bar_manager = BarManager::new(device.header_type.device_type(), location); + device.write_command(command_val | (Command::MEMORY_SPACE | Command::IO_SPACE)); + device.capabilities = Capability::device_capabilities(&mut device); Some(device)