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: &'a CStr,
) -> impl PinInit<Devres<Bar<SIZE>>, Error> + 'a
 
pub fn iomap_region_sized<'a, const SIZE: usize>( &'a self, bar: u32, name: &'a CStr, ) -> impl PinInit<Devres<Bar<SIZE>>, Error> + 'a
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§impl Device<Bound>
 
impl Device<Bound>
Sourcepub fn request_irq<'a, T: Handler + 'static>(
    &'a self,
    vector: IrqVector<'a>,
    flags: Flags,
    name: &'static CStr,
    handler: impl PinInit<T, Error> + 'a,
) -> Result<impl PinInit<Registration<T>, Error> + 'a>
 
pub fn request_irq<'a, T: Handler + 'static>( &'a self, vector: IrqVector<'a>, flags: Flags, name: &'static CStr, handler: impl PinInit<T, Error> + 'a, ) -> Result<impl PinInit<Registration<T>, Error> + 'a>
Returns a kernel::irq::Registration for the given IRQ vector.
Sourcepub fn request_threaded_irq<'a, T: ThreadedHandler + 'static>(
    &'a self,
    vector: IrqVector<'a>,
    flags: Flags,
    name: &'static CStr,
    handler: impl PinInit<T, Error> + 'a,
) -> Result<impl PinInit<ThreadedRegistration<T>, Error> + 'a>
 
pub fn request_threaded_irq<'a, T: ThreadedHandler + 'static>( &'a self, vector: IrqVector<'a>, flags: Flags, name: &'static CStr, handler: impl PinInit<T, Error> + 'a, ) -> Result<impl PinInit<ThreadedRegistration<T>, Error> + 'a>
Returns a kernel::irq::ThreadedRegistration for the given IRQ vector.
Sourcepub fn alloc_irq_vectors(
    &self,
    min_vecs: u32,
    max_vecs: u32,
    irq_types: IrqTypes,
) -> Result<RangeInclusive<IrqVector<'_>>>
 
pub fn alloc_irq_vectors( &self, min_vecs: u32, max_vecs: u32, irq_types: IrqTypes, ) -> Result<RangeInclusive<IrqVector<'_>>>
Allocate IRQ vectors for this PCI device with automatic cleanup.
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 automatically freed when the device is unbound, using the devres (device resource management) system.
§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 a range of IRQ vectors that were successfully allocated, or an error if the allocation fails or cannot meet the minimum requirement.
§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 Device<Core>
 
impl Device<Core>
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 Deref for Device<CoreInternal>
 
impl Deref for Device<CoreInternal>
Source§impl Device for Device<Core>
 
impl Device for Device<Core>
Source§impl From<&Device<CoreInternal>> for ARef<Device>
 
impl From<&Device<CoreInternal>> for ARef<Device>
Source§fn from(dev: &Device<CoreInternal>) -> Self
 
fn from(dev: &Device<CoreInternal>) -> Self
impl Send for Device
impl Sync for Device
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> 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
Source§impl<T> PinInit<T> for T
 
impl<T> PinInit<T> for T
Source§unsafe fn __pinned_init(self, slot: *mut T) -> Result<(), Infallible>
 
unsafe fn __pinned_init(self, slot: *mut T) -> Result<(), Infallible>
slot. Read more