pub struct PagedBuffer { /* private fields */ }Expand description
A paged DMA buffer consisting of one or more pinned pages that are contiguous in virtual memory
(Mapping), but may be discontiguous in physical memory.
Implementations§
Source§impl PagedBuffer
impl PagedBuffer
Sourcepub fn new(bti: &Bti, size: usize) -> Result<Self, Status>
pub fn new(bti: &Bti, size: usize) -> Result<Self, Status>
Creates a new paged DMA buffer of size bytes (rounded up to the system page size) mapped
in the root VMAR with CPU caching enabled.
Sourcepub fn new_with_vmar(
bti: &Bti,
vmar: &Vmar,
size: usize,
) -> Result<Self, Status>
pub fn new_with_vmar( bti: &Bti, vmar: &Vmar, size: usize, ) -> Result<Self, Status>
Creates a new paged DMA buffer of size bytes (rounded up to the system page size) mapped
in vmar with CPU caching enabled.
Sourcepub fn new_with_options(
bti: &Bti,
vmar: &Vmar,
size: usize,
cache_options: CacheOptions,
) -> Result<Self, Status>
pub fn new_with_options( bti: &Bti, vmar: &Vmar, size: usize, cache_options: CacheOptions, ) -> Result<Self, Status>
Creates a new paged DMA buffer of size bytes (rounded up to the system page size) mapped
in vmar with the specified cache_options.
Sourcepub fn phys(&self) -> &[zx_paddr_t] ⓘ
pub fn phys(&self) -> &[zx_paddr_t] ⓘ
Returns the slice of pinned page physical addresses backing the buffer.
Sourcepub unsafe fn unpin(self) -> Result<(), Status>
pub unsafe fn unpin(self) -> Result<(), Status>
Unpins the DMA buffer’s physical memory token, consuming the buffer so its physical addresses and mapping cannot be accessed after unpinning.
§Safety
The caller must ensure that hardware is no longer accessing the pinned memory (e.g. after resetting or quiescing the device).
Methods from Deref<Target = Buffer>§
Sourcepub fn mapping_mut(&mut self) -> &mut Mapping
pub fn mapping_mut(&mut self) -> &mut Mapping
Returns a mutable reference to the underlying Mapping.
Sourcepub fn is_cache_enabled(&self) -> bool
pub fn is_cache_enabled(&self) -> bool
Returns whether CPU caching is enabled for this DMA buffer.
Sourcepub fn cache_options(&self) -> CacheOptions
pub fn cache_options(&self) -> CacheOptions
Returns the CacheOptions configured for this DMA buffer.
Sourcepub fn cache_flush(&self, offset: usize, length: usize) -> Result<(), Status>
pub fn cache_flush(&self, offset: usize, length: usize) -> Result<(), Status>
Flushes CPU data cache lines (clean to memory) for the given byte range.
Use after CPU writes to the buffer so that DMA hardware can read from physical RAM
(DMA_TO_DEVICE).
Sourcepub fn cache_flush_invalidate(
&self,
offset: usize,
length: usize,
) -> Result<(), Status>
pub fn cache_flush_invalidate( &self, offset: usize, length: usize, ) -> Result<(), Status>
Flushes and invalidates CPU data cache lines for the given byte range.
Use before CPU reads from the buffer after DMA hardware writes to physical RAM
(DMA_FROM_DEVICE).
Sourcepub fn write(&self, offset: usize, src: &[u8]) -> Result<(), Status>
pub fn write(&self, offset: usize, src: &[u8]) -> Result<(), Status>
Writes src into the DMA buffer at offset and flushes the CPU cache if caching is
enabled.
Sourcepub fn read(&self, offset: usize, dst: &mut [u8]) -> Result<(), Status>
pub fn read(&self, offset: usize, dst: &mut [u8]) -> Result<(), Status>
Invalidates the CPU cache if caching is enabled and reads from the DMA buffer at offset
into dst.
Sourcepub fn write_struct<T: IntoBytes + Immutable>(
&self,
offset: usize,
val: &T,
) -> Result<(), Status>
pub fn write_struct<T: IntoBytes + Immutable>( &self, offset: usize, val: &T, ) -> Result<(), Status>
Writes a value of type T at byte offset with automatic cache flush.
Sourcepub fn read_struct<T: FromBytes + IntoBytes + KnownLayout + Immutable>(
&self,
offset: usize,
) -> Result<T, Status>
pub fn read_struct<T: FromBytes + IntoBytes + KnownLayout + Immutable>( &self, offset: usize, ) -> Result<T, Status>
Reads a value of type T from byte offset with automatic cache invalidation.
Sourcepub fn read_element<T: FromBytes + IntoBytes + KnownLayout + Immutable>(
&self,
index: usize,
) -> T
pub fn read_element<T: FromBytes + IntoBytes + KnownLayout + Immutable>( &self, index: usize, ) -> T
Reads the index-th element of type T (at byte offset index * size_of::<T>()) from the
mapped buffer.
§Panics
Panics if index * size_of::<T>() + size_of::<T>() overflows or exceeds self.size().