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/export.h>
15 #include <asm/asm-offsets.h>
16 #include <asm/mipsregs.h>
17 #include <asm/regdef.h>
18 #include <asm/stackframe.h>
21 * task_struct *resume(task_struct *prev, task_struct *next,
22 * struct thread_info *next_ti)
28 LONG_S t1, THREAD_STATUS(a0)
29 cpu_save_nonscratch a0
30 LONG_S ra, THREAD_REG31(a0)
32 #if CONFIG_CAVIUM_OCTEON_CVMSEG_SIZE > 0
33 /* Check if we need to store CVMSEG state */
34 dmfc0 t0, $11,7 /* CvmMemCtl */
35 bbit0 t0, 6, 3f /* Is user access enabled? */
37 /* Store the CVMSEG state */
38 /* Extract the size of CVMSEG */
40 /* Multiply * (cache line size/sizeof(long)/2) */
42 li t1, -32768 /* Base address of CVMSEG */
43 LONG_ADDI t2, a0, THREAD_CVMSEG /* Where to store CVMSEG to */
47 LONG_L t8, 0(t1) /* Load from CVMSEG */
48 subu t0, 1 /* Decrement loop var */
49 LONG_L t9, LONGSIZE(t1)/* Load from CVMSEG */
50 LONG_ADDU t1, LONGSIZE*2 /* Increment loc in CVMSEG */
51 LONG_S t8, 0(t2) /* Store CVMSEG to thread storage */
52 LONG_ADDU t2, LONGSIZE*2 /* Increment loc in thread storage */
53 bnez t0, 2b /* Loop until we've copied it all */
54 LONG_S t9, -LONGSIZE(t2)/* Store CVMSEG to thread storage */
57 /* Disable access to CVMSEG */
58 dmfc0 t0, $11,7 /* CvmMemCtl */
59 xori t0, t0, 0x40 /* Bit 6 is CVMSEG user enable */
60 dmtc0 t0, $11,7 /* CvmMemCtl */
64 #if defined(CONFIG_CC_STACKPROTECTOR) && !defined(CONFIG_SMP)
65 PTR_LA t8, __stack_chk_guard
66 LONG_L t9, TASK_STACK_CANARY(a1)
71 * The order of restoring the registers takes care of the race
72 * updating $28, $29 and kernelsp without disabling ints.
75 cpu_restore_nonscratch a1
77 PTR_ADDU t0, $28, _THREAD_SIZE - 32
78 set_saved_sp t0, t1, t2
80 mfc0 t1, CP0_STATUS /* Do we really need this? */
83 LONG_L a2, THREAD_STATUS(a1)
93 * void octeon_cop2_save(struct octeon_cop2_state *a0)
98 LEAF(octeon_cop2_save)
100 dmfc0 t9, $9,7 /* CvmCtl register. */
102 /* Save the COP2 CRC state */
106 sd t0, OCTEON_CP2_CRC_IV(a0)
107 sd t1, OCTEON_CP2_CRC_LENGTH(a0)
108 /* Skip next instructions if CvmCtl[NODFA_CP2] set */
110 sd t2, OCTEON_CP2_CRC_POLY(a0)
112 /* Save the LLM state */
115 sd t0, OCTEON_CP2_LLM_DAT(a0)
117 1: bbit1 t9, 26, 3f /* done if CvmCtl[NOCRYPTO] set */
118 sd t1, OCTEON_CP2_LLM_DAT+8(a0)
120 /* Save the COP2 crypto state */
121 /* this part is mostly common to both pass 1 and later revisions */
126 sd t0, OCTEON_CP2_3DES_IV(a0)
128 sd t1, OCTEON_CP2_3DES_KEY(a0)
129 dmfc2 t1, 0x0111 /* only necessary for pass 1 */
130 sd t2, OCTEON_CP2_3DES_KEY+8(a0)
132 sd t3, OCTEON_CP2_3DES_KEY+16(a0)
134 sd t0, OCTEON_CP2_3DES_RESULT(a0)
136 sd t1, OCTEON_CP2_AES_INP0(a0) /* only necessary for pass 1 */
138 sd t2, OCTEON_CP2_AES_IV(a0)
140 sd t3, OCTEON_CP2_AES_IV+8(a0)
142 sd t0, OCTEON_CP2_AES_KEY(a0)
144 sd t1, OCTEON_CP2_AES_KEY+8(a0)
146 sd t2, OCTEON_CP2_AES_KEY+16(a0)
148 sd t3, OCTEON_CP2_AES_KEY+24(a0)
149 mfc0 v0, $15,0 /* Get the processor ID register */
150 sd t0, OCTEON_CP2_AES_KEYLEN(a0)
151 li v1, 0x000d0000 /* This is the processor ID of Octeon Pass1 */
152 sd t1, OCTEON_CP2_AES_RESULT(a0)
153 /* Skip to the Pass1 version of the remainder of the COP2 state */
155 sd t2, OCTEON_CP2_AES_RESULT+8(a0)
157 /* the non-pass1 state when !CvmCtl[NOCRYPTO] */
160 ori v1, v1, 0x9500 /* lowest OCTEON III PrId*/
162 subu v1, v0, v1 /* prid - lowest OCTEON III PrId */
164 sd t1, OCTEON_CP2_HSH_DATW(a0)
166 sd t2, OCTEON_CP2_HSH_DATW+8(a0)
168 sd t3, OCTEON_CP2_HSH_DATW+16(a0)
170 sd t0, OCTEON_CP2_HSH_DATW+24(a0)
172 sd t1, OCTEON_CP2_HSH_DATW+32(a0)
174 sd t2, OCTEON_CP2_HSH_DATW+40(a0)
176 sd t3, OCTEON_CP2_HSH_DATW+48(a0)
178 sd t0, OCTEON_CP2_HSH_DATW+56(a0)
180 sd t1, OCTEON_CP2_HSH_DATW+64(a0)
182 sd t2, OCTEON_CP2_HSH_DATW+72(a0)
184 sd t3, OCTEON_CP2_HSH_DATW+80(a0)
186 sd t0, OCTEON_CP2_HSH_DATW+88(a0)
188 sd t1, OCTEON_CP2_HSH_DATW+96(a0)
190 sd t2, OCTEON_CP2_HSH_DATW+104(a0)
192 sd t3, OCTEON_CP2_HSH_DATW+112(a0)
194 sd t0, OCTEON_CP2_HSH_IVW(a0)
196 sd t1, OCTEON_CP2_HSH_IVW+8(a0)
198 sd t2, OCTEON_CP2_HSH_IVW+16(a0)
200 sd t3, OCTEON_CP2_HSH_IVW+24(a0)
202 sd t0, OCTEON_CP2_HSH_IVW+32(a0)
204 sd t1, OCTEON_CP2_HSH_IVW+40(a0)
206 sd t2, OCTEON_CP2_HSH_IVW+48(a0)
208 sd t3, OCTEON_CP2_HSH_IVW+56(a0)
210 sd t0, OCTEON_CP2_GFM_MULT(a0)
212 sd t1, OCTEON_CP2_GFM_MULT+8(a0)
213 sd t2, OCTEON_CP2_GFM_POLY(a0)
214 sd t3, OCTEON_CP2_GFM_RESULT(a0)
216 sd t0, OCTEON_CP2_GFM_RESULT+8(a0)
217 /* OCTEON III things*/
220 sd t0, OCTEON_CP2_SHA3(a0)
221 sd t1, OCTEON_CP2_SHA3+8(a0)
226 2: /* pass 1 special stuff when !CvmCtl[NOCRYPTO] */
231 sd t3, OCTEON_CP2_HSH_DATW(a0)
233 sd t0, OCTEON_CP2_HSH_DATW+8(a0)
235 sd t1, OCTEON_CP2_HSH_DATW+16(a0)
237 sd t2, OCTEON_CP2_HSH_DATW+24(a0)
239 sd t3, OCTEON_CP2_HSH_DATW+32(a0)
241 sd t0, OCTEON_CP2_HSH_DATW+40(a0)
243 sd t1, OCTEON_CP2_HSH_DATW+48(a0)
244 sd t2, OCTEON_CP2_HSH_IVW(a0)
245 sd t3, OCTEON_CP2_HSH_IVW+8(a0)
246 sd t0, OCTEON_CP2_HSH_IVW+16(a0)
248 3: /* pass 1 or CvmCtl[NOCRYPTO] set */
251 END(octeon_cop2_save)
255 * void octeon_cop2_restore(struct octeon_cop2_state *a0)
260 LEAF(octeon_cop2_restore)
261 /* First cache line was prefetched before the call */
263 dmfc0 t9, $9,7 /* CvmCtl register. */
266 ld t0, OCTEON_CP2_CRC_IV(a0)
268 ld t1, OCTEON_CP2_CRC_LENGTH(a0)
269 ld t2, OCTEON_CP2_CRC_POLY(a0)
271 /* Restore the COP2 CRC state */
274 bbit1 t9, 28, 2f /* Skip LLM if CvmCtl[NODFA_CP2] is set */
277 /* Restore the LLM state */
278 ld t0, OCTEON_CP2_LLM_DAT(a0)
279 ld t1, OCTEON_CP2_LLM_DAT+8(a0)
284 bbit1 t9, 26, done_restore /* done if CvmCtl[NOCRYPTO] set */
287 /* Restore the COP2 crypto state common to pass 1 and pass 2 */
288 ld t0, OCTEON_CP2_3DES_IV(a0)
289 ld t1, OCTEON_CP2_3DES_KEY(a0)
290 ld t2, OCTEON_CP2_3DES_KEY+8(a0)
292 ld t0, OCTEON_CP2_3DES_KEY+16(a0)
294 ld t1, OCTEON_CP2_3DES_RESULT(a0)
296 ld t2, OCTEON_CP2_AES_INP0(a0) /* only really needed for pass 1 */
298 ld t0, OCTEON_CP2_AES_IV(a0)
300 ld t1, OCTEON_CP2_AES_IV+8(a0)
301 dmtc2 t2, 0x010A /* only really needed for pass 1 */
302 ld t2, OCTEON_CP2_AES_KEY(a0)
304 ld t0, OCTEON_CP2_AES_KEY+8(a0)
306 ld t1, OCTEON_CP2_AES_KEY+16(a0)
308 ld t2, OCTEON_CP2_AES_KEY+24(a0)
310 ld t0, OCTEON_CP2_AES_KEYLEN(a0)
312 ld t1, OCTEON_CP2_AES_RESULT(a0)
314 ld t2, OCTEON_CP2_AES_RESULT+8(a0)
315 mfc0 t3, $15,0 /* Get the processor ID register */
317 li v0, 0x000d0000 /* This is the processor ID of Octeon Pass1 */
319 bne v0, t3, 3f /* Skip the next stuff for non-pass1 */
322 /* this code is specific for pass 1 */
323 ld t0, OCTEON_CP2_HSH_DATW(a0)
324 ld t1, OCTEON_CP2_HSH_DATW+8(a0)
325 ld t2, OCTEON_CP2_HSH_DATW+16(a0)
327 ld t0, OCTEON_CP2_HSH_DATW+24(a0)
329 ld t1, OCTEON_CP2_HSH_DATW+32(a0)
331 ld t2, OCTEON_CP2_HSH_DATW+40(a0)
333 ld t0, OCTEON_CP2_HSH_DATW+48(a0)
335 ld t1, OCTEON_CP2_HSH_IVW(a0)
337 ld t2, OCTEON_CP2_HSH_IVW+8(a0)
339 ld t0, OCTEON_CP2_HSH_IVW+16(a0)
342 b done_restore /* unconditional branch */
345 3: /* this is post-pass1 code */
346 ld t2, OCTEON_CP2_HSH_DATW(a0)
347 ori v0, v0, 0x9500 /* lowest OCTEON III PrId*/
348 ld t0, OCTEON_CP2_HSH_DATW+8(a0)
349 ld t1, OCTEON_CP2_HSH_DATW+16(a0)
351 ld t2, OCTEON_CP2_HSH_DATW+24(a0)
353 ld t0, OCTEON_CP2_HSH_DATW+32(a0)
355 ld t1, OCTEON_CP2_HSH_DATW+40(a0)
357 ld t2, OCTEON_CP2_HSH_DATW+48(a0)
359 ld t0, OCTEON_CP2_HSH_DATW+56(a0)
361 ld t1, OCTEON_CP2_HSH_DATW+64(a0)
363 ld t2, OCTEON_CP2_HSH_DATW+72(a0)
365 ld t0, OCTEON_CP2_HSH_DATW+80(a0)
367 ld t1, OCTEON_CP2_HSH_DATW+88(a0)
369 ld t2, OCTEON_CP2_HSH_DATW+96(a0)
371 ld t0, OCTEON_CP2_HSH_DATW+104(a0)
373 ld t1, OCTEON_CP2_HSH_DATW+112(a0)
375 ld t2, OCTEON_CP2_HSH_IVW(a0)
377 ld t0, OCTEON_CP2_HSH_IVW+8(a0)
379 ld t1, OCTEON_CP2_HSH_IVW+16(a0)
381 ld t2, OCTEON_CP2_HSH_IVW+24(a0)
383 ld t0, OCTEON_CP2_HSH_IVW+32(a0)
385 ld t1, OCTEON_CP2_HSH_IVW+40(a0)
387 ld t2, OCTEON_CP2_HSH_IVW+48(a0)
389 ld t0, OCTEON_CP2_HSH_IVW+56(a0)
391 ld t1, OCTEON_CP2_GFM_MULT(a0)
393 ld t2, OCTEON_CP2_GFM_MULT+8(a0)
395 ld t0, OCTEON_CP2_GFM_POLY(a0)
397 ld t1, OCTEON_CP2_GFM_RESULT(a0)
399 ld t2, OCTEON_CP2_GFM_RESULT+8(a0)
401 subu v0, t3, v0 /* prid - lowest OCTEON III PrId */
403 bltz v0, done_restore
405 /* OCTEON III things*/
406 ld t0, OCTEON_CP2_SHA3(a0)
407 ld t1, OCTEON_CP2_SHA3+8(a0)
413 END(octeon_cop2_restore)
417 * void octeon_mult_save()
418 * sp is assumed to point to a struct pt_regs
420 * NOTE: This is called in SAVE_TEMP in stackframe.h. It can
421 * safely modify v1,k0, k1,$10-$15, and $24. It will
422 * be overwritten with a processor specific version of the code.
427 LEAF(octeon_mult_save)
431 octeon_mult_save_end:
432 EXPORT(octeon_mult_save_end)
433 END(octeon_mult_save)
435 LEAF(octeon_mult_save2)
436 /* Save the multiplier state OCTEON II and earlier*/
439 sd k0, PT_MTP(sp) /* PT_MTP has P0 */
441 sd k1, PT_MTP+8(sp) /* PT_MTP+8 has P1 */
444 sd k0, PT_MTP+16(sp) /* PT_MTP+16 has P2 */
446 sd k1, PT_MPL(sp) /* PT_MPL has MPL0 */
448 sd k0, PT_MPL+8(sp) /* PT_MPL+8 has MPL1 */
450 sd k1, PT_MPL+16(sp) /* PT_MPL+16 has MPL2 */
451 octeon_mult_save2_end:
452 EXPORT(octeon_mult_save2_end)
453 END(octeon_mult_save2)
455 LEAF(octeon_mult_save3)
456 /* Save the multiplier state OCTEON III */
457 v3mulu $10, $0, $0 /* read P0 */
458 v3mulu $11, $0, $0 /* read P1 */
459 v3mulu $12, $0, $0 /* read P2 */
460 sd $10, PT_MTP+(0*8)(sp) /* store P0 */
461 v3mulu $10, $0, $0 /* read P3 */
462 sd $11, PT_MTP+(1*8)(sp) /* store P1 */
463 v3mulu $11, $0, $0 /* read P4 */
464 sd $12, PT_MTP+(2*8)(sp) /* store P2 */
466 v3mulu $12, $0, $0 /* read P5 */
467 sd $10, PT_MTP+(3*8)(sp) /* store P3 */
468 v3mulu $13, $13, $0 /* P4-P0 = MPL5-MPL1, $13 = MPL0 */
469 sd $11, PT_MTP+(4*8)(sp) /* store P4 */
470 v3mulu $10, $0, $0 /* read MPL1 */
471 sd $12, PT_MTP+(5*8)(sp) /* store P5 */
472 v3mulu $11, $0, $0 /* read MPL2 */
473 sd $13, PT_MPL+(0*8)(sp) /* store MPL0 */
474 v3mulu $12, $0, $0 /* read MPL3 */
475 sd $10, PT_MPL+(1*8)(sp) /* store MPL1 */
476 v3mulu $10, $0, $0 /* read MPL4 */
477 sd $11, PT_MPL+(2*8)(sp) /* store MPL2 */
478 v3mulu $11, $0, $0 /* read MPL5 */
479 sd $12, PT_MPL+(3*8)(sp) /* store MPL3 */
480 sd $10, PT_MPL+(4*8)(sp) /* store MPL4 */
482 sd $11, PT_MPL+(5*8)(sp) /* store MPL5 */
483 octeon_mult_save3_end:
484 EXPORT(octeon_mult_save3_end)
485 END(octeon_mult_save3)
489 * void octeon_mult_restore()
490 * sp is assumed to point to a struct pt_regs
492 * NOTE: This is called in RESTORE_TEMP in stackframe.h.
497 LEAF(octeon_mult_restore)
501 octeon_mult_restore_end:
502 EXPORT(octeon_mult_restore_end)
503 END(octeon_mult_restore)
505 LEAF(octeon_mult_restore2)
506 ld v0, PT_MPL(sp) /* MPL0 */
507 ld v1, PT_MPL+8(sp) /* MPL1 */
508 ld k0, PT_MPL+16(sp) /* MPL2 */
509 /* Restore the multiplier state */
510 ld k1, PT_MTP+16(sp) /* P2 */
512 ld v0, PT_MTP+8(sp) /* P1 */
514 ld v1, PT_MTP(sp) /* P0 */
520 octeon_mult_restore2_end:
521 EXPORT(octeon_mult_restore2_end)
522 END(octeon_mult_restore2)
524 LEAF(octeon_mult_restore3)
525 ld $12, PT_MPL+(0*8)(sp) /* read MPL0 */
526 ld $13, PT_MPL+(3*8)(sp) /* read MPL3 */
527 ld $10, PT_MPL+(1*8)(sp) /* read MPL1 */
528 ld $11, PT_MPL+(4*8)(sp) /* read MPL4 */
530 /* mtm0 $12, $13 restore MPL0 and MPL3 */
531 ld $12, PT_MPL+(2*8)(sp) /* read MPL2 */
533 /* mtm1 $10, $11 restore MPL1 and MPL4 */
534 ld $13, PT_MPL+(5*8)(sp) /* read MPL5 */
535 ld $10, PT_MTP+(0*8)(sp) /* read P0 */
536 ld $11, PT_MTP+(3*8)(sp) /* read P3 */
538 /* mtm2 $12, $13 restore MPL2 and MPL5 */
539 ld $12, PT_MTP+(1*8)(sp) /* read P1 */
541 /* mtp0 $10, $11 restore P0 and P3 */
542 ld $13, PT_MTP+(4*8)(sp) /* read P4 */
543 ld $10, PT_MTP+(2*8)(sp) /* read P2 */
544 ld $11, PT_MTP+(5*8)(sp) /* read P5 */
546 /* mtp1 $12, $13 restore P1 and P4 */
549 /* mtp2 $10, $11 restore P2 and P5 */
551 octeon_mult_restore3_end:
552 EXPORT(octeon_mult_restore3_end)
553 END(octeon_mult_restore3)