diff options
| author | Amlal El Mahrouss <amlal.elmahrouss@icloud.com> | 2024-01-06 09:14:11 +0100 |
|---|---|---|
| committer | Amlal El Mahrouss <amlal.elmahrouss@icloud.com> | 2024-01-06 09:14:11 +0100 |
| commit | 5339d016c07bf717ee388f4feb73544087324af0 (patch) | |
| tree | 94be6f67ed626091f24aee24ec3b3be03d01e4e7 /StorageKit | |
git: port from mercurial repo.
Signed-off-by: Amlal El Mahrouss <amlal.elmahrouss@icloud.com>
Diffstat (limited to 'StorageKit')
| -rw-r--r-- | StorageKit/ATA.hpp | 104 | ||||
| -rw-r--r-- | StorageKit/NVME.hpp | 48 | ||||
| -rw-r--r-- | StorageKit/PRDT.hpp | 54 | ||||
| -rw-r--r-- | StorageKit/Storage.hpp | 28 | ||||
| -rw-r--r-- | StorageKit/StorageCore.inl | 56 |
5 files changed, 290 insertions, 0 deletions
diff --git a/StorageKit/ATA.hpp b/StorageKit/ATA.hpp new file mode 100644 index 00000000..0531e933 --- /dev/null +++ b/StorageKit/ATA.hpp @@ -0,0 +1,104 @@ +/* +* ======================================================== +* +* hCore +* Copyright Mahrouss Logic, all rights reserved. +* +* ======================================================== +*/ + +#pragma once + +#include <KernelKit/PCI/Dma.hpp> +#include <KernelKit/PCI/IO.hpp> +#include <NewKit/Defines.hpp> +#include <StorageKit/PRDT.hpp> +#include <KernelKit/DebugOutput.hpp> + +namespace hCore +{ + enum class PATAType + { + kRead28, + kRead48, + kWrite28, + kWrite48, + kUnknown + }; + + const char* ata_read_28(ULong lba); + const char* ata_read_48(ULong lba); + + Int32 ata_write_48(ULong lba, const char *text = nullptr); + Int32 ata_write_28(ULong lba, const char *text = nullptr); + + class PATACommandManager final + { + public: + PATACommandManager() = default; + ~PATACommandManager() = default; + + PATACommandManager &operator=(const PATACommandManager &) = default; + PATACommandManager(const PATACommandManager &) = default; + + public: + static Ref<PATACommandManager> Shared() + { + static Ref<PATACommandManager> manager; + return manager; + } + + public: + template <PATAType Command> + ErrorOr<const char*> operator()(ULong lba, const char *text = nullptr) noexcept + { + switch (Command) + { + case PATAType::kRead28: + return ErrorOr<const char*>(ata_read_28(lba)); + case PATAType::kRead48: + return ErrorOr<const char*>(ata_read_48(lba)); + case PATAType::kWrite28: + { + if (text) + { + ata_write_28(lba, text); + kcout << "ErrorOr<CT> ata_read<CT, Command>: Write ATA Command... " + "(Write28)\n"; + + return {}; + } + + kcout << "ErrorOr<CT> ata_read<CT, Command>: Bad ATA Command... " + "(Write28)\n"; + + return {}; + } + case PATAType::kWrite48: + { + if (text) + { + ata_write_48(lba, text); + kcout << "ErrorOr<CT> ata_read<CT, Command>: Write ATA Command... " + "(Write48)\n"; + + return {}; + } + + kcout << "ErrorOr<CT> ata_read<CT, Command>: Bad ATA Command... " + "(Write48)\n"; + + return {}; + } + case PATAType::kUnknown: + { + kcout << "ErrorOr<CT> ata_read<CT, Command>: Unknown ATA Command...\n"; + return {}; + } + } + + return ErrorOr<const char*>(nullptr); + } + + }; +} // namespace hCore diff --git a/StorageKit/NVME.hpp b/StorageKit/NVME.hpp new file mode 100644 index 00000000..1b8fa836 --- /dev/null +++ b/StorageKit/NVME.hpp @@ -0,0 +1,48 @@ +/* + * ======================================================== + * + * hCore + * Copyright Mahrouss Logic, all rights reserved. + * + * ======================================================== + */ + +#pragma once + +#include <KernelKit/Device.hpp> +#include <NewKit/OwnPtr.hpp> + +namespace hCore +{ + class NVMEPacket; + + class NVMEDevice : public IDevice<NVMEPacket> + { + public: + NVMEDevice(void(*Out)(NVMEPacket outpacket), + void(*In)(NVMEPacket inpacket), + void(*Cleanup)(void)) + : IDevice(Out, In), fCleanup(Cleanup) + {} + + virtual ~NVMEDevice() + { + if (fCleanup) + fCleanup(); + } + + public: + NVMEDevice &operator=(const NVMEDevice &) = default; + NVMEDevice(const NVMEDevice &) = default; + + virtual const char *Name() const; + + public: + OwnPtr<NVMEPacket> operator()(UInt32 dmaLow, UInt32 dmaHigh, SizeT sz); + + private: + void(*fCleanup)(void); + + + }; +} // namespace hCore diff --git a/StorageKit/PRDT.hpp b/StorageKit/PRDT.hpp new file mode 100644 index 00000000..152bc6f1 --- /dev/null +++ b/StorageKit/PRDT.hpp @@ -0,0 +1,54 @@ +/* + * ======================================================== + * + * hCore + * Copyright Mahrouss Logic, all rights reserved. + * + * ======================================================== + */ +#pragma once + +#include <KernelKit/PCI/Dma.hpp> +#include <KernelKit/PCI/Iterator.hpp> + +#define PRDT_TRANSFER_SIZE (sizeof(hCore::UShort)) + +namespace hCore +{ + class PRDT final + { + public: + PRDT() = delete; + explicit PRDT(const UIntPtr &physAddr); + ~PRDT(); + + PRDT &operator=(const PRDT &) = default; + PRDT(const PRDT &) = default; + + public: + const UInt &Low(); + const UShort &High(); + const UIntPtr &PhysicalAddress(); + + public: + PRDT &operator=(const UIntPtr& prdtAddress); + + public: + operator bool() + { + return m_PrdtAddr != 0; + } + + private: + union + { + UInt m_Low; + UShort m_High; + }; + + UIntPtr m_PrdtAddr; + + }; + + using PhysicalAddress = PRDT; // here +} // namespace hCore diff --git a/StorageKit/Storage.hpp b/StorageKit/Storage.hpp new file mode 100644 index 00000000..420e67fd --- /dev/null +++ b/StorageKit/Storage.hpp @@ -0,0 +1,28 @@ +/* + * ======================================================== + * + * hCore + * Copyright Mahrouss Logic, all rights reserved. + * + * ======================================================== + */ + +#pragma once + +#include <NewKit/Defines.hpp> + +#include <StorageKit/ATA.hpp> +#include <StorageKit/NVME.hpp> + +#include <StorageKit/StorageCore.inl> + +typedef hCore::UInt16 OSScsiPacket[12]; + +extern const OSScsiPacket kCDRomPacketTemplate; + +#define f_kDriveSectorSize 2048 +#define f_kDriveSize(last_lba) (last_lba + 1) * f_kDriveSectorSize + + + + diff --git a/StorageKit/StorageCore.inl b/StorageKit/StorageCore.inl new file mode 100644 index 00000000..f0891880 --- /dev/null +++ b/StorageKit/StorageCore.inl @@ -0,0 +1,56 @@ +/* + * ======================================================== + * + * hCore + * Copyright Mahrouss Logic, all rights reserved. + * + * ======================================================== + */ + +#ifndef __STORAGEKIT_STORAGECORE_INL__ +#define __STORAGEKIT_STORAGECORE_INL__ + +#include <NewKit/Defines.hpp> + +// @brief Storage management unit. +// swap files, files, dirs optimization. + +namespace hCore +{ + typedef Char* SKStr; + + //! @brief Storage context, reads and write file according to the descriptor layout. + class StorageContext + { + public: + explicit StorageContext() = default; + ~StorageContext() = default; + + StorageContext& operator=(const StorageContext&) = default; + StorageContext(const StorageContext&) = default; + + public: + bool Write(VoidPtr fileDescriptor, SizeT sizeFileDescriptor); + + struct SDescriptor + { + VoidPtr fFilePtr; + SizeT fFilePtrSz; + }; + + SDescriptor Read(const SKStr name); + + }; + +#define kMaxPathSK 4096 + + struct StorageLayout final + { + Char fName[kMaxPathSK]; + VoidPtr fData; + SizeT fDataSz; + Int32 fType; + }; +} + +#endif /* ifndef __STORAGEKIT_STORAGECORE_INL__ */ |
