From 6ee30e7435ccfd44fb5178d57d2ec8185144997b Mon Sep 17 00:00:00 2001 From: Ayoung Sim Date: Fri, 22 Jun 2018 13:55:32 +0900 Subject: [PATCH] [COMMON] media: mfc: add buffer mask to dma-buf container Change-Id: I0f2d92331b4e131bf1f67519ad1866894a1986a0 Signed-off-by: Ayoung Sim --- .../platform/exynos/mfc/s5p_mfc_data_struct.h | 1 + .../platform/exynos/mfc/s5p_mfc_enc_vb2_ops.c | 40 +++++++++---------- .../media/platform/exynos/mfc/s5p_mfc_mem.c | 31 ++++++++++---- .../media/platform/exynos/mfc/s5p_mfc_queue.c | 1 + 4 files changed, 44 insertions(+), 29 deletions(-) diff --git a/drivers/media/platform/exynos/mfc/s5p_mfc_data_struct.h b/drivers/media/platform/exynos/mfc/s5p_mfc_data_struct.h index 73e599d6482c..bb736df3bd59 100644 --- a/drivers/media/platform/exynos/mfc/s5p_mfc_data_struct.h +++ b/drivers/media/platform/exynos/mfc/s5p_mfc_data_struct.h @@ -212,6 +212,7 @@ struct s5p_mfc_buf { int next_index; int done_index; int used; + int num_bufs_in_batch; int num_bufs_in_vb; unsigned char *vir_addr; }; 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 745e7ce7fdd0..63fd7f1ec97b 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 @@ -163,7 +163,7 @@ static int s5p_mfc_enc_buf_prepare(struct vb2_buffer *vb) 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[MFC_MAX_PLANES]; + struct dma_buf *bufcon_dmabuf[MFC_MAX_PLANES]; int i, mem_get_count = 0; size_t buf_size; @@ -206,46 +206,42 @@ static int s5p_mfc_enc_buf_prepare(struct vb2_buffer *vb) } for (i = 0; i < ctx->src_fmt->mem_planes; i++) { - dmabuf[i] = dma_buf_get(vb->planes[i].m.fd); - if (IS_ERR(dmabuf[i])) { + bufcon_dmabuf[i] = dma_buf_get(vb->planes[i].m.fd); + if (IS_ERR(bufcon_dmabuf[i])) { mfc_err_ctx("failed to get bufcon dmabuf\n"); goto err_mem_put; } mem_get_count++; - buf->num_bufs_in_vb = s5p_mfc_bufcon_get_buf_count(dmabuf[i]); - mfc_debug(3, "bufcon count:%d\n", buf->num_bufs_in_vb); - if (buf->num_bufs_in_vb == 0) { + buf->num_bufs_in_batch = s5p_mfc_bufcon_get_buf_count(bufcon_dmabuf[i]); + mfc_debug(3, "bufcon count:%d\n", buf->num_bufs_in_batch); + if (buf->num_bufs_in_batch == 0) { mfc_err_ctx("bufcon count couldn't be zero\n"); goto err_mem_put; } - if (buf->num_bufs_in_vb < 0) - buf->num_bufs_in_vb = 0; + if (buf->num_bufs_in_batch < 0) + buf->num_bufs_in_batch = 0; - if (!ctx->batch_mode && buf->num_bufs_in_vb > 0) { + if (!ctx->batch_mode && buf->num_bufs_in_batch > 0) { ctx->batch_mode = 1; - mfc_debug(3, "buffer batch mode enabled\n"); + mfc_debug(3, "buffer batch mode enable\n"); } - if (buf->num_bufs_in_vb > 0) { - int count = 0; + if (buf->num_bufs_in_batch > 0) { + if (s5p_mfc_bufcon_get_daddr(ctx, buf, bufcon_dmabuf[i], i)) { + mfc_err_ctx("failed to get daddr[%d] in buffer container\n", i); + goto err_mem_put; + } ctx->framerate = buf->num_bufs_in_vb * ENC_DEFAULT_CAM_CAPTURE_FPS; mfc_debug(3, "framerate: %ld\n", ctx->framerate); - count = s5p_mfc_bufcon_get_daddr(ctx, buf, dmabuf[i], i); - if (count != buf->num_bufs_in_vb) { - mfc_err_ctx("invalid buffer count %d != num_bufs_in_vb %d\n", - count, buf->num_bufs_in_vb); - goto err_mem_put; - } - - dma_buf_put(dmabuf[i]); + dma_buf_put(bufcon_dmabuf[i]); } else { dma_addr_t start_raw; - dma_buf_put(dmabuf[i]); + dma_buf_put(bufcon_dmabuf[i]); start_raw = s5p_mfc_mem_get_daddr_vb(vb, 0); if (start_raw == 0) { mfc_err_ctx("Plane mem not allocated\n"); @@ -282,7 +278,7 @@ static int s5p_mfc_enc_buf_prepare(struct vb2_buffer *vb) err_mem_put: for (i = 0; i < mem_get_count; i++) - dma_buf_put(dmabuf[i]); + dma_buf_put(bufcon_dmabuf[i]); return -ENOMEM; } diff --git a/drivers/media/platform/exynos/mfc/s5p_mfc_mem.c b/drivers/media/platform/exynos/mfc/s5p_mfc_mem.c index 21e3b6505200..96de70099e3c 100644 --- a/drivers/media/platform/exynos/mfc/s5p_mfc_mem.c +++ b/drivers/media/platform/exynos/mfc/s5p_mfc_mem.c @@ -217,10 +217,23 @@ int s5p_mfc_bufcon_get_daddr(struct s5p_mfc_ctx *ctx, struct s5p_mfc_buf *mfc_bu { struct s5p_mfc_dev *dev = ctx->dev; struct s5p_mfc_raw_info *raw = &ctx->raw_buf; - int i; + int i, j = 0; + u32 mask; + + if (dmabuf_container_get_mask(bufcon_dmabuf, &mask)) { + mfc_err_ctx("it is not buffer container\n"); + return -1; + } else { + mfc_debug(3, "bufcon mask info %#x\n", mask); + } - for (i = 0; i < mfc_buf->num_bufs_in_vb; i++) { - mfc_buf->dmabufs[i][plane] = dmabuf_container_get_buffer(bufcon_dmabuf, i); + for (i = 0; i < mfc_buf->num_bufs_in_batch; i++) { + if ((mask & (1 << i)) == 0) { + mfc_debug(3, "unmasked buf[%d]\n", i); + continue; + } + + mfc_buf->dmabufs[j][plane] = dmabuf_container_get_buffer(bufcon_dmabuf, i); if (IS_ERR(mfc_buf->dmabufs[i][plane])) { mfc_err_ctx("Failed to get dma_buf (err %ld)", PTR_ERR(mfc_buf->dmabufs[i][plane])); @@ -228,7 +241,7 @@ int s5p_mfc_bufcon_get_daddr(struct s5p_mfc_ctx *ctx, struct s5p_mfc_buf *mfc_bu goto err_get_daddr; } - mfc_buf->attachments[i][plane] = dma_buf_attach(mfc_buf->dmabufs[i][plane], dev->device); + mfc_buf->attachments[j][plane] = dma_buf_attach(mfc_buf->dmabufs[i][plane], dev->device); if (IS_ERR(mfc_buf->attachments[i][plane])) { mfc_err_ctx("Failed to get dma_buf_attach (err %ld)", PTR_ERR(mfc_buf->attachments[i][plane])); @@ -236,7 +249,7 @@ int s5p_mfc_bufcon_get_daddr(struct s5p_mfc_ctx *ctx, struct s5p_mfc_buf *mfc_bu goto err_get_daddr; } - mfc_buf->addr[i][plane] = ion_iovmm_map(mfc_buf->attachments[i][plane], 0, + mfc_buf->addr[j][plane] = ion_iovmm_map(mfc_buf->attachments[i][plane], 0, raw->plane_size[plane], DMA_BIDIRECTIONAL, 0); if (IS_ERR_VALUE(mfc_buf->addr[i][plane])) { mfc_err_ctx("Failed to allocate iova (err %pa)", @@ -246,10 +259,14 @@ int s5p_mfc_bufcon_get_daddr(struct s5p_mfc_ctx *ctx, struct s5p_mfc_buf *mfc_bu } mfc_debug(4, "get batch buf addr[%d][%d]: 0x%08llx, size: %d\n", - i, plane, mfc_buf->addr[i][plane], raw->plane_size[plane]); + j, plane, mfc_buf->addr[j][plane], raw->plane_size[plane]); + j++; } - return i; + mfc_buf->num_bufs_in_vb = j; + mfc_debug(3, "batch buffer has %d buffers\n", mfc_buf->num_bufs_in_vb); + + return 0; err_get_daddr: s5p_mfc_bufcon_put_daddr(ctx, mfc_buf, plane); diff --git a/drivers/media/platform/exynos/mfc/s5p_mfc_queue.c b/drivers/media/platform/exynos/mfc/s5p_mfc_queue.c index 5c0dbbb9ba40..a4e4fda08e4a 100644 --- a/drivers/media/platform/exynos/mfc/s5p_mfc_queue.c +++ b/drivers/media/platform/exynos/mfc/s5p_mfc_queue.c @@ -576,6 +576,7 @@ static void mfc_cleanup_batch_queue(struct s5p_mfc_ctx *ctx, struct s5p_mfc_buf_ INIT_LIST_HEAD(&queue->head); queue->count = 0; + ctx->batch_mode = 0; spin_unlock_irqrestore(&ctx->buf_queue_lock, flags); } -- 2.20.1