diff options
| author | Amlal <amlal@nekernel.org> | 2025-04-27 13:35:09 +0200 |
|---|---|---|
| committer | Amlal <amlal@nekernel.org> | 2025-04-27 13:35:09 +0200 |
| commit | 780263dedaa289dd707af387529674ef63804b60 (patch) | |
| tree | 570b7bb0eb547fef0cc3eb1731ea403d26324b1a /dev/kernel/StorageKit/DMA.h | |
| parent | e5efb02ff49e7a5a0083acc5f4b1af5fbb73b518 (diff) | |
StorageKit: made DMA.h stronger and more resilient.
Signed-off-by: Amlal <amlal@nekernel.org>
Diffstat (limited to 'dev/kernel/StorageKit/DMA.h')
| -rw-r--r-- | dev/kernel/StorageKit/DMA.h | 17 |
1 files changed, 16 insertions, 1 deletions
diff --git a/dev/kernel/StorageKit/DMA.h b/dev/kernel/StorageKit/DMA.h index 953683eb..17dda29a 100644 --- a/dev/kernel/StorageKit/DMA.h +++ b/dev/kernel/StorageKit/DMA.h @@ -33,6 +33,10 @@ namespace Kernel { inline UInt8* kDmaPoolPtr = (UInt8*) DMA_POOL_START; inline VoidPtr rtl_dma_alloc(SizeT size, SizeT align) { + if (!size) { + return nullptr; + } + UIntPtr addr = (UIntPtr) kDmaPoolPtr; addr = (addr + (align - 1)) & ~(align - 1); // Align up @@ -47,12 +51,23 @@ inline VoidPtr rtl_dma_alloc(SizeT size, SizeT align) { return (VoidPtr) addr; } +inline Void rtl_dma_free(SizeT size) { + if (!size) + return; + + kDmaPoolPtr = (UInt8*) (kDmaPoolPtr - size); +} + inline Void rtl_dma_flush(Void* ptr, SizeT size_buffer) { + if (ptr > (Void*)(DMA_POOL_START + DMA_POOL_SIZE)) + { + return; + } + for (SizeT i = 0; i < size_buffer; ++i) { asm volatile("clflush (%0)" : : "r"((UInt8*) ptr + i) : "memory"); } asm volatile("mfence" ::: "memory"); } } // namespace Kernel -#else #endif
\ No newline at end of file |
