From patchwork Wed Aug 30 20:56:06 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dave Jiang X-Patchwork-Id: 9930759 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 4FE4B60383 for ; Wed, 30 Aug 2017 20:56:37 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 42209287B3 for ; Wed, 30 Aug 2017 20:56:37 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 33B64287BD; Wed, 30 Aug 2017 20:56:37 +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=-1.9 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from ml01.01.org (ml01.01.org [198.145.21.10]) (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 F02D6287B0 for ; Wed, 30 Aug 2017 20:56:35 +0000 (UTC) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id B6DC121E95DEC; Wed, 30 Aug 2017 13:56:04 -0700 (PDT) X-Original-To: linux-nvdimm@lists.01.org Delivered-To: linux-nvdimm@lists.01.org Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 5611E21E70D58 for ; Wed, 30 Aug 2017 13:56:03 -0700 (PDT) Received: from orsmga001.jf.intel.com ([10.7.209.18]) by orsmga101.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 30 Aug 2017 13:56:07 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos; i="5.41,450,1498546800"; d="scan'208"; a="1167717291" Received: from djiang5-desk3.ch.intel.com ([143.182.137.38]) by orsmga001.jf.intel.com with ESMTP; 30 Aug 2017 13:56:06 -0700 Subject: [PATCH v7 6/9] dmaengine: provide number of available channels From: Dave Jiang To: vinod.koul@intel.com, dan.j.williams@intel.com Date: Wed, 30 Aug 2017 13:56:06 -0700 Message-ID: <150412656647.69288.13890123701883074968.stgit@djiang5-desk3.ch.intel.com> In-Reply-To: <150412628764.69288.12074115435918322858.stgit@djiang5-desk3.ch.intel.com> References: <150412628764.69288.12074115435918322858.stgit@djiang5-desk3.ch.intel.com> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 X-BeenThere: linux-nvdimm@lists.01.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: "Linux-nvdimm developer list." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: dmaengine@vger.kernel.org, hch@infradead.org, linux-nvdimm@lists.01.org Errors-To: linux-nvdimm-bounces@lists.01.org Sender: "Linux-nvdimm" X-Virus-Scanned: ClamAV using ClamSMTP Adding a dmaengine support function to provide the number of available channels that can be shared with support of a filter function. Signed-off-by: Dave Jiang --- drivers/dma/dmaengine.c | 45 +++++++++++++++++++++++++++++++++++++++++++++ include/linux/dmaengine.h | 7 +++++++ 2 files changed, 52 insertions(+) diff --git a/drivers/dma/dmaengine.c b/drivers/dma/dmaengine.c index b4fd81a..bd5000e 100644 --- a/drivers/dma/dmaengine.c +++ b/drivers/dma/dmaengine.c @@ -674,6 +674,51 @@ struct dma_chan *__dma_request_channel(const dma_cap_mask_t *mask, } EXPORT_SYMBOL_GPL(__dma_request_channel); +static int get_candidate_count(const dma_cap_mask_t *mask, + struct dma_device *dev, + dma_filter_fn fn, void *fn_param) +{ + struct dma_chan *chan; + int count = 0; + + if (mask && !__dma_device_satisfies_mask(dev, mask)) { + dev_dbg(dev->dev, "%s: wrong capabilities\n", __func__); + return 0; + } + + list_for_each_entry(chan, &dev->channels, device_node) { + if (dma_has_cap(DMA_PRIVATE, dev->cap_mask)) { + dev_dbg(dev->dev, "%s: %s is marked for private\n", + __func__, dma_chan_name(chan)); + continue; + } + if (fn && !fn(chan, fn_param)) { + dev_dbg(dev->dev, "%s: %s filter said false\n", + __func__, dma_chan_name(chan)); + continue; + } + count++; + } + + return count; +} + +int dma_get_channel_count(const dma_cap_mask_t *mask, + dma_filter_fn fn, void *fn_param) +{ + struct dma_device *device; + int total = 0; + + /* Find a channel */ + mutex_lock(&dma_list_mutex); + list_for_each_entry(device, &dma_device_list, global_node) + total += get_candidate_count(mask, device, fn, fn_param); + mutex_unlock(&dma_list_mutex); + + return total; +} +EXPORT_SYMBOL_GPL(dma_get_channel_count); + static const struct dma_slave_map *dma_filter_match(struct dma_device *device, const char *name, struct device *dev) diff --git a/include/linux/dmaengine.h b/include/linux/dmaengine.h index fc53854..ab5f8c1 100644 --- a/include/linux/dmaengine.h +++ b/include/linux/dmaengine.h @@ -1331,6 +1331,8 @@ enum dma_status dma_wait_for_async_tx(struct dma_async_tx_descriptor *tx); void dma_issue_pending_all(void); struct dma_chan *__dma_request_channel(const dma_cap_mask_t *mask, dma_filter_fn fn, void *fn_param); +int dma_get_channel_count(const dma_cap_mask_t *mask, + dma_filter_fn fn, void *fn_param); struct dma_chan *dma_request_slave_channel(struct device *dev, const char *name); struct dma_chan *dma_request_chan(struct device *dev, const char *name); @@ -1364,6 +1366,11 @@ static inline struct dma_chan *__dma_request_channel(const dma_cap_mask_t *mask, { return NULL; } +static inline int dma_get_channel_count(const dma_cap_mask_t *mask, + dma_filter_fn fn, void *fn_param) +{ + return 0; +} static inline struct dma_chan *dma_request_slave_channel(struct device *dev, const char *name) {