From a3a9083c7b604b246aede8aa468721daa32bf1c0 Mon Sep 17 00:00:00 2001 From: Ayoung Sim Date: Tue, 5 Dec 2017 09:26:47 +0900 Subject: [PATCH] media: mfc: change the map/unmap location before: buf_init / buf_cleanup after: buf_prepare / buf_finish(IRQ) Change-Id: Ia3577b6e69b768b224fa0f84d90b44da1e330d74 Signed-off-by: Ayoung Sim --- .../platform/exynos/mfc/s5p_mfc_enc_vb2_ops.c | 133 ++++++++---------- .../media/platform/exynos/mfc/s5p_mfc_irq.c | 5 +- .../media/platform/exynos/mfc/s5p_mfc_nal_q.c | 5 +- .../media/platform/exynos/mfc/s5p_mfc_queue.c | 4 +- 4 files changed, 68 insertions(+), 79 deletions(-) diff --git a/drivers/media/platform/exynos/mfc/s5p_mfc_enc_vb2_ops.c b/drivers/media/platform/exynos/mfc/s5p_mfc_enc_vb2_ops.c index 2cc3c43c1ca1..f31adbc3f3b6 100644 --- a/drivers/media/platform/exynos/mfc/s5p_mfc_enc_vb2_ops.c +++ b/drivers/media/platform/exynos/mfc/s5p_mfc_enc_vb2_ops.c @@ -123,9 +123,7 @@ static int s5p_mfc_enc_buf_init(struct vb2_buffer *vb) { struct vb2_queue *vq = vb->vb2_queue; struct s5p_mfc_ctx *ctx = vq->drv_priv; - struct s5p_mfc_buf *buf = vb_to_mfc_buf(vb); - struct dma_buf *dmabuf; - int i, ret; + int ret; mfc_debug_enter(); @@ -134,8 +132,6 @@ static int s5p_mfc_enc_buf_init(struct vb2_buffer *vb) if (ret < 0) return ret; - buf->addr[0][0] = s5p_mfc_mem_get_daddr_vb(vb, 0); - if (call_cop(ctx, init_buf_ctrls, ctx, MFC_CTRL_TYPE_DST, vb->index) < 0) mfc_err_ctx("failed in init_buf_ctrls\n"); @@ -145,6 +141,64 @@ static int s5p_mfc_enc_buf_init(struct vb2_buffer *vb) if (ret < 0) return ret; + if (call_cop(ctx, init_buf_ctrls, ctx, MFC_CTRL_TYPE_SRC, + vb->index) < 0) + mfc_err_ctx("failed in init_buf_ctrls\n"); + } else { + mfc_err_ctx("inavlid queue type: %d\n", vq->type); + return -EINVAL; + } + + mfc_debug_leave(); + + return 0; +} + +static int s5p_mfc_enc_buf_prepare(struct vb2_buffer *vb) +{ + struct vb2_queue *vq = vb->vb2_queue; + struct s5p_mfc_ctx *ctx = vq->drv_priv; + struct s5p_mfc_enc *enc = ctx->enc_priv; + struct s5p_mfc_raw_info *raw; + unsigned int index = vb->index; + struct s5p_mfc_buf *buf = vb_to_mfc_buf(vb); + struct dma_buf *dmabuf; + int i; + + mfc_debug_enter(); + + if (vq->type == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE) { + mfc_debug(2, "plane size: %lu, dst size: %u\n", + vb2_plane_size(vb, 0), enc->dst_buf_size); + + if (vb2_plane_size(vb, 0) < enc->dst_buf_size) { + mfc_err_ctx("plane size is too small for capture\n"); + return -EINVAL; + } + + buf->addr[0][0] = s5p_mfc_mem_get_daddr_vb(vb, 0); + } else if (vq->type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE) { + raw = &ctx->raw_buf; + if (ctx->src_fmt->mem_planes == 1) { + mfc_debug(2, "Plane size = %lu, src size:%d\n", + vb2_plane_size(vb, 0), + raw->total_plane_size); + if (vb2_plane_size(vb, 0) < raw->total_plane_size) { + mfc_err_ctx("Output plane is too small\n"); + return -EINVAL; + } + } else { + for (i = 0; i < ctx->src_fmt->mem_planes; i++) { + mfc_debug(2, "plane[%d] size: %lu, src[%d] size: %d\n", + i, vb2_plane_size(vb, i), + i, raw->plane_size[i]); + if (vb2_plane_size(vb, i) < raw->plane_size[i]) { + mfc_err_ctx("Output plane[%d] is too smalli\n", i); + return -EINVAL; + } + } + } + for (i = 0; i < ctx->src_fmt->num_planes; i++) { dmabuf = s5p_mfc_mem_get_dmabuf(vb->planes[i].m.fd); if (!dmabuf) @@ -197,68 +251,6 @@ static int s5p_mfc_enc_buf_init(struct vb2_buffer *vb) } else { buf->addr[0][i] = s5p_mfc_mem_get_daddr_vb(vb, i); } - - } - } - if (call_cop(ctx, init_buf_ctrls, ctx, MFC_CTRL_TYPE_SRC, - vb->index) < 0) - mfc_err_ctx("failed in init_buf_ctrls\n"); - } else { - mfc_err_ctx("inavlid queue type: %d\n", vq->type); - return -EINVAL; - } - - mfc_debug_leave(); - - return 0; -} - -static int s5p_mfc_enc_buf_prepare(struct vb2_buffer *vb) -{ - struct vb2_queue *vq = vb->vb2_queue; - struct s5p_mfc_ctx *ctx = vq->drv_priv; - struct s5p_mfc_enc *enc = ctx->enc_priv; - struct s5p_mfc_raw_info *raw; - unsigned int index = vb->index; - int ret, i; - - mfc_debug_enter(); - - if (vq->type == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE) { - ret = s5p_mfc_check_vb_with_fmt(ctx->dst_fmt, vb); - if (ret < 0) - return ret; - - mfc_debug(2, "plane size: %lu, dst size: %u\n", - vb2_plane_size(vb, 0), enc->dst_buf_size); - - if (vb2_plane_size(vb, 0) < enc->dst_buf_size) { - mfc_err_ctx("plane size is too small for capture\n"); - return -EINVAL; - } - } else if (vq->type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE) { - ret = s5p_mfc_check_vb_with_fmt(ctx->src_fmt, vb); - if (ret < 0) - return ret; - - raw = &ctx->raw_buf; - if (ctx->src_fmt->mem_planes == 1) { - mfc_debug(2, "Plane size = %lu, src size:%d\n", - vb2_plane_size(vb, 0), - raw->total_plane_size); - if (vb2_plane_size(vb, 0) < raw->total_plane_size) { - mfc_err_ctx("Output plane is too small\n"); - return -EINVAL; - } - } else { - for (i = 0; i < ctx->src_fmt->mem_planes; i++) { - mfc_debug(2, "plane[%d] size: %lu, src[%d] size: %d\n", - i, vb2_plane_size(vb, i), - i, raw->plane_size[i]); - if (vb2_plane_size(vb, i) < raw->plane_size[i]) { - mfc_err_ctx("Output plane[%d] is too smalli\n", i); - return -EINVAL; - } } } @@ -303,13 +295,6 @@ static void s5p_mfc_enc_buf_cleanup(struct vb2_buffer *vb) MFC_CTRL_TYPE_DST, index) < 0) mfc_err_ctx("failed in cleanup_buf_ctrls\n"); } else if (vq->type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE) { - if (IS_BUFFER_BATCH_MODE(ctx)) { - struct s5p_mfc_buf *buf = vb_to_mfc_buf(vb); - int i; - - for (i = 0; i < ctx->src_fmt->num_planes; i++) - s5p_mfc_bufcon_put_daddr(ctx, buf, i); - } if (call_cop(ctx, cleanup_buf_ctrls, ctx, MFC_CTRL_TYPE_SRC, index) < 0) mfc_err_ctx("failed in cleanup_buf_ctrls\n"); diff --git a/drivers/media/platform/exynos/mfc/s5p_mfc_irq.c b/drivers/media/platform/exynos/mfc/s5p_mfc_irq.c index 8e188b6b6fd7..e6237215a735 100644 --- a/drivers/media/platform/exynos/mfc/s5p_mfc_irq.c +++ b/drivers/media/platform/exynos/mfc/s5p_mfc_irq.c @@ -833,8 +833,9 @@ static void mfc_handle_stream_input(struct s5p_mfc_ctx *ctx, int slice_type) if (!src_mb->num_bufs_in_vb || src_mb->done_index == src_mb->num_bufs_in_vb) { src_mb = s5p_mfc_find_del_buf(&ctx->buf_queue_lock, &ctx->src_buf_queue, enc_addr[0]); - if (src_mb) - vb2_buffer_done(&src_mb->vb.vb2_buf, VB2_BUF_STATE_DONE); + for (i = 0; i < raw->num_planes; i++) + s5p_mfc_bufcon_put_daddr(ctx, src_mb, i); + vb2_buffer_done(&src_mb->vb.vb2_buf, VB2_BUF_STATE_DONE); } /* encoder src buffer CFW UNPROT */ diff --git a/drivers/media/platform/exynos/mfc/s5p_mfc_nal_q.c b/drivers/media/platform/exynos/mfc/s5p_mfc_nal_q.c index 1fcff1c51616..0124bf551faf 100644 --- a/drivers/media/platform/exynos/mfc/s5p_mfc_nal_q.c +++ b/drivers/media/platform/exynos/mfc/s5p_mfc_nal_q.c @@ -876,8 +876,9 @@ static void mfc_nal_q_handle_stream_input(struct s5p_mfc_ctx *ctx, int slice_typ if (src_mb->done_index == src_mb->num_bufs_in_vb) { src_mb = s5p_mfc_find_del_buf(&ctx->buf_queue_lock, &ctx->src_buf_nal_queue, enc_addr[0]); - if (src_mb) - vb2_buffer_done(&src_mb->vb.vb2_buf, VB2_BUF_STATE_DONE); + for (i = 0; i < raw->num_planes; i++) + s5p_mfc_bufcon_put_daddr(ctx, src_mb, i); + vb2_buffer_done(&src_mb->vb.vb2_buf, VB2_BUF_STATE_DONE); } } } diff --git a/drivers/media/platform/exynos/mfc/s5p_mfc_queue.c b/drivers/media/platform/exynos/mfc/s5p_mfc_queue.c index 8639b326de62..68532fee8b82 100644 --- a/drivers/media/platform/exynos/mfc/s5p_mfc_queue.c +++ b/drivers/media/platform/exynos/mfc/s5p_mfc_queue.c @@ -697,8 +697,10 @@ void s5p_mfc_cleanup_enc_src_queue(struct s5p_mfc_ctx *ctx) s5p_mfc_raw_unprotect(ctx, src_mb, i); - for (i = 0; i < src_mb->vb.vb2_buf.num_planes; i++) + for (i = 0; i < src_mb->vb.vb2_buf.num_planes; i++) { + s5p_mfc_bufcon_put_daddr(ctx, src_mb, i); vb2_set_plane_payload(&src_mb->vb.vb2_buf, i, 0); + } vb2_buffer_done(&src_mb->vb.vb2_buf, VB2_BUF_STATE_ERROR); list_del(&src_mb->list); -- 2.20.1