diff --git a/pcid/src/config.rs b/pcid/src/config.rs index 8278f33c3c..c9610f667c 100644 --- a/pcid/src/config.rs +++ b/pcid/src/config.rs @@ -3,7 +3,7 @@ use std::ops::Range; use serde::Deserialize; -use crate::driver_interface::FullDeviceId; +use pcid_interface::FullDeviceId; #[derive(Clone, Debug, Default, Deserialize)] pub struct Config { diff --git a/pcid/src/driver_handler.rs b/pcid/src/driver_handler.rs index 4374df9387..7b3098101a 100644 --- a/pcid/src/driver_handler.rs +++ b/pcid/src/driver_handler.rs @@ -8,7 +8,6 @@ use log::{error, info}; use pci_types::capability::{MultipleMessageSupport, PciCapability}; use pci_types::{ConfigRegionAccess, PciAddress}; -use crate::driver_interface; use crate::State; pub struct DriverHandler { @@ -21,11 +20,11 @@ pub struct DriverHandler { impl DriverHandler { pub fn spawn( state: Arc, - func: driver_interface::PciFunction, + func: pcid_interface::PciFunction, capabilities: Vec, args: &[String], ) { - let subdriver_args = driver_interface::SubdriverArguments { func }; + let subdriver_args = pcid_interface::SubdriverArguments { func }; let mut args = args.iter(); if let Some(program) = args.next() { @@ -94,11 +93,12 @@ impl DriverHandler { fn respond( &mut self, - request: driver_interface::PcidClientRequest, - args: &driver_interface::SubdriverArguments, - ) -> driver_interface::PcidClientResponse { - use driver_interface::*; + request: pcid_interface::PcidClientRequest, + args: &pcid_interface::SubdriverArguments, + ) -> pcid_interface::PcidClientResponse { + use pcid_interface::*; + #[forbid(non_exhaustive_omitted_patterns)] match request { PcidClientRequest::RequestVendorCapabilities => PcidClientResponse::VendorCapabilities( self.capabilities @@ -320,6 +320,7 @@ impl DriverHandler { ); } } + _ => unreachable!(), }, PcidClientRequest::ReadConfig(offset) => { let value = unsafe { self.state.pcie.read(self.addr, offset) }; @@ -331,15 +332,16 @@ impl DriverHandler { } return PcidClientResponse::WriteConfig; } + _ => unreachable!(), } } fn handle_spawn( mut self, pcid_to_client_write: usize, pcid_from_client_read: usize, - args: driver_interface::SubdriverArguments, + args: pcid_interface::SubdriverArguments, ) { - use driver_interface::*; + use pcid_interface::*; let mut pcid_to_client = unsafe { File::from_raw_fd(pcid_to_client_write as RawFd) }; let mut pcid_from_client = unsafe { File::from_raw_fd(pcid_from_client_read as RawFd) }; diff --git a/pcid/src/driver_interface/cap.rs b/pcid/src/driver_interface/cap.rs index d03e6ff520..aa3f5540de 100644 --- a/pcid/src/driver_interface/cap.rs +++ b/pcid/src/driver_interface/cap.rs @@ -8,7 +8,7 @@ pub struct VendorSpecificCapability { } impl VendorSpecificCapability { - pub(crate) unsafe fn parse( + pub unsafe fn parse( addr: PciCapabilityAddress, access: &dyn ConfigRegionAccess, ) -> Self { diff --git a/pcid/src/driver_interface/id.rs b/pcid/src/driver_interface/id.rs index 307efc955a..7b4ec84444 100644 --- a/pcid/src/driver_interface/id.rs +++ b/pcid/src/driver_interface/id.rs @@ -13,7 +13,7 @@ pub struct FullDeviceId { } impl FullDeviceId { - pub(crate) fn display(&self) -> String { + pub fn display(&self) -> String { let mut string = format!( "{:>04X}:{:>04X} {:>02X}.{:>02X}.{:>02X}.{:>02X} {:?}", self.vendor_id, diff --git a/pcid/src/driver_interface/irq_helpers.rs b/pcid/src/driver_interface/irq_helpers.rs index 2624be2951..82f444eabe 100644 --- a/pcid/src/driver_interface/irq_helpers.rs +++ b/pcid/src/driver_interface/irq_helpers.rs @@ -194,5 +194,5 @@ pub fn allocate_single_interrupt_vector_for_msi(cpu_id: usize) -> (MsiAddrAndDat let msg_data = x86_msix::message_data_edge_triggered(x86_msix::DeliveryMode::Fixed, vector); - (MsiAddrAndData::new(addr, msg_data), interrupt_handle) + (MsiAddrAndData { addr, data: msg_data }, interrupt_handle) } diff --git a/pcid/src/driver_interface/mod.rs b/pcid/src/driver_interface/mod.rs index fd9792a270..ece101d3bb 100644 --- a/pcid/src/driver_interface/mod.rs +++ b/pcid/src/driver_interface/mod.rs @@ -21,7 +21,7 @@ pub mod irq_helpers; pub mod msi; #[derive(Clone, Copy, Debug, Serialize, Deserialize)] -pub struct LegacyInterruptLine(pub(crate) u8); +pub struct LegacyInterruptLine(#[doc(hidden)] pub u8); impl LegacyInterruptLine { /// Get an IRQ handle for this interrupt line. @@ -257,7 +257,8 @@ pub struct PciFunctionHandle { mapped_bars: [Option; 6], } -pub(crate) fn send(w: &mut W, message: &T) -> Result<()> { +#[doc(hidden)] +pub fn send(w: &mut W, message: &T) -> Result<()> { let mut data = Vec::new(); bincode::serialize_into(&mut data, message)?; let length_bytes = u64::to_le_bytes(data.len() as u64); @@ -265,7 +266,8 @@ pub(crate) fn send(w: &mut W, message: &T) -> Result<()> w.write_all(&data)?; Ok(()) } -pub(crate) fn recv(r: &mut R) -> Result { +#[doc(hidden)] +pub fn recv(r: &mut R) -> Result { let mut length_bytes = [0u8; 8]; r.read_exact(&mut length_bytes)?; let length = u64::from_le_bytes(length_bytes); diff --git a/pcid/src/driver_interface/msi.rs b/pcid/src/driver_interface/msi.rs index 0a625d53e0..cba4d21399 100644 --- a/pcid/src/driver_interface/msi.rs +++ b/pcid/src/driver_interface/msi.rs @@ -11,14 +11,8 @@ use syscall::{Io, Mmio}; /// For MSI-X you can have a single [MsiEntry] for each interrupt vector. #[derive(Debug, Default, Serialize, Deserialize)] pub struct MsiAddrAndData { - pub(crate) addr: u64, - pub(crate) data: u32, -} - -impl MsiAddrAndData { - pub fn new(addr: u64, data: u32) -> Self { - MsiAddrAndData { addr, data } - } + pub addr: u64, + pub data: u32, } #[derive(Debug, Serialize, Deserialize)] diff --git a/pcid/src/main.rs b/pcid/src/main.rs index 7a6df7d091..e392ba37b0 100644 --- a/pcid/src/main.rs +++ b/pcid/src/main.rs @@ -1,3 +1,5 @@ +#![feature(non_exhaustive_omitted_patterns_lint)] + use std::fs::{metadata, read_dir, File}; use std::io::prelude::*; use std::sync::{Arc, Mutex}; @@ -13,12 +15,11 @@ use structopt::StructOpt; use crate::cfg_access::Pcie; use crate::config::Config; -use crate::driver_interface::{FullDeviceId, LegacyInterruptLine, PciBar}; +use pcid_interface::{FullDeviceId, LegacyInterruptLine, PciBar}; mod cfg_access; mod config; mod driver_handler; -mod driver_interface; #[derive(StructOpt)] #[structopt(about)] @@ -150,7 +151,7 @@ fn handle_parsed_header( capabilities ); - let func = driver_interface::PciFunction { + let func = pcid_interface::PciFunction { bars, addr: endpoint_header.header().address(), legacy_interrupt_line: if legacy_interrupt_enabled {