Skip to main content

CdevDevice

Struct CdevDevice 

Source
pub struct CdevDevice { /* private fields */ }
Expand description

A VFIO device opened via the cdev interface (/dev/vfio/devices/vfioN).

This is the modern per-device access path. After opening, the device must be bound to an iommufd fd via bind_iommufd and then attached to an IOAS or HWPT via attach_ioas before any DMA can occur.

Once bound and attached, call into_device to get the standard Device for config space, BAR, IRQ, and mmap operations.

Implementations§

Source§

impl CdevDevice

Source

pub fn from_file(file: File) -> Self

Wrap a pre-opened VFIO cdev file descriptor.

Source

pub fn bind_iommufd(&self, iommufd_fd: RawFd) -> Result<u32>

Bind this device to an iommufd instance.

Returns the kernel-assigned device ID within the iommufd context. This must be called before any DMA operations.

Source

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

Attach the device to an IOAS or HWPT by its iommufd object ID.

Pass an IOAS ID for identity DMA translation, or a HWPT ID for nested translation.

Returns the attached page table ID (may differ from input if the kernel auto-created a HWPT for the IOAS).

Source

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

Detach the device from its current IOAS/HWPT.

After detaching, the device is in a blocking DMA state.

Source

pub fn into_device(self) -> Device

Convert to a standard Device for config space, BAR, IRQ, and mmap operations.

The cdev fd supports the same VFIO_DEVICE_* ioctls as the legacy group path, so the Device type works unchanged.

Trait Implementations§

Source§

impl AsFd for CdevDevice

Source§

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

Borrows the file descriptor. Read more
Source§

impl AsRef<File> for CdevDevice

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