pub struct ConfigSpace<'a, T: ?Sized = Extended> { /* private fields */ }Expand description
A view of PCI configuration space of a device.
Provides typed read and write accessors for configuration registers
using the standard pci_read_config_* and pci_write_config_* helpers.
The generic parameter T is the type of the view. The full configuration space is also a
special type of view; in such cases, T can be Normal for 256-byte legacy configuration
space or Extended for 4096-byte PCIe extended configuration space (default).
§Invariants
ptr is aligned and range ptr..ptr + KnownSize::size(ptr) is within
0..pdev.cfg_size().into_raw().
Implementations§
Source§impl<'a> ConfigSpace<'a, Extended>
impl<'a> ConfigSpace<'a, Extended>
Sourcepub fn find_ext_capability<C: ExtCapability>(
&self,
) -> Result<Option<ConfigSpace<'a, C>>>
pub fn find_ext_capability<C: ExtCapability>( &self, ) -> Result<Option<ConfigSpace<'a, C>>>
Finds and projects an extended capability into its typed register layout.
Returns None if the device does not implement the capability.
Returns an error if the capability is present but its register span is too small or
insufficiently aligned for C.
§Examples
use kernel::{
device::Bound,
pci,
prelude::*,
};
fn probe_sriov(pdev: &pci::Device<Bound>) -> Result {
let Some(sriov) = pdev
.config_space_extended()?
.find_ext_capability::<pci::ExtSriovRegs>()?
else {
return Ok(());
};
let first_vf_offset = sriov.first_vf_offset();
let mut vf_bars = sriov.vf_bars()?;
let bar0 = vf_bars.next().ok_or(EINVAL)?;
let bar1 = vf_bars.next().ok_or(EINVAL)?;
let bar2 = vf_bars.next().ok_or(EINVAL)?;
Ok(())
}Source§impl ConfigSpace<'_, ExtSriovRegs>
impl ConfigSpace<'_, ExtSriovRegs>
Sourcepub fn first_vf_offset(&self) -> u16
pub fn first_vf_offset(&self) -> u16
Returns the current PCIe First VF Offset in Routing ID space.
This value may change when NumVFs changes. Drivers should use PCI core helpers when they need to calculate a VF BDF; this accessor is intended for interfaces that require the First VF Offset itself.
Sourcepub fn vf_bars(&self) -> Result<impl Iterator<Item = ExtSriovVfBar>>
pub fn vf_bars(&self) -> Result<impl Iterator<Item = ExtSriovVfBar>>
Returns an iterator over decoded VF BAR register encodings.
All six raw VF BAR register slots are read and decoded up front. A 32-bit encoding yields one entry; a 64-bit encoding combines two slots into one entry.
A zero-valued low DWORD is yielded as a 32-bit BAR at address zero; this method does not probe whether a BAR is implemented.
Returns EINVAL and logs an error if a BAR low DWORD does not encode a 32-bit or 64-bit
memory BAR, or if a 64-bit encoding has no upper DWORD.
Trait Implementations§
Source§impl<T: ?Sized> Clone for ConfigSpace<'_, T>
impl<T: ?Sized> Clone for ConfigSpace<'_, T>
impl<T: ?Sized> Copy for ConfigSpace<'_, T>
impl<T: ?Sized + Sync> Send for ConfigSpace<'_, T>
impl<T: ?Sized + Sync> Sync for ConfigSpace<'_, T>
Auto Trait Implementations§
impl<'a, T = Region<4096>> !RefUnwindSafe for ConfigSpace<'a, T>
impl<'a, T = Region<4096>> !UnwindSafe for ConfigSpace<'a, T>
impl<'a, T> Freeze for ConfigSpace<'a, T>
impl<'a, T> Unpin for ConfigSpace<'a, T>
impl<'a, T> UnsafeUnpin for ConfigSpace<'a, T>
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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<S, T> IntoSafeCast<T> for Swhere
T: FromSafeCast<S>,
impl<S, T> IntoSafeCast<T> for Swhere
T: FromSafeCast<S>,
Source§fn into_safe_cast(self) -> T
fn into_safe_cast(self) -> T
self into a T. This operation is guaranteed to be lossless.Source§impl<S, T> IntoSafeCastArch<T> for Swhere
T: FromSafeCastArch<S>,
impl<S, T> IntoSafeCastArch<T> for Swhere
T: FromSafeCastArch<S>,
Source§fn into_safe_cast_arch(self) -> T
fn into_safe_cast_arch(self) -> T
self into a T. This operation is guaranteed to be lossless.Source§impl<'a, T> Io<'a> for Twhere
T: IoBase<'a>,
impl<'a, T> Io<'a> for Twhere
T: IoBase<'a>,
Source§fn cast<U>(self) -> <Self::Backend as IoBackend>::View<'a, U>
fn cast<U>(self) -> <Self::Backend as IoBackend>::View<'a, U>
Source§fn try_cast<U>(self) -> Result<<Self::Backend as IoBackend>::View<'a, U>>
fn try_cast<U>(self) -> Result<<Self::Backend as IoBackend>::View<'a, U>>
Source§fn copy_write(self, value: Self::Target)
fn copy_write(self, value: Self::Target)
Source§fn copy_from_slice(self, data: &[u8])
fn copy_from_slice(self, data: &[u8])
data to I/O memory. Read moreSource§fn copy_to_slice(self, data: &mut [u8])
fn copy_to_slice(self, data: &mut [u8])
data. Read more