From 9898520f721220a2af4be59fd92e8ad8afcd4287 Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Sun, 17 Mar 2024 10:59:07 +0100 Subject: Unstable: See below. These changes are related to the current ticket regarding AHCI support. This commit is just to upstream changes from local. Signed-off-by: Amlal El Mahrouss --- Private/Source/Storage/AHCI.cxx | 29 ------- Private/Source/Storage/AHCIDeviceInterface.cxx | 29 +++++++ Private/Source/Storage/ATA-Wrapper.cxx | 102 +++++++++++++++++++++++++ Private/Source/Storage/ATA.cxx | 102 ------------------------- Private/Source/Storage/NVME.cxx | 11 --- Private/Source/Storage/NVMEDeviceInterface.cxx | 11 +++ Private/Source/Storage/Storage.cxx | 11 --- Private/Source/Storage/StorageBase.cxx | 11 +++ 8 files changed, 153 insertions(+), 153 deletions(-) delete mode 100644 Private/Source/Storage/AHCI.cxx create mode 100644 Private/Source/Storage/AHCIDeviceInterface.cxx create mode 100644 Private/Source/Storage/ATA-Wrapper.cxx delete mode 100644 Private/Source/Storage/ATA.cxx delete mode 100644 Private/Source/Storage/NVME.cxx create mode 100644 Private/Source/Storage/NVMEDeviceInterface.cxx delete mode 100644 Private/Source/Storage/Storage.cxx create mode 100644 Private/Source/Storage/StorageBase.cxx (limited to 'Private/Source/Storage') diff --git a/Private/Source/Storage/AHCI.cxx b/Private/Source/Storage/AHCI.cxx deleted file mode 100644 index 31fbce67..00000000 --- a/Private/Source/Storage/AHCI.cxx +++ /dev/null @@ -1,29 +0,0 @@ -/* ------------------------------------------- - - Copyright Mahrouss Logic - -------------------------------------------- */ - -#include - -using namespace HCore; - -/// @brief Class constructor -/// @param Out Disk output -/// @param In Disk input -/// @param Cleanup Disk cleanup. -AHCIDeviceInterface::AHCIDeviceInterface(void (*Out)(AHCIPacket outpacket), - void (*In)(AHCIPacket inpacket), void (*Cleanup)(void)) - : DeviceInterface(Out, In), fCleanup(Cleanup) {} - -/// @brief Class desctructor -AHCIDeviceInterface::~AHCIDeviceInterface() { - MUST_PASS(fCleanup); - if (fCleanup) fCleanup(); -} - -/// @brief Returns the name of the device interface. -/// @return it's name as a string. -const char *AHCIDeviceInterface::Name() const { return "AHCIDeviceInterface"; } - - diff --git a/Private/Source/Storage/AHCIDeviceInterface.cxx b/Private/Source/Storage/AHCIDeviceInterface.cxx new file mode 100644 index 00000000..31fbce67 --- /dev/null +++ b/Private/Source/Storage/AHCIDeviceInterface.cxx @@ -0,0 +1,29 @@ +/* ------------------------------------------- + + Copyright Mahrouss Logic + +------------------------------------------- */ + +#include + +using namespace HCore; + +/// @brief Class constructor +/// @param Out Disk output +/// @param In Disk input +/// @param Cleanup Disk cleanup. +AHCIDeviceInterface::AHCIDeviceInterface(void (*Out)(AHCIPacket outpacket), + void (*In)(AHCIPacket inpacket), void (*Cleanup)(void)) + : DeviceInterface(Out, In), fCleanup(Cleanup) {} + +/// @brief Class desctructor +AHCIDeviceInterface::~AHCIDeviceInterface() { + MUST_PASS(fCleanup); + if (fCleanup) fCleanup(); +} + +/// @brief Returns the name of the device interface. +/// @return it's name as a string. +const char *AHCIDeviceInterface::Name() const { return "AHCIDeviceInterface"; } + + diff --git a/Private/Source/Storage/ATA-Wrapper.cxx b/Private/Source/Storage/ATA-Wrapper.cxx new file mode 100644 index 00000000..407cd30f --- /dev/null +++ b/Private/Source/Storage/ATA-Wrapper.cxx @@ -0,0 +1,102 @@ +/* ------------------------------------------- + + Copyright Mahrouss Logic + +------------------------------------------- */ + +#include +#include + +#define kBufferLen 512 + +//! @brief ATA DMA Driver +//! The idea is to let a driver do the transfer. + +/// bugs 0 + +#define kATAError 2 + +namespace HCore { +Ref kPrdt = nullptr; + +bool set_prdt_struct(Ref& refCtrl) { + if (!kPrdt) { + kPrdt = refCtrl; + kcout << "[set_prdt_struct] PRDT is set."; + + return true; + } + + kcout << "[set_prdt_struct] [WARNING] Trying to change PRDT.\n"; + return false; +} + +enum { + k28BitRead = 0xC8, + k48BitRead = 0x25, + k28BitWrite = 0xCA, + k48BitWrite = 0x35, +}; + +const char* ata_read_28(ULong lba) { + if (!kPrdt) return nullptr; + + char* buffer = reinterpret_cast(Alloca(sizeof(char) * kBufferLen)); + rt_set_memory(buffer, 0, kBufferLen); + + UIntPtr* packet = reinterpret_cast(kPrdt.Leak()->PhysicalAddress()); + + packet[0] = k28BitRead; + packet[1] = (UIntPtr)&buffer; + packet[4] = lba; + + rt_wait_400ns(); + + return buffer; +} + +const char* ata_read_48(ULong lba) { + if (!kPrdt) return nullptr; + + char* buffer = reinterpret_cast(Alloca(sizeof(char) * kBufferLen)); + rt_set_memory(buffer, 0, kBufferLen); + + UIntPtr* packet = reinterpret_cast(kPrdt.Leak()->PhysicalAddress()); + + packet[0] = k48BitRead; + packet[1] = (UIntPtr)buffer; + packet[4] = lba; + + rt_wait_400ns(); + + return buffer; +} + +Int32 ata_write_48(ULong lba, const char* buffer) { + if (!kPrdt) return kATAError; + + UIntPtr* packet = reinterpret_cast(kPrdt.Leak()->PhysicalAddress()); + + packet[0] = k48BitWrite; + packet[1] = (UIntPtr)buffer; + packet[2] = lba; + + rt_wait_400ns(); + + return packet[1] == 2 ? kATAError : 0; +} + +Int32 ata_write_28(ULong lba, const char* buffer) { + if (!kPrdt) return kATAError; + + UIntPtr* packet = (UIntPtr*)kPrdt.Leak()->PhysicalAddress(); + + packet[0] = k28BitWrite; + packet[1] = (UIntPtr)buffer; + packet[2] = lba; + + rt_wait_400ns(); + + return packet[1] == 2 ? kATAError : 0; +} +} // namespace HCore diff --git a/Private/Source/Storage/ATA.cxx b/Private/Source/Storage/ATA.cxx deleted file mode 100644 index 61a58fb1..00000000 --- a/Private/Source/Storage/ATA.cxx +++ /dev/null @@ -1,102 +0,0 @@ -/* ------------------------------------------- - - Copyright Mahrouss Logic - -------------------------------------------- */ - -#include -#include - -#define kBufferLen 512 - -//! @brief ATA DMA Driver -//! The idea is to let a driver do the transfer. - -/// bugs 0 - -#define kATAError 2 - -namespace HCore { -Ref kPrdt = nullptr; - -bool set_prdt_struct(Ref& refCtrl) { - if (!kPrdt) { - kPrdt = refCtrl; - kcout << "[set_prdt_struct] PRDT is set."; - - return true; - } - - kcout << "[set_prdt_struct] [WARNING] Tried to change PRDT.\n"; - return false; -} - -enum { - k28BitRead = 0xC8, - k48BitRead = 0x25, - k28BitWrite = 0xCA, - k48BitWrite = 0x35, -}; - -const char* ata_read_28(ULong lba) { - if (!kPrdt) return nullptr; - - char* buffer = reinterpret_cast(Alloca(sizeof(char) * kBufferLen)); - rt_set_memory(buffer, 0, kBufferLen); - - UIntPtr* packet = reinterpret_cast(kPrdt.Leak()->PhysicalAddress()); - - packet[0] = k28BitRead; - packet[1] = (UIntPtr)&buffer; - packet[4] = lba; - - rt_wait_400ns(); - - return buffer; -} - -const char* ata_read_48(ULong lba) { - if (!kPrdt) return nullptr; - - char* buffer = reinterpret_cast(Alloca(sizeof(char) * kBufferLen)); - rt_set_memory(buffer, 0, kBufferLen); - - UIntPtr* packet = reinterpret_cast(kPrdt.Leak()->PhysicalAddress()); - - packet[0] = k48BitRead; - packet[1] = (UIntPtr)&buffer; - packet[4] = lba; - - rt_wait_400ns(); - - return buffer; -} - -Int32 ata_write_48(ULong lba, const char* buffer) { - if (!kPrdt) return kATAError; - - UIntPtr* packet = reinterpret_cast(kPrdt.Leak()->PhysicalAddress()); - - packet[0] = k48BitWrite; - packet[1] = (UIntPtr)&buffer; - packet[2] = lba; - - rt_wait_400ns(); - - return packet[1] == 2 ? kATAError : 0; -} - -Int32 ata_write_28(ULong lba, const char* text) { - if (!kPrdt) return kATAError; - - UIntPtr* packet = (UIntPtr*)kPrdt.Leak()->PhysicalAddress(); - - packet[0] = k28BitWrite; - packet[1] = (UIntPtr)&text; - packet[2] = lba; - - rt_wait_400ns(); - - return packet[1] == 2 ? kATAError : 0; -} -} // namespace HCore diff --git a/Private/Source/Storage/NVME.cxx b/Private/Source/Storage/NVME.cxx deleted file mode 100644 index fc75604d..00000000 --- a/Private/Source/Storage/NVME.cxx +++ /dev/null @@ -1,11 +0,0 @@ -/* ------------------------------------------- - - Copyright Mahrouss Logic - -------------------------------------------- */ - -#include - -namespace HCore { -const char *NVMEDeviceInterface::Name() const { return ("NVMEDeviceInterface"); } -} // namespace HCore diff --git a/Private/Source/Storage/NVMEDeviceInterface.cxx b/Private/Source/Storage/NVMEDeviceInterface.cxx new file mode 100644 index 00000000..fc75604d --- /dev/null +++ b/Private/Source/Storage/NVMEDeviceInterface.cxx @@ -0,0 +1,11 @@ +/* ------------------------------------------- + + Copyright Mahrouss Logic + +------------------------------------------- */ + +#include + +namespace HCore { +const char *NVMEDeviceInterface::Name() const { return ("NVMEDeviceInterface"); } +} // namespace HCore diff --git a/Private/Source/Storage/Storage.cxx b/Private/Source/Storage/Storage.cxx deleted file mode 100644 index bba4be1f..00000000 --- a/Private/Source/Storage/Storage.cxx +++ /dev/null @@ -1,11 +0,0 @@ -/* ------------------------------------------- - - Copyright Mahrouss Logic - -------------------------------------------- */ - -#include - -///! @brief ATAPI SCSI packet. -const SKScsiPacket kCDRomPacketTemplate = {0x43, 0, 1, 0, 0, 0, - 0, 12, 0x40, 0, 0}; diff --git a/Private/Source/Storage/StorageBase.cxx b/Private/Source/Storage/StorageBase.cxx new file mode 100644 index 00000000..bba4be1f --- /dev/null +++ b/Private/Source/Storage/StorageBase.cxx @@ -0,0 +1,11 @@ +/* ------------------------------------------- + + Copyright Mahrouss Logic + +------------------------------------------- */ + +#include + +///! @brief ATAPI SCSI packet. +const SKScsiPacket kCDRomPacketTemplate = {0x43, 0, 1, 0, 0, 0, + 0, 12, 0x40, 0, 0}; -- cgit v1.2.3