morpheus_network::dma::pool

Struct BufferPool

Source
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: usize

Number of free buffers.

§total_count: usize

Total number of buffers in pool.

§buffer_size: usize

Size of each buffer.

Implementations§

Source§

impl BufferPool

Source

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 start
  • bus_base: Bus address of buffer region start
  • buffer_size: Size of each buffer (should be >= 1526 for RX)
  • count: Number of buffers (max 32)
§Safety
  • cpu_base must point to valid DMA-capable memory
  • bus_base must be the corresponding device-visible address
  • Memory must be at least buffer_size * count bytes
Source

pub fn alloc(&mut self) -> Option<&mut DmaBuffer>

Allocate a buffer from the pool.

Returns None if pool is exhausted.

Source

pub fn free(&mut self, index: u16)

Return a buffer to the pool.

§Arguments
  • index: Buffer index (must be valid and driver-owned)
Source

pub fn get_mut(&mut self, index: u16) -> Option<&mut DmaBuffer>

Get mutable reference to buffer by index.

§Panics

Panics if index is out of range.

Source

pub fn get(&self, index: u16) -> Option<&DmaBuffer>

Get reference to buffer by index.

Source

pub fn available(&self) -> usize

Get number of available (free) buffers.

Source

pub fn total(&self) -> usize

Get total number of buffers in pool.

Source

pub fn in_use(&self) -> usize

Get number of buffers currently in use.

Source

pub fn is_empty(&self) -> bool

Check if pool is empty (no free buffers).

Source

pub fn is_full(&self) -> bool

Check if pool is full (all buffers free).

Source

pub fn buffer_size(&self) -> usize

Get buffer size.

Source

pub fn iter(&self) -> impl Iterator<Item = &DmaBuffer>

Iterate over all buffers (for debugging).

Source

pub fn iter_mut(&mut self) -> impl Iterator<Item = &mut DmaBuffer>

Iterate over all buffers mutably.

Trait Implementations§

Source§

impl Default for BufferPool

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.