static bool suspend_again(bool *drivers_resumed) { const struct list_head *irqs; struct list_head unfinished; *drivers_resumed = false; /* If a platform suspend_again handler is defined, when it decides to * not suspend again, this takes precedence over drivers. If a * platform's suspend_again callback returns true, then we proceed to * check the drivers as well. */ if (suspend_ops->suspend_again && !suspend_ops->suspend_again()) return false; /* TODO: resume only the drivers associated with the wakeup interrupts! */ dpm_resume_end(PMSG_RESUME); *drivers_resumed = true; /* Thaw kernel threads opportunistically, to allow get_wakeup_reasons * to block while the wakeup interrupt list is being assembled. Calls * schedule() internally. */ thaw_kernel_threads(); /* Look for a match between the wakeup reasons and the registered * callbacks. Don't bother thawing the kernel threads if a match is * not found. */ irqs = get_wakeup_reasons(msecs_to_jiffies(100), &unfinished); if (!suspend_again_match(irqs, &unfinished)) return false; if (suspend_again_consensus() && !freeze_kernel_threads()) { clear_wakeup_reasons(); dpm_suspend_start(PMSG_SUSPEND); *drivers_resumed = false; return true; } return false; }
/** * hibernation_snapshot - Quiesce devices and create a hibernation image. * @platform_mode: If set, use platform driver to prepare for the transition. * * This routine must be called with pm_mutex held. */ int hibernation_snapshot(int platform_mode) { pm_message_t msg; int error; pm_suspend_clear_flags(); error = platform_begin(platform_mode); if (error) goto Close; /* Preallocate image memory before shutting down devices. */ error = hibernate_preallocate_memory(); if (error) goto Close; error = freeze_kernel_threads(); if (error) goto Cleanup; if (hibernation_test(TEST_FREEZER)) { /* * Indicate to the caller that we are returning due to a * successful freezer test. */ freezer_test_done = true; goto Thaw; } error = dpm_prepare(PMSG_FREEZE); if (error) { dpm_complete(PMSG_RECOVER); goto Thaw; } suspend_console(); pm_restrict_gfp_mask(); error = dpm_suspend(PMSG_FREEZE); if (error || hibernation_test(TEST_DEVICES)) platform_recover(platform_mode); else error = create_image(platform_mode); /* * In the case that we call create_image() above, the control * returns here (1) after the image has been created or the * image creation has failed and (2) after a successful restore. */ /* We may need to release the preallocated image pages here. */ if (error || !in_suspend) swsusp_free(); msg = in_suspend ? (error ? PMSG_RECOVER : PMSG_THAW) : PMSG_RESTORE; dpm_resume(msg); if (error || !in_suspend) pm_restore_gfp_mask(); resume_console(); dpm_complete(msg); Close: platform_end(platform_mode); return error; Thaw: thaw_kernel_threads(); Cleanup: swsusp_free(); goto Close; }
static void do_suspend(void) { int err; struct suspend_info si; shutting_down = SHUTDOWN_SUSPEND; err = freeze_processes(); if (err) { pr_err("%s: freeze processes failed %d\n", __func__, err); goto out; } err = freeze_kernel_threads(); if (err) { pr_err("%s: freeze kernel threads failed %d\n", __func__, err); goto out_thaw; } err = dpm_suspend_start(PMSG_FREEZE); if (err) { pr_err("%s: dpm_suspend_start %d\n", __func__, err); goto out_thaw; } printk(KERN_DEBUG "suspending xenstore...\n"); xs_suspend(); err = dpm_suspend_end(PMSG_FREEZE); if (err) { pr_err("dpm_suspend_end failed: %d\n", err); si.cancelled = 0; goto out_resume; } xen_arch_suspend(); si.cancelled = 1; err = stop_machine(xen_suspend, &si, cpumask_of(0)); /* Resume console as early as possible. */ if (!si.cancelled) xen_console_resume(); raw_notifier_call_chain(&xen_resume_notifier, 0, NULL); dpm_resume_start(si.cancelled ? PMSG_THAW : PMSG_RESTORE); if (err) { pr_err("failed to start xen_suspend: %d\n", err); si.cancelled = 1; } xen_arch_resume(); out_resume: if (!si.cancelled) xs_resume(); else xs_suspend_cancel(); dpm_resume_end(si.cancelled ? PMSG_THAW : PMSG_RESTORE); out_thaw: thaw_processes(); out: shutting_down = SHUTDOWN_INVALID; }
/** * hibernation_snapshot - Quiesce devices and create a hibernation image. * @platform_mode: If set, use platform driver to prepare for the transition. * * This routine must be called with pm_mutex held. */ int hibernation_snapshot(int platform_mode) { pm_message_t msg = PMSG_RECOVER; int error; error = platform_begin(platform_mode); if (error) goto Close; /* Preallocate image memory before shutting down devices. */ error = hibernate_preallocate_memory(); if (error) goto Close; error = freeze_kernel_threads(); if (error) goto Close; error = dpm_prepare(PMSG_FREEZE); if (error) goto Complete_devices; suspend_console(); pm_restrict_gfp_mask(); error = dpm_suspend(PMSG_FREEZE); if (error) goto Recover_platform; if (hibernation_test(TEST_DEVICES)) goto Recover_platform; error = create_image(platform_mode); /* * Control returns here (1) after the image has been created or the * image creation has failed and (2) after a successful restore. */ Resume_devices: /* We may need to release the preallocated image pages here. */ if (error || !in_suspend) swsusp_free(); msg = in_suspend ? (error ? PMSG_RECOVER : PMSG_THAW) : PMSG_RESTORE; dpm_resume(msg); if (error || !in_suspend) pm_restore_gfp_mask(); resume_console(); Complete_devices: dpm_complete(msg); Close: platform_end(platform_mode); return error; Recover_platform: platform_recover(platform_mode); goto Resume_devices; }