From patchwork Thu Mar 22 10:02:21 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 7402 Return-Path: X-Original-To: patchwork@peony.canonical.com Delivered-To: patchwork@peony.canonical.com Received: from fiordland.canonical.com (fiordland.canonical.com [91.189.94.145]) by peony.canonical.com (Postfix) with ESMTP id 22A5823DEA for ; Thu, 22 Mar 2012 10:02:21 +0000 (UTC) Received: from mail-iy0-f180.google.com (mail-iy0-f180.google.com [209.85.210.180]) by fiordland.canonical.com (Postfix) with ESMTP id DE02FA183ED for ; Thu, 22 Mar 2012 10:02:20 +0000 (UTC) Received: by mail-iy0-f180.google.com with SMTP id e36so3827723iag.11 for ; Thu, 22 Mar 2012 03:02:20 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-forwarded-to:x-forwarded-for:delivered-to:received-spf:from:to :date:message-id:x-mailer:in-reply-to:references:cc:subject :x-beenthere:x-mailman-version:precedence:list-id:list-unsubscribe :list-archive:list-post:list-help:list-subscribe:mime-version:sender :errors-to:x-gm-message-state:content-type:content-transfer-encoding; bh=x2Prb/xx1uLJDtFsesEhG/aurZMydS/lhyCOYtRxVrE=; b=DlwdtRSQPcfTj6CvuoQoULzM3iW5509Cmjk+cPTYCFpYWdVkGylwzqMzGhTiGmTlqL HA7taYwWN8n/atPbTEvwRUcQp78E+XWye7CjJec9L1w/6GE9RZCAWfJ8u+VFHUo0aYi5 RAo0kxfqQ0mtZ0P8aCOMeIbmIFPbrwoEGKvcN71qahVgnu5T7nQa0KfHbr89lg5DRXNE UYzBnefJ/EdgyC0FgVYWB6i+w8bnhWdO8PCtvVv9qtwiggkAlp9KbV9rOYxJl6Y92g6n nfdgtZEb21Sn+l1Jb+COymwsenNatzh8Vp8zyQf5MjYtNWz1QxoUBAKAqzQs5JJJQIFQ GR2Q== Received: by 10.50.47.231 with SMTP id g7mr875980ign.12.1332410540600; Thu, 22 Mar 2012 03:02:20 -0700 (PDT) X-Forwarded-To: linaro-patchwork@canonical.com X-Forwarded-For: patch@linaro.org linaro-patchwork@canonical.com Delivered-To: patches@linaro.org Received: by 10.231.203.79 with SMTP id fh15csp43649ibb; Thu, 22 Mar 2012 03:02:20 -0700 (PDT) Received: by 10.180.24.4 with SMTP id q4mr3513509wif.7.1332410535069; Thu, 22 Mar 2012 03:02:15 -0700 (PDT) Received: from mombin.canonical.com (mombin.canonical.com. [91.189.95.16]) by mx.google.com with ESMTP id fi7si1514872wib.21.2012.03.22.03.02.13; Thu, 22 Mar 2012 03:02:15 -0700 (PDT) Received-SPF: neutral (google.com: 91.189.95.16 is neither permitted nor denied by best guess record for domain of linaro-mm-sig-bounces@lists.linaro.org) client-ip=91.189.95.16; Authentication-Results: mx.google.com; spf=neutral (google.com: 91.189.95.16 is neither permitted nor denied by best guess record for domain of linaro-mm-sig-bounces@lists.linaro.org) smtp.mail=linaro-mm-sig-bounces@lists.linaro.org Received: from localhost ([127.0.0.1] helo=mombin.canonical.com) by mombin.canonical.com with esmtp (Exim 4.71) (envelope-from ) id 1SAeqS-00075W-Tk; Thu, 22 Mar 2012 10:02:13 +0000 Received: from perceval.ideasonboard.com ([95.142.166.194]) by mombin.canonical.com with esmtp (Exim 4.71) (envelope-from ) id 1SAeqR-00074a-RA for linaro-mm-sig@lists.linaro.org; Thu, 22 Mar 2012 10:02:11 +0000 Received: from localhost.localdomain (ptr-91-87-217-68.mobistar.be [91.87.217.68]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 83716362D5; Thu, 22 Mar 2012 11:02:07 +0100 (CET) From: Laurent Pinchart To: Tomasz Stanislawski Date: Thu, 22 Mar 2012 11:02:21 +0100 Message-Id: <1332410543-14433-2-git-send-email-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 1.7.3.4 In-Reply-To: <5187420.ORugDzE4Gp@avalon> References: <5187420.ORugDzE4Gp@avalon> Cc: sumit.semwal@ti.com, robdclark@gmail.com, dri-devel@lists.freedesktop.org, linaro-mm-sig@lists.linaro.org, kyungmin.park@samsung.com, sakari.ailus@iki.fi, Andrzej Pietrasiewicz , airlied@redhat.com, Kamil Debski Subject: [Linaro-mm-sig] [RFCv2 PATCH 2/9 - 2/4] v4l: vb2-dma-contig: Reorder functions X-BeenThere: linaro-mm-sig@lists.linaro.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: "Unified memory management interest group." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: linaro-mm-sig-bounces@lists.linaro.org Errors-To: linaro-mm-sig-bounces@lists.linaro.org X-Gm-Message-State: ALoCoQm4s8IUXMIoEiKXpQgRO6JDIsfPVVziXkApdiFAFxAfV7YcjIolfdA+RzOkVCkOp3vR6RDQ Group functions by buffer type. Signed-off-by: Laurent Pinchart --- drivers/media/video/videobuf2-dma-contig.c | 94 ++++++++++++++++----------- 1 files changed, 56 insertions(+), 38 deletions(-) diff --git a/drivers/media/video/videobuf2-dma-contig.c b/drivers/media/video/videobuf2-dma-contig.c index 5207eb1..6bc4651 100644 --- a/drivers/media/video/videobuf2-dma-contig.c +++ b/drivers/media/video/videobuf2-dma-contig.c @@ -24,14 +24,58 @@ struct vb2_dc_conf { struct vb2_dc_buf { struct vb2_dc_conf *conf; void *vaddr; - dma_addr_t dma_addr; unsigned long size; - struct vm_area_struct *vma; - atomic_t refcount; + dma_addr_t dma_addr; + + /* MMAP related */ struct vb2_vmarea_handler handler; + atomic_t refcount; + + /* USERPTR related */ + struct vm_area_struct *vma; }; -static void vb2_dc_put(void *buf_priv); +/*********************************************/ +/* callbacks for all buffers */ +/*********************************************/ + +static void *vb2_dc_cookie(void *buf_priv) +{ + struct vb2_dc_buf *buf = buf_priv; + + return &buf->dma_addr; +} + +static void *vb2_dc_vaddr(void *buf_priv) +{ + struct vb2_dc_buf *buf = buf_priv; + if (!buf) + return 0; + + return buf->vaddr; +} + +static unsigned int vb2_dc_num_users(void *buf_priv) +{ + struct vb2_dc_buf *buf = buf_priv; + + return atomic_read(&buf->refcount); +} + +/*********************************************/ +/* callbacks for MMAP buffers */ +/*********************************************/ + +static void vb2_dc_put(void *buf_priv) +{ + struct vb2_dc_buf *buf = buf_priv; + + if (atomic_dec_and_test(&buf->refcount)) { + dma_free_coherent(buf->conf->dev, buf->size, buf->vaddr, + buf->dma_addr); + kfree(buf); + } +} static void *vb2_dc_alloc(void *alloc_ctx, unsigned long size) { @@ -63,40 +107,6 @@ static void *vb2_dc_alloc(void *alloc_ctx, unsigned long size) return buf; } -static void vb2_dc_put(void *buf_priv) -{ - struct vb2_dc_buf *buf = buf_priv; - - if (atomic_dec_and_test(&buf->refcount)) { - dma_free_coherent(buf->conf->dev, buf->size, buf->vaddr, - buf->dma_addr); - kfree(buf); - } -} - -static void *vb2_dc_cookie(void *buf_priv) -{ - struct vb2_dc_buf *buf = buf_priv; - - return &buf->dma_addr; -} - -static void *vb2_dc_vaddr(void *buf_priv) -{ - struct vb2_dc_buf *buf = buf_priv; - if (!buf) - return 0; - - return buf->vaddr; -} - -static unsigned int vb2_dc_num_users(void *buf_priv) -{ - struct vb2_dc_buf *buf = buf_priv; - - return atomic_read(&buf->refcount); -} - static int vb2_dc_mmap(void *buf_priv, struct vm_area_struct *vma) { struct vb2_dc_buf *buf = buf_priv; @@ -110,6 +120,10 @@ static int vb2_dc_mmap(void *buf_priv, struct vm_area_struct *vma) &vb2_common_vm_ops, &buf->handler); } +/*********************************************/ +/* callbacks for USERPTR buffers */ +/*********************************************/ + static void *vb2_dc_get_userptr(void *alloc_ctx, unsigned long vaddr, unsigned long size, int write) { @@ -148,6 +162,10 @@ static void vb2_dc_put_userptr(void *mem_priv) kfree(buf); } +/*********************************************/ +/* DMA CONTIG exported functions */ +/*********************************************/ + const struct vb2_mem_ops vb2_dma_contig_memops = { .alloc = vb2_dc_alloc, .put = vb2_dc_put,