Skip to contentSkip to conversation

ACPI / processor_idle: Add ACPI v6.0 LPI support

PATCH Superseded Sudeep Holla 4 participants 27 messages Jun 14, 2016 – Jun 27, 2016

Subsystems (4)

v6 of 10 Superseded Latest is v10 →

lore
Share & tools
lore
#1 lore raw

PATCH v6 1/5 ACPI / processor_idle: introduce ACPI_PROCESSOR_CSTATE

In reply to Sudeep Holla

ACPI 6.0 adds a new method to specify the CPU idle states(C-states) called Low Power Idle(LPI) states. Since new architectures like ARM64 use only LPIs, introduce ACPI_PROCESSOR_CSTATE to encapsulate all the code supporting the old style C-states(_CST).

This patch will help to extend the processor_idle module to support LPI.

Cc "Rafael J. Wysocki" <[email protected]>
---
 drivers/acpi/Kconfig          |  4 +++
 drivers/acpi/processor_idle.c | 80 ++++++++++++++++++++++++++++---------------
 include/acpi/processor.h      |  2 +-
 3 files changed, 58 insertions(+), 28 deletions(-)
drivers/acpi/Kconfig +4 -0
index b7e2e776397d..1358fb7d7a68 100644
@@ -213,6 +213,10 @@ config ACPI_CPU_FREQ_PSS
 	bool
 	select THERMAL
 
+config ACPI_PROCESSOR_CSTATE
+	def_bool y
+	depends on IA64 || X86
+
 config ACPI_PROCESSOR_IDLE
 	bool
 	select CPU_IDLE
drivers/acpi/processor_idle.c +53 -27

111 lines not on this page · raw message

include/acpi/processor.h +1 -1
index 6f1805dd5d3c..48779d678122 100644
@@ -242,7 +242,7 @@ extern int acpi_processor_get_performance_info(struct acpi_processor *pr);
 DECLARE_PER_CPU(struct acpi_processor *, processors);
 extern struct acpi_processor_errata errata;
 
-#ifdef ARCH_HAS_POWER_INIT
+#if defined(ARCH_HAS_POWER_INIT) && defined(CONFIG_ACPI_PROCESSOR_CSTATE)
 void acpi_processor_power_init_bm_check(struct acpi_processor_flags *flags,
 					unsigned int cpu);
 int acpi_processor_ffh_cstate_probe(unsigned int cpu,
Signature · 1 line
2.7.4
#2 lore raw

PATCH v6 2/5 ACPI / processor_idle: Add support for Low Power Idle(LPI) states

In reply to Sudeep Holla

ACPI 6.0 introduced an optional object _LPI that provides an alternate method to describe Low Power Idle states. It defines the local power states for each node in a hierarchical processor topology. The OSPM can use _LPI object to select a local power state for each level of processor hierarchy in the system. They used to produce a composite power state request that is presented to the platform by the OSPM.

Since multiple processors affect the idle state for any non-leaf hierarchy node, coordination of idle state requests between the processors is required. ACPI supports two different coordination schemes: Platform coordinated and OS initiated.

This patch adds initial support for Platform coordination scheme of LPI.

Cc "Rafael J. Wysocki" <[email protected]>
---
 drivers/acpi/bus.c              |  14 +-
 drivers/acpi/processor_driver.c |   2 +-
 drivers/acpi/processor_idle.c   | 469 +++++++++++++++++++++++++++++++++++-----
 include/acpi/processor.h        |  24 +-
 include/linux/acpi.h            |   4 +
 5 files changed, 453 insertions(+), 60 deletions(-)
drivers/acpi/bus.c +13 -1
index 262ca31b86d9..80ebb05e387c 100644
@@ -302,6 +302,14 @@ acpi_status acpi_run_osc(acpi_handle handle, struct acpi_osc_context *context)
 EXPORT_SYMBOL(acpi_run_osc);
 
 bool osc_sb_apei_support_acked;
+
+/*
+ * ACPI 6.0 Section 8.4.4.2 Idle State Coordination
+ * OSPM supports platform coordinated low power idle(LPI) states
+ */
+bool osc_pc_lpi_support_confirmed;
+EXPORT_SYMBOL_GPL(osc_pc_lpi_support_confirmed);
+
 static u8 sb_uuid_str[] = "0811B06E-4A27-44F9-8D60-3CBBC22E7B48";
 static void acpi_bus_osc_support(void)
 {
@@ -322,6 +330,7 @@ static void acpi_bus_osc_support(void)
 		capbuf[OSC_SUPPORT_DWORD] |= OSC_SB_PPC_OST_SUPPORT;
 
 	capbuf[OSC_SUPPORT_DWORD] |= OSC_SB_HOTPLUG_OST_SUPPORT;
+	capbuf[OSC_SUPPORT_DWORD] |= OSC_SB_PCLPI_SUPPORT;
 
 	if (!ghes_disable)
 		capbuf[OSC_SUPPORT_DWORD] |= OSC_SB_APEI_SUPPORT;
@@ -329,9 +338,12 @@ static void acpi_bus_osc_support(void)
 		return;
 	if (ACPI_SUCCESS(acpi_run_osc(handle, &context))) {
 		u32 *capbuf_ret = context.ret.pointer;
-		if (context.ret.length > OSC_SUPPORT_DWORD)
+		if (context.ret.length > OSC_SUPPORT_DWORD) {
 			osc_sb_apei_support_acked =
 				capbuf_ret[OSC_SUPPORT_DWORD] & OSC_SB_APEI_SUPPORT;
+			osc_pc_lpi_support_confirmed =
+				capbuf_ret[OSC_SUPPORT_DWORD] & OSC_SB_PCLPI_SUPPORT;
+		}
 		kfree(context.ret.pointer);
 	}
 	/* do we need to check other returned cap? Sounds no */
drivers/acpi/processor_driver.c +1 -1
index d2fa8cb82d2b..0ca14ac7bb28 100644
@@ -90,7 +90,7 @@ static void acpi_processor_notify(acpi_handle handle, u32 event, void *data)
 						  pr->performance_platform_limit);
 		break;
 	case ACPI_PROCESSOR_NOTIFY_POWER:
-		acpi_processor_cst_has_changed(pr);
+		acpi_processor_power_state_has_changed(pr);
 		acpi_bus_generate_netlink_event(device->pnp.device_class,
 						  dev_name(&device->dev), event, 0);
 		break;
drivers/acpi/processor_idle.c +414 -55

565 lines not on this page · raw message

include/acpi/processor.h +21 -3
index 48779d678122..e2dcb0c51554 100644
@@ -39,6 +39,7 @@
 #define ACPI_CSTATE_SYSTEMIO	0
 #define ACPI_CSTATE_FFH		1
 #define ACPI_CSTATE_HALT	2
+#define ACPI_CSTATE_INTEGER	3
 
 #define ACPI_CX_DESC_LEN	32
 
@@ -67,9 +68,25 @@ struct acpi_processor_cx {
 	char desc[ACPI_CX_DESC_LEN];
 };
 
+struct acpi_lpi_state {
+	u32 min_residency;
+	u32 wake_latency; /* worst case */
+	u32 flags;
+	u32 arch_flags;
+	u32 res_cnt_freq;
+	u32 enable_parent_state;
+	u64 address;
+	u8 index;
+	u8 entry_method;
+	char desc[ACPI_CX_DESC_LEN];
+};
+
 struct acpi_processor_power {
 	int count;
-	struct acpi_processor_cx states[ACPI_PROCESSOR_MAX_POWER];
+	union {
+		struct acpi_processor_cx states[ACPI_PROCESSOR_MAX_POWER];
+		struct acpi_lpi_state lpi_states[ACPI_PROCESSOR_MAX_POWER];
+	};
 	int timer_broadcast_on_state;
 };
 
@@ -189,6 +206,7 @@ struct acpi_processor_flags {
 	u8 bm_control:1;
 	u8 bm_check:1;
 	u8 has_cst:1;
+	u8 has_lpi:1;
 	u8 power_setup_done:1;
 	u8 bm_rld_set:1;
 	u8 need_hotplug_init:1;
@@ -371,7 +389,7 @@ extern struct cpuidle_driver acpi_idle_driver;
 #ifdef CONFIG_ACPI_PROCESSOR_IDLE
 int acpi_processor_power_init(struct acpi_processor *pr);
 int acpi_processor_power_exit(struct acpi_processor *pr);
-int acpi_processor_cst_has_changed(struct acpi_processor *pr);
+int acpi_processor_power_state_has_changed(struct acpi_processor *pr);
 int acpi_processor_hotplug(struct acpi_processor *pr);
 #else
 static inline int acpi_processor_power_init(struct acpi_processor *pr)
@@ -384,7 +402,7 @@ static inline int acpi_processor_power_exit(struct acpi_processor *pr)
 	return -ENODEV;
 }
 
-static inline int acpi_processor_cst_has_changed(struct acpi_processor *pr)
+static inline int acpi_processor_power_state_has_changed(struct acpi_processor *pr)
 {
 	return -ENODEV;
 }
include/linux/acpi.h +4 -0
index 288fac5294f5..65754566ae17 100644
@@ -444,8 +444,12 @@ acpi_status acpi_run_osc(acpi_handle handle, struct acpi_osc_context *context);
 #define OSC_SB_HOTPLUG_OST_SUPPORT		0x00000008
 #define OSC_SB_APEI_SUPPORT			0x00000010
 #define OSC_SB_CPC_SUPPORT			0x00000020
+#define OSC_SB_CPCV2_SUPPORT			0x00000040
+#define OSC_SB_PCLPI_SUPPORT			0x00000080
+#define OSC_SB_OSLPI_SUPPORT			0x00000100
 
 extern bool osc_sb_apei_support_acked;
+extern bool osc_pc_lpi_support_confirmed;
 
 /* PCI Host Bridge _OSC: Capabilities DWORD 2: Support Field */
 #define OSC_PCI_EXT_CONFIG_SUPPORT		0x00000001
Signature · 1 line
2.7.4
#5 lore raw

PATCH v6 3/5 arm64: cpuidle: drop __init section marker to arm_cpuidle_init

In reply to Sudeep Holla

Commit ea389daa7fd9 ("arm64: cpuidle: add __init section marker to arm_cpuidle_init") added the __init annotation to arm_cpuidle_init as it was not needed after booting which was correct at that time.

However with the introduction of ACPI LPI support, this will be used from cpuhotplug path in ACPI processor driver.

This patch drops the __init annotation from arm_cpuidle_init to avoid the following warning:

WARNING: vmlinux.o(.text+0x113c8): Section mismatch in reference from the
function acpi_processor_ffh_lpi_probe() to the function .init.text:arm_cpuidle_init()
The function acpi_processor_ffh_lpi_probe() references
the function __init arm_cpuidle_init().
This is often because acpi_processor_ffh_lpi_probe lacks a __init annotation or the annotation of arm_cpuidle_init is wrong.

Cc Lorenzo Pieralisi <[email protected]>
Cc Mark Rutland <[email protected]>
---
 arch/arm64/kernel/cpuidle.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/arm64/kernel/cpuidle.c +1 -1
index e11857fce05f..06786fdaadeb 100644
@@ -15,7 +15,7 @@
 #include <asm/cpuidle.h>
 #include <asm/cpu_ops.h>
 
-int __init arm_cpuidle_init(unsigned int cpu)
+int arm_cpuidle_init(unsigned int cpu)
 {
 	int ret = -EOPNOTSUPP;
 
Signature · 1 line
2.7.4
#7 lore raw

PATCH v6 4/5 arm64: add support for ACPI Low Power Idle(LPI)

In reply to Sudeep Holla

This patch adds appropriate callbacks to support ACPI Low Power Idle (LPI) on ARM64.

Now that arm_enter_idle_state is exactly same in both generic ARM{32,64} CPUIdle driver and ARM64 backend for ACPI processor idle driver, we can unify it and move to cpuidle-arm.h header.

Cc Lorenzo Pieralisi <[email protected]>
Cc Mark Rutland <[email protected]>
Cc Daniel Lezcano <[email protected]>
Cc "Rafael J. Wysocki" <[email protected]>
---
 arch/arm64/kernel/cpuidle.c   | 17 +++++++++++++
 drivers/cpuidle/cpuidle-arm.c | 23 ++----------------
 drivers/firmware/psci.c       | 56 +++++++++++++++++++++++++++++++++++++++++++
 include/linux/cpuidle-arm.h   | 30 +++++++++++++++++++++++
 4 files changed, 105 insertions(+), 21 deletions(-)
 create mode 100644 include/linux/cpuidle-arm.h
arch/arm64/kernel/cpuidle.c +17 -0
index 06786fdaadeb..6874d01531ae 100644
@@ -9,6 +9,8 @@
  * published by the Free Software Foundation.
  */
 
+#include <linux/acpi.h>
+#include <linux/cpuidle-arm.h>
 #include <linux/of.h>
 #include <linux/of_device.h>
 
@@ -39,3 +41,18 @@ int arm_cpuidle_suspend(int index)
 
 	return cpu_ops[cpu]->cpu_suspend(index);
 }
+
+#ifdef CONFIG_ACPI
+
+#include <acpi/processor.h>
+
+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 arm_generic_enter_idle_state(lpi->index);
+}
+#endif
drivers/cpuidle/cpuidle-arm.c +2 -21
index e342565e8715..75178ba4a1b2 100644
@@ -12,8 +12,8 @@
 #define pr_fmt(fmt) "CPUidle arm: " fmt
 
 #include <linux/cpuidle.h>
