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 #include <asm/asm-offsets.h>
15 #include <asm/mipsregs.h>
16 #include <asm/regdef.h>
17 #include <asm/stackframe.h>
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_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 EXPORT(octeon_mult_save_end)
431 END(octeon_mult_save)
433 LEAF(octeon_mult_save2)
434 /* Save the multiplier state OCTEON II and earlier*/
437 sd k0, PT_MTP(sp) /* PT_MTP has P0 */
439 sd k1, PT_MTP+8(sp) /* PT_MTP+8 has P1 */
442 sd k0, PT_MTP+16(sp) /* PT_MTP+16 has P2 */
444 sd k1, PT_MPL(sp) /* PT_MPL has MPL0 */
446 sd k0, PT_MPL+8(sp) /* PT_MPL+8 has MPL1 */
448 sd k1, PT_MPL+16(sp) /* PT_MPL+16 has MPL2 */
449 EXPORT(octeon_mult_save2_end)
450 END(octeon_mult_save2)
452 LEAF(octeon_mult_save3)
453 /* Save the multiplier state OCTEON III */
454 v3mulu $10, $0, $0 /* read P0 */
455 v3mulu $11, $0, $0 /* read P1 */
456 v3mulu $12, $0, $0 /* read P2 */
457 sd $10, PT_MTP+(0*8)(sp) /* store P0 */
458 v3mulu $10, $0, $0 /* read P3 */
459 sd $11, PT_MTP+(1*8)(sp) /* store P1 */
460 v3mulu $11, $0, $0 /* read P4 */
461 sd $12, PT_MTP+(2*8)(sp) /* store P2 */
463 v3mulu $12, $0, $0 /* read P5 */
464 sd $10, PT_MTP+(3*8)(sp) /* store P3 */
465 v3mulu $13, $13, $0 /* P4-P0 = MPL5-MPL1, $13 = MPL0 */
466 sd $11, PT_MTP+(4*8)(sp) /* store P4 */
467 v3mulu $10, $0, $0 /* read MPL1 */
468 sd $12, PT_MTP+(5*8)(sp) /* store P5 */
469 v3mulu $11, $0, $0 /* read MPL2 */
470 sd $13, PT_MPL+(0*8)(sp) /* store MPL0 */
471 v3mulu $12, $0, $0 /* read MPL3 */
472 sd $10, PT_MPL+(1*8)(sp) /* store MPL1 */
473 v3mulu $10, $0, $0 /* read MPL4 */
474 sd $11, PT_MPL+(2*8)(sp) /* store MPL2 */
475 v3mulu $11, $0, $0 /* read MPL5 */
476 sd $12, PT_MPL+(3*8)(sp) /* store MPL3 */
477 sd $10, PT_MPL+(4*8)(sp) /* store MPL4 */
479 sd $11, PT_MPL+(5*8)(sp) /* store MPL5 */
480 EXPORT(octeon_mult_save3_end)
481 END(octeon_mult_save3)
485 * void octeon_mult_restore()
486 * sp is assumed to point to a struct pt_regs
488 * NOTE: This is called in RESTORE_TEMP in stackframe.h.
493 LEAF(octeon_mult_restore)
497 EXPORT(octeon_mult_restore_end)
498 END(octeon_mult_restore)
500 LEAF(octeon_mult_restore2)
501 ld v0, PT_MPL(sp) /* MPL0 */
502 ld v1, PT_MPL+8(sp) /* MPL1 */
503 ld k0, PT_MPL+16(sp) /* MPL2 */
504 /* Restore the multiplier state */
505 ld k1, PT_MTP+16(sp) /* P2 */
507 ld v0, PT_MTP+8(sp) /* P1 */
509 ld v1, PT_MTP(sp) /* P0 */
515 EXPORT(octeon_mult_restore2_end)
516 END(octeon_mult_restore2)
518 LEAF(octeon_mult_restore3)
519 ld $12, PT_MPL+(0*8)(sp) /* read MPL0 */
520 ld $13, PT_MPL+(3*8)(sp) /* read MPL3 */
521 ld $10, PT_MPL+(1*8)(sp) /* read MPL1 */
522 ld $11, PT_MPL+(4*8)(sp) /* read MPL4 */
524 /* mtm0 $12, $13 restore MPL0 and MPL3 */
525 ld $12, PT_MPL+(2*8)(sp) /* read MPL2 */
527 /* mtm1 $10, $11 restore MPL1 and MPL4 */
528 ld $13, PT_MPL+(5*8)(sp) /* read MPL5 */
529 ld $10, PT_MTP+(0*8)(sp) /* read P0 */
530 ld $11, PT_MTP+(3*8)(sp) /* read P3 */
532 /* mtm2 $12, $13 restore MPL2 and MPL5 */
533 ld $12, PT_MTP+(1*8)(sp) /* read P1 */
535 /* mtp0 $10, $11 restore P0 and P3 */
536 ld $13, PT_MTP+(4*8)(sp) /* read P4 */
537 ld $10, PT_MTP+(2*8)(sp) /* read P2 */
538 ld $11, PT_MTP+(5*8)(sp) /* read P5 */
540 /* mtp1 $12, $13 restore P1 and P4 */
543 /* mtp2 $10, $11 restore P2 and P5 */
545 EXPORT(octeon_mult_restore3_end)
546 END(octeon_mult_restore3)