[PATCH RFC 01/10] PM: runtime: Add helpers to resume consumers
From: Miquel Raynal
Date: Wed Mar 26 2025 - 14:26:46 EST
The runtime PM core currently allows to runtime resume/suspend a device,
or its suppliers.
Let's make it also possible to runtime resume/suspend consumers.
Consumers and suppliers are seen here through the description made by
device_links.
Signed-off-by: Miquel Raynal <miquel.raynal@xxxxxxxxxxx>
---
drivers/base/power/runtime.c | 54 ++++++++++++++++++++++++++++++++++++++++++++
include/linux/pm_runtime.h | 2 ++
2 files changed, 56 insertions(+)
diff --git a/drivers/base/power/runtime.c b/drivers/base/power/runtime.c
index 2ee45841486bc73225b3e971164466647b3ce6d3..04bb66c18e3e4a45751fb3f9a6a1267d73757310 100644
--- a/drivers/base/power/runtime.c
+++ b/drivers/base/power/runtime.c
@@ -1841,6 +1841,60 @@ void pm_runtime_put_suppliers(struct device *dev)
device_links_read_unlock(idx);
}
+static void __pm_runtime_get_consumers(struct device *dev)
+{
+ struct device_link *link;
+
+ list_for_each_entry_rcu(link, &dev->links.consumers, s_node,
+ device_links_read_lock_held())
+ if (link->flags & DL_FLAG_PM_RUNTIME) {
+ pm_runtime_get_sync(link->consumer);
+ __pm_runtime_get_consumers(link->consumer);
+ }
+}
+
+/**
+ * pm_runtime_get_consumers - Resume and reference-count consumer devices.
+ * @dev: Supplier device.
+ */
+void pm_runtime_get_consumers(struct device *dev)
+{
+ int idx;
+
+ idx = device_links_read_lock();
+
+ __pm_runtime_get_consumers(dev);
+
+ device_links_read_unlock(idx);
+}
+
+static void __pm_runtime_put_consumers(struct device *dev)
+{
+ struct device_link *link;
+
+ list_for_each_entry_rcu(link, &dev->links.consumers, s_node,
+ device_links_read_lock_held())
+ if (link->flags & DL_FLAG_PM_RUNTIME) {
+ pm_runtime_put(link->consumer);
+ __pm_runtime_put_consumers(link->consumer);
+ }
+}
+
+/**
+ * pm_runtime_put_consumers - Drop references to consumer devices.
+ * @dev: Supplier device.
+ */
+void pm_runtime_put_consumers(struct device *dev)
+{
+ int idx;
+
+ idx = device_links_read_lock();
+
+ __pm_runtime_put_consumers(dev);
+
+ device_links_read_unlock(idx);
+}
+
void pm_runtime_new_link(struct device *dev)
{
spin_lock_irq(&dev->power.lock);
diff --git a/include/linux/pm_runtime.h b/include/linux/pm_runtime.h
index d39dc863f612fe18dc34182117f87908d63c8e6d..151c885a3f421f09509232f144618da62297d61d 100644
--- a/include/linux/pm_runtime.h
+++ b/include/linux/pm_runtime.h
@@ -89,6 +89,8 @@ extern u64 pm_runtime_autosuspend_expiration(struct device *dev);
extern void pm_runtime_set_memalloc_noio(struct device *dev, bool enable);
extern void pm_runtime_get_suppliers(struct device *dev);
extern void pm_runtime_put_suppliers(struct device *dev);
+extern void pm_runtime_get_consumers(struct device *dev);
+extern void pm_runtime_put_consumers(struct device *dev);
extern void pm_runtime_new_link(struct device *dev);
extern void pm_runtime_drop_link(struct device_link *link);
extern void pm_runtime_release_supplier(struct device_link *link);
--
2.48.1