From: Thierry Escande <thierry.escande@collabora.com>
To: Mauro Carvalho Chehab <mchehab@kernel.org>,
Sakari Ailus <sakari.ailus@iki.fi>
Cc: linux-media@vger.kernel.org, linux-kernel@vger.kernel.org,
Pawel Osciak <pawel@osciak.com>,
Marek Szyprowski <m.szyprowski@samsung.com>,
Kyungmin Park <kyungmin.park@samsung.com>
Subject: [PATCH v3 2/2] [media] videobuf2-dc: Support cacheable MMAP
Date: Wed, 26 Oct 2016 10:52:06 +0200 [thread overview]
Message-ID: <1477471926-15796-3-git-send-email-thierry.escande@collabora.com> (raw)
In-Reply-To: <1477471926-15796-1-git-send-email-thierry.escande@collabora.com>
From: Heng-Ruey Hsu <henryhsu@chromium.org>
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.
This patch enables cacheable memory for DMA coherent allocator in mmap
buffer allocation if non-consistent DMA attribute is set and kernel
mapping is present. Even if userspace doesn't mmap the buffer, sync
still should be happening if kernel mapping is present.
If not done in allocation, it is enabled when memory is mapped from
userspace (if non-consistent DMA attribute is set).
Signed-off-by: Heng-Ruey Hsu <henryhsu@chromium.org>
Tested-by: Heng-ruey Hsu <henryhsu@chromium.org>
Reviewed-by: Tomasz Figa <tfiga@chromium.org>
Signed-off-by: Thierry Escande <thierry.escande@collabora.com>
---
drivers/media/v4l2-core/videobuf2-dma-contig.c | 16 ++++++++++++++++
1 file changed, 16 insertions(+)
diff --git a/drivers/media/v4l2-core/videobuf2-dma-contig.c b/drivers/media/v4l2-core/videobuf2-dma-contig.c
index 0d9665d..89b534a 100644
--- a/drivers/media/v4l2-core/videobuf2-dma-contig.c
+++ b/drivers/media/v4l2-core/videobuf2-dma-contig.c
@@ -151,6 +151,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);
@@ -192,6 +196,14 @@ static void *vb2_dc_alloc(struct device *dev, unsigned long attrs,
buf->handler.put = vb2_dc_put;
buf->handler.arg = buf;
+ /*
+ * Enable cache maintenance. Even if userspace doesn't mmap the buffer,
+ * sync still should be happening if kernel mapping is present.
+ */
+ 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;
@@ -227,6 +239,10 @@ static int vb2_dc_mmap(void *buf_priv, struct vm_area_struct *vma)
vma->vm_ops->open(vma);
+ /* Enable cache maintenance if not enabled in allocation. */
+ if (!buf->dma_sgt && buf->attrs & DMA_ATTR_NON_CONSISTENT)
+ 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);
--
2.7.4
next prev parent reply other threads:[~2016-10-26 8:52 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <CGME20161026085228epcas3p3895ea279d5538750a3b1c59715ad3761@epcas3p3.samsung.com>
2016-10-26 8:52 ` [PATCH v3 0/2] [media] videobuf2-dc: Add support for " Thierry Escande
2016-10-26 8:52 ` [PATCH v3 1/2] [media] videobuf2-dc: Move vb2_dc_get_base_sgt() above mmap callbacks Thierry Escande
2016-10-26 8:52 ` Thierry Escande [this message]
2018-09-17 14:41 ` [PATCH v3 2/2] [media] videobuf2-dc: Support cacheable MMAP Hans Verkuil
2018-09-18 9:41 ` Tomasz Figa
2017-07-03 9:27 ` [PATCH v3 0/2] [media] videobuf2-dc: Add support for " Marek Szyprowski
2017-07-05 17:33 ` Christoph Hellwig
2017-07-13 11:13 ` Marek Szyprowski
2017-07-13 13:21 ` Russell King - ARM Linux
2017-07-13 13:36 ` Christoph Hellwig
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1477471926-15796-3-git-send-email-thierry.escande@collabora.com \
--to=thierry.escande@collabora.com \
--cc=kyungmin.park@samsung.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-media@vger.kernel.org \
--cc=m.szyprowski@samsung.com \
--cc=mchehab@kernel.org \
--cc=pawel@osciak.com \
--cc=sakari.ailus@iki.fi \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®