NeKernel dev
Loading...
Searching...
No Matches
NVME.h
Go to the documentation of this file.
1/* -------------------------------------------
2
3 Copyright (C) 2024-2025, Amlal El Mahrouss, all rights reserved.
4
5 Revision History:
6
7 ??/??/24: Added file (amlel)
8 23 Jul 24: Update filename to Defines.h and using NE_ALIGN_NVME for NVME structs. (amlel)
9
10------------------------------------------- */
11
12#ifndef __MODULE_NVME_H__
13#define __MODULE_NVME_H__
14
15#include <NeKit/Defines.h>
16
19
20#define NE_ALIGN_NVME ATTRIBUTE(aligned(sizeof(Kernel::UInt32)))
21
22namespace Kernel {
34
43
44enum {
49 kReadNVME = 0x02,
50 kWriteNVME = 0x01,
52};
53
55template <Int32 Opcode>
56inline Bool nvme_create_admin_command(HAL_NVME_QUEUE* entry, UInt32 nsid, UInt32 prpTransfer[3],
57 UInt32 startingLba[2], UInt32 lowTransferBlocks) {
58 if (entry == nullptr) return false;
59
60 entry->CommandSpecific[9] = startingLba[0];
61 entry->CommandSpecific[10] = startingLba[1];
62
63 entry->CommandSpecific[11] = lowTransferBlocks;
64
65 entry->CommandSpecific[5] = prpTransfer[0];
66 entry->CommandSpecific[6] = prpTransfer[1];
67 entry->CommandSpecific[7] = prpTransfer[2];
68
69 entry->CommandSpecific[0] = nsid;
70
71 return true;
72}
73
75template <Int32 Opcode>
77 UInt32 identLoAndQueueSizeHi, UInt32 flagsLoAndQueueComplIdHi,
78 UInt32 identify, Bool provideIdentify = false,
79 Bool namespaceIdentify = false) {
80 if (entry == nullptr) return false;
81
82 if (baseAddress == 0) return false;
83
84 entry->fOpcode = Opcode;
85
86 entry->CommandSpecific[5] = (baseAddress & 0xFF);
87 entry->CommandSpecific[6] = static_cast<UInt32>(baseAddress);
88
89 if (!provideIdentify) {
90 entry->CommandSpecific[9] = identLoAndQueueSizeHi;
91 entry->CommandSpecific[10] = flagsLoAndQueueComplIdHi;
92 } else {
93 entry->CommandSpecific[9] = identify;
94
95 if (namespaceIdentify) {
96 entry->CommandSpecific[0] = 1;
97 }
98 }
99
100 return true;
101}
102} // namespace Kernel
103
104#endif // ifndef __MODULE_NVME_H__
#define NE_ALIGN_NVME
Definition NVME.h:20
USER_PROCESS inline definitions.
Definition Qr.h:793
@ kReadNVME
Definition NVME.h:49
@ kCountNVME
Definition NVME.h:51
@ kCreateCompletionQueueNVME
Definition NVME.h:46
@ kCreateSubmissionQueueNVME
Definition NVME.h:47
@ kInvalidNVME
Definition NVME.h:45
@ kWriteNVME
Definition NVME.h:50
@ kIdentifyNVME
Definition NVME.h:48
Bool nvme_create_io_command(HAL_NVME_QUEUE *entry, UInt64 baseAddress, UInt32 identLoAndQueueSizeHi, UInt32 flagsLoAndQueueComplIdHi, UInt32 identify, Bool provideIdentify=false, Bool namespaceIdentify=false)
Creates an I/O command for a DMA operation.
Definition NVME.h:76
Bool nvme_create_admin_command(HAL_NVME_QUEUE *entry, UInt32 nsid, UInt32 prpTransfer[3], UInt32 startingLba[2], UInt32 lowTransferBlocks)
Creates an admin command for a DMA operation.
Definition NVME.h:56
unsigned int UInt32
Definition Defines.h:44
__UINT64_TYPE__ UInt64
Definition Defines.h:48
bool Bool
Definition Defines.h:50
Definition NVME.h:23
UInt32 fContrlConf
Definition NVME.h:28
UInt32 fIntMaskSet
Definition NVME.h:26
UInt32 fAdminCompletionQueue
Definition NVME.h:32
UInt32 fIntMaskClr
Definition NVME.h:27
UInt32 fContrlStat
Definition NVME.h:29
UInt32 fAdminQueueAttr
Definition NVME.h:30
UInt32 fAdminSubmissionQueue
Definition NVME.h:31
UInt32 fVersion
Definition NVME.h:25
UInt32 fCapabilities
Definition NVME.h:24
Definition NVME.h:35
UInt32 fNSID
Definition NVME.h:37
UInt32 fOpcode
Definition NVME.h:36
UInt32 CommandSpecific[15]
Definition NVME.h:41
UInt32 fDataPtr[9]
Definition NVME.h:40
UInt32 fMetadataPtr[5]
Definition NVME.h:39
UInt32 fReserved[3]
Definition NVME.h:38