* [PATCH v3 00/24] pmdomain: Add generic ->sync_state() support to genpd
@ 2025-07-01 11:47 Ulf Hansson
2025-07-01 11:47 ` [PATCH v3 01/24] pmdomain: renesas: rcar-sysc: Add genpd OF provider at postcore_initcall Ulf Hansson
` (25 more replies)
0 siblings, 26 replies; 59+ messages in thread
From: Ulf Hansson @ 2025-07-01 11:47 UTC (permalink / raw)
To: Saravana Kannan, Stephen Boyd, linux-pm
Cc: Rafael J . Wysocki, Greg Kroah-Hartman, Michael Grzeschik,
Bjorn Andersson, Abel Vesa, Peng Fan, Tomi Valkeinen,
Johan Hovold, Maulik Shah, Michal Simek, Konrad Dybcio,
Thierry Reding, Jonathan Hunter, Hiago De Franco,
Geert Uytterhoeven, Ulf Hansson, linux-arm-kernel, linux-kernel
Changes in v3:
- Added a couple of patches to adress problems on some Renesas
platforms. Thanks Geert and Tomi for helping out!
- Adressed a few comments from Saravanna and Konrad.
- Added some tested-by tags.
Changes in v2:
- Well, quite a lot as I discovered various problems when doing
additional testing of corner-case. I suggest re-review from scratch,
even if I decided to keep some reviewed-by tags.
- Added patches to allow some drivers that needs to align or opt-out
from the new common behaviour in genpd.
If a PM domain (genpd) is powered-on during boot, there is probably a good
reason for it. Therefore it's known to be a bad idea to allow such genpd to be
powered-off before all of its consumer devices have been probed. This series
intends to fix this problem.
We have been discussing these issues at LKML and at various Linux-conferences
in the past. I have therefore tried to include the people I can recall being
involved, but I may have forgotten some (my apologies), feel free to loop them
in.
I have tested this with QEMU with a bunch of local test-drivers and DT nodes.
Let me know if you want me to share this code too.
Please help review and test!
Finally, a big thanks to Saravana for all the support!
Kind regards
Ulf Hansson
Saravana Kannan (1):
driver core: Add dev_set_drv_sync_state()
Ulf Hansson (23):
pmdomain: renesas: rcar-sysc: Add genpd OF provider at
postcore_initcall
pmdomain: renesas: rmobile-sysc: Move init to postcore_initcall
pmdomain: renesas: rcar-gen4-sysc: Move init to postcore_initcall
pmdomain: core: Prevent registering devices before the bus
pmdomain: core: Add a bus and a driver for genpd providers
pmdomain: core: Add the genpd->dev to the genpd provider bus
pmdomain: core: Export a common ->sync_state() helper for genpd
providers
pmdomain: core: Prepare to add the common ->sync_state() support
soc/tegra: pmc: Opt-out from genpd's common ->sync_state() support
cpuidle: psci: Opt-out from genpd's common ->sync_state() support
cpuidle: riscv-sbi: Opt-out from genpd's common ->sync_state() support
pmdomain: qcom: rpmpd: Use of_genpd_sync_state()
pmdomain: qcom: rpmhpd: Use of_genpd_sync_state()
firmware/pmdomain: xilinx: Move ->sync_state() support to firmware
driver
firmware: xilinx: Don't share zynqmp_pm_init_finalize()
firmware: xilinx: Use of_genpd_sync_state()
driver core: Export get_dev_from_fwnode()
pmdomain: core: Add common ->sync_state() support for genpd providers
pmdomain: core: Default to use of_genpd_sync_state() for genpd
providers
pmdomain: core: Leave powered-on genpds on until late_initcall_sync
pmdomain: core: Leave powered-on genpds on until sync_state
cpuidle: psci: Drop redundant sync_state support
cpuidle: riscv-sbi: Drop redundant sync_state support
drivers/base/core.c | 8 +-
drivers/cpuidle/cpuidle-psci-domain.c | 14 --
drivers/cpuidle/cpuidle-riscv-sbi.c | 14 --
drivers/firmware/xilinx/zynqmp.c | 18 +-
drivers/pmdomain/core.c | 211 ++++++++++++++++++--
drivers/pmdomain/qcom/rpmhpd.c | 2 +
drivers/pmdomain/qcom/rpmpd.c | 2 +
drivers/pmdomain/renesas/rcar-gen4-sysc.c | 2 +-
drivers/pmdomain/renesas/rcar-sysc.c | 19 +-
drivers/pmdomain/renesas/rmobile-sysc.c | 3 +-
drivers/pmdomain/xilinx/zynqmp-pm-domains.c | 16 --
drivers/soc/tegra/pmc.c | 26 ++-
include/linux/device.h | 13 ++
include/linux/firmware/xlnx-zynqmp.h | 6 -
include/linux/pm_domain.h | 17 ++
15 files changed, 291 insertions(+), 80 deletions(-)
--
2.43.0
^ permalink raw reply [flat|nested] 59+ messages in thread
* [PATCH v3 01/24] pmdomain: renesas: rcar-sysc: Add genpd OF provider at postcore_initcall
2025-07-01 11:47 [PATCH v3 00/24] pmdomain: Add generic ->sync_state() support to genpd Ulf Hansson
@ 2025-07-01 11:47 ` Ulf Hansson
2025-07-01 11:47 ` [PATCH v3 02/24] pmdomain: renesas: rmobile-sysc: Move init to postcore_initcall Ulf Hansson
` (24 subsequent siblings)
25 siblings, 0 replies; 59+ messages in thread
From: Ulf Hansson @ 2025-07-01 11:47 UTC (permalink / raw)
To: Saravana Kannan, Stephen Boyd, linux-pm
Cc: Rafael J . Wysocki, Greg Kroah-Hartman, Michael Grzeschik,
Bjorn Andersson, Abel Vesa, Peng Fan, Tomi Valkeinen,
Johan Hovold, Maulik Shah, Michal Simek, Konrad Dybcio,
Thierry Reding, Jonathan Hunter, Hiago De Franco,
Geert Uytterhoeven, Ulf Hansson, linux-arm-kernel, linux-kernel
Subsequent changes to genpd adds a limitation that registering a genpd OF
providers must be done after its bus registration, which is at
core_initcall.
To adopt to this, let's split the initialization into two steps. The first
part keep registering the PM domains with genpd at early_initcall, as this
is needed to bringup the CPUs for R-Car H1, by calling
rcar_sysc_power_up_cpu(). The second and new part, moves the registration
of the genpd OF provider to a postcore_initcall().
Suggested-by: Geert Uytterhoeven <geert@linux-m68k.org>
Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
---
Changes in v3:
- New patch.
---
drivers/pmdomain/renesas/rcar-sysc.c | 19 ++++++++++++++++++-
1 file changed, 18 insertions(+), 1 deletion(-)
diff --git a/drivers/pmdomain/renesas/rcar-sysc.c b/drivers/pmdomain/renesas/rcar-sysc.c
index 047495f54e8a..4b310c1d35fa 100644
--- a/drivers/pmdomain/renesas/rcar-sysc.c
+++ b/drivers/pmdomain/renesas/rcar-sysc.c
@@ -342,6 +342,7 @@ struct rcar_pm_domains {
};
static struct genpd_onecell_data *rcar_sysc_onecell_data;
+static struct device_node *rcar_sysc_onecell_np;
static int __init rcar_sysc_pd_init(void)
{
@@ -428,7 +429,8 @@ static int __init rcar_sysc_pd_init(void)
}
}
- error = of_genpd_add_provider_onecell(np, &domains->onecell_data);
+ rcar_sysc_onecell_np = np;
+ return 0;
out_put:
of_node_put(np);
@@ -436,6 +438,21 @@ static int __init rcar_sysc_pd_init(void)
}
early_initcall(rcar_sysc_pd_init);
+static int __init rcar_sysc_pd_init_provider(void)
+{
+ int error;
+
+ if (!rcar_sysc_onecell_np)
+ return -ENODEV;
+
+ error = of_genpd_add_provider_onecell(rcar_sysc_onecell_np,
+ rcar_sysc_onecell_data);
+
+ of_node_put(rcar_sysc_onecell_np);
+ return error;
+}
+postcore_initcall(rcar_sysc_pd_init_provider);
+
#ifdef CONFIG_ARCH_R8A7779
static int rcar_sysc_power_cpu(unsigned int idx, bool on)
{
--
2.43.0
^ permalink raw reply related [flat|nested] 59+ messages in thread
* [PATCH v3 02/24] pmdomain: renesas: rmobile-sysc: Move init to postcore_initcall
2025-07-01 11:47 [PATCH v3 00/24] pmdomain: Add generic ->sync_state() support to genpd Ulf Hansson
2025-07-01 11:47 ` [PATCH v3 01/24] pmdomain: renesas: rcar-sysc: Add genpd OF provider at postcore_initcall Ulf Hansson
@ 2025-07-01 11:47 ` Ulf Hansson
2025-07-01 11:47 ` [PATCH v3 03/24] pmdomain: renesas: rcar-gen4-sysc: " Ulf Hansson
` (23 subsequent siblings)
25 siblings, 0 replies; 59+ messages in thread
From: Ulf Hansson @ 2025-07-01 11:47 UTC (permalink / raw)
To: Saravana Kannan, Stephen Boyd, linux-pm
Cc: Rafael J . Wysocki, Greg Kroah-Hartman, Michael Grzeschik,
Bjorn Andersson, Abel Vesa, Peng Fan, Tomi Valkeinen,
Johan Hovold, Maulik Shah, Michal Simek, Konrad Dybcio,
Thierry Reding, Jonathan Hunter, Hiago De Franco,
Geert Uytterhoeven, Ulf Hansson, linux-arm-kernel, linux-kernel
Subsequent changes to genpd adds a limitation that registering a genpd OF
providers must be done after its bus registration, which is at
core_initcall. To adopt to this, let's move to a postcore_initcall.
Suggested-by: Geert Uytterhoeven <geert@linux-m68k.org>
Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
---
Changes in v3:
- New patch.
---
drivers/pmdomain/renesas/rmobile-sysc.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/drivers/pmdomain/renesas/rmobile-sysc.c b/drivers/pmdomain/renesas/rmobile-sysc.c
index 5848e79aa438..8eedc9a1d825 100644
--- a/drivers/pmdomain/renesas/rmobile-sysc.c
+++ b/drivers/pmdomain/renesas/rmobile-sysc.c
@@ -335,5 +335,4 @@ static int __init rmobile_init_pm_domains(void)
return ret;
}
-
-core_initcall(rmobile_init_pm_domains);
+postcore_initcall(rmobile_init_pm_domains);
--
2.43.0
^ permalink raw reply related [flat|nested] 59+ messages in thread
* [PATCH v3 03/24] pmdomain: renesas: rcar-gen4-sysc: Move init to postcore_initcall
2025-07-01 11:47 [PATCH v3 00/24] pmdomain: Add generic ->sync_state() support to genpd Ulf Hansson
2025-07-01 11:47 ` [PATCH v3 01/24] pmdomain: renesas: rcar-sysc: Add genpd OF provider at postcore_initcall Ulf Hansson
2025-07-01 11:47 ` [PATCH v3 02/24] pmdomain: renesas: rmobile-sysc: Move init to postcore_initcall Ulf Hansson
@ 2025-07-01 11:47 ` Ulf Hansson
2025-07-01 11:47 ` [PATCH v3 04/24] pmdomain: core: Prevent registering devices before the bus Ulf Hansson
` (22 subsequent siblings)
25 siblings, 0 replies; 59+ messages in thread
From: Ulf Hansson @ 2025-07-01 11:47 UTC (permalink / raw)
To: Saravana Kannan, Stephen Boyd, linux-pm
Cc: Rafael J . Wysocki, Greg Kroah-Hartman, Michael Grzeschik,
Bjorn Andersson, Abel Vesa, Peng Fan, Tomi Valkeinen,
Johan Hovold, Maulik Shah, Michal Simek, Konrad Dybcio,
Thierry Reding, Jonathan Hunter, Hiago De Franco,
Geert Uytterhoeven, Ulf Hansson, linux-arm-kernel, linux-kernel
Subsequent changes to genpd adds a limitation that registering a genpd OF
providers must be done after its bus registration, which is at
core_initcall. To adopt to this, let's move to a postcore_initcall.
Suggested-by: Geert Uytterhoeven <geert@linux-m68k.org>
Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
---
Changes in v3:
- New patch.
---
drivers/pmdomain/renesas/rcar-gen4-sysc.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/pmdomain/renesas/rcar-gen4-sysc.c b/drivers/pmdomain/renesas/rcar-gen4-sysc.c
index e001b5c25bed..5aa7fa1df8fe 100644
--- a/drivers/pmdomain/renesas/rcar-gen4-sysc.c
+++ b/drivers/pmdomain/renesas/rcar-gen4-sysc.c
@@ -374,4 +374,4 @@ static int __init rcar_gen4_sysc_pd_init(void)
of_node_put(np);
return error;
}
-early_initcall(rcar_gen4_sysc_pd_init);
+postcore_initcall(rcar_gen4_sysc_pd_init);
--
2.43.0
^ permalink raw reply related [flat|nested] 59+ messages in thread
* [PATCH v3 04/24] pmdomain: core: Prevent registering devices before the bus
2025-07-01 11:47 [PATCH v3 00/24] pmdomain: Add generic ->sync_state() support to genpd Ulf Hansson
` (2 preceding siblings ...)
2025-07-01 11:47 ` [PATCH v3 03/24] pmdomain: renesas: rcar-gen4-sysc: " Ulf Hansson
@ 2025-07-01 11:47 ` Ulf Hansson
2025-07-01 11:47 ` [PATCH v3 05/24] pmdomain: core: Add a bus and a driver for genpd providers Ulf Hansson
` (21 subsequent siblings)
25 siblings, 0 replies; 59+ messages in thread
From: Ulf Hansson @ 2025-07-01 11:47 UTC (permalink / raw)
To: Saravana Kannan, Stephen Boyd, linux-pm
Cc: Rafael J . Wysocki, Greg Kroah-Hartman, Michael Grzeschik,
Bjorn Andersson, Abel Vesa, Peng Fan, Tomi Valkeinen,
Johan Hovold, Maulik Shah, Michal Simek, Konrad Dybcio,
Thierry Reding, Jonathan Hunter, Hiago De Franco,
Geert Uytterhoeven, Ulf Hansson, linux-arm-kernel, linux-kernel
We must not register a consumer device to the genpd bus, before registering
the bus itself. Even if this doesn't seem to be an issue, let's add a
simple check to make sure we really avoid this from happening.
Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
---
Changes in v3:
- New patch.
---
drivers/pmdomain/core.c | 14 +++++++++++++-
1 file changed, 13 insertions(+), 1 deletion(-)
diff --git a/drivers/pmdomain/core.c b/drivers/pmdomain/core.c
index 9a66b728fbbf..93d71164fc56 100644
--- a/drivers/pmdomain/core.c
+++ b/drivers/pmdomain/core.c
@@ -2491,6 +2491,8 @@ struct of_genpd_provider {
static LIST_HEAD(of_genpd_providers);
/* Mutex to protect the list above. */
static DEFINE_MUTEX(of_genpd_mutex);
+/* Used to prevent registering devices before the bus. */
+static bool genpd_bus_registered;
/**
* genpd_xlate_simple() - Xlate function for direct node-domain mapping
@@ -3179,6 +3181,9 @@ struct device *genpd_dev_pm_attach_by_id(struct device *dev,
if (num_domains < 0 || index >= num_domains)
return NULL;
+ if (!genpd_bus_registered)
+ return ERR_PTR(-ENODEV);
+
/* Allocate and register device on the genpd bus. */
virt_dev = kzalloc(sizeof(*virt_dev), GFP_KERNEL);
if (!virt_dev)
@@ -3357,7 +3362,14 @@ EXPORT_SYMBOL_GPL(of_genpd_parse_idle_states);
static int __init genpd_bus_init(void)
{
- return bus_register(&genpd_bus_type);
+ int ret;
+
+ ret = bus_register(&genpd_bus_type);
+ if (ret)
+ return ret;
+
+ genpd_bus_registered = true;
+ return 0;
}
core_initcall(genpd_bus_init);
--
2.43.0
^ permalink raw reply related [flat|nested] 59+ messages in thread
* [PATCH v3 05/24] pmdomain: core: Add a bus and a driver for genpd providers
2025-07-01 11:47 [PATCH v3 00/24] pmdomain: Add generic ->sync_state() support to genpd Ulf Hansson
` (3 preceding siblings ...)
2025-07-01 11:47 ` [PATCH v3 04/24] pmdomain: core: Prevent registering devices before the bus Ulf Hansson
@ 2025-07-01 11:47 ` Ulf Hansson
2025-07-01 11:47 ` [PATCH v3 06/24] pmdomain: core: Add the genpd->dev to the genpd provider bus Ulf Hansson
` (20 subsequent siblings)
25 siblings, 0 replies; 59+ messages in thread
From: Ulf Hansson @ 2025-07-01 11:47 UTC (permalink / raw)
To: Saravana Kannan, Stephen Boyd, linux-pm
Cc: Rafael J . Wysocki, Greg Kroah-Hartman, Michael Grzeschik,
Bjorn Andersson, Abel Vesa, Peng Fan, Tomi Valkeinen,
Johan Hovold, Maulik Shah, Michal Simek, Konrad Dybcio,
Thierry Reding, Jonathan Hunter, Hiago De Franco,
Geert Uytterhoeven, Ulf Hansson, linux-arm-kernel, linux-kernel
When we create a genpd via pm_genpd_init() we are initializing a
corresponding struct device for it, but we don't add the device to any
bus_type. It has not really been needed as the device is used as cookie to
help us manage OPP tables.
However, to prepare to make better use of the device, let's add a new genpd
provider bus_type and a corresponding genpd provider driver. Subsequent
changes will make use of this.
Suggested-by: Saravana Kannan <saravanak@google.com>
Reviewed-by: Abel Vesa <abel.vesa@linaro.org>
Tested-by: Hiago De Franco <hiago.franco@toradex.com> # Colibri iMX8X
Tested-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com> # TI AM62A,Xilinx ZynqMP ZCU106
Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
---
Changes in v3:
- Dropped unnecessary callbacks and convert to use struct device_driver.
---
drivers/pmdomain/core.c | 53 ++++++++++++++++++++++++++++++++++++++++-
1 file changed, 52 insertions(+), 1 deletion(-)
diff --git a/drivers/pmdomain/core.c b/drivers/pmdomain/core.c
index 93d71164fc56..a41f5f91e87f 100644
--- a/drivers/pmdomain/core.c
+++ b/drivers/pmdomain/core.c
@@ -27,6 +27,16 @@
/* Provides a unique ID for each genpd device */
static DEFINE_IDA(genpd_ida);
+/* The bus for genpd_providers. */
+static const struct bus_type genpd_provider_bus_type = {
+ .name = "genpd_provider",
+};
+
+/* The parent for genpd_provider devices. */
+static struct device genpd_provider_bus = {
+ .init_name = "genpd_provider",
+};
+
#define GENPD_RETRY_MAX_MS 250 /* Approximate */
#define GENPD_DEV_CALLBACK(genpd, type, callback, dev) \
@@ -2262,6 +2272,8 @@ static int genpd_alloc_data(struct generic_pm_domain *genpd)
genpd->gd = gd;
device_initialize(&genpd->dev);
genpd->dev.release = genpd_provider_release;
+ genpd->dev.bus = &genpd_provider_bus_type;
+ genpd->dev.parent = &genpd_provider_bus;
if (!genpd_is_dev_name_fw(genpd)) {
dev_set_name(&genpd->dev, "%s", genpd->name);
@@ -3360,16 +3372,55 @@ int of_genpd_parse_idle_states(struct device_node *dn,
}
EXPORT_SYMBOL_GPL(of_genpd_parse_idle_states);
+static int genpd_provider_probe(struct device *dev)
+{
+ return 0;
+}
+
+static void genpd_provider_sync_state(struct device *dev)
+{
+}
+
+static struct device_driver genpd_provider_drv = {
+ .name = "genpd_provider",
+ .bus = &genpd_provider_bus_type,
+ .probe = genpd_provider_probe,
+ .sync_state = genpd_provider_sync_state,
+ .suppress_bind_attrs = true,
+};
+
static int __init genpd_bus_init(void)
{
int ret;
+ ret = device_register(&genpd_provider_bus);
+ if (ret) {
+ put_device(&genpd_provider_bus);
+ return ret;
+ }
+
+ ret = bus_register(&genpd_provider_bus_type);
+ if (ret)
+ goto err_dev;
+
ret = bus_register(&genpd_bus_type);
if (ret)
- return ret;
+ goto err_prov_bus;
+
+ ret = driver_register(&genpd_provider_drv);
+ if (ret)
+ goto err_bus;
genpd_bus_registered = true;
return 0;
+
+err_bus:
+ bus_unregister(&genpd_bus_type);
+err_prov_bus:
+ bus_unregister(&genpd_provider_bus_type);
+err_dev:
+ device_unregister(&genpd_provider_bus);
+ return ret;
}
core_initcall(genpd_bus_init);
--
2.43.0
^ permalink raw reply related [flat|nested] 59+ messages in thread
* [PATCH v3 06/24] pmdomain: core: Add the genpd->dev to the genpd provider bus
2025-07-01 11:47 [PATCH v3 00/24] pmdomain: Add generic ->sync_state() support to genpd Ulf Hansson
` (4 preceding siblings ...)
2025-07-01 11:47 ` [PATCH v3 05/24] pmdomain: core: Add a bus and a driver for genpd providers Ulf Hansson
@ 2025-07-01 11:47 ` Ulf Hansson
2025-07-01 11:47 ` [PATCH v3 07/24] pmdomain: core: Export a common ->sync_state() helper for genpd providers Ulf Hansson
` (19 subsequent siblings)
25 siblings, 0 replies; 59+ messages in thread
From: Ulf Hansson @ 2025-07-01 11:47 UTC (permalink / raw)
To: Saravana Kannan, Stephen Boyd, linux-pm
Cc: Rafael J . Wysocki, Greg Kroah-Hartman, Michael Grzeschik,
Bjorn Andersson, Abel Vesa, Peng Fan, Tomi Valkeinen,
Johan Hovold, Maulik Shah, Michal Simek, Konrad Dybcio,
Thierry Reding, Jonathan Hunter, Hiago De Franco,
Geert Uytterhoeven, Ulf Hansson, linux-arm-kernel, linux-kernel
To take the next step for a more common handling of the genpd providers,
let's add the genpd->dev to the genpd provider bus when registering a genpd
OF provider.
Also note, to allow us to add devices to the genpd provider bus we need to
make sure the bus has been registered first, which is done via a
core_initcall. Hence, calls to of_genpd_add_provider_simple|onecell() must
be done after the bus has been registered, else they will fail.
Suggested-by: Saravana Kannan <saravanak@google.com>
Reviewed-by: Abel Vesa <abel.vesa@linaro.org>
Tested-by: Hiago De Franco <hiago.franco@toradex.com> # Colibri iMX8X
Tested-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com> # TI AM62A,Xilinx ZynqMP ZCU106
Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
---
Changes in v3:
- Prevent adding the device until the genpd provider bus is registered.
---
drivers/pmdomain/core.c | 44 +++++++++++++++++++++++++++++++----------
1 file changed, 34 insertions(+), 10 deletions(-)
diff --git a/drivers/pmdomain/core.c b/drivers/pmdomain/core.c
index a41f5f91e87f..79dc0bf406f0 100644
--- a/drivers/pmdomain/core.c
+++ b/drivers/pmdomain/core.c
@@ -2611,16 +2611,25 @@ int of_genpd_add_provider_simple(struct device_node *np,
if (!np || !genpd)
return -EINVAL;
+ if (!genpd_bus_registered)
+ return -ENODEV;
+
if (!genpd_present(genpd))
return -EINVAL;
genpd->dev.of_node = np;
+ ret = device_add(&genpd->dev);
+ if (ret)
+ return ret;
+
/* Parse genpd OPP table */
if (!genpd_is_opp_table_fw(genpd) && genpd->set_performance_state) {
ret = dev_pm_opp_of_add_table(&genpd->dev);
- if (ret)
- return dev_err_probe(&genpd->dev, ret, "Failed to add OPP table\n");
+ if (ret) {
+ dev_err_probe(&genpd->dev, ret, "Failed to add OPP table\n");
+ goto err_del;
+ }
/*
* Save table for faster processing while setting performance
@@ -2631,19 +2640,22 @@ int of_genpd_add_provider_simple(struct device_node *np,
}
ret = genpd_add_provider(np, genpd_xlate_simple, genpd);
- if (ret) {
- if (genpd->opp_table) {
- dev_pm_opp_put_opp_table(genpd->opp_table);
- dev_pm_opp_of_remove_table(&genpd->dev);
- }
-
- return ret;
- }
+ if (ret)
+ goto err_opp;
genpd->provider = &np->fwnode;
genpd->has_provider = true;
return 0;
+
+err_opp:
+ if (genpd->opp_table) {
+ dev_pm_opp_put_opp_table(genpd->opp_table);
+ dev_pm_opp_of_remove_table(&genpd->dev);
+ }
+err_del:
+ device_del(&genpd->dev);
+ return ret;
}
EXPORT_SYMBOL_GPL(of_genpd_add_provider_simple);
@@ -2662,6 +2674,9 @@ int of_genpd_add_provider_onecell(struct device_node *np,
if (!np || !data)
return -EINVAL;
+ if (!genpd_bus_registered)
+ return -ENODEV;
+
if (!data->xlate)
data->xlate = genpd_xlate_onecell;
@@ -2675,12 +2690,17 @@ int of_genpd_add_provider_onecell(struct device_node *np,
genpd->dev.of_node = np;
+ ret = device_add(&genpd->dev);
+ if (ret)
+ goto error;
+
/* Parse genpd OPP table */
if (!genpd_is_opp_table_fw(genpd) && genpd->set_performance_state) {
ret = dev_pm_opp_of_add_table_indexed(&genpd->dev, i);
if (ret) {
dev_err_probe(&genpd->dev, ret,
"Failed to add OPP table for index %d\n", i);
+ device_del(&genpd->dev);
goto error;
}
@@ -2716,6 +2736,8 @@ int of_genpd_add_provider_onecell(struct device_node *np,
dev_pm_opp_put_opp_table(genpd->opp_table);
dev_pm_opp_of_remove_table(&genpd->dev);
}
+
+ device_del(&genpd->dev);
}
return ret;
@@ -2748,6 +2770,8 @@ void of_genpd_del_provider(struct device_node *np)
dev_pm_opp_put_opp_table(gpd->opp_table);
dev_pm_opp_of_remove_table(&gpd->dev);
}
+
+ device_del(&gpd->dev);
}
}
--
2.43.0
^ permalink raw reply related [flat|nested] 59+ messages in thread
* [PATCH v3 07/24] pmdomain: core: Export a common ->sync_state() helper for genpd providers
2025-07-01 11:47 [PATCH v3 00/24] pmdomain: Add generic ->sync_state() support to genpd Ulf Hansson
` (5 preceding siblings ...)
2025-07-01 11:47 ` [PATCH v3 06/24] pmdomain: core: Add the genpd->dev to the genpd provider bus Ulf Hansson
@ 2025-07-01 11:47 ` Ulf Hansson
2025-07-01 11:47 ` [PATCH v3 08/24] pmdomain: core: Prepare to add the common ->sync_state() support Ulf Hansson
` (18 subsequent siblings)
25 siblings, 0 replies; 59+ messages in thread
From: Ulf Hansson @ 2025-07-01 11:47 UTC (permalink / raw)
To: Saravana Kannan, Stephen Boyd, linux-pm
Cc: Rafael J . Wysocki, Greg Kroah-Hartman, Michael Grzeschik,
Bjorn Andersson, Abel Vesa, Peng Fan, Tomi Valkeinen,
Johan Hovold, Maulik Shah, Michal Simek, Konrad Dybcio,
Thierry Reding, Jonathan Hunter, Hiago De Franco,
Geert Uytterhoeven, Ulf Hansson, linux-arm-kernel, linux-kernel
In some cases the typical platform driver that act as genpd provider, may
need its own ->sync_state() callback to manage various things. In this
regards, the provider most likely wants to allow its corresponding genpds
to be powered-off.
For this reason, let's introduce a new genpd helper function,
of_genpd_sync_state() that helps genpd provider drivers to achieve this.
Suggested-by: Saravana Kannan <saravanak@google.com>
Reviewed-by: Abel Vesa <abel.vesa@linaro.org>
Tested-by: Hiago De Franco <hiago.franco@toradex.com> # Colibri iMX8X
Tested-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com> # TI AM62A,Xilinx ZynqMP ZCU106
Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
---
drivers/pmdomain/core.c | 27 +++++++++++++++++++++++++++
include/linux/pm_domain.h | 3 +++
2 files changed, 30 insertions(+)
diff --git a/drivers/pmdomain/core.c b/drivers/pmdomain/core.c
index 79dc0bf406f0..0a6593a1b1c8 100644
--- a/drivers/pmdomain/core.c
+++ b/drivers/pmdomain/core.c
@@ -3396,6 +3396,33 @@ int of_genpd_parse_idle_states(struct device_node *dn,
}
EXPORT_SYMBOL_GPL(of_genpd_parse_idle_states);
+/**
+ * of_genpd_sync_state() - A common sync_state function for genpd providers
+ * @np: The device node the genpd provider is associated with.
+ *
+ * The @np that corresponds to a genpd provider may provide one or multiple
+ * genpds. This function makes use @np to find the genpds that belongs to the
+ * provider. For each genpd we try a power-off.
+ */
+void of_genpd_sync_state(struct device_node *np)
+{
+ struct generic_pm_domain *genpd;
+
+ if (!np)
+ return;
+
+ mutex_lock(&gpd_list_lock);
+ list_for_each_entry(genpd, &gpd_list, gpd_list_node) {
+ if (genpd->provider == of_fwnode_handle(np)) {
+ genpd_lock(genpd);
+ genpd_power_off(genpd, false, 0);
+ genpd_unlock(genpd);
+ }
+ }
+ mutex_unlock(&gpd_list_lock);
+}
+EXPORT_SYMBOL_GPL(of_genpd_sync_state);
+
static int genpd_provider_probe(struct device *dev)
{
return 0;
diff --git a/include/linux/pm_domain.h b/include/linux/pm_domain.h
index 0b18160901a2..3578196e6626 100644
--- a/include/linux/pm_domain.h
+++ b/include/linux/pm_domain.h
@@ -431,6 +431,7 @@ int of_genpd_remove_subdomain(const struct of_phandle_args *parent_spec,
struct generic_pm_domain *of_genpd_remove_last(struct device_node *np);
int of_genpd_parse_idle_states(struct device_node *dn,
struct genpd_power_state **states, int *n);
+void of_genpd_sync_state(struct device_node *np);
int genpd_dev_pm_attach(struct device *dev);
struct device *genpd_dev_pm_attach_by_id(struct device *dev,
@@ -476,6 +477,8 @@ static inline int of_genpd_parse_idle_states(struct device_node *dn,
return -ENODEV;
}
+static inline void of_genpd_sync_state(struct device_node *np) {}
+
static inline int genpd_dev_pm_attach(struct device *dev)
{
return 0;
--
2.43.0
^ permalink raw reply related [flat|nested] 59+ messages in thread
* [PATCH v3 08/24] pmdomain: core: Prepare to add the common ->sync_state() support
2025-07-01 11:47 [PATCH v3 00/24] pmdomain: Add generic ->sync_state() support to genpd Ulf Hansson
` (6 preceding siblings ...)
2025-07-01 11:47 ` [PATCH v3 07/24] pmdomain: core: Export a common ->sync_state() helper for genpd providers Ulf Hansson
@ 2025-07-01 11:47 ` Ulf Hansson
2025-07-01 11:47 ` [PATCH v3 09/24] soc/tegra: pmc: Opt-out from genpd's " Ulf Hansson
` (17 subsequent siblings)
25 siblings, 0 replies; 59+ messages in thread
From: Ulf Hansson @ 2025-07-01 11:47 UTC (permalink / raw)
To: Saravana Kannan, Stephen Boyd, linux-pm
Cc: Rafael J . Wysocki, Greg Kroah-Hartman, Michael Grzeschik,
Bjorn Andersson, Abel Vesa, Peng Fan, Tomi Valkeinen,
Johan Hovold, Maulik Shah, Michal Simek, Konrad Dybcio,
Thierry Reding, Jonathan Hunter, Hiago De Franco,
Geert Uytterhoeven, Ulf Hansson, linux-arm-kernel, linux-kernel
Before we can implement the common ->sync_state() support in genpd, we need
to allow a few specific genpd providers to opt out from the new behaviour.
Let's introduce GENPD_FLAG_NO_SYNC_STATE as a new genpd config option, to
allow providers to opt out.
Suggested-by: Saravana Kannan <saravanak@google.com>
Tested-by: Hiago De Franco <hiago.franco@toradex.com> # Colibri iMX8X
Tested-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com> # TI AM62A,Xilinx ZynqMP ZCU106
Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
---
include/linux/pm_domain.h | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/include/linux/pm_domain.h b/include/linux/pm_domain.h
index 3578196e6626..9329554b9c4a 100644
--- a/include/linux/pm_domain.h
+++ b/include/linux/pm_domain.h
@@ -104,6 +104,11 @@ struct dev_pm_domain_list {
* GENPD_FLAG_DEV_NAME_FW: Instructs genpd to generate an unique device name
* using ida. It is used by genpd providers which
* get their genpd-names directly from FW.
+ *
+ * GENPD_FLAG_NO_SYNC_STATE: The ->sync_state() support is implemented in a
+ * genpd provider specific way, likely through a
+ * parent device node. This flag makes genpd to
+ * skip its internal support for this.
*/
#define GENPD_FLAG_PM_CLK (1U << 0)
#define GENPD_FLAG_IRQ_SAFE (1U << 1)
@@ -114,6 +119,7 @@ struct dev_pm_domain_list {
#define GENPD_FLAG_MIN_RESIDENCY (1U << 6)
#define GENPD_FLAG_OPP_TABLE_FW (1U << 7)
#define GENPD_FLAG_DEV_NAME_FW (1U << 8)
+#define GENPD_FLAG_NO_SYNC_STATE (1U << 9)
enum gpd_status {
GENPD_STATE_ON = 0, /* PM domain is on */
--
2.43.0
^ permalink raw reply related [flat|nested] 59+ messages in thread
* [PATCH v3 09/24] soc/tegra: pmc: Opt-out from genpd's common ->sync_state() support
2025-07-01 11:47 [PATCH v3 00/24] pmdomain: Add generic ->sync_state() support to genpd Ulf Hansson
` (7 preceding siblings ...)
2025-07-01 11:47 ` [PATCH v3 08/24] pmdomain: core: Prepare to add the common ->sync_state() support Ulf Hansson
@ 2025-07-01 11:47 ` Ulf Hansson
2025-07-01 11:47 ` [PATCH v3 10/24] cpuidle: psci: " Ulf Hansson
` (16 subsequent siblings)
25 siblings, 0 replies; 59+ messages in thread
From: Ulf Hansson @ 2025-07-01 11:47 UTC (permalink / raw)
To: Saravana Kannan, Stephen Boyd, linux-pm
Cc: Rafael J . Wysocki, Greg Kroah-Hartman, Michael Grzeschik,
Bjorn Andersson, Abel Vesa, Peng Fan, Tomi Valkeinen,
Johan Hovold, Maulik Shah, Michal Simek, Konrad Dybcio,
Thierry Reding, Jonathan Hunter, Hiago De Franco,
Geert Uytterhoeven, Ulf Hansson, linux-arm-kernel, linux-kernel
Tegra implements its own specific ->sync_state() callback for the genpd
providers. Let's set the GENPD_FLAG_NO_SYNC_STATE to inform genpd about it.
Moreover, let's call of_genpd_sync_state() to make sure genpd tries to
power off unused PM domains.
Cc: Thierry Reding <thierry.reding@gmail.com>
Cc: Jonathan Hunter <jonathanh@nvidia.com>
Tested-by: Hiago De Franco <hiago.franco@toradex.com> # Colibri iMX8X
Tested-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com> # TI AM62A,Xilinx ZynqMP ZCU106
Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
---
drivers/soc/tegra/pmc.c | 26 +++++++++++++++++++-------
1 file changed, 19 insertions(+), 7 deletions(-)
diff --git a/drivers/soc/tegra/pmc.c b/drivers/soc/tegra/pmc.c
index e0d67bfe955c..d209e3435878 100644
--- a/drivers/soc/tegra/pmc.c
+++ b/drivers/soc/tegra/pmc.c
@@ -418,7 +418,6 @@ struct tegra_pmc_soc {
* @irq: chip implementation for the IRQ domain
* @clk_nb: pclk clock changes handler
* @core_domain_state_synced: flag marking the core domain's state as synced
- * @core_domain_registered: flag marking the core domain as registered
* @wake_type_level_map: Bitmap indicating level type for non-dual edge wakes
* @wake_type_dual_edge_map: Bitmap indicating if a wake is dual-edge or not
* @wake_sw_status_map: Bitmap to hold raw status of wakes without mask
@@ -462,7 +461,6 @@ struct tegra_pmc {
struct notifier_block clk_nb;
bool core_domain_state_synced;
- bool core_domain_registered;
unsigned long *wake_type_level_map;
unsigned long *wake_type_dual_edge_map;
@@ -1297,6 +1295,7 @@ static int tegra_powergate_add(struct tegra_pmc *pmc, struct device_node *np)
pg->id = id;
pg->genpd.name = np->name;
+ pg->genpd.flags = GENPD_FLAG_NO_SYNC_STATE;
pg->genpd.power_off = tegra_genpd_power_off;
pg->genpd.power_on = tegra_genpd_power_on;
pg->pmc = pmc;
@@ -1406,6 +1405,7 @@ static int tegra_pmc_core_pd_add(struct tegra_pmc *pmc, struct device_node *np)
return -ENOMEM;
genpd->name = "core";
+ genpd->flags = GENPD_FLAG_NO_SYNC_STATE;
genpd->set_performance_state = tegra_pmc_core_pd_set_performance_state;
err = devm_pm_opp_set_regulators(pmc->dev, rname);
@@ -1425,8 +1425,6 @@ static int tegra_pmc_core_pd_add(struct tegra_pmc *pmc, struct device_node *np)
goto remove_genpd;
}
- pmc->core_domain_registered = true;
-
return 0;
remove_genpd:
@@ -4263,8 +4261,25 @@ static const struct of_device_id tegra_pmc_match[] = {
static void tegra_pmc_sync_state(struct device *dev)
{
+ struct device_node *np, *child;
int err;
+ np = of_get_child_by_name(dev->of_node, "powergates");
+ if (!np)
+ return;
+
+ for_each_child_of_node(np, child)
+ of_genpd_sync_state(child);
+
+ of_node_put(np);
+
+ np = of_get_child_by_name(dev->of_node, "core-domain");
+ if (!np)
+ return;
+
+ of_genpd_sync_state(np);
+ of_node_put(np);
+
/*
* Newer device-trees have power domains, but we need to prepare all
* device drivers with runtime PM and OPP support first, otherwise
@@ -4278,9 +4293,6 @@ static void tegra_pmc_sync_state(struct device *dev)
* no dependencies that will block the state syncing. We shouldn't
* mark the domain as synced in this case.
*/
- if (!pmc->core_domain_registered)
- return;
-
pmc->core_domain_state_synced = true;
/* this is a no-op if core regulator isn't used */
--
2.43.0
^ permalink raw reply related [flat|nested] 59+ messages in thread
* [PATCH v3 10/24] cpuidle: psci: Opt-out from genpd's common ->sync_state() support
2025-07-01 11:47 [PATCH v3 00/24] pmdomain: Add generic ->sync_state() support to genpd Ulf Hansson
` (8 preceding siblings ...)
2025-07-01 11:47 ` [PATCH v3 09/24] soc/tegra: pmc: Opt-out from genpd's " Ulf Hansson
@ 2025-07-01 11:47 ` Ulf Hansson
2025-07-01 11:47 ` [PATCH v3 11/24] cpuidle: riscv-sbi: " Ulf Hansson
` (15 subsequent siblings)
25 siblings, 0 replies; 59+ messages in thread
From: Ulf Hansson @ 2025-07-01 11:47 UTC (permalink / raw)
To: Saravana Kannan, Stephen Boyd, linux-pm
Cc: Rafael J . Wysocki, Greg Kroah-Hartman, Michael Grzeschik,
Bjorn Andersson, Abel Vesa, Peng Fan, Tomi Valkeinen,
Johan Hovold, Maulik Shah, Michal Simek, Konrad Dybcio,
Thierry Reding, Jonathan Hunter, Hiago De Franco,
Geert Uytterhoeven, Ulf Hansson, linux-arm-kernel, linux-kernel
The cpuidle-psci-domain implements its own specific ->sync_state()
callback. Let's set the GENPD_FLAG_NO_SYNC_STATE to inform genpd about it.
Moreover, let's call of_genpd_sync_state() to make sure genpd tries to
power off unused PM domains.
Tested-by: Hiago De Franco <hiago.franco@toradex.com> # Colibri iMX8X
Tested-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com> # TI AM62A,Xilinx ZynqMP ZCU106
Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
---
drivers/cpuidle/cpuidle-psci-domain.c | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)
diff --git a/drivers/cpuidle/cpuidle-psci-domain.c b/drivers/cpuidle/cpuidle-psci-domain.c
index 2041f59116ce..b880ce2df8b5 100644
--- a/drivers/cpuidle/cpuidle-psci-domain.c
+++ b/drivers/cpuidle/cpuidle-psci-domain.c
@@ -63,7 +63,8 @@ static int psci_pd_init(struct device_node *np, bool use_osi)
if (!pd_provider)
goto free_pd;
- pd->flags |= GENPD_FLAG_IRQ_SAFE | GENPD_FLAG_CPU_DOMAIN;
+ pd->flags |= GENPD_FLAG_IRQ_SAFE | GENPD_FLAG_CPU_DOMAIN |
+ GENPD_FLAG_NO_SYNC_STATE;
/*
* Allow power off when OSI has been successfully enabled.
@@ -128,11 +129,16 @@ static void psci_pd_remove(void)
static void psci_cpuidle_domain_sync_state(struct device *dev)
{
+ struct psci_pd_provider *pd_provider;
+
/*
* All devices have now been attached/probed to the PM domain topology,
* hence it's fine to allow domain states to be picked.
*/
psci_pd_allow_domain_state = true;
+
+ list_for_each_entry(pd_provider, &psci_pd_providers, link)
+ of_genpd_sync_state(pd_provider->node);
}
static const struct of_device_id psci_of_match[] = {
--
2.43.0
^ permalink raw reply related [flat|nested] 59+ messages in thread
* [PATCH v3 11/24] cpuidle: riscv-sbi: Opt-out from genpd's common ->sync_state() support
2025-07-01 11:47 [PATCH v3 00/24] pmdomain: Add generic ->sync_state() support to genpd Ulf Hansson
` (9 preceding siblings ...)
2025-07-01 11:47 ` [PATCH v3 10/24] cpuidle: psci: " Ulf Hansson
@ 2025-07-01 11:47 ` Ulf Hansson
2025-07-04 10:14 ` Rahul Pathak
` (2 more replies)
2025-07-01 11:47 ` [PATCH v3 12/24] pmdomain: qcom: rpmpd: Use of_genpd_sync_state() Ulf Hansson
` (14 subsequent siblings)
25 siblings, 3 replies; 59+ messages in thread
From: Ulf Hansson @ 2025-07-01 11:47 UTC (permalink / raw)
To: Saravana Kannan, Stephen Boyd, linux-pm
Cc: Rafael J . Wysocki, Greg Kroah-Hartman, Michael Grzeschik,
Bjorn Andersson, Abel Vesa, Peng Fan, Tomi Valkeinen,
Johan Hovold, Maulik Shah, Michal Simek, Konrad Dybcio,
Thierry Reding, Jonathan Hunter, Hiago De Franco,
Geert Uytterhoeven, Ulf Hansson, linux-arm-kernel, linux-kernel,
Anup Patel, linux-riscv
The riscv-sbi-domain implements its own specific ->sync_state() callback.
Let's set the GENPD_FLAG_NO_SYNC_STATE to inform genpd about it.
Moreover, let's call of_genpd_sync_state() to make sure genpd tries to
power off unused PM domains.
Cc: Anup Patel <anup@brainfault.org>
Cc: linux-riscv@lists.infradead.org
Tested-by: Hiago De Franco <hiago.franco@toradex.com> # Colibri iMX8X
Tested-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com> # TI AM62A,Xilinx ZynqMP ZCU106
Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
---
drivers/cpuidle/cpuidle-riscv-sbi.c | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)
diff --git a/drivers/cpuidle/cpuidle-riscv-sbi.c b/drivers/cpuidle/cpuidle-riscv-sbi.c
index 0fe1ece9fbdc..83d58d00872f 100644
--- a/drivers/cpuidle/cpuidle-riscv-sbi.c
+++ b/drivers/cpuidle/cpuidle-riscv-sbi.c
@@ -347,11 +347,16 @@ static int sbi_cpuidle_init_cpu(struct device *dev, int cpu)
static void sbi_cpuidle_domain_sync_state(struct device *dev)
{
+ struct sbi_pd_provider *pd_provider;
+
/*
* All devices have now been attached/probed to the PM domain
* topology, hence it's fine to allow domain states to be picked.
*/
sbi_cpuidle_pd_allow_domain_state = true;
+
+ list_for_each_entry(pd_provider, &sbi_pd_providers, link)
+ of_genpd_sync_state(pd_provider->node);
}
#ifdef CONFIG_DT_IDLE_GENPD
@@ -396,7 +401,8 @@ static int sbi_pd_init(struct device_node *np)
if (!pd_provider)
goto free_pd;
- pd->flags |= GENPD_FLAG_IRQ_SAFE | GENPD_FLAG_CPU_DOMAIN;
+ pd->flags |= GENPD_FLAG_IRQ_SAFE | GENPD_FLAG_CPU_DOMAIN |
+ GENPD_FLAG_NO_SYNC_STATE;
/* Allow power off when OSI is available. */
if (sbi_cpuidle_use_osi)
--
2.43.0
^ permalink raw reply related [flat|nested] 59+ messages in thread
* [PATCH v3 12/24] pmdomain: qcom: rpmpd: Use of_genpd_sync_state()
2025-07-01 11:47 [PATCH v3 00/24] pmdomain: Add generic ->sync_state() support to genpd Ulf Hansson
` (10 preceding siblings ...)
2025-07-01 11:47 ` [PATCH v3 11/24] cpuidle: riscv-sbi: " Ulf Hansson
@ 2025-07-01 11:47 ` Ulf Hansson
2025-07-01 11:47 ` [PATCH v3 13/24] pmdomain: qcom: rpmhpd: " Ulf Hansson
` (13 subsequent siblings)
25 siblings, 0 replies; 59+ messages in thread
From: Ulf Hansson @ 2025-07-01 11:47 UTC (permalink / raw)
To: Saravana Kannan, Stephen Boyd, linux-pm
Cc: Rafael J . Wysocki, Greg Kroah-Hartman, Michael Grzeschik,
Bjorn Andersson, Abel Vesa, Peng Fan, Tomi Valkeinen,
Johan Hovold, Maulik Shah, Michal Simek, Konrad Dybcio,
Thierry Reding, Jonathan Hunter, Hiago De Franco,
Geert Uytterhoeven, Ulf Hansson, linux-arm-kernel, linux-kernel
To make sure genpd tries to power off unused PM domains, let's call
of_genpd_sync_state() from our own ->sync_state() callback.
Cc: Bjorn Andersson <andersson@kernel.org>
Cc: Konrad Dybcio <konradybcio@kernel.org>
Tested-by: Hiago De Franco <hiago.franco@toradex.com> # Colibri iMX8X
Tested-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com> # TI AM62A,Xilinx ZynqMP ZCU106
Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
---
Changes in v3:
- Fixup the prefix in the commit-message-header.
---
drivers/pmdomain/qcom/rpmpd.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/drivers/pmdomain/qcom/rpmpd.c b/drivers/pmdomain/qcom/rpmpd.c
index 0be6b3026e3a..833c46944600 100644
--- a/drivers/pmdomain/qcom/rpmpd.c
+++ b/drivers/pmdomain/qcom/rpmpd.c
@@ -1144,6 +1144,8 @@ static void rpmpd_sync_state(struct device *dev)
unsigned int i;
int ret;
+ of_genpd_sync_state(dev->of_node);
+
mutex_lock(&rpmpd_lock);
for (i = 0; i < desc->num_pds; i++) {
pd = rpmpds[i];
--
2.43.0
^ permalink raw reply related [flat|nested] 59+ messages in thread
* [PATCH v3 13/24] pmdomain: qcom: rpmhpd: Use of_genpd_sync_state()
2025-07-01 11:47 [PATCH v3 00/24] pmdomain: Add generic ->sync_state() support to genpd Ulf Hansson
` (11 preceding siblings ...)
2025-07-01 11:47 ` [PATCH v3 12/24] pmdomain: qcom: rpmpd: Use of_genpd_sync_state() Ulf Hansson
@ 2025-07-01 11:47 ` Ulf Hansson
2025-07-01 11:47 ` [PATCH v3 14/24] firmware/pmdomain: xilinx: Move ->sync_state() support to firmware driver Ulf Hansson
` (12 subsequent siblings)
25 siblings, 0 replies; 59+ messages in thread
From: Ulf Hansson @ 2025-07-01 11:47 UTC (permalink / raw)
To: Saravana Kannan, Stephen Boyd, linux-pm
Cc: Rafael J . Wysocki, Greg Kroah-Hartman, Michael Grzeschik,
Bjorn Andersson, Abel Vesa, Peng Fan, Tomi Valkeinen,
Johan Hovold, Maulik Shah, Michal Simek, Konrad Dybcio,
Thierry Reding, Jonathan Hunter, Hiago De Franco,
Geert Uytterhoeven, Ulf Hansson, linux-arm-kernel, linux-kernel
To make sure genpd tries to power off unused PM domains, let's call
of_genpd_sync_state() from our own ->sync_state() callback.
Cc: Bjorn Andersson <andersson@kernel.org>
Cc: Konrad Dybcio <konradybcio@kernel.org>
Tested-by: Hiago De Franco <hiago.franco@toradex.com> # Colibri iMX8X
Tested-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com> # TI AM62A,Xilinx ZynqMP ZCU106
Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
---
drivers/pmdomain/qcom/rpmhpd.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/drivers/pmdomain/qcom/rpmhpd.c b/drivers/pmdomain/qcom/rpmhpd.c
index 078323b85b56..d9ad6a94b3ab 100644
--- a/drivers/pmdomain/qcom/rpmhpd.c
+++ b/drivers/pmdomain/qcom/rpmhpd.c
@@ -1027,6 +1027,8 @@ static void rpmhpd_sync_state(struct device *dev)
unsigned int i;
int ret;
+ of_genpd_sync_state(dev->of_node);
+
mutex_lock(&rpmhpd_lock);
for (i = 0; i < desc->num_pds; i++) {
pd = rpmhpds[i];
--
2.43.0
^ permalink raw reply related [flat|nested] 59+ messages in thread
* [PATCH v3 14/24] firmware/pmdomain: xilinx: Move ->sync_state() support to firmware driver
2025-07-01 11:47 [PATCH v3 00/24] pmdomain: Add generic ->sync_state() support to genpd Ulf Hansson
` (12 preceding siblings ...)
2025-07-01 11:47 ` [PATCH v3 13/24] pmdomain: qcom: rpmhpd: " Ulf Hansson
@ 2025-07-01 11:47 ` Ulf Hansson
2025-07-01 11:47 ` [PATCH v3 15/24] firmware: xilinx: Don't share zynqmp_pm_init_finalize() Ulf Hansson
` (11 subsequent siblings)
25 siblings, 0 replies; 59+ messages in thread
From: Ulf Hansson @ 2025-07-01 11:47 UTC (permalink / raw)
To: Saravana Kannan, Stephen Boyd, linux-pm
Cc: Rafael J . Wysocki, Greg Kroah-Hartman, Michael Grzeschik,
Bjorn Andersson, Abel Vesa, Peng Fan, Tomi Valkeinen,
Johan Hovold, Maulik Shah, Michal Simek, Konrad Dybcio,
Thierry Reding, Jonathan Hunter, Hiago De Franco,
Geert Uytterhoeven, Ulf Hansson, linux-arm-kernel, linux-kernel,
Michael Tretter
Rather than having the genpd provider to add device_links for each device
that gets attached, to implement the ->sync_state() support, let's rely on
fw_devlink to do this for us.
In this way, we can simplify the code by moving the ->sync_state() callback
into the firmware driver, so let's do that.
Cc: Michael Tretter <m.tretter@pengutronix.de>
Cc: Michal Simek <michal.simek@amd.com>
Tested-by: Hiago De Franco <hiago.franco@toradex.com> # Colibri iMX8X
Tested-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com> # TI AM62A,Xilinx ZynqMP ZCU106
Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
---
drivers/firmware/xilinx/zynqmp.c | 10 ++++++++++
drivers/pmdomain/xilinx/zynqmp-pm-domains.c | 16 ----------------
2 files changed, 10 insertions(+), 16 deletions(-)
diff --git a/drivers/firmware/xilinx/zynqmp.c b/drivers/firmware/xilinx/zynqmp.c
index 7356e860e65c..a91a0191c689 100644
--- a/drivers/firmware/xilinx/zynqmp.c
+++ b/drivers/firmware/xilinx/zynqmp.c
@@ -2100,6 +2100,15 @@ static void zynqmp_firmware_remove(struct platform_device *pdev)
platform_device_unregister(em_dev);
}
+static void zynqmp_firmware_sync_state(struct device *dev)
+{
+ if (!of_device_is_compatible(dev->of_node, "xlnx,zynqmp-firmware"))
+ return;
+
+ if (zynqmp_pm_init_finalize())
+ dev_warn(dev, "failed to release power management to firmware\n");
+}
+
static const struct of_device_id zynqmp_firmware_of_match[] = {
{.compatible = "xlnx,zynqmp-firmware"},
{.compatible = "xlnx,versal-firmware"},
@@ -2112,6 +2121,7 @@ static struct platform_driver zynqmp_firmware_driver = {
.name = "zynqmp_firmware",
.of_match_table = zynqmp_firmware_of_match,
.dev_groups = zynqmp_firmware_groups,
+ .sync_state = zynqmp_firmware_sync_state,
},
.probe = zynqmp_firmware_probe,
.remove = zynqmp_firmware_remove,
diff --git a/drivers/pmdomain/xilinx/zynqmp-pm-domains.c b/drivers/pmdomain/xilinx/zynqmp-pm-domains.c
index d579220a4500..b5aedd6e33ad 100644
--- a/drivers/pmdomain/xilinx/zynqmp-pm-domains.c
+++ b/drivers/pmdomain/xilinx/zynqmp-pm-domains.c
@@ -153,14 +153,8 @@ static int zynqmp_gpd_attach_dev(struct generic_pm_domain *domain,
struct device *dev)
{
struct zynqmp_pm_domain *pd = to_zynqmp_pm_domain(domain);
- struct device_link *link;
int ret;
- link = device_link_add(dev, &domain->dev, DL_FLAG_SYNC_STATE_ONLY);
- if (!link)
- dev_dbg(&domain->dev, "failed to create device link for %s\n",
- dev_name(dev));
-
/* If this is not the first device to attach there is nothing to do */
if (domain->device_count)
return 0;
@@ -298,19 +292,9 @@ static void zynqmp_gpd_remove(struct platform_device *pdev)
of_genpd_del_provider(pdev->dev.parent->of_node);
}
-static void zynqmp_gpd_sync_state(struct device *dev)
-{
- int ret;
-
- ret = zynqmp_pm_init_finalize();
- if (ret)
- dev_warn(dev, "failed to release power management to firmware\n");
-}
-
static struct platform_driver zynqmp_power_domain_driver = {
.driver = {
.name = "zynqmp_power_controller",
- .sync_state = zynqmp_gpd_sync_state,
},
.probe = zynqmp_gpd_probe,
.remove = zynqmp_gpd_remove,
--
2.43.0
^ permalink raw reply related [flat|nested] 59+ messages in thread
* [PATCH v3 15/24] firmware: xilinx: Don't share zynqmp_pm_init_finalize()
2025-07-01 11:47 [PATCH v3 00/24] pmdomain: Add generic ->sync_state() support to genpd Ulf Hansson
` (13 preceding siblings ...)
2025-07-01 11:47 ` [PATCH v3 14/24] firmware/pmdomain: xilinx: Move ->sync_state() support to firmware driver Ulf Hansson
@ 2025-07-01 11:47 ` Ulf Hansson
2025-07-01 11:47 ` [PATCH v3 16/24] firmware: xilinx: Use of_genpd_sync_state() Ulf Hansson
` (10 subsequent siblings)
25 siblings, 0 replies; 59+ messages in thread
From: Ulf Hansson @ 2025-07-01 11:47 UTC (permalink / raw)
To: Saravana Kannan, Stephen Boyd, linux-pm
Cc: Rafael J . Wysocki, Greg Kroah-Hartman, Michael Grzeschik,
Bjorn Andersson, Abel Vesa, Peng Fan, Tomi Valkeinen,
Johan Hovold, Maulik Shah, Michal Simek, Konrad Dybcio,
Thierry Reding, Jonathan Hunter, Hiago De Franco,
Geert Uytterhoeven, Ulf Hansson, linux-arm-kernel, linux-kernel
As there no longer any users outside the zynqmp firmware driver of
zynqmp_pm_init_finalize(), let's turn into a local static function.
Cc: Michal Simek <michal.simek@amd.com>
Tested-by: Hiago De Franco <hiago.franco@toradex.com> # Colibri iMX8X
Tested-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com> # TI AM62A,Xilinx ZynqMP ZCU106
Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
---
drivers/firmware/xilinx/zynqmp.c | 3 +--
include/linux/firmware/xlnx-zynqmp.h | 6 ------
2 files changed, 1 insertion(+), 8 deletions(-)
diff --git a/drivers/firmware/xilinx/zynqmp.c b/drivers/firmware/xilinx/zynqmp.c
index a91a0191c689..87ddbb7d11c2 100644
--- a/drivers/firmware/xilinx/zynqmp.c
+++ b/drivers/firmware/xilinx/zynqmp.c
@@ -1299,11 +1299,10 @@ EXPORT_SYMBOL_GPL(zynqmp_pm_bootmode_write);
* This API function is to be used for notify the power management controller
* about the completed power management initialization.
*/
-int zynqmp_pm_init_finalize(void)
+static int zynqmp_pm_init_finalize(void)
{
return zynqmp_pm_invoke_fn(PM_PM_INIT_FINALIZE, NULL, 0);
}
-EXPORT_SYMBOL_GPL(zynqmp_pm_init_finalize);
/**
* zynqmp_pm_set_suspend_mode() - Set system suspend mode
diff --git a/include/linux/firmware/xlnx-zynqmp.h b/include/linux/firmware/xlnx-zynqmp.h
index 6d4dbc196b93..ae48d619c4e0 100644
--- a/include/linux/firmware/xlnx-zynqmp.h
+++ b/include/linux/firmware/xlnx-zynqmp.h
@@ -585,7 +585,6 @@ int zynqmp_pm_reset_assert(const u32 reset,
int zynqmp_pm_reset_get_status(const u32 reset, u32 *status);
unsigned int zynqmp_pm_bootmode_read(u32 *ps_mode);
int zynqmp_pm_bootmode_write(u32 ps_mode);
-int zynqmp_pm_init_finalize(void);
int zynqmp_pm_set_suspend_mode(u32 mode);
int zynqmp_pm_request_node(const u32 node, const u32 capabilities,
const u32 qos, const enum zynqmp_pm_request_ack ack);
@@ -746,11 +745,6 @@ static inline int zynqmp_pm_bootmode_write(u32 ps_mode)
return -ENODEV;
}
-static inline int zynqmp_pm_init_finalize(void)
-{
- return -ENODEV;
-}
-
static inline int zynqmp_pm_set_suspend_mode(u32 mode)
{
return -ENODEV;
--
2.43.0
^ permalink raw reply related [flat|nested] 59+ messages in thread
* [PATCH v3 16/24] firmware: xilinx: Use of_genpd_sync_state()
2025-07-01 11:47 [PATCH v3 00/24] pmdomain: Add generic ->sync_state() support to genpd Ulf Hansson
` (14 preceding siblings ...)
2025-07-01 11:47 ` [PATCH v3 15/24] firmware: xilinx: Don't share zynqmp_pm_init_finalize() Ulf Hansson
@ 2025-07-01 11:47 ` Ulf Hansson
2025-07-01 11:47 ` [PATCH v3 17/24] driver core: Export get_dev_from_fwnode() Ulf Hansson
` (9 subsequent siblings)
25 siblings, 0 replies; 59+ messages in thread
From: Ulf Hansson @ 2025-07-01 11:47 UTC (permalink / raw)
To: Saravana Kannan, Stephen Boyd, linux-pm
Cc: Rafael J . Wysocki, Greg Kroah-Hartman, Michael Grzeschik,
Bjorn Andersson, Abel Vesa, Peng Fan, Tomi Valkeinen,
Johan Hovold, Maulik Shah, Michal Simek, Konrad Dybcio,
Thierry Reding, Jonathan Hunter, Hiago De Franco,
Geert Uytterhoeven, Ulf Hansson, linux-arm-kernel, linux-kernel
To make sure genpd tries to power off unused PM domains, let's call
of_genpd_sync_state() from our own ->sync_state() callback.
Cc: Michal Simek <michal.simek@amd.com>
Tested-by: Hiago De Franco <hiago.franco@toradex.com> # Colibri iMX8X
Tested-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com> # TI AM62A,Xilinx ZynqMP ZCU106
Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
---
drivers/firmware/xilinx/zynqmp.c | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
diff --git a/drivers/firmware/xilinx/zynqmp.c b/drivers/firmware/xilinx/zynqmp.c
index 87ddbb7d11c2..02da3e48bc8f 100644
--- a/drivers/firmware/xilinx/zynqmp.c
+++ b/drivers/firmware/xilinx/zynqmp.c
@@ -20,6 +20,7 @@
#include <linux/of.h>
#include <linux/of_platform.h>
#include <linux/platform_device.h>
+#include <linux/pm_domain.h>
#include <linux/slab.h>
#include <linux/uaccess.h>
#include <linux/hashtable.h>
@@ -2101,9 +2102,13 @@ static void zynqmp_firmware_remove(struct platform_device *pdev)
static void zynqmp_firmware_sync_state(struct device *dev)
{
- if (!of_device_is_compatible(dev->of_node, "xlnx,zynqmp-firmware"))
+ struct device_node *np = dev->of_node;
+
+ if (!of_device_is_compatible(np, "xlnx,zynqmp-firmware"))
return;
+ of_genpd_sync_state(np);
+
if (zynqmp_pm_init_finalize())
dev_warn(dev, "failed to release power management to firmware\n");
}
--
2.43.0
^ permalink raw reply related [flat|nested] 59+ messages in thread
* [PATCH v3 17/24] driver core: Export get_dev_from_fwnode()
2025-07-01 11:47 [PATCH v3 00/24] pmdomain: Add generic ->sync_state() support to genpd Ulf Hansson
` (15 preceding siblings ...)
2025-07-01 11:47 ` [PATCH v3 16/24] firmware: xilinx: Use of_genpd_sync_state() Ulf Hansson
@ 2025-07-01 11:47 ` Ulf Hansson
2025-07-02 7:34 ` Greg Kroah-Hartman
2025-07-01 11:47 ` [PATCH v3 18/24] pmdomain: core: Add common ->sync_state() support for genpd providers Ulf Hansson
` (8 subsequent siblings)
25 siblings, 1 reply; 59+ messages in thread
From: Ulf Hansson @ 2025-07-01 11:47 UTC (permalink / raw)
To: Saravana Kannan, Stephen Boyd, linux-pm
Cc: Rafael J . Wysocki, Greg Kroah-Hartman, Michael Grzeschik,
Bjorn Andersson, Abel Vesa, Peng Fan, Tomi Valkeinen,
Johan Hovold, Maulik Shah, Michal Simek, Konrad Dybcio,
Thierry Reding, Jonathan Hunter, Hiago De Franco,
Geert Uytterhoeven, Ulf Hansson, linux-arm-kernel, linux-kernel
It has turned out get_dev_from_fwnode() is useful at a few other places
outside of the driver core, as in gpiolib.c for example. Therefore let's
make it available as a common helper function.
Suggested-by: Saravana Kannan <saravanak@google.com>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Tested-by: Hiago De Franco <hiago.franco@toradex.com> # Colibri iMX8X
Tested-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com> # TI AM62A,Xilinx ZynqMP ZCU106
Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
---
drivers/base/core.c | 8 ++++++--
include/linux/device.h | 1 +
2 files changed, 7 insertions(+), 2 deletions(-)
diff --git a/drivers/base/core.c b/drivers/base/core.c
index cbc0099d8ef2..6f91ece7c06a 100644
--- a/drivers/base/core.c
+++ b/drivers/base/core.c
@@ -1881,8 +1881,6 @@ static void fw_devlink_unblock_consumers(struct device *dev)
device_links_write_unlock();
}
-#define get_dev_from_fwnode(fwnode) get_device((fwnode)->dev)
-
static bool fwnode_init_without_drv(struct fwnode_handle *fwnode)
{
struct device *dev;
@@ -5281,6 +5279,12 @@ void device_set_node(struct device *dev, struct fwnode_handle *fwnode)
}
EXPORT_SYMBOL_GPL(device_set_node);
+struct device *get_dev_from_fwnode(struct fwnode_handle *fwnode)
+{
+ return get_device((fwnode)->dev);
+}
+EXPORT_SYMBOL_GPL(get_dev_from_fwnode);
+
int device_match_name(struct device *dev, const void *name)
{
return sysfs_streq(dev_name(dev), name);
diff --git a/include/linux/device.h b/include/linux/device.h
index 4940db137fff..315b00171335 100644
--- a/include/linux/device.h
+++ b/include/linux/device.h
@@ -1048,6 +1048,7 @@ void device_set_node(struct device *dev, struct fwnode_handle *fwnode);
int device_add_of_node(struct device *dev, struct device_node *of_node);
void device_remove_of_node(struct device *dev);
void device_set_of_node_from_dev(struct device *dev, const struct device *dev2);
+struct device *get_dev_from_fwnode(struct fwnode_handle *fwnode);
static inline struct device_node *dev_of_node(struct device *dev)
{
--
2.43.0
^ permalink raw reply related [flat|nested] 59+ messages in thread
* [PATCH v3 18/24] pmdomain: core: Add common ->sync_state() support for genpd providers
2025-07-01 11:47 [PATCH v3 00/24] pmdomain: Add generic ->sync_state() support to genpd Ulf Hansson
` (16 preceding siblings ...)
2025-07-01 11:47 ` [PATCH v3 17/24] driver core: Export get_dev_from_fwnode() Ulf Hansson
@ 2025-07-01 11:47 ` Ulf Hansson
2025-07-01 11:47 ` [PATCH v3 19/24] driver core: Add dev_set_drv_sync_state() Ulf Hansson
` (7 subsequent siblings)
25 siblings, 0 replies; 59+ messages in thread
From: Ulf Hansson @ 2025-07-01 11:47 UTC (permalink / raw)
To: Saravana Kannan, Stephen Boyd, linux-pm
Cc: Rafael J . Wysocki, Greg Kroah-Hartman, Michael Grzeschik,
Bjorn Andersson, Abel Vesa, Peng Fan, Tomi Valkeinen,
Johan Hovold, Maulik Shah, Michal Simek, Konrad Dybcio,
Thierry Reding, Jonathan Hunter, Hiago De Franco,
Geert Uytterhoeven, Ulf Hansson, linux-arm-kernel, linux-kernel
If the genpd provider's fwnode doesn't have an associated struct device
with it, we can make use of the generic genpd->dev and it corresponding
driver internally in genpd to manage ->sync_state().
More precisely, while adding a genpd OF provider let's check if the fwnode
has a device and if not, make the preparation to handle ->sync_state()
internally through the genpd_provider_driver and the genpd_provider_bus.
Note that, genpd providers may opt out from this behaviour by setting the
GENPD_FLAG_NO_SYNC_STATE config options for the genpds in question.
Suggested-by: Saravana Kannan <saravanak@google.com>
Tested-by: Hiago De Franco <hiago.franco@toradex.com> # Colibri iMX8X
Tested-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com> # TI AM62A,Xilinx ZynqMP ZCU106
Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
---
drivers/pmdomain/core.c | 52 +++++++++++++++++++++++++++++++++++++--
include/linux/pm_domain.h | 7 ++++++
2 files changed, 57 insertions(+), 2 deletions(-)
diff --git a/drivers/pmdomain/core.c b/drivers/pmdomain/core.c
index 0a6593a1b1c8..ca47f91b9e91 100644
--- a/drivers/pmdomain/core.c
+++ b/drivers/pmdomain/core.c
@@ -186,6 +186,7 @@ static const struct genpd_lock_ops genpd_raw_spin_ops = {
#define genpd_is_rpm_always_on(genpd) (genpd->flags & GENPD_FLAG_RPM_ALWAYS_ON)
#define genpd_is_opp_table_fw(genpd) (genpd->flags & GENPD_FLAG_OPP_TABLE_FW)
#define genpd_is_dev_name_fw(genpd) (genpd->flags & GENPD_FLAG_DEV_NAME_FW)
+#define genpd_is_no_sync_state(genpd) (genpd->flags & GENPD_FLAG_NO_SYNC_STATE)
static inline bool irq_safe_dev_in_sleep_domain(struct device *dev,
const struct generic_pm_domain *genpd)
@@ -2351,6 +2352,7 @@ int pm_genpd_init(struct generic_pm_domain *genpd,
INIT_WORK(&genpd->power_off_work, genpd_power_off_work_fn);
atomic_set(&genpd->sd_count, 0);
genpd->status = is_off ? GENPD_STATE_OFF : GENPD_STATE_ON;
+ genpd->sync_state = GENPD_SYNC_STATE_OFF;
genpd->device_count = 0;
genpd->provider = NULL;
genpd->device_id = -ENXIO;
@@ -2606,6 +2608,8 @@ static bool genpd_present(const struct generic_pm_domain *genpd)
int of_genpd_add_provider_simple(struct device_node *np,
struct generic_pm_domain *genpd)
{
+ struct fwnode_handle *fwnode;
+ struct device *dev;
int ret;
if (!np || !genpd)
@@ -2619,6 +2623,15 @@ int of_genpd_add_provider_simple(struct device_node *np,
genpd->dev.of_node = np;
+ fwnode = of_fwnode_handle(np);
+ dev = get_dev_from_fwnode(fwnode);
+ if (!dev && !genpd_is_no_sync_state(genpd)) {
+ genpd->sync_state = GENPD_SYNC_STATE_SIMPLE;
+ device_set_node(&genpd->dev, fwnode);
+ }
+
+ put_device(dev);
+
ret = device_add(&genpd->dev);
if (ret)
return ret;
@@ -2643,7 +2656,7 @@ int of_genpd_add_provider_simple(struct device_node *np,
if (ret)
goto err_opp;
- genpd->provider = &np->fwnode;
+ genpd->provider = fwnode;
genpd->has_provider = true;
return 0;
@@ -2668,8 +2681,11 @@ int of_genpd_add_provider_onecell(struct device_node *np,
struct genpd_onecell_data *data)
{
struct generic_pm_domain *genpd;
+ struct fwnode_handle *fwnode;
+ struct device *dev;
unsigned int i;
int ret = -EINVAL;
+ bool sync_state = false;
if (!np || !data)
return -EINVAL;
@@ -2680,6 +2696,13 @@ int of_genpd_add_provider_onecell(struct device_node *np,
if (!data->xlate)
data->xlate = genpd_xlate_onecell;
+ fwnode = of_fwnode_handle(np);
+ dev = get_dev_from_fwnode(fwnode);
+ if (!dev)
+ sync_state = true;
+
+ put_device(dev);
+
for (i = 0; i < data->num_domains; i++) {
genpd = data->domains[i];
@@ -2690,6 +2713,12 @@ int of_genpd_add_provider_onecell(struct device_node *np,
genpd->dev.of_node = np;
+ if (sync_state && !genpd_is_no_sync_state(genpd)) {
+ genpd->sync_state = GENPD_SYNC_STATE_ONECELL;
+ device_set_node(&genpd->dev, fwnode);
+ sync_state = false;
+ }
+
ret = device_add(&genpd->dev);
if (ret)
goto error;
@@ -2712,7 +2741,7 @@ int of_genpd_add_provider_onecell(struct device_node *np,
WARN_ON(IS_ERR(genpd->opp_table));
}
- genpd->provider = &np->fwnode;
+ genpd->provider = fwnode;
genpd->has_provider = true;
}
@@ -3430,6 +3459,25 @@ static int genpd_provider_probe(struct device *dev)
static void genpd_provider_sync_state(struct device *dev)
{
+ struct generic_pm_domain *genpd = container_of(dev, struct generic_pm_domain, dev);
+
+ switch (genpd->sync_state) {
+ case GENPD_SYNC_STATE_OFF:
+ break;
+
+ case GENPD_SYNC_STATE_ONECELL:
+ of_genpd_sync_state(dev->of_node);
+ break;
+
+ case GENPD_SYNC_STATE_SIMPLE:
+ genpd_lock(genpd);
+ genpd_power_off(genpd, false, 0);
+ genpd_unlock(genpd);
+ break;
+
+ default:
+ break;
+ }
}
static struct device_driver genpd_provider_drv = {
diff --git a/include/linux/pm_domain.h b/include/linux/pm_domain.h
index 9329554b9c4a..d68e07dadc99 100644
--- a/include/linux/pm_domain.h
+++ b/include/linux/pm_domain.h
@@ -133,6 +133,12 @@ enum genpd_notication {
GENPD_NOTIFY_ON,
};
+enum genpd_sync_state {
+ GENPD_SYNC_STATE_OFF = 0,
+ GENPD_SYNC_STATE_SIMPLE,
+ GENPD_SYNC_STATE_ONECELL,
+};
+
struct dev_power_governor {
bool (*power_down_ok)(struct dev_pm_domain *domain);
bool (*suspend_ok)(struct device *dev);
@@ -193,6 +199,7 @@ struct generic_pm_domain {
unsigned int performance_state; /* Aggregated max performance state */
cpumask_var_t cpus; /* A cpumask of the attached CPUs */
bool synced_poweroff; /* A consumer needs a synced poweroff */
+ enum genpd_sync_state sync_state; /* How sync_state is managed. */
int (*power_off)(struct generic_pm_domain *domain);
int (*power_on)(struct generic_pm_domain *domain);
struct raw_notifier_head power_notifiers; /* Power on/off notifiers */
--
2.43.0
^ permalink raw reply related [flat|nested] 59+ messages in thread
* [PATCH v3 19/24] driver core: Add dev_set_drv_sync_state()
2025-07-01 11:47 [PATCH v3 00/24] pmdomain: Add generic ->sync_state() support to genpd Ulf Hansson
` (17 preceding siblings ...)
2025-07-01 11:47 ` [PATCH v3 18/24] pmdomain: core: Add common ->sync_state() support for genpd providers Ulf Hansson
@ 2025-07-01 11:47 ` Ulf Hansson
2025-07-01 11:47 ` [PATCH v3 20/24] pmdomain: core: Default to use of_genpd_sync_state() for genpd providers Ulf Hansson
` (6 subsequent siblings)
25 siblings, 0 replies; 59+ messages in thread
From: Ulf Hansson @ 2025-07-01 11:47 UTC (permalink / raw)
To: Saravana Kannan, Stephen Boyd, linux-pm
Cc: Rafael J . Wysocki, Greg Kroah-Hartman, Michael Grzeschik,
Bjorn Andersson, Abel Vesa, Peng Fan, Tomi Valkeinen,
Johan Hovold, Maulik Shah, Michal Simek, Konrad Dybcio,
Thierry Reding, Jonathan Hunter, Hiago De Franco,
Geert Uytterhoeven, Ulf Hansson, linux-arm-kernel, linux-kernel
From: Saravana Kannan <saravanak@google.com>
This can be used by frameworks to set the sync_state() helper functions
for drivers that don't already have them set.
Signed-off-by: Saravana Kannan <saravanak@google.com>
Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Reviewed-by: Abel Vesa <abel.vesa@linaro.org>
Tested-by: Hiago De Franco <hiago.franco@toradex.com> # Colibri iMX8X
Tested-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com> # TI AM62A,Xilinx ZynqMP ZCU106
Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
---
include/linux/device.h | 12 ++++++++++++
1 file changed, 12 insertions(+)
diff --git a/include/linux/device.h b/include/linux/device.h
index 315b00171335..686f2a578fbd 100644
--- a/include/linux/device.h
+++ b/include/linux/device.h
@@ -917,6 +917,18 @@ static inline bool dev_has_sync_state(struct device *dev)
return false;
}
+static inline int dev_set_drv_sync_state(struct device *dev,
+ void (*fn)(struct device *dev))
+{
+ if (!dev || !dev->driver)
+ return 0;
+ if (dev->driver->sync_state && dev->driver->sync_state != fn)
+ return -EBUSY;
+ if (!dev->driver->sync_state)
+ dev->driver->sync_state = fn;
+ return 0;
+}
+
static inline void dev_set_removable(struct device *dev,
enum device_removable removable)
{
--
2.43.0
^ permalink raw reply related [flat|nested] 59+ messages in thread
* [PATCH v3 20/24] pmdomain: core: Default to use of_genpd_sync_state() for genpd providers
2025-07-01 11:47 [PATCH v3 00/24] pmdomain: Add generic ->sync_state() support to genpd Ulf Hansson
` (18 preceding siblings ...)
2025-07-01 11:47 ` [PATCH v3 19/24] driver core: Add dev_set_drv_sync_state() Ulf Hansson
@ 2025-07-01 11:47 ` Ulf Hansson
2025-07-31 15:07 ` Jon Hunter
2025-07-01 11:47 ` [PATCH v3 21/24] pmdomain: core: Leave powered-on genpds on until late_initcall_sync Ulf Hansson
` (5 subsequent siblings)
25 siblings, 1 reply; 59+ messages in thread
From: Ulf Hansson @ 2025-07-01 11:47 UTC (permalink / raw)
To: Saravana Kannan, Stephen Boyd, linux-pm
Cc: Rafael J . Wysocki, Greg Kroah-Hartman, Michael Grzeschik,
Bjorn Andersson, Abel Vesa, Peng Fan, Tomi Valkeinen,
Johan Hovold, Maulik Shah, Michal Simek, Konrad Dybcio,
Thierry Reding, Jonathan Hunter, Hiago De Franco,
Geert Uytterhoeven, Ulf Hansson, linux-arm-kernel, linux-kernel
Unless the typical platform driver that act as genpd provider, has its own
->sync_state() callback implemented let's default to use
of_genpd_sync_state().
More precisely, while adding a genpd OF provider let's assign the
->sync_state() callback, in case the fwnode has a device and its driver
doesn't have the ->sync_state() set already. In this way the typical
platform driver doesn't need to assign ->sync_state(), unless it has some
additional things to manage beyond genpds.
Suggested-by: Saravana Kannan <saravanak@google.com>
Tested-by: Hiago De Franco <hiago.franco@toradex.com> # Colibri iMX8X
Tested-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com> # TI AM62A,Xilinx ZynqMP ZCU106
Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
---
drivers/pmdomain/core.c | 9 +++++++++
1 file changed, 9 insertions(+)
diff --git a/drivers/pmdomain/core.c b/drivers/pmdomain/core.c
index ca47f91b9e91..5cef6de60c72 100644
--- a/drivers/pmdomain/core.c
+++ b/drivers/pmdomain/core.c
@@ -2600,6 +2600,11 @@ static bool genpd_present(const struct generic_pm_domain *genpd)
return ret;
}
+static void genpd_sync_state(struct device *dev)
+{
+ return of_genpd_sync_state(dev->of_node);
+}
+
/**
* of_genpd_add_provider_simple() - Register a simple PM domain provider
* @np: Device node pointer associated with the PM domain provider.
@@ -2628,6 +2633,8 @@ int of_genpd_add_provider_simple(struct device_node *np,
if (!dev && !genpd_is_no_sync_state(genpd)) {
genpd->sync_state = GENPD_SYNC_STATE_SIMPLE;
device_set_node(&genpd->dev, fwnode);
+ } else {
+ dev_set_drv_sync_state(dev, genpd_sync_state);
}
put_device(dev);
@@ -2700,6 +2707,8 @@ int of_genpd_add_provider_onecell(struct device_node *np,
dev = get_dev_from_fwnode(fwnode);
if (!dev)
sync_state = true;
+ else
+ dev_set_drv_sync_state(dev, genpd_sync_state);
put_device(dev);
--
2.43.0
^ permalink raw reply related [flat|nested] 59+ messages in thread
* [PATCH v3 21/24] pmdomain: core: Leave powered-on genpds on until late_initcall_sync
2025-07-01 11:47 [PATCH v3 00/24] pmdomain: Add generic ->sync_state() support to genpd Ulf Hansson
` (19 preceding siblings ...)
2025-07-01 11:47 ` [PATCH v3 20/24] pmdomain: core: Default to use of_genpd_sync_state() for genpd providers Ulf Hansson
@ 2025-07-01 11:47 ` Ulf Hansson
[not found] ` <CGME20250710122654eucas1p20f1179a9ff22d562d89252f924d34dae@eucas1p2.samsung.com>
2025-07-01 11:47 ` [PATCH v3 22/24] pmdomain: core: Leave powered-on genpds on until sync_state Ulf Hansson
` (4 subsequent siblings)
25 siblings, 1 reply; 59+ messages in thread
From: Ulf Hansson @ 2025-07-01 11:47 UTC (permalink / raw)
To: Saravana Kannan, Stephen Boyd, linux-pm
Cc: Rafael J . Wysocki, Greg Kroah-Hartman, Michael Grzeschik,
Bjorn Andersson, Abel Vesa, Peng Fan, Tomi Valkeinen,
Johan Hovold, Maulik Shah, Michal Simek, Konrad Dybcio,
Thierry Reding, Jonathan Hunter, Hiago De Franco,
Geert Uytterhoeven, Ulf Hansson, linux-arm-kernel, linux-kernel
Powering-off a genpd that was on during boot, before all of its consumer
devices have been probed, is certainly prone to problems.
As a step to improve this situation, let's prevent these genpds from being
powered-off until genpd_power_off_unused() gets called, which is a
late_initcall_sync().
Note that, this still doesn't guarantee that all the consumer devices has
been probed before we allow to power-off the genpds. Yet, this should be a
step in the right direction.
Suggested-by: Saravana Kannan <saravanak@google.com>
Tested-by: Hiago De Franco <hiago.franco@toradex.com> # Colibri iMX8X
Tested-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com> # TI AM62A,Xilinx ZynqMP ZCU106
Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
---
drivers/pmdomain/core.c | 10 ++++++++--
include/linux/pm_domain.h | 1 +
2 files changed, 9 insertions(+), 2 deletions(-)
diff --git a/drivers/pmdomain/core.c b/drivers/pmdomain/core.c
index 5cef6de60c72..18951ed6295d 100644
--- a/drivers/pmdomain/core.c
+++ b/drivers/pmdomain/core.c
@@ -931,11 +931,12 @@ static void genpd_power_off(struct generic_pm_domain *genpd, bool one_dev_on,
* The domain is already in the "power off" state.
* System suspend is in progress.
* The domain is configured as always on.
+ * The domain was on at boot and still need to stay on.
* The domain has a subdomain being powered on.
*/
if (!genpd_status_on(genpd) || genpd->prepared_count > 0 ||
genpd_is_always_on(genpd) || genpd_is_rpm_always_on(genpd) ||
- atomic_read(&genpd->sd_count) > 0)
+ genpd->stay_on || atomic_read(&genpd->sd_count) > 0)
return;
/*
@@ -1346,8 +1347,12 @@ static int __init genpd_power_off_unused(void)
pr_info("genpd: Disabling unused power domains\n");
mutex_lock(&gpd_list_lock);
- list_for_each_entry(genpd, &gpd_list, gpd_list_node)
+ list_for_each_entry(genpd, &gpd_list, gpd_list_node) {
+ genpd_lock(genpd);
+ genpd->stay_on = false;
+ genpd_unlock(genpd);
genpd_queue_power_off_work(genpd);
+ }
mutex_unlock(&gpd_list_lock);
@@ -2352,6 +2357,7 @@ int pm_genpd_init(struct generic_pm_domain *genpd,
INIT_WORK(&genpd->power_off_work, genpd_power_off_work_fn);
atomic_set(&genpd->sd_count, 0);
genpd->status = is_off ? GENPD_STATE_OFF : GENPD_STATE_ON;
+ genpd->stay_on = !is_off;
genpd->sync_state = GENPD_SYNC_STATE_OFF;
genpd->device_count = 0;
genpd->provider = NULL;
diff --git a/include/linux/pm_domain.h b/include/linux/pm_domain.h
index d68e07dadc99..99556589f45e 100644
--- a/include/linux/pm_domain.h
+++ b/include/linux/pm_domain.h
@@ -199,6 +199,7 @@ struct generic_pm_domain {
unsigned int performance_state; /* Aggregated max performance state */
cpumask_var_t cpus; /* A cpumask of the attached CPUs */
bool synced_poweroff; /* A consumer needs a synced poweroff */
+ bool stay_on; /* Stay powered-on during boot. */
enum genpd_sync_state sync_state; /* How sync_state is managed. */
int (*power_off)(struct generic_pm_domain *domain);
int (*power_on)(struct generic_pm_domain *domain);
--
2.43.0
^ permalink raw reply related [flat|nested] 59+ messages in thread
* [PATCH v3 22/24] pmdomain: core: Leave powered-on genpds on until sync_state
2025-07-01 11:47 [PATCH v3 00/24] pmdomain: Add generic ->sync_state() support to genpd Ulf Hansson
` (20 preceding siblings ...)
2025-07-01 11:47 ` [PATCH v3 21/24] pmdomain: core: Leave powered-on genpds on until late_initcall_sync Ulf Hansson
@ 2025-07-01 11:47 ` Ulf Hansson
2025-07-01 11:47 ` [PATCH v3 23/24] cpuidle: psci: Drop redundant sync_state support Ulf Hansson
` (3 subsequent siblings)
25 siblings, 0 replies; 59+ messages in thread
From: Ulf Hansson @ 2025-07-01 11:47 UTC (permalink / raw)
To: Saravana Kannan, Stephen Boyd, linux-pm
Cc: Rafael J . Wysocki, Greg Kroah-Hartman, Michael Grzeschik,
Bjorn Andersson, Abel Vesa, Peng Fan, Tomi Valkeinen,
Johan Hovold, Maulik Shah, Michal Simek, Konrad Dybcio,
Thierry Reding, Jonathan Hunter, Hiago De Franco,
Geert Uytterhoeven, Ulf Hansson, linux-arm-kernel, linux-kernel
Powering-off a genpd that was on during boot, before all of its consumer
devices have been probed, is certainly prone to problems.
For OF based platforms we can rely on using the sync_state mechanism that
the fw_devlink provides, to understand when all consumers for a genpd
provider have been probed. Let's therefore prevent these genpds from being
powered-off until the ->sync_state() callback gets called.
Note that, for non-OF based platform we will keep relying on the
late_initcall_sync, which seems to be the best we can do for now.
Suggested-by: Saravana Kannan <saravanak@google.com>
Tested-by: Hiago De Franco <hiago.franco@toradex.com> # Colibri iMX8X
Tested-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com> # TI AM62A,Xilinx ZynqMP ZCU106
Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
---
drivers/pmdomain/core.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/drivers/pmdomain/core.c b/drivers/pmdomain/core.c
index 18951ed6295d..a86aeda1c955 100644
--- a/drivers/pmdomain/core.c
+++ b/drivers/pmdomain/core.c
@@ -1324,6 +1324,7 @@ static int genpd_runtime_resume(struct device *dev)
return ret;
}
+#ifndef CONFIG_PM_GENERIC_DOMAINS_OF
static bool pd_ignore_unused;
static int __init pd_ignore_unused_setup(char *__unused)
{
@@ -1359,6 +1360,7 @@ static int __init genpd_power_off_unused(void)
return 0;
}
late_initcall_sync(genpd_power_off_unused);
+#endif
#ifdef CONFIG_PM_SLEEP
@@ -3459,6 +3461,7 @@ void of_genpd_sync_state(struct device_node *np)
list_for_each_entry(genpd, &gpd_list, gpd_list_node) {
if (genpd->provider == of_fwnode_handle(np)) {
genpd_lock(genpd);
+ genpd->stay_on = false;
genpd_power_off(genpd, false, 0);
genpd_unlock(genpd);
}
@@ -3486,6 +3489,7 @@ static void genpd_provider_sync_state(struct device *dev)
case GENPD_SYNC_STATE_SIMPLE:
genpd_lock(genpd);
+ genpd->stay_on = false;
genpd_power_off(genpd, false, 0);
genpd_unlock(genpd);
break;
--
2.43.0
^ permalink raw reply related [flat|nested] 59+ messages in thread
* [PATCH v3 23/24] cpuidle: psci: Drop redundant sync_state support
2025-07-01 11:47 [PATCH v3 00/24] pmdomain: Add generic ->sync_state() support to genpd Ulf Hansson
` (21 preceding siblings ...)
2025-07-01 11:47 ` [PATCH v3 22/24] pmdomain: core: Leave powered-on genpds on until sync_state Ulf Hansson
@ 2025-07-01 11:47 ` Ulf Hansson
2025-07-01 11:47 ` [PATCH v3 24/24] cpuidle: riscv-sbi: " Ulf Hansson
` (2 subsequent siblings)
25 siblings, 0 replies; 59+ messages in thread
From: Ulf Hansson @ 2025-07-01 11:47 UTC (permalink / raw)
To: Saravana Kannan, Stephen Boyd, linux-pm
Cc: Rafael J . Wysocki, Greg Kroah-Hartman, Michael Grzeschik,
Bjorn Andersson, Abel Vesa, Peng Fan, Tomi Valkeinen,
Johan Hovold, Maulik Shah, Michal Simek, Konrad Dybcio,
Thierry Reding, Jonathan Hunter, Hiago De Franco,
Geert Uytterhoeven, Ulf Hansson, linux-arm-kernel, linux-kernel
The recent updates to the genpd core, can entirely manage the sync_state
support for the cpuidle-psci-domain. More precisely, genpd prevents our
->power_off() callback from being invoked, until all of our consumers are
ready for it.
Let's therefore drop the sync_state support for the cpuidle-psci-domain as
it has become redundant.
Tested-by: Hiago De Franco <hiago.franco@toradex.com> # Colibri iMX8X
Tested-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com> # TI AM62A,Xilinx ZynqMP ZCU106
Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
---
drivers/cpuidle/cpuidle-psci-domain.c | 22 +---------------------
1 file changed, 1 insertion(+), 21 deletions(-)
diff --git a/drivers/cpuidle/cpuidle-psci-domain.c b/drivers/cpuidle/cpuidle-psci-domain.c
index b880ce2df8b5..37c41209eaf9 100644
--- a/drivers/cpuidle/cpuidle-psci-domain.c
+++ b/drivers/cpuidle/cpuidle-psci-domain.c
@@ -28,7 +28,6 @@ struct psci_pd_provider {
};
static LIST_HEAD(psci_pd_providers);
-static bool psci_pd_allow_domain_state;
static int psci_pd_power_off(struct generic_pm_domain *pd)
{
@@ -38,9 +37,6 @@ static int psci_pd_power_off(struct generic_pm_domain *pd)
if (!state->data)
return 0;
- if (!psci_pd_allow_domain_state)
- return -EBUSY;
-
/* OSI mode is enabled, set the corresponding domain state. */
pd_state = state->data;
psci_set_domain_state(pd, pd->state_idx, *pd_state);
@@ -63,8 +59,7 @@ static int psci_pd_init(struct device_node *np, bool use_osi)
if (!pd_provider)
goto free_pd;
- pd->flags |= GENPD_FLAG_IRQ_SAFE | GENPD_FLAG_CPU_DOMAIN |
- GENPD_FLAG_NO_SYNC_STATE;
+ pd->flags |= GENPD_FLAG_IRQ_SAFE | GENPD_FLAG_CPU_DOMAIN;
/*
* Allow power off when OSI has been successfully enabled.
@@ -127,20 +122,6 @@ static void psci_pd_remove(void)
}
}
-static void psci_cpuidle_domain_sync_state(struct device *dev)
-{
- struct psci_pd_provider *pd_provider;
-
- /*
- * All devices have now been attached/probed to the PM domain topology,
- * hence it's fine to allow domain states to be picked.
- */
- psci_pd_allow_domain_state = true;
-
- list_for_each_entry(pd_provider, &psci_pd_providers, link)
- of_genpd_sync_state(pd_provider->node);
-}
-
static const struct of_device_id psci_of_match[] = {
{ .compatible = "arm,psci-1.0" },
{}
@@ -201,7 +182,6 @@ static struct platform_driver psci_cpuidle_domain_driver = {
.driver = {
.name = "psci-cpuidle-domain",
.of_match_table = psci_of_match,
- .sync_state = psci_cpuidle_domain_sync_state,
},
};
--
2.43.0
^ permalink raw reply related [flat|nested] 59+ messages in thread
* [PATCH v3 24/24] cpuidle: riscv-sbi: Drop redundant sync_state support
2025-07-01 11:47 [PATCH v3 00/24] pmdomain: Add generic ->sync_state() support to genpd Ulf Hansson
` (22 preceding siblings ...)
2025-07-01 11:47 ` [PATCH v3 23/24] cpuidle: psci: Drop redundant sync_state support Ulf Hansson
@ 2025-07-01 11:47 ` Ulf Hansson
2025-07-04 10:39 ` Rahul Pathak
2025-07-07 9:38 ` Anup Patel
2025-07-09 11:30 ` [PATCH v3 00/24] pmdomain: Add generic ->sync_state() support to genpd Ulf Hansson
2025-09-03 7:39 ` Sebin Francis
25 siblings, 2 replies; 59+ messages in thread
From: Ulf Hansson @ 2025-07-01 11:47 UTC (permalink / raw)
To: Saravana Kannan, Stephen Boyd, linux-pm
Cc: Rafael J . Wysocki, Greg Kroah-Hartman, Michael Grzeschik,
Bjorn Andersson, Abel Vesa, Peng Fan, Tomi Valkeinen,
Johan Hovold, Maulik Shah, Michal Simek, Konrad Dybcio,
Thierry Reding, Jonathan Hunter, Hiago De Franco,
Geert Uytterhoeven, Ulf Hansson, linux-arm-kernel, linux-kernel,
Anup Patel, linux-riscv
The recent updates to the genpd core, can entirely manage the sync_state
support for the cpuidle-riscv-sbi-domain. More precisely, genpd prevents
our ->power_off() callback from being invoked, until all of our consumers
are ready for it.
Let's therefore drop the sync_state support for the
cpuidle-riscv-sbi-domain as it has become redundant.
Cc: Anup Patel <anup@brainfault.org>
Cc: linux-riscv@lists.infradead.org
Tested-by: Hiago De Franco <hiago.franco@toradex.com> # Colibri iMX8X
Tested-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com> # TI AM62A,Xilinx ZynqMP ZCU106
Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
---
drivers/cpuidle/cpuidle-riscv-sbi.c | 22 +---------------------
1 file changed, 1 insertion(+), 21 deletions(-)
diff --git a/drivers/cpuidle/cpuidle-riscv-sbi.c b/drivers/cpuidle/cpuidle-riscv-sbi.c
index 83d58d00872f..a360bc4d20b7 100644
--- a/drivers/cpuidle/cpuidle-riscv-sbi.c
+++ b/drivers/cpuidle/cpuidle-riscv-sbi.c
@@ -44,7 +44,6 @@ static DEFINE_PER_CPU_READ_MOSTLY(struct sbi_cpuidle_data, sbi_cpuidle_data);
static DEFINE_PER_CPU(struct sbi_domain_state, domain_state);
static bool sbi_cpuidle_use_osi;
static bool sbi_cpuidle_use_cpuhp;
-static bool sbi_cpuidle_pd_allow_domain_state;
static inline void sbi_set_domain_state(u32 state)
{
@@ -345,20 +344,6 @@ static int sbi_cpuidle_init_cpu(struct device *dev, int cpu)
return ret;
}
-static void sbi_cpuidle_domain_sync_state(struct device *dev)
-{
- struct sbi_pd_provider *pd_provider;
-
- /*
- * All devices have now been attached/probed to the PM domain
- * topology, hence it's fine to allow domain states to be picked.
- */
- sbi_cpuidle_pd_allow_domain_state = true;
-
- list_for_each_entry(pd_provider, &sbi_pd_providers, link)
- of_genpd_sync_state(pd_provider->node);
-}
-
#ifdef CONFIG_DT_IDLE_GENPD
static int sbi_cpuidle_pd_power_off(struct generic_pm_domain *pd)
@@ -369,9 +354,6 @@ static int sbi_cpuidle_pd_power_off(struct generic_pm_domain *pd)
if (!state->data)
return 0;
- if (!sbi_cpuidle_pd_allow_domain_state)
- return -EBUSY;
-
/* OSI mode is enabled, set the corresponding domain state. */
pd_state = state->data;
sbi_set_domain_state(*pd_state);
@@ -401,8 +383,7 @@ static int sbi_pd_init(struct device_node *np)
if (!pd_provider)
goto free_pd;
- pd->flags |= GENPD_FLAG_IRQ_SAFE | GENPD_FLAG_CPU_DOMAIN |
- GENPD_FLAG_NO_SYNC_STATE;
+ pd->flags |= GENPD_FLAG_IRQ_SAFE | GENPD_FLAG_CPU_DOMAIN;
/* Allow power off when OSI is available. */
if (sbi_cpuidle_use_osi)
@@ -570,7 +551,6 @@ static struct platform_driver sbi_cpuidle_driver = {
.probe = sbi_cpuidle_probe,
.driver = {
.name = "sbi-cpuidle",
- .sync_state = sbi_cpuidle_domain_sync_state,
},
};
--
2.43.0
^ permalink raw reply related [flat|nested] 59+ messages in thread
* Re: [PATCH v3 17/24] driver core: Export get_dev_from_fwnode()
2025-07-01 11:47 ` [PATCH v3 17/24] driver core: Export get_dev_from_fwnode() Ulf Hansson
@ 2025-07-02 7:34 ` Greg Kroah-Hartman
2025-07-02 19:26 ` Danilo Krummrich
0 siblings, 1 reply; 59+ messages in thread
From: Greg Kroah-Hartman @ 2025-07-02 7:34 UTC (permalink / raw)
To: Ulf Hansson
Cc: Saravana Kannan, Stephen Boyd, linux-pm, Rafael J . Wysocki,
Michael Grzeschik, Bjorn Andersson, Abel Vesa, Peng Fan,
Tomi Valkeinen, Johan Hovold, Maulik Shah, Michal Simek,
Konrad Dybcio, Thierry Reding, Jonathan Hunter, Hiago De Franco,
Geert Uytterhoeven, linux-arm-kernel, linux-kernel
On Tue, Jul 01, 2025 at 01:47:19PM +0200, Ulf Hansson wrote:
> It has turned out get_dev_from_fwnode() is useful at a few other places
> outside of the driver core, as in gpiolib.c for example. Therefore let's
> make it available as a common helper function.
>
> Suggested-by: Saravana Kannan <saravanak@google.com>
> Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
> Tested-by: Hiago De Franco <hiago.franco@toradex.com> # Colibri iMX8X
> Tested-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com> # TI AM62A,Xilinx ZynqMP ZCU106
> Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
> ---
> drivers/base/core.c | 8 ++++++--
> include/linux/device.h | 1 +
> 2 files changed, 7 insertions(+), 2 deletions(-)
>
Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
^ permalink raw reply [flat|nested] 59+ messages in thread
* Re: [PATCH v3 17/24] driver core: Export get_dev_from_fwnode()
2025-07-02 7:34 ` Greg Kroah-Hartman
@ 2025-07-02 19:26 ` Danilo Krummrich
2025-07-02 21:34 ` Saravana Kannan
0 siblings, 1 reply; 59+ messages in thread
From: Danilo Krummrich @ 2025-07-02 19:26 UTC (permalink / raw)
To: Greg Kroah-Hartman
Cc: Ulf Hansson, Saravana Kannan, Stephen Boyd, linux-pm,
Rafael J . Wysocki, Michael Grzeschik, Bjorn Andersson, Abel Vesa,
Peng Fan, Tomi Valkeinen, Johan Hovold, Maulik Shah, Michal Simek,
Konrad Dybcio, Thierry Reding, Jonathan Hunter, Hiago De Franco,
Geert Uytterhoeven, linux-arm-kernel, linux-kernel
On Wed, Jul 02, 2025 at 09:34:12AM +0200, Greg Kroah-Hartman wrote:
> On Tue, Jul 01, 2025 at 01:47:19PM +0200, Ulf Hansson wrote:
> > It has turned out get_dev_from_fwnode() is useful at a few other places
> > outside of the driver core, as in gpiolib.c for example. Therefore let's
> > make it available as a common helper function.
> >
> > Suggested-by: Saravana Kannan <saravanak@google.com>
> > Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
> > Tested-by: Hiago De Franco <hiago.franco@toradex.com> # Colibri iMX8X
> > Tested-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com> # TI AM62A,Xilinx ZynqMP ZCU106
> > Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
> > ---
> > drivers/base/core.c | 8 ++++++--
> > include/linux/device.h | 1 +
> > 2 files changed, 7 insertions(+), 2 deletions(-)
> >
>
> Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
I'm a bit concerned about exporting get_dev_from_fwnode() -- at least without a
clear note on that this helper should be used with caution.
AFAIK, a struct fwnode_handle instance does not have a reference count for its
struct device pointer.
Hence, calling get_dev_from_fwnode() with a valid fwnode handle is not enough.
The caller also needs to ensure that the device the fwnode has a pointer to has
not been released yet.
If this really needs to be exported, can we please add documentation covering
this properly?
- Danilo
^ permalink raw reply [flat|nested] 59+ messages in thread
* Re: [PATCH v3 17/24] driver core: Export get_dev_from_fwnode()
2025-07-02 19:26 ` Danilo Krummrich
@ 2025-07-02 21:34 ` Saravana Kannan
2025-07-02 21:55 ` Danilo Krummrich
0 siblings, 1 reply; 59+ messages in thread
From: Saravana Kannan @ 2025-07-02 21:34 UTC (permalink / raw)
To: Danilo Krummrich
Cc: Greg Kroah-Hartman, Ulf Hansson, Stephen Boyd, linux-pm,
Rafael J . Wysocki, Michael Grzeschik, Bjorn Andersson, Abel Vesa,
Peng Fan, Tomi Valkeinen, Johan Hovold, Maulik Shah, Michal Simek,
Konrad Dybcio, Thierry Reding, Jonathan Hunter, Hiago De Franco,
Geert Uytterhoeven, linux-arm-kernel, linux-kernel
On Wed, Jul 2, 2025 at 12:26 PM Danilo Krummrich <dakr@kernel.org> wrote:
>
> On Wed, Jul 02, 2025 at 09:34:12AM +0200, Greg Kroah-Hartman wrote:
> > On Tue, Jul 01, 2025 at 01:47:19PM +0200, Ulf Hansson wrote:
> > > It has turned out get_dev_from_fwnode() is useful at a few other places
> > > outside of the driver core, as in gpiolib.c for example. Therefore let's
> > > make it available as a common helper function.
> > >
> > > Suggested-by: Saravana Kannan <saravanak@google.com>
> > > Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
> > > Tested-by: Hiago De Franco <hiago.franco@toradex.com> # Colibri iMX8X
> > > Tested-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com> # TI AM62A,Xilinx ZynqMP ZCU106
> > > Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
> > > ---
> > > drivers/base/core.c | 8 ++++++--
> > > include/linux/device.h | 1 +
> > > 2 files changed, 7 insertions(+), 2 deletions(-)
> > >
> >
> > Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
>
> I'm a bit concerned about exporting get_dev_from_fwnode() -- at least without a
> clear note on that this helper should be used with caution.
>
> AFAIK, a struct fwnode_handle instance does not have a reference count for its
> struct device pointer.
>
> Hence, calling get_dev_from_fwnode() with a valid fwnode handle is not enough.
Not enough for what?
> The caller also needs to ensure that the device the fwnode has a pointer to has
> not been released yet.
Why? The point of the API is to give you the driver core's notion of
the primary device that corresponds to a fwnode at that instant.
There's no refcount needed for that. This is just a simpler way than
looping through all the devices to find the first device that has that
specific fwnode.
It's only the device that needs to be ref counted because the caller
needs to do stuff with it.
-Saravana
^ permalink raw reply [flat|nested] 59+ messages in thread
* Re: [PATCH v3 17/24] driver core: Export get_dev_from_fwnode()
2025-07-02 21:34 ` Saravana Kannan
@ 2025-07-02 21:55 ` Danilo Krummrich
0 siblings, 0 replies; 59+ messages in thread
From: Danilo Krummrich @ 2025-07-02 21:55 UTC (permalink / raw)
To: Saravana Kannan
Cc: Greg Kroah-Hartman, Ulf Hansson, Stephen Boyd, linux-pm,
Rafael J . Wysocki, Michael Grzeschik, Bjorn Andersson, Abel Vesa,
Peng Fan, Tomi Valkeinen, Johan Hovold, Maulik Shah, Michal Simek,
Konrad Dybcio, Thierry Reding, Jonathan Hunter, Hiago De Franco,
Geert Uytterhoeven, linux-arm-kernel, linux-kernel
On Wed, Jul 02, 2025 at 02:34:04PM -0700, Saravana Kannan wrote:
> On Wed, Jul 2, 2025 at 12:26 PM Danilo Krummrich <dakr@kernel.org> wrote:
> >
> > On Wed, Jul 02, 2025 at 09:34:12AM +0200, Greg Kroah-Hartman wrote:
> > > On Tue, Jul 01, 2025 at 01:47:19PM +0200, Ulf Hansson wrote:
> > > > It has turned out get_dev_from_fwnode() is useful at a few other places
> > > > outside of the driver core, as in gpiolib.c for example. Therefore let's
> > > > make it available as a common helper function.
> > > >
> > > > Suggested-by: Saravana Kannan <saravanak@google.com>
> > > > Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
> > > > Tested-by: Hiago De Franco <hiago.franco@toradex.com> # Colibri iMX8X
> > > > Tested-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com> # TI AM62A,Xilinx ZynqMP ZCU106
> > > > Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
> > > > ---
> > > > drivers/base/core.c | 8 ++++++--
> > > > include/linux/device.h | 1 +
> > > > 2 files changed, 7 insertions(+), 2 deletions(-)
> > > >
> > >
> > > Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
> >
> > I'm a bit concerned about exporting get_dev_from_fwnode() -- at least without a
> > clear note on that this helper should be used with caution.
> >
> > AFAIK, a struct fwnode_handle instance does not have a reference count for its
> > struct device pointer.
> >
> > Hence, calling get_dev_from_fwnode() with a valid fwnode handle is not enough.
>
> Not enough for what?
Having a valid pointer to a fwnode does not guarantee that fwnode->dev is a
valid pointer. Given that fwnode is reference counted itself, but only has a
weak reference of the device behind fwnode->dev, the device may have been
released already.
If the scope this function is called from can't guarantee that fwnode->dev has
not been released yet, it's a potential UAF.
Yes, device_del() sets dev->fwnode->dev = NULL. But that makes it still racy.
If someone has a reference count on the fwnode and calls get_dev_from_fwnode()
while device_del() runs concurrently (assuming that device_del() drops the last
reference of the device), it's a race with a potential UAF.
We should warn about this, when makeing get_dev_from_fwnode() and API that can
be used by *everyone*.
- Danilo
^ permalink raw reply [flat|nested] 59+ messages in thread
* Re: [PATCH v3 11/24] cpuidle: riscv-sbi: Opt-out from genpd's common ->sync_state() support
2025-07-01 11:47 ` [PATCH v3 11/24] cpuidle: riscv-sbi: " Ulf Hansson
@ 2025-07-04 10:14 ` Rahul Pathak
2025-07-07 9:36 ` Anup Patel
2025-08-10 21:12 ` patchwork-bot+linux-riscv
2 siblings, 0 replies; 59+ messages in thread
From: Rahul Pathak @ 2025-07-04 10:14 UTC (permalink / raw)
To: Ulf Hansson
Cc: Saravana Kannan, Stephen Boyd, linux-pm, Rafael J . Wysocki,
Greg Kroah-Hartman, Michael Grzeschik, Bjorn Andersson, Abel Vesa,
Peng Fan, Tomi Valkeinen, Johan Hovold, Maulik Shah, Michal Simek,
Konrad Dybcio, Thierry Reding, Jonathan Hunter, Hiago De Franco,
Geert Uytterhoeven, linux-arm-kernel, linux-kernel, Anup Patel,
linux-riscv
On Tue, Jul 1, 2025 at 5:20 PM Ulf Hansson <ulf.hansson@linaro.org> wrote:
>
> The riscv-sbi-domain implements its own specific ->sync_state() callback.
> Let's set the GENPD_FLAG_NO_SYNC_STATE to inform genpd about it.
>
> Moreover, let's call of_genpd_sync_state() to make sure genpd tries to
> power off unused PM domains.
>
> Cc: Anup Patel <anup@brainfault.org>
> Cc: linux-riscv@lists.infradead.org
> Tested-by: Hiago De Franco <hiago.franco@toradex.com> # Colibri iMX8X
> Tested-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com> # TI AM62A,Xilinx ZynqMP ZCU106
> Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
> ---
> drivers/cpuidle/cpuidle-riscv-sbi.c | 8 +++++++-
> 1 file changed, 7 insertions(+), 1 deletion(-)
>
LGTM
Reviewed-by: Rahul Pathak <rpathak@ventanamicro.com>
^ permalink raw reply [flat|nested] 59+ messages in thread
* Re: [PATCH v3 24/24] cpuidle: riscv-sbi: Drop redundant sync_state support
2025-07-01 11:47 ` [PATCH v3 24/24] cpuidle: riscv-sbi: " Ulf Hansson
@ 2025-07-04 10:39 ` Rahul Pathak
2025-07-07 9:38 ` Anup Patel
1 sibling, 0 replies; 59+ messages in thread
From: Rahul Pathak @ 2025-07-04 10:39 UTC (permalink / raw)
To: Ulf Hansson
Cc: Saravana Kannan, Stephen Boyd, linux-pm, Rafael J . Wysocki,
Greg Kroah-Hartman, Michael Grzeschik, Bjorn Andersson, Abel Vesa,
Peng Fan, Tomi Valkeinen, Johan Hovold, Maulik Shah, Michal Simek,
Konrad Dybcio, Thierry Reding, Jonathan Hunter, Hiago De Franco,
Geert Uytterhoeven, linux-arm-kernel, linux-kernel, Anup Patel,
linux-riscv
On Tue, Jul 1, 2025 at 5:23 PM Ulf Hansson <ulf.hansson@linaro.org> wrote:
>
> The recent updates to the genpd core, can entirely manage the sync_state
> support for the cpuidle-riscv-sbi-domain. More precisely, genpd prevents
> our ->power_off() callback from being invoked, until all of our consumers
> are ready for it.
>
> Let's therefore drop the sync_state support for the
> cpuidle-riscv-sbi-domain as it has become redundant.
>
> Cc: Anup Patel <anup@brainfault.org>
> Cc: linux-riscv@lists.infradead.org
> Tested-by: Hiago De Franco <hiago.franco@toradex.com> # Colibri iMX8X
> Tested-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com> # TI AM62A,Xilinx ZynqMP ZCU106
> Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
> ---
> drivers/cpuidle/cpuidle-riscv-sbi.c | 22 +---------------------
> 1 file changed, 1 insertion(+), 21 deletions(-)
>
LGTM
Reviewed-by: Rahul Pathak <rpathak@ventanamicro.com>
^ permalink raw reply [flat|nested] 59+ messages in thread
* Re: [PATCH v3 11/24] cpuidle: riscv-sbi: Opt-out from genpd's common ->sync_state() support
2025-07-01 11:47 ` [PATCH v3 11/24] cpuidle: riscv-sbi: " Ulf Hansson
2025-07-04 10:14 ` Rahul Pathak
@ 2025-07-07 9:36 ` Anup Patel
2025-08-10 21:12 ` patchwork-bot+linux-riscv
2 siblings, 0 replies; 59+ messages in thread
From: Anup Patel @ 2025-07-07 9:36 UTC (permalink / raw)
To: Ulf Hansson
Cc: Saravana Kannan, Stephen Boyd, linux-pm, Rafael J . Wysocki,
Greg Kroah-Hartman, Michael Grzeschik, Bjorn Andersson, Abel Vesa,
Peng Fan, Tomi Valkeinen, Johan Hovold, Maulik Shah, Michal Simek,
Konrad Dybcio, Thierry Reding, Jonathan Hunter, Hiago De Franco,
Geert Uytterhoeven, linux-arm-kernel, linux-kernel, linux-riscv
On Tue, Jul 1, 2025 at 5:17 PM Ulf Hansson <ulf.hansson@linaro.org> wrote:
>
> The riscv-sbi-domain implements its own specific ->sync_state() callback.
> Let's set the GENPD_FLAG_NO_SYNC_STATE to inform genpd about it.
>
> Moreover, let's call of_genpd_sync_state() to make sure genpd tries to
> power off unused PM domains.
>
> Cc: Anup Patel <anup@brainfault.org>
> Cc: linux-riscv@lists.infradead.org
> Tested-by: Hiago De Franco <hiago.franco@toradex.com> # Colibri iMX8X
> Tested-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com> # TI AM62A,Xilinx ZynqMP ZCU106
> Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
LGTM.
Reviewed-by: Anup Patel <anup@brainfault.org>
Regards,
Anup
> ---
> drivers/cpuidle/cpuidle-riscv-sbi.c | 8 +++++++-
> 1 file changed, 7 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/cpuidle/cpuidle-riscv-sbi.c b/drivers/cpuidle/cpuidle-riscv-sbi.c
> index 0fe1ece9fbdc..83d58d00872f 100644
> --- a/drivers/cpuidle/cpuidle-riscv-sbi.c
> +++ b/drivers/cpuidle/cpuidle-riscv-sbi.c
> @@ -347,11 +347,16 @@ static int sbi_cpuidle_init_cpu(struct device *dev, int cpu)
>
> static void sbi_cpuidle_domain_sync_state(struct device *dev)
> {
> + struct sbi_pd_provider *pd_provider;
> +
> /*
> * All devices have now been attached/probed to the PM domain
> * topology, hence it's fine to allow domain states to be picked.
> */
> sbi_cpuidle_pd_allow_domain_state = true;
> +
> + list_for_each_entry(pd_provider, &sbi_pd_providers, link)
> + of_genpd_sync_state(pd_provider->node);
> }
>
> #ifdef CONFIG_DT_IDLE_GENPD
> @@ -396,7 +401,8 @@ static int sbi_pd_init(struct device_node *np)
> if (!pd_provider)
> goto free_pd;
>
> - pd->flags |= GENPD_FLAG_IRQ_SAFE | GENPD_FLAG_CPU_DOMAIN;
> + pd->flags |= GENPD_FLAG_IRQ_SAFE | GENPD_FLAG_CPU_DOMAIN |
> + GENPD_FLAG_NO_SYNC_STATE;
>
> /* Allow power off when OSI is available. */
> if (sbi_cpuidle_use_osi)
> --
> 2.43.0
>
^ permalink raw reply [flat|nested] 59+ messages in thread
* Re: [PATCH v3 24/24] cpuidle: riscv-sbi: Drop redundant sync_state support
2025-07-01 11:47 ` [PATCH v3 24/24] cpuidle: riscv-sbi: " Ulf Hansson
2025-07-04 10:39 ` Rahul Pathak
@ 2025-07-07 9:38 ` Anup Patel
1 sibling, 0 replies; 59+ messages in thread
From: Anup Patel @ 2025-07-07 9:38 UTC (permalink / raw)
To: Ulf Hansson
Cc: Saravana Kannan, Stephen Boyd, linux-pm, Rafael J . Wysocki,
Greg Kroah-Hartman, Michael Grzeschik, Bjorn Andersson, Abel Vesa,
Peng Fan, Tomi Valkeinen, Johan Hovold, Maulik Shah, Michal Simek,
Konrad Dybcio, Thierry Reding, Jonathan Hunter, Hiago De Franco,
Geert Uytterhoeven, linux-arm-kernel, linux-kernel, linux-riscv
On Tue, Jul 1, 2025 at 5:18 PM Ulf Hansson <ulf.hansson@linaro.org> wrote:
>
> The recent updates to the genpd core, can entirely manage the sync_state
> support for the cpuidle-riscv-sbi-domain. More precisely, genpd prevents
> our ->power_off() callback from being invoked, until all of our consumers
> are ready for it.
>
> Let's therefore drop the sync_state support for the
> cpuidle-riscv-sbi-domain as it has become redundant.
>
> Cc: Anup Patel <anup@brainfault.org>
> Cc: linux-riscv@lists.infradead.org
> Tested-by: Hiago De Franco <hiago.franco@toradex.com> # Colibri iMX8X
> Tested-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com> # TI AM62A,Xilinx ZynqMP ZCU106
> Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
LGTM.
Reviewed-by: Anup Patel <anup@brainfault.org>
Regards,
Anup
> ---
> drivers/cpuidle/cpuidle-riscv-sbi.c | 22 +---------------------
> 1 file changed, 1 insertion(+), 21 deletions(-)
>
> diff --git a/drivers/cpuidle/cpuidle-riscv-sbi.c b/drivers/cpuidle/cpuidle-riscv-sbi.c
> index 83d58d00872f..a360bc4d20b7 100644
> --- a/drivers/cpuidle/cpuidle-riscv-sbi.c
> +++ b/drivers/cpuidle/cpuidle-riscv-sbi.c
> @@ -44,7 +44,6 @@ static DEFINE_PER_CPU_READ_MOSTLY(struct sbi_cpuidle_data, sbi_cpuidle_data);
> static DEFINE_PER_CPU(struct sbi_domain_state, domain_state);
> static bool sbi_cpuidle_use_osi;
> static bool sbi_cpuidle_use_cpuhp;
> -static bool sbi_cpuidle_pd_allow_domain_state;
>
> static inline void sbi_set_domain_state(u32 state)
> {
> @@ -345,20 +344,6 @@ static int sbi_cpuidle_init_cpu(struct device *dev, int cpu)
> return ret;
> }
>
> -static void sbi_cpuidle_domain_sync_state(struct device *dev)
> -{
> - struct sbi_pd_provider *pd_provider;
> -
> - /*
> - * All devices have now been attached/probed to the PM domain
> - * topology, hence it's fine to allow domain states to be picked.
> - */
> - sbi_cpuidle_pd_allow_domain_state = true;
> -
> - list_for_each_entry(pd_provider, &sbi_pd_providers, link)
> - of_genpd_sync_state(pd_provider->node);
> -}
> -
> #ifdef CONFIG_DT_IDLE_GENPD
>
> static int sbi_cpuidle_pd_power_off(struct generic_pm_domain *pd)
> @@ -369,9 +354,6 @@ static int sbi_cpuidle_pd_power_off(struct generic_pm_domain *pd)
> if (!state->data)
> return 0;
>
> - if (!sbi_cpuidle_pd_allow_domain_state)
> - return -EBUSY;
> -
> /* OSI mode is enabled, set the corresponding domain state. */
> pd_state = state->data;
> sbi_set_domain_state(*pd_state);
> @@ -401,8 +383,7 @@ static int sbi_pd_init(struct device_node *np)
> if (!pd_provider)
> goto free_pd;
>
> - pd->flags |= GENPD_FLAG_IRQ_SAFE | GENPD_FLAG_CPU_DOMAIN |
> - GENPD_FLAG_NO_SYNC_STATE;
> + pd->flags |= GENPD_FLAG_IRQ_SAFE | GENPD_FLAG_CPU_DOMAIN;
>
> /* Allow power off when OSI is available. */
> if (sbi_cpuidle_use_osi)
> @@ -570,7 +551,6 @@ static struct platform_driver sbi_cpuidle_driver = {
> .probe = sbi_cpuidle_probe,
> .driver = {
> .name = "sbi-cpuidle",
> - .sync_state = sbi_cpuidle_domain_sync_state,
> },
> };
>
> --
> 2.43.0
>
^ permalink raw reply [flat|nested] 59+ messages in thread
* Re: [PATCH v3 00/24] pmdomain: Add generic ->sync_state() support to genpd
2025-07-01 11:47 [PATCH v3 00/24] pmdomain: Add generic ->sync_state() support to genpd Ulf Hansson
` (23 preceding siblings ...)
2025-07-01 11:47 ` [PATCH v3 24/24] cpuidle: riscv-sbi: " Ulf Hansson
@ 2025-07-09 11:30 ` Ulf Hansson
2025-07-15 8:50 ` Danilo Krummrich
` (2 more replies)
2025-09-03 7:39 ` Sebin Francis
25 siblings, 3 replies; 59+ messages in thread
From: Ulf Hansson @ 2025-07-09 11:30 UTC (permalink / raw)
To: Saravana Kannan, Stephen Boyd, linux-pm
Cc: Rafael J . Wysocki, Greg Kroah-Hartman, Michael Grzeschik,
Bjorn Andersson, Abel Vesa, Peng Fan, Tomi Valkeinen,
Johan Hovold, Maulik Shah, Michal Simek, Konrad Dybcio,
Thierry Reding, Jonathan Hunter, Hiago De Franco,
Geert Uytterhoeven, linux-arm-kernel, linux-kernel
On Tue, 1 Jul 2025 at 13:47, Ulf Hansson <ulf.hansson@linaro.org> wrote:
>
> Changes in v3:
> - Added a couple of patches to adress problems on some Renesas
> platforms. Thanks Geert and Tomi for helping out!
> - Adressed a few comments from Saravanna and Konrad.
> - Added some tested-by tags.
I decided it was time to give this a try, so I have queued this up for
v6.17 via the next branch at my pmdomain tree.
If you encounter any issues, please let me know so I can help to fix them.
Kind regards
Uffe
>
> Changes in v2:
> - Well, quite a lot as I discovered various problems when doing
> additional testing of corner-case. I suggest re-review from scratch,
> even if I decided to keep some reviewed-by tags.
> - Added patches to allow some drivers that needs to align or opt-out
> from the new common behaviour in genpd.
>
> If a PM domain (genpd) is powered-on during boot, there is probably a good
> reason for it. Therefore it's known to be a bad idea to allow such genpd to be
> powered-off before all of its consumer devices have been probed. This series
> intends to fix this problem.
>
> We have been discussing these issues at LKML and at various Linux-conferences
> in the past. I have therefore tried to include the people I can recall being
> involved, but I may have forgotten some (my apologies), feel free to loop them
> in.
>
> I have tested this with QEMU with a bunch of local test-drivers and DT nodes.
> Let me know if you want me to share this code too.
>
> Please help review and test!
> Finally, a big thanks to Saravana for all the support!
>
> Kind regards
> Ulf Hansson
>
>
> Saravana Kannan (1):
> driver core: Add dev_set_drv_sync_state()
>
> Ulf Hansson (23):
> pmdomain: renesas: rcar-sysc: Add genpd OF provider at
> postcore_initcall
> pmdomain: renesas: rmobile-sysc: Move init to postcore_initcall
> pmdomain: renesas: rcar-gen4-sysc: Move init to postcore_initcall
> pmdomain: core: Prevent registering devices before the bus
> pmdomain: core: Add a bus and a driver for genpd providers
> pmdomain: core: Add the genpd->dev to the genpd provider bus
> pmdomain: core: Export a common ->sync_state() helper for genpd
> providers
> pmdomain: core: Prepare to add the common ->sync_state() support
> soc/tegra: pmc: Opt-out from genpd's common ->sync_state() support
> cpuidle: psci: Opt-out from genpd's common ->sync_state() support
> cpuidle: riscv-sbi: Opt-out from genpd's common ->sync_state() support
> pmdomain: qcom: rpmpd: Use of_genpd_sync_state()
> pmdomain: qcom: rpmhpd: Use of_genpd_sync_state()
> firmware/pmdomain: xilinx: Move ->sync_state() support to firmware
> driver
> firmware: xilinx: Don't share zynqmp_pm_init_finalize()
> firmware: xilinx: Use of_genpd_sync_state()
> driver core: Export get_dev_from_fwnode()
> pmdomain: core: Add common ->sync_state() support for genpd providers
> pmdomain: core: Default to use of_genpd_sync_state() for genpd
> providers
> pmdomain: core: Leave powered-on genpds on until late_initcall_sync
> pmdomain: core: Leave powered-on genpds on until sync_state
> cpuidle: psci: Drop redundant sync_state support
> cpuidle: riscv-sbi: Drop redundant sync_state support
>
> drivers/base/core.c | 8 +-
> drivers/cpuidle/cpuidle-psci-domain.c | 14 --
> drivers/cpuidle/cpuidle-riscv-sbi.c | 14 --
> drivers/firmware/xilinx/zynqmp.c | 18 +-
> drivers/pmdomain/core.c | 211 ++++++++++++++++++--
> drivers/pmdomain/qcom/rpmhpd.c | 2 +
> drivers/pmdomain/qcom/rpmpd.c | 2 +
> drivers/pmdomain/renesas/rcar-gen4-sysc.c | 2 +-
> drivers/pmdomain/renesas/rcar-sysc.c | 19 +-
> drivers/pmdomain/renesas/rmobile-sysc.c | 3 +-
> drivers/pmdomain/xilinx/zynqmp-pm-domains.c | 16 --
> drivers/soc/tegra/pmc.c | 26 ++-
> include/linux/device.h | 13 ++
> include/linux/firmware/xlnx-zynqmp.h | 6 -
> include/linux/pm_domain.h | 17 ++
> 15 files changed, 291 insertions(+), 80 deletions(-)
>
> --
> 2.43.0
>
^ permalink raw reply [flat|nested] 59+ messages in thread
* Re: [PATCH v3 21/24] pmdomain: core: Leave powered-on genpds on until late_initcall_sync
[not found] ` <CGME20250710122654eucas1p20f1179a9ff22d562d89252f924d34dae@eucas1p2.samsung.com>
@ 2025-07-10 12:26 ` Marek Szyprowski
2025-07-10 14:54 ` Ulf Hansson
0 siblings, 1 reply; 59+ messages in thread
From: Marek Szyprowski @ 2025-07-10 12:26 UTC (permalink / raw)
To: Ulf Hansson, Saravana Kannan, Stephen Boyd, linux-pm
Cc: Rafael J . Wysocki, Greg Kroah-Hartman, Michael Grzeschik,
Bjorn Andersson, Abel Vesa, Peng Fan, Tomi Valkeinen,
Johan Hovold, Maulik Shah, Michal Simek, Konrad Dybcio,
Thierry Reding, Jonathan Hunter, Hiago De Franco,
Geert Uytterhoeven, linux-arm-kernel, linux-kernel
On 01.07.2025 13:47, Ulf Hansson wrote:
> Powering-off a genpd that was on during boot, before all of its consumer
> devices have been probed, is certainly prone to problems.
>
> As a step to improve this situation, let's prevent these genpds from being
> powered-off until genpd_power_off_unused() gets called, which is a
> late_initcall_sync().
>
> Note that, this still doesn't guarantee that all the consumer devices has
> been probed before we allow to power-off the genpds. Yet, this should be a
> step in the right direction.
>
> Suggested-by: Saravana Kannan <saravanak@google.com>
> Tested-by: Hiago De Franco <hiago.franco@toradex.com> # Colibri iMX8X
> Tested-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com> # TI AM62A,Xilinx ZynqMP ZCU106
> Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
This change has a side effect on some Exynos based boards, which have
display and bootloader is configured to setup a splash screen on it.
Since today's linux-next, those boards fails to boot, because of the
IOMMU page fault.
This happens because the display controller is enabled and configured to
perform the scanout from the spash-screen buffer until the respective
driver will reset it in driver probe() function. This however doesn't
work with IOMMU, which is being probed earlier than the display
controller driver, what in turn causes IOMMU page fault once the IOMMU
driver gets attached. This worked before applying this patch, because
the power domain of display controller was simply turned off early
effectively reseting the display controller.
This has been discussed a bit recently:
https://lore.kernel.org/all/544ad69cba52a9b87447e3ac1c7fa8c3@disroot.org/
and I can add a workaround for this issue in the bootloaders of those
boards, but this is something that has to be somehow addressed in a
generic way.
> ---
> drivers/pmdomain/core.c | 10 ++++++++--
> include/linux/pm_domain.h | 1 +
> 2 files changed, 9 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/pmdomain/core.c b/drivers/pmdomain/core.c
> index 5cef6de60c72..18951ed6295d 100644
> --- a/drivers/pmdomain/core.c
> +++ b/drivers/pmdomain/core.c
> @@ -931,11 +931,12 @@ static void genpd_power_off(struct generic_pm_domain *genpd, bool one_dev_on,
> * The domain is already in the "power off" state.
> * System suspend is in progress.
> * The domain is configured as always on.
> + * The domain was on at boot and still need to stay on.
> * The domain has a subdomain being powered on.
> */
> if (!genpd_status_on(genpd) || genpd->prepared_count > 0 ||
> genpd_is_always_on(genpd) || genpd_is_rpm_always_on(genpd) ||
> - atomic_read(&genpd->sd_count) > 0)
> + genpd->stay_on || atomic_read(&genpd->sd_count) > 0)
> return;
>
> /*
> @@ -1346,8 +1347,12 @@ static int __init genpd_power_off_unused(void)
> pr_info("genpd: Disabling unused power domains\n");
> mutex_lock(&gpd_list_lock);
>
> - list_for_each_entry(genpd, &gpd_list, gpd_list_node)
> + list_for_each_entry(genpd, &gpd_list, gpd_list_node) {
> + genpd_lock(genpd);
> + genpd->stay_on = false;
> + genpd_unlock(genpd);
> genpd_queue_power_off_work(genpd);
> + }
>
> mutex_unlock(&gpd_list_lock);
>
> @@ -2352,6 +2357,7 @@ int pm_genpd_init(struct generic_pm_domain *genpd,
> INIT_WORK(&genpd->power_off_work, genpd_power_off_work_fn);
> atomic_set(&genpd->sd_count, 0);
> genpd->status = is_off ? GENPD_STATE_OFF : GENPD_STATE_ON;
> + genpd->stay_on = !is_off;
> genpd->sync_state = GENPD_SYNC_STATE_OFF;
> genpd->device_count = 0;
> genpd->provider = NULL;
> diff --git a/include/linux/pm_domain.h b/include/linux/pm_domain.h
> index d68e07dadc99..99556589f45e 100644
> --- a/include/linux/pm_domain.h
> +++ b/include/linux/pm_domain.h
> @@ -199,6 +199,7 @@ struct generic_pm_domain {
> unsigned int performance_state; /* Aggregated max performance state */
> cpumask_var_t cpus; /* A cpumask of the attached CPUs */
> bool synced_poweroff; /* A consumer needs a synced poweroff */
> + bool stay_on; /* Stay powered-on during boot. */
> enum genpd_sync_state sync_state; /* How sync_state is managed. */
> int (*power_off)(struct generic_pm_domain *domain);
> int (*power_on)(struct generic_pm_domain *domain);
Best regards
--
Marek Szyprowski, PhD
Samsung R&D Institute Poland
^ permalink raw reply [flat|nested] 59+ messages in thread
* Re: [PATCH v3 21/24] pmdomain: core: Leave powered-on genpds on until late_initcall_sync
2025-07-10 12:26 ` Marek Szyprowski
@ 2025-07-10 14:54 ` Ulf Hansson
2025-07-15 10:28 ` Jon Hunter
0 siblings, 1 reply; 59+ messages in thread
From: Ulf Hansson @ 2025-07-10 14:54 UTC (permalink / raw)
To: Marek Szyprowski
Cc: Saravana Kannan, Stephen Boyd, linux-pm, Rafael J . Wysocki,
Greg Kroah-Hartman, Michael Grzeschik, Bjorn Andersson, Abel Vesa,
Peng Fan, Tomi Valkeinen, Johan Hovold, Maulik Shah, Michal Simek,
Konrad Dybcio, Thierry Reding, Jonathan Hunter, Hiago De Franco,
Geert Uytterhoeven, linux-arm-kernel, linux-kernel
On Thu, 10 Jul 2025 at 14:26, Marek Szyprowski <m.szyprowski@samsung.com> wrote:
>
> On 01.07.2025 13:47, Ulf Hansson wrote:
> > Powering-off a genpd that was on during boot, before all of its consumer
> > devices have been probed, is certainly prone to problems.
> >
> > As a step to improve this situation, let's prevent these genpds from being
> > powered-off until genpd_power_off_unused() gets called, which is a
> > late_initcall_sync().
> >
> > Note that, this still doesn't guarantee that all the consumer devices has
> > been probed before we allow to power-off the genpds. Yet, this should be a
> > step in the right direction.
> >
> > Suggested-by: Saravana Kannan <saravanak@google.com>
> > Tested-by: Hiago De Franco <hiago.franco@toradex.com> # Colibri iMX8X
> > Tested-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com> # TI AM62A,Xilinx ZynqMP ZCU106
> > Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
>
> This change has a side effect on some Exynos based boards, which have
> display and bootloader is configured to setup a splash screen on it.
> Since today's linux-next, those boards fails to boot, because of the
> IOMMU page fault.
Thanks for reporting, let's try to fix this as soon as possible then.
>
> This happens because the display controller is enabled and configured to
> perform the scanout from the spash-screen buffer until the respective
> driver will reset it in driver probe() function. This however doesn't
> work with IOMMU, which is being probed earlier than the display
> controller driver, what in turn causes IOMMU page fault once the IOMMU
> driver gets attached. This worked before applying this patch, because
> the power domain of display controller was simply turned off early
> effectively reseting the display controller.
I can certainly try to help to find a solution, but I believe I need
some more details of what is happening.
Perhaps you can point me to some relevant DTS file to start with?
>
> This has been discussed a bit recently:
> https://lore.kernel.org/all/544ad69cba52a9b87447e3ac1c7fa8c3@disroot.org/
> and I can add a workaround for this issue in the bootloaders of those
> boards, but this is something that has to be somehow addressed in a
> generic way.
It kind of sounds like there is a missing power-domain not being
described in DT for the IOMMU, but I might have understood the whole
thing wrong.
Let's see if we can work something out in the next few days, otherwise
we need to find another way to let some genpds for these platforms to
opt out from this new behaviour.
Kind regards
Uffe
>
> > ---
> > drivers/pmdomain/core.c | 10 ++++++++--
> > include/linux/pm_domain.h | 1 +
> > 2 files changed, 9 insertions(+), 2 deletions(-)
> >
> > diff --git a/drivers/pmdomain/core.c b/drivers/pmdomain/core.c
> > index 5cef6de60c72..18951ed6295d 100644
> > --- a/drivers/pmdomain/core.c
> > +++ b/drivers/pmdomain/core.c
> > @@ -931,11 +931,12 @@ static void genpd_power_off(struct generic_pm_domain *genpd, bool one_dev_on,
> > * The domain is already in the "power off" state.
> > * System suspend is in progress.
> > * The domain is configured as always on.
> > + * The domain was on at boot and still need to stay on.
> > * The domain has a subdomain being powered on.
> > */
> > if (!genpd_status_on(genpd) || genpd->prepared_count > 0 ||
> > genpd_is_always_on(genpd) || genpd_is_rpm_always_on(genpd) ||
> > - atomic_read(&genpd->sd_count) > 0)
> > + genpd->stay_on || atomic_read(&genpd->sd_count) > 0)
> > return;
> >
> > /*
> > @@ -1346,8 +1347,12 @@ static int __init genpd_power_off_unused(void)
> > pr_info("genpd: Disabling unused power domains\n");
> > mutex_lock(&gpd_list_lock);
> >
> > - list_for_each_entry(genpd, &gpd_list, gpd_list_node)
> > + list_for_each_entry(genpd, &gpd_list, gpd_list_node) {
> > + genpd_lock(genpd);
> > + genpd->stay_on = false;
> > + genpd_unlock(genpd);
> > genpd_queue_power_off_work(genpd);
> > + }
> >
> > mutex_unlock(&gpd_list_lock);
> >
> > @@ -2352,6 +2357,7 @@ int pm_genpd_init(struct generic_pm_domain *genpd,
> > INIT_WORK(&genpd->power_off_work, genpd_power_off_work_fn);
> > atomic_set(&genpd->sd_count, 0);
> > genpd->status = is_off ? GENPD_STATE_OFF : GENPD_STATE_ON;
> > + genpd->stay_on = !is_off;
> > genpd->sync_state = GENPD_SYNC_STATE_OFF;
> > genpd->device_count = 0;
> > genpd->provider = NULL;
> > diff --git a/include/linux/pm_domain.h b/include/linux/pm_domain.h
> > index d68e07dadc99..99556589f45e 100644
> > --- a/include/linux/pm_domain.h
> > +++ b/include/linux/pm_domain.h
> > @@ -199,6 +199,7 @@ struct generic_pm_domain {
> > unsigned int performance_state; /* Aggregated max performance state */
> > cpumask_var_t cpus; /* A cpumask of the attached CPUs */
> > bool synced_poweroff; /* A consumer needs a synced poweroff */
> > + bool stay_on; /* Stay powered-on during boot. */
> > enum genpd_sync_state sync_state; /* How sync_state is managed. */
> > int (*power_off)(struct generic_pm_domain *domain);
> > int (*power_on)(struct generic_pm_domain *domain);
>
> Best regards
> --
> Marek Szyprowski, PhD
> Samsung R&D Institute Poland
>
^ permalink raw reply [flat|nested] 59+ messages in thread
* Re: [PATCH v3 00/24] pmdomain: Add generic ->sync_state() support to genpd
2025-07-09 11:30 ` [PATCH v3 00/24] pmdomain: Add generic ->sync_state() support to genpd Ulf Hansson
@ 2025-07-15 8:50 ` Danilo Krummrich
2025-07-16 12:46 ` Ulf Hansson
2025-07-30 9:56 ` Geert Uytterhoeven
2025-08-13 12:04 ` Geert Uytterhoeven
2 siblings, 1 reply; 59+ messages in thread
From: Danilo Krummrich @ 2025-07-15 8:50 UTC (permalink / raw)
To: Ulf Hansson
Cc: Saravana Kannan, Stephen Boyd, linux-pm, Rafael J . Wysocki,
Greg Kroah-Hartman, Michael Grzeschik, Bjorn Andersson, Abel Vesa,
Peng Fan, Tomi Valkeinen, Johan Hovold, Maulik Shah, Michal Simek,
Konrad Dybcio, Thierry Reding, Jonathan Hunter, Hiago De Franco,
Geert Uytterhoeven, linux-arm-kernel, linux-kernel
Hi Ulf,
On Wed Jul 9, 2025 at 1:30 PM CEST, Ulf Hansson wrote:
> I decided it was time to give this a try, so I have queued this up for
> v6.17 via the next branch at my pmdomain tree.
>
> If you encounter any issues, please let me know so I can help to fix them.
Can you please address my concern in patch 17 ("driver core: Export
get_dev_from_fwnode()")?
Since this has been applied already, a subsequent patch would be perfectly fine.
Thanks,
Danilo
^ permalink raw reply [flat|nested] 59+ messages in thread
* Re: [PATCH v3 21/24] pmdomain: core: Leave powered-on genpds on until late_initcall_sync
2025-07-10 14:54 ` Ulf Hansson
@ 2025-07-15 10:28 ` Jon Hunter
2025-07-15 11:32 ` Ulf Hansson
0 siblings, 1 reply; 59+ messages in thread
From: Jon Hunter @ 2025-07-15 10:28 UTC (permalink / raw)
To: Ulf Hansson, Marek Szyprowski
Cc: Saravana Kannan, Stephen Boyd, linux-pm, Rafael J . Wysocki,
Greg Kroah-Hartman, Michael Grzeschik, Bjorn Andersson, Abel Vesa,
Peng Fan, Tomi Valkeinen, Johan Hovold, Maulik Shah, Michal Simek,
Konrad Dybcio, Thierry Reding, Hiago De Franco,
Geert Uytterhoeven, linux-arm-kernel, linux-kernel,
linux-tegra@vger.kernel.org
Hi Ulf,
On 10/07/2025 15:54, Ulf Hansson wrote:
> On Thu, 10 Jul 2025 at 14:26, Marek Szyprowski <m.szyprowski@samsung.com> wrote:
>>
>> On 01.07.2025 13:47, Ulf Hansson wrote:
>>> Powering-off a genpd that was on during boot, before all of its consumer
>>> devices have been probed, is certainly prone to problems.
>>>
>>> As a step to improve this situation, let's prevent these genpds from being
>>> powered-off until genpd_power_off_unused() gets called, which is a
>>> late_initcall_sync().
>>>
>>> Note that, this still doesn't guarantee that all the consumer devices has
>>> been probed before we allow to power-off the genpds. Yet, this should be a
>>> step in the right direction.
>>>
>>> Suggested-by: Saravana Kannan <saravanak@google.com>
>>> Tested-by: Hiago De Franco <hiago.franco@toradex.com> # Colibri iMX8X
>>> Tested-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com> # TI AM62A,Xilinx ZynqMP ZCU106
>>> Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
>>
>> This change has a side effect on some Exynos based boards, which have
>> display and bootloader is configured to setup a splash screen on it.
>> Since today's linux-next, those boards fails to boot, because of the
>> IOMMU page fault.
>
> Thanks for reporting, let's try to fix this as soon as possible then.
>
>>
>> This happens because the display controller is enabled and configured to
>> perform the scanout from the spash-screen buffer until the respective
>> driver will reset it in driver probe() function. This however doesn't
>> work with IOMMU, which is being probed earlier than the display
>> controller driver, what in turn causes IOMMU page fault once the IOMMU
>> driver gets attached. This worked before applying this patch, because
>> the power domain of display controller was simply turned off early
>> effectively reseting the display controller.
>
> I can certainly try to help to find a solution, but I believe I need
> some more details of what is happening.
>
> Perhaps you can point me to some relevant DTS file to start with?
>
>>
>> This has been discussed a bit recently:
>> https://lore.kernel.org/all/544ad69cba52a9b87447e3ac1c7fa8c3@disroot.org/
>> and I can add a workaround for this issue in the bootloaders of those
>> boards, but this is something that has to be somehow addressed in a
>> generic way.
>
> It kind of sounds like there is a missing power-domain not being
> described in DT for the IOMMU, but I might have understood the whole
> thing wrong.
>
> Let's see if we can work something out in the next few days, otherwise
> we need to find another way to let some genpds for these platforms to
> opt out from this new behaviour.
Have you found any resolution for this? I have also noticed a boot
regression on one of our Tegra210 boards and bisect is pointing to this
commit. I don't see any particular crash, but a hang on boot.
If there is any debug we can enable to see which pmdomain is the problem
let me know.
Thanks!
Jon
--
nvpublic
^ permalink raw reply [flat|nested] 59+ messages in thread
* Re: [PATCH v3 21/24] pmdomain: core: Leave powered-on genpds on until late_initcall_sync
2025-07-15 10:28 ` Jon Hunter
@ 2025-07-15 11:32 ` Ulf Hansson
2025-07-15 11:34 ` Ulf Hansson
0 siblings, 1 reply; 59+ messages in thread
From: Ulf Hansson @ 2025-07-15 11:32 UTC (permalink / raw)
To: Jon Hunter
Cc: Marek Szyprowski, Saravana Kannan, Stephen Boyd, linux-pm,
Rafael J . Wysocki, Greg Kroah-Hartman, Michael Grzeschik,
Bjorn Andersson, Abel Vesa, Peng Fan, Tomi Valkeinen,
Johan Hovold, Maulik Shah, Michal Simek, Konrad Dybcio,
Thierry Reding, Hiago De Franco, Geert Uytterhoeven,
linux-arm-kernel, linux-kernel, linux-tegra@vger.kernel.org
On Tue, 15 Jul 2025 at 12:28, Jon Hunter <jonathanh@nvidia.com> wrote:
>
> Hi Ulf,
>
> On 10/07/2025 15:54, Ulf Hansson wrote:
> > On Thu, 10 Jul 2025 at 14:26, Marek Szyprowski <m.szyprowski@samsung.com> wrote:
> >>
> >> On 01.07.2025 13:47, Ulf Hansson wrote:
> >>> Powering-off a genpd that was on during boot, before all of its consumer
> >>> devices have been probed, is certainly prone to problems.
> >>>
> >>> As a step to improve this situation, let's prevent these genpds from being
> >>> powered-off until genpd_power_off_unused() gets called, which is a
> >>> late_initcall_sync().
> >>>
> >>> Note that, this still doesn't guarantee that all the consumer devices has
> >>> been probed before we allow to power-off the genpds. Yet, this should be a
> >>> step in the right direction.
> >>>
> >>> Suggested-by: Saravana Kannan <saravanak@google.com>
> >>> Tested-by: Hiago De Franco <hiago.franco@toradex.com> # Colibri iMX8X
> >>> Tested-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com> # TI AM62A,Xilinx ZynqMP ZCU106
> >>> Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
> >>
> >> This change has a side effect on some Exynos based boards, which have
> >> display and bootloader is configured to setup a splash screen on it.
> >> Since today's linux-next, those boards fails to boot, because of the
> >> IOMMU page fault.
> >
> > Thanks for reporting, let's try to fix this as soon as possible then.
> >
> >>
> >> This happens because the display controller is enabled and configured to
> >> perform the scanout from the spash-screen buffer until the respective
> >> driver will reset it in driver probe() function. This however doesn't
> >> work with IOMMU, which is being probed earlier than the display
> >> controller driver, what in turn causes IOMMU page fault once the IOMMU
> >> driver gets attached. This worked before applying this patch, because
> >> the power domain of display controller was simply turned off early
> >> effectively reseting the display controller.
> >
> > I can certainly try to help to find a solution, but I believe I need
> > some more details of what is happening.
> >
> > Perhaps you can point me to some relevant DTS file to start with?
> >
> >>
> >> This has been discussed a bit recently:
> >> https://lore.kernel.org/all/544ad69cba52a9b87447e3ac1c7fa8c3@disroot.org/
> >> and I can add a workaround for this issue in the bootloaders of those
> >> boards, but this is something that has to be somehow addressed in a
> >> generic way.
> >
> > It kind of sounds like there is a missing power-domain not being
> > described in DT for the IOMMU, but I might have understood the whole
> > thing wrong.
> >
> > Let's see if we can work something out in the next few days, otherwise
> > we need to find another way to let some genpds for these platforms to
> > opt out from this new behaviour.
>
> Have you found any resolution for this? I have also noticed a boot
> regression on one of our Tegra210 boards and bisect is pointing to this
> commit. I don't see any particular crash, but a hang on boot.
Thanks for reporting!
For Exynos we opt-out from the behaviour by enforcing a sync_state of
all PM domains upfront [1], which means before any devices get
attached.
Even if that defeats the purpose of the $subject series, this was one
way forward that solved the problem. When the boot-ordering problem
(that's how I understood the issue) for Exynos gets resolved, we
should be able to drop the hack, at least that's the idea.
>
> If there is any debug we can enable to see which pmdomain is the problem
> let me know.
There aren't many debug prints in genpd that I think makes much sense
to enable, but you can always give it a try. Since you are hanging,
obviously you can't look at the genpd debugfs data...
Note that, the interesting PM domains are those that are powered-on
when calling pm_genpd_init(). As a start, I would add some debug
prints in () to see which PM domains that are relevant to track.
Potentially you could then try to power them off and register them
accordingly with genpd. One by one, to see which of them is causing
the problem.
Another option could be to add a new genpd config flag
(GENPD_FLAG_DONT_STAY_ON or something along those lines), that informs
genpd to not set the genpd->stay_on in pm_genpd_init(). Then
tegra_powergate_add() would have to set GENPD_FLAG_DONT_STAY_ON for
those genpds that really need it.
Kind regards
Uffe
[1]
https://lore.kernel.org/all/20250711114719.189441-1-ulf.hansson@linaro.org/
^ permalink raw reply [flat|nested] 59+ messages in thread
* Re: [PATCH v3 21/24] pmdomain: core: Leave powered-on genpds on until late_initcall_sync
2025-07-15 11:32 ` Ulf Hansson
@ 2025-07-15 11:34 ` Ulf Hansson
2025-07-31 12:53 ` Jon Hunter
0 siblings, 1 reply; 59+ messages in thread
From: Ulf Hansson @ 2025-07-15 11:34 UTC (permalink / raw)
To: Jon Hunter
Cc: Marek Szyprowski, Saravana Kannan, Stephen Boyd, linux-pm,
Rafael J . Wysocki, Greg Kroah-Hartman, Michael Grzeschik,
Bjorn Andersson, Abel Vesa, Peng Fan, Tomi Valkeinen,
Johan Hovold, Maulik Shah, Michal Simek, Konrad Dybcio,
Thierry Reding, Hiago De Franco, Geert Uytterhoeven,
linux-arm-kernel, linux-kernel, linux-tegra@vger.kernel.org
On Tue, 15 Jul 2025 at 13:32, Ulf Hansson <ulf.hansson@linaro.org> wrote:
>
> On Tue, 15 Jul 2025 at 12:28, Jon Hunter <jonathanh@nvidia.com> wrote:
> >
> > Hi Ulf,
> >
> > On 10/07/2025 15:54, Ulf Hansson wrote:
> > > On Thu, 10 Jul 2025 at 14:26, Marek Szyprowski <m.szyprowski@samsung.com> wrote:
> > >>
> > >> On 01.07.2025 13:47, Ulf Hansson wrote:
> > >>> Powering-off a genpd that was on during boot, before all of its consumer
> > >>> devices have been probed, is certainly prone to problems.
> > >>>
> > >>> As a step to improve this situation, let's prevent these genpds from being
> > >>> powered-off until genpd_power_off_unused() gets called, which is a
> > >>> late_initcall_sync().
> > >>>
> > >>> Note that, this still doesn't guarantee that all the consumer devices has
> > >>> been probed before we allow to power-off the genpds. Yet, this should be a
> > >>> step in the right direction.
> > >>>
> > >>> Suggested-by: Saravana Kannan <saravanak@google.com>
> > >>> Tested-by: Hiago De Franco <hiago.franco@toradex.com> # Colibri iMX8X
> > >>> Tested-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com> # TI AM62A,Xilinx ZynqMP ZCU106
> > >>> Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
> > >>
> > >> This change has a side effect on some Exynos based boards, which have
> > >> display and bootloader is configured to setup a splash screen on it.
> > >> Since today's linux-next, those boards fails to boot, because of the
> > >> IOMMU page fault.
> > >
> > > Thanks for reporting, let's try to fix this as soon as possible then.
> > >
> > >>
> > >> This happens because the display controller is enabled and configured to
> > >> perform the scanout from the spash-screen buffer until the respective
> > >> driver will reset it in driver probe() function. This however doesn't
> > >> work with IOMMU, which is being probed earlier than the display
> > >> controller driver, what in turn causes IOMMU page fault once the IOMMU
> > >> driver gets attached. This worked before applying this patch, because
> > >> the power domain of display controller was simply turned off early
> > >> effectively reseting the display controller.
> > >
> > > I can certainly try to help to find a solution, but I believe I need
> > > some more details of what is happening.
> > >
> > > Perhaps you can point me to some relevant DTS file to start with?
> > >
> > >>
> > >> This has been discussed a bit recently:
> > >> https://lore.kernel.org/all/544ad69cba52a9b87447e3ac1c7fa8c3@disroot.org/
> > >> and I can add a workaround for this issue in the bootloaders of those
> > >> boards, but this is something that has to be somehow addressed in a
> > >> generic way.
> > >
> > > It kind of sounds like there is a missing power-domain not being
> > > described in DT for the IOMMU, but I might have understood the whole
> > > thing wrong.
> > >
> > > Let's see if we can work something out in the next few days, otherwise
> > > we need to find another way to let some genpds for these platforms to
> > > opt out from this new behaviour.
> >
> > Have you found any resolution for this? I have also noticed a boot
> > regression on one of our Tegra210 boards and bisect is pointing to this
> > commit. I don't see any particular crash, but a hang on boot.
>
> Thanks for reporting!
>
> For Exynos we opt-out from the behaviour by enforcing a sync_state of
> all PM domains upfront [1], which means before any devices get
> attached.
>
> Even if that defeats the purpose of the $subject series, this was one
> way forward that solved the problem. When the boot-ordering problem
> (that's how I understood the issue) for Exynos gets resolved, we
> should be able to drop the hack, at least that's the idea.
>
> >
> > If there is any debug we can enable to see which pmdomain is the problem
> > let me know.
>
> There aren't many debug prints in genpd that I think makes much sense
> to enable, but you can always give it a try. Since you are hanging,
> obviously you can't look at the genpd debugfs data...
>
> Note that, the interesting PM domains are those that are powered-on
> when calling pm_genpd_init(). As a start, I would add some debug
> prints in () to see which PM domains that are relevant to track.
/s/()/tegra_powergate_add()
> Potentially you could then try to power them off and register them
> accordingly with genpd. One by one, to see which of them is causing
> the problem.
>
> Another option could be to add a new genpd config flag
> (GENPD_FLAG_DONT_STAY_ON or something along those lines), that informs
> genpd to not set the genpd->stay_on in pm_genpd_init(). Then
> tegra_powergate_add() would have to set GENPD_FLAG_DONT_STAY_ON for
> those genpds that really need it.
>
> Kind regards
> Uffe
>
> [1]
> https://lore.kernel.org/all/20250711114719.189441-1-ulf.hansson@linaro.org/
^ permalink raw reply [flat|nested] 59+ messages in thread
* Re: [PATCH v3 00/24] pmdomain: Add generic ->sync_state() support to genpd
2025-07-15 8:50 ` Danilo Krummrich
@ 2025-07-16 12:46 ` Ulf Hansson
2025-07-16 13:08 ` Danilo Krummrich
0 siblings, 1 reply; 59+ messages in thread
From: Ulf Hansson @ 2025-07-16 12:46 UTC (permalink / raw)
To: Danilo Krummrich
Cc: Saravana Kannan, Stephen Boyd, linux-pm, Rafael J . Wysocki,
Greg Kroah-Hartman, Michael Grzeschik, Bjorn Andersson, Abel Vesa,
Peng Fan, Tomi Valkeinen, Johan Hovold, Maulik Shah, Michal Simek,
Konrad Dybcio, Thierry Reding, Jonathan Hunter, Hiago De Franco,
Geert Uytterhoeven, linux-arm-kernel, linux-kernel
On Tue, 15 Jul 2025 at 10:50, Danilo Krummrich <dakr@kernel.org> wrote:
>
> Hi Ulf,
>
> On Wed Jul 9, 2025 at 1:30 PM CEST, Ulf Hansson wrote:
> > I decided it was time to give this a try, so I have queued this up for
> > v6.17 via the next branch at my pmdomain tree.
> >
> > If you encounter any issues, please let me know so I can help to fix them.
>
> Can you please address my concern in patch 17 ("driver core: Export
> get_dev_from_fwnode()")?
>
> Since this has been applied already, a subsequent patch would be perfectly fine.
Hi Danilo,
As Greg and Saravana were happy, I didn't want to hold back the whole
series only because of a minor comment on some missing documentation.
But, yes, let me look into it. It may take a while though, as vacation
is getting closer. If you want to send a patch yourself, please, feel
free to do it.
Note that, while at it, we should probably also add some documentation
of device_set_node() (next to get_dev_from_fwnode()) as it also lacks
it.
Kind regards
Uffe
^ permalink raw reply [flat|nested] 59+ messages in thread
* Re: [PATCH v3 00/24] pmdomain: Add generic ->sync_state() support to genpd
2025-07-16 12:46 ` Ulf Hansson
@ 2025-07-16 13:08 ` Danilo Krummrich
0 siblings, 0 replies; 59+ messages in thread
From: Danilo Krummrich @ 2025-07-16 13:08 UTC (permalink / raw)
To: Ulf Hansson
Cc: Saravana Kannan, Stephen Boyd, linux-pm, Rafael J . Wysocki,
Greg Kroah-Hartman, Michael Grzeschik, Bjorn Andersson, Abel Vesa,
Peng Fan, Tomi Valkeinen, Johan Hovold, Maulik Shah, Michal Simek,
Konrad Dybcio, Thierry Reding, Jonathan Hunter, Hiago De Franco,
Geert Uytterhoeven, linux-arm-kernel, linux-kernel
On Wed Jul 16, 2025 at 2:46 PM CEST, Ulf Hansson wrote:
> On Tue, 15 Jul 2025 at 10:50, Danilo Krummrich <dakr@kernel.org> wrote:
>>
>> Hi Ulf,
>>
>> On Wed Jul 9, 2025 at 1:30 PM CEST, Ulf Hansson wrote:
>> > I decided it was time to give this a try, so I have queued this up for
>> > v6.17 via the next branch at my pmdomain tree.
>> >
>> > If you encounter any issues, please let me know so I can help to fix them.
>>
>> Can you please address my concern in patch 17 ("driver core: Export
>> get_dev_from_fwnode()")?
>>
>> Since this has been applied already, a subsequent patch would be perfectly fine.
>
> Hi Danilo,
>
> As Greg and Saravana were happy, I didn't want to hold back the whole
> series only because of a minor comment on some missing documentation.
Fair enough -- yet, a brief reply asking if it can be done as a follow-up would
have been appreciated.
I don't think it's that minor. The race may be unlikely to happen, but if it
happens because someone isn't careful with this (now exported) API - and I'm
absolutely sure it's only gonna be a matter of time until that happens -, it'll
be painful. :(
> But, yes, let me look into it. It may take a while though, as vacation
> is getting closer. If you want to send a patch yourself, please, feel
> free to do it.
Ok, let me see if I can get to it.
> Note that, while at it, we should probably also add some documentation
> of device_set_node() (next to get_dev_from_fwnode()) as it also lacks
> it.
Agreed!
Have a nice vacation!
- Danilo
^ permalink raw reply [flat|nested] 59+ messages in thread
* Re: [PATCH v3 00/24] pmdomain: Add generic ->sync_state() support to genpd
2025-07-09 11:30 ` [PATCH v3 00/24] pmdomain: Add generic ->sync_state() support to genpd Ulf Hansson
2025-07-15 8:50 ` Danilo Krummrich
@ 2025-07-30 9:56 ` Geert Uytterhoeven
2025-07-30 10:29 ` Ulf Hansson
2025-08-13 12:04 ` Geert Uytterhoeven
2 siblings, 1 reply; 59+ messages in thread
From: Geert Uytterhoeven @ 2025-07-30 9:56 UTC (permalink / raw)
To: Ulf Hansson
Cc: Saravana Kannan, Stephen Boyd, linux-pm, Rafael J . Wysocki,
Greg Kroah-Hartman, Michael Grzeschik, Bjorn Andersson, Abel Vesa,
Peng Fan, Tomi Valkeinen, Johan Hovold, Maulik Shah, Michal Simek,
Konrad Dybcio, Thierry Reding, Jonathan Hunter, Hiago De Franco,
linux-arm-kernel, linux-kernel, Linux-Renesas
Hi Ulf,
On Wed, 9 Jul 2025 at 13:31, Ulf Hansson <ulf.hansson@linaro.org> wrote:
> On Tue, 1 Jul 2025 at 13:47, Ulf Hansson <ulf.hansson@linaro.org> wrote:
> > Changes in v3:
> > - Added a couple of patches to adress problems on some Renesas
> > platforms. Thanks Geert and Tomi for helping out!
> > - Adressed a few comments from Saravanna and Konrad.
> > - Added some tested-by tags.
>
> I decided it was time to give this a try, so I have queued this up for
> v6.17 via the next branch at my pmdomain tree.
>
> If you encounter any issues, please let me know so I can help to fix them.
Thanks for your series! Due to holidays, I only managed to test
this very recently.
Unfortunately I have an issue with unused PM Domains no longer being
disabled on R-Car:
- On R-Car Gen1/2/3, using rcar-sysc.c, unused PM Domains are never
disabled.
- On R-Car Gen4, using rcar-gen4-sysc.c, unused PM Domains are
sometimes not disabled.
At first, I noticed the IOMMU driver was not enabled in my config,
and enabling it did fix the issue. However, after that I still
encountered the issue in a different config that does have the
IOMMU driver enabled...
FTR, unused PM Domains are still disabled correctly on R/SH-Mobile
(using rmobile-sysc.c) and on BeagleBone Black. Note that these use
of_genpd_add_provider_simple(), while all R-Car drivers use
of_genpd_add_provider_onecell(). Perhaps there is an issue with
the latter? If you don't have a clue, I plan to do some more
investigation later...
BTW, the "pending due to"-messages look weird to me.
On R-Car M2-W (r8a7791.dtsi) I see e.g.:
genpd_provider ca15-cpu0: sync_state() pending due to e6020000.watchdog
renesas-cpg-mssr e6150000.clock-controller: sync_state() pending
due to e6020000.watchdog
ca15-cpu0 is the PM Domain holding the first CPU core, while
the watchdog resides in the always-on Clock Domain, and uses the
clock-controller for PM_CLK handling.
Thanks!
Gr{oetje,eeting}s,
Geert
--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org
In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds
^ permalink raw reply [flat|nested] 59+ messages in thread
* Re: [PATCH v3 00/24] pmdomain: Add generic ->sync_state() support to genpd
2025-07-30 9:56 ` Geert Uytterhoeven
@ 2025-07-30 10:29 ` Ulf Hansson
2025-08-07 9:38 ` Geert Uytterhoeven
0 siblings, 1 reply; 59+ messages in thread
From: Ulf Hansson @ 2025-07-30 10:29 UTC (permalink / raw)
To: Geert Uytterhoeven
Cc: Saravana Kannan, Stephen Boyd, linux-pm, Rafael J . Wysocki,
Greg Kroah-Hartman, Michael Grzeschik, Bjorn Andersson, Abel Vesa,
Peng Fan, Tomi Valkeinen, Johan Hovold, Maulik Shah, Michal Simek,
Konrad Dybcio, Thierry Reding, Jonathan Hunter, Hiago De Franco,
linux-arm-kernel, linux-kernel, Linux-Renesas
On Wed, 30 Jul 2025 at 11:56, Geert Uytterhoeven <geert@linux-m68k.org> wrote:
>
> Hi Ulf,
>
> On Wed, 9 Jul 2025 at 13:31, Ulf Hansson <ulf.hansson@linaro.org> wrote:
> > On Tue, 1 Jul 2025 at 13:47, Ulf Hansson <ulf.hansson@linaro.org> wrote:
> > > Changes in v3:
> > > - Added a couple of patches to adress problems on some Renesas
> > > platforms. Thanks Geert and Tomi for helping out!
> > > - Adressed a few comments from Saravanna and Konrad.
> > > - Added some tested-by tags.
> >
> > I decided it was time to give this a try, so I have queued this up for
> > v6.17 via the next branch at my pmdomain tree.
> >
> > If you encounter any issues, please let me know so I can help to fix them.
>
> Thanks for your series! Due to holidays, I only managed to test
> this very recently.
>
> Unfortunately I have an issue with unused PM Domains no longer being
> disabled on R-Car:
> - On R-Car Gen1/2/3, using rcar-sysc.c, unused PM Domains are never
> disabled.
> - On R-Car Gen4, using rcar-gen4-sysc.c, unused PM Domains are
> sometimes not disabled.
> At first, I noticed the IOMMU driver was not enabled in my config,
> and enabling it did fix the issue. However, after that I still
> encountered the issue in a different config that does have the
> IOMMU driver enabled...
>
> FTR, unused PM Domains are still disabled correctly on R/SH-Mobile
> (using rmobile-sysc.c) and on BeagleBone Black. Note that these use
> of_genpd_add_provider_simple(), while all R-Car drivers use
> of_genpd_add_provider_onecell(). Perhaps there is an issue with
> the latter? If you don't have a clue, I plan to do some more
> investigation later...
Geert, thanks for reporting!
>
> BTW, the "pending due to"-messages look weird to me.
> On R-Car M2-W (r8a7791.dtsi) I see e.g.:
>
> genpd_provider ca15-cpu0: sync_state() pending due to e6020000.watchdog
> renesas-cpg-mssr e6150000.clock-controller: sync_state() pending
> due to e6020000.watchdog
>
> ca15-cpu0 is the PM Domain holding the first CPU core, while
> the watchdog resides in the always-on Clock Domain, and uses the
> clock-controller for PM_CLK handling.
I will have a closer look as soon as I can to see if I can find some
potential problems.
Kind regards
Uffe
^ permalink raw reply [flat|nested] 59+ messages in thread
* Re: [PATCH v3 21/24] pmdomain: core: Leave powered-on genpds on until late_initcall_sync
2025-07-15 11:34 ` Ulf Hansson
@ 2025-07-31 12:53 ` Jon Hunter
0 siblings, 0 replies; 59+ messages in thread
From: Jon Hunter @ 2025-07-31 12:53 UTC (permalink / raw)
To: Ulf Hansson
Cc: Marek Szyprowski, Saravana Kannan, Stephen Boyd, linux-pm,
Rafael J . Wysocki, Greg Kroah-Hartman, Michael Grzeschik,
Bjorn Andersson, Abel Vesa, Peng Fan, Tomi Valkeinen,
Johan Hovold, Maulik Shah, Michal Simek, Konrad Dybcio,
Thierry Reding, Hiago De Franco, Geert Uytterhoeven,
linux-arm-kernel, linux-kernel, linux-tegra@vger.kernel.org
On 15/07/2025 12:34, Ulf Hansson wrote:
...
>>> Have you found any resolution for this? I have also noticed a boot
>>> regression on one of our Tegra210 boards and bisect is pointing to this
>>> commit. I don't see any particular crash, but a hang on boot.
>>
>> Thanks for reporting!
>>
>> For Exynos we opt-out from the behaviour by enforcing a sync_state of
>> all PM domains upfront [1], which means before any devices get
>> attached.
>>
>> Even if that defeats the purpose of the $subject series, this was one
>> way forward that solved the problem. When the boot-ordering problem
>> (that's how I understood the issue) for Exynos gets resolved, we
>> should be able to drop the hack, at least that's the idea.
>>
>>>
>>> If there is any debug we can enable to see which pmdomain is the problem
>>> let me know.
>>
>> There aren't many debug prints in genpd that I think makes much sense
>> to enable, but you can always give it a try. Since you are hanging,
>> obviously you can't look at the genpd debugfs data...
>>
>> Note that, the interesting PM domains are those that are powered-on
>> when calling pm_genpd_init(). As a start, I would add some debug
>> prints in () to see which PM domains that are relevant to track.
>
> /s/()/tegra_powergate_add()
I have been able to track this down to a problem in the Tegra PMC driver
where we are registering the power-domains and I have sent a fix [0].
Looks like we have been getting lucky up until now.
Cheers!
Jon
[0]
https://lore.kernel.org/linux-tegra/20250731121832.213671-1-jonathanh@nvidia.com/T/#u
--
nvpublic
^ permalink raw reply [flat|nested] 59+ messages in thread
* Re: [PATCH v3 20/24] pmdomain: core: Default to use of_genpd_sync_state() for genpd providers
2025-07-01 11:47 ` [PATCH v3 20/24] pmdomain: core: Default to use of_genpd_sync_state() for genpd providers Ulf Hansson
@ 2025-07-31 15:07 ` Jon Hunter
2025-08-11 12:11 ` Ulf Hansson
0 siblings, 1 reply; 59+ messages in thread
From: Jon Hunter @ 2025-07-31 15:07 UTC (permalink / raw)
To: Ulf Hansson, Saravana Kannan, Stephen Boyd, linux-pm
Cc: Rafael J . Wysocki, Greg Kroah-Hartman, Michael Grzeschik,
Bjorn Andersson, Abel Vesa, Peng Fan, Tomi Valkeinen,
Johan Hovold, Maulik Shah, Michal Simek, Konrad Dybcio,
Thierry Reding, Hiago De Franco, Geert Uytterhoeven,
linux-arm-kernel, linux-kernel, linux-tegra@vger.kernel.org
Hi Ulf,
On 01/07/2025 12:47, Ulf Hansson wrote:
> Unless the typical platform driver that act as genpd provider, has its own
> ->sync_state() callback implemented let's default to use
> of_genpd_sync_state().
>
> More precisely, while adding a genpd OF provider let's assign the
> ->sync_state() callback, in case the fwnode has a device and its driver
> doesn't have the ->sync_state() set already. In this way the typical
> platform driver doesn't need to assign ->sync_state(), unless it has some
> additional things to manage beyond genpds.
>
> Suggested-by: Saravana Kannan <saravanak@google.com>
> Tested-by: Hiago De Franco <hiago.franco@toradex.com> # Colibri iMX8X
> Tested-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com> # TI AM62A,Xilinx ZynqMP ZCU106
> Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
> ---
> drivers/pmdomain/core.c | 9 +++++++++
> 1 file changed, 9 insertions(+)
>
> diff --git a/drivers/pmdomain/core.c b/drivers/pmdomain/core.c
> index ca47f91b9e91..5cef6de60c72 100644
> --- a/drivers/pmdomain/core.c
> +++ b/drivers/pmdomain/core.c
> @@ -2600,6 +2600,11 @@ static bool genpd_present(const struct generic_pm_domain *genpd)
> return ret;
> }
>
> +static void genpd_sync_state(struct device *dev)
> +{
> + return of_genpd_sync_state(dev->of_node);
> +}
> +
> /**
> * of_genpd_add_provider_simple() - Register a simple PM domain provider
> * @np: Device node pointer associated with the PM domain provider.
> @@ -2628,6 +2633,8 @@ int of_genpd_add_provider_simple(struct device_node *np,
> if (!dev && !genpd_is_no_sync_state(genpd)) {
> genpd->sync_state = GENPD_SYNC_STATE_SIMPLE;
> device_set_node(&genpd->dev, fwnode);
> + } else {
> + dev_set_drv_sync_state(dev, genpd_sync_state);
> }
>
> put_device(dev);
> @@ -2700,6 +2707,8 @@ int of_genpd_add_provider_onecell(struct device_node *np,
> dev = get_dev_from_fwnode(fwnode);
> if (!dev)
> sync_state = true;
> + else
> + dev_set_drv_sync_state(dev, genpd_sync_state);
>
> put_device(dev);
>
Following this change I am seeing the following warning on our Tegra194
devices ...
WARNING KERN tegra-bpmp bpmp: sync_state() pending due to 17000000.gpu
WARNING KERN tegra-bpmp bpmp: sync_state() pending due to 3960000.cec
WARNING KERN tegra-bpmp bpmp: sync_state() pending due to 15380000.nvjpg
WARNING KERN tegra-bpmp bpmp: sync_state() pending due to 154c0000.nvenc
WARNING KERN tegra-bpmp bpmp: sync_state() pending due to 15a80000.nvenc
Per your change [0], the 'GENPD_FLAG_NO_SYNC_STATE' is set for Tegra
and so should Tegra be using of_genpd_sync_state() by default?
Thanks
Jon
[0] https://lore.kernel.org/all/20250701114733.636510-10-ulf.hansson@linaro.org/
--
nvpublic
^ permalink raw reply [flat|nested] 59+ messages in thread
* Re: [PATCH v3 00/24] pmdomain: Add generic ->sync_state() support to genpd
2025-07-30 10:29 ` Ulf Hansson
@ 2025-08-07 9:38 ` Geert Uytterhoeven
2025-08-12 10:00 ` Ulf Hansson
0 siblings, 1 reply; 59+ messages in thread
From: Geert Uytterhoeven @ 2025-08-07 9:38 UTC (permalink / raw)
To: Ulf Hansson
Cc: Saravana Kannan, Stephen Boyd, linux-pm, Rafael J . Wysocki,
Greg Kroah-Hartman, Michael Grzeschik, Bjorn Andersson, Abel Vesa,
Peng Fan, Tomi Valkeinen, Johan Hovold, Maulik Shah, Michal Simek,
Konrad Dybcio, Thierry Reding, Jonathan Hunter, Hiago De Franco,
linux-arm-kernel, linux-kernel, Linux-Renesas
Hi Ulf,
On Wed, 30 Jul 2025 at 12:29, Ulf Hansson <ulf.hansson@linaro.org> wrote:
> On Wed, 30 Jul 2025 at 11:56, Geert Uytterhoeven <geert@linux-m68k.org> wrote:
> > On Wed, 9 Jul 2025 at 13:31, Ulf Hansson <ulf.hansson@linaro.org> wrote:
> > > On Tue, 1 Jul 2025 at 13:47, Ulf Hansson <ulf.hansson@linaro.org> wrote:
> > > > Changes in v3:
> > > > - Added a couple of patches to adress problems on some Renesas
> > > > platforms. Thanks Geert and Tomi for helping out!
> > > > - Adressed a few comments from Saravanna and Konrad.
> > > > - Added some tested-by tags.
> > >
> > > I decided it was time to give this a try, so I have queued this up for
> > > v6.17 via the next branch at my pmdomain tree.
> > >
> > > If you encounter any issues, please let me know so I can help to fix them.
> >
> > Thanks for your series! Due to holidays, I only managed to test
> > this very recently.
> >
> > Unfortunately I have an issue with unused PM Domains no longer being
> > disabled on R-Car:
> > - On R-Car Gen1/2/3, using rcar-sysc.c, unused PM Domains are never
> > disabled.
> > - On R-Car Gen4, using rcar-gen4-sysc.c, unused PM Domains are
> > sometimes not disabled.
> > At first, I noticed the IOMMU driver was not enabled in my config,
> > and enabling it did fix the issue. However, after that I still
> > encountered the issue in a different config that does have the
> > IOMMU driver enabled...
> >
> > FTR, unused PM Domains are still disabled correctly on R/SH-Mobile
> > (using rmobile-sysc.c) and on BeagleBone Black. Note that these use
> > of_genpd_add_provider_simple(), while all R-Car drivers use
> > of_genpd_add_provider_onecell(). Perhaps there is an issue with
> > the latter? If you don't have a clue, I plan to do some more
> > investigation later...
of_genpd_add_provider_onecell() has:
if (!dev)
sync_state = true;
else
dev_set_drv_sync_state(dev, genpd_sync_state);
for (i = 0; i < data->num_domains; i++) {
...
if (sync_state && !genpd_is_no_sync_state(genpd)) {
genpd->sync_state = GENPD_SYNC_STATE_ONECELL;
device_set_node(&genpd->dev, fwnode);
sync_state = false;
^^^^^^^^^^^^^^^^^^^
}
...
}
As the R-Car SYSC drivers are not platform drivers, dev is NULL, and
genpd->sync_state is set to GENPD_SYNC_STATE_ONECELL for the first PM
Domain only. All other domains have the default value of sync_state
(0 = GENPD_SYNC_STATE_OFF). Hence when genpd_provider_sync_state()
is called later, it ignores all but the first domain.
Apparently this is intentional, as of_genpd_sync_state() tries to
power off all domains handled by the same controller anyway (see below)?
> > BTW, the "pending due to"-messages look weird to me.
> > On R-Car M2-W (r8a7791.dtsi) I see e.g.:
> >
> > genpd_provider ca15-cpu0: sync_state() pending due to e6020000.watchdog
> > renesas-cpg-mssr e6150000.clock-controller: sync_state() pending
> > due to e6020000.watchdog
> >
> > ca15-cpu0 is the PM Domain holding the first CPU core, while
> > the watchdog resides in the always-on Clock Domain, and uses the
> > clock-controller for PM_CLK handling.
Unfortunately the first PM Domain is "ca15-cpu0", which is blocked on
these bogus pending states, and no PM Domain is powered off.
If I remove the "sync_state = false" above, genpd_provider_sync_state()
considers all domains, and does power down all unused domains (even
multiple times, as expected).
Upon closer look, all "pending due to" messages I see claim that the
first (index 0) PM Domain is pending on some devices, while all of
these devices are part of a different domain (usually the always-on
domain, which is always the last (32 or 64) on R-Car).
So I think there are two issues:
1. Devices are not attributed to the correct PM Domain using
fw_devlink sync_state,
2. One PM Domain of a multi-domain controller being blocked should
not block all other domains handled by the same controller.
Does that make sense?
Thanks!
Gr{oetje,eeting}s,
Geert
--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org
In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds
^ permalink raw reply [flat|nested] 59+ messages in thread
* Re: [PATCH v3 11/24] cpuidle: riscv-sbi: Opt-out from genpd's common ->sync_state() support
2025-07-01 11:47 ` [PATCH v3 11/24] cpuidle: riscv-sbi: " Ulf Hansson
2025-07-04 10:14 ` Rahul Pathak
2025-07-07 9:36 ` Anup Patel
@ 2025-08-10 21:12 ` patchwork-bot+linux-riscv
2 siblings, 0 replies; 59+ messages in thread
From: patchwork-bot+linux-riscv @ 2025-08-10 21:12 UTC (permalink / raw)
To: Ulf Hansson
Cc: linux-riscv, saravanak, sboyd, linux-pm, rafael, gregkh,
m.grzeschik, andersson, abel.vesa, peng.fan, tomi.valkeinen,
johan, maulik.shah, michal.simek, konradybcio, thierry.reding,
jonathanh, hiago.franco, geert, linux-arm-kernel, linux-kernel,
anup
Hello:
This series was applied to riscv/linux.git (fixes)
by Ulf Hansson <ulf.hansson@linaro.org>:
On Tue, 1 Jul 2025 13:47:13 +0200 you wrote:
> The riscv-sbi-domain implements its own specific ->sync_state() callback.
> Let's set the GENPD_FLAG_NO_SYNC_STATE to inform genpd about it.
>
> Moreover, let's call of_genpd_sync_state() to make sure genpd tries to
> power off unused PM domains.
>
> Cc: Anup Patel <anup@brainfault.org>
> Cc: linux-riscv@lists.infradead.org
> Tested-by: Hiago De Franco <hiago.franco@toradex.com> # Colibri iMX8X
> Tested-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com> # TI AM62A,Xilinx ZynqMP ZCU106
> Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
>
> [...]
Here is the summary with links:
- [v3,11/24] cpuidle: riscv-sbi: Opt-out from genpd's common ->sync_state() support
https://git.kernel.org/riscv/c/ee766b017586
- [v3,24/24] cpuidle: riscv-sbi: Drop redundant sync_state support
https://git.kernel.org/riscv/c/eb34a0b5fee7
You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
^ permalink raw reply [flat|nested] 59+ messages in thread
* Re: [PATCH v3 20/24] pmdomain: core: Default to use of_genpd_sync_state() for genpd providers
2025-07-31 15:07 ` Jon Hunter
@ 2025-08-11 12:11 ` Ulf Hansson
2025-09-03 12:33 ` Jon Hunter
0 siblings, 1 reply; 59+ messages in thread
From: Ulf Hansson @ 2025-08-11 12:11 UTC (permalink / raw)
To: Jon Hunter
Cc: Saravana Kannan, Stephen Boyd, linux-pm, Rafael J . Wysocki,
Greg Kroah-Hartman, Michael Grzeschik, Bjorn Andersson, Abel Vesa,
Peng Fan, Tomi Valkeinen, Johan Hovold, Maulik Shah, Michal Simek,
Konrad Dybcio, Thierry Reding, Hiago De Franco,
Geert Uytterhoeven, linux-arm-kernel, linux-kernel,
linux-tegra@vger.kernel.org
On Thu, 31 Jul 2025 at 17:07, Jon Hunter <jonathanh@nvidia.com> wrote:
>
> Hi Ulf,
>
> On 01/07/2025 12:47, Ulf Hansson wrote:
> > Unless the typical platform driver that act as genpd provider, has its own
> > ->sync_state() callback implemented let's default to use
> > of_genpd_sync_state().
> >
> > More precisely, while adding a genpd OF provider let's assign the
> > ->sync_state() callback, in case the fwnode has a device and its driver
> > doesn't have the ->sync_state() set already. In this way the typical
> > platform driver doesn't need to assign ->sync_state(), unless it has some
> > additional things to manage beyond genpds.
> >
> > Suggested-by: Saravana Kannan <saravanak@google.com>
> > Tested-by: Hiago De Franco <hiago.franco@toradex.com> # Colibri iMX8X
> > Tested-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com> # TI AM62A,Xilinx ZynqMP ZCU106
> > Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
> > ---
> > drivers/pmdomain/core.c | 9 +++++++++
> > 1 file changed, 9 insertions(+)
> >
> > diff --git a/drivers/pmdomain/core.c b/drivers/pmdomain/core.c
> > index ca47f91b9e91..5cef6de60c72 100644
> > --- a/drivers/pmdomain/core.c
> > +++ b/drivers/pmdomain/core.c
> > @@ -2600,6 +2600,11 @@ static bool genpd_present(const struct generic_pm_domain *genpd)
> > return ret;
> > }
> >
> > +static void genpd_sync_state(struct device *dev)
> > +{
> > + return of_genpd_sync_state(dev->of_node);
> > +}
> > +
> > /**
> > * of_genpd_add_provider_simple() - Register a simple PM domain provider
> > * @np: Device node pointer associated with the PM domain provider.
> > @@ -2628,6 +2633,8 @@ int of_genpd_add_provider_simple(struct device_node *np,
> > if (!dev && !genpd_is_no_sync_state(genpd)) {
> > genpd->sync_state = GENPD_SYNC_STATE_SIMPLE;
> > device_set_node(&genpd->dev, fwnode);
> > + } else {
> > + dev_set_drv_sync_state(dev, genpd_sync_state);
> > }
> >
> > put_device(dev);
> > @@ -2700,6 +2707,8 @@ int of_genpd_add_provider_onecell(struct device_node *np,
> > dev = get_dev_from_fwnode(fwnode);
> > if (!dev)
> > sync_state = true;
> > + else
> > + dev_set_drv_sync_state(dev, genpd_sync_state);
> >
> > put_device(dev);
> >
>
> Following this change I am seeing the following warning on our Tegra194
> devices ...
>
> WARNING KERN tegra-bpmp bpmp: sync_state() pending due to 17000000.gpu
> WARNING KERN tegra-bpmp bpmp: sync_state() pending due to 3960000.cec
> WARNING KERN tegra-bpmp bpmp: sync_state() pending due to 15380000.nvjpg
> WARNING KERN tegra-bpmp bpmp: sync_state() pending due to 154c0000.nvenc
> WARNING KERN tegra-bpmp bpmp: sync_state() pending due to 15a80000.nvenc
>
> Per your change [0], the 'GENPD_FLAG_NO_SYNC_STATE' is set for Tegra
> and so should Tegra be using of_genpd_sync_state() by default?
This is a different power-domain provider (bpmp) in
drivers/firmware/tegra/bpmp.c and
drivers/pmdomain/tegra/powergate-bpmp.c.
For the bpmp we don't need GENPD_FLAG_NO_SYNC_STATE, as the
power-domain provider is described along with the
"nvidia,tegra186-bpmp" compatible string. In the other case
(drivers/soc/tegra/pmc.c) the "core-domain" and "powergates" are
described through child-nodes, while ->sync_state() is managed by the
parent-device-node.
In the bpmp case there is no ->sync_state() callback assigned, which
means genpd decides to assign a default one.
The reason for the warnings above is because we are still waiting for
those devices to be probed, hence the ->sync_state() callback is still
waiting to be invoked. Enforcing ->sync_state() callback to be invoked
can be done via user-space if that is needed.
Did that make sense?
>
> Thanks
> Jon
>
> [0] https://lore.kernel.org/all/20250701114733.636510-10-ulf.hansson@linaro.org/
> --
> nvpublic
>
Kind regards
Uffe
^ permalink raw reply [flat|nested] 59+ messages in thread
* Re: [PATCH v3 00/24] pmdomain: Add generic ->sync_state() support to genpd
2025-08-07 9:38 ` Geert Uytterhoeven
@ 2025-08-12 10:00 ` Ulf Hansson
2025-08-13 11:58 ` Geert Uytterhoeven
0 siblings, 1 reply; 59+ messages in thread
From: Ulf Hansson @ 2025-08-12 10:00 UTC (permalink / raw)
To: Geert Uytterhoeven
Cc: Saravana Kannan, Stephen Boyd, linux-pm, Rafael J . Wysocki,
Greg Kroah-Hartman, Michael Grzeschik, Bjorn Andersson, Abel Vesa,
Peng Fan, Tomi Valkeinen, Johan Hovold, Maulik Shah, Michal Simek,
Konrad Dybcio, Thierry Reding, Jonathan Hunter, Hiago De Franco,
linux-arm-kernel, linux-kernel, Linux-Renesas
On Thu, 7 Aug 2025 at 11:38, Geert Uytterhoeven <geert@linux-m68k.org> wrote:
>
> Hi Ulf,
>
> On Wed, 30 Jul 2025 at 12:29, Ulf Hansson <ulf.hansson@linaro.org> wrote:
> > On Wed, 30 Jul 2025 at 11:56, Geert Uytterhoeven <geert@linux-m68k.org> wrote:
> > > On Wed, 9 Jul 2025 at 13:31, Ulf Hansson <ulf.hansson@linaro.org> wrote:
> > > > On Tue, 1 Jul 2025 at 13:47, Ulf Hansson <ulf.hansson@linaro.org> wrote:
> > > > > Changes in v3:
> > > > > - Added a couple of patches to adress problems on some Renesas
> > > > > platforms. Thanks Geert and Tomi for helping out!
> > > > > - Adressed a few comments from Saravanna and Konrad.
> > > > > - Added some tested-by tags.
> > > >
> > > > I decided it was time to give this a try, so I have queued this up for
> > > > v6.17 via the next branch at my pmdomain tree.
> > > >
> > > > If you encounter any issues, please let me know so I can help to fix them.
> > >
> > > Thanks for your series! Due to holidays, I only managed to test
> > > this very recently.
> > >
> > > Unfortunately I have an issue with unused PM Domains no longer being
> > > disabled on R-Car:
> > > - On R-Car Gen1/2/3, using rcar-sysc.c, unused PM Domains are never
> > > disabled.
> > > - On R-Car Gen4, using rcar-gen4-sysc.c, unused PM Domains are
> > > sometimes not disabled.
> > > At first, I noticed the IOMMU driver was not enabled in my config,
> > > and enabling it did fix the issue. However, after that I still
> > > encountered the issue in a different config that does have the
> > > IOMMU driver enabled...
> > >
> > > FTR, unused PM Domains are still disabled correctly on R/SH-Mobile
> > > (using rmobile-sysc.c) and on BeagleBone Black. Note that these use
> > > of_genpd_add_provider_simple(), while all R-Car drivers use
> > > of_genpd_add_provider_onecell(). Perhaps there is an issue with
> > > the latter? If you don't have a clue, I plan to do some more
> > > investigation later...
>
> of_genpd_add_provider_onecell() has:
>
> if (!dev)
> sync_state = true;
> else
> dev_set_drv_sync_state(dev, genpd_sync_state);
>
> for (i = 0; i < data->num_domains; i++) {
> ...
> if (sync_state && !genpd_is_no_sync_state(genpd)) {
> genpd->sync_state = GENPD_SYNC_STATE_ONECELL;
> device_set_node(&genpd->dev, fwnode);
> sync_state = false;
> ^^^^^^^^^^^^^^^^^^^
> }
> ...
> }
>
> As the R-Car SYSC drivers are not platform drivers, dev is NULL, and
> genpd->sync_state is set to GENPD_SYNC_STATE_ONECELL for the first PM
> Domain only. All other domains have the default value of sync_state
> (0 = GENPD_SYNC_STATE_OFF). Hence when genpd_provider_sync_state()
> is called later, it ignores all but the first domain.
> Apparently this is intentional, as of_genpd_sync_state() tries to
> power off all domains handled by the same controller anyway (see below)?
Right, this is intentional and mainly because of how fw_devlink works.
fw_devlink is limited to use only the first device - if multiple
devices share the same fwnode. In principle, we could have picked any
of the devices in the array of genpds here - and reached the same
result.
>
> > > BTW, the "pending due to"-messages look weird to me.
> > > On R-Car M2-W (r8a7791.dtsi) I see e.g.:
> > >
> > > genpd_provider ca15-cpu0: sync_state() pending due to e6020000.watchdog
> > > renesas-cpg-mssr e6150000.clock-controller: sync_state() pending
> > > due to e6020000.watchdog
> > >
> > > ca15-cpu0 is the PM Domain holding the first CPU core, while
> > > the watchdog resides in the always-on Clock Domain, and uses the
> > > clock-controller for PM_CLK handling.
>
> Unfortunately the first PM Domain is "ca15-cpu0", which is blocked on
> these bogus pending states, and no PM Domain is powered off.
I see, thanks for the details. I am looking closer at this.
In any case, this is the main issue, as it prevents the ->sync_state()
callback to be called. Hence the "genpd->stay_on" will also *not* be
cleared for any of the genpd's for the genpd-provider.
>
> If I remove the "sync_state = false" above, genpd_provider_sync_state()
> considers all domains, and does power down all unused domains (even
> multiple times, as expected).
I think those are getting called because with the change above, there
is no device_link being tracked. As stated above, fw_devlink is
limited to use only one device - if multiple devices share the same
fwnode.
In other words, the ->sync_state() callbacks are called even if the
corresponding consumer devices have not been probed yet.
>
> Upon closer look, all "pending due to" messages I see claim that the
> first (index 0) PM Domain is pending on some devices, while all of
> these devices are part of a different domain (usually the always-on
> domain, which is always the last (32 or 64) on R-Car).
>
> So I think there are two issues:
> 1. Devices are not attributed to the correct PM Domain using
> fw_devlink sync_state,
> 2. One PM Domain of a multi-domain controller being blocked should
> not block all other domains handled by the same controller.
Right, that's a current limitation with fw_devlink. To cope with this,
it's possible to enforce the ->sync_state() callback to be invoked
from user-space (timeout or explicitly) for a device.
Another option would be to allow an opt-out behavior for some genpd's
that are powered-on at initialization. Something along the lines of
the below.
From: Ulf Hansson <ulf.hansson@linaro.org>
Date: Tue, 29 Jul 2025 14:27:22 +0200
Subject: [PATCH] pmdomain: core: Allow powered-on PM domains to be powered-off
during boot
Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
---
drivers/pmdomain/core.c | 3 ++-
include/linux/pm_domain.h | 7 +++++++
2 files changed, 9 insertions(+), 1 deletion(-)
diff --git a/drivers/pmdomain/core.c b/drivers/pmdomain/core.c
index 0006ab3d0789..ef0760824c92 100644
--- a/drivers/pmdomain/core.c
+++ b/drivers/pmdomain/core.c
@@ -187,6 +187,7 @@ static const struct genpd_lock_ops genpd_raw_spin_ops = {
#define genpd_is_opp_table_fw(genpd) (genpd->flags & GENPD_FLAG_OPP_TABLE_FW)
#define genpd_is_dev_name_fw(genpd) (genpd->flags & GENPD_FLAG_DEV_NAME_FW)
#define genpd_is_no_sync_state(genpd) (genpd->flags &
GENPD_FLAG_NO_SYNC_STATE)
+#define genpd_is_no_stay_on(genpd) (genpd->flags & GENPD_FLAG_NO_STAY_ON)
static inline bool irq_safe_dev_in_sleep_domain(struct device *dev,
const struct generic_pm_domain *genpd)
@@ -2392,7 +2393,7 @@ int pm_genpd_init(struct generic_pm_domain *genpd,
INIT_WORK(&genpd->power_off_work, genpd_power_off_work_fn);
atomic_set(&genpd->sd_count, 0);
genpd->status = is_off ? GENPD_STATE_OFF : GENPD_STATE_ON;
- genpd->stay_on = !is_off;
+ genpd->stay_on = !genpd_is_no_stay_on(genpd) && !is_off;
genpd->sync_state = GENPD_SYNC_STATE_OFF;
genpd->device_count = 0;
genpd->provider = NULL;
diff --git a/include/linux/pm_domain.h b/include/linux/pm_domain.h
index b9d3c7d5c4f8..61b81574efc4 100644
--- a/include/linux/pm_domain.h
+++ b/include/linux/pm_domain.h
@@ -109,6 +109,12 @@ struct dev_pm_domain_list {
* genpd provider specific way, likely through a
* parent device node. This flag makes genpd to
* skip its internal support for this.
+ *
+ * GENPD_FLAG_NO_STAY_ON: A powered-on PM domain at initialization is
+ * prevented by genpd from being powered-off until
+ * we receive a ->sync_state() or runs the
+ * late_initcall_sync. Use this flag to allow
+ * power-off without waiting for these conditions.
*/
#define GENPD_FLAG_PM_CLK (1U << 0)
#define GENPD_FLAG_IRQ_SAFE (1U << 1)
@@ -120,6 +126,7 @@ struct dev_pm_domain_list {
#define GENPD_FLAG_OPP_TABLE_FW (1U << 7)
#define GENPD_FLAG_DEV_NAME_FW (1U << 8)
#define GENPD_FLAG_NO_SYNC_STATE (1U << 9)
+#define GENPD_FLAG_NO_STAY_ON (1U << 10)
enum gpd_status {
GENPD_STATE_ON = 0, /* PM domain is on */
--
2.43.0
Kind regards
Uffe
^ permalink raw reply related [flat|nested] 59+ messages in thread
* Re: [PATCH v3 00/24] pmdomain: Add generic ->sync_state() support to genpd
2025-08-12 10:00 ` Ulf Hansson
@ 2025-08-13 11:58 ` Geert Uytterhoeven
2025-08-14 15:49 ` Ulf Hansson
0 siblings, 1 reply; 59+ messages in thread
From: Geert Uytterhoeven @ 2025-08-13 11:58 UTC (permalink / raw)
To: Ulf Hansson
Cc: Saravana Kannan, Stephen Boyd, linux-pm, Rafael J . Wysocki,
Greg Kroah-Hartman, Michael Grzeschik, Bjorn Andersson, Abel Vesa,
Peng Fan, Tomi Valkeinen, Johan Hovold, Maulik Shah, Michal Simek,
Konrad Dybcio, Thierry Reding, Jonathan Hunter, Hiago De Franco,
linux-arm-kernel, linux-kernel, Linux-Renesas
Hi Ulf,
On Tue, 12 Aug 2025 at 12:01, Ulf Hansson <ulf.hansson@linaro.org> wrote:
> On Thu, 7 Aug 2025 at 11:38, Geert Uytterhoeven <geert@linux-m68k.org> wrote:
> > On Wed, 30 Jul 2025 at 12:29, Ulf Hansson <ulf.hansson@linaro.org> wrote:
> > > On Wed, 30 Jul 2025 at 11:56, Geert Uytterhoeven <geert@linux-m68k.org> wrote:
> > > > On Wed, 9 Jul 2025 at 13:31, Ulf Hansson <ulf.hansson@linaro.org> wrote:
> > > > > On Tue, 1 Jul 2025 at 13:47, Ulf Hansson <ulf.hansson@linaro.org> wrote:
> > > > > > Changes in v3:
> > > > > > - Added a couple of patches to adress problems on some Renesas
> > > > > > platforms. Thanks Geert and Tomi for helping out!
> > > > > > - Adressed a few comments from Saravanna and Konrad.
> > > > > > - Added some tested-by tags.
> > > > >
> > > > > I decided it was time to give this a try, so I have queued this up for
> > > > > v6.17 via the next branch at my pmdomain tree.
> > > > >
> > > > > If you encounter any issues, please let me know so I can help to fix them.
> > > >
> > > > Thanks for your series! Due to holidays, I only managed to test
> > > > this very recently.
> > > >
> > > > Unfortunately I have an issue with unused PM Domains no longer being
> > > > disabled on R-Car:
> > > > - On R-Car Gen1/2/3, using rcar-sysc.c, unused PM Domains are never
> > > > disabled.
> > > > - On R-Car Gen4, using rcar-gen4-sysc.c, unused PM Domains are
> > > > sometimes not disabled.
> > > > At first, I noticed the IOMMU driver was not enabled in my config,
> > > > and enabling it did fix the issue. However, after that I still
> > > > encountered the issue in a different config that does have the
> > > > IOMMU driver enabled...
> > > >
> > > > FTR, unused PM Domains are still disabled correctly on R/SH-Mobile
> > > > (using rmobile-sysc.c) and on BeagleBone Black. Note that these use
> > > > of_genpd_add_provider_simple(), while all R-Car drivers use
> > > > of_genpd_add_provider_onecell(). Perhaps there is an issue with
> > > > the latter? If you don't have a clue, I plan to do some more
> > > > investigation later...
> >
> > of_genpd_add_provider_onecell() has:
> >
> > if (!dev)
> > sync_state = true;
> > else
> > dev_set_drv_sync_state(dev, genpd_sync_state);
> >
> > for (i = 0; i < data->num_domains; i++) {
> > ...
> > if (sync_state && !genpd_is_no_sync_state(genpd)) {
> > genpd->sync_state = GENPD_SYNC_STATE_ONECELL;
> > device_set_node(&genpd->dev, fwnode);
> > sync_state = false;
> > ^^^^^^^^^^^^^^^^^^^
> > }
> > ...
> > }
> >
> > As the R-Car SYSC drivers are not platform drivers, dev is NULL, and
> > genpd->sync_state is set to GENPD_SYNC_STATE_ONECELL for the first PM
> > Domain only. All other domains have the default value of sync_state
> > (0 = GENPD_SYNC_STATE_OFF). Hence when genpd_provider_sync_state()
> > is called later, it ignores all but the first domain.
> > Apparently this is intentional, as of_genpd_sync_state() tries to
> > power off all domains handled by the same controller anyway (see below)?
>
> Right, this is intentional and mainly because of how fw_devlink works.
>
> fw_devlink is limited to use only the first device - if multiple
> devices share the same fwnode. In principle, we could have picked any
> of the devices in the array of genpds here - and reached the same
> result.
OK, just like I already assumed...
> > > > BTW, the "pending due to"-messages look weird to me.
> > > > On R-Car M2-W (r8a7791.dtsi) I see e.g.:
> > > >
> > > > genpd_provider ca15-cpu0: sync_state() pending due to e6020000.watchdog
> > > > renesas-cpg-mssr e6150000.clock-controller: sync_state() pending
> > > > due to e6020000.watchdog
> > > >
> > > > ca15-cpu0 is the PM Domain holding the first CPU core, while
> > > > the watchdog resides in the always-on Clock Domain, and uses the
> > > > clock-controller for PM_CLK handling.
> >
> > Unfortunately the first PM Domain is "ca15-cpu0", which is blocked on
> > these bogus pending states, and no PM Domain is powered off.
>
> I see, thanks for the details. I am looking closer at this.
>
> In any case, this is the main issue, as it prevents the ->sync_state()
> callback to be called. Hence the "genpd->stay_on" will also *not* be
> cleared for any of the genpd's for the genpd-provider.
I was under the impression there is a time-out, after which the
.sync_state() callback would be called anyway, just like for probe
deferral due to missing optional providers like DMACs and IOMMUs.
Apparently that is not the case?
> > If I remove the "sync_state = false" above, genpd_provider_sync_state()
> > considers all domains, and does power down all unused domains (even
> > multiple times, as expected).
>
> I think those are getting called because with the change above, there
> is no device_link being tracked. As stated above, fw_devlink is
> limited to use only one device - if multiple devices share the same
> fwnode.
Indeed.
> In other words, the ->sync_state() callbacks are called even if the
> corresponding consumer devices have not been probed yet.
Hence shouldn't there be a timeout, as the kernel may not even have
a driver for one or more consumer devices?
> > Upon closer look, all "pending due to" messages I see claim that the
> > first (index 0) PM Domain is pending on some devices, while all of
> > these devices are part of a different domain (usually the always-on
> > domain, which is always the last (32 or 64) on R-Car).
> >
> > So I think there are two issues:
> > 1. Devices are not attributed to the correct PM Domain using
> > fw_devlink sync_state,
> > 2. One PM Domain of a multi-domain controller being blocked should
> > not block all other domains handled by the same controller.
>
> Right, that's a current limitation with fw_devlink. To cope with this,
> it's possible to enforce the ->sync_state() callback to be invoked
> from user-space (timeout or explicitly) for a device.
>
> Another option would be to allow an opt-out behavior for some genpd's
> that are powered-on at initialization. Something along the lines of
> the below.
>
> From: Ulf Hansson <ulf.hansson@linaro.org>
> Date: Tue, 29 Jul 2025 14:27:22 +0200
> Subject: [PATCH] pmdomain: core: Allow powered-on PM domains to be powered-off
> during boot
[...]
I gave this a try (i.e. "| GENPD_FLAG_NO_STAY_ON" in rcar-sysc.c), but
this doesn't make any difference. I assume this would only work when
actively calling genpd_power_off() (i.e. not from of_genpd_sync_state()
or genpd_provider_sync_state())?
Thanks!
Gr{oetje,eeting}s,
Geert
--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org
In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds
^ permalink raw reply [flat|nested] 59+ messages in thread
* Re: [PATCH v3 00/24] pmdomain: Add generic ->sync_state() support to genpd
2025-07-09 11:30 ` [PATCH v3 00/24] pmdomain: Add generic ->sync_state() support to genpd Ulf Hansson
2025-07-15 8:50 ` Danilo Krummrich
2025-07-30 9:56 ` Geert Uytterhoeven
@ 2025-08-13 12:04 ` Geert Uytterhoeven
2 siblings, 0 replies; 59+ messages in thread
From: Geert Uytterhoeven @ 2025-08-13 12:04 UTC (permalink / raw)
To: Ulf Hansson
Cc: Saravana Kannan, Stephen Boyd, linux-pm, Rafael J . Wysocki,
Greg Kroah-Hartman, Michael Grzeschik, Bjorn Andersson, Abel Vesa,
Peng Fan, Tomi Valkeinen, Johan Hovold, Maulik Shah, Michal Simek,
Konrad Dybcio, Thierry Reding, Jonathan Hunter, Hiago De Franco,
linux-arm-kernel, linux-kernel, Lubomir Rintel
Hi Ulf,
On Wed, 9 Jul 2025 at 13:31, Ulf Hansson <ulf.hansson@linaro.org> wrote:
> On Tue, 1 Jul 2025 at 13:47, Ulf Hansson <ulf.hansson@linaro.org> wrote:
> > Changes in v3:
> > - Added a couple of patches to adress problems on some Renesas
> > platforms. Thanks Geert and Tomi for helping out!
> > - Adressed a few comments from Saravanna and Konrad.
> > - Added some tested-by tags.
>
> I decided it was time to give this a try, so I have queued this up for
> v6.17 via the next branch at my pmdomain tree.
>
> If you encounter any issues, please let me know so I can help to fix them.
FTR, I discovered two more issues with clock drivers registering a
genpd OF provider from CLK_OF_DECLARE(), which is now too early:
1. drivers/clk/mmp/clk-of-mmp2.c,
2. drivers/clk/renesas/clk-mstp.c.
I have submitted a fix for the second driver: "[PATCH] clk: renesas:
mstp: Add genpd OF provider at postcore_initcall()"
https://lore.kernel.org/all/81ef5f8d5d31374b7852b05453c52d2f735062a2.1755073087.git.geert+renesas@glider.be
I don't have MMP2 hardware, I guess it needs a similar fix.
Gr{oetje,eeting}s,
Geert
--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org
In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds
^ permalink raw reply [flat|nested] 59+ messages in thread
* Re: [PATCH v3 00/24] pmdomain: Add generic ->sync_state() support to genpd
2025-08-13 11:58 ` Geert Uytterhoeven
@ 2025-08-14 15:49 ` Ulf Hansson
2025-09-04 12:41 ` Geert Uytterhoeven
0 siblings, 1 reply; 59+ messages in thread
From: Ulf Hansson @ 2025-08-14 15:49 UTC (permalink / raw)
To: Geert Uytterhoeven
Cc: Saravana Kannan, Stephen Boyd, linux-pm, Rafael J . Wysocki,
Greg Kroah-Hartman, Michael Grzeschik, Bjorn Andersson, Abel Vesa,
Peng Fan, Tomi Valkeinen, Johan Hovold, Maulik Shah, Michal Simek,
Konrad Dybcio, Thierry Reding, Jonathan Hunter, Hiago De Franco,
linux-arm-kernel, linux-kernel, Linux-Renesas
On Wed, 13 Aug 2025 at 13:58, Geert Uytterhoeven <geert@linux-m68k.org> wrote:
>
> Hi Ulf,
>
> On Tue, 12 Aug 2025 at 12:01, Ulf Hansson <ulf.hansson@linaro.org> wrote:
> > On Thu, 7 Aug 2025 at 11:38, Geert Uytterhoeven <geert@linux-m68k.org> wrote:
> > > On Wed, 30 Jul 2025 at 12:29, Ulf Hansson <ulf.hansson@linaro.org> wrote:
> > > > On Wed, 30 Jul 2025 at 11:56, Geert Uytterhoeven <geert@linux-m68k.org> wrote:
> > > > > On Wed, 9 Jul 2025 at 13:31, Ulf Hansson <ulf.hansson@linaro.org> wrote:
> > > > > > On Tue, 1 Jul 2025 at 13:47, Ulf Hansson <ulf.hansson@linaro.org> wrote:
> > > > > > > Changes in v3:
> > > > > > > - Added a couple of patches to adress problems on some Renesas
> > > > > > > platforms. Thanks Geert and Tomi for helping out!
> > > > > > > - Adressed a few comments from Saravanna and Konrad.
> > > > > > > - Added some tested-by tags.
> > > > > >
> > > > > > I decided it was time to give this a try, so I have queued this up for
> > > > > > v6.17 via the next branch at my pmdomain tree.
> > > > > >
> > > > > > If you encounter any issues, please let me know so I can help to fix them.
> > > > >
> > > > > Thanks for your series! Due to holidays, I only managed to test
> > > > > this very recently.
> > > > >
> > > > > Unfortunately I have an issue with unused PM Domains no longer being
> > > > > disabled on R-Car:
> > > > > - On R-Car Gen1/2/3, using rcar-sysc.c, unused PM Domains are never
> > > > > disabled.
> > > > > - On R-Car Gen4, using rcar-gen4-sysc.c, unused PM Domains are
> > > > > sometimes not disabled.
> > > > > At first, I noticed the IOMMU driver was not enabled in my config,
> > > > > and enabling it did fix the issue. However, after that I still
> > > > > encountered the issue in a different config that does have the
> > > > > IOMMU driver enabled...
> > > > >
> > > > > FTR, unused PM Domains are still disabled correctly on R/SH-Mobile
> > > > > (using rmobile-sysc.c) and on BeagleBone Black. Note that these use
> > > > > of_genpd_add_provider_simple(), while all R-Car drivers use
> > > > > of_genpd_add_provider_onecell(). Perhaps there is an issue with
> > > > > the latter? If you don't have a clue, I plan to do some more
> > > > > investigation later...
> > >
> > > of_genpd_add_provider_onecell() has:
> > >
> > > if (!dev)
> > > sync_state = true;
> > > else
> > > dev_set_drv_sync_state(dev, genpd_sync_state);
> > >
> > > for (i = 0; i < data->num_domains; i++) {
> > > ...
> > > if (sync_state && !genpd_is_no_sync_state(genpd)) {
> > > genpd->sync_state = GENPD_SYNC_STATE_ONECELL;
> > > device_set_node(&genpd->dev, fwnode);
> > > sync_state = false;
> > > ^^^^^^^^^^^^^^^^^^^
> > > }
> > > ...
> > > }
> > >
> > > As the R-Car SYSC drivers are not platform drivers, dev is NULL, and
> > > genpd->sync_state is set to GENPD_SYNC_STATE_ONECELL for the first PM
> > > Domain only. All other domains have the default value of sync_state
> > > (0 = GENPD_SYNC_STATE_OFF). Hence when genpd_provider_sync_state()
> > > is called later, it ignores all but the first domain.
> > > Apparently this is intentional, as of_genpd_sync_state() tries to
> > > power off all domains handled by the same controller anyway (see below)?
> >
> > Right, this is intentional and mainly because of how fw_devlink works.
> >
> > fw_devlink is limited to use only the first device - if multiple
> > devices share the same fwnode. In principle, we could have picked any
> > of the devices in the array of genpds here - and reached the same
> > result.
>
> OK, just like I already assumed...
>
> > > > > BTW, the "pending due to"-messages look weird to me.
> > > > > On R-Car M2-W (r8a7791.dtsi) I see e.g.:
> > > > >
> > > > > genpd_provider ca15-cpu0: sync_state() pending due to e6020000.watchdog
> > > > > renesas-cpg-mssr e6150000.clock-controller: sync_state() pending
> > > > > due to e6020000.watchdog
> > > > >
> > > > > ca15-cpu0 is the PM Domain holding the first CPU core, while
> > > > > the watchdog resides in the always-on Clock Domain, and uses the
> > > > > clock-controller for PM_CLK handling.
> > >
> > > Unfortunately the first PM Domain is "ca15-cpu0", which is blocked on
> > > these bogus pending states, and no PM Domain is powered off.
> >
> > I see, thanks for the details. I am looking closer at this.
> >
> > In any case, this is the main issue, as it prevents the ->sync_state()
> > callback to be called. Hence the "genpd->stay_on" will also *not* be
> > cleared for any of the genpd's for the genpd-provider.
>
> I was under the impression there is a time-out, after which the
> .sync_state() callback would be called anyway, just like for probe
> deferral due to missing optional providers like DMACs and IOMMUs.
> Apparently that is not the case?
The behaviour is configurable, so it depends. The current default
behaviour does *not* enforce the ->sync_state() callbacks to be
called, even after a time-out.
You may set CONFIG_FW_DEVLINK_SYNC_STATE_TIMEOUT to achieve the above
behavior or use the fw_devlink command line parameters to change it.
Like setting "fw_devlink.sync_state=timeout".
I guess it can be debated what the default behaviour should be.
Perhaps we should even allow the default behaviour to be dynamically
tweaked on a per provider device/driver basis?
>
> > > If I remove the "sync_state = false" above, genpd_provider_sync_state()
> > > considers all domains, and does power down all unused domains (even
> > > multiple times, as expected).
> >
> > I think those are getting called because with the change above, there
> > is no device_link being tracked. As stated above, fw_devlink is
> > limited to use only one device - if multiple devices share the same
> > fwnode.
>
> Indeed.
>
> > In other words, the ->sync_state() callbacks are called even if the
> > corresponding consumer devices have not been probed yet.
>
> Hence shouldn't there be a timeout, as the kernel may not even have
> a driver for one or more consumer devices?
See above.
>
> > > Upon closer look, all "pending due to" messages I see claim that the
> > > first (index 0) PM Domain is pending on some devices, while all of
> > > these devices are part of a different domain (usually the always-on
> > > domain, which is always the last (32 or 64) on R-Car).
> > >
> > > So I think there are two issues:
> > > 1. Devices are not attributed to the correct PM Domain using
> > > fw_devlink sync_state,
> > > 2. One PM Domain of a multi-domain controller being blocked should
> > > not block all other domains handled by the same controller.
> >
> > Right, that's a current limitation with fw_devlink. To cope with this,
> > it's possible to enforce the ->sync_state() callback to be invoked
> > from user-space (timeout or explicitly) for a device.
> >
> > Another option would be to allow an opt-out behavior for some genpd's
> > that are powered-on at initialization. Something along the lines of
> > the below.
> >
> > From: Ulf Hansson <ulf.hansson@linaro.org>
> > Date: Tue, 29 Jul 2025 14:27:22 +0200
> > Subject: [PATCH] pmdomain: core: Allow powered-on PM domains to be powered-off
> > during boot
>
> [...]
>
> I gave this a try (i.e. "| GENPD_FLAG_NO_STAY_ON" in rcar-sysc.c), but
> this doesn't make any difference. I assume this would only work when
> actively calling genpd_power_off() (i.e. not from of_genpd_sync_state()
> or genpd_provider_sync_state())?
Right. Thanks for testing!
So, we may need to restore some part of the genpd_power_off_unused()
when CONFIG_PM_GENERIC_DOMAINS_OF is set. Without clearing
"genpd->stay_on".
I can extend the patch, if you think it would make sense for you?
Kind regards
Uffe
^ permalink raw reply [flat|nested] 59+ messages in thread
* Re: [PATCH v3 00/24] pmdomain: Add generic ->sync_state() support to genpd
2025-07-01 11:47 [PATCH v3 00/24] pmdomain: Add generic ->sync_state() support to genpd Ulf Hansson
` (24 preceding siblings ...)
2025-07-09 11:30 ` [PATCH v3 00/24] pmdomain: Add generic ->sync_state() support to genpd Ulf Hansson
@ 2025-09-03 7:39 ` Sebin Francis
2025-09-03 10:33 ` Ulf Hansson
25 siblings, 1 reply; 59+ messages in thread
From: Sebin Francis @ 2025-09-03 7:39 UTC (permalink / raw)
To: Ulf Hansson, Saravana Kannan, Stephen Boyd, linux-pm
Cc: Rafael J . Wysocki, Greg Kroah-Hartman, Michael Grzeschik,
Bjorn Andersson, Abel Vesa, Peng Fan, Tomi Valkeinen,
Johan Hovold, Maulik Shah, Michal Simek, Konrad Dybcio,
Thierry Reding, Jonathan Hunter, Hiago De Franco,
Geert Uytterhoeven, linux-arm-kernel, linux-kernel
Hi Ulf,
On 01/07/25 17:17, Ulf Hansson wrote:
> Changes in v3:
> - Added a couple of patches to adress problems on some Renesas
> platforms. Thanks Geert and Tomi for helping out!
> - Adressed a few comments from Saravanna and Konrad.
> - Added some tested-by tags.
>
> Changes in v2:
> - Well, quite a lot as I discovered various problems when doing
> additional testing of corner-case. I suggest re-review from scratch,
> even if I decided to keep some reviewed-by tags.
> - Added patches to allow some drivers that needs to align or opt-out
> from the new common behaviour in genpd.
>
> If a PM domain (genpd) is powered-on during boot, there is probably a good
> reason for it. Therefore it's known to be a bad idea to allow such genpd to be
> powered-off before all of its consumer devices have been probed. This series
> intends to fix this problem.
>
> We have been discussing these issues at LKML and at various Linux-conferences
> in the past. I have therefore tried to include the people I can recall being
> involved, but I may have forgotten some (my apologies), feel free to loop them
> in.
> > I have tested this with QEMU with a bunch of local test-drivers and
DT nodes.
> Let me know if you want me to share this code too.
>
> Please help review and test!
During testing on a TI platform, I observed new kernel warnings after
applying this patch series:
ti_sci_pm_domains 44043000.system-controller:power-controller:
sync_state() pending due to fd00000.gpu
These warnings occur when a device (in this case, the GPU) has no driver
bound to it. The fw_devlink_dev_sync_state[0] in the core has a check
before printing this warning. It checks whether the device driver has a
sync_state handler OR the device bus has a sync_state handler in the
dev_has_sync_state[1]. If both conditions are false,
fw_devlink_dev_sync_state[0] performs an early return before printing
the warning.
Before this patch series, both handlers were absent for device driver
ti_sci_pm_domains and the device bus, so both conditions failed and no
warnings were printed.
This patch series adds a sync_state handler for the bus, which now
satisfies the second condition. So it doesn't do an early return and
proceeds to print the warning.
[0]: https://elixir.bootlin.com/linux/v6.16/source/drivers/base/core.c#L1777
[1]:
https://elixir.bootlin.com/linux/v6.16/source/include/linux/device.h#L909
Thanks
Sebin
> Finally, a big thanks to Saravana for all the support!
>
> Kind regards
> Ulf Hansson
>
>
> Saravana Kannan (1):
> driver core: Add dev_set_drv_sync_state()
>
> Ulf Hansson (23):
> pmdomain: renesas: rcar-sysc: Add genpd OF provider at
> postcore_initcall
> pmdomain: renesas: rmobile-sysc: Move init to postcore_initcall
> pmdomain: renesas: rcar-gen4-sysc: Move init to postcore_initcall
> pmdomain: core: Prevent registering devices before the bus
> pmdomain: core: Add a bus and a driver for genpd providers
> pmdomain: core: Add the genpd->dev to the genpd provider bus
> pmdomain: core: Export a common ->sync_state() helper for genpd
> providers
> pmdomain: core: Prepare to add the common ->sync_state() support
> soc/tegra: pmc: Opt-out from genpd's common ->sync_state() support
> cpuidle: psci: Opt-out from genpd's common ->sync_state() support
> cpuidle: riscv-sbi: Opt-out from genpd's common ->sync_state() support
> pmdomain: qcom: rpmpd: Use of_genpd_sync_state()
> pmdomain: qcom: rpmhpd: Use of_genpd_sync_state()
> firmware/pmdomain: xilinx: Move ->sync_state() support to firmware
> driver
> firmware: xilinx: Don't share zynqmp_pm_init_finalize()
> firmware: xilinx: Use of_genpd_sync_state()
> driver core: Export get_dev_from_fwnode()
> pmdomain: core: Add common ->sync_state() support for genpd providers
> pmdomain: core: Default to use of_genpd_sync_state() for genpd
> providers
> pmdomain: core: Leave powered-on genpds on until late_initcall_sync
> pmdomain: core: Leave powered-on genpds on until sync_state
> cpuidle: psci: Drop redundant sync_state support
> cpuidle: riscv-sbi: Drop redundant sync_state support
>
> drivers/base/core.c | 8 +-
> drivers/cpuidle/cpuidle-psci-domain.c | 14 --
> drivers/cpuidle/cpuidle-riscv-sbi.c | 14 --
> drivers/firmware/xilinx/zynqmp.c | 18 +-
> drivers/pmdomain/core.c | 211 ++++++++++++++++++--
> drivers/pmdomain/qcom/rpmhpd.c | 2 +
> drivers/pmdomain/qcom/rpmpd.c | 2 +
> drivers/pmdomain/renesas/rcar-gen4-sysc.c | 2 +-
> drivers/pmdomain/renesas/rcar-sysc.c | 19 +-
> drivers/pmdomain/renesas/rmobile-sysc.c | 3 +-
> drivers/pmdomain/xilinx/zynqmp-pm-domains.c | 16 --
> drivers/soc/tegra/pmc.c | 26 ++-
> include/linux/device.h | 13 ++
> include/linux/firmware/xlnx-zynqmp.h | 6 -
> include/linux/pm_domain.h | 17 ++
> 15 files changed, 291 insertions(+), 80 deletions(-)
>
^ permalink raw reply [flat|nested] 59+ messages in thread
* Re: [PATCH v3 00/24] pmdomain: Add generic ->sync_state() support to genpd
2025-09-03 7:39 ` Sebin Francis
@ 2025-09-03 10:33 ` Ulf Hansson
2025-09-04 12:32 ` Diederik de Haas
0 siblings, 1 reply; 59+ messages in thread
From: Ulf Hansson @ 2025-09-03 10:33 UTC (permalink / raw)
To: Sebin Francis, Saravana Kannan
Cc: Stephen Boyd, linux-pm, Rafael J . Wysocki, Greg Kroah-Hartman,
Michael Grzeschik, Bjorn Andersson, Abel Vesa, Peng Fan,
Tomi Valkeinen, Johan Hovold, Maulik Shah, Michal Simek,
Konrad Dybcio, Thierry Reding, Jonathan Hunter, Hiago De Franco,
Geert Uytterhoeven, linux-arm-kernel, linux-kernel
On Wed, 3 Sept 2025 at 09:39, Sebin Francis <sebin.francis@ti.com> wrote:
>
> Hi Ulf,
>
> On 01/07/25 17:17, Ulf Hansson wrote:
> > Changes in v3:
> > - Added a couple of patches to adress problems on some Renesas
> > platforms. Thanks Geert and Tomi for helping out!
> > - Adressed a few comments from Saravanna and Konrad.
> > - Added some tested-by tags.
> >
> > Changes in v2:
> > - Well, quite a lot as I discovered various problems when doing
> > additional testing of corner-case. I suggest re-review from scratch,
> > even if I decided to keep some reviewed-by tags.
> > - Added patches to allow some drivers that needs to align or opt-out
> > from the new common behaviour in genpd.
> >
> > If a PM domain (genpd) is powered-on during boot, there is probably a good
> > reason for it. Therefore it's known to be a bad idea to allow such genpd to be
> > powered-off before all of its consumer devices have been probed. This series
> > intends to fix this problem.
> >
> > We have been discussing these issues at LKML and at various Linux-conferences
> > in the past. I have therefore tried to include the people I can recall being
> > involved, but I may have forgotten some (my apologies), feel free to loop them
> > in.
> > > I have tested this with QEMU with a bunch of local test-drivers and
> DT nodes.
> > Let me know if you want me to share this code too.
> >
> > Please help review and test!
>
> During testing on a TI platform, I observed new kernel warnings after
> applying this patch series:
>
> ti_sci_pm_domains 44043000.system-controller:power-controller:
> sync_state() pending due to fd00000.gpu
>
> These warnings occur when a device (in this case, the GPU) has no driver
> bound to it. The fw_devlink_dev_sync_state[0] in the core has a check
> before printing this warning. It checks whether the device driver has a
> sync_state handler OR the device bus has a sync_state handler in the
> dev_has_sync_state[1]. If both conditions are false,
> fw_devlink_dev_sync_state[0] performs an early return before printing
> the warning.
>
> Before this patch series, both handlers were absent for device driver
> ti_sci_pm_domains and the device bus, so both conditions failed and no
> warnings were printed.
>
> This patch series adds a sync_state handler for the bus, which now
> satisfies the second condition. So it doesn't do an early return and
> proceeds to print the warning.
Thanks for the report and testing!
Indeed this is the new and expected behaviour. I agree that it's
certainly questionable if those prints should be at the warning level.
We should probably downgrade those to dev_info(), at least. Let me
send a patch to see what Saravana and others are thinking about it!
>
> [0]: https://elixir.bootlin.com/linux/v6.16/source/drivers/base/core.c#L1777
> [1]:
> https://elixir.bootlin.com/linux/v6.16/source/include/linux/device.h#L909
>
> Thanks
> Sebin
[...]
Kind regards
Uffe
^ permalink raw reply [flat|nested] 59+ messages in thread
* Re: [PATCH v3 20/24] pmdomain: core: Default to use of_genpd_sync_state() for genpd providers
2025-08-11 12:11 ` Ulf Hansson
@ 2025-09-03 12:33 ` Jon Hunter
0 siblings, 0 replies; 59+ messages in thread
From: Jon Hunter @ 2025-09-03 12:33 UTC (permalink / raw)
To: Ulf Hansson
Cc: Saravana Kannan, Stephen Boyd, linux-pm, Rafael J . Wysocki,
Greg Kroah-Hartman, Michael Grzeschik, Bjorn Andersson, Abel Vesa,
Peng Fan, Tomi Valkeinen, Johan Hovold, Maulik Shah, Michal Simek,
Konrad Dybcio, Thierry Reding, Hiago De Franco,
Geert Uytterhoeven, linux-arm-kernel, linux-kernel,
linux-tegra@vger.kernel.org
Hi Ulf,
On 11/08/2025 13:11, Ulf Hansson wrote:
> On Thu, 31 Jul 2025 at 17:07, Jon Hunter <jonathanh@nvidia.com> wrote:
>>
>> Hi Ulf,
>>
>> On 01/07/2025 12:47, Ulf Hansson wrote:
>>> Unless the typical platform driver that act as genpd provider, has its own
>>> ->sync_state() callback implemented let's default to use
>>> of_genpd_sync_state().
>>>
>>> More precisely, while adding a genpd OF provider let's assign the
>>> ->sync_state() callback, in case the fwnode has a device and its driver
>>> doesn't have the ->sync_state() set already. In this way the typical
>>> platform driver doesn't need to assign ->sync_state(), unless it has some
>>> additional things to manage beyond genpds.
>>>
>>> Suggested-by: Saravana Kannan <saravanak@google.com>
>>> Tested-by: Hiago De Franco <hiago.franco@toradex.com> # Colibri iMX8X
>>> Tested-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com> # TI AM62A,Xilinx ZynqMP ZCU106
>>> Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
>>> ---
>>> drivers/pmdomain/core.c | 9 +++++++++
>>> 1 file changed, 9 insertions(+)
>>>
>>> diff --git a/drivers/pmdomain/core.c b/drivers/pmdomain/core.c
>>> index ca47f91b9e91..5cef6de60c72 100644
>>> --- a/drivers/pmdomain/core.c
>>> +++ b/drivers/pmdomain/core.c
>>> @@ -2600,6 +2600,11 @@ static bool genpd_present(const struct generic_pm_domain *genpd)
>>> return ret;
>>> }
>>>
>>> +static void genpd_sync_state(struct device *dev)
>>> +{
>>> + return of_genpd_sync_state(dev->of_node);
>>> +}
>>> +
>>> /**
>>> * of_genpd_add_provider_simple() - Register a simple PM domain provider
>>> * @np: Device node pointer associated with the PM domain provider.
>>> @@ -2628,6 +2633,8 @@ int of_genpd_add_provider_simple(struct device_node *np,
>>> if (!dev && !genpd_is_no_sync_state(genpd)) {
>>> genpd->sync_state = GENPD_SYNC_STATE_SIMPLE;
>>> device_set_node(&genpd->dev, fwnode);
>>> + } else {
>>> + dev_set_drv_sync_state(dev, genpd_sync_state);
>>> }
>>>
>>> put_device(dev);
>>> @@ -2700,6 +2707,8 @@ int of_genpd_add_provider_onecell(struct device_node *np,
>>> dev = get_dev_from_fwnode(fwnode);
>>> if (!dev)
>>> sync_state = true;
>>> + else
>>> + dev_set_drv_sync_state(dev, genpd_sync_state);
>>>
>>> put_device(dev);
>>>
>>
>> Following this change I am seeing the following warning on our Tegra194
>> devices ...
>>
>> WARNING KERN tegra-bpmp bpmp: sync_state() pending due to 17000000.gpu
>> WARNING KERN tegra-bpmp bpmp: sync_state() pending due to 3960000.cec
>> WARNING KERN tegra-bpmp bpmp: sync_state() pending due to 15380000.nvjpg
>> WARNING KERN tegra-bpmp bpmp: sync_state() pending due to 154c0000.nvenc
>> WARNING KERN tegra-bpmp bpmp: sync_state() pending due to 15a80000.nvenc
>>
>> Per your change [0], the 'GENPD_FLAG_NO_SYNC_STATE' is set for Tegra
>> and so should Tegra be using of_genpd_sync_state() by default?
>
> This is a different power-domain provider (bpmp) in
> drivers/firmware/tegra/bpmp.c and
> drivers/pmdomain/tegra/powergate-bpmp.c.
>
> For the bpmp we don't need GENPD_FLAG_NO_SYNC_STATE, as the
> power-domain provider is described along with the
> "nvidia,tegra186-bpmp" compatible string. In the other case
> (drivers/soc/tegra/pmc.c) the "core-domain" and "powergates" are
> described through child-nodes, while ->sync_state() is managed by the
> parent-device-node.
>
> In the bpmp case there is no ->sync_state() callback assigned, which
> means genpd decides to assign a default one.
>
> The reason for the warnings above is because we are still waiting for
> those devices to be probed, hence the ->sync_state() callback is still
> waiting to be invoked. Enforcing ->sync_state() callback to be invoked
> can be done via user-space if that is needed.
>
> Did that make sense?
Sorry for the delay, I was on vacation. Yes makes sense and drivers for
some of the above drivers are not yet upstreamed to mainline and so this
would be expected for now.
Thanks
Jon
--
nvpublic
^ permalink raw reply [flat|nested] 59+ messages in thread
* Re: [PATCH v3 00/24] pmdomain: Add generic ->sync_state() support to genpd
2025-09-03 10:33 ` Ulf Hansson
@ 2025-09-04 12:32 ` Diederik de Haas
0 siblings, 0 replies; 59+ messages in thread
From: Diederik de Haas @ 2025-09-04 12:32 UTC (permalink / raw)
To: Ulf Hansson, Sebin Francis, Saravana Kannan
Cc: Stephen Boyd, linux-pm, Rafael J . Wysocki, Greg Kroah-Hartman,
Michael Grzeschik, Bjorn Andersson, Abel Vesa, Peng Fan,
Tomi Valkeinen, Johan Hovold, Maulik Shah, Michal Simek,
Konrad Dybcio, Thierry Reding, Jonathan Hunter, Hiago De Franco,
Geert Uytterhoeven, linux-arm-kernel, linux-kernel,
linux-rockchip, Nicolas Frattaroli
[-- Attachment #1: Type: text/plain, Size: 3979 bytes --]
Hi,
On Wed Sep 3, 2025 at 12:33 PM CEST, Ulf Hansson wrote:
> On Wed, 3 Sept 2025 at 09:39, Sebin Francis <sebin.francis@ti.com> wrote:
>> On 01/07/25 17:17, Ulf Hansson wrote:
>> >
>> > If a PM domain (genpd) is powered-on during boot, there is probably a good
>> > reason for it. Therefore it's known to be a bad idea to allow such genpd to be
>> > powered-off before all of its consumer devices have been probed. This series
>> > intends to fix this problem.
>> >
>> > We have been discussing these issues at LKML and at various Linux-conferences
>> > in the past. I have therefore tried to include the people I can recall being
>> > involved, but I may have forgotten some (my apologies), feel free to loop them
>> > in.
>> >
>> > Please help review and test!
>>
>> During testing on a TI platform, I observed new kernel warnings after
>> applying this patch series:
>>
>> ti_sci_pm_domains 44043000.system-controller:power-controller:
>> sync_state() pending due to fd00000.gpu
>>
>> These warnings occur when a device (in this case, the GPU) has no driver
>> bound to it. The fw_devlink_dev_sync_state[0] in the core has a check
>> before printing this warning. It checks whether the device driver has a
>> sync_state handler OR the device bus has a sync_state handler in the
>> dev_has_sync_state[1]. If both conditions are false,
>> fw_devlink_dev_sync_state[0] performs an early return before printing
>> the warning.
>>
>> Before this patch series, both handlers were absent for device driver
>> ti_sci_pm_domains and the device bus, so both conditions failed and no
>> warnings were printed.
>>
>> This patch series adds a sync_state handler for the bus, which now
>> satisfies the second condition. So it doesn't do an early return and
>> proceeds to print the warning.
>
> Thanks for the report and testing!
>
> Indeed this is the new and expected behaviour. I agree that it's
> certainly questionable if those prints should be at the warning level.
>
> We should probably downgrade those to dev_info(), at least. Let me
> send a patch to see what Saravana and others are thinking about it!
I want to report that I see similar warnings on Rock64 (rk3328):
[ 16.868033] rockchip-pm-domain ff100000.syscon:power-controller: sync_state() pending due to ff300000.gpu
[ 16.873637] rockchip-pm-domain ff100000.syscon:power-controller: sync_state() pending due to ff350000.video-codec
[ 16.896495] rockchip-pm-domain ff100000.syscon:power-controller: sync_state() pending due to ff360000.video-codec
This is with a 6.17-rc3 kernel with various rkvdec patches and in dmesg
I later see msgs wrt ff300000.gpu (lima) and ff350000.video-codec
(hantro-vpu), but not ff360000.video-codec (rkvdec). Full dmesg:
https://paste.sr.ht/~diederik/951b54ea8422756e5efaa61d6bcefb575cfe28a4
But there were also USB issues (not sure why), so I rebooted and then I
did see msgs wrt rkvdec. Full dmesg:
https://paste.sr.ht/~diederik/156f65fc6be05d02484568dfd303c46ba76b3a8e
I also have a 6.17-rc4 kernel which is clean upstream, thus without any
media patches. This time no USB issues (also no USB device plugged in)
and I see msgs wrt lima and hantro-vpu, but not rkvdec. Full dmesg:
https://paste.sr.ht/~diederik/4affea034b0c9fb522a8ad5b90e8b59b4bd856ec
What's possibly relevant is that the 6.17-rc3+unreleased kernel also has
this patch added, which adds 'power-domain@RK3328_PD_GPU' to rk3328.dtsi
https://lore.kernel.org/linux-rockchip/20250830115135.3549305-1-christianshewitt@gmail.com/
I actually found this thread because I too couldn't find the commit ID
Nicolas referenced in this post:
https://lore.kernel.org/linux-rockchip/20250902-rk3576-lockup-regression-v1-1-c4a0c9daeb00@collabora.com/
I have no idea whether it's related though (I have no rk3576 device).
I haven't tried (yet) whether the sync_state() msg is also present on
other Rockchip based devices.
Cheers,
Diederik
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 228 bytes --]
^ permalink raw reply [flat|nested] 59+ messages in thread
* Re: [PATCH v3 00/24] pmdomain: Add generic ->sync_state() support to genpd
2025-08-14 15:49 ` Ulf Hansson
@ 2025-09-04 12:41 ` Geert Uytterhoeven
2025-09-04 15:44 ` Ulf Hansson
0 siblings, 1 reply; 59+ messages in thread
From: Geert Uytterhoeven @ 2025-09-04 12:41 UTC (permalink / raw)
To: Ulf Hansson
Cc: Saravana Kannan, Stephen Boyd, linux-pm, Rafael J . Wysocki,
Greg Kroah-Hartman, Michael Grzeschik, Bjorn Andersson, Abel Vesa,
Peng Fan, Tomi Valkeinen, Johan Hovold, Maulik Shah, Michal Simek,
Konrad Dybcio, Thierry Reding, Jonathan Hunter, Hiago De Franco,
linux-arm-kernel, linux-kernel, Linux-Renesas
Hi Ulf,
On Thu, 14 Aug 2025 at 17:50, Ulf Hansson <ulf.hansson@linaro.org> wrote:
> On Wed, 13 Aug 2025 at 13:58, Geert Uytterhoeven <geert@linux-m68k.org> wrote:
> > On Tue, 12 Aug 2025 at 12:01, Ulf Hansson <ulf.hansson@linaro.org> wrote:
> > > On Thu, 7 Aug 2025 at 11:38, Geert Uytterhoeven <geert@linux-m68k.org> wrote:
> > > > On Wed, 30 Jul 2025 at 12:29, Ulf Hansson <ulf.hansson@linaro.org> wrote:
> > > > > On Wed, 30 Jul 2025 at 11:56, Geert Uytterhoeven <geert@linux-m68k.org> wrote:
> > > > > > On Wed, 9 Jul 2025 at 13:31, Ulf Hansson <ulf.hansson@linaro.org> wrote:
> > > > > > > On Tue, 1 Jul 2025 at 13:47, Ulf Hansson <ulf.hansson@linaro.org> wrote:
> > > > > > > > Changes in v3:
> > > > > > > > - Added a couple of patches to adress problems on some Renesas
> > > > > > > > platforms. Thanks Geert and Tomi for helping out!
> > > > > > > > - Adressed a few comments from Saravanna and Konrad.
> > > > > > > > - Added some tested-by tags.
> > > > > > >
> > > > > > > I decided it was time to give this a try, so I have queued this up for
> > > > > > > v6.17 via the next branch at my pmdomain tree.
> > > > > > >
> > > > > > > If you encounter any issues, please let me know so I can help to fix them.
> > > > > >
> > > > > > Thanks for your series! Due to holidays, I only managed to test
> > > > > > this very recently.
> > > > > >
> > > > > > Unfortunately I have an issue with unused PM Domains no longer being
> > > > > > disabled on R-Car:
> > > > > > - On R-Car Gen1/2/3, using rcar-sysc.c, unused PM Domains are never
> > > > > > disabled.
> > > > > > - On R-Car Gen4, using rcar-gen4-sysc.c, unused PM Domains are
> > > > > > sometimes not disabled.
> > > > > > At first, I noticed the IOMMU driver was not enabled in my config,
> > > > > > and enabling it did fix the issue. However, after that I still
> > > > > > encountered the issue in a different config that does have the
> > > > > > IOMMU driver enabled...
> > > > > >
> > > > > > FTR, unused PM Domains are still disabled correctly on R/SH-Mobile
> > > > > > (using rmobile-sysc.c) and on BeagleBone Black. Note that these use
> > > > > > of_genpd_add_provider_simple(), while all R-Car drivers use
> > > > > > of_genpd_add_provider_onecell(). Perhaps there is an issue with
> > > > > > the latter? If you don't have a clue, I plan to do some more
> > > > > > investigation later...
> > > >
> > > > of_genpd_add_provider_onecell() has:
> > > >
> > > > if (!dev)
> > > > sync_state = true;
> > > > else
> > > > dev_set_drv_sync_state(dev, genpd_sync_state);
> > > >
> > > > for (i = 0; i < data->num_domains; i++) {
> > > > ...
> > > > if (sync_state && !genpd_is_no_sync_state(genpd)) {
> > > > genpd->sync_state = GENPD_SYNC_STATE_ONECELL;
> > > > device_set_node(&genpd->dev, fwnode);
> > > > sync_state = false;
> > > > ^^^^^^^^^^^^^^^^^^^
> > > > }
> > > > ...
> > > > }
> > > >
> > > > As the R-Car SYSC drivers are not platform drivers, dev is NULL, and
> > > > genpd->sync_state is set to GENPD_SYNC_STATE_ONECELL for the first PM
> > > > Domain only. All other domains have the default value of sync_state
> > > > (0 = GENPD_SYNC_STATE_OFF). Hence when genpd_provider_sync_state()
> > > > is called later, it ignores all but the first domain.
> > > > Apparently this is intentional, as of_genpd_sync_state() tries to
> > > > power off all domains handled by the same controller anyway (see below)?
> > >
> > > Right, this is intentional and mainly because of how fw_devlink works.
> > >
> > > fw_devlink is limited to use only the first device - if multiple
> > > devices share the same fwnode. In principle, we could have picked any
> > > of the devices in the array of genpds here - and reached the same
> > > result.
> >
> > OK, just like I already assumed...
> >
> > > > > > BTW, the "pending due to"-messages look weird to me.
> > > > > > On R-Car M2-W (r8a7791.dtsi) I see e.g.:
> > > > > >
> > > > > > genpd_provider ca15-cpu0: sync_state() pending due to e6020000.watchdog
> > > > > > renesas-cpg-mssr e6150000.clock-controller: sync_state() pending
> > > > > > due to e6020000.watchdog
> > > > > >
> > > > > > ca15-cpu0 is the PM Domain holding the first CPU core, while
> > > > > > the watchdog resides in the always-on Clock Domain, and uses the
> > > > > > clock-controller for PM_CLK handling.
> > > >
> > > > Unfortunately the first PM Domain is "ca15-cpu0", which is blocked on
> > > > these bogus pending states, and no PM Domain is powered off.
> > >
> > > I see, thanks for the details. I am looking closer at this.
> > >
> > > In any case, this is the main issue, as it prevents the ->sync_state()
> > > callback to be called. Hence the "genpd->stay_on" will also *not* be
> > > cleared for any of the genpd's for the genpd-provider.
> >
> > I was under the impression there is a time-out, after which the
> > .sync_state() callback would be called anyway, just like for probe
> > deferral due to missing optional providers like DMACs and IOMMUs.
> > Apparently that is not the case?
>
> The behaviour is configurable, so it depends. The current default
> behaviour does *not* enforce the ->sync_state() callbacks to be
> called, even after a time-out.
>
> You may set CONFIG_FW_DEVLINK_SYNC_STATE_TIMEOUT to achieve the above
> behavior or use the fw_devlink command line parameters to change it.
> Like setting "fw_devlink.sync_state=timeout".
>
> I guess it can be debated what the default behaviour should be.
> Perhaps we should even allow the default behaviour to be dynamically
> tweaked on a per provider device/driver basis?
The domains are indeed powered off like before when passing
"fw_devlink.sync_state=timeout", so that fixes the regression.
But it was not needed before...
I could add "select FW_DEVLINK_SYNC_STATE_TIMEOUT" to the SYSC_RCAR
and SYSC_RCAR_GEN4 Kconfig options, but that would play badly with
multi-platform kernels. As the fw_devlink_sync_state flag is static,
the R-Car SYSC drivers can't just auto-enable the flag at runtime.
Any other options? Perhaps a device-specific flag to be set by the PM
Domain driver, and to be checked by fw_devlink_dev_sync_state()?
> > > > If I remove the "sync_state = false" above, genpd_provider_sync_state()
> > > > considers all domains, and does power down all unused domains (even
> > > > multiple times, as expected).
> > >
> > > I think those are getting called because with the change above, there
> > > is no device_link being tracked. As stated above, fw_devlink is
> > > limited to use only one device - if multiple devices share the same
> > > fwnode.
> >
> > Indeed.
> >
> > > In other words, the ->sync_state() callbacks are called even if the
> > > corresponding consumer devices have not been probed yet.
> >
> > Hence shouldn't there be a timeout, as the kernel may not even have
> > a driver for one or more consumer devices?
>
> See above.
>
> > > > Upon closer look, all "pending due to" messages I see claim that the
> > > > first (index 0) PM Domain is pending on some devices, while all of
> > > > these devices are part of a different domain (usually the always-on
> > > > domain, which is always the last (32 or 64) on R-Car).
> > > >
> > > > So I think there are two issues:
> > > > 1. Devices are not attributed to the correct PM Domain using
> > > > fw_devlink sync_state,
> > > > 2. One PM Domain of a multi-domain controller being blocked should
> > > > not block all other domains handled by the same controller.
> > >
> > > Right, that's a current limitation with fw_devlink. To cope with this,
> > > it's possible to enforce the ->sync_state() callback to be invoked
> > > from user-space (timeout or explicitly) for a device.
That needs explicit handling, which was not needed before.
Perhaps the fw_devlink creation should be removed again from
of_genpd_add_provider_onecell(), as it is not correct, except for
the first domain?
> > > Another option would be to allow an opt-out behavior for some genpd's
> > > that are powered-on at initialization. Something along the lines of
> > > the below.
> > >
> > > From: Ulf Hansson <ulf.hansson@linaro.org>
> > > Date: Tue, 29 Jul 2025 14:27:22 +0200
> > > Subject: [PATCH] pmdomain: core: Allow powered-on PM domains to be powered-off
> > > during boot
> >
> > [...]
> >
> > I gave this a try (i.e. "| GENPD_FLAG_NO_STAY_ON" in rcar-sysc.c), but
> > this doesn't make any difference. I assume this would only work when
> > actively calling genpd_power_off() (i.e. not from of_genpd_sync_state()
> > or genpd_provider_sync_state())?
>
> Right. Thanks for testing!
>
> So, we may need to restore some part of the genpd_power_off_unused()
> when CONFIG_PM_GENERIC_DOMAINS_OF is set. Without clearing
> "genpd->stay_on".
>
> I can extend the patch, if you think it would make sense for you?
I would applaud anything that would fix these regressions.
Thanks!
Gr{oetje,eeting}s,
Geert
--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org
In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds
^ permalink raw reply [flat|nested] 59+ messages in thread
* Re: [PATCH v3 00/24] pmdomain: Add generic ->sync_state() support to genpd
2025-09-04 12:41 ` Geert Uytterhoeven
@ 2025-09-04 15:44 ` Ulf Hansson
0 siblings, 0 replies; 59+ messages in thread
From: Ulf Hansson @ 2025-09-04 15:44 UTC (permalink / raw)
To: Saravana Kannan, Geert Uytterhoeven
Cc: Stephen Boyd, linux-pm, Rafael J . Wysocki, Greg Kroah-Hartman,
Michael Grzeschik, Bjorn Andersson, Abel Vesa, Peng Fan,
Tomi Valkeinen, Johan Hovold, Maulik Shah, Michal Simek,
Konrad Dybcio, Thierry Reding, Jonathan Hunter, Hiago De Franco,
linux-arm-kernel, linux-kernel, Linux-Renesas
On Thu, 4 Sept 2025 at 14:41, Geert Uytterhoeven <geert@linux-m68k.org> wrote:
>
> Hi Ulf,
>
> On Thu, 14 Aug 2025 at 17:50, Ulf Hansson <ulf.hansson@linaro.org> wrote:
> > On Wed, 13 Aug 2025 at 13:58, Geert Uytterhoeven <geert@linux-m68k.org> wrote:
> > > On Tue, 12 Aug 2025 at 12:01, Ulf Hansson <ulf.hansson@linaro.org> wrote:
> > > > On Thu, 7 Aug 2025 at 11:38, Geert Uytterhoeven <geert@linux-m68k.org> wrote:
> > > > > On Wed, 30 Jul 2025 at 12:29, Ulf Hansson <ulf.hansson@linaro.org> wrote:
> > > > > > On Wed, 30 Jul 2025 at 11:56, Geert Uytterhoeven <geert@linux-m68k.org> wrote:
> > > > > > > On Wed, 9 Jul 2025 at 13:31, Ulf Hansson <ulf.hansson@linaro.org> wrote:
> > > > > > > > On Tue, 1 Jul 2025 at 13:47, Ulf Hansson <ulf.hansson@linaro.org> wrote:
> > > > > > > > > Changes in v3:
> > > > > > > > > - Added a couple of patches to adress problems on some Renesas
> > > > > > > > > platforms. Thanks Geert and Tomi for helping out!
> > > > > > > > > - Adressed a few comments from Saravanna and Konrad.
> > > > > > > > > - Added some tested-by tags.
> > > > > > > >
> > > > > > > > I decided it was time to give this a try, so I have queued this up for
> > > > > > > > v6.17 via the next branch at my pmdomain tree.
> > > > > > > >
> > > > > > > > If you encounter any issues, please let me know so I can help to fix them.
> > > > > > >
> > > > > > > Thanks for your series! Due to holidays, I only managed to test
> > > > > > > this very recently.
> > > > > > >
> > > > > > > Unfortunately I have an issue with unused PM Domains no longer being
> > > > > > > disabled on R-Car:
> > > > > > > - On R-Car Gen1/2/3, using rcar-sysc.c, unused PM Domains are never
> > > > > > > disabled.
> > > > > > > - On R-Car Gen4, using rcar-gen4-sysc.c, unused PM Domains are
> > > > > > > sometimes not disabled.
> > > > > > > At first, I noticed the IOMMU driver was not enabled in my config,
> > > > > > > and enabling it did fix the issue. However, after that I still
> > > > > > > encountered the issue in a different config that does have the
> > > > > > > IOMMU driver enabled...
> > > > > > >
> > > > > > > FTR, unused PM Domains are still disabled correctly on R/SH-Mobile
> > > > > > > (using rmobile-sysc.c) and on BeagleBone Black. Note that these use
> > > > > > > of_genpd_add_provider_simple(), while all R-Car drivers use
> > > > > > > of_genpd_add_provider_onecell(). Perhaps there is an issue with
> > > > > > > the latter? If you don't have a clue, I plan to do some more
> > > > > > > investigation later...
> > > > >
> > > > > of_genpd_add_provider_onecell() has:
> > > > >
> > > > > if (!dev)
> > > > > sync_state = true;
> > > > > else
> > > > > dev_set_drv_sync_state(dev, genpd_sync_state);
> > > > >
> > > > > for (i = 0; i < data->num_domains; i++) {
> > > > > ...
> > > > > if (sync_state && !genpd_is_no_sync_state(genpd)) {
> > > > > genpd->sync_state = GENPD_SYNC_STATE_ONECELL;
> > > > > device_set_node(&genpd->dev, fwnode);
> > > > > sync_state = false;
> > > > > ^^^^^^^^^^^^^^^^^^^
> > > > > }
> > > > > ...
> > > > > }
> > > > >
> > > > > As the R-Car SYSC drivers are not platform drivers, dev is NULL, and
> > > > > genpd->sync_state is set to GENPD_SYNC_STATE_ONECELL for the first PM
> > > > > Domain only. All other domains have the default value of sync_state
> > > > > (0 = GENPD_SYNC_STATE_OFF). Hence when genpd_provider_sync_state()
> > > > > is called later, it ignores all but the first domain.
> > > > > Apparently this is intentional, as of_genpd_sync_state() tries to
> > > > > power off all domains handled by the same controller anyway (see below)?
> > > >
> > > > Right, this is intentional and mainly because of how fw_devlink works.
> > > >
> > > > fw_devlink is limited to use only the first device - if multiple
> > > > devices share the same fwnode. In principle, we could have picked any
> > > > of the devices in the array of genpds here - and reached the same
> > > > result.
> > >
> > > OK, just like I already assumed...
> > >
> > > > > > > BTW, the "pending due to"-messages look weird to me.
> > > > > > > On R-Car M2-W (r8a7791.dtsi) I see e.g.:
> > > > > > >
> > > > > > > genpd_provider ca15-cpu0: sync_state() pending due to e6020000.watchdog
> > > > > > > renesas-cpg-mssr e6150000.clock-controller: sync_state() pending
> > > > > > > due to e6020000.watchdog
> > > > > > >
> > > > > > > ca15-cpu0 is the PM Domain holding the first CPU core, while
> > > > > > > the watchdog resides in the always-on Clock Domain, and uses the
> > > > > > > clock-controller for PM_CLK handling.
> > > > >
> > > > > Unfortunately the first PM Domain is "ca15-cpu0", which is blocked on
> > > > > these bogus pending states, and no PM Domain is powered off.
> > > >
> > > > I see, thanks for the details. I am looking closer at this.
> > > >
> > > > In any case, this is the main issue, as it prevents the ->sync_state()
> > > > callback to be called. Hence the "genpd->stay_on" will also *not* be
> > > > cleared for any of the genpd's for the genpd-provider.
> > >
> > > I was under the impression there is a time-out, after which the
> > > .sync_state() callback would be called anyway, just like for probe
> > > deferral due to missing optional providers like DMACs and IOMMUs.
> > > Apparently that is not the case?
> >
> > The behaviour is configurable, so it depends. The current default
> > behaviour does *not* enforce the ->sync_state() callbacks to be
> > called, even after a time-out.
> >
> > You may set CONFIG_FW_DEVLINK_SYNC_STATE_TIMEOUT to achieve the above
> > behavior or use the fw_devlink command line parameters to change it.
> > Like setting "fw_devlink.sync_state=timeout".
> >
> > I guess it can be debated what the default behaviour should be.
> > Perhaps we should even allow the default behaviour to be dynamically
> > tweaked on a per provider device/driver basis?
>
> The domains are indeed powered off like before when passing
> "fw_devlink.sync_state=timeout", so that fixes the regression.
> But it was not needed before...
Right, the default behavior in genpd has changed. The approach was
taken as we believed that original behavior was not correct.
Although, the current situation isn't good as it causes lot of churns for us.
>
> I could add "select FW_DEVLINK_SYNC_STATE_TIMEOUT" to the SYSC_RCAR
> and SYSC_RCAR_GEN4 Kconfig options, but that would play badly with
> multi-platform kernels. As the fw_devlink_sync_state flag is static,
> the R-Car SYSC drivers can't just auto-enable the flag at runtime.
>
> Any other options? Perhaps a device-specific flag to be set by the PM
> Domain driver, and to be checked by fw_devlink_dev_sync_state()?
Something along those lines seems reasonable to me too.
However, the remaining question though, is what should be the default
behavior in genpd for this. Due to all the churns, we may want
something that is closer to what we had *before*, which means to
always use the timeout option, unless the genpd provider driver
explicitly requests to not to (an opt-out genpd config flag).
Saravana, it would be nice to get some thoughts from you are around
this? Does it make sense?
>
> > > > > If I remove the "sync_state = false" above, genpd_provider_sync_state()
> > > > > considers all domains, and does power down all unused domains (even
> > > > > multiple times, as expected).
> > > >
> > > > I think those are getting called because with the change above, there
> > > > is no device_link being tracked. As stated above, fw_devlink is
> > > > limited to use only one device - if multiple devices share the same
> > > > fwnode.
> > >
> > > Indeed.
> > >
> > > > In other words, the ->sync_state() callbacks are called even if the
> > > > corresponding consumer devices have not been probed yet.
> > >
> > > Hence shouldn't there be a timeout, as the kernel may not even have
> > > a driver for one or more consumer devices?
> >
> > See above.
> >
> > > > > Upon closer look, all "pending due to" messages I see claim that the
> > > > > first (index 0) PM Domain is pending on some devices, while all of
> > > > > these devices are part of a different domain (usually the always-on
> > > > > domain, which is always the last (32 or 64) on R-Car).
> > > > >
> > > > > So I think there are two issues:
> > > > > 1. Devices are not attributed to the correct PM Domain using
> > > > > fw_devlink sync_state,
> > > > > 2. One PM Domain of a multi-domain controller being blocked should
> > > > > not block all other domains handled by the same controller.
> > > >
> > > > Right, that's a current limitation with fw_devlink. To cope with this,
> > > > it's possible to enforce the ->sync_state() callback to be invoked
> > > > from user-space (timeout or explicitly) for a device.
>
> That needs explicit handling, which was not needed before.
>
> Perhaps the fw_devlink creation should be removed again from
> of_genpd_add_provider_onecell(), as it is not correct, except for
> the first domain?
There is nothing wrong with it, the behavior is correct, unless I
failed to understand your problem. To me the problem is that it is
just less fine grained, compared to using
of_genpd_add_provider_simple(). All PM domains that is provided by a
single power-domain controller that uses #power-domain-cells = <1>,
requires all consumers of them to be probed, to allow the sync_state
callback to be invoked.
If we could teach fw_devlink to take into account the
power-domain-*id* that is specified by the consumer node, when the
provider is using #power-domain-cells = <1>, this could potentially
become as fine-grained as of_genpd_add_provider_simple().
Saravana, do think we can extend fw_devlink to take this into account somehow?
>
> > > > Another option would be to allow an opt-out behavior for some genpd's
> > > > that are powered-on at initialization. Something along the lines of
> > > > the below.
> > > >
> > > > From: Ulf Hansson <ulf.hansson@linaro.org>
> > > > Date: Tue, 29 Jul 2025 14:27:22 +0200
> > > > Subject: [PATCH] pmdomain: core: Allow powered-on PM domains to be powered-off
> > > > during boot
> > >
> > > [...]
> > >
> > > I gave this a try (i.e. "| GENPD_FLAG_NO_STAY_ON" in rcar-sysc.c), but
> > > this doesn't make any difference. I assume this would only work when
> > > actively calling genpd_power_off() (i.e. not from of_genpd_sync_state()
> > > or genpd_provider_sync_state())?
> >
> > Right. Thanks for testing!
> >
> > So, we may need to restore some part of the genpd_power_off_unused()
> > when CONFIG_PM_GENERIC_DOMAINS_OF is set. Without clearing
> > "genpd->stay_on".
> >
> > I can extend the patch, if you think it would make sense for you?
>
> I would applaud anything that would fix these regressions.
> Thanks!
While being mostly silent from my side for a while, I have been
continuing to evolve my test suite for sync_state tests. Wanted to
make sure I cover additional new corner cases that you have pointed
out for Renesas platforms.
That said, I have not observed any issues on my side, so it looks like
we are simply facing new behaviors that you have pointed out to be a
problem. In this regards, I think it's important to note that we are
currently only seeing problems for those genpds that are powered-on
when the provider driver calls pm_genpd_init(). Another simple option
is to power-off those PM domains that we know is not really needed to
be powered-on. Also not perfect, but an option.
Another option is something along the lines of what I posted, but
perhaps extending it to let the late_initcall_sync to try to power-off
the unused PM domains.
I will work on updating the patch so we can try it out - or perhaps
what you suggested above with a device-specific flag taken into
account by fw_devlink_dev_sync_state() would be better/sufficient you
think?
Kind regards
Uffe
^ permalink raw reply [flat|nested] 59+ messages in thread
end of thread, other threads:[~2025-09-04 15:44 UTC | newest]
Thread overview: 59+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-07-01 11:47 [PATCH v3 00/24] pmdomain: Add generic ->sync_state() support to genpd Ulf Hansson
2025-07-01 11:47 ` [PATCH v3 01/24] pmdomain: renesas: rcar-sysc: Add genpd OF provider at postcore_initcall Ulf Hansson
2025-07-01 11:47 ` [PATCH v3 02/24] pmdomain: renesas: rmobile-sysc: Move init to postcore_initcall Ulf Hansson
2025-07-01 11:47 ` [PATCH v3 03/24] pmdomain: renesas: rcar-gen4-sysc: " Ulf Hansson
2025-07-01 11:47 ` [PATCH v3 04/24] pmdomain: core: Prevent registering devices before the bus Ulf Hansson
2025-07-01 11:47 ` [PATCH v3 05/24] pmdomain: core: Add a bus and a driver for genpd providers Ulf Hansson
2025-07-01 11:47 ` [PATCH v3 06/24] pmdomain: core: Add the genpd->dev to the genpd provider bus Ulf Hansson
2025-07-01 11:47 ` [PATCH v3 07/24] pmdomain: core: Export a common ->sync_state() helper for genpd providers Ulf Hansson
2025-07-01 11:47 ` [PATCH v3 08/24] pmdomain: core: Prepare to add the common ->sync_state() support Ulf Hansson
2025-07-01 11:47 ` [PATCH v3 09/24] soc/tegra: pmc: Opt-out from genpd's " Ulf Hansson
2025-07-01 11:47 ` [PATCH v3 10/24] cpuidle: psci: " Ulf Hansson
2025-07-01 11:47 ` [PATCH v3 11/24] cpuidle: riscv-sbi: " Ulf Hansson
2025-07-04 10:14 ` Rahul Pathak
2025-07-07 9:36 ` Anup Patel
2025-08-10 21:12 ` patchwork-bot+linux-riscv
2025-07-01 11:47 ` [PATCH v3 12/24] pmdomain: qcom: rpmpd: Use of_genpd_sync_state() Ulf Hansson
2025-07-01 11:47 ` [PATCH v3 13/24] pmdomain: qcom: rpmhpd: " Ulf Hansson
2025-07-01 11:47 ` [PATCH v3 14/24] firmware/pmdomain: xilinx: Move ->sync_state() support to firmware driver Ulf Hansson
2025-07-01 11:47 ` [PATCH v3 15/24] firmware: xilinx: Don't share zynqmp_pm_init_finalize() Ulf Hansson
2025-07-01 11:47 ` [PATCH v3 16/24] firmware: xilinx: Use of_genpd_sync_state() Ulf Hansson
2025-07-01 11:47 ` [PATCH v3 17/24] driver core: Export get_dev_from_fwnode() Ulf Hansson
2025-07-02 7:34 ` Greg Kroah-Hartman
2025-07-02 19:26 ` Danilo Krummrich
2025-07-02 21:34 ` Saravana Kannan
2025-07-02 21:55 ` Danilo Krummrich
2025-07-01 11:47 ` [PATCH v3 18/24] pmdomain: core: Add common ->sync_state() support for genpd providers Ulf Hansson
2025-07-01 11:47 ` [PATCH v3 19/24] driver core: Add dev_set_drv_sync_state() Ulf Hansson
2025-07-01 11:47 ` [PATCH v3 20/24] pmdomain: core: Default to use of_genpd_sync_state() for genpd providers Ulf Hansson
2025-07-31 15:07 ` Jon Hunter
2025-08-11 12:11 ` Ulf Hansson
2025-09-03 12:33 ` Jon Hunter
2025-07-01 11:47 ` [PATCH v3 21/24] pmdomain: core: Leave powered-on genpds on until late_initcall_sync Ulf Hansson
[not found] ` <CGME20250710122654eucas1p20f1179a9ff22d562d89252f924d34dae@eucas1p2.samsung.com>
2025-07-10 12:26 ` Marek Szyprowski
2025-07-10 14:54 ` Ulf Hansson
2025-07-15 10:28 ` Jon Hunter
2025-07-15 11:32 ` Ulf Hansson
2025-07-15 11:34 ` Ulf Hansson
2025-07-31 12:53 ` Jon Hunter
2025-07-01 11:47 ` [PATCH v3 22/24] pmdomain: core: Leave powered-on genpds on until sync_state Ulf Hansson
2025-07-01 11:47 ` [PATCH v3 23/24] cpuidle: psci: Drop redundant sync_state support Ulf Hansson
2025-07-01 11:47 ` [PATCH v3 24/24] cpuidle: riscv-sbi: " Ulf Hansson
2025-07-04 10:39 ` Rahul Pathak
2025-07-07 9:38 ` Anup Patel
2025-07-09 11:30 ` [PATCH v3 00/24] pmdomain: Add generic ->sync_state() support to genpd Ulf Hansson
2025-07-15 8:50 ` Danilo Krummrich
2025-07-16 12:46 ` Ulf Hansson
2025-07-16 13:08 ` Danilo Krummrich
2025-07-30 9:56 ` Geert Uytterhoeven
2025-07-30 10:29 ` Ulf Hansson
2025-08-07 9:38 ` Geert Uytterhoeven
2025-08-12 10:00 ` Ulf Hansson
2025-08-13 11:58 ` Geert Uytterhoeven
2025-08-14 15:49 ` Ulf Hansson
2025-09-04 12:41 ` Geert Uytterhoeven
2025-09-04 15:44 ` Ulf Hansson
2025-08-13 12:04 ` Geert Uytterhoeven
2025-09-03 7:39 ` Sebin Francis
2025-09-03 10:33 ` Ulf Hansson
2025-09-04 12:32 ` Diederik de Haas
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).