Skip to main content

ConfigSpace

Struct ConfigSpace 

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

Source

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>

Source

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.

Source

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>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<T: ?Sized> Copy for ConfigSpace<'_, T>

Source§

impl<'a, T: ?Sized + KnownSize> IoBase<'a> for ConfigSpace<'a, T>

Source§

type Backend = ConfigSpaceBackend

Type that defines all I/O operations.
Source§

type Target = T

Type of this I/O region. For untyped regions, Region can be used.
Source§

fn as_view(self) -> ConfigSpace<'a, T>

Return a view that covers the full region.
Source§

impl<T: ?Sized + Sync> Send for ConfigSpace<'_, T>

Source§

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>
where *mut T: Freeze, T: ?Sized,

§

impl<'a, T> Unpin for ConfigSpace<'a, T>
where *mut T: Unpin, T: ?Sized,

§

impl<'a, T> UnsafeUnpin for ConfigSpace<'a, T>
where *mut T: UnsafeUnpin, T: ?Sized,

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> 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
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Init<T> for T

Source§

fn chain<F>(self, f: F) -> ChainInit<Self, F, T, E>
where F: FnOnce(&mut T) -> Result<(), E>,

First initializes the value using self then calls the function f with the initialized value. Read more
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<S, T> IntoSafeCast<T> for S
where T: FromSafeCast<S>,

Source§

fn into_safe_cast(self) -> T

Convert self into a T. This operation is guaranteed to be lossless.
Source§

impl<S, T> IntoSafeCastArch<T> for S
where T: FromSafeCastArch<S>,

Source§

fn into_safe_cast_arch(self) -> T

Convert self into a T. This operation is guaranteed to be lossless.
Source§

impl<'a, T> Io<'a> for T
where T: IoBase<'a>,

Source§

fn size(self) -> usize

Returns the size of this I/O region.
Source§

fn len<T>(self) -> usize
where Self: Io<'a, Target = [T]>,

Returns the length of the slice in number of elements.
Source§

fn is_empty<T>(self) -> bool
where Self: Io<'a, Target = [T]>,

Returns true if the slice has a length of 0.
Source§

fn cast<U>(self) -> <Self::Backend as IoBackend>::View<'a, U>

Convert into a different typed I/O view. Read more
Source§

fn try_cast<U>(self) -> Result<<Self::Backend as IoBackend>::View<'a, U>>

Try to convert into a different typed I/O view. Read more
Source§

fn read_val(self) -> Self::Target
where Self::Target: AsReprMut, Self::Backend: IoCapable<<Self::Target as AsRepr>::Repr>,

Read a value from I/O. Read more
Source§

fn write_val(self, value: Self::Target)
where Self::Target: AsRepr, Self::Backend: IoCapable<<Self::Target as AsRepr>::Repr>,

Write a value to I/O. Read more
Source§

fn copy_read(self) -> Self::Target
where Self::Backend: IoCopyable, Self::Target: Sized + FromBytes,

Copy-read from I/O memory. Read more
Source§

fn copy_write(self, value: Self::Target)
where Self::Backend: IoCopyable, Self::Target: Sized + IntoBytes,

Copy-write to I/O memory. Read more
Source§

fn copy_from_slice(self, data: &[u8])
where Self::Backend: IoCopyable, Self: Io<'a, Target = [u8]>,

Copy bytes from data to I/O memory. Read more
Source§

fn copy_to_slice(self, data: &mut [u8])
where Self::Backend: IoCopyable, Self: Io<'a, Target = [u8]>,

Copy bytes from I/O memory to data. Read more
Source§

fn try_read8(self, offset: usize) -> Result<u8>
where usize: IoLoc<Self::Target, u8>, Self::Backend: IoCapable<u8>,

Fallible 8-bit read with runtime bounds check.
Source§

fn try_read16(self, offset: usize) -> Result<u16>
where usize: IoLoc<Self::Target, u16>, Self::Backend: IoCapable<u16>,

Fallible 16-bit read with runtime bounds check.
Source§

fn try_read32(self, offset: usize) -> Result<u32>
where usize: IoLoc<Self::Target, u32>, Self::Backend: IoCapable<u32>,

Fallible 32-bit read with runtime bounds check.
Source§

fn try_read64(self, offset: usize) -> Result<u64>
where usize: IoLoc<Self::Target, u64>, Self::Backend: IoCapable<u64>,

Fallible 64-bit read with runtime bounds check.
Source§

fn try_write8(self, value: u8, offset: usize) -> Result
where usize: IoLoc<Self::Target, u8>, Self::Backend: IoCapable<u8>,

Fallible 8-bit write with runtime bounds check.
Source§

fn try_write16(self, value: u16, offset: usize) -> Result
where usize: IoLoc<Self::Target, u16>, Self::Backend: IoCapable<u16>,

Fallible 16-bit write with runtime bounds check.
Source§

fn try_write32(self, value: u32, offset: usize) -> Result
where usize: IoLoc<Self::Target, u32>, Self::Backend: IoCapable<u32>,

Fallible 32-bit write with runtime bounds check.
Source§

fn try_write64(self, value: u64, offset: usize) -> Result
where usize: IoLoc<Self::Target, u64>, Self::Backend: IoCapable<u64>,

