Received: by 2002:a25:f815:0:0:0:0:0 with SMTP id u21csp4119933ybd; Tue, 25 Jun 2019 14:34:23 -0700 (PDT) X-Google-Smtp-Source: APXvYqyYQ9mhC5Xt5Ed0rDu57Fz/zjjFds7VOzh0bxFzWTztOgVW1vU5MhFgV1ISq8APqZRV+LcH X-Received: by 2002:a63:ed13:: with SMTP id d19mr40753314pgi.100.1561498463475; Tue, 25 Jun 2019 14:34:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1561498463; cv=none; d=google.com; s=arc-20160816; b=CDWJtdbRkmfvDSWMG6Qik5XjQ1spsIYYjbeRIItObvswh5GUZ+HbC9zCgVj6IPxhZL DbeOS1THnzkEdlZowutDcVFf03SuFqPdkf6IZXQf03RUqXjNtWDaN5kUSj/CZSvNUewg pJPx7EmxIr/7GS7tqQ8jTJ2gqAHWCZPgvnFQ4tuI3+pk3GNnPgNT81NeTHNOIN96XqH+ tRMuVJ3ZAZH34voSI/04DbjSRvL7xGx9mmEeT/K4kxlkhtfIuUzrONNsZXdiKlncMHw9 P1n1RiMOmQsdw+KF4M+Mbb4gl7OE5b86lYgTKt37fg9oGV1OAA4DW2C9rhGu75soFkLm tN2w== 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=55ECQLYpQeuYJFjToVK2bkLCDXOJV5cNzofiMV5ttzw=; b=RIbMLiKxKJ688BEvhp3VvZ7F1oaFCY4VVWNnvzo7uvd0Xc5ry4caYSItNZ0KqF3ajl tVhmwSrsBbJdWKBV6iQN061Z5nbC5kDUHw0KxidIYDIOvurfcTBroVnBr+mfWHV0C2eA yqwhwUvZPczVkYIk47NKUNgEA/RvvVFhbQuDx/fP/hzGM5E0fWtOB817NtnDZqA/EZ33 Sfe77Hxxy+VxiDE3UUw6ObTXwMmquAo1ZPaxFxfFyMzlolhM3hcUEtJLf60/Ke3+t1X3 2Hm1vZ3ZnjoGf8PJTyTq8MBlmJo3kbE5KKIHn5DfBq4pIETnChdhfrwH9D688AFw/aWJ NV6w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=Spli0ntD; 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 j17si14652783pfr.13.2019.06.25.14.34.05; Tue, 25 Jun 2019 14:34:23 -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=Spli0ntD; 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 S1726437AbfFYVdw (ORCPT + 99 others); Tue, 25 Jun 2019 17:33:52 -0400 Received: from mail-yw1-f73.google.com ([209.85.161.73]:50842 "EHLO mail-yw1-f73.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726387AbfFYVdt (ORCPT ); Tue, 25 Jun 2019 17:33:49 -0400 Received: by mail-yw1-f73.google.com with SMTP id p18so326405ywe.17 for ; Tue, 25 Jun 2019 14:33:48 -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=55ECQLYpQeuYJFjToVK2bkLCDXOJV5cNzofiMV5ttzw=; b=Spli0ntDMpZ6dRXQDnlLhHi0fVx1WJuQhhfvcZPaGNmfW7Y/kXel+iFyKdsv2i5jfn CFQ2CGGfAQ9miZBR4q346MAMIACb09Gafnlrr1Onm9mlLpE/MV5UmAor4wbEgj4CS205 d/NmuMjGqTEkJwbO3TlKcTrFEf63tafgWWCWMrw/l5qzS6AvehlP0MmNi7JbgkGjBlwk s/kQ3B9QNKelCtt9BVx0DZ0UriXid+4I82Jz4XgbzE7qFgiAJCXVetqbRckxngxP+Qos QDfPN2FcKkTbrGon55ExRecGZsnBkbu8MrLHNkaeG2zSzf3Sj+o/h4bPNVM1DatH/rs2 iKLw== 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=55ECQLYpQeuYJFjToVK2bkLCDXOJV5cNzofiMV5ttzw=; b=G1m2QuX/3vY+0o/UIS0qtrQr2rAom6zt5Xa1E9YP0sf4XnZ6I/zkln8zsFQZktA1DS a6m8iXSr32eKgQlsqNvQx1UuUFp9HDfsVS5YX7GYJhKJMIPE+/OKtEI0VNCSz2uPpkgO x9VhlwOmT0IktILBDrAnyoAVey++mfRjcor0j33dK3wLBKymJxLwmyokiwnVovTgF370 J1pwudBO8eGcP0YOp7d5LByygsZHQEw0cTGNvT83vw+I7jasvChaZjRIV+w8rNj97ZRD b9I/VMVKIiI3vkdp7RjD0Qg6wCBPdyRsLp5riakHVVWvwlHqHpQuDRlgfh6VGo/Z1HkI NxRA== X-Gm-Message-State: APjAAAUtBxzsOrN3UVDq13rbWtl+cuqApPkvJQ6TeKdoJVe29ZoumuMv W4Rg0tdVQdOi432pQ37KXcqxiYIG3CnUrXU= X-Received: by 2002:a81:7746:: with SMTP id s67mr563043ywc.257.1561498428384; Tue, 25 Jun 2019 14:33:48 -0700 (PDT) Date: Tue, 25 Jun 2019 14:33:35 -0700 In-Reply-To: <20190625213337.157525-1-saravanak@google.com> Message-Id: <20190625213337.157525-3-saravanak@google.com> Mime-Version: 1.0 References: <20190625213337.157525-1-saravanak@google.com> X-Mailer: git-send-email 2.22.0.410.gd8fdbe21b5-goog Subject: [PATCH v2 2/4] OPP: Add function to look up required OPP's for a given OPP From: Saravana Kannan To: MyungJoo Ham , Kyungmin Park , Chanwoo Choi , Viresh Kumar , Nishanth Menon , Stephen Boyd , "Rafael J. Wysocki" Cc: Saravana Kannan , kernel-team@android.com, linux-pm@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.410.gd8fdbe21b5-goog