+#include <linux/cpuidle-arm.h>
 #include <linux/cpumask.h>
-#include <linux/cpu_pm.h>
 #include <linux/kernel.h>
 #include <linux/module.h>
 #include <linux/of.h>
@@ -36,26 +36,7 @@
 static int arm_enter_idle_state(struct cpuidle_device *dev,
 				struct cpuidle_driver *drv, int idx)
 {
-	int ret;
-
-	if (!idx) {
-		cpu_do_idle();
-		return idx;
-	}
-
-	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);
-
-		cpu_pm_exit();
-	}
-
-	return ret ? -1 : idx;
+	return arm_generic_enter_idle_state(idx);
 }
 
 static struct cpuidle_driver arm_idle_driver = {
drivers/firmware/psci.c +56 -0

73 lines not on this page · raw message

include/linux/cpuidle-arm.h new file +30 -0
new file mode 100644
index 000000000000..b99bcb3f43dd
@@ -0,0 +1,30 @@
+#include <linux/cpu_pm.h>
+
+#include <asm/cpuidle.h>
+
+/*
+ * arm_enter_idle_state - Programs CPU to enter the specified state
+ */
+static int arm_generic_enter_idle_state(int idx)
+{
+	int ret;
+
+	if (!idx) {
+		cpu_do_idle();
+		return idx;
+	}
+
+	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);
+
+		cpu_pm_exit();
+	}
+
+	return ret ? -1 : idx;
+}
Signature · 1 line
2.7.4
#16 lore raw

PATCH v6 5/5 ACPI : enable ACPI_PROCESSOR_IDLE on ARM64

In reply to Sudeep Holla

Now that ACPI processor idle driver supports LPI(Low Power Idle), lets enable ACPI_PROCESSOR_IDLE for ARM64 too.

This patch just removes the IA64 and X86 dependency on ACPI_PROCESSOR_IDLE

---
 drivers/acpi/Kconfig | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/acpi/Kconfig +1 -1
index 1358fb7d7a68..d74275c0f374 100644
@@ -238,7 +238,7 @@ config ACPI_CPPC_LIB
 config ACPI_PROCESSOR
 	tristate "Processor"
 	depends on X86 || IA64 || ARM64
-	select ACPI_PROCESSOR_IDLE if X86 || IA64
+	select ACPI_PROCESSOR_IDLE
 	select ACPI_CPU_FREQ_PSS if X86 || IA64
 	default y
 	help
Signature · 1 line
2.7.4
#0 lore raw

v6 cover ACPI / processor_idle: Add ACPI v6.0 LPI support

ACPI 6.0 introduced LPI(Low Power Idle) states that provides an alternate method to describe processor idle states. It extends the specification to allow the expression of idle states like C-states selectable by the OSPM when a processor goes idle, but may affect more than one processor, and may affect other system components.

LPI extensions leverages the processor container device(again introduced in ACPI 6.0) allowing to express which parts of the system are affected by a given LPI state. It defines the local power states for each node in a hierarchical processor topology. The OSPM can use _LPI object to select a local power state for each level of processor hierarchy in the system. They used to produce a composite power state request that is presented to the platform by the OSPM.

Since multiple processors affect the idle state for any non-leaf hierarchy node, coordination of idle state requests between the processors is required. ACPI supports two different coordination schemes: Platform coordinated and OS initiated.

This series aims at providing basic and initial support for platform coordinated LPI states.

v5[5]->v6:
- Added support for autopromotable state by not flattening them
- Moved arm_enter_idle_state to cpuidle-arm.h as it can be reused in ARM64 backend for ACPI LPI
- Other review comments(mainly for ARM64 from Lorenzo)
- Dropped support for skipping PM notifier as it needs to be fixed in GICv3 code(will be done separately)

v4[4]->v5:
- Addressed all the comments from Rafael
- Added support for retention mode(Prashant)
- Handled acpi_processor_get_power_info return value correctly(Vikas)
- Dropped __init from arm_cpuidle_init
- Merged psci prepartory patch into arm64 lpi support

v3[3]->v4:
- Dropped the preparatory patches that are merged already
- Added ARM64 arch specific callback implementations
- Addressed most of the review comments from Rafael

v2[2]->v3:
- rebased against v4.4-rc3
- fixed couple of issues reported by Prashanth and review comments from Ashwin

v1[1]->v2[2]:
- Fixed support for ACPI0010 processor container
- moved sleep state code out of processor_idle

Code is also available @[5]

Regards,
Sudeep

[1] http://marc.info/?l=linux-acpi&m=143871041601132&w=2
[2] http://marc.info/?l=linux-acpi&m=144241209800788&w=2
[3] http://marc.info/?l=linux-acpi&m=144906557814813&w=2
[4] http://marc.info/?l=linux-acpi&m=146106902731359&w=2
[5] http://marc.info/?l=linux-acpi&m=146298107608349&w=2
[6] git://git.kernel.org/pub/scm/linux/kernel/git/sudeep.holla/linux.git for_review/arm64_lpi

