Chris Zankel | 5a0015d | 2005-06-23 22:01:16 -0700 | [diff] [blame] | 1 | /* |
| 2 | * arch/xtensa/kernel/coprocessor.S |
| 3 | * |
| 4 | * Xtensa processor configuration-specific table of coprocessor and |
| 5 | * other custom register layout information. |
| 6 | * |
| 7 | * This file is subject to the terms and conditions of the GNU General Public |
| 8 | * License. See the file "COPYING" in the main directory of this archive |
| 9 | * for more details. |
| 10 | * |
Chris Zankel | c658eac | 2008-02-12 13:17:07 -0800 | [diff] [blame] | 11 | * Copyright (C) 2003 - 2007 Tensilica Inc. |
Chris Zankel | 5a0015d | 2005-06-23 22:01:16 -0700 | [diff] [blame] | 12 | */ |
| 13 | |
Chris Zankel | 5a0015d | 2005-06-23 22:01:16 -0700 | [diff] [blame] | 14 | |
Chris Zankel | 5a0015d | 2005-06-23 22:01:16 -0700 | [diff] [blame] | 15 | #include <linux/linkage.h> |
Chris Zankel | c658eac | 2008-02-12 13:17:07 -0800 | [diff] [blame] | 16 | #include <asm/asm-offsets.h> |
Max Filippov | e3cacb7 | 2019-07-24 17:39:47 -0700 | [diff] [blame] | 17 | #include <asm/asmmacro.h> |
Chris Zankel | 5a0015d | 2005-06-23 22:01:16 -0700 | [diff] [blame] | 18 | #include <asm/processor.h> |
Chris Zankel | c658eac | 2008-02-12 13:17:07 -0800 | [diff] [blame] | 19 | #include <asm/coprocessor.h> |
| 20 | #include <asm/thread_info.h> |
Al Viro | 7658023 | 2016-09-04 14:26:36 -0400 | [diff] [blame] | 21 | #include <asm/asm-uaccess.h> |
Chris Zankel | c658eac | 2008-02-12 13:17:07 -0800 | [diff] [blame] | 22 | #include <asm/unistd.h> |
| 23 | #include <asm/ptrace.h> |
| 24 | #include <asm/current.h> |
| 25 | #include <asm/pgtable.h> |
| 26 | #include <asm/page.h> |
| 27 | #include <asm/signal.h> |
| 28 | #include <asm/tlbflush.h> |
Chris Zankel | 5a0015d | 2005-06-23 22:01:16 -0700 | [diff] [blame] | 29 | |
Chris Zankel | c658eac | 2008-02-12 13:17:07 -0800 | [diff] [blame] | 30 | #if XTENSA_HAVE_COPROCESSORS |
Chris Zankel | 5a0015d | 2005-06-23 22:01:16 -0700 | [diff] [blame] | 31 | |
Chris Zankel | c658eac | 2008-02-12 13:17:07 -0800 | [diff] [blame] | 32 | /* |
| 33 | * Macros for lazy context switch. |
| 34 | */ |
Chris Zankel | 5a0015d | 2005-06-23 22:01:16 -0700 | [diff] [blame] | 35 | |
Chris Zankel | c658eac | 2008-02-12 13:17:07 -0800 | [diff] [blame] | 36 | #define SAVE_CP_REGS(x) \ |
Chris Zankel | c658eac | 2008-02-12 13:17:07 -0800 | [diff] [blame] | 37 | .if XTENSA_HAVE_COPROCESSOR(x); \ |
Max Filippov | 5dacbbe | 2018-11-25 23:32:28 -0800 | [diff] [blame] | 38 | .align 4; \ |
| 39 | .Lsave_cp_regs_cp##x: \ |
Chris Zankel | c658eac | 2008-02-12 13:17:07 -0800 | [diff] [blame] | 40 | xchal_cp##x##_store a2 a4 a5 a6 a7; \ |
Max Filippov | 5dacbbe | 2018-11-25 23:32:28 -0800 | [diff] [blame] | 41 | jx a0; \ |
| 42 | .endif |
Chris Zankel | c658eac | 2008-02-12 13:17:07 -0800 | [diff] [blame] | 43 | |
| 44 | #define SAVE_CP_REGS_TAB(x) \ |
| 45 | .if XTENSA_HAVE_COPROCESSOR(x); \ |
Max Filippov | 5dacbbe | 2018-11-25 23:32:28 -0800 | [diff] [blame] | 46 | .long .Lsave_cp_regs_cp##x; \ |
Chris Zankel | c658eac | 2008-02-12 13:17:07 -0800 | [diff] [blame] | 47 | .else; \ |
| 48 | .long 0; \ |
| 49 | .endif; \ |
| 50 | .long THREAD_XTREGS_CP##x |
| 51 | |
| 52 | |
| 53 | #define LOAD_CP_REGS(x) \ |
Chris Zankel | c658eac | 2008-02-12 13:17:07 -0800 | [diff] [blame] | 54 | .if XTENSA_HAVE_COPROCESSOR(x); \ |
Max Filippov | 5dacbbe | 2018-11-25 23:32:28 -0800 | [diff] [blame] | 55 | .align 4; \ |
| 56 | .Lload_cp_regs_cp##x: \ |
Chris Zankel | c658eac | 2008-02-12 13:17:07 -0800 | [diff] [blame] | 57 | xchal_cp##x##_load a2 a4 a5 a6 a7; \ |
Max Filippov | 5dacbbe | 2018-11-25 23:32:28 -0800 | [diff] [blame] | 58 | jx a0; \ |
| 59 | .endif |
Chris Zankel | c658eac | 2008-02-12 13:17:07 -0800 | [diff] [blame] | 60 | |
| 61 | #define LOAD_CP_REGS_TAB(x) \ |
| 62 | .if XTENSA_HAVE_COPROCESSOR(x); \ |
Max Filippov | 5dacbbe | 2018-11-25 23:32:28 -0800 | [diff] [blame] | 63 | .long .Lload_cp_regs_cp##x; \ |
Chris Zankel | c658eac | 2008-02-12 13:17:07 -0800 | [diff] [blame] | 64 | .else; \ |
| 65 | .long 0; \ |
| 66 | .endif; \ |
| 67 | .long THREAD_XTREGS_CP##x |
| 68 | |
| 69 | SAVE_CP_REGS(0) |
| 70 | SAVE_CP_REGS(1) |
| 71 | SAVE_CP_REGS(2) |
| 72 | SAVE_CP_REGS(3) |
| 73 | SAVE_CP_REGS(4) |
| 74 | SAVE_CP_REGS(5) |
| 75 | SAVE_CP_REGS(6) |
| 76 | SAVE_CP_REGS(7) |
| 77 | |
| 78 | LOAD_CP_REGS(0) |
| 79 | LOAD_CP_REGS(1) |
| 80 | LOAD_CP_REGS(2) |
| 81 | LOAD_CP_REGS(3) |
| 82 | LOAD_CP_REGS(4) |
| 83 | LOAD_CP_REGS(5) |
| 84 | LOAD_CP_REGS(6) |
| 85 | LOAD_CP_REGS(7) |
| 86 | |
Max Filippov | 5dacbbe | 2018-11-25 23:32:28 -0800 | [diff] [blame] | 87 | .section ".rodata", "a" |
Chris Zankel | c658eac | 2008-02-12 13:17:07 -0800 | [diff] [blame] | 88 | .align 4 |
| 89 | .Lsave_cp_regs_jump_table: |
| 90 | SAVE_CP_REGS_TAB(0) |
| 91 | SAVE_CP_REGS_TAB(1) |
| 92 | SAVE_CP_REGS_TAB(2) |
| 93 | SAVE_CP_REGS_TAB(3) |
| 94 | SAVE_CP_REGS_TAB(4) |
| 95 | SAVE_CP_REGS_TAB(5) |
| 96 | SAVE_CP_REGS_TAB(6) |
| 97 | SAVE_CP_REGS_TAB(7) |
| 98 | |
| 99 | .Lload_cp_regs_jump_table: |
| 100 | LOAD_CP_REGS_TAB(0) |
| 101 | LOAD_CP_REGS_TAB(1) |
| 102 | LOAD_CP_REGS_TAB(2) |
| 103 | LOAD_CP_REGS_TAB(3) |
| 104 | LOAD_CP_REGS_TAB(4) |
| 105 | LOAD_CP_REGS_TAB(5) |
| 106 | LOAD_CP_REGS_TAB(6) |
| 107 | LOAD_CP_REGS_TAB(7) |
| 108 | |
Max Filippov | 5dacbbe | 2018-11-25 23:32:28 -0800 | [diff] [blame] | 109 | .previous |
| 110 | |
Chris Zankel | c658eac | 2008-02-12 13:17:07 -0800 | [diff] [blame] | 111 | /* |
Max Filippov | 3ffc2df | 2018-11-26 13:15:21 -0800 | [diff] [blame] | 112 | * coprocessor_flush(struct thread_info*, index) |
Chris Zankel | c658eac | 2008-02-12 13:17:07 -0800 | [diff] [blame] | 113 | * a2 a3 |
Chris Zankel | 5a0015d | 2005-06-23 22:01:16 -0700 | [diff] [blame] | 114 | * |
Max Filippov | 3ffc2df | 2018-11-26 13:15:21 -0800 | [diff] [blame] | 115 | * Save coprocessor registers for coprocessor 'index'. |
Chris Zankel | c658eac | 2008-02-12 13:17:07 -0800 | [diff] [blame] | 116 | * The register values are saved to or loaded from the coprocessor area |
| 117 | * inside the task_info structure. |
Chris Zankel | 5a0015d | 2005-06-23 22:01:16 -0700 | [diff] [blame] | 118 | * |
Max Filippov | 3ffc2df | 2018-11-26 13:15:21 -0800 | [diff] [blame] | 119 | * Note that this function doesn't update the coprocessor_owner information! |
Chris Zankel | c658eac | 2008-02-12 13:17:07 -0800 | [diff] [blame] | 120 | * |
Chris Zankel | 5a0015d | 2005-06-23 22:01:16 -0700 | [diff] [blame] | 121 | */ |
| 122 | |
Chris Zankel | c658eac | 2008-02-12 13:17:07 -0800 | [diff] [blame] | 123 | ENTRY(coprocessor_flush) |
Chris Zankel | d1538c4 | 2012-11-16 16:16:20 -0800 | [diff] [blame] | 124 | |
Max Filippov | d6d5f19 | 2019-05-12 20:28:25 -0700 | [diff] [blame] | 125 | /* reserve 4 bytes on stack to save a0 */ |
| 126 | abi_entry(4) |
| 127 | |
Chris Zankel | c658eac | 2008-02-12 13:17:07 -0800 | [diff] [blame] | 128 | s32i a0, a1, 0 |
| 129 | movi a0, .Lsave_cp_regs_jump_table |
| 130 | addx8 a3, a3, a0 |
| 131 | l32i a4, a3, 4 |
| 132 | l32i a3, a3, 0 |
| 133 | add a2, a2, a4 |
| 134 | beqz a3, 1f |
Max Filippov | 5dacbbe | 2018-11-25 23:32:28 -0800 | [diff] [blame] | 135 | callx0 a3 |
Chris Zankel | c658eac | 2008-02-12 13:17:07 -0800 | [diff] [blame] | 136 | 1: l32i a0, a1, 0 |
Max Filippov | d6d5f19 | 2019-05-12 20:28:25 -0700 | [diff] [blame] | 137 | |
| 138 | abi_ret(4) |
Chris Zankel | 5a0015d | 2005-06-23 22:01:16 -0700 | [diff] [blame] | 139 | |
Chris Zankel | d1538c4 | 2012-11-16 16:16:20 -0800 | [diff] [blame] | 140 | ENDPROC(coprocessor_flush) |
| 141 | |
Chris Zankel | 5a0015d | 2005-06-23 22:01:16 -0700 | [diff] [blame] | 142 | /* |
Chris Zankel | c658eac | 2008-02-12 13:17:07 -0800 | [diff] [blame] | 143 | * Entry condition: |
| 144 | * |
| 145 | * a0: trashed, original value saved on stack (PT_AREG0) |
| 146 | * a1: a1 |
| 147 | * a2: new stack pointer, original in DEPC |
Max Filippov | 99d5040 | 2013-07-03 20:23:28 +0400 | [diff] [blame] | 148 | * a3: a3 |
Chris Zankel | c658eac | 2008-02-12 13:17:07 -0800 | [diff] [blame] | 149 | * depc: a2, original value saved on stack (PT_DEPC) |
Max Filippov | 99d5040 | 2013-07-03 20:23:28 +0400 | [diff] [blame] | 150 | * excsave_1: dispatch table |
Chris Zankel | c658eac | 2008-02-12 13:17:07 -0800 | [diff] [blame] | 151 | * |
| 152 | * PT_DEPC >= VALID_DOUBLE_EXCEPTION_ADDRESS: double exception, DEPC |
| 153 | * < VALID_DOUBLE_EXCEPTION_ADDRESS: regular exception |
Chris Zankel | 5a0015d | 2005-06-23 22:01:16 -0700 | [diff] [blame] | 154 | */ |
| 155 | |
Chris Zankel | c658eac | 2008-02-12 13:17:07 -0800 | [diff] [blame] | 156 | ENTRY(fast_coprocessor_double) |
Chris Zankel | d1538c4 | 2012-11-16 16:16:20 -0800 | [diff] [blame] | 157 | |
Max Filippov | bc5378f | 2012-10-15 03:55:38 +0400 | [diff] [blame] | 158 | wsr a0, excsave1 |
Max Filippov | 2da03d4 | 2017-12-09 18:44:11 -0800 | [diff] [blame] | 159 | call0 unrecoverable_exception |
Chris Zankel | 5a0015d | 2005-06-23 22:01:16 -0700 | [diff] [blame] | 160 | |
Chris Zankel | d1538c4 | 2012-11-16 16:16:20 -0800 | [diff] [blame] | 161 | ENDPROC(fast_coprocessor_double) |
Chris Zankel | c658eac | 2008-02-12 13:17:07 -0800 | [diff] [blame] | 162 | |
| 163 | ENTRY(fast_coprocessor) |
| 164 | |
| 165 | /* Save remaining registers a1-a3 and SAR */ |
| 166 | |
Chris Zankel | c658eac | 2008-02-12 13:17:07 -0800 | [diff] [blame] | 167 | s32i a3, a2, PT_AREG3 |
Max Filippov | bc5378f | 2012-10-15 03:55:38 +0400 | [diff] [blame] | 168 | rsr a3, sar |
Chris Zankel | c658eac | 2008-02-12 13:17:07 -0800 | [diff] [blame] | 169 | s32i a1, a2, PT_AREG1 |
| 170 | s32i a3, a2, PT_SAR |
| 171 | mov a1, a2 |
Max Filippov | bc5378f | 2012-10-15 03:55:38 +0400 | [diff] [blame] | 172 | rsr a2, depc |
Chris Zankel | c658eac | 2008-02-12 13:17:07 -0800 | [diff] [blame] | 173 | s32i a2, a1, PT_AREG2 |
| 174 | |
| 175 | /* |
| 176 | * The hal macros require up to 4 temporary registers. We use a3..a6. |
| 177 | */ |
| 178 | |
| 179 | s32i a4, a1, PT_AREG4 |
| 180 | s32i a5, a1, PT_AREG5 |
| 181 | s32i a6, a1, PT_AREG6 |
| 182 | |
| 183 | /* Find coprocessor number. Subtract first CP EXCCAUSE from EXCCAUSE */ |
| 184 | |
Max Filippov | bc5378f | 2012-10-15 03:55:38 +0400 | [diff] [blame] | 185 | rsr a3, exccause |
Chris Zankel | c658eac | 2008-02-12 13:17:07 -0800 | [diff] [blame] | 186 | addi a3, a3, -EXCCAUSE_COPROCESSOR0_DISABLED |
| 187 | |
| 188 | /* Set corresponding CPENABLE bit -> (sar:cp-index, a3: 1<<cp-index)*/ |
| 189 | |
| 190 | ssl a3 # SAR: 32 - coprocessor_number |
| 191 | movi a2, 1 |
Max Filippov | bc5378f | 2012-10-15 03:55:38 +0400 | [diff] [blame] | 192 | rsr a0, cpenable |
Chris Zankel | c658eac | 2008-02-12 13:17:07 -0800 | [diff] [blame] | 193 | sll a2, a2 |
| 194 | or a0, a0, a2 |
Max Filippov | bc5378f | 2012-10-15 03:55:38 +0400 | [diff] [blame] | 195 | wsr a0, cpenable |
Chris Zankel | c658eac | 2008-02-12 13:17:07 -0800 | [diff] [blame] | 196 | rsync |
| 197 | |
| 198 | /* Retrieve previous owner. (a3 still holds CP number) */ |
| 199 | |
| 200 | movi a0, coprocessor_owner # list of owners |
| 201 | addx4 a0, a3, a0 # entry for CP |
| 202 | l32i a4, a0, 0 |
| 203 | |
| 204 | beqz a4, 1f # skip 'save' if no previous owner |
| 205 | |
| 206 | /* Disable coprocessor for previous owner. (a2 = 1 << CP number) */ |
| 207 | |
| 208 | l32i a5, a4, THREAD_CPENABLE |
| 209 | xor a5, a5, a2 # (1 << cp-id) still in a2 |
| 210 | s32i a5, a4, THREAD_CPENABLE |
| 211 | |
| 212 | /* |
| 213 | * Get context save area and 'call' save routine. |
| 214 | * (a4 still holds previous owner (thread_info), a3 CP number) |
| 215 | */ |
| 216 | |
| 217 | movi a5, .Lsave_cp_regs_jump_table |
| 218 | movi a0, 2f # a0: 'return' address |
| 219 | addx8 a3, a3, a5 # a3: coprocessor number |
| 220 | l32i a2, a3, 4 # a2: xtregs offset |
Max Filippov | 5dacbbe | 2018-11-25 23:32:28 -0800 | [diff] [blame] | 221 | l32i a3, a3, 0 # a3: jump address |
Chris Zankel | c658eac | 2008-02-12 13:17:07 -0800 | [diff] [blame] | 222 | add a2, a2, a4 |
Max Filippov | 5dacbbe | 2018-11-25 23:32:28 -0800 | [diff] [blame] | 223 | jx a3 |
Chris Zankel | c658eac | 2008-02-12 13:17:07 -0800 | [diff] [blame] | 224 | |
| 225 | /* Note that only a0 and a1 were preserved. */ |
| 226 | |
Max Filippov | bc5378f | 2012-10-15 03:55:38 +0400 | [diff] [blame] | 227 | 2: rsr a3, exccause |
Chris Zankel | c658eac | 2008-02-12 13:17:07 -0800 | [diff] [blame] | 228 | addi a3, a3, -EXCCAUSE_COPROCESSOR0_DISABLED |
| 229 | movi a0, coprocessor_owner |
| 230 | addx4 a0, a3, a0 |
| 231 | |
| 232 | /* Set new 'owner' (a0 points to the CP owner, a3 contains the CP nr) */ |
| 233 | |
| 234 | 1: GET_THREAD_INFO (a4, a1) |
| 235 | s32i a4, a0, 0 |
| 236 | |
| 237 | /* Get context save area and 'call' load routine. */ |
| 238 | |
| 239 | movi a5, .Lload_cp_regs_jump_table |
| 240 | movi a0, 1f |
| 241 | addx8 a3, a3, a5 |
| 242 | l32i a2, a3, 4 # a2: xtregs offset |
Max Filippov | 5dacbbe | 2018-11-25 23:32:28 -0800 | [diff] [blame] | 243 | l32i a3, a3, 0 # a3: jump address |
Chris Zankel | c658eac | 2008-02-12 13:17:07 -0800 | [diff] [blame] | 244 | add a2, a2, a4 |
Max Filippov | 5dacbbe | 2018-11-25 23:32:28 -0800 | [diff] [blame] | 245 | jx a3 |
Chris Zankel | c658eac | 2008-02-12 13:17:07 -0800 | [diff] [blame] | 246 | |
| 247 | /* Restore all registers and return from exception handler. */ |
| 248 | |
| 249 | 1: l32i a6, a1, PT_AREG6 |
| 250 | l32i a5, a1, PT_AREG5 |
| 251 | l32i a4, a1, PT_AREG4 |
| 252 | |
| 253 | l32i a0, a1, PT_SAR |
| 254 | l32i a3, a1, PT_AREG3 |
| 255 | l32i a2, a1, PT_AREG2 |
Max Filippov | bc5378f | 2012-10-15 03:55:38 +0400 | [diff] [blame] | 256 | wsr a0, sar |
Chris Zankel | c658eac | 2008-02-12 13:17:07 -0800 | [diff] [blame] | 257 | l32i a0, a1, PT_AREG0 |
| 258 | l32i a1, a1, PT_AREG1 |
| 259 | |
| 260 | rfe |
| 261 | |
Chris Zankel | d1538c4 | 2012-11-16 16:16:20 -0800 | [diff] [blame] | 262 | ENDPROC(fast_coprocessor) |
| 263 | |
Chris Zankel | c658eac | 2008-02-12 13:17:07 -0800 | [diff] [blame] | 264 | .data |
Chris Zankel | d1538c4 | 2012-11-16 16:16:20 -0800 | [diff] [blame] | 265 | |
Chris Zankel | c658eac | 2008-02-12 13:17:07 -0800 | [diff] [blame] | 266 | ENTRY(coprocessor_owner) |
Chris Zankel | d1538c4 | 2012-11-16 16:16:20 -0800 | [diff] [blame] | 267 | |
Chris Zankel | c658eac | 2008-02-12 13:17:07 -0800 | [diff] [blame] | 268 | .fill XCHAL_CP_MAX, 4, 0 |
| 269 | |
Chris Zankel | d1538c4 | 2012-11-16 16:16:20 -0800 | [diff] [blame] | 270 | END(coprocessor_owner) |
| 271 | |
Chris Zankel | c658eac | 2008-02-12 13:17:07 -0800 | [diff] [blame] | 272 | #endif /* XTENSA_HAVE_COPROCESSORS */ |