From 8eee31685e4334415870bb00b11b6b0d29821f10 Mon Sep 17 00:00:00 2001 From: Amlal Date: Tue, 23 Jul 2024 09:03:11 +0200 Subject: [MHR-36] NVME driver improvements, add RLE flag for NewFS. NVME: - Rename NVME.hxx to Defines.hxx, inside NVME module. NewFS: - Add RLE flag to NewFS. Which marks catalog as compressed. Meta: - Remove unused headers. - Use Mahrouss API version for kernel version. Signed-off-by: Amlal --- Kernel/Modules/NVME/Defines.hxx | 116 ++++++++++++++++++++++++++++++++++++++++ Kernel/Modules/NVME/NVME.hxx | 107 ------------------------------------ 2 files changed, 116 insertions(+), 107 deletions(-) create mode 100644 Kernel/Modules/NVME/Defines.hxx delete mode 100644 Kernel/Modules/NVME/NVME.hxx (limited to 'Kernel/Modules') diff --git a/Kernel/Modules/NVME/Defines.hxx b/Kernel/Modules/NVME/Defines.hxx new file mode 100644 index 00000000..50960ed5 --- /dev/null +++ b/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 + +/// 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 + 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 + 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(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/Kernel/Modules/NVME/NVME.hxx b/Kernel/Modules/NVME/NVME.hxx deleted file mode 100644 index b306af4b..00000000 --- a/Kernel/Modules/NVME/NVME.hxx +++ /dev/null @@ -1,107 +0,0 @@ -/* ------------------------------------------- - - Copyright ZKA Technologies - -------------------------------------------- */ - -#ifndef __MODULE_NVME_HXX__ -#define __MODULE_NVME_HXX__ - -#include - -/// TODO: checklist in: https://wiki.osdev.org/NVMe - -#define mNVMEAlign ATTRIBUTE(aligned(sizeof(Kernel::NVMEInt32))) - -namespace Kernel -{ - typedef UInt32 NVMEInt32; - - struct NVMEBar0 final - { - NVMEInt32 fCap; - NVMEInt32 fVer; - NVMEInt32 fIntMaskSet; - NVMEInt32 fIntMaskClr; - NVMEInt32 fContrlConf; - NVMEInt32 fContrlStat; - NVMEInt32 fAdminQueueAttr; - NVMEInt32 fAdminSubmissionQueue; - NVMEInt32 fAdminCompletionQueue; - }; - - struct 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 - 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 - inline Bool nvme_create_admin_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(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__ -- cgit v1.2.3