From patchwork Thu Aug 25 19:51:43 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lina Iyer X-Patchwork-Id: 74712 Delivered-To: patch@linaro.org Received: by 10.140.29.52 with SMTP id a49csp1012606qga; Thu, 25 Aug 2016 12:53:28 -0700 (PDT) X-Received: by 10.98.33.147 with SMTP id o19mr19621332pfj.8.1472154801284; Thu, 25 Aug 2016 12:53:21 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id p11si16919143par.193.2016.08.25.12.53.21; Thu, 25 Aug 2016 12:53:21 -0700 (PDT) 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; dkim=neutral (body hash did not verify) header.i=@linaro.org; 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; dmarc=fail (p=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757443AbcHYTxJ (ORCPT + 14 others); Thu, 25 Aug 2016 15:53:09 -0400 Received: from mail-pa0-f44.google.com ([209.85.220.44]:34824 "EHLO mail-pa0-f44.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756915AbcHYTw0 (ORCPT ); Thu, 25 Aug 2016 15:52:26 -0400 Received: by mail-pa0-f44.google.com with SMTP id hb8so19692428pac.2 for ; Thu, 25 Aug 2016 12:52:26 -0700 (PDT) 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=HbfQdxrUDgL1ltlv8mzDj3K3rNIP5pjP/7vxumdBRa0=; b=HKJe91+nP+ieyMlfSXsemtgBOgQG+yG4uR6bcW8SdR7CvweAxCP7FfMO/ZtoiJU80Y 14P/oQBBMg1VxBeRCqkBbBQO6gmU0ylL24ex8wfB9KBVpQFBtPVtgyCx4J/CtQyCXfLK OguGtZycRWcmGGpAwZflKPuZMpCLIBa4j+wjQ= 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=HbfQdxrUDgL1ltlv8mzDj3K3rNIP5pjP/7vxumdBRa0=; b=FSMw9xGjMKw8ku+baG+qSal8aOPsCCYpWHb5Kt3AJMfkbKfnRzmNBJG4lsm0GdMPOA r2mKYdoaG0jZs+7Y5x4HNi9jLJFCFVMI+ReajskUbBbEaO32D3RVDdB0S+/H1g+EGtn5 6jm/27fXccc/8CZY2MFT6O2BYJ8gUxUEQzBdjR+mFra20szKLw+IcKvY5Y8cD8UAVnQk ZFPzqLQmxmShgBgmasjhfLoEBUldIWmkHaQufJBpsGWxz+FYXpTOdHGkXKp3ap7Z0oii jIf5jrqG7q2hTLIDkU+g6l+scu+FJgnpLCyCF727TwcuvbDwZBY3SQwFl7YiXszzK9JW Iz5w== X-Gm-Message-State: AE9vXwN71sNCO6nEy9RM9PUuxSRTDdnB2e4CvOQRVtmLSPCZh00w4p082Z6v2+PvMya+7NY7 X-Received: by 10.66.255.42 with SMTP id an10mr19704317pad.57.1472154745857; Thu, 25 Aug 2016 12:52:25 -0700 (PDT) Received: from ubuntu.localdomain (i-global254.qualcomm.com. [199.106.103.254]) by smtp.gmail.com with ESMTPSA id i62sm22783375pfg.62.2016.08.25.12.52.23 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 25 Aug 2016 12:52:25 -0700 (PDT) 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 Cc: andy.gross@linaro.org, sboyd@codeaurora.org, linux-arm-msm@vger.kernel.org, brendan.jackman@arm.com, lorenzo.pieralisi@arm.com, sudeep.holla@arm.com, Juri.Lelli@arm.com, Lina Iyer , Mark Rutland Subject: [PATCH v4 13/16] drivers: firmware: psci: Support cluster idle states for OS-Initiated Date: Thu, 25 Aug 2016 13:51:43 -0600 Message-Id: <1472154706-40119-14-git-send-email-lina.iyer@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1472154706-40119-1-git-send-email-lina.iyer@linaro.org> References: <1472154706-40119-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 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 --- drivers/firmware/psci.c | 93 +++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 90 insertions(+), 3 deletions(-) -- 2.7.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/drivers/firmware/psci.c b/drivers/firmware/psci.c index 759b134..431385a 100644 --- a/drivers/firmware/psci.c +++ b/drivers/firmware/psci.c @@ -15,6 +15,7 @@ #include #include +#include #include #include #include @@ -53,6 +54,18 @@ */ static int resident_cpu = -1; static bool psci_has_osi; +static bool psci_has_osi_pd; +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); +} bool psci_tos_resident_on(int cpu) { @@ -179,6 +192,8 @@ static int psci_cpu_on(unsigned long cpuid, unsigned long entry_point) fn = psci_function_id[PSCI_FN_CPU_ON]; err = invoke_psci_fn(fn, cpuid, entry_point, 0); + /* Reset CPU cluster states */ + psci_reset_composite_state_id(); return psci_to_linux_errno(err); } @@ -250,6 +265,27 @@ static int __init psci_features(u32 psci_func_id) #ifdef CONFIG_CPU_IDLE static DEFINE_PER_CPU_READ_MOSTLY(u32 *, psci_power_state); +static bool psci_suspend_mode_is_osi; + +static int psci_set_suspend_mode_osi(bool enable) +{ + int ret; + int mode; + + if (enable && !psci_has_osi) + return -ENODEV; + + if (enable == psci_suspend_mode_is_osi) + return 0; + + mode = enable ? PSCI_1_0_SUSPEND_MODE_OSI : PSCI_1_0_SUSPEND_MODE_PC; + ret = invoke_psci_fn(PSCI_1_0_FN_SET_SUSPEND_MODE, + mode, 0, 0); + if (!ret) + psci_suspend_mode_is_osi = enable; + + return psci_to_linux_errno(ret); +} static int psci_dt_cpu_init_idle(struct device_node *cpu_node, int cpu) { @@ -311,11 +347,48 @@ free_mem: return ret; } +static int psci_pd_populate_state_data(struct device_node *np, u32 *param) +{ + return of_property_read_u32(np, "arm,psci-suspend-param", param); +} + +static int psci_pd_power_off(u32 idx, u32 param, const struct cpumask *mask) +{ + __this_cpu_add(cluster_state_id, param); + return 0; +} + +const struct cpu_pd_ops psci_pd_ops = { + .populate_state_data = psci_pd_populate_state_data, + .power_off = psci_pd_power_off, +}; + +static int psci_cpu_osi_pd_init(int cpu) +{ + int ret; + + if (!psci_has_osi_pd) + return 0; + + 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 ret; +} + int psci_cpu_init_idle(unsigned int cpu) { struct device_node *cpu_node; int ret; + ret = psci_cpu_osi_pd_init(cpu); + if (ret) + return ret; + cpu_node = of_get_cpu_node(cpu, NULL); if (!cpu_node) return -ENODEV; @@ -330,15 +403,17 @@ int psci_cpu_init_idle(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)); } int psci_cpu_suspend_enter(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 @@ -347,10 +422,16 @@ int psci_cpu_suspend_enter(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; } @@ -558,6 +639,7 @@ static int __init psci_0_1_init(struct device_node *np) static int __init psci_1_0_init(struct device_node *np) { + struct device_node *dn; int ret; ret = psci_0_2_init(np); @@ -569,6 +651,11 @@ static int __init psci_1_0_init(struct device_node *np) if (ret & PSCI_1_0_OS_INITIATED) { if (!psci_features(PSCI_1_0_FN_SET_SUSPEND_MODE)) psci_has_osi = true; + /* Check if we power domains defined in the PSCI node */ + dn = of_find_node_with_property(np, "#power-domain-cells"); + if (dn) + psci_has_osi_pd = true; + of_node_put(dn); } return 0;