Skip to main content

pci_core/capabilities/
mod.rs

1// Copyright (c) Microsoft Corporation.
2// Licensed under the MIT License.
3
4//! PCI capabilities.
5
6pub use self::extended::PciExtendedCapability;
7pub use self::read_only::ReadOnlyCapability;
8
9use crate::spec::caps::CapabilityId;
10use inspect::Inspect;
11use vmcore::save_restore::ProtobufSaveRestore;
12
13pub mod extended;
14pub mod msi_cap;
15pub mod msix;
16pub mod pci_express;
17pub mod read_only;
18
19/// A generic PCI configuration space capability structure.
20pub trait PciCapability: Send + Sync + Inspect + ProtobufSaveRestore {
21    /// A descriptive label for use in Save/Restore + Inspect output
22    fn label(&self) -> &str;
23
24    /// Returns the PCI capability ID for this capability
25    fn capability_id(&self) -> CapabilityId;
26
27    /// Length of the capability structure
28    fn len(&self) -> usize;
29
30    /// Read a u32 at the given offset
31    fn read_u32(&self, offset: u16) -> u32;
32
33    /// Write a u32 at the given offset
34    fn write_u32(&mut self, offset: u16, val: u32);
35
36    /// Reset the capability
37    fn reset(&mut self);
38
39    // Specific downcast methods for known capability types
40
41    /// Downcast to PCI Express capability
42    fn as_pci_express(&self) -> Option<&pci_express::PciExpressCapability> {
43        None
44    }
45
46    /// Downcast to PCI Express capability (mutable)
47    fn as_pci_express_mut(&mut self) -> Option<&mut pci_express::PciExpressCapability> {
48        None
49    }
50
51    /// Downcast to MSI capability
52    fn as_msi_cap(&self) -> Option<&msi_cap::MsiCapability> {
53        None
54    }
55
56    /// Downcast to MSI capability (mutable)
57    fn as_msi_cap_mut(&mut self) -> Option<&mut msi_cap::MsiCapability> {
58        None
59    }
60}