From patchwork Fri Mar 3 20:41:30 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lina Iyer X-Patchwork-Id: 9603507 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id BF65D60414 for ; Fri, 3 Mar 2017 20:44:36 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id ABDAF28555 for ; Fri, 3 Mar 2017 20:44:36 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9EA512855A; Fri, 3 Mar 2017 20:44:36 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-1.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id C051128555 for ; Fri, 3 Mar 2017 20:44:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=BimN8o3wYosLlHWxANu7kYds9n0wdgB/uyCn6yK1f1M=; b=Fn5or3FOhqRtjG2XWkq1U5a+LY o/oUHoTfVwCAISincDf+eVchqONTgtrqRoNvgbpDEi5MmdBW7YFqHS++1Sz1+2QmxhbMPnwuaI1Ip 9neILASSJvt9U0UtVU95H4f55seE1dYUIBZUca2Yo+o/+RryLr9rm8+FDkXxpYdYRKqZGjIT4k2Ad GJsGUdISV4FQdNB+gU7/ZAFprf5ZuZvvzrZ/GqPQfqv7Xc749b095iJ5m9rQQvvhHZWweOiPLOewf 7xfnWYLQe1jENPR/cRy1PefHPzNDpngcOKYKu9x7sNgdcVmPY1exVRYAxGfOrLuaE14P0xnsQfEtN ibKN45Nw==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1cju43-0006Ul-8A; Fri, 03 Mar 2017 20:44:35 +0000 Received: from mail-pg0-x22a.google.com ([2607:f8b0:400e:c05::22a]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1cju1k-0004ql-BN for linux-arm-kernel@lists.infradead.org; Fri, 03 Mar 2017 20:42:14 +0000 Received: by mail-pg0-x22a.google.com with SMTP id b129so47455292pgc.2 for ; Fri, 03 Mar 2017 12:41:50 -0800 (PST) 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; bh=2lAJHhHbBud0/8z3g7/p/jQ0kIxeqjIfVAKhfkMvpTo=; b=dO0gxOJjz3LG8uxTV3kcHQoFmL2YiI2+5OEKCRb1JsHkTXpBqGvinqlMxqN4zSJKZx ZqOB9mH/IkJFTdO4pP2hG3PefGgnwqvvQFvVJCi3qfs6iT8zJy6Ez30/rQHwAquj/kk6 3qPL7doH4HtyWNysC0ibyTCrjcX3Tx9claZZc= 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; bh=2lAJHhHbBud0/8z3g7/p/jQ0kIxeqjIfVAKhfkMvpTo=; b=Df3842d/xPRv0FXysctjdeJwMir9K2mytiPwdxcSgf+FdjG5az5h7eRdO8hboKS/qP xFhOn9AC70/gDIGEg534INmNV1TA5+yLrQ1qMaJZXKCO4APnTuHYH1V0UFOPYyCSUcUW 5n71yhM0jf52r6nGxgq/ShBiVbAma5GqGgdKgeCX4Va64ojTwqnQubwcCYsDDjAZ/Ywl sI/BLTDAhSy0habgTdDnHsLwa3gMgID4lJyRj0eLLB5/BK+tTPjOndRW9Qr6nWnncmtA pRBYuL+VWnFRP5g5U/2jfn4EuOfcMxd1i8gmDXKnLrwExsUVClS55zzuKfA+1bS5GvwX gIaQ== X-Gm-Message-State: AMke39l3bR4WUBJfAS7fvPKvRqW0L51Y3OSvcXdmEubOO5iNUC+tQ2We5xH/uFwJHKhKuxrC X-Received: by 10.84.238.199 with SMTP id l7mr6977602pln.90.1488573710048; Fri, 03 Mar 2017 12:41:50 -0800 (PST) Received: from ubuntu.localdomain (i-global254.qualcomm.com. [199.106.103.254]) by smtp.gmail.com with ESMTPSA id o189sm25207003pga.12.2017.03.03.12.41.47 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 03 Mar 2017 12:41:49 -0800 (PST) From: Lina Iyer To: ulf.hansson@linaro.org, khilman@kernel.org, rjw@rjwysocki.net, linux-pm@vger.kernel.org, linux-arm-kernel@lists.infradead.org Subject: [PATCH V5 4/9] PM / cpu_domains: Setup PM domains for CPUs/clusters Date: Fri, 3 Mar 2017 12:41:30 -0800 Message-Id: <1488573695-106680-5-git-send-email-lina.iyer@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1488573695-106680-1-git-send-email-lina.iyer@linaro.org> References: <1488573695-106680-1-git-send-email-lina.iyer@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170303_124212_445485_F4973AC7 X-CRM114-Status: GOOD ( 19.93 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: lorenzo.pieralisi@arm.com, Juri.Lelli@arm.com, linux-arm-msm@vger.kernel.org, sboyd@codeaurora.org, brendan.jackman@arm.com, sudeep.holla@arm.com, andy.gross@linaro.org, Lina Iyer MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP Define and add Generic PM domains (genpd) for CPU clusters. Many new SoCs group CPUs as clusters. Clusters share common resources like power rails, caches, VFP, Coresight etc. When all CPUs in the cluster are idle, these shared resources may also be put in their idle state. CPUs may be associated with their domain providers. The domains in turn may be associated with their providers. This is clean way to model the cluster hierarchy like that of ARM's big.little architecture. Platform drivers may initialize generic PM domains and setup the CPU PM domains for the genpd and attach CPUs to the domain. In the following patches, the CPUs are hooked up to runtime PM framework which helps power down the domain, when all the CPUs in the domain are idle. Cc: Ulf Hansson Suggested-by: Kevin Hilman Signed-off-by: Lina Iyer --- drivers/base/power/Makefile | 2 +- drivers/base/power/cpu_domains.c | 192 +++++++++++++++++++++++++++++++++++++++ include/linux/cpu_domains.h | 48 ++++++++++ 3 files changed, 241 insertions(+), 1 deletion(-) create mode 100644 drivers/base/power/cpu_domains.c create mode 100644 include/linux/cpu_domains.h diff --git a/drivers/base/power/Makefile b/drivers/base/power/Makefile index 5998c53..ee383f1 100644 --- a/drivers/base/power/Makefile +++ b/drivers/base/power/Makefile @@ -2,7 +2,7 @@ obj-$(CONFIG_PM) += sysfs.o generic_ops.o common.o qos.o runtime.o wakeirq.o obj-$(CONFIG_PM_SLEEP) += main.o wakeup.o obj-$(CONFIG_PM_TRACE_RTC) += trace.o obj-$(CONFIG_PM_OPP) += opp/ -obj-$(CONFIG_PM_GENERIC_DOMAINS) += domain.o domain_governor.o +obj-$(CONFIG_PM_GENERIC_DOMAINS) += domain.o domain_governor.o cpu_domains.o obj-$(CONFIG_HAVE_CLK) += clock_ops.o ccflags-$(CONFIG_DEBUG_DRIVER) := -DDEBUG diff --git a/drivers/base/power/cpu_domains.c b/drivers/base/power/cpu_domains.c new file mode 100644 index 0000000..04891dc --- /dev/null +++ b/drivers/base/power/cpu_domains.c @@ -0,0 +1,192 @@ +/* + * drivers/base/power/cpu_domains.c - Helper functions to create CPU PM domains. + * + * Copyright (C) 2016 Linaro Ltd. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define CPU_PD_NAME_MAX 36 + +struct cpu_pm_domain { + struct list_head link; + struct cpu_pd_ops ops; + struct generic_pm_domain *genpd; + struct cpu_pm_domain *parent; + cpumask_var_t cpus; +}; + +/* List of CPU PM domains we care about */ +static LIST_HEAD(of_cpu_pd_list); +static DEFINE_MUTEX(cpu_pd_list_lock); + +static inline struct cpu_pm_domain *to_cpu_pd(struct generic_pm_domain *d) +{ + struct cpu_pm_domain *pd; + struct cpu_pm_domain *res = NULL; + + rcu_read_lock(); + list_for_each_entry_rcu(pd, &of_cpu_pd_list, link) + if (pd->genpd == d) { + res = pd; + break; + } + rcu_read_unlock(); + + return res; +} + +static int cpu_pd_power_on(struct generic_pm_domain *genpd) +{ + struct cpu_pm_domain *pd = to_cpu_pd(genpd); + + return pd->ops.power_on ? pd->ops.power_on() : 0; +} + +static int cpu_pd_power_off(struct generic_pm_domain *genpd) +{ + struct cpu_pm_domain *pd = to_cpu_pd(genpd); + + return pd->ops.power_off ? pd->ops.power_off(genpd->state_idx, + genpd->states[genpd->state_idx].param, + pd->cpus) : 0; +} + +/** + * cpu_pd_attach_domain: Attach a child CPU PM to its parent + * + * @parent: The parent generic PM domain + * @child: The child generic PM domain + * + * Generally, the child PM domain is the one to which CPUs are attached. + */ +int cpu_pd_attach_domain(struct generic_pm_domain *parent, + struct generic_pm_domain *child) +{ + struct cpu_pm_domain *cpu_pd, *parent_cpu_pd; + int ret; + + ret = pm_genpd_add_subdomain(parent, child); + if (ret) { + pr_err("%s: Unable to add sub-domain (%s) to %s.\n err=%d", + __func__, child->name, parent->name, ret); + return ret; + } + + cpu_pd = to_cpu_pd(child); + parent_cpu_pd = to_cpu_pd(parent); + + if (cpu_pd && parent_cpu_pd) + cpu_pd->parent = parent_cpu_pd; + + return ret; +} +EXPORT_SYMBOL(cpu_pd_attach_domain); + +/** + * cpu_pd_attach_cpu: Attach a CPU to its CPU PM domain. + * + * @genpd: The parent generic PM domain + * @cpu: The CPU number + */ +int cpu_pd_attach_cpu(struct generic_pm_domain *genpd, int cpu) +{ + int ret; + struct device *cpu_dev; + struct cpu_pm_domain *cpu_pd = to_cpu_pd(genpd); + + cpu_dev = get_cpu_device(cpu); + if (!cpu_dev) { + pr_warn("%s: Unable to get device for CPU%d\n", + __func__, cpu); + return -ENODEV; + } + + ret = genpd_dev_pm_attach(cpu_dev); + if (ret) + dev_warn(cpu_dev, + "%s: Unable to attach to power-domain: %d\n", + __func__, ret); + else + dev_dbg(cpu_dev, "Attached to domain\n"); + + while (!ret && cpu_pd) { + cpumask_set_cpu(cpu, cpu_pd->cpus); + cpu_pd = cpu_pd->parent; + }; + + return ret; +} +EXPORT_SYMBOL(cpu_pd_attach_cpu); + +/** + * cpu_pd_init: Initialize a CPU PM domain for a genpd + * + * @genpd: The initialized generic PM domain object. + * @ops: The power_on/power_off ops for the domain controller. + * + * Initialize a CPU PM domain based on a generic PM domain. The platform driver + * is expected to setup the genpd object and the states associated with the + * generic PM domain, before calling this function. + */ +int cpu_pd_init(struct generic_pm_domain *genpd, const struct cpu_pd_ops *ops) +{ + int ret = -ENOMEM; + struct cpu_pm_domain *pd; + + if (IS_ERR_OR_NULL(genpd)) + return -EINVAL; + + pd = kzalloc(sizeof(*pd), GFP_KERNEL); + if (!pd) + goto fail; + + if (!zalloc_cpumask_var(&pd->cpus, GFP_KERNEL)) + goto fail; + + genpd->power_off = cpu_pd_power_off; + genpd->power_on = cpu_pd_power_on; + genpd->flags |= GENPD_FLAG_IRQ_SAFE; + pd->genpd = genpd; + if (ops) { + pd->ops.power_on = ops->power_on; + pd->ops.power_off = ops->power_off; + } + + INIT_LIST_HEAD_RCU(&pd->link); + mutex_lock(&cpu_pd_list_lock); + list_add_rcu(&pd->link, &of_cpu_pd_list); + mutex_unlock(&cpu_pd_list_lock); + + ret = pm_genpd_init(genpd, &simple_qos_governor, false); + if (ret) { + pr_err("Unable to initialize domain %s\n", genpd->name); + goto fail; + } + + pr_debug("adding %s as CPU PM domain\n", pd->genpd->name); + + return 0; +fail: + kfree(genpd->name); + kfree(genpd); + if (pd) + kfree(pd->cpus); + kfree(pd); + return ret; +} +EXPORT_SYMBOL(cpu_pd_init); diff --git a/include/linux/cpu_domains.h b/include/linux/cpu_domains.h new file mode 100644 index 0000000..7e71291 --- /dev/null +++ b/include/linux/cpu_domains.h @@ -0,0 +1,48 @@ +/* + * include/linux/cpu_domains.h + * + * Copyright (C) 2016 Linaro Ltd. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + */ + +#ifndef __CPU_DOMAINS_H__ +#define __CPU_DOMAINS_H__ + +#include + +struct generic_pm_domain; +struct cpumask; + +struct cpu_pd_ops { + int (*power_off)(u32 state_idx, u32 param, const struct cpumask *mask); + int (*power_on)(void); +}; + +#ifdef CONFIG_PM_GENERIC_DOMAINS + +int cpu_pd_init(struct generic_pm_domain *genpd, const struct cpu_pd_ops *ops); + +int cpu_pd_attach_domain(struct generic_pm_domain *parent, + struct generic_pm_domain *child); + +int cpu_pd_attach_cpu(struct generic_pm_domain *genpd, int cpu); + +#else + +static inline int cpu_pd_init(struct generic_pm_domain *genpd, + const struct cpu_pd_ops *ops) +{ return ERR_PTR(-ENODEV); } + +static inline int cpu_pd_attach_domain(struct generic_pm_domain *parent, + struct generic_pm_domain *child) +{ return -ENODEV; } + +static inline int cpu_pd_attach_cpu(struct generic_pm_domain *genpd, int cpu) +{ return -ENODEV; } + +#endif /* CONFIG_PM_GENERIC_DOMAINS */ + +#endif /* __CPU_DOMAINS_H__ */