Skip to content

Commit 758cc55

Browse files
committed
PM: runtime: Introduce pm_runtime_blocked()
Introduce a new helper function called pm_runtime_blocked() for checking the power.last_status value indicating whether or not enabling runtime PM for the given device has been blocked (which happens in the "prepare" phase of system-wide suspend if runtime PM is disabled for the given device at that point). Signed-off-by: Rafael J. Wysocki <[email protected]> Reviewed-by: Ulf Hansson <[email protected]> Link: https://patch.msgid.link/[email protected]
1 parent 3e5eee1 commit 758cc55

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

drivers/base/power/runtime.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1555,6 +1555,23 @@ void pm_runtime_enable(struct device *dev)
15551555
}
15561556
EXPORT_SYMBOL_GPL(pm_runtime_enable);
15571557

1558+
bool pm_runtime_blocked(struct device *dev)
1559+
{
1560+
bool ret;
1561+
1562+
/*
1563+
* dev->power.last_status is a bit field, so in case it is updated via
1564+
* RMW, read it under the spin lock.
1565+
*/
1566+
spin_lock_irq(&dev->power.lock);
1567+
1568+
ret = dev->power.last_status == RPM_BLOCKED;
1569+
1570+
spin_unlock_irq(&dev->power.lock);
1571+
1572+
return ret;
1573+
}
1574+
15581575
static void pm_runtime_disable_action(void *data)
15591576
{
15601577
pm_runtime_dont_use_autosuspend(data);

include/linux/pm_runtime.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ extern void pm_runtime_block_if_disabled(struct device *dev);
8181
extern void pm_runtime_unblock(struct device *dev);
8282
extern void pm_runtime_enable(struct device *dev);
8383
extern void __pm_runtime_disable(struct device *dev, bool check_resume);
84+
extern bool pm_runtime_blocked(struct device *dev);
8485
extern void pm_runtime_allow(struct device *dev);
8586
extern void pm_runtime_forbid(struct device *dev);
8687
extern void pm_runtime_no_callbacks(struct device *dev);
@@ -277,6 +278,7 @@ static inline void pm_runtime_block_if_disabled(struct device *dev) {}
277278
static inline void pm_runtime_unblock(struct device *dev) {}
278279
static inline void pm_runtime_enable(struct device *dev) {}
279280
static inline void __pm_runtime_disable(struct device *dev, bool c) {}
281+
static inline bool pm_runtime_blocked(struct device *dev) { return true; }
280282
static inline void pm_runtime_allow(struct device *dev) {}
281283
static inline void pm_runtime_forbid(struct device *dev) {}
282284

0 commit comments

Comments
 (0)