Struct CoherentAllocation

Source
pub struct CoherentAllocation<T: AsBytes + FromBytes> { /* private fields */ }
Expand description

An abstraction of the dma_alloc_coherent API.

This is an abstraction around the dma_alloc_coherent API which is used to allocate and map large consistent DMA regions.

A CoherentAllocation instance contains a pointer to the allocated region (in the processor’s virtual address space) and the device address which can be given to the device as the DMA address base of the region. The region is released once CoherentAllocation is dropped.

§Invariants

For the lifetime of an instance of CoherentAllocation, the cpu_addr is a valid pointer to an allocated region of consistent memory and dma_handle is the DMA address base of the region.

Implementations§

Source§

impl<T: AsBytes + FromBytes> CoherentAllocation<T>

Source

pub fn alloc_attrs( dev: &Device<Bound>, count: usize, gfp_flags: Flags, dma_attrs: Attrs, ) -> Result<CoherentAllocation<T>>

Allocates a region of size_of::<T> * count of consistent memory.

§Examples
use kernel::dma::{attrs::*, CoherentAllocation};

let c: CoherentAllocation<u64> =
    CoherentAllocation::alloc_attrs(dev, 4, GFP_KERNEL, DMA_ATTR_NO_WARN)?;
Source

pub fn alloc_coherent( dev: &Device<Bound>, count: usize, gfp_flags: Flags, ) -> Result<CoherentAllocation<T>>

Performs the same functionality as CoherentAllocation::alloc_attrs, except the dma_attrs is 0 by default.

Source

pub fn start_ptr(&self) -> *const T

Returns the base address to the allocated region in the CPU’s virtual address space.

Source

pub fn start_ptr_mut(&mut self) -> *mut T

Returns the base address to the allocated region in the CPU’s virtual address space as a mutable pointer.

Source

pub fn dma_handle(&self) -> dma_addr_t

Returns a DMA handle which may given to the device as the DMA address base of the region.

Trait Implementations§

Source§

impl<T: AsBytes + FromBytes> Drop for CoherentAllocation<T>

Note that the device configured to do DMA must be halted before this object is dropped.

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl<T: AsBytes + FromBytes + Send> Send for CoherentAllocation<T>

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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, E> Init<T, E> for T

Source§

unsafe fn __init(self, slot: *mut T) -> Result<(), E>

Initializes slot. Read more
Source§

fn chain<F>(self, f: F) -> ChainInit<Self, F, T, E>
where F: FnOnce(&mut T) -> Result<(), E>,

First initializes the value using self then calls the function f with the initialized value. 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, E> PinInit<T, E> for T

Source§

unsafe fn __pinned_init(self, slot: *mut T) -> Result<(), E>

Initializes slot. Read more
Source§

fn pin_chain<F>(self, f: F) -> ChainPinInit<Self, F, T, E>
where F: FnOnce(Pin<&mut T>) -> Result<(), E>,

First initializes the value using self then calls the function f with the initialized value. 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.