2 * arch/ia64/kernel/crash.c
4 * Architecture specific (ia64) functions for kexec based crash dumps.
6 * Created by: Khalid Aziz <khalid.aziz@hp.com>
7 * Copyright (C) 2005 Hewlett-Packard Development Company, L.P.
8 * Copyright (C) 2005 Intel Corp Zou Nan hai <nanhai.zou@intel.com>
11 #include <linux/smp.h>
12 #include <linux/delay.h>
13 #include <linux/crash_dump.h>
14 #include <linux/bootmem.h>
15 #include <linux/kexec.h>
16 #include <linux/elfcore.h>
17 #include <linux/sysctl.h>
18 #include <linux/init.h>
19 #include <linux/kdebug.h>
23 int kdump_status[NR_CPUS];
24 static atomic_t kdump_cpu_frozen;
25 atomic_t kdump_in_progress;
26 static int kdump_freeze_monarch;
27 static int kdump_on_init = 1;
28 static int kdump_on_fatal_mca = 1;
30 static inline Elf64_Word
31 *append_elf_note(Elf64_Word *buf, char *name, unsigned type, void *data,
34 struct elf_note *note = (struct elf_note *)buf;
35 note->n_namesz = strlen(name) + 1;
36 note->n_descsz = data_len;
38 buf += (sizeof(*note) + 3)/4;
39 memcpy(buf, name, note->n_namesz);
40 buf += (note->n_namesz + 3)/4;
41 memcpy(buf, data, data_len);
42 buf += (data_len + 3)/4;
49 memset(buf, 0, sizeof(struct elf_note));
52 extern void ia64_dump_cpu_regs(void *);
54 static DEFINE_PER_CPU(struct elf_prstatus, elf_prstatus);
57 crash_save_this_cpu(void)
60 unsigned long cfm, sof, sol;
62 int cpu = smp_processor_id();
63 struct elf_prstatus *prstatus = &per_cpu(elf_prstatus, cpu);
65 elf_greg_t *dst = (elf_greg_t *)&(prstatus->pr_reg);
66 memset(prstatus, 0, sizeof(*prstatus));
67 prstatus->pr_pid = current->pid;
69 ia64_dump_cpu_regs(dst);
71 sol = (cfm >> 7) & 0x7f;
73 dst[46] = (unsigned long)ia64_rse_skip_regs((unsigned long *)dst[46],
76 buf = (u64 *) per_cpu_ptr(crash_notes, cpu);
79 buf = append_elf_note(buf, KEXEC_CORE_NOTE_NAME, NT_PRSTATUS, prstatus,
86 kdump_wait_cpu_freeze(void)
88 int cpu_num = num_online_cpus() - 1;
90 while(timeout-- > 0) {
91 if (atomic_read(&kdump_cpu_frozen) == cpu_num)
100 machine_crash_shutdown(struct pt_regs *pt)
102 /* This function is only called after the system
103 * has paniced or is otherwise in a critical state.
104 * The minimum amount of code to allow a kexec'd kernel
105 * to run successfully needs to happen here.
107 * In practice this means shooting down the other cpus in
110 kexec_disable_iosapic();
113 * If kdump_on_init is set and an INIT is asserted here, kdump will
114 * be started again via INIT monarch.
117 ia64_set_psr_mc(); /* mask MCA/INIT */
118 if (atomic_inc_return(&kdump_in_progress) != 1)
119 unw_init_running(kdump_cpu_freeze, NULL);
122 * Now this cpu is ready for kdump.
123 * Stop all others by IPI or INIT. They could receive INIT from
124 * outside and might be INIT monarch, but only thing they have to
125 * do is falling into kdump_cpu_freeze().
127 * If an INIT is asserted here:
128 * - All receivers might be slaves, since some of cpus could already
129 * be frozen and INIT might be masked on monarch. In this case,
130 * all slaves will park in while (monarch_cpu == -1) loop before
131 * DIE_INIT_SLAVE_ENTER that for waiting monarch enters.
132 * => TBD: freeze all slaves
133 * - One might be a monarch, but INIT rendezvous will fail since
134 * at least this cpu already have INIT masked so it never join
135 * to the rendezvous. In this case, all slaves and monarch will
136 * be frozen after timeout of the INIT rendezvous.
137 * => TBD: freeze them without waiting timeout
139 kdump_smp_send_stop();
140 /* not all cpu response to IPI, send INIT to freeze them */
141 if (kdump_wait_cpu_freeze() && kdump_on_init) {
142 kdump_smp_send_init();
148 machine_kdump_on_init(void)
150 crash_save_vmcoreinfo();
152 kexec_disable_iosapic();
153 machine_kexec(ia64_kimage);
157 kdump_cpu_freeze(struct unw_frame_info *info, void *arg)
162 cpuid = smp_processor_id();
163 crash_save_this_cpu();
164 current->thread.ksp = (__u64)info->sw - 16;
166 ia64_set_psr_mc(); /* mask MCA/INIT and stop reentrance */
168 atomic_inc(&kdump_cpu_frozen);
169 kdump_status[cpuid] = 1;
176 kdump_init_notifier(struct notifier_block *self, unsigned long val, void *data)
178 struct ia64_mca_notify_die *nd;
179 struct die_args *args = data;
181 if (!kdump_on_init && !kdump_on_fatal_mca)
185 if (val == DIE_INIT_MONARCH_LEAVE)
186 ia64_mca_printk(KERN_NOTICE
187 "%s: kdump not configured\n",
192 if (val != DIE_INIT_MONARCH_LEAVE &&
193 val != DIE_INIT_SLAVE_LEAVE &&
194 val != DIE_INIT_MONARCH_PROCESS &&
195 val != DIE_MCA_RENDZVOUS_LEAVE &&
196 val != DIE_MCA_MONARCH_LEAVE)
199 nd = (struct ia64_mca_notify_die *)args->err;
200 /* Reason code 1 means machine check rendezvous*/
201 if ((val == DIE_INIT_MONARCH_LEAVE || val == DIE_INIT_SLAVE_LEAVE
202 || val == DIE_INIT_MONARCH_PROCESS) && nd->sos->rv_rc == 1)
206 case DIE_INIT_MONARCH_PROCESS:
208 if (atomic_inc_return(&kdump_in_progress) != 1)
209 kdump_freeze_monarch = 1;
210 *(nd->monarch_cpu) = -1;
213 case DIE_INIT_MONARCH_LEAVE:
215 if (kdump_freeze_monarch)
216 unw_init_running(kdump_cpu_freeze, NULL);
218 machine_kdump_on_init();
221 case DIE_INIT_SLAVE_LEAVE:
222 if (atomic_read(&kdump_in_progress))
223 unw_init_running(kdump_cpu_freeze, NULL);
225 case DIE_MCA_RENDZVOUS_LEAVE:
226 if (atomic_read(&kdump_in_progress))
227 unw_init_running(kdump_cpu_freeze, NULL);
229 case DIE_MCA_MONARCH_LEAVE:
230 /* *(nd->data) indicate if MCA is recoverable */
231 if (kdump_on_fatal_mca && !(*(nd->data))) {
232 if (atomic_inc_return(&kdump_in_progress) == 1) {
233 *(nd->monarch_cpu) = -1;
234 machine_kdump_on_init();
236 /* We got fatal MCA while kdump!? No way!! */
244 static ctl_table kdump_ctl_table[] = {
246 .ctl_name = CTL_UNNUMBERED,
247 .procname = "kdump_on_init",
248 .data = &kdump_on_init,
249 .maxlen = sizeof(int),
251 .proc_handler = &proc_dointvec,
254 .ctl_name = CTL_UNNUMBERED,
255 .procname = "kdump_on_fatal_mca",
256 .data = &kdump_on_fatal_mca,
257 .maxlen = sizeof(int),
259 .proc_handler = &proc_dointvec,
264 static ctl_table sys_table[] = {
266 .ctl_name = CTL_KERN,
267 .procname = "kernel",
269 .child = kdump_ctl_table,
276 machine_crash_setup(void)
278 /* be notified before default_monarch_init_process */
279 static struct notifier_block kdump_init_notifier_nb = {
280 .notifier_call = kdump_init_notifier,
284 if((ret = register_die_notifier(&kdump_init_notifier_nb)) != 0)
287 register_sysctl_table(sys_table);
292 __initcall(machine_crash_setup);