pcid: Move VendorSpecificCapability form pci to driver_interface

This commit is contained in:
bjorn3
2024-06-16 15:21:51 +02:00
parent 5c9bbb5c96
commit ba6224bc27
3 changed files with 2 additions and 2 deletions
+41
View File
@@ -0,0 +1,41 @@
use pci_types::capability::PciCapabilityAddress;
use pci_types::ConfigRegionAccess;
use serde::{Deserialize, Serialize};
#[derive(Clone, Debug, Eq, Hash, PartialEq, Serialize, Deserialize)]
pub struct VendorSpecificCapability {
pub data: Vec<u8>,
}
impl VendorSpecificCapability {
pub(crate) unsafe fn parse(
addr: PciCapabilityAddress,
access: &dyn ConfigRegionAccess,
) -> Self {
let dword = access.read(addr.address, addr.offset);
let next = (dword >> 8) & 0xFF;
let length = ((dword >> 16) & 0xFF) as u16;
log::info!(
"Vendor specific offset: {:#02x} next: {next:#02x} cap len: {length:#02x}",
addr.offset
);
let data = if length > 0 {
assert!(
length > 3 && length % 4 == 0,
"invalid range length: {}",
length
);
let mut raw_data = {
(addr.offset..addr.offset + length)
.step_by(4)
.flat_map(|offset| access.read(addr.address, offset).to_le_bytes())
.collect::<Vec<u8>>()
};
raw_data.drain(3..).collect()
} else {
log::warn!("Vendor specific capability is invalid");
Vec::new()
};
VendorSpecificCapability { data }
}
}
+2 -1
View File
@@ -9,13 +9,14 @@ use std::os::unix::io::{FromRawFd, RawFd};
use serde::{de::DeserializeOwned, Deserialize, Serialize};
use thiserror::Error;
pub use crate::pci::cap::VendorSpecificCapability;
pub use crate::pci::msi;
pub use crate::pci::PciAddress;
pub use bar::PciBar;
pub use cap::VendorSpecificCapability;
pub use id::FullDeviceId;
mod bar;
pub mod cap;
mod id;
pub mod irq_helpers;