From e2a8255547a9fa7be888d4e3ad3ca41532c90291 Mon Sep 17 00:00:00 2001 From: Jeremy Soller Date: Wed, 7 Sep 2022 12:15:41 -0600 Subject: [PATCH] Allow reading PCI header through pcid socket --- pcid/src/driver_interface/mod.rs | 11 ++++++++++- pcid/src/main.rs | 3 +++ pcid/src/pci/class.rs | 4 +++- pcid/src/pci/header.rs | 6 ++++-- 4 files changed, 20 insertions(+), 4 deletions(-) diff --git a/pcid/src/driver_interface/mod.rs b/pcid/src/driver_interface/mod.rs index 0b0a5c1009..aedbf86f77 100644 --- a/pcid/src/driver_interface/mod.rs +++ b/pcid/src/driver_interface/mod.rs @@ -7,7 +7,7 @@ use std::os::unix::io::{FromRawFd, RawFd}; use serde::{Serialize, Deserialize, de::DeserializeOwned}; use thiserror::Error; -pub use crate::pci::PciBar; +pub use crate::pci::{PciBar, PciHeader}; pub use crate::pci::msi; pub mod irq_helpers; @@ -169,6 +169,7 @@ pub enum SetFeatureInfo { #[non_exhaustive] pub enum PcidClientRequest { RequestConfig, + RequestHeader, RequestFeatures, EnableFeature(PciFeature), FeatureStatus(PciFeature), @@ -187,6 +188,7 @@ pub enum PcidServerResponseError { #[non_exhaustive] pub enum PcidClientResponse { Config(SubdriverArguments), + Header(PciHeader), AllFeatures(Vec<(PciFeature, FeatureStatus)>), FeatureEnabled(PciFeature), FeatureStatus(PciFeature, FeatureStatus), @@ -252,6 +254,13 @@ impl PcidServerHandle { other => Err(PcidClientHandleError::InvalidResponse(other)), } } + 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 31f997afae..3dee0e8963 100644 --- a/pcid/src/main.rs +++ b/pcid/src/main.rs @@ -68,6 +68,9 @@ 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()))), diff --git a/pcid/src/pci/class.rs b/pcid/src/pci/class.rs index 98c503c2b3..042c354df0 100644 --- a/pcid/src/pci/class.rs +++ b/pcid/src/pci/class.rs @@ -1,4 +1,6 @@ -#[derive(Clone, Copy, Debug, PartialEq)] +use serde::{Deserialize, Serialize}; + +#[derive(Clone, Copy, Debug, PartialEq, Serialize, Deserialize)] pub enum PciClass { Legacy, Storage, diff --git a/pcid/src/pci/header.rs b/pcid/src/pci/header.rs index 8fef60b9d0..6139c45bb9 100644 --- a/pcid/src/pci/header.rs +++ b/pcid/src/pci/header.rs @@ -1,9 +1,10 @@ +use bitflags::bitflags; use byteorder::{LittleEndian, ByteOrder}; +use serde::{Serialize, Deserialize}; use super::func::ConfigReader; use super::class::PciClass; use super::bar::PciBar; -use bitflags::bitflags; #[derive(Debug, PartialEq)] pub enum PciHeaderError { @@ -13,6 +14,7 @@ pub enum PciHeaderError { bitflags! { /// Flags found in the status register of a PCI device + #[derive(Serialize, Deserialize)] pub struct PciHeaderType: u8 { /// A general PCI device (Type 0x01). const GENERAL = 0b00000000; @@ -27,7 +29,7 @@ bitflags! { } } -#[derive(Clone, Copy, Debug, PartialEq)] +#[derive(Clone, Copy, Debug, PartialEq, Serialize, Deserialize)] pub enum PciHeader { General { vendor_id: u16,