From patchwork Tue Mar 1 21:15:29 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lina Iyer X-Patchwork-Id: 8470571 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 7429CC0553 for ; Tue, 1 Mar 2016 21:22:05 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 83B0220122 for ; Tue, 1 Mar 2016 21:22:04 +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 92CEC2010E for ; Tue, 1 Mar 2016 21:22:03 +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 1aari9-0004Dp-PB; Tue, 01 Mar 2016 21:20:05 +0000 Received: from mail-pf0-x230.google.com ([2607:f8b0:400e:c00::230]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1aareu-0000xE-3o for linux-arm-kernel@lists.infradead.org; Tue, 01 Mar 2016 21:16:49 +0000 Received: by mail-pf0-x230.google.com with SMTP id 4so41322957pfd.1 for ; Tue, 01 Mar 2016 13:16:26 -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=XJh4dJtCr604ViHhTkdFoz5BOdFK+BEzXHWSoSVpXH0=; b=RtZr6Qt9sMAQueAgWVp+RHVMtpto308UxdDye90+JicMy3vSGok5ud83JWmvIed2tK 6/Di+kaC0we/OSOh64JzLfgK1FPHPAG6qcZmjKgnN0i7PptkVsNJ3gA9rU0Y2oYSIIIo Jf7e9eurBJEmMTFFUNtKcpwW4jr0q5OsFECjE= 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=XJh4dJtCr604ViHhTkdFoz5BOdFK+BEzXHWSoSVpXH0=; b=OvBy1eyqDuhs7oSWjdQV3ttX/Q3cEUX8kXvsGjpntQBd/Dy6zXgzm/N4lTSijIkUmL PkF9PFU5YwYtl4NDGYrEydwilCjPt6cwscRSZ1elkWahW0JIrY+75JbIE34Avb+bSaHR u+cLyQ22yzcry62mKV/8BlzDndtp3lINtjhLcqhjaMp+mjt1l3bylWNmiAkZMO6YnecT DhGZeeYaXed0zgo4pFYbeJc8FhoSMO/zUmA+KRUb1y7igxWpGFqn4Zr9YPdLpn6whhdx +f9OnKrJw9sdQXKGjC6Img6y6O6YJsJRVOGINsmfhjrYesO0pfNdzEAUFoLFrSQlr6RD 4g6Q== X-Gm-Message-State: AD7BkJKAVYovQ/Y6Z6lfYq4bgpGBb0HQGoz9Q0b15z7ujeixRzyAt+WL0zTvrhMJ9nfsQ/3Z X-Received: by 10.98.10.149 with SMTP id 21mr33488911pfk.75.1456866986546; Tue, 01 Mar 2016 13:16:26 -0800 (PST) Received: from ubuntu.localdomain (i-global254.qualcomm.com. [199.106.103.254]) by smtp.gmail.com with ESMTPSA id kw10sm47749328pab.0.2016.03.01.13.16.23 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 01 Mar 2016 13:16:25 -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: [RFC v3 10/12] ARM64: psci: Support cluster idle states for OS-Initiated Date: Tue, 1 Mar 2016 14:15:29 -0700 Message-Id: <1456866931-37851-12-git-send-email-lina.iyer@linaro.org> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1456866931-37851-1-git-send-email-lina.iyer@linaro.org> References: <1456866931-37851-1-git-send-email-lina.iyer@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20160301_131644_539447_2968D446 X-CRM114-Status: GOOD ( 17.54 ) X-Spam-Score: -2.7 (--) 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, 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.1 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 PSCI OS initiated 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, is responsible for 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 system may provide the state of the coherency domain along with the cluster and the CPU state IDs. Utilize the CPU PM domain framework's helper functions to build up the hierarchy of cluster topology using Generic PM domains. We provide callbacks for domain power_on and power_off. By appending the state IDs at each domain level in the -power_off() callbacks, we build up a composite state ID that can be passed onto the firmware to idle the CPU, the cluster and the coherency interface. Cc: Lorenzo Pieralisi Cc: Mark Rutland Signed-off-by: Lina Iyer --- arch/arm64/kernel/psci.c | 46 +++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 43 insertions(+), 3 deletions(-) diff --git a/arch/arm64/kernel/psci.c b/arch/arm64/kernel/psci.c index f67f35b..75b1707 100644 --- a/arch/arm64/kernel/psci.c +++ b/arch/arm64/kernel/psci.c @@ -15,6 +15,7 @@ #define pr_fmt(fmt) "psci: " fmt +#include #include #include #include @@ -31,6 +32,24 @@ #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) +{ + return cpu_state | this_cpu_read(cluster_state_id); +} + +static inline void psci_reset_composite_state_id(void) +{ + this_cpu_write(cluster_state_id, 0); +} + +static int psci_pd_power_off(u32 state_idx, u32 param, + const struct cpumask *mask) +{ + __this_cpu_add(cluster_state_id, param); + return 0; +} static int __maybe_unused cpu_psci_cpu_init_idle(unsigned int cpu) { @@ -89,6 +108,19 @@ static int __maybe_unused cpu_psci_cpu_init_idle(unsigned int cpu) } /* Idle states parsed correctly, initialize per-cpu pointer */ per_cpu(psci_power_state, cpu) = psci_states; + + if (psci_has_osi_pd_support()) { + const struct cpu_pd_ops psci_pd_ops = { + .power_off = psci_pd_power_off, + }; + + ret = of_setup_cpu_pd_single(cpu, &psci_pd_ops); + if (!ret) + ret = psci_set_suspend_mode_osi(true); + if (ret) + pr_warn("CPU%d: Error setting PSCI OSI mode\n", cpu); + } + return 0; free_mem: @@ -117,6 +149,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 +215,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 +233,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; }