From d0e90f5ded685862fd16a1ab6a82cf2450e8d617 Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Sun, 21 Jan 2024 19:35:39 +0100 Subject: [PATCH] Remove fetch_header from pcid_interface Most things are already stored in SubdriverArguments and the couple of things that aren't may change over time and thus should be read again each time they are accessed, while fetch_header would receive a fixed copy from pcid. --- ided/src/main.rs | 7 +++---- pcid/src/driver_interface/mod.rs | 11 +---------- pcid/src/main.rs | 7 ------- virtio-core/src/arch/x86_64.rs | 4 ++-- virtio-core/src/probe.rs | 5 ++--- 5 files changed, 8 insertions(+), 26 deletions(-) diff --git a/ided/src/main.rs b/ided/src/main.rs index f8e42c5deb..603a20baab 100644 --- a/ided/src/main.rs +++ b/ided/src/main.rs @@ -86,17 +86,16 @@ fn daemon(daemon: redox_daemon::Daemon) -> ! { info!("IDE PCI CONFIG: {:?}", pci_config); - let pci_header = pcid_handle.fetch_header().expect("ided: failed to fetch PCI header"); - let busmaster_base = match pci_header.get_bar(4) { + let busmaster_base = match pci_config.func.bars[4] { PciBar::Port(port) => port, other => panic!("TODO: IDE busmaster BAR {:#x?}", other), }; - let (primary, primary_irq) = if pci_header.interface() & 1 != 0 { + let (primary, primary_irq) = if pci_config.func.full_device_id.interface & 1 != 0 { panic!("TODO: IDE primary channel is PCI native"); } else { (Channel::primary_compat(busmaster_base).unwrap(), 14) }; - let (secondary, secondary_irq) = if pci_header.interface() & 1 != 0 { + let (secondary, secondary_irq) = if pci_config.func.full_device_id.interface & 1 != 0 { panic!("TODO: IDE secondary channel is PCI native"); } else { (Channel::secondary_compat(busmaster_base + 8).unwrap(), 15) diff --git a/pcid/src/driver_interface/mod.rs b/pcid/src/driver_interface/mod.rs index b7cb34a7f0..6357ec5a92 100644 --- a/pcid/src/driver_interface/mod.rs +++ b/pcid/src/driver_interface/mod.rs @@ -9,7 +9,7 @@ use thiserror::Error; pub use crate::pci::cap::Capability; pub use crate::pci::msi; -pub use crate::pci::{FullDeviceId, PciAddress, PciBar, PciHeader}; +pub use crate::pci::{FullDeviceId, PciAddress, PciBar}; pub mod irq_helpers; @@ -163,7 +163,6 @@ pub enum SetFeatureInfo { #[non_exhaustive] pub enum PcidClientRequest { RequestConfig, - RequestHeader, RequestFeatures, RequestCapabilities, EnableFeature(PciFeature), @@ -186,7 +185,6 @@ pub enum PcidServerResponseError { pub enum PcidClientResponse { Capabilities(Vec), Config(SubdriverArguments), - Header(PciHeader), AllFeatures(Vec<(PciFeature, FeatureStatus)>), FeatureEnabled(PciFeature), FeatureStatus(PciFeature, FeatureStatus), @@ -264,13 +262,6 @@ impl PcidServerHandle { } } - pub fn fetch_header(&mut self) -> Result { - self.send(&PcidClientRequest::RequestHeader)?; - match self.recv()? { - PcidClientResponse::Header(a) => Ok(a), - other => Err(PcidClientHandleError::InvalidResponse(other)), - } - } pub fn fetch_all_features(&mut self) -> Result> { self.send(&PcidClientRequest::RequestFeatures)?; match self.recv()? { diff --git a/pcid/src/main.rs b/pcid/src/main.rs index f8725429e2..74c3f80688 100644 --- a/pcid/src/main.rs +++ b/pcid/src/main.rs @@ -33,9 +33,7 @@ struct Args { } pub struct DriverHandler { - config: config::DriverConfig, addr: PciAddress, - header: PciHeader, capabilities: Vec<(u8, PciCapability)>, state: Arc, @@ -59,9 +57,6 @@ impl DriverHandler { PcidClientRequest::RequestConfig => { PcidClientResponse::Config(args.clone()) } - PcidClientRequest::RequestHeader => { - PcidClientResponse::Header(self.header.clone()) - } PcidClientRequest::RequestFeatures => { PcidClientResponse::AllFeatures(self.capabilities.iter().filter_map(|(_, capability)| match capability { PciCapability::Msi(msi) => Some((PciFeature::Msi, FeatureStatus::enabled(msi.enabled()))), @@ -409,8 +404,6 @@ fn handle_parsed_header(state: Arc, config: &Config, addr: PciAddress, he Ok(mut child) => { let driver_handler = DriverHandler { addr, - config: driver.clone(), - header, state: Arc::clone(&state), capabilities, }; diff --git a/virtio-core/src/arch/x86_64.rs b/virtio-core/src/arch/x86_64.rs index e8200da934..502bfcdafa 100644 --- a/virtio-core/src/arch/x86_64.rs +++ b/virtio-core/src/arch/x86_64.rs @@ -96,10 +96,10 @@ pub fn enable_msix(pcid_handle: &mut PcidServerHandle) -> Result { } pub fn probe_legacy_port_transport( - pci_header: &PciHeader, + pci_config: &SubdriverArguments, pcid_handle: &mut PcidServerHandle, ) -> Result { - if let PciBar::Port(port) = pci_header.get_bar(0) { + if let PciBar::Port(port) = pci_config.func.bars[0] { unsafe { syscall::iopl(3).expect("virtio: failed to set I/O privilege level") }; log::warn!("virtio: using legacy transport"); diff --git a/virtio-core/src/probe.rs b/virtio-core/src/probe.rs index c0c5ec3e1f..292bf429a6 100644 --- a/virtio-core/src/probe.rs +++ b/virtio-core/src/probe.rs @@ -61,7 +61,6 @@ fn enable_msix(pcid_handle: &mut PcidServerHandle) -> Result { /// This function panics if the device is not a virtio device. pub fn probe_device(pcid_handle: &mut PcidServerHandle) -> Result { let pci_config = pcid_handle.fetch_config()?; - let pci_header = pcid_handle.fetch_header()?; assert_eq!( pci_config.func.full_device_id.vendor_id, 6900, @@ -91,7 +90,7 @@ pub fn probe_device(pcid_handle: &mut PcidServerHandle) -> Result _ => continue, } - let bar = pci_header.get_bar(capability.bar as usize); + let bar = pci_config.func.bars[capability.bar as usize]; let addr = match bar { PciBar::Memory32(addr) => addr as usize, PciBar::Memory64(addr) => addr as usize, @@ -189,7 +188,7 @@ pub fn probe_device(pcid_handle: &mut PcidServerHandle) -> Result Ok(device) } else { - crate::arch::probe_legacy_port_transport(&pci_header, pcid_handle) + crate::arch::probe_legacy_port_transport(&pci_config, pcid_handle) } }