PM / wakeirq: Fix dedicated wakeirq for drivers not using autosuspend
I noticed some wakeirq flakeyness with consumer drivers not using
autosuspend. For drivers not using autosuspend, the wakeirq may never
get unmasked in rpm_suspend() because of irq desc->depth.
We are configuring dedicated wakeirqs to start with IRQ_NOAUTOEN as we
naturally don't want them running until rpm_suspend() is called.
However, when a consumer driver initially calls pm_runtime_get(), we
now wrongly start with disable_irq_nosync() call on the dedicated
wakeirq that is disabled to start with.
This causes desc->depth to toggle between 1 and 2 instead of the usual
0 and 1. This can prevent enable_irq() from unmasking the wakeirq as
that only happens at desc->depth 1.
This does not necessarily show up with drivers using autosuspend as
there is time for disable_irq_nosync() before rpm_suspend() gets called
after the autosuspend timeout.
Let's fix the issue by adding wirq->status that lazily gets set on
the first rpm_suspend(). We also need PM runtime core private functions
for dev_pm_enable_wake_irq_check() and dev_pm_disable_wake_irq_check()
so we can enable the dedicated wakeirq on the first rpm_suspend().
While at it, let's also fix the comments for dev_pm_enable_wake_irq()
and dev_pm_disable_wake_irq(). Those can still be used by the consumer
drivers as needed because the IRQ core manages the interrupt usecount
for us.
Fixes: 4990d4fe32
(PM / Wakeirq: Add automated device wake IRQ handling)
Signed-off-by: Tony Lindgren <tony@atomide.com>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
This commit is contained in:
parent
1d9174fbc5
commit
bed570307e
@ -21,14 +21,22 @@ extern void pm_runtime_init(struct device *dev);
|
|||||||
extern void pm_runtime_reinit(struct device *dev);
|
extern void pm_runtime_reinit(struct device *dev);
|
||||||
extern void pm_runtime_remove(struct device *dev);
|
extern void pm_runtime_remove(struct device *dev);
|
||||||
|
|
||||||
|
#define WAKE_IRQ_DEDICATED_ALLOCATED BIT(0)
|
||||||
|
#define WAKE_IRQ_DEDICATED_MANAGED BIT(1)
|
||||||
|
#define WAKE_IRQ_DEDICATED_MASK (WAKE_IRQ_DEDICATED_ALLOCATED | \
|
||||||
|
WAKE_IRQ_DEDICATED_MANAGED)
|
||||||
|
|
||||||
struct wake_irq {
|
struct wake_irq {
|
||||||
struct device *dev;
|
struct device *dev;
|
||||||
|
unsigned int status;
|
||||||
int irq;
|
int irq;
|
||||||
bool dedicated_irq:1;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
extern void dev_pm_arm_wake_irq(struct wake_irq *wirq);
|
extern void dev_pm_arm_wake_irq(struct wake_irq *wirq);
|
||||||
extern void dev_pm_disarm_wake_irq(struct wake_irq *wirq);
|
extern void dev_pm_disarm_wake_irq(struct wake_irq *wirq);
|
||||||
|
extern void dev_pm_enable_wake_irq_check(struct device *dev,
|
||||||
|
bool can_change_status);
|
||||||
|
extern void dev_pm_disable_wake_irq_check(struct device *dev);
|
||||||
|
|
||||||
#ifdef CONFIG_PM_SLEEP
|
#ifdef CONFIG_PM_SLEEP
|
||||||
|
|
||||||
@ -104,6 +112,15 @@ static inline void dev_pm_disarm_wake_irq(struct wake_irq *wirq)
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static inline void dev_pm_enable_wake_irq_check(struct device *dev,
|
||||||
|
bool can_change_status)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline void dev_pm_disable_wake_irq_check(struct device *dev)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef CONFIG_PM_SLEEP
|
#ifdef CONFIG_PM_SLEEP
|
||||||
|
@ -516,7 +516,7 @@ static int rpm_suspend(struct device *dev, int rpmflags)
|
|||||||
|
|
||||||
callback = RPM_GET_CALLBACK(dev, runtime_suspend);
|
callback = RPM_GET_CALLBACK(dev, runtime_suspend);
|
||||||
|
|
||||||
dev_pm_enable_wake_irq(dev);
|
dev_pm_enable_wake_irq_check(dev, true);
|
||||||
retval = rpm_callback(callback, dev);
|
retval = rpm_callback(callback, dev);
|
||||||
if (retval)
|
if (retval)
|
||||||
goto fail;
|
goto fail;
|
||||||
@ -555,7 +555,7 @@ static int rpm_suspend(struct device *dev, int rpmflags)
|
|||||||
return retval;
|
return retval;
|
||||||
|
|
||||||
fail:
|
fail:
|
||||||
dev_pm_disable_wake_irq(dev);
|
dev_pm_disable_wake_irq_check(dev);
|
||||||
__update_runtime_status(dev, RPM_ACTIVE);
|
__update_runtime_status(dev, RPM_ACTIVE);
|
||||||
dev->power.deferred_resume = false;
|
dev->power.deferred_resume = false;
|
||||||
wake_up_all(&dev->power.wait_queue);
|
wake_up_all(&dev->power.wait_queue);
|
||||||
@ -738,12 +738,12 @@ static int rpm_resume(struct device *dev, int rpmflags)
|
|||||||
|
|
||||||
callback = RPM_GET_CALLBACK(dev, runtime_resume);
|
callback = RPM_GET_CALLBACK(dev, runtime_resume);
|
||||||
|
|
||||||
dev_pm_disable_wake_irq(dev);
|
dev_pm_disable_wake_irq_check(dev);
|
||||||
retval = rpm_callback(callback, dev);
|
retval = rpm_callback(callback, dev);
|
||||||
if (retval) {
|
if (retval) {
|
||||||
__update_runtime_status(dev, RPM_SUSPENDED);
|
__update_runtime_status(dev, RPM_SUSPENDED);
|
||||||
pm_runtime_cancel_pending(dev);
|
pm_runtime_cancel_pending(dev);
|
||||||
dev_pm_enable_wake_irq(dev);
|
dev_pm_enable_wake_irq_check(dev, false);
|
||||||
} else {
|
} else {
|
||||||
no_callback:
|
no_callback:
|
||||||
__update_runtime_status(dev, RPM_ACTIVE);
|
__update_runtime_status(dev, RPM_ACTIVE);
|
||||||
|
@ -110,8 +110,10 @@ void dev_pm_clear_wake_irq(struct device *dev)
|
|||||||
dev->power.wakeirq = NULL;
|
dev->power.wakeirq = NULL;
|
||||||
spin_unlock_irqrestore(&dev->power.lock, flags);
|
spin_unlock_irqrestore(&dev->power.lock, flags);
|
||||||
|
|
||||||
if (wirq->dedicated_irq)
|
if (wirq->status & WAKE_IRQ_DEDICATED_ALLOCATED) {
|
||||||
free_irq(wirq->irq, wirq);
|
free_irq(wirq->irq, wirq);
|
||||||
|
wirq->status &= ~WAKE_IRQ_DEDICATED_MASK;
|
||||||
|
}
|
||||||
kfree(wirq);
|
kfree(wirq);
|
||||||
}
|
}
|
||||||
EXPORT_SYMBOL_GPL(dev_pm_clear_wake_irq);
|
EXPORT_SYMBOL_GPL(dev_pm_clear_wake_irq);
|
||||||
@ -179,7 +181,6 @@ int dev_pm_set_dedicated_wake_irq(struct device *dev, int irq)
|
|||||||
|
|
||||||
wirq->dev = dev;
|
wirq->dev = dev;
|
||||||
wirq->irq = irq;
|
wirq->irq = irq;
|
||||||
wirq->dedicated_irq = true;
|
|
||||||
irq_set_status_flags(irq, IRQ_NOAUTOEN);
|
irq_set_status_flags(irq, IRQ_NOAUTOEN);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -195,6 +196,8 @@ int dev_pm_set_dedicated_wake_irq(struct device *dev, int irq)
|
|||||||
if (err)
|
if (err)
|
||||||
goto err_free_irq;
|
goto err_free_irq;
|
||||||
|
|
||||||
|
wirq->status = WAKE_IRQ_DEDICATED_ALLOCATED;
|
||||||
|
|
||||||
return err;
|
return err;
|
||||||
|
|
||||||
err_free_irq:
|
err_free_irq:
|
||||||
@ -210,9 +213,9 @@ EXPORT_SYMBOL_GPL(dev_pm_set_dedicated_wake_irq);
|
|||||||
* dev_pm_enable_wake_irq - Enable device wake-up interrupt
|
* dev_pm_enable_wake_irq - Enable device wake-up interrupt
|
||||||
* @dev: Device
|
* @dev: Device
|
||||||
*
|
*
|
||||||
* Called from the bus code or the device driver for
|
* Optionally called from the bus code or the device driver for
|
||||||
* runtime_suspend() to enable the wake-up interrupt while
|
* runtime_resume() to override the PM runtime core managed wake-up
|
||||||
* the device is running.
|
* interrupt handling to enable the wake-up interrupt.
|
||||||
*
|
*
|
||||||
* Note that for runtime_suspend()) the wake-up interrupts
|
* Note that for runtime_suspend()) the wake-up interrupts
|
||||||
* should be unconditionally enabled unlike for suspend()
|
* should be unconditionally enabled unlike for suspend()
|
||||||
@ -222,7 +225,7 @@ void dev_pm_enable_wake_irq(struct device *dev)
|
|||||||
{
|
{
|
||||||
struct wake_irq *wirq = dev->power.wakeirq;
|
struct wake_irq *wirq = dev->power.wakeirq;
|
||||||
|
|
||||||
if (wirq && wirq->dedicated_irq)
|
if (wirq && (wirq->status & WAKE_IRQ_DEDICATED_ALLOCATED))
|
||||||
enable_irq(wirq->irq);
|
enable_irq(wirq->irq);
|
||||||
}
|
}
|
||||||
EXPORT_SYMBOL_GPL(dev_pm_enable_wake_irq);
|
EXPORT_SYMBOL_GPL(dev_pm_enable_wake_irq);
|
||||||
@ -231,19 +234,72 @@ EXPORT_SYMBOL_GPL(dev_pm_enable_wake_irq);
|
|||||||
* dev_pm_disable_wake_irq - Disable device wake-up interrupt
|
* dev_pm_disable_wake_irq - Disable device wake-up interrupt
|
||||||
* @dev: Device
|
* @dev: Device
|
||||||
*
|
*
|
||||||
* Called from the bus code or the device driver for
|
* Optionally called from the bus code or the device driver for
|
||||||
* runtime_resume() to disable the wake-up interrupt while
|
* runtime_suspend() to override the PM runtime core managed wake-up
|
||||||
* the device is running.
|
* interrupt handling to disable the wake-up interrupt.
|
||||||
*/
|
*/
|
||||||
void dev_pm_disable_wake_irq(struct device *dev)
|
void dev_pm_disable_wake_irq(struct device *dev)
|
||||||
{
|
{
|
||||||
struct wake_irq *wirq = dev->power.wakeirq;
|
struct wake_irq *wirq = dev->power.wakeirq;
|
||||||
|
|
||||||
if (wirq && wirq->dedicated_irq)
|
if (wirq && (wirq->status & WAKE_IRQ_DEDICATED_ALLOCATED))
|
||||||
disable_irq_nosync(wirq->irq);
|
disable_irq_nosync(wirq->irq);
|
||||||
}
|
}
|
||||||
EXPORT_SYMBOL_GPL(dev_pm_disable_wake_irq);
|
EXPORT_SYMBOL_GPL(dev_pm_disable_wake_irq);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* dev_pm_enable_wake_irq_check - Checks and enables wake-up interrupt
|
||||||
|
* @dev: Device
|
||||||
|
* @can_change_status: Can change wake-up interrupt status
|
||||||
|
*
|
||||||
|
* Enables wakeirq conditionally. We need to enable wake-up interrupt
|
||||||
|
* lazily on the first rpm_suspend(). This is needed as the consumer device
|
||||||
|
* starts in RPM_SUSPENDED state, and the the first pm_runtime_get() would
|
||||||
|
* otherwise try to disable already disabled wakeirq. The wake-up interrupt
|
||||||
|
* starts disabled with IRQ_NOAUTOEN set.
|
||||||
|
*
|
||||||
|
* Should be only called from rpm_suspend() and rpm_resume() path.
|
||||||
|
* Caller must hold &dev->power.lock to change wirq->status
|
||||||
|
*/
|
||||||
|
void dev_pm_enable_wake_irq_check(struct device *dev,
|
||||||
|
bool can_change_status)
|
||||||
|
{
|
||||||
|
struct wake_irq *wirq = dev->power.wakeirq;
|
||||||
|
|
||||||
|
if (!wirq || !((wirq->status & WAKE_IRQ_DEDICATED_MASK)))
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (likely(wirq->status & WAKE_IRQ_DEDICATED_MANAGED)) {
|
||||||
|
goto enable;
|
||||||
|
} else if (can_change_status) {
|
||||||
|
wirq->status |= WAKE_IRQ_DEDICATED_MANAGED;
|
||||||
|
goto enable;
|
||||||
|
}
|
||||||
|
|
||||||
|
return;
|
||||||
|
|
||||||
|
enable:
|
||||||
|
enable_irq(wirq->irq);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* dev_pm_disable_wake_irq_check - Checks and disables wake-up interrupt
|
||||||
|
* @dev: Device
|
||||||
|
*
|
||||||
|
* Disables wake-up interrupt conditionally based on status.
|
||||||
|
* Should be only called from rpm_suspend() and rpm_resume() path.
|
||||||
|
*/
|
||||||
|
void dev_pm_disable_wake_irq_check(struct device *dev)
|
||||||
|
{
|
||||||
|
struct wake_irq *wirq = dev->power.wakeirq;
|
||||||
|
|
||||||
|
if (!wirq || !((wirq->status & WAKE_IRQ_DEDICATED_MASK)))
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (wirq->status & WAKE_IRQ_DEDICATED_MANAGED)
|
||||||
|
disable_irq_nosync(wirq->irq);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* dev_pm_arm_wake_irq - Arm device wake-up
|
* dev_pm_arm_wake_irq - Arm device wake-up
|
||||||
* @wirq: Device wake-up interrupt
|
* @wirq: Device wake-up interrupt
|
||||||
|
Loading…
Reference in New Issue
Block a user