From e79f94f9980351626f13d709a536390a4be701e2 Mon Sep 17 00:00:00 2001 From: Pankaj Raghav Date: Sat, 8 Jan 2022 13:07:30 +0530 Subject: [PATCH] Kernel: Set Cacheable parameter to NO explicitly in DMA helpers The cacheable parameter to allocate_kernel_region should be explicitly set to No as this region is used to do physical memory transfers. Even though most architectures ignore this even if it is set, it is better to make this explicit. --- Kernel/Memory/MemoryManager.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Kernel/Memory/MemoryManager.cpp b/Kernel/Memory/MemoryManager.cpp index 8b06e7732d..b044b991b5 100644 --- a/Kernel/Memory/MemoryManager.cpp +++ b/Kernel/Memory/MemoryManager.cpp @@ -748,7 +748,8 @@ ErrorOr> MemoryManager::allocate_dma_buffer_page(S 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); + // Do not enable Cache for this region as physical memory transfers are performed (Most architectures have this behaviour by default) + auto region_or_error = allocate_kernel_region(dma_buffer_page->paddr(), PAGE_SIZE, name, access, Region::Cacheable::No); return region_or_error; } @@ -758,7 +759,8 @@ ErrorOr> MemoryManager::allocate_dma_buffer_pages( 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); + // Do not enable Cache for this region as physical memory transfers are performed (Most architectures have this behaviour by default) + auto region_or_error = allocate_kernel_region(dma_buffer_pages.first().paddr(), size, name, access, Region::Cacheable::No); return region_or_error; }