From 3964d13a63e0602bc16857a4d51993e872ce2f23 Mon Sep 17 00:00:00 2001 From: Chinmay Sawarkar Date: Mon, 12 Apr 2021 21:46:49 -0700 Subject: [PATCH] video: driver: Fix bin buffer allocation in secure usecase In Secure session, BIN buffer should be allocated from Secure Bitstream region. Allocated buffer must be hypassigned using the DMA buffer Lend call. Change-Id: If5303e78975aab55ac7475ca3ac9f6272585a44b Signed-off-by: Chinmay Sawarkar --- driver/vidc/src/msm_vidc_driver.c | 2 ++ driver/vidc/src/msm_vidc_memory.c | 25 +++++++++++++++++++++++-- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/driver/vidc/src/msm_vidc_driver.c b/driver/vidc/src/msm_vidc_driver.c index 84178e080f..2c9569db9b 100644 --- a/driver/vidc/src/msm_vidc_driver.c +++ b/driver/vidc/src/msm_vidc_driver.c @@ -881,6 +881,8 @@ u32 msm_vidc_get_buffer_region(struct msm_vidc_inst *inst, region = MSM_VIDC_SECURE_PIXEL; break; case MSM_VIDC_BUF_BIN: + region = MSM_VIDC_SECURE_BITSTREAM; + break; case MSM_VIDC_BUF_ARP: case MSM_VIDC_BUF_COMV: case MSM_VIDC_BUF_NON_COMV: diff --git a/driver/vidc/src/msm_vidc_memory.c b/driver/vidc/src/msm_vidc_memory.c index 8eeb77d3dd..f5fdb4a884 100644 --- a/driver/vidc/src/msm_vidc_memory.c +++ b/driver/vidc/src/msm_vidc_memory.c @@ -7,8 +7,8 @@ #include #include #include -#include -#include +#include +#include #include "msm_vidc_memory.h" #include "msm_vidc_debug.h" @@ -209,6 +209,9 @@ int msm_vidc_memory_alloc(struct msm_vidc_core *core, struct msm_vidc_alloc *mem int size = 0; struct dma_heap *heap; char *heap_name = NULL; + struct mem_buf_lend_kernel_arg lend_arg; + int vmids[1]; + int perms[1]; if (!mem) { d_vpr_e("%s: invalid params\n", __func__); @@ -226,6 +229,8 @@ int msm_vidc_memory_alloc(struct msm_vidc_core *core, struct msm_vidc_alloc *mem heap_name = "qcom,secure-non-pixel"; break; case MSM_VIDC_SECURE_BITSTREAM: + heap_name = "qcom,system"; + break; default: d_vpr_e("invalid secure region : %#x\n", mem->region); return -EINVAL; @@ -243,6 +248,22 @@ int msm_vidc_memory_alloc(struct msm_vidc_core *core, struct msm_vidc_alloc *mem goto error; } + if (mem->secure && mem->type == MSM_VIDC_BUF_BIN) + { + vmids[0] = VMID_CP_BITSTREAM; + perms[0] = PERM_READ | PERM_WRITE; + + lend_arg.nr_acl_entries = ARRAY_SIZE(vmids); + lend_arg.vmids = vmids; + lend_arg.perms = perms; + + rc = mem_buf_lend(mem->dmabuf, &lend_arg); + if (rc) { + d_vpr_e("%s: BIN dmabuf %pK LEND failed, rc %d heap %s\n", + __func__, mem->dmabuf, rc, heap_name); + } + } + if (mem->map_kernel) { dma_buf_begin_cpu_access(mem->dmabuf, DMA_BIDIRECTIONAL); mem->kvaddr = dma_buf_vmap(mem->dmabuf);