From patchwork Wed Apr 27 03:22:23 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 66761 Delivered-To: patch@linaro.org Received: by 10.140.93.198 with SMTP id d64csp1955665qge; Tue, 26 Apr 2016 20:23:38 -0700 (PDT) X-Received: by 10.66.246.165 with SMTP id xx5mr8546923pac.87.1461727418530; Tue, 26 Apr 2016 20:23:38 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id g7si2611275pat.103.2016.04.26.20.23.38; Tue, 26 Apr 2016 20:23:38 -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=@linaro.org; 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=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752872AbcD0DXY (ORCPT + 29 others); Tue, 26 Apr 2016 23:23:24 -0400 Received: from mail-pa0-f45.google.com ([209.85.220.45]:33061 "EHLO mail-pa0-f45.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751920AbcD0DXV (ORCPT ); Tue, 26 Apr 2016 23:23:21 -0400 Received: by mail-pa0-f45.google.com with SMTP id zm5so15610889pac.0 for ; Tue, 26 Apr 2016 20:23:20 -0700 (PDT) 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 :in-reply-to:references; bh=EyXdBQ3KSLXpp/kaJJoCeKNFixRD06R7QnkC+65SXQs=; b=VysnQ2CcdHfhKByTkqeZwyxbbzR9jknockNXf5rTNjbcqxY1X83eHdlZ/FwtzU8qr0 cNsJSWaihacz1IJvUX05Dva0LFqfoe0WUFWjvN4BugikVTLeu0YWwTyVJTJys1+kmlTc TX232k+fMmLE2HB0GwuiZAueJZgawVo2vltN0= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:in-reply-to:references; bh=EyXdBQ3KSLXpp/kaJJoCeKNFixRD06R7QnkC+65SXQs=; b=is5AvDO9/tKuAGnWRes6qHOqEwmbqXHVk0tS8FiBQ6uwrg+fUuGPdcPqXW2wik9W/e Ajof0ny0xHNIyrAG6RHSQkS1Yr7PyQVlB/73Co1P4yiTpmh3RG+BHQocoMkU8aaVhOJw q1AldNtgH5TGVlG+CEeUfzCyZ1EKLj8WfAvU0bi0l8tCqc9/7vmP/MCXQzlnA7CHSTOF ZiP/HYxWghNQvhnRaz0oZdL5s9Ihvs/rUUcbsW11Hjive+IbLfF0DCFjF1MF12ZFksJe VtRb/Zcr20DfZie6Cmp1PtQw46JW2sPPMaJIRXcxoIuwAnPGATOsBkZxpjL3eHNBZXeb VjHw== X-Gm-Message-State: AOPr4FVzwhO6U0Lx9m/h2L67XOJ5o4iX3aMbqs0ylX6JkIc9Mbc2wbV/kUwRRh6VuqR+Jnvp X-Received: by 10.66.122.100 with SMTP id lr4mr8237601pab.99.1461727400236; Tue, 26 Apr 2016 20:23:20 -0700 (PDT) Received: from localhost ([122.167.143.140]) by smtp.gmail.com with ESMTPSA id h85sm1782704pfj.52.2016.04.26.20.23.18 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 26 Apr 2016 20:23:19 -0700 (PDT) From: Viresh Kumar To: Rafael Wysocki , Viresh Kumar , Nishanth Menon , Stephen Boyd Cc: linaro-kernel@lists.linaro.org, linux-pm@vger.kernel.org, arnd.bergmann@linaro.org, Viresh Kumar , linux-kernel@vger.kernel.org Subject: [PATCH V2 3/7] PM / OPP: Add dev_pm_opp_get_sharing_cpus() Date: Wed, 27 Apr 2016 08:52:23 +0530 Message-Id: X-Mailer: git-send-email 2.7.1.410.g6faf27b In-Reply-To: References: In-Reply-To: References: Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org OPP core allows a platform to mark OPP table as shared, when the platform isn't using operating-points-v2 bindings. And, so there should be a non DT way of finding out if the OPP table is shared or not. This patch adds dev_pm_opp_get_sharing_cpus(), which first tries to get OPP sharing information from the opp-table (in case it is already marked as shared), otherwise it uses the existing DT way of finding sharing information. Signed-off-by: Viresh Kumar --- drivers/base/power/opp/cpu.c | 45 ++++++++++++++++++++++++++++++++++++++++++++ include/linux/pm_opp.h | 6 ++++++ 2 files changed, 51 insertions(+) -- 2.7.1.410.g6faf27b diff --git a/drivers/base/power/opp/cpu.c b/drivers/base/power/opp/cpu.c index 5469e7730ff2..3428380dfca7 100644 --- a/drivers/base/power/opp/cpu.c +++ b/drivers/base/power/opp/cpu.c @@ -330,3 +330,48 @@ int dev_pm_opp_set_sharing_cpus(struct device *cpu_dev, return ret; } EXPORT_SYMBOL_GPL(dev_pm_opp_set_sharing_cpus); + +/** + * dev_pm_opp_get_sharing_cpus() - Get cpumask of CPUs sharing OPPs with @cpu_dev + * @cpu_dev: CPU device for which we do this operation + * @cpumask: cpumask to update with information of sharing CPUs + * + * This updates the @cpumask with CPUs that are sharing OPPs with @cpu_dev. + * + * Returns -ENODEV if OPP table isn't already present. + * + * Locking: The internal opp_table and opp structures are RCU protected. + * Hence this function internally uses RCU updater strategy with mutex locks + * to keep the integrity of the internal data structures. Callers should ensure + * that this function is *NOT* called under RCU protection or in contexts where + * mutex cannot be locked. + */ +int dev_pm_opp_get_sharing_cpus(struct device *cpu_dev, cpumask_var_t cpumask) +{ + struct opp_device *opp_dev; + struct opp_table *opp_table; + int ret = 0; + + mutex_lock(&opp_table_lock); + + opp_table = _find_opp_table(cpu_dev); + if (IS_ERR(opp_table)) { + ret = PTR_ERR(opp_table); + goto unlock; + } + + cpumask_clear(cpumask); + + if (opp_table->shared_opp) { + list_for_each_entry(opp_dev, &opp_table->dev_list, node) + cpumask_set_cpu(opp_dev->dev->id, cpumask); + } else { + cpumask_set_cpu(cpu_dev->id, cpumask); + } + +unlock: + mutex_unlock(&opp_table_lock); + + return ret; +} +EXPORT_SYMBOL_GPL(dev_pm_opp_get_sharing_cpus); diff --git a/include/linux/pm_opp.h b/include/linux/pm_opp.h index 0c08ed3836b1..15f554443b59 100644 --- a/include/linux/pm_opp.h +++ b/include/linux/pm_opp.h @@ -66,6 +66,7 @@ int dev_pm_opp_set_regulator(struct device *dev, const char *name); void dev_pm_opp_put_regulator(struct device *dev); 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 cpumask_var_t cpumask); +int dev_pm_opp_get_sharing_cpus(struct device *cpu_dev, cpumask_var_t cpumask); #else static inline unsigned long dev_pm_opp_get_voltage(struct dev_pm_opp *opp) { @@ -184,6 +185,11 @@ static inline int dev_pm_opp_set_sharing_cpus(struct device *cpu_dev, const cpum return -ENOTSUPP; } +static inline int dev_pm_opp_get_sharing_cpus(struct device *cpu_dev, cpumask_var_t cpumask) +{ + return -EINVAL; +} + #endif /* CONFIG_PM_OPP */ #if defined(CONFIG_PM_OPP) && defined(CONFIG_OF)