@@ -5,16 +5,63 @@ use crate::Status;
55use core:: ffi:: c_void;
66use uguid:: { guid, Guid } ;
77
8- #[ derive( Debug ) ]
8+ bitflags:: bitflags! {
9+ /// In an NVMe command, the `flags` field specifies which cdw (command specific word)
10+ /// contains a value.
11+ #[ derive( Clone , Copy , Debug , Default , PartialEq , Eq , PartialOrd , Ord ) ]
12+ #[ repr( transparent) ]
13+ pub struct NvmExpressCommandCdwValidity : u8 {
14+ const CDW_2 = 0x01 ;
15+ const CDW_3 = 0x02 ;
16+ const CDW_10 = 0x04 ;
17+ const CDW_11 = 0x08 ;
18+ const CDW_12 = 0x10 ;
19+ const CDW_13 = 0x20 ;
20+ const CDW_14 = 0x40 ;
21+ const CDW_15 = 0x80 ;
22+ }
23+
24+ /// Represents the `EFI_NVM_EXPRESS_PASS_THRU_ATTRIBUTES_*` defines from the UEFI specification.
25+ ///
26+ /// # UEFI Specification Description
27+ /// Tells if the interface is for physical NVM Express controllers or logical NVM Express controllers.
28+ ///
29+ /// Drivers for non-RAID NVM Express controllers will set both the `PHYSICAL` and the `LOGICAL` bit.
30+ ///
31+ /// Drivers for RAID controllers that allow access to the underlying physical controllers will produces
32+ /// two protocol instances. One where the `LOGICAL` bit is set (representing the logical RAID volume),
33+ /// and one where the `PHYSICAL` bit is set, which can be used to access the underlying NVMe controllers.
34+ ///
35+ /// Drivers for RAID controllers that do not allow access of the underlying NVMe controllers will only
36+ /// produce one protocol instance for the logical RAID volume with the `LOGICAL` bit set.
37+ #[ derive( Clone , Copy , Debug , Default , PartialEq , Eq , PartialOrd , Ord ) ]
38+ #[ repr( transparent) ]
39+ pub struct NvmExpressPassThruAttributes : u32 {
40+ /// If this bit is set, the interface is for directly addressable namespaces.
41+ const PHYSICAL = 0x0001 ;
42+
43+ /// If this bit is set, the interface is for a single logical namespace comprising multiple namespaces.
44+ const LOGICAL = 0x0002 ;
45+
46+ /// If this bit is set, the interface supports both blocking and non-blocking I/O.
47+ /// - All interfaces must support blocking I/O, but this bit indicates that non-blocking I/O is also supported.
48+ const NONBLOCKIO = 0x0004 ;
49+
50+ /// If this bit is set, the interface supports the NVM Express command set.
51+ const CMD_SET_NVM = 0x0008 ;
52+ }
53+ }
54+
55+ #[ derive( Clone , Debug ) ]
956#[ repr( C ) ]
1057pub struct NvmExpressPassThruMode {
11- pub attributes : u32 ,
58+ pub attributes : NvmExpressPassThruAttributes ,
1259 pub io_align : u32 ,
1360 pub nvme_version : u32 ,
1461}
1562
1663/// This structure maps to the NVM Express specification Submission Queue Entry
17- #[ derive( Debug ) ]
64+ #[ derive( Debug , Default ) ]
1865#[ repr( C ) ]
1966pub struct NvmExpressCommand {
2067 pub cdw0 : u32 ,
@@ -30,8 +77,20 @@ pub struct NvmExpressCommand {
3077 pub cdw15 : u32 ,
3178}
3279
80+ newtype_enum ! {
81+ /// Type of queues an NVMe command can be placed into
82+ /// (Which queue a command should be placed into depends on the command)
83+ #[ derive( Default ) ]
84+ pub enum NvmExpressQueueType : u8 => {
85+ /// Admin Submission Queue
86+ ADMIN = 0 ,
87+ /// 1) I/O Submission Queue
88+ IO = 1 ,
89+ }
90+ }
91+
3392/// This structure maps to the NVM Express specification Completion Queue Entry
34- #[ derive( Debug ) ]
93+ #[ derive( Debug , Default ) ]
3594#[ repr( C ) ]
3695pub struct NvmExpressCompletion {
3796 pub dw0 : u32 ,
@@ -48,7 +107,7 @@ pub struct NvmExpressPassThruCommandPacket {
48107 pub transfer_length : u32 ,
49108 pub meta_data_buffer : * mut c_void ,
50109 pub meta_data_length : u32 ,
51- pub queue_type : u8 ,
110+ pub queue_type : NvmExpressQueueType ,
52111 pub nvme_cmd : * const NvmExpressCommand ,
53112 pub nvme_completion : * mut NvmExpressCompletion ,
54113}
@@ -58,7 +117,7 @@ pub struct NvmExpressPassThruCommandPacket {
58117pub struct NvmExpressPassThruProtocol {
59118 pub mode : * const NvmExpressPassThruMode ,
60119 pub pass_thru : unsafe extern "efiapi" fn (
61- this : * const Self ,
120+ this : * mut Self ,
62121 namespace_id : u32 ,
63122 packet : * mut NvmExpressPassThruCommandPacket ,
64123 event : * mut c_void ,
@@ -68,7 +127,7 @@ pub struct NvmExpressPassThruProtocol {
68127 pub build_device_path : unsafe extern "efiapi" fn (
69128 this : * const Self ,
70129 namespace_id : u32 ,
71- device_path : * mut * mut DevicePathProtocol ,
130+ device_path : * mut * const DevicePathProtocol ,
72131 ) -> Status ,
73132 pub get_namespace : unsafe extern "efiapi" fn (
74133 this : * const Self ,
0 commit comments