Open hbiyik opened 4 months ago
in case no dma device is available, mpp thinks that dma allocator is still valid. I think it should check the availablity of at least one device device in dma devices.
here is a potential fix.
diff --git a/osal/allocator/allocator_dma_heap.c b/osal/allocator/allocator_dma_heap.c index f2465af..828b22d 100644 --- a/osal/allocator/allocator_dma_heap.c +++ b/osal/allocator/allocator_dma_heap.c @@ -67,23 +67,6 @@ RK_U32 flags; } allocator_ctx_dmaheap; -typedef struct DmaHeapInfo_t { - const char *name; - RK_S32 fd; - RK_U32 flags; -} DmaHeapInfo; - -static DmaHeapInfo heap_infos[MPP_ALLOC_FLAG_TYPE_NB] = { - { "system-uncached", -1, MPP_ALLOC_FLAG_NONE , }, /* 0 */ - { "system-uncached-dma32", -1, MPP_ALLOC_FLAG_DMA32, }, /* 1 */ - { "system", -1, MPP_ALLOC_FLAG_CACHABLE , }, /* 2 */ - { "system-dma32", -1, MPP_ALLOC_FLAG_CACHABLE | MPP_ALLOC_FLAG_DMA32, }, /* 3 */ - { "cma-uncached", -1, MPP_ALLOC_FLAG_CMA , }, /* 4 */ - { "cma-uncached-dma32", -1, MPP_ALLOC_FLAG_CMA | MPP_ALLOC_FLAG_DMA32, }, /* 5 */ - { "cma", -1, MPP_ALLOC_FLAG_CMA | MPP_ALLOC_FLAG_CACHABLE , }, /* 6 */ - { "cma-dma32", -1, MPP_ALLOC_FLAG_CMA | MPP_ALLOC_FLAG_CACHABLE | MPP_ALLOC_FLAG_DMA32, }, /* 7 */ -}; - static int try_open_path(const char *name) { static const char *heap_path = "/dev/dma_heap/"; diff --git a/osal/allocator/allocator_dma_heap.h b/osal/allocator/allocator_dma_heap.h index 60f30f4..e7f5535 100644 --- a/osal/allocator/allocator_dma_heap.h +++ b/osal/allocator/allocator_dma_heap.h @@ -19,6 +19,23 @@ #include "mpp_allocator_api.h" +typedef struct DmaHeapInfo_t { + const char *name; + RK_S32 fd; + RK_U32 flags; +} DmaHeapInfo; + +static DmaHeapInfo heap_infos[MPP_ALLOC_FLAG_TYPE_NB] = { + { "system-uncached", -1, MPP_ALLOC_FLAG_NONE , }, /* 0 */ + { "system-uncached-dma32", -1, MPP_ALLOC_FLAG_DMA32, }, /* 1 */ + { "system", -1, MPP_ALLOC_FLAG_CACHABLE , }, /* 2 */ + { "system-dma32", -1, MPP_ALLOC_FLAG_CACHABLE | MPP_ALLOC_FLAG_DMA32, }, /* 3 */ + { "cma-uncached", -1, MPP_ALLOC_FLAG_CMA , }, /* 4 */ + { "cma-uncached-dma32", -1, MPP_ALLOC_FLAG_CMA | MPP_ALLOC_FLAG_DMA32, }, /* 5 */ + { "cma", -1, MPP_ALLOC_FLAG_CMA | MPP_ALLOC_FLAG_CACHABLE , }, /* 6 */ + { "cma-dma32", -1, MPP_ALLOC_FLAG_CMA | MPP_ALLOC_FLAG_CACHABLE | MPP_ALLOC_FLAG_DMA32, }, /* 7 */ +}; + extern os_allocator allocator_dma_heap; #endif diff --git a/osal/mpp_runtime.cpp b/osal/mpp_runtime.cpp index c237996..2e469f3 100644 --- a/osal/mpp_runtime.cpp +++ b/osal/mpp_runtime.cpp @@ -18,11 +18,13 @@ #include <fcntl.h> #include <unistd.h> +#include <stdio.h> #include "mpp_env.h" #include "mpp_log.h" #include "mpp_common.h" #include "mpp_runtime.h" +#include "allocator/allocator_dma_heap.h" #define MAX_DTS_PATH_LEN 256 @@ -86,7 +88,16 @@ allocator_valid[MPP_BUFFER_TYPE_NORMAL] = 1; allocator_valid[MPP_BUFFER_TYPE_ION] = !access("/dev/ion", F_OK | R_OK | W_OK); allocator_valid[MPP_BUFFER_TYPE_DRM] = !access("/dev/dri/card0", F_OK | R_OK | W_OK); - allocator_valid[MPP_BUFFER_TYPE_DMA_HEAP] = !access("/dev/dma_heap", F_OK | R_OK); + + allocator_valid[MPP_BUFFER_TYPE_DMA_HEAP] = 0; + for (int i = 0; i < MPP_ARRAY_ELEMS(heap_infos); i++) { + char buf[64]; + snprintf(buf, sizeof(buf) - 1, "/dev/dma_heap/%s", heap_infos[i].name); + if(!access(buf, F_OK | R_OK)){ + allocator_valid[MPP_BUFFER_TYPE_DMA_HEAP] = 1; + break; + } + } if (!allocator_valid[MPP_BUFFER_TYPE_ION] && !allocator_valid[MPP_BUFFER_TYPE_DRM] &&
Thanks for the patch~
in case no dma device is available, mpp thinks that dma allocator is still valid. I think it should check the availablity of at least one device device in dma devices.
here is a potential fix.