Add DmaBuf for DMA-capable memory areas

This commit is contained in:
Jianfeng Jiang
2024-03-12 11:09:15 +00:00
committed by Tate, Hongliang Tian
parent a60a8ad3e1
commit d8a841f88a
6 changed files with 129 additions and 3 deletions

View File

@ -0,0 +1,25 @@
// SPDX-License-Identifier: MPL-2.0
use aster_frame::vm::{DmaCoherent, DmaStream, HasDaddr};
/// A DMA-capable buffer.
///
/// Any type implements this trait should also implements `HasDaddr` trait,
/// and provides the exact length of DMA area.
#[allow(clippy::len_without_is_empty)]
pub trait DmaBuf: HasDaddr {
/// The length of Dma area, in bytes
fn len(&self) -> usize;
}
impl DmaBuf for DmaStream {
fn len(&self) -> usize {
self.nbytes()
}
}
impl DmaBuf for DmaCoherent {
fn len(&self) -> usize {
self.nbytes()
}
}