summaryrefslogtreecommitdiffhomepage
path: root/dev/kernel/StorageKit
diff options
context:
space:
mode:
authorAmlal <amlal@nekernel.org>2025-04-27 19:51:43 +0200
committerAmlal <amlal@nekernel.org>2025-04-27 19:51:43 +0200
commit11dd858e1d9da71a182bc707ca3a481dafbccbe4 (patch)
tree0b2ce000054b257e005199f31ac6a21a0eb5ffe5 /dev/kernel/StorageKit
parentcb2f383f45dda8d1cdcef0b87fe4c70243659701 (diff)
dev, kernel: refactor and improve parts of the kernel, related to I/O
Signed-off-by: Amlal <amlal@nekernel.org>
Diffstat (limited to 'dev/kernel/StorageKit')
-rw-r--r--dev/kernel/StorageKit/ATA.h4
-rw-r--r--dev/kernel/StorageKit/DmaPool.h (renamed from dev/kernel/StorageKit/DMA.h)25
-rw-r--r--dev/kernel/StorageKit/StorageKit.h2
3 files changed, 20 insertions, 11 deletions
diff --git a/dev/kernel/StorageKit/ATA.h b/dev/kernel/StorageKit/ATA.h
index d2950228..5887c579 100644
--- a/dev/kernel/StorageKit/ATA.h
+++ b/dev/kernel/StorageKit/ATA.h
@@ -47,10 +47,10 @@ class ATADeviceInterface : public IDeviceObject<MountpointInterface*> {
/// @brief Initialize an PIO device (StorageKit function)
/// @param is_master is the current PIO master?
/// @return [io:master] for PIO device.
-BOOL sk_init_pio_device(BOOL is_master, UInt16& io, UInt8& master);
+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_pio_device(Int32 drv_index);
+ErrorOr<ATADeviceInterface> sk_acquire_ata_device(Int32 drv_index);
} // namespace Kernel
diff --git a/dev/kernel/StorageKit/DMA.h b/dev/kernel/StorageKit/DmaPool.h
index c572ffa3..9e59910a 100644
--- a/dev/kernel/StorageKit/DMA.h
+++ b/dev/kernel/StorageKit/DmaPool.h
@@ -23,15 +23,18 @@
#pragma once
#include <KernelKit/DebugOutput.h>
-#include <NewKit/Defines.h>
#ifdef __NE_AMD64__
-#define DMA_POOL_START (0x1000000)
-#define DMA_POOL_SIZE (0x1000000)
+#define NE_DMA_POOL_START (0x1000000)
+#define NE_DMA_POOL_SIZE (0x1000000)
namespace Kernel {
-inline UInt8* kDmaPoolPtr = (UInt8*) DMA_POOL_START;
+/// @brief DMA pool base pointer, here we're sure that AHCI or whatever tricky standard sees it.
+inline UInt8* kDmaPoolPtr = (UInt8*) NE_DMA_POOL_START;
+/// @brief allocate from the rtl_dma_alloc system.
+/// @param size the size of the chunk to allocate.
+/// @param align alignement of pointer.
inline VoidPtr rtl_dma_alloc(SizeT size, SizeT align) {
if (!size) {
return nullptr;
@@ -39,9 +42,10 @@ inline VoidPtr rtl_dma_alloc(SizeT size, SizeT align) {
UIntPtr addr = (UIntPtr) kDmaPoolPtr;
- addr = (addr + (align - 1)) & ~(align - 1); // Align up
+ /// here we just align the address according to a `align` variable, i'd rather be a power of two really.
+ addr = (addr + (align - 1)) & ~(align - 1);
- if (addr + size >= DMA_POOL_START + DMA_POOL_SIZE) {
+ if ((addr + size) >= (NE_DMA_POOL_START + NE_DMA_POOL_SIZE)) {
kout << "DMA Pool exhausted!\r";
return nullptr;
@@ -57,14 +61,19 @@ inline Void rtl_dma_free(SizeT size) {
kDmaPoolPtr = (UInt8*) (kDmaPoolPtr - size);
}
-inline Void rtl_dma_flush(Void* ptr, SizeT size_buffer) {
- if (ptr > (Void*) (DMA_POOL_START + DMA_POOL_SIZE)) {
+inline Void rtl_dma_flush(VoidPtr ptr, SizeT size_buffer) {
+ if (ptr > (Void*) (NE_DMA_POOL_START + NE_DMA_POOL_SIZE)) {
+ return;
+ }
+
+ if (!ptr) {
return;
}
for (SizeT i = 0; i < size_buffer; ++i) {
asm volatile("clflush (%0)" : : "r"((UInt8*) ptr + i) : "memory");
}
+
asm volatile("mfence" ::: "memory");
}
} // namespace Kernel
diff --git a/dev/kernel/StorageKit/StorageKit.h b/dev/kernel/StorageKit/StorageKit.h
index 9dbb014d..adb9f5dc 100644
--- a/dev/kernel/StorageKit/StorageKit.h
+++ b/dev/kernel/StorageKit/StorageKit.h
@@ -8,7 +8,7 @@
#define kDriveSectorSizeHDD (512U)
#define kDriveSectorSizeSSD (512U)
-#define kDriveSectorSizeOptical (2048)
+#define kDriveSectorSizeOptical (2048U)
namespace Kernel {
template <typename T>