From patchwork Fri Jul 30 00:08:02 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Figo.zhang" X-Patchwork-Id: 115348 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter.kernel.org (8.14.4/8.14.3) with ESMTP id o6U09ghK021150 for ; Fri, 30 Jul 2010 00:09:42 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755368Ab0G3AJl (ORCPT ); Thu, 29 Jul 2010 20:09:41 -0400 Received: from mail-gy0-f174.google.com ([209.85.160.174]:34778 "EHLO mail-gy0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755180Ab0G3AJk (ORCPT ); Thu, 29 Jul 2010 20:09:40 -0400 Received: by gyg10 with SMTP id 10so371566gyg.19 for ; Thu, 29 Jul 2010 17:09:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:subject:from:to:cc :content-type:date:message-id:mime-version:x-mailer :content-transfer-encoding; bh=Nav8ISx+h/m9p4xH72k7cWG2LtvwnYYSUnfwKRzUf4s=; b=b+7WL0XsESKZw0PtCLDrts3FxUOPZ6DdXXMQls3fkZC7XizOK3WMPvUA1+OUG3TpXi be7i508iA8swViTUkgHrZZBdPNDG7RL/7cNcMfCsCuJ+1DQdgFGCFeK8Z5CmyZITA7lS yWjuAm2XQ3UeD9NJH7jF+vmbAfNjyGULZ7PyU= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=subject:from:to:cc:content-type:date:message-id:mime-version :x-mailer:content-transfer-encoding; b=Goh55m5K9UYM9dMJqB6VjFuXahmiLL0ZWsL7FVXYgHRphwmVxzuHK4sptVjz3rflh/ 1/vKkj9/OYgF2j9cTDSXyZhCvl2w8ftBMdn7iM49mzdD1Rd+dPK8Bto80EAw5GQJnjhK YASed8B5Ooei3hCd5GhLeyDp+xhrTfcqtRC3c= Received: by 10.150.31.17 with SMTP id e17mr2109591ybe.48.1280448580006; Thu, 29 Jul 2010 17:09:40 -0700 (PDT) Received: from [192.168.1.100] ([118.133.169.28]) by mx.google.com with ESMTPS id e32sm1782195qcg.34.2010.07.29.17.09.36 (version=SSLv3 cipher=RC4-MD5); Thu, 29 Jul 2010 17:09:38 -0700 (PDT) Subject: [PATCH v2]Resend:videobuf_dma_sg: a new implementation for mmap From: "Figo.zhang" To: Mauro Carvalho Chehab , "max.song" Cc: linux-media , Laurent Pinchart Date: Fri, 30 Jul 2010 08:08:02 +0800 Message-ID: <1280448482.2648.2.camel@localhost.localdomain> Mime-Version: 1.0 X-Mailer: Evolution 2.30.2 Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.3 (demeter.kernel.org [140.211.167.41]); Fri, 30 Jul 2010 00:09:43 +0000 (UTC) diff --git a/drivers/media/video/videobuf-dma-sg.c b/drivers/media/video/videobuf-dma-sg.c index 8359e6b..f7295da 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,47 @@ 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;