From patchwork Tue Nov 17 22:37:47 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lina Iyer X-Patchwork-Id: 56899 Delivered-To: patch@linaro.org Received: by 10.112.155.196 with SMTP id vy4csp2218560lbb; Tue, 17 Nov 2015 14:39:48 -0800 (PST) X-Received: by 10.68.233.233 with SMTP id tz9mr66104990pbc.15.1447799960585; Tue, 17 Nov 2015 14:39:20 -0800 (PST) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id hx5si60778575pbc.82.2015.11.17.14.39.20; Tue, 17 Nov 2015 14:39:20 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-pm-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-pm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-pm-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 S932662AbbKQWjP (ORCPT + 11 others); Tue, 17 Nov 2015 17:39:15 -0500 Received: from mail-pa0-f53.google.com ([209.85.220.53]:34415 "EHLO mail-pa0-f53.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932641AbbKQWjF (ORCPT ); Tue, 17 Nov 2015 17:39:05 -0500 Received: by padhx2 with SMTP id hx2so22145339pad.1 for ; Tue, 17 Nov 2015 14:39:04 -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=t+1R4c6/R4GuQ/DS7Ngwcv/wuVEZrFTPp0asBTJboJQ=; b=KjsNJXcZaf/XfHJu533VgmWE9803XXozdFwkXVa5U5MXbGVDseWQDmUdabM4x4mbbo SXPKZRB81pH9uIFfjbi/fYJaxmV0+1pXUMTzaERa1Q2z0llcsah8k/wG0xbgBI4SW4iF wLPG8U3CPMFNdHr79gxXA386J9UQ4xQnnhIW5A8LNW33bs0hEzPVDKugWAdgFFLw4JBK Swn0nfll7L/cSZL7Tw0nkeL8PzKpsYWoQ8fyyyNNklWXwdMKyRgegT4sW5XRCix9eI/r zeBdvOBJ9vLj1p73ftRyOMoQA3QdWr7hyMDZVtGXDH0UoqlPxrCFeKC/mHuGFEggNyBf cnrg== 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=t+1R4c6/R4GuQ/DS7Ngwcv/wuVEZrFTPp0asBTJboJQ=; b=BS1gKSVyl++Qfr1LVHnDz114Yo5kRgHdwytQEeBIviXaqXhTXKi+673339gYoeZ+8T 79haAzJ9EAlZ47EU0iCDhwDx4q1Lu51yEBYkiTbK0CSYNKRovYS2rp9k0CsKs/ceyZ7N syFnZM0h6G5Zf7f0NNj3pQQHhPJ9MJ+HGe0NU/YUn7QmYF+hFo6Dusa28c0FfMpyRoZc HBCIfTacevE0/fw96t5XRY3LvEENI2RdLslvz3ZIy5nUAk2vaszYhQNYMq+mmnEBdRFU 9lh5pUwzmqyFXnMtNVgXA9HhrvmdoA/mBMK3ekyB3FEYZcGeHxXqehYBMOTuu8qw+Ipw MXJA== X-Gm-Message-State: ALoCoQnXnHSPNZ73i9F1FQjsfQwjQzHNuOB72neId2YW0kOYGX2D7MJcsUYZsO54xOdaJwpIAK/P X-Received: by 10.66.140.79 with SMTP id re15mr66128837pab.127.1447799944524; Tue, 17 Nov 2015 14:39:04 -0800 (PST) Received: from ubuntu.localdomain ([8.42.77.226]) by smtp.gmail.com with ESMTPSA id hy1sm14875199pbb.63.2015.11.17.14.39.02 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 17 Nov 2015 14:39:03 -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 , Daniel Lezcano , Mark Rutland Subject: [PATCH RFC 23/27] ARM64: psci: Support cluster idle states for OS-Initated Date: Tue, 17 Nov 2015 15:37:47 -0700 Message-Id: <1447799871-56374-24-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-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org ARMv8 PSCI firmware may allow Linux to determine the state of the CPU cluster and the cluster at coherency level to enter idle states when there are no active CPUs. Since Linux has a better idea of the QoS and the wakeup pattern of the CPUs, the cluster idle states may be better determined by the OS instead of the firmware. The last CPU entering idle in a cluster, holds the responsibility of selecting the state of the cluster. Only one CPU in a cluster may provide the cluster idle state to the firmware. Similarly, the last CPU in the cluster of clusters may provide the state of the coherency domain. The CPU PM domain framework facilitates registration of CPU PM domains and reference counting for the last man down and the first man up. But the organzation of CPUs into clusters must be provided. The cpu-map topology node provides the information. Call into the CPU PM framework to parse the CPU topology node and setup the PM domains. The state id for the cluster ids is available with the domain idle state. The last CPU PSCI state id of the entire system would therefore be - Coherency State ID + Cluster State ID + CPU idle state ID, that is passed into the PSCI firmware when the CPU makes the PSCI enable-method. Cc: Daniel Lezcano Cc: Lorenzo Pieralisi Cc: Mark Rutland Signed-off-by: Lina Iyer --- arch/arm64/kernel/psci.c | 54 +++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 51 insertions(+), 3 deletions(-) -- 2.1.4 -- To unsubscribe from this list: send the line "unsubscribe linux-pm" 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/arch/arm64/kernel/psci.c b/arch/arm64/kernel/psci.c index f67f35b..6618d33 100644 --- a/arch/arm64/kernel/psci.c +++ b/arch/arm64/kernel/psci.c @@ -15,10 +15,12 @@ #define pr_fmt(fmt) "psci: " fmt +#include #include #include #include #include +#include #include #include @@ -31,6 +33,44 @@ #include static DEFINE_PER_CPU_READ_MOSTLY(u32 *, psci_power_state); +static DEFINE_PER_CPU(u32, cluster_state_id); + +static inline u32 psci_get_composite_state_id(u32 cpu_state) +{ + u32 val = cpu_state; + + if (psci_has_ext_power_state()) + val += this_cpu_read(cluster_state_id); + + return val; +} + +static inline void psci_reset_composite_state_id(void) +{ + this_cpu_write(cluster_state_id, 0); +} + +static int psci_pd_power_on(struct generic_pm_domain *genpd) +{ + return 0; +} + +static int psci_pd_power_off(struct generic_pm_domain *genpd) +{ + __this_cpu_add(cluster_state_id, genpd->states[genpd->state_idx].param); + return 0; +} + +static const struct cpu_pd_ops psci_pd_ops = { + .power_on = psci_pd_power_on, + .power_off = psci_pd_power_off, +}; + +static int __init psci_setup_cpu_domains(void) +{ + return of_setup_cpu_domain_topology(&psci_pd_ops); +} +subsys_initcall(psci_setup_cpu_domains); static int __maybe_unused cpu_psci_cpu_init_idle(unsigned int cpu) { @@ -117,6 +157,8 @@ static int cpu_psci_cpu_boot(unsigned int cpu) if (err) pr_err("failed to boot CPU%d (%d)\n", cpu, err); + /* Reset CPU cluster states */ + psci_reset_composite_state_id(); return err; } @@ -181,15 +223,16 @@ static int cpu_psci_cpu_kill(unsigned int cpu) static int psci_suspend_finisher(unsigned long index) { u32 *state = __this_cpu_read(psci_power_state); + u32 ext_state = psci_get_composite_state_id(state[index - 1]); - return psci_ops.cpu_suspend(state[index - 1], - virt_to_phys(cpu_resume)); + return psci_ops.cpu_suspend(ext_state, virt_to_phys(cpu_resume)); } static int __maybe_unused cpu_psci_cpu_suspend(unsigned long index) { int ret; u32 *state = __this_cpu_read(psci_power_state); + u32 ext_state = psci_get_composite_state_id(state[index - 1]); /* * idle state index 0 corresponds to wfi, should never be called * from the cpu_suspend operations @@ -198,10 +241,15 @@ static int __maybe_unused cpu_psci_cpu_suspend(unsigned long index) return -EINVAL; if (!psci_power_state_loses_context(state[index - 1])) - ret = psci_ops.cpu_suspend(state[index - 1], 0); + ret = psci_ops.cpu_suspend(ext_state, 0); else ret = cpu_suspend(index, psci_suspend_finisher); + /* + * Clear the CPU's cluster states, we start afresh after coming + * out of idle. + */ + psci_reset_composite_state_id(); return ret; }