Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp496313ybi; Thu, 13 Jun 2019 21:18:15 -0700 (PDT) X-Google-Smtp-Source: APXvYqz3MOxgG8fzRdqKu8G9IzrdANLfDZdyOVGVOqt0gfznGae/xgAwcstlt7hiw8N0U21IBQNK X-Received: by 2002:a63:5d25:: with SMTP id r37mr32838176pgb.449.1560485895377; Thu, 13 Jun 2019 21:18:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1560485895; cv=none; d=google.com; s=arc-20160816; b=o+yLsF0DrBnjphdE/rEJAdT1WDlGLxS9Frc6rjiQdMAwRH1i9pb6BWgmGJ7/GpzrgV 7galWPdby1k44sjdNRKgpkxNdVIAVd3DRyB2bDec7DA0Wyqjc7CKErOX09YSRpB/J/xQ /OTtPxUSSWfVMleKnzxUbOl5+lM7I4xFKQHkPgZM7xCxh3FM8hCo0aiEB/DZQz1DeSEd /cMKjip9GTyVX3Y6VB6dz+IAEVjnxbiSqORN/8BWr04ejhzAToZiJFWjdPhWWW72b66x DOX/Hmh5VD/XAMixgO8VGODyCX7PNEfvYRgYMJ2pMtv+ApzZKz51pfu4NsEPXdt340OA 6Mwg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:from:subject:references :mime-version:message-id:in-reply-to:date:dkim-signature; bh=aquWBLmVdfTsfPmb1EWD0BsWvbkQBS182ArgyBvCIFk=; b=J1Ec4sNZ440AnG67OghG9i/0ZBz/XHQJSxK8FUZG1Hs8ZRdR1ZxambCQnjUYrPwWPQ i4znYtLCRCMJmSO5QSEEzj/u6sywAlHkJxz3uC8SvkWOl3RBvF2OvNUktjuMBTJrOYLi fHxZJm/0+K9yvl4SeqZ5udN6qSx0rtsS+d72b3wjjGGopEu/vHRemaMkq5//eTHPd0Im omiJBhAI+YsSJuqE/zrNg2VH8l8v7XNN+53NLNtyYm5pMdbPb1cT5NoqFv+c6MVGUfNY RgWN3ztBaeqqdidiIVEHNRK6rL1jxPomKxeTDpVWh5gtIZukoxQyMdwLg+gCXBRv78Ni iiNg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=SALd+e5W; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id d142si1250578pfd.217.2019.06.13.21.17.59; Thu, 13 Jun 2019 21:18:15 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-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=@google.com header.s=20161025 header.b=SALd+e5W; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726073AbfFNERq (ORCPT + 99 others); Fri, 14 Jun 2019 00:17:46 -0400 Received: from mail-pf1-f202.google.com ([209.85.210.202]:51139 "EHLO mail-pf1-f202.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725886AbfFNERp (ORCPT ); Fri, 14 Jun 2019 00:17:45 -0400 Received: by mail-pf1-f202.google.com with SMTP id u7so833234pfh.17 for ; Thu, 13 Jun 2019 21:17:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=aquWBLmVdfTsfPmb1EWD0BsWvbkQBS182ArgyBvCIFk=; b=SALd+e5WH1k6h9KcX/9goKx7DKFiD/tzpEIBpi1VyWU7XvDu2xfmpkkCjFagLgLKso k1F40bZQT27d7k8eZ/rO9FhFjh+RR+wKxJlzQBp9VaLE8hPlY104nQTZUPgpBNn2mBPT ++1C4AFj9N2cFkqt3XQBxF6i5xX1XSSOJtAeBM2KoD1aCwZr+WpBiJTtGYSyIu8/SEA6 Ev3DN/C/EBTdnmu7GB6Qeihyh1trdVho2bgPh4i+MQk6bPv0Y3nBGorTJMx2a7I+qcye +Q96sesGXGqkm4m66kbYNy19Ae8APrRe2uRpJPw13DLMOyKylYFGNOgNFe/yzbhVkTk9 c4EQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=aquWBLmVdfTsfPmb1EWD0BsWvbkQBS182ArgyBvCIFk=; b=HR2kRSOeOvDiFsz00cA8vIGuqHR32EaUxwPDpDOLY4FX6ORC8HGti0tfDjqzbQcyRv GltkZri/fqsSwNXjnTjndNSzN8n9TCPMtkpGNOD+eu/DhDEyHgY/2V/HkxnKdrcro/7j gRc3JQYtRYW0SLm7ureJdv3unkqzebA8tWKDiuVj9kLOgw0a0s6PHsf1KHXmejMwmraV WnyNpw0NNXPs9ghWzfnfY4fvjWoPes/E+OhvdjfO8quhnkbhTenuXNXllUyEI/gcg7xn IcGEX9hEj5X0p7ThdM3+eHJmA5vOV+q+YJ48XP0H5JN0qYxTL/pbJdFxm1ccNFfu1h5V cGDg== X-Gm-Message-State: APjAAAVKEuO1i1I3JRAmVV/pOyTlCaoLB13xljz8IPsYAMIxKhX4DMvr f8xDaCw9WFGqxGmUnF6n0FQ6BqDwo4u/7qA= X-Received: by 2002:a63:de0e:: with SMTP id f14mr14823969pgg.348.1560485864345; Thu, 13 Jun 2019 21:17:44 -0700 (PDT) Date: Thu, 13 Jun 2019 21:17:24 -0700 In-Reply-To: <20190614041733.120807-1-saravanak@google.com> Message-Id: <20190614041733.120807-3-saravanak@google.com> Mime-Version: 1.0 References: <20190614041733.120807-1-saravanak@google.com> X-Mailer: git-send-email 2.22.0.rc2.383.gf4fbbf30c2-goog Subject: [PATCH v2 02/11] OPP: Add function to look up required OPP's for a given OPP From: Saravana Kannan To: Georgi Djakov , Rob Herring , Mark Rutland , Viresh Kumar , Nishanth Menon , Stephen Boyd , "Rafael J. Wysocki" , MyungJoo Ham , Kyungmin Park , Chanwoo Choi Cc: Saravana Kannan , Rajendra Nayak , Jordan Crouse , vincent.guittot@linaro.org, bjorn.andersson@linaro.org, amit.kucheria@linaro.org, seansw@qti.qualcomm.com, daidavid1@codeaurora.org, evgreen@chromium.org, sibis@codeaurora.org, kernel-team@android.com, linux-pm@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Add a function that allows looking up required OPPs given a source OPP table, destination OPP table and the source OPP. Signed-off-by: Saravana Kannan --- drivers/opp/core.c | 54 ++++++++++++++++++++++++++++++++++++++++++ include/linux/pm_opp.h | 11 +++++++++ 2 files changed, 65 insertions(+) diff --git a/drivers/opp/core.c b/drivers/opp/core.c index 74c7bdc6f463..4f7870bffbf8 100644 --- a/drivers/opp/core.c +++ b/drivers/opp/core.c @@ -1830,6 +1830,60 @@ 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_opp() - Find required OPP for src_table OPP. + * @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: OPP of the src_table. + * + * This function returns the OPP (present in @dst_table) pointed out by the + * "required-opps" property of the OPP (present in @src_table). + * + * The callers are required to call dev_pm_opp_put() for the returned OPP after + * use. + * + * Return: destination table OPP on success, otherwise NULL on errors. + */ +struct dev_pm_opp *dev_pm_opp_xlate_opp(struct opp_table *src_table, + struct opp_table *dst_table, + struct dev_pm_opp *src_opp) +{ + struct dev_pm_opp *opp, *dest_opp = NULL; + int i; + + if (!src_table || !dst_table || !src_opp) + return NULL; + + 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 NULL; + } + + mutex_lock(&src_table->lock); + + list_for_each_entry(opp, &src_table->opp_list, node) { + if (opp == src_opp) { + dest_opp = opp->required_opps[i]; + dev_pm_opp_get(dest_opp); + 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_opp; +} + /** * 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. diff --git a/include/linux/pm_opp.h b/include/linux/pm_opp.h index b150fe97ce5a..bc5c68bdfc8d 100644 --- a/include/linux/pm_opp.h +++ b/include/linux/pm_opp.h @@ -134,6 +134,9 @@ 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); +struct dev_pm_opp *dev_pm_opp_xlate_opp(struct opp_table *src_table, + struct opp_table *dst_table, + struct dev_pm_opp *src_opp); 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); @@ -307,6 +310,14 @@ static inline int dev_pm_opp_xlate_performance_state(struct opp_table *src_table return -ENOTSUPP; } +static inline struct dev_pm_opp *dev_pm_opp_xlate_opp( + struct opp_table *src_table, + struct opp_table *dst_table, + struct dev_pm_opp *src_opp) +{ + return NULL; +} + static inline int dev_pm_opp_set_rate(struct device *dev, unsigned long target_freq) { return -ENOTSUPP; -- 2.22.0.rc2.383.gf4fbbf30c2-goog