From patchwork Thu Feb 9 14:22:49 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marek Szyprowski X-Patchwork-Id: 93714 Delivered-To: patch@linaro.org Received: by 10.140.20.99 with SMTP id 90csp25911qgi; Thu, 9 Feb 2017 06:25:30 -0800 (PST) X-Received: by 10.98.152.79 with SMTP id q76mr3931092pfd.147.1486650330826; Thu, 09 Feb 2017 06:25:30 -0800 (PST) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b21si10178493pfc.225.2017.02.09.06.25.30; Thu, 09 Feb 2017 06:25:30 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-pm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-pm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-pm-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753010AbdBIOZZ (ORCPT + 13 others); Thu, 9 Feb 2017 09:25:25 -0500 Received: from mailout4.w1.samsung.com ([210.118.77.14]:63950 "EHLO mailout4.w1.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752177AbdBIOY7 (ORCPT ); Thu, 9 Feb 2017 09:24:59 -0500 Received: from eucas1p1.samsung.com (unknown [182.198.249.206]) by mailout4.w1.samsung.com (Oracle Communications Messaging Server 7.0.5.31.0 64bit (built May 5 2014)) with ESMTP id <0OL4005A42ML9790@mailout4.w1.samsung.com>; Thu, 09 Feb 2017 14:23:09 +0000 (GMT) Received: from eusmges5.samsung.com (unknown [203.254.199.245]) by eucas1p2.samsung.com (KnoxPortal) with ESMTP id 20170209142308eucas1p20d10fd81841160959b67a98419dc75b0~hpHhLZiDS0919409194eucas1p2X; Thu, 9 Feb 2017 14:23:08 +0000 (GMT) Received: from eucas1p2.samsung.com ( [182.198.249.207]) by eusmges5.samsung.com (EUCPMTA) with SMTP id 25.A2.17477.C4B7C985; Thu, 9 Feb 2017 14:23:08 +0000 (GMT) Received: from eusmgms1.samsung.com (unknown [182.198.249.179]) by eucas1p1.samsung.com (KnoxPortal) with ESMTP id 20170209142307eucas1p180323d005f524760913b8d04ac966423~hpHgfPyUD1473314733eucas1p1k; Thu, 9 Feb 2017 14:23:07 +0000 (GMT) X-AuditID: cbfec7f5-f79d06d000004445-cf-589c7b4c7376 Received: from eusync4.samsung.com ( [203.254.199.214]) by eusmgms1.samsung.com (EUCPMTA) with SMTP id 98.95.06687.79B7C985; Thu, 9 Feb 2017 14:24:23 +0000 (GMT) Received: from AMDC2765.digital.local ([106.116.147.25]) by eusync4.samsung.com (Oracle Communications Messaging Server 7.0.5.31.0 64bit (built May 5 2014)) with ESMTPA id <0OL400ADQ2MEJ1A0@eusync4.samsung.com>; Thu, 09 Feb 2017 14:23:07 +0000 (GMT) From: Marek Szyprowski To: linux-samsung-soc@vger.kernel.org, dmaengine@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Marek Szyprowski , Krzysztof Kozlowski , Bartlomiej Zolnierkiewicz , Vinod Koul , Ulf Hansson , "Rafael J. Wysocki" , Lars-Peter Clausen , Arnd Bergmann , Inki Dae Subject: [PATCH v8 1/3] dmaengine: Add new device_{set, release}_slave callbacks Date: Thu, 09 Feb 2017 15:22:49 +0100 Message-id: <1486650171-20598-2-git-send-email-m.szyprowski@samsung.com> X-Mailer: git-send-email 1.9.1 In-reply-to: <1486650171-20598-1-git-send-email-m.szyprowski@samsung.com> X-Brightmail-Tracker: H4sIAAAAAAAAAzWSbUhTURzGO7svuxvNLlPyoKY4KsJKE4yuWlFgciM/VBKK+6AzL1PanOz6 MvNDyzDdRBNnZLjSdBoYazanhC+Z29gSw5mZJFhSUqSoo4aGhZbb1W+/5zz/8zz8D4dAxFto GFFQWMyoC2U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osUUvOS81My89JtlUJD3HQtlBTyEnNTbZUidH1DgpQUyhJzSoE8IwM0 4OAc4B6spG+X4JbRvX8eW8Er+Yqb32czNjAuk+pi5OSQEDCR2Lp7ASOELSZx4d56ti5GLg4h gSWMEm1vV7JAOE1MEouvz2ABqWITMJToetsFViUisIhR4sSK/8wgDrPAOyaJWw0v2UGqhAX8 JU4e2s4EYrMIqEo8vvCeDcTmFfCQ6P37mRlin5zEyWOTWUFsTgFPia7uCWB3CAHVTF2/mm0C I+8CRoZVjCKppcW56bnFhnrFibnFpXnpesn5uZsYgbGz7djPzTsYL20MPsQowMGoxMM7oWpO hBBrYllxZe4hRgkOZiURXq0KoBBvSmJlVWpRfnxRaU5q8SFGU6CjJjJLiSbnA+M6ryTe0MTQ 3NLQyNjCwtzISEmct+TDlXAhgfTEktTs1NSC1CKYPiYOTqkGxtgltzhji3i+vV98ofrM1s2F Mq+/yP/QSLRVYAiLib5XtfbOM93zh5V/Ls5aHnO/v7n605zHybXv4v8e6jz9dBl3wVYX+YAD pU/nV75ZKdhip/1NZX5h0/xLWoouV/7ty3ljvHDxinm9Erfas8Tez/G6tyOHoUuy91/Hqw9y q5fazJ3jJr8096ESS3FGoqEWc1FxIgCmSbfFswIAAA== X-MTR: 20000000000000000@CPGS X-CMS-MailID: 20170209142307eucas1p180323d005f524760913b8d04ac966423 X-Msg-Generator: CA X-Sender-IP: 182.198.249.179 X-Local-Sender: =?utf-8?q?Marek_Szyprowski=1BSRPOL-Kernel_=28TP=29=1B?= =?utf-8?b?7IK87ISx7KCE7J6QG1NlbmlvciBTb2Z0d2FyZSBFbmdpbmVlcg==?= X-Global-Sender: =?utf-8?q?Marek_Szyprowski=1BSRPOL-Kernel_=28TP=29=1BSam?= =?utf-8?q?sung_Electronics=1BSenior_Software_Engineer?= X-Sender-Code: =?utf-8?q?C10=1BEHQ=1BC10CD02CD027392?= CMS-TYPE: 201P X-HopCount: 7 X-CMS-RootMailID: 20170209142307eucas1p180323d005f524760913b8d04ac966423 X-RootMTR: 20170209142307eucas1p180323d005f524760913b8d04ac966423 References: <1486650171-20598-1-git-send-email-m.szyprowski@samsung.com> Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org Add two new callbacks to DMA engine device. They will used to provide access to slave device (the device which requested given DMA channel) for DMA engine driver. Access to slave device might be useful for example for implementing advanced runtime power management. DMA slave channels are exclusive, so only one slave device can be set for a given DMA slave channel. device_set_slave() will be called after the device_alloc_chan_resources() and device_release_slave() before the device_free_chan_resources(). Signed-off-by: Marek Szyprowski --- drivers/dma/dmaengine.c | 27 ++++++++++++++++++++++++--- include/linux/dmaengine.h | 10 ++++++++++ 2 files changed, 34 insertions(+), 3 deletions(-) -- 1.9.1 -- To unsubscribe from this list: send the line "unsubscribe linux-pm" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/drivers/dma/dmaengine.c b/drivers/dma/dmaengine.c index 24e0221fd66d..5b7089d8be4d 100644 --- a/drivers/dma/dmaengine.c +++ b/drivers/dma/dmaengine.c @@ -705,6 +705,7 @@ struct dma_chan *dma_request_chan(struct device *dev, const char *name) { struct dma_device *d, *_d; struct dma_chan *chan = NULL; + int ret; /* If device-tree is present get slave info from here */ if (dev->of_node) @@ -715,8 +716,9 @@ struct dma_chan *dma_request_chan(struct device *dev, const char *name) chan = acpi_dma_request_slave_chan_by_name(dev, name); if (chan) { - /* Valid channel found or requester need to be deferred */ - if (!IS_ERR(chan) || PTR_ERR(chan) == -EPROBE_DEFER) + if (!IS_ERR(chan)) + goto found; + if (PTR_ERR(chan) == -EPROBE_DEFER) return chan; } @@ -738,7 +740,21 @@ struct dma_chan *dma_request_chan(struct device *dev, const char *name) } mutex_unlock(&dma_list_mutex); - return chan ? chan : ERR_PTR(-EPROBE_DEFER); + if (!chan) + return ERR_PTR(-EPROBE_DEFER); + if (IS_ERR(chan)) + return chan; +found: + if (chan->device->device_set_slave) { + chan->slave = dev; + ret = chan->device->device_set_slave(chan, dev); + if (ret) { + chan->slave = NULL; + dma_release_channel(chan); + chan = ERR_PTR(ret); + } + } + return chan; } EXPORT_SYMBOL_GPL(dma_request_chan); @@ -786,6 +802,11 @@ void dma_release_channel(struct dma_chan *chan) mutex_lock(&dma_list_mutex); WARN_ONCE(chan->client_count != 1, "chan reference count %d != 1\n", chan->client_count); + if (chan->slave) { + if (chan->device->device_release_slave) + chan->device->device_release_slave(chan); + chan->slave = NULL; + } dma_chan_put(chan); /* drop PRIVATE cap enabled by __dma_request_channel() */ if (--chan->device->privatecnt == 0) diff --git a/include/linux/dmaengine.h b/include/linux/dmaengine.h index 533680860865..d22299e37e69 100644 --- a/include/linux/dmaengine.h +++ b/include/linux/dmaengine.h @@ -277,6 +277,9 @@ struct dma_chan { struct dma_router *router; void *route_data; + /* Only for SLAVE channels */ + struct device *slave; + void *private; }; @@ -686,6 +689,10 @@ struct dma_filter { * @device_alloc_chan_resources: allocate resources and return the * number of allocated descriptors * @device_free_chan_resources: release DMA channel's resources + * @device_set_slave: provide access to the slave device, which requested + * given DMA channel, called after @device_alloc_chan_resources + * @device_release_slave: finishes access to the slave device, called + * before @device_free_chan_resources * @device_prep_dma_memcpy: prepares a memcpy operation * @device_prep_dma_xor: prepares a xor operation * @device_prep_dma_xor_val: prepares a xor validation operation @@ -746,6 +753,9 @@ struct dma_device { int (*device_alloc_chan_resources)(struct dma_chan *chan); void (*device_free_chan_resources)(struct dma_chan *chan); + int (*device_set_slave)(struct dma_chan *chan, struct device *slave); + void (*device_release_slave)(struct dma_chan *chan); + struct dma_async_tx_descriptor *(*device_prep_dma_memcpy)( struct dma_chan *chan, dma_addr_t dst, dma_addr_t src, size_t len, unsigned long flags);