From 9508cdec7ebe42575d8b9dcda09176fced35d24a Mon Sep 17 00:00:00 2001 From: Cho KyongHo Date: Mon, 12 Feb 2018 15:07:45 +0900 Subject: [PATCH] media: mfc: fix use of ION API for 4.14 kernel ION is dramatically changed in 4.14 kernel including kernel API and the header files. But the symantics of ION API is not changed. Change-Id: I75d56fa81c62d37b41aa7c973c42a4aa3a5895ff Signed-off-by: Cho KyongHo Signed-off-by: Jeonghee Kim --- drivers/media/platform/exynos/mfc/s5p_mfc.c | 21 +-- .../media/platform/exynos/mfc/s5p_mfc_buf.c | 74 ++------ .../media/platform/exynos/mfc/s5p_mfc_cmd.c | 2 +- .../platform/exynos/mfc/s5p_mfc_common.h | 2 +- .../media/platform/exynos/mfc/s5p_mfc_ctrl.c | 2 +- .../platform/exynos/mfc/s5p_mfc_data_struct.h | 6 +- .../media/platform/exynos/mfc/s5p_mfc_dec.c | 10 +- .../platform/exynos/mfc/s5p_mfc_dec_vb2_ops.c | 8 +- .../media/platform/exynos/mfc/s5p_mfc_enc.c | 19 +-- .../platform/exynos/mfc/s5p_mfc_enc_vb2_ops.c | 4 +- .../platform/exynos/mfc/s5p_mfc_hwlock.c | 2 +- .../media/platform/exynos/mfc/s5p_mfc_mem.c | 158 +++++++++--------- .../media/platform/exynos/mfc/s5p_mfc_mem.h | 6 +- .../media/platform/exynos/mfc/s5p_mfc_nal_q.c | 20 +-- .../media/platform/exynos/mfc/s5p_mfc_otf.c | 4 +- .../media/platform/exynos/mfc/s5p_mfc_queue.c | 18 +- .../media/platform/exynos/mfc/s5p_mfc_reg.c | 10 +- .../platform/exynos/mfc/s5p_mfc_watchdog.c | 2 +- 18 files changed, 136 insertions(+), 232 deletions(-) diff --git a/drivers/media/platform/exynos/mfc/s5p_mfc.c b/drivers/media/platform/exynos/mfc/s5p_mfc.c index df7209812e13..95c324807bac 100644 --- a/drivers/media/platform/exynos/mfc/s5p_mfc.c +++ b/drivers/media/platform/exynos/mfc/s5p_mfc.c @@ -562,7 +562,7 @@ static int s5p_mfc_open(struct file *file) } trace_mfc_node_open(ctx->num, dev->num_inst, ctx->type, ctx->is_drm); - mfc_info_ctx("MFC open completed [%d:%d] dev = %p, ctx = %p, version = %d\n", + mfc_info_ctx("MFC open completed [%d:%d] dev = 0x%p, ctx = 0x%p, version = %d\n", dev->num_drm_inst, dev->num_inst, dev, ctx, MFC_DRIVER_INFO); mutex_unlock(&dev->mfc_mutex); return ret; @@ -758,7 +758,7 @@ static int s5p_mfc_release(struct file *file) dev->ctx[ctx->num] = 0; kfree(ctx); - mfc_info_dev("mfc driver release finished [%d:%d], dev = %p\n", + mfc_info_dev("mfc driver release finished [%d:%d], dev = 0x%p\n", dev->num_drm_inst, dev->num_inst, dev); if (s5p_mfc_is_work_to_do(dev)) @@ -1082,6 +1082,8 @@ static int s5p_mfc_probe(struct platform_device *pdev) dev->mfc_trace = g_mfc_trace; dev->mfc_trace_hwlock = g_mfc_trace_hwlock; + dma_set_mask(&pdev->dev, DMA_BIT_MASK(36)); + s5p_mfc_pm_init(dev); ret = mfc_register_resource(pdev, dev); if (ret) @@ -1177,14 +1179,6 @@ static int s5p_mfc_probe(struct platform_device *pdev) } INIT_WORK(&dev->butler_work, s5p_mfc_butler_worker); -#ifdef CONFIG_ION_EXYNOS - dev->mfc_ion_client = exynos_ion_client_create("mfc"); - if (IS_ERR(dev->mfc_ion_client)) { - dev_err(&pdev->dev, "failed to ion_client_create\n"); - goto err_ion_client; - } -#endif - #ifdef CONFIG_MFC_USE_BUS_DEVFREQ atomic_set(&dev->qos_req_cur, 0); @@ -1223,10 +1217,6 @@ static int s5p_mfc_probe(struct platform_device *pdev) err_alloc_debug: iovmm_deactivate(&pdev->dev); err_iovmm_active: -#ifdef CONFIG_ION_EXYNOS - ion_client_destroy(dev->mfc_ion_client); -err_ion_client: -#endif destroy_workqueue(dev->butler_wq); err_butler_wq: destroy_workqueue(dev->watchdog_wq); @@ -1282,9 +1272,6 @@ static int s5p_mfc_remove(struct platform_device *pdev) remove_proc_entry(MFC_PROC_ROOT, NULL); #endif s5p_mfc_destroy_listable_wq_dev(dev); -#ifdef CONFIG_ION_EXYNOS - ion_client_destroy(dev->mfc_ion_client); -#endif iovmm_deactivate(&pdev->dev); mfc_debug(2, "Will now deinit HW\n"); s5p_mfc_deinit_hw(dev); diff --git a/drivers/media/platform/exynos/mfc/s5p_mfc_buf.c b/drivers/media/platform/exynos/mfc/s5p_mfc_buf.c index e02581d0a5dc..75de9c69edb8 100644 --- a/drivers/media/platform/exynos/mfc/s5p_mfc_buf.c +++ b/drivers/media/platform/exynos/mfc/s5p_mfc_buf.c @@ -43,7 +43,7 @@ static int mfc_alloc_common_context(struct s5p_mfc_dev *dev, firmware_size = dev->variant->buf_size->firmware_code; - ctx_buf->handle = NULL; + ctx_buf->dma_buf = NULL; ctx_buf->vaddr = NULL; ctx_buf->daddr = fw_daddr + firmware_size; @@ -88,7 +88,7 @@ static void mfc_release_common_context(struct s5p_mfc_dev *dev, ctx_buf = &dev->drm_common_ctx_buf; #endif - ctx_buf->handle = NULL; + ctx_buf->dma_buf = NULL; ctx_buf->vaddr = NULL; ctx_buf->daddr = 0; } @@ -170,14 +170,6 @@ int s5p_mfc_alloc_instance_context(struct s5p_mfc_ctx *ctx) return -ENOMEM; } - ctx->instance_ctx_buf.vaddr = s5p_mfc_mem_get_vaddr(dev, &ctx->instance_ctx_buf); - - if (!ctx->instance_ctx_buf.vaddr) { - mfc_err_dev("failed to get instance ctx buffer vaddr\n"); - s5p_mfc_mem_ion_free(dev, &ctx->instance_ctx_buf); - return -ENOMEM; - } - mfc_debug(2, "Instance buf alloc, ctx: %d, size: %ld, addr: 0x%08llx\n", ctx->num, ctx->instance_ctx_buf.size, ctx->instance_ctx_buf.daddr); @@ -421,13 +413,6 @@ int s5p_mfc_alloc_codec_buffers(struct s5p_mfc_ctx *ctx) mfc_err_ctx("Allocating codec buffer failed\n"); return -ENOMEM; } - - ctx->codec_buf.vaddr = s5p_mfc_mem_get_vaddr(dev, &ctx->codec_buf); - if (!ctx->codec_buf.vaddr) { - mfc_err_dev("failed to get codec buffer vaddr\n"); - s5p_mfc_mem_ion_free(dev, &ctx->codec_buf); - return -ENOMEM; - } ctx->codec_buffer_allocated = 1; } else if (ctx->codec_mode == S5P_FIMV_CODEC_MPEG2_DEC) { ctx->codec_buffer_allocated = 1; @@ -472,17 +457,8 @@ int s5p_mfc_alloc_dbg_info_buffer(struct s5p_mfc_dev *dev) mfc_err_dev("Allocating debug info buffer failed\n"); return -ENOMEM; } - mfc_debug(2, "dev->dbg_info_buf.daddr = 0x%08llx\n", - dev->dbg_info_buf.daddr); - - dev->dbg_info_buf.vaddr = s5p_mfc_mem_get_vaddr(dev, &dev->dbg_info_buf); - if (!dev->dbg_info_buf.vaddr) { - mfc_err_dev("failed to get debug info buffer vaddr\n"); - s5p_mfc_mem_ion_free(dev, &dev->dbg_info_buf); - return -ENOMEM; - } - mfc_debug(2, "dev->dbg_info_buf.vaddr = 0x%p\n", - dev->dbg_info_buf.vaddr); + mfc_debug(2, "dev->dbg_info_buf.daddr = 0x%08llx, vaddr = 0x%p\n", + dev->dbg_info_buf.daddr, dev->dbg_info_buf.vaddr); return 0; } @@ -495,7 +471,7 @@ int s5p_mfc_release_dbg_info_buffer(struct s5p_mfc_dev *dev) return -EINVAL; } - if (!dev->dbg_info_buf.handle) { + if (!dev->dbg_info_buf.dma_buf) { mfc_debug(2, "debug info buffer is already freed\n"); return 0; } @@ -518,14 +494,8 @@ static int mfc_alloc_enc_roi_buffer(struct s5p_mfc_ctx *ctx, struct s5p_mfc_spec mfc_err_ctx("Allocating ROI buffer failed\n"); return -ENOMEM; } - mfc_debug(2, "roi_buf.daddr = 0x%08llx\n", roi_buf->daddr); - - roi_buf->vaddr = s5p_mfc_mem_get_vaddr(dev, roi_buf); - if (!roi_buf->vaddr) { - mfc_err_dev("failed to get ROI buffer vaddr\n"); - s5p_mfc_mem_ion_free(dev, roi_buf); - return -ENOMEM; - } + mfc_debug(2, "roi_buf.daddr = 0x%08llx, vaddr = 0x%p\n", + roi_buf->daddr, roi_buf->vaddr); memset(roi_buf->vaddr, 0, buf_size->shared_buf); @@ -555,7 +525,7 @@ void s5p_mfc_release_enc_roi_buffer(struct s5p_mfc_ctx *ctx) int i; for (i = 0; i < MFC_MAX_EXTRA_BUF; i++) - if (enc->roi_buf[i].handle) + if (enc->roi_buf[i].dma_buf) s5p_mfc_mem_ion_free(ctx->dev, &enc->roi_buf[i]); } @@ -578,12 +548,6 @@ int s5p_mfc_otf_alloc_stream_buf(struct s5p_mfc_ctx *ctx) mfc_err_ctx("OTF: Allocating stream buffer failed\n"); return -EINVAL; } - buf->vaddr = s5p_mfc_mem_get_vaddr(dev, buf); - if (!buf->vaddr) { - mfc_err_dev("OTF: failed to get stream buffer vaddr\n"); - s5p_mfc_mem_ion_free(dev, buf); - return -EINVAL; - } memset(buf->vaddr, 0, raw->total_plane_size); } @@ -604,7 +568,7 @@ void s5p_mfc_otf_release_stream_buf(struct s5p_mfc_ctx *ctx) for (i = 0; i < OTF_MAX_BUF; i++) { buf = &debug->stream_buf[i]; - if (buf->handle) + if (buf->dma_buf) s5p_mfc_mem_ion_free(dev, buf); } @@ -630,7 +594,7 @@ int s5p_mfc_alloc_firmware(struct s5p_mfc_dev *dev) firmware_size = dev->variant->buf_size->firmware_code; dev->fw.size = firmware_size + buf_size->dev_ctx; - if (dev->fw_buf.handle) + if (dev->fw_buf.dma_buf) return 0; mfc_debug(2, "Allocating memory for firmware.\n"); @@ -643,12 +607,6 @@ int s5p_mfc_alloc_firmware(struct s5p_mfc_dev *dev) return -ENOMEM; } - dev->fw_buf.vaddr = s5p_mfc_mem_get_vaddr(dev, &dev->fw_buf); - if (!dev->fw_buf.vaddr) { - mfc_err_dev("failed to get normal firmware buffer vaddr\n"); - s5p_mfc_mem_ion_free(dev, &dev->fw_buf); - return -EIO; - } mfc_debug(2, "FW normal: 0x%08llx (vaddr: 0x%p), size: %08zu\n", dev->fw_buf.daddr, dev->fw_buf.vaddr, dev->fw_buf.size); @@ -661,14 +619,6 @@ int s5p_mfc_alloc_firmware(struct s5p_mfc_dev *dev) return -ENOMEM; } - dev->drm_fw_buf.vaddr = s5p_mfc_mem_get_vaddr(dev, &dev->drm_fw_buf); - if (!dev->drm_fw_buf.vaddr) { - mfc_err_dev("failed to get DRM firmware buffer vaddr\n"); - s5p_mfc_mem_ion_free(dev, &dev->fw_buf); - s5p_mfc_mem_ion_free(dev, &dev->drm_fw_buf); - return -EIO; - } - mfc_debug(2, "FW DRM: 0x%08llx (vaddr: 0x%p), size: %08zu\n", dev->drm_fw_buf.daddr, dev->drm_fw_buf.vaddr, dev->drm_fw_buf.size); @@ -713,7 +663,7 @@ int s5p_mfc_load_firmware(struct s5p_mfc_dev *dev) return -ENOMEM; } - if (dev->fw_buf.handle == NULL || dev->fw_buf.daddr == 0) { + if (dev->fw_buf.dma_buf == NULL || dev->fw_buf.daddr == 0) { mfc_err_dev("MFC firmware is not allocated or was not mapped correctly.\n"); release_firmware(fw_blob); return -EINVAL; @@ -740,7 +690,7 @@ int s5p_mfc_release_firmware(struct s5p_mfc_dev *dev) return -EINVAL; } - if (!dev->fw_buf.handle) { + if (!dev->fw_buf.dma_buf) { mfc_err_dev("firmware memory is already freed\n"); return -EINVAL; } diff --git a/drivers/media/platform/exynos/mfc/s5p_mfc_cmd.c b/drivers/media/platform/exynos/mfc/s5p_mfc_cmd.c index ca817376e8aa..1131d35bfc26 100644 --- a/drivers/media/platform/exynos/mfc/s5p_mfc_cmd.c +++ b/drivers/media/platform/exynos/mfc/s5p_mfc_cmd.c @@ -258,7 +258,7 @@ int s5p_mfc_cmd_enc_init_buffers(struct s5p_mfc_ctx *ctx) /* Header was generated now starting processing * First set the reference frame buffers */ - if (!ctx->codec_buf.handle) { + if (!ctx->codec_buf.dma_buf) { mfc_info_ctx("there isn't codec buffer, re-alloc!\n"); ret = s5p_mfc_alloc_codec_buffers(ctx); if (ret) { diff --git a/drivers/media/platform/exynos/mfc/s5p_mfc_common.h b/drivers/media/platform/exynos/mfc/s5p_mfc_common.h index 063e26f4f060..00b8fd150492 100644 --- a/drivers/media/platform/exynos/mfc/s5p_mfc_common.h +++ b/drivers/media/platform/exynos/mfc/s5p_mfc_common.h @@ -17,7 +17,7 @@ #include #include #include -#include +#include #include #include diff --git a/drivers/media/platform/exynos/mfc/s5p_mfc_ctrl.c b/drivers/media/platform/exynos/mfc/s5p_mfc_ctrl.c index a5c4ac87307f..ee15f5e2fa88 100644 --- a/drivers/media/platform/exynos/mfc/s5p_mfc_ctrl.c +++ b/drivers/media/platform/exynos/mfc/s5p_mfc_ctrl.c @@ -40,7 +40,7 @@ static int mfc_init_hw(struct s5p_mfc_dev *dev, enum mfc_buf_usage_type buf_type curr_ctx_is_drm_backup = dev->curr_ctx_is_drm; - if (!dev->fw_buf.handle) + if (!dev->fw_buf.dma_buf) return -EINVAL; /* 0. MFC reset */ 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 c6a6c0041cb9..55a68a4ca4be 100644 --- a/drivers/media/platform/exynos/mfc/s5p_mfc_data_struct.h +++ b/drivers/media/platform/exynos/mfc/s5p_mfc_data_struct.h @@ -322,7 +322,6 @@ struct s5p_mfc_debugfs { */ struct s5p_mfc_special_buf { enum mfc_buf_usage_type buftype; - struct ion_handle *handle; struct dma_buf *dma_buf; struct dma_buf_attachment *attachment; struct sg_table *sgt; @@ -639,9 +638,6 @@ struct s5p_mfc_dev { struct video_device *vfd_enc_otf; struct video_device *vfd_enc_otf_drm; struct device *device; -#ifdef CONFIG_ION_EXYNOS - struct ion_client *mfc_ion_client; -#endif void __iomem *regs_base; void __iomem *sysmmu0_base; @@ -1086,7 +1082,7 @@ struct mfc_enc_roi_info { struct mfc_user_shared_handle { int fd; - struct ion_handle *ion_handle; + struct dma_buf *dma_buf; void *vaddr; }; diff --git a/drivers/media/platform/exynos/mfc/s5p_mfc_dec.c b/drivers/media/platform/exynos/mfc/s5p_mfc_dec.c index 1fb877cd8f06..fe035867795f 100644 --- a/drivers/media/platform/exynos/mfc/s5p_mfc_dec.c +++ b/drivers/media/platform/exynos/mfc/s5p_mfc_dec.c @@ -739,7 +739,7 @@ static int vidioc_dqbuf(struct file *file, void *priv, struct v4l2_buffer *buf) int ncount = 0; mfc_debug_enter(); - mfc_debug(2, "Addr: %p %p %p Type: %d\n", &ctx->vq_src, buf, buf->m.planes, + mfc_debug(2, "Addr: 0x%p 0x%p 0x%p Type: %d\n", &ctx->vq_src, buf, buf->m.planes, buf->type); if (ctx->state == MFCINST_ERROR) { mfc_err_ctx("Call on DQBUF after unrecoverable error.\n"); @@ -1086,10 +1086,10 @@ static int vidioc_s_ctrl(struct file *file, void *priv, mfc_err_dev("is_dynamic_dpb is 0. it has to be enabled.\n"); break; case V4L2_CID_MPEG_MFC_SET_USER_SHARED_HANDLE: - dec->sh_handle.fd = ctrl->value; - if (s5p_mfc_mem_get_user_shared_handle(ctx, &dec->sh_handle)) { - dec->sh_handle.fd = -1; - return -EINVAL; + if (dec->sh_handle.fd == -1) { + dec->sh_handle.fd = ctrl->value; + if (s5p_mfc_mem_get_user_shared_handle(ctx, &dec->sh_handle)) + return -EINVAL; } break; case V4L2_CID_MPEG_MFC_SET_BUF_PROCESS_TYPE: diff --git a/drivers/media/platform/exynos/mfc/s5p_mfc_dec_vb2_ops.c b/drivers/media/platform/exynos/mfc/s5p_mfc_dec_vb2_ops.c index b545fdeef2be..a965d2e0ab8f 100644 --- a/drivers/media/platform/exynos/mfc/s5p_mfc_dec_vb2_ops.c +++ b/drivers/media/platform/exynos/mfc/s5p_mfc_dec_vb2_ops.c @@ -577,8 +577,8 @@ static void s5p_mfc_dec_buf_queue(struct vb2_buffer *vb) } if (vq->type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE) { - mfc_debug(2, "Src queue: %p\n", &ctx->src_buf_queue); - mfc_debug(2, "Adding to src: %p (0x%08llx, 0x%08llx)\n", vb, + mfc_debug(2, "Src queue: 0x%p\n", &ctx->src_buf_queue); + mfc_debug(2, "Adding to src: 0x%p (0x%08llx, 0x%08llx)\n", vb, s5p_mfc_mem_get_daddr_vb(vb, 0), buf->addr[0]); if (dec->dst_memtype == V4L2_MEMORY_DMABUF && @@ -593,8 +593,8 @@ static void s5p_mfc_dec_buf_queue(struct vb2_buffer *vb) vb->index, vb->planes[0].m.fd, buf->addr[0]); } else if (vq->type == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE) { index = vb->index; - mfc_debug(2, "Dst queue: %p\n", &ctx->dst_buf_queue); - mfc_debug(2, "Adding to dst: %p (0x%08llx)\n", vb, + mfc_debug(2, "Dst queue: 0x%p\n", &ctx->dst_buf_queue); + mfc_debug(2, "Adding to dst: 0x%p (0x%08llx)\n", vb, s5p_mfc_mem_get_daddr_vb(vb, 0)); for (i = 0; i < ctx->dst_fmt->num_planes; i++) mfc_debug(2, "dec dst plane[%d]: %08llx\n", diff --git a/drivers/media/platform/exynos/mfc/s5p_mfc_enc.c b/drivers/media/platform/exynos/mfc/s5p_mfc_enc.c index c1728c2bbc58..9d24dae74e4a 100644 --- a/drivers/media/platform/exynos/mfc/s5p_mfc_enc.c +++ b/drivers/media/platform/exynos/mfc/s5p_mfc_enc.c @@ -645,7 +645,7 @@ static int vidioc_dqbuf(struct file *file, void *priv, struct v4l2_buffer *buf) return 0; } - mfc_debug(2, "Addr: %p %p %p Type: %d\n", &ctx->vq_src, buf, buf->m.planes, + mfc_debug(2, "Addr: 0x%p 0x%p 0x%p Type: %d\n", &ctx->vq_src, buf, buf->m.planes, buf->type); if (ctx->state == MFCINST_ERROR) { mfc_err_ctx("Call on DQBUF after unrecoverable error.\n"); @@ -1675,10 +1675,8 @@ static int mfc_enc_set_ctrl_val(struct s5p_mfc_ctx *ctx, struct v4l2_control *ct (enc->sh_handle_svc.fd == -1)) { enc->sh_handle_svc.fd = ctrl->value; if (s5p_mfc_mem_get_user_shared_handle(ctx, - &enc->sh_handle_svc)) { - enc->sh_handle_svc.fd = -1; + &enc->sh_handle_svc)) return -EINVAL; - } } if (ctx_ctrl->id == V4L2_CID_MPEG_MFC51_VIDEO_I_PERIOD_CH && p->i_frm_ctrl_mode) { @@ -1693,13 +1691,12 @@ static int mfc_enc_set_ctrl_val(struct s5p_mfc_ctx *ctx, struct v4l2_control *ct ctx_ctrl->val = mfc_enc_h264_level((enum v4l2_mpeg_video_h264_level)(ctrl->value)); if (ctx_ctrl->id == V4L2_CID_MPEG_VIDEO_H264_PROFILE) ctx_ctrl->val = mfc_enc_h264_profile(ctx, (enum v4l2_mpeg_video_h264_profile)(ctrl->value)); - if (ctx_ctrl->id == \ - V4L2_CID_MPEG_VIDEO_ROI_CONTROL) { - enc->sh_handle_roi.fd = ctrl->value; - if (s5p_mfc_mem_get_user_shared_handle(ctx, - &enc->sh_handle_roi)) { - enc->sh_handle_roi.fd = -1; - return -EINVAL; + if (ctx_ctrl->id == V4L2_CID_MPEG_VIDEO_ROI_CONTROL) { + if (enc->sh_handle_roi.fd == -1) { + enc->sh_handle_roi.fd = ctrl->value; + if (s5p_mfc_mem_get_user_shared_handle(ctx, + &enc->sh_handle_roi)) + return -EINVAL; } index = enc->roi_index; memcpy(&enc->roi_info[index], 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 0a87654fd8c6..cc2b04c1d079 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 @@ -372,8 +372,8 @@ static void s5p_mfc_enc_buf_queue(struct vb2_buffer *vb) mfc_debug_enter(); if (vq->type == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE) { - mfc_debug(2, "dst queue: %p\n", &ctx->dst_buf_queue); - mfc_debug(2, "Adding to dst vb: %p, addr: %08llx\n", vb, buf->addr[0]); + mfc_debug(2, "dst queue: 0x%p\n", &ctx->dst_buf_queue); + mfc_debug(2, "Adding to dst vb: 0x%p, addr: %08llx\n", vb, buf->addr[0]); /* Mark destination as available for use by MFC */ s5p_mfc_add_tail_buf(&ctx->buf_queue_lock, &ctx->dst_buf_queue, buf); diff --git a/drivers/media/platform/exynos/mfc/s5p_mfc_hwlock.c b/drivers/media/platform/exynos/mfc/s5p_mfc_hwlock.c index 0cedccccb03a..b31c2966cc77 100644 --- a/drivers/media/platform/exynos/mfc/s5p_mfc_hwlock.c +++ b/drivers/media/platform/exynos/mfc/s5p_mfc_hwlock.c @@ -564,7 +564,7 @@ void s5p_mfc_try_run(struct s5p_mfc_dev *dev) mfc_err_dev("no mfc device to run\n"); return; } - mfc_debug(2, "Try run dev: %p\n", dev); + mfc_debug(2, "Try run dev: 0x%p\n", dev); spin_lock_irqsave(&dev->hwlock.lock, flags); mfc_print_hwlock(dev); diff --git a/drivers/media/platform/exynos/mfc/s5p_mfc_mem.c b/drivers/media/platform/exynos/mfc/s5p_mfc_mem.c index 4e36bd09d165..f23ef7fe1f0c 100644 --- a/drivers/media/platform/exynos/mfc/s5p_mfc_mem.c +++ b/drivers/media/platform/exynos/mfc/s5p_mfc_mem.c @@ -36,19 +36,16 @@ void s5p_mfc_mem_invalidate(struct s5p_mfc_dev *dev, int s5p_mfc_mem_get_user_shared_handle(struct s5p_mfc_ctx *ctx, struct mfc_user_shared_handle *handle) { - struct s5p_mfc_dev *dev = ctx->dev; int ret = 0; - handle->ion_handle = - ion_import_dma_buf_fd(dev->mfc_ion_client, handle->fd); - if (IS_ERR(handle->ion_handle)) { + handle->dma_buf = dma_buf_get(handle->fd); + if (IS_ERR(handle->dma_buf)) { mfc_err_ctx("Failed to import fd\n"); - ret = PTR_ERR(handle->ion_handle); + ret = PTR_ERR(handle->dma_buf); goto import_dma_fail; } - handle->vaddr = - ion_map_kernel(dev->mfc_ion_client, handle->ion_handle); + handle->vaddr = dma_buf_vmap(handle->dma_buf); if (handle->vaddr == NULL) { mfc_err_ctx("Failed to get kernel virtual address\n"); ret = -EINVAL; @@ -61,138 +58,133 @@ int s5p_mfc_mem_get_user_shared_handle(struct s5p_mfc_ctx *ctx, return 0; map_kernel_fail: - ion_free(dev->mfc_ion_client, handle->ion_handle); + handle->vaddr = NULL; + dma_buf_put(handle->dma_buf); import_dma_fail: + handle->dma_buf = NULL; + handle->fd = -1; return ret; } -int s5p_mfc_mem_cleanup_user_shared_handle(struct s5p_mfc_ctx *ctx, +void s5p_mfc_mem_cleanup_user_shared_handle(struct s5p_mfc_ctx *ctx, struct mfc_user_shared_handle *handle) { - struct s5p_mfc_dev *dev = ctx->dev; - - if (handle->fd == -1) - return 0; - if (handle->vaddr) - ion_unmap_kernel(dev->mfc_ion_client, - handle->ion_handle); - - ion_free(dev->mfc_ion_client, handle->ion_handle); - - return 0; -} + dma_buf_vunmap(handle->dma_buf, handle->vaddr); + if (handle->dma_buf) + dma_buf_put(handle->dma_buf); -void *s5p_mfc_mem_get_vaddr(struct s5p_mfc_dev *dev, - struct s5p_mfc_special_buf *special_buf) -{ - return ion_map_kernel(dev->mfc_ion_client, special_buf->handle); -} - -void s5p_mfc_mem_ion_free(struct s5p_mfc_dev *dev, - struct s5p_mfc_special_buf *special_buf) -{ - if (!special_buf->handle) - return; - - if (special_buf->daddr) - ion_iovmm_unmap(special_buf->attachment, special_buf->daddr); - - if (special_buf->handle) { - dma_buf_unmap_attachment(special_buf->attachment, - special_buf->sgt, DMA_BIDIRECTIONAL); - dma_buf_detach(special_buf->dma_buf, special_buf->attachment); - dma_buf_put(special_buf->dma_buf); - ion_free(dev->mfc_ion_client, special_buf->handle); - } - - memset(&special_buf->handle, 0, sizeof(struct ion_handle *)); - memset(&special_buf->daddr, 0, sizeof(special_buf->daddr)); - - special_buf->handle = NULL; - special_buf->dma_buf = NULL; - special_buf->attachment = NULL; - special_buf->sgt = NULL; - special_buf->daddr = 0; - special_buf->vaddr = NULL; + handle->dma_buf = NULL; + handle->vaddr = NULL; + handle->fd = -1; } int s5p_mfc_mem_ion_alloc(struct s5p_mfc_dev *dev, struct s5p_mfc_special_buf *special_buf) { struct s5p_mfc_ctx *ctx = dev->ctx[dev->curr_ctx]; - int ion_mask, flag; + int flag; + const char *heapname; switch (special_buf->buftype) { case MFCBUF_NORMAL: - ion_mask = EXYNOS_ION_HEAP_SYSTEM_MASK; + heapname = "ion_system_heap"; flag = 0; break; case MFCBUF_NORMAL_FW: - ion_mask = EXYNOS_ION_HEAP_VIDEO_NFW_MASK; + heapname = "vnfw_heap"; flag = 0; break; case MFCBUF_DRM: - ion_mask = EXYNOS_ION_HEAP_VIDEO_FRAME_MASK; + heapname = "vframe_heap"; flag = ION_FLAG_PROTECTED; break; case MFCBUF_DRM_FW: - ion_mask = EXYNOS_ION_HEAP_VIDEO_FW_MASK; + heapname = "vfw_heap"; flag = ION_FLAG_PROTECTED; break; default: - mfc_err_ctx("not supported mfc mem type: %d\n", - special_buf->buftype); + mfc_err_ctx("not supported mfc mem type: %d, heapname: %s\n", + special_buf->buftype, heapname); return -EINVAL; } - special_buf->handle = ion_alloc(dev->mfc_ion_client, - special_buf->size, 0, ion_mask, flag); - if (IS_ERR(special_buf->handle)) { - mfc_err_ctx("Failed to allocate buffer (err %ld)", - PTR_ERR(special_buf->handle)); - special_buf->handle = NULL; - goto err_ion_alloc; - } - - special_buf->dma_buf = ion_share_dma_buf(dev->mfc_ion_client, - special_buf->handle); + special_buf->dma_buf = + ion_alloc_dmabuf(heapname, special_buf->size, flag); if (IS_ERR(special_buf->dma_buf)) { - mfc_err_ctx("Failed to get dma_buf (err %ld)", + mfc_err_ctx("Failed to allocate buffer (err %ld)\n", PTR_ERR(special_buf->dma_buf)); - special_buf->dma_buf = NULL; goto err_ion_alloc; } special_buf->attachment = dma_buf_attach(special_buf->dma_buf, dev->device); if (IS_ERR(special_buf->attachment)) { - mfc_err_ctx("Failed to get dma_buf_attach (err %ld)", + mfc_err_ctx("Failed to get dma_buf_attach (err %ld)\n", PTR_ERR(special_buf->attachment)); - special_buf->attachment = NULL; - goto err_ion_alloc; + goto err_attach; } special_buf->sgt = dma_buf_map_attachment(special_buf->attachment, DMA_BIDIRECTIONAL); if (IS_ERR(special_buf->sgt)) { - mfc_err_ctx("Failed to get sgt (err %ld)", + mfc_err_ctx("Failed to get sgt (err %ld)\n", PTR_ERR(special_buf->sgt)); - special_buf->sgt = NULL; - goto err_ion_alloc; + goto err_map; } special_buf->daddr = ion_iovmm_map(special_buf->attachment, 0, special_buf->size, DMA_BIDIRECTIONAL, 0); if (IS_ERR_VALUE(special_buf->daddr)) { - mfc_err_ctx("Failed to allocate iova (err %pa)", + mfc_err_ctx("Failed to allocate iova (err 0x%p)\n", &special_buf->daddr); - special_buf->daddr = 0; - goto err_ion_alloc; + goto err_iovmm; + } + + special_buf->vaddr = dma_buf_vmap(special_buf->dma_buf); + if (IS_ERR(special_buf->vaddr)) { + mfc_err_ctx("Failed to get vaddr (err 0x%p)\n", + &special_buf->vaddr); + goto err_vaddr; } return 0; +err_vaddr: + special_buf->vaddr = NULL; + ion_iovmm_unmap(special_buf->attachment, special_buf->daddr); +err_iovmm: + special_buf->daddr = 0; + dma_buf_unmap_attachment(special_buf->attachment, special_buf->sgt, + DMA_BIDIRECTIONAL); +err_map: + special_buf->sgt = NULL; + dma_buf_detach(special_buf->dma_buf, special_buf->attachment); +err_attach: + special_buf->attachment = NULL; + dma_buf_put(special_buf->dma_buf); err_ion_alloc: - s5p_mfc_mem_ion_free(dev, special_buf); + special_buf->dma_buf = NULL; return -ENOMEM; } + +void s5p_mfc_mem_ion_free(struct s5p_mfc_dev *dev, + struct s5p_mfc_special_buf *special_buf) +{ + if (special_buf->vaddr) + dma_buf_vunmap(special_buf->dma_buf, special_buf->vaddr); + if (special_buf->daddr) + ion_iovmm_unmap(special_buf->attachment, special_buf->daddr); + if (special_buf->sgt) + dma_buf_unmap_attachment(special_buf->attachment, + special_buf->sgt, DMA_BIDIRECTIONAL); + if (special_buf->attachment) + dma_buf_detach(special_buf->dma_buf, special_buf->attachment); + if (special_buf->dma_buf) + dma_buf_put(special_buf->dma_buf); + + special_buf->dma_buf = NULL; + special_buf->attachment = NULL; + special_buf->sgt = NULL; + special_buf->daddr = 0; + special_buf->vaddr = NULL; +} diff --git a/drivers/media/platform/exynos/mfc/s5p_mfc_mem.h b/drivers/media/platform/exynos/mfc/s5p_mfc_mem.h index add0548296fb..51d274662043 100644 --- a/drivers/media/platform/exynos/mfc/s5p_mfc_mem.h +++ b/drivers/media/platform/exynos/mfc/s5p_mfc_mem.h @@ -42,14 +42,12 @@ void s5p_mfc_mem_invalidate(struct s5p_mfc_dev *dev, int s5p_mfc_mem_get_user_shared_handle(struct s5p_mfc_ctx *ctx, struct mfc_user_shared_handle *handle); -int s5p_mfc_mem_cleanup_user_shared_handle(struct s5p_mfc_ctx *ctx, +void s5p_mfc_mem_cleanup_user_shared_handle(struct s5p_mfc_ctx *ctx, struct mfc_user_shared_handle *handle); -void *s5p_mfc_mem_get_vaddr(struct s5p_mfc_dev *dev, +int s5p_mfc_mem_ion_alloc(struct s5p_mfc_dev *dev, struct s5p_mfc_special_buf *special_buf); void s5p_mfc_mem_ion_free(struct s5p_mfc_dev *dev, struct s5p_mfc_special_buf *special_buf); -int s5p_mfc_mem_ion_alloc(struct s5p_mfc_dev *dev, - struct s5p_mfc_special_buf *special_buf); #endif /* __S5P_MFC_MEM_H */ 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 9cb790bca93b..eab303f8551e 100644 --- a/drivers/media/platform/exynos/mfc/s5p_mfc_nal_q.c +++ b/drivers/media/platform/exynos/mfc/s5p_mfc_nal_q.c @@ -169,15 +169,7 @@ static nal_queue_in_handle* mfc_nal_q_create_in_q(struct s5p_mfc_dev *dev, kfree(nal_q_in_handle); return NULL; } - - nal_q_in_handle->nal_q_in_addr - = (nal_in_queue *)s5p_mfc_mem_get_vaddr(dev, &nal_q_in_handle->in_buf); - if (!nal_q_in_handle->nal_q_in_addr) { - mfc_err_dev("NAL Q: failed to get vaddr\n"); - s5p_mfc_mem_ion_free(dev, &nal_q_in_handle->in_buf); - kfree(nal_q_in_handle); - return NULL; - } + nal_q_in_handle->nal_q_in_addr = (nal_in_queue *)nal_q_in_handle->in_buf.vaddr; mfc_debug_leave(); @@ -210,15 +202,7 @@ static nal_queue_out_handle* mfc_nal_q_create_out_q(struct s5p_mfc_dev *dev, kfree(nal_q_out_handle); return NULL; } - - nal_q_out_handle->nal_q_out_addr - = (nal_out_queue *)s5p_mfc_mem_get_vaddr(dev, &nal_q_out_handle->out_buf); - if (!nal_q_out_handle->nal_q_out_addr) { - mfc_err_dev("NAL Q : failed to get vaddr\n"); - s5p_mfc_mem_ion_free(dev, &nal_q_out_handle->out_buf); - kfree(nal_q_out_handle); - return NULL; - } + nal_q_out_handle->nal_q_out_addr = (nal_out_queue *)nal_q_out_handle->out_buf.vaddr; mfc_debug_leave(); diff --git a/drivers/media/platform/exynos/mfc/s5p_mfc_otf.c b/drivers/media/platform/exynos/mfc/s5p_mfc_otf.c index 1660122a0868..23096d98c005 100644 --- a/drivers/media/platform/exynos/mfc/s5p_mfc_otf.c +++ b/drivers/media/platform/exynos/mfc/s5p_mfc_otf.c @@ -93,7 +93,7 @@ static int mfc_otf_map_buf(struct s5p_mfc_ctx *ctx) mfc_debug(2, "OTF: buffer count: %d\n", buf_info->buffer_count); /* map buffers */ for (i = 0; i < buf_info->buffer_count; i++) { - mfc_debug(2, "OTF: dma_buf: %p\n", buf_info->bufs[i]); + mfc_debug(2, "OTF: dma_buf: 0x%p\n", buf_info->bufs[i]); buf_addr->otf_buf_attach[i] = dma_buf_attach(buf_info->bufs[i], dev->device); if (IS_ERR(buf_addr->otf_buf_attach[i])) { mfc_err_ctx("OTF: Failed to get attachment (err %ld)", @@ -389,7 +389,7 @@ int s5p_mfc_otf_run_enc_frame(struct s5p_mfc_ctx *ctx) raw = &ctx->raw_buf; if (!handle) { - mfc_err_ctx("OTF: There is no otf_handle, handle: %p\n", handle); + mfc_err_ctx("OTF: There is no otf_handle, handle: 0x%p\n", handle); return -EINVAL; } diff --git a/drivers/media/platform/exynos/mfc/s5p_mfc_queue.c b/drivers/media/platform/exynos/mfc/s5p_mfc_queue.c index 19193d3d4b40..235dd2637187 100644 --- a/drivers/media/platform/exynos/mfc/s5p_mfc_queue.c +++ b/drivers/media/platform/exynos/mfc/s5p_mfc_queue.c @@ -27,8 +27,8 @@ void s5p_mfc_add_tail_buf(spinlock_t *plock, struct s5p_mfc_buf_queue *queue, spin_lock_irqsave(plock, flags); - mfc_debug(2, "queue address: %p\n", queue); - mfc_debug(2, "mfc_buf: %p\n", mfc_buf); + mfc_debug(2, "queue address: 0x%p\n", queue); + mfc_debug(2, "mfc_buf: 0x%p\n", mfc_buf); mfc_buf->used = 0; list_add_tail(&mfc_buf->list, &queue->head); @@ -55,7 +55,7 @@ int s5p_mfc_peek_buf_csd(spinlock_t *plock, struct s5p_mfc_buf_queue *queue) csd = mfc_buf->vb.reserved2 & FLAG_CSD ? 1 : 0; - mfc_debug(2, "mfc_buf: %p\n", mfc_buf); + mfc_debug(2, "mfc_buf: 0x%p\n", mfc_buf); mfc_debug(2, "First plane address: 0x%08llx\n", mfc_buf->addr[0]); spin_unlock_irqrestore(plock, flags); @@ -81,7 +81,7 @@ struct s5p_mfc_buf *s5p_mfc_get_buf(spinlock_t *plock, struct s5p_mfc_buf_queue if ((used == MFC_BUF_RESET_USED) || (used == MFC_BUF_SET_USED)) mfc_buf->used = used; - mfc_debug(2, "mfc_buf: %p\n", mfc_buf); + mfc_debug(2, "mfc_buf: 0x%p\n", mfc_buf); mfc_debug(2, "First plane address: 0x%08llx\n", mfc_buf->addr[0]); spin_unlock_irqrestore(plock, flags); @@ -107,7 +107,7 @@ struct s5p_mfc_buf *s5p_mfc_get_del_buf(spinlock_t *plock, struct s5p_mfc_buf_qu if ((used == MFC_BUF_RESET_USED) || (used == MFC_BUF_SET_USED)) mfc_buf->used = used; - mfc_debug(2, "mfc_buf: %p\n", mfc_buf); + mfc_debug(2, "mfc_buf: 0x%p\n", mfc_buf); mfc_debug(2, "First plane address: 0x%08llx\n", mfc_buf->addr[0]); list_del(&mfc_buf->list); @@ -134,7 +134,7 @@ struct s5p_mfc_buf *s5p_mfc_get_del_if_consumed(spinlock_t *plock, struct s5p_mf mfc_buf = list_entry(queue->head.next, struct s5p_mfc_buf, list); - mfc_debug(2, "mfc_buf: %p\n", mfc_buf); + mfc_debug(2, "mfc_buf: 0x%p\n", mfc_buf); mfc_debug(2, "First plane address: 0x%08llx\n", mfc_buf->addr[0]); remained = (unsigned int)(mfc_buf->vb.vb2_buf.planes[0].bytesused - consumed); @@ -177,7 +177,7 @@ struct s5p_mfc_buf *s5p_mfc_get_move_buf(spinlock_t *plock, if ((used == MFC_BUF_RESET_USED) || (used == MFC_BUF_SET_USED)) mfc_buf->used = used; - mfc_debug(2, "mfc_buf: %p\n", mfc_buf); + mfc_debug(2, "mfc_buf: 0x%p\n", mfc_buf); mfc_debug(2, "First plane address: 0x%08llx\n", mfc_buf->addr[0]); list_del(&mfc_buf->list); @@ -211,7 +211,7 @@ struct s5p_mfc_buf *s5p_mfc_get_move_buf_used(spinlock_t *plock, mfc_buf = list_entry(from_queue->head.next, struct s5p_mfc_buf, list); if (mfc_buf->used) { - mfc_debug(2, "mfc_buf: %p\n", mfc_buf); + mfc_debug(2, "mfc_buf: 0x%p\n", mfc_buf); mfc_debug(2, "First plane address: 0x%08llx\n", mfc_buf->addr[0]); list_del(&mfc_buf->list); @@ -899,7 +899,7 @@ int s5p_mfc_is_last_frame(struct s5p_mfc_ctx *ctx) src_mb = list_entry(ctx->src_buf_queue.head.next, struct s5p_mfc_buf, list); - mfc_debug(2, "mfc_buf: %p\n", src_mb); + mfc_debug(2, "mfc_buf: 0x%p\n", src_mb); mfc_debug(2, "First plane address: 0x%08llx\n", src_mb->addr[0]); if (src_mb->vb.reserved2 & FLAG_LAST_FRAME) { diff --git a/drivers/media/platform/exynos/mfc/s5p_mfc_reg.c b/drivers/media/platform/exynos/mfc/s5p_mfc_reg.c index 13aeac2b3ca4..29b9e60b073b 100644 --- a/drivers/media/platform/exynos/mfc/s5p_mfc_reg.c +++ b/drivers/media/platform/exynos/mfc/s5p_mfc_reg.c @@ -117,7 +117,7 @@ int s5p_mfc_set_dec_codec_buffers(struct s5p_mfc_ctx *ctx) buf_addr1 = ctx->codec_buf.daddr; buf_size1 = ctx->codec_buf.size; - mfc_debug(2, "Buf1: %p (%d)\n", (void *)buf_addr1, buf_size1); + mfc_debug(2, "Buf1: 0x%p (%d)\n", (void *)buf_addr1, buf_size1); mfc_debug(2, "Total DPB COUNT: %d\n", dec->total_dpb_count); mfc_debug(2, "Setting display delay to %d\n", dec->display_delay); @@ -208,14 +208,14 @@ int s5p_mfc_set_dec_codec_buffers(struct s5p_mfc_ctx *ctx) align_gap = buf_addr1 - align_gap; buf_size1 -= align_gap; - mfc_debug(2, "\tBuf1: %p, size: %d\n", (void *)buf_addr1, buf_size1); + mfc_debug(2, "\tBuf1: 0x%p, size: %d\n", (void *)buf_addr1, buf_size1); MFC_WRITEL(buf_addr1, S5P_FIMV_D_MV_BUFFER0 + i * 4); buf_addr1 += frame_size_mv; buf_size1 -= frame_size_mv; } } - mfc_debug(2, "Buf1: %p, buf_size1: %d (frames %d)\n", + mfc_debug(2, "Buf1: 0x%p, buf_size1: %d (frames %d)\n", (void *)buf_addr1, buf_size1, dec->total_dpb_count); if (buf_size1 < 0) { mfc_debug(2, "Not enough memory has been allocated.\n"); @@ -240,7 +240,7 @@ int s5p_mfc_set_enc_codec_buffers(struct s5p_mfc_ctx *ctx) buf_addr1 = ctx->codec_buf.daddr; buf_size1 = ctx->codec_buf.size; - mfc_debug(2, "Buf1: %p (%d)\n", (void *)buf_addr1, buf_size1); + mfc_debug(2, "Buf1: 0x%p (%d)\n", (void *)buf_addr1, buf_size1); MFC_WRITEL(buf_addr1, S5P_FIMV_E_SCRATCH_BUFFER_ADDR); MFC_WRITEL(ctx->scratch_buf_size, S5P_FIMV_E_SCRATCH_BUFFER_SIZE); @@ -270,7 +270,7 @@ int s5p_mfc_set_enc_codec_buffers(struct s5p_mfc_ctx *ctx) buf_addr1 += enc->tmv_buffer_size >> 1; buf_size1 -= enc->tmv_buffer_size; - mfc_debug(2, "Buf1: %p, buf_size1: %d (ref frames %d)\n", + mfc_debug(2, "Buf1: 0x%p, buf_size1: %d (ref frames %d)\n", (void *)buf_addr1, buf_size1, ctx->dpb_count); if (buf_size1 < 0) { mfc_debug(2, "Not enough memory has been allocated.\n"); diff --git a/drivers/media/platform/exynos/mfc/s5p_mfc_watchdog.c b/drivers/media/platform/exynos/mfc/s5p_mfc_watchdog.c index 7dbd69c08b87..90848af615ae 100644 --- a/drivers/media/platform/exynos/mfc/s5p_mfc_watchdog.c +++ b/drivers/media/platform/exynos/mfc/s5p_mfc_watchdog.c @@ -55,7 +55,7 @@ static void mfc_dump_regs(struct s5p_mfc_dev *dev) { 0xD000, 0x74 }, }; - pr_err("-----------dumping MFC registers (SFR base = %p, dev = %p)\n", + pr_err("-----------dumping MFC registers (SFR base = 0x%p, dev = 0x%p)\n", dev->regs_base, dev); s5p_mfc_enable_all_clocks(dev); -- 2.20.1