From patchwork Wed Jun 21 14:40:16 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Abel Vesa X-Patchwork-Id: 13287422 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 3B5B3EB64D8 for ; Wed, 21 Jun 2023 14:40:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230511AbjFUOk2 (ORCPT ); Wed, 21 Jun 2023 10:40:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50956 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229923AbjFUOk1 (ORCPT ); Wed, 21 Jun 2023 10:40:27 -0400 Received: from mail-lj1-x22b.google.com (mail-lj1-x22b.google.com [IPv6:2a00:1450:4864:20::22b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 59D2F1735 for ; Wed, 21 Jun 2023 07:40:26 -0700 (PDT) Received: by mail-lj1-x22b.google.com with SMTP id 38308e7fff4ca-2b470330145so59577311fa.3 for ; Wed, 21 Jun 2023 07:40:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1687358424; x=1689950424; 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=BIB5wlsg1EGijWyF8j75rKQgBWBiWi5YkvKjCqAmdlA=; b=hZPbxCk9XomiOQ86nLsKa9dg5VwY4wVkkRVEU+cDxbFEM+K8+b0BMrhwJnpdzq/0pz rCuE1hbYh8VV0GTWXM14TwPmqPvBWkle4n8WBK542wPk8521nEWj7NkXJcMaDrjttFam V4yR5DFCFFIcXklM/60ZbdaFtySrXICV+vjlfsokVGWjDPFVHyUQ3Y1qlqIXnRl97aV/ PLJkgb4n/lyGB9ibzT/VKBGZjLzaKarEAa6mAzHVeLR84tiestjLMnguFe8NI5QSWaBH leJnf2t9e+JPvcDCnoLkpHreNi/SOk8+ICal1qavMc32+jOF/InGmEPhs9dJ3JlgGBnI 41tA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687358424; x=1689950424; 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=BIB5wlsg1EGijWyF8j75rKQgBWBiWi5YkvKjCqAmdlA=; b=j4BnFUeptu54ePRlkWQgGHjwpg+N38olXlqplMdqIV1cchM8pox6B89IJBLQR9KMG3 urtqljjpKliVprD5dVyQeLfeFRbYqXtHoJHebEWnuTTksCqJvh941X6tFLpSs/uNQucY zbfsnnZUJ8AlWF/t+f3dKbj/X/XFzRgiqHhMOk2nsyjkwMWte3DliDPIxiOlr+U7rsAE /VjysDyn89pPlhhUUtZ3smiER8LUxorhLEue7n3E51ZOOuqIFDwyMxC6YTRHgINCy7BB sdQ0HsWr3drY1PDaVd8MyJQVXcn1t/mLmFnHdXmZVBqM4A35E6wgyxd9sXHB97CTJMGm 8teQ== X-Gm-Message-State: AC+VfDz7CMYkqRWcCtaS483B8ythc0sm77cjMSH7n94sektsZMpny7sc GwpMLex04PvvUtHRISFDdtM4QA== X-Google-Smtp-Source: ACHHUZ7k63ENiQkXV05akRIrSQQx+fyIyMmPCMnSBT7DefX3zvKIr+pXgiEvpsGoEML2BHGHFjQs5w== X-Received: by 2002:a2e:b16d:0:b0:2b4:7875:dd98 with SMTP id a13-20020a2eb16d000000b002b47875dd98mr6627839ljm.23.1687358424498; Wed, 21 Jun 2023 07:40:24 -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.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Jun 2023 07:40:23 -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 1/4] driver core: Add dev_set_drv_sync_state() Date: Wed, 21 Jun 2023 17:40:16 +0300 Message-Id: <20230621144019.3219858-2-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 From: Saravana Kannan This can be used by frameworks to set the sync_state() helper functions for drivers that don't already have them set. Signed-off-by: Saravana Kannan Acked-by: Greg Kroah-Hartman --- include/linux/device.h | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/include/linux/device.h b/include/linux/device.h index 66c13965153d..bae11928ef7e 100644 --- a/include/linux/device.h +++ b/include/linux/device.h @@ -995,6 +995,18 @@ static inline bool dev_has_sync_state(struct device *dev) return false; } +static inline int dev_set_drv_sync_state(struct device *dev, + void (*fn)(struct device *dev)) +{ + if (!dev || !dev->driver) + return 0; + if (dev->driver->sync_state && dev->driver->sync_state != fn) + return -EBUSY; + if (!dev->driver->sync_state) + dev->driver->sync_state = fn; + return 0; +} + static inline void dev_set_removable(struct device *dev, enum device_removable removable) { From patchwork Wed Jun 21 14:40:17 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Abel Vesa X-Patchwork-Id: 13287423 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 5B556EB64D7 for ; Wed, 21 Jun 2023 14:40:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231271AbjFUOka (ORCPT ); Wed, 21 Jun 2023 10:40:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50996 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231178AbjFUOk2 (ORCPT ); Wed, 21 Jun 2023 10:40:28 -0400 Received: from mail-ed1-x52f.google.com (mail-ed1-x52f.google.com [IPv6:2a00:1450:4864:20::52f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 515121739 for ; Wed, 21 Jun 2023 07:40:27 -0700 (PDT) Received: by mail-ed1-x52f.google.com with SMTP id 4fb4d7f45d1cf-51a324beca6so7884581a12.1 for ; Wed, 21 Jun 2023 07:40:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1687358426; x=1689950426; 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=2W3Kf4ey7QY4pTA3JpFMV/TNECBh7Gq30HfrcLuf2lU=; b=qvokshYUKY7HCe7qvXfL6wjYYLXu4sLS55Nbn5MMSRaW3ci8oSwdrPhew+rcuX2SGB ttF+BrNowbQuVuwKWys48yk9Pp0Rqcb8/qlhp3OiBdxnhHoN0cNYjwyl2jlRW3nIJnbP XSOR9VS87RpPQWiKFJHP5L0cJX0OAjgyeIkzIPN1YHYbGcaiD/eqsXgwwYd76a/cee65 gOf3sJhWtsKrOBhZTFPntSptaEMNKExo8zFZoqU4t94AQH59SXnYGMOn8JeiYbbh1Tdo xgKZP+jAeulj6cyNtmCOXXXogsSB3bnXaTruagohS/wdx+Sfv8zc0cM4+ifmo9z/x7QA fBOg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687358426; x=1689950426; 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=2W3Kf4ey7QY4pTA3JpFMV/TNECBh7Gq30HfrcLuf2lU=; b=Vw/p4JUyBynWlfmk19fnfeTzW7OCnYy9ApDcwWOjcTa4jdob37Af2XqY4U/rKO6tLz mabCiSJriNa0un+1xqz/r+3Le+rPTfruDx3xm3IJqWrT2AlWcCOMvePDCUxqPilWinRI N6yprUCQVTp4azxpFAH9bXjpPuo0xVFNrfCMKkQSB/k1F0RJAsBIT9aIaqJHmLlH/DTJ Lr6eBPBwnSV980UTgyMdtJEsvjNFgQi74irBONSGYChhzGJzlzUDE5uDtY00gBzxIDVI 23s72wwIGsLKysOZn0YsSCJZBIe4NpYmhuKH7NSvV6474sPhxAyfsZBboIsV9vdTEvnl ooPA== X-Gm-Message-State: AC+VfDwX4NAFoUyqFnXtZxuUc53roIYtdi49kDljcI9FFZpDdnnasVDT 0DUpgBg5XtjJBb1KsUCky2wDGw== X-Google-Smtp-Source: ACHHUZ41TS8wh8wraPOcFMSensNy0EVeaB1fuQHXmzdq80qlDOpEP1Dbjcjfb7T640VzWNcl1j9V2A== X-Received: by 2002:a05:6402:642:b0:51a:5ebe:4ab9 with SMTP id u2-20020a056402064200b0051a5ebe4ab9mr5948602edx.14.1687358425839; Wed, 21 Jun 2023 07:40:25 -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.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Jun 2023 07:40:25 -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 2/4] driver core: Add dev_is_drv_state_synced() Date: Wed, 21 Jun 2023 17:40:17 +0300 Message-Id: <20230621144019.3219858-3-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 This can be used by drivers to figure out if a different device driver has state synced or not for a specific device. Signed-off-by: Abel Vesa --- include/linux/device.h | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/include/linux/device.h b/include/linux/device.h index bae11928ef7e..8f042f04b5d9 100644 --- a/include/linux/device.h +++ b/include/linux/device.h @@ -1007,6 +1007,20 @@ static inline int dev_set_drv_sync_state(struct device *dev, return 0; } +static inline bool dev_is_drv_state_synced(struct device *dev) +{ + bool ret = false; + + if (!dev) + return ret; + + device_lock(dev); + ret = dev->state_synced; + device_unlock(dev); + + return ret; +} + static inline void dev_set_removable(struct device *dev, enum device_removable removable) { 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: 13287424 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 */ From patchwork Wed Jun 21 14:40:19 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Abel Vesa X-Patchwork-Id: 13287425 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 41D82EB64DC for ; Wed, 21 Jun 2023 14:40:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231777AbjFUOks (ORCPT ); Wed, 21 Jun 2023 10:40:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51154 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231346AbjFUOkf (ORCPT ); Wed, 21 Jun 2023 10:40:35 -0400 Received: from mail-ed1-x52b.google.com (mail-ed1-x52b.google.com [IPv6:2a00:1450:4864:20::52b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 08728171C for ; Wed, 21 Jun 2023 07:40:30 -0700 (PDT) Received: by mail-ed1-x52b.google.com with SMTP id 4fb4d7f45d1cf-51bdc87feb1so875334a12.3 for ; Wed, 21 Jun 2023 07:40:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1687358428; x=1689950428; 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=XmB7aafZYu+t3l7iCsSmX4rGYeW4d39sw8kiK1MfRbc=; b=vbFeL6g/0gsnlVG3qe4dFQ8UgIqumpBG61md5jata02BeIpTUP5kaC99ThhE7dmF4O I7Y6Zk5tYifXsAurwx4LMPSIMFpU9Uu6yDlI+EBdE6mOHSG1vQP3bEWFSAODNm5tMAIz LsRijdo+V3NVq1ZT/fxLXgfSryujgdNMA1JxE9gWEwTMz1pUqJLzarZBXWf44s239bLm TdB9UU5sroVO28ey88uuV0uMfBQwyLW+RskbylYy58Ok9Xk4xzMLpNXO98g5W5m1cRPx iD8aORPz8tkdFjxBJk6+5sw+YR+XVIlM9Clkc1SXJc9guWiefmUzSYaphjxgmLinhgdV +6xw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687358428; x=1689950428; 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=XmB7aafZYu+t3l7iCsSmX4rGYeW4d39sw8kiK1MfRbc=; b=kgWMIIkSzN48xgHmgTGslbPt6nWG/7uE1lQAqWElJWVY2cA8r1SMUxvr8oYJcw6VP7 6wQ9Kp+072AbABsuAluU3DN/99JXSC9RNtGUDmjqWFzC37mTdBBO0iyXN4reqnfVCP0s h/v8aJW1spOl8HJM0sGmPoJBdw0KoUggOb/FOHqI18LVZ1/xFp6ovlq26u6AR1ZyTCg7 89c+Y61ZyXHCqssBaiCHDas1beSdDPR6OTW4MZWI3fA0wnRSh3fZ75pupl7PY0mX8WWP HcyhJ88LDffaDO1G/PObouWTLhsDaZs3TBmfCaRYgcaJfBunn68ZzkZ2ZCWLk2CH+gO5 Tekg== X-Gm-Message-State: AC+VfDybLEhu02zwGWgvJg08RTnZ5CsClSXlmc8jackqxoYvj/LHyska BWEW1E0F9C1LzcXzGtqBfuAEfQ== X-Google-Smtp-Source: ACHHUZ4omXHV92p6l7BRCmNWk6b/xm5hYh8nglQVFTzBHSceHAhc/cMnje+b0wXypCUxuAfl56P+9g== X-Received: by 2002:aa7:c90f:0:b0:51a:50f2:4e7a with SMTP id b15-20020aa7c90f000000b0051a50f24e7amr7153676edt.13.1687358428418; Wed, 21 Jun 2023 07:40:28 -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.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Jun 2023 07:40:28 -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 4/4] PM: domains: Add and set generic sync state callback Date: Wed, 21 Jun 2023 17:40:19 +0300 Message-Id: <20230621144019.3219858-5-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 For every provider that doesn't register a sync_state callback, register a generic one. This new generic sync_state callback queues up a power off request. Signed-off-by: Abel Vesa --- drivers/base/power/domain.c | 23 +++++++++++++++++++++++ include/linux/pm_domain.h | 3 +++ 2 files changed, 26 insertions(+) diff --git a/drivers/base/power/domain.c b/drivers/base/power/domain.c index 5967ade160e2..ec16db0599ac 100644 --- a/drivers/base/power/domain.c +++ b/drivers/base/power/domain.c @@ -654,6 +654,27 @@ static void genpd_queue_power_off_work(struct generic_pm_domain *genpd) queue_work(pm_wq, &genpd->power_off_work); } +/** + * pm_genpd_power_off_unused_sync_state - Power off all domains for provider. + * @dev: Provider's device. + * + * Request power off for all unused domains of the provider. + * This should be used exclusively as sync state callback for genpd providers. + */ +void pm_genpd_power_off_unused_sync_state(struct device *dev) +{ + struct generic_pm_domain *genpd; + + mutex_lock(&gpd_list_lock); + + list_for_each_entry(genpd, &gpd_list, gpd_list_node) + if (genpd->provider && genpd->provider->dev == dev) + genpd_queue_power_off_work(genpd); + + mutex_unlock(&gpd_list_lock); +} +EXPORT_SYMBOL_GPL(pm_genpd_power_off_unused_sync_state); + /** * genpd_keep_on - Tells if the domain should skip the power 'off' request * @genpd: PM domain to be checked. @@ -2329,6 +2350,8 @@ static int genpd_add_provider(struct device_node *np, genpd_xlate_t xlate, cp->xlate = xlate; fwnode_dev_initialized(&np->fwnode, true); + dev_set_drv_sync_state(np->fwnode.dev, pm_genpd_power_off_unused_sync_state); + mutex_lock(&of_genpd_mutex); list_add(&cp->link, &of_genpd_providers); mutex_unlock(&of_genpd_mutex); diff --git a/include/linux/pm_domain.h b/include/linux/pm_domain.h index 3eb32c4b6d4f..78164244b89f 100644 --- a/include/linux/pm_domain.h +++ b/include/linux/pm_domain.h @@ -279,6 +279,9 @@ static inline int pm_genpd_remove(struct generic_pm_domain *genpd) return -EOPNOTSUPP; } +static inline void pm_genpd_power_off_unused_sync_state(struct device *dev) +{ } + static inline int dev_pm_genpd_set_performance_state(struct device *dev, unsigned int state) {