[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20250326-cross-lock-dep-v1-1-3199e49e8652@bootlin.com>
Date: Wed, 26 Mar 2025 19:26:16 +0100
From: Miquel Raynal <miquel.raynal@...tlin.com>
To: "Rafael J. Wysocki" <rafael@...nel.org>, Pavel Machek <pavel@....cz>,
Len Brown <len.brown@...el.com>,
Greg Kroah-Hartman <gregkh@...uxfoundation.org>,
Danilo Krummrich <dakr@...nel.org>,
Michael Turquette <mturquette@...libre.com>,
Stephen Boyd <sboyd@...nel.org>
Cc: Thomas Petazzoni <thomas.petazzoni@...tlin.com>,
linux-pm@...r.kernel.org, linux-kernel@...r.kernel.org,
linux-clk@...r.kernel.org, Chen-Yu Tsai <wenst@...omium.org>,
Lucas Stach <l.stach@...gutronix.de>,
Laurent Pinchart <laurent.pinchart@...asonboard.com>,
Marek Vasut <marex@...x.de>, Ulf Hansson <ulf.hansson@...aro.org>,
Kevin Hilman <khilman@...nel.org>, Fabio Estevam <festevam@...x.de>,
Jacky Bai <ping.bai@....com>, Peng Fan <peng.fan@....com>,
Shawn Guo <shawnguo@...nel.org>, Shengjiu Wang <shengjiu.wang@....com>,
linux-imx@....com, Ian Ray <ian.ray@...ealthcare.com>,
Hervé Codina <herve.codina@...tlin.com>,
Luca Ceresoli <luca.ceresoli@...tlin.com>,
Saravana Kannan <saravanak@...gle.com>,
Miquel Raynal <miquel.raynal@...tlin.com>
Subject: [PATCH RFC 01/10] PM: runtime: Add helpers to resume consumers
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@...tlin.com>
---
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
Powered by blists - more mailing lists