diff options
| author | Amlal <amlal@nekernel.org> | 2025-04-28 09:06:35 +0200 |
|---|---|---|
| committer | Amlal <amlal@nekernel.org> | 2025-04-28 09:06:35 +0200 |
| commit | 2ead335ccc7afd8e1b2a6533e966c10f49fbdfe9 (patch) | |
| tree | ca447cda4307a2e51990d901be29a72829b2ea4c /dev/kernel/StorageKit/DmaPool.h | |
| parent | 8a7396493c3effb356d2dc4484b993b4698bc422 (diff) | |
dev, kernel: HeFS, Tooling: reworked the mkfs.hefs tool for the new filesystem.
other/related:
- Add new KPC codes.
- Final refactors for HeFS's Format method.
- Dma pool improvements.
- Better standard disk I/O names.
- Add mm_memory_fence function inside HalPagingMgrAMD64.cc
Signed-off-by: Amlal <amlal@nekernel.org>
Diffstat (limited to 'dev/kernel/StorageKit/DmaPool.h')
| -rw-r--r-- | dev/kernel/StorageKit/DmaPool.h | 21 |
1 files changed, 17 insertions, 4 deletions
diff --git a/dev/kernel/StorageKit/DmaPool.h b/dev/kernel/StorageKit/DmaPool.h index 9e59910a..09851a0c 100644 --- a/dev/kernel/StorageKit/DmaPool.h +++ b/dev/kernel/StorageKit/DmaPool.h @@ -23,6 +23,7 @@ #pragma once #include <KernelKit/DebugOutput.h> +#include "NewKit/Defines.h" #ifdef __NE_AMD64__ #define NE_DMA_POOL_START (0x1000000) @@ -30,11 +31,14 @@ namespace Kernel { /// @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; +inline UInt8* kDmaPoolPtr = (UInt8*) NE_DMA_POOL_START; +inline const UInt8* kDmaPoolEnd = (UInt8*) (NE_DMA_POOL_START + NE_DMA_POOL_SIZE); +/***********************************************************************************/ /// @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; @@ -42,11 +46,14 @@ inline VoidPtr rtl_dma_alloc(SizeT size, SizeT align) { UIntPtr addr = (UIntPtr) kDmaPoolPtr; - /// here we just align the address according to a `align` variable, i'd rather be a power of two really. + /// 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) >= (NE_DMA_POOL_START + NE_DMA_POOL_SIZE)) { - kout << "DMA Pool exhausted!\r"; + if ((addr + size) >= reinterpret_cast<UIntPtr>(kDmaPoolEnd)) { + kout << "DMA Pool is exhausted!\r"; + + err_global_get() = kErrorDmaExhausted; return nullptr; } @@ -55,12 +62,18 @@ inline VoidPtr rtl_dma_alloc(SizeT size, SizeT align) { return (VoidPtr) addr; } +/***********************************************************************************/ +/// @brief Free DMA pointer. +/***********************************************************************************/ inline Void rtl_dma_free(SizeT size) { if (!size) return; kDmaPoolPtr = (UInt8*) (kDmaPoolPtr - size); } +/***********************************************************************************/ +/// @brief Flush DMA pointer. +/***********************************************************************************/ inline Void rtl_dma_flush(VoidPtr ptr, SizeT size_buffer) { if (ptr > (Void*) (NE_DMA_POOL_START + NE_DMA_POOL_SIZE)) { return; |
