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 chipset_device::pci::ByteEnabledDwordRead;
11use chipset_device::pci::ByteEnabledDwordWrite;
12use inspect::Inspect;
13use vmcore::save_restore::ProtobufSaveRestore;
14
15pub mod extended;
16pub mod msi_cap;
17pub mod msix;
18pub mod pci_express;
19pub mod read_only;
20
21/// A generic PCI configuration space capability structure.
22pub trait PciCapability: Send + Sync + Inspect + ProtobufSaveRestore {
23    /// A descriptive label for use in Save/Restore + Inspect output
24    fn label(&self) -> &str;
25
26    /// Returns the PCI capability ID for this capability
27    fn capability_id(&self) -> CapabilityId;
28
29    /// Length of the capability structure
30    fn len(&self) -> usize;
31
32    /// Read a byte-enabled DWORD at the given capability-relative offset.
33    /// The offset must be 32-bit aligned.
34    fn read(&self, offset: u16, value: ByteEnabledDwordRead<'_>);
35
36    /// Write a byte-enabled DWORD to the given capability-relative offset.
37    /// The offset must be 32-bit aligned.
38    fn write(&mut self, offset: u16, val: ByteEnabledDwordWrite);
39
40    /// Reset the capability
41    fn reset(&mut self);
42
43    // Specific downcast methods for known capability types
44
45    /// Downcast to PCI Express capability
46    fn as_pci_express(&self) -> Option<&pci_express::PciExpressCapability> {
47        None
48    }
49
50    /// Downcast to PCI Express capability (mutable)
51    fn as_pci_express_mut(&mut self) -> Option<&mut pci_express::PciExpressCapability> {
52        None
53    }
54
55    /// Downcast to MSI capability
56    fn as_msi_cap(&self) -> Option<&msi_cap::MsiCapability> {
57        None
58    }
59
60    /// Downcast to MSI capability (mutable)
61    fn as_msi_cap_mut(&mut self) -> Option<&mut msi_cap::MsiCapability> {
62        None
63    }
64}