From patchwork Mon Nov 25 21:48:20 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Warren X-Patchwork-Id: 3234751 Return-Path: X-Original-To: patchwork-dmaengine@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 364D59F3A0 for ; Mon, 25 Nov 2013 21:48:29 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 4163A201B4 for ; Mon, 25 Nov 2013 21:48:28 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 4B54E202D1 for ; Mon, 25 Nov 2013 21:48:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752039Ab3KYVs1 (ORCPT ); Mon, 25 Nov 2013 16:48:27 -0500 Received: from avon.wwwdotorg.org ([70.85.31.133]:56490 "EHLO avon.wwwdotorg.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752083Ab3KYVs0 (ORCPT ); Mon, 25 Nov 2013 16:48:26 -0500 Received: from severn.wwwdotorg.org (unknown [192.168.65.5]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by avon.wwwdotorg.org (Postfix) with ESMTPS id 478A96232; Mon, 25 Nov 2013 14:48:26 -0700 (MST) Received: from swarren-lx1.nvidia.com (localhost [127.0.0.1]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by severn.wwwdotorg.org (Postfix) with ESMTPSA id E6AC0E4623; Mon, 25 Nov 2013 14:48:22 -0700 (MST) From: Stephen Warren To: Dan Williams , Vinod Koul Cc: Stephen Warren , dmaengine@vger.kernel.org Subject: [PATCH] dma: add common of_dma_slave_xlate() Date: Mon, 25 Nov 2013 14:48:20 -0700 Message-Id: <1385416100-3234-1-git-send-email-swarren@wwwdotorg.org> X-Mailer: git-send-email 1.8.1.5 X-NVConfidentiality: public X-Virus-Scanned: clamav-milter 0.97.8 at avon.wwwdotorg.org X-Virus-Status: Clean Sender: dmaengine-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: dmaengine@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Stephen Warren mmp_pdma.c implements a custom of_xlate() function that is 95% identical to what Tegra will need. Create a function to implement the common part, so everyone doesn't just cut/paste the implementation. Cc: Dan Williams Cc: Vinod Koul Cc: dmaengine@vger.kernel.org Signed-off-by: Stephen Warren --- This patch is a dependency for a series that reworks many of the Tegra drivers. As such, it needs to go into a topic branch on its own, based directly on 3.13-rc1. If the DMA maintainers ack the patches I'm happy to create this topic branch myself and send a pull request to the DMA tree. Or the patches can be applied to a topic branch by the DMA maintainers and I will merge their topic branch into the Tegra rework branch that I mentioned. Note that this patch is independant from the "dma: add channel request API that supports deferred probe" which I just sent, so it could (should?) be a different topic branch. --- drivers/dma/of-dma.c | 43 +++++++++++++++++++++++++++++++++++++++++++ include/linux/of_dma.h | 14 ++++++++++++++ 2 files changed, 57 insertions(+) diff --git a/drivers/dma/of-dma.c b/drivers/dma/of-dma.c index 0b88dd3d05f4..324ca538cd3b 100644 --- a/drivers/dma/of-dma.c +++ b/drivers/dma/of-dma.c @@ -215,3 +215,46 @@ struct dma_chan *of_dma_simple_xlate(struct of_phandle_args *dma_spec, &dma_spec->args[0]); } EXPORT_SYMBOL_GPL(of_dma_simple_xlate); + +struct dma_chan *of_dma_slave_xlate(struct of_phandle_args *dma_spec, + struct of_dma *ofdma) +{ + struct of_dma_slave_xlate_info *info = ofdma->of_dma_data; + struct dma_chan *candidate, *chan; + int ret; + +retry: + candidate = NULL; + + /* + * walk the list of channels registered with the current instance and + * find one that is currently unused + */ + list_for_each_entry(chan, &info->device->channels, device_node) + if (chan->client_count == 0) { + candidate = chan; + break; + } + + if (!candidate) + return NULL; + + /* + * dma_get_slave_channel will return NULL if we lost a race between + * the lookup and the reservation + */ + chan = dma_get_slave_channel(candidate); + if (!chan) + goto retry; + + if (info->post_alloc) { + ret = info->post_alloc(chan, dma_spec); + if (ret) { + dma_release_channel(chan); + return NULL; + } + } + + return chan; +} +EXPORT_SYMBOL_GPL(of_dma_slave_xlate); diff --git a/include/linux/of_dma.h b/include/linux/of_dma.h index ae36298ba076..fb4187adc68b 100644 --- a/include/linux/of_dma.h +++ b/include/linux/of_dma.h @@ -31,6 +31,12 @@ struct of_dma_filter_info { dma_filter_fn filter_fn; }; +struct of_dma_slave_xlate_info { + struct dma_device *device; + int (*post_alloc)(struct dma_chan *chan, + struct of_phandle_args *dma_spec); +}; + #ifdef CONFIG_OF extern int of_dma_controller_register(struct device_node *np, struct dma_chan *(*of_dma_xlate) @@ -41,6 +47,8 @@ extern struct dma_chan *of_dma_request_slave_channel(struct device_node *np, const char *name); extern struct dma_chan *of_dma_simple_xlate(struct of_phandle_args *dma_spec, struct of_dma *ofdma); +extern struct dma_chan *of_dma_slave_xlate(struct of_phandle_args *dma_spec, + struct of_dma *ofdma); #else static inline int of_dma_controller_register(struct device_node *np, struct dma_chan *(*of_dma_xlate) @@ -66,6 +74,12 @@ static inline struct dma_chan *of_dma_simple_xlate(struct of_phandle_args *dma_s return NULL; } +static inline struct dma_chan *of_dma_slave_xlate(struct of_phandle_args *dma_spec, + struct of_dma *ofdma) +{ + return NULL; +} + #endif #endif /* __LINUX_OF_DMA_H */