blob: ebd4c51d096a525cbc6978561e11b3a4afbeb385 [file] [log] [blame]
Eric W. Biederman5033cba2005-06-25 14:57:56 -07001/*
Hiroshi Shimamoto62a31a02007-10-19 18:24:20 -07002 * Architecture specific (i386/x86_64) functions for kexec based crash dumps.
Eric W. Biederman5033cba2005-06-25 14:57:56 -07003 *
4 * Created by: Hariprasad Nellitheertha (hari@in.ibm.com)
5 *
6 * Copyright (C) IBM Corporation, 2004. All rights reserved.
7 *
8 */
9
10#include <linux/init.h>
11#include <linux/types.h>
12#include <linux/kernel.h>
13#include <linux/smp.h>
Eric W. Biederman5033cba2005-06-25 14:57:56 -070014#include <linux/reboot.h>
15#include <linux/kexec.h>
Eric W. Biederman5033cba2005-06-25 14:57:56 -070016#include <linux/delay.h>
17#include <linux/elf.h>
18#include <linux/elfcore.h>
19
20#include <asm/processor.h>
21#include <asm/hardirq.h>
22#include <asm/nmi.h>
23#include <asm/hw_irq.h>
Vivek Goyal19842d62005-11-15 00:09:04 -080024#include <asm/apic.h>
OGAWA Hirofumi0c1b2722007-12-03 17:17:10 +010025#include <asm/hpet.h>
Christoph Hellwig1eeb66a2007-05-08 00:27:03 -070026#include <linux/kdebug.h>
Jaswinder Singh Rajput96b89dc2009-01-07 21:35:48 +053027#include <asm/cpu.h>
Glauber Costaed23dc62008-03-17 16:08:38 -030028#include <asm/reboot.h>
Eduardo Habkost2340b622008-11-17 19:03:23 -020029#include <asm/virtext.h>
Eduardo Habkost8e294782008-11-12 11:34:40 -020030
Eduardo Habkostb2bbe712008-11-12 11:34:38 -020031#if defined(CONFIG_SMP) && defined(CONFIG_X86_LOCAL_APIC)
32
Eduardo Habkosta7d41822008-11-12 11:34:37 -020033static void kdump_nmi_callback(int cpu, struct die_args *args)
Eric W. Biedermanc4ac4262005-06-25 14:57:58 -070034{
Don Zickus2fbe7b22006-09-26 10:52:27 +020035 struct pt_regs *regs;
Mike Galbraith1fb473d2007-10-24 12:58:01 +020036#ifdef CONFIG_X86_32
Vivek Goyal4d554762005-06-25 14:58:13 -070037 struct pt_regs fixed_regs;
Hiroshi Shimamoto62a31a02007-10-19 18:24:20 -070038#endif
Eduardo Habkosta7d41822008-11-12 11:34:37 -020039
40 regs = args->regs;
41
42#ifdef CONFIG_X86_32
43 if (!user_mode_vm(regs)) {
44 crash_fixup_ss_esp(&fixed_regs, regs);
45 regs = &fixed_regs;
46 }
47#endif
48 crash_save_cpu(regs, cpu);
49
Eduardo Habkost2340b622008-11-17 19:03:23 -020050 /* Disable VMX or SVM if needed.
51 *
52 * We need to disable virtualization on all CPUs.
53 * Having VMX or SVM enabled on any CPU may break rebooting
54 * after the kdump kernel has finished its task.
55 */
56 cpu_emergency_vmxoff();
57 cpu_emergency_svm_disable();
58
Eduardo Habkosta7d41822008-11-12 11:34:37 -020059 disable_local_APIC();
60}
61
Eduardo Habkostd1e7b912008-11-12 11:34:39 -020062static void kdump_nmi_shootdown_cpus(void)
63{
Eduardo Habkost8e294782008-11-12 11:34:40 -020064 nmi_shootdown_cpus(kdump_nmi_callback);
Eduardo Habkostd1e7b912008-11-12 11:34:39 -020065
Vivek Goyal19842d62005-11-15 00:09:04 -080066 disable_local_APIC();
Eric W. Biedermanc4ac4262005-06-25 14:57:58 -070067}
Eduardo Habkostd1e7b912008-11-12 11:34:39 -020068
Eric W. Biedermanc4ac4262005-06-25 14:57:58 -070069#else
Eduardo Habkostd1e7b912008-11-12 11:34:39 -020070static void kdump_nmi_shootdown_cpus(void)
Eric W. Biedermanc4ac4262005-06-25 14:57:58 -070071{
72 /* There are no cpus to shootdown */
73}
74#endif
75
Glauber Costaed23dc62008-03-17 16:08:38 -030076void native_machine_crash_shutdown(struct pt_regs *regs)
Eric W. Biederman5033cba2005-06-25 14:57:56 -070077{
78 /* This function is only called after the system
Lee Revellf18190b2006-06-26 18:30:00 +020079 * has panicked or is otherwise in a critical state.
Eric W. Biederman5033cba2005-06-25 14:57:56 -070080 * The minimum amount of code to allow a kexec'd kernel
81 * to run successfully needs to happen here.
82 *
83 * In practice this means shooting down the other cpus in
84 * an SMP system.
85 */
Eric W. Biedermanc4ac4262005-06-25 14:57:58 -070086 /* The kernel is broken so disable interrupts */
87 local_irq_disable();
Vivek Goyala3ea8ac2005-06-25 14:58:14 -070088
Eduardo Habkostd1e7b912008-11-12 11:34:39 -020089 kdump_nmi_shootdown_cpus();
Eduardo Habkost2340b622008-11-17 19:03:23 -020090
91 /* Booting kdump kernel with VMX or SVM enabled won't work,
92 * because (among other limitations) we can't disable paging
93 * with the virt flags.
94 */
95 cpu_emergency_vmxoff();
96 cpu_emergency_svm_disable();
97
Vivek Goyal19842d62005-11-15 00:09:04 -080098 lapic_shutdown();
99#if defined(CONFIG_X86_IO_APIC)
100 disable_IO_APIC();
101#endif
OGAWA Hirofumi0c1b2722007-12-03 17:17:10 +0100102#ifdef CONFIG_HPET_TIMER
103 hpet_disable();
104#endif
Magnus Damm85916f82006-12-06 20:40:41 -0800105 crash_save_cpu(regs, safe_smp_processor_id());
Eric W. Biederman5033cba2005-06-25 14:57:56 -0700106}