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> |
Horms | abac08db | 2007-02-05 10:16:20 +0900 | [diff] [blame] | 17 | #include <linux/efi.h> |
Zou Nan hai | a795611 | 2006-12-07 09:51:35 -0800 | [diff] [blame] | 18 | #include <asm/mmu_context.h> |
| 19 | #include <asm/setup.h> |
| 20 | #include <asm/delay.h> |
| 21 | #include <asm/meminit.h> |
| 22 | |
Horms | 53da576 | 2006-12-12 18:06:13 +0900 | [diff] [blame] | 23 | typedef NORET_TYPE void (*relocate_new_kernel_t)( |
| 24 | unsigned long indirection_page, |
| 25 | unsigned long start_address, |
| 26 | struct ia64_boot_param *boot_param, |
| 27 | unsigned long pal_addr) ATTRIB_NORET; |
Zou Nan hai | a795611 | 2006-12-07 09:51:35 -0800 | [diff] [blame] | 28 | |
| 29 | struct kimage *ia64_kimage; |
| 30 | |
| 31 | struct resource efi_memmap_res = { |
| 32 | .name = "EFI Memory Map", |
| 33 | .start = 0, |
| 34 | .end = 0, |
| 35 | .flags = IORESOURCE_BUSY | IORESOURCE_MEM |
| 36 | }; |
| 37 | |
| 38 | struct resource boot_param_res = { |
| 39 | .name = "Boot parameter", |
| 40 | .start = 0, |
| 41 | .end = 0, |
| 42 | .flags = IORESOURCE_BUSY | IORESOURCE_MEM |
| 43 | }; |
| 44 | |
| 45 | |
| 46 | /* |
| 47 | * Do what every setup is needed on image and the |
| 48 | * reboot code buffer to allow us to avoid allocations |
| 49 | * later. |
| 50 | */ |
| 51 | int machine_kexec_prepare(struct kimage *image) |
| 52 | { |
| 53 | void *control_code_buffer; |
| 54 | const unsigned long *func; |
| 55 | |
| 56 | func = (unsigned long *)&relocate_new_kernel; |
| 57 | /* Pre-load control code buffer to minimize work in kexec path */ |
| 58 | control_code_buffer = page_address(image->control_code_page); |
| 59 | memcpy((void *)control_code_buffer, (const void *)func[0], |
| 60 | relocate_new_kernel_size); |
| 61 | flush_icache_range((unsigned long)control_code_buffer, |
| 62 | (unsigned long)control_code_buffer + relocate_new_kernel_size); |
| 63 | ia64_kimage = image; |
| 64 | |
| 65 | return 0; |
| 66 | } |
| 67 | |
| 68 | void machine_kexec_cleanup(struct kimage *image) |
| 69 | { |
| 70 | } |
| 71 | |
Zou Nan hai | a795611 | 2006-12-07 09:51:35 -0800 | [diff] [blame] | 72 | /* |
| 73 | * Do not allocate memory (or fail in any way) in machine_kexec(). |
| 74 | * We are past the point of no return, committed to rebooting now. |
| 75 | */ |
Zou Nan hai | a795611 | 2006-12-07 09:51:35 -0800 | [diff] [blame] | 76 | static void ia64_machine_kexec(struct unw_frame_info *info, void *arg) |
| 77 | { |
| 78 | struct kimage *image = arg; |
| 79 | relocate_new_kernel_t rnk; |
| 80 | void *pal_addr = efi_get_pal_addr(); |
| 81 | unsigned long code_addr = (unsigned long)page_address(image->control_code_page); |
Zou Nan hai | a795611 | 2006-12-07 09:51:35 -0800 | [diff] [blame] | 82 | int ii; |
| 83 | |
Bernhard Walle | c2c77fe | 2007-01-28 13:47:02 +0100 | [diff] [blame] | 84 | BUG_ON(!image); |
Zou Nan hai | a795611 | 2006-12-07 09:51:35 -0800 | [diff] [blame] | 85 | if (image->type == KEXEC_TYPE_CRASH) { |
| 86 | crash_save_this_cpu(); |
| 87 | current->thread.ksp = (__u64)info->sw - 16; |
| 88 | } |
| 89 | |
| 90 | /* Interrupts aren't acceptable while we reboot */ |
| 91 | local_irq_disable(); |
| 92 | |
| 93 | /* Mask CMC and Performance Monitor interrupts */ |
| 94 | ia64_setreg(_IA64_REG_CR_PMV, 1 << 16); |
| 95 | ia64_setreg(_IA64_REG_CR_CMCV, 1 << 16); |
| 96 | |
| 97 | /* Mask ITV and Local Redirect Registers */ |
| 98 | ia64_set_itv(1 << 16); |
| 99 | ia64_set_lrr0(1 << 16); |
| 100 | ia64_set_lrr1(1 << 16); |
| 101 | |
| 102 | /* terminate possible nested in-service interrupts */ |
| 103 | for (ii = 0; ii < 16; ii++) |
| 104 | ia64_eoi(); |
| 105 | |
| 106 | /* unmask TPR and clear any pending interrupts */ |
| 107 | ia64_setreg(_IA64_REG_CR_TPR, 0); |
| 108 | ia64_srlz_d(); |
Simon Horman | a62c9fe | 2007-09-19 14:02:20 +0900 | [diff] [blame^] | 109 | while (ia64_get_ivr() != IA64_SPURIOUS_INT_VECTOR) |
Zou Nan hai | a795611 | 2006-12-07 09:51:35 -0800 | [diff] [blame] | 110 | ia64_eoi(); |
Zou Nan hai | a795611 | 2006-12-07 09:51:35 -0800 | [diff] [blame] | 111 | platform_kernel_launch_event(); |
| 112 | rnk = (relocate_new_kernel_t)&code_addr; |
| 113 | (*rnk)(image->head, image->start, ia64_boot_param, |
| 114 | GRANULEROUNDDOWN((unsigned long) pal_addr)); |
| 115 | BUG(); |
| 116 | } |
| 117 | |
| 118 | void machine_kexec(struct kimage *image) |
| 119 | { |
Bernhard Walle | c2c77fe | 2007-01-28 13:47:02 +0100 | [diff] [blame] | 120 | BUG_ON(!image); |
Zou Nan hai | a795611 | 2006-12-07 09:51:35 -0800 | [diff] [blame] | 121 | unw_init_running(ia64_machine_kexec, image); |
| 122 | for(;;); |
| 123 | } |