blob: d704df89a54673914b6b1b84885136bad2917517 [file] [log] [blame]
Russell King045ab942015-04-01 17:02:45 +01001/*
2 * Copyright (C) 1996-2000 Russell King - Converted to ARM.
3 * Original Copyright (C) 1995 Linus Torvalds
4 *
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.
8 */
Dima Zavin24446622011-08-23 15:56:50 -07009#include <linux/console.h>
Russell King045ab942015-04-01 17:02:45 +010010#include <linux/cpu.h>
11#include <linux/delay.h>
12#include <linux/reboot.h>
13
14#include <asm/cacheflush.h>
15#include <asm/idmap.h>
16
17#include "reboot.h"
18
19typedef void (*phys_reset_t)(unsigned long);
20
21/*
22 * Function pointers to optional machine specific functions
23 */
24void (*arm_pm_restart)(enum reboot_mode reboot_mode, const char *cmd);
25void (*pm_power_off)(void);
26EXPORT_SYMBOL(pm_power_off);
27
28/*
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
33 * code.
34 */
35static u64 soft_restart_stack[16];
36
37static void __soft_restart(void *addr)
38{
39 phys_reset_t phys_reset;
40
41 /* Take out a flat memory mapping. */
42 setup_mm_for_reboot();
43
44 /* Clean and invalidate caches */
45 flush_cache_all();
46
47 /* Turn off caching */
48 cpu_proc_fin();
49
50 /* Push out any further dirty data, and ensure cache is empty */
51 flush_cache_all();
52
53 /* Switch to the identity mapping. */
Russell King28410292016-01-11 17:15:58 +000054 phys_reset = (phys_reset_t)virt_to_idmap(cpu_reset);
Russell King045ab942015-04-01 17:02:45 +010055 phys_reset((unsigned long)addr);
56
57 /* Should never get here. */
58 BUG();
59}
60
61void _soft_restart(unsigned long addr, bool disable_l2)
62{
63 u64 *stack = soft_restart_stack + ARRAY_SIZE(soft_restart_stack);
64
65 /* Disable interrupts first */
66 raw_local_irq_disable();
67 local_fiq_disable();
68
69 /* Disable the L2 if we're the last man standing. */
70 if (disable_l2)
71 outer_disable();
72
73 /* Change to the new stack and continue with the reset. */
74 call_with_stack(__soft_restart, (void *)addr, (void *)stack);
75
76 /* Should never get here. */
77 BUG();
78}
79
80void soft_restart(unsigned long addr)
81{
82 _soft_restart(addr, num_online_cpus() == 1);
83}
84
85/*
86 * Called by kexec, immediately prior to machine_kexec().
87 *
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.
93 */
94void machine_shutdown(void)
95{
96 disable_nonboot_cpus();
97}
98
99/*
100 * Halting simply requires that the secondary CPUs stop performing any
101 * activity (executing tasks, handling interrupts). smp_send_stop()
102 * achieves this.
103 */
104void machine_halt(void)
105{
106 local_irq_disable();
107 smp_send_stop();
Russell King045ab942015-04-01 17:02:45 +0100108 while (1);
109}
110
111/*
112 * Power-off simply requires that the secondary CPUs stop performing any
113 * activity (executing tasks, handling interrupts). smp_send_stop()
114 * achieves this. When the system power is turned off, it will take all CPUs
115 * with it.
116 */
117void machine_power_off(void)
118{
119 local_irq_disable();
120 smp_send_stop();
121
122 if (pm_power_off)
123 pm_power_off();
124}
125
Dima Zavin24446622011-08-23 15:56:50 -0700126#ifdef CONFIG_ARM_FLUSH_CONSOLE_ON_RESTART
127void arm_machine_flush_console(void)
128{
129 printk("\n");
130 pr_emerg("Restarting %s\n", linux_banner);
131 if (console_trylock()) {
132 console_unlock();
133 return;
134 }
135
136 mdelay(50);
137
138 local_irq_disable();
139 if (!console_trylock())
140 pr_emerg("arm_restart: Console was locked! Busting\n");
141 else
142 pr_emerg("arm_restart: Console was locked!\n");
143 console_unlock();
144}
145#else
146void arm_machine_flush_console(void)
147{
148}
149#endif
150
Russell King045ab942015-04-01 17:02:45 +0100151/*
152 * Restart requires that the secondary CPUs stop performing any activity
153 * while the primary CPU resets the system. Systems with a single CPU can
154 * use soft_restart() as their machine descriptor's .restart hook, since that
155 * will cause the only available CPU to reset. Systems with multiple CPUs must
156 * provide a HW restart implementation, to ensure that all CPUs reset at once.
157 * This is required so that any code running after reset on the primary CPU
158 * doesn't have to co-ordinate with other CPUs to ensure they aren't still
159 * executing pre-reset code, and using RAM that the primary CPU's code wishes
160 * to use. Implementing such co-ordination would be essentially impossible.
161 */
162void machine_restart(char *cmd)
163{
164 local_irq_disable();
165 smp_send_stop();
166
Dima Zavin24446622011-08-23 15:56:50 -0700167 /* Flush the console to make sure all the relevant messages make it
168 * out to the console drivers */
169 arm_machine_flush_console();
170
Russell King045ab942015-04-01 17:02:45 +0100171 if (arm_pm_restart)
172 arm_pm_restart(reboot_mode, cmd);
173 else
174 do_kernel_restart(cmd);
175
176 /* Give a grace period for failure to restart of 1s */
177 mdelay(1000);
178
179 /* Whoops - the platform was unable to reboot. Tell the user! */
180 printk("Reboot failed -- System halted\n");
Russell King045ab942015-04-01 17:02:45 +0100181 while (1);
182}