mirror of
https://github.com/asterinas/asterinas.git
synced 2025-06-18 03:56:42 +00:00
Add DmaBuf for DMA-capable memory areas
This commit is contained in:
committed by
Tate, Hongliang Tian
parent
a60a8ad3e1
commit
d8a841f88a
25
kernel/comps/virtio/src/dma_buf.rs
Normal file
25
kernel/comps/virtio/src/dma_buf.rs
Normal 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()
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user