implement vmo apis

This commit is contained in:
Jianfeng Jiang
2022-12-01 14:20:15 +08:00
parent 244a83e463
commit 31d644a0f3
10 changed files with 561 additions and 42 deletions

View File

@ -4,6 +4,7 @@ use crate::{config::PAGE_SIZE, mm::address::PhysAddr, prelude::*, Error};
use pod::Pod;
use super::VmIo;
use alloc::vec;
use crate::mm::PhysFrame;
@ -31,7 +32,7 @@ impl VmFrameVec {
let mut frame_list = Vec::new();
for i in 0..page_size {
let vm_frame = if let Some(paddr) = options.paddr {
VmFrame::alloc_with_paddr(paddr)
VmFrame::alloc_with_paddr(paddr + i * PAGE_SIZE)
} else {
VmFrame::alloc()
};
@ -88,6 +89,11 @@ impl VmFrameVec {
self.0.iter()
}
/// Return IntoIterator for internal frames
pub fn into_iter(self) -> alloc::vec::IntoIter<VmFrame> {
self.0.into_iter()
}
/// Returns the number of frames.
pub fn len(&self) -> usize {
self.0.len()
@ -104,6 +110,10 @@ impl VmFrameVec {
pub fn nbytes(&self) -> usize {
self.0.len() * PAGE_SIZE
}
pub fn from_one_frame(frame: VmFrame) -> Self {
Self(vec![frame])
}
}
impl VmIo for VmFrameVec {
@ -288,6 +298,11 @@ impl VmFrame {
self.physical_frame.start_pa().0
}
/// fill the frame with zero
pub fn zero(&self) {
unsafe { core::ptr::write_bytes(self.start_pa().kvaddr().as_ptr(), 0, PAGE_SIZE) }
}
pub fn start_pa(&self) -> PhysAddr {
self.physical_frame.start_pa()
}