]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
PM: runtime: Introduce pm_runtime_blocked()
authorRafael J. Wysocki <rafael.j.wysocki@intel.com>
Tue, 18 Feb 2025 20:13:09 +0000 (21:13 +0100)
committerRafael J. Wysocki <rafael.j.wysocki@intel.com>
Tue, 18 Feb 2025 20:43:06 +0000 (21:43 +0100)
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 <rafael.j.wysocki@intel.com>
Reviewed-by: Ulf Hansson <ulf.hansson@linaro.org>
Link: https://patch.msgid.link/4632087.LvFx2qVVIh@rjwysocki.net
drivers/base/power/runtime.c
include/linux/pm_runtime.h

index 797ea38ceba7d2f2c4355a937238c14f51055dab..c0f5a9f892997e4d766312bb8fb6375fc2e4edee 100644 (file)
@@ -1555,6 +1555,23 @@ out:
 }
 EXPORT_SYMBOL_GPL(pm_runtime_enable);
 
+bool pm_runtime_blocked(struct device *dev)
+{
+       bool ret;
+
+       /*
+        * dev->power.last_status is a bit field, so in case it is updated via
+        * RMW, read it under the spin lock.
+        */
+       spin_lock_irq(&dev->power.lock);
+
+       ret = dev->power.last_status == RPM_BLOCKED;
+
+       spin_unlock_irq(&dev->power.lock);
+
+       return ret;
+}
+
 static void pm_runtime_disable_action(void *data)
 {
        pm_runtime_dont_use_autosuspend(data);
index 10769119867b5b5e8c4a5b2928ed36b831cf9751..aea0395c10a14100adba81632a4a8233b014b893 100644 (file)
@@ -81,6 +81,7 @@ extern void pm_runtime_block_if_disabled(struct device *dev);
 extern void pm_runtime_unblock(struct device *dev);
 extern void pm_runtime_enable(struct device *dev);
 extern void __pm_runtime_disable(struct device *dev, bool check_resume);
+extern bool pm_runtime_blocked(struct device *dev);
 extern void pm_runtime_allow(struct device *dev);
 extern void pm_runtime_forbid(struct device *dev);
 extern void pm_runtime_no_callbacks(struct device *dev);
@@ -277,6 +278,7 @@ static inline void pm_runtime_block_if_disabled(struct device *dev) {}
 static inline void pm_runtime_unblock(struct device *dev) {}
 static inline void pm_runtime_enable(struct device *dev) {}
 static inline void __pm_runtime_disable(struct device *dev, bool c) {}
+static inline bool pm_runtime_blocked(struct device *dev) { return true; }
 static inline void pm_runtime_allow(struct device *dev) {}
 static inline void pm_runtime_forbid(struct device *dev) {}