From patchwork Fri Oct 14 13:21:49 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thierry Escande X-Patchwork-Id: 9376835 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 1479F6022E for ; Fri, 14 Oct 2016 13:23:42 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 039F32A6A7 for ; Fri, 14 Oct 2016 13:23:42 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id EA7DE2A6AA; Fri, 14 Oct 2016 13:23:41 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 940D42A6A7 for ; Fri, 14 Oct 2016 13:23:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932548AbcJNNW4 (ORCPT ); Fri, 14 Oct 2016 09:22:56 -0400 Received: from bhuna.collabora.co.uk ([46.235.227.227]:50726 "EHLO bhuna.collabora.co.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753093AbcJNNV5 (ORCPT ); Fri, 14 Oct 2016 09:21:57 -0400 Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: tescande) with ESMTPSA id BB75E260BD7 From: Thierry Escande To: Mauro Carvalho Chehab Cc: linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, Pawel Osciak , Marek Szyprowski , Kyungmin Park Subject: [PATCH] [media] videobuf2-dma-contig: Support cacheable MMAP Date: Fri, 14 Oct 2016 15:21:49 +0200 Message-Id: <1476451309-10645-1-git-send-email-thierry.escande@collabora.com> X-Mailer: git-send-email 2.7.4 MIME-Version: 1.0 Content-Transfert-Encoding: 8bit Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Heng-Ruey Hsu DMA allocations for MMAP type are uncached by default. But for some cases, CPU has to access the buffers. ie: memcpy for format converter. Supporting cacheable MMAP improves huge performance. Signed-off-by: Heng-Ruey Hsu Tested-by: Heng-ruey Hsu Reviewed-by: Tomasz Figa Signed-off-by: Thierry Escande --- drivers/media/v4l2-core/videobuf2-dma-contig.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/drivers/media/v4l2-core/videobuf2-dma-contig.c b/drivers/media/v4l2-core/videobuf2-dma-contig.c index fb6a177..c953c24 100644 --- a/drivers/media/v4l2-core/videobuf2-dma-contig.c +++ b/drivers/media/v4l2-core/videobuf2-dma-contig.c @@ -42,6 +42,12 @@ struct vb2_dc_buf { }; /*********************************************/ +/* Forward declarations */ +/*********************************************/ + +static struct sg_table *vb2_dc_get_base_sgt(struct vb2_dc_buf *buf); + +/*********************************************/ /* scatterlist table functions */ /*********************************************/ @@ -129,6 +135,10 @@ static void vb2_dc_put(void *buf_priv) sg_free_table(buf->sgt_base); kfree(buf->sgt_base); } + if (buf->dma_sgt) { + sg_free_table(buf->dma_sgt); + kfree(buf->dma_sgt); + } dma_free_attrs(buf->dev, buf->size, buf->cookie, buf->dma_addr, buf->attrs); put_device(buf->dev); @@ -170,6 +180,10 @@ static void *vb2_dc_alloc(struct device *dev, unsigned long attrs, buf->handler.put = vb2_dc_put; buf->handler.arg = buf; + if (!(buf->attrs & DMA_ATTR_NO_KERNEL_MAPPING) && + (buf->attrs & DMA_ATTR_NON_CONSISTENT)) + buf->dma_sgt = vb2_dc_get_base_sgt(buf); + atomic_inc(&buf->refcount); return buf; @@ -205,6 +219,11 @@ static int vb2_dc_mmap(void *buf_priv, struct vm_area_struct *vma) vma->vm_ops->open(vma); + if ((buf->attrs & DMA_ATTR_NO_KERNEL_MAPPING) && + (buf->attrs & DMA_ATTR_NON_CONSISTENT) && + !buf->dma_sgt) + buf->dma_sgt = vb2_dc_get_base_sgt(buf); + pr_debug("%s: mapped dma addr 0x%08lx at 0x%08lx, size %ld\n", __func__, (unsigned long)buf->dma_addr, vma->vm_start, buf->size);