Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp136381pxb; Wed, 3 Feb 2021 01:29:59 -0800 (PST) X-Google-Smtp-Source: ABdhPJwKFAPg0RtoQRC+dAgTteS0OMU31nV1l7cqmuH86ftgSW1FfzipFhw+Dycb1UFawo1Hy500 X-Received: by 2002:a17:906:6d44:: with SMTP id a4mr2356027ejt.453.1612344599716; Wed, 03 Feb 2021 01:29:59 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1612344599; cv=none; d=google.com; s=arc-20160816; b=Tu2BwourddpZ/TDu65BQTr0nrqCxyeaZlExN0+GTTB4a8SIgSjwONgqEwMpQO9frSb DXN3/q0Pr/aHDazdXRfc2VgTE89yexzRUEiuQj5QcE/Oe4xFNsZ16LDrN68+f9aqZa2p 8o0kYf5PKljlLNMs/DZRpgkxUDbk/YNJMAaO3/tgPc0T+eHmI3J7EKMf6GRRd/wwdm+B gkBEh1/m1ekkJv5++NQbdj2qpKw2gO0LxknwfT3FlMSzEiXvqhmLfTDIZ9ygpTKAgbJQ WPjKC8ypuj9ZMYqWixiLjkinGBkrzDwjrjXBN8keDTus7WQuSQFwYRT/Qr1+yrL6wTTo kh8A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=HZ6BkzwJWuysG9Ncleyt9tGqJKvRpmo0CkvfsB7TcKk=; b=ALUVqqntHRl21PWups6xBEwtKgGGNwdgRIGr98wwrQ6d5VJ0HwXuuadu/hurcRrAv6 fZ/kH4hE8TcIvpdSZyzIZEzkvQwU6pA/8liM3Ps7WF5fqNux3lwZBxCEwhXGy7sBDSAh j5A3hsJAAQVGS4L3idMjBWg5l1F99Djrv8DtnBBiL6hObGwX5qaX6BzGPbw/Z8rigYb4 kwNrYcU9JFPzUkrQzzEpUQStBRkNZBYIYZuzlCe7bq95P6kyB4Lp54bOHWERdfVp750R rgkEqHaq5gBOfekBnyNcNvcleBU3jQXkBKWXjG8V7tAL+8W3FR/Xbtr/nMAMeR1mjZ5b rfog== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b="Ann/UFGc"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id s12si792968edw.252.2021.02.03.01.29.35; Wed, 03 Feb 2021 01:29:59 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b="Ann/UFGc"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233450AbhBCJ05 (ORCPT + 99 others); Wed, 3 Feb 2021 04:26:57 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45836 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233340AbhBCJYt (ORCPT ); Wed, 3 Feb 2021 04:24:49 -0500 Received: from mail-pf1-x434.google.com (mail-pf1-x434.google.com [IPv6:2607:f8b0:4864:20::434]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DDDDEC0613ED for ; Wed, 3 Feb 2021 01:24:08 -0800 (PST) Received: by mail-pf1-x434.google.com with SMTP id m6so16281464pfk.1 for ; Wed, 03 Feb 2021 01:24:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=HZ6BkzwJWuysG9Ncleyt9tGqJKvRpmo0CkvfsB7TcKk=; b=Ann/UFGcEilfP4bbNvsmSpXNxAD6le02tln9ZZDTT8t0N8m2tunukhf/ECBfEAztwT 78yf8YtmRnWyKRPunIopa4FAFk1DgkrmMMr65nbMX+wzzIvrTfxHI4M5JJf/cdZDFerJ 1bDMnebwuCPZ86HY5vFXTJ7EJ+w5FFdCEkB9g= 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=HZ6BkzwJWuysG9Ncleyt9tGqJKvRpmo0CkvfsB7TcKk=; b=TwXP6q8nJpoSYqKBKG0OuPHeuLBjcvTiPogvpZ7/kMMN2bEDPDZgAPvdWlBMnETggR NahMb2vSL6je0I5JpYVUZ+BqY+dLFTikk9TrNIBO2Md01f0UoILor7NpNZMEF3W2StQ5 h8FmqLxKXgo7XezkmHh48QxiNsBvsr/XEKEKNXNCj6TDnliATsh50wuZx3xe44N7dADL W1gTunUTRPJFSXmOK1lIl/tLEJHnrDfOtao73ela+yVuqJA21rgblmO1tnRMI+kNxUM2 IWkl/8Jv3CttITg7Z3J3CPBe+hq2vhKt9BeGzBuxwXflpC7UyUBMQtr4Oc8f6/qyKJCz H0lA== X-Gm-Message-State: AOAM5300mva1G4ImDXJnQWhjGwxQBBNXMp9O9B9FoRD33qsTVkl64MKT Yx3fNeQjH16Sc5GOXTxKu+SrIg== X-Received: by 2002:a62:7650:0:b029:1bb:aa42:aa96 with SMTP id r77-20020a6276500000b02901bbaa42aa96mr2211330pfc.33.1612344248257; Wed, 03 Feb 2021 01:24:08 -0800 (PST) Received: from hsinyi-z840.tpe.corp.google.com ([2401:fa00:1:10:743e:7944:50c8:ff72]) by smtp.gmail.com with ESMTPSA id u20sm932294pjy.36.2021.02.03.01.24.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 03 Feb 2021 01:24:07 -0800 (PST) From: Hsin-Yi Wang To: Viresh Kumar , linux-pm@vger.kernel.org Cc: Nishanth Menon , Stephen Boyd , "Rafael J . Wysocki" , linux-kernel@vger.kernel.org, "MyungJoo Ham )" , Kyungmin Park , Chanwoo Choi , Saravana Kannan Subject: [PATCH v5 1/3] OPP: Add function to look up required OPP's for a given OPP Date: Wed, 3 Feb 2021 17:23:58 +0800 Message-Id: <20210203092400.1791884-2-hsinyi@chromium.org> X-Mailer: git-send-email 2.30.0.365.g02bc693789-goog In-Reply-To: <20210203092400.1791884-1-hsinyi@chromium.org> References: <20210203092400.1791884-1-hsinyi@chromium.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Saravana Kannan 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 Signed-off-by: Hsin-Yi Wang --- drivers/opp/core.c | 58 ++++++++++++++++++++++++++++++++++++++++++ include/linux/pm_opp.h | 11 ++++++++ 2 files changed, 69 insertions(+) diff --git a/drivers/opp/core.c b/drivers/opp/core.c index dc95d29e94c1b..878f066b972cc 100644 --- a/drivers/opp/core.c +++ b/drivers/opp/core.c @@ -2398,6 +2398,64 @@ devm_pm_opp_attach_genpd(struct device *dev, const char **names, } EXPORT_SYMBOL_GPL(devm_pm_opp_attach_genpd); +/** + * dev_pm_opp_xlate_required_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. + * + * 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_required_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 || + !src_table->required_opp_tables) + return NULL; + + /* required-opps not fully initialized yet */ + if (lazy_linking_pending(src_table)) + return NULL; + + for (i = 0; i < src_table->required_opp_count; i++) { + if (src_table->required_opp_tables[i] == dst_table) + 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 ab1d15ce559db..6f5f72a7f601c 100644 --- a/include/linux/pm_opp.h +++ b/include/linux/pm_opp.h @@ -156,6 +156,9 @@ struct opp_table *devm_pm_opp_register_set_opp_helper(struct device *dev, int (* struct opp_table *dev_pm_opp_attach_genpd(struct device *dev, const char **names, struct device ***virt_devs); void dev_pm_opp_detach_genpd(struct opp_table *opp_table); struct opp_table *devm_pm_opp_attach_genpd(struct device *dev, const char **names, struct device ***virt_devs); +struct dev_pm_opp *dev_pm_opp_xlate_required_opp(struct opp_table *src_table, + struct opp_table *dst_table, + struct dev_pm_opp *src_opp); 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_opp(struct device *dev, struct dev_pm_opp *opp); @@ -367,6 +370,14 @@ static inline struct opp_table *devm_pm_opp_attach_genpd(struct device *dev, return ERR_PTR(-EOPNOTSUPP); } +static inline struct dev_pm_opp *dev_pm_opp_xlate_required_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_xlate_performance_state(struct opp_table *src_table, struct opp_table *dst_table, unsigned int pstate) { return -EOPNOTSUPP; -- 2.30.0.365.g02bc693789-goog