From patchwork Fri Mar 3 21:48:14 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lina Iyer X-Patchwork-Id: 9603601 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id A2F9C602B4 for ; Fri, 3 Mar 2017 21:50:37 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9421A28610 for ; Fri, 3 Mar 2017 21:50:37 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 88FDD28614; Fri, 3 Mar 2017 21:50:37 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-1.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 01DB028610 for ; Fri, 3 Mar 2017 21:50:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=U91rJuC89g6nTlVVURKUAKgPuqdTn/jW/od2/li0Iqs=; b=A48y6iAH82x/llfRbwzt+fIKIZ xGV0vs6uNyENs+g7l6+gF9or/ercs9E7N819Z/a5RcLGwR9nzT+VFe5B/QIqNq9B24xyv20uyaFnL 6iWRrTEbGLTYSpe+bXdIfCdViOkIZh9jK78JYsGj5hR4uJowFTvXMaLXbP5UXqg34Cs5uVpm9+x52 tYJ97q2pNd20tYsj6aL+X9Kw8nHYF6BvTXxzUrWcVDa7799JAoGDo0iwzEjLGu7/W/FBc1PWpH+HD t0aYZvrHN8xghM1YX5j0sdiQ3CqXVvmGoKNO1yf1T7Hv52Zifjb8S3QguOAcbs/R+6kOJhsef3LWI qeJFisAw==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1cjv5w-0002BJ-Oo; Fri, 03 Mar 2017 21:50:36 +0000 Received: from mail-pf0-x22a.google.com ([2607:f8b0:400e:c00::22a]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1cjv4E-00005U-9i for linux-arm-kernel@lists.infradead.org; Fri, 03 Mar 2017 21:48:52 +0000 Received: by mail-pf0-x22a.google.com with SMTP id j5so37096356pfb.2 for ; Fri, 03 Mar 2017 13:48:29 -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=HnX1R2U+zkFRnQ0FKBS4rl+0aVREUPJZAkkad61JZWI=; b=NVM1upbohj4s4XdP5+BCGjy3lCfII8PeDds/0GVCQkDE9T4p9VD6HUDt/tY1wsBf+7 B5adDrAxwih8Vx2whMp10sUH+gaAczuFJ2f50jCkqhnI2qMZltB463FETo4YxJ08zqam QIN3OANXZnfQOngC21V47FE5cg8DiJAU5tkNM= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=HnX1R2U+zkFRnQ0FKBS4rl+0aVREUPJZAkkad61JZWI=; b=IDg3KPHeq7NxupDUWaElIZuRPmY3hkY05UHZZiRxFZQi9xz2P0Kz9XMVqvme7vKWeF r005OzH73ia21qtVI61r7voQz0wZWZOF7VcUy1nPFCEwyBPfjcUPVGTlDramCpDe7L7A W3LSwL5Mhq8/GHgjS1BeWUCdzdkpeItnr4as79a/gKnKg0yzLEV/RC7FHMnpO0FEIGka 28IzThJnDvLRvL7vG34Ba4AZKdfMtX5cIkbJsXXaApX/GjEUir64EuyQcKgRLAJFiFjQ UIS1LVO//jP5Nq5aF2VRimYxGnhclYHlEtFdrDt+eKlnedn09puxK3xSGKksh5i1/Ond zkZQ== X-Gm-Message-State: AMke39nu3xx2uQ+mlKCaKxcGFSlXHygert7WSRfv8jBlD8WxuEUthrifCux+jMglto9vdFpZ X-Received: by 10.99.94.198 with SMTP id s189mr6066824pgb.211.1488577709380; Fri, 03 Mar 2017 13:48:29 -0800 (PST) Received: from ubuntu.localdomain (i-global254.qualcomm.com. [199.106.103.254]) by smtp.gmail.com with ESMTPSA id q23sm25200585pfg.63.2017.03.03.13.48.27 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 03 Mar 2017 13:48:28 -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: [PATCH V5 3/6] drivers: firmware: psci: Support cluster idle states for OS-Initiated Date: Fri, 3 Mar 2017 13:48:14 -0800 Message-Id: <1488577697-127445-4-git-send-email-lina.iyer@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1488577697-127445-1-git-send-email-lina.iyer@linaro.org> References: <1488577697-127445-1-git-send-email-lina.iyer@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170303_134850_380083_50E677C8 X-CRM114-Status: GOOD ( 18.58 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Mark Rutland , lorenzo.pieralisi@arm.com, Juri.Lelli@arm.com, linux-arm-msm@vger.kernel.org, sboyd@codeaurora.org, brendan.jackman@arm.com, sudeep.holla@arm.com, andy.gross@linaro.org, Lina Iyer MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.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 --- drivers/firmware/psci.c | 93 +++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 90 insertions(+), 3 deletions(-) diff --git a/drivers/firmware/psci.c b/drivers/firmware/psci.c index ec922b8..18ae62d 100644 --- a/drivers/firmware/psci.c +++ b/drivers/firmware/psci.c @@ -16,6 +16,7 @@ #include #include #include +#include #include #include #include @@ -54,6 +55,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) { @@ -180,6 +193,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); } @@ -251,6 +266,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) { @@ -353,6 +389,39 @@ static int __maybe_unused psci_acpi_cpu_init_idle(unsigned int cpu) } #endif +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; @@ -368,6 +437,10 @@ int psci_cpu_init_idle(unsigned int cpu) if (!acpi_disabled) return psci_acpi_cpu_init_idle(cpu); + ret = psci_cpu_osi_pd_init(cpu); + if (ret) + return ret; + cpu_node = of_get_cpu_node(cpu, NULL); if (!cpu_node) return -ENODEV; @@ -382,15 +455,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 @@ -399,10 +474,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; } @@ -610,6 +691,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); @@ -621,6 +703,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;