Sudeep Holla (5):
ACPI / processor_idle: introduce ACPI_PROCESSOR_CSTATE ACPI / processor_idle: Add support for Low Power Idle(LPI) states
arm64: cpuidle: drop __init section marker to arm_cpuidle_init
arm64: add support for ACPI Low Power Idle(LPI)
ACPI : enable ACPI_PROCESSOR_IDLE on ARM64

 arch/arm64/kernel/cpuidle.c     |  19 +-
 drivers/acpi/Kconfig            |   6 +-
 drivers/acpi/bus.c              |  14 +-
 drivers/acpi/processor_driver.c |   2 +-
 drivers/acpi/processor_idle.c   | 545 ++++++++++++++++++++++++++++++++++------
 drivers/cpuidle/cpuidle-arm.c   |  23 +-
 drivers/firmware/psci.c         |  56 +++++
 include/acpi/processor.h        |  26 +-
 include/linux/acpi.h            |   4 +
 include/linux/cpuidle-arm.h     |  30 +++
 10 files changed, 616 insertions(+), 109 deletions(-)
 create mode 100644 include/linux/cpuidle-arm.h
Signature · 1 line
2.7.4
#3 lore raw

Re: [PATCH v6 2/5] ACPI / processor_idle: Add support for Low Power Idle(LPI) states

In reply to Sudeep Holla
Quoted 7 lines · Sudeep Holla

ACPI 6.0 introduced an optional object _LPI that provides an alternate method to describe Low Power Idle states. It defines the local power states for each node in a hierarchical processor topology. The OSPM can use _LPI object to select a local power state for each level of processor hierarchy in the system. They used to produce a composite power state request that is presented to the platform by the OSPM.

Quoted 7 lines

Since multiple processors affect the idle state for any non-leaf hierarchy node, coordination of idle state requests between the processors is required. ACPI supports two different coordination schemes: Platform coordinated and OS initiated.

This patch adds initial support for Platform coordination scheme of LPI.

I seem to have sent a stale version of this patch, will send an updated version of this patch alone. Please ignore this one.

Signature · 2 lines
Regards,
Sudeep
#4 lore raw

PATCH v6 2/5 ACPI / processor_idle: Add support for Low Power Idle(LPI) states

In reply to Sudeep Holla

ACPI 6.0 introduced an optional object _LPI that provides an alternate method to describe Low Power Idle states. It defines the local power states for each node in a hierarchical processor topology. The OSPM can use _LPI object to select a local power state for each level of processor hierarchy in the system. They used to produce a composite power state request that is presented to the platform by the OSPM.

Since multiple processors affect the idle state for any non-leaf hierarchy node, coordination of idle state requests between the processors is required. ACPI supports two different coordination schemes: Platform coordinated and OS initiated.

This patch adds initial support for Platform coordination scheme of LPI.

Cc "Rafael J. Wysocki" <[email protected]>
---
 drivers/acpi/bus.c              |  14 +-
 drivers/acpi/processor_driver.c |   2 +-
 drivers/acpi/processor_idle.c   | 468 +++++++++++++++++++++++++++++++++++-----
 include/acpi/processor.h        |  24 ++-
 include/linux/acpi.h            |   4 +
 5 files changed, 452 insertions(+), 60 deletions(-)
drivers/acpi/bus.c +13 -1
index 262ca31b86d9..80ebb05e387c 100644
@@ -302,6 +302,14 @@ acpi_status acpi_run_osc(acpi_handle handle, struct acpi_osc_context *context)
 EXPORT_SYMBOL(acpi_run_osc);
 
 bool osc_sb_apei_support_acked;
+
+/*
+ * ACPI 6.0 Section 8.4.4.2 Idle State Coordination
+ * OSPM supports platform coordinated low power idle(LPI) states
+ */
+bool osc_pc_lpi_support_confirmed;
+EXPORT_SYMBOL_GPL(osc_pc_lpi_support_confirmed);
+
 static u8 sb_uuid_str[] = "0811B06E-4A27-44F9-8D60-3CBBC22E7B48";
 static void acpi_bus_osc_support(void)
 {
@@ -322,6 +330,7 @@ static void acpi_bus_osc_support(void)
 		capbuf[OSC_SUPPORT_DWORD] |= OSC_SB_PPC_OST_SUPPORT;
 
 	capbuf[OSC_SUPPORT_DWORD] |= OSC_SB_HOTPLUG_OST_SUPPORT;
+	capbuf[OSC_SUPPORT_DWORD] |= OSC_SB_PCLPI_SUPPORT;
 
 	if (!ghes_disable)
 		capbuf[OSC_SUPPORT_DWORD] |= OSC_SB_APEI_SUPPORT;
@@ -329,9 +338,12 @@ static void acpi_bus_osc_support(void)
 		return;
 	if (ACPI_SUCCESS(acpi_run_osc(handle, &context))) {
 		u32 *capbuf_ret = context.ret.pointer;
-		if (context.ret.length > OSC_SUPPORT_DWORD)
+		if (context.ret.length > OSC_SUPPORT_DWORD) {
 			osc_sb_apei_support_acked =
 				capbuf_ret[OSC_SUPPORT_DWORD] & OSC_SB_APEI_SUPPORT;
+			osc_pc_lpi_support_confirmed =
+				capbuf_ret[OSC_SUPPORT_DWORD] & OSC_SB_PCLPI_SUPPORT;
+		}
 		kfree(context.ret.pointer);
 	}
 	/* do we need to check other returned cap? Sounds no */
drivers/acpi/processor_driver.c +1 -1
index d2fa8cb82d2b..0ca14ac7bb28 100644
@@ -90,7 +90,7 @@ static void acpi_processor_notify(acpi_handle handle, u32 event, void *data)
 						  pr->performance_platform_limit);
 		break;
 	case ACPI_PROCESSOR_NOTIFY_POWER:
-		acpi_processor_cst_has_changed(pr);
+		acpi_processor_power_state_has_changed(pr);
 		acpi_bus_generate_netlink_event(device->pnp.device_class,
 						  dev_name(&device->dev), event, 0);
 		break;
drivers/acpi/processor_idle.c +413 -55

564 lines not on this page · raw message

include/acpi/processor.h +21 -3
index 48779d678122..e2dcb0c51554 100644
@@ -39,6 +39,7 @@
 #define ACPI_CSTATE_SYSTEMIO	0
 #define ACPI_CSTATE_FFH		1
 #define ACPI_CSTATE_HALT	2
+#define ACPI_CSTATE_INTEGER	3
 
 #define ACPI_CX_DESC_LEN	32
 
@@ -67,9 +68,25 @@ struct acpi_processor_cx {
 	char desc[ACPI_CX_DESC_LEN];
 };
 
+struct acpi_lpi_state {
+	u32 min_residency;
+	u32 wake_latency; /* worst case */
+	u32 flags;
+	u32 arch_flags;
+	u32 res_cnt_freq;
+	u32 enable_parent_state;
+	u64 address;
+	u8 index;
+	u8 entry_method;
+	char desc[ACPI_CX_DESC_LEN];
+};
+
 struct acpi_processor_power {
 	int count;
-	struct acpi_processor_cx states[ACPI_PROCESSOR_MAX_POWER];
+	union {
+		struct acpi_processor_cx states[ACPI_PROCESSOR_MAX_POWER];
+		struct acpi_lpi_state lpi_states[ACPI_PROCESSOR_MAX_POWER];
+	};
 	int timer_broadcast_on_state;
 };
 
@@ -189,6 +206,7 @@ struct acpi_processor_flags {
 	u8 bm_control:1;
 	u8 bm_check:1;
 	u8 has_cst:1;
+	u8 has_lpi:1;
 	u8 power_setup_done:1;
 	u8 bm_rld_set:1;
 	u8 need_hotplug_init:1;
@@ -371,7 +389,7 @@ extern struct cpuidle_driver acpi_idle_driver;
 #ifdef CONFIG_ACPI_PROCESSOR_IDLE
 int acpi_processor_power_init(struct acpi_processor *pr);
 int acpi_processor_power_exit(struct acpi_processor *pr);
-int acpi_processor_cst_has_changed(struct acpi_processor *pr);
+int acpi_processor_power_state_has_changed(struct acpi_processor *pr);
 int acpi_processor_hotplug(struct acpi_processor *pr);
 #else
 static inline int acpi_processor_power_init(struct acpi_processor *pr)
@@ -384,7 +402,7 @@ static inline int acpi_processor_power_exit(struct acpi_processor *pr)
 	return -ENODEV;
 }
 
-static inline int acpi_processor_cst_has_changed(struct acpi_processor *pr)
+static inline int acpi_processor_power_state_has_changed(struct acpi_processor *pr)
 {
 	return -ENODEV;
 }
include/linux/acpi.h +4 -0
index 288fac5294f5..65754566ae17 100644
@@ -444,8 +444,12 @@ acpi_status acpi_run_osc(acpi_handle handle, struct acpi_osc_context *context);
 #define OSC_SB_HOTPLUG_OST_SUPPORT		0x00000008
 #define OSC_SB_APEI_SUPPORT			0x00000010
 #define OSC_SB_CPC_SUPPORT			0x00000020
+#define OSC_SB_CPCV2_SUPPORT			0x00000040
+#define OSC_SB_PCLPI_SUPPORT			0x00000080
+#define OSC_SB_OSLPI_SUPPORT			0x00000100
 
 extern bool osc_sb_apei_support_acked;
+extern bool osc_pc_lpi_support_confirmed;
 
 /* PCI Host Bridge _OSC: Capabilities DWORD 2: Support Field */
 #define OSC_PCI_EXT_CONFIG_SUPPORT		0x00000001
Signature · 1 line
2.7.4
#8 lore raw

Re: [PATCH v6 4/5] arm64: add support for ACPI Low Power Idle(LPI)

In reply to Sudeep Holla

Hi Sudeep,

Quoted 13 lines · Sudeep Holla

This patch adds appropriate callbacks to support ACPI Low Power Idle (LPI) on ARM64.

Now that arm_enter_idle_state is exactly same in both generic ARM{32,64} CPUIdle driver and ARM64 backend for ACPI processor idle driver, we can unify it and move to cpuidle-arm.h header.

Cc Lorenzo Pieralisi <[email protected]>
Cc Mark Rutland <[email protected]>
Cc Daniel Lezcano <[email protected]>
Cc "Rafael J. Wysocki" <[email protected]>
Quoted 7 lines
---
 arch/arm64/kernel/cpuidle.c   | 17 +++++++++++++
 drivers/cpuidle/cpuidle-arm.c | 23 ++----------------
 drivers/firmware/psci.c       | 56 +++++++++++++++++++++++++++++++++++++++++++
 include/linux/cpuidle-arm.h   | 30 +++++++++++++++++++++++
 4 files changed, 105 insertions(+), 21 deletions(-)
 create mode 100644 include/linux/cpuidle-arm.h

This patch seems fine by me, it would be good if Daniel can have a look too.

Some minor comments below.

[...]

Quoted 50 lines
drivers/firmware/psci.c +35 -0
index 03e04582791c..c6caa863d156 100644
@@ -13,6 +13,7 @@
 
 #define pr_fmt(fmt) "psci: " fmt
 
+#include <linux/acpi.h>
 #include <linux/arm-smccc.h>
 #include <linux/cpuidle.h>
 #include <linux/errno.h>
@@ -310,11 +311,66 @@ static int psci_dt_cpu_init_idle(struct device_node *cpu_node, int cpu)
 	return ret;
 }
 
+#ifdef CONFIG_ACPI
+#include <acpi/processor.h>
+
+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))
+		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 <= 0)
+		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];
+		state = lpi->address & 0xFFFFFFFF;

drivers/firmware/psci.c static int psci_dt_cpu_init_idle(struct device_node *cpu_node, int cpu) · line 357

Quoted 10 lines
drivers/firmware/psci.c +10 -0
+		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;

Most of the code in this function is FW independent, it would be nice to factor it out and add the respective ACPI/DT helper functions to retrieve idle states count and parameters, we can update it later anyway it is fine by me to leave it as it is.

include/linux/cpuidle-arm.h

Quoted 24 lines
drivers/firmware/psci.c +11 -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;
include/linux/cpuidle-arm.h new file +0 -0
new file mode 100644
index 000000000000..b99bcb3f43dd

arm-cpuidle.h for consistency with other (ARM) include/linux files ?

Quoted 21 lines
include/linux/cpuidle-arm.h new file +20 -0
@@ -0,0 +1,30 @@
+#include <linux/cpu_pm.h>
+
+#include <asm/cpuidle.h>
+
+/*
+ * arm_enter_idle_state - Programs CPU to enter the specified state
+ */
+static int arm_generic_enter_idle_state(int idx)
+{
+	int ret;
+
+	if (!idx) {
+		cpu_do_idle();
+		return idx;
+	}
+
+	ret = cpu_pm_enter();
+	if (!ret) {
+		/*
+		 * Pass idle state index to cpu_suspend which in turn will

include/linux/cpuidle-arm.h line 30

Quoted 10 lines
include/linux/cpuidle-arm.h new file +10 -0
+		 * call the CPU ops suspend protocol with idle index as a
+		 * parameter.
+		 */
+		ret = arm_cpuidle_suspend(idx);
+
+		cpu_pm_exit();
+	}
+
+	return ret ? -1 : idx;
+}

Either you do this, or we have to add it somehow somewhere in drivers/cpuidle to avoid duplicating it.

@Daniel: do you have an opinion on this please ?

Thanks,
Lorenzo

Acked-by on v6 3/5
#6 lore raw

Re: [PATCH v6 3/5] arm64: cpuidle: drop __init section marker to arm_cpuidle_init

In reply to Sudeep Holla
Quoted 18 lines · Sudeep Holla

Commit ea389daa7fd9 ("arm64: cpuidle: add __init section marker to arm_cpuidle_init") added the __init annotation to arm_cpuidle_init as it was not needed after booting which was correct at that time.

However with the introduction of ACPI LPI support, this will be used from cpuhotplug path in ACPI processor driver.

This patch drops the __init annotation from arm_cpuidle_init to avoid the following warning:

WARNING: vmlinux.o(.text+0x113c8): Section mismatch in reference from the
function acpi_processor_ffh_lpi_probe() to the function .init.text:arm_cpuidle_init()
The function acpi_processor_ffh_lpi_probe() references
the function __init arm_cpuidle_init().
This is often because acpi_processor_ffh_lpi_probe lacks a __init annotation or the annotation of arm_cpuidle_init is wrong.

Quoted 4 lines
Cc Lorenzo Pieralisi <[email protected]>
Cc Mark Rutland <[email protected]>

Depending on acceptance of other patches in this series:

Quoted 20 lines
---
 arch/arm64/kernel/cpuidle.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/arm64/kernel/cpuidle.c +1 -1
index e11857fce05f..06786fdaadeb 100644
@@ -15,7 +15,7 @@
 #include <asm/cpuidle.h>
 #include <asm/cpu_ops.h>
 
-int __init arm_cpuidle_init(unsigned int cpu)
+int arm_cpuidle_init(unsigned int cpu)
 {
 	int ret = -EOPNOTSUPP;
 
Signature · 1 line
2.7.4
#24 lore raw
In reply to Sudeep Holla

Hi Rafael,

Quoted 14 lines · Sudeep Holla

ACPI 6.0 introduced LPI(Low Power Idle) states that provides an alternate method to describe processor idle states. It extends the specification to allow the expression of idle states like C-states selectable by the OSPM when a processor goes idle, but may affect more than one processor, and may affect other system components.

LPI extensions leverages the processor container device(again introduced in ACPI 6.0) allowing to express which parts of the system are affected by a given LPI state. It defines the local power states for each node in a hierarchical processor topology. The OSPM can use _LPI object to select a local power state for each level of processor hierarchy in the system. They used to produce a composite power state request that is presented to the platform by the OSPM.

Quoted 8 lines

Since multiple processors affect the idle state for any non-leaf hierarchy node, coordination of idle state requests between the processors is required. ACPI supports two different coordination schemes: Platform coordinated and OS initiated.

This series aims at providing basic and initial support for platform coordinated LPI states.

Gentle ping, was hoping to target this series for v4.8

Signature · 2 lines
Regards,
Sudeep
#25 lore raw
Quoted 22 lines · Sudeep Holla

Hi Rafael,

Quoted 19 lines · Sudeep Holla

ACPI 6.0 introduced LPI(Low Power Idle) states that provides an alternate method to describe processor idle states. It extends the specification to allow the expression of idle states like C-states selectable by the OSPM when a processor goes idle, but may affect more than one processor, and may affect other system components.

LPI extensions leverages the processor container device(again introduced in ACPI 6.0) allowing to express which parts of the system are affected by a given LPI state. It defines the local power states for each node in a hierarchical processor topology. The OSPM can use _LPI object to select a local power state for each level of processor hierarchy in the system. They used to produce a composite power state request that is presented to the platform by the OSPM.

Since multiple processors affect the idle state for any non-leaf hierarchy node, coordination of idle state requests between the processors is required. ACPI supports two different coordination schemes: Platform coordinated and OS initiated.

Quoted 5 lines
Quoted 3 lines

This series aims at providing basic and initial support for platform coordinated LPI states.

Gentle ping, was hoping to target this series for v4.8

On my list of things to take care of this week. But this is a long list ...

Thanks,
Rafael

#9 lore raw

Re: [PATCH v6 4/5] arm64: add support for ACPI Low Power Idle(LPI)

In reply to Lorenzo Pieralisi
Quoted 73 lines · Lorenzo Pieralisi

Hi Sudeep,

Quoted 13 lines · Sudeep Holla

This patch adds appropriate callbacks to support ACPI Low Power Idle (LPI) on ARM64.

Now that arm_enter_idle_state is exactly same in both generic ARM{32,64} CPUIdle driver and ARM64 backend for ACPI processor idle driver, we can unify it and move to cpuidle-arm.h header.

Cc Lorenzo Pieralisi <[email protected]>
Cc Mark Rutland <[email protected]>
Cc Daniel Lezcano <[email protected]>
Cc "Rafael J. Wysocki" <[email protected]>
Cc linux-arm-kernel at lists.infradead.org
Quoted 7 lines
---
  arch/arm64/kernel/cpuidle.c   | 17 +++++++++++++
  drivers/cpuidle/cpuidle-arm.c | 23 ++----------------
  drivers/firmware/psci.c       | 56 +++++++++++++++++++++++++++++++++++++++++++
  include/linux/cpuidle-arm.h   | 30 +++++++++++++++++++++++
  4 files changed, 105 insertions(+), 21 deletions(-)

create mode 100644 include/linux/cpuidle-arm.h

This patch seems fine by me, it would be good if Daniel can have a look too.

Some minor comments below.

[...]

Quoted 42 lines
drivers/firmware/psci.c +27 -0
index 03e04582791c..c6caa863d156 100644
@@ -13,6 +13,7 @@
 
  #define pr_fmt(fmt) "psci: " fmt
 
+#include <linux/acpi.h>
  #include <linux/arm-smccc.h>
  #include <linux/cpuidle.h>
  #include <linux/errno.h>
@@ -310,11 +311,66 @@ static int psci_dt_cpu_init_idle(struct device_node *cpu_node, int cpu)
  	return ret;
  }
 
+#ifdef CONFIG_ACPI
+#include <acpi/processor.h>
+
+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))
+		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 <= 0)
+		return -ENODEV;
+
+	psci_states = kcalloc(count, sizeof(*psci_states), GFP_KERNEL);
Quoted 8 lines

drivers/firmware/psci.c static int psci_dt_cpu_init_idle(struct device_node *cpu_node, int cpu) · line 347

Quoted 8 lines
drivers/firmware/psci.c +8 -0
+	if (!psci_states)
+		return -ENOMEM;
+
+	for (i = 0; i < count; i++) {
+		u32 state;
+
+		lpi = &pr->power.lpi_states[i + 1];
+		state = lpi->address & 0xFFFFFFFF;

Why is needed to mask 'address' ?

Quoted 29 lines

drivers/firmware/psci.c static int psci_dt_cpu_init_idle(struct device_node *cpu_node, int cpu) · line 357

Quoted 10 lines
drivers/firmware/psci.c +10 -0
+		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;

Most of the code in this function is FW independent, it would be nice to factor it out and add the respective ACPI/DT helper functions to retrieve idle states count and parameters, we can update it later anyway it is fine by me to leave it as it is.

Quoted 13 lines
drivers/firmware/psci.c +8 -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;
 
Quoted 2 lines

drivers/firmware/psci.c static int psci_dt_cpu_init_idle(struct device_node *cpu_node, int cpu) · line 372

Quoted 2 lines
drivers/firmware/psci.c +2 -0
+	if (!acpi_disabled)
+		return psci_acpi_cpu_init_idle(cpu);

Is it possible the case where there is information in both the DT and in ACPI ? So ACPI is enabled without idle information which is in the DT ?

Quoted 46 lines

include/linux/cpuidle-arm.h

Quoted 8 lines
drivers/firmware/psci.c +0 -0
  	cpu_node = of_get_cpu_node(cpu, NULL);
  	if (!cpu_node)
  		return -ENODEV;
include/linux/cpuidle-arm.h new file +0 -0
new file mode 100644
index 000000000000..b99bcb3f43dd

arm-cpuidle.h for consistency with other (ARM) include/linux files ?

Quoted 21 lines
include/linux/cpuidle-arm.h new file +20 -0
@@ -0,0 +1,30 @@
+#include <linux/cpu_pm.h>
+
+#include <asm/cpuidle.h>
+
+/*
+ * arm_enter_idle_state - Programs CPU to enter the specified state
+ */
+static int arm_generic_enter_idle_state(int idx)
+{
+	int ret;
+
+	if (!idx) {
+		cpu_do_idle();
+		return idx;
+	}
+
+	ret = cpu_pm_enter();
+	if (!ret) {
+		/*
+		 * Pass idle state index to cpu_suspend which in turn will

include/linux/cpuidle-arm.h line 30

Quoted 10 lines
include/linux/cpuidle-arm.h new file +10 -0
+		 * call the CPU ops suspend protocol with idle index as a
+		 * parameter.
+		 */
+		ret = arm_cpuidle_suspend(idx);
+
+		cpu_pm_exit();
+	}
+
+	return ret ? -1 : idx;
+}

Either you do this, or we have to add it somehow somewhere in drivers/cpuidle to avoid duplicating it.

Quoted 1 line

@Daniel: do you have an opinion on this please ?

Yes, this function should be added to avoid duplication.

-- Daniel

Signature · 5 lines
  <http://www.linaro.org/> Linaro.org ? Open source software for ARM SoCs

Follow Linaro:  <http://www.facebook.com/pages/Linaro> Facebook |
<http://twitter.com/#!/linaroorg> Twitter |
<http://www.linaro.org/linaro-blog/> Blog
#10 lore raw

Re: [PATCH v6 4/5] arm64: add support for ACPI Low Power Idle(LPI)

Quoted 114 lines · Daniel Lezcano
Quoted 73 lines · Lorenzo Pieralisi

Hi Sudeep,

Quoted 13 lines · Sudeep Holla

This patch adds appropriate callbacks to support ACPI Low Power Idle (LPI) on ARM64.

Now that arm_enter_idle_state is exactly same in both generic ARM{32,64} CPUIdle driver and ARM64 backend for ACPI processor idle driver, we can unify it and move to cpuidle-arm.h header.

Cc Lorenzo Pieralisi <[email protected]>
Cc Mark Rutland <[email protected]>
Cc Daniel Lezcano <[email protected]>
Cc "Rafael J. Wysocki" <[email protected]>
Quoted 7 lines
---
  arch/arm64/kernel/cpuidle.c   | 17 +++++++++++++
  drivers/cpuidle/cpuidle-arm.c | 23 ++----------------
  drivers/firmware/psci.c       | 56 +++++++++++++++++++++++++++++++++++++++++++
  include/linux/cpuidle-arm.h   | 30 +++++++++++++++++++++++
  4 files changed, 105 insertions(+), 21 deletions(-)

create mode 100644 include/linux/cpuidle-arm.h

This patch seems fine by me, it would be good if Daniel can have a look too.

Some minor comments below.

[...]

Quoted 42 lines
drivers/firmware/psci.c +27 -0
index 03e04582791c..c6caa863d156 100644
@@ -13,6 +13,7 @@
 
  #define pr_fmt(fmt) "psci: " fmt
 
+#include <linux/acpi.h>
  #include <linux/arm-smccc.h>
  #include <linux/cpuidle.h>
  #include <linux/errno.h>
@@ -310,11 +311,66 @@ static int psci_dt_cpu_init_idle(struct device_node *cpu_node, int cpu)
  	return ret;
  }
 
+#ifdef CONFIG_ACPI
+#include <acpi/processor.h>
+
+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))
+		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 <= 0)
+		return -ENODEV;
+
+	psci_states = kcalloc(count, sizeof(*psci_states), GFP_KERNEL);
Quoted 8 lines

drivers/firmware/psci.c static int psci_dt_cpu_init_idle(struct device_node *cpu_node, int cpu) · line 347

Quoted 8 lines
drivers/firmware/psci.c +8 -0
+	if (!psci_states)
+		return -ENOMEM;
+
+	for (i = 0; i < count; i++) {
+		u32 state;
+
+		lpi = &pr->power.lpi_states[i + 1];
+		state = lpi->address & 0xFFFFFFFF;

Why is needed to mask 'address' ?

Quoted 29 lines

drivers/firmware/psci.c static int psci_dt_cpu_init_idle(struct device_node *cpu_node, int cpu) · line 357

Quoted 10 lines
drivers/firmware/psci.c +10 -0
+		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;

Most of the code in this function is FW independent, it would be nice to factor it out and add the respective ACPI/DT helper functions to retrieve idle states count and parameters, we can update it later anyway it is fine by me to leave it as it is.

Quoted 13 lines
drivers/firmware/psci.c +8 -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;
 
Quoted 5 lines
Quoted 2 lines

drivers/firmware/psci.c static int psci_dt_cpu_init_idle(struct device_node *cpu_node, int cpu) · line 372

Quoted 2 lines
drivers/firmware/psci.c +2 -0
+	if (!acpi_disabled)
+		return psci_acpi_cpu_init_idle(cpu);

Is it possible the case where there is information in both the DT and in ACPI ?

No, it isn't.

It is either-or, never both at the same time.

Thanks,
Rafael

#26 lore raw
In reply to Rafael J. Wysocki
Quoted 23 lines · Rafael J. Wysocki
Quoted 22 lines · Sudeep Holla

Hi Rafael,

Quoted 19 lines · Sudeep Holla

ACPI 6.0 introduced LPI(Low Power Idle) states that provides an alternate method to describe processor idle states. It extends the specification to allow the expression of idle states like C-states selectable by the OSPM when a processor goes idle, but may affect more than one processor, and may affect other system components.

LPI extensions leverages the processor container device(again introduced in ACPI 6.0) allowing to express which parts of the system are affected by a given LPI state. It defines the local power states for each node in a hierarchical processor topology. The OSPM can use _LPI object to select a local power state for each level of processor hierarchy in the system. They used to produce a composite power state request that is presented to the platform by the OSPM.

Since multiple processors affect the idle state for any non-leaf hierarchy node, coordination of idle state requests between the processors is required. ACPI supports two different coordination schemes: Platform coordinated and OS initiated.

Quoted 7 lines
Quoted 5 lines
Quoted 3 lines

This series aims at providing basic and initial support for platform coordinated LPI states.

Gentle ping, was hoping to target this series for v4.8

On my list of things to take care of this week. But this is a long list ...

Well, there are comments from Lorenzo and Daniel that need addressing, so can you please do that and resend?

Thanks,
Rafael

#11 lore raw

Re: [PATCH v6 4/5] arm64: add support for ACPI Low Power Idle(LPI)

In reply to Rafael J. Wysocki

On 06/25/2016 12:47 AM, Rafael J. Wysocki wrote:

[ ... ]

Quoted 9 lines
Quoted 5 lines
Quoted 2 lines

drivers/firmware/psci.c static int psci_dt_cpu_init_idle(struct device_node *cpu_node, int cpu) · line 372

Quoted 2 lines
drivers/firmware/psci.c +2 -0
+	if (!acpi_disabled)
+		return psci_acpi_cpu_init_idle(cpu);

Is it possible the case where there is information in both the DT and in ACPI ?

No, it isn't.

It is either-or, never both at the same time.

Ok, thanks for the clarification.

-- Daniel

Signature · 5 lines
 <http://www.linaro.org/> Linaro.org │ Open source software for ARM SoCs

Follow Linaro:  <http://www.facebook.com/pages/Linaro> Facebook |
<http://twitter.com/#!/linaroorg> Twitter |
<http://www.linaro.org/linaro-blog/> Blog
#12 lore raw

Re: [PATCH v6 4/5] arm64: add support for ACPI Low Power Idle(LPI)

In reply to Daniel Lezcano

Hi, Daniel,

On 24/06/16 22:04, Daniel Lezcano wrote:

[...]

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
drivers/firmware/psci.c +4 -0
+
+    psci_states = kcalloc(count, sizeof(*psci_states), GFP_KERNEL);
+    if (!psci_states)
+        return -ENOMEM;
Quoted 9 lines
Quoted 6 lines

drivers/firmware/psci.c static int psci_dt_cpu_init_idle(struct device_node *cpu_node, int cpu) · line 347

Quoted 6 lines
drivers/firmware/psci.c +6 -0
+
+    for (i = 0; i < count; i++) {
+        u32 state;
+
+        lpi = &pr->power.lpi_states[i + 1];
+        state = lpi->address & 0xFFFFFFFF;

Why is needed to mask 'address' ?

This is as per Section 3.1.1 FFH Usage in LPI state entry methods in [1]

[...]

Quoted 11 lines
Quoted 7 lines

drivers/firmware/psci.c static int psci_dt_cpu_init_idle(struct device_node *cpu_node, int cpu) · line 372

Quoted 7 lines
  int psci_cpu_init_idle(unsigned int cpu)
  {
      struct device_node *cpu_node;
      int ret;
drivers/firmware/psci.c +2 -0
+    if (!acpi_disabled)
+        return psci_acpi_cpu_init_idle(cpu);

Is it possible the case where there is information in both the DT and in ACPI ? So ACPI is enabled without idle information which is in the DT ?

No, as Rafael mentioned aready.

Quoted 8 lines
Quoted 5 lines

Either you do this, or we have to add it somehow somewhere in drivers/cpuidle to avoid duplicating it.

@Daniel: do you have an opinion on this please ?

Yes, this function should be added to avoid duplication.

So, I assume you are happy with the way it's handled in this patch ? (I will rename the file as suggested by Lorenzo)

Signature · 5 lines
Regards,
Sudeep

[1] 
http://infocenter.arm.com/help/topic/com.arm.doc.den0048a/DEN0048A_ARM_FFH_Specification.pdf
#17 lore raw

Re: [PATCH v6 5/5] ACPI : enable ACPI_PROCESSOR_IDLE on ARM64

In reply to Sudeep Holla
Quoted 9 lines · Sudeep Holla

Now that ACPI processor idle driver supports LPI(Low Power Idle), lets enable ACPI_PROCESSOR_IDLE for ARM64 too.

This patch just removes the IA64 and X86 dependency on ACPI_PROCESSOR_IDLE

Cc linux-arm-kernel at lists.infradead.org
Cc "Rafael J. Wysocki" <[email protected]>

---

Hi Sudeep,

now that ACPI processor supports ARM64 did you check the CPUIDLE_DRIVER_STATE_START trick in the code and its derivative ?

I deleted the patch 2/5 but there is a place where:

if (max_cstate=0)

	max_cstate=1;

Probably this is because the POLL state is inserted, so there is always an idle state. But for ARM, that is not the case.

Also, there are some places where the idle state index begins to 1. I think it should be 0 for ARM.

Quoted 17 lines
  drivers/acpi/Kconfig | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
drivers/acpi/Kconfig +1 -1
index 1358fb7d7a68..d74275c0f374 100644
@@ -238,7 +238,7 @@ config ACPI_CPPC_LIB
  config ACPI_PROCESSOR
  	tristate "Processor"
  	depends on X86 || IA64 || ARM64
-	select ACPI_PROCESSOR_IDLE if X86 || IA64
+	select ACPI_PROCESSOR_IDLE
  	select ACPI_CPU_FREQ_PSS if X86 || IA64
  	default y
  	help
Signature · 5 lines
  <http://www.linaro.org/> Linaro.org ? Open source software for ARM SoCs

Follow Linaro:  <http://www.facebook.com/pages/Linaro> Facebook |
<http://twitter.com/#!/linaroorg> Twitter |
<http://www.linaro.org/linaro-blog/> Blog
#18 lore raw

Re: [PATCH v6 5/5] ACPI : enable ACPI_PROCESSOR_IDLE on ARM64

Hi Daniel,

Quoted 12 lines · Daniel Lezcano
Quoted 10 lines · Sudeep Holla

Now that ACPI processor idle driver supports LPI(Low Power Idle), lets enable ACPI_PROCESSOR_IDLE for ARM64 too.

This patch just removes the IA64 and X86 dependency on ACPI_PROCESSOR_IDLE

Cc linux-arm-kernel at lists.infradead.org
Cc "Rafael J. Wysocki" <[email protected]>

---

Quoted 5 lines

Hi Sudeep,

now that ACPI processor supports ARM64 did you check the CPUIDLE_DRIVER_STATE_START trick in the code and its derivative ?

No, that is used only for C-State and ARM64 doesn't support it. Patch 1/5 puts all the C-State code under #ifdef so that it's not compiled on ARM64.

Quoted 2 lines

I deleted the patch 2/5 but there is a place where:

Sorry, I don't follow what you mean by that.

Quoted 6 lines

if (max_cstate=0)

     max_cstate=1;

Probably this is because the POLL state is inserted, so there is always an idle state. But for ARM, that is not the case.

Yes

Quoted 3 lines

Also, there are some places where the idle state index begins to 1. I think it should be 0 for ARM.

Yes for LPI, it does start from 0.

Signature · 2 lines
Regards,
Sudeep
#19 lore raw

Re: [PATCH v6 5/5] ACPI : enable ACPI_PROCESSOR_IDLE on ARM64

Quoted 21 lines · Sudeep Holla

Hi Daniel,

Quoted 12 lines · Daniel Lezcano
Quoted 10 lines · Sudeep Holla

Now that ACPI processor idle driver supports LPI(Low Power Idle), lets enable ACPI_PROCESSOR_IDLE for ARM64 too.

This patch just removes the IA64 and X86 dependency on ACPI_PROCESSOR_IDLE

Cc linux-arm-kernel at lists.infradead.org
Cc "Rafael J. Wysocki" <[email protected]>

---

Quoted 5 lines

Hi Sudeep,

now that ACPI processor supports ARM64 did you check the CPUIDLE_DRIVER_STATE_START trick in the code and its derivative ?

Quoted 8 lines

No, that is used only for C-State and ARM64 doesn't support it. Patch 1/5 puts all the C-State code under #ifdef so that it's not compiled on ARM64.

Quoted 2 lines

I deleted the patch 2/5 but there is a place where:

Sorry, I don't follow what you mean by that.

I meant I just deleted from my mailbox the patch 2/5, so I can't do inline comment.

Quoted 15 lines
Quoted 6 lines

if (max_cstate=0)

     max_cstate=1;

Probably this is because the POLL state is inserted, so there is always an idle state. But for ARM, that is not the case.

Yes

Quoted 3 lines

Also, there are some places where the idle state index begins to 1. I think it should be 0 for ARM.

Yes for LPI, it does start from 0.

Signature · 5 lines
  <http://www.linaro.org/> Linaro.org ? Open source software for ARM SoCs

Follow Linaro:  <http://www.facebook.com/pages/Linaro> Facebook |
<http://twitter.com/#!/linaroorg> Twitter |
<http://www.linaro.org/linaro-blog/> Blog
#20 lore raw

Re: [PATCH v6 5/5] ACPI : enable ACPI_PROCESSOR_IDLE on ARM64

Quoted 26 lines · Daniel Lezcano
Quoted 25 lines · Sudeep Holla

Hi Daniel,

Quoted 12 lines · Daniel Lezcano
Quoted 10 lines · Sudeep Holla

Now that ACPI processor idle driver supports LPI(Low Power Idle), lets enable ACPI_PROCESSOR_IDLE for ARM64 too.

This patch just removes the IA64 and X86 dependency on ACPI_PROCESSOR_IDLE

Cc linux-arm-kernel at lists.infradead.org
Cc "Rafael J. Wysocki" <[email protected]>

---

Quoted 5 lines

Hi Sudeep,

now that ACPI processor supports ARM64 did you check the CPUIDLE_DRIVER_STATE_START trick in the code and its derivative ?

No, that is used only for C-State and ARM64 doesn't support it. Patch 1/5 puts all the C-State code under #ifdef so that it's not compiled on ARM64.

Quoted 8 lines
Quoted 4 lines
Quoted 2 lines

I deleted the patch 2/5 but there is a place where:

Sorry, I don't follow what you mean by that.

I meant I just deleted from my mailbox the patch 2/5, so I can't do inline comment.

Ah ok, anyways LPI always starts from index 0. IIUC that was your main concern.

Signature · 2 lines
Regards,
Sudeep
#21 lore raw

Re: [PATCH v6 5/5] ACPI : enable ACPI_PROCESSOR_IDLE on ARM64

Quoted 32 lines · Sudeep Holla
Quoted 29 lines · Daniel Lezcano
Quoted 28 lines · Sudeep Holla

Hi Daniel,

Quoted 12 lines · Daniel Lezcano
Quoted 10 lines · Sudeep Holla

Now that ACPI processor idle driver supports LPI(Low Power Idle), lets enable ACPI_PROCESSOR_IDLE for ARM64 too.

This patch just removes the IA64 and X86 dependency on ACPI_PROCESSOR_IDLE

Cc linux-arm-kernel at lists.infradead.org
Cc "Rafael J. Wysocki" <[email protected]>

---

Quoted 5 lines

Hi Sudeep,

now that ACPI processor supports ARM64 did you check the CPUIDLE_DRIVER_STATE_START trick in the code and its derivative ?

No, that is used only for C-State and ARM64 doesn't support it. Patch 1/5 puts all the C-State code under #ifdef so that it's not compiled on ARM64.

Quoted 2 lines

I deleted the patch 2/5 but there is a place where:

Quoted 8 lines
Quoted 5 lines
Quoted 1 line

Sorry, I don't follow what you mean by that.

I meant I just deleted from my mailbox the patch 2/5, so I can't do inline comment.

Ah ok, anyways LPI always starts from index 0. IIUC that was your main concern.

Do you have a repo where I can see the code ?

#22 lore raw

Re: [PATCH v6 5/5] ACPI : enable ACPI_PROCESSOR_IDLE on ARM64

Quoted 1 line · Daniel Lezcano

On 06/27/2016 05:06 PM, Sudeep Holla wrote:

[...]

Quoted 5 lines
Quoted 2 lines

Ah ok, anyways LPI always starts from index 0. IIUC that was your main concern.

Do you have a repo where I can see the code ?

Yes, you can get it from [1]

--
Regards,
Sudeep

[1] http://git.kernel.org/sudeep.holla/linux/h/for_review/arm64_lpi

#23 lore raw

Re: [PATCH v6 5/5] ACPI : enable ACPI_PROCESSOR_IDLE on ARM64

Quoted 7 lines · Sudeep Holla
Quoted 1 line · Daniel Lezcano

On 06/27/2016 05:06 PM, Sudeep Holla wrote:

[...]

Quoted 7 lines
Quoted 5 lines
Quoted 2 lines

Ah ok, anyways LPI always starts from index 0. IIUC that was your main concern.

Do you have a repo where I can see the code ?

Yes, you can get it from [1]

Great. Thanks Sudeep !

Quoted 4 lines

Regards,
Sudeep

[1] http://git.kernel.org/sudeep.holla/linux/h/for_review/arm64_lpi

Signature · 5 lines
  <http://www.linaro.org/> Linaro.org ? Open source software for ARM SoCs

Follow Linaro:  <http://www.facebook.com/pages/Linaro> Facebook |
<http://twitter.com/#!/linaroorg> Twitter |
<http://www.linaro.org/linaro-blog/> Blog
#13 lore raw

Re: [PATCH v6 4/5] arm64: add support for ACPI Low Power Idle(LPI)

In reply to Lorenzo Pieralisi
Quoted 73 lines · Lorenzo Pieralisi

Hi Sudeep,

Quoted 13 lines · Sudeep Holla

This patch adds appropriate callbacks to support ACPI Low Power Idle (LPI) on ARM64.

Now that arm_enter_idle_state is exactly same in both generic ARM{32,64} CPUIdle driver and ARM64 backend for ACPI processor idle driver, we can unify it and move to cpuidle-arm.h header.

Cc Lorenzo Pieralisi <[email protected]>
Cc Mark Rutland <[email protected]>
Cc Daniel Lezcano <[email protected]>
Cc "Rafael J. Wysocki" <[email protected]>
Cc linux-arm-kernel at lists.infradead.org
Quoted 7 lines
---
  arch/arm64/kernel/cpuidle.c   | 17 +++++++++++++
  drivers/cpuidle/cpuidle-arm.c | 23 ++----------------
  drivers/firmware/psci.c       | 56 +++++++++++++++++++++++++++++++++++++++++++
  include/linux/cpuidle-arm.h   | 30 +++++++++++++++++++++++
  4 files changed, 105 insertions(+), 21 deletions(-)

create mode 100644 include/linux/cpuidle-arm.h

This patch seems fine by me, it would be good if Daniel can have a look too.

Some minor comments below.

[...]

Quoted 42 lines
drivers/firmware/psci.c +27 -0
index 03e04582791c..c6caa863d156 100644
@@ -13,6 +13,7 @@
 
  #define pr_fmt(fmt) "psci: " fmt
 
+#include <linux/acpi.h>
  #include <linux/arm-smccc.h>
  #include <linux/cpuidle.h>
  #include <linux/errno.h>
@@ -310,11 +311,66 @@ static int psci_dt_cpu_init_idle(struct device_node *cpu_node, int cpu)
  	return ret;
  }
 
+#ifdef CONFIG_ACPI
+#include <acpi/processor.h>
+
+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))
+		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 <= 0)
+		return -ENODEV;
+
+	psci_states = kcalloc(count, sizeof(*psci_states), GFP_KERNEL);
Quoted 8 lines

drivers/firmware/psci.c static int psci_dt_cpu_init_idle(struct device_node *cpu_node, int cpu) · line 347

Quoted 8 lines
drivers/firmware/psci.c +8 -0
+	if (!psci_states)
+		return -ENOMEM;
+
+	for (i = 0; i < count; i++) {
+		u32 state;
+
+		lpi = &pr->power.lpi_states[i + 1];
+		state = lpi->address & 0xFFFFFFFF;

Why mask 'address' if 'state' is u32 ?

Quoted 10 lines

drivers/firmware/psci.c static int psci_dt_cpu_init_idle(struct device_node *cpu_node, int cpu) · line 357

Quoted 10 lines
drivers/firmware/psci.c +10 -0
+		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;

The ACPI and the PSCI code are not self contained here.

It would be nice to move this function to the ACPI code.

Quoted 13 lines
Quoted 13 lines
drivers/firmware/psci.c +8 -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;
 
Quoted 3 lines

drivers/firmware/psci.c static int psci_dt_cpu_init_idle(struct device_node *cpu_node, int cpu) · line 373

Quoted 3 lines
drivers/firmware/psci.c +3 -0
+	if (!acpi_disabled)
+		return psci_acpi_cpu_init_idle(cpu);
+

acpi_disabled - acpi_disabled - acpi_disabled everywhere :/

The enable-method approach is not straightforward and now it is polluted by acpi-disabled.

So IIUC,

smp_init_cpus (contains acpi_disabled)
smp_cpu_setup
cpu_read_ops
cpu_read_enable_method (contains acpi_disabled)
acpi_get_enable_method (returns 'psci' after checking
psci_is_present)

Then psci_cpu_init_idle is called... and check again acpi_disabled.

IMO, the circumlocution with the psci vs acpi vs acpi_disabled is getting unnecessary too complex, is prone to error and will lead to unmaintainable code very soon.

I suggest to sort out encapsulation and self-contained code before adding more feature in this area.

Quoted 46 lines

include/linux/cpuidle-arm.h

Quoted 8 lines
drivers/firmware/psci.c +0 -0
  	cpu_node = of_get_cpu_node(cpu, NULL);
  	if (!cpu_node)
  		return -ENODEV;
include/linux/cpuidle-arm.h new file +0 -0
new file mode 100644
index 000000000000..b99bcb3f43dd

arm-cpuidle.h for consistency with other (ARM) include/linux files ?

Quoted 21 lines
include/linux/cpuidle-arm.h new file +20 -0
@@ -0,0 +1,30 @@
+#include <linux/cpu_pm.h>
+
+#include <asm/cpuidle.h>
+
+/*
+ * arm_enter_idle_state - Programs CPU to enter the specified state
+ */
+static int arm_generic_enter_idle_state(int idx)
+{
+	int ret;
+
+	if (!idx) {
+		cpu_do_idle();
+		return idx;
+	}
+
+	ret = cpu_pm_enter();
+	if (!ret) {
+		/*
+		 * Pass idle state index to cpu_suspend which in turn will

include/linux/cpuidle-arm.h line 30

Quoted 10 lines
include/linux/cpuidle-arm.h new file +10 -0
+		 * call the CPU ops suspend protocol with idle index as a
+		 * parameter.
+		 */
+		ret = arm_cpuidle_suspend(idx);
+
+		cpu_pm_exit();
+	}
+
+	return ret ? -1 : idx;
+}

Either you do this, or we have to add it somehow somewhere in drivers/cpuidle to avoid duplicating it.

Quoted 1 line

@Daniel: do you have an opinion on this please ?

I don't like the idea to add an ARM arch specific header in include/linux. I thought this directory was supposed to contain as much as possible arch agnostic headers.

May be the name can be changed to something more generic:

eg.

int cpuidle_generic_enter(int idx);

and then add an option:

HAVE_CPUIDLE_GENERIC_ENTER

, then in the generic header:

#ifdef HAVE_CPUIDLE_GENERIC_ENTER
int cpuidle_generic_enter(int idx);
#endif

, change the function name in cpuidle-arm .c

and finally add in the ARM and ARM64 Kconfig's option HAVE_CPUIDLE_GENERIC_ENTER.

-- Daniel

Signature · 5 lines
  <http://www.linaro.org/> Linaro.org ? Open source software for ARM SoCs

Follow Linaro:  <http://www.facebook.com/pages/Linaro> Facebook |
<http://twitter.com/#!/linaroorg> Twitter |
<http://www.linaro.org/linaro-blog/> Blog
#14 lore raw

Re: [PATCH v6 4/5] arm64: add support for ACPI Low Power Idle(LPI)

Quoted 78 lines · Daniel Lezcano
Quoted 77 lines · Lorenzo Pieralisi

Hi Sudeep,

Quoted 13 lines · Sudeep Holla

This patch adds appropriate callbacks to support ACPI Low Power Idle (LPI) on ARM64.

Now that arm_enter_idle_state is exactly same in both generic ARM{32,64} CPUIdle driver and ARM64 backend for ACPI processor idle driver, we can unify it and move to cpuidle-arm.h header.

Cc Lorenzo Pieralisi <[email protected]>
Cc Mark Rutland <[email protected]>
Cc Daniel Lezcano <[email protected]>
Cc "Rafael J. Wysocki" <[email protected]>
Cc linux-arm-kernel at lists.infradead.org
Quoted 8 lines
---
  arch/arm64/kernel/cpuidle.c   | 17 +++++++++++++
  drivers/cpuidle/cpuidle-arm.c | 23 ++----------------
  drivers/firmware/psci.c       | 56
+++++++++++++++++++++++++++++++++++++++++++
  include/linux/cpuidle-arm.h   | 30 +++++++++++++++++++++++
  4 files changed, 105 insertions(+), 21 deletions(-)

create mode 100644 include/linux/cpuidle-arm.h

This patch seems fine by me, it would be good if Daniel can have a look too.

Some minor comments below.

[...]

Quoted 45 lines
drivers/firmware/psci.c +29 -0
index 03e04582791c..c6caa863d156 100644
@@ -13,6 +13,7 @@
 
  #define pr_fmt(fmt) "psci: " fmt
 
+#include <linux/acpi.h>
  #include <linux/arm-smccc.h>
  #include <linux/cpuidle.h>
  #include <linux/errno.h>
@@ -310,11 +311,66 @@ static int psci_dt_cpu_init_idle(struct
 device_node *cpu_node, int cpu)
      return ret;
  }
 
