Skip to contentSkip to conversation

Revert "power-domain: Add refcounting"

PATCH In review Wadim Egorov 4 participants 5 messages Apr 17, 2025 – Apr 22, 2025

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Revert "power-domain: Add refcounting"

Unfortunately this change breaks boot on K3 platform. U-Boot will hang after:

U-Boot SPL 2025.04-01050-ga40fc5afaec0 (Apr 14 2025 - 07:31:32 +0000) SYSFW ABI: 3.1 (firmware rev 0x0009 '9.2.7--v09.02.07 (Kool Koala)')

This reverts commit 197376fbf300e92afa0a1583815d9c9eb52d613a as suggested in [1].

[1] https://lists.denx.de/pipermail/u-boot/2025-April/587032.html

---
 drivers/firmware/scmi/sandbox-scmi_devices.c  |  1 -
 drivers/power/domain/power-domain-uclass.c    | 40 ++-----------
 .../power/domain/sandbox-power-domain-test.c  |  1 -
 include/power-domain.h                        | 60 +++----------------
 test/dm/power-domain.c                        |  2 +-
 5 files changed, 13 insertions(+), 91 deletions(-)
drivers/firmware/scmi/sandbox-scmi_devices.c +0 -1
index 9f253b0fd40..96c2922b067 100644
@@ -163,5 +163,4 @@ U_BOOT_DRIVER(sandbox_scmi_devices) = {
 	.priv_auto = sizeof(struct sandbox_scmi_device_priv),
 	.remove = sandbox_scmi_devices_remove,
 	.probe = sandbox_scmi_devices_probe,
-	.flags = DM_FLAG_DEFAULT_PD_CTRL_OFF,
 };
drivers/power/domain/power-domain-uclass.c +4 -36
index a6e5f9ed036..938bd8cbc9f 100644
@@ -12,10 +12,6 @@
 #include <power-domain-uclass.h>
 #include <dm/device-internal.h>
 
-struct power_domain_priv {
-	int on_count;
-};
-
 static inline struct power_domain_ops *power_domain_dev_ops(struct udevice *dev)
 {
 	return (struct power_domain_ops *)dev->driver->ops;
@@ -111,49 +107,22 @@ int power_domain_free(struct power_domain *power_domain)
 	return ops->rfree ? ops->rfree(power_domain) : 0;
 }
 
-int power_domain_on_lowlevel(struct power_domain *power_domain)
+int power_domain_on(struct power_domain *power_domain)
 {
-	struct power_domain_priv *priv = dev_get_uclass_priv(power_domain->dev);
 	struct power_domain_ops *ops = power_domain_dev_ops(power_domain->dev);
-	int ret;
 
 	debug("%s(power_domain=%p)\n", __func__, power_domain);
 
-	if (priv->on_count++ > 0)
-		return -EALREADY;
-
-	ret = ops->on ? ops->on(power_domain) : 0;
-	if (ret) {
-		priv->on_count--;
-		return ret;
-	}
-
-	return 0;
+	return ops->on ? ops->on(power_domain) : 0;
 }
 
-int power_domain_off_lowlevel(struct power_domain *power_domain)
+int power_domain_off(struct power_domain *power_domain)
 {
-	struct power_domain_priv *priv = dev_get_uclass_priv(power_domain->dev);
 	struct power_domain_ops *ops = power_domain_dev_ops(power_domain->dev);
-	int ret;
 
 	debug("%s(power_domain=%p)\n", __func__, power_domain);
 
-	if (priv->on_count <= 0) {
-		debug("Power domain %s already off.\n", power_domain->dev->name);
-		return -EALREADY;
-	}
-
-	if (priv->on_count-- > 1)
-		return -EBUSY;
-
-	ret = ops->off ? ops->off(power_domain) : 0;
-	if (ret) {
-		priv->on_count++;
-		return ret;
-	}
-
-	return 0;
+	return ops->off ? ops->off(power_domain) : 0;
 }
 
 #if CONFIG_IS_ENABLED(OF_REAL)
@@ -211,5 +180,4 @@ int dev_power_domain_off(struct udevice *dev)
 UCLASS_DRIVER(power_domain) = {
 	.id		= UCLASS_POWER_DOMAIN,
 	.name		= "power_domain",
-	.per_device_auto = sizeof(struct power_domain_priv),
 };
drivers/power/domain/sandbox-power-domain-test.c +0 -1
index 5b530974e94..08c15ef342b 100644
@@ -51,5 +51,4 @@ U_BOOT_DRIVER(sandbox_power_domain_test) = {
 	.id = UCLASS_MISC,
 	.of_match = sandbox_power_domain_test_ids,
 	.priv_auto	= sizeof(struct sandbox_power_domain_test),
-	.flags = DM_FLAG_DEFAULT_PD_CTRL_OFF,
 };
