aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--include/linux/reboot.h3
-rw-r--r--kernel/reboot.c81
2 files changed, 84 insertions, 0 deletions
diff --git a/include/linux/reboot.h b/include/linux/reboot.h
index 48bf152761c7..67fc8fcdc4b0 100644
--- a/include/linux/reboot.h
+++ b/include/linux/reboot.h
@@ -38,6 +38,9 @@ extern int reboot_force;
38extern int register_reboot_notifier(struct notifier_block *); 38extern int register_reboot_notifier(struct notifier_block *);
39extern int unregister_reboot_notifier(struct notifier_block *); 39extern int unregister_reboot_notifier(struct notifier_block *);
40 40
41extern int register_restart_handler(struct notifier_block *);
42extern int unregister_restart_handler(struct notifier_block *);
43extern void do_kernel_restart(char *cmd);
41 44
42/* 45/*
43 * Architecture-specific implementations of sys_reboot commands. 46 * Architecture-specific implementations of sys_reboot commands.
diff --git a/kernel/reboot.c b/kernel/reboot.c
index a3a9e240fcdb..5925f5ae8dff 100644
--- a/kernel/reboot.c
+++ b/kernel/reboot.c
@@ -104,6 +104,87 @@ int unregister_reboot_notifier(struct notifier_block *nb)
104} 104}
105EXPORT_SYMBOL(unregister_reboot_notifier); 105EXPORT_SYMBOL(unregister_reboot_notifier);
106 106
107/*
108 * Notifier list for kernel code which wants to be called
109 * to restart the system.
110 */
111static ATOMIC_NOTIFIER_HEAD(restart_handler_list);
112
113/**
114 * register_restart_handler - Register function to be called to reset
115 * the system
116 * @nb: Info about handler function to be called
117 * @nb->priority: Handler priority. Handlers should follow the
118 * following guidelines for setting priorities.
119 * 0: Restart handler of last resort,
120 * with limited restart capabilities
121 * 128: Default restart handler; use if no other
122 * restart handler is expected to be available,
123 * and/or if restart functionality is
124 * sufficient to restart the entire system
125 * 255: Highest priority restart handler, will
126 * preempt all other restart handlers
127 *
128 * Registers a function with code to be called to restart the
129 * system.
130 *
131 * Registered functions will be called from machine_restart as last
132 * step of the restart sequence (if the architecture specific
133 * machine_restart function calls do_kernel_restart - see below
134 * for details).
135 * Registered functions are expected to restart the system immediately.
136 * If more than one function is registered, the restart handler priority
137 * selects which function will be called first.
138 *
139 * Restart handlers are expected to be registered from non-architecture
140 * code, typically from drivers. A typical use case would be a system
141 * where restart functionality is provided through a watchdog. Multiple
142 * restart handlers may exist; for example, one restart handler might
143 * restart the entire system, while another only restarts the CPU.
144 * In such cases, the restart handler which only restarts part of the
145 * hardware is expected to register with low priority to ensure that
146 * it only runs if no other means to restart the system is available.
147 *
148 * Currently always returns zero, as atomic_notifier_chain_register()
149 * always returns zero.
150 */
151int register_restart_handler(struct notifier_block *nb)
152{
153 return atomic_notifier_chain_register(&restart_handler_list, nb);
154}
155EXPORT_SYMBOL(register_restart_handler);
156
157/**
158 * unregister_restart_handler - Unregister previously registered
159 * restart handler
160 * @nb: Hook to be unregistered
161 *
162 * Unregisters a previously registered restart handler function.
163 *
164 * Returns zero on success, or %-ENOENT on failure.
165 */
166int unregister_restart_handler(struct notifier_block *nb)
167{
168 return atomic_notifier_chain_unregister(&restart_handler_list, nb);
169}
170EXPORT_SYMBOL(unregister_restart_handler);
171
172/**
173 * do_kernel_restart - Execute kernel restart handler call chain
174 *
175 * Calls functions registered with register_restart_handler.
176 *
177 * Expected to be called from machine_restart as last step of the restart
178 * sequence.
179 *
180 * Restarts the system immediately if a restart handler function has been
181 * registered. Otherwise does nothing.
182 */
183void do_kernel_restart(char *cmd)
184{
185 atomic_notifier_call_chain(&restart_handler_list, reboot_mode, cmd);
186}
187
107void migrate_to_reboot_cpu(void) 188void migrate_to_reboot_cpu(void)
108{ 189{
109 /* The boot cpu is always logical cpu 0 */ 190 /* The boot cpu is always logical cpu 0 */