Skip to contentSkip to conversation

ACPI / processor_idle: Add ACPI v6.0 LPI support

PATCH Superseded Sudeep Holla 8 participants 22 messages May 11, 2016 – Jun 14, 2016 1 message not in the archive

Subsystems (4)

v5 of 10 Superseded Latest is v10 →

lore
Share & tools
lore
#0 lore raw

v5 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.

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] 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/acpi.c        |  48 ++++
 arch/arm64/kernel/cpuidle.c     |   2 +-
 arch/ia64/Kconfig               |   1 +
 arch/x86/Kconfig                |   1 +
 drivers/acpi/Kconfig            |   6 +-
 drivers/acpi/bus.c              |  14 +-
 drivers/acpi/processor_driver.c |   2 +-
 drivers/acpi/processor_idle.c   | 539 ++++++++++++++++++++++++++++++++++------
 drivers/firmware/psci.c         |  56 +++++
 include/acpi/processor.h        |  26 +-
 include/linux/acpi.h            |   4 +
 11 files changed, 611 insertions(+), 88 deletions(-)
Signature · 1 line
1.9.1
#1 lore raw

PATCH v5 1/5 ACPI / processor_idle: introduce ACPI_PROCESSOR_CSTATE

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.

---
 arch/ia64/Kconfig             |  1 +
 arch/x86/Kconfig              |  1 +
 drivers/acpi/Kconfig          |  4 +++
 drivers/acpi/processor_idle.c | 80 ++++++++++++++++++++++++++++---------------
 include/acpi/processor.h      |  2 +-
 5 files changed, 60 insertions(+), 28 deletions(-)
arch/ia64/Kconfig +1 -0
index b534ebab36ea..e820670d7243 100644
@@ -15,6 +15,7 @@ config IA64
 	select ARCH_MIGHT_HAVE_PC_SERIO
 	select PCI if (!IA64_HP_SIM)
 	select ACPI if (!IA64_HP_SIM)
+	select ACPI_PROCESSOR_CSTATE if ACPI
 	select ACPI_SYSTEM_POWER_STATES_SUPPORT if ACPI
 	select ARCH_MIGHT_HAVE_ACPI_PDC if ACPI
 	select HAVE_UNSTABLE_SCHED_CLOCK
arch/x86/Kconfig +1 -0
index 2dc18605831f..cb3e14757c9c 100644
@@ -18,6 +18,7 @@ config X86_64
 config X86
 	def_bool y
 	select ACPI_LEGACY_TABLES_LOOKUP	if ACPI
+	select ACPI_PROCESSOR_CSTATE		if ACPI
 	select ACPI_SYSTEM_POWER_STATES_SUPPORT	if ACPI
 	select ANON_INODES
 	select ARCH_CLOCKSOURCE_DATA
drivers/acpi/Kconfig +4 -0
index b7e2e776397d..093bfcc4f9c3 100644
@@ -213,6 +213,10 @@ config ACPI_CPU_FREQ_PSS
 	bool
 	select THERMAL
 
+config ACPI_PROCESSOR_CSTATE
+	bool
+	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
1.9.1
#2 lore raw

Re: [PATCH v5 1/5] ACPI / processor_idle: introduce ACPI_PROCESSOR_CSTATE

Quoted 25 lines · 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.

---
 arch/ia64/Kconfig             |  1 +
 arch/x86/Kconfig              |  1 +
 drivers/acpi/Kconfig          |  4 +++
 drivers/acpi/processor_idle.c | 80 ++++++++++++++++++++++++++++---------------
 include/acpi/processor.h      |  2 +-
 5 files changed, 60 insertions(+), 28 deletions(-)
arch/ia64/Kconfig +0 -0
index b534ebab36ea..e820670d7243 100644

arch/ia64/Kconfig config IA64 · line 18

Quoted 4 lines
arch/ia64/Kconfig +1 -0
@@ -15,6 +15,7 @@ config IA64
        select ARCH_MIGHT_HAVE_PC_SERIO
        select PCI if (!IA64_HP_SIM)
        select ACPI if (!IA64_HP_SIM)
