From patchwork Fri Dec 14 10:15:29 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 153806 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp1881762ljp; Fri, 14 Dec 2018 02:15:49 -0800 (PST) X-Google-Smtp-Source: AFSGD/U9DMPXvRho0D71Aa2k6IdekoDCLiwaSbyJzwjnfnhVrGTNNbnc7ei32ink7lLf+vHg7Byb X-Received: by 2002:a63:1157:: with SMTP id 23mr2170555pgr.245.1544782549693; Fri, 14 Dec 2018 02:15:49 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1544782549; cv=none; d=google.com; s=arc-20160816; b=EmmXGp4v0+f8X0erGx4vKRp6sYwlt4fMJP8GlzB0IqulmrVbCcm3qtMGI+AT0sFzrd uM02X9JNhWMNZNmJ7q6bDs7vZRBqQvXQ5GDhn0YF84bUDGSU/cJQ4e7PvM9nq/MTgvsE x2J8HYuS0zZ+nL0cpbAIvQSWfV8B1IZHw5xeI4F6GFoNqOkg8gR4bA9MoBxbxC7alfr6 kso2atAhW1fNuiRjFNTSLOv/zgBbzGF8jLKQLOtkgEWgv79Q54k4C8+Nlj4yAouxF71h 5bnvIck27DGSDCyInCp01ztPIHFO69MNFz+k3L/cOX+4mTexo4UeXzMpKg+NY7zPUi0v EGZA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=GkuIX39i4rCYkrrJtZv3mmFIkfBIoBUxRhe9gw4VKQg=; b=eVK5q/fdl+FdWzaEL/eTmooucXUTPLVhxguk5qEqttVg3AMX5OHy8CncbbtkdZfzv2 S0urev/h2gp1W7MN6C8jlkowo2q1RFiF6C2w35u58f0aIf08TdjWlBAWa+7PdiOlLuE6 QGSUlbEE+jUnO2oDuEaFRFZ7ArLVjQmIZy2HAS1i7k1b5aN1vwocExxs803QVnTIBwyY eJAGI3dlcv2bFU0UScefZsyn1asarZwVIrOkWD5Cscd6Lwm8M8yNHYPuf1JsR8xHHt55 LeePooRq07GXqiNHA+FpeYRhEvhT6hQ75tXVWEX0IzB3+/r4Re4uOvPN6bqqmfhsGHyu Hsvg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=F4tdvChz; spf=pass (google.com: best guess record for domain of linux-pm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-pm-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id v4si3778037pfm.71.2018.12.14.02.15.49; Fri, 14 Dec 2018 02:15:49 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-pm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=F4tdvChz; spf=pass (google.com: best guess record for domain of linux-pm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-pm-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 S1729499AbeLNKPs (ORCPT + 11 others); Fri, 14 Dec 2018 05:15:48 -0500 Received: from mail-pg1-f194.google.com ([209.85.215.194]:39855 "EHLO mail-pg1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729488AbeLNKPs (ORCPT ); Fri, 14 Dec 2018 05:15:48 -0500 Received: by mail-pg1-f194.google.com with SMTP id w6so2501382pgl.6 for ; Fri, 14 Dec 2018 02:15:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=GkuIX39i4rCYkrrJtZv3mmFIkfBIoBUxRhe9gw4VKQg=; b=F4tdvChzO67jzzhDjYAYnpTanNNJ4rOvWFk+/gzYQHsB5ENhaVc0yIYK2i+MpdkJBb l9vN/I3jDp0rjKOs65VHOW0xdnULsMaU7ZFvkV7SHrE7zyc+cbT4mOd6siINiG23fC/+ xwyVpkXjE8BKL1AGJstHuBqmtdLtzpbyqTz3g= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=GkuIX39i4rCYkrrJtZv3mmFIkfBIoBUxRhe9gw4VKQg=; b=fuRvcux5lcaxccFKalKhOj5hDpE3l08hJvKQbcgcyp5vaE3UcfOVT7S2HcCw4vyFq1 vSRZRHV+sk+2OA+6HI2Q9m5oMVM1/Bjxb7ewOGgOLT60QVqHFHBXOiSTAeMNjKoy0YdF MbfCAimNT5MQjVSAv6Zhi8+xDEOxNDpyISGe+h7TJ4IFMCCUjhyLpWYGeXSDDTzZGWkr oSbsd+/I8f8M9lcl4fouq7LqJTVWoYgvJVHw4Ghvwind2Xyv5BTZxaFzFV9Bvz1vZoy1 axWL+ItjwohlshFwKFzaUqDi0MfMgiFpBaJnIYGqDIlZja60zcqPHZhhIRVkSrVT5Z0X g5kA== X-Gm-Message-State: AA+aEWZDfXCHmUyAlBURkcOVb4Ror/XNo4HxqVGNCiBXJZU9GNuE3iOb s0nA635xWQstVUyyrqLqo0Nq9A== X-Received: by 2002:a63:2054:: with SMTP id r20mr2165843pgm.328.1544782547498; Fri, 14 Dec 2018 02:15:47 -0800 (PST) Received: from localhost ([122.172.23.29]) by smtp.gmail.com with ESMTPSA id l69sm10100872pfb.75.2018.12.14.02.15.46 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 14 Dec 2018 02:15:46 -0800 (PST) From: Viresh Kumar To: ulf.hansson@linaro.org, Rafael Wysocki , Viresh Kumar , Nishanth Menon , Stephen Boyd Cc: Viresh Kumar , linux-pm@vger.kernel.org, Vincent Guittot , rnayak@codeaurora.org, niklas.cassel@linaro.org, linux-kernel@vger.kernel.org Subject: [PATCH V4 3/7] OPP: Add dev_pm_opp_xlate_performance_state() helper Date: Fri, 14 Dec 2018 15:45:29 +0530 Message-Id: <135e59ab6353cc086b15ef96e2882aaec08e3322.1544782279.git.viresh.kumar@linaro.org> X-Mailer: git-send-email 2.19.1.568.g152ad8e3369a In-Reply-To: References: MIME-Version: 1.0 Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org dev_pm_genpd_set_performance_state() needs to handle performance state propagation going forward. Currently this routine only gets the required performance state of the device's genpd as an argument, but it doesn't know how to translate that to master genpd(s) of the device's genpd. Introduce a new helper dev_pm_opp_xlate_performance_state() which will be used to translate from performance state of a device (or genpd sub-domain) to another device (or master genpd). Normally the src_table (of genpd sub-domain) will have the "required_opps" property set to point to one of the OPPs in the dst_table (of master genpd), but in some cases the genpd and its master have one to one mapping of performance states and so none of them have the "required-opps" property set. Return the performance state of the src_table as it is in such cases. Tested-by: Rajendra Nayak Signed-off-by: Viresh Kumar --- drivers/opp/core.c | 63 ++++++++++++++++++++++++++++++++++++++++++ include/linux/pm_opp.h | 7 +++++ 2 files changed, 70 insertions(+) -- 2.19.1.568.g152ad8e3369a diff --git a/drivers/opp/core.c b/drivers/opp/core.c index 98e60f0ed8b0..e5507add8f04 100644 --- a/drivers/opp/core.c +++ b/drivers/opp/core.c @@ -1713,6 +1713,69 @@ void dev_pm_opp_put_genpd_virt_dev(struct opp_table *opp_table, dev_err(virt_dev, "Failed to find required device entry\n"); } +/** + * dev_pm_opp_xlate_performance_state() - Find required OPP's pstate for src_table. + * @src_table: OPP table which has dst_table as one of its required OPP table. + * @dst_table: Required OPP table of the src_table. + * @pstate: Current performance state of the src_table. + * + * This Returns pstate of the OPP (present in @dst_table) pointed out by the + * "required-opps" property of the OPP (present in @src_table) which has + * performance state set to @pstate. + * + * Return: Zero or positive performance state on success, otherwise negative + * value on errors. + */ +int dev_pm_opp_xlate_performance_state(struct opp_table *src_table, + struct opp_table *dst_table, + unsigned int pstate) +{ + struct dev_pm_opp *opp; + int dest_pstate = -EINVAL; + int i; + + if (!pstate) + return 0; + + /* + * 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 + * genpd and its master have one to one mapping of performance states + * and so none of them have the "required-opps" property set. Return the + * pstate of the src_table as it is in such cases. + */ + if (!src_table->required_opp_count) + return pstate; + + for (i = 0; i < src_table->required_opp_count; i++) { + if (src_table->required_opp_tables[i]->np == dst_table->np) + break; + } + + if (unlikely(i == src_table->required_opp_count)) { + pr_err("%s: Couldn't find matching OPP table (%p: %p)\n", + __func__, src_table, dst_table); + return -EINVAL; + } + + 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; + goto unlock; + } + } + + pr_err("%s: Couldn't find matching OPP (%p: %p)\n", __func__, src_table, + dst_table); + +unlock: + mutex_unlock(&src_table->lock); + + return dest_pstate; +} + /** * dev_pm_opp_add() - Add an OPP table from a table definitions * @dev: device for which we do this operation diff --git a/include/linux/pm_opp.h b/include/linux/pm_opp.h index 2b2c3fd985ab..0b04c2093eb9 100644 --- a/include/linux/pm_opp.h +++ b/include/linux/pm_opp.h @@ -128,6 +128,7 @@ struct opp_table *dev_pm_opp_register_set_opp_helper(struct device *dev, int (*s void dev_pm_opp_unregister_set_opp_helper(struct opp_table *opp_table); struct opp_table *dev_pm_opp_set_genpd_virt_dev(struct device *dev, struct device *virt_dev, int index); void dev_pm_opp_put_genpd_virt_dev(struct opp_table *opp_table, struct device *virt_dev); +int dev_pm_opp_xlate_performance_state(struct opp_table *src_table, struct opp_table *dst_table, unsigned int pstate); int dev_pm_opp_set_rate(struct device *dev, unsigned long target_freq); int dev_pm_opp_set_sharing_cpus(struct device *cpu_dev, const struct cpumask *cpumask); int dev_pm_opp_get_sharing_cpus(struct device *cpu_dev, struct cpumask *cpumask); @@ -280,6 +281,12 @@ static inline struct opp_table *dev_pm_opp_set_genpd_virt_dev(struct device *dev } static inline void dev_pm_opp_put_genpd_virt_dev(struct opp_table *opp_table, struct device *virt_dev) {} + +static inline int dev_pm_opp_xlate_performance_state(struct opp_table *src_table, struct opp_table *dst_table, unsigned int pstate) +{ + return -ENOTSUPP; +} + static inline int dev_pm_opp_set_rate(struct device *dev, unsigned long target_freq) { return -ENOTSUPP;