From patchwork Wed Oct 10 14:46:26 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tomasz Stanislawski X-Patchwork-Id: 12116 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 2032224189 for ; Wed, 10 Oct 2012 14:51:18 +0000 (UTC) Received: from mail-ie0-f180.google.com (mail-ie0-f180.google.com [209.85.223.180]) by fiordland.canonical.com (Postfix) with ESMTP id 58A1CA190C9 for ; Wed, 10 Oct 2012 14:51:17 +0000 (UTC) Received: by mail-ie0-f180.google.com with SMTP id e10so997530iej.11 for ; Wed, 10 Oct 2012 07:51:16 -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:x-auditid :from:to:date:message-id:x-mailer:in-reply-to:references :x-brightmail-tracker:cc:subject:x-beenthere:x-mailman-version :precedence:list-id:list-unsubscribe:list-archive:list-post :list-help:list-subscribe:mime-version:content-type :content-transfer-encoding:sender:errors-to:x-gm-message-state; bh=GJyNkhesnfQIlLskTx+xkwgOKontEfwqKgeEpmbFte4=; b=RYSscUIwHDP+6fX/k4BCm1tB2NCq1kw+jYANlMqXssRbcnYt9gNuwxWiP9mWESHaxM eF0RkiUWEXP3Wn+qTWeWbO4L6C2KF/4nCvuKr3pahkY9qH1WJF3N75DHHBd1EgVF366r Vb5yw/9qVv6Brk0DFaUM40qUZNYXtfsevGNla2YUCZyR2XOTfLp0iuddKKGNNPK6UAEE GQQM4Yj5UqTyK6iyX6Snh4ZTiidQX9B1X17NvrroyGHFC0yA2O5h+0gjQSGVzjWOMcl9 +yX4no6NA18ZV/z7aLKauD3o6kQLejmdne2JrUL04eiws9W60cWjER7QspPVH/bEV0te ylKw== Received: by 10.50.152.137 with SMTP id uy9mr5434827igb.62.1349880676814; Wed, 10 Oct 2012 07:51:16 -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.50.67.148 with SMTP id n20csp235836igt; Wed, 10 Oct 2012 07:51:16 -0700 (PDT) Received: by 10.204.146.13 with SMTP id f13mr8175787bkv.29.1349880675364; Wed, 10 Oct 2012 07:51:15 -0700 (PDT) Received: from mombin.canonical.com (mombin.canonical.com. [91.189.95.16]) by mx.google.com with ESMTP id ie15si2788856bkc.105.2012.10.10.07.51.09; Wed, 10 Oct 2012 07:51: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 1TLxcq-0001Mh-Hw; Wed, 10 Oct 2012 14:51:08 +0000 Received: from mailout1.samsung.com ([203.254.224.24]) by mombin.canonical.com with esmtp (Exim 4.71) (envelope-from ) id 1TLxco-0001MU-Nv for linaro-mm-sig@lists.linaro.org; Wed, 10 Oct 2012 14:51:07 +0000 Received: from epcpsbgm2.samsung.com (epcpsbgm2 [203.254.230.27]) by mailout1.samsung.com (Oracle Communications Messaging Server 7u4-24.01(7.0.4.24.0) 64bit (built Nov 17 2011)) with ESMTP id <0MBO00M1UMKLT830@mailout1.samsung.com> for linaro-mm-sig@lists.linaro.org; Wed, 10 Oct 2012 23:51:04 +0900 (KST) X-AuditID: cbfee61b-b7f2b6d000000f14-77-50758b58fde1 Received: from epmmp1.local.host ( [203.254.227.16]) by epcpsbgm2.samsung.com (EPCPMTA) with SMTP id D2.2B.03860.85B85705; Wed, 10 Oct 2012 23:51:04 +0900 (KST) Received: from mcdsrvbld02.digital.local ([106.116.37.23]) by mmp1.samsung.com (Oracle Communications Messaging Server 7u4-24.01 (7.0.4.24.0) 64bit (built Nov 17 2011)) with ESMTPA id <0MBO002YDME0EC70@mmp1.samsung.com> for linaro-mm-sig@lists.linaro.org; Wed, 10 Oct 2012 23:51:04 +0900 (KST) From: Tomasz Stanislawski To: linux-media@vger.kernel.org, dri-devel@lists.freedesktop.org Date: Wed, 10 Oct 2012 16:46:26 +0200 Message-id: <1349880405-26049-8-git-send-email-t.stanislaws@samsung.com> X-Mailer: git-send-email 1.7.10 In-reply-to: <1349880405-26049-1-git-send-email-t.stanislaws@samsung.com> References: <1349880405-26049-1-git-send-email-t.stanislaws@samsung.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFnrCJMWRmVeSWpSXmKPExsVy+t9jAd2I7tIAg08nVCy+XHnI5MDocfvf Y+YAxigum5TUnMyy1CJ9uwSujC3XFjEXPJWp2Duxh6mB8bh4FyMnh4SAicSL/lfMELaYxIV7 69m6GLk4hAQWMUq8mjSBFcJZyyQxt3UvE0gVG1DHsSWfGUFsEQEHidN3ZzGDFDELrGGWeLHy BhtIQhgo0byshx3EZhFQlZhyug+sgVfAQ+Lw7i2sEOvkJZ7e7wOr5xTwlLgwbzrYGUJANf/X b2aawMi7gJFhFaNoakFyQXFSeq6RXnFibnFpXrpecn7uJkaw359J72Bc1WBxiFGAg1GJh7ci oyRAiDWxrLgy9xCjBAezkgivqU9pgBBvSmJlVWpRfnxRaU5q8SFGaQ4WJXHeZo+UACGB9MSS 1OzU1ILUIpgsEwenVANj8bI8Jbe0XdNf7PoZ/Oz7Bp8dD9T8bz9rKJkiwH7U7UTQ2nd/asts tvHGTxBTX7y81IWfeVlulc/pLP0UtcLEnZGa/Yetk+Yka+zNLt6mEmMhqvSD9wbD7QPvM6ub VhhoOlcc//3Lu05wRt984T9cwp5Ma6JjQpvcuViDVjFxHf35nfvjmvtKLMUZiYZazEXFiQBp BDZK9wEAAA== Cc: k.debski@samsung.com, s.nawrocki@samsung.com, pawel@osciak.com, sumit.semwal@ti.com, mchehab@redhat.com, robdclark@gmail.com, linaro-mm-sig@lists.linaro.org, kyungmin.park@samsung.com, laurent.pinchart@ideasonboard.com, airlied@redhat.com, remi@remlab.net Subject: [Linaro-mm-sig] [PATCHv10 07/26] 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: ALoCoQnbv6pxIAkxaZTVCqViDX6fGl25wHdbNIjR8oML0kXehoy36+xyr2DhzyKzGqvxcu6xQK56 From: Laurent Pinchart Group functions by buffer type. Signed-off-by: Laurent Pinchart Acked-by: Hans Verkuil --- drivers/media/v4l2-core/videobuf2-dma-contig.c | 92 ++++++++++++++---------- 1 file changed, 54 insertions(+), 38 deletions(-) diff --git a/drivers/media/v4l2-core/videobuf2-dma-contig.c b/drivers/media/v4l2-core/videobuf2-dma-contig.c index 20c95da..daac2b2 100644 --- a/drivers/media/v4l2-core/videobuf2-dma-contig.c +++ b/drivers/media/v4l2-core/videobuf2-dma-contig.c @@ -25,14 +25,56 @@ struct vb2_dc_conf { struct vb2_dc_buf { struct device *dev; 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; + + 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)) + return; + + dma_free_coherent(buf->dev, buf->size, buf->vaddr, buf->dma_addr); + kfree(buf); +} static void *vb2_dc_alloc(void *alloc_ctx, unsigned long size) { @@ -63,40 +105,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->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 NULL; - - 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 +118,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 +160,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,