From patchwork Tue Nov 1 02:47:34 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shawn Guo X-Patchwork-Id: 13508 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp2689917wru; Mon, 31 Oct 2022 19:59:38 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7/AyTUaZdAbX9OcLfk2sy/YcpxrhFby3izLhjFD0BQpAOBOWoe9FXZTq7fzi0bfRcud6lP X-Received: by 2002:a17:902:d64d:b0:186:634e:5517 with SMTP id y13-20020a170902d64d00b00186634e5517mr17177537plh.3.1667271578541; Mon, 31 Oct 2022 19:59:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667271578; cv=none; d=google.com; s=arc-20160816; b=robHrzScsyRZ1sGJg4AiVBZX+MfLbet6y/3vcSo6kPdrje9fdtbdgye04EbmcoAvSh b5sTjRuKD+48Px8khUdUhHTRXMMrCfBlTXbTvH7Vdxel44PYaza16cVENi92ViCkw26J AUyEbjnmloBVFcEplfTpJq2Rzqhy8B5aVAvzfBRx8g56aQRFhFJyTuze+gJaFLs9oHWq ZOX0fuWuf/LvwB7UYzMS5CBvNw8HClX6KAbwjpkID+0ldfan+YAlxGruDJ5O28fLkAla lIQfEY3sloVSfnMSatLcxbd88zCMVlxjTea7V8RDcISBiB1pngwHff8AvGxsYv2MtXWY +EBg== 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=XGwO4GhQFCnfEGWVPRq8FBqqasnQ0/oWKbkrBe1VfIA=; b=QMErd1UPfPV0JXvBi8wh8S/oh0A42zS92zDXS9eDf9XwVYkg85XrMTKydMzAh7aQFc dIS5lY1iHXd2TApy7m+ozxlODL3NyTogr+rgsi7fN8ybOvBw6a+PKZ7HS261MKib1dez rp5UE+DxGXSeAHjwRio96TKBr9jqaJ8Owo2d/raqR+eJNuXjoy4nNMGFy5z8CEbEAP2a cQJ6kaMgF2XfX1IuOtca0ySRiIqfIx6tBXmmOI8cyGpExl/DRFAEJ+OD4jHyHuQ2pBnD nAQSVA+9pDXiG64ruVFhJovP5XGDDAhHR0hpS8w4w2H5yrlZZmb6y/k1G9Ayz7e5gDSF +PQw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=mTkPZRYD; 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 b9-20020a170902d50900b00186748fe89asi12617356plg.191.2022.10.31.19.59.25; Mon, 31 Oct 2022 19:59:38 -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=mTkPZRYD; 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 S229913AbiKACrz (ORCPT + 99 others); Mon, 31 Oct 2022 22:47:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42236 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229832AbiKACrw (ORCPT ); Mon, 31 Oct 2022 22:47:52 -0400 Received: from mail-pg1-x535.google.com (mail-pg1-x535.google.com [IPv6:2607:f8b0:4864:20::535]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B6C1517894 for ; Mon, 31 Oct 2022 19:47:51 -0700 (PDT) Received: by mail-pg1-x535.google.com with SMTP id q1so12282069pgl.11 for ; Mon, 31 Oct 2022 19:47:51 -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=XGwO4GhQFCnfEGWVPRq8FBqqasnQ0/oWKbkrBe1VfIA=; b=mTkPZRYDYhw7QQ4scrrL39McOrmqG4T2zdd9b1wJc1nA4b4vOHpdpe2kQIBil7+LLD 2ZRTIHbgqZo1u2pX5NK3RY9NdieoqMYh3AxjH+xsnP+X5JoUdv7ApEWQdqDJz4DNzFa+ RX0mx/sFa46oPS5LrNP+0FUWDUjDgei/9C7J4jMn6S8MnRfvipYU+Do7DzYSDJU4SdY2 l5//Wj1X/eibK1Pg3kEj/kryDik3M4ZOjdyIqIskK+IE2rgOMevVRB2ZyFv/OhlZE97L h19CJ8DsgqfSkhUIRSTuFucLbA+2+L3ZTWUZVjx9v6I4QDLMEuHXB59VWI4Ep6PsaiXi fQoA== 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=XGwO4GhQFCnfEGWVPRq8FBqqasnQ0/oWKbkrBe1VfIA=; b=WsivHhmQyhqH3x3tOq61unjGCo6GvBrD1o3B/9wPCM6joWfaFRuVAg/gcAx6nGkTkR PMh5WgpmBZiLUu9g4iu+z20LWJsCI6jeOYzdNwZ6M1tpJsA4CoYtV7bc0T2HN/ml6KBh G6uFn/4z6LVfzVPa+0DWX86AH9GPkVS2MTg63KnNnynOqOTJR4ShbfCWPLrU5qnPt369 9zkY7+7uC7L85suxpQXlgo1Si8d9vDm1SWkLakCxFvxhHbSPm+1aPZz/jwrOpQxHB32k WVFZB0gWp8R+B1LFttz2vGgX+nuDOGRQRGyjrPWcWs72xGjGOs0mf7mFky+I0o8VNLfZ Su8g== X-Gm-Message-State: ACrzQf1e1k5FIxLSrqr4padZMO4AjHtUNhKaBrPCsdRHT6kmM9L5erUt d2AzeVt0T6rl5/RSc27+Mkx9wQ== X-Received: by 2002:a62:4c6:0:b0:55f:c739:51e0 with SMTP id 189-20020a6204c6000000b0055fc73951e0mr17184994pfe.49.1667270871297; Mon, 31 Oct 2022 19:47:51 -0700 (PDT) Received: from localhost.localdomain (80.251.214.228.16clouds.com. [80.251.214.228]) by smtp.gmail.com with ESMTPSA id y4-20020a170902ed4400b001714c36a6e7sm5079570plb.284.2022.10.31.19.47.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 31 Oct 2022 19:47:50 -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 v2 1/3] PM: domains: Pass generic PM noirq hooks to genpd_finish_suspend() Date: Tue, 1 Nov 2022 10:47:34 +0800 Message-Id: <20221101024736.1509207-2-shawn.guo@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20221101024736.1509207-1-shawn.guo@linaro.org> References: <20221101024736.1509207-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?1748260962309484038?= X-GMAIL-MSGID: =?utf-8?q?1748260962309484038?= 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 6471b559230e..54f6b0dd35fb 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 Tue Nov 1 02:47:35 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shawn Guo X-Patchwork-Id: 13509 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp2691615wru; Mon, 31 Oct 2022 20:03:02 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6XA2/ARN0Zv5aWRWUG8cvll5SovBA/EJIQHnMgI7OP1q4C82bMGoaqAncJdQvJv+tSiwuW X-Received: by 2002:a63:235c:0:b0:459:5fef:88ab with SMTP id u28-20020a63235c000000b004595fef88abmr15691718pgm.312.1667271782434; Mon, 31 Oct 2022 20:03:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667271782; cv=none; d=google.com; s=arc-20160816; b=OVBOO+Hr/IGvsrXogd/2iZNKUTo9V4qdh7RPBa5h2YelYTzQe/5TfhRoMBC5SDSLmf PxP+C3IHF21Fg4wvsymAFVido0uQjlIY/3vj81XDe/yAfUEzujoQ3/PIvHfkd0ZeEbmJ REo9V3Meh2pDhfqyGuQyot3soZECVRTxNNSsQmr6dNX8xYCsHlL+xtPOjsGh00/Z56uU HEd//20uLD/xkOQDn9YDHi2UNMkVpfSsaCIzm1C0zUU8v5XFERdNdADHLVHsmJWPjYa7 h1k7Iu01BnrJbe3Vqy73QgsBWZEMzjRpBorskFM/WZv/rCctUcGU0F7KaWPgrdxaJCXI 398A== 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=jbrdZ3AfNBZwnOI0fG3SRJzo0Qc3Dqvr8k7roe04PJI=; b=WnDCX29/fwcGT2HCeOScD0kqs4mkGLwOt0gHPeV2y4FqYoFVDFICa1kEYtoPldC5i4 aDNXJlvXrooYoLSxb6SH4MEMiTknZRgCMdSQc1hXzJBp5MVRBr7VSiVfMmL+DRC6HymF SjRnnfJKyQcsuQhWLVYfwicabyCSiuzRzJTkuJ5S8Qjg0iI3zww0CAeO/plXkvl/yjJg oetPwjYuTFd/eD/+3XnxhCcvu72aPz4IfZZ97rFm+1jFhuEZtns7LjGXn0IBWtfJanSP oniUOkKEDT/N3y85547mUmrMvb+uNQCkOYqRYo1X/v1isxz+d1Azx2/HcP1ZsXYrQ3NQ phhg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=HWqorN7M; 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 m22-20020a634c56000000b0045af77fa685si11131826pgl.235.2022.10.31.20.02.46; Mon, 31 Oct 2022 20:03:02 -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=HWqorN7M; 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 S229933AbiKACr7 (ORCPT + 99 others); Mon, 31 Oct 2022 22:47:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42284 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229928AbiKACr4 (ORCPT ); Mon, 31 Oct 2022 22:47:56 -0400 Received: from mail-pj1-x1036.google.com (mail-pj1-x1036.google.com [IPv6:2607:f8b0:4864:20::1036]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 58ACC17A8F for ; Mon, 31 Oct 2022 19:47:55 -0700 (PDT) Received: by mail-pj1-x1036.google.com with SMTP id o7so8801519pjj.1 for ; Mon, 31 Oct 2022 19:47:55 -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=jbrdZ3AfNBZwnOI0fG3SRJzo0Qc3Dqvr8k7roe04PJI=; b=HWqorN7Mn3JENdNCLQsXnKQ+LlgwfD3rhZ8l+NteXzFRkW08IFKMUxsFk45ZA5CXQN WpKxiy1ayugBAnoB7oC0WN9m4v3O9mkQ5V+ooBuIsjXhq9l0uJvnJNs3IKkbh2wbAC7Z GjcFGu7tJqVjoOTotKBJErQ4sKFIMu4jt52yxLL73oTfb8pumbi2Uh2cj0VE6EO8gpqC KhD7vu4KOVapF/OEyiiSdwSk02kD7Lmk9aHis/3wVND+YF2K77DFdaVjzyeMTUIOqg7T E53odfale8+xgW9HpsKwHwzcwsKqruUwYKIFZ88wov0TR7JaE1B1q8YTa6D4IXxStOO3 QqjA== 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=jbrdZ3AfNBZwnOI0fG3SRJzo0Qc3Dqvr8k7roe04PJI=; b=LBBo77swdfCh/SbMAMPbtR18BExYEkaE6f0Nmw+kxGh0T0IqVGNvTPffHSU8mlmwt2 W6CKEKFoyGFbCGKDvQbQgFRzrSCVR4RCS+fblZA+teziQfWPKh2hwd0XDSx3DTmI0sm6 d24jZ5PuZzyJCCEpniI+1PCZgXCjAUQ35QR5d/1tHQA7au0XMLw1bfQA9TIM/WN6gi3q beKPzezQr5lU9R171ovh+816BGiJfYwGsNEEfMZQH4uX+loGAxpSviryl1xJlrztrpqz W6Q/uYe7LTRXFPvqmbja/Gn1mCndbipJEETr3ymz0wG6aMz9hhvCTeUdAmE3RM2jedta shNQ== X-Gm-Message-State: ACrzQf39uxtO+IMhPTe0IrzvZPPS8PuoKD5OxqqAgEEF9+M6RGgcptC6 WSCTK29LvjZE5pWpmM1+PviSbQ== X-Received: by 2002:a17:902:8c8f:b0:186:b6ad:3592 with SMTP id t15-20020a1709028c8f00b00186b6ad3592mr17430451plo.119.1667270874862; Mon, 31 Oct 2022 19:47:54 -0700 (PDT) Received: from localhost.localdomain (80.251.214.228.16clouds.com. [80.251.214.228]) by smtp.gmail.com with ESMTPSA id y4-20020a170902ed4400b001714c36a6e7sm5079570plb.284.2022.10.31.19.47.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 31 Oct 2022 19:47:54 -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 v2 2/3] PM: domains: Consolidate genpd_restore_noirq() and genpd_resume_noirq() Date: Tue, 1 Nov 2022 10:47:35 +0800 Message-Id: <20221101024736.1509207-3-shawn.guo@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20221101024736.1509207-1-shawn.guo@linaro.org> References: <20221101024736.1509207-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?1748261176685441126?= X-GMAIL-MSGID: =?utf-8?q?1748261176685441126?= 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 Reviewed-by: Ulf Hansson --- 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 54f6b0dd35fb..b81baeb38d81 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,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 Tue Nov 1 02:47:36 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Shawn Guo X-Patchwork-Id: 13510 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp2692851wru; Mon, 31 Oct 2022 20:05:45 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4pJQawp+Lu7UVgqdoyS+8ufDKk3gAbITb5/R2hbJneQM2+haamrGfpEpYQeCl4cEVxOyYq X-Received: by 2002:a17:902:7590:b0:187:29fe:bdb1 with SMTP id j16-20020a170902759000b0018729febdb1mr5479933pll.134.1667271945641; Mon, 31 Oct 2022 20:05:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667271945; cv=none; d=google.com; s=arc-20160816; b=Oq7j/cW2ZRjDP6kK3N/gZx4i4Wpou34qLWpY/NGb4Lyl8J4BiSHWQ9YxxMRsXlJaxv TDpZIACmOnukZ+KFaMpt5J75K/+T6EEDsQen8DFMNL6oBShj0I5oevSiqcDw8CiI5d6m L8ZxGXRvjx/TpOY0RkoamVlvkFlJ7D/QCLCjKULYDkCs/jxPD1dWE99QTS6Kx5KL2oIB gSyR8pszf8rFK466A5ryiUOKfsrsH8GCR1IhTmiBeQmv08lh1nO+TgwaWgOSSGXAb1L0 9vKlEgK7uFwQR8/o+uNQgcqzEsmj61o1HpjuNH0N8vAxpxBL+aMrRcUG8VdlQ4WuRw5R 88Aw== 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=YzzxAfsdgRp0sBb+mu0K+QG/OOHcPzTsEjXihYPQFME=; b=ujrqn6WJDF4nlwz5tl/qBEwtsQoUC6CMqoCs9y6046WEfGyTpmFTEtwfSukuoL348O ypbFadtGEU3UZPuxRVsqM6csiOLNt1w8R1Z/T1hVHOEjP008EJ58tAkZg33+93Yr/BQW MGQvwxL414YaCc1WiBxu6AbJuPf0OnrPTLe6DCi52dPA8D76qmA6RfHfF5277jBAaXte hBNtP+qyfVUo2Uldys9W7BSD2c7fLA2XQyFizV2ajoESv19zlQ/O/O9XTZeGfzZnYRlR xkm3UvgvGyxOLt6w2xlj8kgKtthAXKgUmdAV2HvaROKFYNVFJbHhG7x5/3z/1iY2LxNB ZILg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=nFJQRNfB; 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 m22-20020a634c56000000b0045af77fa685si11131826pgl.235.2022.10.31.20.05.32; Mon, 31 Oct 2022 20:05:45 -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=nFJQRNfB; 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 S229936AbiKACsF (ORCPT + 99 others); Mon, 31 Oct 2022 22:48:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42354 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229934AbiKACr7 (ORCPT ); Mon, 31 Oct 2022 22:47:59 -0400 Received: from mail-pf1-x42c.google.com (mail-pf1-x42c.google.com [IPv6:2607:f8b0:4864:20::42c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BD31517A98 for ; Mon, 31 Oct 2022 19:47:58 -0700 (PDT) Received: by mail-pf1-x42c.google.com with SMTP id i3so12291270pfc.11 for ; Mon, 31 Oct 2022 19:47:58 -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=YzzxAfsdgRp0sBb+mu0K+QG/OOHcPzTsEjXihYPQFME=; b=nFJQRNfBcSfuRnyWTPD2PqIVAOVoYK8UwR3GpVyEu2Kt7VviKDzvwPmdC4oda5tXZ2 bkA+kGHYv3NlC4q4ZHPDUbPSbh6JNnrUCT1mB2s6tZ9C8gFT7fd/oKUen8GU1TFH76ay VJzUmhUvN+OlpOq9PZ8uAuBZLra85nD1jHX5WwHREw4xSjw2bhs800mOw96m7m9xPfXH eC3AgwSdpr/3F65Q0U1FyNBpn5U/7gZLQr1zvjdB0JiEsOP4uDAL0Lgpt/yWfLt2M/BK jHrfqt42dh6i9vJ16+5GY+4I3AmKfe6glSRwh5Hs8sYpdNigMIdicFc2B75xzPHEcUxI fd/A== 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=YzzxAfsdgRp0sBb+mu0K+QG/OOHcPzTsEjXihYPQFME=; b=pH+oKN00BWRS1mcbgfjyi4B94eA87gmJBSUZzo+BO6ct/IUOhJlD2PCKamZHyK3Jac 3jhdQ83vr14tXLqc9nrlvGmMKoDcoHdERB1G6zmr9uqRRcjxeVvCwCAwnDYVhH/qHCSG +Z95Qs7Nj6w2yuqEHnvfJr68TNzn348W5M8lORwErFE6pgnluNut0ANrbeouoGFe+FVw yfCu+vPBbxuQ0NJwKdVvaqrKpl/2NmefSPiqK9M+TO6DhC1w6YCX4m8xhe/WwwGhTz8N 7edz7ZKGIqrB+SYKYaEtBQruyfLlGPYSiiJ6CAciBpZTjaraH3mqIO4YwStWSaAAixNw sIKQ== X-Gm-Message-State: ACrzQf2kQlubohowKJwYRnBrko8WArxyHcItiBIbkShJRhwFNy7hs3dj XK/ryBHyzrS/1b8e3rDrfSbiug== X-Received: by 2002:a63:100a:0:b0:46f:b030:877d with SMTP id f10-20020a63100a000000b0046fb030877dmr8939251pgl.333.1667270878330; Mon, 31 Oct 2022 19:47:58 -0700 (PDT) Received: from localhost.localdomain (80.251.214.228.16clouds.com. [80.251.214.228]) by smtp.gmail.com with ESMTPSA id y4-20020a170902ed4400b001714c36a6e7sm5079570plb.284.2022.10.31.19.47.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 31 Oct 2022 19:47:57 -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 v2 3/3] PM: domains: Power off[on] domain in hibernate .freeze[thaw]_noirq hook Date: Tue, 1 Nov 2022 10:47:36 +0800 Message-Id: <20221101024736.1509207-4-shawn.guo@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20221101024736.1509207-1-shawn.guo@linaro.org> References: <20221101024736.1509207-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?1748261347521422536?= X-GMAIL-MSGID: =?utf-8?q?1748261347521422536?= 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 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 b81baeb38d81..28c9e04e3488 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); } /**