From 83d870e58457a1d335a1d9b9966a6a1887cc297b Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Mon, 24 Nov 2025 03:02:43 +0100 Subject: feat! breaking changes on kernel sources. Signed-off-by: Amlal El Mahrouss --- src/kernel/StorageKit/AHCI.h | 49 +++++++++++++++++++++++++++++++++ src/kernel/StorageKit/ATA.h | 56 ++++++++++++++++++++++++++++++++++++++ src/kernel/StorageKit/NVME.h | 32 ++++++++++++++++++++++ src/kernel/StorageKit/PRDT.h | 33 ++++++++++++++++++++++ src/kernel/StorageKit/SCSI.h | 11 ++++++++ src/kernel/StorageKit/StorageKit.h | 21 ++++++++++++++ 6 files changed, 202 insertions(+) create mode 100644 src/kernel/StorageKit/AHCI.h create mode 100644 src/kernel/StorageKit/ATA.h create mode 100644 src/kernel/StorageKit/NVME.h create mode 100644 src/kernel/StorageKit/PRDT.h create mode 100644 src/kernel/StorageKit/SCSI.h create mode 100644 src/kernel/StorageKit/StorageKit.h (limited to 'src/kernel/StorageKit') diff --git a/src/kernel/StorageKit/AHCI.h b/src/kernel/StorageKit/AHCI.h new file mode 100644 index 00000000..82bd9747 --- /dev/null +++ b/src/kernel/StorageKit/AHCI.h @@ -0,0 +1,49 @@ +/* ======================================== + + Copyright (C) 2024-2025, Amlal El Mahrouss, licensed under the Apache 2.0 license. + +======================================== */ + +#pragma once + +#include +#include +#include + +namespace Kernel { +/// @brief AHCIDeviceInterface class +/// @details This class is used to send and receive data from the AHCI device. +/// @note The class is derived from the DeviceInterface class. +class AHCIDeviceInterface NE_DEVICE { + public: + explicit AHCIDeviceInterface(void (*out)(DeviceInterface* self, IMountpoint* out), + void (*in)(DeviceInterface* self, IMountpoint* in)); + + virtual ~AHCIDeviceInterface() override; + + public: + AHCIDeviceInterface& operator=(const AHCIDeviceInterface&) = default; + AHCIDeviceInterface(const AHCIDeviceInterface&) = default; + + const Char* Name() const override; + + const UInt16& GetPortsImplemented(); + + Void SetPortsImplemented(const UInt16& pi); + + const UInt32& GetIndex(); + + Void SetIndex(const UInt32& drv); + + public: + AHCIDeviceInterface& operator<<(IMountpoint* Data) override; + AHCIDeviceInterface& operator>>(IMountpoint* Data) override; + + private: + UInt16 fPortsImplemented{0U}; + UInt32 fDriveIndex{0U}; +}; + +UInt16 sk_init_ahci_device(BOOL atapi); +ErrorOr sk_acquire_ahci_device(UInt32 drv_index); +} // namespace Kernel diff --git a/src/kernel/StorageKit/ATA.h b/src/kernel/StorageKit/ATA.h new file mode 100644 index 00000000..f92e09d3 --- /dev/null +++ b/src/kernel/StorageKit/ATA.h @@ -0,0 +1,56 @@ +/* ======================================== + + Copyright (C) 2024-2025, Amlal El Mahrouss, licensed under the Apache 2.0 license. + +======================================== */ + +#pragma once + +#include +#include +#include +#include + +namespace Kernel { +/// @brief ATA device interface class. +class ATADeviceInterface : public DeviceInterface { + public: + explicit ATADeviceInterface(void (*Out)(DeviceInterface*, IMountpoint* outpacket), + void (*In)(DeviceInterface*, IMountpoint* inpacket)); + + virtual ~ATADeviceInterface(); + + public: + ATADeviceInterface& operator<<(IMountpoint* Data) override; + ATADeviceInterface& operator>>(IMountpoint* Data) override; + + public: + ATADeviceInterface& operator=(const ATADeviceInterface&) = default; + ATADeviceInterface(const ATADeviceInterface&) = default; + + const Char* Name() const override; + + const UInt16& GetIO(); + Void SetIO(const UInt16& io); + + const UInt16& GetMaster(); + Void SetMaster(const UInt16& master); + + const UInt32& GetIndex(); + Void SetIndex(const UInt32& drv); + + private: + UInt32 fDriveIndex{0U}; + UInt16 fIO, fMaster{0U}; +}; + +/// @brief Initialize an PIO device (StorageKit function) +/// @param is_master is the current PIO master? +/// @return [io:master] for PIO device. +BOOL sk_init_ata_device(BOOL is_master, UInt16& io, UInt8& master); + +/// @brief Acquires a new PIO device with drv_index in mind. +/// @param drv_index The drive index to assign. +/// @return A wrapped device interface if successful, or error code. +ErrorOr sk_acquire_ata_device(Int32 drv_index); +} // namespace Kernel diff --git a/src/kernel/StorageKit/NVME.h b/src/kernel/StorageKit/NVME.h new file mode 100644 index 00000000..d1c036ab --- /dev/null +++ b/src/kernel/StorageKit/NVME.h @@ -0,0 +1,32 @@ +/* ======================================== + + Copyright (C) 2024-2025, Amlal El Mahrouss, licensed under the Apache 2.0 license. + +======================================== */ + +#pragma once + +#include +#include + +namespace Kernel { +class NVMEDeviceInterface final NE_DEVICE { + public: + explicit NVMEDeviceInterface(Void (*out)(DeviceInterface*, IMountpoint* out_packet), + Void (*in)(DeviceInterface*, IMountpoint* in_packet), + Void (*cleanup)(Void)); + + ~NVMEDeviceInterface() override; + + public: + NE_COPY_DEFAULT(NVMEDeviceInterface) + + const Char* Name() const override; + + public: + OwnPtr operator()(UInt32 dma_low, UInt32 dma_high, SizeT dma_sz); + + private: + Void (*fCleanup)(Void) = {nullptr}; +}; +} // namespace Kernel diff --git a/src/kernel/StorageKit/PRDT.h b/src/kernel/StorageKit/PRDT.h new file mode 100644 index 00000000..44eb11be --- /dev/null +++ b/src/kernel/StorageKit/PRDT.h @@ -0,0 +1,33 @@ +/* ======================================== + + Copyright (C) 2024-2025, Amlal El Mahrouss, licensed under the Apache 2.0 license. + +======================================== */ + +#pragma once + +#include +#include +#include + +#define kPrdtTransferSize (sizeof(Kernel::UShort)) + +namespace Kernel { +/// @brief Tranfer information about PRD. +enum { + kPRDTTransferInProgress, + kPRDTTransferIsDone, + kPRDTTransferCount, +}; + +/// @brief Physical Region Descriptor Table. +struct PRDT final { + UInt32 fPhysAddress; + UInt32 fSectorCount; + UInt8 fEndBit; +}; + +void construct_prdt(Ref& prd); + +EXTERN_C Int32 kPRDTTransferStatus; +} // namespace Kernel diff --git a/src/kernel/StorageKit/SCSI.h b/src/kernel/StorageKit/SCSI.h new file mode 100644 index 00000000..4dad00ad --- /dev/null +++ b/src/kernel/StorageKit/SCSI.h @@ -0,0 +1,11 @@ +/* ======================================== + + Copyright (C) 2024-2025, Amlal El Mahrouss, licensed under the Apache 2.0 license. + +======================================== */ + +#pragma once + +#include + +namespace Kernel {} // namespace Kernel \ No newline at end of file diff --git a/src/kernel/StorageKit/StorageKit.h b/src/kernel/StorageKit/StorageKit.h new file mode 100644 index 00000000..c9633392 --- /dev/null +++ b/src/kernel/StorageKit/StorageKit.h @@ -0,0 +1,21 @@ +/* ======================================== + + Copyright (C) 2024-2025, Amlal El Mahrouss, licensed under the Apache 2.0 license. + +======================================== */ + +#pragma once + +#define kDriveSectorSizeHDD (512U) +#define kDriveSectorSizeSSD (512U) +#define kDriveSectorSizeOptical (2048U) + +namespace Kernel { +template +class DeviceInterface; + +class NVMEDeviceInterface; +class AHCIDeviceInterface; +class ATADeviceInterface; +class SCSIDeviceInterface; +} // namespace Kernel -- cgit v1.2.3