dmaengine: tegra-apb: Various updates
Subsystems (3)
Jon Hunter
maintainercover dmaengine: tegra-apb: Various updates
A few updates for the tegra-apb driver. Build tested for ARM and ARM64 and the driver has been tested on tegra124 with the HSUART driver that uses DMA.
Jon Hunter (6):
dmaengine: tegra-apb: Correct runtime-pm usage
dmaengine: tegra-apb: Use dev_get_drvdata()
dmaengine: tegra-apb: Save and restore word count
dmaengine: tegra-apb: Only save channel state for those in use
dmaengine: tegra-apb: Update driver to use GFP_NOWAIT
dmaengine: tegra-apb: Disable interrupts on removal
drivers/dma/tegra20-apb-dma.c | 79 ++++++++++++++++++++++--------------------- 1 file changed, 41 insertions(+), 38 deletions(-)
Signature · 1 line
2.1.4
Jon Hunter
maintainerPATCH 1/6 dmaengine: tegra-apb: Correct runtime-pm usage
The tegra-apb DMA driver enables runtime-pm but never calls pm_runtime_get/put and hence the runtime-pm callbacks are never invoked. The driver manages the clocks by directly calling clk_prepare_enable() and clk_unprepare_disable().
Fix this by replacing the clk_prepare_enable() and clk_disable_unprepare() with pm_runtime_get_sync() and pm_runtime_put(), respectively. Note that the consequence of this is that if runtime-pm is disabled, then the clocks will remain on the entire time the driver is loaded. However, if runtime-pm is disabled, then power is not most likely not a concern.
--- drivers/dma/tegra20-apb-dma.c | 50 ++++++++++++++++--------------------------- 1 file changed, 18 insertions(+), 32 deletions(-)
drivers/dma/tegra20-apb-dma.c +18 -32
@@ -1182,14 +1182,11 @@ static int tegra_dma_alloc_chan_resources(struct dma_chan *dc) {struct tegra_dma_channel *tdc =to_tegra_dma_chan (dc);struct tegra_dma *tdma = tdc->tdma; -int ret;dma_cookie_init (&tdc->dma_chan); tdc->config_init = false; - ret =clk_prepare_enable (tdma->dma_clk); -if (ret <0 ) -dev_err (tdc2dev (tdc),"clk_prepare_enable failed: %d\n" , ret); -return ret; + +return pm_runtime_get_sync (tdma->dev); }static void tegra_dma_free_chan_resources (struct dma_chan *dc)
@@ -1232,7 +1229,7 @@ static void tegra_dma_free_chan_resources(struct dma_chan *dc)list_del (&sg_req->node);kfree (sg_req); } -clk_disable_unprepare (tdma->dma_clk); +pm_runtime_put (tdma->dev); tdc->slave_id =0 ; }
@@ -1356,20 +1353,14 @@ static int tegra_dma_probe(struct platform_device *pdev)spin_lock_init (&tdma->global_lock);pm_runtime_enable (&pdev->dev); -if (!pm_runtime_enabled (&pdev->dev)) { +if (!pm_runtime_enabled (&pdev->dev)) ret =tegra_dma_runtime_resume (&pdev->dev); -if (ret) { -dev_err (&pdev->dev,"dma_runtime_resume failed %d\n" , - ret); - goto err_pm_disable; - } - } +else + ret =pm_runtime_get_sync (&pdev->dev); -/* Enable clock before accessing registers */ - ret =clk_prepare_enable (tdma->dma_clk); -if (ret <0 ) { -dev_err (&pdev->dev,"clk_prepare_enable failed: %d\n" , ret); - goto err_pm_disable; +if (ret) { +pm_runtime_disable (&pdev->dev); +return ret; }/* Reset DMA controller */
@@ -1382,7 +1373,7 @@ static int tegra_dma_probe(struct platform_device *pdev)tdma_write (tdma,TEGRA_APBDMA_CONTROL ,0 );tdma_write (tdma,TEGRA_APBDMA_IRQ_MASK_SET ,0xFFFFFFFFul ); -clk_disable_unprepare (tdma->dma_clk); +pm_runtime_put (&pdev->dev);INIT_LIST_HEAD (&tdma->dma_dev.channels);for (i =0 ; i < cdata->nr_channels; i++) {
@@ -1485,7 +1476,6 @@ err_irq:tasklet_kill (&tdc->tasklet); } -err_pm_disable:pm_runtime_disable (&pdev->dev);if (!pm_runtime_status_suspended (&pdev->dev))tegra_dma_runtime_suspend (&pdev->dev);
@@ -1539,11 +1529,10 @@ static int tegra_dma_runtime_resume(struct device *dev)static int tegra_dma_pm_suspend (struct device *dev) {struct tegra_dma *tdma =dev_get_drvdata (dev); -int i; -int ret; +int i, ret;/* Enable clock before accessing register */ - ret =tegra_dma_runtime_resume (dev); + ret =pm_runtime_get_sync (dev);if (ret <0 )return ret;
@@ -1560,18 +1549,17 @@ static int tegra_dma_pm_suspend(struct device *dev) }/* Disable clock */ -tegra_dma_runtime_suspend (dev); +pm_runtime_put (dev);return 0 ; }static int tegra_dma_pm_resume (struct device *dev) {struct tegra_dma *tdma =dev_get_drvdata (dev); -int i; -int ret; +int i, ret;/* Enable clock before accessing register */ - ret =tegra_dma_runtime_resume (dev); + ret =pm_runtime_get_sync (dev);if (ret <0 )return ret;
@@ -1592,16 +1580,14 @@ static int tegra_dma_pm_resume(struct device *dev) }/* Disable clock */ -tegra_dma_runtime_suspend (dev); +pm_runtime_put (dev);return 0 ; }#endif static const struct dev_pm_ops tegra_dma_dev_pm_ops = { -#ifdef CONFIG_PM - .runtime_suspend = tegra_dma_runtime_suspend, - .runtime_resume = tegra_dma_runtime_resume, -#endif + SET_RUNTIME_PM_OPS(tegra_dma_runtime_suspend, tegra_dma_runtime_resume, + NULL)SET_SYSTEM_SLEEP_PM_OPS (tegra_dma_pm_suspend, tegra_dma_pm_resume) };
Signature · 1 line
2.1.4
Re: [PATCH 1/6] dmaengine: tegra-apb: Correct runtime-pm usage
Quoted 4 lines · Jon Hunter
drivers/dma/tegra20-apb-dma.c +0
-0@@ -1182,14 +1182,11 @@ static int tegra_dma_alloc_chan_resources(struct dma_chan *dc) {struct tegra_dma_channel *tdc =to_tegra_dma_chan (dc);struct tegra_dma *tdma = tdc->tdma;
drivers/dma/tegra20-apb-dma.c static int tegra_dma_alloc_chan_resources(struct dma_chan *dc) · line 1189
Quoted 10 lines
drivers/dma/tegra20-apb-dma.c +2
-5-int ret;dma_cookie_init (&tdc->dma_chan); tdc->config_init = false; - ret =clk_prepare_enable (tdma->dma_clk); -if (ret <0 ) -dev_err (tdc2dev (tdc),"clk_prepare_enable failed: %d\n" , ret); -return ret; + +return pm_runtime_get_sync (tdma->dev);
Alloc channel is supposed to return number of descriptors allocated and if pm_runtime_get_sync() returns postive values we get wrong return!
drivers/dma/tegra20-apb-dma.c static int tegra_dma_probe(struct platform_device *pdev) · line 1359
Quoted 12 lines
drivers/dma/tegra20-apb-dma.c +3
-7pm_runtime_enable (&pdev->dev); -if (!pm_runtime_enabled (&pdev->dev)) { +if (!pm_runtime_enabled (&pdev->dev)) ret =tegra_dma_runtime_resume (&pdev->dev); -if (ret) { -dev_err (&pdev->dev,"dma_runtime_resume failed %d\n" , - ret); - goto err_pm_disable; - } - } +else + ret =pm_runtime_get_sync (&pdev->dev);
do we need pm_runtime_get() here, should we use pm_request_resume() ?
drivers/dma/tegra20-apb-dma.c static int tegra_dma_runtime_resume(struct device *dev) · line 1535
Quoted 10 lines
static int
tegra_dma_pm_suspend(struct device *dev){drivers/dma/tegra20-apb-dma.c +2
-3struct tegra_dma *tdma =dev_get_drvdata (dev); -int i; -int ret; +int i, ret;/* Enable clock before accessing register */ - ret =tegra_dma_runtime_resume (dev); + ret =pm_runtime_get_sync (dev);
If you are runtime suspended then core will runtime resume you before invoking suspend, so why do we need this
Signature · 1 line
~Vinod
Jon Hunter
maintainerRe: [PATCH 1/6] dmaengine: tegra-apb: Correct runtime-pm usage
Quoted 7 lines · Vinod Koul
Quoted 6 lines · Jon Hunter
drivers/dma/tegra20-apb-dma.c +0
-1@@ -1182,14 +1182,11 @@ static int tegra_dma_alloc_chan_resources(struct dma_chan *dc) {struct tegra_dma_channel *tdc =to_tegra_dma_chan (dc);struct tegra_dma *tdma = tdc->tdma; -int ret;
Quoted 11 lines
drivers/dma/tegra20-apb-dma.c static int tegra_dma_alloc_chan_resources(struct dma_chan *dc) · line 1189
Quoted 8 lines
drivers/dma/tegra20-apb-dma.c +2
-4dma_cookie_init (&tdc->dma_chan); tdc->config_init = false; - ret =clk_prepare_enable (tdma->dma_clk); -if (ret <0 ) -dev_err (tdc2dev (tdc),"clk_prepare_enable failed: %d\n" , ret); -return ret; + +return pm_runtime_get_sync (tdma->dev);Alloc channel is supposed to return number of descriptors allocated and if
pm_runtime_get_sync()returns postive values we get wrong return!
Yes I will fix. I assume that returning 0 is allowed if no descriptors are allocated here. So much for correcting rpm usage ;-)
Quoted 6 lines
Quoted 6 lines
drivers/dma/tegra20-apb-dma.c +1
-3pm_runtime_enable (&pdev->dev); -if (!pm_runtime_enabled (&pdev->dev)) { +if (!pm_runtime_enabled (&pdev->dev)) ret =tegra_dma_runtime_resume (&pdev->dev); -if (ret) { - dev_err(&pdev->dev, "dma_runtime_resume failed %d\n",
Quoted 8 lines
drivers/dma/tegra20-apb-dma.c static int tegra_dma_probe(struct platform_device *pdev) · line 1359
Quoted 6 lines
drivers/dma/tegra20-apb-dma.c +2
-4- ret); - goto err_pm_disable; - } - } +else + ret =pm_runtime_get_sync (&pdev->dev);do we need
pm_runtime_get()here, should we usepm_request_resume()?
We definitely want pm_runtime_get_sync() because pm_request_resume() is an ASYNC resume and so does not guarantee the device is accessible after the call returns. The pm_runtime_get variant is nice too because it keeps track of the number of gets and puts that have occurred.
Quoted 7 lines
Quoted 7 lines
static int
tegra_dma_pm_suspend(struct device *dev){drivers/dma/tegra20-apb-dma.c +1
-2struct tegra_dma *tdma =dev_get_drvdata (dev); -int i; -int ret; +int i, ret;
Quoted 6 lines
drivers/dma/tegra20-apb-dma.c static int tegra_dma_runtime_resume(struct device *dev) · line 1535
Quoted 3 lines
drivers/dma/tegra20-apb-dma.c +1
-1/* Enable clock before accessing register */ - ret =tegra_dma_runtime_resume (dev); + ret =pm_runtime_get_sync (dev);If you are runtime suspended then core will runtime resume you before invoking suspend, so why do we need this
Is this change now in the mainline? Do you have commit ID for that?
I recall the last time we discussed this that Rafael said that they were going to do that, but he said as a rule of thumb if you need to resume it, resume it [0].
Cheers
Jon
Re: [PATCH 1/6] dmaengine: tegra-apb: Correct runtime-pm usage
Quoted 21 lines · Jon Hunter
Quoted 7 lines · Vinod Koul
Quoted 6 lines · Jon Hunter
drivers/dma/tegra20-apb-dma.c +0
-1@@ -1182,14 +1182,11 @@ static int tegra_dma_alloc_chan_resources(struct dma_chan *dc) {struct tegra_dma_channel *tdc =to_tegra_dma_chan (dc);struct tegra_dma *tdma = tdc->tdma; -int ret;Quoted 11 lines
drivers/dma/tegra20-apb-dma.c static int tegra_dma_alloc_chan_resources(struct dma_chan *dc) · line 1189
Quoted 8 lines
drivers/dma/tegra20-apb-dma.c +2
-4dma_cookie_init (&tdc->dma_chan); tdc->config_init = false; - ret =clk_prepare_enable (tdma->dma_clk); -if (ret <0 ) -dev_err (tdc2dev (tdc),"clk_prepare_enable failed: %d\n" , ret); -return ret; + +return pm_runtime_get_sync (tdma->dev);Alloc channel is supposed to return number of descriptors allocated and if
pm_runtime_get_sync()returns postive values we get wrong return!
Quoted 2 lines
Yes I will fix. I assume that returning 0 is allowed if no descriptors are allocated here. So much for correcting rpm usage ;-)
Yes 0 is allowed...
Quoted 14 lines
Quoted 7 lines
Quoted 7 lines
drivers/dma/tegra20-apb-dma.c +1
-2static int tegra_dma_pm_suspend (struct device *dev) {struct tegra_dma *tdma =dev_get_drvdata (dev); -int i; -int ret; +int i, ret;Quoted 6 lines
drivers/dma/tegra20-apb-dma.c static int tegra_dma_runtime_resume(struct device *dev) · line 1535
Quoted 3 lines
drivers/dma/tegra20-apb-dma.c +1
-1/* Enable clock before accessing register */ - ret =tegra_dma_runtime_resume (dev); + ret =pm_runtime_get_sync (dev);If you are runtime suspended then core will runtime resume you before invoking suspend, so why do we need this
Quoted 5 lines
Is this change now in the mainline? Do you have commit ID for that?
I recall the last time we discussed this that Rafael said that they were going to do that, but he said as a rule of thumb if you need to resume it, resume it [0].
IIRC this has been always the behaviour, at least I see this when I test the devices
Signature · 1 line
~Vinod
Jon Hunter
maintainerRe: [PATCH 1/6] dmaengine: tegra-apb: Correct runtime-pm usage
Quoted 41 lines · Vinod Koul
Quoted 21 lines · Jon Hunter
Quoted 7 lines · Vinod Koul
Quoted 6 lines · Jon Hunter
drivers/dma/tegra20-apb-dma.c +0
-1@@ -1182,14 +1182,11 @@ static int tegra_dma_alloc_chan_resources(struct dma_chan *dc) {struct tegra_dma_channel *tdc =to_tegra_dma_chan (dc);struct tegra_dma *tdma = tdc->tdma; -int ret;Quoted 11 lines
drivers/dma/tegra20-apb-dma.c static int tegra_dma_alloc_chan_resources(struct dma_chan *dc) · line 1189
Quoted 8 lines
drivers/dma/tegra20-apb-dma.c +2
-4dma_cookie_init (&tdc->dma_chan); tdc->config_init = false; - ret =clk_prepare_enable (tdma->dma_clk); -if (ret <0 ) -dev_err (tdc2dev (tdc),"clk_prepare_enable failed: %d\n" , ret); -return ret; + +return pm_runtime_get_sync (tdma->dev);Alloc channel is supposed to return number of descriptors allocated and if
pm_runtime_get_sync()returns postive values we get wrong return!Quoted 2 lines
Yes I will fix. I assume that returning 0 is allowed if no descriptors are allocated here. So much for correcting rpm usage ;-)
Yes 0 is allowed...
Quoted 14 lines
Quoted 13 lines
drivers/dma/tegra20-apb-dma.c static int tegra_dma_runtime_resume(struct device *dev) · line 1535
Quoted 10 lines
drivers/dma/tegra20-apb-dma.c +2
-3static int tegra_dma_pm_suspend (struct device *dev) {struct tegra_dma *tdma =dev_get_drvdata (dev); -int i; -int ret; +int i, ret;/* Enable clock before accessing register */ - ret =tegra_dma_runtime_resume (dev); + ret =pm_runtime_get_sync (dev);If you are runtime suspended then core will runtime resume you before invoking suspend, so why do we need this
Quoted 8 lines
Quoted 5 lines
Is this change now in the mainline? Do you have commit ID for that?
I recall the last time we discussed this that Rafael said that they were going to do that, but he said as a rule of thumb if you need to resume it, resume it [0].
IIRC this has been always the behaviour, at least I see this when I test the devices
I have been doing some testing today and if the DMA is runtime suspended, then I don't see it runtime resumed before suspend is called.
Can you elborate on "at least I see this when I test the devices"? What are you looking at? Are you using kernel function tracers in some way?
Cheers
Jon
Re: [PATCH 1/6] dmaengine: tegra-apb: Correct runtime-pm usage
Quoted 5 lines · Jon Hunter
Quoted 4 lines · Vinod Koul
Quoted 3 lines · Jon Hunter
Quoted 1 line · Vinod Koul
On Fri, Oct 16, 2015 at 09:25:52AM +0100, Jon Hunter wrote:
[...]
Quoted 13 lines
Quoted 13 lines
Quoted 12 lines
Quoted 6 lines
drivers/dma/tegra20-apb-dma.c static int tegra_dma_runtime_resume(struct device *dev) · line 1535
Quoted 3 lines
drivers/dma/tegra20-apb-dma.c +1
-1/* Enable clock before accessing register */ - ret =tegra_dma_runtime_resume (dev); + ret =pm_runtime_get_sync (dev);If you are runtime suspended then core will runtime resume you before invoking suspend, so why do we need this
Is this change now in the mainline? Do you have commit ID for that?
I recall the last time we discussed this that Rafael said that they were going to do that, but he said as a rule of thumb if you need to resume it, resume it [0].
Quoted 8 lines
Quoted 2 lines
IIRC this has been always the behaviour, at least I see this when I test the devices
I have been doing some testing today and if the DMA is runtime suspended, then I don't see it runtime resumed before suspend is called.
Can you elborate on "at least I see this when I test the devices"? What are you looking at? Are you using kernel function tracers in some way?
The PM core does a _get_noresume()[1] which tries to prevent runtime suspends *during* a system suspend. However, the PM core should not be doing an actual runtime resume of the device, so if the device is already runtime suspended, it will not be runtime resumed by the core, so if the driver needs it to be runtime resumed, it needs to do it itself.
Kevin
[1] c.f. drivers/base/power/main.c::device_prepare()
Re: [PATCH 1/6] dmaengine: tegra-apb: Correct runtime-pm usage
Quoted 22 lines · Kevin Hilman
Quoted 13 lines
Quoted 13 lines
Quoted 12 lines
Quoted 6 lines
drivers/dma/tegra20-apb-dma.c static int tegra_dma_runtime_resume(struct device *dev) · line 1535
Quoted 3 lines
drivers/dma/tegra20-apb-dma.c +1
-1/* Enable clock before accessing register */ - ret =tegra_dma_runtime_resume (dev); + ret =pm_runtime_get_sync (dev);If you are runtime suspended then core will runtime resume you before invoking suspend, so why do we need this
Is this change now in the mainline? Do you have commit ID for that?
I recall the last time we discussed this that Rafael said that they were going to do that, but he said as a rule of thumb if you need to resume it, resume it [0].
Quoted 8 lines
Quoted 2 lines
IIRC this has been always the behaviour, at least I see this when I test the devices
I have been doing some testing today and if the DMA is runtime suspended, then I don't see it runtime resumed before suspend is called.
Can you elborate on "at least I see this when I test the devices"? What are you looking at? Are you using kernel function tracers in some way?
Quoted 6 lines
The PM core does a _get_noresume()[1] which tries to prevent runtime suspends *during* a system suspend. However, the PM core should not be doing an actual runtime resume of the device, so if the device is already runtime suspended, it will not be runtime resumed by the core, so if the driver needs it to be runtime resumed, it needs to do it itself.
+ Rafael
This is contrariry to what I see, If my driver is runtime suspended and on suspend, it gets runtime resumed and then suspended
Signature · 1 line
~Vinod
Re: [PATCH 1/6] dmaengine: tegra-apb: Correct runtime-pm usage
Quoted 30 lines · Vinod Koul
Quoted 22 lines · Kevin Hilman
Quoted 13 lines
Quoted 13 lines
Quoted 12 lines
Quoted 6 lines
Review
Quoted 3 lines
(quoted diff) +1
-1/* Enable clock before accessing register */ - ret = tegra_dma_runtime_resume(dev); + ret = pm_runtime_get_sync(dev);If you are runtime suspended then core will runtime resume you before invoking suspend, so why do we need this
Is this change now in the mainline? Do you have commit ID for that?
I recall the last time we discussed this that Rafael said that they were going to do that, but he said as a rule of thumb if you need to resume it, resume it [0].
Quoted 8 lines
Quoted 2 lines
IIRC this has been always the behaviour, at least I see this when I test the devices
I have been doing some testing today and if the DMA is runtime suspended, then I don't see it runtime resumed before suspend is called.
Can you elborate on "at least I see this when I test the devices"? What are you looking at? Are you using kernel function tracers in some way?
Quoted 6 lines
The PM core does a _get_noresume()[1] which tries to prevent runtime suspends *during* a system suspend. However, the PM core should not be doing an actual runtime resume of the device, so if the device is already runtime suspended, it will not be runtime resumed by the core, so if the driver needs it to be runtime resumed, it needs to do it itself.
Quoted 4 lines
+ Rafael
This is contrariry to what I see, If my driver is runtime suspended and on suspend, it gets runtime resumed and then suspended
Since I was late to the thread, can you explain what kind of driver and on what bus type you're seeing this behavior?
It could be that your bus-type is doing something, but I don't think it should be the PM core.
Kevin
Re: [PATCH 1/6] dmaengine: tegra-apb: Correct runtime-pm usage
Quoted 34 lines · Kevin Hilman
Quoted 32 lines · Vinod Koul
Quoted 22 lines · Kevin Hilman
Quoted 13 lines
Quoted 13 lines
Quoted 12 lines
Quoted 6 lines
Review
Quoted 3 lines
(quoted diff) +1
-1/* Enable clock before accessing register */ - ret = tegra_dma_runtime_resume(dev); + ret = pm_runtime_get_sync(dev);If you are runtime suspended then core will runtime resume you before invoking suspend, so why do we need this
Is this change now in the mainline? Do you have commit ID for that?
I recall the last time we discussed this that Rafael said that they were going to do that, but he said as a rule of thumb if you need to resume it, resume it [0].
Quoted 8 lines
Quoted 2 lines
IIRC this has been always the behaviour, at least I see this when I test the devices
I have been doing some testing today and if the DMA is runtime suspended, then I don't see it runtime resumed before suspend is called.
Can you elborate on "at least I see this when I test the devices"? What are you looking at? Are you using kernel function tracers in some way?
Quoted 6 lines
The PM core does a _get_noresume()[1] which tries to prevent runtime suspends *during* a system suspend. However, the PM core should not be doing an actual runtime resume of the device, so if the device is already runtime suspended, it will not be runtime resumed by the core, so if the driver needs it to be runtime resumed, it needs to do it itself.
+ Rafael
Quoted 8 lines
Quoted 2 lines
This is contrariry to what I see, If my driver is runtime suspended and on suspend, it gets runtime resumed and then suspended
Since I was late to the thread, can you explain what kind of driver and on what bus type you're seeing this behavior?
It could be that your bus-type is doing something, but I don't think it should be the PM core.
Right.
Bus types do that, the core doesn't. The ACPI PM domain does that too for some devices.
So Vinod, more details, please.
Thanks,
Rafael
Re: [PATCH 1/6] dmaengine: tegra-apb: Correct runtime-pm usage
Quoted 11 lines · Rafael J. Wysocki
Quoted 10 lines
Quoted 4 lines
+ Rafael
This is contrariry to what I see, If my driver is runtime suspended and on suspend, it gets runtime resumed and then suspended
Since I was late to the thread, can you explain what kind of driver and on what bus type you're seeing this behavior?
It could be that your bus-type is doing something, but I don't think it should be the PM core.
Quoted 6 lines
Right.
Bus types do that, the core doesn't. The ACPI PM domain does that too for some devices.
So Vinod, more details, please.
Okay relooking at core I do think that runtime resume should not be invoked while suspending, as core seems to call pm_runtime_get_noresume() but I am still missing something here..
I do see this behaviour (runtime resume on suspend) on Intel audio drivers which are PCI devices, is PCI or ACPI doing some magic here.
I have seen this as consistent behavior and actually an irritant, as we used to download firmware in resume patch, but then we end up thrashing the controller while going to suspend!
Signature · 1 line
~Vinod
Jon Hunter
maintainerPATCH 2/6 dmaengine: tegra-apb: Use dev_get_drvdata()
In reply to Jon HunterIn the tegra_dma_runtime_suspend/resume functions, the pdev structure is not needed, and so just call dev_get_drvdata() to get the device data structure.
--- drivers/dma/tegra20-apb-dma.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)
drivers/dma/tegra20-apb-dma.c +2 -4
@@ -1504,8 +1504,7 @@ static int tegra_dma_remove(struct platform_device *pdev)static int tegra_dma_runtime_suspend (struct device *dev) { -struct platform_device *pdev =to_platform_device (dev); -struct tegra_dma *tdma =platform_get_drvdata (pdev); +struct tegra_dma *tdma =dev_get_drvdata (dev);clk_disable_unprepare (tdma->dma_clk);return 0 ;
@@ -1513,8 +1512,7 @@ static int tegra_dma_runtime_suspend(struct device *dev)static int tegra_dma_runtime_resume (struct device *dev) { -struct platform_device *pdev =to_platform_device (dev); -struct tegra_dma *tdma =platform_get_drvdata (pdev); +struct tegra_dma *tdma =dev_get_drvdata (dev);int ret; ret =clk_prepare_enable (tdma->dma_clk);
Signature · 1 line
2.1.4
Jon Hunter
maintainerPATCH 3/6 dmaengine: tegra-apb: Save and restore word count
In reply to Jon HunterNewer tegra devices have a separate word count register per channel that contains the number of words to be transferred. This register is not saved or restored by the suspend/resume helpers for these newer devices and so ensure that it is.
--- drivers/dma/tegra20-apb-dma.c | 6 ++++++ 1 file changed, 6 insertions(+)
drivers/dma/tegra20-apb-dma.c +6 -0
@@ -1544,6 +1544,9 @@ static int tegra_dma_pm_suspend(struct device *dev) ch_reg->apb_ptr =tdc_read (tdc,TEGRA_APBDMA_CHAN_APBPTR ); ch_reg->ahb_seq =tdc_read (tdc,TEGRA_APBDMA_CHAN_AHBSEQ ); ch_reg->apb_seq =tdc_read (tdc,TEGRA_APBDMA_CHAN_APBSEQ ); +if (tdma->chip_data->support_separate_wcount_reg) + ch_reg->wcount =tdc_read (tdc, +TEGRA_APBDMA_CHAN_WCOUNT ); }/* Disable clock */
@@ -1569,6 +1572,9 @@ static int tegra_dma_pm_resume(struct device *dev)struct tegra_dma_channel *tdc = &tdma->channels[i];struct tegra_dma_channel_regs *ch_reg = &tdc->channel_reg; +if (tdma->chip_data->support_separate_wcount_reg) +tdc_write (tdc,TEGRA_APBDMA_CHAN_WCOUNT , + ch_reg->wcount);tdc_write (tdc,TEGRA_APBDMA_CHAN_APBSEQ , ch_reg->apb_seq);tdc_write (tdc,TEGRA_APBDMA_CHAN_APBPTR , ch_reg->apb_ptr);tdc_write (tdc,TEGRA_APBDMA_CHAN_AHBSEQ , ch_reg->ahb_seq);
Signature · 1 line
2.1.4
Jon Hunter
maintainerPATCH 4/6 dmaengine: tegra-apb: Only save channel state for those in use
In reply to Jon HunterCurrently the tegra-apb DMA driver suspend/resume helpers, save and restore the registers for all channels regardless of whether they are in use or not. Change this so that only channels that have been allocated and configured are saved and restored.
--- drivers/dma/tegra20-apb-dma.c | 12 ++++++++++++ 1 file changed, 12 insertions(+)
drivers/dma/tegra20-apb-dma.c +12 -0
@@ -1539,6 +1539,12 @@ static int tegra_dma_pm_suspend(struct device *dev)struct tegra_dma_channel *tdc = &tdma->channels[i];struct tegra_dma_channel_regs *ch_reg = &tdc->channel_reg; +/* +* Only save the state of DMA channels that are in use. +*/ +if (!tdc->config_init) +continue ; + ch_reg->csr =tdc_read (tdc,TEGRA_APBDMA_CHAN_CSR ); ch_reg->ahb_ptr =tdc_read (tdc,TEGRA_APBDMA_CHAN_AHBPTR ); ch_reg->apb_ptr =tdc_read (tdc,TEGRA_APBDMA_CHAN_APBPTR );
@@ -1572,6 +1578,12 @@ static int tegra_dma_pm_resume(struct device *dev)struct tegra_dma_channel *tdc = &tdma->channels[i];struct tegra_dma_channel_regs *ch_reg = &tdc->channel_reg; +/* +* Only restore the state of DMA channels that are in use. +*/ +if (!tdc->config_init) +continue ; +if (tdma->chip_data->support_separate_wcount_reg)tdc_write (tdc,TEGRA_APBDMA_CHAN_WCOUNT , ch_reg->wcount);
Signature · 1 line
2.1.4
Jon Hunter
maintainerPATCH 5/6 dmaengine: tegra-apb: Update driver to use GFP_NOWAIT
In reply to Jon HunterThe tegra20-apb-dma driver currently uses the flag GFP_ATOMIC when allocating memory for structures used in conjunction with the DMA descriptors. It is preferred that dmaengine drivers use GFP_NOWAIT instead and so the emergency memory pool will not be used by these drivers.
--- drivers/dma/tegra20-apb-dma.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/dma/tegra20-apb-dma.c +2 -2
@@ -296,7 +296,7 @@ static struct tegra_dma_desc *tegra_dma_desc_get(spin_unlock_irqrestore (&tdc->lock, flags);/* Allocate DMA desc */ - dma_desc =kzalloc (sizeof (*dma_desc),GFP_ATOMIC ); + dma_desc =kzalloc (sizeof (*dma_desc),GFP_NOWAIT );if (!dma_desc) {dev_err (tdc2dev (tdc),"dma_desc alloc failed\n" );return NULL ;
@@ -336,7 +336,7 @@ static struct tegra_dma_sg_req *tegra_dma_sg_req_get( }spin_unlock_irqrestore (&tdc->lock, flags); - sg_req =kzalloc (sizeof (struct tegra_dma_sg_req ),GFP_ATOMIC ); + sg_req =kzalloc (sizeof (struct tegra_dma_sg_req ),GFP_NOWAIT );if (!sg_req)dev_err (tdc2dev (tdc),"sg_req alloc failed\n" );return sg_req;
Signature · 1 line
2.1.4
Jon Hunter
maintainerPATCH 6/6 dmaengine: tegra-apb: Disable interrupts on removal
In reply to Jon HunterOn driver removal, before killing any tasklets, ensure that the channel interrupts are disabled so that the tasklet will not try to run during or after the removal of the driver.
--- drivers/dma/tegra20-apb-dma.c | 1 + 1 file changed, 1 insertion(+)
drivers/dma/tegra20-apb-dma.c +1 -0
@@ -1492,6 +1492,7 @@ static int tegra_dma_remove(struct platform_device *pdev)for (i =0 ; i < tdma->chip_data->nr_channels; ++i) { tdc = &tdma->channels[i]; +disable_irq (tdc->irq);tasklet_kill (&tdc->tasklet); }
Signature · 1 line
2.1.4
Re: [PATCH 6/6] dmaengine: tegra-apb: Disable interrupts on removal
Quoted 14 lines · Jon Hunter
On driver removal, before killing any tasklets, ensure that the channel interrupts are disabled so that the tasklet will not try to run during or after the removal of the driver.
Signed-off-by Jon Hunter <[email protected]>--- drivers/dma/tegra20-apb-dma.c | 1 + 1 file changed, 1 insertion(+)drivers/dma/tegra20-apb-dma.c +0
-0
drivers/dma/tegra20-apb-dma.c static int tegra_dma_remove(struct platform_device *pdev) · line 1495
Quoted 4 lines
drivers/dma/tegra20-apb-dma.c +1
-0@@ -1492,6 +1492,7 @@ static int tegra_dma_remove(struct platform_device *pdev)for (i =0 ; i < tdma->chip_data->nr_channels; ++i) { tdc = &tdma->channels[i]; +disable_irq (tdc->irq);
How about just calling free_irq()? That's how you'd typically handle this.
Quoted 4 lines
drivers/dma/tegra20-apb-dma.c +0
-0tasklet_kill (&tdc->tasklet); }
Jon Hunter
maintainerRe: [PATCH 6/6] dmaengine: tegra-apb: Disable interrupts on removal
Quoted 16 lines · Lars-Peter Clausen
Quoted 15 lines · Jon Hunter
On driver removal, before killing any tasklets, ensure that the channel interrupts are disabled so that the tasklet will not try to run during or after the removal of the driver.
Signed-off-by Jon Hunter <[email protected]>--- drivers/dma/tegra20-apb-dma.c | 1 + 1 file changed, 1 insertion(+)drivers/dma/tegra20-apb-dma.c +0
-0@@ -1492,6 +1492,7 @@ static int tegra_dma_remove(struct platform_device *pdev)
Quoted 5 lines
drivers/dma/tegra20-apb-dma.c static int tegra_dma_remove(struct platform_device *pdev) · line 1495
Quoted 3 lines
drivers/dma/tegra20-apb-dma.c +1
-0for (i =0 ; i < tdma->chip_data->nr_channels; ++i) { tdc = &tdma->channels[i]; +disable_irq (tdc->irq);How about just calling
free_irq()? That's how you'd typically handle this.
Yes, however, the interrupt is requested by devm_request_irq(). I guess I could call devm_free_irq() here?
Cheers
Jon
Re: [PATCH 6/6] dmaengine: tegra-apb: Disable interrupts on removal
Quoted 18 lines · Jon Hunter
Quoted 16 lines · Lars-Peter Clausen
Quoted 15 lines · Jon Hunter
On driver removal, before killing any tasklets, ensure that the channel interrupts are disabled so that the tasklet will not try to run during or after the removal of the driver.
Signed-off-by Jon Hunter <[email protected]>--- drivers/dma/tegra20-apb-dma.c | 1 + 1 file changed, 1 insertion(+)drivers/dma/tegra20-apb-dma.c +0
-0@@ -1492,6 +1492,7 @@ static int tegra_dma_remove(struct platform_device *pdev)
Quoted 8 lines
Quoted 5 lines
drivers/dma/tegra20-apb-dma.c static int tegra_dma_remove(struct platform_device *pdev) · line 1495
Quoted 3 lines
drivers/dma/tegra20-apb-dma.c +1
-0for (i =0 ; i < tdma->chip_data->nr_channels; ++i) { tdc = &tdma->channels[i]; +disable_irq (tdc->irq);How about just calling
free_irq()? That's how you'd typically handle this.Yes, however, the interrupt is requested by
devm_request_irq(). I guess I could calldevm_free_irq()here?
Just use request_irq() instead of devm_request_irq(). You have the same issue on the error path in the probe function anyway and also need to add the free_irq() before the tasklet_kill() there as well.
Jon Hunter
maintainerRe: [PATCH 6/6] dmaengine: tegra-apb: Disable interrupts on removal
Quoted 25 lines · Lars-Peter Clausen
Quoted 24 lines · Jon Hunter
Quoted 21 lines · Lars-Peter Clausen
Quoted 14 lines · Jon Hunter
On driver removal, before killing any tasklets, ensure that the channel interrupts are disabled so that the tasklet will not try to run during or after the removal of the driver.
Signed-off-by Jon Hunter <[email protected]>--- drivers/dma/tegra20-apb-dma.c | 1 + 1 file changed, 1 insertion(+)drivers/dma/tegra20-apb-dma.c +0
-0drivers/dma/tegra20-apb-dma.c static int tegra_dma_remove(struct platform_device *pdev) · line 1495
Quoted 4 lines
drivers/dma/tegra20-apb-dma.c +1
-0@@ -1492,6 +1492,7 @@ static int tegra_dma_remove(struct platform_device *pdev)for (i =0 ; i < tdma->chip_data->nr_channels; ++i) { tdc = &tdma->channels[i]; +disable_irq (tdc->irq);How about just calling
free_irq()? That's how you'd typically handle this.
Quoted 6 lines
Quoted 2 lines
Yes, however, the interrupt is requested by
devm_request_irq(). I guess I could calldevm_free_irq()here?Just use
request_irq()instead ofdevm_request_irq(). You have the same issue on the error path in the probe function anyway and also need to add thefree_irq()before thetasklet_kill()there as well.
I was wondering about that but the tasklets should never be scheduled if the probe does not succeed, so I think it is ok.
Jon
Re: [PATCH 6/6] dmaengine: tegra-apb: Disable interrupts on removal
Quoted 11 lines · Jon Hunter
Quoted 8 lines
Quoted 4 lines
Quoted 1 line
How about just calling
free_irq()? That's how you'd typically handle this.Yes, however, the interrupt is requested by
devm_request_irq(). I guess I could calldevm_free_irq()here?Just use
request_irq()instead ofdevm_request_irq(). You have the same issue on the error path in the probe function anyway and also need to add thefree_irq()before thetasklet_kill()there as well.I was wondering about that but the tasklets should never be scheduled if the probe does not succeed, so I think it is ok.
This is actually very racy, if probe fails but due to devm_ calls your irq is alive till it freed by core
And a faulty device triggering irq can complicate matters, so for irq IMHO we don't get much benefit with devm_ variant
Signature · 1 line
~Vinod
Jon Hunter
maintainerRe: [PATCH 6/6] dmaengine: tegra-apb: Disable interrupts on removal
Quoted 10 lines · Vinod Koul
Quoted 9 lines · Jon Hunter
Quoted 8 lines
Quoted 4 lines
Quoted 1 line
How about just calling
free_irq()? That's how you'd typically handle this.Yes, however, the interrupt is requested by
devm_request_irq(). I guess I could calldevm_free_irq()here?Just use
request_irq()instead ofdevm_request_irq(). You have the same issue on the error path in the probe function anyway and also need to add thefree_irq()before thetasklet_kill()there as well.
Quoted 8 lines
Quoted 2 lines
I was wondering about that but the tasklets should never be scheduled if the probe does not succeed, so I think it is ok.
This is actually very racy, if probe fails but due to
devm_calls your irq is alive till it freed by coreAnd a faulty device triggering irq can complicate matters, so for irq IMHO we don't get much benefit with
devm_variant
That's fine, I will drop the devm_ usage here then.
Jon