Because we need to request and release access to reference buffers that are backed by a dma-buf import, keep track of the buffers used as reference and add the appropriate calls in the device_run and job_done m2m callbacks. The latter is introduced for this purpose. Signed-off-by: Paul Kocialkowski <paul.kocialkowski@xxxxxxxxxxx> --- drivers/staging/media/sunxi/cedrus/cedrus.c | 1 + drivers/staging/media/sunxi/cedrus/cedrus.h | 1 + .../staging/media/sunxi/cedrus/cedrus_dec.c | 18 ++++++++++++++++++ .../staging/media/sunxi/cedrus/cedrus_dec.h | 1 + .../staging/media/sunxi/cedrus/cedrus_mpeg2.c | 8 ++++++++ 5 files changed, 29 insertions(+) diff --git a/drivers/staging/media/sunxi/cedrus/cedrus.c b/drivers/staging/media/sunxi/cedrus/cedrus.c index ff11cbeba205..a2c75eb01c2c 100644 --- a/drivers/staging/media/sunxi/cedrus/cedrus.c +++ b/drivers/staging/media/sunxi/cedrus/cedrus.c @@ -250,6 +250,7 @@ static const struct video_device cedrus_video_device = { static const struct v4l2_m2m_ops cedrus_m2m_ops = { .device_run = cedrus_device_run, + .job_done = cedrus_job_done, }; static const struct media_device_ops cedrus_m2m_media_ops = { diff --git a/drivers/staging/media/sunxi/cedrus/cedrus.h b/drivers/staging/media/sunxi/cedrus/cedrus.h index 4aedd24a9848..c1ce3c4ae2a1 100644 --- a/drivers/staging/media/sunxi/cedrus/cedrus.h +++ b/drivers/staging/media/sunxi/cedrus/cedrus.h @@ -77,6 +77,7 @@ struct cedrus_ctx { struct v4l2_ctrl **ctrls; struct vb2_buffer *dst_bufs[VIDEO_MAX_FRAME]; + bool reference_bufs[VIDEO_MAX_FRAME]; }; struct cedrus_dec_ops { diff --git a/drivers/staging/media/sunxi/cedrus/cedrus_dec.c b/drivers/staging/media/sunxi/cedrus/cedrus_dec.c index 2c295286766c..90bf51e71f4f 100644 --- a/drivers/staging/media/sunxi/cedrus/cedrus_dec.c +++ b/drivers/staging/media/sunxi/cedrus/cedrus_dec.c @@ -41,6 +41,7 @@ void cedrus_device_run(void *priv) struct cedrus_dev *dev = ctx->dev; struct cedrus_run run = {}; struct media_request *src_req; + unsigned int i; run.src = v4l2_m2m_next_src_buf(ctx->fh.m2m_ctx); run.dst = v4l2_m2m_next_dst_buf(ctx->fh.m2m_ctx); @@ -63,10 +64,17 @@ void cedrus_device_run(void *priv) break; } + for (i = 0; i < VIDEO_MAX_FRAME; i++) + ctx->reference_bufs[i] = false; + v4l2_m2m_buf_copy_data(run.src, run.dst, true); dev->dec_ops[ctx->current_codec]->setup(ctx, &run); + for (i = 0; i < VIDEO_MAX_FRAME; i++) + if (ctx->reference_bufs[i] && ctx->dst_bufs[i]) + vb2_buffer_access_request(ctx->dst_bufs[i]); + /* Complete request(s) controls if needed. */ if (src_req) @@ -74,3 +82,13 @@ void cedrus_device_run(void *priv) dev->dec_ops[ctx->current_codec]->trigger(ctx); } + +void cedrus_job_done(void *priv) +{ + struct cedrus_ctx *ctx = priv; + unsigned int i; + + for (i = 0; i < VIDEO_MAX_FRAME; i++) + if (ctx->reference_bufs[i] && ctx->dst_bufs[i]) + vb2_buffer_access_release(ctx->dst_bufs[i]); +} diff --git a/drivers/staging/media/sunxi/cedrus/cedrus_dec.h b/drivers/staging/media/sunxi/cedrus/cedrus_dec.h index 8d0fc248220f..9265f28e6dbe 100644 --- a/drivers/staging/media/sunxi/cedrus/cedrus_dec.h +++ b/drivers/staging/media/sunxi/cedrus/cedrus_dec.h @@ -19,5 +19,6 @@ int cedrus_reference_index_find(struct vb2_queue *queue, struct vb2_buffer *vb2_buf, u64 timestamp); void cedrus_device_run(void *priv); +void cedrus_job_done(void *priv); #endif diff --git a/drivers/staging/media/sunxi/cedrus/cedrus_mpeg2.c b/drivers/staging/media/sunxi/cedrus/cedrus_mpeg2.c index 81c66a8aa1ac..2e7deded17aa 100644 --- a/drivers/staging/media/sunxi/cedrus/cedrus_mpeg2.c +++ b/drivers/staging/media/sunxi/cedrus/cedrus_mpeg2.c @@ -162,6 +162,10 @@ static void cedrus_mpeg2_setup(struct cedrus_ctx *ctx, struct cedrus_run *run) /* Forward and backward prediction reference buffers. */ forward_idx = cedrus_reference_index_find(cap_q, &run->dst->vb2_buf, slice_params->forward_ref_ts); + if (forward_idx < 0) + return; + + ctx->reference_bufs[forward_idx] = true; fwd_luma_addr = cedrus_dst_buf_addr(ctx, forward_idx, 0); fwd_chroma_addr = cedrus_dst_buf_addr(ctx, forward_idx, 1); @@ -171,6 +175,10 @@ static void cedrus_mpeg2_setup(struct cedrus_ctx *ctx, struct cedrus_run *run) backward_idx = cedrus_reference_index_find(cap_q, &run->dst->vb2_buf, slice_params->backward_ref_ts); + if (forward_idx < 0) + return; + + ctx->reference_bufs[backward_idx] = true; bwd_luma_addr = cedrus_dst_buf_addr(ctx, backward_idx, 0); bwd_chroma_addr = cedrus_dst_buf_addr(ctx, backward_idx, 1); -- 2.20.1