From 0f066190b1758f7311473aaf524f90c95afe49d2 Mon Sep 17 00:00:00 2001 From: Darshana Patil Date: Fri, 16 Apr 2021 20:49:04 -0700 Subject: [PATCH] video: driver: handle release during batching Before output buffer is queued to FW, checking if it is pending release and refcount accordingly. The check needs to be added just before queueing to FW to handle batch usecase as well. Change-Id: I2d394b5642ed8fa916e86ebc59ea414300415fab Signed-off-by: Darshana Patil --- driver/vidc/src/msm_vidc_driver.c | 37 +++++++++++++++++++++---------- driver/vidc/src/msm_vidc_memory.c | 11 +++++---- 2 files changed, 30 insertions(+), 18 deletions(-) diff --git a/driver/vidc/src/msm_vidc_driver.c b/driver/vidc/src/msm_vidc_driver.c index c1472fa9ec..5bb649254c 100644 --- a/driver/vidc/src/msm_vidc_driver.c +++ b/driver/vidc/src/msm_vidc_driver.c @@ -2159,7 +2159,6 @@ int msm_vidc_map_driver_buf(struct msm_vidc_inst *inst, int rc = 0; struct msm_vidc_mappings *mappings; struct msm_vidc_map *map; - struct msm_vidc_buffer *rel_buf; bool found = false; if (!inst || !buf) { @@ -2212,16 +2211,6 @@ int msm_vidc_map_driver_buf(struct msm_vidc_inst *inst, buf->device_addr = map->device_addr; - /* increment map ref_count, if buf already present in release list */ - list_for_each_entry(rel_buf, &inst->buffers.release.list, list) { - if (rel_buf->device_addr == buf->device_addr) { - rc = msm_vidc_memory_map(inst->core, map); - if (rc) - return rc; - break; - } - } - return 0; } @@ -2492,8 +2481,10 @@ exit: static int msm_vidc_queue_buffer(struct msm_vidc_inst *inst, struct msm_vidc_buffer *buf) { - struct msm_vidc_buffer *meta; + struct msm_vidc_buffer *meta, *rel_buf; + struct msm_vidc_map *map; int rc = 0; + bool found = false; if (!inst || !buf || !inst->capabilities) { d_vpr_e("%s: invalid params\n", __func__); @@ -2510,6 +2501,28 @@ static int msm_vidc_queue_buffer(struct msm_vidc_inst *inst, struct msm_vidc_buf rc = msm_vidc_process_readonly_buffers(inst, buf); if (rc) return rc; + + list_for_each_entry(map, &inst->mappings.output.list, list) { + if (map->dmabuf == buf->dmabuf) { + found = true; + break; + } + } + + if (!found) { + print_vidc_buffer(VIDC_ERR, "err ", "missing map", inst, buf); + return -EINVAL; + } + + /* increment map ref_count, if buf already present in release list */ + list_for_each_entry(rel_buf, &inst->buffers.release.list, list) { + if (rel_buf->device_addr == buf->device_addr) { + rc = msm_vidc_memory_map(inst->core, map); + if (rc) + return rc; + break; + } + } } print_vidc_buffer(VIDC_HIGH, "high", "qbuf", inst, buf); diff --git a/driver/vidc/src/msm_vidc_memory.c b/driver/vidc/src/msm_vidc_memory.c index 8eeb77d3dd..c4fc709fd1 100644 --- a/driver/vidc/src/msm_vidc_memory.c +++ b/driver/vidc/src/msm_vidc_memory.c @@ -98,7 +98,7 @@ int msm_vidc_memory_map(struct msm_vidc_core *core, struct msm_vidc_map *map) if (map->refcount) { map->refcount++; - return 0; + goto exit; } cb = get_context_bank(core, map->region); @@ -153,12 +153,11 @@ int msm_vidc_memory_map(struct msm_vidc_core *core, struct msm_vidc_map *map) map->attach = attach; map->refcount++; +exit: d_vpr_l( "%s: type %11s, device_addr %#x, refcount %d, region %d\n", __func__, buf_name(map->type), map->device_addr, map->refcount, map->region); - return 0; - error_sg: dma_buf_unmap_attachment(attach, table, DMA_BIDIRECTIONAL); error_table: @@ -185,13 +184,13 @@ int msm_vidc_memory_unmap(struct msm_vidc_core *core, return -EINVAL; } - if (map->refcount) - goto exit; - d_vpr_l( "%s: type %11s, device_addr %#x, refcount %d, region %d\n", __func__, buf_name(map->type), map->device_addr, map->refcount, map->region); + if (map->refcount) + goto exit; + dma_buf_unmap_attachment(map->attach, map->table, DMA_BIDIRECTIONAL); dma_buf_detach(map->dmabuf, map->attach);