diff options
| author | Amlal El Mahrouss <amlal.elmahrouss@icloud.com> | 2024-01-26 22:26:48 +0100 |
|---|---|---|
| committer | Amlal El Mahrouss <amlal.elmahrouss@icloud.com> | 2024-01-26 22:27:09 +0100 |
| commit | eba8b7ddd0a455d9e49f32dcae712c5612c0093c (patch) | |
| tree | 749a3d34546d055507a920bce4ab10e8a9945719 /Private/StorageKit | |
| parent | dd192787a70a973f2474720aea49af3f6ddabb7a (diff) | |
Kernel: Major repository refactor.
Rework the repo into Private and Public modules.
Signed-off-by: Amlal El Mahrouss <amlal.elmahrouss@icloud.com>
Diffstat (limited to 'Private/StorageKit')
| -rw-r--r-- | Private/StorageKit/ATA.hpp | 104 | ||||
| -rw-r--r-- | Private/StorageKit/NVME.hpp | 48 | ||||
| -rw-r--r-- | Private/StorageKit/PRDT.hpp | 54 | ||||
| -rw-r--r-- | Private/StorageKit/Storage.hpp | 28 | ||||
| -rw-r--r-- | Private/StorageKit/StorageCore.inl | 56 |
5 files changed, 290 insertions, 0 deletions
diff --git a/Private/StorageKit/ATA.hpp b/Private/StorageKit/ATA.hpp new file mode 100644 index 00000000..76f06409 --- /dev/null +++ b/Private/StorageKit/ATA.hpp @@ -0,0 +1,104 @@ +/* +* ======================================================== +* +* hCore +* Copyright 2024 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/Private/StorageKit/NVME.hpp b/Private/StorageKit/NVME.hpp new file mode 100644 index 00000000..13f6131c --- /dev/null +++ b/Private/StorageKit/NVME.hpp @@ -0,0 +1,48 @@ +/* + * ======================================================== + * + * hCore + * Copyright 2024 Mahrouss Logic, all rights reserved. + * + * ======================================================== + */ + +#pragma once + +#include <KernelKit/Device.hpp> +#include <NewKit/OwnPtr.hpp> + +namespace hCore +{ + class NVMEPacket; + + class NVMEDevice : public DeviceInterface<NVMEPacket> + { + public: + NVMEDevice(void(*Out)(NVMEPacket outpacket), + void(*In)(NVMEPacket inpacket), + void(*Cleanup)(void)) + : DeviceInterface(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/Private/StorageKit/PRDT.hpp b/Private/StorageKit/PRDT.hpp new file mode 100644 index 00000000..96e0c5cd --- /dev/null +++ b/Private/StorageKit/PRDT.hpp @@ -0,0 +1,54 @@ +/* + * ======================================================== + * + * hCore + * Copyright 2024 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/Private/StorageKit/Storage.hpp b/Private/StorageKit/Storage.hpp new file mode 100644 index 00000000..8b3670af --- /dev/null +++ b/Private/StorageKit/Storage.hpp @@ -0,0 +1,28 @@ +/* + * ======================================================== + * + * hCore + * Copyright 2024 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/Private/StorageKit/StorageCore.inl b/Private/StorageKit/StorageCore.inl new file mode 100644 index 00000000..85e2a3f5 --- /dev/null +++ b/Private/StorageKit/StorageCore.inl @@ -0,0 +1,56 @@ +/* + * ======================================================== + * + * hCore + * Copyright 2024 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__ */ |
