Thomas Gleixner | 40b0b3f | 2019-06-03 07:44:46 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
Nicolas Schichan | 583bb86 | 2006-10-18 15:14:55 +0200 | [diff] [blame] | 2 | /* |
| 3 | * relocate_kernel.S for kexec |
| 4 | * Created by <nschichan@corp.free.fr> on Thu Oct 12 17:49:57 2006 |
Nicolas Schichan | 583bb86 | 2006-10-18 15:14:55 +0200 | [diff] [blame] | 5 | */ |
| 6 | |
| 7 | #include <asm/asm.h> |
| 8 | #include <asm/asmmacro.h> |
| 9 | #include <asm/regdef.h> |
Nicolas Schichan | 583bb86 | 2006-10-18 15:14:55 +0200 | [diff] [blame] | 10 | #include <asm/mipsregs.h> |
| 11 | #include <asm/stackframe.h> |
| 12 | #include <asm/addrspace.h> |
| 13 | |
Huacai Chen | 6ce4889 | 2021-04-13 16:57:23 +0800 | [diff] [blame] | 14 | #include <kernel-entry-init.h> |
| 15 | |
Ralf Baechle | 00be0f3 | 2007-07-31 15:17:21 +0100 | [diff] [blame] | 16 | LEAF(relocate_new_kernel) |
Ralf Baechle | 7aa1c8f | 2012-10-11 18:14:58 +0200 | [diff] [blame] | 17 | PTR_L a0, arg0 |
| 18 | PTR_L a1, arg1 |
| 19 | PTR_L a2, arg2 |
| 20 | PTR_L a3, arg3 |
| 21 | |
Ralf Baechle | 00be0f3 | 2007-07-31 15:17:21 +0100 | [diff] [blame] | 22 | PTR_L s0, kexec_indirection_page |
| 23 | PTR_L s1, kexec_start_address |
Nicolas Schichan | 583bb86 | 2006-10-18 15:14:55 +0200 | [diff] [blame] | 24 | |
| 25 | process_entry: |
Ralf Baechle | 00be0f3 | 2007-07-31 15:17:21 +0100 | [diff] [blame] | 26 | PTR_L s2, (s0) |
James Cowgill | a450475 | 2015-06-17 17:12:50 +0100 | [diff] [blame] | 27 | PTR_ADDIU s0, s0, SZREG |
Nicolas Schichan | 583bb86 | 2006-10-18 15:14:55 +0200 | [diff] [blame] | 28 | |
Prem Mallappa | 273463b | 2013-08-30 15:35:10 +0530 | [diff] [blame] | 29 | /* |
| 30 | * In case of a kdump/crash kernel, the indirection page is not |
| 31 | * populated as the kernel is directly copied to a reserved location |
| 32 | */ |
| 33 | beqz s2, done |
| 34 | |
Nicolas Schichan | 583bb86 | 2006-10-18 15:14:55 +0200 | [diff] [blame] | 35 | /* destination page */ |
Ralf Baechle | 00be0f3 | 2007-07-31 15:17:21 +0100 | [diff] [blame] | 36 | and s3, s2, 0x1 |
| 37 | beq s3, zero, 1f |
| 38 | and s4, s2, ~0x1 /* store destination addr in s4 */ |
Ralf Baechle | 00be0f3 | 2007-07-31 15:17:21 +0100 | [diff] [blame] | 39 | b process_entry |
Nicolas Schichan | 583bb86 | 2006-10-18 15:14:55 +0200 | [diff] [blame] | 40 | |
| 41 | 1: |
Ralf Baechle | 7034228 | 2013-01-22 12:59:30 +0100 | [diff] [blame] | 42 | /* indirection page, update s0 */ |
Ralf Baechle | 00be0f3 | 2007-07-31 15:17:21 +0100 | [diff] [blame] | 43 | and s3, s2, 0x2 |
| 44 | beq s3, zero, 1f |
| 45 | and s0, s2, ~0x2 |
| 46 | b process_entry |
Nicolas Schichan | 583bb86 | 2006-10-18 15:14:55 +0200 | [diff] [blame] | 47 | |
| 48 | 1: |
| 49 | /* done page */ |
Ralf Baechle | 00be0f3 | 2007-07-31 15:17:21 +0100 | [diff] [blame] | 50 | and s3, s2, 0x4 |
| 51 | beq s3, zero, 1f |
| 52 | b done |
Nicolas Schichan | 583bb86 | 2006-10-18 15:14:55 +0200 | [diff] [blame] | 53 | 1: |
| 54 | /* source page */ |
Ralf Baechle | 00be0f3 | 2007-07-31 15:17:21 +0100 | [diff] [blame] | 55 | and s3, s2, 0x8 |
| 56 | beq s3, zero, process_entry |
| 57 | and s2, s2, ~0x8 |
Ralf Baechle | bef9ae3 | 2012-12-28 15:15:25 +0100 | [diff] [blame] | 58 | li s6, (1 << _PAGE_SHIFT) / SZREG |
Nicolas Schichan | 583bb86 | 2006-10-18 15:14:55 +0200 | [diff] [blame] | 59 | |
| 60 | copy_word: |
| 61 | /* copy page word by word */ |
Ralf Baechle | 00be0f3 | 2007-07-31 15:17:21 +0100 | [diff] [blame] | 62 | REG_L s5, (s2) |
| 63 | REG_S s5, (s4) |
James Cowgill | a450475 | 2015-06-17 17:12:50 +0100 | [diff] [blame] | 64 | PTR_ADDIU s4, s4, SZREG |
| 65 | PTR_ADDIU s2, s2, SZREG |
| 66 | LONG_ADDIU s6, s6, -1 |
Ralf Baechle | 00be0f3 | 2007-07-31 15:17:21 +0100 | [diff] [blame] | 67 | beq s6, zero, process_entry |
| 68 | b copy_word |
| 69 | b process_entry |
Nicolas Schichan | 583bb86 | 2006-10-18 15:14:55 +0200 | [diff] [blame] | 70 | |
| 71 | done: |
Ralf Baechle | 7aa1c8f | 2012-10-11 18:14:58 +0200 | [diff] [blame] | 72 | #ifdef CONFIG_SMP |
| 73 | /* kexec_flag reset is signal to other CPUs what kernel |
| 74 | was moved to it's location. Note - we need relocated address |
| 75 | of kexec_flag. */ |
| 76 | |
| 77 | bal 1f |
Ralf Baechle | 7034228 | 2013-01-22 12:59:30 +0100 | [diff] [blame] | 78 | 1: move t1,ra; |
Ralf Baechle | 7aa1c8f | 2012-10-11 18:14:58 +0200 | [diff] [blame] | 79 | PTR_LA t2,1b |
| 80 | PTR_LA t0,kexec_flag |
| 81 | PTR_SUB t0,t0,t2; |
| 82 | PTR_ADD t0,t1,t0; |
| 83 | LONG_S zero,(t0) |
| 84 | #endif |
| 85 | |
Ralf Baechle | abe77f9 | 2012-10-25 16:23:31 +0200 | [diff] [blame] | 86 | #ifdef CONFIG_CPU_CAVIUM_OCTEON |
| 87 | /* We need to flush I-cache before jumping to new kernel. |
Yegor Yefremov | 28a87b4 | 2018-04-25 09:39:06 +0200 | [diff] [blame] | 88 | * Unfortunately, this code is cpu-specific. |
Ralf Baechle | abe77f9 | 2012-10-25 16:23:31 +0200 | [diff] [blame] | 89 | */ |
| 90 | .set push |
| 91 | .set noreorder |
| 92 | syncw |
| 93 | syncw |
| 94 | synci 0($0) |
| 95 | .set pop |
| 96 | #else |
Ralf Baechle | 7aa1c8f | 2012-10-11 18:14:58 +0200 | [diff] [blame] | 97 | sync |
Ralf Baechle | abe77f9 | 2012-10-25 16:23:31 +0200 | [diff] [blame] | 98 | #endif |
Nicolas Schichan | 583bb86 | 2006-10-18 15:14:55 +0200 | [diff] [blame] | 99 | /* jump to kexec_start_address */ |
Ralf Baechle | 00be0f3 | 2007-07-31 15:17:21 +0100 | [diff] [blame] | 100 | j s1 |
| 101 | END(relocate_new_kernel) |
Nicolas Schichan | 583bb86 | 2006-10-18 15:14:55 +0200 | [diff] [blame] | 102 | |
Ralf Baechle | 7aa1c8f | 2012-10-11 18:14:58 +0200 | [diff] [blame] | 103 | #ifdef CONFIG_SMP |
| 104 | /* |
| 105 | * Other CPUs should wait until code is relocated and |
| 106 | * then start at entry (?) point. |
| 107 | */ |
| 108 | LEAF(kexec_smp_wait) |
| 109 | PTR_L a0, s_arg0 |
| 110 | PTR_L a1, s_arg1 |
| 111 | PTR_L a2, s_arg2 |
| 112 | PTR_L a3, s_arg3 |
| 113 | PTR_L s1, kexec_start_address |
| 114 | |
| 115 | /* Non-relocated address works for args and kexec_start_address ( old |
| 116 | * kernel is not overwritten). But we need relocated address of |
| 117 | * kexec_flag. |
| 118 | */ |
| 119 | |
| 120 | bal 1f |
| 121 | 1: move t1,ra; |
| 122 | PTR_LA t2,1b |
| 123 | PTR_LA t0,kexec_flag |
| 124 | PTR_SUB t0,t0,t2; |
| 125 | PTR_ADD t0,t1,t0; |
| 126 | |
| 127 | 1: LONG_L s0, (t0) |
| 128 | bne s0, zero,1b |
| 129 | |
Huacai Chen | 6ce4889 | 2021-04-13 16:57:23 +0800 | [diff] [blame] | 130 | #ifdef USE_KEXEC_SMP_WAIT_FINAL |
| 131 | kexec_smp_wait_final |
Ralf Baechle | abe77f9 | 2012-10-25 16:23:31 +0200 | [diff] [blame] | 132 | #else |
Ralf Baechle | 7aa1c8f | 2012-10-11 18:14:58 +0200 | [diff] [blame] | 133 | sync |
Ralf Baechle | abe77f9 | 2012-10-25 16:23:31 +0200 | [diff] [blame] | 134 | #endif |
Ralf Baechle | 7aa1c8f | 2012-10-11 18:14:58 +0200 | [diff] [blame] | 135 | j s1 |
| 136 | END(kexec_smp_wait) |
| 137 | #endif |
| 138 | |
| 139 | #ifdef __mips64 |
| 140 | /* all PTR's must be aligned to 8 byte in 64-bit mode */ |
| 141 | .align 3 |
| 142 | #endif |
| 143 | |
| 144 | /* All parameters to new kernel are passed in registers a0-a3. |
Yegor Yefremov | 28a87b4 | 2018-04-25 09:39:06 +0200 | [diff] [blame] | 145 | * kexec_args[0..3] are used to prepare register values. |
Ralf Baechle | 7aa1c8f | 2012-10-11 18:14:58 +0200 | [diff] [blame] | 146 | */ |
| 147 | |
| 148 | kexec_args: |
| 149 | EXPORT(kexec_args) |
Thomas Bogendoerfer | fa62f39 | 2022-01-25 15:19:44 +0100 | [diff] [blame] | 150 | arg0: PTR_WD 0x0 |
| 151 | arg1: PTR_WD 0x0 |
| 152 | arg2: PTR_WD 0x0 |
| 153 | arg3: PTR_WD 0x0 |
Ralf Baechle | 7aa1c8f | 2012-10-11 18:14:58 +0200 | [diff] [blame] | 154 | .size kexec_args,PTRSIZE*4 |
| 155 | |
| 156 | #ifdef CONFIG_SMP |
| 157 | /* |
| 158 | * Secondary CPUs may have different kernel parameters in |
| 159 | * their registers a0-a3. secondary_kexec_args[0..3] are used |
| 160 | * to prepare register values. |
| 161 | */ |
| 162 | secondary_kexec_args: |
| 163 | EXPORT(secondary_kexec_args) |
Thomas Bogendoerfer | fa62f39 | 2022-01-25 15:19:44 +0100 | [diff] [blame] | 164 | s_arg0: PTR_WD 0x0 |
| 165 | s_arg1: PTR_WD 0x0 |
| 166 | s_arg2: PTR_WD 0x0 |
| 167 | s_arg3: PTR_WD 0x0 |
Ralf Baechle | 7aa1c8f | 2012-10-11 18:14:58 +0200 | [diff] [blame] | 168 | .size secondary_kexec_args,PTRSIZE*4 |
| 169 | kexec_flag: |
| 170 | LONG 0x1 |
| 171 | |
| 172 | #endif |
| 173 | |
Nicolas Schichan | 583bb86 | 2006-10-18 15:14:55 +0200 | [diff] [blame] | 174 | kexec_start_address: |
Ralf Baechle | 00be0f3 | 2007-07-31 15:17:21 +0100 | [diff] [blame] | 175 | EXPORT(kexec_start_address) |
Thomas Bogendoerfer | fa62f39 | 2022-01-25 15:19:44 +0100 | [diff] [blame] | 176 | PTR_WD 0x0 |
Ralf Baechle | 00be0f3 | 2007-07-31 15:17:21 +0100 | [diff] [blame] | 177 | .size kexec_start_address, PTRSIZE |
Nicolas Schichan | 583bb86 | 2006-10-18 15:14:55 +0200 | [diff] [blame] | 178 | |
Nicolas Schichan | 583bb86 | 2006-10-18 15:14:55 +0200 | [diff] [blame] | 179 | kexec_indirection_page: |
Ralf Baechle | 00be0f3 | 2007-07-31 15:17:21 +0100 | [diff] [blame] | 180 | EXPORT(kexec_indirection_page) |
Thomas Bogendoerfer | fa62f39 | 2022-01-25 15:19:44 +0100 | [diff] [blame] | 181 | PTR_WD 0 |
Ralf Baechle | 00be0f3 | 2007-07-31 15:17:21 +0100 | [diff] [blame] | 182 | .size kexec_indirection_page, PTRSIZE |
Nicolas Schichan | 583bb86 | 2006-10-18 15:14:55 +0200 | [diff] [blame] | 183 | |
| 184 | relocate_new_kernel_end: |
| 185 | |
Nicolas Schichan | 583bb86 | 2006-10-18 15:14:55 +0200 | [diff] [blame] | 186 | relocate_new_kernel_size: |
Ralf Baechle | 00be0f3 | 2007-07-31 15:17:21 +0100 | [diff] [blame] | 187 | EXPORT(relocate_new_kernel_size) |
Thomas Bogendoerfer | fa62f39 | 2022-01-25 15:19:44 +0100 | [diff] [blame] | 188 | PTR_WD relocate_new_kernel_end - relocate_new_kernel |
Ralf Baechle | 00be0f3 | 2007-07-31 15:17:21 +0100 | [diff] [blame] | 189 | .size relocate_new_kernel_size, PTRSIZE |