From patchwork Thu Jul 7 17:10:50 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sudeep Holla X-Patchwork-Id: 71612 Delivered-To: patch@linaro.org Received: by 10.140.28.4 with SMTP id 4csp8108qgy; Thu, 7 Jul 2016 10:12:06 -0700 (PDT) X-Received: by 10.66.189.167 with SMTP id gj7mr2202226pac.0.1467911524005; Thu, 07 Jul 2016 10:12:04 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id g25si5083150pfd.87.2016.07.07.10.12.03; Thu, 07 Jul 2016 10:12:03 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-acpi-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-acpi-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-acpi-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753313AbcGGRMB (ORCPT + 6 others); Thu, 7 Jul 2016 13:12:01 -0400 Received: from foss.arm.com ([217.140.101.70]:37895 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751843AbcGGRLN (ORCPT ); Thu, 7 Jul 2016 13:11:13 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 73C1FB9A; Thu, 7 Jul 2016 10:12:12 -0700 (PDT) Received: from e107155-lin.cambridge.arm.com (unknown [10.1.207.160]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 7D7253F21A; Thu, 7 Jul 2016 10:11:10 -0700 (PDT) From: Sudeep Holla To: ACPI List , "Rafael J . Wysocki" Cc: Sudeep Holla , Vikas Sajjan , Sunil , Lorenzo Pieralisi , PrashanthPrakash , Al Stone , Ashwin Chaugule , Daniel Lezcano , LKML , ALKML , Mark Rutland Subject: [PATCH v8 5/6] arm64: add support for ACPI Low Power Idle(LPI) Date: Thu, 7 Jul 2016 18:10:50 +0100 Message-Id: <1467911451-24731-6-git-send-email-sudeep.holla@arm.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1467911451-24731-5-git-send-email-sudeep.holla@arm.com> References: <1467911451-24731-1-git-send-email-sudeep.holla@arm.com> <1467911451-24731-2-git-send-email-sudeep.holla@arm.com> <1467911451-24731-3-git-send-email-sudeep.holla@arm.com> <1467911451-24731-4-git-send-email-sudeep.holla@arm.com> <1467911451-24731-5-git-send-email-sudeep.holla@arm.com> Sender: linux-acpi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org This patch adds appropriate callbacks to support ACPI Low Power Idle (LPI) on ARM64. Cc: Lorenzo Pieralisi Cc: Mark Rutland Cc: Daniel Lezcano Cc: "Rafael J. Wysocki" Signed-off-by: Sudeep Holla --- arch/arm64/kernel/cpuidle.c | 18 +++++++ drivers/firmware/psci.c | 122 ++++++++++++++++++++++++++++++++++++-------- 2 files changed, 118 insertions(+), 22 deletions(-) -- 2.7.4 -- To unsubscribe from this list: send the line "unsubscribe linux-acpi" 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/arch/arm64/kernel/cpuidle.c b/arch/arm64/kernel/cpuidle.c index 06786fdaadeb..7f16df7d7b23 100644 --- a/arch/arm64/kernel/cpuidle.c +++ b/arch/arm64/kernel/cpuidle.c @@ -9,6 +9,9 @@ * published by the Free Software Foundation. */ +#include +#include +#include #include #include @@ -39,3 +42,18 @@ int arm_cpuidle_suspend(int index) return cpu_ops[cpu]->cpu_suspend(index); } + +#ifdef CONFIG_ACPI + +#include + +int acpi_processor_ffh_lpi_probe(unsigned int cpu) +{ + return arm_cpuidle_init(cpu); +} + +int acpi_processor_ffh_lpi_enter(struct acpi_lpi_state *lpi) +{ + return CPU_IDLE_ENTER_WRAPPED(arm_cpuidle_suspend, lpi->index); +} +#endif diff --git a/drivers/firmware/psci.c b/drivers/firmware/psci.c index 03e04582791c..edd83c884a1d 100644 --- a/drivers/firmware/psci.c +++ b/drivers/firmware/psci.c @@ -13,6 +13,7 @@ #define pr_fmt(fmt) "psci: " fmt +#include #include #include #include @@ -250,12 +251,84 @@ static int __init psci_features(u32 psci_func_id) #ifdef CONFIG_CPU_IDLE static DEFINE_PER_CPU_READ_MOSTLY(u32 *, psci_power_state); -static int psci_dt_cpu_init_idle(struct device_node *cpu_node, int cpu) +static int psci_dt_get_state_count(struct device_node *cpu_dn) { - int i, ret, count = 0; - u32 *psci_states; + int count = 0; struct device_node *state_node; + /* Count idle states */ + while ((state_node = of_parse_phandle(cpu_dn, "cpu-idle-states", + count))) { + count++; + of_node_put(state_node); + } + + return count; +} + +static int psci_dt_get_idle_state(struct device_node *node, int idx, u32 *state) +{ + int ret; + struct device_node *state_node; + + state_node = of_parse_phandle(node, "cpu-idle-states", idx); + + ret = of_property_read_u32(state_node, "arm,psci-suspend-param", + state); + if (ret) + pr_warn(" * %s missing arm,psci-suspend-param property\n", + state_node->full_name); + + of_node_put(state_node); + + return ret; +} + +#ifdef CONFIG_ACPI +#include + +static int psci_acpi_get_state_count(unsigned int cpu) +{ + struct acpi_processor *pr = per_cpu(processors, cpu); + + if (unlikely(!pr || !pr->flags.has_lpi)) + return -EINVAL; + + return pr->power.count - 1; +} + +static int psci_acpi_get_idle_state(unsigned int cpu, int idx, u32 *state) +{ + struct acpi_processor *pr = per_cpu(processors, cpu); + struct acpi_lpi_state *lpi = &pr->power.lpi_states[idx + 1]; + + if (!lpi) + return -EINVAL; + + /* + * Only bits[31:0] represent a PSCI power_state while + * bits[63:32] must be 0x0 as per ARM ACPI FFH Specification + */ + *state = lpi->address; + return 0; +} +#else +static int psci_acpi_get_state_count(unsigned int cpu) +{ + return -EINVAL; +} + +static int psci_acpi_get_idle_state(unsigned int cpu, int idx, u32 *state) +{ + return -EINVAL; +} +#endif + +static int __psci_cpu_init_idle(struct device_node *cpu_dn, int cpu, bool acpi) +{ + int i, count, ret; + u32 *psci_states; + /* * If the PSCI cpu_suspend function hook has not been initialized * idle states must not be enabled, so bail out @@ -263,14 +336,12 @@ static int psci_dt_cpu_init_idle(struct device_node *cpu_node, int cpu) if (!psci_ops.cpu_suspend) return -EOPNOTSUPP; - /* Count idle states */ - while ((state_node = of_parse_phandle(cpu_node, "cpu-idle-states", - count))) { - count++; - of_node_put(state_node); - } + if (acpi) + count = psci_acpi_get_state_count(cpu); + else + count = psci_dt_get_state_count(cpu_dn); - if (!count) + if (count <= 0) return -ENODEV; psci_states = kcalloc(count, sizeof(*psci_states), GFP_KERNEL); @@ -278,21 +349,15 @@ static int psci_dt_cpu_init_idle(struct device_node *cpu_node, int cpu) return -ENOMEM; for (i = 0; i < count; i++) { - u32 state; - - state_node = of_parse_phandle(cpu_node, "cpu-idle-states", i); + u32 state = 0; - ret = of_property_read_u32(state_node, - "arm,psci-suspend-param", - &state); - if (ret) { - pr_warn(" * %s missing arm,psci-suspend-param property\n", - state_node->full_name); - of_node_put(state_node); + if (acpi) + ret = psci_acpi_get_idle_state(cpu, i, &state); + else + ret = psci_dt_get_idle_state(cpu_dn, i, &state); + if (ret) goto free_mem; - } - of_node_put(state_node); pr_debug("psci-power-state %#x index %d\n", state, i); if (!psci_power_state_is_valid(state)) { pr_warn("Invalid PSCI power state %#x\n", state); @@ -310,11 +375,24 @@ static int psci_dt_cpu_init_idle(struct device_node *cpu_node, int cpu) return ret; } +static int psci_dt_cpu_init_idle(struct device_node *cpu_node, int cpu) +{ + return __psci_cpu_init_idle(cpu_node, cpu, false); +} + +static int psci_acpi_cpu_init_idle(unsigned int cpu) +{ + return __psci_cpu_init_idle(NULL, cpu, true); +} + int psci_cpu_init_idle(unsigned int cpu) { struct device_node *cpu_node; int ret; + if (!acpi_disabled) + return psci_acpi_cpu_init_idle(cpu); + cpu_node = of_get_cpu_node(cpu, NULL); if (!cpu_node) return -ENODEV;