From patchwork Tue Jul 27 12:21:40 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Figo.zhang" X-Patchwork-Id: 114520 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 o6RCNDKq027669 for ; Tue, 27 Jul 2010 12:23:13 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753636Ab0G0MXM (ORCPT ); Tue, 27 Jul 2010 08:23:12 -0400 Received: from mail-pw0-f46.google.com ([209.85.160.46]:34781 "EHLO mail-pw0-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752425Ab0G0MXL (ORCPT ); Tue, 27 Jul 2010 08:23:11 -0400 Received: by pwi5 with SMTP id 5so404545pwi.19 for ; Tue, 27 Jul 2010 05:23:11 -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=6MsA1uBl+Qz03MYKxVp8GyJgKNKwvUbLaMprzNxmiSc=; b=OorIXjSv4MygaCeOS9fad+t9XW7mNTsndLgY20blqXJRz0yScNARrhOZXmIY19QHYw +Ds6bVcjcqehei9pGH2/e69VPw29f9qvEnnDxMDjgZowxvcU0ary7VOMfaNQXpqBzeAk 24Ct+FdqtKR5lVosJtR8PbtHvghK8IbVwoanY= 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=HG8SvQSvVJl9pwJnMll77SuSJwANFMWtXHuiuEUgX2tciJWI4CNOE+nyO3anNGtBSA epwFC4/+DIYHNWIiVbuxH/0nGrMJWpaaJkfU1Ag+dVk58BzcSVUJB0a9BLN5te3s28LV XIDEhdQE26pLuujDOst6ydD5+fp6+LvcRD5UM= Received: by 10.114.59.15 with SMTP id h15mr9752157waa.186.1280233391129; Tue, 27 Jul 2010 05:23:11 -0700 (PDT) Received: from [192.168.1.100] ([118.133.169.28]) by mx.google.com with ESMTPS id s5sm8751402wak.12.2010.07.27.05.23.07 (version=SSLv3 cipher=RC4-MD5); Tue, 27 Jul 2010 05:23:10 -0700 (PDT) Subject: [PATCH]videobuf_dma_sg: a new implementation for mmap From: "Figo.zhang" To: Mauro Carvalho Chehab , Mauro Carvalho Chehab Cc: linux-media , Laurent Pinchart Date: Tue, 27 Jul 2010 20:21:40 +0800 Message-ID: <1280233300.2628.8.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]); Tue, 27 Jul 2010 12:23:13 +0000 (UTC) diff --git a/drivers/media/video/videobuf-dma-sg.c b/drivers/media/video/videobuf-dma-sg.c index 8359e6b..c9a8817 100644 --- a/drivers/media/video/videobuf-dma-sg.c +++ b/drivers/media/video/videobuf-dma-sg.c @@ -397,16 +397,44 @@ 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) + page = vmalloc_to_page(mem->dma.vmalloc+ + (offset & (~PAGE_MASK))); + if (mem->dma.pages) + page = mem->dma.pages[page_nr]; + mutex_unlock(&q->vb_lock); + vmf->page = page;