+       select ACPI_PROCESSOR_CSTATE if ACPI

You don't need this ->

Quoted 20 lines
arch/ia64/Kconfig +0 -0
        select ACPI_SYSTEM_POWER_STATES_SUPPORT if ACPI
        select ARCH_MIGHT_HAVE_ACPI_PDC if ACPI
        select HAVE_UNSTABLE_SCHED_CLOCK
arch/x86/Kconfig +1 -0
index 2dc18605831f..cb3e14757c9c 100644
@@ -18,6 +18,7 @@ config X86_64
 config X86
        def_bool y
        select ACPI_LEGACY_TABLES_LOOKUP        if ACPI
+       select ACPI_PROCESSOR_CSTATE            if ACPI
        select ACPI_SYSTEM_POWER_STATES_SUPPORT if ACPI
        select ANON_INODES
        select ARCH_CLOCKSOURCE_DATA
drivers/acpi/Kconfig +0 -0
index b7e2e776397d..093bfcc4f9c3 100644

drivers/acpi/Kconfig config ACPI_CPU_FREQ_PSS · line 217

Quoted 5 lines
drivers/acpi/Kconfig +2 -0
@@ -213,6 +213,10 @@ config ACPI_CPU_FREQ_PSS
        bool
        select THERMAL
 
+config ACPI_PROCESSOR_CSTATE
+       bool

-> if you do "def_bool y" here.

Quoted 5 lines
drivers/acpi/Kconfig +2 -0
+       depends on IA64 || X86
+
 config ACPI_PROCESSOR_IDLE
        bool
        select CPU_IDLE
#3 lore raw

Re: [PATCH v5 1/5] ACPI / processor_idle: introduce ACPI_PROCESSOR_CSTATE

Quoted 56 lines · Rafael J. Wysocki
Quoted 25 lines · 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.

---
  arch/ia64/Kconfig             |  1 +
  arch/x86/Kconfig              |  1 +
  drivers/acpi/Kconfig          |  4 +++
  drivers/acpi/processor_idle.c | 80 ++++++++++++++++++++++++++++---------------
  include/acpi/processor.h      |  2 +-
  5 files changed, 60 insertions(+), 28 deletions(-)
arch/ia64/Kconfig +0 -0
index b534ebab36ea..e820670d7243 100644

arch/ia64/Kconfig config IA64 · line 18

Quoted 4 lines
arch/ia64/Kconfig +1 -0
@@ -15,6 +15,7 @@ config IA64
         select ARCH_MIGHT_HAVE_PC_SERIO
         select PCI if (!IA64_HP_SIM)
         select ACPI if (!IA64_HP_SIM)
+       select ACPI_PROCESSOR_CSTATE if ACPI

You don't need this ->

Quoted 23 lines
arch/ia64/Kconfig +0 -0
         select ACPI_SYSTEM_POWER_STATES_SUPPORT if ACPI
         select ARCH_MIGHT_HAVE_ACPI_PDC if ACPI
         select HAVE_UNSTABLE_SCHED_CLOCK
arch/x86/Kconfig +1 -0
index 2dc18605831f..cb3e14757c9c 100644
@@ -18,6 +18,7 @@ config X86_64
  config X86
         def_bool y
         select ACPI_LEGACY_TABLES_LOOKUP        if ACPI
+       select ACPI_PROCESSOR_CSTATE            if ACPI
         select ACPI_SYSTEM_POWER_STATES_SUPPORT if ACPI
         select ANON_INODES
         select ARCH_CLOCKSOURCE_DATA
drivers/acpi/Kconfig +0 -0
index b7e2e776397d..093bfcc4f9c3 100644
@@ -213,6 +213,10 @@ config ACPI_CPU_FREQ_PSS
         bool
         select THERMAL
 
Quoted 5 lines

drivers/acpi/Kconfig config ACPI_CPU_FREQ_PSS · line 217

