]> www.pilppa.org Git - linux-2.6-omap-h63xx.git/blobdiff - kernel/power/disk.c
Hibernation: Fix comment in disk.c
[linux-2.6-omap-h63xx.git] / kernel / power / disk.c
index b138b431e27135aa7b2716335288069ea00beeee..3e24a200f1d493bc0d61a531614722673148dccc 100644 (file)
@@ -70,6 +70,35 @@ void hibernation_set_ops(struct platform_hibernation_ops *ops)
        mutex_unlock(&pm_mutex);
 }
 
+#ifdef CONFIG_PM_DEBUG
+static void hibernation_debug_sleep(void)
+{
+       printk(KERN_INFO "hibernation debug: Waiting for 5 seconds.\n");
+       mdelay(5000);
+}
+
+static int hibernation_testmode(int mode)
+{
+       if (hibernation_mode == mode) {
+               hibernation_debug_sleep();
+               return 1;
+       }
+       return 0;
+}
+
+static int hibernation_test(int level)
+{
+       if (pm_test_level == level) {
+               hibernation_debug_sleep();
+               return 1;
+       }
+       return 0;
+}
+#else /* !CONFIG_PM_DEBUG */
+static int hibernation_testmode(int mode) { return 0; }
+static int hibernation_test(int level) { return 0; }
+#endif /* !CONFIG_PM_DEBUG */
+
 /**
  *     platform_start - tell the platform driver that we're starting
  *     hibernation
@@ -167,6 +196,10 @@ int create_image(int platform_mode)
                goto Enable_irqs;
        }
 
+       if (hibernation_test(TEST_CORE))
+               goto Power_up;
+
+       in_suspend = 1;
        save_processor_state();
        error = swsusp_arch_suspend();
        if (error)
@@ -175,6 +208,7 @@ int create_image(int platform_mode)
        restore_processor_state();
        if (!in_suspend)
                platform_leave(platform_mode);
+ Power_up:
        /* NOTE:  device_power_up() is just a resume() for devices
         * that suspended with irqs off ... no overall powerup.
         */
@@ -211,30 +245,82 @@ int hibernation_snapshot(int platform_mode)
        if (error)
                goto Resume_console;
 
-       error = platform_pre_snapshot(platform_mode);
-       if (error)
+       if (hibernation_test(TEST_DEVICES))
                goto Resume_devices;
 
+       error = platform_pre_snapshot(platform_mode);
+       if (error || hibernation_test(TEST_PLATFORM))
+               goto Finish;
+
        error = disable_nonboot_cpus();
        if (!error) {
-               if (hibernation_mode != HIBERNATION_TEST) {
-                       in_suspend = 1;
-                       error = create_image(platform_mode);
-                       /* Control returns here after successful restore */
-               } else {
-                       printk("swsusp debug: Waiting for 5 seconds.\n");
-                       mdelay(5000);
-               }
+               if (hibernation_test(TEST_CPUS))
+                       goto Enable_cpus;
+
+               if (hibernation_testmode(HIBERNATION_TEST))
+                       goto Enable_cpus;
+
+               error = create_image(platform_mode);
+               /* Control returns here after successful restore */
        }
+ Enable_cpus:
        enable_nonboot_cpus();
Resume_devices:
Finish:
        platform_finish(platform_mode);
+ Resume_devices:
        device_resume();
  Resume_console:
        resume_console();
        return error;
 }
 
+/**
+ *     resume_target_kernel - prepare devices that need to be suspended with
+ *     interrupts off, restore the contents of highmem that have not been
+ *     restored yet from the image and run the low level code that will restore
+ *     the remaining contents of memory and switch to the just restored target
+ *     kernel.
+ */
+
+static int resume_target_kernel(void)
+{
+       int error;
+
+       local_irq_disable();
+       error = device_power_down(PMSG_PRETHAW);
+       if (error) {
+               printk(KERN_ERR "Some devices failed to power down, "
+                       "aborting resume\n");
+               goto Enable_irqs;
+       }
+       /* We'll ignore saved state, but this gets preempt count (etc) right */
+       save_processor_state();
+       error = restore_highmem();
+       if (!error) {
+               error = swsusp_arch_resume();
+               /*
+                * The code below is only ever reached in case of a failure.
+                * Otherwise execution continues at place where
+                * swsusp_arch_suspend() was called
+                */
+               BUG_ON(!error);
+               /* This call to restore_highmem() undos the previous one */
+               restore_highmem();
+       }
+       /*
+        * The only reason why swsusp_arch_resume() can fail is memory being
+        * very tight, so we have to free it as soon as we can to avoid
+        * subsequent failures
+        */
+       swsusp_free();
+       restore_processor_state();
+       touch_softlockup_watchdog();
+       device_power_up();
+ Enable_irqs:
+       local_irq_enable();
+       return error;
+}
+
 /**
  *     hibernation_restore - quiesce devices and restore the hibernation
  *     snapshot image.  If successful, control returns in hibernation_snaphot()
@@ -258,7 +344,7 @@ int hibernation_restore(int platform_mode)
        if (!error) {
                error = disable_nonboot_cpus();
                if (!error)
-                       error = swsusp_resume();
+                       error = resume_target_kernel();
                enable_nonboot_cpus();
        }
        platform_restore_cleanup(platform_mode);
@@ -406,11 +492,12 @@ int hibernate(void)
        if (error)
                goto Finish;
 
-       if (hibernation_mode == HIBERNATION_TESTPROC) {
-               printk("swsusp debug: Waiting for 5 seconds.\n");
-               mdelay(5000);
+       if (hibernation_test(TEST_FREEZER))
                goto Thaw;
-       }
+
+       if (hibernation_testmode(HIBERNATION_TESTPROC))
+               goto Thaw;
+
        error = hibernation_snapshot(hibernation_mode == HIBERNATION_PLATFORM);
        if (in_suspend && !error) {
                unsigned int flags = 0;
@@ -481,8 +568,8 @@ static int software_resume(void)
 
        if (noresume) {
                /**
-                * FIXME: If noresume is specified, we need to find the partition
-                * and reset it back to normal swap space.
+                * FIXME: If noresume is specified, we need to find the
+                * partition and reset it back to normal swap space.
                 */
                mutex_unlock(&pm_mutex);
                return 0;
@@ -499,6 +586,10 @@ static int software_resume(void)
                goto Unlock;
        }
 
+       error = pm_notifier_call_chain(PM_RESTORE_PREPARE);
+       if (error)
+               goto Finish;
+
        error = create_basic_memory_bitmaps();
        if (error)
                goto Finish;
@@ -522,6 +613,7 @@ static int software_resume(void)
  Done:
        free_basic_memory_bitmaps();
  Finish:
+       pm_notifier_call_chain(PM_POST_RESTORE);
        atomic_inc(&snapshot_device_available);
        /* For success case, the suspend path will release the lock */
  Unlock: