From patchwork Tue Nov 26 01:10:55 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gurchetan Singh X-Patchwork-Id: 11261271 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 878591393 for ; Tue, 26 Nov 2019 01:11:37 +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 703B52068F for ; Tue, 26 Nov 2019 01:11:37 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 703B52068F 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 D900F6E1E5; Tue, 26 Nov 2019 01:11:34 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-pj1-x1043.google.com (mail-pj1-x1043.google.com [IPv6:2607:f8b0:4864:20::1043]) by gabe.freedesktop.org (Postfix) with ESMTPS id 9C3D36E1E0 for ; Tue, 26 Nov 2019 01:11:30 +0000 (UTC) Received: by mail-pj1-x1043.google.com with SMTP id bb19so3901666pjb.4 for ; Mon, 25 Nov 2019 17:11:30 -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=ghrwFxO818UoK8VetowCRFQffMjIOkvAfQ3v9xbttnw=; b=HsNSB6ZS9qfX4ouncHRMbiu9a6xwJv6WM6sRJIXGrVMe8cc4CX+OxiQ2KoQ+BTJ34m tgkUeYIOP0Kuuqud+SDM7lWh1CDZmUbrYQDps5vr/4j8u8i5zyLwYT86aExQQGa9xyPx ytoFtSFdR49cfdhTjy61ORw0usW/LOWEsmAtRSjwhCYBOHk7vzngIwQB0R+aiK6wXedI uYPJ+iYMMiukphdzYn923NMsL13wTNopGTWz7BidZNlsYyU8y6LkOMFQ+F/N7zwaHSc6 vyMWrN3bTvtpfPXrNAsdQA6D7lUopjGtEF7FA4MxIa+KRDaMqbS2S/cDe9oq7o5sMkYg jT+g== X-Gm-Message-State: APjAAAXghPgYvp4KJjn4u9au3sSo3QMcaBOxZSojemY86y6XKbt9wxHA YhZowp7aPsoJzh/ykaBLQ80g3XUzdRE= X-Google-Smtp-Source: APXvYqzVL3/E4ZIaU+Kwqbhjk9+5S/H6jnox5RjWJwEk18dpafx3G092uB/gv0Th9142Qsj0mldwwQ== X-Received: by 2002:a17:902:9a8e:: with SMTP id w14mr32578884plp.215.1574730689905; Mon, 25 Nov 2019 17:11:29 -0800 (PST) Received: from gurchetansingh0.mtv.corp.google.com ([2620:15c:202:201:bc97:5740:52a7:6875]) by smtp.gmail.com with ESMTPSA id z10sm9672903pgg.39.2019.11.25.17.11.29 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 25 Nov 2019 17:11:29 -0800 (PST) From: Gurchetan Singh To: dri-devel@lists.freedesktop.org Subject: [PATCH 4/5] udmabuf: separate out creating/destroying scatter-table Date: Mon, 25 Nov 2019 17:10:55 -0800 Message-Id: <20191126011056.67928-4-gurchetansingh@chromium.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20191126011056.67928-1-gurchetansingh@chromium.org> References: <20191126011056.67928-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=ghrwFxO818UoK8VetowCRFQffMjIOkvAfQ3v9xbttnw=; b=bjQiRQnkTIJk7xaJAmU3rUsZEwFA9izbk1Nt1r7qkmcdtPgkSmoq+yv51kKezAaR76 Znba5vsISPOkd4WV6umB/7G0uVLSLpFdJMYAsIynemULdwMz3729ksy3mTO+36xPitQ1 UmlB0RqK4wVRfIt92L0ppbMOuPKXSHPQzh4A0= 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 9e6fdd2bc979..67e89bb034c5 100644 --- a/drivers/dma-buf/udmabuf.c +++ b/drivers/dma-buf/udmabuf.c @@ -54,10 +54,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; @@ -69,7 +69,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; } @@ -81,13 +81,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)