From patchwork Wed Nov 2 14:21:01 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shawn Guo X-Patchwork-Id: 13028202 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2DE67C43219 for ; Wed, 2 Nov 2022 14:22:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231391AbiKBOV6 (ORCPT ); Wed, 2 Nov 2022 10:21:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48798 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231462AbiKBOVs (ORCPT ); Wed, 2 Nov 2022 10:21:48 -0400 Received: from mail-pl1-x634.google.com (mail-pl1-x634.google.com [IPv6:2607:f8b0:4864:20::634]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6CB3029CB7 for ; Wed, 2 Nov 2022 07:21:46 -0700 (PDT) Received: by mail-pl1-x634.google.com with SMTP id b21so853377plc.9 for ; Wed, 02 Nov 2022 07:21:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=ODaPlzoiM2wGPR3JeVuPfzDqwHYUcKlkdeyiRb2Q0lw=; b=dak2HCVpbEaeVp7CSu+TOT5ppVs2qsQOQoQSzIcU5YzTb/X4cctoidWvx1Y+mWXgJC rXX14WjJcAycOPiZAuyD4EzZv2OO5H4Q/wDFdS3UAgSZdiPyC2TKLzRvcKzZBENjx8ru 5e2yu0z4x08FDLahkeTp4/kViprl7KWaAGk2SlNTVWpTrZ62TIDl1s8J5d+EFO3dSFky SI+BDDgi1kOnposCaxtKTnpGtgGRzbqLpkduGlzGqiNb1rKPmGgVaMh4lLPGhknmmoWv njo7EXv22zsqXyOUBlSzmhOAs2/e0UMzhM4TXQP7R76rtCXpCKE/QzvkWvarmcNiUYhJ NWTg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ODaPlzoiM2wGPR3JeVuPfzDqwHYUcKlkdeyiRb2Q0lw=; b=yhzhCyZvbySJV5r+stYo7VcWMZ4B+qIwW+PbUdanKw7oSJ/xhmwH7ir1sGigdEziMQ Iw641v+wMj+Uc5DS+vkNdnDtX+Fflune2sbBGxZ0vIKgU+hHKsbtMsDKPghCJ60WXO14 UmrM1oNTnSOhEhqbvMzHduWjmPX5Dbr+8Yl7PWkOtwyrOlRrMYz89ounmNwPItpZUlUi wbStbn+XbytbG04MyC89+P45vTtrNEqbdGdoxq1ks6bCpY66tcfXbdiHXlcnKeQyzsXn LAouOc/pKsZWvVAaGRZkCHjNF4Pk6DdJVIv2npcnEXmQsDWL//Txr3q4XwWPBwawHCeM 6Tdg== X-Gm-Message-State: ACrzQf26DWEZEkg2xTIfbhqlMEPjVYJTEkQFiC3pgx//faBasFE/0iTc hezvQXQKFMdGfj0Tyr8lgOk0Yw== X-Google-Smtp-Source: AMsMyM5+KOZ2eFs9n0BP9un2hL/Hu0/DT+cdPD/ekZdtg2xoj2pGgUf72pgOM6m+al2whrRTmykuEw== X-Received: by 2002:a17:90b:164d:b0:213:6a84:2529 with SMTP id il13-20020a17090b164d00b002136a842529mr26114236pjb.32.1667398905990; Wed, 02 Nov 2022 07:21:45 -0700 (PDT) Received: from localhost.localdomain (80.251.214.228.16clouds.com. [80.251.214.228]) by smtp.gmail.com with ESMTPSA id o28-20020aa7979c000000b0056b8181861esm8817773pfp.19.2022.11.02.07.21.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Nov 2022 07:21:45 -0700 (PDT) From: Shawn Guo To: "Rafael J . Wysocki" Cc: Kevin Hilman , Ulf Hansson , Len Brown , Pavel Machek , Greg Kroah-Hartman , linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, Shawn Guo Subject: [PATCH v3 1/4] PM: domains: Drop genpd status manipulation for hibernate restore Date: Wed, 2 Nov 2022 22:21:01 +0800 Message-Id: <20221102142104.2006554-2-shawn.guo@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20221102142104.2006554-1-shawn.guo@linaro.org> References: <20221102142104.2006554-1-shawn.guo@linaro.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org The genpd status manipulation for hibernate restore has really never worked as intended. For example, if the genpd->status was GENPD_STATE_ON, the parent domain's `sd_count` must have been increased, so it needs to be adjusted too. So drop this status manipulation. Suggested-by: Ulf Hansson Signed-off-by: Shawn Guo Reviewed-by: Ulf Hansson --- drivers/base/power/domain.c | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/drivers/base/power/domain.c b/drivers/base/power/domain.c index 6471b559230e..97deae1d4e77 100644 --- a/drivers/base/power/domain.c +++ b/drivers/base/power/domain.c @@ -1374,20 +1374,7 @@ static int genpd_restore_noirq(struct device *dev) if (IS_ERR(genpd)) return -EINVAL; - /* - * At this point suspended_count == 0 means we are being run for the - * first time for the given domain in the present cycle. - */ genpd_lock(genpd); - if (genpd->suspended_count++ == 0) { - /* - * The boot kernel might put the domain into arbitrary state, - * so make it appear as powered off to genpd_sync_power_on(), - * so that it tries to power it on in case it was really off. - */ - genpd->status = GENPD_STATE_OFF; - } - genpd_sync_power_on(genpd, true, 0); genpd_unlock(genpd); From patchwork Wed Nov 2 14:21:02 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shawn Guo X-Patchwork-Id: 13028203 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8B753C4321E for ; Wed, 2 Nov 2022 14:22:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231481AbiKBOV6 (ORCPT ); Wed, 2 Nov 2022 10:21:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48192 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231511AbiKBOVv (ORCPT ); Wed, 2 Nov 2022 10:21:51 -0400 Received: from mail-pj1-x1033.google.com (mail-pj1-x1033.google.com [IPv6:2607:f8b0:4864:20::1033]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BCE0221E3E for ; Wed, 2 Nov 2022 07:21:49 -0700 (PDT) Received: by mail-pj1-x1033.google.com with SMTP id m14-20020a17090a3f8e00b00212dab39bcdso2304544pjc.0 for ; Wed, 02 Nov 2022 07:21:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=u3X2UOS5GCzAk+RwX2Y3XrY61x6yZgTDSncBoSeqZLI=; b=tP92GVRcbpnSB3xByd6EKkdFhI2ZZxEFq+0qM0sGK5E+2xuX6AHz+yeAWxUIRaFqur AU3x3apJWWF5aeMB+VrgbTciJbWFSd7zo/WZRF0pEi6LgmVXPO30AYNBoO4+G1hi/ijt 1jncQwvWehSCooj+r+y0aIOk9l0rxvB2kRewercVL8R3IktqPtZmqyZL3QkQ6rNA8aaH sSWEgANy+SHsjEpUjsN1OFjRilyWolHnh19b+FyPKhNuePvhf/m2OEyd8w3gyckD3uT8 H7rF1A9ldjjt0b0xjFv51yGzcZAdkPZb6ew+0hEWjN3+HqnrTHMTyc9s0FU4QbCmrLvD P17A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=u3X2UOS5GCzAk+RwX2Y3XrY61x6yZgTDSncBoSeqZLI=; b=eLkDWPzziSxy4/jf96KejKQES20d1o6TCyaTrd+0Gx54hkV1Iz2F7EpG2eYKUC9SXl lmVqWG+vbL2/nK33R/hR/FeKmOhQY6usO9hdALYYP+hFL8PV0wogWsNPDBe8+q/PxIRb rJzDpD1P16+QhDqEY0w6ZPkqH6nUlKqze95ZYPzhp7JEAHbtbOatgcwG9XZiGk9WGnuM A4ER570LJf1UbOfUU0S77d0YHEoV9y8gPFr95JiQcNF4V70KkcNY/UPQDrH1qMSvVegr uMeAfjH+gqg+L88YWVcYFh6wbfmp06H6VV7f1kzMbiFAPTgxJVkhJYO5vFkCQ4DLijd4 bfEA== X-Gm-Message-State: ACrzQf3iQwMWWEWz04QzBid7g6wpH/vtFhDX6NdrAQOcCzlLV+50PIe7 b06HtTVmS4vXiaJLnoIjCDD5TA== X-Google-Smtp-Source: AMsMyM5/desmGwo//lnCNuPp/LhooK+lM+AiUwQtTK6uVMwC4hR5ggGtuEkCyD1JSMcpyjgnrGVKrg== X-Received: by 2002:a17:903:188:b0:187:dd28:5fc1 with SMTP id z8-20020a170903018800b00187dd285fc1mr2273476plg.26.1667398909278; Wed, 02 Nov 2022 07:21:49 -0700 (PDT) Received: from localhost.localdomain (80.251.214.228.16clouds.com. [80.251.214.228]) by smtp.gmail.com with ESMTPSA id o28-20020aa7979c000000b0056b8181861esm8817773pfp.19.2022.11.02.07.21.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Nov 2022 07:21:48 -0700 (PDT) From: Shawn Guo To: "Rafael J . Wysocki" Cc: Kevin Hilman , Ulf Hansson , Len Brown , Pavel Machek , Greg Kroah-Hartman , linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, Shawn Guo Subject: [PATCH v3 2/4] PM: domains: Pass generic PM noirq hooks to genpd_finish_suspend() Date: Wed, 2 Nov 2022 22:21:02 +0800 Message-Id: <20221102142104.2006554-3-shawn.guo@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20221102142104.2006554-1-shawn.guo@linaro.org> References: <20221102142104.2006554-1-shawn.guo@linaro.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org While argument `poweroff` works fine for genpd_finish_suspend() to handle distinction between suspend and poweroff, it won't scale if we want to use it for freeze as well. Pass generic PM noirq hooks as arguments instead, so that the function can possibly cover freeze case too. Signed-off-by: Shawn Guo Reviewed-by: Ulf Hansson --- drivers/base/power/domain.c | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/drivers/base/power/domain.c b/drivers/base/power/domain.c index 97deae1d4e77..f18b8b1bc17a 100644 --- a/drivers/base/power/domain.c +++ b/drivers/base/power/domain.c @@ -1189,12 +1189,15 @@ static int genpd_prepare(struct device *dev) * genpd_finish_suspend - Completion of suspend or hibernation of device in an * I/O pm domain. * @dev: Device to suspend. - * @poweroff: Specifies if this is a poweroff_noirq or suspend_noirq callback. + * @suspend_noirq: Generic suspend_noirq callback. + * @resume_noirq: Generic resume_noirq callback. * * Stop the device and remove power from the domain if all devices in it have * been stopped. */ -static int genpd_finish_suspend(struct device *dev, bool poweroff) +static int genpd_finish_suspend(struct device *dev, + int (*suspend_noirq)(struct device *dev), + int (*resume_noirq)(struct device *dev)) { struct generic_pm_domain *genpd; int ret = 0; @@ -1203,10 +1206,7 @@ static int genpd_finish_suspend(struct device *dev, bool poweroff) if (IS_ERR(genpd)) return -EINVAL; - if (poweroff) - ret = pm_generic_poweroff_noirq(dev); - else - ret = pm_generic_suspend_noirq(dev); + ret = suspend_noirq(dev); if (ret) return ret; @@ -1217,10 +1217,7 @@ static int genpd_finish_suspend(struct device *dev, bool poweroff) !pm_runtime_status_suspended(dev)) { ret = genpd_stop_dev(genpd, dev); if (ret) { - if (poweroff) - pm_generic_restore_noirq(dev); - else - pm_generic_resume_noirq(dev); + resume_noirq(dev); return ret; } } @@ -1244,7 +1241,9 @@ static int genpd_suspend_noirq(struct device *dev) { dev_dbg(dev, "%s()\n", __func__); - return genpd_finish_suspend(dev, false); + return genpd_finish_suspend(dev, + pm_generic_suspend_noirq, + pm_generic_resume_noirq); } /** @@ -1353,7 +1352,9 @@ static int genpd_poweroff_noirq(struct device *dev) { dev_dbg(dev, "%s()\n", __func__); - return genpd_finish_suspend(dev, true); + return genpd_finish_suspend(dev, + pm_generic_poweroff_noirq, + pm_generic_restore_noirq); } /** From patchwork Wed Nov 2 14:21:03 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shawn Guo X-Patchwork-Id: 13028204 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3DAFAC4332F for ; Wed, 2 Nov 2022 14:22:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230516AbiKBOWa (ORCPT ); Wed, 2 Nov 2022 10:22:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48798 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231624AbiKBOV4 (ORCPT ); Wed, 2 Nov 2022 10:21:56 -0400 Received: from mail-pj1-x1034.google.com (mail-pj1-x1034.google.com [IPv6:2607:f8b0:4864:20::1034]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 162A627CD1 for ; Wed, 2 Nov 2022 07:21:53 -0700 (PDT) Received: by mail-pj1-x1034.google.com with SMTP id p15-20020a17090a348f00b002141615576dso2236352pjb.4 for ; Wed, 02 Nov 2022 07:21:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=GG7lcQ6B6Fm/T8LV8zudWuwDEbtHmTF64TDq9Olscfs=; b=PvzIPDEaMTxlCBzHeWB28vY0jwJKBCLL1AR3V06rmFooumUv1jPop0oiy7VlFAab+8 9X2W/hENaPNuh5hwH030LiHExwbxx4PlOmsmhD37ydMeugOoka5U3ADPw4TZkwYvqPG8 IcWS6xYmcj32PB2fh79Kk7136zg1voEKRW91DGoBHR+kFgIL69TrJ5foYR3hrZlaOdxQ o7m+EMklaYGDOO2e0ROew1+eXiH0eV1GwwXB9b893TqSRX7QJr9c/57qQENio0fe+fih z2gjPV6x1XGWkeSYnElgigWVp0yt8ShTlAptC14iiTL/YHnjSE2qi7Efuo1um5IF/s5V p2Tg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=GG7lcQ6B6Fm/T8LV8zudWuwDEbtHmTF64TDq9Olscfs=; b=bWuYCOClZUBdMmG+63bUL6VmnukpJGo9DyPFCdr2b9mcrWUZ/evo5v1IIMNl9zifTm Ev4wfbyS0GKz3B7l7UDhpQY4P1OW0OoMy0uIC++sayK5WkQzwUpmMkQw2UBUjcAz/H9f QTU9eb2JgbmwLNpWCsJvhWCAKbCQDdLsP8nBC05FkreIrPvE0Ww0r533mJY3nm3MaFh3 F+DGxIRDd+6i0OWVfydye7ZbOp724DYKepanIG63+UB8DWTFwGvE+G60drH0syYe8iMx TiUhzdI8ZhbPB35L+VPEjPNyyxmkirIE81k6ahq7hZR0OqVxJO26Ez6WhfbUcy5uXdwm 2EbQ== X-Gm-Message-State: ACrzQf3VZCap03J9iE/prIHPnvNcmh18DCs2D6OPr74tXtQwK4+Chrs8 HKknba9ervfOIPKcjdPw51PmpA== X-Google-Smtp-Source: AMsMyM6/WinPB5KRYZObewr0hl5APcRQ/dnj/+cDkzbklVPh+D60qhSJi1NZIsDHkDGFkh0xYnj2Gw== X-Received: by 2002:a17:902:8a93:b0:17f:66ae:b6c with SMTP id p19-20020a1709028a9300b0017f66ae0b6cmr25058677plo.94.1667398912588; Wed, 02 Nov 2022 07:21:52 -0700 (PDT) Received: from localhost.localdomain (80.251.214.228.16clouds.com. [80.251.214.228]) by smtp.gmail.com with ESMTPSA id o28-20020aa7979c000000b0056b8181861esm8817773pfp.19.2022.11.02.07.21.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Nov 2022 07:21:52 -0700 (PDT) From: Shawn Guo To: "Rafael J . Wysocki" Cc: Kevin Hilman , Ulf Hansson , Len Brown , Pavel Machek , Greg Kroah-Hartman , linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, Shawn Guo Subject: [PATCH v3 3/4] PM: domains: Consolidate genpd_restore_noirq() and genpd_resume_noirq() Date: Wed, 2 Nov 2022 22:21:03 +0800 Message-Id: <20221102142104.2006554-4-shawn.guo@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20221102142104.2006554-1-shawn.guo@linaro.org> References: <20221102142104.2006554-1-shawn.guo@linaro.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org Most of the logic between genpd_restore_noirq() and genpd_resume_noirq() are identical. The suspended_count decrement for restore should be the right thing to do anyway, considering there is an increment in genpd_finish_suspend() for hibernation. So consolidate these two functions into genpd_finish_resume(). Signed-off-by: Shawn Guo Reviewed-by: Ulf Hansson --- drivers/base/power/domain.c | 41 +++++++++++++++++-------------------- 1 file changed, 19 insertions(+), 22 deletions(-) diff --git a/drivers/base/power/domain.c b/drivers/base/power/domain.c index f18b8b1bc17a..7cee9439fd21 100644 --- a/drivers/base/power/domain.c +++ b/drivers/base/power/domain.c @@ -1247,12 +1247,14 @@ static int genpd_suspend_noirq(struct device *dev) } /** - * genpd_resume_noirq - Start of resume of device in an I/O PM domain. + * genpd_finish_resume - Completion of resume of device in an I/O PM domain. * @dev: Device to resume. + * @resume_noirq: Generic resume_noirq callback. * * Restore power to the device's PM domain, if necessary, and start the device. */ -static int genpd_resume_noirq(struct device *dev) +static int genpd_finish_resume(struct device *dev, + int (*resume_noirq)(struct device *dev)) { struct generic_pm_domain *genpd; int ret; @@ -1264,7 +1266,7 @@ static int genpd_resume_noirq(struct device *dev) return -EINVAL; if (device_wakeup_path(dev) && genpd_is_active_wakeup(genpd)) - return pm_generic_resume_noirq(dev); + return resume_noirq(dev); genpd_lock(genpd); genpd_sync_power_on(genpd, true, 0); @@ -1281,6 +1283,19 @@ static int genpd_resume_noirq(struct device *dev) return pm_generic_resume_noirq(dev); } +/** + * genpd_resume_noirq - Start of resume of device in an I/O PM domain. + * @dev: Device to resume. + * + * Restore power to the device's PM domain, if necessary, and start the device. + */ +static int genpd_resume_noirq(struct device *dev) +{ + dev_dbg(dev, "%s()\n", __func__); + + return genpd_finish_resume(dev, pm_generic_resume_noirq); +} + /** * genpd_freeze_noirq - Completion of freezing a device in an I/O PM domain. * @dev: Device to freeze. @@ -1366,27 +1381,9 @@ static int genpd_poweroff_noirq(struct device *dev) */ static int genpd_restore_noirq(struct device *dev) { - struct generic_pm_domain *genpd; - int ret = 0; - dev_dbg(dev, "%s()\n", __func__); - genpd = dev_to_genpd(dev); - if (IS_ERR(genpd)) - return -EINVAL; - - genpd_lock(genpd); - genpd_sync_power_on(genpd, true, 0); - genpd_unlock(genpd); - - if (genpd->dev_ops.stop && genpd->dev_ops.start && - !pm_runtime_status_suspended(dev)) { - ret = genpd_start_dev(genpd, dev); - if (ret) - return ret; - } - - return pm_generic_restore_noirq(dev); + return genpd_finish_resume(dev, pm_generic_restore_noirq); } /** From patchwork Wed Nov 2 14:21:04 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Shawn Guo X-Patchwork-Id: 13028205 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9D5D9C433FE for ; Wed, 2 Nov 2022 14:22:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231625AbiKBOWc (ORCPT ); Wed, 2 Nov 2022 10:22:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49128 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231441AbiKBOV5 (ORCPT ); Wed, 2 Nov 2022 10:21:57 -0400 Received: from mail-pl1-x634.google.com (mail-pl1-x634.google.com [IPv6:2607:f8b0:4864:20::634]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 55CA41F613 for ; Wed, 2 Nov 2022 07:21:56 -0700 (PDT) Received: by mail-pl1-x634.google.com with SMTP id d24so16727570pls.4 for ; Wed, 02 Nov 2022 07:21:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=c/pMCaexTxPLJj78ppz2hR1Nnq2hMOxwXWSwZaAwP1o=; b=v2KPaSNwlUsp7p+WI5eQrzk4CxEQ6P+VRict3TlT67cdkOV/KtVsTQn1bBV14Y2xFO M8iBDtfXrhY2DbRs3tQQNOkLjkdUY82UJJqDY+Yl/unoGbQJNfn398w3vhZPkbwkrS2h 5JC21Q1z1i3DqZn9MSKDNQEhrzRa0DvrsJKeuxCwN4H0Za6QySEnjA90r53MOB9JEY0w UMISsBQmaJHGYYCzVoSXOGHlHeaahNz1VAxpoL4LfN/bcaTQ3gGtzt0fqqGW183CHhjC w1FSWrIobeM+RnDn2GHoAUhyA07K5CPRng9lsDQuK1MpgoOo3DiUlY/lSh6Ke8Q6EUv7 o7jA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=c/pMCaexTxPLJj78ppz2hR1Nnq2hMOxwXWSwZaAwP1o=; b=PVYAJsGpErdEUqXoGH2fJ87JLnKePgVyMdnWfR3gLfAu9Wj1nLUOuo31AaAsaf7fUD DpQDgNQ5Td0yJoe4gU/Xw64R9QV/iH/I2gbnyWonqcR0/Xj2vydbPOSrP+CtYYiAZUpj dsdtEP/IPep9X4wNoYEvMue3HQPY0Wz3FnlVxwfBIL0PpAqRK7+N3Q35twhxgy3OVJAq ZPK8RYIW9GcEGRCF9jP5RfYASAiHuprJFrJiF2L6UdTdDU5vvcy96j5GKVcYkMoRRX7x Kg/eR4WhaMuBZ97qMBp5dKmn5IlpWHpoJDZcVcPx/5O38Zy98prTtk3sMH94nIj0nlJT sezQ== X-Gm-Message-State: ACrzQf04IgcfXwRaEBztXou3/RIyMT7sAj/Y1jaDvRNZnInfJEmKk3ty Nc1EiQZoeUhTShzDy6iankoxYw== X-Google-Smtp-Source: AMsMyM4qK/lnzUIzNqln7RZX8vMCbyXMe2wNHwxwm70Vj3P2QkQS7yGpFjKhbkoOYB6isVoY+KTCpA== X-Received: by 2002:a17:903:11c4:b0:178:634b:1485 with SMTP id q4-20020a17090311c400b00178634b1485mr24234234plh.142.1667398915892; Wed, 02 Nov 2022 07:21:55 -0700 (PDT) Received: from localhost.localdomain (80.251.214.228.16clouds.com. [80.251.214.228]) by smtp.gmail.com with ESMTPSA id o28-20020aa7979c000000b0056b8181861esm8817773pfp.19.2022.11.02.07.21.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Nov 2022 07:21:55 -0700 (PDT) From: Shawn Guo To: "Rafael J . Wysocki" Cc: Kevin Hilman , Ulf Hansson , Len Brown , Pavel Machek , Greg Kroah-Hartman , linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, Shawn Guo Subject: [PATCH v3 4/4] PM: domains: Power off[on] domain in hibernate .freeze[thaw]_noirq hook Date: Wed, 2 Nov 2022 22:21:04 +0800 Message-Id: <20221102142104.2006554-5-shawn.guo@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20221102142104.2006554-1-shawn.guo@linaro.org> References: <20221102142104.2006554-1-shawn.guo@linaro.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org On platforms which use SHUTDOWN as hibernation mode, the genpd noirq hooks will be called like below. genpd_freeze_noirq() genpd_restore_noirq() ↓ ↑ Create snapshot image Restore target kernel ↓ ↑ genpd_thaw_noirq() genpd_freeze_noirq() ↓ ↑ Write snapshot image Read snapshot image ↓ ↑ power_down() Kernel boot As of today suspend hooks genpd_suspend[resume]_noirq() manages domain on/off state, but hibernate hooks genpd_freeze[thaw]_noirq() doesn't. This results in a different behavior of domain power state between suspend and hibernate freeze, i.e. domain is powered off for the former while on for the later. It causes a problem on platforms like i.MX where the domain needs to be powered on/off by calling clock and regulator interface. When the platform restores from hibernation, the domain is off in hardware and genpd_restore_noirq() tries to power it on, but will never succeed because software state of domain (clock and regulator) is left on from the last hibernate freeze, so kernel thinks that clock and regulator are enabled while they are actually not turned on in hardware. The consequence would be that devices in the power domain will access registers without clock or power, and cause hardware lockup. Power off[on] domain in hibernate .freeze[thaw]_noirq hook for reasons: - Align the behavior between suspend and hibernate freeze. - Have power state of domains stay in sync between hardware and software for hibernate freeze, and thus fix the lockup issue seen on i.MX platform. Signed-off-by: Shawn Guo Reviewed-by: Ulf Hansson --- drivers/base/power/domain.c | 35 ++++------------------------------- 1 file changed, 4 insertions(+), 31 deletions(-) diff --git a/drivers/base/power/domain.c b/drivers/base/power/domain.c index 7cee9439fd21..2f0787d5101b 100644 --- a/drivers/base/power/domain.c +++ b/drivers/base/power/domain.c @@ -1307,24 +1307,11 @@ static int genpd_resume_noirq(struct device *dev) */ static int genpd_freeze_noirq(struct device *dev) { - const struct generic_pm_domain *genpd; - int ret = 0; - dev_dbg(dev, "%s()\n", __func__); - genpd = dev_to_genpd(dev); - if (IS_ERR(genpd)) - return -EINVAL; - - ret = pm_generic_freeze_noirq(dev); - if (ret) - return ret; - - if (genpd->dev_ops.stop && genpd->dev_ops.start && - !pm_runtime_status_suspended(dev)) - ret = genpd_stop_dev(genpd, dev); - - return ret; + return genpd_finish_suspend(dev, + pm_generic_freeze_noirq, + pm_generic_thaw_noirq); } /** @@ -1336,23 +1323,9 @@ static int genpd_freeze_noirq(struct device *dev) */ static int genpd_thaw_noirq(struct device *dev) { - const struct generic_pm_domain *genpd; - int ret = 0; - dev_dbg(dev, "%s()\n", __func__); - genpd = dev_to_genpd(dev); - if (IS_ERR(genpd)) - return -EINVAL; - - if (genpd->dev_ops.stop && genpd->dev_ops.start && - !pm_runtime_status_suspended(dev)) { - ret = genpd_start_dev(genpd, dev); - if (ret) - return ret; - } - - return pm_generic_thaw_noirq(dev); + return genpd_finish_resume(dev, pm_generic_thaw_noirq); } /**