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 u8CPU-accessible pointer to buffer data.
bus_addr: u64Device-visible bus address.
capacity: usizeBuffer capacity in bytes.
ownership: BufferOwnershipCurrent ownership state.
index: u16Buffer index within the pool.
Implementations§
Source§impl DmaBuffer
impl DmaBuffer
Sourcepub unsafe fn new(
cpu_ptr: *mut u8,
bus_addr: u64,
capacity: usize,
index: u16,
) -> Self
pub unsafe fn new( cpu_ptr: *mut u8, bus_addr: u64, capacity: usize, index: u16, ) -> Self
Create a new DMA buffer.
§Safety
cpu_ptrmust point to valid DMA-capable memorybus_addrmust be the corresponding device-visible address
Sourcepub fn as_mut_slice(&mut self) -> &mut [u8]
pub fn as_mut_slice(&mut self) -> &mut [u8]
Sourcepub fn as_mut_slice_len(&mut self, len: usize) -> &mut [u8]
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.
Sourcepub fn ownership(&self) -> BufferOwnership
pub fn ownership(&self) -> BufferOwnership
Get current ownership state.
Sourcepub fn is_driver_owned(&self) -> bool
pub fn is_driver_owned(&self) -> bool
Check if buffer is owned by driver.
Sourcepub fn is_device_owned(&self) -> bool
pub fn is_device_owned(&self) -> bool
Check if buffer is owned by device.
Sourcepub(crate) unsafe fn mark_allocated(&mut self)
pub(crate) unsafe fn mark_allocated(&mut self)
Sourcepub unsafe fn mark_device_owned(&mut self)
pub unsafe fn mark_device_owned(&mut self)
Mark buffer as device-owned (DriverOwned -> DeviceOwned).
§Safety
Only call immediately before submitting to device.
Sourcepub unsafe fn mark_driver_owned(&mut self)
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).
Trait Implementations§
Auto Trait Implementations§
impl Freeze for DmaBuffer
impl RefUnwindSafe for DmaBuffer
impl Unpin for DmaBuffer
impl UnwindSafe for DmaBuffer
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