-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
66 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
pub mod virtio; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
use alloc::vec::Vec; | ||
use crate::mm::{ | ||
frame_alloc, frame_dealloc, kernel_token, FrameTracker, PageTable, PhysAddr, PhysPageNum, | ||
StepByOne, VirtAddr, | ||
}; | ||
use crate::sync::UPIntrFreeCell; | ||
use lazy_static::*; | ||
use virtio_drivers::Hal; | ||
|
||
lazy_static! { | ||
static ref QUEUE_FRAMES: UPIntrFreeCell<Vec<FrameTracker>> = | ||
unsafe { UPIntrFreeCell::new(Vec::new()) }; | ||
} | ||
|
||
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 pa: PhysAddr = ppn_base.into(); | ||
pa.0 | ||
} | ||
|
||
fn dma_dealloc(pa: usize, pages: usize) -> i32 { | ||
let pa = PhysAddr::from(pa); | ||
let mut ppn_base: PhysPageNum = pa.into(); | ||
for _ in 0..pages { | ||
frame_dealloc(ppn_base); | ||
ppn_base.step(); | ||
} | ||
0 | ||
} | ||
|
||
fn phys_to_virt(addr: usize) -> usize { | ||
addr | ||
} | ||
|
||
fn virt_to_phys(vaddr: usize) -> usize { | ||
PageTable::from_token(kernel_token()) | ||
.translate_va(VirtAddr::from(vaddr)) | ||
.unwrap() | ||
.0 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters