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).
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
Mutably borrows from an owned value. Read more
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>
Initializes
slot. Read more