]> www.pilppa.org Git - linux-2.6-omap-h63xx.git/blobdiff - kernel/power/disk.c
PM: Introduce PM_EVENT_HIBERNATE callback state
[linux-2.6-omap-h63xx.git] / kernel / power / disk.c
index 3e24a200f1d493bc0d61a531614722673148dccc..14a656cdc6523bf64d9c5b64c3a628529b56bab5 100644 (file)
@@ -26,7 +26,7 @@
 
 
 static int noresume = 0;
-char resume_file[256] = CONFIG_PM_STD_PARTITION;
+static char resume_file[256] = CONFIG_PM_STD_PARTITION;
 dev_t swsusp_resume_device;
 sector_t swsusp_resume_block;
 
@@ -54,8 +54,8 @@ static struct platform_hibernation_ops *hibernation_ops;
 
 void hibernation_set_ops(struct platform_hibernation_ops *ops)
 {
-       if (ops && !(ops->start && ops->pre_snapshot && ops->finish
-           && ops->prepare && ops->enter && ops->pre_restore
+       if (ops && !(ops->begin && ops->end &&  ops->pre_snapshot
+           && ops->prepare && ops->finish && ops->enter && ops->pre_restore
            && ops->restore_cleanup)) {
                WARN_ON(1);
                return;
@@ -100,14 +100,25 @@ static int hibernation_test(int level) { return 0; }
 #endif /* !CONFIG_PM_DEBUG */
 
 /**
- *     platform_start - tell the platform driver that we're starting
+ *     platform_begin - tell the platform driver that we're starting
  *     hibernation
  */
 
-static int platform_start(int platform_mode)
+static int platform_begin(int platform_mode)
 {
        return (platform_mode && hibernation_ops) ?
-               hibernation_ops->start() : 0;
+               hibernation_ops->begin() : 0;
+}
+
+/**
+ *     platform_end - tell the platform driver that we've entered the
+ *     working state
+ */
+
+static void platform_end(int platform_mode)
+{
+       if (platform_mode && hibernation_ops)
+               hibernation_ops->end();
 }
 
 /**
@@ -174,7 +185,7 @@ static void platform_restore_cleanup(int platform_mode)
  *     reappears in this routine after a restore.
  */
 
-int create_image(int platform_mode)
+static int create_image(int platform_mode)
 {
        int error;
 
@@ -191,8 +202,8 @@ int create_image(int platform_mode)
         */
        error = device_power_down(PMSG_FREEZE);
        if (error) {
-               printk(KERN_ERR "Some devices failed to power down, "
-                       KERN_ERR "aborting suspend\n");
+               printk(KERN_ERR "PM: Some devices failed to power down, "
+                       "aborting hibernation\n");
                goto Enable_irqs;
        }
 
@@ -203,7 +214,8 @@ int create_image(int platform_mode)
        save_processor_state();
        error = swsusp_arch_suspend();
        if (error)
-               printk(KERN_ERR "Error %d while creating the image\n", error);
+               printk(KERN_ERR "PM: Error %d creating hibernation image\n",
+                       error);
        /* Restore control flow magically appears here */
        restore_processor_state();
        if (!in_suspend)
@@ -236,9 +248,9 @@ int hibernation_snapshot(int platform_mode)
        if (error)
                return error;
 
-       error = platform_start(platform_mode);
+       error = platform_begin(platform_mode);
        if (error)
-               return error;
+               goto Close;
 
        suspend_console();
        error = device_suspend(PMSG_FREEZE);
@@ -271,6 +283,8 @@ int hibernation_snapshot(int platform_mode)
        device_resume();
  Resume_console:
        resume_console();
+ Close:
+       platform_end(platform_mode);
        return error;
 }
 
@@ -289,7 +303,7 @@ static int resume_target_kernel(void)
        local_irq_disable();
        error = device_power_down(PMSG_PRETHAW);
        if (error) {
-               printk(KERN_ERR "Some devices failed to power down, "
+               printk(KERN_ERR "PM: Some devices failed to power down, "
                        "aborting resume\n");
                goto Enable_irqs;
        }
@@ -372,12 +386,12 @@ int hibernation_platform_enter(void)
         * hibernation_ops->finish() before saving the image, so we should let
         * the firmware know that we're going to enter the sleep state after all
         */
-       error = hibernation_ops->start();
+       error = hibernation_ops->begin();
        if (error)
-               return error;
+               goto Close;
 
        suspend_console();
-       error = device_suspend(PMSG_SUSPEND);
+       error = device_suspend(PMSG_HIBERNATE);
        if (error)
                goto Resume_console;
 
@@ -390,7 +404,7 @@ int hibernation_platform_enter(void)
                goto Finish;
 
        local_irq_disable();
-       error = device_power_down(PMSG_SUSPEND);
+       error = device_power_down(PMSG_HIBERNATE);
        if (!error) {
                hibernation_ops->enter();
                /* We should never get here */
@@ -408,6 +422,8 @@ int hibernation_platform_enter(void)
        device_resume();
  Resume_console:
        resume_console();
+ Close:
+       hibernation_ops->end();
        return error;
 }
 
@@ -438,24 +454,17 @@ static void power_down(void)
         * Valid image is on the disk, if we continue we risk serious data
         * corruption after resume.
         */
-       printk(KERN_CRIT "Please power me down manually\n");
+       printk(KERN_CRIT "PM: Please power down manually\n");
        while(1);
 }
 
-static void unprepare_processes(void)
-{
-       thaw_processes();
-       pm_restore_console();
-}
-
 static int prepare_processes(void)
 {
        int error = 0;
 
-       pm_prepare_console();
        if (freeze_processes()) {
                error = -EBUSY;
-               unprepare_processes();
+               thaw_processes();
        }
        return error;
 }
@@ -475,6 +484,7 @@ int hibernate(void)
                goto Unlock;
        }
 
+       pm_prepare_console();
        error = pm_notifier_call_chain(PM_HIBERNATION_PREPARE);
        if (error)
                goto Exit;
@@ -484,7 +494,7 @@ int hibernate(void)
        if (error)
                goto Exit;
 
-       printk("Syncing filesystems ... ");
+       printk(KERN_INFO "PM: Syncing filesystems ... ");
        sys_sync();
        printk("done.\n");
 
@@ -514,11 +524,12 @@ int hibernate(void)
                swsusp_free();
        }
  Thaw:
-       unprepare_processes();
+       thaw_processes();
  Finish:
        free_basic_memory_bitmaps();
  Exit:
        pm_notifier_call_chain(PM_POST_HIBERNATION);
+       pm_restore_console();
        atomic_inc(&snapshot_device_available);
  Unlock:
        mutex_unlock(&pm_mutex);
@@ -560,10 +571,11 @@ static int software_resume(void)
                        return -ENOENT;
                }
                swsusp_resume_device = name_to_dev_t(resume_file);
-               pr_debug("swsusp: Resume From Partition %s\n", resume_file);
+               pr_debug("PM: Resume from partition %s\n", resume_file);
        } else {
-               pr_debug("swsusp: Resume From Partition %d:%d\n",
-                        MAJOR(swsusp_resume_device), MINOR(swsusp_resume_device));
+               pr_debug("PM: Resume from partition %d:%d\n",
+                               MAJOR(swsusp_resume_device),
+                               MINOR(swsusp_resume_device));
        }
 
        if (noresume) {
@@ -575,7 +587,7 @@ static int software_resume(void)
                return 0;
        }
 
