From patchwork Sat Feb 15 11:34:43 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anatolij Gustschin X-Patchwork-Id: 1238491 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=85.214.62.61; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=denx.de Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=denx.de header.i=@denx.de header.a=rsa-sha256 header.s=phobos-20191101 header.b=vsDqyf3u; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 48KSpY0zp0z9sNg for ; Sat, 15 Feb 2020 22:34:57 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id AD53080257; Sat, 15 Feb 2020 12:34:50 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=denx.de Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=denx.de; s=phobos-20191101; t=1581766490; bh=jmF/ySGMYDRvDvm7P7W7qDU+3decD3YPtnT13pN5Jd8=; h=From:To:Cc:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From; b=vsDqyf3uGaihAVw0eNMz9pG+pqDhW4RoW863FJ4F5h5v6TGCBZ/6GJJJG3CZSjK4v Z5xl4nEdwHYF67Z/jfSk4F0aeRUyN9XBeumUkLQU3OAPfqUCYR9INTTJDLc4XKWOOz xPg8b105Ca0llgA78aOEniT813QQ5IKkpxP2HaVA8cXNGHBMx0L39tWXXpHzuK6p+a A4AE+dIq2tmlQBcTIHi0ZirgN4EMM904Tf37HZ0K0SYML5Sx6VXLCzaTTXYSOyfkAh CnxK5I3QLGGa2ZVcmq+by8hondQUqQIkqycWa+GEQCw/AtyNU6NCzRWi8RqTmowLag HUW7exkpZH+Ig== Received: by phobos.denx.de (Postfix, from userid 109) id A770D80251; Sat, 15 Feb 2020 12:34:48 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-out.m-online.net (mail-out.m-online.net [212.18.0.9]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 149CB80251 for ; Sat, 15 Feb 2020 12:34:46 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=denx.de Authentication-Results: phobos.denx.de; spf=none smtp.mailfrom=agust@denx.de Received: from frontend01.mail.m-online.net (unknown [192.168.8.182]) by mail-out.m-online.net (Postfix) with ESMTP id 48KSpF16kZz1qqkh; Sat, 15 Feb 2020 12:34:45 +0100 (CET) Received: from localhost (dynscan1.mnet-online.de [192.168.6.70]) by mail.m-online.net (Postfix) with ESMTP id 48KSpF0MdWz1r0bd; Sat, 15 Feb 2020 12:34:45 +0100 (CET) Received: from mail.mnet-online.de ([192.168.8.182]) by localhost (dynscan1.mail.m-online.net [192.168.6.70]) (amavisd-new, port 10024) with ESMTP id 02KEUS6HczxB; Sat, 15 Feb 2020 12:34:43 +0100 (CET) X-Auth-Info: 4MmyGPb61XnMqgOxcJ5a3Fw8bqt1aQi7yFuTlbuJE/o= Received: from crub.agik.hopto.org (pD95F1BAA.dip0.t-ipconnect.de [217.95.27.170]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.mnet-online.de (Postfix) with ESMTPSA; Sat, 15 Feb 2020 12:34:43 +0100 (CET) From: Anatolij Gustschin To: u-boot@lists.denx.de Cc: festevam@gmail.com, jh80.chung@samsung.com, lokeshvutla@ti.com, oliver.graute@gmail.com, peng.fan@nxp.com, sjg@chromium.org Subject: [PATCH] power-domain: fix hang in endless loop on i.MX8 Date: Sat, 15 Feb 2020 12:34:43 +0100 Message-Id: <20200215113443.6866-1-agust@denx.de> X-Mailer: git-send-email 2.17.1 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.30rc1 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.102.1 at phobos.denx.de X-Virus-Status: Clean 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@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. Fixes: 52edfed65de9 ("dm: core: device: switch off power domain after device removal") Signed-off-by: Anatolij Gustschin Reported-by: Oliver Graute Reported-by: Fabio Estevam Reviewed-by: Simon Glass Reviewed-by: Lokesh Vutla --- drivers/power/domain/power-domain-uclass.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/drivers/power/domain/power-domain-uclass.c b/drivers/power/domain/power-domain-uclass.c index d9c623b56e..d8fe4d4877 100644 --- a/drivers/power/domain/power-domain-uclass.c +++ b/drivers/power/domain/power-domain-uclass.c @@ -127,6 +127,18 @@ 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