Hello Miquel,

Thanks for the fast fix, and sorry, that I did not found the
time to look into faster...

On 25.04.25 08:49, Miquel Raynal wrote:
It is very surprising that such an uclass, specifically designed to
handle resources that may be shared by different devices, is not keeping
the count of the number of times a power domain has been
enabled/disabled to avoid shutting it down unexpectedly or disabling it
several times.

Doing this causes troubles on eg. i.MX8MP because disabling power
domains can be done in recursive loops were the same power domain
disabled up to 4 times in a row. PGCs seem to have tight FSM internal
timings to respect and it is easy to produce a race condition that puts
the power domains in an unstable state, leading to ADB400 errors and
later crashes in Linux.

Some drivers implement their own mechanism for that, but it is probably
best to add this feature in the uclass and share the common code across
drivers. In order to avoid breaking existing drivers, refcounting is
only enabled if the number of subdomains a device node supports is
explicitly set in the probe function. ->xlate() callbacks will return
the power domain ID which is then being used as the array index to reach
the correct refcounter.

As we do not want to break existing users while stile getting
interesting error codes, the implementation is split between:
- a low-level helper reporting error codes if the requested transition
   could not be operated,
- a higher-level helper ignoring the "non error" codes, like EALREADY and
   EBUSY.

CI tests using power domains are slightly updated to make sure the count
of on/off calls is even and the results match what we *now* expect. They
are also extended to test the low-level functions.

Signed-off-by: Miquel Raynal <miquel.ray...@bootlin.com>
---
  arch/sandbox/include/asm/power-domain.h          |  2 +
  drivers/firmware/scmi/sandbox-scmi_devices.c     |  1 +
  drivers/power/domain/power-domain-uclass.c       | 90 ++++++++++++++++++++++--
  drivers/power/domain/sandbox-power-domain-test.c | 15 ++++
  drivers/power/domain/sandbox-power-domain.c      |  4 ++
  include/power-domain.h                           | 69 +++++++++++++++---
  test/dm/power-domain.c                           | 11 ++-
  7 files changed, 177 insertions(+), 15 deletions(-)

after reverting locally commit "197376fbf300e92afa0a1583815d9c9eb52d613a."
and applying this patch and patch 2/2 of this series, "pci enum"
works again on imx8mp based board:

u-boot=> pci enum
PCIE-0: Link up (Gen1-x1, Bus0)
u-boot=> print update_ub_emmc
update_ub_emmc=run prepemmc loadub updub cmpub
u-boot=> run loadub
e1000: 00:30:d6:39:7a:c1
       e1000: 00:30:d6:39:7a:c2
       Using e1000#1 device
TFTP from server 192.168.3.1; our IP address is 192.168.3.51
Filename 'lec/20250327/flash.bin.4g'.
Load address: 0x50000000
Loading: ##################################################  2 MiB
         354.5 KiB/s
done
Bytes transferred = 2097152 (200000 hex)
u-boot=>

Thanks!

Reviewed-by: Heiko Schocher <h...@denx.de>
Tested-by: Heiko Schocher <h...@denx.de>

bye,
Heiko
--
DENX Software Engineering GmbH,      Managing Director: Erika Unter
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: +49-8142-66989-52   Fax: +49-8142-66989-80   Email: h...@denx.de

Reply via email to