2 * Architecture specific (PPC64) functions for kexec based crash dumps.
4 * Copyright (C) 2005, IBM Corp.
6 * Created by: Haren Myneni
8 * This source code is licensed under the GNU General Public License,
9 * Version 2. See the file COPYING for more details.
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>
20 #include <linux/crash_dump.h>
21 #include <linux/irq.h>
22 #include <linux/delay.h>
23 #include <linux/elf.h>
24 #include <linux/elfcore.h>
25 #include <linux/init.h>
26 #include <linux/types.h>
28 #include <asm/processor.h>
29 #include <asm/machdep.h>
30 #include <asm/kdump.h>
32 #include <asm/firmware.h>
36 #define DBG(fmt...) udbg_printf(fmt)
41 /* This keeps a track of which one is crashing cpu. */
42 int crashing_cpu = -1;
44 static u32 *append_elf_note(u32 *buf, char *name, unsigned type, void *data,
49 note.n_namesz = strlen(name) + 1;
50 note.n_descsz = data_len;
52 memcpy(buf, ¬e, sizeof(note));
53 buf += (sizeof(note) +3)/4;
54 memcpy(buf, name, note.n_namesz);
55 buf += (note.n_namesz + 3)/4;
56 memcpy(buf, data, note.n_descsz);
57 buf += (note.n_descsz + 3)/4;
62 static void final_note(u32 *buf)
69 memcpy(buf, ¬e, sizeof(note));
72 static void crash_save_this_cpu(struct pt_regs *regs, int cpu)
74 struct elf_prstatus prstatus;
77 if ((cpu < 0) || (cpu >= NR_CPUS))
80 /* Using ELF notes here is opportunistic.
81 * I need a well defined structure format
82 * for the data I pass, and I need tags
83 * on the data to indicate what information I have
84 * squirrelled away. ELF notes happen to provide
85 * all of that that no need to invent something new.
87 buf = &crash_notes[cpu][0];
88 memset(&prstatus, 0, sizeof(prstatus));
89 prstatus.pr_pid = current->pid;
90 elf_core_copy_regs(&prstatus.pr_reg, regs);
91 buf = append_elf_note(buf, "CORE", NT_PRSTATUS, &prstatus,
96 /* FIXME Merge this with xmon_save_regs ?? */
97 static inline void crash_get_current_regs(struct pt_regs *regs)
99 unsigned long tmp1, tmp2;
101 __asm__ __volatile__ (
146 : "=&r" (tmp1), "=&r" (tmp2)
150 /* We may have saved_regs from where the error came from
151 * or it is NULL if via a direct panic().
153 static void crash_save_self(struct pt_regs *saved_regs)
158 cpu = smp_processor_id();
160 memcpy(®s, saved_regs, sizeof(regs));
162 crash_get_current_regs(®s);
163 crash_save_this_cpu(®s, cpu);
167 static atomic_t waiting_for_crash_ipi;
169 void crash_ipi_callback(struct pt_regs *regs)
171 int cpu = smp_processor_id();
173 if (cpu == crashing_cpu)
176 if (!cpu_online(cpu))
179 if (ppc_md.kexec_cpu_down)
180 ppc_md.kexec_cpu_down(1, 1);
184 crash_save_this_cpu(regs, cpu);
185 atomic_dec(&waiting_for_crash_ipi);
190 static void crash_kexec_prepare_cpus(void)
194 atomic_set(&waiting_for_crash_ipi, num_online_cpus() - 1);
196 crash_send_ipi(crash_ipi_callback);
200 * FIXME: Until we will have the way to stop other CPUSs reliabally,
201 * the crash CPU will send an IPI and wait for other CPUs to
202 * respond. If not, proceed the kexec boot even though we failed to
203 * capture other CPU states.
206 while ((atomic_read(&waiting_for_crash_ipi) > 0) && (--msecs > 0)) {
211 /* Would it be better to replace the trap vector here? */
214 * FIXME: In case if we do not get all CPUs, one possibility: ask the
215 * user to do soft reset such that we get all.
216 * IPI handler is already set by the panic cpu initially. Therefore,
217 * all cpus could invoke this handler from die() and the panic CPU
218 * will call machine_kexec() directly from this handler to do
221 if (atomic_read(&waiting_for_crash_ipi))
222 printk(KERN_ALERT "done waiting: %d cpus not responding\n",
223 atomic_read(&waiting_for_crash_ipi));
224 /* Leave the IPI callback set */
227 static void crash_kexec_prepare_cpus(void)
230 * move the secondarys to us so that we can copy
231 * the new kernel 0-0x100 safely
233 * do this if kexec in setup.c ?
240 void default_machine_crash_shutdown(struct pt_regs *regs)
243 * This function is only called after the system
244 * has paniced or is otherwise in a critical state.
245 * The minimum amount of code to allow a kexec'd kernel
246 * to run successfully needs to happen here.
248 * In practice this means stopping other cpus in
250 * The kernel is broken so disable interrupts.
254 if (ppc_md.kexec_cpu_down)
255 ppc_md.kexec_cpu_down(1, 0);
258 * Make a note of crashing cpu. Will be used in machine_kexec
259 * such that another IPI will not be sent.
261 crashing_cpu = smp_processor_id();
262 crash_kexec_prepare_cpus();
263 crash_save_self(regs);