Commit 63dd2286 authored by Jeremy Soller's avatar Jeremy Soller

nvmed: Verify correct memory space

parent 7be81d78
......@@ -11,6 +11,8 @@ use std::io::{Read, Write};
use std::os::unix::io::{AsRawFd, FromRawFd, RawFd};
use syscall::{EVENT_READ, MAP_WRITE, Event, Packet, Result, Scheme};
use self::nvme::Nvme;
mod nvme;
fn create_scheme_fallback<'a>(name: &'a str, fallback: &'a str) -> Result<(&'a str, RawFd)> {
......@@ -40,6 +42,8 @@ fn main() {
if unsafe { syscall::clone(0).unwrap() } == 0 {
let address = unsafe { syscall::physmap(bar, 4096, MAP_WRITE).expect("nvmed: failed to map address") };
{
let mut nvme = Nvme::new(address);
nvme.init();
/*
let (_scheme_name, socket_fd) = create_scheme_fallback("disk", &name).expect("nvmed: failed to create disk scheme");
let mut socket = unsafe { File::from_raw_fd(socket_fd) };
......
use syscall::io::{Io, Mmio};
#[repr(packed)]
pub struct NvmeCmd {
/// Command dword 0
cdw0: u32,
/// Opcode
opcode: u8,
/// Flags
flags: u8,
/// Command ID
cid: u16,
/// Namespace identifier
nsid: u32,
/// Reserved
......@@ -28,7 +33,9 @@ pub struct NvmeCmd {
impl NvmeCmd {
pub fn read(cid: u16, lba: u64, count: u16, dst: u64) -> Self {
NvmeCmd {
cdw0: (cid as u32) << 16 | 1 << 14 | 2,
opcode: 2,
flags: 1 << 6,
cid: cid,
nsid: 0xFFFFFFFF,
_rsvd: 0,
mptr: 0,
......@@ -44,7 +51,9 @@ impl NvmeCmd {
pub fn write(cid: u16, lba: u64, count: u16, src: u64) -> Self {
NvmeCmd {
cdw0: (cid as u32) << 16 | 1 << 14 | 1,
opcode: 1,
flags: 1 << 6,
cid: cid,
nsid: 0xFFFFFFFF,
_rsvd: 0,
mptr: 0,
......@@ -88,3 +97,20 @@ pub struct NvmeRegs {
/// Controller memory buffer size
cmbsz: Mmio<u32>,
}
pub struct Nvme {
regs: &'static mut NvmeRegs
}
impl Nvme {
pub fn new(address: usize) -> Self {
Nvme {
regs: unsafe { &mut *(address as *mut NvmeRegs) }
}
}
pub fn init(&mut self) {
println!(" - CAPS: {:X}", self.regs.cap.read());
println!(" - VS: {:X}", self.regs.vs.read());
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment