From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753466AbcFMFRj (ORCPT ); Mon, 13 Jun 2016 01:17:39 -0400 Received: from mail-by2on0125.outbound.protection.outlook.com ([207.46.100.125]:59680 "EHLO na01-by2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1750715AbcFMFRi convert rfc822-to-8bit (ORCPT ); Mon, 13 Jun 2016 01:17:38 -0400 X-Greylist: delayed 905 seconds by postgrey-1.27 at vger.kernel.org; Mon, 13 Jun 2016 01:17:38 EDT From: "Sajjan, Vikas C" To: Sudeep Holla , "linux-acpi@vger.kernel.org" , "Rafael J. Wysocki" CC: "linux-kernel@vger.kernel.org" , "Lakshminarasimha, Sunil Vishwanathpur" , Prashanth Prakash , Ashwin Chaugule , "Al Stone" , Lorenzo Pieralisi , Mark Rutland , "linux-arm-kernel@lists.infradead.org" Subject: RE: [PATCH v5 4/5] arm64: add support for ACPI Low Power Idle(LPI) Thread-Topic: [PATCH v5 4/5] arm64: add support for ACPI Low Power Idle(LPI) Thread-Index: AQHRq5smdkHX9E1emEmUdJO6YJ6n8p/nBBiQ Date: Mon, 13 Jun 2016 04:47:24 +0000 Message-ID: References: <1462981062-24909-1-git-send-email-sudeep.holla@arm.com> <1462981062-24909-5-git-send-email-sudeep.holla@arm.com> In-Reply-To: <1462981062-24909-5-git-send-email-sudeep.holla@arm.com> Accept-Language: en-IN, en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: authentication-results: spf=none (sender IP is ) smtp.mailfrom=vikas.cha.sajjan@hpe.com; x-originating-ip: [15.219.195.11] x-ms-office365-filtering-correlation-id: e30dacd4-1c4e-4241-aebc-08d39345d088 x-microsoft-exchange-diagnostics: 1;DF4PR84MB0076;6:9pFtuJEYzDW/1aN/by5Cv33Sjypi4Y5EsLS4TUiToDTb2/5znoJYg/ZXkhB7+vyf1JwGu7WMEqbVDy1xkyTkkN0vR2vuuvisfrZ7NNvVDeBEbTZtedZXgAfmQGJGsLPC8PONAnxBhUeXb2u+lCwa1K4Q2ScQ05Jc+3oVDSELhaAtGeJFWc9uyw1d6kVjw/QVLJPrcop7LBSSUE3aWyLEpD5loEgYbCZqHj1engo6rfz3N5UBdywGibqUMmB56nPoWaNlyjAxv0OykWJtGpSPkspiCjgf/Z6IXwi+SKOVwDU=;5:+YfLEXIz0uAiWZlCm7F+yidECce4e97QMj076hpD5hRuBKpqMefWcPGV9AubUIg5eAr3AOR2myhDIjxu+k0N9ImhbcCM6jYXp2QsZD4anaCNa43IvUY6wH+Tt3TFtGrwnnFA+C8LF4cZzJCVrdVH2Q==;24:i6Py1OYMZ+d+awmBU4hT16DGwpG0pizc4qjsu3RCm5BLqSCUVRvXzAwCNufhoASQ1NWP9cDvmQvoDpTvEtIPtmchlNcip8WnJOH8lX2RoJ0=;7:mBQ1nR7kFJ2Ysxjf6zO2WMrA+Zbx2SHd3xiz5JcaHSFEVvUxCIB0puG/Ee32xVf7EUti8ZlIAsNOXvVPQCCZC0/JEaTm0EvPQUHaOH+78FERsN2X6TCaZ6mcCO8xL/enexpbqmtXPzaBqL8BpM8Dmrn1MVHU3jIVwb73XFJDMq/gQcO/HxyMLq3ZArEJtlflPg1OWwHNX1nl+9lE8f0I/Tm6sj/pr/dqxdKcGYG0sGM= x-microsoft-antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:DF4PR84MB0076; x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:(227479698468861)(180628864354917)(9452136761055)(258649278758335); x-exchange-antispam-report-cfa-test: BCL:0;PCL:0;RULEID:(601004)(2401047)(5005006)(8121501046)(10201501046)(3002001);SRVR:DF4PR84MB0076;BCL:0;PCL:0;RULEID:;SRVR:DF4PR84MB0076; x-forefront-prvs: 0972DEC1D9 x-forefront-antispam-report: SFV:NSPM;SFS:(10019020)(6009001)(7916002)(377454003)(199003)(13464003)(189002)(106356001)(106116001)(105586002)(5004730100002)(66066001)(5001770100001)(97736004)(76176999)(19580395003)(2950100001)(9686002)(2900100001)(3280700002)(3660700001)(19580405001)(87936001)(5003600100002)(2501003)(4326007)(5002640100001)(8936002)(2906002)(122556002)(102836003)(81166006)(5008740100001)(6116002)(3846002)(586003)(68736007)(54356999)(189998001)(33656002)(101416001)(81156014)(10400500002)(8676002)(77096005)(99286002)(86362001)(92566002)(50986999);DIR:OUT;SFP:1102;SCL:1;SRVR:DF4PR84MB0076;H:DF4PR84MB0041.NAMPRD84.PROD.OUTLOOK.COM;FPR:;SPF:None;PTR:InfoNoRecords;A:1;MX:1;CAT:NONE;LANG:en;CAT:NONE; spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 8BIT MIME-Version: 1.0 X-OriginatorOrg: hpe.com X-MS-Exchange-CrossTenant-originalarrivaltime: 13 Jun 2016 04:47:24.8141 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 105b2061-b669-4b31-92ac-24d304d195dc X-MS-Exchange-Transport-CrossTenantHeadersStamped: DF4PR84MB0076 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Sudeep, -----Original Message----- From: Sudeep Holla [mailto:sudeep.holla@arm.com] Sent: Wednesday, May 11, 2016 9:08 PM To: linux-acpi@vger.kernel.org; Rafael J. Wysocki Cc: Sudeep Holla ; linux-kernel@vger.kernel.org; Sajjan, Vikas C ; Lakshminarasimha, Sunil Vishwanathpur ; Prashanth Prakash ; Ashwin Chaugule ; Al Stone ; Lorenzo Pieralisi ; Mark Rutland ; linux-arm-kernel@lists.infradead.org Subject: [PATCH v5 4/5] arm64: add support for ACPI Low Power Idle(LPI) This patch adds appropriate callbacks to support ACPI Low Power Idle (LPI) on ARM64. Cc: Lorenzo Pieralisi Cc: Mark Rutland Cc: linux-arm-kernel@lists.infradead.org Signed-off-by: Sudeep Holla --- arch/arm64/kernel/acpi.c | 48 +++++++++++++++++++++++++++++++++++++++++ drivers/firmware/psci.c | 56 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 104 insertions(+) diff --git a/arch/arm64/kernel/acpi.c b/arch/arm64/kernel/acpi.c index d1ce8e2f98b9..bf82ce5c8fce 100644 --- a/arch/arm64/kernel/acpi.c +++ b/arch/arm64/kernel/acpi.c @@ -18,6 +18,7 @@ #include #include #include +#include #include #include #include @@ -25,6 +26,9 @@ #include #include +#include + +#include #include #include #include @@ -211,6 +215,50 @@ void __init acpi_boot_table_init(void) } } +int acpi_processor_ffh_lpi_probe(unsigned int cpu) { + return arm_cpuidle_init(cpu); +} + +#define ACPI_FFH_LPI_ARM_FLAGS_CORE_CONTEXT BIT(0) +#define ACPI_FFH_LPI_ARM_FLAGS_TRACE_CONTEXT BIT(1) +#define ACPI_FFH_LPI_ARM_FLAGS_GICR_CONTEXT BIT(2) +#define ACPI_FFH_LPI_ARM_FLAGS_GICD_CONTEXT BIT(3) +#define ACPI_FFH_LPI_ARM_FLAGS_ALL_CONTEXT \ + (ACPI_FFH_LPI_ARM_FLAGS_CORE_CONTEXT | \ + ACPI_FFH_LPI_ARM_FLAGS_TRACE_CONTEXT | \ + ACPI_FFH_LPI_ARM_FLAGS_GICR_CONTEXT | \ + ACPI_FFH_LPI_ARM_FLAGS_GICD_CONTEXT) + +struct acpi_lpi_state *lpi; +int acpi_processor_ffh_lpi_enter(struct acpi_lpi_state *lpi, int idx) { + int ret = 0; + bool save_ctx = lpi->arch_flags & ACPI_FFH_LPI_ARM_FLAGS_ALL_CONTEXT; + + if (!idx) { + cpu_do_idle(); + return idx; + } + + /* TODO cpu_pm_{enter,exit} can be done in generic code ? */ + if (save_ctx) + ret = cpu_pm_enter(); + if (!ret) { + /* + * Pass idle state index to cpu_suspend which in turn will + * call the CPU ops suspend protocol with idle index as a + * parameter. + */ + ret = arm_cpuidle_suspend(idx); + + if (save_ctx) + cpu_pm_exit(); + } + + return ret ? -1 : idx; +} + #ifdef CONFIG_ACPI_APEI pgprot_t arch_apei_get_mem_attribute(phys_addr_t addr) { diff --git a/drivers/firmware/psci.c b/drivers/firmware/psci.c index fa4ea22ca12e..e06bfee68e1d 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 @@ -310,11 +311,66 @@ static int psci_dt_cpu_init_idle(struct device_node *cpu_node, int cpu) return ret; } +#ifdef CONFIG_ACPI +#include + +static int __maybe_unused psci_acpi_cpu_init_idle(unsigned int cpu) { + int i, count; + u32 *psci_states; + struct acpi_processor *pr; + struct acpi_lpi_state *lpi; + + pr = per_cpu(processors, cpu); + if (unlikely(!pr || !pr->flags.has_lpi)) Any particular reason for _not_ considering CST flag here. Or you are planning to add CST support in some other patch set. + return -EINVAL; + + /* + * If the PSCI cpu_suspend function hook has not been initialized + * idle states must not be enabled, so bail out + */ + if (!psci_ops.cpu_suspend) + return -EOPNOTSUPP; + + count = pr->power.count - 1; + if (!count) + return -ENODEV; + + psci_states = kcalloc(count, sizeof(*psci_states), GFP_KERNEL); + if (!psci_states) + return -ENOMEM; + + for (i = 0; i < count; i++) { + u32 state; + + lpi = &pr->power.lpi_states[i + 1]; Same case here too. + state = lpi->address & 0xFFFFFFFF; + if (!psci_power_state_is_valid(state)) { + pr_warn("Invalid PSCI power state %#x\n", state); + kfree(psci_states); + return -EINVAL; + } + psci_states[i] = state; + } + /* Idle states parsed correctly, initialize per-cpu pointer */ + per_cpu(psci_power_state, cpu) = psci_states; + return 0; +} +#else +static int __maybe_unused psci_acpi_cpu_init_idle(unsigned int cpu) { + return -EINVAL; +} +#endif + 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; -- 1.9.1 From mboxrd@z Thu Jan 1 00:00:00 1970 From: vikas.cha.sajjan@hpe.com (Sajjan, Vikas C) Date: Mon, 13 Jun 2016 04:47:24 +0000 Subject: [PATCH v5 4/5] arm64: add support for ACPI Low Power Idle(LPI) In-Reply-To: <1462981062-24909-5-git-send-email-sudeep.holla@arm.com> References: <1462981062-24909-1-git-send-email-sudeep.holla@arm.com> <1462981062-24909-5-git-send-email-sudeep.holla@arm.com> Message-ID: To: linux-arm-kernel@lists.infradead.org List-Id: linux-arm-kernel.lists.infradead.org Hi Sudeep, -----Original Message----- From: Sudeep Holla [mailto:sudeep.holla at arm.com] Sent: Wednesday, May 11, 2016 9:08 PM To: linux-acpi at vger.kernel.org; Rafael J. Wysocki Cc: Sudeep Holla ; linux-kernel at vger.kernel.org; Sajjan, Vikas C ; Lakshminarasimha, Sunil Vishwanathpur ; Prashanth Prakash ; Ashwin Chaugule ; Al Stone ; Lorenzo Pieralisi ; Mark Rutland ; linux-arm-kernel at lists.infradead.org Subject: [PATCH v5 4/5] arm64: add support for ACPI Low Power Idle(LPI) This patch adds appropriate callbacks to support ACPI Low Power Idle (LPI) on ARM64. Cc: Lorenzo Pieralisi Cc: Mark Rutland Cc: linux-arm-kernel at lists.infradead.org Signed-off-by: Sudeep Holla --- arch/arm64/kernel/acpi.c | 48 +++++++++++++++++++++++++++++++++++++++++ drivers/firmware/psci.c | 56 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 104 insertions(+) diff --git a/arch/arm64/kernel/acpi.c b/arch/arm64/kernel/acpi.c index d1ce8e2f98b9..bf82ce5c8fce 100644 --- a/arch/arm64/kernel/acpi.c +++ b/arch/arm64/kernel/acpi.c @@ -18,6 +18,7 @@ #include #include #include +#include #include #include #include @@ -25,6 +26,9 @@ #include #include +#include + +#include #include #include #include @@ -211,6 +215,50 @@ void __init acpi_boot_table_init(void) } } +int acpi_processor_ffh_lpi_probe(unsigned int cpu) { + return arm_cpuidle_init(cpu); +} + +#define ACPI_FFH_LPI_ARM_FLAGS_CORE_CONTEXT BIT(0) +#define ACPI_FFH_LPI_ARM_FLAGS_TRACE_CONTEXT BIT(1) +#define ACPI_FFH_LPI_ARM_FLAGS_GICR_CONTEXT BIT(2) +#define ACPI_FFH_LPI_ARM_FLAGS_GICD_CONTEXT BIT(3) +#define ACPI_FFH_LPI_ARM_FLAGS_ALL_CONTEXT \ + (ACPI_FFH_LPI_ARM_FLAGS_CORE_CONTEXT | \ + ACPI_FFH_LPI_ARM_FLAGS_TRACE_CONTEXT | \ + ACPI_FFH_LPI_ARM_FLAGS_GICR_CONTEXT | \ + ACPI_FFH_LPI_ARM_FLAGS_GICD_CONTEXT) + +struct acpi_lpi_state *lpi; +int acpi_processor_ffh_lpi_enter(struct acpi_lpi_state *lpi, int idx) { + int ret = 0; + bool save_ctx = lpi->arch_flags & ACPI_FFH_LPI_ARM_FLAGS_ALL_CONTEXT; + + if (!idx) { + cpu_do_idle(); + return idx; + } + + /* TODO cpu_pm_{enter,exit} can be done in generic code ? */ + if (save_ctx) + ret = cpu_pm_enter(); + if (!ret) { + /* + * Pass idle state index to cpu_suspend which in turn will + * call the CPU ops suspend protocol with idle index as a + * parameter. + */ + ret = arm_cpuidle_suspend(idx); + + if (save_ctx) + cpu_pm_exit(); + } + + return ret ? -1 : idx; +} + #ifdef CONFIG_ACPI_APEI pgprot_t arch_apei_get_mem_attribute(phys_addr_t addr) { diff --git a/drivers/firmware/psci.c b/drivers/firmware/psci.c index fa4ea22ca12e..e06bfee68e1d 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 @@ -310,11 +311,66 @@ static int psci_dt_cpu_init_idle(struct device_node *cpu_node, int cpu) return ret; } +#ifdef CONFIG_ACPI +#include + +static int __maybe_unused psci_acpi_cpu_init_idle(unsigned int cpu) { + int i, count; + u32 *psci_states; + struct acpi_processor *pr; + struct acpi_lpi_state *lpi; + + pr = per_cpu(processors, cpu); + if (unlikely(!pr || !pr->flags.has_lpi)) Any particular reason for _not_ considering CST flag here. Or you are planning to add CST support in some other patch set. + return -EINVAL; + + /* + * If the PSCI cpu_suspend function hook has not been initialized + * idle states must not be enabled, so bail out + */ + if (!psci_ops.cpu_suspend) + return -EOPNOTSUPP; + + count = pr->power.count - 1; + if (!count) + return -ENODEV; + + psci_states = kcalloc(count, sizeof(*psci_states), GFP_KERNEL); + if (!psci_states) + return -ENOMEM; + + for (i = 0; i < count; i++) { + u32 state; + + lpi = &pr->power.lpi_states[i + 1]; Same case here too. + state = lpi->address & 0xFFFFFFFF; + if (!psci_power_state_is_valid(state)) { + pr_warn("Invalid PSCI power state %#x\n", state); + kfree(psci_states); + return -EINVAL; + } + psci_states[i] = state; + } + /* Idle states parsed correctly, initialize per-cpu pointer */ + per_cpu(psci_power_state, cpu) = psci_states; + return 0; +} +#else +static int __maybe_unused psci_acpi_cpu_init_idle(unsigned int cpu) { + return -EINVAL; +} +#endif + 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; -- 1.9.1