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 | cc53291 | 2005-12-04 18:39:43 +1100 | [diff] [blame] | 50 | |
Anton Blanchard | 158d5b5e | 2011-01-21 13:43:59 +1100 | [diff] [blame] | 51 | #define CRASH_HANDLER_MAX 3 |
Michael Neuling | 496b010 | 2008-01-18 15:50:30 +1100 | [diff] [blame] | 52 | /* NULL terminated list of shutdown handles */ |
| 53 | static crash_shutdown_t crash_shutdown_handles[CRASH_HANDLER_MAX+1]; |
| 54 | static DEFINE_SPINLOCK(crash_handlers_lock); |
| 55 | |
Anton Blanchard | 07fe0c6 | 2011-11-30 00:23:11 +0000 | [diff] [blame^] | 56 | static unsigned long crash_shutdown_buf[JMP_BUF_LEN]; |
| 57 | static int crash_shutdown_cpu = -1; |
| 58 | |
| 59 | static int handle_fault(struct pt_regs *regs) |
| 60 | { |
| 61 | if (crash_shutdown_cpu == smp_processor_id()) |
| 62 | longjmp(crash_shutdown_buf, 1); |
| 63 | return 0; |
| 64 | } |
| 65 | |
Michael Ellerman | cc53291 | 2005-12-04 18:39:43 +1100 | [diff] [blame] | 66 | #ifdef CONFIG_SMP |
Michael Ellerman | cc53291 | 2005-12-04 18:39:43 +1100 | [diff] [blame] | 67 | |
| 68 | void crash_ipi_callback(struct pt_regs *regs) |
| 69 | { |
| 70 | int cpu = smp_processor_id(); |
| 71 | |
Michael Ellerman | cc53291 | 2005-12-04 18:39:43 +1100 | [diff] [blame] | 72 | if (!cpu_online(cpu)) |
| 73 | return; |
| 74 | |
Paul Mackerras | d04c56f | 2006-10-04 16:47:49 +1000 | [diff] [blame] | 75 | hard_irq_disable(); |
KOSAKI Motohiro | 104699c | 2011-04-28 05:07:23 +0000 | [diff] [blame] | 76 | if (!cpumask_test_cpu(cpu, &cpus_in_crash)) |
Magnus Damm | 85916f8 | 2006-12-06 20:40:41 -0800 | [diff] [blame] | 77 | crash_save_cpu(regs, cpu); |
KOSAKI Motohiro | 104699c | 2011-04-28 05:07:23 +0000 | [diff] [blame] | 78 | cpumask_set_cpu(cpu, &cpus_in_crash); |
David Wilder | c0ce7d0 | 2006-06-23 15:29:34 -0700 | [diff] [blame] | 79 | |
| 80 | /* |
David Wilder | c0ce7d0 | 2006-06-23 15:29:34 -0700 | [diff] [blame] | 81 | * Starting the kdump boot. |
| 82 | * This barrier is needed to make sure that all CPUs are stopped. |
David Wilder | c0ce7d0 | 2006-06-23 15:29:34 -0700 | [diff] [blame] | 83 | */ |
KOSAKI Motohiro | 104699c | 2011-04-28 05:07:23 +0000 | [diff] [blame] | 84 | while (!cpumask_test_cpu(crashing_cpu, &cpus_in_crash)) |
David Wilder | c0ce7d0 | 2006-06-23 15:29:34 -0700 | [diff] [blame] | 85 | cpu_relax(); |
| 86 | |
Michael Ellerman | cc53291 | 2005-12-04 18:39:43 +1100 | [diff] [blame] | 87 | if (ppc_md.kexec_cpu_down) |
| 88 | ppc_md.kexec_cpu_down(1, 1); |
Michael Ellerman | b6f35b4 | 2006-07-05 14:39:43 +1000 | [diff] [blame] | 89 | |
| 90 | #ifdef CONFIG_PPC64 |
Michael Ellerman | cc53291 | 2005-12-04 18:39:43 +1100 | [diff] [blame] | 91 | kexec_smp_wait(); |
Michael Ellerman | b6f35b4 | 2006-07-05 14:39:43 +1000 | [diff] [blame] | 92 | #else |
| 93 | for (;;); /* FIXME */ |
| 94 | #endif |
| 95 | |
Michael Ellerman | cc53291 | 2005-12-04 18:39:43 +1100 | [diff] [blame] | 96 | /* NOTREACHED */ |
| 97 | } |
| 98 | |
David Wilder | c0ce7d0 | 2006-06-23 15:29:34 -0700 | [diff] [blame] | 99 | static void crash_kexec_prepare_cpus(int cpu) |
Michael Ellerman | cc53291 | 2005-12-04 18:39:43 +1100 | [diff] [blame] | 100 | { |
| 101 | unsigned int msecs; |
David Wilder | c0ce7d0 | 2006-06-23 15:29:34 -0700 | [diff] [blame] | 102 | unsigned int ncpus = num_online_cpus() - 1;/* Excluding the panic cpu */ |
Anton Blanchard | 07fe0c6 | 2011-11-30 00:23:11 +0000 | [diff] [blame^] | 103 | int tries = 0; |
| 104 | int (*old_handler)(struct pt_regs *regs); |
Michael Ellerman | cc53291 | 2005-12-04 18:39:43 +1100 | [diff] [blame] | 105 | |
Anton Blanchard | 9b00ac0 | 2011-11-30 00:23:10 +0000 | [diff] [blame] | 106 | printk(KERN_EMERG "Sending IPI to other CPUs\n"); |
| 107 | |
Michael Ellerman | cc53291 | 2005-12-04 18:39:43 +1100 | [diff] [blame] | 108 | crash_send_ipi(crash_ipi_callback); |
| 109 | smp_wmb(); |
| 110 | |
Anton Blanchard | 07fe0c6 | 2011-11-30 00:23:11 +0000 | [diff] [blame^] | 111 | again: |
Michael Ellerman | cc53291 | 2005-12-04 18:39:43 +1100 | [diff] [blame] | 112 | /* |
Anton Blanchard | 158d5b5e | 2011-01-21 13:43:59 +1100 | [diff] [blame] | 113 | * FIXME: Until we will have the way to stop other CPUs reliably, |
Michael Ellerman | cc53291 | 2005-12-04 18:39:43 +1100 | [diff] [blame] | 114 | * 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] | 115 | * respond. |
Haren Myneni | 01aaed9 | 2006-02-07 15:47:03 -0800 | [diff] [blame] | 116 | * Delay of at least 10 seconds. |
Michael Ellerman | cc53291 | 2005-12-04 18:39:43 +1100 | [diff] [blame] | 117 | */ |
Haren Myneni | 01aaed9 | 2006-02-07 15:47:03 -0800 | [diff] [blame] | 118 | msecs = 10000; |
KOSAKI Motohiro | 104699c | 2011-04-28 05:07:23 +0000 | [diff] [blame] | 119 | while ((cpumask_weight(&cpus_in_crash) < ncpus) && (--msecs > 0)) { |
David Wilder | c0ce7d0 | 2006-06-23 15:29:34 -0700 | [diff] [blame] | 120 | cpu_relax(); |
Michael Ellerman | cc53291 | 2005-12-04 18:39:43 +1100 | [diff] [blame] | 121 | mdelay(1); |
| 122 | } |
| 123 | |
| 124 | /* Would it be better to replace the trap vector here? */ |
| 125 | |
Anton Blanchard | 07fe0c6 | 2011-11-30 00:23:11 +0000 | [diff] [blame^] | 126 | if (cpumask_weight(&cpus_in_crash) >= ncpus) { |
| 127 | printk(KERN_EMERG "IPI complete\n"); |
| 128 | return; |
David Wilder | c0ce7d0 | 2006-06-23 15:29:34 -0700 | [diff] [blame] | 129 | } |
Anton Blanchard | 9b00ac0 | 2011-11-30 00:23:10 +0000 | [diff] [blame] | 130 | |
Anton Blanchard | 07fe0c6 | 2011-11-30 00:23:11 +0000 | [diff] [blame^] | 131 | printk(KERN_EMERG "ERROR: %d cpu(s) not responding\n", |
| 132 | ncpus - cpumask_weight(&cpus_in_crash)); |
| 133 | |
| 134 | /* |
| 135 | * If we have a panic timeout set then we can't wait indefinitely |
| 136 | * for someone to activate system reset. We also give up on the |
| 137 | * second time through if system reset fail to work. |
| 138 | */ |
| 139 | if ((panic_timeout > 0) || (tries > 0)) |
| 140 | return; |
| 141 | |
| 142 | /* |
| 143 | * A system reset will cause all CPUs to take an 0x100 exception. |
| 144 | * The primary CPU returns here via setjmp, and the secondary |
| 145 | * CPUs reexecute the crash_kexec_secondary path. |
| 146 | */ |
| 147 | old_handler = __debugger; |
| 148 | __debugger = handle_fault; |
| 149 | crash_shutdown_cpu = smp_processor_id(); |
| 150 | |
| 151 | if (setjmp(crash_shutdown_buf) == 0) { |
| 152 | printk(KERN_EMERG "Activate system reset (dumprestart) " |
| 153 | "to stop other cpu(s)\n"); |
| 154 | |
| 155 | /* |
| 156 | * A system reset will force all CPUs to execute the |
| 157 | * crash code again. We need to reset cpus_in_crash so we |
| 158 | * wait for everyone to do this. |
| 159 | */ |
| 160 | cpus_in_crash = CPU_MASK_NONE; |
| 161 | smp_mb(); |
| 162 | |
| 163 | while (cpumask_weight(&cpus_in_crash) < ncpus) |
| 164 | cpu_relax(); |
| 165 | } |
| 166 | |
| 167 | crash_shutdown_cpu = -1; |
| 168 | __debugger = old_handler; |
| 169 | |
| 170 | tries++; |
| 171 | goto again; |
Michael Ellerman | cc53291 | 2005-12-04 18:39:43 +1100 | [diff] [blame] | 172 | } |
David Wilder | c0ce7d0 | 2006-06-23 15:29:34 -0700 | [diff] [blame] | 173 | |
| 174 | /* |
Anton Blanchard | 9b00ac0 | 2011-11-30 00:23:10 +0000 | [diff] [blame] | 175 | * This function will be called by secondary cpus. |
David Wilder | c0ce7d0 | 2006-06-23 15:29:34 -0700 | [diff] [blame] | 176 | */ |
| 177 | void crash_kexec_secondary(struct pt_regs *regs) |
| 178 | { |
David Wilder | c0ce7d0 | 2006-06-23 15:29:34 -0700 | [diff] [blame] | 179 | unsigned long flags; |
Anton Blanchard | 9b00ac0 | 2011-11-30 00:23:10 +0000 | [diff] [blame] | 180 | int msecs = 500; |
David Wilder | c0ce7d0 | 2006-06-23 15:29:34 -0700 | [diff] [blame] | 181 | |
| 182 | local_irq_save(flags); |
Anton Blanchard | 9b00ac0 | 2011-11-30 00:23:10 +0000 | [diff] [blame] | 183 | |
| 184 | /* Wait 500ms for the primary crash CPU to signal its progress */ |
David Wilder | c0ce7d0 | 2006-06-23 15:29:34 -0700 | [diff] [blame] | 185 | while (crashing_cpu < 0) { |
| 186 | if (--msecs < 0) { |
Anton Blanchard | 9b00ac0 | 2011-11-30 00:23:10 +0000 | [diff] [blame] | 187 | /* No response, kdump image may not have been loaded */ |
David Wilder | c0ce7d0 | 2006-06-23 15:29:34 -0700 | [diff] [blame] | 188 | local_irq_restore(flags); |
| 189 | return; |
| 190 | } |
Anton Blanchard | 9b00ac0 | 2011-11-30 00:23:10 +0000 | [diff] [blame] | 191 | |
David Wilder | c0ce7d0 | 2006-06-23 15:29:34 -0700 | [diff] [blame] | 192 | mdelay(1); |
| 193 | cpu_relax(); |
| 194 | } |
Anton Blanchard | 9b00ac0 | 2011-11-30 00:23:10 +0000 | [diff] [blame] | 195 | |
David Wilder | c0ce7d0 | 2006-06-23 15:29:34 -0700 | [diff] [blame] | 196 | crash_ipi_callback(regs); |
| 197 | } |
| 198 | |
Paul Gortmaker | 7c7a81b | 2011-04-13 06:30:08 +0000 | [diff] [blame] | 199 | #else /* ! CONFIG_SMP */ |
Paul Gortmaker | 7c7a81b | 2011-04-13 06:30:08 +0000 | [diff] [blame] | 200 | |
David Wilder | c0ce7d0 | 2006-06-23 15:29:34 -0700 | [diff] [blame] | 201 | static void crash_kexec_prepare_cpus(int cpu) |
Michael Ellerman | cc53291 | 2005-12-04 18:39:43 +1100 | [diff] [blame] | 202 | { |
| 203 | /* |
| 204 | * move the secondarys to us so that we can copy |
| 205 | * the new kernel 0-0x100 safely |
| 206 | * |
| 207 | * do this if kexec in setup.c ? |
| 208 | */ |
Michael Ellerman | b6f35b4 | 2006-07-05 14:39:43 +1000 | [diff] [blame] | 209 | #ifdef CONFIG_PPC64 |
Michael Ellerman | cc53291 | 2005-12-04 18:39:43 +1100 | [diff] [blame] | 210 | smp_release_cpus(); |
Michael Ellerman | b6f35b4 | 2006-07-05 14:39:43 +1000 | [diff] [blame] | 211 | #else |
| 212 | /* FIXME */ |
| 213 | #endif |
Michael Ellerman | cc53291 | 2005-12-04 18:39:43 +1100 | [diff] [blame] | 214 | } |
| 215 | |
David Wilder | c0ce7d0 | 2006-06-23 15:29:34 -0700 | [diff] [blame] | 216 | void crash_kexec_secondary(struct pt_regs *regs) |
| 217 | { |
David Wilder | c0ce7d0 | 2006-06-23 15:29:34 -0700 | [diff] [blame] | 218 | } |
Paul Gortmaker | 7c7a81b | 2011-04-13 06:30:08 +0000 | [diff] [blame] | 219 | #endif /* CONFIG_SMP */ |
Michael Ellerman | cc53291 | 2005-12-04 18:39:43 +1100 | [diff] [blame] | 220 | |
Ben Hutchings | 7707e41 | 2011-04-24 15:04:31 +0000 | [diff] [blame] | 221 | /* wait for all the CPUs to hit real mode but timeout if they don't come in */ |
| 222 | #if defined(CONFIG_SMP) && defined(CONFIG_PPC_STD_MMU_64) |
| 223 | static void crash_kexec_wait_realmode(int cpu) |
| 224 | { |
| 225 | unsigned int msecs; |
| 226 | int i; |
| 227 | |
| 228 | msecs = 10000; |
Milton Miller | bd9e5ee | 2011-05-10 19:28:41 +0000 | [diff] [blame] | 229 | for (i=0; i < nr_cpu_ids && msecs > 0; i++) { |
Ben Hutchings | 7707e41 | 2011-04-24 15:04:31 +0000 | [diff] [blame] | 230 | if (i == cpu) |
| 231 | continue; |
| 232 | |
| 233 | while (paca[i].kexec_state < KEXEC_STATE_REAL_MODE) { |
| 234 | barrier(); |
Michael Neuling | 63f21a5 | 2011-07-04 20:40:10 +0000 | [diff] [blame] | 235 | if (!cpu_possible(i) || !cpu_online(i) || (msecs <= 0)) |
Ben Hutchings | 7707e41 | 2011-04-24 15:04:31 +0000 | [diff] [blame] | 236 | break; |
Ben Hutchings | 7707e41 | 2011-04-24 15:04:31 +0000 | [diff] [blame] | 237 | msecs--; |
| 238 | mdelay(1); |
| 239 | } |
| 240 | } |
| 241 | mb(); |
| 242 | } |
| 243 | #else |
| 244 | static inline void crash_kexec_wait_realmode(int cpu) {} |
| 245 | #endif /* CONFIG_SMP && CONFIG_PPC_STD_MMU_64 */ |
| 246 | |
Michael Neuling | 496b010 | 2008-01-18 15:50:30 +1100 | [diff] [blame] | 247 | /* |
| 248 | * Register a function to be called on shutdown. Only use this if you |
| 249 | * can't reset your device in the second kernel. |
| 250 | */ |
| 251 | int crash_shutdown_register(crash_shutdown_t handler) |
| 252 | { |
| 253 | unsigned int i, rc; |
| 254 | |
| 255 | spin_lock(&crash_handlers_lock); |
| 256 | for (i = 0 ; i < CRASH_HANDLER_MAX; i++) |
| 257 | if (!crash_shutdown_handles[i]) { |
| 258 | /* Insert handle at first empty entry */ |
| 259 | crash_shutdown_handles[i] = handler; |
| 260 | rc = 0; |
| 261 | break; |
| 262 | } |
| 263 | |
| 264 | if (i == CRASH_HANDLER_MAX) { |
| 265 | printk(KERN_ERR "Crash shutdown handles full, " |
| 266 | "not registered.\n"); |
| 267 | rc = 1; |
| 268 | } |
| 269 | |
| 270 | spin_unlock(&crash_handlers_lock); |
| 271 | return rc; |
| 272 | } |
| 273 | EXPORT_SYMBOL(crash_shutdown_register); |
| 274 | |
| 275 | int crash_shutdown_unregister(crash_shutdown_t handler) |
| 276 | { |
| 277 | unsigned int i, rc; |
| 278 | |
| 279 | spin_lock(&crash_handlers_lock); |
| 280 | for (i = 0 ; i < CRASH_HANDLER_MAX; i++) |
| 281 | if (crash_shutdown_handles[i] == handler) |
| 282 | break; |
| 283 | |
| 284 | if (i == CRASH_HANDLER_MAX) { |
| 285 | printk(KERN_ERR "Crash shutdown handle not found\n"); |
| 286 | rc = 1; |
| 287 | } else { |
| 288 | /* Shift handles down */ |
| 289 | for (; crash_shutdown_handles[i]; i++) |
| 290 | crash_shutdown_handles[i] = |
| 291 | crash_shutdown_handles[i+1]; |
| 292 | rc = 0; |
| 293 | } |
| 294 | |
| 295 | spin_unlock(&crash_handlers_lock); |
| 296 | return rc; |
| 297 | } |
| 298 | EXPORT_SYMBOL(crash_shutdown_unregister); |
| 299 | |
Michael Ellerman | cc53291 | 2005-12-04 18:39:43 +1100 | [diff] [blame] | 300 | void default_machine_crash_shutdown(struct pt_regs *regs) |
| 301 | { |
Michael Neuling | 496b010 | 2008-01-18 15:50:30 +1100 | [diff] [blame] | 302 | unsigned int i; |
| 303 | int (*old_handler)(struct pt_regs *regs); |
| 304 | |
Michael Ellerman | d6c1a90 | 2006-04-04 13:43:01 +0200 | [diff] [blame] | 305 | |
Michael Ellerman | cc53291 | 2005-12-04 18:39:43 +1100 | [diff] [blame] | 306 | /* |
| 307 | * This function is only called after the system |
Lee Revell | f18190b | 2006-06-26 18:30:00 +0200 | [diff] [blame] | 308 | * has panicked or is otherwise in a critical state. |
Michael Ellerman | cc53291 | 2005-12-04 18:39:43 +1100 | [diff] [blame] | 309 | * The minimum amount of code to allow a kexec'd kernel |
| 310 | * to run successfully needs to happen here. |
| 311 | * |
| 312 | * In practice this means stopping other cpus in |
| 313 | * an SMP system. |
| 314 | * The kernel is broken so disable interrupts. |
| 315 | */ |
Paul Mackerras | d04c56f | 2006-10-04 16:47:49 +1000 | [diff] [blame] | 316 | hard_irq_disable(); |
Michael Ellerman | cc53291 | 2005-12-04 18:39:43 +1100 | [diff] [blame] | 317 | |
Anton Blanchard | 249ec22 | 2010-08-02 20:39:41 +0000 | [diff] [blame] | 318 | /* |
| 319 | * Make a note of crashing cpu. Will be used in machine_kexec |
| 320 | * such that another IPI will not be sent. |
| 321 | */ |
| 322 | crashing_cpu = smp_processor_id(); |
| 323 | crash_save_cpu(regs, crashing_cpu); |
| 324 | crash_kexec_prepare_cpus(crashing_cpu); |
KOSAKI Motohiro | 104699c | 2011-04-28 05:07:23 +0000 | [diff] [blame] | 325 | cpumask_set_cpu(crashing_cpu, &cpus_in_crash); |
Anton Blanchard | 249ec22 | 2010-08-02 20:39:41 +0000 | [diff] [blame] | 326 | crash_kexec_wait_realmode(crashing_cpu); |
Anton Blanchard | 249ec22 | 2010-08-02 20:39:41 +0000 | [diff] [blame] | 327 | |
Matthew McClintock | c71635d | 2010-09-16 17:58:23 -0500 | [diff] [blame] | 328 | machine_kexec_mask_interrupts(); |
Michael Ellerman | d6c1a90 | 2006-04-04 13:43:01 +0200 | [diff] [blame] | 329 | |
Michael Ellerman | cc53291 | 2005-12-04 18:39:43 +1100 | [diff] [blame] | 330 | /* |
Michael Neuling | 496b010 | 2008-01-18 15:50:30 +1100 | [diff] [blame] | 331 | * Call registered shutdown routines savely. Swap out |
| 332 | * __debugger_fault_handler, and replace on exit. |
| 333 | */ |
| 334 | old_handler = __debugger_fault_handler; |
| 335 | __debugger_fault_handler = handle_fault; |
Anton Blanchard | 0644079 | 2010-05-10 16:25:51 +0000 | [diff] [blame] | 336 | crash_shutdown_cpu = smp_processor_id(); |
Michael Neuling | 496b010 | 2008-01-18 15:50:30 +1100 | [diff] [blame] | 337 | for (i = 0; crash_shutdown_handles[i]; i++) { |
| 338 | if (setjmp(crash_shutdown_buf) == 0) { |
| 339 | /* |
| 340 | * Insert syncs and delay to ensure |
| 341 | * instructions in the dangerous region don't |
| 342 | * leak away from this protected region. |
| 343 | */ |
| 344 | asm volatile("sync; isync"); |
| 345 | /* dangerous region */ |
| 346 | crash_shutdown_handles[i](); |
| 347 | asm volatile("sync; isync"); |
| 348 | } |
| 349 | } |
Anton Blanchard | 0644079 | 2010-05-10 16:25:51 +0000 | [diff] [blame] | 350 | crash_shutdown_cpu = -1; |
Michael Neuling | 496b010 | 2008-01-18 15:50:30 +1100 | [diff] [blame] | 351 | __debugger_fault_handler = old_handler; |
| 352 | |
David Wilder | c0ce7d0 | 2006-06-23 15:29:34 -0700 | [diff] [blame] | 353 | if (ppc_md.kexec_cpu_down) |
| 354 | ppc_md.kexec_cpu_down(1, 0); |
Michael Ellerman | cc53291 | 2005-12-04 18:39:43 +1100 | [diff] [blame] | 355 | } |