* [PATCH 2/3] dmaengine: add dmaengine_pm_get()/dmaengine_pm_put() functions
[not found] <1429191554-24972-1-git-send-email-r.baldyga@samsung.com>
2015-04-16 13:39 ` [PATCH 1/3] amba: add no_pm_pclk_management flag to amba_driver Robert Baldyga
@ 2015-04-16 13:39 ` Robert Baldyga
2015-04-16 13:39 ` [PATCH 3/3] dmaengine: pl330: get rid of pm_runtime_irq_safe() Robert Baldyga
2 siblings, 0 replies; 5+ messages in thread
From: Robert Baldyga @ 2015-04-16 13:39 UTC (permalink / raw)
To: linux, dan.j.williams, vinod.koul
Cc: lars, dmaengine, linux-kernel, m.szyprowski, Robert Baldyga
This patch introduces dmaengine_pm_{get, put}() functions. They can be
useful for better power management, as dma_issue_pending() can be called
from atomic context, so we can't use non-irqsafe runtime pm inside of
it. The new API functions can be called only from non-atomic context,
and they can be used to tell dmaengine driver that we are going to use
given DMA channel in near future. In the result power domain can be switched
off when DMA client doesn't plan to use DMA channel for some time, which
can give us some power save.
For backward compatibility we call dmaengine_pm_get() automatically when
channel is requested. If client want to use dmaengine_pm, he can call
dmaengine_pm_put() after obtaining channel, and then embrace access
to channel with dmaengine_pm_get/put() calls.
Signed-off-by: Robert Baldyga <r.baldyga@samsung.com>
---
drivers/dma/dmaengine.c | 40 ++++++++++++++++++++++++++++++++++++++++
include/linux/dmaengine.h | 13 +++++++++++++
2 files changed, 53 insertions(+)
diff --git a/drivers/dma/dmaengine.c b/drivers/dma/dmaengine.c
index ac336a9..26938f2 100644
--- a/drivers/dma/dmaengine.c
+++ b/drivers/dma/dmaengine.c
@@ -241,6 +241,13 @@ static int dma_chan_get(struct dma_chan *chan)
goto err_out;
}
+ if (chan->device->device_pm_get) {
+ chan->pm_get_count = 1;
+ ret = chan->device->device_pm_get(chan);
+ if (ret < 0)
+ goto err_out;
+ }
+
if (!dma_has_cap(DMA_PRIVATE, chan->device->cap_mask))
balance_ref_count(chan);
@@ -268,11 +275,44 @@ static void dma_chan_put(struct dma_chan *chan)
chan->client_count--;
module_put(dma_chan_to_owner(chan));
+ if (chan->device->device_pm_put && chan->pm_get_count)
+ chan->device->device_pm_put(chan);
+
/* This channel is not in use anymore, free it */
if (!chan->client_count && chan->device->device_free_chan_resources)
chan->device->device_free_chan_resources(chan);
}
+int dmaengine_pm_get(struct dma_chan *chan)
+{
+ int ret = -ENOSYS;
+
+ if (chan->device->device_pm_get) {
+ mutex_lock(&dma_list_mutex);
+ ret = chan->pm_get_count++ ?
+ 0 : chan->device->device_pm_get(chan);
+ mutex_unlock(&dma_list_mutex);
+ }
+
+ return ret;
+}
+EXPORT_SYMBOL(dmaengine_pm_get);
+
+int dmaengine_pm_put(struct dma_chan *chan)
+{
+ int ret = -ENOSYS;
+
+ if (chan->device->device_pm_put) {
+ mutex_lock(&dma_list_mutex);
+ ret = --chan->pm_get_count ?
+ 0 : chan->device->device_pm_put(chan);
+ mutex_unlock(&dma_list_mutex);
+ }
+
+ return ret;
+}
+EXPORT_SYMBOL(dmaengine_pm_put);
+
enum dma_status dma_sync_wait(struct dma_chan *chan, dma_cookie_t cookie)
{
enum dma_status status;
diff --git a/include/linux/dmaengine.h b/include/linux/dmaengine.h
index b6997a0..13d0ed8 100644
--- a/include/linux/dmaengine.h
+++ b/include/linux/dmaengine.h
@@ -251,6 +251,7 @@ struct dma_chan {
struct dma_chan_percpu __percpu *local;
int client_count;
int table_count;
+ int pm_get_count;
void *private;
};
@@ -678,6 +679,8 @@ struct dma_device {
int (*device_config)(struct dma_chan *chan,
struct dma_slave_config *config);
+ int (*device_pm_get)(struct dma_chan *chan);
+ int (*device_pm_put)(struct dma_chan *chan);
int (*device_pause)(struct dma_chan *chan);
int (*device_resume)(struct dma_chan *chan);
int (*device_terminate_all)(struct dma_chan *chan);
@@ -891,6 +894,8 @@ static inline int dma_maxpq(struct dma_device *dma, enum dma_ctrl_flags flags)
#ifdef CONFIG_DMA_ENGINE
void dmaengine_get(void);
void dmaengine_put(void);
+int dmaengine_pm_get(struct dma_chan *chan);
+int dmaengine_pm_put(struct dma_chan *chan);
#else
static inline void dmaengine_get(void)
{
@@ -898,6 +903,14 @@ static inline void dmaengine_get(void)
static inline void dmaengine_put(void)
{
}
+int dmaengine_pm_get(struct dma_chan *chan)
+{
+ return -ENXIO;
+}
+int dmaengine_pm_put(struct dma_chan *chan)
+{
+ return -ENXIO;
+}
#endif
#ifdef CONFIG_ASYNC_TX_DMA
--
1.9.1
^ permalink raw reply related [flat|nested] 5+ messages in thread* [PATCH 3/3] dmaengine: pl330: get rid of pm_runtime_irq_safe()
[not found] <1429191554-24972-1-git-send-email-r.baldyga@samsung.com>
2015-04-16 13:39 ` [PATCH 1/3] amba: add no_pm_pclk_management flag to amba_driver Robert Baldyga
2015-04-16 13:39 ` [PATCH 2/3] dmaengine: add dmaengine_pm_get()/dmaengine_pm_put() functions Robert Baldyga
@ 2015-04-16 13:39 ` Robert Baldyga
2 siblings, 0 replies; 5+ messages in thread
From: Robert Baldyga @ 2015-04-16 13:39 UTC (permalink / raw)
To: linux, dan.j.williams, vinod.koul
Cc: lars, dmaengine, linux-kernel, m.szyprowski, Robert Baldyga
As using pm_runtime_irq_safe() causes power domain is always enabled,
we want to get rid of it to reach better power efficiency. For this purpose
we call pm_runtime_get()/pm_runtime_put() in pl330_pm_get/pl330_pm_put()
functions, which are called when channel client want to use DMA channel.
With pm_runtime_irq_safe() enabled the only action performed by
pm_runtime_get()/pm_runtime_put() functions was enabling and disabling
AHB clock, so now we do that manually to avoid using pm_runtime functions
in atomic context. We also use no_pm_pclk_management flag in amba_driver
to prevent bus driver from touching pclk in runtime pm callbacks.
In result we manage AHB clock as we did before, plus we can disable power
domain when used isn't using DMA channel.
Signed-off-by: Robert Baldyga <r.baldyga@samsung.com>
---
drivers/dma/pl330.c | 107 ++++++++++++++++++++++++++++++++++++++++------------
1 file changed, 82 insertions(+), 25 deletions(-)
diff --git a/drivers/dma/pl330.c b/drivers/dma/pl330.c
index 0e1f567..5f9b867c 100644
--- a/drivers/dma/pl330.c
+++ b/drivers/dma/pl330.c
@@ -266,9 +266,6 @@ static unsigned cmd_line;
#define NR_DEFAULT_DESC 16
-/* Delay for runtime PM autosuspend, ms */
-#define PL330_AUTOSUSPEND_DELAY 20
-
/* Populated by the PL330 core driver for DMA API driver's info */
struct pl330_config {
u32 periph_id;
@@ -484,6 +481,8 @@ struct pl330_dmac {
enum pl330_dmac_state state;
/* Holds list of reqs with due callbacks */
struct list_head req_done;
+ /* Refcount for AMBA clock management */
+ unsigned int pclk_refcnt;
/* Peripheral channels connected to this DMAC */
unsigned int num_peripherals;
@@ -548,6 +547,30 @@ static inline u32 get_revision(u32 periph_id)
return (periph_id >> PERIPH_REV_SHIFT) & PERIPH_REV_MASK;
}
+static inline int pl330_pclk_enable(struct pl330_dmac *pl330)
+{
+ struct amba_device *pcdev = to_amba_device(pl330->ddma.dev);
+ unsigned long flags;
+ int ret;
+
+ spin_lock_irqsave(&pl330->lock, flags);
+ ret = pl330->pclk_refcnt++ ? 0 : amba_pclk_enable(pcdev);
+ spin_unlock_irqrestore(&pl330->lock, flags);
+
+ return ret;
+}
+
+static inline void pl330_pclk_disable(struct pl330_dmac *pl330)
+{
+ struct amba_device *pcdev = to_amba_device(pl330->ddma.dev);
+ unsigned long flags;
+
+ spin_lock_irqsave(&pl330->lock, flags);
+ if (--pl330->pclk_refcnt == 0)
+ amba_pclk_disable(pcdev);
+ spin_unlock_irqrestore(&pl330->lock, flags);
+}
+
static inline u32 _emit_ADDH(unsigned dry_run, u8 buf[],
enum pl330_dst da, u16 val)
{
@@ -2032,11 +2055,9 @@ static void pl330_tasklet(unsigned long data)
}
spin_unlock_irqrestore(&pch->lock, flags);
- /* If work list empty, power down */
- if (power_down) {
- pm_runtime_mark_last_busy(pch->dmac->ddma.dev);
- pm_runtime_put_autosuspend(pch->dmac->ddma.dev);
- }
+ /* If work list empty, disable clock */
+ if (power_down)
+ pl330_pclk_disable(pch->dmac);
}
bool pl330_filter(struct dma_chan *chan, void *param)
@@ -2155,6 +2176,21 @@ static int pl330_terminate_all(struct dma_chan *chan)
return 0;
}
+static int pl330_pm_get(struct dma_chan *chan)
+{
+ struct dma_pl330_chan *pch = to_pchan(chan);
+
+ return pm_runtime_get_sync(pch->dmac->ddma.dev);
+}
+
+static int pl330_pm_put(struct dma_chan *chan)
+{
+ struct dma_pl330_chan *pch = to_pchan(chan);
+
+ pm_runtime_mark_last_busy(pch->dmac->ddma.dev);
+ return pm_runtime_put_autosuspend(pch->dmac->ddma.dev);
+}
+
/*
* We don't support DMA_RESUME command because of hardware
* limitations, so after pausing the channel we cannot restore
@@ -2167,8 +2203,12 @@ int pl330_pause(struct dma_chan *chan)
struct dma_pl330_chan *pch = to_pchan(chan);
struct pl330_dmac *pl330 = pch->dmac;
unsigned long flags;
+ int ret;
+
+ ret = pl330_pclk_enable(pl330);
+ if (ret < 0)
+ return ret;
- pm_runtime_get_sync(pl330->ddma.dev);
spin_lock_irqsave(&pch->lock, flags);
spin_lock(&pl330->lock);
@@ -2176,8 +2216,7 @@ int pl330_pause(struct dma_chan *chan)
spin_unlock(&pl330->lock);
spin_unlock_irqrestore(&pch->lock, flags);
- pm_runtime_mark_last_busy(pl330->ddma.dev);
- pm_runtime_put_autosuspend(pl330->ddma.dev);
+ pl330_pclk_disable(pl330);
return 0;
}
@@ -2186,10 +2225,15 @@ static void pl330_free_chan_resources(struct dma_chan *chan)
{
struct dma_pl330_chan *pch = to_pchan(chan);
unsigned long flags;
+ int ret;
tasklet_kill(&pch->task);
pm_runtime_get_sync(pch->dmac->ddma.dev);
+ ret = pl330_pclk_enable(pch->dmac);
+ if (ret < 0)
+ return;
+
spin_lock_irqsave(&pch->lock, flags);
pl330_release_channel(pch->thread);
@@ -2199,6 +2243,7 @@ static void pl330_free_chan_resources(struct dma_chan *chan)
list_splice_tail_init(&pch->work_list, &pch->dmac->desc_pool);
spin_unlock_irqrestore(&pch->lock, flags);
+ pl330_pclk_disable(pch->dmac);
pm_runtime_mark_last_busy(pch->dmac->ddma.dev);
pm_runtime_put_autosuspend(pch->dmac->ddma.dev);
}
@@ -2207,11 +2252,14 @@ int pl330_get_current_xferred_count(struct dma_pl330_chan *pch,
struct dma_pl330_desc *desc)
{
struct pl330_thread *thrd = pch->thread;
- struct pl330_dmac *pl330 = pch->dmac;
void __iomem *regs = thrd->dmac->base;
u32 val, addr;
+ int ret;
+
+ ret = pl330_pclk_enable(pch->dmac);
+ if (ret < 0)
+ return ret;
- pm_runtime_get_sync(pl330->ddma.dev);
val = addr = 0;
if (desc->rqcfg.src_inc) {
val = readl(regs + SA(thrd->id));
@@ -2220,8 +2268,8 @@ int pl330_get_current_xferred_count(struct dma_pl330_chan *pch,
val = readl(regs + DA(thrd->id));
addr = desc->px.dst_addr;
}
- pm_runtime_mark_last_busy(pch->dmac->ddma.dev);
- pm_runtime_put_autosuspend(pl330->ddma.dev);
+
+ pl330_pclk_disable(pch->dmac);
return val - addr;
}
@@ -2277,16 +2325,19 @@ static void pl330_issue_pending(struct dma_chan *chan)
{
struct dma_pl330_chan *pch = to_pchan(chan);
unsigned long flags;
+ int ret;
spin_lock_irqsave(&pch->lock, flags);
if (list_empty(&pch->work_list)) {
/*
* Warn on nothing pending. Empty submitted_list may
- * break our pm_runtime usage counter as it is
- * updated on work_list emptiness status.
+ * break our clock usage counter as it is updated on
+ * work_list emptiness status.
*/
WARN_ON(list_empty(&pch->submitted_list));
- pm_runtime_get_sync(pch->dmac->ddma.dev);
+ ret = pl330_pclk_enable(pch->dmac);
+ if (ret < 0)
+ return;
}
list_splice_tail_init(&pch->submitted_list, &pch->work_list);
spin_unlock_irqrestore(&pch->lock, flags);
@@ -2720,13 +2771,13 @@ static irqreturn_t pl330_irq_handler(int irq, void *data)
static int __maybe_unused pl330_suspend(struct device *dev)
{
struct amba_device *pcdev = to_amba_device(dev);
+ struct pl330_dmac *pl330 = amba_get_drvdata(pcdev);
pm_runtime_disable(dev);
- if (!pm_runtime_status_suspended(dev)) {
- /* amba did not disable the clock */
+ if (pl330->pclk_refcnt)
amba_pclk_disable(pcdev);
- }
+
amba_pclk_unprepare(pcdev);
return 0;
@@ -2735,14 +2786,18 @@ static int __maybe_unused pl330_suspend(struct device *dev)
static int __maybe_unused pl330_resume(struct device *dev)
{
struct amba_device *pcdev = to_amba_device(dev);
+ struct pl330_dmac *pl330 = amba_get_drvdata(pcdev);
int ret;
ret = amba_pclk_prepare(pcdev);
if (ret)
return ret;
- if (!pm_runtime_status_suspended(dev))
+ if (pl330->pclk_refcnt) {
ret = amba_pclk_enable(pcdev);
+ if (ret)
+ return ret;
+ }
pm_runtime_enable(dev);
@@ -2815,6 +2870,8 @@ pl330_probe(struct amba_device *adev, const struct amba_id *id)
if (!add_desc(pl330, GFP_KERNEL, NR_DEFAULT_DESC))
dev_warn(&adev->dev, "unable to allocate desc\n");
+ amba_pclk_disable(adev);
+
INIT_LIST_HEAD(&pd->channels);
/* Initialize channel parameters */
@@ -2869,6 +2926,8 @@ pl330_probe(struct amba_device *adev, const struct amba_id *id)
pd->device_tx_status = pl330_tx_status;
pd->device_prep_slave_sg = pl330_prep_slave_sg;
pd->device_config = pl330_config;
+ pd->device_pm_get = pl330_pm_get;
+ pd->device_pm_put = pl330_pm_put;
pd->device_pause = pl330_pause;
pd->device_terminate_all = pl330_terminate_all;
pd->device_issue_pending = pl330_issue_pending;
@@ -2902,7 +2961,6 @@ pl330_probe(struct amba_device *adev, const struct amba_id *id)
if (ret)
dev_err(&adev->dev, "unable to set the seg size\n");
-
dev_info(&adev->dev,
"Loaded driver for PL330 DMAC-%x\n", adev->periphid);
dev_info(&adev->dev,
@@ -2910,9 +2968,7 @@ pl330_probe(struct amba_device *adev, const struct amba_id *id)
pcfg->data_buf_dep, pcfg->data_bus_width / 8, pcfg->num_chan,
pcfg->num_peri, pcfg->num_events);
- pm_runtime_irq_safe(&adev->dev);
pm_runtime_use_autosuspend(&adev->dev);
- pm_runtime_set_autosuspend_delay(&adev->dev, PL330_AUTOSUSPEND_DELAY);
pm_runtime_mark_last_busy(&adev->dev);
pm_runtime_put_autosuspend(&adev->dev);
@@ -2987,6 +3043,7 @@ static struct amba_driver pl330_driver = {
.id_table = pl330_ids,
.probe = pl330_probe,
.remove = pl330_remove,
+ .no_pm_pclk_management = true,
};
module_amba_driver(pl330_driver);
--
1.9.1
^ permalink raw reply related [flat|nested] 5+ messages in thread