From be0b8e30b11e234bebd71a894181dc37d2cf855d Mon Sep 17 00:00:00 2001 From: Tomasz Figa Date: Mon, 13 Apr 2015 14:49:43 +0900 Subject: [PATCH] CHROMIUM: [media] rk3288-vpu: Require kernel mapping only for encoder output For rk3288-vpu, kernel mapping of video buffers is required only for encoder bitstream output buffers for additional bistream formatting. Any other buffers can be allocated without kernel mapping, greatly conserving the limited pool of vmalloc memory. This patch modifies the rk3288-vpu driver to use the newly added vb2-dc interface to create two separate allocation contexts, one for allocations with kernel mapping and one without. BUG=chrome-os-partner:38873 TEST=vda/vea unit tests Signed-off-by: Tomasz Figa Reviewed-on: https://chromium-review.googlesource.com/265364 Reviewed-by: Pawel Osciak Change-Id: I4154802dda2329934dea675a242d67e80b925db0 Signed-off-by: Jeffy Chen Signed-off-by: Yakir Yang --- drivers/media/platform/rk3288-vpu/rk3288_vpu.c | 14 +++++++++++++- .../media/platform/rk3288-vpu/rk3288_vpu_common.h | 6 +++++- drivers/media/platform/rk3288-vpu/rk3288_vpu_enc.c | 3 ++- 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/drivers/media/platform/rk3288-vpu/rk3288_vpu.c b/drivers/media/platform/rk3288-vpu/rk3288_vpu.c index c9ea748148a2..17728371896b 100644 --- a/drivers/media/platform/rk3288-vpu/rk3288_vpu.c +++ b/drivers/media/platform/rk3288-vpu/rk3288_vpu.c @@ -558,6 +558,7 @@ static const struct v4l2_file_operations rk3288_vpu_fops = { static int rk3288_vpu_probe(struct platform_device *pdev) { struct rk3288_vpu_dev *vpu = NULL; + DEFINE_DMA_ATTRS(attrs_novm); struct video_device *vfd; int ret = 0; @@ -580,12 +581,20 @@ static int rk3288_vpu_probe(struct platform_device *pdev) goto err_hw_probe; } - vpu->alloc_ctx = vb2_dma_contig_init_ctx(&pdev->dev); + dma_set_attr(DMA_ATTR_NO_KERNEL_MAPPING, &attrs_novm); + vpu->alloc_ctx = vb2_dma_contig_init_ctx_attrs(&pdev->dev, + &attrs_novm); if (IS_ERR(vpu->alloc_ctx)) { ret = PTR_ERR(vpu->alloc_ctx); goto err_dma_contig; } + vpu->alloc_ctx_vm = vb2_dma_contig_init_ctx(&pdev->dev); + if (IS_ERR(vpu->alloc_ctx_vm)) { + ret = PTR_ERR(vpu->alloc_ctx_vm); + goto err_dma_contig_vm; + } + ret = v4l2_device_register(&pdev->dev, &vpu->v4l2_dev); if (ret) { dev_err(&pdev->dev, "Failed to register v4l2 device\n"); @@ -667,6 +676,8 @@ err_enc_reg: err_enc_alloc: v4l2_device_unregister(&vpu->v4l2_dev); err_v4l2_dev_reg: + vb2_dma_contig_cleanup_ctx(vpu->alloc_ctx_vm); +err_dma_contig_vm: vb2_dma_contig_cleanup_ctx(vpu->alloc_ctx); err_dma_contig: rk3288_vpu_hw_remove(vpu); @@ -694,6 +705,7 @@ static int rk3288_vpu_remove(struct platform_device *pdev) video_unregister_device(vpu->vfd_dec); video_unregister_device(vpu->vfd_enc); v4l2_device_unregister(&vpu->v4l2_dev); + vb2_dma_contig_cleanup_ctx(vpu->alloc_ctx_vm); vb2_dma_contig_cleanup_ctx(vpu->alloc_ctx); rk3288_vpu_hw_remove(vpu); diff --git a/drivers/media/platform/rk3288-vpu/rk3288_vpu_common.h b/drivers/media/platform/rk3288-vpu/rk3288_vpu_common.h index a074e2c63d60..0082e2f57bfd 100644 --- a/drivers/media/platform/rk3288-vpu/rk3288_vpu_common.h +++ b/drivers/media/platform/rk3288-vpu/rk3288_vpu_common.h @@ -137,7 +137,10 @@ enum rk3288_vpu_state { * @pdev: Pointer to VPU platform device. * @dev: Pointer to device for convenient logging using * dev_ macros. - * @alloc_ctx: VB2 allocator context. + * @alloc_ctx: VB2 allocator context + * (for allocations without kernel mapping). + * @alloc_ctx_vm: VB2 allocator context + * (for allocations with kernel mapping). * @aclk_vcodec: Handle of ACLK clock. * @hclk_vcodec: Handle of HCLK clock. * @base: Mapped address of VPU registers. @@ -161,6 +164,7 @@ struct rk3288_vpu_dev { struct platform_device *pdev; struct device *dev; void *alloc_ctx; + void *alloc_ctx_vm; struct clk *aclk_vcodec; struct clk *hclk_vcodec; void __iomem *base; diff --git a/drivers/media/platform/rk3288-vpu/rk3288_vpu_enc.c b/drivers/media/platform/rk3288-vpu/rk3288_vpu_enc.c index bf00ae0d7d76..cee6a5ebbb49 100644 --- a/drivers/media/platform/rk3288-vpu/rk3288_vpu_enc.c +++ b/drivers/media/platform/rk3288-vpu/rk3288_vpu_enc.c @@ -1036,7 +1036,8 @@ static int rk3288_vpu_queue_setup(struct vb2_queue *vq, *buf_count = VIDEO_MAX_FRAME; psize[0] = ctx->dst_fmt.plane_fmt[0].sizeimage; - allocators[0] = ctx->dev->alloc_ctx; + /* Kernel mapping necessary for bitstream post processing. */ + allocators[0] = ctx->dev->alloc_ctx_vm; vpu_debug(0, "capture psize[%d]: %d\n", 0, psize[0]); break; -- 2.34.1