Struct devices::pci::msix::MsixConfig
source · pub struct MsixConfig {
table_entries: Vec<MsixTableEntry>,
pba_entries: Vec<u64>,
irq_vec: Vec<Option<IrqfdGsi>>,
masked: bool,
enabled: bool,
msi_device_socket: Tube,
msix_num: u16,
pci_id: u32,
device_name: String,
}
Expand description
Wrapper over MSI-X Capability Structure and MSI-X Tables
Fields§
§table_entries: Vec<MsixTableEntry>
§pba_entries: Vec<u64>
§irq_vec: Vec<Option<IrqfdGsi>>
§masked: bool
§enabled: bool
§msi_device_socket: Tube
§msix_num: u16
§pci_id: u32
§device_name: String
Implementations§
source§impl MsixConfig
impl MsixConfig
pub fn new( msix_vectors: u16, vm_socket: Tube, pci_id: u32, device_name: String ) -> Self
sourcepub fn num_vectors(&self) -> u16
pub fn num_vectors(&self) -> u16
Get the number of MSI-X vectors in this configuration.
sourcepub fn masked(&self) -> bool
pub fn masked(&self) -> bool
Check whether the Function Mask bit in Message Control word in set or not. if 1, all of the vectors associated with the function are masked, regardless of their per-vector Mask bit states. If 0, each vector’s Mask bit determines whether the vector is masked or not.
sourcepub fn table_masked(&self, index: usize) -> bool
pub fn table_masked(&self, index: usize) -> bool
Check whether the Function Mask bit in MSIX table Message Control word in set or not. If true, the vector is masked. If false, the vector is unmasked.
sourcepub fn enabled(&self) -> bool
pub fn enabled(&self) -> bool
Check whether the MSI-X Enable bit in Message Control word in set or not. if 1, the function is permitted to use MSI-X to request service.
sourcepub fn read_msix_capability(&self, data: u32) -> u32
pub fn read_msix_capability(&self, data: u32) -> u32
Read the MSI-X Capability Structure. The top 2 bits in Message Control word are emulated and all other bits are read only.
sourcepub fn write_msix_capability(&mut self, offset: u64, data: &[u8]) -> MsixStatus
pub fn write_msix_capability(&mut self, offset: u64, data: &[u8]) -> MsixStatus
Write to the MSI-X Capability Structure. Only the top 2 bits in Message Control Word are writable.
sourcepub fn snapshot(&mut self) -> Result<Value>
pub fn snapshot(&mut self) -> Result<Value>
Create a snapshot of the current MsixConfig struct for use in snapshotting.
sourcepub fn restore(&mut self, snapshot: Value) -> Result<(), MsixError>
pub fn restore(&mut self, snapshot: Value) -> Result<(), MsixError>
Restore a MsixConfig struct based on a snapshot. In short, this will restore all data exposed via MMIO, and recreate all MSI-X vectors (they will be re-wired to the irq chip).
sourcefn msix_restore_one(&mut self, index: usize, gsi: u32) -> Result<(), MsixError>
fn msix_restore_one(&mut self, index: usize, gsi: u32) -> Result<(), MsixError>
Restore the specified MSI-X vector.
Note: we skip the checks from MsixConfig::msix_enable_one because for an interrupt to be present in MsixConfigSnapshot::irq_gsi_vec, it must have passed those checks.
sourcefn msix_release_all(&mut self) -> Result<(), MsixError>
fn msix_release_all(&mut self) -> Result<(), MsixError>
On warm restore, there could already be MSIs registered. We need to release them in case the routing has changed (e.g. different data <-> GSI).
fn add_msi_route(&mut self, index: u16, gsi: u32) -> Result<(), MsixError>
fn msix_enable_all(&mut self) -> Result<(), MsixError>
fn msix_enable_one(&mut self, index: usize) -> Result<(), MsixError>
sourcepub fn read_msix_table(&self, offset: u64, data: &mut [u8])
pub fn read_msix_table(&self, offset: u64, data: &mut [u8])
Read MSI-X table
§Arguments
- ‘offset’ - the offset within the MSI-X Table
- ‘data’ - used to store the read results
For all accesses to MSI-X Table and MSI-X PBA fields, software must use aligned full DWORD or aligned full QWORD transactions; otherwise, the result is undefined.
location: DWORD3 DWORD2 DWORD1 DWORD0 entry 0: Vector Control Msg Data Msg Upper Addr Msg Addr entry 1: Vector Control Msg Data Msg Upper Addr Msg Addr entry 2: Vector Control Msg Data Msg Upper Addr Msg Addr …
sourcepub fn write_msix_table(&mut self, offset: u64, data: &[u8]) -> MsixStatus
pub fn write_msix_table(&mut self, offset: u64, data: &[u8]) -> MsixStatus
Write to MSI-X table
Message Address: the contents of this field specifies the address for the memory write transaction; different MSI-X vectors have different Message Address values Message Data: the contents of this field specifies the data driven on AD[31::00] during the memory write transaction’s data phase. Vector Control: only bit 0 (Mask Bit) is not reserved: when this bit is set, the function is prohibited from sending a message using this MSI-X Table entry.
sourcepub fn read_pba_entries(&self, offset: u64, data: &mut [u8])
pub fn read_pba_entries(&self, offset: u64, data: &mut [u8])
Read PBA Entries
§Arguments
- ‘offset’ - the offset within the PBA entries
- ‘data’ - used to store the read results
Pending Bits[63::00]: For each Pending Bit that is set, the function has a pending message for the associated MSI-X Table entry.
sourcepub fn write_pba_entries(&mut self, _offset: u64, _data: &[u8])
pub fn write_pba_entries(&mut self, _offset: u64, _data: &[u8])
Write to PBA Entries
Software should never write, and should only read Pending Bits. If software writes to Pending Bits, the result is undefined.
fn set_pba_bit(&mut self, vector: u16, set: bool)
fn get_pba_bit(&self, vector: u16) -> u8
fn inject_msix_and_clear_pba(&mut self, vector: usize)
sourcepub fn trigger(&mut self, vector: u16)
pub fn trigger(&mut self, vector: u16)
Inject virtual interrupt to the guest
§Arguments
- ‘vector’ - the index to the MSI-X Table entry
PCI Spec 3.0 6.8.3.5: while a vector is masked, the function is prohibited from sending the associated message, and the function must set the associated Pending bit whenever the function would otherwise send the message. When software unmasks a vector whose associated Pending bit is set, the function must schedule sending the associated message, and clear the Pending bit as soon as the message has been sent.
If the vector is unmasked, writing to irqfd which wakes up KVM to inject virtual interrupt to the guest.
sourcepub fn get_msi_socket(&self) -> RawDescriptor
pub fn get_msi_socket(&self) -> RawDescriptor
Return the raw descriptor of the MSI device socket
pub fn destroy(&mut self)
Trait Implementations§
source§impl AsRawDescriptor for MsixConfig
impl AsRawDescriptor for MsixConfig
source§fn as_raw_descriptor(&self) -> RawDescriptor
fn as_raw_descriptor(&self) -> RawDescriptor
source§impl PciCapConfig for MsixConfig
impl PciCapConfig for MsixConfig
source§fn read_reg(&self, reg_idx: usize) -> u32
fn read_reg(&self, reg_idx: usize) -> u32
PciConfiguration
’s register data.
reg_idx
- index into the capabilitysource§fn write_reg(
&mut self,
reg_idx: usize,
offset: u64,
data: &[u8]
) -> Option<Box<dyn PciCapConfigWriteResult>>
fn write_reg( &mut self, reg_idx: usize, offset: u64, data: &[u8] ) -> Option<Box<dyn PciCapConfigWriteResult>>
reg_idx
- index into PciConfiguration.registers.
offset
- PciConfiguration.registers is in unit of DWord, offset define byte
offset in the DWord.
data
- The data to write.source§fn set_cap_mapping(&mut self, _mapping: PciCapMapping)
fn set_cap_mapping(&mut self, _mapping: PciCapMapping)
PciCapMapping.set_reg
must be called to make the changes visible
to the guest.fn num_regs(&self) -> usize
Auto Trait Implementations§
impl RefUnwindSafe for MsixConfig
impl Send for MsixConfig
impl Sync for MsixConfig
impl Unpin for MsixConfig
impl UnwindSafe for MsixConfig
Blanket Implementations§
source§impl<T> AsRawDescriptors for Twhere
T: AsRawDescriptor,
impl<T> AsRawDescriptors for Twhere
T: AsRawDescriptor,
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait>
(where Trait: Downcast
) to Box<dyn Any>
. Box<dyn Any>
can
then be further downcast
into Box<ConcreteType>
where ConcreteType
implements Trait
.§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait>
(where Trait: Downcast
) to Rc<Any>
. Rc<Any>
can then be
further downcast
into Rc<ConcreteType>
where ConcreteType
implements Trait
.§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &Any
’s vtable from &Trait
’s.§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &mut Any
’s vtable from &mut Trait
’s.