<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
    <channel>
        <title>[PATCH 2/6] PM / Domains: Fix hibernation restore of devices</title>
        <description> From: Rafael J. Wysocki &amp;lt;rjw@sisk.pl&amp;gt;

During resume from hibernation pm_genpd_restore_noirq() has to
deal with software state left by pm_genpd_suspend_noirq() and
unknown hardware state (the boot kernel may leave all PM domains and
devices in arbitrary states).  For this reason, make it attempt to
power cycle each domain when before resuming its first device to
possibly get rid of any unwanted hardware state that may interfere
with genpd_start_dev() later on.

Signed-off-by: Rafael J. Wysocki &amp;lt;rjw@sisk.pl&amp;gt;
---
 drivers/base/power/domain.c |   21 +++++++++++++--------
 1 file changed, 13 insertions(+), 8 deletions(-)

Index: linux/drivers/base/power/domain.c
===================================================================
--- linux.orig/drivers/base/power/domain.c
+++ linux/drivers/base/power/domain.c
@@ -770,8 +770,10 @@ static int pm_genpd_prepare(struct devic
 
 	genpd_acquire_lock(genpd);
 
-	if (genpd-&amp;gt;prepared_count++ == 0)
+	if (genpd-&amp;gt;prepared_count++ == 0) {
+		genpd-&amp;gt;suspended_count = 0;
 		genpd-&amp;gt;suspend_power_off = genpd-&amp;gt;status == GPD_STATE_POWER_OFF;
+	}
 
 	genpd_release_lock(genpd);
 
@@ -1103,20 +1105,24 @@ static int pm_genpd_restore_noirq(struct
 	 * Since all of the &amp;quot;noirq&amp;quot; callbacks are executed sequentially, it is
 	 * guaranteed that this function will never run twice in parallel for
 	 * the same PM domain, so it is not necessary to use locking here.
+	 *
+	 * At this point suspended_count == 0 means this routing is being run
+	 * for the first time for the given domain in the present cycle.
 	 */
-	genpd-&amp;gt;status = GPD_STATE_POWER_OFF;
-	if (genpd-&amp;gt;suspend_power_off) {
+	if (genpd-&amp;gt;suspended_count++ == 0) {
 		/*
-		 * The boot kernel might put the domain into the power on state,
-		 * so make sure it really is powered off.
+		 * The boot kernel might put the domain into arbitrary state,
+		 * so make sure it is powered off.
 		 */
+		genpd-&amp;gt;status = GPD_STATE_POWER_OFF;
 		if (genpd-&amp;gt;power_off)
 			genpd-&amp;gt;power_off(genpd);
-		return 0;
 	}
 
+	if (genpd-&amp;gt;suspend_power_off)
+		return 0;
+
 	pm_genpd_poweron(genpd);
-	genpd-&amp;gt;suspended_count--;
 
 	return genpd_start_dev(genpd, dev);
 }
@@ -1623,7 +1629,6 @@ void pm_genpd_init(struct generic_pm_dom
 	genpd-&amp;gt;poweroff_task = NULL;
 	genpd-&amp;gt;resume_count = 0;
 	genpd-&amp;gt;device_count = 0;
-	genpd-&amp;gt;suspended_count = 0;
 	genpd-&amp;gt;max_off_time_ns = -1;
 	genpd-&amp;gt;domain.ops.runtime_suspend = pm_genpd_runtime_suspend;
 	genpd-&amp;gt;domain.ops.runtime_resume = pm_genpd_runtime_resume;

--
To unsubscribe from this list: send the line &amp;quot;unsubscribe linux-kernel&amp;quot; in
the body of a message to &amp;#109;&amp;#97;&amp;#106;&amp;#111;&amp;#114;&amp;#100;&amp;#111;&amp;#109;&amp;#111;&amp;#64;&amp;#118;&amp;#103;&amp;#101;&amp;#114;&amp;#46;&amp;#107;&amp;#101;&amp;#114;&amp;#110;&amp;#101;&amp;#108;&amp;#46;&amp;#111;&amp;#114;&amp;#103;
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/</description>
        <link>http://www.serverphorums.com/read.php?12,460960,460960#msg-460960</link>
        <lastBuildDate>Sat, 25 May 2013 05:32:45 +0200</lastBuildDate>
        <generator>Phorum 5.2.18</generator>
        <item>
            <guid>http://www.serverphorums.com/read.php?12,460960,463293#msg-463293</guid>
            <title>Re: [Replacement][PATCH 2/6] PM / Domains: Fix hibernation restore of devices, v2</title>
            <link>http://www.serverphorums.com/read.php?12,460960,463293#msg-463293</link>
            <description><![CDATA[ On Thu, Mar 15, 2012 at 10:00:09PM +0100, Rafael J. Wysocki wrote:<br />
&gt; On Thursday, March 15, 2012, Simon Horman wrote:<br />
&gt; &gt; On Tue, Mar 13, 2012 at 10:32:42PM +0100, Rafael J. Wysocki wrote:<br />
&gt; &gt; &gt; On Tuesday, March 13, 2012, Rafael J. Wysocki wrote:<br />
&gt; &gt; &gt; &gt; From: Rafael J. Wysocki &lt;rjw@sisk.pl&gt;<br />
&gt; &gt; &gt; &gt; <br />
&gt; &gt; &gt; &gt; During resume from hibernation pm_genpd_restore_noirq() has to<br />
&gt; &gt; &gt; &gt; deal with software state left by pm_genpd_suspend_noirq() and<br />
&gt; &gt; &gt; &gt; unknown hardware state (the boot kernel may leave all PM domains and<br />
&gt; &gt; &gt; &gt; devices in arbitrary states).  For this reason, make it attempt to<br />
&gt; &gt; &gt; &gt; power cycle each domain when before resuming its first device to<br />
&gt; &gt; &gt; &gt; possibly get rid of any unwanted hardware state that may interfere<br />
&gt; &gt; &gt; &gt; with genpd_start_dev() later on.<br />
&gt; &gt; &gt; &gt; <br />
&gt; &gt; &gt; &gt; Signed-off-by: Rafael J. Wysocki &lt;rjw@sisk.pl&gt;<br />
&gt; &gt; &gt; <br />
&gt; &gt; &gt; I realized that this wasn't a good idea because of patch [3/6] (we<br />
&gt; &gt; &gt; can't power cycle domains containing &quot;always on&quot; devices), so I<br />
&gt; &gt; &gt; decided to only fix the really broken things in pm_genpd_restore_noirq().<br />
&gt; &gt; &gt; <br />
&gt; &gt; &gt; Of course, patch [3/6] also needs to be updated on top of the below to<br />
&gt; &gt; &gt; avoid starting &quot;always on&quot; devices in pm_genpd_restore_noirq() (it has<br />
&gt; &gt; &gt; to assume that they will be &quot;always on&quot; in the boot kernel too, but that<br />
&gt; &gt; &gt; seems to be a reasonable expectation).<br />
&gt; &gt; &gt; <br />
&gt; &gt; &gt; Please note that those changes only affect resume from hibernation, so<br />
&gt; &gt; &gt; they don't invalidate the testing that has already been carried out.<br />
&gt; &gt; <br />
&gt; &gt; Hi Rafael,<br />
&gt; &gt; <br />
&gt; &gt; sorry for such a naeive question, but if I was to test<br />
&gt; &gt; hibernate on the Mackerel how would I achieve resume?<br />
&gt; &gt; Is there a button I should press?<br />
&gt; <br />
&gt; Hibernation is not supported on Mackerel at the moment, so you'd need to add<br />
&gt; some platform hooks first.  Then, you'd need some persistent storage with<br />
&gt; a swap patrition (or swap file at least) to save the image.  You'd need<br />
&gt; to point your kernel to the image storage using the resume= and resume_offset=<br />
&gt; command line switches.  Then, you should be able to create an image and the<br />
&gt; kernel would look for it automatically on the next boot.<br />
&gt; <br />
&gt; Still, I'm not sure if doing all that at this point is worth the effort.<br />
<br />
Point taken.<br />
--<br />
To unsubscribe from this list: send the line &quot;unsubscribe linux-kernel&quot; in<br />
the body of a message to <a href="mailto:&#109;&#97;&#106;&#111;&#114;&#100;&#111;&#109;&#111;&#64;&#118;&#103;&#101;&#114;&#46;&#107;&#101;&#114;&#110;&#101;&#108;&#46;&#111;&#114;&#103;">&#109;&#97;&#106;&#111;&#114;&#100;&#111;&#109;&#111;&#64;&#118;&#103;&#101;&#114;&#46;&#107;&#101;&#114;&#110;&#101;&#108;&#46;&#111;&#114;&#103;</a><br />
More majordomo info at  <a href="http://vger.kernel.org/majordomo-info.html" target="_blank"  rel="nofollow">http://vger.kernel.org/majordomo-info.html</a><br />
Please read the FAQ at  <a href="http://www.tux.org/lkml/" target="_blank"  rel="nofollow">http://www.tux.org/lkml/</a>]]></description>
            <dc:creator>Simon Horman</dc:creator>
            <category>Linux Kernel</category>
            <pubDate>Fri, 16 Mar 2012 01:10:02 +0100</pubDate>
        </item>
        <item>
            <guid>http://www.serverphorums.com/read.php?12,460960,463180#msg-463180</guid>
            <title>Re: [Replacement][PATCH 2/6] PM / Domains: Fix hibernation restore of devices, v2</title>
            <link>http://www.serverphorums.com/read.php?12,460960,463180#msg-463180</link>
            <description><![CDATA[ On Thursday, March 15, 2012, Simon Horman wrote:<br />
&gt; On Tue, Mar 13, 2012 at 10:32:42PM +0100, Rafael J. Wysocki wrote:<br />
&gt; &gt; On Tuesday, March 13, 2012, Rafael J. Wysocki wrote:<br />
&gt; &gt; &gt; From: Rafael J. Wysocki &lt;rjw@sisk.pl&gt;<br />
&gt; &gt; &gt; <br />
&gt; &gt; &gt; During resume from hibernation pm_genpd_restore_noirq() has to<br />
&gt; &gt; &gt; deal with software state left by pm_genpd_suspend_noirq() and<br />
&gt; &gt; &gt; unknown hardware state (the boot kernel may leave all PM domains and<br />
&gt; &gt; &gt; devices in arbitrary states).  For this reason, make it attempt to<br />
&gt; &gt; &gt; power cycle each domain when before resuming its first device to<br />
&gt; &gt; &gt; possibly get rid of any unwanted hardware state that may interfere<br />
&gt; &gt; &gt; with genpd_start_dev() later on.<br />
&gt; &gt; &gt; <br />
&gt; &gt; &gt; Signed-off-by: Rafael J. Wysocki &lt;rjw@sisk.pl&gt;<br />
&gt; &gt; <br />
&gt; &gt; I realized that this wasn't a good idea because of patch [3/6] (we<br />
&gt; &gt; can't power cycle domains containing &quot;always on&quot; devices), so I<br />
&gt; &gt; decided to only fix the really broken things in pm_genpd_restore_noirq().<br />
&gt; &gt; <br />
&gt; &gt; Of course, patch [3/6] also needs to be updated on top of the below to<br />
&gt; &gt; avoid starting &quot;always on&quot; devices in pm_genpd_restore_noirq() (it has<br />
&gt; &gt; to assume that they will be &quot;always on&quot; in the boot kernel too, but that<br />
&gt; &gt; seems to be a reasonable expectation).<br />
&gt; &gt; <br />
&gt; &gt; Please note that those changes only affect resume from hibernation, so<br />
&gt; &gt; they don't invalidate the testing that has already been carried out.<br />
&gt; <br />
&gt; Hi Rafael,<br />
&gt; <br />
&gt; sorry for such a naeive question, but if I was to test<br />
&gt; hibernate on the Mackerel how would I achieve resume?<br />
&gt; Is there a button I should press?<br />
<br />
Hibernation is not supported on Mackerel at the moment, so you'd need to add<br />
some platform hooks first.  Then, you'd need some persistent storage with<br />
a swap patrition (or swap file at least) to save the image.  You'd need<br />
to point your kernel to the image storage using the resume= and resume_offset=<br />
command line switches.  Then, you should be able to create an image and the<br />
kernel would look for it automatically on the next boot.<br />
<br />
Still, I'm not sure if doing all that at this point is worth the effort.<br />
<br />
Thanks,<br />
Rafael<br />
--<br />
To unsubscribe from this list: send the line &quot;unsubscribe linux-kernel&quot; in<br />
the body of a message to <a href="mailto:&#109;&#97;&#106;&#111;&#114;&#100;&#111;&#109;&#111;&#64;&#118;&#103;&#101;&#114;&#46;&#107;&#101;&#114;&#110;&#101;&#108;&#46;&#111;&#114;&#103;">&#109;&#97;&#106;&#111;&#114;&#100;&#111;&#109;&#111;&#64;&#118;&#103;&#101;&#114;&#46;&#107;&#101;&#114;&#110;&#101;&#108;&#46;&#111;&#114;&#103;</a><br />
More majordomo info at  <a href="http://vger.kernel.org/majordomo-info.html" target="_blank"  rel="nofollow">http://vger.kernel.org/majordomo-info.html</a><br />
Please read the FAQ at  <a href="http://www.tux.org/lkml/" target="_blank"  rel="nofollow">http://www.tux.org/lkml/</a>]]></description>
            <dc:creator>Rafael J. Wysocki</dc:creator>
            <category>Linux Kernel</category>
            <pubDate>Thu, 15 Mar 2012 22:00:02 +0100</pubDate>
        </item>
        <item>
            <guid>http://www.serverphorums.com/read.php?12,460960,462690#msg-462690</guid>
            <title>Re: [Replacement][PATCH 2/6] PM / Domains: Fix hibernation restore of devices, v2</title>
            <link>http://www.serverphorums.com/read.php?12,460960,462690#msg-462690</link>
            <description><![CDATA[ On Tue, Mar 13, 2012 at 10:32:42PM +0100, Rafael J. Wysocki wrote:<br />
&gt; On Tuesday, March 13, 2012, Rafael J. Wysocki wrote:<br />
&gt; &gt; From: Rafael J. Wysocki &lt;rjw@sisk.pl&gt;<br />
&gt; &gt; <br />
&gt; &gt; During resume from hibernation pm_genpd_restore_noirq() has to<br />
&gt; &gt; deal with software state left by pm_genpd_suspend_noirq() and<br />
&gt; &gt; unknown hardware state (the boot kernel may leave all PM domains and<br />
&gt; &gt; devices in arbitrary states).  For this reason, make it attempt to<br />
&gt; &gt; power cycle each domain when before resuming its first device to<br />
&gt; &gt; possibly get rid of any unwanted hardware state that may interfere<br />
&gt; &gt; with genpd_start_dev() later on.<br />
&gt; &gt; <br />
&gt; &gt; Signed-off-by: Rafael J. Wysocki &lt;rjw@sisk.pl&gt;<br />
&gt; <br />
&gt; I realized that this wasn't a good idea because of patch [3/6] (we<br />
&gt; can't power cycle domains containing &quot;always on&quot; devices), so I<br />
&gt; decided to only fix the really broken things in pm_genpd_restore_noirq().<br />
&gt; <br />
&gt; Of course, patch [3/6] also needs to be updated on top of the below to<br />
&gt; avoid starting &quot;always on&quot; devices in pm_genpd_restore_noirq() (it has<br />
&gt; to assume that they will be &quot;always on&quot; in the boot kernel too, but that<br />
&gt; seems to be a reasonable expectation).<br />
&gt; <br />
&gt; Please note that those changes only affect resume from hibernation, so<br />
&gt; they don't invalidate the testing that has already been carried out.<br />
<br />
Hi Rafael,<br />
<br />
sorry for such a naeive question, but if I was to test<br />
hibernate on the Mackerel how would I achieve resume?<br />
Is there a button I should press?<br />
--<br />
To unsubscribe from this list: send the line &quot;unsubscribe linux-kernel&quot; in<br />
the body of a message to <a href="mailto:&#109;&#97;&#106;&#111;&#114;&#100;&#111;&#109;&#111;&#64;&#118;&#103;&#101;&#114;&#46;&#107;&#101;&#114;&#110;&#101;&#108;&#46;&#111;&#114;&#103;">&#109;&#97;&#106;&#111;&#114;&#100;&#111;&#109;&#111;&#64;&#118;&#103;&#101;&#114;&#46;&#107;&#101;&#114;&#110;&#101;&#108;&#46;&#111;&#114;&#103;</a><br />
More majordomo info at  <a href="http://vger.kernel.org/majordomo-info.html" target="_blank"  rel="nofollow">http://vger.kernel.org/majordomo-info.html</a><br />
Please read the FAQ at  <a href="http://www.tux.org/lkml/" target="_blank"  rel="nofollow">http://www.tux.org/lkml/</a>]]></description>
            <dc:creator>Simon Horman</dc:creator>
            <category>Linux Kernel</category>
            <pubDate>Thu, 15 Mar 2012 10:50:02 +0100</pubDate>
        </item>
        <item>
            <guid>http://www.serverphorums.com/read.php?12,460960,461746#msg-461746</guid>
            <title>[Replacement][PATCH 2/6] PM / Domains: Fix hibernation restore of devices, v2</title>
            <link>http://www.serverphorums.com/read.php?12,460960,461746#msg-461746</link>
            <description><![CDATA[ On Tuesday, March 13, 2012, Rafael J. Wysocki wrote:<br />
&gt; From: Rafael J. Wysocki &lt;rjw@sisk.pl&gt;<br />
&gt; <br />
&gt; During resume from hibernation pm_genpd_restore_noirq() has to<br />
&gt; deal with software state left by pm_genpd_suspend_noirq() and<br />
&gt; unknown hardware state (the boot kernel may leave all PM domains and<br />
&gt; devices in arbitrary states).  For this reason, make it attempt to<br />
&gt; power cycle each domain when before resuming its first device to<br />
&gt; possibly get rid of any unwanted hardware state that may interfere<br />
&gt; with genpd_start_dev() later on.<br />
&gt; <br />
&gt; Signed-off-by: Rafael J. Wysocki &lt;rjw@sisk.pl&gt;<br />
<br />
I realized that this wasn't a good idea because of patch [3/6] (we<br />
can't power cycle domains containing &quot;always on&quot; devices), so I<br />
decided to only fix the really broken things in pm_genpd_restore_noirq().<br />
<br />
Of course, patch [3/6] also needs to be updated on top of the below to<br />
avoid starting &quot;always on&quot; devices in pm_genpd_restore_noirq() (it has<br />
to assume that they will be &quot;always on&quot; in the boot kernel too, but that<br />
seems to be a reasonable expectation).<br />
<br />
Please note that those changes only affect resume from hibernation, so<br />
they don't invalidate the testing that has already been carried out.<br />
<br />
Thanks,<br />
Rafael<br />
<br />
---<br />
From: Rafael J. Wysocki &lt;rjw@sisk.pl&gt;<br />
Subject: PM / Domains: Fix hibernation restore of devices, v2<br />
<br />
During resume from hibernation pm_genpd_restore_noirq() should only<br />
power off domains whose suspend_power_off flags are set once and<br />
not every time it is called for a device in the given domain.<br />
Moreover, it shouldn't decrement genpd-&gt;suspended_count, because<br />
that field is not touched during device freezing and therefore it is<br />
always equal to 0 when pm_genpd_restore_noirq() runs for the first<br />
device in the given domain.<br />
<br />
This means pm_genpd_restore_noirq() may use genpd-&gt;suspended_count<br />
to determine whether or not it it has been called for the domain in<br />
question already in this cycle (it only needs to increment that<br />
field every time it runs for this purpose) and whether or not it<br />
should check if the domain needs to be powered off.  For that to<br />
work, though, pm_genpd_prepare() has to clear genpd-&gt;suspended_count<br />
when it runs for the first device in the given domain (in which case<br />
that flag need not be cleared during domain initialization).<br />
<br />
Signed-off-by: Rafael J. Wysocki &lt;rjw@sisk.pl&gt;<br />
---<br />
 drivers/base/power/domain.c |   31 +++++++++++++++++++++----------<br />
 1 file changed, 21 insertions(+), 10 deletions(-)<br />
<br />
Index: linux/drivers/base/power/domain.c<br />
===================================================================<br />
--- linux.orig/drivers/base/power/domain.c<br />
+++ linux/drivers/base/power/domain.c<br />
@@ -764,8 +764,10 @@ static int pm_genpd_prepare(struct devic<br />
 <br />
 	genpd_acquire_lock(genpd);<br />
 <br />
-	if (genpd-&gt;prepared_count++ == 0)<br />
+	if (genpd-&gt;prepared_count++ == 0) {<br />
+		genpd-&gt;suspended_count = 0;<br />
 		genpd-&gt;suspend_power_off = genpd-&gt;status == GPD_STATE_POWER_OFF;<br />
+	}<br />
 <br />
 	genpd_release_lock(genpd);<br />
 <br />
@@ -1097,20 +1099,30 @@ static int pm_genpd_restore_noirq(struct<br />
 	 * Since all of the &quot;noirq&quot; callbacks are executed sequentially, it is<br />
 	 * guaranteed that this function will never run twice in parallel for<br />
 	 * the same PM domain, so it is not necessary to use locking here.<br />
+	 *<br />
+	 * At this point suspended_count == 0 means we are being run for the<br />
+	 * first time for the given domain in the present cycle.<br />
 	 */<br />
-	genpd-&gt;status = GPD_STATE_POWER_OFF;<br />
-	if (genpd-&gt;suspend_power_off) {<br />
+	if (genpd-&gt;suspended_count++ == 0) {<br />
 		/*<br />
-		 * The boot kernel might put the domain into the power on state,<br />
-		 * so make sure it really is powered off.<br />
+		 * The boot kernel might put the domain into arbitrary state,<br />
+		 * so make it appear as powered off to pm_genpd_poweron(), so<br />
+		 * that it tries to power it on in case it was really off.<br />
 		 */<br />
-		if (genpd-&gt;power_off)<br />
-			genpd-&gt;power_off(genpd);<br />
-		return 0;<br />
+		genpd-&gt;status = GPD_STATE_POWER_OFF;<br />
+		if (genpd-&gt;suspend_power_off) {<br />
+			/*<br />
+			 * If the domain was off before the hibernation, make<br />
+			 * sure it will be off going forward.<br />
+			 */<br />
+			if (genpd-&gt;power_off)<br />
+				genpd-&gt;power_off(genpd);<br />
+<br />
+			return 0;<br />
+		}<br />
 	}<br />
 <br />
 	pm_genpd_poweron(genpd);<br />
-	genpd-&gt;suspended_count--;<br />
 <br />
 	return genpd_start_dev(genpd, dev);<br />
 }<br />
@@ -1617,7 +1629,6 @@ void pm_genpd_init(struct generic_pm_dom<br />
 	genpd-&gt;poweroff_task = NULL;<br />
 	genpd-&gt;resume_count = 0;<br />
 	genpd-&gt;device_count = 0;<br />
-	genpd-&gt;suspended_count = 0;<br />
 	genpd-&gt;max_off_time_ns = -1;<br />
 	genpd-&gt;domain.ops.runtime_suspend = pm_genpd_runtime_suspend;<br />
 	genpd-&gt;domain.ops.runtime_resume = pm_genpd_runtime_resume;<br />
--<br />
To unsubscribe from this list: send the line &quot;unsubscribe linux-kernel&quot; in<br />
the body of a message to <a href="mailto:&#109;&#97;&#106;&#111;&#114;&#100;&#111;&#109;&#111;&#64;&#118;&#103;&#101;&#114;&#46;&#107;&#101;&#114;&#110;&#101;&#108;&#46;&#111;&#114;&#103;">&#109;&#97;&#106;&#111;&#114;&#100;&#111;&#109;&#111;&#64;&#118;&#103;&#101;&#114;&#46;&#107;&#101;&#114;&#110;&#101;&#108;&#46;&#111;&#114;&#103;</a><br />
More majordomo info at  <a href="http://vger.kernel.org/majordomo-info.html" target="_blank"  rel="nofollow">http://vger.kernel.org/majordomo-info.html</a><br />
Please read the FAQ at  <a href="http://www.tux.org/lkml/" target="_blank"  rel="nofollow">http://www.tux.org/lkml/</a>]]></description>
            <dc:creator>Rafael J. Wysocki</dc:creator>
            <category>Linux Kernel</category>
            <pubDate>Tue, 13 Mar 2012 22:30:02 +0100</pubDate>
        </item>
        <item>
            <guid>http://www.serverphorums.com/read.php?12,460960,460960#msg-460960</guid>
            <title>[PATCH 2/6] PM / Domains: Fix hibernation restore of devices</title>
            <link>http://www.serverphorums.com/read.php?12,460960,460960#msg-460960</link>
            <description><![CDATA[ From: Rafael J. Wysocki &lt;rjw@sisk.pl&gt;<br />
<br />
During resume from hibernation pm_genpd_restore_noirq() has to<br />
deal with software state left by pm_genpd_suspend_noirq() and<br />
unknown hardware state (the boot kernel may leave all PM domains and<br />
devices in arbitrary states).  For this reason, make it attempt to<br />
power cycle each domain when before resuming its first device to<br />
possibly get rid of any unwanted hardware state that may interfere<br />
with genpd_start_dev() later on.<br />
<br />
Signed-off-by: Rafael J. Wysocki &lt;rjw@sisk.pl&gt;<br />
---<br />
 drivers/base/power/domain.c |   21 +++++++++++++--------<br />
 1 file changed, 13 insertions(+), 8 deletions(-)<br />
<br />
Index: linux/drivers/base/power/domain.c<br />
===================================================================<br />
--- linux.orig/drivers/base/power/domain.c<br />
+++ linux/drivers/base/power/domain.c<br />
@@ -770,8 +770,10 @@ static int pm_genpd_prepare(struct devic<br />
 <br />
 	genpd_acquire_lock(genpd);<br />
 <br />
-	if (genpd-&gt;prepared_count++ == 0)<br />
+	if (genpd-&gt;prepared_count++ == 0) {<br />
+		genpd-&gt;suspended_count = 0;<br />
 		genpd-&gt;suspend_power_off = genpd-&gt;status == GPD_STATE_POWER_OFF;<br />
+	}<br />
 <br />
 	genpd_release_lock(genpd);<br />
 <br />
@@ -1103,20 +1105,24 @@ static int pm_genpd_restore_noirq(struct<br />
 	 * Since all of the &quot;noirq&quot; callbacks are executed sequentially, it is<br />
 	 * guaranteed that this function will never run twice in parallel for<br />
 	 * the same PM domain, so it is not necessary to use locking here.<br />
+	 *<br />
+	 * At this point suspended_count == 0 means this routing is being run<br />
+	 * for the first time for the given domain in the present cycle.<br />
 	 */<br />
-	genpd-&gt;status = GPD_STATE_POWER_OFF;<br />
-	if (genpd-&gt;suspend_power_off) {<br />
+	if (genpd-&gt;suspended_count++ == 0) {<br />
 		/*<br />
-		 * The boot kernel might put the domain into the power on state,<br />
-		 * so make sure it really is powered off.<br />
+		 * The boot kernel might put the domain into arbitrary state,<br />
+		 * so make sure it is powered off.<br />
 		 */<br />
+		genpd-&gt;status = GPD_STATE_POWER_OFF;<br />
 		if (genpd-&gt;power_off)<br />
 			genpd-&gt;power_off(genpd);<br />
-		return 0;<br />
 	}<br />
 <br />
+	if (genpd-&gt;suspend_power_off)<br />
+		return 0;<br />
+<br />
 	pm_genpd_poweron(genpd);<br />
-	genpd-&gt;suspended_count--;<br />
 <br />
 	return genpd_start_dev(genpd, dev);<br />
 }<br />
@@ -1623,7 +1629,6 @@ void pm_genpd_init(struct generic_pm_dom<br />
 	genpd-&gt;poweroff_task = NULL;<br />
 	genpd-&gt;resume_count = 0;<br />
 	genpd-&gt;device_count = 0;<br />
-	genpd-&gt;suspended_count = 0;<br />
 	genpd-&gt;max_off_time_ns = -1;<br />
 	genpd-&gt;domain.ops.runtime_suspend = pm_genpd_runtime_suspend;<br />
 	genpd-&gt;domain.ops.runtime_resume = pm_genpd_runtime_resume;<br />
<br />
--<br />
To unsubscribe from this list: send the line &quot;unsubscribe linux-kernel&quot; in<br />
the body of a message to <a href="mailto:&#109;&#97;&#106;&#111;&#114;&#100;&#111;&#109;&#111;&#64;&#118;&#103;&#101;&#114;&#46;&#107;&#101;&#114;&#110;&#101;&#108;&#46;&#111;&#114;&#103;">&#109;&#97;&#106;&#111;&#114;&#100;&#111;&#109;&#111;&#64;&#118;&#103;&#101;&#114;&#46;&#107;&#101;&#114;&#110;&#101;&#108;&#46;&#111;&#114;&#103;</a><br />
More majordomo info at  <a href="http://vger.kernel.org/majordomo-info.html" target="_blank"  rel="nofollow">http://vger.kernel.org/majordomo-info.html</a><br />
Please read the FAQ at  <a href="http://www.tux.org/lkml/" target="_blank"  rel="nofollow">http://www.tux.org/lkml/</a>]]></description>
            <dc:creator>Rafael J. Wysocki</dc:creator>
            <category>Linux Kernel</category>
            <pubDate>Tue, 13 Mar 2012 01:50:02 +0100</pubDate>
        </item>
    </channel>
</rss>
