linux-pm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Derek Basehore <dbasehore@chromium.org>
To: linux-kernel@vger.kernel.org
Cc: linux-pm@vger.kernel.org, rafael.j.wysocki@intel.com,
	tglx@linutronix.de, briannorris@chromium.org,
	marc.zyngier@arm.com, Derek Basehore <dbasehore@chromium.org>
Subject: [PATCH 3/8] cpu_pm: Add SYSTEM_PM state
Date: Fri, 12 Jan 2018 13:24:17 -0800	[thread overview]
Message-ID: <20180112212422.148625-4-dbasehore@chromium.org> (raw)
In-Reply-To: <20180112212422.148625-1-dbasehore@chromium.org>

This adds a new CPU PM state that is only called on system suspend.
Saving the GIC state needs to happen after the CPU_PM and
CPU_CLUSTER_PM transitions on suspend. The corresponding restore needs
to happen before these same transitions on resume. The CPU_CLUSTER_PM
transition is not valid since that can be called with normal idle
operations when powering down the GIC is not desired. Another set of
syscore ops would have to rely on the correct ordering of syscore ops,
so avoid that by adding a new CPU_PM state.

Change-Id: I484bafbad8e810540d54b7c73ef03e4adf7b7c9a
Signed-off-by: Derek Basehore <dbasehore@chromium.org>
Signed-off-by: Brian Norris <briannorris@chromium.org>
---
 include/linux/cpu_pm.h | 14 ++++++++++
 kernel/cpu_pm.c        | 74 +++++++++++++++++++++++++++++++++-----------------
 2 files changed, 63 insertions(+), 25 deletions(-)

diff --git a/include/linux/cpu_pm.h b/include/linux/cpu_pm.h
index 455b233dd3b1..28a462120cc5 100644
--- a/include/linux/cpu_pm.h
+++ b/include/linux/cpu_pm.h
@@ -41,6 +41,11 @@
  * are used to save any global context for affected blocks, and must be called
  * after all the CPUs in the power domain have been notified of the low power
  * state.
+ *
+ * CPU system notifications apply to all CPUs within the system. They are used
+ * for operations that must only happen on suspend and have an ordering
+ * requirement with the other CPU PM notifications. Must be called after all
+ * CPUs and clusters in the system have been notified of the low power state.
  */
 
 /*
@@ -64,6 +69,15 @@ enum cpu_pm_event {
 
 	/* A cpu power domain is exiting a low power state */
 	CPU_CLUSTER_PM_EXIT,
+
+	/* A cpu power domain is entering a system low power state (suspend) */
+	CPU_SYSTEM_PM_ENTER,
+
+	/* A cpu power domain failed to enter a system low power state */
+	CPU_SYSTEM_PM_ENTER_FAILED,
+
+	/* A cpu power domain is exiting a system low power state */
+	CPU_SYSTEM_PM_EXIT,
 };
 
 #ifdef CONFIG_CPU_PM
diff --git a/kernel/cpu_pm.c b/kernel/cpu_pm.c
index 03bcc0751a51..833357959bc5 100644
--- a/kernel/cpu_pm.c
+++ b/kernel/cpu_pm.c
@@ -72,6 +72,22 @@ int cpu_pm_unregister_notifier(struct notifier_block *nb)
 }
 EXPORT_SYMBOL_GPL(cpu_pm_unregister_notifier);
 
+static int cpu_pm_notify_enter(enum cpu_pm_event enter, enum cpu_pm_event fail)
+{
+	int nr_calls;
+	int ret = 0;
+
+	ret = cpu_pm_notify(enter, -1, &nr_calls);
+	if (ret)
+		/*
+		 * Inform listeners (nr_calls - 1) about failure to enter CPU PM
+		 * state <enter> who were notified earlier to prepare for it.
+		 */
+		cpu_pm_notify(fail, nr_calls - 1, NULL);
+
+	return ret;
+}
+
 /**
  * cpu_pm_enter - CPU low power entry notifier
  *
@@ -89,18 +105,7 @@ EXPORT_SYMBOL_GPL(cpu_pm_unregister_notifier);
  */
 int cpu_pm_enter(void)
 {
-	int nr_calls;
-	int ret = 0;
-
-	ret = cpu_pm_notify(CPU_PM_ENTER, -1, &nr_calls);
-	if (ret)
-		/*
-		 * Inform listeners (nr_calls - 1) about failure of CPU PM
-		 * PM entry who are notified earlier to prepare for it.
-		 */
-		cpu_pm_notify(CPU_PM_ENTER_FAILED, nr_calls - 1, NULL);
-
-	return ret;
+	return cpu_pm_notify_enter(CPU_PM_ENTER, CPU_PM_ENTER_FAILED);
 }
 EXPORT_SYMBOL_GPL(cpu_pm_enter);
 
