Skip to main content

Coherent

Struct Coherent 

Source
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, the cpu_addr is a valid pointer to an allocated region of coherent memory and dma_handle is 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>

Source

pub fn size(&self) -> usize

Returns the size in bytes of this allocation.

Source

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

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

Source

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.

Source

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.

Source

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.
Source

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>

Source

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)?;
Source

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.

Source

pub fn init_with_attrs<E>( dev: &Device<Bound>, gfp_flags: Flags, dma_attrs: Attrs, init: impl Init<T, E>, ) -> Result<Self>
where Error: From<E>,

Same as Coherent::zeroed_with_attrs, but instead of a zero-initialization the memory is initialized with init.

Source

pub fn init<E>( dev: &Device<Bound>, gfp_flags: Flags, init: impl Init<T, E>, ) -> Result<Self>
where Error: From<E>,

Same as Coherent::zeroed, but instead of a zero-initialization the memory is initialized with init.

Source

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)?;
Source

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.

Source§

impl<T> Coherent<[T]>

Source

pub fn len(&self) -> usize

Returns the number of elements T in this allocation.

Note that this is not the size of the allocation in bytes, which is provided by Self::size.

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.

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl<T: AsBytes + FromBytes + KnownSize + ?Sized> From<CoherentBox<T>> for Coherent<T>

Source§

fn from(value: CoherentBox<T>) -> Self

Converts to this type from the input type.
Source§

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

Source§

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

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

Source§

fn size(_: *const T) -> usize

Get the size of an object of this type in bytes, with the metadata of the given pointer.
Source§

impl<T> PinInit<T> for T

Source§

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

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.
Source§

impl<T, U, const N: u32> TryIntoBounded<T, N> for U
where T: Integer, U: TryInto<T>,

Source§

fn try_into_bounded(self) -> Option<Bounded<T, N>>

Attempts to convert self into a Bounded using N bits. Read more