pub struct CoherentBox<T: KnownSize + ?Sized>(/* private fields */);Expand description
CPU-owned DMA allocation that can be converted into a device-shared Coherent object.
Unlike Coherent, a CoherentBox is guaranteed to be fully owned by the CPU – its DMA
address is not exposed and it cannot be accessed by a device. This means it can safely be used
like a normal boxed allocation (e.g. direct reads, writes, and mutable slices are all safe).
A typical use is to allocate a CoherentBox, populate it with normal CPU access, and then
convert it into a Coherent object to share it with the device.
§Examples
CoherentBox<T>:
use kernel::dma::{attrs::*,
Coherent,
CoherentBox,
};
let mut dmem: CoherentBox<u64> = CoherentBox::zeroed(dev, GFP_KERNEL)?;
*dmem = 42;
let dmem: Coherent<u64> = dmem.into();CoherentBox<[T]>:
use kernel::dma::{attrs::*,
Coherent,
CoherentBox,
};
let mut dmem: CoherentBox<[u64]> = CoherentBox::zeroed_slice(dev, 4, GFP_KERNEL)?;
dmem.fill(42);
let dmem: Coherent<[u64]> = dmem.into();Implementations§
Source§impl<T: AsBytes + FromBytes> CoherentBox<[T]>
impl<T: AsBytes + FromBytes> CoherentBox<[T]>
Sourcepub fn zeroed_slice_with_attrs(
dev: &Device<Bound>,
count: usize,
gfp_flags: Flags,
dma_attrs: Attrs,
) -> Result<Self>
pub fn zeroed_slice_with_attrs( dev: &Device<Bound>, count: usize, gfp_flags: Flags, dma_attrs: Attrs, ) -> Result<Self>
CoherentBox variant of Coherent::zeroed_slice_with_attrs.
Sourcepub fn zeroed_slice(
dev: &Device<Bound>,
count: usize,
gfp_flags: Flags,
) -> Result<Self>
pub fn zeroed_slice( dev: &Device<Bound>, count: usize, gfp_flags: Flags, ) -> Result<Self>
Same as CoherentBox::zeroed_slice_with_attrs, but with dma::Attrs(0).
Sourcepub fn init_at<E>(&mut self, i: usize, init: impl Init<T, E>) -> Result
pub fn init_at<E>(&mut self, i: usize, init: impl Init<T, E>) -> Result
Initializes the element at i using the given initializer.
Returns EINVAL if i is out of bounds.
Sourcepub fn from_slice_with_attrs(
dev: &Device<Bound>,
data: &[T],
gfp_flags: Flags,
dma_attrs: Attrs,
) -> Result<Self>where
T: Copy,
pub fn from_slice_with_attrs(
dev: &Device<Bound>,
data: &[T],
gfp_flags: Flags,
dma_attrs: Attrs,
) -> Result<Self>where
T: Copy,
Allocates a region of coherent memory of the same size as data and initializes it with a
copy of its contents.
This is the CoherentBox variant of Coherent::from_slice_with_attrs.
§Examples
use core::ops::Deref;
use kernel::dma::{
attrs::*,
CoherentBox
};
let data = [0u8, 1u8, 2u8, 3u8];
let c: CoherentBox<[u8]> =
CoherentBox::from_slice_with_attrs(dev, &data, GFP_KERNEL, DMA_ATTR_NO_WARN)?;
assert_eq!(c.deref(), &data);Sourcepub fn from_slice(
dev: &Device<Bound>,
data: &[T],
gfp_flags: Flags,
) -> Result<Self>where
T: Copy,
pub fn from_slice(
dev: &Device<Bound>,
data: &[T],
gfp_flags: Flags,
) -> Result<Self>where
T: Copy,
Performs the same functionality as CoherentBox::from_slice_with_attrs, except the
dma_attrs is 0 by default.
Source§impl<T: AsBytes + FromBytes> CoherentBox<T>
impl<T: AsBytes + FromBytes> CoherentBox<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>
Same as CoherentBox::zeroed_slice_with_attrs, but for a single element.
Trait Implementations§
Auto Trait Implementations§
impl<T> Freeze for CoherentBox<T>where
T: ?Sized,
impl<T> !RefUnwindSafe for CoherentBox<T>
impl<T> Send for CoherentBox<T>
impl<T> Sync for CoherentBox<T>
impl<T> Unpin for CoherentBox<T>where
T: ?Sized,
impl<T> UnsafeUnpin for CoherentBox<T>where
T: ?Sized,
impl<T> !UnwindSafe for CoherentBox<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