diff options
| author | Amlal EL Mahrouss <amlalelmahrouss@icloud.com> | 2024-08-15 18:35:34 +0200 |
|---|---|---|
| committer | Amlal EL Mahrouss <amlalelmahrouss@icloud.com> | 2024-08-15 18:35:34 +0200 |
| commit | f3d931aa7cfaf96baef8383b59a8938779541ee7 (patch) | |
| tree | fdb9fc51badb3dbd03e46ab0766a49d9522e13e2 /dev/Kernel/Modules/NVME | |
| parent | 86640816e8b1d3595365f1fcc8a2a9e61fb40ff1 (diff) | |
[IMP] Moved source code into dev/ folder.
Signed-off-by: Amlal EL Mahrouss <amlalelmahrouss@icloud.com>
Diffstat (limited to 'dev/Kernel/Modules/NVME')
| -rw-r--r-- | dev/Kernel/Modules/NVME/.gitkeep | 0 | ||||
| -rw-r--r-- | dev/Kernel/Modules/NVME/Defines.hxx | 116 | ||||
| -rw-r--r-- | dev/Kernel/Modules/NVME/compile_flags.txt | 4 |
3 files changed, 120 insertions, 0 deletions
diff --git a/dev/Kernel/Modules/NVME/.gitkeep b/dev/Kernel/Modules/NVME/.gitkeep new file mode 100644 index 00000000..e69de29b --- /dev/null +++ b/dev/Kernel/Modules/NVME/.gitkeep diff --git a/dev/Kernel/Modules/NVME/Defines.hxx b/dev/Kernel/Modules/NVME/Defines.hxx new file mode 100644 index 00000000..6ab57ccb --- /dev/null +++ b/dev/Kernel/Modules/NVME/Defines.hxx @@ -0,0 +1,116 @@ +/* ------------------------------------------- + + Copyright ZKA Technologies. + + Revision History: + + ??/??/24: Added file (amlel) + 23 Jul 24: Update filename to Defines.hxx and using ALIGN_NVME for NVME structs. (amlel) + +------------------------------------------- */ + +#ifndef __MODULE_NVME_HXX__ +#define __MODULE_NVME_HXX__ + +#include <NewKit/Defines.hxx> + +/// TODO: checklist in: https://wiki.osdev.org/NVMe + +#define ALIGN_NVME ATTRIBUTE(aligned(sizeof(Kernel::NVMEInt32))) + +namespace Kernel +{ + typedef UInt32 NVMEInt32; + + struct ALIGN_NVME NVMEBar0 final + { + NVMEInt32 fCap; + NVMEInt32 fVer; + NVMEInt32 fIntMaskSet; + NVMEInt32 fIntMaskClr; + NVMEInt32 fContrlConf; + NVMEInt32 fContrlStat; + NVMEInt32 fAdminQueueAttr; + NVMEInt32 fAdminSubmissionQueue; + NVMEInt32 fAdminCompletionQueue; + }; + + struct ALIGN_NVME NVMEQueue final + { + NVMEInt32 fOpcode; + NVMEInt32 fNSID; + NVMEInt32 fReserved[3]; + NVMEInt32 fMetadataPtr[5]; + NVMEInt32 fDataPtr[9]; + NVMEInt32 CommandSpecific[15]; + }; + + enum + { + eCreateCompletionQueueNVME = 0x05, + eCreateSubmissionQueueNVME = 0x01, + eIdentifyNVME = 0x06, + eReadNVME = 0x02, + eWriteNVME = 0x01, + }; + + template <Int32 Opcode> + inline Bool nvme_create_admin_command(NVMEQueue* entry, UInt32 nsid, + UInt32 prpTransfer[3], + UInt32 startingLba[2], UInt32 lowTransferBlocks) + { + if (entry == nullptr) + return false; + + entry->CommandSpecific[9] = startingLba[0]; + entry->CommandSpecific[10] = startingLba[1]; + + entry->CommandSpecific[11] = lowTransferBlocks; + + entry->CommandSpecific[5] = prpTransfer[0]; + entry->CommandSpecific[6] = prpTransfer[1]; + entry->CommandSpecific[7] = prpTransfer[2]; + + entry->CommandSpecific[0] = nsid; + + return true; + } + + template <Int32 Opcode> + inline Bool nvme_create_io_command(NVMEQueue* entry, UInt64 baseAddress, + UInt32 identLoAndQueueSizeHi, UInt32 flagsLoAndQueueComplIdHi, + UInt32 identify, Bool provideIdentify = false, Bool namespaceIdentify = false) + { + if (entry == nullptr) + return false; + + if (baseAddress == 0) + return false; + + entry->fOpcode = Opcode; + + entry->CommandSpecific[5] = (baseAddress & 0xFF); + entry->CommandSpecific[6] = static_cast<UInt32>(baseAddress); + + if (!provideIdentify) + { + entry->CommandSpecific[9] = identLoAndQueueSizeHi; + entry->CommandSpecific[10] = flagsLoAndQueueComplIdHi; + } + else + { + entry->CommandSpecific[9] = identify; + + if (namespaceIdentify) + { + entry->CommandSpecific[0] = 1; + } + } + + // use (1 << 0) as contigunous is better supported. + + return true; + } +} // namespace Kernel + +#endif // ifndef __MODULE_NVME_HXX__ diff --git a/dev/Kernel/Modules/NVME/compile_flags.txt b/dev/Kernel/Modules/NVME/compile_flags.txt new file mode 100644 index 00000000..1bc51142 --- /dev/null +++ b/dev/Kernel/Modules/NVME/compile_flags.txt @@ -0,0 +1,4 @@ +-I./ +-I../ +-I../../ +-std=c++20 |
