power-domain: fix hang in endless loop on i.MX8
Subsystems (3)
PATCH v2 1/1 power-domain: fix hang in endless loop on i.MX8
Currently when booting the kernel on i.MX8 U-Boot hangs in an endless loop when switching off dma, connectivity or lsio power domains during device removal. It hapens first when removing gpio0 (gpio at 5d080000) device, here its power domain device 'lsio_gpio0' is obtained for switching off power. Since the obtained 'lsio_gpio0' device is removed afterwards, its power domain is also switched off and here the parent power domain device 'lsio_power_domain' is optained for switching off the power. Thereafter, when the obtained 'lsio_power_domain' is removed, device_remove() removes its first child 'lsio_gpio0'. During this child removal the 'lsio_power_domain' device is obtained again for switching and when removing it later, the same child removal is repeated, so we are stuck in an endless loop. Below is a snippet from dm tree on i.MX8QXP for better illustration of the DM devices relationship:
Class Index Probed Driver Name
-----------------------------------------------------------
root 0 [ + ] root_driver root_driver
...
simple_bus 0 [ + ] generic_simple_bus |-- imx8qx-pm power_doma 0 [ + ] imx8_power_domain | |-- lsio_power_domain power_doma 1 [ + ] imx8_power_domain | | |-- lsio_gpio0 power_doma 2 [ + ] imx8_power_domain | | |-- lsio_gpio1
Do not remove a power domain device if it is a parent of the currently controlled device.
---
Changes in v2:
- drop braces
- add RB tags
drivers/power/domain/power-domain-uclass.c | 11 +++++++++++ 1 file changed, 11 insertions(+)
drivers/power/domain/power-domain-uclass.c +11 -0
@@ -127,6 +127,17 @@ static int dev_power_domain_ctrl(struct udevice *dev, bool on) ret =power_domain_off (&pd); } +/* +* For platforms with parent and child power-domain devices +* we may not run device_remove() on the power-domain parent +* because it will result in removing its children and switching +* off their power-domain parent. So we will get here again and +* again and will be stuck in an endless loop. +*/ +if (!on &&dev_get_parent (dev) == pd.dev && +device_get_uclass_id (dev) ==UCLASS_POWER_DOMAIN ) +return ret; +/* * power_domain_get() bound the device, thus * we must remove it again to prevent unbinding
Signature · 1 line
2.17.1
Fabio Estevam
reviewerPATCH v2 1/1 power-domain: fix hang in endless loop on i.MX8
Hi Anatolij,
Quoted 26 lines · Anatolij Gustschin
Currently when booting the kernel on i.MX8 U-Boot hangs in an endless loop when switching off dma, connectivity or lsio power domains during device removal. It hapens first when removing gpio0 (gpio at
5d080000) device, here its power domain device 'lsio_gpio0' is obtained for switching off power. Since the obtained 'lsio_gpio0' device is removed afterwards, its power domain is also switched off and here the parent power domain device 'lsio_power_domain' is optained for switching off the power. Thereafter, when the obtained 'lsio_power_domain' is removed,device_remove()removes its first child 'lsio_gpio0'. During this child removal the 'lsio_power_domain' device is obtained again for switching and when removing it later, the same child removal is repeated, so we are stuck in an endless loop. Below is a snippet from dm tree on i.MX8QXP for better illustration of the DM devices relationship:Class Index Probed Driver Name
-----------------------------------------------------------
root 0 [ + ]root_driverroot_driver
...simple_bus 0 [ + ] generic_simple_bus |-- imx8qx-pm power_doma 0 [ + ] imx8_power_domain | |-- lsio_power_domain power_doma 1 [ + ] imx8_power_domain | | |-- lsio_gpio0 power_doma 2 [ + ] imx8_power_domain | | |-- lsio_gpio1
Quoted 5 lines
Do not remove a power domain device if it is a parent of the currently controlled device.
Fixes 52edfed65de9 ("dm: core: device: switch off power domain after device removal")Signed-off-by Anatolij Gustschin <[email protected]>
I also had to apply the following change in order to boot a i.MX8QXP MEK board:
arch/arm/mach-imx/imx8/fdt.c +2 -0
@@ -280,6 +280,8 @@ int ft_system_setup(void *blob, bd_t *bd) {int ret; +return 0 ; +update_fdt_with_owned_resources (blob);if (is_imx8qm ()) {
With your patch and this change a 4.14.98 NXP kernel can boot, but not a 4.19.35 NXP nor a mainline kernel.
Fabio Estevam
reviewerPATCH v2 1/1 power-domain: fix hang in endless loop on i.MX8
Quoted 14 lines · Fabio Estevam
I also had to apply the following change in order to boot a i.MX8QXP MEK board:
arch/arm/mach-imx/imx8/fdt.c +2
-0@@ -280,6 +280,8 @@ int ft_system_setup(void *blob, bd_t *bd) {int ret; +return 0 ; +update_fdt_with_owned_resources (blob);if (is_imx8qm ()) {
Quoted 4 lines
With your patch and this change a 4.14.98 NXP kernel can boot, but not a 4.19.35 NXP nor a mainline kernel.
Tested-by Fabio Estevam <[email protected]>
Correction: the above change is not needed now.
I saw an issue with the command line and I sent a fix.
This patch plus the one that fixes the command line are enough to get i.MX8QXP MEK board booting a mainline kernel.
Thanks
PATCH v2 1/1 power-domain: fix hang in endless loop on i.MX8
In reply to Anatolij GustschinQuoted 16 lines · Anatolij Gustschin
Currently when booting the kernel on i.MX8 U-Boot hangs in an endless loop when switching off dma, connectivity or lsio power domains during device removal. It hapens first when removing gpio0 (gpio at
5d080000) device, here its power domain device 'lsio_gpio0' is obtained for switching off power. Since the obtained 'lsio_gpio0' device is removed afterwards, its power domain is also switched off and here the parent power domain device 'lsio_power_domain' is optained for switching off the power. Thereafter, when the obtained 'lsio_power_domain' is removed,device_remove()removes its first child 'lsio_gpio0'. During this child removal the 'lsio_power_domain' device is obtained again for switching and when removing it later, the same child removal is repeated, so we are stuck in an endless loop. Below is a snippet from dm tree on i.MX8QXP for better illustration of the DM devices relationship:
Quoted 1 line
Class Index Probed Driver Name
Applied to u-boot/master, thanks!
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 659 bytes Desc: not available URL: <https://lists.denx.de/pipermail/u-boot/attachments/20200310/fbf36c15/attachment.sig>