From patchwork Thu Apr 13 07:57:12 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sakari Ailus X-Patchwork-Id: 9679181 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 54DFC60326 for ; Thu, 13 Apr 2017 11:17:27 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4970124560 for ; Thu, 13 Apr 2017 11:17:27 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3DDC528471; Thu, 13 Apr 2017 11:17:27 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.2 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 45CF524560 for ; Thu, 13 Apr 2017 11:17:26 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 9BCD46E85B; Thu, 13 Apr 2017 11:17:08 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) by gabe.freedesktop.org (Postfix) with ESMTPS id D965D6E7E1 for ; Thu, 13 Apr 2017 07:58:01 +0000 (UTC) Received: from orsmga001.jf.intel.com ([10.7.209.18]) by orsmga102.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 13 Apr 2017 00:58:01 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos; i="5.37,194,1488873600"; d="scan'208"; a="1118967527" Received: from paasikivi.fi.intel.com ([10.237.72.42]) by orsmga001.jf.intel.com with ESMTP; 13 Apr 2017 00:57:58 -0700 Received: from nauris.fi.intel.com (nauris.localdomain [192.168.240.2]) by paasikivi.fi.intel.com (Postfix) with ESMTP id B62D52115B; Thu, 13 Apr 2017 10:57:54 +0300 (EEST) Received: by nauris.fi.intel.com (Postfix, from userid 1000) id 3470D201AB; Thu, 13 Apr 2017 10:57:20 +0300 (EEST) From: Sakari Ailus To: linux-media@vger.kernel.org Subject: [RFC v3 07/14] vb2: dma-contig: Remove redundant sgt_base field Date: Thu, 13 Apr 2017 10:57:12 +0300 Message-Id: <1492070239-21532-8-git-send-email-sakari.ailus@linux.intel.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1492070239-21532-1-git-send-email-sakari.ailus@linux.intel.com> References: <1492070239-21532-1-git-send-email-sakari.ailus@linux.intel.com> X-Mailman-Approved-At: Thu, 13 Apr 2017 11:17:04 +0000 Cc: daniel.vetter@ffwll.ch, dri-devel@lists.freedesktop.org, hverkuil@xs4all.nl, kyungmin.park@samsung.com, posciak@chromium.org, m.szyprowski@samsung.com X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP The struct vb2_dc_buf contains two struct sg_table fields: sgt_base and dma_sgt. The former is used by DMA-BUF buffers whereas the latter is used by USERPTR. Unify the two, leaving dma_sgt. MMAP buffers do not need cache flushing since they have been allocated using dma_alloc_coherent(). Signed-off-by: Sakari Ailus Acked-by: Hans Verkuil --- drivers/media/v4l2-core/videobuf2-dma-contig.c | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/drivers/media/v4l2-core/videobuf2-dma-contig.c b/drivers/media/v4l2-core/videobuf2-dma-contig.c index a8a46a8..ddbbcf0 100644 --- a/drivers/media/v4l2-core/videobuf2-dma-contig.c +++ b/drivers/media/v4l2-core/videobuf2-dma-contig.c @@ -31,12 +31,13 @@ struct vb2_dc_buf { unsigned long attrs; enum dma_data_direction dma_dir; struct sg_table *dma_sgt; - struct frame_vector *vec; /* MMAP related */ struct vb2_vmarea_handler handler; refcount_t refcount; - struct sg_table *sgt_base; + + /* USERPTR related */ + struct frame_vector *vec; /* DMABUF related */ struct dma_buf_attachment *db_attach; @@ -96,7 +97,7 @@ static void vb2_dc_prepare(void *buf_priv) struct sg_table *sgt = buf->dma_sgt; /* DMABUF exporter will flush the cache for us */ - if (!sgt || buf->db_attach) + if (!buf->vec) return; dma_sync_sg_for_device(buf->dev, sgt->sgl, sgt->orig_nents, @@ -109,7 +110,7 @@ static void vb2_dc_finish(void *buf_priv) struct sg_table *sgt = buf->dma_sgt; /* DMABUF exporter will flush the cache for us */ - if (!sgt || buf->db_attach) + if (!buf->vec) return; dma_sync_sg_for_cpu(buf->dev, sgt->sgl, sgt->orig_nents, buf->dma_dir); @@ -126,9 +127,9 @@ static void vb2_dc_put(void *buf_priv) if (!refcount_dec_and_test(&buf->refcount)) return; - if (buf->sgt_base) { - sg_free_table(buf->sgt_base); - kfree(buf->sgt_base); + if (buf->dma_sgt) { + sg_free_table(buf->dma_sgt); + kfree(buf->dma_sgt); } dma_free_attrs(buf->dev, buf->size, buf->cookie, buf->dma_addr, buf->attrs); @@ -239,13 +240,13 @@ static int vb2_dc_dmabuf_ops_attach(struct dma_buf *dbuf, struct device *dev, /* Copy the buf->base_sgt scatter list to the attachment, as we can't * map the same scatter list to multiple attachments at the same time. */ - ret = sg_alloc_table(sgt, buf->sgt_base->orig_nents, GFP_KERNEL); + ret = sg_alloc_table(sgt, buf->dma_sgt->orig_nents, GFP_KERNEL); if (ret) { kfree(attach); return -ENOMEM; } - rd = buf->sgt_base->sgl; + rd = buf->dma_sgt->sgl; wr = sgt->sgl; for (i = 0; i < sgt->orig_nents; ++i) { sg_set_page(wr, sg_page(rd), rd->length, rd->offset); @@ -396,10 +397,10 @@ static struct dma_buf *vb2_dc_get_dmabuf(void *buf_priv, unsigned long flags) exp_info.flags = flags; exp_info.priv = buf; - if (!buf->sgt_base) - buf->sgt_base = vb2_dc_get_base_sgt(buf); + if (!buf->dma_sgt) + buf->dma_sgt = vb2_dc_get_base_sgt(buf); - if (WARN_ON(!buf->sgt_base)) + if (WARN_ON(!buf->dma_sgt)) return NULL; dbuf = dma_buf_export(&exp_info);