1 // SPDX-License-Identifier: GPL-2.0
3 * syscore.c - Execution of system core operations.
5 * Copyright (C) 2011 Rafael J. Wysocki <rjw@sisk.pl>, Novell Inc.
8 #include <linux/syscore_ops.h>
9 #include <linux/mutex.h>
10 #include <linux/module.h>
11 #include <linux/suspend.h>
12 #include <trace/events/power.h>
14 static LIST_HEAD(syscore_ops_list);
15 static DEFINE_MUTEX(syscore_ops_lock);
18 * register_syscore_ops - Register a set of system core operations.
19 * @ops: System core operations to register.
21 void register_syscore_ops(struct syscore_ops *ops)
23 mutex_lock(&syscore_ops_lock);
24 list_add_tail(&ops->node, &syscore_ops_list);
25 mutex_unlock(&syscore_ops_lock);
27 EXPORT_SYMBOL_GPL(register_syscore_ops);
30 * unregister_syscore_ops - Unregister a set of system core operations.
31 * @ops: System core operations to unregister.
33 void unregister_syscore_ops(struct syscore_ops *ops)
35 mutex_lock(&syscore_ops_lock);
37 mutex_unlock(&syscore_ops_lock);
39 EXPORT_SYMBOL_GPL(unregister_syscore_ops);
41 #ifdef CONFIG_PM_SLEEP
43 * syscore_suspend - Execute all the registered system core suspend callbacks.
45 * This function is executed with one CPU on-line and disabled interrupts.
47 int syscore_suspend(void)
49 struct syscore_ops *ops;
52 trace_suspend_resume(TPS("syscore_suspend"), 0, true);
53 pm_pr_dbg("Checking wakeup interrupts\n");
55 /* Return error code if there are any wakeup interrupts pending. */
56 if (pm_wakeup_pending())
59 WARN_ONCE(!irqs_disabled(),
60 "Interrupts enabled before system core suspend.\n");
62 list_for_each_entry_reverse(ops, &syscore_ops_list, node)
64 pm_pr_dbg("Calling %pS\n", ops->suspend);
68 WARN_ONCE(!irqs_disabled(),
69 "Interrupts enabled after %pS\n", ops->suspend);
72 trace_suspend_resume(TPS("syscore_suspend"), 0, false);
76 pr_err("PM: System core suspend callback %pS failed.\n", ops->suspend);
78 list_for_each_entry_continue(ops, &syscore_ops_list, node)
84 EXPORT_SYMBOL_GPL(syscore_suspend);
87 * syscore_resume - Execute all the registered system core resume callbacks.
89 * This function is executed with one CPU on-line and disabled interrupts.
91 void syscore_resume(void)
93 struct syscore_ops *ops;
95 trace_suspend_resume(TPS("syscore_resume"), 0, true);
96 WARN_ONCE(!irqs_disabled(),
97 "Interrupts enabled before system core resume.\n");
99 list_for_each_entry(ops, &syscore_ops_list, node)
101 pm_pr_dbg("Calling %pS\n", ops->resume);
103 WARN_ONCE(!irqs_disabled(),
104 "Interrupts enabled after %pS\n", ops->resume);
106 trace_suspend_resume(TPS("syscore_resume"), 0, false);
108 EXPORT_SYMBOL_GPL(syscore_resume);
109 #endif /* CONFIG_PM_SLEEP */
112 * syscore_shutdown - Execute all the registered system core shutdown callbacks.
114 void syscore_shutdown(void)
116 struct syscore_ops *ops;
118 mutex_lock(&syscore_ops_lock);
120 list_for_each_entry_reverse(ops, &syscore_ops_list, node)
123 pr_info("PM: Calling %pS\n", ops->shutdown);
127 mutex_unlock(&syscore_ops_lock);