mirror of
https://github.com/asterinas/asterinas.git
synced 2025-06-26 02:43:24 +00:00
Add DmaBuf for DMA-capable memory areas
This commit is contained in:
committed by
Tate, Hongliang Tian
parent
a60a8ad3e1
commit
d8a841f88a
@ -38,7 +38,7 @@ struct DmaStreamInner {
|
||||
|
||||
/// `DmaDirection` limits the data flow direction of `DmaStream` and
|
||||
/// prevents users from reading and writing to `DmaStream` unexpectedly.
|
||||
#[derive(Debug, PartialEq, Clone)]
|
||||
#[derive(Debug, PartialEq, Clone, Copy)]
|
||||
pub enum DmaDirection {
|
||||
ToDevice,
|
||||
FromDevice,
|
||||
@ -108,6 +108,10 @@ impl DmaStream {
|
||||
&self.inner.vm_segment
|
||||
}
|
||||
|
||||
pub fn nframes(&self) -> usize {
|
||||
self.inner.vm_segment.nframes()
|
||||
}
|
||||
|
||||
pub fn nbytes(&self) -> usize {
|
||||
self.inner.vm_segment.nbytes()
|
||||
}
|
||||
|
@ -595,6 +595,21 @@ impl<'a> VmReader<'a> {
|
||||
}
|
||||
copy_len
|
||||
}
|
||||
|
||||
/// Read a value of `Pod` type.
|
||||
///
|
||||
/// # Panic
|
||||
///
|
||||
/// If the length of the `Pod` type exceeds `self.remain()`, then this method will panic.
|
||||
pub fn read_val<T: Pod>(&mut self) -> T {
|
||||
assert!(self.remain() >= core::mem::size_of::<T>());
|
||||
|
||||
let mut val = T::new_uninit();
|
||||
let mut writer = VmWriter::from(val.as_bytes_mut());
|
||||
let read_len = self.read(&mut writer);
|
||||
|
||||
val
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> From<&'a [u8]> for VmReader<'a> {
|
||||
|
@ -25,7 +25,7 @@ use core::ops::Range;
|
||||
use spin::Once;
|
||||
|
||||
pub use self::{
|
||||
dma::{DmaCoherent, DmaDirection, DmaStream, HasDaddr},
|
||||
dma::{Daddr, DmaCoherent, DmaDirection, DmaStream, HasDaddr},
|
||||
frame::{VmFrame, VmFrameVec, VmFrameVecIter, VmReader, VmSegment, VmWriter},
|
||||
io::VmIo,
|
||||
memory_set::{MapArea, MemorySet},
|
||||
|
Reference in New Issue
Block a user