2 * This file is subject to the terms and conditions of the GNU General Public
3 * License. See the file "COPYING" in the main directory of this archive
6 * Copyright (C) 1994, 1995, 1996, 1998, 1999, 2002, 2003 Ralf Baechle
7 * Copyright (C) 1996 David S. Miller (davem@davemloft.net)
8 * Copyright (C) 1994, 1995, 1996, by Andreas Busse
9 * Copyright (C) 1999 Silicon Graphics, Inc.
10 * Copyright (C) 2000 MIPS Technologies, Inc.
11 * written by Carsten Langgaard, carstenl@mips.com
14 #define USE_ALTERNATE_RESUME_IMPL 1
17 #include "r4k_switch.S"
20 * task_struct *resume(task_struct *prev, task_struct *next,
21 * struct thread_info *next_ti)
27 LONG_S t1, THREAD_STATUS(a0)
28 cpu_save_nonscratch a0
29 LONG_S ra, THREAD_REG31(a0)
31 #if CONFIG_CAVIUM_OCTEON_CVMSEG_SIZE > 0
32 /* Check if we need to store CVMSEG state */
33 dmfc0 t0, $11,7 /* CvmMemCtl */
34 bbit0 t0, 6, 3f /* Is user access enabled? */
36 /* Store the CVMSEG state */
37 /* Extract the size of CVMSEG */
39 /* Multiply * (cache line size/sizeof(long)/2) */
41 li t1, -32768 /* Base address of CVMSEG */
42 LONG_ADDI t2, a0, THREAD_CVMSEG /* Where to store CVMSEG to */
46 LONG_L t8, 0(t1) /* Load from CVMSEG */
47 subu t0, 1 /* Decrement loop var */
48 LONG_L t9, LONGSIZE(t1)/* Load from CVMSEG */
49 LONG_ADDU t1, LONGSIZE*2 /* Increment loc in CVMSEG */
50 LONG_S t8, 0(t2) /* Store CVMSEG to thread storage */
51 LONG_ADDU t2, LONGSIZE*2 /* Increment loc in thread storage */
52 bnez t0, 2b /* Loop until we've copied it all */
53 LONG_S t9, -LONGSIZE(t2)/* Store CVMSEG to thread storage */
56 /* Disable access to CVMSEG */
57 dmfc0 t0, $11,7 /* CvmMemCtl */
58 xori t0, t0, 0x40 /* Bit 6 is CVMSEG user enable */
59 dmtc0 t0, $11,7 /* CvmMemCtl */
63 #if defined(CONFIG_CC_STACKPROTECTOR) && !defined(CONFIG_SMP)
64 PTR_LA t8, __stack_chk_guard
65 LONG_L t9, TASK_STACK_CANARY(a1)
70 * The order of restoring the registers takes care of the race
71 * updating $28, $29 and kernelsp without disabling ints.
74 cpu_restore_nonscratch a1
76 PTR_ADDU t0, $28, _THREAD_SIZE - 32
77 set_saved_sp t0, t1, t2
79 mfc0 t1, CP0_STATUS /* Do we really need this? */
82 LONG_L a2, THREAD_STATUS(a1)
92 * void octeon_cop2_save(struct octeon_cop2_state *a0)
97 LEAF(octeon_cop2_save)
99 dmfc0 t9, $9,7 /* CvmCtl register. */
101 /* Save the COP2 CRC state */
105 sd t0, OCTEON_CP2_CRC_IV(a0)
106 sd t1, OCTEON_CP2_CRC_LENGTH(a0)
107 /* Skip next instructions if CvmCtl[NODFA_CP2] set */
109 sd t2, OCTEON_CP2_CRC_POLY(a0)
111 /* Save the LLM state */
114 sd t0, OCTEON_CP2_LLM_DAT(a0)
116 1: bbit1 t9, 26, 3f /* done if CvmCtl[NOCRYPTO] set */
117 sd t1, OCTEON_CP2_LLM_DAT+8(a0)
119 /* Save the COP2 crypto state */
120 /* this part is mostly common to both pass 1 and later revisions */
125 sd t0, OCTEON_CP2_3DES_IV(a0)
127 sd t1, OCTEON_CP2_3DES_KEY(a0)
128 dmfc2 t1, 0x0111 /* only necessary for pass 1 */
129 sd t2, OCTEON_CP2_3DES_KEY+8(a0)
131 sd t3, OCTEON_CP2_3DES_KEY+16(a0)
133 sd t0, OCTEON_CP2_3DES_RESULT(a0)
135 sd t1, OCTEON_CP2_AES_INP0(a0) /* only necessary for pass 1 */
137 sd t2, OCTEON_CP2_AES_IV(a0)
139 sd t3, OCTEON_CP2_AES_IV+8(a0)
141 sd t0, OCTEON_CP2_AES_KEY(a0)
143 sd t1, OCTEON_CP2_AES_KEY+8(a0)
145 sd t2, OCTEON_CP2_AES_KEY+16(a0)
147 sd t3, OCTEON_CP2_AES_KEY+24(a0)
148 mfc0 v0, $15,0 /* Get the processor ID register */
149 sd t0, OCTEON_CP2_AES_KEYLEN(a0)
150 li v1, 0x000d0000 /* This is the processor ID of Octeon Pass1 */
151 sd t1, OCTEON_CP2_AES_RESULT(a0)
152 /* Skip to the Pass1 version of the remainder of the COP2 state */
154 sd t2, OCTEON_CP2_AES_RESULT+8(a0)
156 /* the non-pass1 state when !CvmCtl[NOCRYPTO] */
159 ori v1, v1, 0x9500 /* lowest OCTEON III PrId*/
161 subu v1, v0, v1 /* prid - lowest OCTEON III PrId */
163 sd t1, OCTEON_CP2_HSH_DATW(a0)
165 sd t2, OCTEON_CP2_HSH_DATW+8(a0)
167 sd t3, OCTEON_CP2_HSH_DATW+16(a0)
169 sd t0, OCTEON_CP2_HSH_DATW+24(a0)
171 sd t1, OCTEON_CP2_HSH_DATW+32(a0)
173 sd t2, OCTEON_CP2_HSH_DATW+40(a0)
175 sd t3, OCTEON_CP2_HSH_DATW+48(a0)
177 sd t0, OCTEON_CP2_HSH_DATW+56(a0)
179 sd t1, OCTEON_CP2_HSH_DATW+64(a0)
181 sd t2, OCTEON_CP2_HSH_DATW+72(a0)
183 sd t3, OCTEON_CP2_HSH_DATW+80(a0)
185 sd t0, OCTEON_CP2_HSH_DATW+88(a0)
187 sd t1, OCTEON_CP2_HSH_DATW+96(a0)
189 sd t2, OCTEON_CP2_HSH_DATW+104(a0)
191 sd t3, OCTEON_CP2_HSH_DATW+112(a0)
193 sd t0, OCTEON_CP2_HSH_IVW(a0)
195 sd t1, OCTEON_CP2_HSH_IVW+8(a0)
197 sd t2, OCTEON_CP2_HSH_IVW+16(a0)
199 sd t3, OCTEON_CP2_HSH_IVW+24(a0)
201 sd t0, OCTEON_CP2_HSH_IVW+32(a0)
203 sd t1, OCTEON_CP2_HSH_IVW+40(a0)
205 sd t2, OCTEON_CP2_HSH_IVW+48(a0)
207 sd t3, OCTEON_CP2_HSH_IVW+56(a0)
209 sd t0, OCTEON_CP2_GFM_MULT(a0)
211 sd t1, OCTEON_CP2_GFM_MULT+8(a0)
212 sd t2, OCTEON_CP2_GFM_POLY(a0)
213 sd t3, OCTEON_CP2_GFM_RESULT(a0)
215 sd t0, OCTEON_CP2_GFM_RESULT+8(a0)
216 /* OCTEON III things*/
219 sd t0, OCTEON_CP2_SHA3(a0)
220 sd t1, OCTEON_CP2_SHA3+8(a0)
225 2: /* pass 1 special stuff when !CvmCtl[NOCRYPTO] */
230 sd t3, OCTEON_CP2_HSH_DATW(a0)
232 sd t0, OCTEON_CP2_HSH_DATW+8(a0)
234 sd t1, OCTEON_CP2_HSH_DATW+16(a0)
236 sd t2, OCTEON_CP2_HSH_DATW+24(a0)
238 sd t3, OCTEON_CP2_HSH_DATW+32(a0)
240 sd t0, OCTEON_CP2_HSH_DATW+40(a0)
242 sd t1, OCTEON_CP2_HSH_DATW+48(a0)
243 sd t2, OCTEON_CP2_HSH_IVW(a0)
244 sd t3, OCTEON_CP2_HSH_IVW+8(a0)
245 sd t0, OCTEON_CP2_HSH_IVW+16(a0)
247 3: /* pass 1 or CvmCtl[NOCRYPTO] set */
250 END(octeon_cop2_save)
254 * void octeon_cop2_restore(struct octeon_cop2_state *a0)
259 LEAF(octeon_cop2_restore)
260 /* First cache line was prefetched before the call */
262 dmfc0 t9, $9,7 /* CvmCtl register. */
265 ld t0, OCTEON_CP2_CRC_IV(a0)
267 ld t1, OCTEON_CP2_CRC_LENGTH(a0)
268 ld t2, OCTEON_CP2_CRC_POLY(a0)
270 /* Restore the COP2 CRC state */
273 bbit1 t9, 28, 2f /* Skip LLM if CvmCtl[NODFA_CP2] is set */
276 /* Restore the LLM state */
277 ld t0, OCTEON_CP2_LLM_DAT(a0)
278 ld t1, OCTEON_CP2_LLM_DAT+8(a0)
283 bbit1 t9, 26, done_restore /* done if CvmCtl[NOCRYPTO] set */
286 /* Restore the COP2 crypto state common to pass 1 and pass 2 */
287 ld t0, OCTEON_CP2_3DES_IV(a0)
288 ld t1, OCTEON_CP2_3DES_KEY(a0)
289 ld t2, OCTEON_CP2_3DES_KEY+8(a0)
291 ld t0, OCTEON_CP2_3DES_KEY+16(a0)
293 ld t1, OCTEON_CP2_3DES_RESULT(a0)
295 ld t2, OCTEON_CP2_AES_INP0(a0) /* only really needed for pass 1 */
297 ld t0, OCTEON_CP2_AES_IV(a0)
299 ld t1, OCTEON_CP2_AES_IV+8(a0)
300 dmtc2 t2, 0x010A /* only really needed for pass 1 */
301 ld t2, OCTEON_CP2_AES_KEY(a0)
303 ld t0, OCTEON_CP2_AES_KEY+8(a0)
305 ld t1, OCTEON_CP2_AES_KEY+16(a0)
307 ld t2, OCTEON_CP2_AES_KEY+24(a0)
309 ld t0, OCTEON_CP2_AES_KEYLEN(a0)
311 ld t1, OCTEON_CP2_AES_RESULT(a0)
313 ld t2, OCTEON_CP2_AES_RESULT+8(a0)
314 mfc0 t3, $15,0 /* Get the processor ID register */
316 li v0, 0x000d0000 /* This is the processor ID of Octeon Pass1 */
318 bne v0, t3, 3f /* Skip the next stuff for non-pass1 */
321 /* this code is specific for pass 1 */
322 ld t0, OCTEON_CP2_HSH_DATW(a0)
323 ld t1, OCTEON_CP2_HSH_DATW+8(a0)
324 ld t2, OCTEON_CP2_HSH_DATW+16(a0)
326 ld t0, OCTEON_CP2_HSH_DATW+24(a0)
328 ld t1, OCTEON_CP2_HSH_DATW+32(a0)
330 ld t2, OCTEON_CP2_HSH_DATW+40(a0)
332 ld t0, OCTEON_CP2_HSH_DATW+48(a0)
334 ld t1, OCTEON_CP2_HSH_IVW(a0)
336 ld t2, OCTEON_CP2_HSH_IVW+8(a0)
338 ld t0, OCTEON_CP2_HSH_IVW+16(a0)
341 b done_restore /* unconditional branch */
344 3: /* this is post-pass1 code */
345 ld t2, OCTEON_CP2_HSH_DATW(a0)
346 ori v0, v0, 0x9500 /* lowest OCTEON III PrId*/
347 ld t0, OCTEON_CP2_HSH_DATW+8(a0)
348 ld t1, OCTEON_CP2_HSH_DATW+16(a0)
350 ld t2, OCTEON_CP2_HSH_DATW+24(a0)
352 ld t0, OCTEON_CP2_HSH_DATW+32(a0)
354 ld t1, OCTEON_CP2_HSH_DATW+40(a0)
356 ld t2, OCTEON_CP2_HSH_DATW+48(a0)
358 ld t0, OCTEON_CP2_HSH_DATW+56(a0)
360 ld t1, OCTEON_CP2_HSH_DATW+64(a0)
362 ld t2, OCTEON_CP2_HSH_DATW+72(a0)
364 ld t0, OCTEON_CP2_HSH_DATW+80(a0)
366 ld t1, OCTEON_CP2_HSH_DATW+88(a0)
368 ld t2, OCTEON_CP2_HSH_DATW+96(a0)
370 ld t0, OCTEON_CP2_HSH_DATW+104(a0)
372 ld t1, OCTEON_CP2_HSH_DATW+112(a0)
374 ld t2, OCTEON_CP2_HSH_IVW(a0)
376 ld t0, OCTEON_CP2_HSH_IVW+8(a0)
378 ld t1, OCTEON_CP2_HSH_IVW+16(a0)
380 ld t2, OCTEON_CP2_HSH_IVW+24(a0)
382 ld t0, OCTEON_CP2_HSH_IVW+32(a0)
384 ld t1, OCTEON_CP2_HSH_IVW+40(a0)
386 ld t2, OCTEON_CP2_HSH_IVW+48(a0)
388 ld t0, OCTEON_CP2_HSH_IVW+56(a0)
390 ld t1, OCTEON_CP2_GFM_MULT(a0)
392 ld t2, OCTEON_CP2_GFM_MULT+8(a0)
394 ld t0, OCTEON_CP2_GFM_POLY(a0)
396 ld t1, OCTEON_CP2_GFM_RESULT(a0)
398 ld t2, OCTEON_CP2_GFM_RESULT+8(a0)
400 subu v0, t3, v0 /* prid - lowest OCTEON III PrId */
402 bltz v0, done_restore
404 /* OCTEON III things*/
405 ld t0, OCTEON_CP2_SHA3(a0)
406 ld t1, OCTEON_CP2_SHA3+8(a0)
412 END(octeon_cop2_restore)
416 * void octeon_mult_save()
417 * sp is assumed to point to a struct pt_regs
419 * NOTE: This is called in SAVE_TEMP in stackframe.h. It can
420 * safely modify v1,k0, k1,$10-$15, and $24. It will
421 * be overwritten with a processor specific version of the code.
426 LEAF(octeon_mult_save)
430 octeon_mult_save_end:
431 EXPORT(octeon_mult_save_end)
432 END(octeon_mult_save)
434 LEAF(octeon_mult_save2)
435 /* Save the multiplier state OCTEON II and earlier*/
438 sd k0, PT_MTP(sp) /* PT_MTP has P0 */
440 sd k1, PT_MTP+8(sp) /* PT_MTP+8 has P1 */
443 sd k0, PT_MTP+16(sp) /* PT_MTP+16 has P2 */
445 sd k1, PT_MPL(sp) /* PT_MPL has MPL0 */
447 sd k0, PT_MPL+8(sp) /* PT_MPL+8 has MPL1 */
449 sd k1, PT_MPL+16(sp) /* PT_MPL+16 has MPL2 */
450 octeon_mult_save2_end:
451 EXPORT(octeon_mult_save2_end)
452 END(octeon_mult_save2)
454 LEAF(octeon_mult_save3)
455 /* Save the multiplier state OCTEON III */
456 v3mulu $10, $0, $0 /* read P0 */
457 v3mulu $11, $0, $0 /* read P1 */
458 v3mulu $12, $0, $0 /* read P2 */
459 sd $10, PT_MTP+(0*8)(sp) /* store P0 */
460 v3mulu $10, $0, $0 /* read P3 */
461 sd $11, PT_MTP+(1*8)(sp) /* store P1 */
462 v3mulu $11, $0, $0 /* read P4 */
463 sd $12, PT_MTP+(2*8)(sp) /* store P2 */
465 v3mulu $12, $0, $0 /* read P5 */
466 sd $10, PT_MTP+(3*8)(sp) /* store P3 */
467 v3mulu $13, $13, $0 /* P4-P0 = MPL5-MPL1, $13 = MPL0 */
468 sd $11, PT_MTP+(4*8)(sp) /* store P4 */
469 v3mulu $10, $0, $0 /* read MPL1 */
470 sd $12, PT_MTP+(5*8)(sp) /* store P5 */
471 v3mulu $11, $0, $0 /* read MPL2 */
472 sd $13, PT_MPL+(0*8)(sp) /* store MPL0 */
473 v3mulu $12, $0, $0 /* read MPL3 */
474 sd $10, PT_MPL+(1*8)(sp) /* store MPL1 */
475 v3mulu $10, $0, $0 /* read MPL4 */
476 sd $11, PT_MPL+(2*8)(sp) /* store MPL2 */
477 v3mulu $11, $0, $0 /* read MPL5 */
478 sd $12, PT_MPL+(3*8)(sp) /* store MPL3 */
479 sd $10, PT_MPL+(4*8)(sp) /* store MPL4 */
481 sd $11, PT_MPL+(5*8)(sp) /* store MPL5 */
482 octeon_mult_save3_end:
483 EXPORT(octeon_mult_save3_end)
484 END(octeon_mult_save3)
488 * void octeon_mult_restore()
489 * sp is assumed to point to a struct pt_regs
491 * NOTE: This is called in RESTORE_TEMP in stackframe.h.
496 LEAF(octeon_mult_restore)
500 octeon_mult_restore_end:
501 EXPORT(octeon_mult_restore_end)
502 END(octeon_mult_restore)
504 LEAF(octeon_mult_restore2)
505 ld v0, PT_MPL(sp) /* MPL0 */
506 ld v1, PT_MPL+8(sp) /* MPL1 */
507 ld k0, PT_MPL+16(sp) /* MPL2 */
508 /* Restore the multiplier state */
509 ld k1, PT_MTP+16(sp) /* P2 */
511 ld v0, PT_MTP+8(sp) /* P1 */
513 ld v1, PT_MTP(sp) /* P0 */
519 octeon_mult_restore2_end:
520 EXPORT(octeon_mult_restore2_end)
521 END(octeon_mult_restore2)
523 LEAF(octeon_mult_restore3)
524 ld $12, PT_MPL+(0*8)(sp) /* read MPL0 */
525 ld $13, PT_MPL+(3*8)(sp) /* read MPL3 */
526 ld $10, PT_MPL+(1*8)(sp) /* read MPL1 */
527 ld $11, PT_MPL+(4*8)(sp) /* read MPL4 */
529 /* mtm0 $12, $13 restore MPL0 and MPL3 */
530 ld $12, PT_MPL+(2*8)(sp) /* read MPL2 */
532 /* mtm1 $10, $11 restore MPL1 and MPL4 */
533 ld $13, PT_MPL+(5*8)(sp) /* read MPL5 */
534 ld $10, PT_MTP+(0*8)(sp) /* read P0 */
535 ld $11, PT_MTP+(3*8)(sp) /* read P3 */
537 /* mtm2 $12, $13 restore MPL2 and MPL5 */
538 ld $12, PT_MTP+(1*8)(sp) /* read P1 */
540 /* mtp0 $10, $11 restore P0 and P3 */
541 ld $13, PT_MTP+(4*8)(sp) /* read P4 */
542 ld $10, PT_MTP+(2*8)(sp) /* read P2 */
543 ld $11, PT_MTP+(5*8)(sp) /* read P5 */
545 /* mtp1 $12, $13 restore P1 and P4 */
548 /* mtp2 $10, $11 restore P2 and P5 */
550 octeon_mult_restore3_end:
551 EXPORT(octeon_mult_restore3_end)
552 END(octeon_mult_restore3)