pub struct Device<Ctx: DeviceContext = Normal>(/* private fields */);Expand description
The PCI device representation.
This structure represents the Rust abstraction for a C struct pci_dev. The implementation
abstracts the usage of an already existing C struct pci_dev within Rust code that we get
passed from the C side.
§Invariants
A Device instance represents a valid struct pci_dev created by the C portion of the
kernel.
Implementations§
Source§impl Device<Bound>
impl Device<Bound>
Sourcepub fn iomap_region_sized<'a, const SIZE: usize>(
&'a self,
bar: u32,
name: &'static CStr,
) -> Result<Bar<'a, SIZE>>
pub fn iomap_region_sized<'a, const SIZE: usize>( &'a self, bar: u32, name: &'static CStr, ) -> Result<Bar<'a, SIZE>>
Maps an entire PCI BAR after performing a region-request on it. I/O operation bound checks can be performed on compile time for offsets (plus the requested type size) < SIZE.
Sourcepub fn iomap_region<'a>(
&'a self,
bar: u32,
name: &'static CStr,
) -> Result<Bar<'a>>
pub fn iomap_region<'a>( &'a self, bar: u32, name: &'static CStr, ) -> Result<Bar<'a>>
Maps an entire PCI BAR after performing a region-request on it.
Sourcepub fn cfg_size(&self) -> ConfigSpaceSize
pub fn cfg_size(&self) -> ConfigSpaceSize
Returns the size of configuration space.
Sourcepub fn config_space<'a>(&'a self) -> ConfigSpace<'a, Normal>
pub fn config_space<'a>(&'a self) -> ConfigSpace<'a, Normal>
Return a view of the normal (256-byte) config space.
Sourcepub fn config_space_extended<'a>(&'a self) -> Result<ConfigSpace<'a, Extended>>
pub fn config_space_extended<'a>(&'a self) -> Result<ConfigSpace<'a, Extended>>
Return a view of the extended (4096-byte) config space.
Source§impl Device<Bound>
impl Device<Bound>
Sourcepub fn alloc_irq_vectors(
&self,
min_vecs: u32,
max_vecs: u32,
irq_types: IrqTypes,
) -> Result<IrqVectorRegistration<'_>>
pub fn alloc_irq_vectors( &self, min_vecs: u32, max_vecs: u32, irq_types: IrqTypes, ) -> Result<IrqVectorRegistration<'_>>
Allocate IRQ vectors for this PCI device.
Allocates between min_vecs and max_vecs interrupt vectors for the device.
The allocation will use MSI-X, MSI, or INTx interrupts based on the irq_types
parameter and hardware capabilities. When multiple types are specified, the kernel
will try them in order of preference: MSI-X first, then MSI, then INTx interrupts.
The allocated vectors are freed when the returned IrqVectorRegistration is dropped.
Use IrqVectorRegistration::index to obtain an IrqVector for a given vector
index.
§Arguments
min_vecs- Minimum number of vectors required.max_vecs- Maximum number of vectors to allocate.irq_types- Types of interrupts that can be used.
§Returns
Returns the IRQ vector registration, or an error if min_vecs vectors cannot be
allocated.
§Examples
// Allocate using any available interrupt type in the order mentioned above.
let vectors = dev.alloc_irq_vectors(1, 32, pci::IrqTypes::all())?;
// Allocate MSI or MSI-X only (no INTx interrupts).
let msi_only = pci::IrqTypes::default()
.with(pci::IrqType::Msi)
.with(pci::IrqType::MsiX);
let vectors = dev.alloc_irq_vectors(4, 16, msi_only)?;Source§impl Device
impl Device
Sourcepub fn revision_id(&self) -> u8
pub fn revision_id(&self) -> u8
Returns the PCI revision ID.
Sourcepub fn subsystem_vendor_id(&self) -> u16
pub fn subsystem_vendor_id(&self) -> u16
Returns the PCI subsystem vendor ID.
Sourcepub fn subsystem_device_id(&self) -> u16
pub fn subsystem_device_id(&self) -> u16
Returns the PCI subsystem device ID.
Sourcepub fn resource_start(&self, bar: u32) -> Result<resource_size_t>
pub fn resource_start(&self, bar: u32) -> Result<resource_size_t>
Returns the start of the given PCI BAR resource.
Sourcepub fn resource_len(&self, bar: u32) -> Result<resource_size_t>
pub fn resource_len(&self, bar: u32) -> Result<resource_size_t>
Returns the size of the given PCI BAR resource.
Source§impl<'a> Device<Core<'a>>
impl<'a> Device<Core<'a>>
Sourcepub fn sriov_get_totalvfs(&self) -> Option<NonZero<u16>>
pub fn sriov_get_totalvfs(&self) -> Option<NonZero<u16>>
Returns the total number of VFs, or None if SR-IOV is not available.
Sourcepub fn enable_device_mem(&self) -> Result
pub fn enable_device_mem(&self) -> Result
Enable memory resources for this device.
Sourcepub fn set_master(&self)
pub fn set_master(&self)
Enable bus-mastering for this device.
Trait Implementations§
Source§impl AlwaysRefCounted for Device
impl AlwaysRefCounted for Device
Source§impl<Ctx: DeviceContext> AsBusDevice<Ctx> for Device<Ctx>
impl<Ctx: DeviceContext> AsBusDevice<Ctx> for Device<Ctx>
Source§impl<'a> Deref for Device<CoreInternal<'a>>
impl<'a> Deref for Device<CoreInternal<'a>>
Source§impl Deref for Device<BoundInternal>
impl Deref for Device<BoundInternal>
Source§impl<'a> Device<'a> for Device<Core<'a>>
impl<'a> Device<'a> for Device<Core<'a>>
Source§unsafe fn dma_set_mask(&self, mask: DmaMask) -> Result
unsafe fn dma_set_mask(&self, mask: DmaMask) -> Result
Source§unsafe fn dma_set_coherent_mask(&self, mask: DmaMask) -> Result
unsafe fn dma_set_coherent_mask(&self, mask: DmaMask) -> Result
Source§unsafe fn dma_set_mask_and_coherent(&self, mask: DmaMask) -> Result
unsafe fn dma_set_mask_and_coherent(&self, mask: DmaMask) -> Result
Source§unsafe fn dma_set_max_seg_size(&self, size: u32)
unsafe fn dma_set_max_seg_size(&self, size: u32)
Source§impl From<&Device<BoundInternal>> for ARef<Device>
impl From<&Device<BoundInternal>> for ARef<Device>
Source§fn from(dev: &Device<BoundInternal>) -> Self
fn from(dev: &Device<BoundInternal>) -> Self
Source§impl<'a> From<&Device<CoreInternal<'a>>> for ARef<Device>
impl<'a> From<&Device<CoreInternal<'a>>> for ARef<Device>
Source§fn from(dev: &Device<CoreInternal<'a>>) -> Self
fn from(dev: &Device<CoreInternal<'a>>) -> Self
impl Send for Device
impl Sync for Device
impl Sync for Device<Bound>
Auto Trait Implementations§
impl<Ctx = Normal> !Freeze for Device<Ctx>
impl<Ctx = Normal> !RefUnwindSafe for Device<Ctx>
impl<Ctx = Normal> !Send for Device<Ctx>
impl<Ctx = Normal> !Sync for Device<Ctx>
impl<Ctx = Normal> !Unpin for Device<Ctx>
impl<Ctx = Normal> !UnsafeUnpin for Device<Ctx>
impl<Ctx> UnwindSafe for Device<Ctx>where
Ctx: UnwindSafe,
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<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.