From patchwork Sun Oct 16 09:58:13 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shawn Guo X-Patchwork-Id: 2995 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4ac7:0:0:0:0:0 with SMTP id y7csp951791wrs; Sun, 16 Oct 2022 03:01:01 -0700 (PDT) X-Google-Smtp-Source: AMsMyM65eHVONwY1TDYX8VHzUAfpop5Xx0ZC9NHR01KGxFxrkkE4QabjarPH92NSXwV+2OdHKnLt X-Received: by 2002:a17:907:e89:b0:78d:cdd7:5a28 with SMTP id ho9-20020a1709070e8900b0078dcdd75a28mr4782916ejc.167.1665914461661; Sun, 16 Oct 2022 03:01:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1665914461; cv=none; d=google.com; s=arc-20160816; b=ik00X5lC3UaEXob/zzrKAKG78V7bEt27U4xD00nk09bwOiGnP8vwQPumRfJ6D13+ci 3aeUQVdXj3Kqs2dMT88ggVy+MKMypEMvXXIzUNXvx1Q0NtxbUyO2xQcH3qCb5jfbNBrh 1T6vdjMBOjBdACmk5B0pQEgltLW7gzUeYBNkhsJPtvIsQEdrLONj0jfAOSKTOVi8cLC1 W9V02gbcewoji+Y/UpFNBrbhPXcxouVtw5EKY6m6NZyKx0ncRxDeEgs5tePd9dlbnNAY f5dzdlvjotpf3Vdu7Y4CI7FVdYHHdZBPLzjnHeDyshMPpdqOJC8VELeWSwo+MrQY6NcC gVrA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=uIHYWY56QD8kdVR8UkvvdHp3cIEPSeTOMo7K4e0+8vI=; b=Jc2krOmQojiFIuiNXgDp/sjEl+nBv5GbyWM+Pt9MlQQv6eFzfqVqUI2tzwnsAIq60V Owkt988qzolxC4KMyvJEveB6bynQcAFiCcHoaulXmpq1upc8VBCyv4OsWGM8kS1gpNFm a4kiddyrdJLyEnxb0RQqmqnWnerH4ANcyals3vZ6H5Ou/VkHcskdqLVusNb00U1T1bc6 ROE+0aZWYbMJtf60W6N9vcQF6QZTCzutnv/WiJSKmwQ2pDzCm4bdSiZuC9ByujB9esTv ThrC4Fr6d0e7MWf2HtZqOOFllRt2b2okiz8XuxmtT77SXWFx9SQ8BfbeKn8ZRH0uNYXi 2JXg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=ZxddD8Za; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id ne22-20020a1709077b9600b007701a050273si7465203ejc.942.2022.10.16.03.00.35; Sun, 16 Oct 2022 03:01:01 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=ZxddD8Za; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229733AbiJPJ6n (ORCPT + 99 others); Sun, 16 Oct 2022 05:58:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52564 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229481AbiJPJ6j (ORCPT ); Sun, 16 Oct 2022 05:58:39 -0400 Received: from mail-pg1-x52a.google.com (mail-pg1-x52a.google.com [IPv6:2607:f8b0:4864:20::52a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 70BCF32D92 for ; Sun, 16 Oct 2022 02:58:37 -0700 (PDT) Received: by mail-pg1-x52a.google.com with SMTP id q1so8079396pgl.11 for ; Sun, 16 Oct 2022 02:58:37 -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=uIHYWY56QD8kdVR8UkvvdHp3cIEPSeTOMo7K4e0+8vI=; b=ZxddD8Za0wZsUUJ6Nk5mbI13E2BDhHfxNKYxve4XGPZY25S3f5dartelW6ig1AJ0TE urk9Jfrnxh9RzIRoYYOZ9fA6PU+cBmvY4TBahjbDqVUs9hCjgnEyQuVHAvD4dRN7zqVl khbXWIUjHw2GsM8BuJw1b0yQd4dsWKKVTjPhdZ6SGP9wVHwdwjiFAm9UQoff/CU0ma9D adwcI+adygygmXnksMbFYHxWu9jtYVhJJ9INfrsK8lWYTu3rLP17Hqzpv9WXQnsL3rZ5 zfrhFKvaUExS+xQk8tdSPECGcIm+cRqDKTSa4bVdQcEMHZk6B5Mv04Z84z0FGILHixFf nB6w== 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=uIHYWY56QD8kdVR8UkvvdHp3cIEPSeTOMo7K4e0+8vI=; b=pc1KP9pUxVuFaArykismAIIwuv8z8zLCDfO9ZwtY2LMB9wqxuyIHups6WtxFu/Ah+V j0YDgqXczCW2pYknlUha3vSik5+S+UEN+XKLWyJZXM9YPT+bU4SbqKe5fil+vMEnESzO 3Q8hNPNoCRAlY1Z/HW6b9/+ecSWmFxVGtzhv7EzBnsK+npwtAaRDMJAAtyfnhbcdnM9Q in2ITUhS0DW6XR/bTjB3RsXYBCg6YUqXKJzkgMHJtnJweiqyqgo602jLF3BBL3P5TPnd DyNSm5PGglN5i+eo2QuhtYOoO+ikAP4KnlJ+GMZ7DRx+rNLrd7DaZet1hOYw9VFDwjG3 s1xQ== X-Gm-Message-State: ACrzQf26rbfau4OkTFEfiGKSIqVkWEw3XfVxTVkU9W7ly8koTFaXb23C td6a2WZmxMf2ngYJTGix64OT4g== X-Received: by 2002:a05:6a00:1341:b0:566:5e54:8110 with SMTP id k1-20020a056a00134100b005665e548110mr6842504pfu.6.1665914316527; Sun, 16 Oct 2022 02:58:36 -0700 (PDT) Received: from localhost.localdomain (80.251.214.228.16clouds.com. [80.251.214.228]) by smtp.gmail.com with ESMTPSA id c18-20020a170902d49200b001745662d568sm4481838plg.278.2022.10.16.02.58.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 16 Oct 2022 02:58:35 -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 1/3] PM: domains: Pass generic PM noirq hooks to genpd_finish_suspend() Date: Sun, 16 Oct 2022 17:58:13 +0800 Message-Id: <20221016095815.2550034-2-shawn.guo@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20221016095815.2550034-1-shawn.guo@linaro.org> References: <20221016095815.2550034-1-shawn.guo@linaro.org> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1746837922475056866?= X-GMAIL-MSGID: =?utf-8?q?1746837922475056866?= 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 --- 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 55a10e6d4e2a..01f5644938e0 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 Sun Oct 16 09:58:14 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shawn Guo X-Patchwork-Id: 2996 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4ac7:0:0:0:0:0 with SMTP id y7csp951833wrs; Sun, 16 Oct 2022 03:01:08 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6Zx3TgRRs7MMU84IisjNwY3Bq4Zwx6DvLgXL3214qDvTfKT7atGBSlV9vFwUv2a1rAMxqr X-Received: by 2002:a17:907:2cd9:b0:78d:9e76:be26 with SMTP id hg25-20020a1709072cd900b0078d9e76be26mr4571550ejc.315.1665914468564; Sun, 16 Oct 2022 03:01:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1665914468; cv=none; d=google.com; s=arc-20160816; b=qWN7Uk8185jUTGRKmCioftV912wECzFS7G6CVsH68aMRGyJCbKP5dp1PBdeX3fhMvb Ia8U1N6ifA44tN8l3cxjIRPnALXhSxV8VxFTuqSg5lk+W9G6+4/VBiW+Gfwqh/0MbMwj mm0AuiY29cNW1gt8Pokb+gAb1gTKRbM1vdDH+qcEJALbfjofDN853knw6fdEGFKrmUru PlJ/T1gj1TXG7nEWeY3bPJDitQOQ+S7xCIWGgkMxGYpWSDPE1Y37Y0EPurHuJMLFkjSg OdQcn6f/sjCWv7JjH2UOQHx2x5joAEtygPLHdt0JXcbtNWvRCMIWz+VNrKZRMRfyAwT2 iWNw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=dGtXWioNl23rW8/5PZCxfXNs96/lCBczDCDN08pJgeE=; b=QASvZ9czgduzupfZhFqTcRLf5/dq4zbs4z8v7Z1cDh4JVf1nQ8CBnRoyAV0Mv1JoKf yF2hA7UBZlMJ2dAcydEElyp1HDv0LMU8MY4hIcGP6gOm6TgOxIJDk05XSfX/VeDZtgVQ +u1Sh6bs51EvmVoBf8FZGo6oXvxtEy5ybS2926+F69UDlUvbnRG9tJR3TWP7NQwsOAF4 Lx3LcC/4vvvUpRihjQ93em1WcQ7IS7Orsyz+se0E1TXxk9EI60yt2M5ns9uJskVcllJ3 izzTFkpvhfz0/tygNNENDfrpxeO+5Ls0OAebRvkamrEFtbXtdfWLgNa2pXFH9DXoUL1f in7w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=gZoqZQA+; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id w23-20020a50fa97000000b0045853b3a802si6051521edr.605.2022.10.16.03.00.37; Sun, 16 Oct 2022 03:01:08 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=gZoqZQA+; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229742AbiJPJ6p (ORCPT + 99 others); Sun, 16 Oct 2022 05:58:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52662 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229727AbiJPJ6m (ORCPT ); Sun, 16 Oct 2022 05:58:42 -0400 Received: from mail-pj1-x1031.google.com (mail-pj1-x1031.google.com [IPv6:2607:f8b0:4864:20::1031]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 84AC42F66B for ; Sun, 16 Oct 2022 02:58:40 -0700 (PDT) Received: by mail-pj1-x1031.google.com with SMTP id o9-20020a17090a0a0900b0020ad4e758b3so8519944pjo.4 for ; Sun, 16 Oct 2022 02:58:40 -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=dGtXWioNl23rW8/5PZCxfXNs96/lCBczDCDN08pJgeE=; b=gZoqZQA+VejqjudxyDRZRTdLGp7mPiU4gdY/9o/1PGcLZpSUxvYUJGs3xZzf8APrPA ZIOu0QsWCBUzknjQPaagSvSPQj3khFXtqGAGuOAOltolU6nxckCTH98DLhVX5FjM2ZOg y9UwjieMFvRH+0u9uyQhdzz9ZjciIG5iqqbUqQBvMVTQ+Y7RlFLLjM4HySBx1IIMtBRm d5OZ39n8ce/HTThh6z8BJvr112L5v4BGIW43hX6QC0hdfYRxhVBUk8agPNH7Iy2QP19X WYrxSK7rRrJSuuwDDwtT9c79VKBzloVRvzlpzG0BL19CeuSS4RVYOH1qqu1lT+WNcE9K h2TA== 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=dGtXWioNl23rW8/5PZCxfXNs96/lCBczDCDN08pJgeE=; b=2zy91G05JvK11us2f8kK3UWKi18HSmECLQkNNUIfMZaVNOmZTV2yFEWlGQlc5nnGmK Fgb+cWfKaRBVH4NaRPiNaVQo5zkX4CwRFozX8P2ODp2O8NP62lNqyB3Nh9DFM5sDCf1J 75Z7WZoV5FaYpqvuoeoMss2qPzTbsNpAGwPUh0tYxRwqN2J+mXaXaRkWkqM3sUHUrCwb KI+kOGZvx+R0iskbzxN+wCpGvYxsIJNFMQ5FL9aPZNrw2CVYc7NbYcK/Q8BqoUuoQrLu 1J6tfVppDmlWULO0eKs8KHObFJPmfPnuWRBL05XH7MNhex/u2AgvDXMcF+parPCf9428 G5Dw== X-Gm-Message-State: ACrzQf1WMDxAVE6iQQ18v4wMu75kjkVkQ8jzDu2Ky+kdHuDriraTAeVl Xo/768v/kCiNYO+xp+sRj51AOQ== X-Received: by 2002:a17:903:30d4:b0:184:fadd:ec27 with SMTP id s20-20020a17090330d400b00184faddec27mr6367766plc.44.1665914319981; Sun, 16 Oct 2022 02:58:39 -0700 (PDT) Received: from localhost.localdomain (80.251.214.228.16clouds.com. [80.251.214.228]) by smtp.gmail.com with ESMTPSA id c18-20020a170902d49200b001745662d568sm4481838plg.278.2022.10.16.02.58.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 16 Oct 2022 02:58:39 -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 2/3] PM: domains: Consolidate genpd_restore_noirq() and genpd_resume_noirq() Date: Sun, 16 Oct 2022 17:58:14 +0800 Message-Id: <20221016095815.2550034-3-shawn.guo@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20221016095815.2550034-1-shawn.guo@linaro.org> References: <20221016095815.2550034-1-shawn.guo@linaro.org> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1746837929849642619?= X-GMAIL-MSGID: =?utf-8?q?1746837929849642619?= Most of the logic between genpd_restore_noirq() and genpd_resume_noirq() are same except GENPD_STATE_OFF status reset for hibernation restore. 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. Consolidate genpd_restore_noirq() and genpd_resume_noirq() into genpd_finish_resume() and handle GENPD_STATE_OFF status reset for restore case specially. Signed-off-by: Shawn Guo --- drivers/base/power/domain.c | 70 ++++++++++++++++++------------------- 1 file changed, 35 insertions(+), 35 deletions(-) diff --git a/drivers/base/power/domain.c b/drivers/base/power/domain.c index 01f5644938e0..fc0ac9e6050e 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_resume_noirq - 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,9 +1266,25 @@ 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); + + /* + * Special handling for hibernation restore: + * At this point suspended_count == 0 means we are being run for the + * first time for the given domain in the present cycle. + */ + if (resume_noirq == pm_generic_restore_noirq && + 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->suspended_count--; genpd_unlock(genpd); @@ -1281,6 +1299,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,40 +1397,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; - - /* - * 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); - - 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 Sun Oct 16 09:58:15 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Shawn Guo X-Patchwork-Id: 2997 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4ac7:0:0:0:0:0 with SMTP id y7csp952883wrs; Sun, 16 Oct 2022 03:04:00 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7vKf3WwwYjFhznFOiAkccHMsb0shYd5Ny6AeXqGDdtO1uQvLted4MBiLDWSv7m6nunKIyF X-Received: by 2002:a17:906:dc89:b0:78d:5616:4c24 with SMTP id cs9-20020a170906dc8900b0078d56164c24mr4707366ejc.118.1665914640473; Sun, 16 Oct 2022 03:04:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1665914640; cv=none; d=google.com; s=arc-20160816; b=CCi3jnuK9L68luMnH8lr6owfOWEyL9FphY0ZhvzWpmEmatwUbxnmvosxrqkVHXYfyI ERCnHEgMnmLKh+ZEbxD6LAVkGE2eSYD54rnCucRLvefPnbr7p6XDqjvXwwxC3fpIB2tf rJzhqJVF1fDYyTtsHrtq3/7NYu7QZ03pe/cI9pjD7vvJ/u56eEvFEK6iCOOiNyLyDLp9 +5+VLX30VP2cwlOCV+kdx8l+2xOiCoVxZ2QFMDbM4/OyURKsdH7C+eOTWUJcW3aKDGk+ serhNE2shubsWHZsV1SXBNmVeqTIERclcjoyPPQnSLraEN4MTcuXaUd7zlc0uNSdfD6p mXlg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=apttPogZPuWSTkpcshSvusTStupOpIbnisKrYu+q1ls=; b=sWQnnZ1VSD61UjTZOCvLOC6wtGv8EojrtSuvrRRw4ZsGHZEb1LpXdCD5pmbviHiavp 0E1N8qQ+K+ngBEchEiHr+SIazrBMsbD5HjT89SzSJw3mQdDnsI3e+pK2EbCnw9RSdOWP 7ApYoeaw6mbvACjETulycfIRY6FYJBX+ubsxmJhtmDvMTL9hEjkyIq8B0yyhge8T3dcB SuoG1VweSRiMU9CY+pgZIGtS9xxHKzr2Nwlr3ZDjVQ4Ka32C9hJ9Tmt5jDrghFDW22Fm ZRY8djwLLQcamlB0bbI9XPaFE5+BvZ+XzBHMVOzIGNGt+/PYAYSTaWAeX5GLn6bPn0Jg G87Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=qt8x47++; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id hb30-20020a170907161e00b0077077ded253si7586777ejc.924.2022.10.16.03.03.35; Sun, 16 Oct 2022 03:04:00 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=qt8x47++; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229727AbiJPJ6y (ORCPT + 99 others); Sun, 16 Oct 2022 05:58:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52666 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229712AbiJPJ6q (ORCPT ); Sun, 16 Oct 2022 05:58:46 -0400 Received: from mail-pf1-x433.google.com (mail-pf1-x433.google.com [IPv6:2607:f8b0:4864:20::433]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5A77336DDA for ; Sun, 16 Oct 2022 02:58:44 -0700 (PDT) Received: by mail-pf1-x433.google.com with SMTP id 67so8675740pfz.12 for ; Sun, 16 Oct 2022 02:58:44 -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=apttPogZPuWSTkpcshSvusTStupOpIbnisKrYu+q1ls=; b=qt8x47++WeLGlR1rL/oqJJ25Q0JgsCvq6siuhsG98podW+UGqu2ZlP2SzLF+MoEvct cOIUaa3Cninhl65CPH3oT/WsflP6LN63T7AnJE5ShFdAwYqvtHWmPUlWEqHH2q+QYMV2 vW3ZO4+xBoEvxlEoB430Xi3X6ooC1tc3us3781R3vjBgIPSzP/1sZGQXK0iqCHOI+rkY H5fxh38aacsI2JbDQ+yCdTnr0QrepPiaTp2ZRdo7LKsUGQdU/dDGFZW/vnGKkpLftblx Pq1nFUsEPWQyfHxA49zQd5TqWnYiaT2rw3WdS+7tZZ7WPyFR+rIGsVWRInLqpdkqm3EW WW5w== 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=apttPogZPuWSTkpcshSvusTStupOpIbnisKrYu+q1ls=; b=DcLoTQJ6E2pjrK6WHeqKNkuOYu27MQEZHyla8OlfFjWHFDNql1pWM3B5VmTHJxWBBV Vr7RxsxRGKwvtZWil9M3cg7CE+AhcnjD0qjXaupbkmV3BzlAAFrMP+ufSB3fO2Hu1/dd NHUvzlUO8k7zdEt6Q5AQkH643jKM/trjNPdsE5zV1LsnNpMs6Ve2zzl8uOI7yPsbynWj XsH0AFlF1NNRVLLDo+TCiOr9SeXdpwnsatrYlXHodVVHYcC7Yd937fosyTwKF5T798xs DFX5cvIHEnFtOkll2uzZFjAPuhlhT2y72LgsKPLjoNxAQkEzAqtPNDrqydnoy+sOf1ec +o7g== X-Gm-Message-State: ACrzQf06KXh665fkAh8rUD+vDGqYaZ/dgh3dF6J1pM3gNbNdDJQKFd1Q S1QdXrUP63r+x8wPj99ci6v94Q== X-Received: by 2002:a63:1e5a:0:b0:43c:b966:e2d6 with SMTP id p26-20020a631e5a000000b0043cb966e2d6mr5722678pgm.569.1665914323414; Sun, 16 Oct 2022 02:58:43 -0700 (PDT) Received: from localhost.localdomain (80.251.214.228.16clouds.com. [80.251.214.228]) by smtp.gmail.com with ESMTPSA id c18-20020a170902d49200b001745662d568sm4481838plg.278.2022.10.16.02.58.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 16 Oct 2022 02:58:42 -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 3/3] PM: domains: Power off[on] domain in hibernate .freeze[thaw]_noirq hook Date: Sun, 16 Oct 2022 17:58:15 +0800 Message-Id: <20221016095815.2550034-4-shawn.guo@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20221016095815.2550034-1-shawn.guo@linaro.org> References: <20221016095815.2550034-1-shawn.guo@linaro.org> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1746838110367943522?= X-GMAIL-MSGID: =?utf-8?q?1746838110367943522?= 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 system ↓ ↑ genpd_thaw_noirq() Read snapshot image ↓ ↑ Write snapshot image Kernel boot ↓ ↑ power_down() Power on device 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 power platform. Signed-off-by: Shawn Guo --- 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 fc0ac9e6050e..2497a43737e0 100644 --- a/drivers/base/power/domain.c +++ b/drivers/base/power/domain.c @@ -1323,24 +1323,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); } /** @@ -1352,23 +1339,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); } /**