From 972cddc45f7a71d85b11ce6d76b13c780958b3e4 Mon Sep 17 00:00:00 2001 From: Akshay Chandrashekhar Kalghatgi Date: Thu, 12 Mar 2020 17:20:52 -0700 Subject: [PATCH] msm: vidc: add check for prefetch memory sufficiency Check if the non-pix and pix prefetched memory is sufficient Change-Id: I71561959a3ed1e9acdb654650144f35656230345 Signed-off-by: Akshay Chandrashekhar Kalghatgi --- msm/vidc/msm_vidc.c | 2 ++ msm/vidc/msm_vidc_common.c | 55 ++++++++++++++++++++++++++++++++++++++ msm/vidc/msm_vidc_common.h | 1 + 3 files changed, 58 insertions(+) diff --git a/msm/vidc/msm_vidc.c b/msm/vidc/msm_vidc.c index 60fadec7452d..79fcbbfea408 100644 --- a/msm/vidc/msm_vidc.c +++ b/msm/vidc/msm_vidc.c @@ -885,6 +885,8 @@ static inline int start_streaming(struct msm_vidc_inst *inst) goto fail_start; } + msm_comm_check_prefetch_sufficient(inst); + rc = msm_comm_set_scratch_buffers(inst); if (rc) { s_vpr_e(inst->sid, "Failed to set scratch buffers: %d\n", rc); diff --git a/msm/vidc/msm_vidc_common.c b/msm/vidc/msm_vidc_common.c index aa0c47d323cd..9ce78e0de404 100644 --- a/msm/vidc/msm_vidc_common.c +++ b/msm/vidc/msm_vidc_common.c @@ -7434,3 +7434,58 @@ int msm_comm_memory_drain(struct msm_vidc_inst *inst) return rc; } + +int msm_comm_check_prefetch_sufficient(struct msm_vidc_inst *inst) +{ + int rc = 0; + struct msm_vidc_platform_resources *res; + struct v4l2_plane_pix_format *fmt; + u32 i, internal_buf_sz = 0; + u32 prefetch_npix_sz = 0; + u32 prefetch_pix_sz = 0; + + if (!inst || !inst->core) { + d_vpr_e("%s: invalid parameters\n", __func__); + return -EINVAL; + } + res = &inst->core->resources; + fmt = inst->fmts[OUTPUT_PORT].v4l2_fmt.fmt.pix_mp.plane_fmt; + + if (!is_secure_session(inst) || !is_decode_session(inst)) + return rc; + + if (!(inst->memory_ops & MEMORY_PREFETCH)) + return -ENOMEM; + + prefetch_npix_sz = res->prefetch_non_pix_buf_count * + res->prefetch_non_pix_buf_size; + prefetch_pix_sz = res->prefetch_pix_buf_count * + res->prefetch_pix_buf_size; + + for (i = 0; i < HAL_BUFFER_MAX; i++) { + struct hal_buffer_requirements *req; + + req = &inst->buff_req.buffer[i]; + if (req->buffer_type == HAL_BUFFER_INTERNAL_SCRATCH || + req->buffer_type == HAL_BUFFER_INTERNAL_SCRATCH_1 || + req->buffer_type == HAL_BUFFER_INTERNAL_SCRATCH_2 || + req->buffer_type == HAL_BUFFER_INTERNAL_PERSIST || + req->buffer_type == HAL_BUFFER_INTERNAL_PERSIST_1) + internal_buf_sz += req->buffer_size; + } + + if (prefetch_npix_sz < internal_buf_sz) { + s_vpr_e(inst->sid, + "insufficient non-pix region prefetched %u, required %u", + internal_buf_sz, prefetch_npix_sz); + rc = -ENOMEM; + } + if (prefetch_pix_sz < fmt->sizeimage) { + s_vpr_e(inst->sid, + "insufficient pix region prefetched %u, required %u", + fmt->sizeimage, prefetch_pix_sz); + rc = -ENOMEM; + } + + return rc; +} diff --git a/msm/vidc/msm_vidc_common.h b/msm/vidc/msm_vidc_common.h index 234d0c58be95..3c5c84093ed2 100644 --- a/msm/vidc/msm_vidc_common.h +++ b/msm/vidc/msm_vidc_common.h @@ -341,4 +341,5 @@ u32 msm_comm_calc_framerate(struct msm_vidc_inst *inst, u64 timestamp_us, u64 prev_ts); int msm_comm_memory_prefetch(struct msm_vidc_inst *inst); int msm_comm_memory_drain(struct msm_vidc_inst *inst); +int msm_comm_check_prefetch_sufficient(struct msm_vidc_inst *inst); #endif