linux-media.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
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,
	hverkuil@xs4all.nl, remi@remlab.net, subashrp@gmail.com,
	mchehab@redhat.com, g.liakhovetski@gmx.de
Subject: Re: [PATCH 11/12] v4l: vb2-dma-contig: use sg_alloc_table_from_pages function
Date: Wed, 06 Jun 2012 10:05:41 +0200	[thread overview]
Message-ID: <3795802.eekr7JsUpA@avalon> (raw)
In-Reply-To: <1337778455-27912-12-git-send-email-t.stanislaws@samsung.com>

Hi Tomasz,

Thanks for the patch.

On Wednesday 23 May 2012 15:07:34 Tomasz Stanislawski wrote:
> This patch makes use of sg_alloc_table_from_pages to simplify
> handling of sg tables.

Would you mind moving this patch before 04/12, to avoid introducing a 
vb2_dc_pages_to_sgt() user only to remove it in this patch ? Otherwise this 
looks good.

> 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 |   90 +++++++------------------
>  1 file changed, 25 insertions(+), 65 deletions(-)
> 
> diff --git a/drivers/media/video/videobuf2-dma-contig.c
> b/drivers/media/video/videobuf2-dma-contig.c index 59ee81c..b5caf1d 100644
> --- a/drivers/media/video/videobuf2-dma-contig.c
> +++ b/drivers/media/video/videobuf2-dma-contig.c
> @@ -32,7 +32,7 @@ struct vb2_dc_buf {
>  	/* MMAP related */
>  	struct vb2_vmarea_handler	handler;
>  	atomic_t			refcount;
> -	struct sg_table			*sgt_base;
> +	struct sg_table			sgt_base;
> 
>  	/* USERPTR related */
>  	struct vm_area_struct		*vma;
> @@ -45,57 +45,6 @@ struct vb2_dc_buf {
>  /*        scatterlist table functions        */
>  /*********************************************/
> 
> -static struct sg_table *vb2_dc_pages_to_sgt(struct page **pages,
> -	unsigned int n_pages, unsigned long offset, unsigned long size)
> -{
> -	struct sg_table *sgt;
> -	unsigned int chunks;
> -	unsigned int i;
> -	unsigned int cur_page;
> -	int ret;
> -	struct scatterlist *s;
> -
> -	sgt = kzalloc(sizeof *sgt, GFP_KERNEL);
> -	if (!sgt)
> -		return ERR_PTR(-ENOMEM);
> -
> -	/* compute number of chunks */
> -	chunks = 1;
> -	for (i = 1; i < n_pages; ++i)
> -		if (pages[i] != pages[i - 1] + 1)
> -			++chunks;
> -
> -	ret = sg_alloc_table(sgt, chunks, GFP_KERNEL);
> -	if (ret) {
> -		kfree(sgt);
> -		return ERR_PTR(-ENOMEM);
> -	}
> -
> -	/* merging chunks and putting them into the scatterlist */
> -	cur_page = 0;
> -	for_each_sg(sgt->sgl, s, sgt->orig_nents, i) {
> -		unsigned long chunk_size;
> -		unsigned int j;
> -
> -		for (j = cur_page + 1; j < n_pages; ++j)
> -			if (pages[j] != pages[j - 1] + 1)
> -				break;
> -
> -		chunk_size = ((j - cur_page) << PAGE_SHIFT) - offset;
> -		sg_set_page(s, pages[cur_page], min(size, chunk_size), offset);
> -		size -= chunk_size;
> -		offset = 0;
> -		cur_page = j;
> -	}
> -
> -	return sgt;
> -}
> -
> -static void vb2_dc_release_sgtable(struct sg_table *sgt)
> -{
> -	sg_free_table(sgt);
> -	kfree(sgt);
> -}
> 
>  static void vb2_dc_sgt_foreach_page(struct sg_table *sgt,
>  	void (*cb)(struct page *pg))
> @@ -190,7 +139,7 @@ static void vb2_dc_put(void *buf_priv)
>  	if (!atomic_dec_and_test(&buf->refcount))
>  		return;
> 
> -	vb2_dc_release_sgtable(buf->sgt_base);
> +	sg_free_table(&buf->sgt_base);
>  	dma_free_coherent(buf->dev, buf->size, buf->vaddr, buf->dma_addr);
>  	kfree(buf);
>  }
> @@ -254,9 +203,9 @@ static void *vb2_dc_alloc(void *alloc_ctx, unsigned long
> size) goto fail_pages;
>  	}
> 
> -	buf->sgt_base = vb2_dc_pages_to_sgt(pages, n_pages, 0, size);
> -	if (IS_ERR(buf->sgt_base)) {
> -		ret = PTR_ERR(buf->sgt_base);
> +	ret = sg_alloc_table_from_pages(&buf->sgt_base,
> +		pages, n_pages, 0, size, GFP_KERNEL);
> +	if (ret) {
>  		dev_err(dev, "failed to prepare sg table\n");
>  		goto fail_pages;
>  	}
> @@ -379,13 +328,13 @@ static struct sg_table *vb2_dc_dmabuf_ops_map(
>  	attach->dir = dir;
> 
>  	/* copying the buf->base_sgt to attachment */
> -	ret = sg_alloc_table(sgt, buf->sgt_base->orig_nents, GFP_KERNEL);
> +	ret = sg_alloc_table(sgt, buf->sgt_base.orig_nents, GFP_KERNEL);
>  	if (ret) {
>  		kfree(attach);
>  		return ERR_PTR(-ENOMEM);
>  	}
> 
> -	rd = buf->sgt_base->sgl;
> +	rd = buf->sgt_base.sgl;
>  	wr = sgt->sgl;
>  	for (i = 0; i < sgt->orig_nents; ++i) {
>  		sg_set_page(wr, sg_page(rd), rd->length, rd->offset);
> @@ -519,7 +468,8 @@ static void vb2_dc_put_userptr(void *buf_priv)
>  	if (!vma_is_io(buf->vma))
>  		vb2_dc_sgt_foreach_page(sgt, vb2_dc_put_dirty_page);
> 
> -	vb2_dc_release_sgtable(sgt);
> +	sg_free_table(sgt);
> +	kfree(sgt);
>  	vb2_put_vma(buf->vma);
>  	kfree(buf);
>  }
> @@ -586,13 +536,20 @@ static void *vb2_dc_get_userptr(void *alloc_ctx,
> unsigned long vaddr, goto fail_vma;
>  	}
> 
> -	sgt = vb2_dc_pages_to_sgt(pages, n_pages, offset, size);
> -	if (IS_ERR(sgt)) {
> -		printk(KERN_ERR "failed to create scatterlist table\n");
> +	sgt = kzalloc(sizeof *sgt, GFP_KERNEL);
> +	if (!sgt) {
> +		printk(KERN_ERR "failed to allocate sg table\n");
>  		ret = -ENOMEM;
>  		goto fail_get_user_pages;
>  	}
> 
> +	ret = sg_alloc_table_from_pages(sgt, pages, n_pages,
> +		offset, size, GFP_KERNEL);
> +	if (ret) {
> +		printk(KERN_ERR "failed to initialize sg table\n");
> +		goto fail_sgt;
> +	}
> +
>  	/* pages are no longer needed */
>  	kfree(pages);
>  	pages = NULL;
> @@ -602,7 +559,7 @@ static void *vb2_dc_get_userptr(void *alloc_ctx,
> unsigned long vaddr, if (sgt->nents <= 0) {
>  		printk(KERN_ERR "failed to map scatterlist\n");
>  		ret = -EIO;
> -		goto fail_sgt;
> +		goto fail_sgt_init;
>  	}
> 
>  	contig_size = vb2_dc_get_contiguous_size(sgt);
> @@ -622,10 +579,13 @@ static void *vb2_dc_get_userptr(void *alloc_ctx,
> unsigned long vaddr, fail_map_sg:
>  	dma_unmap_sg(buf->dev, sgt->sgl, sgt->nents, buf->dma_dir);
> 
> -fail_sgt:
> +fail_sgt_init:
>  	if (!vma_is_io(buf->vma))
>  		vb2_dc_sgt_foreach_page(sgt, put_page);
> -	vb2_dc_release_sgtable(sgt);
> +	sg_free_table(sgt);
> +
> +fail_sgt:
> +	kfree(sgt);
> 
>  fail_get_user_pages:
>  	if (pages && !vma_is_io(buf->vma))
-- 
Regards,

Laurent Pinchart


  reply	other threads:[~2012-06-06  8:05 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-05-23 13:07 [PATCH 00/12] Support for dmabuf exporting for videobuf2 Tomasz Stanislawski
2012-05-23 13:07 ` [PATCH 01/12] v4l: vb2-dma-contig: let mmap method to use dma_mmap_coherent call Tomasz Stanislawski
2012-06-06  7:53   ` Laurent Pinchart
2012-05-23 13:07 ` [PATCH 02/12] v4l: add buffer exporting via dmabuf Tomasz Stanislawski
2012-06-06  7:55   ` Laurent Pinchart
2012-05-23 13:07 ` [PATCH 03/12] v4l: vb2: " Tomasz Stanislawski
2012-06-06  7:42   ` Laurent Pinchart
2012-05-23 13:07 ` [PATCH 04/12] v4l: vb2-dma-contig: add setup of sglist for MMAP buffers Tomasz Stanislawski
2012-06-06  8:06   ` Laurent Pinchart
2012-06-06 11:56     ` Tomasz Stanislawski
2012-06-07  0:36       ` Laurent Pinchart
2012-06-07 14:28         ` Subash Patel
2012-06-08 14:31           ` Tomasz Stanislawski
2012-06-11  6:28             ` Laurent Pinchart
2012-06-11 22:38               ` Subash Patel
2012-05-23 13:07 ` [PATCH 05/12] v4l: vb2-dma-contig: add support for DMABUF exporting Tomasz Stanislawski
2012-05-23 13:07 ` [PATCH 06/12] v4l: vb2-dma-contig: add vmap/kmap for dmabuf exporting Tomasz Stanislawski
2012-05-23 13:07 ` [PATCH 07/12] v4l: s5p-fimc: support " Tomasz Stanislawski
2012-05-23 13:07 ` [PATCH 08/12] v4l: s5p-tv: mixer: " Tomasz Stanislawski
2012-05-23 13:07 ` [PATCH 09/12] v4l: s5p-mfc: " Tomasz Stanislawski
2012-05-23 13:07 ` [PATCH 10/12] v4l: vb2: remove vb2_mmap_pfn_range function Tomasz Stanislawski
2012-05-23 13:07 ` [PATCH 11/12] v4l: vb2-dma-contig: use sg_alloc_table_from_pages function Tomasz Stanislawski
2012-06-06  8:05   ` Laurent Pinchart [this message]
2012-05-23 13:07 ` [PATCH 12/12] v4l: vb2-dma-contig: Move allocation of dbuf attachment to attach cb 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=3795802.eekr7JsUpA@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=g.liakhovetski@gmx.de \
    --cc=hverkuil@xs4all.nl \
    --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=remi@remlab.net \
    --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).