diff --git a/audio/ac97d/src/main.rs b/audio/ac97d/src/main.rs index 846a8af1a0..9066acc52a 100644 --- a/audio/ac97d/src/main.rs +++ b/audio/ac97d/src/main.rs @@ -65,11 +65,9 @@ fn setup_logging() -> Option<&'static RedoxLogger> { } fn main() { - let mut pcid_handle = + let pcid_handle = PciFunctionHandle::connect_default().expect("ac97d: failed to setup channel to pcid"); - let pci_config = pcid_handle - .fetch_config() - .expect("ac97d: failed to fetch config"); + let pci_config = pcid_handle.config(); let mut name = pci_config.func.name(); name.push_str("_ac97"); diff --git a/audio/ihdad/src/main.rs b/audio/ihdad/src/main.rs index a7ba09d801..820b5d2cc1 100755 --- a/audio/ihdad/src/main.rs +++ b/audio/ihdad/src/main.rs @@ -77,7 +77,7 @@ fn setup_logging() -> Option<&'static RedoxLogger> { #[cfg(target_arch = "x86_64")] fn get_int_method(pcid_handle: &mut PciFunctionHandle) -> File { - let pci_config = pcid_handle.fetch_config().expect("ihdad: failed to fetch config"); + let pci_config = pcid_handle.config(); let all_pci_features = pcid_handle.fetch_all_features().expect("ihdad: failed to fetch pci features"); log::debug!("PCI FEATURES: {:?}", all_pci_features); @@ -122,7 +122,7 @@ fn get_int_method(pcid_handle: &mut PciFunctionHandle) -> File { //TODO: MSI on non-x86_64? #[cfg(not(target_arch = "x86_64"))] fn get_int_method(pcid_handle: &mut PciFunctionHandle) -> File { - let pci_config = pcid_handle.fetch_config().expect("ihdad: failed to fetch config"); + let pci_config = pcid_handle.config(); if let Some(irq) = pci_config.func.legacy_interrupt_line { // legacy INTx# interrupt pins. @@ -137,7 +137,7 @@ fn daemon(daemon: redox_daemon::Daemon) -> ! { let mut pcid_handle = PciFunctionHandle::connect_default().expect("ihdad: failed to setup channel to pcid"); - let pci_config = pcid_handle.fetch_config().expect("ihdad: failed to fetch config"); + let pci_config = pcid_handle.config(); let mut name = pci_config.func.name(); name.push_str("_ihda"); diff --git a/graphics/bgad/src/main.rs b/graphics/bgad/src/main.rs index b03f81a2f0..c4832e8560 100644 --- a/graphics/bgad/src/main.rs +++ b/graphics/bgad/src/main.rs @@ -16,11 +16,9 @@ mod bga; mod scheme; fn main() { - let mut pcid_handle = + let pcid_handle = PciFunctionHandle::connect_default().expect("bgad: failed to setup channel to pcid"); - let pci_config = pcid_handle - .fetch_config() - .expect("bgad: failed to fetch config"); + let pci_config = pcid_handle.config(); let mut name = pci_config.func.name(); name.push_str("_bga"); diff --git a/graphics/virtio-gpud/src/main.rs b/graphics/virtio-gpud/src/main.rs index 3fbeb0681d..938ec8c817 100644 --- a/graphics/virtio-gpud/src/main.rs +++ b/graphics/virtio-gpud/src/main.rs @@ -414,7 +414,7 @@ fn deamon(deamon: redox_daemon::Daemon) -> anyhow::Result<()> { // Double check that we have the right device. // // 0x1050 - virtio-gpu - let pci_config = pcid_handle.fetch_config()?; + let pci_config = pcid_handle.config(); assert_eq!(pci_config.func.full_device_id.device_id, 0x1050); log::info!("virtio-gpu: initiating startup sequence :^)"); diff --git a/net/e1000d/src/main.rs b/net/e1000d/src/main.rs index 005770f09d..7e7bb90ade 100644 --- a/net/e1000d/src/main.rs +++ b/net/e1000d/src/main.rs @@ -12,11 +12,9 @@ use syscall::EventFlags; pub mod device; fn main() { - let mut pcid_handle = + let pcid_handle = PciFunctionHandle::connect_default().expect("e1000d: failed to setup channel to pcid"); - let pci_config = pcid_handle - .fetch_config() - .expect("e1000d: failed to fetch config"); + let pci_config = pcid_handle.config(); let mut name = pci_config.func.name(); name.push_str("_e1000"); diff --git a/net/ixgbed/src/main.rs b/net/ixgbed/src/main.rs index a9fe183a79..0b8640dafc 100644 --- a/net/ixgbed/src/main.rs +++ b/net/ixgbed/src/main.rs @@ -14,11 +14,9 @@ pub mod device; mod ixgbe; fn main() { - let mut pcid_handle = + let pcid_handle = PciFunctionHandle::connect_default().expect("ixgbed: failed to setup channel to pcid"); - let pci_config = pcid_handle - .fetch_config() - .expect("ixgbed: failed to fetch config"); + let pci_config = pcid_handle.config(); let mut name = pci_config.func.name(); name.push_str("_ixgbe"); diff --git a/net/rtl8139d/src/main.rs b/net/rtl8139d/src/main.rs index 2eb17379b8..d0893aec93 100644 --- a/net/rtl8139d/src/main.rs +++ b/net/rtl8139d/src/main.rs @@ -96,7 +96,7 @@ impl MappedMsixRegs { #[cfg(target_arch = "x86_64")] fn get_int_method(pcid_handle: &mut PciFunctionHandle) -> File { - let pci_config = pcid_handle.fetch_config().expect("rtl8139d: failed to fetch config"); + let pci_config = pcid_handle.config(); let all_pci_features = pcid_handle.fetch_all_features().expect("rtl8139d: failed to fetch pci features"); log::info!("PCI FEATURES: {:?}", all_pci_features); @@ -178,7 +178,7 @@ fn get_int_method(pcid_handle: &mut PciFunctionHandle) -> File { //TODO: MSI on non-x86_64? #[cfg(not(target_arch = "x86_64"))] fn get_int_method(pcid_handle: &mut PciFunctionHandle) -> File { - let pci_config = pcid_handle.fetch_config().expect("rtl8139d: failed to fetch config"); + let pci_config = pcid_handle.config(); if let Some(irq) = pci_config.func.legacy_interrupt_line { // legacy INTx# interrupt pins. @@ -211,7 +211,7 @@ fn daemon(daemon: redox_daemon::Daemon) -> ! { let mut pcid_handle = PciFunctionHandle::connect_default().expect("rtl8139d: failed to setup channel to pcid"); - let pci_config = pcid_handle.fetch_config().expect("rtl8139d: failed to fetch config"); + let pci_config = pcid_handle.config(); let mut name = pci_config.func.name(); name.push_str("_rtl8139"); diff --git a/net/rtl8168d/src/main.rs b/net/rtl8168d/src/main.rs index 45a16d3ca5..b2ec6f69b5 100644 --- a/net/rtl8168d/src/main.rs +++ b/net/rtl8168d/src/main.rs @@ -91,7 +91,7 @@ impl MappedMsixRegs { #[cfg(target_arch = "x86_64")] fn get_int_method(pcid_handle: &mut PciFunctionHandle) -> File { - let pci_config = pcid_handle.fetch_config().expect("rtl8168d: failed to fetch config"); + let pci_config = pcid_handle.config(); let all_pci_features = pcid_handle.fetch_all_features().expect("rtl8168d: failed to fetch pci features"); log::info!("PCI FEATURES: {:?}", all_pci_features); @@ -173,7 +173,7 @@ fn get_int_method(pcid_handle: &mut PciFunctionHandle) -> File { //TODO: MSI on non-x86_64? #[cfg(not(target_arch = "x86_64"))] fn get_int_method(pcid_handle: &mut PciFunctionHandle) -> File { - let pci_config = pcid_handle.fetch_config().expect("rtl8168d: failed to fetch config"); + let pci_config = pcid_handle.config(); if let Some(irq) = pci_config.func.legacy_interrupt_line { // legacy INTx# interrupt pins. @@ -206,7 +206,7 @@ fn daemon(daemon: redox_daemon::Daemon) -> ! { let mut pcid_handle = PciFunctionHandle::connect_default().expect("rtl8168d: failed to setup channel to pcid"); - let pci_config = pcid_handle.fetch_config().expect("rtl8168d: failed to fetch config"); + let pci_config = pcid_handle.config(); let mut name = pci_config.func.name(); name.push_str("_rtl8168"); diff --git a/net/virtio-netd/src/main.rs b/net/virtio-netd/src/main.rs index d413e62da8..76e07b160f 100644 --- a/net/virtio-netd/src/main.rs +++ b/net/virtio-netd/src/main.rs @@ -33,7 +33,7 @@ fn deamon(daemon: redox_daemon::Daemon) -> Result<(), Box // Double check that we have the right device. // // 0x1000 - virtio-net - let pci_config = pcid_handle.fetch_config()?; + let pci_config = pcid_handle.config(); assert_eq!(pci_config.func.full_device_id.device_id, 0x1000); log::info!("virtio-net: initiating startup sequence :^)"); diff --git a/pcid/src/driver_interface/mod.rs b/pcid/src/driver_interface/mod.rs index 6f92124b53..5f57c343ad 100644 --- a/pcid/src/driver_interface/mod.rs +++ b/pcid/src/driver_interface/mod.rs @@ -230,6 +230,7 @@ pub enum PcidClientResponse { pub struct PciFunctionHandle { pcid_to_client: File, pcid_from_client: File, + config: SubdriverArguments, } pub(crate) fn send(w: &mut W, message: &T) -> Result<()> { @@ -258,9 +259,19 @@ impl PciFunctionHandle { let pcid_to_client_fd = env::var("PCID_TO_CLIENT_FD")?.parse::().map_err(PcidClientHandleError::EnvValidityError)?; let pcid_from_client_fd = env::var("PCID_FROM_CLIENT_FD")?.parse::().map_err(PcidClientHandleError::EnvValidityError)?; + let mut pcid_to_client = unsafe { File::from_raw_fd(pcid_to_client_fd) }; + let mut pcid_from_client = unsafe { File::from_raw_fd(pcid_from_client_fd) }; + + send(&mut pcid_from_client, &PcidClientRequest::RequestConfig)?; + let config = match recv(&mut pcid_to_client)? { + PcidClientResponse::Config(a) => a, + other => return Err(PcidClientHandleError::InvalidResponse(other)), + }; + Ok(Self { - pcid_to_client: unsafe { File::from_raw_fd(pcid_to_client_fd) }, - pcid_from_client: unsafe { File::from_raw_fd(pcid_from_client_fd) }, + pcid_to_client, + pcid_from_client, + config, }) } fn send(&mut self, req: &PcidClientRequest) -> Result<()> { @@ -269,12 +280,8 @@ impl PciFunctionHandle { fn recv(&mut self) -> Result { recv(&mut self.pcid_to_client) } - pub fn fetch_config(&mut self) -> Result { - self.send(&PcidClientRequest::RequestConfig)?; - match self.recv()? { - PcidClientResponse::Config(a) => Ok(a), - other => Err(PcidClientHandleError::InvalidResponse(other)), - } + pub fn config(&self) -> SubdriverArguments { + self.config.clone() } pub fn get_vendor_capabilities(&mut self) -> Result> { diff --git a/storage/ahcid/src/main.rs b/storage/ahcid/src/main.rs index a912de71a5..1947c02094 100644 --- a/storage/ahcid/src/main.rs +++ b/storage/ahcid/src/main.rs @@ -71,11 +71,9 @@ fn main() { } fn daemon(daemon: redox_daemon::Daemon) -> ! { - let mut pcid_handle = + let pcid_handle = PciFunctionHandle::connect_default().expect("ahcid: failed to setup channel to pcid"); - let pci_config = pcid_handle - .fetch_config() - .expect("ahcid: failed to fetch config"); + let pci_config = pcid_handle.config(); let mut name = pci_config.func.name(); name.push_str("_ahci"); diff --git a/storage/ided/src/main.rs b/storage/ided/src/main.rs index b8dd79a70d..c4723fad54 100644 --- a/storage/ided/src/main.rs +++ b/storage/ided/src/main.rs @@ -74,10 +74,10 @@ fn main() { } fn daemon(daemon: redox_daemon::Daemon) -> ! { - let mut pcid_handle = + let pcid_handle = PciFunctionHandle::connect_default().expect("ided: failed to setup channel to pcid"); - let pci_config = pcid_handle.fetch_config().expect("ided: failed to fetch config"); + let pci_config = pcid_handle.config(); let mut name = pci_config.func.name(); name.push_str("_ide"); diff --git a/storage/nvmed/src/main.rs b/storage/nvmed/src/main.rs index f00ef3bbb9..b6abc0e856 100644 --- a/storage/nvmed/src/main.rs +++ b/storage/nvmed/src/main.rs @@ -247,9 +247,7 @@ fn main() { fn daemon(daemon: redox_daemon::Daemon) -> ! { let mut pcid_handle = PciFunctionHandle::connect_default().expect("nvmed: failed to setup channel to pcid"); - let pci_config = pcid_handle - .fetch_config() - .expect("nvmed: failed to fetch config"); + let pci_config = pcid_handle.config(); let scheme_name = format!("disk.{}-nvme", pci_config.func.name()); diff --git a/storage/virtio-blkd/src/main.rs b/storage/virtio-blkd/src/main.rs index 289a4d91a1..8d819db570 100644 --- a/storage/virtio-blkd/src/main.rs +++ b/storage/virtio-blkd/src/main.rs @@ -114,7 +114,7 @@ fn deamon(deamon: redox_daemon::Daemon) -> anyhow::Result<()> { // Double check that we have the right device. // // 0x1001 - virtio-blk - let pci_config = pcid_handle.fetch_config()?; + let pci_config = pcid_handle.config(); assert_eq!(pci_config.func.full_device_id.device_id, 0x1001); log::info!("virtio-blk: initiating startup sequence :^)"); diff --git a/vboxd/src/main.rs b/vboxd/src/main.rs index 16b1dae847..9a1ab423db 100644 --- a/vboxd/src/main.rs +++ b/vboxd/src/main.rs @@ -180,11 +180,9 @@ impl VboxGuestInfo { } fn main() { - let mut pcid_handle = + let pcid_handle = PciFunctionHandle::connect_default().expect("vboxd: failed to setup channel to pcid"); - let pci_config = pcid_handle - .fetch_config() - .expect("vboxd: failed to fetch config"); + let pci_config = pcid_handle.config(); let mut name = pci_config.func.name(); name.push_str("_vbox"); diff --git a/virtio-core/src/arch/x86_64.rs b/virtio-core/src/arch/x86_64.rs index 5413b2f169..c804ab9dfa 100644 --- a/virtio-core/src/arch/x86_64.rs +++ b/virtio-core/src/arch/x86_64.rs @@ -9,7 +9,7 @@ use crate::{probe::MappedMsixRegs, MSIX_PRIMARY_VECTOR}; use pcid_interface::*; pub fn enable_msix(pcid_handle: &mut PciFunctionHandle) -> Result { - let pci_config = pcid_handle.fetch_config()?; + let pci_config = pcid_handle.config(); // Extended message signaled interrupts. let msix_info = match pcid_handle.feature_info(PciFeature::MsiX)? { diff --git a/virtio-core/src/probe.rs b/virtio-core/src/probe.rs index 7da40a958d..984acd88d2 100644 --- a/virtio-core/src/probe.rs +++ b/virtio-core/src/probe.rs @@ -60,7 +60,7 @@ fn enable_msix(pcid_handle: &mut PciFunctionHandle) -> Result { /// ## Panics /// This function panics if the device is not a virtio device. pub fn probe_device(pcid_handle: &mut PciFunctionHandle) -> Result { - let pci_config = pcid_handle.fetch_config()?; + let pci_config = pcid_handle.config(); assert_eq!( pci_config.func.full_device_id.vendor_id, 6900, diff --git a/xhcid/src/main.rs b/xhcid/src/main.rs index 9a1bb570f4..fc441b03bc 100644 --- a/xhcid/src/main.rs +++ b/xhcid/src/main.rs @@ -86,7 +86,7 @@ fn setup_logging(name: &str) -> Option<&'static RedoxLogger> { #[cfg(target_arch = "x86_64")] fn get_int_method(pcid_handle: &mut PciFunctionHandle, bar0_address: usize) -> (Option, InterruptMethod) { - let pci_config = pcid_handle.fetch_config().expect("xhcid: failed to fetch config"); + let pci_config = pcid_handle.config(); let all_pci_features = pcid_handle.fetch_all_features().expect("xhcid: failed to fetch pci features"); log::debug!("XHCI PCI FEATURES: {:?}", all_pci_features); @@ -168,7 +168,7 @@ fn get_int_method(pcid_handle: &mut PciFunctionHandle, bar0_address: usize) -> ( //TODO: MSI on non-x86_64? #[cfg(not(target_arch = "x86_64"))] fn get_int_method(pcid_handle: &mut PciFunctionHandle, address: usize) -> (Option, InterruptMethod) { - let pci_config = pcid_handle.fetch_config().expect("xhcid: failed to fetch config"); + let pci_config = pcid_handle.config(); if let Some(irq) = pci_config.func.legacy_interrupt_line { // legacy INTx# interrupt pins. @@ -184,8 +184,8 @@ fn main() { } fn daemon(daemon: redox_daemon::Daemon) -> ! { - let mut pcid_handle = PciFunctionHandle::connect_default().expect("xhcid: failed to setup channel to pcid"); - let pci_config = pcid_handle.fetch_config().expect("xhcid: failed to fetch config"); + let pcid_handle = PciFunctionHandle::connect_default().expect("xhcid: failed to setup channel to pcid"); + let pci_config = pcid_handle.config(); let mut name = pci_config.func.name(); name.push_str("_xhci");