From patchwork Wed Jun 14 10:37:25 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 13279886 X-Patchwork-Delegate: viresh.linux@gmail.com 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 63B1FEB64DA for ; Wed, 14 Jun 2023 10:37:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235705AbjFNKhh (ORCPT ); Wed, 14 Jun 2023 06:37:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47294 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235592AbjFNKhe (ORCPT ); Wed, 14 Jun 2023 06:37:34 -0400 Received: from mail-pl1-x62b.google.com (mail-pl1-x62b.google.com [IPv6:2607:f8b0:4864:20::62b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 25D221732 for ; Wed, 14 Jun 2023 03:37:32 -0700 (PDT) Received: by mail-pl1-x62b.google.com with SMTP id d9443c01a7336-1b3dd3ca7adso21343095ad.3 for ; Wed, 14 Jun 2023 03:37:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1686739051; x=1689331051; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=0UJGMihjTj1hAjbmHZ6/JGiIPUmZ9LnZE7xgM/0VXOU=; b=mvOOi2pysANY+XAjid4/FlGD4AKXH5Ah/zFubhD1VbJI2jUrrbWcZ59q2tD8Ppibpo nPDCLEVGB+HMycGAfGsvRTPP6+Nxf2NinPMiL56X1sdqy6LXvtC03+nrltA6gRfMkYdP L/6ZiL0Rdb+Qdtd5cJm2Qc0VEFuXu2n8RkZctsQOIJX8VrK2m4DCoxBksfKZxeJfbeqH ViFmR2iPUUFufXbDpmw2raqGvoDKEu226XMRtVIe2yP7QLlqlxyKs25fVGHvLUMNpuVa m9rfT0/l3EVH6a9InjY0rBimeUJJRXTkFnRf2KwN3DlcAwnsyV5OmKYBjjgICm30Mnxv D81g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686739051; x=1689331051; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=0UJGMihjTj1hAjbmHZ6/JGiIPUmZ9LnZE7xgM/0VXOU=; b=X8vEj+2Hqs8V1ZmtsJE54dcmn4qnyyIsDD6S2P717XuSmqJy/nxjrcpm5s4Me3ChtE vzm4AM4HvECFeFLSSjlFKQQ01YT/OmP8TWT5I2VYnkeNTbu8ZzS0gfi3vNHlYPVh/ke8 LIpgjlc5IRJwFgCAQylxyDnpAfDuliEw8/XIjOiekbVM81PSoCY2ciNHLfJZUnorH5Q8 o9Vy66jDcMqAXwL3Ujj7Ois5wShqY35fNElANsKCdPW20wqz/gcs6TLHxPZjNYjjDz38 MsFBMKLEgxGlVnj1PyAwg0HaU6VYl9UN19M/0etFDMlH70pSlljzGoBwa9JjoWDYS5ce pR+g== X-Gm-Message-State: AC+VfDzakpabYbT/e/holu0aZ7aabxqoNTVcApsU+hCpwZBTOahrq+7S IjA3MEAPfBLzb7h58PHVsAB5kQ== X-Google-Smtp-Source: ACHHUZ7G6M362gZBo1XpHgAsxT45uBPwO0hp3bfI6761xauQ3K+uJ6CQ/i4/fw5QNPGONrZ2VKS58w== X-Received: by 2002:a17:902:6ac7:b0:1af:d724:63ed with SMTP id i7-20020a1709026ac700b001afd72463edmr11808868plt.42.1686739051243; Wed, 14 Jun 2023 03:37:31 -0700 (PDT) Received: from localhost ([122.172.87.195]) by smtp.gmail.com with ESMTPSA id az4-20020a170902a58400b001b1c3542f57sm11854863plb.103.2023.06.14.03.37.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 14 Jun 2023 03:37:30 -0700 (PDT) From: Viresh Kumar To: Viresh Kumar , Nishanth Menon , Stephen Boyd Cc: Viresh Kumar , linux-pm@vger.kernel.org, Vincent Guittot , "Rafael J. Wysocki" , Ulf Hansson , linux-kernel@vger.kernel.org Subject: [PATCH 1/2] OPP: pstate is only valid for genpd OPP tables Date: Wed, 14 Jun 2023 16:07:25 +0530 Message-Id: <5437756c65c79f9520886bc54321d39c022c8638.1686739018.git.viresh.kumar@linaro.org> X-Mailer: git-send-email 2.31.1.272.g89b43f80a514 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org It is not very clear right now that the `pstate` field is only valid for genpd OPP tables and not consumer tables. And there is no checking for the same at various places. Add checks in place to verify that and make it clear to the reader. Signed-off-by: Viresh Kumar Reviewed-by: Ulf Hansson Reviewed-by: Bjorn Andersson Tested-by: Bjorn Andersson --- drivers/opp/core.c | 18 ++++++++++++++++-- drivers/opp/debugfs.c | 4 +++- drivers/opp/of.c | 6 ++++++ 3 files changed, 25 insertions(+), 3 deletions(-) diff --git a/drivers/opp/core.c b/drivers/opp/core.c index 7290168ec806..bfb012f5383c 100644 --- a/drivers/opp/core.c +++ b/drivers/opp/core.c @@ -227,16 +227,24 @@ EXPORT_SYMBOL_GPL(dev_pm_opp_get_level); unsigned int dev_pm_opp_get_required_pstate(struct dev_pm_opp *opp, unsigned int index) { + struct opp_table *opp_table = opp->opp_table; + if (IS_ERR_OR_NULL(opp) || !opp->available || - index >= opp->opp_table->required_opp_count) { + index >= opp_table->required_opp_count) { pr_err("%s: Invalid parameters\n", __func__); return 0; } /* required-opps not fully initialized yet */ - if (lazy_linking_pending(opp->opp_table)) + if (lazy_linking_pending(opp_table)) return 0; + /* The required OPP table must belong to a genpd */ + if (unlikely(!opp_table->required_opp_tables[index]->is_genpd)) { + pr_err("%s: Performance state is only valid for genpds.\n", __func__); + return 0; + } + return opp->required_opps[index]->pstate; } EXPORT_SYMBOL_GPL(dev_pm_opp_get_required_pstate); @@ -2686,6 +2694,12 @@ int dev_pm_opp_xlate_performance_state(struct opp_table *src_table, int dest_pstate = -EINVAL; int i; + /* Both OPP tables must belong to genpds */ + if (unlikely(!src_table->is_genpd || !dst_table->is_genpd)) { + pr_err("%s: Performance state is only valid for genpds.\n", __func__); + return -EINVAL; + } + /* * Normally the src_table will have the "required_opps" property set to * point to one of the OPPs in the dst_table, but in some cases the diff --git a/drivers/opp/debugfs.c b/drivers/opp/debugfs.c index 2c7fb683441e..0cc21e2b42ff 100644 --- a/drivers/opp/debugfs.c +++ b/drivers/opp/debugfs.c @@ -152,11 +152,13 @@ void opp_debug_create_one(struct dev_pm_opp *opp, struct opp_table *opp_table) debugfs_create_bool("dynamic", S_IRUGO, d, &opp->dynamic); debugfs_create_bool("turbo", S_IRUGO, d, &opp->turbo); debugfs_create_bool("suspend", S_IRUGO, d, &opp->suspend); - debugfs_create_u32("performance_state", S_IRUGO, d, &opp->pstate); debugfs_create_u32("level", S_IRUGO, d, &opp->level); debugfs_create_ulong("clock_latency_ns", S_IRUGO, d, &opp->clock_latency_ns); + if (opp_table->is_genpd) + debugfs_create_u32("performance_state", S_IRUGO, d, &opp->pstate); + opp->of_name = of_node_full_name(opp->np); debugfs_create_str("of_name", S_IRUGO, d, (char **)&opp->of_name); diff --git a/drivers/opp/of.c b/drivers/opp/of.c index 943c7fb7402b..e23ce6e78eb6 100644 --- a/drivers/opp/of.c +++ b/drivers/opp/of.c @@ -1392,6 +1392,12 @@ int of_get_required_opp_performance_state(struct device_node *np, int index) goto put_required_np; } + /* The OPP tables must belong to a genpd */ + if (unlikely(!opp_table->is_genpd)) { + pr_err("%s: Performance state is only valid for genpds.\n", __func__); + goto put_required_np; + } + opp = _find_opp_of_np(opp_table, required_np); if (opp) { pstate = opp->pstate; From patchwork Wed Jun 14 10:37:26 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 13279887 X-Patchwork-Delegate: viresh.linux@gmail.com 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 998B0EB64D9 for ; Wed, 14 Jun 2023 10:37:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235592AbjFNKhi (ORCPT ); Wed, 14 Jun 2023 06:37:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47322 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235661AbjFNKhg (ORCPT ); Wed, 14 Jun 2023 06:37:36 -0400 Received: from mail-pg1-x52f.google.com (mail-pg1-x52f.google.com [IPv6:2607:f8b0:4864:20::52f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 204F419AC for ; Wed, 14 Jun 2023 03:37:35 -0700 (PDT) Received: by mail-pg1-x52f.google.com with SMTP id 41be03b00d2f7-543cc9541feso3532346a12.2 for ; Wed, 14 Jun 2023 03:37:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1686739054; x=1689331054; 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=uYcdmfInIY4iLHsu2ifmhCLSrZeHago4AwSaJYKqWeU=; b=GmPyR06c8WP0576PRGOpYS8J4G8kICYSimUk0m0JJI7EUlZlfjoEIwW3E1ot0fXUoD LAjgEI03sw+vCF83/PXxLTOyMsN4HK2oEUm6BRyqGFIIsj65lKARGTW/pAyT6bC+udgL iyCC5IWAaS1L/PfyAxsbetS8XjRC4U2jxq3Ui33zSg2BQAN3fc0SnV4LIIrMXkhCC2a5 Bc5YMgD1xXRSc4p8JrXujhmYNAHLJT4ZMAZSWCMo5Y9+i+UlKSW0uLL24OfwG+23zu/v a2BC5mKxeRVUrECK93DBlYyJ2OR1PLCA8WH5Fubfzzs5ECdn1xA7LSNh5kLuNs+XojeF i4ZQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686739054; x=1689331054; 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=uYcdmfInIY4iLHsu2ifmhCLSrZeHago4AwSaJYKqWeU=; b=Nzxh0mm5s447Tu9SRgO1WqlV2NzTx53Ge5ZPq3IpCs8GJ5NKe4u0IXj72mjPVQxiIq 0bRGDzsWImOHN8YzoEvWC51h9+lGg6j0KzQN0CDZkTpyH+mqzclqJ+yLu/+JEIUExGVV y/IXnoql23eYYE4ksTNX+kqHrwbX9iZ8r0mNbRjd2VCfZ4VfwKUxQKYhbuzEGgWeDTz/ dcNY8Of2+Bh/i86apKi4E82FvpJL661G+xbpryqN/9cj6G1DNYgC7Ij4B9soG6/k7Jtp Np86Yz0Tiv9xH6SdQG4QTboI2K3QszAK9i7W+sfNGl86yf9lynE426W5xPzLx173foo5 sEnQ== X-Gm-Message-State: AC+VfDzdWBUyZ/fFQkKCiJn0Cb/9fyGdFGQMKh/eYtjhl/Tt7pywuCNB vdA5zd+nVMd3j4RW/IQsgNH2RA== X-Google-Smtp-Source: ACHHUZ589iilNr7Jek4O5EuZFXNy9wIqySycd47hoKvnzu2cB+DDblm4K/08MehqjtdZv4i9oNxdIg== X-Received: by 2002:a05:6a20:12c8:b0:10c:9773:5e6 with SMTP id v8-20020a056a2012c800b0010c977305e6mr1025269pzg.47.1686739054531; Wed, 14 Jun 2023 03:37:34 -0700 (PDT) Received: from localhost ([122.172.87.195]) by smtp.gmail.com with ESMTPSA id t4-20020a170902a5c400b001ab0159b9edsm11827247plq.250.2023.06.14.03.37.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 14 Jun 2023 03:37:34 -0700 (PDT) From: Viresh Kumar To: Viresh Kumar , Nishanth Menon , Stephen Boyd Cc: Viresh Kumar , linux-pm@vger.kernel.org, Vincent Guittot , "Rafael J. Wysocki" , Ulf Hansson , linux-kernel@vger.kernel.org Subject: [PATCH 2/2] OPP: Simplify the over-designed pstate <-> level dance Date: Wed, 14 Jun 2023 16:07:26 +0530 Message-Id: X-Mailer: git-send-email 2.31.1.272.g89b43f80a514 In-Reply-To: <5437756c65c79f9520886bc54321d39c022c8638.1686739018.git.viresh.kumar@linaro.org> References: <5437756c65c79f9520886bc54321d39c022c8638.1686739018.git.viresh.kumar@linaro.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org While adding support for "performance states" in the OPP and genpd core, it was decided to set the `pstate` field via genpd's pm_genpd_opp_to_performance_state() helper, to allow platforms to set `pstate` even if they don't have a corresponding `level` field in the DT OPP tables (More details are present in commit 6e41766a6a50 ("PM / Domain: Implement of_genpd_opp_to_performance_state()")). Revisiting that five years later clearly suggests that it was over-designed as all current users are eventually using the `level` value only. The previous commit already added necessary checks to make sure pstate is only used for genpd tables. Lets now simplify this a little, and use `level` directly and remove `pstate` field altogether. Suggested-by: Ulf Hansson Signed-off-by: Viresh Kumar Reviewed-by: Ulf Hansson --- drivers/opp/core.c | 8 ++++---- drivers/opp/debugfs.c | 2 +- drivers/opp/of.c | 5 +---- drivers/opp/opp.h | 2 -- 4 files changed, 6 insertions(+), 11 deletions(-) diff --git a/drivers/opp/core.c b/drivers/opp/core.c index bfb012f5383c..48ddd72d2c71 100644 --- a/drivers/opp/core.c +++ b/drivers/opp/core.c @@ -245,7 +245,7 @@ unsigned int dev_pm_opp_get_required_pstate(struct dev_pm_opp *opp, return 0; } - return opp->required_opps[index]->pstate; + return opp->required_opps[index]->level; } EXPORT_SYMBOL_GPL(dev_pm_opp_get_required_pstate); @@ -943,7 +943,7 @@ static int _set_opp_bw(const struct opp_table *opp_table, static int _set_performance_state(struct device *dev, struct device *pd_dev, struct dev_pm_opp *opp, int i) { - unsigned int pstate = likely(opp) ? opp->required_opps[i]->pstate : 0; + unsigned int pstate = likely(opp) ? opp->required_opps[i]->level: 0; int ret; if (!pd_dev) @@ -2728,8 +2728,8 @@ int dev_pm_opp_xlate_performance_state(struct opp_table *src_table, mutex_lock(&src_table->lock); list_for_each_entry(opp, &src_table->opp_list, node) { - if (opp->pstate == pstate) { - dest_pstate = opp->required_opps[i]->pstate; + if (opp->level == pstate) { + dest_pstate = opp->required_opps[i]->level; goto unlock; } } diff --git a/drivers/opp/debugfs.c b/drivers/opp/debugfs.c index 0cc21e2b42ff..954ea31a2ff3 100644 --- a/drivers/opp/debugfs.c +++ b/drivers/opp/debugfs.c @@ -157,7 +157,7 @@ void opp_debug_create_one(struct dev_pm_opp *opp, struct opp_table *opp_table) &opp->clock_latency_ns); if (opp_table->is_genpd) - debugfs_create_u32("performance_state", S_IRUGO, d, &opp->pstate); + debugfs_create_u32("performance_state", S_IRUGO, d, &opp->level); opp->of_name = of_node_full_name(opp->np); debugfs_create_str("of_name", S_IRUGO, d, (char **)&opp->of_name); diff --git a/drivers/opp/of.c b/drivers/opp/of.c index e23ce6e78eb6..e6d1155d0990 100644 --- a/drivers/opp/of.c +++ b/drivers/opp/of.c @@ -945,9 +945,6 @@ static struct dev_pm_opp *_opp_add_static_v2(struct opp_table *opp_table, if (ret) goto free_required_opps; - if (opp_table->is_genpd) - new_opp->pstate = pm_genpd_opp_to_performance_state(dev, new_opp); - ret = _opp_add(dev, new_opp, opp_table); if (ret) { /* Don't return error for duplicate OPPs */ @@ -1400,7 +1397,7 @@ int of_get_required_opp_performance_state(struct device_node *np, int index) opp = _find_opp_of_np(opp_table, required_np); if (opp) { - pstate = opp->pstate; + pstate = opp->level; dev_pm_opp_put(opp); } diff --git a/drivers/opp/opp.h b/drivers/opp/opp.h index 3805b92a6100..8a5ea38f3a3d 100644 --- a/drivers/opp/opp.h +++ b/drivers/opp/opp.h @@ -78,7 +78,6 @@ struct opp_config_data { * @turbo: true if turbo (boost) OPP * @suspend: true if suspend OPP * @removed: flag indicating that OPP's reference is dropped by OPP core. - * @pstate: Device's power domain's performance state. * @rates: Frequencies in hertz * @level: Performance level * @supplies: Power supplies voltage/current values @@ -101,7 +100,6 @@ struct dev_pm_opp { bool turbo; bool suspend; bool removed; - unsigned int pstate; unsigned long *rates; unsigned int level;