DMA: let filter functions of of_dma_simple_xlate possible check of_node
PATCH 1/1 DMA: let filter functions of of_dma_simple_xlate possible check of_node
pass of_phandle_args dma_spec to dma_request_channel in of_dma_simple_xlate, so the filter function could access of_node in of_phandle_args.
It also remove restriction of #dma-cells has to be one.
--- drivers/dma/edma.c | 7 +++++-- drivers/dma/of-dma.c | 10 ++++------ drivers/dma/omap-dma.c | 6 ++++-- 3 files changed, 13 insertions(+), 10 deletions(-)
drivers/dma/edma.c +5 -2
@@ -23,6 +23,7 @@#include <linux/platform_device.h> #include <linux/slab.h> #include <linux/spinlock.h> +#include <linux/of_dma.h> #include <linux/platform_data/edma.h>
@@ -604,9 +605,11 @@ static struct platform_driver edma_driver = {bool edma_filter_fn (struct dma_chan *chan,void *param) { -if (chan->device->dev->driver == &edma_driver.driver) { +struct of_phandle_args *dma_spec = param; +if (chan->device->dev->driver == &edma_driver.driver && + dma_spec->np == chan->device->dev->of_node) {struct edma_chan *echan =to_edma_chan (chan); -unsigned ch_req = *(unsigned *)param; +unsigned ch_req = dma_spec->args[0 ];return ch_req == echan->ch_num; }return false;
drivers/dma/of-dma.c +4 -6
@@ -192,11 +192,9 @@ struct dma_chan *of_dma_request_slave_channel(struct device_node *np,* @dma_spec: pointer to DMA specifier as found in the device tree * @of_dma: pointer to DMA controller data * -* A simple translation function for devices that use a 32-bit value for the +* A simple translation function for devices that use dma_spec for the * filter_param when calling the DMA engine dma_request_channel() function. -* Note that this translation function requires that #dma-cells is equal to 1 -* and the argument of the dma specifier is the 32-bit filter_param. Returns -* pointer to appropriate dma channel on success or NULL on error. +* Returns pointer to appropriate dma channel on success or NULL on error. */ struct dma_chan *of_dma_simple_xlate (struct of_phandle_args *dma_spec,struct of_dma *ofdma)
@@ -207,10 +205,10 @@ struct dma_chan *of_dma_simple_xlate(struct of_phandle_args *dma_spec,if (!info || !info->filter_fn)return NULL ; -if (count !=1 ) +if (count <1 )return NULL ;return dma_request_channel (info->dma_cap, info->filter_fn, - &dma_spec->args[0 ]); + dma_spec); }EXPORT_SYMBOL_GPL (of_dma_simple_xlate);
drivers/dma/omap-dma.c +4 -2
@@ -693,9 +693,11 @@ static struct platform_driver omap_dma_driver = {bool omap_dma_filter_fn (struct dma_chan *chan,void *param) { -if (chan->device->dev->driver == &omap_dma_driver.driver) { +struct of_phandle_args *dma_spec = param; +if (chan->device->dev->driver == &omap_dma_driver.driver && + dma_spec->np == chan->device->dev->of_node) {struct omap_chan *c =to_omap_dma_chan (chan); -unsigned req = *(unsigned *)param; +unsigned req = dma_spec->args[0 ];return req == c->dma_sig; }
Signature · 1 line
1.8.1.5
Quoted 3 lines · Richard Zhao
pass
of_phandle_argsdma_spectodma_request_channelinof_dma_simple_xlate, so the filter function could accessof_nodeinof_phandle_args.
Am just curious the reasoning behind doing so. Can you please expand above bit more with why you need to change it.
Quoted 85 lines
It also remove restriction of #dma-cells has to be one.
Signed-off-by Richard Zhao <[email protected]>--- drivers/dma/edma.c | 7 +++++-- drivers/dma/of-dma.c | 10 ++++------ drivers/dma/omap-dma.c | 6 ++++-- 3 files changed, 13 insertions(+), 10 deletions(-)drivers/dma/edma.c +5
-2@@ -23,6 +23,7 @@#include <linux/platform_device.h> #include <linux/slab.h> #include <linux/spinlock.h> +#include <linux/of_dma.h> #include <linux/platform_data/edma.h> @@ -604,9 +605,11 @@ static struct platform_driver edma_driver = {bool edma_filter_fn (struct dma_chan *chan,void *param) { -if (chan->device->dev->driver == &edma_driver.driver) { +struct of_phandle_args *dma_spec = param; +if (chan->device->dev->driver == &edma_driver.driver && + dma_spec->np == chan->device->dev->of_node) {struct edma_chan *echan =to_edma_chan (chan); -unsigned ch_req = *(unsigned *)param; +unsigned ch_req = dma_spec->args[0 ];return ch_req == echan->ch_num; }return false;drivers/dma/of-dma.c +4
-6@@ -192,11 +192,9 @@ struct dma_chan *of_dma_request_slave_channel(struct device_node *np,* @dma_spec: pointer to DMA specifier as found in the device tree * @of_dma: pointer to DMA controller data * -* A simple translation function for devices that use a 32-bit value for the +* A simple translation function for devices that use dma_spec for the * filter_param when calling the DMA engine dma_request_channel() function. -* Note that this translation function requires that #dma-cells is equal to 1 -* and the argument of the dma specifier is the 32-bit filter_param. Returns -* pointer to appropriate dma channel on success or NULL on error. +* Returns pointer to appropriate dma channel on success or NULL on error. */ struct dma_chan *of_dma_simple_xlate (struct of_phandle_args *dma_spec,struct of_dma *ofdma)@@ -207,10 +205,10 @@ struct dma_chan *of_dma_simple_xlate(struct of_phandle_args *dma_spec,if (!info || !info->filter_fn)return NULL ; -if (count !=1 ) +if (count <1 )return NULL ;return dma_request_channel (info->dma_cap, info->filter_fn, - &dma_spec->args[0 ]); + dma_spec); }EXPORT_SYMBOL_GPL (of_dma_simple_xlate);drivers/dma/omap-dma.c +4
-2@@ -693,9 +693,11 @@ static struct platform_driver omap_dma_driver = {bool omap_dma_filter_fn (struct dma_chan *chan,void *param) { -if (chan->device->dev->driver == &omap_dma_driver.driver) { +struct of_phandle_args *dma_spec = param; +if (chan->device->dev->driver == &omap_dma_driver.driver && + dma_spec->np == chan->device->dev->of_node) {struct omap_chan *c =to_omap_dma_chan (chan); -unsigned req = *(unsigned *)param; +unsigned req = dma_spec->args[0 ];return req == c->dma_sig; }
Quoted 6 lines · Santosh Shilimkar
Quoted 3 lines · Richard Zhao
pass
of_phandle_argsdma_spectodma_request_channelinof_dma_simple_xlate, so the filter function could accessof_nodeinof_phandle_args.Am just curious the reasoning behind doing so. Can you please expand above bit more with why you need to change it.
I believe that this patch is attempting to solve an issue I pointed out with the following patch, which enhances the Tegra DMA controller driver to support the standard DMA DT bindings:
https://lkml.org/lkml/2013/7/24/7
[PATCH 2/9] dma: tegra20-apbdma: move to generic device tree bindings
The issue is in particular that patch included:
Review
Quoted 12 lines
(quoted diff) +12
-0+static bool tegra_dma_filter_fn(struct dma_chan *dc, void *param) +{ + if (dc->device->dev->driver == &tegra_dmac_driver.driver) { + struct tegra_dma_channel *tdc = to_tegra_dma_chan(dc); + unsigned req = *(unsigned *)param; + + tdc->slave_id = req; + + return true; + } + return false; +}
Which is checking that the provider of the DMA channel is the correct DMA controller. The DMA core should be able to work this out, since at least under DT, the DT property specifies both the DMA controller's phandle and the DMA specifier, so that DMA core should be able to validate that it only attempts to match DMA channels for the specified DMA controller, without each DMA controller driver having to implement a custom filter function to do that.
Quoted 12 lines · Richard Zhao
pass
of_phandle_argsdma_spectodma_request_channelinof_dma_simple_xlate, so the filter function could accessof_nodeinof_phandle_args.It also remove restriction of #dma-cells has to be one.
Signed-off-by Richard Zhao <[email protected]>--- drivers/dma/edma.c | 7 +++++-- drivers/dma/of-dma.c | 10 ++++------ drivers/dma/omap-dma.c | 6 ++++-- 3 files changed, 13 insertions(+), 10 deletions(-)
Hi Vinod,
Can you please pick up this change?
Hi Stephen,
Can you please give a ack or reviewed-by etc?
Thanks
Richard
Quoted 14 lines · Richard Zhao
Quoted 12 lines · Richard Zhao
pass
of_phandle_argsdma_spectodma_request_channelinof_dma_simple_xlate, so the filter function could accessof_nodeinof_phandle_args.It also remove restriction of #dma-cells has to be one.
Signed-off-by Richard Zhao <[email protected]>--- drivers/dma/edma.c | 7 +++++-- drivers/dma/of-dma.c | 10 ++++------ drivers/dma/omap-dma.c | 6 ++++-- 3 files changed, 13 insertions(+), 10 deletions(-)
Quoted 7 lines
Hi Vinod,
Can you please pick up this change?
Hi Stephen,
Can you please give a ack or reviewed-by etc?
Hmm. Looking at the patch, I'm not sure it's right.
This patch simply passes all the specfier args to the filter function, and the code to check the equality of the of_node to the filter args is still duplicated in each DMA driver. Instead, the DMA core should be implementing the equality check, and only even calling the driver-specific filter function for devices where the client's phandle matches the DMA providing device's of_node handle.
Quoted 23 lines · Stephen Warren
Quoted 14 lines · Richard Zhao
Quoted 12 lines · Richard Zhao
pass
of_phandle_argsdma_spectodma_request_channelinof_dma_simple_xlate, so the filter function could accessof_nodeinof_phandle_args.It also remove restriction of #dma-cells has to be one.
Signed-off-by Richard Zhao <[email protected]>--- drivers/dma/edma.c | 7 +++++-- drivers/dma/of-dma.c | 10 ++++------ drivers/dma/omap-dma.c | 6 ++++-- 3 files changed, 13 insertions(+), 10 deletions(-)Quoted 7 lines
Hi Vinod,
Can you please pick up this change?
Hi Stephen,
Can you please give a ack or reviewed-by etc?
Quoted 8 lines
Hmm. Looking at the patch, I'm not sure it's right.
This patch simply passes all the specfier args to the filter function, and the code to check the equality of the
of_nodeto the filter args is still duplicated in each DMA driver. Instead, the DMA core should be implementing the equality check, and only even calling the driver-specific filter function for devices where the client's phandle matches the DMA providing device'sof_nodehandle.
Filter function is called in dmaengine core code, independent of dt. And the reason why the driver has to write its own filter function is it has to store slave id there in its own way.
Thanks
Richard
Quoted 26 lines · Richard Zhao
Quoted 25 lines · Stephen Warren
Quoted 14 lines · Richard Zhao
Quoted 12 lines · Richard Zhao
pass
of_phandle_argsdma_spectodma_request_channelinof_dma_simple_xlate, so the filter function could accessof_nodeinof_phandle_args.It also remove restriction of #dma-cells has to be one.
Signed-off-by Richard Zhao <[email protected]>--- drivers/dma/edma.c | 7 +++++-- drivers/dma/of-dma.c | 10 ++++------ drivers/dma/omap-dma.c | 6 ++++-- 3 files changed, 13 insertions(+), 10 deletions(-)Quoted 7 lines
Hi Vinod,
Can you please pick up this change?
Hi Stephen,
Can you please give a ack or reviewed-by etc?
Hmm. Looking at the patch, I'm not sure it's right.
Quoted 8 lines
Quoted 6 lines
This patch simply passes all the specfier args to the filter function, and the code to check the equality of the
of_nodeto the filter args is still duplicated in each DMA driver. Instead, the DMA core should be implementing the equality check, and only even calling the driver-specific filter function for devices where the client's phandle matches the DMA providing device'sof_nodehandle.Filter function is called in dmaengine core code, independent of dt.
The core code can still check if a dmaengine's driver was instantiated from DT and take additional actions in that case.
Quoted 2 lines
And the reason why the driver has to write its own filter function is it has to store slave id there in its own way.
I'm not saying don't call the driver's filter function, but rather that the dmaengine core should perform the common checks before doing so.
Quoted 37 lines · On Friday 23 August 2013 09:57:43 Stephen Warren wrote:
Quoted 27 lines · Richard Zhao
Quoted 26 lines · Stephen Warren
Quoted 15 lines · Richard Zhao
Quoted 6 lines · Richard Zhao
pass
of_phandle_argsdma_spectodma_request_channelinof_dma_simple_xlate, so the filter function could accessof_nodeinof_phandle_args.It also remove restriction of #dma-cells has to be one.
Quoted 7 lines
Signed-off-by Richard Zhao <[email protected]>---
drivers/dma/edma.c | 7 +++++-- drivers/dma/of-dma.c | 10 ++++------ drivers/dma/omap-dma.c | 6 ++++-- 3 files changed, 13 insertions(+), 10 deletions(-)Quoted 7 lines
Hi Vinod,
Can you please pick up this change?
Hi Stephen,
Can you please give a ack or reviewed-by etc?
Hmm. Looking at the patch, I'm not sure it's right.
Quoted 8 lines
Quoted 6 lines
This patch simply passes all the specfier args to the filter function, and the code to check the equality of the
of_nodeto the filter args is still duplicated in each DMA driver. Instead, the DMA core should be implementing the equality check, and only even calling the driver-specific filter function for devices where the client's phandle matches the DMA providing device'sof_nodehandle.Filter function is called in dmaengine core code, independent of dt.
Quoted 8 lines
The core code can still check if a dmaengine's driver was instantiated from DT and take additional actions in that case.
Quoted 2 lines
And the reason why the driver has to write its own filter function is it has to store slave id there in its own way.
I'm not saying don't call the driver's filter function, but rather that the dmaengine core should perform the common checks before doing so.
And it looks to me like the common case could even get rid of the driver's filter function:
https://lkml.org/lkml/2013/5/15/270
https://lkml.org/lkml/2013/3/25/250
Signature · 3 lines
Regards, Laurent Pinchart
Quoted 44 lines · Laurent Pinchart
Quoted 43 lines · On Friday 23 August 2013 09:57:43 Stephen Warren wrote:
Quoted 27 lines · Richard Zhao
Quoted 26 lines · Stephen Warren
Quoted 15 lines · Richard Zhao
Quoted 6 lines · Richard Zhao
pass
of_phandle_argsdma_spectodma_request_channelinof_dma_simple_xlate, so the filter function could accessof_nodeinof_phandle_args.It also remove restriction of #dma-cells has to be one.
Quoted 7 lines
Signed-off-by Richard Zhao <[email protected]>---
drivers/dma/edma.c | 7 +++++-- drivers/dma/of-dma.c | 10 ++++------ drivers/dma/omap-dma.c | 6 ++++-- 3 files changed, 13 insertions(+), 10 deletions(-)Quoted 7 lines
Hi Vinod,
Can you please pick up this change?
Hi Stephen,
Can you please give a ack or reviewed-by etc?
Hmm. Looking at the patch, I'm not sure it's right.
Quoted 8 lines
Quoted 6 lines
This patch simply passes all the specfier args to the filter function, and the code to check the equality of the
of_nodeto the filter args is still duplicated in each DMA driver. Instead, the DMA core should be implementing the equality check, and only even calling the driver-specific filter function for devices where the client's phandle matches the DMA providing device'sof_nodehandle.Filter function is called in dmaengine core code, independent of dt.
The core code can still check if a dmaengine's driver was instantiated from DT and take additional actions in that case.
Quoted 2 lines
And the reason why the driver has to write its own filter function is it has to store slave id there in its own way.
Quoted 8 lines
Quoted 2 lines
I'm not saying don't call the driver's filter function, but rather that the dmaengine core should perform the common checks before doing so.
And it looks to me like the common case could even get rid of the driver's filter function:
https://lkml.org/lkml/2013/5/15/270
https://lkml.org/lkml/2013/3/25/250
For general case, the slave id is not staticly bind to a specific channel.
Thanks
Richard
Hi Richard,
(Dropping Dan Williams from the CC list as his e-mail address doesn't seem to be valid anymore)
Quoted 48 lines · On Monday 26 August 2013 20:55:57 Richard Zhao wrote:
Quoted 47 lines · Laurent Pinchart
Quoted 45 lines · On Friday 23 August 2013 09:57:43 Stephen Warren wrote:
Quoted 27 lines · Richard Zhao
Quoted 26 lines · Stephen Warren
Quoted 15 lines · Richard Zhao
Quoted 6 lines · Richard Zhao
pass
of_phandle_argsdma_spectodma_request_channelinof_dma_simple_xlate, so the filter function could accessof_nodeinof_phandle_args.It also remove restriction of #dma-cells has to be one.
Quoted 7 lines
Signed-off-by Richard Zhao <[email protected]>---
drivers/dma/edma.c | 7 +++++-- drivers/dma/of-dma.c | 10 ++++------ drivers/dma/omap-dma.c | 6 ++++-- 3 files changed, 13 insertions(+), 10 deletions(-)Quoted 7 lines
Hi Vinod,
Can you please pick up this change?
Hi Stephen,
Can you please give a ack or reviewed-by etc?
Hmm. Looking at the patch, I'm not sure it's right.
Quoted 8 lines
Quoted 6 lines
This patch simply passes all the specfier args to the filter function, and the code to check the equality of the
of_nodeto the filter args is still duplicated in each DMA driver. Instead, the DMA core should be implementing the equality check, and only even calling the driver-specific filter function for devices where the client's phandle matches the DMA providing device'sof_nodehandle.Filter function is called in dmaengine core code, independent of dt.
The core code can still check if a dmaengine's driver was instantiated from DT and take additional actions in that case.
Quoted 2 lines
And the reason why the driver has to write its own filter function is it has to store slave id there in its own way.
I'm not saying don't call the driver's filter function, but rather that the dmaengine core should perform the common checks before doing so.
Quoted 7 lines
Quoted 5 lines
And it looks to me like the common case could even get rid of the driver's filter function:
https://lkml.org/lkml/2013/5/15/270
https://lkml.org/lkml/2013/3/25/250For general case, the slave id is not staticly bind to a specific channel.
Certainly not in all cases, but I think it's common enough to deserve a specific helper function.
Signature · 3 lines
Regards, Laurent Pinchart
Quoted 28 lines · Laurent Pinchart
Hi Richard,
(Dropping Dan Williams from the CC list as his e-mail address doesn't seem to be valid anymore)
Quoted 23 lines
Quoted 23 lines
Quoted 11 lines
Quoted 10 lines
Quoted 8 lines
Hmm. Looking at the patch, I'm not sure it's right.
This patch simply passes all the specfier args to the filter function, and the code to check the equality of the
of_nodeto the filter args is still duplicated in each DMA driver. Instead, the DMA core should be implementing the equality check, and only even calling the driver-specific filter function for devices where the client's phandle matches the DMA providing device'sof_nodehandle.Filter function is called in dmaengine core code, independent of dt.
Quoted 8 lines
The core code can still check if a dmaengine's driver was instantiated from DT and take additional actions in that case.
Quoted 2 lines
And the reason why the driver has to write its own filter function is it has to store slave id there in its own way.
I'm not saying don't call the driver's filter function, but rather that the dmaengine core should perform the common checks before doing so.
And it looks to me like the common case could even get rid of the driver's filter function:
Quoted 7 lines
Quoted 4 lines
For general case, the slave id is not staticly bind to a specific channel.
Certainly not in all cases, but I think it's common enough to deserve a specific helper function.
Why does DT need the fliter function in the first place. The DT enabled drivers should not even have a filter function...
The dmaengine core calls the optional filter function. This needs to be implemented in driver in order for driver to check if the channel is what it needs or not.
And the selection should be done for the cases where you dont have programmable mux in dmac. For programmable ones passing slave_id in dma_slave_config should be fine.
~Vinod
Quoted 6 lines · On Monday 26 August 2013 19:40:57 Vinod Koul wrote:
Why does DT need the fliter function in the first place. The DT enabled drivers should not even have a filter function...
The dmaengine core calls the optional filter function. This needs to be implemented in driver in order for driver to check if the channel is what it needs or not.
You only just merged the dma_get_slave_channel() patch, which allows having no filter function. Up to Linux-3.11, the filter was always needed but could be 'static' and only called by the xlate function. Now the xlate function can pick a channel itself.
Quoted 3 lines
And the selection should be done for the cases where you dont have programmable mux in dmac. For programmable ones passing
slave_idindma_slave_configshould be fine.
I think passing a slave_id from the slave driver is never correct with DT, since the ID is a property of the system rather than the slave device, so the driver has no access to it. Drivers have to always take the settings from DT and ignore what dma_slave_config() sets later.
Arnd
Quoted 9 lines · Arnd Bergmann
Quoted 3 lines · On Monday 26 August 2013 19:40:57 Vinod Koul wrote:
And the selection should be done for the cases where you dont have programmable mux in dmac. For programmable ones passing
slave_idindma_slave_configshould be fine.I think passing a
slave_idfrom the slave driver is never correct with DT, since the ID is a property of the system rather than the slave device, so the driver has no access to it. Drivers have to always take the settings from DT and ignore whatdma_slave_config()sets later.
Shouldnt slave id be property of the client driver. That way we can pass it to the driver using dma_slave_config(). That should make it right..
~Vinod
Quoted 34 lines · Stephen Warren
Quoted 33 lines · Richard Zhao
Quoted 31 lines · Stephen Warren
Quoted 14 lines · Richard Zhao
Quoted 12 lines · Richard Zhao
pass
of_phandle_argsdma_spectodma_request_channelinof_dma_simple_xlate, so the filter function could accessof_nodeinof_phandle_args.It also remove restriction of #dma-cells has to be one.
Signed-off-by Richard Zhao <[email protected]>--- drivers/dma/edma.c | 7 +++++-- drivers/dma/of-dma.c | 10 ++++------ drivers/dma/omap-dma.c | 6 ++++-- 3 files changed, 13 insertions(+), 10 deletions(-)Quoted 7 lines
Hi Vinod,
Can you please pick up this change?
Hi Stephen,
Can you please give a ack or reviewed-by etc?
Hmm. Looking at the patch, I'm not sure it's right.
This patch simply passes all the specfier args to the filter function, and the code to check the equality of the
of_nodeto the filter args is still duplicated in each DMA driver. Instead, the DMA core should be implementing the equality check, and only even calling the driver-specific filter function for devices where the client's phandle matches the DMA providing device'sof_nodehandle.
Quoted 6 lines
Quoted 1 line
Filter function is called in dmaengine core code, independent of dt.
The core code can still check if a dmaengine's driver was instantiated from DT and take additional actions in that case.
From perspective of core code, the filter function is not attached to
any dma driver. So it doesn't care whether dt dma driver is instantiated. I'm not sure I've got your point. Can you please write pieces of code if possible?
The goal of this patch is to use least changes to add check of dt node.
Thanks
Richard
Quoted 7 lines
Quoted 3 lines
And the reason why the driver has to write its own filter function is it has to store slave id there in its own way.
I'm not saying don't call the driver's filter function, but rather that the dmaengine core should perform the common checks before doing so.