extract device drivers into new module

This commit is contained in:
Garen Tyler 2023-11-09 21:03:21 -07:00
parent 9693d83bde
commit 49584f0f26
Signed by: garentyler
GPG Key ID: D7A048C454CB7054
14 changed files with 28 additions and 13 deletions

View File

@ -45,7 +45,10 @@ pub mod mem {
pub mod virtual_memory { pub mod virtual_memory {
#[cfg(target_arch = "riscv64")] #[cfg(target_arch = "riscv64")]
pub use super::riscv::virtual_memory::{kvminit as init, kvminithart as inithart, copyin, copyinstr, copyout, mappages, uvmalloc, uvmcopy, uvmcreate, uvmdealloc, uvmfree, uvmunmap}; pub use super::riscv::virtual_memory::{
copyin, copyinstr, copyout, kvminit as init, kvminithart as inithart, mappages, uvmalloc,
uvmcopy, uvmcreate, uvmdealloc, uvmfree, uvmunmap,
};
} }
pub mod power { pub mod power {

View File

@ -57,7 +57,7 @@ pub unsafe fn devintr() -> i32 {
let irq = interrupt::handle_interrupt(); let irq = interrupt::handle_interrupt();
if irq == UART0_IRQ { if irq == UART0_IRQ {
crate::console::uart::UART0.interrupt(); crate::hardware::uart::UART0.interrupt();
} else if irq == VIRTIO0_IRQ { } else if irq == VIRTIO0_IRQ {
virtio_disk_intr(); virtio_disk_intr();
} else if irq > 0 { } else if irq > 0 {

View File

@ -1,4 +1,9 @@
use super::{asm, mem::{make_satp, pte2pa}, plic::PLIC, power::QEMU_POWER}; use super::{
asm,
mem::{make_satp, pte2pa},
plic::PLIC,
power::QEMU_POWER,
};
use crate::{ use crate::{
arch::{ arch::{
self, self,

View File

@ -9,10 +9,10 @@
// - ctrl-p: print process list // - ctrl-p: print process list
pub mod printf; pub mod printf;
pub mod uart;
use crate::{ use crate::{
fs::file::{devsw, CONSOLE}, fs::file::{devsw, CONSOLE},
hardware::uart::UART0,
proc::{ proc::{
process::{procdump, Process}, process::{procdump, Process},
scheduler::wakeup, scheduler::wakeup,
@ -20,7 +20,6 @@ use crate::{
sync::mutex::Mutex, sync::mutex::Mutex,
}; };
use core::{ffi::c_void, ptr::addr_of_mut}; use core::{ffi::c_void, ptr::addr_of_mut};
use uart::UART0;
extern "C" { extern "C" {
fn either_copyin(dst: *mut c_void, user_src: i32, src: u64, len: u64) -> i32; fn either_copyin(dst: *mut c_void, user_src: i32, src: u64, len: u64) -> i32;

View File

@ -30,13 +30,13 @@ pub(crate) use println;
/// Does not use any locks. /// Does not use any locks.
macro_rules! uprint { macro_rules! uprint {
($($arg:tt)*) => {{ ($($arg:tt)*) => {{
use $crate::console::uart::Uart; use $crate::hardware::uart::Uart;
use core::fmt::Write; use core::fmt::Write;
// Do some casts to get a mutable reference. // Do some casts to get a mutable reference.
// Safe because Uart's core::fmt::Write implementation // Safe because Uart's core::fmt::Write implementation
// only uses the &mut reference immutably. // only uses the &mut reference immutably.
let uart: *const Uart = &$crate::console::uart::UART0 as *const Uart; let uart: *const Uart = &$crate::hardware::uart::UART0 as *const Uart;
let uart: &mut Uart = unsafe { &mut *uart.cast_mut() }; let uart: &mut Uart = unsafe { &mut *uart.cast_mut() };
let _ = core::write!(uart, $($arg)*); let _ = core::write!(uart, $($arg)*);

View File

@ -1,9 +1,9 @@
//! Support functions for system calls that involve file descriptors. //! Support functions for system calls that involve file descriptors.
use crate::{ use crate::{
arch::virtual_memory::copyout,
fs::{log, stat::Stat}, fs::{log, stat::Stat},
io::pipe::Pipe, io::pipe::Pipe,
arch::virtual_memory::copyout,
proc::process::Process, proc::process::Process,
sync::{sleeplock::Sleeplock, spinlock::Spinlock}, sync::{sleeplock::Sleeplock, spinlock::Spinlock},
}; };

View File

@ -3,9 +3,7 @@
pub mod file; pub mod file;
pub mod log; pub mod log;
pub mod ramdisk;
pub mod stat; pub mod stat;
pub mod virtio_disk;
use crate::fs::file::Inode; use crate::fs::file::Inode;

View File

@ -0,0 +1,5 @@
//! Device drivers and hardware implementations.
pub mod ramdisk;
pub mod uart;
pub mod virtio_disk;

View File

@ -1,7 +1,7 @@
use crate::{ use crate::{
arch::virtual_memory::{copyin, copyout},
fs::file::{filealloc, fileclose, File, FileType}, fs::file::{filealloc, fileclose, File, FileType},
mem::kalloc::{kalloc, kfree}, mem::kalloc::{kalloc, kfree},
arch::virtual_memory::{copyin, copyout},
proc::{process::Process, scheduler::wakeup}, proc::{process::Process, scheduler::wakeup},
sync::spinlock::Spinlock, sync::spinlock::Spinlock,
}; };

View File

@ -11,6 +11,7 @@ extern crate core;
mod arch; mod arch;
mod console; mod console;
mod fs; mod fs;
mod hardware;
mod io; mod io;
mod mem; mod mem;
mod proc; mod proc;
@ -68,7 +69,7 @@ pub unsafe fn main() -> ! {
io::bio::binit(); io::bio::binit();
fs::iinit(); fs::iinit();
fs::file::fileinit(); fs::file::fileinit();
fs::virtio_disk::virtio_disk_init(); hardware::virtio_disk::virtio_disk_init();
proc::process::userinit(); proc::process::userinit();
STARTED = true; STARTED = true;
} else { } else {

View File

@ -1,5 +1,9 @@
use crate::{ use crate::{
arch::{clock::CLOCK_TICKS, power::shutdown, virtual_memory::{copyin, copyinstr}}, arch::{
clock::CLOCK_TICKS,
power::shutdown,
virtual_memory::{copyin, copyinstr},
},
fs::{ fs::{
self, self,
file::{self, File}, file::{self, File},