Refactor virtio drivers with DMA APIs

This commit is contained in:
Jianfeng Jiang
2024-03-12 11:01:50 +00:00
committed by Tate, Hongliang Tian
parent 5e127b2da0
commit cd1575bc6d
22 changed files with 853 additions and 311 deletions

View File

@ -1,6 +1,7 @@
// SPDX-License-Identifier: MPL-2.0
pub use aster_frame::arch::console::register_console_input_callback;
pub use aster_frame::arch::console;
use aster_frame::vm::VmReader;
use spin::Once;
use crate::{
@ -62,24 +63,25 @@ impl TtyDriver {
Ok(())
}
pub fn receive_char(&self, item: u8) {
pub fn push_char(&self, ch: u8) {
// FIXME: should the char send to all ttys?
for tty in &*self.ttys.lock_irq_disabled() {
tty.receive_char(item);
tty.push_char(ch);
}
}
}
fn console_input_callback(items: &[u8]) {
fn console_input_callback(mut reader: VmReader) {
let tty_driver = get_tty_driver();
for item in items {
tty_driver.receive_char(*item);
while reader.remain() > 0 {
let ch = reader.read_val();
tty_driver.push_char(ch);
}
}
fn serial_input_callback(item: u8) {
let tty_driver = get_tty_driver();
tty_driver.receive_char(item);
tty_driver.push_char(item);
}
fn get_tty_driver() -> &'static TtyDriver {

View File

@ -1,5 +1,6 @@
// SPDX-License-Identifier: MPL-2.0
use aster_frame::early_print;
use spin::Once;
use self::{driver::TtyDriver, line_discipline::LineDiscipline};
@ -61,8 +62,11 @@ impl Tty {
*self.driver.lock_irq_disabled() = driver;
}
pub fn receive_char(&self, ch: u8) {
self.ldisc.push_char(ch, |content| print!("{}", content));
pub fn push_char(&self, ch: u8) {
// FIXME: Use `early_print` to avoid calling virtio-console.
// This is only a workaround
self.ldisc
.push_char(ch, |content| early_print!("{}", content))
}
}

View File

@ -42,7 +42,6 @@ impl Ext2 {
.div_ceil(BLOCK_SIZE);
let segment = VmAllocOptions::new(npages)
.uninit(true)
.is_contiguous(true)
.alloc_contiguous()?;
match block_device.read_blocks_sync(super_block.group_descriptors_bid(0), &segment)? {
BioStatus::Complete => (),

View File

@ -80,6 +80,9 @@ fn init_thread() {
"[kernel] Spawn init thread, tid = {}",
current_thread!().tid()
);
// Work queue should be initialized before interrupt is enabled,
// in case any irq handler uses work queue as bottom half
thread::work_queue::init();
// FIXME: Remove this if we move the step of mounting
// the filesystems to be done within the init process.
aster_frame::trap::enable_local();
@ -97,7 +100,6 @@ fn init_thread() {
"[aster-nix/lib.rs] spawn kernel thread, tid = {}",
thread.tid()
);
thread::work_queue::init();
print_banner();