2 * Copyright (C) 1996-2000 Russell King - Converted to ARM.
3 * Original Copyright (C) 1995 Linus Torvalds
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2 as
7 * published by the Free Software Foundation.
9 #include <linux/console.h>
10 #include <linux/cpu.h>
11 #include <linux/delay.h>
12 #include <linux/reboot.h>
14 #include <asm/cacheflush.h>
15 #include <asm/idmap.h>
19 typedef void (*phys_reset_t)(unsigned long);
22 * Function pointers to optional machine specific functions
24 void (*arm_pm_restart)(enum reboot_mode reboot_mode, const char *cmd);
25 void (*pm_power_off)(void);
26 EXPORT_SYMBOL(pm_power_off);
29 * A temporary stack to use for CPU reset. This is static so that we
30 * don't clobber it with the identity mapping. When running with this
31 * stack, any references to the current task *will not work* so you
32 * should really do as little as possible before jumping to your reset
35 static u64 soft_restart_stack[16];
37 static void __soft_restart(void *addr)
39 phys_reset_t phys_reset;
41 /* Take out a flat memory mapping. */
42 setup_mm_for_reboot();
44 /* Clean and invalidate caches */
47 /* Turn off caching */
50 /* Push out any further dirty data, and ensure cache is empty */
53 /* Switch to the identity mapping. */
54 phys_reset = (phys_reset_t)(unsigned long)virt_to_idmap(cpu_reset);
55 phys_reset((unsigned long)addr);
57 /* Should never get here. */
61 void _soft_restart(unsigned long addr, bool disable_l2)
63 u64 *stack = soft_restart_stack + ARRAY_SIZE(soft_restart_stack);
65 /* Disable interrupts first */
66 raw_local_irq_disable();
69 /* Disable the L2 if we're the last man standing. */
73 /* Change to the new stack and continue with the reset. */
74 call_with_stack(__soft_restart, (void *)addr, (void *)stack);
76 /* Should never get here. */
80 void soft_restart(unsigned long addr)
82 _soft_restart(addr, num_online_cpus() == 1);
86 * Called by kexec, immediately prior to machine_kexec().
88 * This must completely disable all secondary CPUs; simply causing those CPUs
89 * to execute e.g. a RAM-based pin loop is not sufficient. This allows the
90 * kexec'd kernel to use any and all RAM as it sees fit, without having to
91 * avoid any code or data used by any SW CPU pin loop. The CPU hotplug
92 * functionality embodied in disable_nonboot_cpus() to achieve this.
94 void machine_shutdown(void)
96 disable_nonboot_cpus();
100 * Halting simply requires that the secondary CPUs stop performing any
101 * activity (executing tasks, handling interrupts). smp_send_stop()
104 void machine_halt(void)
114 * Power-off simply requires that the secondary CPUs stop performing any
115 * activity (executing tasks, handling interrupts). smp_send_stop()
116 * achieves this. When the system power is turned off, it will take all CPUs
119 void machine_power_off(void)
128 #ifdef CONFIG_ARM_FLUSH_CONSOLE_ON_RESTART
129 void arm_machine_flush_console(void)
132 pr_emerg("Restarting %s\n", linux_banner);
133 if (console_trylock()) {
141 if (!console_trylock())
142 pr_emerg("arm_restart: Console was locked! Busting\n");
144 pr_emerg("arm_restart: Console was locked!\n");
148 void arm_machine_flush_console(void)
154 * Restart requires that the secondary CPUs stop performing any activity
155 * while the primary CPU resets the system. Systems with a single CPU can
156 * use soft_restart() as their machine descriptor's .restart hook, since that
157 * will cause the only available CPU to reset. Systems with multiple CPUs must
158 * provide a HW restart implementation, to ensure that all CPUs reset at once.
159 * This is required so that any code running after reset on the primary CPU
160 * doesn't have to co-ordinate with other CPUs to ensure they aren't still
161 * executing pre-reset code, and using RAM that the primary CPU's code wishes
162 * to use. Implementing such co-ordination would be essentially impossible.
164 void machine_restart(char *cmd)
169 /* Flush the console to make sure all the relevant messages make it
170 * out to the console drivers */
171 arm_machine_flush_console();
174 arm_pm_restart(reboot_mode, cmd);
176 do_kernel_restart(cmd);
178 /* Give a grace period for failure to restart of 1s */
181 /* Whoops - the platform was unable to reboot. Tell the user! */
182 printk("Reboot failed -- System halted\n");