Zou Nan hai | a7956113 | 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> |
Ken'ichi Ohmichi | fd59d23 | 2007-10-16 23:27:27 -0700 | [diff] [blame] | 18 | #include <linux/numa.h> |
| 19 | #include <linux/mmzone.h> |
Andrew Morton | 7259888 | 2007-10-17 14:28:38 -0700 | [diff] [blame] | 20 | |
| 21 | #include <asm/numa.h> |
Zou Nan hai | a7956113 | 2006-12-07 09:51:35 -0800 | [diff] [blame] | 22 | #include <asm/mmu_context.h> |
| 23 | #include <asm/setup.h> |
| 24 | #include <asm/delay.h> |
| 25 | #include <asm/meminit.h> |
Ken'ichi Ohmichi | 00cab92 | 2007-10-16 23:27:29 -0700 | [diff] [blame] | 26 | #include <asm/processor.h> |
Hidetoshi Seto | 07a6a4a | 2009-08-06 14:51:56 -0700 | [diff] [blame] | 27 | #include <asm/sal.h> |
| 28 | #include <asm/mca.h> |
Zou Nan hai | a7956113 | 2006-12-07 09:51:35 -0800 | [diff] [blame] | 29 | |
Joe Perches | 9402c95 | 2012-01-12 17:17:17 -0800 | [diff] [blame] | 30 | typedef void (*relocate_new_kernel_t)( |
Horms | 53da576 | 2006-12-12 18:06:13 +0900 | [diff] [blame] | 31 | unsigned long indirection_page, |
| 32 | unsigned long start_address, |
| 33 | struct ia64_boot_param *boot_param, |
Joe Perches | ff2d8b1 | 2012-01-12 17:17:21 -0800 | [diff] [blame] | 34 | unsigned long pal_addr) __noreturn; |
Zou Nan hai | a7956113 | 2006-12-07 09:51:35 -0800 | [diff] [blame] | 35 | |
| 36 | struct kimage *ia64_kimage; |
| 37 | |
| 38 | struct resource efi_memmap_res = { |
| 39 | .name = "EFI Memory Map", |
| 40 | .start = 0, |
| 41 | .end = 0, |
| 42 | .flags = IORESOURCE_BUSY | IORESOURCE_MEM |
| 43 | }; |
| 44 | |
| 45 | struct resource boot_param_res = { |
| 46 | .name = "Boot parameter", |
| 47 | .start = 0, |
| 48 | .end = 0, |
| 49 | .flags = IORESOURCE_BUSY | IORESOURCE_MEM |
| 50 | }; |
| 51 | |
| 52 | |
| 53 | /* |
| 54 | * Do what every setup is needed on image and the |
| 55 | * reboot code buffer to allow us to avoid allocations |
| 56 | * later. |
| 57 | */ |
| 58 | int machine_kexec_prepare(struct kimage *image) |
| 59 | { |
| 60 | void *control_code_buffer; |
| 61 | const unsigned long *func; |
| 62 | |
| 63 | func = (unsigned long *)&relocate_new_kernel; |
| 64 | /* Pre-load control code buffer to minimize work in kexec path */ |
| 65 | control_code_buffer = page_address(image->control_code_page); |
| 66 | memcpy((void *)control_code_buffer, (const void *)func[0], |
| 67 | relocate_new_kernel_size); |
| 68 | flush_icache_range((unsigned long)control_code_buffer, |
| 69 | (unsigned long)control_code_buffer + relocate_new_kernel_size); |
| 70 | ia64_kimage = image; |
| 71 | |
| 72 | return 0; |
| 73 | } |
| 74 | |
| 75 | void machine_kexec_cleanup(struct kimage *image) |
| 76 | { |
| 77 | } |
| 78 | |
Zou Nan hai | a7956113 | 2006-12-07 09:51:35 -0800 | [diff] [blame] | 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 | */ |
Zou Nan hai | a7956113 | 2006-12-07 09:51:35 -0800 | [diff] [blame] | 83 | static void ia64_machine_kexec(struct unw_frame_info *info, void *arg) |
| 84 | { |
| 85 | struct kimage *image = arg; |
| 86 | relocate_new_kernel_t rnk; |
| 87 | void *pal_addr = efi_get_pal_addr(); |
Wei Yongjun | 36a45e7 | 2012-09-10 12:49:57 +0800 | [diff] [blame] | 88 | unsigned long code_addr; |
Zou Nan hai | a7956113 | 2006-12-07 09:51:35 -0800 | [diff] [blame] | 89 | int ii; |
Hidetoshi Seto | 07a6a4a | 2009-08-06 14:51:56 -0700 | [diff] [blame] | 90 | u64 fp, gp; |
| 91 | ia64_fptr_t *init_handler = (ia64_fptr_t *)ia64_os_init_on_kdump; |
Zou Nan hai | a7956113 | 2006-12-07 09:51:35 -0800 | [diff] [blame] | 92 | |
Bernhard Walle | c2c77fe | 2007-01-28 13:47:02 +0100 | [diff] [blame] | 93 | BUG_ON(!image); |
Wei Yongjun | 36a45e7 | 2012-09-10 12:49:57 +0800 | [diff] [blame] | 94 | code_addr = (unsigned long)page_address(image->control_code_page); |
Zou Nan hai | a7956113 | 2006-12-07 09:51:35 -0800 | [diff] [blame] | 95 | if (image->type == KEXEC_TYPE_CRASH) { |
| 96 | crash_save_this_cpu(); |
| 97 | current->thread.ksp = (__u64)info->sw - 16; |
Hidetoshi Seto | 07a6a4a | 2009-08-06 14:51:56 -0700 | [diff] [blame] | 98 | |
| 99 | /* Register noop init handler */ |
| 100 | fp = ia64_tpa(init_handler->fp); |
| 101 | gp = ia64_tpa(ia64_getreg(_IA64_REG_GP)); |
| 102 | ia64_sal_set_vectors(SAL_VECTOR_OS_INIT, fp, gp, 0, fp, gp, 0); |
| 103 | } else { |
| 104 | /* Unregister init handlers of current kernel */ |
| 105 | ia64_sal_set_vectors(SAL_VECTOR_OS_INIT, 0, 0, 0, 0, 0, 0); |
Zou Nan hai | a7956113 | 2006-12-07 09:51:35 -0800 | [diff] [blame] | 106 | } |
| 107 | |
Hidetoshi Seto | 6cc3efc | 2009-08-06 14:51:57 -0700 | [diff] [blame] | 108 | /* Unregister mca handler - No more recovery on current kernel */ |
| 109 | ia64_sal_set_vectors(SAL_VECTOR_OS_MCA, 0, 0, 0, 0, 0, 0); |
| 110 | |
Zou Nan hai | a7956113 | 2006-12-07 09:51:35 -0800 | [diff] [blame] | 111 | /* Interrupts aren't acceptable while we reboot */ |
| 112 | local_irq_disable(); |
| 113 | |
| 114 | /* Mask CMC and Performance Monitor interrupts */ |
| 115 | ia64_setreg(_IA64_REG_CR_PMV, 1 << 16); |
| 116 | ia64_setreg(_IA64_REG_CR_CMCV, 1 << 16); |
| 117 | |
| 118 | /* Mask ITV and Local Redirect Registers */ |
| 119 | ia64_set_itv(1 << 16); |
| 120 | ia64_set_lrr0(1 << 16); |
| 121 | ia64_set_lrr1(1 << 16); |
| 122 | |
| 123 | /* terminate possible nested in-service interrupts */ |
| 124 | for (ii = 0; ii < 16; ii++) |
| 125 | ia64_eoi(); |
| 126 | |
| 127 | /* unmask TPR and clear any pending interrupts */ |
| 128 | ia64_setreg(_IA64_REG_CR_TPR, 0); |
| 129 | ia64_srlz_d(); |
Simon Horman | a62c9fe | 2007-09-19 14:02:20 +0900 | [diff] [blame] | 130 | while (ia64_get_ivr() != IA64_SPURIOUS_INT_VECTOR) |
Zou Nan hai | a7956113 | 2006-12-07 09:51:35 -0800 | [diff] [blame] | 131 | ia64_eoi(); |
Zou Nan hai | a7956113 | 2006-12-07 09:51:35 -0800 | [diff] [blame] | 132 | platform_kernel_launch_event(); |
| 133 | rnk = (relocate_new_kernel_t)&code_addr; |
| 134 | (*rnk)(image->head, image->start, ia64_boot_param, |
| 135 | GRANULEROUNDDOWN((unsigned long) pal_addr)); |
| 136 | BUG(); |
| 137 | } |
| 138 | |
| 139 | void machine_kexec(struct kimage *image) |
| 140 | { |
Bernhard Walle | c2c77fe | 2007-01-28 13:47:02 +0100 | [diff] [blame] | 141 | BUG_ON(!image); |
Zou Nan hai | a7956113 | 2006-12-07 09:51:35 -0800 | [diff] [blame] | 142 | unw_init_running(ia64_machine_kexec, image); |
| 143 | for(;;); |
| 144 | } |
Ken'ichi Ohmichi | fd59d23 | 2007-10-16 23:27:27 -0700 | [diff] [blame] | 145 | |
| 146 | void arch_crash_save_vmcoreinfo(void) |
| 147 | { |
Ken'ichi Ohmichi | 92df5c3 | 2008-02-07 00:15:23 -0800 | [diff] [blame] | 148 | #if defined(CONFIG_DISCONTIGMEM) || defined(CONFIG_SPARSEMEM) |
Ken'ichi Ohmichi | bcbba6c | 2007-10-16 23:27:30 -0700 | [diff] [blame] | 149 | VMCOREINFO_SYMBOL(pgdat_list); |
| 150 | VMCOREINFO_LENGTH(pgdat_list, MAX_NUMNODES); |
Ken'ichi Ohmichi | 92df5c3 | 2008-02-07 00:15:23 -0800 | [diff] [blame] | 151 | #endif |
| 152 | #ifdef CONFIG_NUMA |
Ken'ichi Ohmichi | bcbba6c | 2007-10-16 23:27:30 -0700 | [diff] [blame] | 153 | VMCOREINFO_SYMBOL(node_memblk); |
| 154 | VMCOREINFO_LENGTH(node_memblk, NR_NODE_MEMBLKS); |
Ken'ichi Ohmichi | c76f860 | 2008-02-07 00:15:20 -0800 | [diff] [blame] | 155 | VMCOREINFO_STRUCT_SIZE(node_memblk_s); |
Ken'ichi Ohmichi | bcbba6c | 2007-10-16 23:27:30 -0700 | [diff] [blame] | 156 | VMCOREINFO_OFFSET(node_memblk_s, start_paddr); |
| 157 | VMCOREINFO_OFFSET(node_memblk_s, size); |
Ken'ichi Ohmichi | fd59d23 | 2007-10-16 23:27:27 -0700 | [diff] [blame] | 158 | #endif |
Kirill A. Shutemov | 4d66bcc | 2015-04-14 15:45:45 -0700 | [diff] [blame] | 159 | #if CONFIG_PGTABLE_LEVELS == 3 |
Ken'ichi Ohmichi | bcbba6c | 2007-10-16 23:27:30 -0700 | [diff] [blame] | 160 | VMCOREINFO_CONFIG(PGTABLE_3); |
Kirill A. Shutemov | 4d66bcc | 2015-04-14 15:45:45 -0700 | [diff] [blame] | 161 | #elif CONFIG_PGTABLE_LEVELS == 4 |
Ken'ichi Ohmichi | bcbba6c | 2007-10-16 23:27:30 -0700 | [diff] [blame] | 162 | VMCOREINFO_CONFIG(PGTABLE_4); |
Ken'ichi Ohmichi | fd59d23 | 2007-10-16 23:27:27 -0700 | [diff] [blame] | 163 | #endif |
| 164 | } |
| 165 | |
| 166 | unsigned long paddr_vmcoreinfo_note(void) |
| 167 | { |
Ken'ichi Ohmichi | 00cab92 | 2007-10-16 23:27:29 -0700 | [diff] [blame] | 168 | return ia64_tpa((unsigned long)(char *)&vmcoreinfo_note); |
Ken'ichi Ohmichi | fd59d23 | 2007-10-16 23:27:27 -0700 | [diff] [blame] | 169 | } |
| 170 | |