public inbox for linux-media@vger.kernel.org
 help / color / mirror / Atom feed
From: "Figo.zhang" <figo1802@gmail.com>
To: Mauro Carvalho Chehab <mchehab@infradead.org>
Cc: Mauro Carvalho Chehab <mchehab@redhat.com>,
	linux-media <linux-media@vger.kernel.org>,
	Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Subject: Re: [PATCH v2]videobuf_dma_sg: a new implementation for mmap
Date: Thu, 29 Jul 2010 21:38:17 +0800	[thread overview]
Message-ID: <1280410697.13781.22.camel@localhost.localdomain> (raw)
In-Reply-To: <1280322504.13781.7.camel@localhost.localdomain>

hi Laurent,
would you like to test this patch?

btw, why i send the patch , patchwork websit display a part of my patch?
https://patchwork.kernel.org/patch/114760/

Best,
Figo.zhang

On Wed, 2010-07-28 at 21:08 +0800, Figo.zhang wrote:
> a mmap issue for videobuf-dma-sg: it will alloc a new page for mmaping
> when it encounter page fault at video_vm_ops->fault().
> 
> a new implementation for mmap, it translate the vmalloc to page at
> video_vm_ops->fault().
> 
> in v2, if mem->dma.vmalloc is NULL at video_vm_ops->fault(), it will
> alloc memory by vmalloc_32().
> 
> Signed-off-by: Figo.zhang <figo1802@gmail.com>
> ---
> drivers/media/video/videobuf-dma-sg.c |   51
> +++++++++++++++++++++++++++------
>  1 files changed, 42 insertions(+), 9 deletions(-)
> 
> diff --git a/drivers/media/video/videobuf-dma-sg.c
> b/drivers/media/video/videobuf-dma-sg.c
> index 8359e6b..767483d 100644
> --- a/drivers/media/video/videobuf-dma-sg.c
> +++ b/drivers/media/video/videobuf-dma-sg.c
> @@ -201,10 +201,11 @@ int videobuf_dma_init_kernel(struct
> videobuf_dmabuf *dma, int direction,
>  	dprintk(1, "init kernel [%d pages]\n", nr_pages);
>  
>  	dma->direction = direction;
> -	dma->vmalloc = vmalloc_32(nr_pages << PAGE_SHIFT);
> -	if (NULL == dma->vmalloc) {
> -		dprintk(1, "vmalloc_32(%d pages) failed\n", nr_pages);
> -		return -ENOMEM;
> +	if (!dma->vmalloc)
> +		dma->vmalloc = vmalloc_32(nr_pages << PAGE_SHIFT);
> +		if (NULL == dma->vmalloc) {
> +			dprintk(1, "vmalloc_32(%d pages) failed\n", nr_pages);
> +			return -ENOMEM;
>  	}
>  
>  	dprintk(1, "vmalloc is at addr 0x%08lx, size=%d\n",
> @@ -397,16 +398,48 @@ static void videobuf_vm_close(struct
> vm_area_struct *vma)
>   */
>  static int videobuf_vm_fault(struct vm_area_struct *vma, struct
> vm_fault *vmf)
>  {
> -	struct page *page;
> +	struct page *page = NULL;
> +	struct videobuf_mapping *map = vma->vm_private_data;
> +	struct videobuf_queue *q = map->q;
> +	struct videobuf_dma_sg_memory *mem = NULL;
> +
> +	unsigned long offset;
> +	unsigned long page_nr;
> +	int first;
>  
>  	dprintk(3, "fault: fault @ %08lx [vma %08lx-%08lx]\n",
>  		(unsigned long)vmf->virtual_address,
>  		vma->vm_start, vma->vm_end);
>  
> -	page = alloc_page(GFP_USER | __GFP_DMA32);
> -	if (!page)
> -		return VM_FAULT_OOM;
> -	clear_user_highpage(page, (unsigned long)vmf->virtual_address);
> +	mutex_lock(&q->vb_lock);
> +
> +	offset = (unsigned long)vmf->virtual_address - vma->vm_start;
> +	page_nr = offset >> PAGE_SHIFT;
> +
> +	for (first = 0; first < VIDEO_MAX_FRAME; first++) {
> +			if (NULL == q->bufs[first])
> +				continue;
> +
> +			MAGIC_CHECK(mem->magic, MAGIC_SG_MEM);
> +
> +			if (q->bufs[first]->map == map)
> +				break;
> +	}
> +
> +	mem = q->bufs[first]->priv;
> +	if (!mem)
> +		return VM_FAULT_SIGBUS;
> +	if (!mem->dma.vmalloc) {
> +		mem->dma.vmalloc = vmalloc_32(PAGE_ALIGN(q->bufs[first]->size));
> +		if (NULL == mem->dma.vmalloc) {
> +			dprintk(1, "%s: vmalloc_32() failed\n", __func__);
> +			return VM_FAULT_OOM;
> +		}
> +	} else
> +		page = vmalloc_to_page(mem->dma.vmalloc+
> +				(offset & (~PAGE_MASK)));
> +	mutex_unlock(&q->vb_lock);
> +
>  	vmf->page = page;
>  
>  	return 0;
> 



  reply	other threads:[~2010-07-29 13:39 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-07-27 12:21 [PATCH]videobuf_dma_sg: a new implementation for mmap Figo.zhang
2010-07-28  9:13 ` Laurent Pinchart
2010-07-28 12:57 ` [PATCH v2]videobuf_dma_sg: " Figo.zhang
2010-07-28 13:08   ` Figo.zhang
2010-07-29 13:38     ` Figo.zhang [this message]
2010-07-29 16:41       ` Mauro Carvalho Chehab
2010-07-29 17:00     ` Laurent Pinchart

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=1280410697.13781.22.camel@localhost.localdomain \
    --to=figo1802@gmail.com \
    --cc=laurent.pinchart@ideasonboard.com \
    --cc=linux-media@vger.kernel.org \
    --cc=mchehab@infradead.org \
    --cc=mchehab@redhat.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