Michael Ellerman | cc53291 | 2005-12-04 18:39:43 +1100 | [diff] [blame] | 1 | /* |
| 2 | * Architecture specific (PPC64) functions for kexec based crash dumps. |
| 3 | * |
| 4 | * Copyright (C) 2005, IBM Corp. |
| 5 | * |
| 6 | * Created by: Haren Myneni |
| 7 | * |
| 8 | * This source code is licensed under the GNU General Public License, |
| 9 | * Version 2. See the file COPYING for more details. |
| 10 | * |
| 11 | */ |
| 12 | |
| 13 | #undef DEBUG |
| 14 | |
| 15 | #include <linux/kernel.h> |
| 16 | #include <linux/smp.h> |
| 17 | #include <linux/reboot.h> |
| 18 | #include <linux/kexec.h> |
| 19 | #include <linux/bootmem.h> |
Paul Gortmaker | 66b15db | 2011-05-27 10:46:24 -0400 | [diff] [blame] | 20 | #include <linux/export.h> |
Michael Ellerman | cc53291 | 2005-12-04 18:39:43 +1100 | [diff] [blame] | 21 | #include <linux/crash_dump.h> |
Michael Ellerman | cc53291 | 2005-12-04 18:39:43 +1100 | [diff] [blame] | 22 | #include <linux/delay.h> |
| 23 | #include <linux/elf.h> |
| 24 | #include <linux/elfcore.h> |
| 25 | #include <linux/init.h> |
Michael Ellerman | d6c1a90 | 2006-04-04 13:43:01 +0200 | [diff] [blame] | 26 | #include <linux/irq.h> |
Michael Ellerman | cc53291 | 2005-12-04 18:39:43 +1100 | [diff] [blame] | 27 | #include <linux/types.h> |
Yinghai Lu | 95f72d1 | 2010-07-12 14:36:09 +1000 | [diff] [blame] | 28 | #include <linux/memblock.h> |
Michael Ellerman | cc53291 | 2005-12-04 18:39:43 +1100 | [diff] [blame] | 29 | |
| 30 | #include <asm/processor.h> |
| 31 | #include <asm/machdep.h> |
David Wilder | c0ce7d0 | 2006-06-23 15:29:34 -0700 | [diff] [blame] | 32 | #include <asm/kexec.h> |
Michael Ellerman | cc53291 | 2005-12-04 18:39:43 +1100 | [diff] [blame] | 33 | #include <asm/kdump.h> |
David S. Miller | d9b2b2a | 2008-02-13 16:56:49 -0800 | [diff] [blame] | 34 | #include <asm/prom.h> |
Michael Ellerman | cc53291 | 2005-12-04 18:39:43 +1100 | [diff] [blame] | 35 | #include <asm/firmware.h> |
Haren Myneni | f6cc82f | 2006-01-10 19:25:25 -0800 | [diff] [blame] | 36 | #include <asm/smp.h> |
Michael Neuling | 496b010 | 2008-01-18 15:50:30 +1100 | [diff] [blame] | 37 | #include <asm/system.h> |
| 38 | #include <asm/setjmp.h> |
Michael Ellerman | cc53291 | 2005-12-04 18:39:43 +1100 | [diff] [blame] | 39 | |
| 40 | #ifdef DEBUG |
| 41 | #include <asm/udbg.h> |
| 42 | #define DBG(fmt...) udbg_printf(fmt) |
| 43 | #else |
| 44 | #define DBG(fmt...) |
| 45 | #endif |
| 46 | |
| 47 | /* This keeps a track of which one is crashing cpu. */ |
| 48 | int crashing_cpu = -1; |
David Wilder | c0ce7d0 | 2006-06-23 15:29:34 -0700 | [diff] [blame] | 49 | static cpumask_t cpus_in_crash = CPU_MASK_NONE; |
Michael Ellerman | b6f35b4 | 2006-07-05 14:39:43 +1000 | [diff] [blame] | 50 | cpumask_t cpus_in_sr = CPU_MASK_NONE; |
Michael Ellerman | cc53291 | 2005-12-04 18:39:43 +1100 | [diff] [blame] | 51 | |
Anton Blanchard | 158d5b5e | 2011-01-21 13:43:59 +1100 | [diff] [blame] | 52 | #define CRASH_HANDLER_MAX 3 |
Michael Neuling | 496b010 | 2008-01-18 15:50:30 +1100 | [diff] [blame] | 53 | /* NULL terminated list of shutdown handles */ |
| 54 | static crash_shutdown_t crash_shutdown_handles[CRASH_HANDLER_MAX+1]; |
| 55 | static DEFINE_SPINLOCK(crash_handlers_lock); |
| 56 | |
Michael Ellerman | cc53291 | 2005-12-04 18:39:43 +1100 | [diff] [blame] | 57 | #ifdef CONFIG_SMP |
David Wilder | c0ce7d0 | 2006-06-23 15:29:34 -0700 | [diff] [blame] | 58 | static atomic_t enter_on_soft_reset = ATOMIC_INIT(0); |
Michael Ellerman | cc53291 | 2005-12-04 18:39:43 +1100 | [diff] [blame] | 59 | |
| 60 | void crash_ipi_callback(struct pt_regs *regs) |
| 61 | { |
| 62 | int cpu = smp_processor_id(); |
| 63 | |
Michael Ellerman | cc53291 | 2005-12-04 18:39:43 +1100 | [diff] [blame] | 64 | if (!cpu_online(cpu)) |
| 65 | return; |
| 66 | |
Paul Mackerras | d04c56f | 2006-10-04 16:47:49 +1000 | [diff] [blame] | 67 | hard_irq_disable(); |
KOSAKI Motohiro | 104699c | 2011-04-28 05:07:23 +0000 | [diff] [blame] | 68 | if (!cpumask_test_cpu(cpu, &cpus_in_crash)) |
Magnus Damm | 85916f8 | 2006-12-06 20:40:41 -0800 | [diff] [blame] | 69 | crash_save_cpu(regs, cpu); |
KOSAKI Motohiro | 104699c | 2011-04-28 05:07:23 +0000 | [diff] [blame] | 70 | cpumask_set_cpu(cpu, &cpus_in_crash); |
David Wilder | c0ce7d0 | 2006-06-23 15:29:34 -0700 | [diff] [blame] | 71 | |
| 72 | /* |
| 73 | * Entered via soft-reset - could be the kdump |
| 74 | * process is invoked using soft-reset or user activated |
| 75 | * it if some CPU did not respond to an IPI. |
| 76 | * For soft-reset, the secondary CPU can enter this func |
| 77 | * twice. 1 - using IPI, and 2. soft-reset. |
| 78 | * Tell the kexec CPU that entered via soft-reset and ready |
| 79 | * to go down. |
| 80 | */ |
KOSAKI Motohiro | 104699c | 2011-04-28 05:07:23 +0000 | [diff] [blame] | 81 | if (cpumask_test_cpu(cpu, &cpus_in_sr)) { |
| 82 | cpumask_clear_cpu(cpu, &cpus_in_sr); |
David Wilder | c0ce7d0 | 2006-06-23 15:29:34 -0700 | [diff] [blame] | 83 | atomic_inc(&enter_on_soft_reset); |
| 84 | } |
| 85 | |
| 86 | /* |
| 87 | * Starting the kdump boot. |
| 88 | * This barrier is needed to make sure that all CPUs are stopped. |
| 89 | * If not, soft-reset will be invoked to bring other CPUs. |
| 90 | */ |
KOSAKI Motohiro | 104699c | 2011-04-28 05:07:23 +0000 | [diff] [blame] | 91 | while (!cpumask_test_cpu(crashing_cpu, &cpus_in_crash)) |
David Wilder | c0ce7d0 | 2006-06-23 15:29:34 -0700 | [diff] [blame] | 92 | cpu_relax(); |
| 93 | |
Michael Ellerman | cc53291 | 2005-12-04 18:39:43 +1100 | [diff] [blame] | 94 | if (ppc_md.kexec_cpu_down) |
| 95 | ppc_md.kexec_cpu_down(1, 1); |
Michael Ellerman | b6f35b4 | 2006-07-05 14:39:43 +1000 | [diff] [blame] | 96 | |
| 97 | #ifdef CONFIG_PPC64 |
Michael Ellerman | cc53291 | 2005-12-04 18:39:43 +1100 | [diff] [blame] | 98 | kexec_smp_wait(); |
Michael Ellerman | b6f35b4 | 2006-07-05 14:39:43 +1000 | [diff] [blame] | 99 | #else |
| 100 | for (;;); /* FIXME */ |
| 101 | #endif |
| 102 | |
Michael Ellerman | cc53291 | 2005-12-04 18:39:43 +1100 | [diff] [blame] | 103 | /* NOTREACHED */ |
| 104 | } |
| 105 | |
David Wilder | c0ce7d0 | 2006-06-23 15:29:34 -0700 | [diff] [blame] | 106 | /* |
| 107 | * Wait until all CPUs are entered via soft-reset. |
| 108 | */ |
| 109 | static void crash_soft_reset_check(int cpu) |
| 110 | { |
| 111 | unsigned int ncpus = num_online_cpus() - 1;/* Excluding the panic cpu */ |
| 112 | |
KOSAKI Motohiro | 104699c | 2011-04-28 05:07:23 +0000 | [diff] [blame] | 113 | cpumask_clear_cpu(cpu, &cpus_in_sr); |
David Wilder | c0ce7d0 | 2006-06-23 15:29:34 -0700 | [diff] [blame] | 114 | while (atomic_read(&enter_on_soft_reset) != ncpus) |
| 115 | cpu_relax(); |
| 116 | } |
| 117 | |
| 118 | |
| 119 | static void crash_kexec_prepare_cpus(int cpu) |
Michael Ellerman | cc53291 | 2005-12-04 18:39:43 +1100 | [diff] [blame] | 120 | { |
| 121 | unsigned int msecs; |
| 122 | |
David Wilder | c0ce7d0 | 2006-06-23 15:29:34 -0700 | [diff] [blame] | 123 | unsigned int ncpus = num_online_cpus() - 1;/* Excluding the panic cpu */ |
Michael Ellerman | cc53291 | 2005-12-04 18:39:43 +1100 | [diff] [blame] | 124 | |
| 125 | crash_send_ipi(crash_ipi_callback); |
| 126 | smp_wmb(); |
| 127 | |
| 128 | /* |
Anton Blanchard | 158d5b5e | 2011-01-21 13:43:59 +1100 | [diff] [blame] | 129 | * FIXME: Until we will have the way to stop other CPUs reliably, |
Michael Ellerman | cc53291 | 2005-12-04 18:39:43 +1100 | [diff] [blame] | 130 | * the crash CPU will send an IPI and wait for other CPUs to |
David Wilder | c0ce7d0 | 2006-06-23 15:29:34 -0700 | [diff] [blame] | 131 | * respond. |
Haren Myneni | 01aaed9 | 2006-02-07 15:47:03 -0800 | [diff] [blame] | 132 | * Delay of at least 10 seconds. |
Michael Ellerman | cc53291 | 2005-12-04 18:39:43 +1100 | [diff] [blame] | 133 | */ |
David Wilder | c0ce7d0 | 2006-06-23 15:29:34 -0700 | [diff] [blame] | 134 | printk(KERN_EMERG "Sending IPI to other cpus...\n"); |
Haren Myneni | 01aaed9 | 2006-02-07 15:47:03 -0800 | [diff] [blame] | 135 | msecs = 10000; |
KOSAKI Motohiro | 104699c | 2011-04-28 05:07:23 +0000 | [diff] [blame] | 136 | while ((cpumask_weight(&cpus_in_crash) < ncpus) && (--msecs > 0)) { |
David Wilder | c0ce7d0 | 2006-06-23 15:29:34 -0700 | [diff] [blame] | 137 | cpu_relax(); |
Michael Ellerman | cc53291 | 2005-12-04 18:39:43 +1100 | [diff] [blame] | 138 | mdelay(1); |
| 139 | } |
| 140 | |
| 141 | /* Would it be better to replace the trap vector here? */ |
| 142 | |
| 143 | /* |
| 144 | * FIXME: In case if we do not get all CPUs, one possibility: ask the |
| 145 | * user to do soft reset such that we get all. |
David Wilder | c0ce7d0 | 2006-06-23 15:29:34 -0700 | [diff] [blame] | 146 | * Soft-reset will be used until better mechanism is implemented. |
Michael Ellerman | cc53291 | 2005-12-04 18:39:43 +1100 | [diff] [blame] | 147 | */ |
KOSAKI Motohiro | 104699c | 2011-04-28 05:07:23 +0000 | [diff] [blame] | 148 | if (cpumask_weight(&cpus_in_crash) < ncpus) { |
David Wilder | c0ce7d0 | 2006-06-23 15:29:34 -0700 | [diff] [blame] | 149 | printk(KERN_EMERG "done waiting: %d cpu(s) not responding\n", |
KOSAKI Motohiro | 104699c | 2011-04-28 05:07:23 +0000 | [diff] [blame] | 150 | ncpus - cpumask_weight(&cpus_in_crash)); |
David Wilder | c0ce7d0 | 2006-06-23 15:29:34 -0700 | [diff] [blame] | 151 | printk(KERN_EMERG "Activate soft-reset to stop other cpu(s)\n"); |
KOSAKI Motohiro | 104699c | 2011-04-28 05:07:23 +0000 | [diff] [blame] | 152 | cpumask_clear(&cpus_in_sr); |
David Wilder | c0ce7d0 | 2006-06-23 15:29:34 -0700 | [diff] [blame] | 153 | atomic_set(&enter_on_soft_reset, 0); |
KOSAKI Motohiro | 104699c | 2011-04-28 05:07:23 +0000 | [diff] [blame] | 154 | while (cpumask_weight(&cpus_in_crash) < ncpus) |
David Wilder | c0ce7d0 | 2006-06-23 15:29:34 -0700 | [diff] [blame] | 155 | cpu_relax(); |
| 156 | } |
| 157 | /* |
| 158 | * Make sure all CPUs are entered via soft-reset if the kdump is |
| 159 | * invoked using soft-reset. |
| 160 | */ |
KOSAKI Motohiro | 104699c | 2011-04-28 05:07:23 +0000 | [diff] [blame] | 161 | if (cpumask_test_cpu(cpu, &cpus_in_sr)) |
David Wilder | c0ce7d0 | 2006-06-23 15:29:34 -0700 | [diff] [blame] | 162 | crash_soft_reset_check(cpu); |
Michael Ellerman | cc53291 | 2005-12-04 18:39:43 +1100 | [diff] [blame] | 163 | /* Leave the IPI callback set */ |
| 164 | } |
David Wilder | c0ce7d0 | 2006-06-23 15:29:34 -0700 | [diff] [blame] | 165 | |
| 166 | /* |
| 167 | * This function will be called by secondary cpus or by kexec cpu |
| 168 | * if soft-reset is activated to stop some CPUs. |
| 169 | */ |
| 170 | void crash_kexec_secondary(struct pt_regs *regs) |
| 171 | { |
| 172 | int cpu = smp_processor_id(); |
| 173 | unsigned long flags; |
| 174 | int msecs = 5; |
| 175 | |
| 176 | local_irq_save(flags); |
| 177 | /* Wait 5ms if the kexec CPU is not entered yet. */ |
| 178 | while (crashing_cpu < 0) { |
| 179 | if (--msecs < 0) { |
| 180 | /* |
| 181 | * Either kdump image is not loaded or |
| 182 | * kdump process is not started - Probably xmon |
| 183 | * exited using 'x'(exit and recover) or |
| 184 | * kexec_should_crash() failed for all running tasks. |
| 185 | */ |
KOSAKI Motohiro | 104699c | 2011-04-28 05:07:23 +0000 | [diff] [blame] | 186 | cpumask_clear_cpu(cpu, &cpus_in_sr); |
David Wilder | c0ce7d0 | 2006-06-23 15:29:34 -0700 | [diff] [blame] | 187 | local_irq_restore(flags); |
| 188 | return; |
| 189 | } |
| 190 | mdelay(1); |
| 191 | cpu_relax(); |
| 192 | } |
| 193 | if (cpu == crashing_cpu) { |
| 194 | /* |
| 195 | * Panic CPU will enter this func only via soft-reset. |
| 196 | * Wait until all secondary CPUs entered and |
| 197 | * then start kexec boot. |
| 198 | */ |
| 199 | crash_soft_reset_check(cpu); |
KOSAKI Motohiro | 104699c | 2011-04-28 05:07:23 +0000 | [diff] [blame] | 200 | cpumask_set_cpu(crashing_cpu, &cpus_in_crash); |
David Wilder | c0ce7d0 | 2006-06-23 15:29:34 -0700 | [diff] [blame] | 201 | if (ppc_md.kexec_cpu_down) |
| 202 | ppc_md.kexec_cpu_down(1, 0); |
| 203 | machine_kexec(kexec_crash_image); |
| 204 | /* NOTREACHED */ |
| 205 | } |
| 206 | crash_ipi_callback(regs); |
| 207 | } |
| 208 | |
Paul Gortmaker | 7c7a81b | 2011-04-13 06:30:08 +0000 | [diff] [blame] | 209 | #else /* ! CONFIG_SMP */ |
Paul Gortmaker | 7c7a81b | 2011-04-13 06:30:08 +0000 | [diff] [blame] | 210 | |
David Wilder | c0ce7d0 | 2006-06-23 15:29:34 -0700 | [diff] [blame] | 211 | static void crash_kexec_prepare_cpus(int cpu) |
Michael Ellerman | cc53291 | 2005-12-04 18:39:43 +1100 | [diff] [blame] | 212 | { |
| 213 | /* |
| 214 | * move the secondarys to us so that we can copy |
| 215 | * the new kernel 0-0x100 safely |
| 216 | * |
| 217 | * do this if kexec in setup.c ? |
| 218 | */ |
Michael Ellerman | b6f35b4 | 2006-07-05 14:39:43 +1000 | [diff] [blame] | 219 | #ifdef CONFIG_PPC64 |
Michael Ellerman | cc53291 | 2005-12-04 18:39:43 +1100 | [diff] [blame] | 220 | smp_release_cpus(); |
Michael Ellerman | b6f35b4 | 2006-07-05 14:39:43 +1000 | [diff] [blame] | 221 | #else |
| 222 | /* FIXME */ |
| 223 | #endif |
Michael Ellerman | cc53291 | 2005-12-04 18:39:43 +1100 | [diff] [blame] | 224 | } |
| 225 | |
David Wilder | c0ce7d0 | 2006-06-23 15:29:34 -0700 | [diff] [blame] | 226 | void crash_kexec_secondary(struct pt_regs *regs) |
| 227 | { |
KOSAKI Motohiro | 104699c | 2011-04-28 05:07:23 +0000 | [diff] [blame] | 228 | cpumask_clear(&cpus_in_sr); |
David Wilder | c0ce7d0 | 2006-06-23 15:29:34 -0700 | [diff] [blame] | 229 | } |
Paul Gortmaker | 7c7a81b | 2011-04-13 06:30:08 +0000 | [diff] [blame] | 230 | #endif /* CONFIG_SMP */ |
Michael Ellerman | cc53291 | 2005-12-04 18:39:43 +1100 | [diff] [blame] | 231 | |
Ben Hutchings | 7707e41 | 2011-04-24 15:04:31 +0000 | [diff] [blame] | 232 | /* wait for all the CPUs to hit real mode but timeout if they don't come in */ |
| 233 | #if defined(CONFIG_SMP) && defined(CONFIG_PPC_STD_MMU_64) |
| 234 | static void crash_kexec_wait_realmode(int cpu) |
| 235 | { |
| 236 | unsigned int msecs; |
| 237 | int i; |
| 238 | |
| 239 | msecs = 10000; |
Milton Miller | bd9e5ee | 2011-05-10 19:28:41 +0000 | [diff] [blame] | 240 | for (i=0; i < nr_cpu_ids && msecs > 0; i++) { |
Ben Hutchings | 7707e41 | 2011-04-24 15:04:31 +0000 | [diff] [blame] | 241 | if (i == cpu) |
| 242 | continue; |
| 243 | |
| 244 | while (paca[i].kexec_state < KEXEC_STATE_REAL_MODE) { |
| 245 | barrier(); |
Michael Neuling | 63f21a5 | 2011-07-04 20:40:10 +0000 | [diff] [blame] | 246 | if (!cpu_possible(i) || !cpu_online(i) || (msecs <= 0)) |
Ben Hutchings | 7707e41 | 2011-04-24 15:04:31 +0000 | [diff] [blame] | 247 | break; |
Ben Hutchings | 7707e41 | 2011-04-24 15:04:31 +0000 | [diff] [blame] | 248 | msecs--; |
| 249 | mdelay(1); |
| 250 | } |
| 251 | } |
| 252 | mb(); |
| 253 | } |
| 254 | #else |
| 255 | static inline void crash_kexec_wait_realmode(int cpu) {} |
| 256 | #endif /* CONFIG_SMP && CONFIG_PPC_STD_MMU_64 */ |
| 257 | |
Michael Neuling | 496b010 | 2008-01-18 15:50:30 +1100 | [diff] [blame] | 258 | /* |
| 259 | * Register a function to be called on shutdown. Only use this if you |
| 260 | * can't reset your device in the second kernel. |
| 261 | */ |
| 262 | int crash_shutdown_register(crash_shutdown_t handler) |
| 263 | { |
| 264 | unsigned int i, rc; |
| 265 | |
| 266 | spin_lock(&crash_handlers_lock); |
| 267 | for (i = 0 ; i < CRASH_HANDLER_MAX; i++) |
| 268 | if (!crash_shutdown_handles[i]) { |
| 269 | /* Insert handle at first empty entry */ |
| 270 | crash_shutdown_handles[i] = handler; |
| 271 | rc = 0; |
| 272 | break; |
| 273 | } |
| 274 | |
| 275 | if (i == CRASH_HANDLER_MAX) { |
| 276 | printk(KERN_ERR "Crash shutdown handles full, " |
| 277 | "not registered.\n"); |
| 278 | rc = 1; |
| 279 | } |
| 280 | |
| 281 | spin_unlock(&crash_handlers_lock); |
| 282 | return rc; |
| 283 | } |
| 284 | EXPORT_SYMBOL(crash_shutdown_register); |
| 285 | |
| 286 | int crash_shutdown_unregister(crash_shutdown_t handler) |
| 287 | { |
| 288 | unsigned int i, rc; |
| 289 | |
| 290 | spin_lock(&crash_handlers_lock); |
| 291 | for (i = 0 ; i < CRASH_HANDLER_MAX; i++) |
| 292 | if (crash_shutdown_handles[i] == handler) |
| 293 | break; |
| 294 | |
| 295 | if (i == CRASH_HANDLER_MAX) { |
| 296 | printk(KERN_ERR "Crash shutdown handle not found\n"); |
| 297 | rc = 1; |
| 298 | } else { |
| 299 | /* Shift handles down */ |
| 300 | for (; crash_shutdown_handles[i]; i++) |
| 301 | crash_shutdown_handles[i] = |
| 302 | crash_shutdown_handles[i+1]; |
| 303 | rc = 0; |
| 304 | } |
| 305 | |
| 306 | spin_unlock(&crash_handlers_lock); |
| 307 | return rc; |
| 308 | } |
| 309 | EXPORT_SYMBOL(crash_shutdown_unregister); |
| 310 | |
| 311 | static unsigned long crash_shutdown_buf[JMP_BUF_LEN]; |
Anton Blanchard | 0644079 | 2010-05-10 16:25:51 +0000 | [diff] [blame] | 312 | static int crash_shutdown_cpu = -1; |
Michael Neuling | 496b010 | 2008-01-18 15:50:30 +1100 | [diff] [blame] | 313 | |
| 314 | static int handle_fault(struct pt_regs *regs) |
| 315 | { |
Anton Blanchard | 0644079 | 2010-05-10 16:25:51 +0000 | [diff] [blame] | 316 | if (crash_shutdown_cpu == smp_processor_id()) |
| 317 | longjmp(crash_shutdown_buf, 1); |
Michael Neuling | 496b010 | 2008-01-18 15:50:30 +1100 | [diff] [blame] | 318 | return 0; |
| 319 | } |
| 320 | |
Michael Ellerman | cc53291 | 2005-12-04 18:39:43 +1100 | [diff] [blame] | 321 | void default_machine_crash_shutdown(struct pt_regs *regs) |
| 322 | { |
Michael Neuling | 496b010 | 2008-01-18 15:50:30 +1100 | [diff] [blame] | 323 | unsigned int i; |
| 324 | int (*old_handler)(struct pt_regs *regs); |
| 325 | |
Michael Ellerman | d6c1a90 | 2006-04-04 13:43:01 +0200 | [diff] [blame] | 326 | |
Michael Ellerman | cc53291 | 2005-12-04 18:39:43 +1100 | [diff] [blame] | 327 | /* |
| 328 | * This function is only called after the system |
Lee Revell | f18190b | 2006-06-26 18:30:00 +0200 | [diff] [blame] | 329 | * has panicked or is otherwise in a critical state. |
Michael Ellerman | cc53291 | 2005-12-04 18:39:43 +1100 | [diff] [blame] | 330 | * The minimum amount of code to allow a kexec'd kernel |
| 331 | * to run successfully needs to happen here. |
| 332 | * |
| 333 | * In practice this means stopping other cpus in |
| 334 | * an SMP system. |
| 335 | * The kernel is broken so disable interrupts. |
| 336 | */ |
Paul Mackerras | d04c56f | 2006-10-04 16:47:49 +1000 | [diff] [blame] | 337 | hard_irq_disable(); |
Michael Ellerman | cc53291 | 2005-12-04 18:39:43 +1100 | [diff] [blame] | 338 | |
Anton Blanchard | 249ec22 | 2010-08-02 20:39:41 +0000 | [diff] [blame] | 339 | /* |
| 340 | * Make a note of crashing cpu. Will be used in machine_kexec |
| 341 | * such that another IPI will not be sent. |
| 342 | */ |
| 343 | crashing_cpu = smp_processor_id(); |
| 344 | crash_save_cpu(regs, crashing_cpu); |
| 345 | crash_kexec_prepare_cpus(crashing_cpu); |
KOSAKI Motohiro | 104699c | 2011-04-28 05:07:23 +0000 | [diff] [blame] | 346 | cpumask_set_cpu(crashing_cpu, &cpus_in_crash); |
Anton Blanchard | 249ec22 | 2010-08-02 20:39:41 +0000 | [diff] [blame] | 347 | crash_kexec_wait_realmode(crashing_cpu); |
Anton Blanchard | 249ec22 | 2010-08-02 20:39:41 +0000 | [diff] [blame] | 348 | |
Matthew McClintock | c71635d | 2010-09-16 17:58:23 -0500 | [diff] [blame] | 349 | machine_kexec_mask_interrupts(); |
Michael Ellerman | d6c1a90 | 2006-04-04 13:43:01 +0200 | [diff] [blame] | 350 | |
Michael Ellerman | cc53291 | 2005-12-04 18:39:43 +1100 | [diff] [blame] | 351 | /* |
Michael Neuling | 496b010 | 2008-01-18 15:50:30 +1100 | [diff] [blame] | 352 | * Call registered shutdown routines savely. Swap out |
| 353 | * __debugger_fault_handler, and replace on exit. |
| 354 | */ |
| 355 | old_handler = __debugger_fault_handler; |
| 356 | __debugger_fault_handler = handle_fault; |
Anton Blanchard | 0644079 | 2010-05-10 16:25:51 +0000 | [diff] [blame] | 357 | crash_shutdown_cpu = smp_processor_id(); |
Michael Neuling | 496b010 | 2008-01-18 15:50:30 +1100 | [diff] [blame] | 358 | for (i = 0; crash_shutdown_handles[i]; i++) { |
| 359 | if (setjmp(crash_shutdown_buf) == 0) { |
| 360 | /* |
| 361 | * Insert syncs and delay to ensure |
| 362 | * instructions in the dangerous region don't |
| 363 | * leak away from this protected region. |
| 364 | */ |
| 365 | asm volatile("sync; isync"); |
| 366 | /* dangerous region */ |
| 367 | crash_shutdown_handles[i](); |
| 368 | asm volatile("sync; isync"); |
| 369 | } |
| 370 | } |
Anton Blanchard | 0644079 | 2010-05-10 16:25:51 +0000 | [diff] [blame] | 371 | crash_shutdown_cpu = -1; |
Michael Neuling | 496b010 | 2008-01-18 15:50:30 +1100 | [diff] [blame] | 372 | __debugger_fault_handler = old_handler; |
| 373 | |
David Wilder | c0ce7d0 | 2006-06-23 15:29:34 -0700 | [diff] [blame] | 374 | if (ppc_md.kexec_cpu_down) |
| 375 | ppc_md.kexec_cpu_down(1, 0); |
Michael Ellerman | cc53291 | 2005-12-04 18:39:43 +1100 | [diff] [blame] | 376 | } |