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>
13 static LIST_HEAD(syscore_ops_list
);
14 static DEFINE_MUTEX(syscore_ops_lock
);
17 * register_syscore_ops - Register a set of system core operations.
18 * @ops: System core operations to register.
20 void register_syscore_ops(struct syscore_ops
*ops
)
22 mutex_lock(&syscore_ops_lock
);
23 list_add_tail(&ops
->node
, &syscore_ops_list
);
24 mutex_unlock(&syscore_ops_lock
);
26 EXPORT_SYMBOL_GPL(register_syscore_ops
);
29 * unregister_syscore_ops - Unregister a set of system core operations.
30 * @ops: System core operations to unregister.
32 void unregister_syscore_ops(struct syscore_ops
*ops
)
34 mutex_lock(&syscore_ops_lock
);
36 mutex_unlock(&syscore_ops_lock
);
38 EXPORT_SYMBOL_GPL(unregister_syscore_ops
);
40 #ifdef CONFIG_PM_SLEEP
42 * syscore_suspend - Execute all the registered system core suspend callbacks.
44 * This function is executed with one CPU on-line and disabled interrupts.
46 int syscore_suspend(void)
48 struct syscore_ops
*ops
;
51 WARN_ONCE(!irqs_disabled(),
52 "Interrupts enabled before system core suspend.\n");
54 list_for_each_entry_reverse(ops
, &syscore_ops_list
, node
)
57 pr_info("PM: Calling %pF\n", ops
->suspend
);
61 WARN_ONCE(!irqs_disabled(),
62 "Interrupts enabled after %pF\n", ops
->suspend
);
68 pr_err("PM: System core suspend callback %pF failed.\n", ops
->suspend
);
70 list_for_each_entry_continue(ops
, &syscore_ops_list
, node
)
76 EXPORT_SYMBOL_GPL(syscore_suspend
);
79 * syscore_resume - Execute all the registered system core resume callbacks.
81 * This function is executed with one CPU on-line and disabled interrupts.
83 void syscore_resume(void)
85 struct syscore_ops
*ops
;
87 WARN_ONCE(!irqs_disabled(),
88 "Interrupts enabled before system core resume.\n");
90 list_for_each_entry(ops
, &syscore_ops_list
, node
)
93 pr_info("PM: Calling %pF\n", ops
->resume
);
95 WARN_ONCE(!irqs_disabled(),
96 "Interrupts enabled after %pF\n", ops
->resume
);
99 EXPORT_SYMBOL_GPL(syscore_resume
);
100 #endif /* CONFIG_PM_SLEEP */
103 * syscore_shutdown - Execute all the registered system core shutdown callbacks.
105 void syscore_shutdown(void)
107 struct syscore_ops
*ops
;
109 mutex_lock(&syscore_ops_lock
);
111 list_for_each_entry_reverse(ops
, &syscore_ops_list
, node
)
114 pr_info("PM: Calling %pF\n", ops
->shutdown
);
118 mutex_unlock(&syscore_ops_lock
);