+#ifdef CONFIG_ACPI
+#include <acpi/processor.h>
+
+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))
+        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 <= 0)
+        return -ENODEV;
+
+    psci_states = kcalloc(count, sizeof(*psci_states), GFP_KERNEL);
+    if (!psci_states)
+        return -ENOMEM;
Quoted 9 lines
Quoted 6 lines

drivers/firmware/psci.c static int psci_dt_cpu_init_idle(struct device_node *cpu_node, int cpu) · line 347

Quoted 6 lines
drivers/firmware/psci.c +6 -0
+
+    for (i = 0; i < count; i++) {
+        u32 state;
+
+        lpi = &pr->power.lpi_states[i + 1];
+        state = lpi->address & 0xFFFFFFFF;

Why mask 'address' if 'state' is u32 ?

Agreed, I overlooked it.

Quoted 46 lines
Quoted 10 lines

drivers/firmware/psci.c static int psci_dt_cpu_init_idle(struct device_node *cpu_node, int cpu) · line 357

Quoted 10 lines
drivers/firmware/psci.c +10 -0
+        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;

The ACPI and the PSCI code are not self contained here.

It would be nice to move this function to the ACPI code.

Quoted 13 lines
Quoted 13 lines
drivers/firmware/psci.c +8 -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;
 
Quoted 3 lines

drivers/firmware/psci.c static int psci_dt_cpu_init_idle(struct device_node *cpu_node, int cpu) · line 373

Quoted 3 lines
drivers/firmware/psci.c +3 -0
+    if (!acpi_disabled)
+        return psci_acpi_cpu_init_idle(cpu);
+

acpi_disabled - acpi_disabled - acpi_disabled everywhere :/

The enable-method approach is not straightforward and now it is polluted by acpi-disabled.

So IIUC,

smp_init_cpus (contains acpi_disabled)
smp_cpu_setup
cpu_read_ops
cpu_read_enable_method (contains acpi_disabled)
acpi_get_enable_method (returns 'psci' after checking
psci_is_present)

Quoted 9 lines

Then psci_cpu_init_idle is called... and check again acpi_disabled.

IMO, the circumlocution with the psci vs acpi vs acpi_disabled is getting unnecessary too complex, is prone to error and will lead to unmaintainable code very soon.

I suggest to sort out encapsulation and self-contained code before adding more feature in this area.

I understand your concern but I have no idea on how to clean up. Lorenzo asked to factor our common code between psci_{dt,acpi}_cpu_init_idle and I think you might not like the refactoring[1]. I didn't want to change cpuidle_ops and hence psci_dt_cpu_init_idle parameters. I will see if changing that simplifies things.

Quoted 46 lines
Quoted 46 lines

include/linux/cpuidle-arm.h

Quoted 8 lines
drivers/firmware/psci.c +0 -0
      cpu_node = of_get_cpu_node(cpu, NULL);
      if (!cpu_node)
          return -ENODEV;
include/linux/cpuidle-arm.h new file +0 -0
new file mode 100644
index 000000000000..b99bcb3f43dd

arm-cpuidle.h for consistency with other (ARM) include/linux files ?

Quoted 21 lines
include/linux/cpuidle-arm.h new file +20 -0
@@ -0,0 +1,30 @@
+#include <linux/cpu_pm.h>
+
+#include <asm/cpuidle.h>
+
+/*
+ * arm_enter_idle_state - Programs CPU to enter the specified state
+ */
+static int arm_generic_enter_idle_state(int idx)
+{
+    int ret;
+
+    if (!idx) {
+        cpu_do_idle();
+        return idx;
+    }
+
+    ret = cpu_pm_enter();
+    if (!ret) {
+        /*
+         * Pass idle state index to cpu_suspend which in turn will

include/linux/cpuidle-arm.h line 30

Quoted 10 lines
include/linux/cpuidle-arm.h new file +10 -0
+         * call the CPU ops suspend protocol with idle index as a
+         * parameter.
+         */
+        ret = arm_cpuidle_suspend(idx);
+
+        cpu_pm_exit();
+    }
+
+    return ret ? -1 : idx;
+}

Either you do this, or we have to add it somehow somewhere in drivers/cpuidle to avoid duplicating it.

Quoted 6 lines
Quoted 1 line

@Daniel: do you have an opinion on this please ?

I don't like the idea to add an ARM arch specific header in include/linux. I thought this directory was supposed to contain as much as possible arch agnostic headers.

While I agree, but what we have is ARM specific code here and calling it generic might not make it any usable on other architecture unless they have the same semantics. I am fine if you and Rafael are OK with that.

Quoted 16 lines

May be the name can be changed to something more generic:

eg.

int cpuidle_generic_enter(int idx);

and then add an option:

HAVE_CPUIDLE_GENERIC_ENTER

, then in the generic header:

#ifdef HAVE_CPUIDLE_GENERIC_ENTER
int cpuidle_generic_enter(int idx);
#endif

Quoted 8 lines

, change the function name in cpuidle-arm .c

and finally add in the ARM and ARM64 Kconfig's option HAVE_CPUIDLE_GENERIC_ENTER.

-- Daniel

[1]
http://git.kernel.org/cgit/linux/kernel/git/sudeep.holla/linux.git/commit/?h=for_review/arm64_lpi&id=9b516ad4442b4168e962ba4ca87bd568d605053b

Signature · 2 lines
Regards,
Sudeep
#15 lore raw

Re: [PATCH v6 4/5] arm64: add support for ACPI Low Power Idle(LPI)

Quoted 3 lines · Sudeep Holla

On 27/06/16 17:29, Daniel Lezcano wrote:

[...]

Quoted 25 lines
Quoted 15 lines

acpi_disabled - acpi_disabled - acpi_disabled everywhere :/

The enable-method approach is not straightforward and now it is polluted by acpi-disabled.

So IIUC,

smp_init_cpus (contains acpi_disabled)
smp_cpu_setup
cpu_read_ops
cpu_read_enable_method (contains acpi_disabled)
acpi_get_enable_method (returns 'psci' after checking
psci_is_present)

Quoted 9 lines

Then psci_cpu_init_idle is called... and check again acpi_disabled.

IMO, the circumlocution with the psci vs acpi vs acpi_disabled is getting unnecessary too complex, is prone to error and will lead to unmaintainable code very soon.

I suggest to sort out encapsulation and self-contained code before adding more feature in this area.

Quoted 6 lines

I understand your concern but I have no idea on how to clean up. Lorenzo asked to factor our common code between psci_{dt,acpi}_cpu_init_idle and I think you might not like the refactoring[1]. I didn't want to change cpuidle_ops and hence psci_dt_cpu_init_idle parameters. I will see if changing that simplifies things.

One of the reasons for adding acpi_disabled check is to keep the other logic at the same place. Otherwise we end up duplicating that code which is what I have done in psci_{dt,acpi}_cpu_init_idle at the first place.

Signature · 2 lines
Regards,
Sudeep