Add read, write command structures
This commit is contained in:
+61
-2
@@ -1,5 +1,64 @@
|
||||
use syscall::io::{Io, Mmio};
|
||||
|
||||
pub struct NvmeCmd {
|
||||
/// Command dword 0
|
||||
cdw0: u32,
|
||||
/// Namespace identifier
|
||||
nsid: u32,
|
||||
/// Reserved
|
||||
_rsvd: u64,
|
||||
/// Metadata pointer
|
||||
mptr: u64,
|
||||
/// Data pointer
|
||||
dptr: [u64; 2],
|
||||
/// Command dword 10
|
||||
cdw10: u32,
|
||||
/// Command dword 11
|
||||
cdw11: u32,
|
||||
/// Command dword 12
|
||||
cdw12: u32,
|
||||
/// Command dword 13
|
||||
cdw13: u32,
|
||||
/// Command dword 14
|
||||
cdw14: u32,
|
||||
/// Command dword 15
|
||||
cdw15: u32,
|
||||
}
|
||||
|
||||
impl NvmeCmd {
|
||||
pub fn read(cid: u16, lba: u64, count: u16, dst: u64) -> Self {
|
||||
NvmeCmd {
|
||||
cdw0: (cid as u32) << 16 | 1 << 14 | 2,
|
||||
nsid: 0xFFFFFFFF,
|
||||
_rsvd: 0,
|
||||
mptr: 0,
|
||||
dptr: [dst, (count as u64) << 9],
|
||||
cdw10: lba as u32,
|
||||
cdw11: (lba >> 32) as u32,
|
||||
cdw12: count as u32,
|
||||
cdw13: 0,
|
||||
cdw14: 0,
|
||||
cdw15: 0,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn write(cid: u16, lba: u64, count: u16, src: u64) -> Self {
|
||||
NvmeCmd {
|
||||
cdw0: (cid as u32) << 16 | 1 << 14 | 1,
|
||||
nsid: 0xFFFFFFFF,
|
||||
_rsvd: 0,
|
||||
mptr: 0,
|
||||
dptr: [src, (count as u64) << 9],
|
||||
cdw10: lba as u32,
|
||||
cdw11: (lba >> 32) as u32,
|
||||
cdw12: count as u32,
|
||||
cdw13: 0,
|
||||
cdw14: 0,
|
||||
cdw15: 0,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[repr(packed)]
|
||||
pub struct NvmeRegs {
|
||||
/// Controller Capabilities
|
||||
@@ -27,5 +86,5 @@ pub struct NvmeRegs {
|
||||
/// Controller memory buffer location
|
||||
cmbloc: Mmio<u32>,
|
||||
/// Controller memory buffer size
|
||||
cmbsz: Mmio<u32>,
|
||||
}
|
||||
cmbsz: Mmio<u32>,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user