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: 7643081 X-Patchwork-Delegate: agross@codeaurora.org Return-Path: X-Original-To: patchwork-linux-arm-msm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id A77C89F392 for ; Tue, 17 Nov 2015 22:39:36 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id DB8A62051A for ; Tue, 17 Nov 2015 22:39:31 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 99E432053B for ; Tue, 17 Nov 2015 22:39:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932665AbbKQWjQ (ORCPT ); Tue, 17 Nov 2015 17:39:16 -0500 Received: from mail-pa0-f48.google.com ([209.85.220.48]:35926 "EHLO mail-pa0-f48.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932640AbbKQWjF (ORCPT ); Tue, 17 Nov 2015 17:39:05 -0500 Received: by pacdm15 with SMTP id dm15so22088012pac.3 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=HFtUbhvdjjz5H1j3skIpDdcOMAkvCSW8iGrrNE+Snoxe1/zZcQ+ZybQJtO3cuqqwKd vohD8HLV9ALWUVB9yH8v5oTPDdiOHSZ9imW4WVCx3uXbX0IbaB+cnCZluLWluyNGIFzJ lQ8b3uzm/mnHrl/xUjwiRl1ZA9ezhU3fbXhR8LtyPro1uUMUJsXmGq+275eAI9mR/Yrv uIyh37za45/1IAFZEJeMlwKJK6Me8YF6TNMlhjNZYOzH0dWowNv8VaSHfiSxUXvS9nKl EhnHSjPvAtza2TqfSP6uUQDvIqYqJ2XOuJi/bovZsq0r7g+oono44FB4Z9D5R5kHbmWr BcWQ== X-Gm-Message-State: ALoCoQkx6adK/89l/WWiQlNz9N2gm+lcRmCExmlGhIonEx2ZWEDN8LfQFmX9gGI8oX/uAlUglKJ5 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-arm-msm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@vger.kernel.org X-Spam-Status: No, score=-7.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,RP_MATCHES_RCVD,T_DKIM_INVALID,UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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(-) 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; }