Allow reading PCI header through pcid socket
This commit is contained in:
@@ -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<PciHeader> {
|
||||
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<Vec<(PciFeature, FeatureStatus)>> {
|
||||
self.send(&PcidClientRequest::RequestFeatures)?;
|
||||
match self.recv()? {
|
||||
|
||||
@@ -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()))),
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user