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