From patchwork Tue Dec 3 01:36:26 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gurchetan Singh X-Patchwork-Id: 11270139 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 63AB9921 for ; Tue, 3 Dec 2019 01:36:45 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 4CAD1206E1 for ; Tue, 3 Dec 2019 01:36:45 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 4CAD1206E1 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=chromium.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=dri-devel-bounces@lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 0DAF56E147; Tue, 3 Dec 2019 01:36:44 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-pl1-x644.google.com (mail-pl1-x644.google.com [IPv6:2607:f8b0:4864:20::644]) by gabe.freedesktop.org (Postfix) with ESMTPS id 2B62E6E25D for ; Tue, 3 Dec 2019 01:36:42 +0000 (UTC) Received: by mail-pl1-x644.google.com with SMTP id ay6so941735plb.0 for ; Mon, 02 Dec 2019 17:36:42 -0800 (PST) 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=LICdhzdPL2HSftzAOCs7MLzTsFAWvzORdwz9P5dMvlA=; b=XG1qgn4uWMkiaxS1c8hTrYV13BAwXhykUQNUebcPsVsod/PweiUzjIp+Er5m3gEleJ 1PZj6jJ4kHaxYsrfQragEXDkJF5kgNuysGHdge7PjGge2IqQ4J4Q7sFpOrOgcYva1Gv8 EAlzYBq6slyJbMqdJ2ZlsMkEe5sZKFYCNn6z5M6P2gjzwC7x1LnJcwxkGMRopev63++5 dxmexVqj5q5ODjl1ym+lbFYE/PP7fg8oVM7Q6rzPFzbyRP1N8yVS8vjfTjXFFHU+cqlZ gGfuX/eXr6pBJfrM/Ap3KOhlyIBKp7oyEa/2CK6jp+8FD/7K8TF5Un2WUWD7kLAWqKBI hq5g== X-Gm-Message-State: APjAAAUtL5dR5SRyiOb25K0ovIZGscVcxWG0gjQA8Kqlnqx8iVMEELI5 xxaa7ptJGAqDgtZC/ryt+2eaREhqJ0g= X-Google-Smtp-Source: APXvYqxDfa5iKKsbrpvlvX8fhBHYdMswm4nGazoq4NlHIq8ZBJKRQMMTPcxGZCscL0e+sbekHGdS3A== X-Received: by 2002:a17:902:7b82:: with SMTP id w2mr2420352pll.92.1575337001558; Mon, 02 Dec 2019 17:36:41 -0800 (PST) Received: from gurchetansingh0.mtv.corp.google.com ([2620:15c:202:201:bc97:5740:52a7:6875]) by smtp.gmail.com with ESMTPSA id r4sm581916pji.11.2019.12.02.17.36.40 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 02 Dec 2019 17:36:41 -0800 (PST) From: Gurchetan Singh To: dri-devel@lists.freedesktop.org Subject: [PATCH 3/4] udmabuf: separate out creating/destroying scatter-table Date: Mon, 2 Dec 2019 17:36:26 -0800 Message-Id: <20191203013627.85991-3-gurchetansingh@chromium.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20191203013627.85991-1-gurchetansingh@chromium.org> References: <20191203013627.85991-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=LICdhzdPL2HSftzAOCs7MLzTsFAWvzORdwz9P5dMvlA=; b=mS5zaMwU/sZmEUX/WkMrz/LIFmrqQarkFTQtjni4vznUW4G5/V1XLmnXXEOCtEuEKT 46P4Fvj0m5QL0rmq+kikGkBWvCUsEweLUoUOXOOhDGlddeeWa1RvAdopKD6iQtxpa5Mg LgROWS5XR/Z0dKPW/PO7CSMAavNZD6iFzKyek= 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: Gurchetan Singh , kraxel@redhat.com, hch@lst.de Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" These are nice functions and can be re-used. 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 f0bf3ba7441e..0a610e09ae23 100644 --- a/drivers/dma-buf/udmabuf.c +++ b/drivers/dma-buf/udmabuf.c @@ -47,10 +47,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; @@ -62,7 +62,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; } @@ -74,13 +74,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)