Struct devices::pci::pci_configuration::PciConfiguration
source · pub struct PciConfiguration {
registers: [u32; 64],
writable_bits: [u32; 64],
bar_used: [bool; 7],
bar_configs: [Option<PciBarConfiguration>; 7],
last_capability: Option<(usize, usize)>,
capability_configs: BTreeMap<usize, Box<dyn PciCapConfig>>,
mmio_mapping: Option<(Arc<Mutex<MemoryMapping>>, usize)>,
}
Expand description
Contains the configuration space of a PCI node. See the specification. The configuration space is accessed with DWORD reads and writes from the guest.
Fields§
§registers: [u32; 64]
§writable_bits: [u32; 64]
§bar_used: [bool; 7]
§bar_configs: [Option<PciBarConfiguration>; 7]
§last_capability: Option<(usize, usize)>
§capability_configs: BTreeMap<usize, Box<dyn PciCapConfig>>
§mmio_mapping: Option<(Arc<Mutex<MemoryMapping>>, usize)>
Implementations§
source§impl PciConfiguration
impl PciConfiguration
pub fn new( vendor_id: u16, device_id: u16, class_code: PciClassCode, subclass: &dyn PciSubclass, programming_interface: Option<&dyn PciProgrammingInterface>, header_type: PciHeaderType, subsystem_vendor_id: u16, subsystem_id: u16, revision_id: u8 ) -> Self
sourcepub fn read_reg(&self, reg_idx: usize) -> u32
pub fn read_reg(&self, reg_idx: usize) -> u32
Reads a 32bit register from reg_idx
in the register map.
sourcepub fn write_reg(
&mut self,
reg_idx: usize,
offset: u64,
data: &[u8]
) -> Option<Box<dyn PciCapConfigWriteResult>>
pub fn write_reg( &mut self, reg_idx: usize, offset: u64, data: &[u8] ) -> Option<Box<dyn PciCapConfigWriteResult>>
Writes data to PciConfiguration.registers.
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.
sourcefn write_dword(&mut self, offset: usize, value: u32)
fn write_dword(&mut self, offset: usize, value: u32)
Writes a 32bit dword to offset
. offset
must be 32bit aligned.
sourcefn write_word(&mut self, offset: usize, value: u16)
fn write_word(&mut self, offset: usize, value: u16)
Writes a 16bit word to offset
. offset
must be 16bit aligned.
sourcefn write_byte(&mut self, offset: usize, value: u8)
fn write_byte(&mut self, offset: usize, value: u8)
Writes a byte to offset
.
sourcefn write_byte_internal(
&mut self,
offset: usize,
value: u8,
apply_writable_mask: bool
)
fn write_byte_internal( &mut self, offset: usize, value: u8, apply_writable_mask: bool )
Writes a byte to offset
, optionally enforcing read-only bits.
sourcepub fn set_reg(&mut self, reg_idx: usize, data: u32, mask: u32)
pub fn set_reg(&mut self, reg_idx: usize, data: u32, mask: u32)
Sets the value of a PciConfiguration register. This should be used when
device-internal events require changing the configuration space - as such,
the writable bits masks do not apply.
reg_idx
- index into PciConfiguration.registers.
data
- The data to write.
mask
- The mask of which bits to modify.
sourcepub fn add_pci_bar(
&mut self,
config: PciBarConfiguration
) -> Result<PciBarIndex, Error>
pub fn add_pci_bar( &mut self, config: PciBarConfiguration ) -> Result<PciBarIndex, Error>
Adds a region specified by config
. Configures the specified BAR(s) to
report this region and size to the guest kernel. Enforces a few constraints
(i.e, region size must be power of two, register not already used). Returns ‘None’ on
failure all, Some(BarIndex)
on success.
sourcepub fn get_bars(&self) -> PciBarIter<'_> ⓘ
pub fn get_bars(&self) -> PciBarIter<'_> ⓘ
Returns an iterator of the currently configured base address registers.
sourcepub fn get_bar_configuration(
&self,
bar_num: usize
) -> Option<PciBarConfiguration>
pub fn get_bar_configuration( &self, bar_num: usize ) -> Option<PciBarConfiguration>
Returns the configuration of a base address register, if present.
sourcepub fn get_bar_type(&self, bar_num: PciBarIndex) -> Option<PciBarRegionType>
pub fn get_bar_type(&self, bar_num: PciBarIndex) -> Option<PciBarRegionType>
Returns the type of the given BAR region.
sourcepub fn get_bar_addr(&self, bar_num: PciBarIndex) -> u64
pub fn get_bar_addr(&self, bar_num: PciBarIndex) -> u64
Returns the address of the given BAR region.
sourcepub fn set_irq(&mut self, line: u8, pin: PciInterruptPin)
pub fn set_irq(&mut self, line: u8, pin: PciInterruptPin)
Configures the IRQ line and pin used by this device.
sourcepub fn add_capability(
&mut self,
cap_data: &dyn PciCapability,
cap_config: Option<Box<dyn PciCapConfig>>
) -> Result<(), Error>
pub fn add_capability( &mut self, cap_data: &dyn PciCapability, cap_config: Option<Box<dyn PciCapConfig>> ) -> Result<(), Error>
Adds the capability cap_data
to the list of capabilities.
cap_data
should include the two-byte PCI capability header (type, next),
but not populate it. Correct values will be generated automatically based
on cap_data.id()
.
fn next_dword(offset: usize, len: usize) -> usize
fn do_write(&mut self, reg_idx: usize, value: u32)
pub fn snapshot(&mut self) -> Result<Value>
pub fn restore(&mut self, data: Value) -> Result<()>
pub fn setup_mapping( &mut self, shmem: &SharedMemory, base: usize, len: usize ) -> Result<()>
Auto Trait Implementations§
impl !RefUnwindSafe for PciConfiguration
impl Send for PciConfiguration
impl !Sync for PciConfiguration
impl Unpin for PciConfiguration
impl !UnwindSafe for PciConfiguration
Blanket Implementations§
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.