2 * syscore.c - Execution of system core operations.
4 * Copyright (C) 2011 Rafael J. Wysocki <rjw@sisk.pl>, Novell Inc.
6 * This file is released under the GPLv2.
9 #include <linux/syscore_ops.h>
10 #include <linux/mutex.h>
11 #include <linux/module.h>
12 #include <linux/suspend.h>
13 #include <trace/events/power.h>
14 #include <linux/wakeup_reason.h>
16 static LIST_HEAD(syscore_ops_list);
17 static DEFINE_MUTEX(syscore_ops_lock);
20 * register_syscore_ops - Register a set of system core operations.
21 * @ops: System core operations to register.
23 void register_syscore_ops(struct syscore_ops *ops)
25 mutex_lock(&syscore_ops_lock);
26 list_add_tail(&ops->node, &syscore_ops_list);
27 mutex_unlock(&syscore_ops_lock);
29 EXPORT_SYMBOL_GPL(register_syscore_ops);
32 * unregister_syscore_ops - Unregister a set of system core operations.
33 * @ops: System core operations to unregister.
35 void unregister_syscore_ops(struct syscore_ops *ops)
37 mutex_lock(&syscore_ops_lock);
39 mutex_unlock(&syscore_ops_lock);
41 EXPORT_SYMBOL_GPL(unregister_syscore_ops);
43 #ifdef CONFIG_PM_SLEEP
45 * syscore_suspend - Execute all the registered system core suspend callbacks.
47 * This function is executed with one CPU on-line and disabled interrupts.
49 int syscore_suspend(void)
51 struct syscore_ops *ops;
54 trace_suspend_resume(TPS("syscore_suspend"), 0, true);
55 pr_debug("Checking wakeup interrupts\n");
57 /* Return error code if there are any wakeup interrupts pending. */
58 if (pm_wakeup_pending())
61 WARN_ONCE(!irqs_disabled(),
62 "Interrupts enabled before system core suspend.\n");
64 list_for_each_entry_reverse(ops, &syscore_ops_list, node)
67 pr_info("PM: Calling %pF\n", ops->suspend);
71 WARN_ONCE(!irqs_disabled(),
72 "Interrupts enabled after %pF\n", ops->suspend);
75 trace_suspend_resume(TPS("syscore_suspend"), 0, false);
79 log_suspend_abort_reason("System core suspend callback %pF failed",
81 pr_err("PM: System core suspend callback %pF failed.\n", ops->suspend);
83 list_for_each_entry_continue(ops, &syscore_ops_list, node)
89 EXPORT_SYMBOL_GPL(syscore_suspend);
92 * syscore_resume - Execute all the registered system core resume callbacks.
94 * This function is executed with one CPU on-line and disabled interrupts.
96 void syscore_resume(void)
98 struct syscore_ops *ops;
100 trace_suspend_resume(TPS("syscore_resume"), 0, true);
101 WARN_ONCE(!irqs_disabled(),
102 "Interrupts enabled before system core resume.\n");
104 list_for_each_entry(ops, &syscore_ops_list, node)
107 pr_info("PM: Calling %pF\n", ops->resume);
109 WARN_ONCE(!irqs_disabled(),
110 "Interrupts enabled after %pF\n", ops->resume);
112 trace_suspend_resume(TPS("syscore_resume"), 0, false);
114 EXPORT_SYMBOL_GPL(syscore_resume);
115 #endif /* CONFIG_PM_SLEEP */
118 * syscore_shutdown - Execute all the registered system core shutdown callbacks.
120 void syscore_shutdown(void)
122 struct syscore_ops *ops;
124 mutex_lock(&syscore_ops_lock);
126 list_for_each_entry_reverse(ops, &syscore_ops_list, node)
129 pr_info("PM: Calling %pF\n", ops->shutdown);
133 mutex_unlock(&syscore_ops_lock);