pub struct BufferPool {
buffers: [Option<DmaBuffer>; 32],
free_list: [u16; 32],
free_count: usize,
total_count: usize,
buffer_size: usize,
}Expand description
Pre-allocated buffer pool for a virtqueue.
Manages a fixed set of DMA buffers with free list tracking.
Fields§
§buffers: [Option<DmaBuffer>; 32]Array of DMA buffers.
free_list: [u16; 32]Free list (indices of free buffers).
free_count: usizeNumber of free buffers.
total_count: usizeTotal number of buffers in pool.
buffer_size: usizeSize of each buffer.
Implementations§
Source§impl BufferPool
impl BufferPool
Sourcepub unsafe fn new(
cpu_base: *mut u8,
bus_base: u64,
buffer_size: usize,
count: usize,
) -> Self
pub unsafe fn new( cpu_base: *mut u8, bus_base: u64, buffer_size: usize, count: usize, ) -> Self
Create a new buffer pool from DMA region.
§Arguments
cpu_base: CPU pointer to buffer region startbus_base: Bus address of buffer region startbuffer_size: Size of each buffer (should be >= 1526 for RX)count: Number of buffers (max 32)
§Safety
cpu_basemust point to valid DMA-capable memorybus_basemust be the corresponding device-visible address- Memory must be at least
buffer_size * countbytes
Sourcepub fn alloc(&mut self) -> Option<&mut DmaBuffer>
pub fn alloc(&mut self) -> Option<&mut DmaBuffer>
Allocate a buffer from the pool.
Returns None if pool is exhausted.
Sourcepub fn buffer_size(&self) -> usize
pub fn buffer_size(&self) -> usize
Get buffer size.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for BufferPool
impl RefUnwindSafe for BufferPool
impl Send for BufferPool
impl Sync for BufferPool
impl Unpin for BufferPool
impl UnwindSafe for BufferPool
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