[Suspend2][ 13/16] [Suspend2] do_resume routine.

From: Nigel Cunningham
Date: Mon Jun 26 2006 - 19:42:18 EST


Main routine for seeing if we can resume - and doing it!

Signed-off-by: Nigel Cunningham <nigel@xxxxxxxxxxxx>

kernel/power/suspend.c | 98 ++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 98 insertions(+), 0 deletions(-)

diff --git a/kernel/power/suspend.c b/kernel/power/suspend.c
index f7138c1..0f751d1 100644
--- a/kernel/power/suspend.c
+++ b/kernel/power/suspend.c
@@ -910,3 +910,101 @@ static __init int core_load(void)
return 0;
}

+/*
+ * Called from init kernel_thread.
+ * We check if we have an image and if so we try to resume.
+ * We also start ksuspendd if configuration looks right.
+ */
+int suspend_resume(void)
+{
+ int read_image_result = 0;
+
+ if (sizeof(swp_entry_t) != sizeof(long)) {
+ printk(KERN_WARNING name_suspend
+ "The size of swp_entry_t != size of long. "
+ "Please report this!\n");
+ return 1;
+ }
+
+ if (!resume2_file[0])
+ printk(KERN_WARNING name_suspend
+ "You need to use a resume2= command line parameter to "
+ "tell Suspend2 where to look for an image.\n");
+
+ suspend_activate_storage(0);
+
+ if (!(test_suspend_state(SUSPEND_RESUME_DEVICE_OK)) &&
+ !suspend_attempt_to_parse_resume_device()) {
+ /*
+ * Without a usable storage device we can do nothing -
+ * even if noresume is given
+ */
+
+ if (!suspend_num_writers)
+ printk(KERN_ALERT name_suspend
+ "No writers have been registered.\n");
+ else
+ printk(KERN_ALERT name_suspend
+ "Missing or invalid storage location "
+ "(resume2= parameter). Please correct and "
+ "rerun lilo (or equivalent) before "
+ "suspending.\n");
+ suspend_deactivate_storage(0);
+ return 1;
+ }
+
+ suspend_orig_mem_free = real_nr_free_pages();
+
+ read_image_result = read_pageset1(); /* non fatal error ignored */
+
+ if (test_suspend_state(SUSPEND_NORESUME_SPECIFIED))
+ printk(KERN_WARNING name_suspend "Resuming disabled as requested.\n");
+
+ suspend_deactivate_storage(0);
+
+ if (read_image_result)
+ return 1;
+
+ suspend2_running = 1;
+
+ suspend_atomic_restore();
+
+ BUG();
+
+ return 0;
+}
+
+/* -- Functions for kickstarting a suspend or resume --- */
+
+/*
+ * Check if we have an image and if so try to resume.
+ */
+void __suspend_try_resume(void)
+{
+ set_suspend_state(SUSPEND_TRYING_TO_RESUME);
+
+ clear_suspend_state(SUSPEND_RESUME_NOT_DONE);
+
+ suspend_resume();
+
+ clear_suspend_state(SUSPEND_IGNORE_LOGLEVEL);
+ clear_suspend_state(SUSPEND_TRYING_TO_RESUME);
+}
+
+/* Wrapper for when called from init/do_mounts.c */
+void suspend2_try_resume(void)
+{
+ if (suspend_start_anything(0))
+ return;
+
+ __suspend_try_resume();
+
+ /*
+ * For initramfs, we have to clear the boot time
+ * flag after trying to resume
+ */
+ clear_suspend_state(SUSPEND_BOOT_TIME);
+
+ suspend_finish_anything(0);
+}
+

--
Nigel Cunningham nigel at suspend2 dot net
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/