| Eric W. Biederman | 5033cba | 2005-06-25 14:57:56 -0700 | [diff] [blame] | 1 | /* | 
| Hiroshi Shimamoto | 62a31a0 | 2007-10-19 18:24:20 -0700 | [diff] [blame] | 2 | * Architecture specific (i386/x86_64) functions for kexec based crash dumps. | 
| Eric W. Biederman | 5033cba | 2005-06-25 14:57:56 -0700 | [diff] [blame] | 3 | * | 
|  | 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. Biederman | 5033cba | 2005-06-25 14:57:56 -0700 | [diff] [blame] | 14 | #include <linux/reboot.h> | 
|  | 15 | #include <linux/kexec.h> | 
| Eric W. Biederman | 5033cba | 2005-06-25 14:57:56 -0700 | [diff] [blame] | 16 | #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 Goyal | 19842d6 | 2005-11-15 00:09:04 -0800 | [diff] [blame] | 24 | #include <asm/apic.h> | 
| OGAWA Hirofumi | 0c1b272 | 2007-12-03 17:17:10 +0100 | [diff] [blame] | 25 | #include <asm/hpet.h> | 
| Christoph Hellwig | 1eeb66a | 2007-05-08 00:27:03 -0700 | [diff] [blame] | 26 | #include <linux/kdebug.h> | 
| Jaswinder Singh Rajput | 96b89dc | 2009-01-07 21:35:48 +0530 | [diff] [blame] | 27 | #include <asm/cpu.h> | 
| Glauber Costa | ed23dc6 | 2008-03-17 16:08:38 -0300 | [diff] [blame] | 28 | #include <asm/reboot.h> | 
| Eduardo Habkost | 2340b62 | 2008-11-17 19:03:23 -0200 | [diff] [blame] | 29 | #include <asm/virtext.h> | 
| Don Zickus | 2fbe7b2 | 2006-09-26 10:52:27 +0200 | [diff] [blame] | 30 |  | 
| Eduardo Habkost | 8e29478 | 2008-11-12 11:34:40 -0200 | [diff] [blame] | 31 |  | 
| Eduardo Habkost | b2bbe71 | 2008-11-12 11:34:38 -0200 | [diff] [blame] | 32 | #if defined(CONFIG_SMP) && defined(CONFIG_X86_LOCAL_APIC) | 
|  | 33 |  | 
| Eduardo Habkost | a7d4182 | 2008-11-12 11:34:37 -0200 | [diff] [blame] | 34 | static void kdump_nmi_callback(int cpu, struct die_args *args) | 
| Eric W. Biederman | c4ac426 | 2005-06-25 14:57:58 -0700 | [diff] [blame] | 35 | { | 
| Don Zickus | 2fbe7b2 | 2006-09-26 10:52:27 +0200 | [diff] [blame] | 36 | struct pt_regs *regs; | 
| Mike Galbraith | 1fb473d | 2007-10-24 12:58:01 +0200 | [diff] [blame] | 37 | #ifdef CONFIG_X86_32 | 
| Vivek Goyal | 4d55476 | 2005-06-25 14:58:13 -0700 | [diff] [blame] | 38 | struct pt_regs fixed_regs; | 
| Hiroshi Shimamoto | 62a31a0 | 2007-10-19 18:24:20 -0700 | [diff] [blame] | 39 | #endif | 
| Eduardo Habkost | a7d4182 | 2008-11-12 11:34:37 -0200 | [diff] [blame] | 40 |  | 
|  | 41 | regs = args->regs; | 
|  | 42 |  | 
|  | 43 | #ifdef CONFIG_X86_32 | 
|  | 44 | if (!user_mode_vm(regs)) { | 
|  | 45 | crash_fixup_ss_esp(&fixed_regs, regs); | 
|  | 46 | regs = &fixed_regs; | 
|  | 47 | } | 
|  | 48 | #endif | 
|  | 49 | crash_save_cpu(regs, cpu); | 
|  | 50 |  | 
| Eduardo Habkost | 2340b62 | 2008-11-17 19:03:23 -0200 | [diff] [blame] | 51 | /* Disable VMX or SVM if needed. | 
|  | 52 | * | 
|  | 53 | * We need to disable virtualization on all CPUs. | 
|  | 54 | * Having VMX or SVM enabled on any CPU may break rebooting | 
|  | 55 | * after the kdump kernel has finished its task. | 
|  | 56 | */ | 
|  | 57 | cpu_emergency_vmxoff(); | 
|  | 58 | cpu_emergency_svm_disable(); | 
|  | 59 |  | 
| Eduardo Habkost | a7d4182 | 2008-11-12 11:34:37 -0200 | [diff] [blame] | 60 | disable_local_APIC(); | 
|  | 61 | } | 
|  | 62 |  | 
| Eduardo Habkost | d1e7b91 | 2008-11-12 11:34:39 -0200 | [diff] [blame] | 63 | static void kdump_nmi_shootdown_cpus(void) | 
|  | 64 | { | 
| Eduardo Habkost | 8e29478 | 2008-11-12 11:34:40 -0200 | [diff] [blame] | 65 | nmi_shootdown_cpus(kdump_nmi_callback); | 
| Eduardo Habkost | d1e7b91 | 2008-11-12 11:34:39 -0200 | [diff] [blame] | 66 |  | 
| Vivek Goyal | 19842d6 | 2005-11-15 00:09:04 -0800 | [diff] [blame] | 67 | disable_local_APIC(); | 
| Eric W. Biederman | c4ac426 | 2005-06-25 14:57:58 -0700 | [diff] [blame] | 68 | } | 
| Eduardo Habkost | d1e7b91 | 2008-11-12 11:34:39 -0200 | [diff] [blame] | 69 |  | 
| Eric W. Biederman | c4ac426 | 2005-06-25 14:57:58 -0700 | [diff] [blame] | 70 | #else | 
| Eduardo Habkost | d1e7b91 | 2008-11-12 11:34:39 -0200 | [diff] [blame] | 71 | static void kdump_nmi_shootdown_cpus(void) | 
| Eric W. Biederman | c4ac426 | 2005-06-25 14:57:58 -0700 | [diff] [blame] | 72 | { | 
|  | 73 | /* There are no cpus to shootdown */ | 
|  | 74 | } | 
|  | 75 | #endif | 
|  | 76 |  | 
| Glauber Costa | ed23dc6 | 2008-03-17 16:08:38 -0300 | [diff] [blame] | 77 | void native_machine_crash_shutdown(struct pt_regs *regs) | 
| Eric W. Biederman | 5033cba | 2005-06-25 14:57:56 -0700 | [diff] [blame] | 78 | { | 
|  | 79 | /* This function is only called after the system | 
| Lee Revell | f18190b | 2006-06-26 18:30:00 +0200 | [diff] [blame] | 80 | * has panicked or is otherwise in a critical state. | 
| Eric W. Biederman | 5033cba | 2005-06-25 14:57:56 -0700 | [diff] [blame] | 81 | * The minimum amount of code to allow a kexec'd kernel | 
|  | 82 | * to run successfully needs to happen here. | 
|  | 83 | * | 
|  | 84 | * In practice this means shooting down the other cpus in | 
|  | 85 | * an SMP system. | 
|  | 86 | */ | 
| Eric W. Biederman | c4ac426 | 2005-06-25 14:57:58 -0700 | [diff] [blame] | 87 | /* The kernel is broken so disable interrupts */ | 
|  | 88 | local_irq_disable(); | 
| Vivek Goyal | a3ea8ac | 2005-06-25 14:58:14 -0700 | [diff] [blame] | 89 |  | 
| Eduardo Habkost | d1e7b91 | 2008-11-12 11:34:39 -0200 | [diff] [blame] | 90 | kdump_nmi_shootdown_cpus(); | 
| Eduardo Habkost | 2340b62 | 2008-11-17 19:03:23 -0200 | [diff] [blame] | 91 |  | 
|  | 92 | /* Booting kdump kernel with VMX or SVM enabled won't work, | 
|  | 93 | * because (among other limitations) we can't disable paging | 
|  | 94 | * with the virt flags. | 
|  | 95 | */ | 
|  | 96 | cpu_emergency_vmxoff(); | 
|  | 97 | cpu_emergency_svm_disable(); | 
|  | 98 |  | 
| Vivek Goyal | 19842d6 | 2005-11-15 00:09:04 -0800 | [diff] [blame] | 99 | lapic_shutdown(); | 
|  | 100 | #if defined(CONFIG_X86_IO_APIC) | 
|  | 101 | disable_IO_APIC(); | 
|  | 102 | #endif | 
| OGAWA Hirofumi | 0c1b272 | 2007-12-03 17:17:10 +0100 | [diff] [blame] | 103 | #ifdef CONFIG_HPET_TIMER | 
|  | 104 | hpet_disable(); | 
|  | 105 | #endif | 
| Magnus Damm | 85916f8 | 2006-12-06 20:40:41 -0800 | [diff] [blame] | 106 | crash_save_cpu(regs, safe_smp_processor_id()); | 
| Eric W. Biederman | 5033cba | 2005-06-25 14:57:56 -0700 | [diff] [blame] | 107 | } |