From cee65540d8bdcb0f2887004cdc09ee22e496727a Mon Sep 17 00:00:00 2001 From: sladro Date: Fri, 26 Dec 2025 16:17:25 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BD=BF=E7=94=A8=20DMA-BUF=20=E5=88=86?= =?UTF-8?q?=E9=85=8D=E5=86=85=E5=AD=98=EF=BC=8C=E4=BF=AE=E5=A4=8D=E5=8A=9F?= =?UTF-8?q?=E8=83=BDbug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/utils/dma_alloc.cpp | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/src/utils/dma_alloc.cpp b/src/utils/dma_alloc.cpp index 1523b1a..109c285 100644 --- a/src/utils/dma_alloc.cpp +++ b/src/utils/dma_alloc.cpp @@ -80,27 +80,43 @@ DmaBuffer& DmaBuffer::operator=(DmaBuffer&& other) noexcept { DmaBufferPtr DmaAlloc(size_t alloc_size) { #if defined(__linux__) - // Try different dma_heap devices + // Try different dma_heap devices - prefer CMA for RGA compatibility (<4GB) const char* heap_paths[] = { + "/dev/dma_heap/cma", + "/dev/dma_heap/cma-uncached", + "/dev/dma_heap/linux,cma", + "/dev/dma_heap/reserved", "/dev/dma_heap/system-uncached", "/dev/dma_heap/system", - "/dev/dma_heap/cma", nullptr }; int heap_fd = -1; + const char* used_heap = nullptr; for (int i = 0; heap_paths[i] != nullptr; ++i) { heap_fd = open(heap_paths[i], O_RDWR | O_CLOEXEC); if (heap_fd >= 0) { + used_heap = heap_paths[i]; break; } } if (heap_fd < 0) { std::cerr << "[DmaAlloc] failed to open dma_heap device: " << strerror(errno) << "\n"; + std::cerr << "[DmaAlloc] tried: "; + for (int i = 0; heap_paths[i] != nullptr; ++i) { + std::cerr << heap_paths[i] << " "; + } + std::cerr << "\n"; return nullptr; } + static bool first_alloc = true; + if (first_alloc) { + std::cout << "[DmaAlloc] using heap: " << used_heap << "\n"; + first_alloc = false; + } + dma_heap_allocation_data alloc_data{}; alloc_data.len = alloc_size; alloc_data.fd_flags = O_RDWR | O_CLOEXEC;