include/power-domain.h +8 -52

89 lines not on this page · raw message

test/dm/power-domain.c +1 -1
index 8a95f6bdb90..896cf5b2ae9 100644
@@ -27,7 +27,7 @@ static int dm_test_power_domain(struct unit_test_state *uts)
 
 	ut_assertok(uclass_get_device_by_name(UCLASS_MISC, "power-domain-test",
 					      &dev_test));
-	ut_asserteq(0, sandbox_power_domain_query(dev_power_domain,
+	ut_asserteq(1, sandbox_power_domain_query(dev_power_domain,
 						  TEST_POWER_DOMAIN));
 	ut_assertok(sandbox_power_domain_test_get(dev_test));
 
Signature · 1 line
2.34.1
Acked-by on v1 1/1
#1 lore raw

Hi Tom,

Quoted 6 lines · Wadim Egorov

Unfortunately this change breaks boot on K3 platform. U-Boot will hang after:

U-Boot SPL 2025.04-01050-ga40fc5afaec0 (Apr 14 2025 - 07:31:32 +0000) SYSFW ABI: 3.1 (firmware rev 0x0009 '9.2.7--v09.02.07 (Kool Koala)')

Quoted 6 lines

This reverts commit 197376fbf300e92afa0a1583815d9c9eb52d613a as suggested in [1].

[1] https://lists.denx.de/pipermail/u-boot/2025-April/587032.html

This sadly needs to get in, there have been 3 or 4 reports already, as many boards are broken. We need to find another way to add refcounting (otherwise some imx8* features will stay broken), but it requires more thinking time.

Thanks,
Miquèl

#2 lore raw

Hi Miquel,

Quoted 16 lines · Miquel Raynal

Hi Tom,

Quoted 11 lines · Wadim Egorov

Unfortunately this change breaks boot on K3 platform. U-Boot will hang after:

U-Boot SPL 2025.04-01050-ga40fc5afaec0 (Apr 14 2025 - 07:31:32 +0000) SYSFW ABI: 3.1 (firmware rev 0x0009 '9.2.7--v09.02.07 (Kool Koala)')

This reverts commit 197376fbf300e92afa0a1583815d9c9eb52d613a as suggested in [1].

[1] https://lists.denx.de/pipermail/u-boot/2025-April/587032.html

Quoted 8 lines
Quoted 1 line

This sadly needs to get in, there have been 3 or 4 reports already, as many boards are broken. We need to find another way to add refcounting (otherwise some imx8* features will stay broken), but it requires more thinking time.

We had this discussion on your patch and you ended up with a 'low-level' function to provide the base functionality. But it would be easier if you retained the current behaviour and then added ref-counting to two new functions. Then people can migrate.

Of course, people perhaps won't migrate. This sort of thing is quite tricky. But I still think this would be an easier route. You could perhaps even add a Kconfig option like POWER_DOMAIN_NO_REF_COUNT which uses the current behaviour.

Regards,
Simon

#3 lore raw

Hi Simon,

Quoted 11 lines
Quoted 6 lines

This sadly needs to get in, there have been 3 or 4 reports already, as many boards are broken. We need to find another way to add refcounting (otherwise some imx8* features will stay broken), but it requires more thinking time.

We had this discussion on your patch and you ended up with a 'low-level' function to provide the base functionality. But it would be easier if you retained the current behaviour and then added ref-counting to two new functions. Then people can migrate.

It's not the fact that people are using refcounting which breaks. It is the fact that the device model does not support well the fact that one DT node might be used to picture several devices. The clock subsystem handles that by registering all clocks manually, and at some point abuses one of the uclass internal structures (there is a FIXME about that). It's not even the drivers that break.

Quoted 4 lines

Of course, people perhaps won't migrate. This sort of thing is quite tricky. But I still think this would be an easier route. You could perhaps even add a Kconfig option like POWER_DOMAIN_NO_REF_COUNT which uses the current behaviour.

I now have an idea how to improve the power domain uclass to make it fit, let's see if that works, otherwise I might fallback to this solution indeed.

Thanks,
Miquèl

#4 lore raw
In reply to Wadim Egorov
Quoted 10 lines · Wadim Egorov

Unfortunately this change breaks boot on K3 platform. U-Boot will hang after:

U-Boot SPL 2025.04-01050-ga40fc5afaec0 (Apr 14 2025 - 07:31:32 +0000) SYSFW ABI: 3.1 (firmware rev 0x0009 '9.2.7--v09.02.07 (Kool Koala)')

This reverts commit 197376fbf300e92afa0a1583815d9c9eb52d613a as suggested in [1].

[...]

Applied to u-boot/master, thanks!

[1/1] Revert "power-domain: Add refcounting"

      commit: 71f497a6d3908574a1b1c3813c2a1385910f76bd
Signature · 1 line
Tom