From patchwork Thu Aug 1 02:25:16 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gurchetan Singh X-Patchwork-Id: 11070067 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id C900F14DB for ; Thu, 1 Aug 2019 02:25:36 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BBF3C283C5 for ; Thu, 1 Aug 2019 02:25:36 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B086A281B7; Thu, 1 Aug 2019 02:25:36 +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=-5.2 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, 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 67A4C281B7 for ; Thu, 1 Aug 2019 02:25:36 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 22B886E32C; Thu, 1 Aug 2019 02:25:35 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-pl1-x630.google.com (mail-pl1-x630.google.com [IPv6:2607:f8b0:4864:20::630]) by gabe.freedesktop.org (Postfix) with ESMTPS id C8B146E32C for ; Thu, 1 Aug 2019 02:25:33 +0000 (UTC) Received: by mail-pl1-x630.google.com with SMTP id i2so31413816plt.1 for ; Wed, 31 Jul 2019 19:25:33 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=RDvIT98WsFO1A5PQ+Bn6K/2QWwxhiilUGERAplpzShI=; b=R+wBVKCgasscXToa75B4XLI/nMmcyTr6MusOp3wx5NNQbxlUC733Sflp967OtqXZjD arUTS8oaCstehjwOpC50lFUVishPbWXcHOgEJTjrm2QLxCR342e0X86vFFMLbwxCU2rr qjWSOl5HYK7afNRZjE2xujFYmThi8javp+UIbHvBrhTpXj4vNKSQCOtGINoWYT9WAg/V 4trpueL0L/Z5+NZlK1l7+sLydLq+PWXzCg3PaVUkau6ff4Uo7+agS0SkeFZ72FM/pE9o CoDvnZpkicmh/+dxSuvPVREwiemWka/KtsQwh1LoVbEmN1LXT1WaUEea2jiFXofDS7Z4 3dyA== X-Gm-Message-State: APjAAAWO5K6Kr0JY6+eb97L4pWiZDrpuM62O/hN7TIH0+AwFl9jnXtqA VSgogpbEhgJS+5Tn5Sbfs2B1SvSspX4= X-Google-Smtp-Source: APXvYqyqIE6py30J7i0lRa2X7+ywni7gnB0WlXAB74Ovn29umnskJhTjJreAqc3Fya83sxLxQvx61Q== X-Received: by 2002:a17:902:ab83:: with SMTP id f3mr123239894plr.122.1564626332843; Wed, 31 Jul 2019 19:25:32 -0700 (PDT) Received: from gurchetansingh0.mtv.corp.google.com ([2620:15c:202:201:bc97:5740:52a7:6875]) by smtp.gmail.com with ESMTPSA id v184sm64911342pgd.34.2019.07.31.19.25.31 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 31 Jul 2019 19:25:32 -0700 (PDT) From: Gurchetan Singh To: dri-devel@lists.freedesktop.org Subject: [RFC 5/6] udmabuf: separate out creating/destroying scatter-table Date: Wed, 31 Jul 2019 19:25:16 -0700 Message-Id: <20190801022517.1903-6-gurchetansingh@chromium.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190801022517.1903-1-gurchetansingh@chromium.org> References: <20190801022517.1903-1-gurchetansingh@chromium.org> MIME-Version: 1.0 X-Mailman-Original-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=RDvIT98WsFO1A5PQ+Bn6K/2QWwxhiilUGERAplpzShI=; b=hYQMYIcex1tChcdz+V+2cHB1R1TDYmvDvHaNhx5Wyp9PT21EY8p9RhsUXKWImDT1fo rPQMrxiwwptBMp0p6teXmzMNDHJ7F0xF2/TVo2f/JX/Pki5Sut0vHreHoMlqWE0SGMsS vubg6a0KuANLkCEOdfvIQz1kduBIHUJ3e6D0I= X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kraxel@redhat.com, Gurchetan Singh Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP Reused later. Signed-off-by: Gurchetan Singh --- drivers/dma-buf/udmabuf.c | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/drivers/dma-buf/udmabuf.c b/drivers/dma-buf/udmabuf.c index 47003abbf4c2..5f8bee1862de 100644 --- a/drivers/dma-buf/udmabuf.c +++ b/drivers/dma-buf/udmabuf.c @@ -55,10 +55,10 @@ static int mmap_udmabuf(struct dma_buf *buf, struct vm_area_struct *vma) return 0; } -static struct sg_table *map_udmabuf(struct dma_buf_attachment *at, - enum dma_data_direction direction) +static struct sg_table *get_sg_table(struct device *dev, struct dma_buf *buf, + enum dma_data_direction direction) { - struct udmabuf *ubuf = at->dmabuf->priv; + struct udmabuf *ubuf = buf->priv; struct sg_table *sg; int ret; @@ -70,7 +70,7 @@ static struct sg_table *map_udmabuf(struct dma_buf_attachment *at, GFP_KERNEL); if (ret < 0) goto err; - if (!dma_map_sg(at->dev, sg->sgl, sg->nents, direction)) { + if (!dma_map_sg(dev, sg->sgl, sg->nents, direction)) { ret = -EINVAL; goto err; } @@ -82,13 +82,25 @@ static struct sg_table *map_udmabuf(struct dma_buf_attachment *at, return ERR_PTR(ret); } +static void put_sg_table(struct device *dev, struct sg_table *sg, + enum dma_data_direction direction) +{ + dma_unmap_sg(dev, sg->sgl, sg->nents, direction); + sg_free_table(sg); + kfree(sg); +} + +static struct sg_table *map_udmabuf(struct dma_buf_attachment *at, + enum dma_data_direction direction) +{ + return get_sg_table(at->dev, at->dmabuf, direction); +} + static void unmap_udmabuf(struct dma_buf_attachment *at, struct sg_table *sg, enum dma_data_direction direction) { - dma_unmap_sg(at->dev, sg->sgl, sg->nents, direction); - sg_free_table(sg); - kfree(sg); + return put_sg_table(at->dev, sg, direction); } static void release_udmabuf(struct dma_buf *buf)