Skip to main content

Dma

Struct Dma 

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

A physically-contiguous DMA arena granted to a driver (e.g. via crate::ServiceContext::dma_region). The CPU accesses it through base, the device through phys. Both views cover the same len bytes one-to-one.

SEC-28 (SMP-port contract, kernel/src/arch/CLAUDE.md): this wrapper does NO cache maintenance. That is correct only because of how each port maps the arena (DMA_ARENA_UNCACHED): x86 maps it cacheable, its DMA being coherent; arm32 and aarch64, whose DMA is not, map it UNCACHED, which is their answer to SEC-28; riscv64 maps it cacheable. A port whose DMA is not coherent must map it uncached too, or add maintenance here - else the CPU and the device can see stale copies.

Implementations§

Source§

impl Dma

Source

pub fn phys_base(&self) -> u64

Physical base address - program this (plus offsets) into the controller.

Source

pub fn len(&self) -> usize

Length of the arena in bytes.

Source

pub fn phys_at(&self, off: usize) -> u64

Physical address of byte offset off within the arena.

Source

pub fn zero(&self)

Zero the whole arena.

Deliberately not write_bytes. That lowers to memset, and a memset is free to reach for whatever the ISA makes fastest - unaligned stores, cache-line zeroing hints (AArch64’s DC ZVA), non-temporal stores. Every one of those is legal on the Normal cacheable memory x86 maps this arena as, and every one of them is a fault on the Device memory a non-coherent port maps it as instead (DMA_ARENA_UNCACHED, the SEC-28 answer): Device-nGnRnE forbids unaligned access outright and cache maintenance by address on it is not meaningful.

So the clear is an explicit aligned 64-bit volatile loop, which is the one shape that is correct on both. The arena is page-based (a whole number of 4 KiB frames at a page-aligned VA), so the fast path always applies; the byte tail exists only so this function is total rather than silently leaving a remainder, and it cannot run on a real grant.

volatile matters as much as the alignment: an ordinary store loop over Device memory is something the optimiser may merge back into a memset call, which would reintroduce exactly what this avoids.

Source

pub fn read8(&self, off: usize) -> u8

Read an 8-bit value at byte offset off (off < len).

Source

pub fn read16(&self, off: usize) -> u16

Read a 16-bit value at byte offset off (off + 2 <= len; any alignment - see ALIGNMENT above).

Source

pub fn read32(&self, off: usize) -> u32

Read a 32-bit value at byte offset off (off + 4 <= len; any alignment - see ALIGNMENT above).

Source

pub fn write32(&self, off: usize, val: u32)

Write a 32-bit value at byte offset off (off + 4 <= len; any alignment - see ALIGNMENT above).

Source

pub fn write8(&self, off: usize, val: u8)

Write an 8-bit value at byte offset off (off < len). For byte-granular device structures (e.g. an e1000 TX descriptor’s command byte, or frame bytes).

Source

pub fn write16(&self, off: usize, val: u16)

Write a 16-bit value at byte offset off (off + 2 <= len; any alignment - see ALIGNMENT above).

Source

pub fn read64(&self, off: usize) -> u64

Read a 64-bit value at byte offset off (off + 8 <= len; any alignment - see ALIGNMENT above).

Source

pub fn write64(&self, off: usize, val: u64)

Write a 64-bit value at byte offset off (off + 8 <= len; any alignment - see ALIGNMENT above).

Trait Implementations§

Source§

impl Clone for Dma

Source§

fn clone(&self) -> Dma

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Copy for Dma

Auto Trait Implementations§

§

impl Freeze for Dma

§

impl RefUnwindSafe for Dma

§

impl !Send for Dma

§

impl !Sync for Dma

§

impl Unpin for Dma

§

impl UnsafeUnpin for Dma

§

impl UnwindSafe for Dma

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.

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.