summaryrefslogtreecommitdiffhomepage
path: root/src/kernel/StorageKit
diff options
context:
space:
mode:
Diffstat (limited to 'src/kernel/StorageKit')
-rw-r--r--src/kernel/StorageKit/AHCI.h49
-rw-r--r--src/kernel/StorageKit/ATA.h56
-rw-r--r--src/kernel/StorageKit/NVME.h32
-rw-r--r--src/kernel/StorageKit/PRDT.h33
-rw-r--r--src/kernel/StorageKit/SCSI.h11
-rw-r--r--src/kernel/StorageKit/StorageKit.h21
6 files changed, 202 insertions, 0 deletions
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 <KernelKit/DeviceMgr.h>
+#include <KernelKit/DriveMgr.h>
+#include <NeKit/OwnPtr.h>
+
+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<IMountpoint*> {
+ 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<AHCIDeviceInterface> 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 <KernelKit/DeviceMgr.h>
+#include <KernelKit/DriveMgr.h>
+#include <NeKit/OwnPtr.h>
+#include <NeKit/Utils.h>
+
+namespace Kernel {
+/// @brief ATA device interface class.
+class ATADeviceInterface : public DeviceInterface<IMountpoint*> {
+ 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<ATADeviceInterface> 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 <KernelKit/DeviceMgr.h>
+#include <KernelKit/DriveMgr.h>
+
+namespace Kernel {
+class NVMEDeviceInterface final NE_DEVICE<IMountpoint*> {
+ 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<IMountpoint*> 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 <KernelKit/PCI/DMA.h>
+#include <KernelKit/PCI/Iterator.h>
+#include <NeKit/Ref.h>
+
+#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<PRDT>& 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 <modules/SCSI/SCSI.h>
+
+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 <typename T>
+class DeviceInterface;
+
+class NVMEDeviceInterface;
+class AHCIDeviceInterface;
+class ATADeviceInterface;
+class SCSIDeviceInterface;
+} // namespace Kernel