morpheus_network::dma::buffer

Struct DmaBuffer

Source
pub struct DmaBuffer {
    cpu_ptr: *mut u8,
    bus_addr: u64,
    capacity: usize,
    ownership: BufferOwnership,
    index: u16,
}
Expand description

A single DMA buffer with ownership tracking.

Tracks both CPU and bus addresses, plus ownership state.

Fields§

§cpu_ptr: *mut u8

CPU-accessible pointer to buffer data.

§bus_addr: u64

Device-visible bus address.

§capacity: usize

Buffer capacity in bytes.

§ownership: BufferOwnership

Current ownership state.

§index: u16

Buffer index within the pool.

Implementations§

Source§

impl DmaBuffer

Source

pub unsafe fn new( cpu_ptr: *mut u8, bus_addr: u64, capacity: usize, index: u16, ) -> Self

Create a new DMA buffer.

§Safety
  • cpu_ptr must point to valid DMA-capable memory
  • bus_addr must be the corresponding device-visible address
Source

pub fn as_slice(&self) -> &[u8]

Get buffer data as slice.

§Panics

Panics if buffer is not DriverOwned.

Source

pub fn as_mut_slice(&mut self) -> &mut [u8]

Get buffer data as mutable slice.

§Panics

Panics if buffer is not DriverOwned.

Source

pub fn as_mut_slice_len(&mut self, len: usize) -> &mut [u8]

Get the first len bytes as mutable slice.

§Panics

Panics if buffer is not DriverOwned or len > capacity.

Source

pub fn bus_addr(&self) -> u64

Get the device-visible bus address.

Source

pub fn cpu_ptr(&self) -> *mut u8

Get the CPU pointer.

Source

pub fn index(&self) -> u16

Get buffer index.

Source

pub fn capacity(&self) -> usize

Get buffer capacity.

Source

pub fn ownership(&self) -> BufferOwnership

Get current ownership state.

Source

pub fn is_free(&self) -> bool

Check if buffer can be allocated.

Source

pub fn is_driver_owned(&self) -> bool

Check if buffer is owned by driver.

Source

pub fn is_device_owned(&self) -> bool

Check if buffer is owned by device.

Source

pub(crate) unsafe fn mark_allocated(&mut self)

Mark buffer as allocated (Free -> DriverOwned).

§Safety

Only call during allocation from pool.

Source

pub unsafe fn mark_device_owned(&mut self)

Mark buffer as device-owned (DriverOwned -> DeviceOwned).

§Safety

Only call immediately before submitting to device.

Source

pub unsafe fn mark_driver_owned(&mut self)

Mark buffer as driver-owned (DeviceOwned -> DriverOwned).

§Safety

Only call after device confirms ownership transfer (poll completion).

Source

pub(crate) unsafe fn mark_free(&mut self)

Mark buffer as free (DriverOwned -> Free).

§Safety

Only call during return to pool.

Trait Implementations§

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.