-       pr_debug("PM: Checking swsusp image.\n");
+       pr_debug("PM: Checking hibernation image.\n");
        error = swsusp_check();
        if (error)
                goto Unlock;
@@ -586,6 +598,7 @@ static int software_resume(void)
                goto Unlock;
        }
 
+       pm_prepare_console();
        error = pm_notifier_call_chain(PM_RESTORE_PREPARE);
        if (error)
                goto Finish;
@@ -601,7 +614,7 @@ static int software_resume(void)
                goto Done;
        }
 
-       pr_debug("PM: Reading swsusp image.\n");
+       pr_debug("PM: Reading hibernation image.\n");
 
        error = swsusp_read(&flags);
        if (!error)
@@ -609,11 +622,12 @@ static int software_resume(void)
 
        printk(KERN_ERR "PM: Restore failed, recovering.\n");
        swsusp_free();
-       unprepare_processes();
+       thaw_processes();
  Done:
        free_basic_memory_bitmaps();
  Finish:
        pm_notifier_call_chain(PM_POST_RESTORE);
+       pm_restore_console();
        atomic_inc(&snapshot_device_available);
        /* For success case, the suspend path will release the lock */
  Unlock:
@@ -728,7 +742,7 @@ static ssize_t disk_store(struct kobject *kobj, struct kobj_attribute *attr,
                error = -EINVAL;
 
        if (!error)
-               pr_debug("PM: suspend-to-disk mode set to '%s'\n",
+               pr_debug("PM: Hibernation mode set to '%s'\n",
                         hibernation_modes[mode]);
        mutex_unlock(&pm_mutex);
        return error ? error : n;
@@ -760,7 +774,7 @@ static ssize_t resume_store(struct kobject *kobj, struct kobj_attribute *attr,
        mutex_lock(&pm_mutex);
        swsusp_resume_device = res;
        mutex_unlock(&pm_mutex);
-       printk("Attempting manual resume\n");
+       printk(KERN_INFO "PM: Starting manual resume from disk\n");
        noresume = 0;
        software_resume();
        ret = n;