summaryrefslogtreecommitdiff
path: root/Kernel/Memory/MemoryManager.cpp
diff options
context:
space:
mode:
authorPankaj Raghav <pankydev8@gmail.com>2021-12-16 20:35:51 +0530
committerAndreas Kling <kling@serenityos.org>2022-01-01 14:55:58 +0100
commit602b35aa62586f5d75ea329ebc29e49cdb470932 (patch)
tree6293f410a0a4b09d505f097cf3bc0e54995e1981 /Kernel/Memory/MemoryManager.cpp
parent8489388e753faa7d0cba2c834c2b5154337490ce (diff)
downloadserenity-602b35aa62586f5d75ea329ebc29e49cdb470932.zip
Kernel: Add DMA allocate functions that are TRY-able
Add DMA allocate buffer helper functions in MemoryManager.
Diffstat (limited to 'Kernel/Memory/MemoryManager.cpp')
-rw-r--r--Kernel/Memory/MemoryManager.cpp19
1 files changed, 19 insertions, 0 deletions
diff --git a/Kernel/Memory/MemoryManager.cpp b/Kernel/Memory/MemoryManager.cpp
index 4e1185e5cb..ae7950a9b2 100644
--- a/Kernel/Memory/MemoryManager.cpp
+++ b/Kernel/Memory/MemoryManager.cpp
@@ -733,6 +733,25 @@ ErrorOr<NonnullOwnPtr<Region>> MemoryManager::allocate_contiguous_kernel_region(
return allocate_kernel_region_with_vmobject(range, move(vmobject), name, access, cacheable);
}
+ErrorOr<NonnullOwnPtr<Memory::Region>> MemoryManager::allocate_dma_buffer_page(StringView name, Memory::Region::Access access, RefPtr<Memory::PhysicalPage>& dma_buffer_page)
+{
+ dma_buffer_page = allocate_supervisor_physical_page();
+ if (dma_buffer_page.is_null())
+ return ENOMEM;
+ auto region_or_error = allocate_kernel_region(dma_buffer_page->paddr(), PAGE_SIZE, name, access);
+ return region_or_error;
+}
+
+ErrorOr<NonnullOwnPtr<Memory::Region>> MemoryManager::allocate_dma_buffer_pages(size_t size, StringView name, Memory::Region::Access access, NonnullRefPtrVector<Memory::PhysicalPage>& dma_buffer_pages)
+{
+ VERIFY(!(size % PAGE_SIZE));
+ dma_buffer_pages = allocate_contiguous_supervisor_physical_pages(size);
+ if (dma_buffer_pages.is_empty())
+ return ENOMEM;
+ auto region_or_error = allocate_kernel_region(dma_buffer_pages.first().paddr(), size, name, access);
+ return region_or_error;
+}
+
ErrorOr<NonnullOwnPtr<Region>> MemoryManager::allocate_kernel_region(size_t size, StringView name, Region::Access access, AllocationStrategy strategy, Region::Cacheable cacheable)
{
VERIFY(!(size % PAGE_SIZE));