From patchwork Tue Oct 2 14:27:18 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tomasz Stanislawski X-Patchwork-Id: 11928 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 546981A52FC for ; Tue, 2 Oct 2012 14:28:53 +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 E0987A186EC for ; Tue, 2 Oct 2012 14:28:52 +0000 (UTC) Received: by mail-ie0-f180.google.com with SMTP id e10so14258231iej.11 for ; Tue, 02 Oct 2012 07:28:52 -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=WaTLYViqlxec3oKockccDnJU4hshzkEspFWoRFECqRw=; b=KJFlVWB0TRRqz++jKFfheeuQ9zzmfpnKlfVzS+RiIrUI5h0vNyLcVJELj6IsaDwJqU ER33Soy0nYk6tiPDTBI0HKkoyIDkpXRJAx5vEMy/+cgRSzeCqZ0hBWVI4FbtUz9Wf7xz wxvCcUKpccHYs+JIr2/cZ6FricavvIAjztJHiUeRlzN/rvH4F1GEKTxVf0SO3eWA4xT5 icfVYqxGzMh138MPSapatWX7RNTeqsmTkF3kkz2oGctv2aZdMDXL+l83xIVq+rypvMJx I7tNdF6qz3DJ8T6AjHE+Jlae8LJqM6tr1BvguCw3RpHMOKrEKYpbPjHgx24+GRqbZgQT P6Zw== Received: by 10.50.0.193 with SMTP id 1mr9062316igg.0.1349188132673; Tue, 02 Oct 2012 07:28:52 -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.184.232 with SMTP id ex8csp84961igc; Tue, 2 Oct 2012 07:28:51 -0700 (PDT) Received: by 10.204.9.4 with SMTP id j4mr6862085bkj.22.1349188131022; Tue, 02 Oct 2012 07:28:51 -0700 (PDT) Received: from mombin.canonical.com (mombin.canonical.com. [91.189.95.16]) by mx.google.com with ESMTP id io2si1700371bkc.62.2012.10.02.07.28.49; Tue, 02 Oct 2012 07:28:50 -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 1TJ3Sq-0004bt-Q1; Tue, 02 Oct 2012 14:28:48 +0000 Received: from mailout3.samsung.com ([203.254.224.33]) by mombin.canonical.com with esmtp (Exim 4.71) (envelope-from ) id 1TJ3So-0004aq-0G for linaro-mm-sig@lists.linaro.org; Tue, 02 Oct 2012 14:28:46 +0000 Received: from epcpsbgm1.samsung.com (epcpsbgm1 [203.254.230.26]) by mailout3.samsung.com (Oracle Communications Messaging Server 7u4-24.01(7.0.4.24.0) 64bit (built Nov 17 2011)) with ESMTP id <0MB9001EIS7W8CE0@mailout3.samsung.com> for linaro-mm-sig@lists.linaro.org; Tue, 02 Oct 2012 23:28:44 +0900 (KST) X-AuditID: cbfee61a-b7f726d000000ec7-fc-506afa1cccf9 Received: from epmmp2 ( [203.254.227.17]) by epcpsbgm1.samsung.com (EPCPMTA) with SMTP id DD.8E.03783.C1AFA605; Tue, 02 Oct 2012 23:28:44 +0900 (KST) Received: from mcdsrvbld02.digital.local ([106.116.37.23]) by mmp2.samsung.com (Oracle Communications Messaging Server 7u4-24.01 (7.0.4.24.0) 64bit (built Nov 17 2011)) with ESMTPA id <0MB9005A7S65K790@mmp2.samsung.com> for linaro-mm-sig@lists.linaro.org; Tue, 02 Oct 2012 23:28:44 +0900 (KST) From: Tomasz Stanislawski To: linux-media@vger.kernel.org, dri-devel@lists.freedesktop.org Date: Tue, 02 Oct 2012 16:27:18 +0200 Message-id: <1349188056-4886-8-git-send-email-t.stanislaws@samsung.com> X-Mailer: git-send-email 1.7.10 In-reply-to: <1349188056-4886-1-git-send-email-t.stanislaws@samsung.com> References: <1349188056-4886-1-git-send-email-t.stanislaws@samsung.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFnrEJMWRmVeSWpSXmKPExsVy+t9jQV2ZX1kBBnePmlp8ufKQyYHR4/a/ x8wBjFFcNimpOZllqUX6dglcGbd397EULJGpOLOfr4GxW7yLkZNDQsBEYuKMX4wQtpjEhXvr 2boYuTiEBKYzSnw49JERwlnLJDF743cmkCo2oI5jSz6DdYgIOEicvjuLGaSIWWANs8SLlTeA 2jk4hAXsJZbeygSpYRFQlTiwuZMVxOYVcJf49eAg1DZ5iaf3+9hAbE4BD4mfTy6wgNhCQDV7 ljexTWDkXcDIsIpRNLUguaA4KT3XUK84Mbe4NC9dLzk/dxMj2OfPpHYwrmywOMQowMGoxMO7 82RmgBBrYllxZe4hRgkOZiURXuv7WQFCvCmJlVWpRfnxRaU5qcWHGKU5WJTEeZs9UgKEBNIT S1KzU1MLUotgskwcnFINjIUVRc2OX9I2TV7/VlPg8AvrW9ek+u84s+ht/RHH9D931wIer0yx 4OjN7CsdpTctUGsvMn830UDryuF138wyV05z38I94enfaQFX1n19v89AwulVwb7jD7SbjfoO xfrE3PVmid6Tvtfio+/cBc83B781WpptMsHOp2ytU7H6a80395rXPcyesVCJpTgj0VCLuag4 EQDVoB0P9QEAAA== 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] [PATCHv9 07/25] 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: ALoCoQnwPQa3O57QAaT9QAKNHyNaBvFsWs8OsrAKNCHtcTbrLLdSz2QUUNTYjhxTXOi4LKO3d2mr From: Laurent Pinchart Group functions by buffer type. Signed-off-by: Laurent Pinchart --- drivers/media/video/videobuf2-dma-contig.c | 92 ++++++++++++++++------------ 1 file changed, 54 insertions(+), 38 deletions(-) diff --git a/drivers/media/video/videobuf2-dma-contig.c b/drivers/media/video/videobuf2-dma-contig.c index 20c95da..daac2b2 100644 --- a/drivers/media/video/videobuf2-dma-contig.c +++ b/drivers/media/video/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,