From fa2d574c3b528518b329102efac93b1a4cd88a88 Mon Sep 17 00:00:00 2001 From: yufeng <321353225@qq.com> Date: Mon, 6 Feb 2023 19:15:46 +0800 Subject: [PATCH] use frame_alloc_more in VirtioHal --- os/src/drivers/bus/virtio.rs | 14 ++++---------- os/src/mm/mod.rs | 2 +- 2 files changed, 5 insertions(+), 11 deletions(-) diff --git a/os/src/drivers/bus/virtio.rs b/os/src/drivers/bus/virtio.rs index 6871eb87..d9a61219 100644 --- a/os/src/drivers/bus/virtio.rs +++ b/os/src/drivers/bus/virtio.rs @@ -1,6 +1,6 @@ use crate::mm::{ frame_alloc, frame_dealloc, kernel_token, FrameTracker, PageTable, PhysAddr, PhysPageNum, - StepByOne, VirtAddr, + StepByOne, VirtAddr, frame_alloc_more, }; use crate::sync::UPIntrFreeCell; use alloc::vec::Vec; @@ -16,15 +16,9 @@ pub struct VirtioHal; impl Hal for VirtioHal { fn dma_alloc(pages: usize) -> usize { - let mut ppn_base = PhysPageNum(0); - for i in 0..pages { - let frame = frame_alloc().unwrap(); - if i == 0 { - ppn_base = frame.ppn; - } - assert_eq!(frame.ppn.0, ppn_base.0 + i); - QUEUE_FRAMES.exclusive_access().push(frame); - } + let trakcers = frame_alloc_more(pages); + let ppn_base = trakcers.as_ref().unwrap().last().unwrap().ppn; + QUEUE_FRAMES.exclusive_access().append(&mut trakcers.unwrap()); let pa: PhysAddr = ppn_base.into(); pa.0 } diff --git a/os/src/mm/mod.rs b/os/src/mm/mod.rs index 34220c4a..05e52ea3 100644 --- a/os/src/mm/mod.rs +++ b/os/src/mm/mod.rs @@ -6,7 +6,7 @@ mod page_table; use address::VPNRange; pub use address::{PhysAddr, PhysPageNum, StepByOne, VirtAddr, VirtPageNum}; -pub use frame_allocator::{frame_alloc, frame_dealloc, FrameTracker}; +pub use frame_allocator::{frame_alloc, frame_alloc_more, frame_dealloc, FrameTracker}; pub use memory_set::remap_test; pub use memory_set::{kernel_token, MapPermission, MemorySet, KERNEL_SPACE}; use page_table::PTEFlags;