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>
impl<T: AsBytes + FromBytes> CoherentAllocation<T>
Sourcepub fn alloc_attrs(
dev: &Device,
count: usize,
gfp_flags: Flags,
dma_attrs: Attrs,
) -> Result<CoherentAllocation<T>>
pub fn alloc_attrs( dev: &Device, 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::device::Device;
use kernel::dma::{attrs::*, CoherentAllocation};
let c: CoherentAllocation<u64> =
CoherentAllocation::alloc_attrs(dev, 4, GFP_KERNEL, DMA_ATTR_NO_WARN)?;
Sourcepub fn alloc_coherent(
dev: &Device,
count: usize,
gfp_flags: Flags,
) -> Result<CoherentAllocation<T>>
pub fn alloc_coherent( dev: &Device, count: usize, gfp_flags: Flags, ) -> Result<CoherentAllocation<T>>
Performs the same functionality as CoherentAllocation::alloc_attrs
, except the
dma_attrs
is 0 by default.
Sourcepub fn start_ptr(&self) -> *const T
pub fn start_ptr(&self) -> *const T
Returns the base address to the allocated region in the CPU’s virtual address space.
Sourcepub fn start_ptr_mut(&mut self) -> *mut T
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.
Sourcepub fn dma_handle(&self) -> dma_addr_t
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.
impl<T: AsBytes + FromBytes> Drop for CoherentAllocation<T>
Note that the device configured to do DMA must be halted before this object is dropped.