pci_core/capabilities/
mod.rs

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