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/interrupt.h>
13 #include <trace/events/power.h>
15 static LIST_HEAD(syscore_ops_list
);
16 static DEFINE_MUTEX(syscore_ops_lock
);
19 * register_syscore_ops - Register a set of system core operations.
20 * @ops: System core operations to register.
22 void register_syscore_ops(struct syscore_ops
*ops
)
24 mutex_lock(&syscore_ops_lock
);
25 list_add_tail(&ops
->node
, &syscore_ops_list
);
26 mutex_unlock(&syscore_ops_lock
);
28 EXPORT_SYMBOL_GPL(register_syscore_ops
);
31 * unregister_syscore_ops - Unregister a set of system core operations.
32 * @ops: System core operations to unregister.
34 void unregister_syscore_ops(struct syscore_ops
*ops
)
36 mutex_lock(&syscore_ops_lock
);
38 mutex_unlock(&syscore_ops_lock
);
40 EXPORT_SYMBOL_GPL(unregister_syscore_ops
);
42 #ifdef CONFIG_PM_SLEEP
44 * syscore_suspend - Execute all the registered system core suspend callbacks.
46 * This function is executed with one CPU on-line and disabled interrupts.
48 int syscore_suspend(void)
50 struct syscore_ops
*ops
;
53 trace_suspend_resume(TPS("syscore_suspend"), 0, true);
54 pr_debug("Checking wakeup interrupts\n");
56 /* Return error code if there are any wakeup interrupts pending. */
57 ret
= check_wakeup_irqs();
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 pr_err("PM: System core suspend callback %pF failed.\n", ops
->suspend
);
81 list_for_each_entry_continue(ops
, &syscore_ops_list
, node
)
87 EXPORT_SYMBOL_GPL(syscore_suspend
);
90 * syscore_resume - Execute all the registered system core resume callbacks.
92 * This function is executed with one CPU on-line and disabled interrupts.
94 void syscore_resume(void)
96 struct syscore_ops
*ops
;
98 trace_suspend_resume(TPS("syscore_resume"), 0, true);
99 WARN_ONCE(!irqs_disabled(),
100 "Interrupts enabled before system core resume.\n");
102 list_for_each_entry(ops
, &syscore_ops_list
, node
)
105 pr_info("PM: Calling %pF\n", ops
->resume
);
107 WARN_ONCE(!irqs_disabled(),
108 "Interrupts enabled after %pF\n", ops
->resume
);
110 trace_suspend_resume(TPS("syscore_resume"), 0, false);
112 EXPORT_SYMBOL_GPL(syscore_resume
);
113 #endif /* CONFIG_PM_SLEEP */
116 * syscore_shutdown - Execute all the registered system core shutdown callbacks.
118 void syscore_shutdown(void)
120 struct syscore_ops
*ops
;
122 mutex_lock(&syscore_ops_lock
);
124 list_for_each_entry_reverse(ops
, &syscore_ops_list
, node
)
127 pr_info("PM: Calling %pF\n", ops
->shutdown
);
131 mutex_unlock(&syscore_ops_lock
);