Skip to main content

DmaTarget

Struct DmaTarget 

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

Everything a PCI device needs for bus-mastered transactions: DMA memory access and MSI interrupt delivery.

Most devices only need guest_memory and msi_target. SR-IOV PFs additionally call with_rid_offset when creating VFs.

Implementations§

Source§

impl DmaTarget

Source

pub fn new( bus_range: AssignedBusRange, devfn: u8, guest_memory: GuestMemory, msi: &MsiConnection, ) -> Self

Creates a DMA target with no IOMMU.

bus_range and devfn set the device’s requester-ID identity, shared by both the DMA and MSI sides. The MSI backend is taken (late-bound) from msi. Since there is no IOMMU, all targets derived from this one share the same guest memory; with_rid_offset only updates the MSI identity.

Source

pub fn with_iommu( bus_range: AssignedBusRange, devfn: u8, iommu: Arc<dyn DmaTargetIommu>, msi: &MsiConnection, ) -> Self

Creates a DMA target backed by a software/emulated IOMMU.

The base (function-devfn) translating guest memory is derived from iommu; per-VF memory is produced by with_rid_offset. The MSI backend is taken (late-bound) from msi.

The device is marked DmaPassthrough::SoftwareBlocked: a software/emulated IOMMU cannot program the host IOMMU, so host passthrough (VFIO assignment) is rejected. Use with_nestable_iommu for a hardware-nestable IOMMU that permits passthrough.

Source

pub fn with_nestable_iommu( bus_range: AssignedBusRange, devfn: u8, iommu: Arc<dyn DmaTargetIommu>, handle: Arc<dyn Any + Send + Sync>, msi: &MsiConnection, ) -> Self

Creates a DMA target backed by a hardware-nestable IOMMU.

Like with_iommu, but marks the device DmaPassthrough::HardwareNestable with an opaque handle that the host-assignment backend downcasts to its arch-specific nesting context. Accel-capable IOMMUs (e.g. an SMMU that programs the host IOMMU for nested stage-1 translation) use this to permit VFIO passthrough despite wrapping guest memory with a translating target; the handle carries everything the backend needs to wire the device into the emulated IOMMU.

Supplying the nesting handle together with the iommu is what makes a DmaPassthrough::HardwareNestable target impossible to construct without a backing IOMMU.

Source

pub fn guest_memory(&self) -> &GuestMemory

Returns the guest memory for DMA from this device.

Source

pub fn msi_target(&self) -> &MsiTarget

Returns the MSI target for interrupt delivery from this device.

Source

pub fn passthrough(&self) -> DmaPassthrough<'_>

The device’s host-passthrough disposition.

Used by host-assignment backends (e.g. the VFIO resolver) to decide whether the device may be passed through and, when it is behind a hardware-nestable IOMMU, to obtain the opaque handle they downcast to attach to the emulated IOMMU.

Source

pub fn with_rid_offset(&self, delta: u16) -> DmaTarget

Derives a DMA target offset by delta from this one in RID space.

This is the SR-IOV VF derivation primitive: given a PF’s target, its ith VF is delta = VF_Offset + i * VF_Stride away. Offsets stack, so deriving from an already-derived target accumulates. Both the DMA and MSI identity are derived in lockstep and resolved at use time as (secondary << 8) + offset against the live bus assignment, so VF targets can be derived before the bus is programmed.

Trait Implementations§

Source§

impl Clone for DmaTarget

Source§

fn clone(&self) -> DmaTarget

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more

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
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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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