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: 7643241 Return-Path: X-Original-To: patchwork-linux-arm@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 50C709F2EC for ; Tue, 17 Nov 2015 22:44:58 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 507E020437 for ; Tue, 17 Nov 2015 22:44:57 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 4EB39203DC for ; Tue, 17 Nov 2015 22:44:56 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1Zyoxm-0001mP-LE; Tue, 17 Nov 2015 22:42:58 +0000 Received: from mail-pa0-x234.google.com ([2607:f8b0:400e:c03::234]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1ZyouL-0005gd-KL for linux-arm-kernel@lists.infradead.org; Tue, 17 Nov 2015 22:39:31 +0000 Received: by pacdm15 with SMTP id dm15so22088011pac.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=duOPlomboC+R1Y/Gwu641PnGyDHdKwVqnCwBiVcmDvNM1Ctq38sugQOcEmA6b2yvbW xzJpVs0lM2X5JjtPjcsmLvwVBKxETdTodTwFmYfsZDTwOx5Wklk8j+R6+D7d1Ok5OCK2 iiEhrXYp4PiwDlgZqiQfw6PM8KXMvSf9N6cZ93zXInt/cchTbhCpiyqq9ni5cZAYXMzP xKMVFy07m1Y0lyqFZlyqZflMzstmDyo4mlihZ3EFFKAGpdHohX98gmZURebqQ391nvvh IyuFxnauFHrpuVxCvfWuXwbUh+qfjKU0FYY0+qON7LA72t7WDkLIjrFoDCsIrUaxmT/5 Vw2Q== X-Gm-Message-State: ALoCoQnTydQbpujc4eTn7cn+Kj+BVQ2g28Jz1oZ5DbTmyj58wBuTbpp4KAI4dWmmSHYriFIHkz8d 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 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> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20151117_143926_095148_8EC7F6C5 X-CRM114-Status: GOOD ( 18.16 ) X-Spam-Score: -2.6 (--) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Mark Rutland , k.kozlowski@samsung.com, lorenzo.pieralisi@arm.com, ahaslam@baylibre.com, linux-arm-msm@vger.kernel.org, Daniel Lezcano , sboyd@codeaurora.org, msivasub@codeaurora.org, geert@linux-m68k.org, Lina Iyer , agross@codeaurora.org, mtitinger@baylibre.com MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-4.7 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED,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; }