Commit | Line | Data |
---|---|---|
40b0b3f8 | 1 | // SPDX-License-Identifier: GPL-2.0-only |
a7956113 ZN |
2 | /* |
3 | * arch/ia64/kernel/machine_kexec.c | |
4 | * | |
5 | * Handle transition of Linux booting another kernel | |
6 | * Copyright (C) 2005 Hewlett-Packard Development Comapny, L.P. | |
7 | * Copyright (C) 2005 Khalid Aziz <khalid.aziz@hp.com> | |
8 | * Copyright (C) 2006 Intel Corp, Zou Nan hai <nanhai.zou@intel.com> | |
a7956113 ZN |
9 | */ |
10 | ||
11 | #include <linux/mm.h> | |
12 | #include <linux/kexec.h> | |
13 | #include <linux/cpu.h> | |
14 | #include <linux/irq.h> | |
abac08db | 15 | #include <linux/efi.h> |
fd59d231 KO |
16 | #include <linux/numa.h> |
17 | #include <linux/mmzone.h> | |
7259888e | 18 | |
8ff059b8 | 19 | #include <asm/efi.h> |
7259888e | 20 | #include <asm/numa.h> |
a7956113 ZN |
21 | #include <asm/mmu_context.h> |
22 | #include <asm/setup.h> | |
23 | #include <asm/delay.h> | |
24 | #include <asm/meminit.h> | |
00cab92f | 25 | #include <asm/processor.h> |
07a6a4ae HS |
26 | #include <asm/sal.h> |
27 | #include <asm/mca.h> | |
a7956113 | 28 | |
9402c95f | 29 | typedef void (*relocate_new_kernel_t)( |
53da5763 H |
30 | unsigned long indirection_page, |
31 | unsigned long start_address, | |
32 | struct ia64_boot_param *boot_param, | |
ff2d8b19 | 33 | unsigned long pal_addr) __noreturn; |
a7956113 ZN |
34 | |
35 | struct kimage *ia64_kimage; | |
36 | ||
37 | struct resource efi_memmap_res = { | |
38 | .name = "EFI Memory Map", | |
39 | .start = 0, | |
40 | .end = 0, | |
41 | .flags = IORESOURCE_BUSY | IORESOURCE_MEM | |
42 | }; | |
43 | ||
44 | struct resource boot_param_res = { | |
45 | .name = "Boot parameter", | |
46 | .start = 0, | |
47 | .end = 0, | |
48 | .flags = IORESOURCE_BUSY | IORESOURCE_MEM | |
49 | }; | |
50 | ||
51 | ||
52 | /* | |
53 | * Do what every setup is needed on image and the | |
54 | * reboot code buffer to allow us to avoid allocations | |
55 | * later. | |
56 | */ | |
57 | int machine_kexec_prepare(struct kimage *image) | |
58 | { | |
59 | void *control_code_buffer; | |
60 | const unsigned long *func; | |
61 | ||
62 | func = (unsigned long *)&relocate_new_kernel; | |
63 | /* Pre-load control code buffer to minimize work in kexec path */ | |
64 | control_code_buffer = page_address(image->control_code_page); | |
65 | memcpy((void *)control_code_buffer, (const void *)func[0], | |
66 | relocate_new_kernel_size); | |
67 | flush_icache_range((unsigned long)control_code_buffer, | |
68 | (unsigned long)control_code_buffer + relocate_new_kernel_size); | |
69 | ia64_kimage = image; | |
70 | ||
71 | return 0; | |
72 | } | |
73 | ||
74 | void machine_kexec_cleanup(struct kimage *image) | |
75 | { | |
76 | } | |
77 | ||
a7956113 ZN |
78 | /* |
79 | * Do not allocate memory (or fail in any way) in machine_kexec(). | |
80 | * We are past the point of no return, committed to rebooting now. | |
81 | */ | |
a7956113 ZN |
82 | static void ia64_machine_kexec(struct unw_frame_info *info, void *arg) |
83 | { | |
84 | struct kimage *image = arg; | |
85 | relocate_new_kernel_t rnk; | |
86 | void *pal_addr = efi_get_pal_addr(); | |
36a45e74 | 87 | unsigned long code_addr; |
a7956113 | 88 | int ii; |
07a6a4ae HS |
89 | u64 fp, gp; |
90 | ia64_fptr_t *init_handler = (ia64_fptr_t *)ia64_os_init_on_kdump; | |
a7956113 | 91 | |
c2c77fe8 | 92 | BUG_ON(!image); |
36a45e74 | 93 | code_addr = (unsigned long)page_address(image->control_code_page); |
a7956113 ZN |
94 | if (image->type == KEXEC_TYPE_CRASH) { |
95 | crash_save_this_cpu(); | |
96 | current->thread.ksp = (__u64)info->sw - 16; | |
07a6a4ae HS |
97 | |
98 | /* Register noop init handler */ | |
99 | fp = ia64_tpa(init_handler->fp); | |
100 | gp = ia64_tpa(ia64_getreg(_IA64_REG_GP)); | |
101 | ia64_sal_set_vectors(SAL_VECTOR_OS_INIT, fp, gp, 0, fp, gp, 0); | |
102 | } else { | |
103 | /* Unregister init handlers of current kernel */ | |
104 | ia64_sal_set_vectors(SAL_VECTOR_OS_INIT, 0, 0, 0, 0, 0, 0); | |
a7956113 ZN |
105 | } |
106 | ||
6cc3efcd HS |
107 | /* Unregister mca handler - No more recovery on current kernel */ |
108 | ia64_sal_set_vectors(SAL_VECTOR_OS_MCA, 0, 0, 0, 0, 0, 0); | |
109 | ||
a7956113 ZN |
110 | /* Interrupts aren't acceptable while we reboot */ |
111 | local_irq_disable(); | |
112 | ||
113 | /* Mask CMC and Performance Monitor interrupts */ | |
114 | ia64_setreg(_IA64_REG_CR_PMV, 1 << 16); | |
115 | ia64_setreg(_IA64_REG_CR_CMCV, 1 << 16); | |
116 | ||
117 | /* Mask ITV and Local Redirect Registers */ | |
118 | ia64_set_itv(1 << 16); | |
119 | ia64_set_lrr0(1 << 16); | |
120 | ia64_set_lrr1(1 << 16); | |
121 | ||
122 | /* terminate possible nested in-service interrupts */ | |
123 | for (ii = 0; ii < 16; ii++) | |
124 | ia64_eoi(); | |
125 | ||
126 | /* unmask TPR and clear any pending interrupts */ | |
127 | ia64_setreg(_IA64_REG_CR_TPR, 0); | |
128 | ia64_srlz_d(); | |
a62c9fe4 | 129 | while (ia64_get_ivr() != IA64_SPURIOUS_INT_VECTOR) |
a7956113 | 130 | ia64_eoi(); |
a7956113 ZN |
131 | rnk = (relocate_new_kernel_t)&code_addr; |
132 | (*rnk)(image->head, image->start, ia64_boot_param, | |
133 | GRANULEROUNDDOWN((unsigned long) pal_addr)); | |
134 | BUG(); | |
135 | } | |
136 | ||
137 | void machine_kexec(struct kimage *image) | |
138 | { | |
c2c77fe8 | 139 | BUG_ON(!image); |
a7956113 ZN |
140 | unw_init_running(ia64_machine_kexec, image); |
141 | for(;;); | |
142 | } | |
fd59d231 KO |
143 | |
144 | void arch_crash_save_vmcoreinfo(void) | |
145 | { | |
9187592b | 146 | #if defined(CONFIG_SPARSEMEM) |
bcbba6c1 KO |
147 | VMCOREINFO_SYMBOL(pgdat_list); |
148 | VMCOREINFO_LENGTH(pgdat_list, MAX_NUMNODES); | |
92df5c3e KO |
149 | #endif |
150 | #ifdef CONFIG_NUMA | |
bcbba6c1 KO |
151 | VMCOREINFO_SYMBOL(node_memblk); |
152 | VMCOREINFO_LENGTH(node_memblk, NR_NODE_MEMBLKS); | |
c76f860c | 153 | VMCOREINFO_STRUCT_SIZE(node_memblk_s); |
bcbba6c1 KO |
154 | VMCOREINFO_OFFSET(node_memblk_s, start_paddr); |
155 | VMCOREINFO_OFFSET(node_memblk_s, size); | |
fd59d231 | 156 | #endif |
4d66bcc7 | 157 | #if CONFIG_PGTABLE_LEVELS == 3 |
bcbba6c1 | 158 | VMCOREINFO_CONFIG(PGTABLE_3); |
4d66bcc7 | 159 | #elif CONFIG_PGTABLE_LEVELS == 4 |
bcbba6c1 | 160 | VMCOREINFO_CONFIG(PGTABLE_4); |
fd59d231 KO |
161 | #endif |
162 | } | |
163 |