From: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
To: Tomasz Stanislawski <t.stanislaws@samsung.com>
Cc: linux-media@vger.kernel.org, dri-devel@lists.freedesktop.org,
airlied@redhat.com, m.szyprowski@samsung.com,
kyungmin.park@samsung.com, sumit.semwal@ti.com,
daeinki@gmail.com, daniel.vetter@ffwll.ch, robdclark@gmail.com,
pawel@osciak.com, linaro-mm-sig@lists.linaro.org,
subashrp@gmail.com, mchehab@redhat.com
Subject: Re: [RFC 04/13] v4l: vb2-dma-contig: add setup of sglist for MMAP buffers
Date: Tue, 17 Apr 2012 15:17:13 +0200 [thread overview]
Message-ID: <1634369.EmMfL12p0k@avalon> (raw)
In-Reply-To: <1334063447-16824-5-git-send-email-t.stanislaws@samsung.com>
Hi Tomasz,
Thanks for the patch.
On Tuesday 10 April 2012 15:10:38 Tomasz Stanislawski wrote:
> This patch adds the setup of sglist list for MMAP buffers.
> It is needed for buffer exporting via DMABUF mechanism.
>
> This patch depends on dma_get_pages extension to DMA api.
>
> Signed-off-by: Tomasz Stanislawski <t.stanislaws@samsung.com>
> Signed-off-by: Kyungmin Park <kyungmin.park@samsung.com>
> ---
> drivers/media/video/videobuf2-dma-contig.c | 51 ++++++++++++++++++++++++-
> 1 files changed, 49 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/media/video/videobuf2-dma-contig.c
> b/drivers/media/video/videobuf2-dma-contig.c index f4df9e2..0cdcd2b 100644
> --- a/drivers/media/video/videobuf2-dma-contig.c
> +++ b/drivers/media/video/videobuf2-dma-contig.c
[snip]
> @@ -197,6 +199,9 @@ static void *vb2_dc_alloc(void *alloc_ctx, unsigned long
> size) {
> struct device *dev = alloc_ctx;
> struct vb2_dc_buf *buf;
> + int ret = -ENOMEM;
> + int n_pages;
> + struct page **pages = NULL;
>
> buf = kzalloc(sizeof *buf, GFP_KERNEL);
> if (!buf)
> @@ -205,10 +210,41 @@ static void *vb2_dc_alloc(void *alloc_ctx, unsigned
> long size) buf->vaddr = dma_alloc_coherent(dev, size, &buf->dma_addr,
> GFP_KERNEL); if (!buf->vaddr) {
> dev_err(dev, "dma_alloc_coherent of size %ld failed\n", size);
> - kfree(buf);
> - return ERR_PTR(-ENOMEM);
> + goto fail_buf;
> + }
> +
> + WARN_ON((unsigned long)buf->vaddr & ~PAGE_MASK);
> + WARN_ON(buf->dma_addr & ~PAGE_MASK);
> +
> + n_pages = PAGE_ALIGN(size) >> PAGE_SHIFT;
> +
> + pages = kmalloc(n_pages * sizeof pages[0], GFP_KERNEL);
> + if (!pages) {
> + dev_err(dev, "failed to alloc page table\n");
> + goto fail_dma;
> + }
> +
> + ret = dma_get_pages(dev, buf->vaddr, buf->dma_addr, pages, n_pages);
> + if (ret < 0) {
> + dev_err(dev, "failed to get buffer pages from DMA API\n");
> + goto fail_pages;
> + }
> + if (ret != n_pages) {
> + ret = -EFAULT;
> + dev_err(dev, "failed to get all pages from DMA API\n");
> + goto fail_pages;
> }
>
> + buf->sgt_base = vb2_dc_pages_to_sgt(pages, n_pages, 0, 0);
> + if (IS_ERR(buf->sgt_base)) {
> + ret = PTR_ERR(buf->sgt_base);
> + dev_err(dev, "failed to prepare sg table\n");
> + goto fail_pages;
> + }
I still (at least partially) share Daniel's opinion regarding dma_get_pages(),
As I stated before, I think what we need here would be either
- a DMA API call that maps the memory to the importer device instead of
dma_get_pages() + vb2_dc_pages_to_sgt(). The call would take a DMA memory
"cookie" (see the "Minutes from V4L2 update call" mail thread) and a pointer
to the importer device.
- a DMA API call to retrieve a scatter list suitable to be passed to
dma_map_sg(). This would be similar to dma_get_pages() +
vb2_dc_pages_to_sgt().
(And we still have to figure out whether the mapping call should be in the
exporter or importer, which might have an influence here).
> +
> + /* pages are no longer needed */
> + kfree(pages);
> +
> buf->dev = dev;
> buf->size = size;
>
> @@ -219,6 +255,17 @@ static void *vb2_dc_alloc(void *alloc_ctx, unsigned
> long size) atomic_inc(&buf->refcount);
>
> return buf;
> +
> +fail_pages:
> + kfree(pages);
As kfree(NULL) is legal, you can remove the fail_pages label and move the
kfree() call just before dma_free_coherent().
> +
> +fail_dma:
> + dma_free_coherent(dev, size, buf->vaddr, buf->dma_addr);
> +
> +fail_buf:
> + kfree(buf);
> +
> + return ERR_PTR(ret);
> }
>
> static int vb2_dc_mmap(void *buf_priv, struct vm_area_struct *vma)
--
Regards,
Laurent Pinchart
next prev parent reply other threads:[~2012-04-17 13:17 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-04-10 13:10 [RFC 00/13] Support for dmabuf exporting for videobuf2 Tomasz Stanislawski
2012-04-10 13:10 ` [RFC 01/13] v4l: add buffer exporting via dmabuf Tomasz Stanislawski
2012-04-17 12:41 ` Laurent Pinchart
2012-04-10 13:10 ` [RFC 02/13] v4l: vb2: " Tomasz Stanislawski
2012-04-17 12:59 ` Laurent Pinchart
2012-04-10 13:10 ` [RFC 03/13] v4l: vb2-dma-contig: let mmap method to use dma_mmap_coherent call Tomasz Stanislawski
2012-04-17 12:56 ` Laurent Pinchart
2012-04-10 13:10 ` [RFC 04/13] v4l: vb2-dma-contig: add setup of sglist for MMAP buffers Tomasz Stanislawski
2012-04-17 13:17 ` Laurent Pinchart [this message]
2012-04-10 13:10 ` [RFC 05/13] v4l: vb2-dma-contig: add support for DMABUF exporting Tomasz Stanislawski
2012-04-17 14:08 ` Laurent Pinchart
2012-04-19 10:42 ` Tomasz Stanislawski
2012-05-07 13:27 ` Laurent Pinchart
2012-05-22 11:51 ` Tomasz Stanislawski
2012-04-10 13:10 ` [RFC 06/13] v4l: vb2-dma-contig: add vmap/kmap for dmabuf exporting Tomasz Stanislawski
2012-04-10 13:10 ` [RFC 07/13] v4l: vb2-dma-contig: change map/unmap behaviour for importers Tomasz Stanislawski
2012-04-10 13:10 ` [RFC 08/13] v4l: vb2-dma-contig: change map/unmap behaviour for exporters Tomasz Stanislawski
2012-04-10 13:10 ` [RFC 09/13] v4l: s5p-tv: mixer: support for dmabuf importing Tomasz Stanislawski
2012-04-10 13:10 ` [RFC 10/13] v4l: s5p-tv: mixer: support for dmabuf exporting Tomasz Stanislawski
2012-04-10 13:10 ` [RFC 11/13] v4l: fimc: support for dmabuf importing Tomasz Stanislawski
2012-04-10 13:10 ` [RFC 12/13] v4l: fimc: support for dmabuf exporting Tomasz Stanislawski
2012-04-10 13:10 ` [RFC 13/13] v4l: vivi: " Tomasz Stanislawski
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=1634369.EmMfL12p0k@avalon \
--to=laurent.pinchart@ideasonboard.com \
--cc=airlied@redhat.com \
--cc=daeinki@gmail.com \
--cc=daniel.vetter@ffwll.ch \
--cc=dri-devel@lists.freedesktop.org \
--cc=kyungmin.park@samsung.com \
--cc=linaro-mm-sig@lists.linaro.org \
--cc=linux-media@vger.kernel.org \
--cc=m.szyprowski@samsung.com \
--cc=mchehab@redhat.com \
--cc=pawel@osciak.com \
--cc=robdclark@gmail.com \
--cc=subashrp@gmail.com \
--cc=sumit.semwal@ti.com \
--cc=t.stanislaws@samsung.com \
/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;
as well as URLs for NNTP newsgroup(s).