From 5dd4373623238c70a90876276c693aeee169a4f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Kr=C3=B6ning?= Date: Sun, 20 Oct 2024 18:47:25 +0200 Subject: [PATCH] fix(drivers): put `PCI_DEVICES` into mutex MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Martin Kröning --- src/arch/aarch64/kernel/pci.rs | 4 +--- src/arch/x86_64/kernel/pci.rs | 4 +--- src/drivers/pci.rs | 27 ++++++++++++--------------- 3 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/arch/aarch64/kernel/pci.rs b/src/arch/aarch64/kernel/pci.rs index e8f2f981e1..4645babe35 100644 --- a/src/arch/aarch64/kernel/pci.rs +++ b/src/arch/aarch64/kernel/pci.rs @@ -339,9 +339,7 @@ pub fn init() { dev.set_irq(pin, line); } - unsafe { - PCI_DEVICES.push(dev); - } + PCI_DEVICES.lock().push(dev); } } } diff --git a/src/arch/x86_64/kernel/pci.rs b/src/arch/x86_64/kernel/pci.rs index 2f44968791..e32fc2c651 100644 --- a/src/arch/x86_64/kernel/pci.rs +++ b/src/arch/x86_64/kernel/pci.rs @@ -62,9 +62,7 @@ pub(crate) fn init() { let (device_id, vendor_id) = header.id(pci_config); if device_id != u16::MAX && vendor_id != u16::MAX { - unsafe { - PCI_DEVICES.push(PciDevice::new(pci_address, pci_config)); - } + PCI_DEVICES.lock().push(PciDevice::new(pci_address, pci_config)); } } } diff --git a/src/drivers/pci.rs b/src/drivers/pci.rs index ed9ff8477d..9b896c1dca 100644 --- a/src/drivers/pci.rs +++ b/src/drivers/pci.rs @@ -6,9 +6,9 @@ use core::fmt; use ahash::RandomState; use hashbrown::HashMap; -use hermit_sync::without_interrupts; #[cfg(any(feature = "tcp", feature = "udp", feature = "fuse", feature = "vsock"))] use hermit_sync::InterruptTicketMutex; +use hermit_sync::{without_interrupts, SpinMutex}; use pci_types::capability::CapabilityIterator; use pci_types::{ Bar, CommandRegister, ConfigRegionAccess, DeviceId, EndpointHeader, InterruptLine, @@ -42,7 +42,8 @@ use crate::drivers::vsock::VirtioVsockDriver; #[allow(unused_imports)] use crate::drivers::{Driver, InterruptHandlerQueue}; -pub(crate) static mut PCI_DEVICES: Vec> = Vec::new(); +pub(crate) static PCI_DEVICES: SpinMutex>> = + SpinMutex::new(Vec::new()); static mut PCI_DRIVERS: Vec = Vec::new(); #[derive(Copy, Clone, Debug)] @@ -301,7 +302,7 @@ impl fmt::Display for PciDevice { pub(crate) fn print_information() { infoheader!(" PCI BUS INFORMATION "); - for adapter in unsafe { PCI_DEVICES.iter() } { + for adapter in PCI_DEVICES.lock().iter() { info!("{}", adapter); } @@ -463,12 +464,10 @@ pub(crate) fn get_filesystem_driver() -> Option<&'static InterruptTicketMutex