@@ -104,6 +104,87 @@ int unregister_reboot_notifier(struct notifier_block *nb)
104104}
105105EXPORT_SYMBOL (unregister_reboot_notifier );
106106
107+ /*
108+ * Notifier list for kernel code which wants to be called
109+ * to restart the system.
110+ */
111+ static 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+ */
151+ int register_restart_handler (struct notifier_block * nb )
152+ {
153+ return atomic_notifier_chain_register (& restart_handler_list , nb );
154+ }
155+ EXPORT_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+ */
166+ int unregister_restart_handler (struct notifier_block * nb )
167+ {
168+ return atomic_notifier_chain_unregister (& restart_handler_list , nb );
169+ }
170+ EXPORT_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+ */
183+ void do_kernel_restart (char * cmd )
184+ {
185+ atomic_notifier_call_chain (& restart_handler_list , reboot_mode , cmd );
186+ }
187+
107188void migrate_to_reboot_cpu (void )
108189{
109190 /* The boot cpu is always logical cpu 0 */
0 commit comments