Quoted 2 lines
drivers/acpi/Kconfig +2 -0
+config ACPI_PROCESSOR_CSTATE
+       bool

-> if you do "def_bool y" here.

I agree and I did exactly the same, but then was not sure on your preference. So dropped it :)

Signature · 2 lines
Regards,
Sudeep

A message that is not in the archive (sent off-list or not yet received): CAJvTdKnJPZ9Nfib=CqBczMP4BERqfqAzeSR-+jjFOGZR51oVmg@mail.gmail.com

reviewer
#5 lore raw

Re: [PATCH v5 1/5] ACPI / processor_idle: introduce ACPI_PROCESSOR_CSTATE

What is the functional goal/purpose of adding CONFIG_ACPI_PROCESSOR_CSTATE?

If the answer is that it saves code space on an ARM build, how much space does it save?

Len Brown, Intel Open Source Technology Center

#6 lore raw

Re: [PATCH v5 1/5] ACPI / processor_idle: introduce ACPI_PROCESSOR_CSTATE

(I seem to have 2 emails, replying on the second)

Quoted 2 lines · Len Brown

What is the functional goal/purpose of adding CONFIG_ACPI_PROCESSOR_CSTATE?

Avoid adding unnecessary dummy implementations of functions and
variables that will never be used on ARM64 and also looks ugly IMO. E.g.: arch_safe_halt
boot_option_idle_override
IDLE_NOMWAIT
acpi_unlazy_tlb
acpi_processor_cstate_check disabled_by_idle_boot_param and more...

Quoted 3 lines

If the answer is that it saves code space on an ARM build, how much space does it save?

NO, it doesn't even add a kB of code I believe, so that's definitely not the reason. I am fine to retain if we can find a saner way to solve the above issue.

Signature · 2 lines
Regards,
Sudeep
#7 lore raw

PATCH v5 1/1 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(-)

Updated to def_bool and removed selection from IA64 and X86

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
1.9.1
#8 lore raw

PATCH v5 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   | 463 +++++++++++++++++++++++++++++++++++-----
 include/acpi/processor.h        |  24 ++-
 include/linux/acpi.h            |   4 +
 5 files changed, 447 insertions(+), 60 deletions(-)
drivers/acpi/bus.c +13 -1
index 31e8da648fff..71edf7b07409 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 +408 -55

559 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
1.9.1
#9 lore raw

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

Hi Sudeep,

