From 9c92ab9e20ba33bc9a663ec3b69d3be7c3ed558c Mon Sep 17 00:00:00 2001 From: Herman Chen Date: Fri, 7 Jun 2024 14:46:25 +0800 Subject: [PATCH] fix[drm]: Fix permission check issue on GKI kernel The GKI kernel does not allow non-render thread to open /dev/dri/card0 and alloc drm buffer from it. So we need to use /dev/dri/renderD128 instead. Signed-off-by: Herman Chen Change-Id: I0fad306c6eeadd8da5507883f4f4915c11946761 --- osal/allocator/allocator_drm.c | 21 +++++++++++++++++---- osal/mpp_runtime.cpp | 4 +++- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/osal/allocator/allocator_drm.c b/osal/allocator/allocator_drm.c index 9bed02fa..415dc9bb 100644 --- a/osal/allocator/allocator_drm.c +++ b/osal/allocator/allocator_drm.c @@ -69,7 +69,11 @@ typedef struct { RK_U32 flags; } allocator_ctx_drm; -static const char *dev_drm = "/dev/dri/card0"; +/* use renderD128 first to avoid GKI kernel permission issue */ +static const char *dev_drm[] = { + "/dev/dri/renderD128", + "/dev/dri/card0", +}; static RK_U32 to_rockchip_gem_mem_flag(RK_U32 flags) { @@ -164,8 +168,9 @@ static int drm_free(int fd, RK_U32 handle) static MPP_RET os_allocator_drm_open(void **ctx, size_t alignment, MppAllocFlagType flags) { - RK_S32 fd; allocator_ctx_drm *p; + RK_S32 fd; + RK_S32 i; if (NULL == ctx) { mpp_err_f("does not accept NULL input\n"); @@ -176,9 +181,17 @@ static MPP_RET os_allocator_drm_open(void **ctx, size_t alignment, MppAllocFlagT mpp_env_get_u32("drm_debug", &drm_debug, 0); - fd = open(dev_drm, O_RDWR | O_CLOEXEC); + for (i = 0; i < (RK_S32)MPP_ARRAY_ELEMS(dev_drm); i++) { + fd = open(dev_drm[i], O_RDWR | O_CLOEXEC); + if (fd > 0) + break; + } + if (fd < 0) { - mpp_err_f("open %s failed!\n", dev_drm); + mpp_err_f("open all drm device failed.\n"); + mpp_err("Please check the following device path and access permission:\n"); + for (i = 0; i < (RK_S32)MPP_ARRAY_ELEMS(dev_drm); i++) + mpp_err("%s\n", dev_drm[i]); return MPP_ERR_UNKNOW; } diff --git a/osal/mpp_runtime.cpp b/osal/mpp_runtime.cpp index c2379963..079463e8 100644 --- a/osal/mpp_runtime.cpp +++ b/osal/mpp_runtime.cpp @@ -85,7 +85,9 @@ MppRuntimeService::MppRuntimeService() 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_DRM] = + !access("/dev/dri/renderD128", F_OK | R_OK | W_OK) || + !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); if (!allocator_valid[MPP_BUFFER_TYPE_ION] &&