Zou Nan hai | a795611 | 2006-12-07 09:51:35 -0800 | [diff] [blame] | 1 | /* |
| 2 | * arch/ia64/kernel/machine_kexec.c |
| 3 | * |
| 4 | * Handle transition of Linux booting another kernel |
| 5 | * Copyright (C) 2005 Hewlett-Packard Development Comapny, L.P. |
| 6 | * Copyright (C) 2005 Khalid Aziz <khalid.aziz@hp.com> |
| 7 | * Copyright (C) 2006 Intel Corp, Zou Nan hai <nanhai.zou@intel.com> |
| 8 | * |
| 9 | * This source code is licensed under the GNU General Public License, |
| 10 | * Version 2. See the file COPYING for more details. |
| 11 | */ |
| 12 | |
| 13 | #include <linux/mm.h> |
| 14 | #include <linux/kexec.h> |
| 15 | #include <linux/cpu.h> |
| 16 | #include <linux/irq.h> |
| 17 | #include <asm/mmu_context.h> |
| 18 | #include <asm/setup.h> |
| 19 | #include <asm/delay.h> |
| 20 | #include <asm/meminit.h> |
| 21 | |
| 22 | typedef void (*relocate_new_kernel_t)(unsigned long, unsigned long, |
| 23 | struct ia64_boot_param *, unsigned long); |
| 24 | |
| 25 | struct kimage *ia64_kimage; |
| 26 | |
| 27 | struct resource efi_memmap_res = { |
| 28 | .name = "EFI Memory Map", |
| 29 | .start = 0, |
| 30 | .end = 0, |
| 31 | .flags = IORESOURCE_BUSY | IORESOURCE_MEM |
| 32 | }; |
| 33 | |
| 34 | struct resource boot_param_res = { |
| 35 | .name = "Boot parameter", |
| 36 | .start = 0, |
| 37 | .end = 0, |
| 38 | .flags = IORESOURCE_BUSY | IORESOURCE_MEM |
| 39 | }; |
| 40 | |
| 41 | |
| 42 | /* |
| 43 | * Do what every setup is needed on image and the |
| 44 | * reboot code buffer to allow us to avoid allocations |
| 45 | * later. |
| 46 | */ |
| 47 | int machine_kexec_prepare(struct kimage *image) |
| 48 | { |
| 49 | void *control_code_buffer; |
| 50 | const unsigned long *func; |
| 51 | |
| 52 | func = (unsigned long *)&relocate_new_kernel; |
| 53 | /* Pre-load control code buffer to minimize work in kexec path */ |
| 54 | control_code_buffer = page_address(image->control_code_page); |
| 55 | memcpy((void *)control_code_buffer, (const void *)func[0], |
| 56 | relocate_new_kernel_size); |
| 57 | flush_icache_range((unsigned long)control_code_buffer, |
| 58 | (unsigned long)control_code_buffer + relocate_new_kernel_size); |
| 59 | ia64_kimage = image; |
| 60 | |
| 61 | return 0; |
| 62 | } |
| 63 | |
| 64 | void machine_kexec_cleanup(struct kimage *image) |
| 65 | { |
| 66 | } |
| 67 | |
| 68 | void machine_shutdown(void) |
| 69 | { |
| 70 | int cpu; |
| 71 | |
| 72 | for_each_online_cpu(cpu) { |
| 73 | if (cpu != smp_processor_id()) |
| 74 | cpu_down(cpu); |
| 75 | } |
| 76 | kexec_disable_iosapic(); |
| 77 | } |
| 78 | |
| 79 | /* |
| 80 | * Do not allocate memory (or fail in any way) in machine_kexec(). |
| 81 | * We are past the point of no return, committed to rebooting now. |
| 82 | */ |
| 83 | extern void *efi_get_pal_addr(void); |
| 84 | static void ia64_machine_kexec(struct unw_frame_info *info, void *arg) |
| 85 | { |
| 86 | struct kimage *image = arg; |
| 87 | relocate_new_kernel_t rnk; |
| 88 | void *pal_addr = efi_get_pal_addr(); |
| 89 | unsigned long code_addr = (unsigned long)page_address(image->control_code_page); |
| 90 | unsigned long vector; |
| 91 | int ii; |
| 92 | |
| 93 | if (image->type == KEXEC_TYPE_CRASH) { |
| 94 | crash_save_this_cpu(); |
| 95 | current->thread.ksp = (__u64)info->sw - 16; |
| 96 | } |
| 97 | |
| 98 | /* Interrupts aren't acceptable while we reboot */ |
| 99 | local_irq_disable(); |
| 100 | |
| 101 | /* Mask CMC and Performance Monitor interrupts */ |
| 102 | ia64_setreg(_IA64_REG_CR_PMV, 1 << 16); |
| 103 | ia64_setreg(_IA64_REG_CR_CMCV, 1 << 16); |
| 104 | |
| 105 | /* Mask ITV and Local Redirect Registers */ |
| 106 | ia64_set_itv(1 << 16); |
| 107 | ia64_set_lrr0(1 << 16); |
| 108 | ia64_set_lrr1(1 << 16); |
| 109 | |
| 110 | /* terminate possible nested in-service interrupts */ |
| 111 | for (ii = 0; ii < 16; ii++) |
| 112 | ia64_eoi(); |
| 113 | |
| 114 | /* unmask TPR and clear any pending interrupts */ |
| 115 | ia64_setreg(_IA64_REG_CR_TPR, 0); |
| 116 | ia64_srlz_d(); |
| 117 | vector = ia64_get_ivr(); |
| 118 | while (vector != IA64_SPURIOUS_INT_VECTOR) { |
| 119 | ia64_eoi(); |
| 120 | vector = ia64_get_ivr(); |
| 121 | } |
| 122 | platform_kernel_launch_event(); |
| 123 | rnk = (relocate_new_kernel_t)&code_addr; |
| 124 | (*rnk)(image->head, image->start, ia64_boot_param, |
| 125 | GRANULEROUNDDOWN((unsigned long) pal_addr)); |
| 126 | BUG(); |
| 127 | } |
| 128 | |
| 129 | void machine_kexec(struct kimage *image) |
| 130 | { |
| 131 | unw_init_running(ia64_machine_kexec, image); |
| 132 | for(;;); |
| 133 | } |