From patchwork Wed Jun 21 14:40:18 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Abel Vesa X-Patchwork-Id: 694852 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 93A89EB64DD for ; Wed, 21 Jun 2023 14:40:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231491AbjFUOkg (ORCPT ); Wed, 21 Jun 2023 10:40:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50936 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231252AbjFUOk3 (ORCPT ); Wed, 21 Jun 2023 10:40:29 -0400 Received: from mail-ed1-x532.google.com (mail-ed1-x532.google.com [IPv6:2a00:1450:4864:20::532]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 983551731 for ; Wed, 21 Jun 2023 07:40:28 -0700 (PDT) Received: by mail-ed1-x532.google.com with SMTP id 4fb4d7f45d1cf-510d6b939bfso8111639a12.0 for ; Wed, 21 Jun 2023 07:40:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1687358427; x=1689950427; 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=kUE1natntFFJxsuWsetQCXUchTahXfnKhHb9xOBxGoI=; b=qNLgGH6/U2CxKdty9gB9OsWqbEI66/eB1ycqZqWjUDLPw5Qp7zQZpAebwvhHwycK8e zmTYkehL8diU3hTT2idtJjbZNc4XpTUHXziQ+croXRzw+ZBfuY/t7WvTOOd5LyAcrQs7 5/s3LofdWZEf9wiA9bLxBNR8Oq/ubOb9ql5blfWJyzlK6AO650+QC2cTQerFbgyLDh2W xBq+u3m0ErKru6xrL/AayQtWrSMzQUQUhxP8/eBlefpVQDI64L/GlAJhz5F0BiU94jrp aEIGxVCMzHO4pHhyZjMB4miUA1jZeFcRyXRZtVZoNQ7iu/q6AYmMOkwJsaDt7vGUtLNv lUSw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687358427; x=1689950427; 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=kUE1natntFFJxsuWsetQCXUchTahXfnKhHb9xOBxGoI=; b=EtHa7WyMaahqXP1/NGwc5dCPLmTNpwgS0D3KNNOK6HrFAMPkIPi4qALS/tUwuyrcni kQEz60asG1TnDKr3hg+jtmSpaCfWKq4+Lm1hlIpWWckJ+CMpNreWUvGRgG01TJjN72lC P8SdK42xq9d2zKKFRtMrO/a58YHVSLxMnhp7Jr646czk3PdFSN5fnOGQ0p/R7moxuios CizDiwbzHbW1xs9Ba+o7ljvHxsJEQgKGMQpyrrRLJsZDo5sb41wzonkYaCIfRunO9kRC NlUmvelG6PZStzY4Si3QuG/hCI6vor86IZO5yHql46ruioGqE3TNKTFOaA9Pm2fmlIga liuA== X-Gm-Message-State: AC+VfDwtWjVnsS1EG0naP69E2M5mmrIE1b8j5hjFq67vNGTMj88NvtpV 2vHZ05FHJd4vCk+IkLoCAQed1g== X-Google-Smtp-Source: ACHHUZ4HCoMV0tAzMxaR5BKXJ048JX29F/y3Dx69qV2TakWJ7Pc8uAurEkNVP+eicW3QAbAB88GYEA== X-Received: by 2002:aa7:cf19:0:b0:510:82b4:844d with SMTP id a25-20020aa7cf19000000b0051082b4844dmr11822520edy.2.1687358427133; Wed, 21 Jun 2023 07:40:27 -0700 (PDT) Received: from hackbox.lan ([82.79.124.17]) by smtp.gmail.com with ESMTPSA id l13-20020a056402344d00b0051879c4f598sm2689505edc.66.2023.06.21.07.40.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Jun 2023 07:40:26 -0700 (PDT) From: Abel Vesa To: "Rafael J . Wysocki" , Kevin Hilman , Ulf Hansson , Len Brown , Pavel Machek , Greg Kroah-Hartman , Saravana Kannan Cc: Bjorn Andersson , linux-pm@vger.kernel.org, Linux Kernel Mailing List , linux-arm-msm@vger.kernel.org, Dmitry Baryshkov Subject: [RFC PATCH v5 3/4] PM: domains: Ignore power off request for enabled unused domains Date: Wed, 21 Jun 2023 17:40:18 +0300 Message-Id: <20230621144019.3219858-4-abel.vesa@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230621144019.3219858-1-abel.vesa@linaro.org> References: <20230621144019.3219858-1-abel.vesa@linaro.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org First of, safekeep the boot state that is provided on init, then use this boot state to make decisions whether a power off request should be ignored or not. In case a domain was left enabled before boot, most likely such domain is needed and should not be disabled on the 'disable unused' late initcall, but rather needs to stay powered on until the consumer driver gets a chance to probe. In order to keep such domain powered on until the consumer handles it correctly, the domain needs to be registered by a provider that has a sync_state callback registered and said provider has state synced. Signed-off-by: Abel Vesa --- drivers/base/power/domain.c | 49 +++++++++++++++++++++++++++++++++++++ include/linux/pm_domain.h | 1 + 2 files changed, 50 insertions(+) diff --git a/drivers/base/power/domain.c b/drivers/base/power/domain.c index 51b9d4eaab5e..5967ade160e2 100644 --- a/drivers/base/power/domain.c +++ b/drivers/base/power/domain.c @@ -654,6 +654,43 @@ static void genpd_queue_power_off_work(struct generic_pm_domain *genpd) queue_work(pm_wq, &genpd->power_off_work); } +/** + * genpd_keep_on - Tells if the domain should skip the power 'off' request + * @genpd: PM domain to be checked. + * + * If the domain's current state meets the following conditions: + * - marked for being kept as enabled + * - has a provider with a sync state callback registered + * - the provider hasn't state synced yet + * then the power 'off' request should be skipped. + * + * This function should only be called from genpd_power_off and with + * the lock held. + */ +static inline bool genpd_keep_on(struct generic_pm_domain *genpd) +{ + bool ret = false; + + if (!(genpd->boot_keep_on)) + return false; + + if (!genpd->has_provider) + goto out; + + if (!dev_has_sync_state(genpd->provider->dev)) + goto out; + + if (dev_is_drv_state_synced(genpd->provider->dev)) + goto out; + + return true; + +out: + genpd->boot_keep_on = false; + + return ret; +} + /** * genpd_power_off - Remove power from a given PM domain. * @genpd: PM domain to power down. @@ -682,6 +719,13 @@ static int genpd_power_off(struct generic_pm_domain *genpd, bool one_dev_on, if (!genpd_status_on(genpd) || genpd->prepared_count > 0) return 0; + /* + * If the domain is enabled and unused, bail out and ignore + * the 'off' request until the provider has state synced. + */ + if (genpd_keep_on(genpd)) + return -EBUSY; + /* * Abort power off for the PM domain in the following situations: * (1) The domain is configured as always on. @@ -2065,6 +2109,7 @@ int pm_genpd_init(struct generic_pm_domain *genpd, atomic_set(&genpd->sd_count, 0); genpd->status = is_off ? GENPD_STATE_OFF : GENPD_STATE_ON; genpd->device_count = 0; + genpd->boot_keep_on = !is_off; genpd->provider = NULL; genpd->has_provider = false; genpd->accounting_time = ktime_get_mono_fast_ns(); @@ -2718,6 +2763,10 @@ static void genpd_dev_pm_sync(struct device *dev) if (IS_ERR(pd)) return; + genpd_lock(pd); + pd->boot_keep_on = false; + genpd_unlock(pd); + genpd_queue_power_off_work(pd); } diff --git a/include/linux/pm_domain.h b/include/linux/pm_domain.h index f776fb93eaa0..3eb32c4b6d4f 100644 --- a/include/linux/pm_domain.h +++ b/include/linux/pm_domain.h @@ -131,6 +131,7 @@ struct generic_pm_domain { const char *name; atomic_t sd_count; /* Number of subdomains with power "on" */ enum gpd_status status; /* Current state of the domain */ + bool boot_keep_on; /* Keep enabled during 'disable unused' late initcall */ unsigned int device_count; /* Number of devices */ unsigned int suspended_count; /* System suspend device counter */ unsigned int prepared_count; /* Suspend counter of prepared devices */