media: mfc: change the map/unmap location
authorAyoung Sim <a.sim@samsung.com>
Tue, 5 Dec 2017 00:26:47 +0000 (09:26 +0900)
committerCosmin Tanislav <demonsingur@gmail.com>
Mon, 22 Apr 2024 17:22:21 +0000 (20:22 +0300)
before: buf_init / buf_cleanup
after: buf_prepare / buf_finish(IRQ)

Change-Id: Ia3577b6e69b768b224fa0f84d90b44da1e330d74
Signed-off-by: Ayoung Sim <a.sim@samsung.com>
drivers/media/platform/exynos/mfc/s5p_mfc_enc_vb2_ops.c
drivers/media/platform/exynos/mfc/s5p_mfc_irq.c
drivers/media/platform/exynos/mfc/s5p_mfc_nal_q.c
drivers/media/platform/exynos/mfc/s5p_mfc_queue.c

index 2cc3c43c1ca17efa11949bdb71bb835cadd1c6f1..f31adbc3f3b6a96d912afc96d8ad3538f7cccbf3 100644 (file)
@@ -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");
index 8e188b6b6fd79e0a1024f2ff993756e4bf1d5076..e6237215a735a1d7eb5fc1abfd9346f0ef81e0e7 100644 (file)
@@ -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 */
index 1fcff1c516169d2bbceaa1395d262176c6ccdc88..0124bf551fafdb96689261eb0a109a39bdbb53a9 100644 (file)
@@ -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);
                                        }
                                }
                        }
index 8639b326de621585989548b6aebe6af25993f38b..68532fee8b820f9cd347b205655410b3db740893 100644 (file)
@@ -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);