Device in kernel::pci - Rust
Skip to main content Device kernel :: pci Struct Device Source 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 > Source 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. Source 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.
Source pub fn cfg_size (&self) -> ConfigSpaceSize Returns the size of configuration space. Source pub fn config_space <'a>(&'a self) -> ConfigSpace <'a, Normal > Return a view of the normal (256-byte) config space. Source 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 > Source 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::IrqType::Msi | pci::IrqType::MsiX; let vectors = dev.alloc_irq_vectors( 4 , 16 , msi_only) ? ; Source § impl Device Source pub fn vendor_id (&self) -> Vendor Returns the PCI vendor ID as Vendor . § Examples fn log_device_info(pdev: & pci::Device<Core< '_ >>) -> Result { // Get an instance of `Vendor`. let vendor = pdev.vendor_id(); dev_info! ( pdev, "Device: Vendor={}, Device=0x{:x}\n" , vendor, pdev.device_id() ); Ok (()) } Source pub fn device_id (&self) -> u16 Returns the PCI device ID.
Source pub fn revision_id (&self) -> u8 Returns the PCI revision ID. Source pub fn dev_id (&self) -> u16 Returns the PCI bus device/function. Source pub fn subsystem_vendor_id (&self) -> u16 Returns the PCI subsystem vendor ID. Source pub fn subsystem_device_id (&self) -> u16 Returns the PCI subsystem device ID. Source pub fn resource_start (&self, bar: u32 ) -> Result <resource_size_t> Returns the start of the given PCI BAR resource.
Source pub fn resource_len (&self, bar: u32 ) -> Result <resource_size_t> Returns the size of the given PCI BAR resource. Source pub fn resource_flags (&self, bar: u32 ) -> Result < Flags > Returns the resource flags ( IORESOURCE_* ) of the given PCI BAR. Source pub fn pci_class (&self) -> Class Returns the PCI class as a Class struct. Source § impl<'a> Device < Core <'a>> Source pub fn sriov_get_totalvfs (&self) -> Option < NonZero < u16 >> Returns the total number of VFs, or None if SR-IOV is not available.
Source pub fn enable_device_mem (&self) -> Result Enable memory resources for this device. Source pub fn set_master (&self) Enable bus-mastering for this device. Trait Implementations § Source § impl AlwaysRefCounted for Device Source § fn inc_ref (&self) Increments the reference count on the object. Source § unsafe fn dec_ref (obj: NonNull <Self>) Decrements the reference count on the object. Read more Source § impl<Ctx: DeviceContext > AsBusDevice <Ctx> for Device <Ctx> Source § const OFFSET : usize The relative offset to the device field.
Read more Source § unsafe fn from_device (dev: & Device <Ctx>) -> &Self where Self: Sized , Convert a reference to Device into Self . Read more Source § impl<Ctx: DeviceContext > AsRef < Device <Ctx>> for Device <Ctx> Source § fn as_ref (&self) -> & Device <Ctx> Converts this type into a shared reference of the (usually inferred) input type. Source § impl<'a> Deref for Device < CoreInternal <'a>> Source § type Target = Device < Core <'a>> The resulting type after dereferencing.
Source § fn deref (&self) -> &Self:: Target Dereferences the value. Source § impl<'a> Deref for Device < Core <'a>> Source § type Target = Device < Bound > The resulting type after dereferencing. Source § fn deref (&self) -> &Self:: Target Dereferences the value. Source § impl Deref for Device < BoundInternal > Source § type Target = Device < Bound > The resulting type after dereferencing. Source § fn deref (&self) -> &Self:: Target Dereferences the value.
Source § impl Deref for Device < Bound > Source § type Target = Device The resulting type after dereferencing. Source § fn deref (&self) -> &Self:: Target Dereferences the value. Source § impl<'a> Device <'a> for Device < Core <'a>> Source § unsafe fn dma_set_mask (&self, mask: DmaMask ) -> Result Set up the device’s DMA streaming addressing capabilities. Read more Source § unsafe fn dma_set_coherent_mask (&self, mask: DmaMask ) -> Result Set up the device’s DMA coherent addressing capabilities.
Read more Source § unsafe fn dma_set_mask_and_coherent (&self, mask: DmaMask ) -> Result Set up the device’s DMA addressing capabilities. Read more Source § unsafe fn dma_set_max_seg_size (&self, size: u32 ) Set the maximum size of a single DMA segment the device may request. Read more Source § impl From <& Device < Bound >> for ARef < Device > Source § fn from (dev: & Device < Bound >) -> Self Converts to this type from the input type.
Source § impl From <& Device < BoundInternal >> for ARef < Device > Source § fn from (dev: & Device < BoundInternal >) -> Self Converts to this type from the input type. Source § impl<'a> From <& Device < Core <'a>>> for ARef < Device > Source § fn from (dev: & Device < Core <'a>>) -> Self Converts to this type from the input type. Source § impl<'a> From <& Device < CoreInternal <'a>>> for ARef < Device > Source § fn from (dev: & Device < CoreInternal <'a>>) -> Self Converts to this type from the input type.
Source § impl Send for Device Source § impl Sync for Device Source § impl Sync for Device < Bound > Source § impl<Ctx: DeviceContext > TryFrom <& Device <Ctx>> for & Device <Ctx> Source § type Error = Error The type returned in the event of a conversion error. Source § fn try_from (dev: & Device <Ctx>) -> Result <Self, Self:: Error > Performs the conversion. 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> 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 b
The rest of this page is on the live site.