pub struct Coherent<T: KnownSize + ?Sized> { /* 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 coherent DMA regions.
A Coherent 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 Coherent
is dropped.
§Invariants
- For the lifetime of an instance of
Coherent, thecpu_addris a valid pointer to an allocated region of coherent memory anddma_handleis the DMA address base of the region. - The size in bytes of the allocation is equal to size information via pointer.
Implementations§
Source§impl<T: KnownSize + ?Sized> Coherent<T>
impl<T: KnownSize + ?Sized> Coherent<T>
Sourcepub fn as_ptr(&self) -> *const T
pub fn as_ptr(&self) -> *const T
Returns the raw pointer to the allocated region in the CPU’s virtual address space.
Sourcepub fn as_mut_ptr(&self) -> *mut T
pub fn as_mut_ptr(&self) -> *mut T
Returns the raw pointer to the allocated region in the CPU’s virtual address space as a mutable pointer.
Sourcepub fn dma_handle(&self) -> DmaAddress
pub fn dma_handle(&self) -> DmaAddress
Returns a DMA handle which may be given to the device as the DMA address base of the region.
Sourcepub unsafe fn as_ref(&self) -> &T
pub unsafe fn as_ref(&self) -> &T
Returns a reference to the data in the region.
§Safety
- Callers must ensure that the device does not read/write to/from memory while the returned slice is live.
- Callers must ensure that this call does not race with a write to the same region while the returned slice is live.
Sourcepub unsafe fn as_mut(&self) -> &mut T
pub unsafe fn as_mut(&self) -> &mut T
Returns a mutable reference to the data in the region.
§Safety
- Callers must ensure that the device does not read/write to/from memory while the returned slice is live.
- Callers must ensure that this call does not race with a read or write to the same region while the returned slice is live.
Source§impl<T: AsBytes + FromBytes> Coherent<T>
impl<T: AsBytes + FromBytes> Coherent<T>
Sourcepub fn zeroed_with_attrs(
dev: &Device<Bound>,
gfp_flags: Flags,
dma_attrs: Attrs,
) -> Result<Self>
pub fn zeroed_with_attrs( dev: &Device<Bound>, gfp_flags: Flags, dma_attrs: Attrs, ) -> Result<Self>
Allocates a region of type T of coherent memory.
§Examples
use kernel::dma::{
attrs::*,
Coherent,
};
let c: Coherent<[u64; 4]> =
Coherent::zeroed_with_attrs(dev, GFP_KERNEL, DMA_ATTR_NO_WARN)?;Sourcepub fn zeroed(dev: &Device<Bound>, gfp_flags: Flags) -> Result<Self>
pub fn zeroed(dev: &Device<Bound>, gfp_flags: Flags) -> Result<Self>
Performs the same functionality as Coherent::zeroed_with_attrs, except the
dma_attrs is 0 by default.
Sourcepub fn init_with_attrs<E>(
dev: &Device<Bound>,
gfp_flags: Flags,
dma_attrs: Attrs,
init: impl Init<T, E>,
) -> Result<Self>
pub fn init_with_attrs<E>( dev: &Device<Bound>, gfp_flags: Flags, dma_attrs: Attrs, init: impl Init<T, E>, ) -> Result<Self>
Same as Coherent::zeroed_with_attrs, but instead of a zero-initialization the memory is
initialized with init.
Sourcepub fn init<E>(
dev: &Device<Bound>,
gfp_flags: Flags,
init: impl Init<T, E>,
) -> Result<Self>
pub fn init<E>( dev: &Device<Bound>, gfp_flags: Flags, init: impl Init<T, E>, ) -> Result<Self>
Same as Coherent::zeroed, but instead of a zero-initialization the memory is initialized
with init.
Sourcepub fn zeroed_slice_with_attrs(
dev: &Device<Bound>,
len: usize,
gfp_flags: Flags,
dma_attrs: Attrs,
) -> Result<Coherent<[T]>>
pub fn zeroed_slice_with_attrs( dev: &Device<Bound>, len: usize, gfp_flags: Flags, dma_attrs: Attrs, ) -> Result<Coherent<[T]>>
Allocates a zeroed region of type T of coherent memory.
Unlike Coherent::<[T; N]>::zeroed_with_attrs, Coherent::<T>::zeroed_slices support
a runtime length.
§Examples
use kernel::dma::{
attrs::*,
Coherent,
};
let c: Coherent<[u64]> =
Coherent::zeroed_slice_with_attrs(dev, 4, GFP_KERNEL, DMA_ATTR_NO_WARN)?;Sourcepub fn zeroed_slice(
dev: &Device<Bound>,
len: usize,
gfp_flags: Flags,
) -> Result<Coherent<[T]>>
pub fn zeroed_slice( dev: &Device<Bound>, len: usize, gfp_flags: Flags, ) -> Result<Coherent<[T]>>
Performs the same functionality as Coherent::zeroed_slice_with_attrs, except the
dma_attrs is 0 by default.
Trait Implementations§
Source§impl<T: KnownSize + ?Sized> Drop for Coherent<T>
Note that the device configured to do DMA must be halted before this object is dropped.
impl<T: KnownSize + ?Sized> Drop for Coherent<T>
Note that the device configured to do DMA must be halted before this object is dropped.
Source§impl<T: AsBytes + FromBytes + KnownSize + ?Sized> From<CoherentBox<T>> for Coherent<T>
impl<T: AsBytes + FromBytes + KnownSize + ?Sized> From<CoherentBox<T>> for Coherent<T>
Source§fn from(value: CoherentBox<T>) -> Self
fn from(value: CoherentBox<T>) -> Self
impl<T: KnownSize + Send + ?Sized> Send for Coherent<T>
Auto Trait Implementations§
impl<T> Freeze for Coherent<T>where
T: ?Sized,
impl<T> !RefUnwindSafe for Coherent<T>
impl<T> !Sync for Coherent<T>
impl<T> Unpin for Coherent<T>where
T: ?Sized,
impl<T> UnsafeUnpin for Coherent<T>where
T: ?Sized,
impl<T> !UnwindSafe for Coherent<T>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> PinInit<T> for T
impl<T> PinInit<T> for T
Source§unsafe fn __pinned_init(self, slot: *mut T) -> Result<(), Infallible>
unsafe fn __pinned_init(self, slot: *mut T) -> Result<(), Infallible>
slot. Read more