pub struct DmaBufferPool { /* private fields */ }
Expand description
A DMA buffer pool.
This struct manages a pool of buffers. Unlike a Vec
-based buffers, this
struct provides a way to know the physical memory address of a buffer so
that it can be passed to a device for DMA operations.
§Future Work
- Distinguish the physical memory address and device memory address. Some computers might have different address spaces for devices, and some might have IOMMU to translate the addresses.
§Example
const BUFFER_SIZE: usize = 4096;
const NUM_BUFFERS: usize = 16;
let mut pool = DmaBufferPool::new(BUFFER_SIZE, NUM_BUFFERS);
let buffer_id = pool.allocate().unwrap();
let paddr = pool.paddr(buffer_id);
let vaddr = pool.vaddr(buffer_id);
// Do DMA operations here!
pool.free(buffer_id);
Implementations§
Source§impl DmaBufferPool
impl DmaBufferPool
pub fn new(buffer_size: usize, num_buffers: usize) -> DmaBufferPool
Sourcepub fn paddr_to_id(&self, paddr: PAddr) -> Option<BufferId>
pub fn paddr_to_id(&self, paddr: PAddr) -> Option<BufferId>
Converts a physical memory address to a buffer index.
Auto Trait Implementations§
impl Freeze for DmaBufferPool
impl RefUnwindSafe for DmaBufferPool
impl Send for DmaBufferPool
impl Sync for DmaBufferPool
impl Unpin for DmaBufferPool
impl UnwindSafe for DmaBufferPool
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