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

source

pub fn new( msix_vectors: u16, vm_socket: Tube, pci_id: u32, device_name: String ) -> Self

source

pub fn num_vectors(&self) -> u16

Get the number of MSI-X vectors in this configuration.

source

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.

source

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.

source

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.

source

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.

source

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.

source

pub fn snapshot(&mut self) -> Result<Value>

Create a snapshot of the current MsixConfig struct for use in snapshotting.

source

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).

source

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.

source

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).

source

fn add_msi_route(&mut self, index: u16, gsi: u32) -> Result<(), MsixError>

source

fn msix_enable_all(&mut self) -> Result<(), MsixError>

source

fn msix_enable_one(&mut self, index: usize) -> Result<(), MsixError>

source

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 …

source

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.

source

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.

source

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.

source

fn set_pba_bit(&mut self, vector: u16, set: bool)

source

fn get_pba_bit(&self, vector: u16) -> u8

source

fn inject_msix_and_clear_pba(&mut self, vector: usize)

source

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.

source

pub fn get_msi_socket(&self) -> RawDescriptor

Return the raw descriptor of the MSI device socket

source

pub fn get_irqfd(&self, vector: usize) -> Option<&Event>

Return irqfd of MSI-X Table entry

§Arguments
  • ‘vector’ - the index to the MSI-X table entry
source

pub fn destroy(&mut self)

Trait Implementations§

source§

impl AsRawDescriptor for MsixConfig

source§

fn as_raw_descriptor(&self) -> RawDescriptor

Returns the underlying raw descriptor. Read more
source§

impl PciCapConfig for MsixConfig

source§

fn read_mask(&self) -> &'static [u32]

Returns the read mask used by read_reg.
source§

fn read_reg(&self, reg_idx: usize) -> u32

Reads a 32bit register from the capability. Only the bits set in the read mask will be used, while the rest of the bits will be taken from the PciConfiguration’s register data. reg_idx - index into the capability
source§

fn write_reg( &mut self, reg_idx: usize, offset: u64, data: &[u8] ) -> Option<Box<dyn PciCapConfigWriteResult>>

Writes data to the capability. 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)

Used to pass the mmio region for the capability to the implementation. If any external events update the capability’s registers, then PciCapMapping.set_reg must be called to make the changes visible to the guest.
source§

fn num_regs(&self) -> usize

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> AsRawDescriptors for T
where T: AsRawDescriptor,

source§

fn as_raw_descriptors(&self) -> Vec<i32>

Returns the underlying raw descriptors. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<T> Downcast for T
where T: Any,

§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert 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>

Convert 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)

Convert &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)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
§

impl<T> DowncastSync for T
where T: Any + Send + Sync,

§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Send + Sync>

Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further downcast into Arc<ConcreteType> where ConcreteType implements Trait.
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V