pub struct Device { /* private fields */ }Implementations§
Source§impl Device
impl Device
Sourcepub fn attach_pt(&self, pt_id: u32) -> Result<u32>
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§impl Device
impl Device
pub fn info(&self) -> Result<DeviceInfo>
pub fn region_info(&self, index: u32) -> Result<RegionInfo>
Sourcepub fn region_mmap_areas(&self, index: u32) -> Result<Vec<MemoryRange>>
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.
pub fn irq_info(&self, index: u32) -> Result<IrqInfo>
pub fn map(&self, offset: u64, len: usize, write: bool) -> Result<MappedRegion>
Sourcepub fn supports_dma_buf(&self) -> Result<bool>
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.
Sourcepub fn export_dma_buf(
&self,
region_index: u32,
offset: u64,
length: u64,
) -> Result<OwnedFd>
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.
pub fn map_msix<I>(&self, start: u32, eventfd: I) -> Result<()>
Sourcepub fn unmap_msix(&self) -> Result<()>
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.
Sourcepub fn reset(&self) -> Result<()>
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.
Sourcepub fn file(&self) -> &File
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.