Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

virtio-pci: map BAR with the information from capabilities #1403

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 0 additions & 53 deletions src/drivers/virtio/env.rs

This file was deleted.

1 change: 0 additions & 1 deletion src/drivers/virtio/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
//! A module containing virtios core infrastructure for hermit-rs.
//!
//! The module contains virtios transport mechanisms, virtqueues and virtio specific errors
pub mod env;
pub mod transport;
pub mod virtqueue;

Expand Down
31 changes: 11 additions & 20 deletions src/drivers/virtio/transport/pci.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ use crate::drivers::virtio::error::VirtioError;
any(feature = "tcp", feature = "udp", feature = "vsock")
))]
use crate::drivers::virtio::transport::hardware;
use crate::drivers::virtio::transport::pci::PciBar as VirtioPciBar;
#[cfg(feature = "vsock")]
use crate::drivers::vsock::VirtioVsockDriver;

Expand Down Expand Up @@ -765,10 +766,7 @@ impl PciBar {
///
/// Returns ONLY Virtio specific capabilities, which allow to locate the actual capability
/// structures inside the memory areas, indicated by the BaseAddressRegisters (BAR's).
fn read_caps(
device: &PciDevice<PciConfigRegion>,
bars: &[PciBar],
) -> Result<Vec<PciCap>, PciError> {
fn read_caps(device: &PciDevice<PciConfigRegion>) -> Result<Vec<PciCap>, PciError> {
let device_id = device.device_id();

let capabilities = device
Expand All @@ -780,10 +778,14 @@ fn read_caps(
})
.map(|addr| CapData::read(addr, device.access()).unwrap())
.filter(|cap| cap.cfg_type != CapCfgType::Pci)
.map(|cap| PciCap {
bar: *bars.iter().find(|bar| bar.index == cap.bar).unwrap(),
dev_id: device_id,
cap,
.map(|cap| {
let slot = cap.bar;
let (addr, size) = device.memory_map_bar(slot, true).unwrap();
PciCap {
bar: VirtioPciBar::new(slot, addr.as_u64(), size.try_into().unwrap()),
dev_id: device_id,
cap,
}
})
.collect::<Vec<_>>();

Expand All @@ -795,11 +797,6 @@ fn read_caps(
}
}

/// Maps memory areas indicated by devices BAR's into virtual address space.
fn map_bars(device: &PciDevice<PciConfigRegion>) -> Result<Vec<PciBar>, PciError> {
crate::drivers::virtio::env::pci::map_bar_mem(device)
}

/// Checks if minimal set of capabilities is present.
///
/// INFO: Currently only checks if at least one common config struct has been found and mapped.
Expand All @@ -821,14 +818,8 @@ pub(crate) fn map_caps(device: &PciDevice<PciConfigRegion>) -> Result<UniCapsCol
return Err(PciError::NoCapPtr(device_id));
}

// Mapped memory areas are reachable through PciBar structs.
let bar_list = match map_bars(device) {
Ok(list) => list,
Err(pci_error) => return Err(pci_error),
};

// Get list of PciCaps pointing to capabilities
let cap_list = match read_caps(device, &bar_list) {
let cap_list = match read_caps(device) {
Ok(list) => list,
Err(pci_error) => return Err(pci_error),
};
Expand Down