6 releases

0.3.2 May 7, 2024
0.3.1 Sep 26, 2022
0.3.0 Aug 30, 2022
0.2.0 Jun 28, 2022
0.1.0 Jan 11, 2022

#104 in Hardware support

Download history 111/week @ 2024-08-14 180/week @ 2024-08-21 107/week @ 2024-08-28 79/week @ 2024-09-04 92/week @ 2024-09-11 157/week @ 2024-09-18 175/week @ 2024-09-25 321/week @ 2024-10-02 157/week @ 2024-10-09 142/week @ 2024-10-16 160/week @ 2024-10-23 116/week @ 2024-10-30 59/week @ 2024-11-06 149/week @ 2024-11-13 144/week @ 2024-11-20 70/week @ 2024-11-27

441 downloads per month
Used in pcitool

MIT license

730KB
14K SLoC

PCI configuration space

PCI configuration space is the underlying way that the Conventional PCI, PCI-X and PCI Express perform auto configuration of the cards inserted into their bus.

This library implements decoding PCI configuration space and PCI Express extended configuration space.

Design

The main purpose of this library is to represent configuration space data as a hierarchical structures. Therefore, CPU and memory usage may not be optimal.

The library is divided into three parts:

Usage

# use pcics::{
#     DDR_OFFSET, ECS_OFFSET,
#     capabilities::{
#         bridge_subsystem_vendor_id::BridgeSubsystemVendorId, Capability, CapabilityKind,
#     },
#     extended_capabilities::{
#         vendor_specific_extended_capability::VendorSpecificExtendedCapability,
#         ExtendedCapability, ExtendedCapabilityKind,
#     },
#     Capabilities, ExtendedCapabilities, Header,
# };
let conf_space_data = include_bytes!(concat!(
    env!("CARGO_MANIFEST_DIR"),
    "/tests/data/device/8086_2030/config"
));

let header = Header::try_from(&conf_space_data[..DDR_OFFSET]).unwrap();
assert_eq!((0x8086, 0x2030), (header.vendor_id, header.device_id));

let mut caps = Capabilities::new(&conf_space_data[DDR_OFFSET..ECS_OFFSET], &header);
let BridgeSubsystemVendorId {
    subsystem_vendor_id,
    ..
} = caps
    .find_map(|cap| {
        if let Ok(Capability {
            kind: CapabilityKind::BridgeSubsystemVendorId(ssvid),
            ..
        }) = cap
        {
            Some(ssvid)
        } else {
            None
        }
    })
    .unwrap();
assert_eq!(0x8086, subsystem_vendor_id);

let mut ecaps = ExtendedCapabilities::new(&conf_space_data[ECS_OFFSET..]);
let VendorSpecificExtendedCapability { header, .. } = ecaps
    .find_map(|ecap| {
        if let Ok(ExtendedCapability {
            kind: ExtendedCapabilityKind::VendorSpecificExtendedCapability(vsec),
            ..
        }) = ecap
        {
            Some(vsec)
        } else {
            None
        }
    })
    .unwrap();
assert_eq!(0x0c, header.vsec_length);

More detailed usage in modules descriptions

Dependencies

~2MB
~43K SLoC