@@ -140,18 +145,8 @@ EXPORT_SYMBOL_GPL(cpu_pm_exit);
  */
 int cpu_cluster_pm_enter(void)
 {
-	int nr_calls;
-	int ret = 0;
-
-	ret = cpu_pm_notify(CPU_CLUSTER_PM_ENTER, -1, &nr_calls);
-	if (ret)
-		/*
-		 * Inform listeners (nr_calls - 1) about failure of CPU cluster
-		 * PM entry who are notified earlier to prepare for it.
-		 */
-		cpu_pm_notify(CPU_CLUSTER_PM_ENTER_FAILED, nr_calls - 1, NULL);
-
-	return ret;
+	return cpu_pm_notify_enter(CPU_CLUSTER_PM_ENTER,
+		CPU_CLUSTER_PM_ENTER_FAILED);
 }
 EXPORT_SYMBOL_GPL(cpu_cluster_pm_enter);
 
@@ -176,6 +171,27 @@ int cpu_cluster_pm_exit(void)
 }
 EXPORT_SYMBOL_GPL(cpu_cluster_pm_exit);
 
+/*
+ * Notifies listeners that the system is entering suspend. Called after
+ * cpu_cluster_pm_enter() and only within the syscore suspend callback,
+ * cpu_pm_suspend.
+ */
+static int cpu_system_pm_enter(void)
+{
+	return cpu_pm_notify_enter(CPU_SYSTEM_PM_ENTER,
+		CPU_SYSTEM_PM_ENTER_FAILED);
+}
+
+/*
+ * Notifies listeners that the system is leaving suspend. Called before
+ * cpu_cluster_pm_exit() and only within the syscore resume callback,
+ * cpu_pm_resume.
+ */
+static int cpu_system_pm_exit(void)
+{
+	return cpu_pm_notify(CPU_SYSTEM_PM_EXIT, -1, NULL);
+}
+
 #ifdef CONFIG_PM
 static int cpu_pm_suspend(void)
 {
@@ -186,14 +202,22 @@ static int cpu_pm_suspend(void)
 		return ret;
 
 	ret = cpu_cluster_pm_enter();
-	if (ret)
+	if (ret) {
 		cpu_pm_exit();
+		return ret;
+	}
 
+	ret = cpu_system_pm_enter();
+	if (ret) {
+		cpu_cluster_pm_exit();
+		cpu_pm_exit();
+	}
 	return ret;
 }
 
 static void cpu_pm_resume(void)
 {
+	cpu_system_pm_exit();
 	cpu_cluster_pm_exit();
 	cpu_pm_exit();
 }
-- 
2.16.0.rc1.238.g530d649a79-goog

  parent reply	other threads:[~2018-01-12 21:24 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-01-12 21:24 [PATCH 0/8] GICv3 Save and Restore Derek Basehore
2018-01-12 21:24 ` [PATCH 1/8] cpu_pm: add syscore_suspend error handling Derek Basehore
2018-01-12 22:07   ` Brian Norris
2018-01-12 21:24 ` [PATCH 2/8] lib/iomap_copy: add __ioread64_copy() Derek Basehore
2018-01-12 21:24 ` Derek Basehore [this message]
2018-01-12 21:24 ` [PATCH 4/8] irqchip/gic-v3: add ability to save/restore GIC/ITS state Derek Basehore
2018-01-13 18:10   ` Marc Zyngier
2018-01-18 23:33     ` Brian Norris
2018-01-19  9:22       ` Marc Zyngier
2018-01-19 22:58         ` dbasehore .
2018-01-12 21:24 ` [PATCH 5/8] DT/arm,gic-v3: add save-suspend-state property Derek Basehore
2018-01-14 10:48   ` Marc Zyngier
2018-01-12 21:24 ` [PATCH 6/8] irqchip/gic-v3-its: add ability to resend MAPC on resume Derek Basehore
2018-01-14 10:56   ` Marc Zyngier
2018-01-25 23:07     ` dbasehore .
2018-01-12 21:24 ` [PATCH 7/8] DT/arm,gic-v3: add resend-mapc-on-resume property Derek Basehore
2018-01-12 21:24 ` [PATCH 8/8] irqchip/gic-v3: add power down/up sequence Derek Basehore
2018-01-14 11:04   ` Marc Zyngier

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20180112212422.148625-4-dbasehore@chromium.org \
    --to=dbasehore@chromium.org \
    --cc=briannorris@chromium.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=marc.zyngier@arm.com \
    --cc=rafael.j.wysocki@intel.com \
    --cc=tglx@linutronix.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).