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/ATA.hpp | |
git: port from mercurial repo.
Signed-off-by: Amlal El Mahrouss <amlal.elmahrouss@icloud.com>
Diffstat (limited to 'StorageKit/ATA.hpp')
| -rw-r--r-- | StorageKit/ATA.hpp | 104 |
1 files changed, 104 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 |
