Skip to main content

Device

Struct Device 

Source
pub struct Device { /* private fields */ }

Implementations§

Source§

impl Device

Source

pub fn attach_pt(&self, pt_id: u32) -> Result<u32>

Attach this VFIO device to an iommufd page table (IOAS or HWPT) by its object ID, via VFIO_DEVICE_ATTACH_IOMMUFD_PT.

Only valid for a device opened through the cdev path and bound to iommufd (see CdevDevice::bind_iommufd); legacy group-path devices use the container/IOAS model instead. If the device is already attached, the kernel replaces the page table atomically. Returns the attached page table ID (the kernel may substitute an auto-created HWPT for an IOAS).

Source

pub fn detach_pt(&self) -> Result<()>

Detach this VFIO device from its current iommufd page table, via VFIO_DEVICE_DETACH_IOMMUFD_PT. Afterward the device is in the blocking DMA state (abort). Only valid for iommufd-bound (cdev) devices.

Source§

impl Device

Source

pub fn info(&self) -> Result<DeviceInfo>

Source

pub fn region_info(&self, index: u32) -> Result<RegionInfo>

Source

pub fn region_mmap_areas(&self, index: u32) -> Result<Vec<MemoryRange>>

Query the mmappable sub-regions for a VFIO region.

If the region has a VFIO_REGION_INFO_CAP_SPARSE_MMAP capability, returns the list of mmappable areas from it. If the region supports mmap but has no sparse capability, returns a single area covering the entire region. Returns an empty list if the region does not support mmap.

Source

pub fn irq_info(&self, index: u32) -> Result<IrqInfo>

Source

pub fn map(&self, offset: u64, len: usize, write: bool) -> Result<MappedRegion>

Source

pub fn supports_dma_buf(&self) -> Result<bool>

Returns whether the device supports exporting a region as a dmabuf for peer-to-peer DMA (VFIO_DEVICE_FEATURE_DMA_BUF).

Ok(false) means the feature is unavailable and the caller should fall back to host-VA mapping. An unexpected probe failure is returned as an error.

Source

pub fn export_dma_buf( &self, region_index: u32, offset: u64, length: u64, ) -> Result<OwnedFd>

Exports a single page-aligned range of a device region (BAR) as a dmabuf for peer-to-peer DMA via iommufd (VFIO_DEVICE_FEATURE_DMA_BUF).

region_index is the VFIO region (BAR) index. offset and length are BAR-relative and must be page-aligned. The kernel interconnect currently supports only a single range per dmabuf, so this exports exactly one range. Returns an owned dmabuf fd.

Source

pub fn map_msix<I>(&self, start: u32, eventfd: I) -> Result<()>
where I: IntoIterator, I::Item: AsFd,

Source

pub fn unmap_msix(&self) -> Result<()>

Disable MSI-X for this device, tearing down all eventfd bindings.

VFIO does not support disabling a subset of MSI-X vectors via DATA_NONE: per vfio_pci_set_msi_trigger in the kernel, the only teardown form is ACTION_TRIGGER | DATA_NONE with count == 0, which disables MSI-X entirely. (A non-zero count with DATA_NONE is instead interpreted as a loopback signal request that fires each vector’s eventfd and unmaps nothing.) This therefore always disables all vectors, and the caller must only invoke it when MSI-X is currently enabled — otherwise the kernel returns EINVAL.

Source

pub fn reset(&self) -> Result<()>

Reset the device via VFIO_DEVICE_RESET.

Not all devices support reset — check DeviceInfo::flags.reset() first. Returns an error if the ioctl fails.

Source

pub fn file(&self) -> &File

Returns the underlying device file, for direct positional I/O on config space and BAR regions (read_at/write_at).

Prefer this over AsRef::<File>::as_ref when the Device is held behind an Arc: Arc<Device> also implements AsRef<Device>, so a bare .as_ref() there would resolve to &Device rather than &File.

Trait Implementations§

Source§

impl AsFd for Device

Source§

fn as_fd(&self) -> BorrowedFd<'_>

Borrows the file descriptor. Read more
Source§

impl AsRef<File> for Device

Source§

fn as_ref(&self) -> &File

Converts this type into a shared reference of the (usually inferred) input type.

Auto Trait Implementations§

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
§

impl<T> AsSockRef for T
where T: Unpin, &'a T: for<'a> Into<SockRef<'a>>,

§

fn as_sock_ref(&self) -> SockRef<'_>

Returns a socket reference.
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<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. 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<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more