Quoted 19 lines · Sudeep Holla
drivers/acpi/processor_idle.c +19 -0
+
+static int acpi_processor_get_lpi_info(struct acpi_processor *pr)
+{
+	int ret, i;
+	struct acpi_lpi_states_array *info;
+	struct acpi_device *d = NULL;
+	acpi_handle handle = pr->handle, pr_ahandle;
+	acpi_status status;
+
+	if (!osc_pc_lpi_support_confirmed)
+		return -EOPNOTSUPP;
+
+	max_leaf_depth = 0;
+	if (!acpi_has_method(handle, "_LPI"))
+		return -EINVAL;
+	flat_state_cnt = 0;
+
+	while (ACPI_SUCCESS(status = acpi_get_parent(handle, &pr_ahandle))) {
+		if (!acpi_has_method(handle, "_LPI"))

drivers/acpi/processor_idle.c static int acpi_processor_setup_cpuidle_cx(struct acpi_processor *pr, · line 1169

Quoted 10 lines
drivers/acpi/processor_idle.c +10 -0
+			continue;
+
+		acpi_bus_get_device(handle, &d);
+		if (!strcmp(acpi_device_hid(d), ACPI_PROCESSOR_CONTAINER_HID))
+			break;
+
+		max_leaf_depth++;
+		handle = pr_ahandle;
+	}
+

In the above loop, we break when we find a device with HID == ACPI_PROCESSOR_CONTAINER_HID. Shouldn't we continue to parse as long as the parent HID == ACPI_PROCESSOR_CONTAINER_HID? This is required to make sure we parse states in levels higher than cluster level in processor hierarchy.

Also, I think it might be safe to break out of the loop if we didn't find _LPI package, instead of continuing. Given the presence of LPI entry: "Enabled Parent State", I can't think of a non-ambiguous scenario where we might find LPI packages in state N and N+2, but not in N+1, as we will not be able to figure out which state in N enables which states in N+2. Thoughts?

Thanks,
Prashanth

#10 lore raw

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

Quoted 28 lines · Prashanth

Hi Sudeep,

Quoted 25 lines · Sudeep Holla
drivers/acpi/processor_idle.c +25 -0
+
+static int acpi_processor_get_lpi_info(struct acpi_processor *pr)
+{
+	int ret, i;
+	struct acpi_lpi_states_array *info;
+	struct acpi_device *d = NULL;
+	acpi_handle handle = pr->handle, pr_ahandle;
+	acpi_status status;
+
+	if (!osc_pc_lpi_support_confirmed)
+		return -EOPNOTSUPP;
+
+	max_leaf_depth = 0;
+	if (!acpi_has_method(handle, "_LPI"))
+		return -EINVAL;
+	flat_state_cnt = 0;
+
+	while (ACPI_SUCCESS(status = acpi_get_parent(handle, &pr_ahandle))) {
+		if (!acpi_has_method(handle, "_LPI"))
+			continue;
+
+		acpi_bus_get_device(handle, &d);
+		if (!strcmp(acpi_device_hid(d), ACPI_PROCESSOR_CONTAINER_HID))
+			break;
+
Quoted 9 lines

drivers/acpi/processor_idle.c static int acpi_processor_setup_cpuidle_cx(struct acpi_processor *pr, · line 1169

Quoted 4 lines
drivers/acpi/processor_idle.c +4 -0
+		max_leaf_depth++;
+		handle = pr_ahandle;
+	}
+

In the above loop, we break when we find a device with HID == ACPI_PROCESSOR_CONTAINER_HID. Shouldn't we continue to parse as long as the parent HID == ACPI_PROCESSOR_CONTAINER_HID? This is required to make sure we parse states in levels higher than cluster level in processor hierarchy.

Yes, thanks for pointing that out. With just clusters in _LPI on my dev board, I missed it.

Quoted 6 lines

Also, I think it might be safe to break out of the loop if we didn't find _LPI package, instead of continuing. Given the presence of LPI entry:
"Enabled Parent State", I can't think of a non-ambiguous scenario where we might find LPI packages in state N and N+2, but not in N+1, as we will not be able to figure out which state in N enables which states in N+2. Thoughts?

Though I admit I haven't thought in detail on how to deal with the asymmetric topology, but that was the reason why I continue instead of breaking.

Excerpts from the spec: "... This example is symmetric but that is not a requirement. For example, a system may contain a different number of processors in different containers or an asymmetric hierarchy where one side of the topology tree is deeper than another...."

Signature · 6 lines
Regards,
Sudeep

-- 
Regards,
Sudeep
#11 lore raw

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

Quoted 41 lines · Sudeep Holla
Quoted 28 lines · Prashanth

Hi Sudeep,

Quoted 25 lines · Sudeep Holla
drivers/acpi/processor_idle.c +25 -0
+
+static int acpi_processor_get_lpi_info(struct acpi_processor *pr)
+{
+    int ret, i;
+    struct acpi_lpi_states_array *info;
+    struct acpi_device *d = NULL;
+    acpi_handle handle = pr->handle, pr_ahandle;
+    acpi_status status;
+
+    if (!osc_pc_lpi_support_confirmed)
+        return -EOPNOTSUPP;
+
+    max_leaf_depth = 0;
+    if (!acpi_has_method(handle, "_LPI"))
+        return -EINVAL;
+    flat_state_cnt = 0;
+
+    while (ACPI_SUCCESS(status = acpi_get_parent(handle, &pr_ahandle))) {
+        if (!acpi_has_method(handle, "_LPI"))
+            continue;
+
+        acpi_bus_get_device(handle, &d);
+        if (!strcmp(acpi_device_hid(d), ACPI_PROCESSOR_CONTAINER_HID))
+            break;
+
Quoted 9 lines

drivers/acpi/processor_idle.c static int acpi_processor_setup_cpuidle_cx(struct acpi_processor *pr, · line 1169

Quoted 4 lines
drivers/acpi/processor_idle.c +4 -0
+        max_leaf_depth++;
+        handle = pr_ahandle;
+    }
+

In the above loop, we break when we find a device with HID == ACPI_PROCESSOR_CONTAINER_HID. Shouldn't we continue to parse as long as the parent HID == ACPI_PROCESSOR_CONTAINER_HID? This is required to make sure we parse states in levels higher than cluster level in processor hierarchy.

Quoted 3 lines

Yes, thanks for pointing that out. With just clusters in _LPI on my dev board, I missed it.

Same reason, I failed to notice it all this time :)

Quoted 7 lines
Quoted 6 lines

Also, I think it might be safe to break out of the loop if we didn't find _LPI package, instead of continuing. Given the presence of LPI entry:
"Enabled Parent State", I can't think of a non-ambiguous scenario where we might find LPI packages in state N and N+2, but not in N+1, as we will not be able to figure out which state in N enables which states in N+2. Thoughts?

Quoted 9 lines

Though I admit I haven't thought in detail on how to deal with the asymmetric topology, but that was the reason why I continue instead of breaking.

Excerpts from the spec: "... This example is symmetric but that is not a requirement. For example, a system may contain a different number of processors in different containers or an asymmetric hierarchy where one side of the topology tree is deeper than another...."

If it addresses asymmetric topology, sure we can keep as it doesn't impact other scenarios. Also, we need to set handle=pr_ahandle prior to the continue statement.

Thanks,
Prashanth

#12 lore raw

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

Quoted 44 lines · Prashanth
Quoted 41 lines · Sudeep Holla
Quoted 37 lines · Prashanth

Hi Sudeep,

Quoted 19 lines · Sudeep Holla
drivers/acpi/processor_idle.c +19 -0
+
+static int acpi_processor_get_lpi_info(struct acpi_processor *pr)
+{
+    int ret, i;
+    struct acpi_lpi_states_array *info;
+    struct acpi_device *d = NULL;
+    acpi_handle handle = pr->handle, pr_ahandle;
+    acpi_status status;
+
+    if (!osc_pc_lpi_support_confirmed)
+        return -EOPNOTSUPP;
+
+    max_leaf_depth = 0;
+    if (!acpi_has_method(handle, "_LPI"))
+        return -EINVAL;
+    flat_state_cnt = 0;
+
+    while (ACPI_SUCCESS(status = acpi_get_parent(handle, &pr_ahandle))) {
+        if (!acpi_has_method(handle, "_LPI"))

drivers/acpi/processor_idle.c static int acpi_processor_setup_cpuidle_cx(struct acpi_processor *pr, · line 1169

Quoted 10 lines
drivers/acpi/processor_idle.c +10 -0
+            continue;
+
+        acpi_bus_get_device(handle, &d);
+        if (!strcmp(acpi_device_hid(d), ACPI_PROCESSOR_CONTAINER_HID))
+            break;
+
+        max_leaf_depth++;
+        handle = pr_ahandle;
+    }
+

In the above loop, we break when we find a device with HID == ACPI_PROCESSOR_CONTAINER_HID. Shouldn't we continue to parse as long as the parent HID == ACPI_PROCESSOR_CONTAINER_HID? This is required to make sure we parse states in levels higher than cluster level in processor hierarchy.

Quoted 4 lines
Quoted 3 lines

Yes, thanks for pointing that out. With just clusters in _LPI on my dev board, I missed it.

Same reason, I failed to notice it all this time :)

No worries.

Quoted 11 lines
Quoted 11 lines
Quoted 6 lines

Also, I think it might be safe to break out of the loop if we didn't find _LPI package, instead of continuing. Given the presence of LPI entry:
"Enabled Parent State", I can't think of a non-ambiguous scenario where we might find LPI packages in state N and N+2, but not in N+1, as we will not be able to figure out which state in N enables which states in N+2. Thoughts?

Though I admit I haven't thought in detail on how to deal with the asymmetric topology, but that was the reason why I continue instead of breaking.

Quoted 8 lines
Quoted 5 lines

Excerpts from the spec: "... This example is symmetric but that is not a requirement. For example, a system may contain a different number of processors in different containers or an asymmetric hierarchy where one side of the topology tree is deeper than another...."

If it addresses asymmetric topology, sure we can keep as it doesn't impact other scenarios. Also, we need to set handle=pr_ahandle prior to the continue statement.

Yes I noticed it yesterday, the more I think, I feel we can break out of the loop. At any level, we need to have container nodes and that must contain _LPI irrespective of asymmetricity. So you were right. I have fixed accordingly and have pushed out on my branch.

Signature · 2 lines
Regards,
Sudeep
#13 lore raw

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

In reply to Sudeep Holla

Hi Rafael,

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 have added support for autopromote states(basically skip flattening or creating composite state). I have also fixed the bug discussed in this thread with Prashant. Do you have any other feedback on this version that I incorporate before posting next version.

Signature · 2 lines
Regards,
Sudeep
#14 lore raw

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

Quoted 1 line · Sudeep Holla

Hi Rafael,

Hi,

Quoted 13 lines · Sudeep Holla
Quoted 12 lines

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.

Quoted 7 lines
Quoted 2 lines

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

I have added support for autopromote states(basically skip flattening or creating composite state). I have also fixed the bug discussed in this thread with Prashant. Do you have any other feedback on this version that I incorporate before posting next version.

I'd really preferred it if you posted the next version without waiting for my feedback to the previous one (as the feedback may not be relevant any more among other things).

Thanks,
Rafael

#15 lore raw

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

Quoted 21 lines · Rafael J. Wysocki
Quoted 1 line · Sudeep Holla

Hi Rafael,

Hi,

Quoted 16 lines · Sudeep Holla
Quoted 14 lines

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.

Quoted 9 lines
Quoted 4 lines

I have added support for autopromote states(basically skip flattening or creating composite state). I have also fixed the bug discussed in this thread with Prashant. Do you have any other feedback on this version that I incorporate before posting next version.

I'd really preferred it if you posted the next version without waiting for my feedback to the previous one (as the feedback may not be relevant any more among other things).

Sure, will do that soon.

Signature · 2 lines
Regards,
Sudeep
#16 lore raw

PATCH v5 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 9047cab68fd3..7ce589ca54a4 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
1.9.1
#17 lore raw

PATCH v5 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.

Cc Lorenzo Pieralisi <[email protected]>
Cc Mark Rutland <[email protected]>
Cc linux-arm-kernel at lists.infradead.org
---
 arch/arm64/kernel/acpi.c | 48 +++++++++++++++++++++++++++++++++++++++++
 drivers/firmware/psci.c  | 56 ++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 104 insertions(+)
arch/arm64/kernel/acpi.c +48 -0
index d1ce8e2f98b9..bf82ce5c8fce 100644
@@ -18,6 +18,7 @@
 #include <linux/acpi.h>
 #include <linux/bootmem.h>
 #include <linux/cpumask.h>
+#include <linux/cpu_pm.h>
 #include <linux/init.h>
 #include <linux/irq.h>
 #include <linux/irqdomain.h>
@@ -25,6 +26,9 @@
 #include <linux/of_fdt.h>
 #include <linux/smp.h>
 
+#include <acpi/processor.h>
+
+#include <asm/cpuidle.h>
 #include <asm/cputype.h>
 #include <asm/cpu_ops.h>
 #include <asm/smp_plat.h>
@@ -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)
 {
drivers/firmware/psci.c +56 -0

73 lines not on this page · raw message

Signature · 1 line
1.9.1
#18 lore raw

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

[+ Daniel, Kevin]

arch/arm64/kernel/acpi.c

Quoted 13 lines · Sudeep Holla

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

Cc Lorenzo Pieralisi <[email protected]>
Cc Mark Rutland <[email protected]>
---
 arch/arm64/kernel/acpi.c | 48 +++++++++++++++++++++++++++++++++++++++++
 drivers/firmware/psci.c  | 56 ++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 104 insertions(+)
arch/arm64/kernel/acpi.c +0 -0

I think we can add this to arm64/kernel/cpuidle.c so that we have all arch code managing idle in one place.

Quoted 35 lines

index d1ce8e2f98b9..bf82ce5c8fce 100644

arch/arm64/kernel/acpi.c +14 -0
@@ -18,6 +18,7 @@
 #include <linux/acpi.h>
 #include <linux/bootmem.h>
 #include <linux/cpumask.h>
+#include <linux/cpu_pm.h>
 #include <linux/init.h>
 #include <linux/irq.h>
 #include <linux/irqdomain.h>
@@ -25,6 +26,9 @@
 #include <linux/of_fdt.h>
 #include <linux/smp.h>
 
+#include <acpi/processor.h>
+
+#include <asm/cpuidle.h>
 #include <asm/cputype.h>
 #include <asm/cpu_ops.h>
 #include <asm/smp_plat.h>
@@ -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	\

arch/arm64/kernel/acpi.c void __init acpi_boot_table_init(void) · line 237

Quoted 10 lines
arch/arm64/kernel/acpi.c +10 -0
+	(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;

I am not really that keen on this, as you know. Those flags are there to say "save these components registers". I see the CPU PM notifiers as a way to save/restore CPU peripheral state, but they should *not* carry out any action that affects the power state itself, that's down to the suspend finisher (eg PSCI), because that's where the specific idle states are managed.

I agree we have no clue whatsoever on what we *really* need to save/restore, but that's orthogonal to what you are solving here.

See eg gic_cpu_if_down(). Do we call it from the GIC CPU PM notifier ? No. We should not handle the same problem differently.

On top of that, we have no way to solve this problem for DT, all I am saying is that it is ill-defined and given that LPI is new I'd rather we got it right from the beginning.

I am open to suggestions here.

Quoted 12 lines
arch/arm64/kernel/acpi.c +12 -0
+
+	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

arch/arm64/kernel/acpi.c void __init acpi_boot_table_init(void) · line 259

Quoted 10 lines
arch/arm64/kernel/acpi.c +10 -0
+		 * 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;

The body of this function (if we remove save_ctx) is identical to arm_enter_idle_state(), it would be nice if we found a way where to put this code and share it with the ARM CPUidle driver, but I am not too fussed about that either.

Quoted 33 lines
arch/arm64/kernel/acpi.c +2 -0
+}
+
 #ifdef CONFIG_ACPI_APEI
 pgprot_t arch_apei_get_mem_attribute(phys_addr_t addr)
 {
drivers/firmware/psci.c +13 -0
index fa4ea22ca12e..e06bfee68e1d 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))

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

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

Nit: I am not sure this can happen, but you really do not want count to become == -1.

Quoted 31 lines
drivers/firmware/psci.c +30 -0
+	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];
+		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)

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

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

save_ctx notwithstanding the patch is fine, let's define what to do with that, remainder of the code is ok.

Thanks,
Lorenzo

#19 lore raw

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

Quoted 11 lines · Lorenzo Pieralisi

[+ Daniel, Kevin]

Quoted 8 lines · Sudeep Holla

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

Cc Lorenzo Pieralisi <[email protected]>
Cc Mark Rutland <[email protected]>
Cc linux-arm-kernel at lists.infradead.org

---

[ ... ]

Quoted 27 lines
Quoted 5 lines
arch/arm64/kernel/acpi.c +5 -0
+#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	\

arch/arm64/kernel/acpi.c void __init acpi_boot_table_init(void) · line 237

Quoted 10 lines
arch/arm64/kernel/acpi.c +10 -0
+	(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;

I am not really that keen on this, as you know. Those flags are there to say "save these components registers". I see the CPU PM notifiers as a way to save/restore CPU peripheral state, but they should *not* carry out any action that affects the power state itself, that's down to the suspend finisher (eg PSCI), because that's where the specific idle states are managed.

I agree we have no clue whatsoever on what we *really* need to save/restore, but that's orthogonal to what you are solving here.

Quoted 8 lines

See eg gic_cpu_if_down(). Do we call it from the GIC CPU PM notifier ? No. We should not handle the same problem differently.

On top of that, we have no way to solve this problem for DT, all I am saying is that it is ill-defined and given that LPI is new I'd rather we got it right from the beginning.

I am open to suggestions here.

There is a part of the idle state flags integer which is reserved for the arch specific flag and can be masked with:

CPUIDLE_DRIVER_FLAGS_MASK()

May be these context flags can be added in the generic cpuidle driver and reused.

Concerning the DT, why not use the power domains to tell which context to save ? yeah, probably mentionned n-th times :)

Quoted 18 lines
Quoted 18 lines
arch/arm64/kernel/acpi.c +18 -0
+
+	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)
Quoted 8 lines

arch/arm64/kernel/acpi.c void __init acpi_boot_table_init(void) · line 259

Quoted 4 lines
arch/arm64/kernel/acpi.c +4 -0
+			cpu_pm_exit();
+	}
+
+	return ret ? -1 : idx;

The body of this function (if we remove save_ctx) is identical to arm_enter_idle_state(), it would be nice if we found a way where to put this code and share it with the ARM CPUidle driver,

+1

We don't want to redo another unmaintable acpi idle driver.

-- Daniel

#20 lore raw

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

In reply to Sudeep Holla

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 <[email protected]>
Cc: Sudeep Holla <[email protected]>; linux-kernel at vger.kernel.org; Sajjan, Vikas C <[email protected]>; Lakshminarasimha, Sunil Vishwanathpur <[email protected]>; Prashanth Prakash <[email protected]>; Ashwin Chaugule <[email protected]>; Al Stone <[email protected]>; Lorenzo Pieralisi <[email protected]>; Mark Rutland <[email protected]>; 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 <[email protected]>
Cc Mark Rutland <[email protected]>
Cc linux-arm-kernel at lists.infradead.org
---
 arch/arm64/kernel/acpi.c | 48 +++++++++++++++++++++++++++++++++++++++++
 drivers/firmware/psci.c  | 56 ++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 104 insertions(+)
arch/arm64/kernel/acpi.c +59 -1
@@ -18,6 +18,7 @@
 #include <linux/acpi.h>
 #include <linux/bootmem.h>
 #include <linux/cpumask.h>
+#include <linux/cpu_pm.h>
 #include <linux/init.h>
 #include <linux/irq.h>
 #include <linux/irqdomain.h>
@@ -25,6 +26,9 @@
 #include <linux/of_fdt.h>
 #include <linux/smp.h>
 
+#include <acpi/processor.h>
+
+#include <asm/cpuidle.h>
 #include <asm/cputype.h>
 #include <asm/cpu_ops.h>
 #include <asm/smp_plat.h>
@@ -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 <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))
 

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

#21 lore raw

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

Quoted 2 lines · Vikas C

Hi Sudeep,

[...]

Quoted 26 lines
drivers/firmware/psci.c +12 -0
@@ -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))
 
Quoted 3 lines

Any particular reason for _not_ considering CST flag here. Or you are planning to add CST support in some other patch set.

Are you referring the old C-state objects ? We don't support them on ARM64. Only LPIs are support. The ARM FFH is not defined for CST, only for LPIs.

Signature · 2 lines
Regards,
Sudeep
#22 lore raw

PATCH v5 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 093bfcc4f9c3..de5c7c09de69 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
1.9.1