Skip to content

Commit

Permalink
fix(drivers): put PCI_DEVICES into mutex
Browse files Browse the repository at this point in the history
Signed-off-by: Martin Kröning <[email protected]>
  • Loading branch information
mkroening committed Oct 20, 2024
1 parent 9919b39 commit 5dd4373
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 21 deletions.
4 changes: 1 addition & 3 deletions src/arch/aarch64/kernel/pci.rs
Original file line number Diff line number Diff line change
Expand Up @@ -339,9 +339,7 @@ pub fn init() {
dev.set_irq(pin, line);
}

unsafe {
PCI_DEVICES.push(dev);
}
PCI_DEVICES.lock().push(dev);
}
}
}
Expand Down
4 changes: 1 addition & 3 deletions src/arch/x86_64/kernel/pci.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
}
}
Expand Down
27 changes: 12 additions & 15 deletions src/drivers/pci.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -42,7 +42,8 @@ use crate::drivers::vsock::VirtioVsockDriver;
#[allow(unused_imports)]
use crate::drivers::{Driver, InterruptHandlerQueue};

pub(crate) static mut PCI_DEVICES: Vec<PciDevice<PciConfigRegion>> = Vec::new();
pub(crate) static PCI_DEVICES: SpinMutex<Vec<PciDevice<PciConfigRegion>>> =
SpinMutex::new(Vec::new());
static mut PCI_DRIVERS: Vec<PciDriver> = Vec::new();

#[derive(Copy, Clone, Debug)]
Expand Down Expand Up @@ -301,7 +302,7 @@ impl<T: ConfigRegionAccess> fmt::Display for PciDevice<T> {
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);
}

Expand Down Expand Up @@ -463,12 +464,10 @@ pub(crate) fn get_filesystem_driver() -> Option<&'static InterruptTicketMutex<Vi
pub(crate) fn init() {
// virtio: 4.1.2 PCI Device Discovery
without_interrupts(|| {
for adapter in unsafe {
PCI_DEVICES.iter().filter(|x| {
let (vendor_id, device_id) = x.id();
vendor_id == 0x1AF4 && (0x1000..=0x107F).contains(&device_id)
})
} {
for adapter in PCI_DEVICES.lock().iter().filter(|x| {
let (vendor_id, device_id) = x.id();
vendor_id == 0x1AF4 && (0x1000..=0x107F).contains(&device_id)
}) {
info!(
"Found virtio device with device id {:#x}",
adapter.device_id()
Expand Down Expand Up @@ -498,12 +497,10 @@ pub(crate) fn init() {

// Searching for Realtek RTL8139, which is supported by Qemu
#[cfg(feature = "rtl8139")]
for adapter in unsafe {
PCI_DEVICES.iter().filter(|x| {
let (vendor_id, device_id) = x.id();
vendor_id == 0x10ec && (0x8138..=0x8139).contains(&device_id)
})
} {
for adapter in PCI_DEVICES.lock().iter().filter(|x| {
let (vendor_id, device_id) = x.id();
vendor_id == 0x10ec && (0x8138..=0x8139).contains(&device_id)
}) {
info!(
"Found Realtek network device with device id {:#x}",
adapter.device_id()
Expand Down

0 comments on commit 5dd4373

Please sign in to comment.