From patchwork Tue Nov 17 22:37:41 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lina Iyer X-Patchwork-Id: 56895 Delivered-To: patch@linaro.org Received: by 10.112.155.196 with SMTP id vy4csp2218441lbb; Tue, 17 Nov 2015 14:39:27 -0800 (PST) X-Received: by 10.66.148.67 with SMTP id tq3mr67289470pab.124.1447799939084; Tue, 17 Nov 2015 14:38:59 -0800 (PST) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id ax2si60766904pbd.123.2015.11.17.14.38.58; Tue, 17 Nov 2015 14:38:59 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-arm-msm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-arm-msm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-arm-msm-owner@vger.kernel.org; dkim=neutral (body hash did not verify) header.i=@linaro_org.20150623.gappssmtp.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932603AbbKQWi5 (ORCPT + 6 others); Tue, 17 Nov 2015 17:38:57 -0500 Received: from mail-pa0-f52.google.com ([209.85.220.52]:34246 "EHLO mail-pa0-f52.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932585AbbKQWix (ORCPT ); Tue, 17 Nov 2015 17:38:53 -0500 Received: by padhx2 with SMTP id hx2so22140710pad.1 for ; Tue, 17 Nov 2015 14:38:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro_org.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=MJmezBJFwVHmYglKKYgUutcpt+2+uwPSFWYll3NX0IE=; b=KoNYhxch/kv4f/BwGKoAzn95m8cWNml93D1S8yika1Wk2TsWk1aAgsiTj7AGJ+8bqp JUnRUkv6f1xOYLYkBXkBHlyLG2aBlBAzSK3i0cpdA2wZlP4H78s432dz5GX/uPgOSr+I 6hAjdtdo7kQZQ2Nfy4HDFQLYpIIwnWglUbNL10B/ZJ1U7tZ3YBd/yRE8pMSLkTtmTYjb ZuCgX1LI7j5it1krq8ahVN13fftfFhI7HuQb7Hg50yVFThTLWaqMmtQFwZr/iKn3P8q+ 7m5zxb8GL2Jukod7Na6xmXs30bXjdv79+TwFbgVTVVh1J5o3SaFcD9b9AiGZTppK/FBX 4xdQ== 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; bh=MJmezBJFwVHmYglKKYgUutcpt+2+uwPSFWYll3NX0IE=; b=gduGjqEstf9Nc7qVG84PpAq8trNqO0v9iRXUen2uAJtEQ5v3SqSB4aF9OlNCegD2nJ Jc/b0rC7rmfJmQYtK7kVnvWaRzsGWzOd/T6+TlcMpbqzZvmGmIYVRWA66LO1EztFk5uX u/VXzL3KeN5zccqp4uGFKpg3fURt2NHmOEQFS9kGIWIQA7npe+TxUbQq1gem81EOAY15 gxZ5uM6/udXWkBr1MmcGxZtxnzn/E1E4Vg+THwBstbeGaow0up6H9QMuUzQPxv5Xp1Uu UM5/glBL07DCdLk6LTy0gZpq+3k4gaV/I+qVqJv8IQy5gFvSGufDOfhGf6IlJ5MUfpV/ oUfQ== X-Gm-Message-State: ALoCoQmomxcmJ5AsBRwokCoyCHcPCRWhCsmjMnRBTIBUXXdPVBn9nbIgUcKSiD95cz85JBQ5Ac9P X-Received: by 10.66.251.193 with SMTP id zm1mr68125485pac.154.1447799932760; Tue, 17 Nov 2015 14:38:52 -0800 (PST) Received: from ubuntu.localdomain ([8.42.77.226]) by smtp.gmail.com with ESMTPSA id hy1sm14875199pbb.63.2015.11.17.14.38.50 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 17 Nov 2015 14:38:52 -0800 (PST) From: Lina Iyer To: ulf.hansson@linaro.org, khilman@linaro.org, linux-pm@vger.kernel.org, linux-arm-kernel@lists.infradead.org Cc: geert@linux-m68k.org, k.kozlowski@samsung.com, msivasub@codeaurora.org, agross@codeaurora.org, sboyd@codeaurora.org, linux-arm-msm@vger.kernel.org, lorenzo.pieralisi@arm.com, ahaslam@baylibre.com, mtitinger@baylibre.com, Lina Iyer Subject: [PATCH RFC 17/27] drivers: cpu-pd: Record CPUs that are part of the domain Date: Tue, 17 Nov 2015 15:37:41 -0700 Message-Id: <1447799871-56374-18-git-send-email-lina.iyer@linaro.org> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1447799871-56374-1-git-send-email-lina.iyer@linaro.org> References: <1447799871-56374-1-git-send-email-lina.iyer@linaro.org> Sender: linux-arm-msm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@vger.kernel.org In order to power down the heirarchy of the CPU domain, the domain needs information about the CPUs in that domain hierarchy . A domain that has sub-domains containing CPU devices, will need information about all the CPUs in the sub-domains as well. Introduce of_attach_cpu_pm_domain() to allow CPU domains to be attached to its parent domain and the information on CPUs attached directly or indirectly be bubbled up the hierarchy. Signed-off-by: Lina Iyer --- drivers/base/power/cpu-pd.c | 96 ++++++++++++++++++++++++++++++++++++++++++++- include/linux/cpu-pd.h | 3 ++ 2 files changed, 97 insertions(+), 2 deletions(-) -- 2.1.4 -- To unsubscribe from this list: send the line "unsubscribe linux-arm-msm" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/drivers/base/power/cpu-pd.c b/drivers/base/power/cpu-pd.c index 9758b8d..617ce54 100644 --- a/drivers/base/power/cpu-pd.c +++ b/drivers/base/power/cpu-pd.c @@ -18,6 +18,7 @@ #include #include #include +#include #include #include @@ -44,6 +45,27 @@ struct cpu_pm_domain *to_cpu_pd(struct generic_pm_domain *d) return res; } +/** + * get_cpus_in_domain() - Recursively parse CPUs in a domain. + */ +static void get_cpus_in_domain(struct generic_pm_domain *genpd, + struct cpumask *mask) +{ + struct gpd_link *link; + struct cpu_pm_domain *pd = to_cpu_pd(genpd); + struct generic_pm_domain *sd; + + if (!cpumask_empty(pd->cpus) && mask != pd->cpus) { + cpumask_or(mask, pd->cpus, mask); + return; + } + + list_for_each_entry(link, &genpd->master_links, master_node) { + sd = link->slave; + get_cpus_in_domain(sd, mask); + } +} + static int cpu_pd_power_off(struct generic_pm_domain *genpd) { struct cpu_pm_domain *pd = to_cpu_pd(genpd); @@ -81,7 +103,8 @@ static void run_cpu(void *unused) pm_runtime_get_noresume(cpu_dev); } -static int of_pm_domain_attach_cpus(struct device_node *dn) +static int of_pm_domain_attach_cpus(struct device_node *dn, + struct cpu_pm_domain *pd) { int cpuid, ret; @@ -126,6 +149,7 @@ static int of_pm_domain_attach_cpus(struct device_node *dn) } else { pm_runtime_enable(cpu_dev); dev_dbg(cpu_dev, "Attached CPU%d to domain\n", cpuid); + cpumask_set_cpu(cpuid, pd->cpus); } } @@ -171,7 +195,7 @@ int of_register_cpu_pm_domain(struct device_node *dn, pd->genpd->name); /* Attach the CPUs to the CPU PM domain */ - ret = of_pm_domain_attach_cpus(dn); + ret = of_pm_domain_attach_cpus(dn, pd); if (ret) of_genpd_del_provider(dn); @@ -213,6 +237,13 @@ struct generic_pm_domain *of_init_cpu_pm_domain(struct device_node *dn, return ERR_PTR(-ENOMEM); } + if (!zalloc_cpumask_var(&pd->cpus, GFP_KERNEL)) { + kfree(pd->genpd->name); + kfree(pd->genpd); + kfree(pd); + return ERR_PTR(-ENOMEM); + } + if (ops) { pd->plat_ops.power_off = ops->power_off; pd->plat_ops.power_on = ops->power_on; @@ -222,6 +253,7 @@ struct generic_pm_domain *of_init_cpu_pm_domain(struct device_node *dn, if (ret) { kfree(pd->genpd->name); kfree(pd->genpd); + kfree(pd->cpus); kfree(pd); return ERR_PTR(ret); } @@ -229,3 +261,63 @@ struct generic_pm_domain *of_init_cpu_pm_domain(struct device_node *dn, return pd->genpd; } EXPORT_SYMBOL(of_init_cpu_pm_domain); + +/** + * of_attach_cpu_pm_domain() - Attach a CPU PM domain to its parent + * @dn: The device node of the CPU PM domain that needs to be attached + * + * The platform code can use this simplfied function to parse the domain + * provider of this device node and attach the genpd associated with @dn + * to it parents. + * + * Note: Both @dn and its domain provider must be initialized using + * of_init_cpu_pm_domain. + */ +int of_attach_cpu_pm_domain(struct device_node *dn) +{ + struct of_phandle_args args; + struct generic_pm_domain *genpd, *parent; + struct cpu_pm_domain *pd; + int ret; + + args.np = dn; + args.args_count = 0; + + genpd = of_genpd_get_from_provider(&args); + if (IS_ERR(genpd)) + return -EINVAL; + + if (!to_cpu_pd(genpd)) { + pr_warn("%s: domain %s is not a CPU domain\n", + __func__, genpd->name); + return -EINVAL; + } + + ret = of_parse_phandle_with_args(dn, "power-domains", + "#power-domain-cells", 0, &args); + if (ret < 0) + return ret; + + parent = of_genpd_get_from_provider(&args); + if (IS_ERR(parent)) + return -EINVAL; + + pd = to_cpu_pd(parent); + if (!pd) { + pr_warn("%s: domain (%s) parent (%s) is non-CPU domain\n", + __func__, genpd->name, parent->name); + return -EINVAL; + } + + ret = pm_genpd_add_subdomain(genpd, parent); + if (ret) { + pr_err("%s: Unable to add sub-domain (%s) to parent (%s)\n", + __func__, genpd->name, parent->name); + return ret; + } + + get_cpus_in_domain(parent, pd->cpus); + + return 0; +} +EXPORT_SYMBOL(of_attach_cpu_pm_domain); diff --git a/include/linux/cpu-pd.h b/include/linux/cpu-pd.h index a2a217d..489ee2f 100644 --- a/include/linux/cpu-pd.h +++ b/include/linux/cpu-pd.h @@ -11,6 +11,7 @@ #ifndef __CPU_PD_H__ #define __CPU_PD_H__ +#include #include #include #include @@ -25,8 +26,10 @@ struct cpu_pm_domain { struct generic_pm_domain *genpd; struct device_node *dn; struct cpu_pd_ops plat_ops; + cpumask_var_t cpus; }; struct generic_pm_domain *of_init_cpu_pm_domain(struct device_node *dn, const struct cpu_pd_ops *ops); +int of_attach_cpu_pm_domain(struct device_node *dn); #endif /* __CPU_PD_H__ */