Fallible 64-bit write with runtime bounds check.
Source§

fn read8(self, offset: usize) -> u8
where usize: IoLoc<Self::Target, u8>, Self::Backend: IoCapable<u8>,

Infallible 8-bit read with compile-time bounds check. Read more
Source§

fn read16(self, offset: usize) -> u16
where usize: IoLoc<Self::Target, u16>, Self::Backend: IoCapable<u16>,

Infallible 16-bit read with compile-time bounds check. Read more
Source§

fn read32(self, offset: usize) -> u32
where usize: IoLoc<Self::Target, u32>, Self::Backend: IoCapable<u32>,

Infallible 32-bit read with compile-time bounds check. Read more
Source§

fn read64(self, offset: usize) -> u64
where usize: IoLoc<Self::Target, u64>, Self::Backend: IoCapable<u64>,

Infallible 64-bit read with compile-time bounds check. Read more
Source§

fn write8(self, value: u8, offset: usize)
where usize: IoLoc<Self::Target, u8>, Self::Backend: IoCapable<u8>,

Infallible 8-bit write with compile-time bounds check. Read more
Source§

fn write16(self, value: u16, offset: usize)
where usize: IoLoc<Self::Target, u16>, Self::Backend: IoCapable<u16>,

Infallible 16-bit write with compile-time bounds check. Read more
Source§

fn write32(self, value: u32, offset: usize)
where usize: IoLoc<Self::Target, u32>, Self::Backend: IoCapable<u32>,

Infallible 32-bit write with compile-time bounds check. Read more
Source§

fn write64(self, value: u64, offset: usize)
where usize: IoLoc<Self::Target, u64>, Self::Backend: IoCapable<u64>,

Infallible 64-bit write with compile-time bounds check. Read more
Source§

fn try_read<T, L>(self, location: L) -> Result<T>
where T: AsReprMut, L: IoLoc<Self::Target, T>, Self::Backend: IoCapable<<T as AsRepr>::Repr>,

Generic fallible read with runtime bounds check. Read more
Source§

fn try_write<T, L>(self, location: L, value: T) -> Result
where T: AsRepr, L: IoLoc<Self::Target, T>, Self::Backend: IoCapable<<T as AsRepr>::Repr>,

Generic fallible write with runtime bounds check. Read more
Source§

fn try_write_reg<T, L, V>(self, value: V) -> Result
where T: AsRepr, L: IoLoc<Self::Target, T>, V: LocatedRegister<Self::Target, Location = L, Value = T>, Self::Backend: IoCapable<<T as AsRepr>::Repr>,

Generic fallible write of a fully-located register value. Read more
Source§

fn try_update<T, L, F>(self, location: L, f: F) -> Result
where T: AsReprMut, L: IoLoc<Self::Target, T>, Self::Backend: IoCapable<<T as AsRepr>::Repr>, F: FnOnce(T) -> T,

Generic fallible update with runtime bounds check. Read more
Source§

fn read<T, L>(self, location: L) -> T
where T: AsReprMut, L: IoLoc<Self::Target, T>, Self::Backend: IoCapable<<T as AsRepr>::Repr>,

Generic infallible read with compile-time bounds check. Read more
Source§

fn write<T, L>(self, location: L, value: T)
where T: AsRepr, L: IoLoc<Self::Target, T>, Self::Backend: IoCapable<<T as AsRepr>::Repr>,

Generic infallible write with compile-time bounds check. Read more
Source§

fn write_reg<T, L, V>(self, value: V)
where T: AsRepr, L: IoLoc<Self::Target, T>, V: LocatedRegister<Self::Target, Location = L, Value = T>, Self::Backend: IoCapable<<T as AsRepr>::Repr>,

Generic infallible write of a fully-located register value. Read more
Source§

fn update<T, L, F>(self, location: L, f: F)
where T: AsReprMut, L: IoLoc<Self::Target, T>, Self::Backend: IoCapable<<T as AsRepr>::Repr>, F: FnOnce(T) -> T,

Generic infallible update with compile-time bounds check. Read more
Source§

impl<T> KnownSize for T

Source§

const MIN_SIZE: usize = const MIN_SIZE: usize = size_of::<T>();

Minimum size of this type known at compile-time.
Source§

const MIN_ALIGN: Alignment = const MIN_ALIGN: Alignment = Alignment::of::<T>();

Minimum alignment of this type known at compile-time.
Source§

fn size(_: *const T) -> usize

Get the size of an object of this type in bytes, with the metadata of the given pointer.
Source§

impl<T> PinInit<T> for T

Source§

unsafe fn __init(self, slot: *mut T) -> Result<(), !>

Initializes slot. Read more
Source§

fn pin_chain<F>(self, f: F) -> ChainPinInit<Self, F, T, E>
where F: FnOnce(Pin<&mut T>) -> Result<(), E>,

First initializes the value using self then calls the function f with the initialized value. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

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

Source§

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.
Source§

impl<T, U, const N: u32> TryIntoBounded<T, N> for U
where T: Integer, U: TryInto<T>,

Source§

fn try_into_bounded(self) -> Option<Bounded<T, N>>

Attempts to convert self into a Bounded using N bits. Read more