Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp3474205yba; Tue, 7 May 2019 01:39:43 -0700 (PDT) X-Google-Smtp-Source: APXvYqzQhEYX69Fw8hMkEq/e+ktuAe1n/5BtRguNKaNZYlSt9L/LvN1W4Ghb90hYHL9g3KeBbuQV X-Received: by 2002:a63:1a03:: with SMTP id a3mr9337136pga.412.1557218383781; Tue, 07 May 2019 01:39:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557218383; cv=none; d=google.com; s=arc-20160816; b=dxOf7Aba+qM4Z7x1Mq/rcWmqPwzjzK1ibqBP7JDCO5WI1Gau8QucyZUQGgbd0HniSc EZsxYINtSxcDAvy2bpShYs06dSWQ7i/P4zzFsAArUxYod5Ncm+n0Lmi3N/xK1eTbawmr t2riw/h8ekcjX47iQ0zNlAl3+wMZbIfHIHlhvPFaXb7WF/B9NHrU7qwpKxp9H0AYaYRB ebhAp2Mo76nu/PUP8B0K3kh+CArg9FC2yfSMTnRMru1mCyuqhoNpC1bRcnkhdz6G5+CB jcuEcseEDbPUAbgzu1ueHmOnpvZsEtNDJzRc62mHFP9pPyM/jpUzw8R8U0LgBv12ZKNh KO4A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:dkim-signature; bh=Olgyr8WZLKt8gGzTEuPealNrw31hIrJIggcB6sk9mwA=; b=ZCRWiuJ8xOEAiLVBwnKr1IgK56OGW4/z8oMPNEKGMy+03p4G6JWKt5BzXfkjsMO2Jy QNcal7ZLoQMVvWxw5HSKIaqtTnG13pUzl4U70iw1bi1S2pqmSNNces/cpNivZ9GLGXbJ xXLU4loRaOoSmos/QRhTlYX7TWkJRrwmfCKCfFw43PN4mnVU0A+kGpZgUNs6t4icTzXL RH2jkYBTOgazMr8pgk435Zz6PEHil4WS0DyBGc2EjTILEN5HUw5XKL0XEH9CIY3ftp9P zXieO5qXwyinACxLAgFohbdu8IAEHEDFnHD5h9inIy5pj8oP3qi0OCxyXgZhI0/Golbs AfMA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ti.com header.s=ti-com-17Q1 header.b=AfFSF5Ep; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=ti.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id w11si18117996plz.403.2019.05.07.01.39.27; Tue, 07 May 2019 01:39:43 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@ti.com header.s=ti-com-17Q1 header.b=AfFSF5Ep; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=ti.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727139AbfEGIiU (ORCPT + 99 others); Tue, 7 May 2019 04:38:20 -0400 Received: from fllv0015.ext.ti.com ([198.47.19.141]:57066 "EHLO fllv0015.ext.ti.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726159AbfEGIiT (ORCPT ); Tue, 7 May 2019 04:38:19 -0400 Received: from lelv0265.itg.ti.com ([10.180.67.224]) by fllv0015.ext.ti.com (8.15.2/8.15.2) with ESMTP id x478bsCu127307; Tue, 7 May 2019 03:37:54 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; s=ti-com-17Q1; t=1557218274; bh=Olgyr8WZLKt8gGzTEuPealNrw31hIrJIggcB6sk9mwA=; h=Subject:To:CC:References:From:Date:In-Reply-To; b=AfFSF5EpswIiPbbL86OZYu4kcAilSG876Qa3ixDnLUyX+cjNV9vO0Tk9jHPPemr4v 1CVzjgsmaL03L1j016BhNw3R8ODKp8RRZ+IWqjbVYJTx7SmneRYDxRMF1UZz+8Lce3 gOWook+vRea/dwRFIjqOgQhifaTq2U9ckMd44ibM= Received: from DLEE108.ent.ti.com (dlee108.ent.ti.com [157.170.170.38]) by lelv0265.itg.ti.com (8.15.2/8.15.2) with ESMTPS id x478bsVP089757 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=FAIL); Tue, 7 May 2019 03:37:54 -0500 Received: from DLEE112.ent.ti.com (157.170.170.23) by DLEE108.ent.ti.com (157.170.170.38) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1713.5; Tue, 7 May 2019 03:37:54 -0500 Received: from lelv0326.itg.ti.com (10.180.67.84) by DLEE112.ent.ti.com (157.170.170.23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1713.5 via Frontend Transport; Tue, 7 May 2019 03:37:54 -0500 Received: from [192.168.2.10] (ileax41-snat.itg.ti.com [10.172.224.153]) by lelv0326.itg.ti.com (8.15.2/8.15.2) with ESMTP id x478boXY045826; Tue, 7 May 2019 03:37:50 -0500 Subject: Re: [PATCH 1/8] dmaengine: Add matching device node validation in __dma_request_channel() To: Baolin Wang , , CC: , , , , , , , , , , , , , , References: <17a22052fdb759ae6129e30f9bd8862f23a03ad9.1557206859.git.baolin.wang@linaro.org> From: Peter Ujfalusi Message-ID: <42b84cfe-3281-7f4e-03cc-6ca126e16191@ti.com> Date: Tue, 7 May 2019 11:37:56 +0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.6.1 MIME-Version: 1.0 In-Reply-To: <17a22052fdb759ae6129e30f9bd8862f23a03ad9.1557206859.git.baolin.wang@linaro.org> Content-Type: text/plain; charset="utf-8" Content-Language: en-US Content-Transfer-Encoding: 8bit X-EXCLAIMER-MD-CONFIG: e1e8a2fd-e40a-4ac6-ac9b-f7e9cc9ee180 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi, On 07/05/2019 9.09, Baolin Wang wrote: > When user try to request one DMA channel by __dma_request_channel(), it won't > validate if it is the correct DMA device to request, that will lead each DMA > engine driver to validate the correct device node in their filter function > if it is necessary. > > Thus we can add the matching device node validation in the DMA engine core, > to remove all of device node validation in the drivers. I have picked this patch to my TI UDMA series and with __dma_request_channel() it works as expected - picking the channel from the correct DMA device. Tested-by: Peter Ujfalusi > > Signed-off-by: Baolin Wang > --- > drivers/dma/dmaengine.c | 10 ++++++++-- > drivers/dma/of-dma.c | 4 ++-- > include/linux/dmaengine.h | 12 ++++++++---- > 3 files changed, 18 insertions(+), 8 deletions(-) > > diff --git a/drivers/dma/dmaengine.c b/drivers/dma/dmaengine.c > index 3a11b10..610080c 100644 > --- a/drivers/dma/dmaengine.c > +++ b/drivers/dma/dmaengine.c > @@ -641,11 +641,13 @@ struct dma_chan *dma_get_any_slave_channel(struct dma_device *device) > * @mask: capabilities that the channel must satisfy > * @fn: optional callback to disposition available channels > * @fn_param: opaque parameter to pass to dma_filter_fn > + * @np: device node to look for DMA channels > * > * Returns pointer to appropriate DMA channel on success or NULL. > */ > struct dma_chan *__dma_request_channel(const dma_cap_mask_t *mask, > - dma_filter_fn fn, void *fn_param) > + dma_filter_fn fn, void *fn_param, > + struct device_node *np) > { > struct dma_device *device, *_d; > struct dma_chan *chan = NULL; > @@ -653,6 +655,10 @@ struct dma_chan *__dma_request_channel(const dma_cap_mask_t *mask, > /* Find a channel */ > mutex_lock(&dma_list_mutex); > list_for_each_entry_safe(device, _d, &dma_device_list, global_node) { > + /* Finds a DMA controller with matching device node */ > + if (np && device->dev->of_node && np != device->dev->of_node) > + continue; > + > chan = find_candidate(device, mask, fn, fn_param); > if (!IS_ERR(chan)) > break; > @@ -769,7 +775,7 @@ struct dma_chan *dma_request_chan_by_mask(const dma_cap_mask_t *mask) > if (!mask) > return ERR_PTR(-ENODEV); > > - chan = __dma_request_channel(mask, NULL, NULL); > + chan = __dma_request_channel(mask, NULL, NULL, NULL); > if (!chan) { > mutex_lock(&dma_list_mutex); > if (list_empty(&dma_device_list)) > diff --git a/drivers/dma/of-dma.c b/drivers/dma/of-dma.c > index 91fd395..6b43d04 100644 > --- a/drivers/dma/of-dma.c > +++ b/drivers/dma/of-dma.c > @@ -316,8 +316,8 @@ struct dma_chan *of_dma_simple_xlate(struct of_phandle_args *dma_spec, > if (count != 1) > return NULL; > > - return dma_request_channel(info->dma_cap, info->filter_fn, > - &dma_spec->args[0]); > + return __dma_request_channel(&info->dma_cap, info->filter_fn, > + &dma_spec->args[0], dma_spec->np); > } > EXPORT_SYMBOL_GPL(of_dma_simple_xlate); > > diff --git a/include/linux/dmaengine.h b/include/linux/dmaengine.h > index d49ec5c..504085b 100644 > --- a/include/linux/dmaengine.h > +++ b/include/linux/dmaengine.h > @@ -1314,7 +1314,8 @@ static inline enum dma_status dma_async_is_complete(dma_cookie_t cookie, > 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); > + dma_filter_fn fn, void *fn_param, > + struct device_node *np); > 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); > @@ -1339,7 +1340,9 @@ static inline void dma_issue_pending_all(void) > { > } > static inline struct dma_chan *__dma_request_channel(const dma_cap_mask_t *mask, > - dma_filter_fn fn, void *fn_param) > + dma_filter_fn fn, > + void *fn_param, > + struct device_node *np) > { > return NULL; > } > @@ -1411,7 +1414,8 @@ static inline int dmaengine_desc_free(struct dma_async_tx_descriptor *desc) > void dma_run_dependencies(struct dma_async_tx_descriptor *tx); > struct dma_chan *dma_get_slave_channel(struct dma_chan *chan); > struct dma_chan *dma_get_any_slave_channel(struct dma_device *device); > -#define dma_request_channel(mask, x, y) __dma_request_channel(&(mask), x, y) > +#define dma_request_channel(mask, x, y) \ > + __dma_request_channel(&(mask), x, y, NULL) > #define dma_request_slave_channel_compat(mask, x, y, dev, name) \ > __dma_request_slave_channel_compat(&(mask), x, y, dev, name) > > @@ -1429,6 +1433,6 @@ static inline int dmaengine_desc_free(struct dma_async_tx_descriptor *desc) > if (!fn || !fn_param) > return NULL; > > - return __dma_request_channel(mask, fn, fn_param); > + return __dma_request_channel(mask, fn, fn_param, NULL); > } > #endif /* DMAENGINE_H */ > - Péter Texas Instruments Finland Oy, Porkkalankatu 22, 00180 Helsinki. Y-tunnus/Business ID: 0615521-4. Kotipaikka/Domicile: Helsinki