starina_driver_utils

Struct DmaBufferPool

Source
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

Source

pub fn new(buffer_size: usize, num_buffers: usize) -> DmaBufferPool

Source

pub fn allocate(&mut self) -> Option<BufferId>

Allocates a buffer.

Source

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

Frees a buffer.

Source

pub fn paddr_to_id(&self, paddr: PAddr) -> Option<BufferId>

Converts a physical memory address to a buffer index.

Source

pub fn vaddr(&self, index: BufferId) -> VAddr

Returns the virtual memory address of a buffer.

Source

pub fn paddr(&self, index: BufferId) -> PAddr

Returns the physical memory address of a buffer.

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.