1
0
mirror of https://github.com/sgmarz/osblog.git synced 2024-11-24 02:16:19 +04:00

Finish virtio

This commit is contained in:
Stephen Marz 2020-03-15 20:18:09 -04:00
parent 858c838e73
commit 703c2cf5b0
3 changed files with 13 additions and 4 deletions

View File

@ -256,6 +256,9 @@ pub fn block_op(dev: usize, buffer: *mut u8, size: u32, offset: u64, write: bool
return; return;
} }
let sector = offset / 512; let sector = offset / 512;
// TODO: Before we get here, we are NOT allowed to schedule a read or
// write OUTSIDE of the disk's size. So, we can read capacity from
// the configuration space to ensure we stay within bounds.
let blk_request_size = size_of::<Request>(); let blk_request_size = size_of::<Request>();
let blk_request = kmalloc(blk_request_size) as *mut Request; let blk_request = kmalloc(blk_request_size) as *mut Request;
let desc = Descriptor { addr: &(*blk_request).header as *const Header as u64, let desc = Descriptor { addr: &(*blk_request).header as *const Header as u64,

View File

@ -209,6 +209,7 @@ pub mod kmem;
pub mod page; pub mod page;
pub mod plic; pub mod plic;
pub mod process; pub mod process;
pub mod rng;
pub mod sched; pub mod sched;
pub mod syscall; pub mod syscall;
pub mod trap; pub mod trap;

View File

@ -4,6 +4,7 @@
// 10 March 2020 // 10 March 2020
use crate::{block, block::setup_block_device, page::PAGE_SIZE}; use crate::{block, block::setup_block_device, page::PAGE_SIZE};
use crate::rng::setup_entropy_device;
use core::mem::size_of; use core::mem::size_of;
// Flags // Flags
@ -24,6 +25,12 @@ pub const VIRTIO_USED_F_NO_NOTIFY: u16 = 1;
pub const VIRTIO_RING_SIZE: usize = 1 << 7; pub const VIRTIO_RING_SIZE: usize = 1 << 7;
// VirtIO structures // VirtIO structures
// The descriptor holds the data that we need to send to
// the device. The address is a physical address and NOT
// a virtual address. The len is in bytes and the flags are
// specified above. Any descriptor can be chained, hence the
// next field, but only if the F_NEXT flag is specified.
#[repr(C)] #[repr(C)]
pub struct Descriptor { pub struct Descriptor {
pub addr: u64, pub addr: u64,
@ -64,6 +71,8 @@ pub struct Queue {
pub used: Used, pub used: Used,
} }
// The MMIO transport is "legacy" in QEMU, so these registers represent
// the legacy interface.
#[repr(usize)] #[repr(usize)]
pub enum MmioOffsets { pub enum MmioOffsets {
MagicValue = 0x000, MagicValue = 0x000,
@ -280,10 +289,6 @@ pub fn probe() {
} }
} }
pub fn setup_entropy_device(_ptr: *mut u32) -> bool {
false
}
pub fn setup_network_device(_ptr: *mut u32) -> bool { pub fn setup_network_device(_ptr: *mut u32) -> bool {
false false
} }