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 (dm@engr.sgi.com)
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/cachectl.h>
15 #include <asm/fpregdef.h>
16 #include <asm/mipsregs.h>
17 #include <asm/asm-offsets.h>
19 #include <asm/pgtable-bits.h>
20 #include <asm/regdef.h>
21 #include <asm/stackframe.h>
22 #include <asm/thread_info.h>
24 #include <asm/asmmacro.h>
27 * Offset to the current process status flags, the first 32 bytes of the
30 #define ST_OFF (_THREAD_SIZE - 32 - PT_SIZE + PT_STATUS)
33 * task_struct *resume(task_struct *prev, task_struct *next,
34 * struct thread_info *next_ti)
39 #ifndef CONFIG_CPU_HAS_LLSC
43 LONG_S t1, THREAD_STATUS(a0)
44 cpu_save_nonscratch a0
45 LONG_S ra, THREAD_REG31(a0)
47 /* check if we need to save COP2 registers */
48 PTR_L t2, TASK_THREAD_INFO(a0)
52 /* Disable COP2 in the stored process state */
57 /* Enable COP2 so we can save it */
67 /* Disable COP2 now that we are done */
74 #if CONFIG_CAVIUM_OCTEON_CVMSEG_SIZE > 0
75 /* Check if we need to store CVMSEG state */
76 mfc0 t0, $11,7 /* CvmMemCtl */
77 bbit0 t0, 6, 3f /* Is user access enabled? */
79 /* Store the CVMSEG state */
80 /* Extract the size of CVMSEG */
82 /* Multiply * (cache line size/sizeof(long)/2) */
84 li t1, -32768 /* Base address of CVMSEG */
85 LONG_ADDI t2, a0, THREAD_CVMSEG /* Where to store CVMSEG to */
89 LONG_L t8, 0(t1) /* Load from CVMSEG */
90 subu t0, 1 /* Decrement loop var */
91 LONG_L t9, LONGSIZE(t1)/* Load from CVMSEG */
92 LONG_ADDU t1, LONGSIZE*2 /* Increment loc in CVMSEG */
93 LONG_S t8, 0(t2) /* Store CVMSEG to thread storage */
94 LONG_ADDU t2, LONGSIZE*2 /* Increment loc in thread storage */
95 bnez t0, 2b /* Loop until we've copied it all */
96 LONG_S t9, -LONGSIZE(t2)/* Store CVMSEG to thread storage */
99 /* Disable access to CVMSEG */
100 mfc0 t0, $11,7 /* CvmMemCtl */
101 xori t0, t0, 0x40 /* Bit 6 is CVMSEG user enable */
102 mtc0 t0, $11,7 /* CvmMemCtl */
106 * The order of restoring the registers takes care of the race
107 * updating $28, $29 and kernelsp without disabling ints.
110 cpu_restore_nonscratch a1
112 #if (_THREAD_SIZE - 32) < 0x8000
113 PTR_ADDIU t0, $28, _THREAD_SIZE - 32
115 PTR_LI t0, _THREAD_SIZE - 32
118 set_saved_sp t0, t1, t2
120 mfc0 t1, CP0_STATUS /* Do we really need this? */
123 LONG_L a2, THREAD_STATUS(a1)
133 * void octeon_cop2_save(struct octeon_cop2_state *a0)
136 LEAF(octeon_cop2_save)
138 dmfc0 t9, $9,7 /* CvmCtl register. */
140 /* Save the COP2 CRC state */
144 sd t0, OCTEON_CP2_CRC_IV(a0)
145 sd t1, OCTEON_CP2_CRC_LENGTH(a0)
146 sd t2, OCTEON_CP2_CRC_POLY(a0)
147 /* Skip next instructions if CvmCtl[NODFA_CP2] set */
150 /* Save the LLM state */
153 sd t0, OCTEON_CP2_LLM_DAT(a0)
154 sd t1, OCTEON_CP2_LLM_DAT+8(a0)
156 1: bbit1 t9, 26, 3f /* done if CvmCtl[NOCRYPTO] set */
158 /* Save the COP2 crypto state */
159 /* this part is mostly common to both pass 1 and later revisions */
164 sd t0, OCTEON_CP2_3DES_IV(a0)
166 sd t1, OCTEON_CP2_3DES_KEY(a0)
167 dmfc2 t1, 0x0111 /* only necessary for pass 1 */
168 sd t2, OCTEON_CP2_3DES_KEY+8(a0)
170 sd t3, OCTEON_CP2_3DES_KEY+16(a0)
172 sd t0, OCTEON_CP2_3DES_RESULT(a0)
174 sd t1, OCTEON_CP2_AES_INP0(a0) /* only necessary for pass 1 */
176 sd t2, OCTEON_CP2_AES_IV(a0)
178 sd t3, OCTEON_CP2_AES_IV+8(a0)
180 sd t0, OCTEON_CP2_AES_KEY(a0)
182 sd t1, OCTEON_CP2_AES_KEY+8(a0)
184 sd t2, OCTEON_CP2_AES_KEY+16(a0)
186 sd t3, OCTEON_CP2_AES_KEY+24(a0)
187 mfc0 t3, $15,0 /* Get the processor ID register */
188 sd t0, OCTEON_CP2_AES_KEYLEN(a0)
189 li t0, 0x000d0000 /* This is the processor ID of Octeon Pass1 */
190 sd t1, OCTEON_CP2_AES_RESULT(a0)
191 sd t2, OCTEON_CP2_AES_RESULT+8(a0)
192 /* Skip to the Pass1 version of the remainder of the COP2 state */
195 /* the non-pass1 state when !CvmCtl[NOCRYPTO] */
200 sd t1, OCTEON_CP2_HSH_DATW(a0)
202 sd t2, OCTEON_CP2_HSH_DATW+8(a0)
204 sd t3, OCTEON_CP2_HSH_DATW+16(a0)
206 sd t0, OCTEON_CP2_HSH_DATW+24(a0)
208 sd t1, OCTEON_CP2_HSH_DATW+32(a0)
210 sd t2, OCTEON_CP2_HSH_DATW+40(a0)
212 sd t3, OCTEON_CP2_HSH_DATW+48(a0)
214 sd t0, OCTEON_CP2_HSH_DATW+56(a0)
216 sd t1, OCTEON_CP2_HSH_DATW+64(a0)
218 sd t2, OCTEON_CP2_HSH_DATW+72(a0)
220 sd t3, OCTEON_CP2_HSH_DATW+80(a0)
222 sd t0, OCTEON_CP2_HSH_DATW+88(a0)
224 sd t1, OCTEON_CP2_HSH_DATW+96(a0)
226 sd t2, OCTEON_CP2_HSH_DATW+104(a0)
228 sd t3, OCTEON_CP2_HSH_DATW+112(a0)
230 sd t0, OCTEON_CP2_HSH_IVW(a0)
232 sd t1, OCTEON_CP2_HSH_IVW+8(a0)
234 sd t2, OCTEON_CP2_HSH_IVW+16(a0)
236 sd t3, OCTEON_CP2_HSH_IVW+24(a0)
238 sd t0, OCTEON_CP2_HSH_IVW+32(a0)
240 sd t1, OCTEON_CP2_HSH_IVW+40(a0)
242 sd t2, OCTEON_CP2_HSH_IVW+48(a0)
244 sd t3, OCTEON_CP2_HSH_IVW+56(a0)
246 sd t0, OCTEON_CP2_GFM_MULT(a0)
248 sd t1, OCTEON_CP2_GFM_MULT+8(a0)
249 sd t2, OCTEON_CP2_GFM_POLY(a0)
250 sd t3, OCTEON_CP2_GFM_RESULT(a0)
251 sd t0, OCTEON_CP2_GFM_RESULT+8(a0)
254 2: /* pass 1 special stuff when !CvmCtl[NOCRYPTO] */
259 sd t3, OCTEON_CP2_HSH_DATW(a0)
261 sd t0, OCTEON_CP2_HSH_DATW+8(a0)
263 sd t1, OCTEON_CP2_HSH_DATW+16(a0)
265 sd t2, OCTEON_CP2_HSH_DATW+24(a0)
267 sd t3, OCTEON_CP2_HSH_DATW+32(a0)
269 sd t0, OCTEON_CP2_HSH_DATW+40(a0)
271 sd t1, OCTEON_CP2_HSH_DATW+48(a0)
272 sd t2, OCTEON_CP2_HSH_IVW(a0)
273 sd t3, OCTEON_CP2_HSH_IVW+8(a0)
274 sd t0, OCTEON_CP2_HSH_IVW+16(a0)
276 3: /* pass 1 or CvmCtl[NOCRYPTO] set */
278 END(octeon_cop2_save)
281 * void octeon_cop2_restore(struct octeon_cop2_state *a0)
286 LEAF(octeon_cop2_restore)
287 /* First cache line was prefetched before the call */
289 dmfc0 t9, $9,7 /* CvmCtl register. */
292 ld t0, OCTEON_CP2_CRC_IV(a0)
294 ld t1, OCTEON_CP2_CRC_LENGTH(a0)
295 ld t2, OCTEON_CP2_CRC_POLY(a0)
297 /* Restore the COP2 CRC state */
300 bbit1 t9, 28, 2f /* Skip LLM if CvmCtl[NODFA_CP2] is set */
303 /* Restore the LLM state */
304 ld t0, OCTEON_CP2_LLM_DAT(a0)
305 ld t1, OCTEON_CP2_LLM_DAT+8(a0)
310 bbit1 t9, 26, done_restore /* done if CvmCtl[NOCRYPTO] set */
313 /* Restore the COP2 crypto state common to pass 1 and pass 2 */
314 ld t0, OCTEON_CP2_3DES_IV(a0)
315 ld t1, OCTEON_CP2_3DES_KEY(a0)
316 ld t2, OCTEON_CP2_3DES_KEY+8(a0)
318 ld t0, OCTEON_CP2_3DES_KEY+16(a0)
320 ld t1, OCTEON_CP2_3DES_RESULT(a0)
322 ld t2, OCTEON_CP2_AES_INP0(a0) /* only really needed for pass 1 */
324 ld t0, OCTEON_CP2_AES_IV(a0)
326 ld t1, OCTEON_CP2_AES_IV+8(a0)
327 dmtc2 t2, 0x010A /* only really needed for pass 1 */
328 ld t2, OCTEON_CP2_AES_KEY(a0)
330 ld t0, OCTEON_CP2_AES_KEY+8(a0)
332 ld t1, OCTEON_CP2_AES_KEY+16(a0)
334 ld t2, OCTEON_CP2_AES_KEY+24(a0)
336 ld t0, OCTEON_CP2_AES_KEYLEN(a0)
338 ld t1, OCTEON_CP2_AES_RESULT(a0)
340 ld t2, OCTEON_CP2_AES_RESULT+8(a0)
341 mfc0 t3, $15,0 /* Get the processor ID register */
343 li t0, 0x000d0000 /* This is the processor ID of Octeon Pass1 */
345 bne t0, t3, 3f /* Skip the next stuff for non-pass1 */
348 /* this code is specific for pass 1 */
349 ld t0, OCTEON_CP2_HSH_DATW(a0)
350 ld t1, OCTEON_CP2_HSH_DATW+8(a0)
351 ld t2, OCTEON_CP2_HSH_DATW+16(a0)
353 ld t0, OCTEON_CP2_HSH_DATW+24(a0)
355 ld t1, OCTEON_CP2_HSH_DATW+32(a0)
357 ld t2, OCTEON_CP2_HSH_DATW+40(a0)
359 ld t0, OCTEON_CP2_HSH_DATW+48(a0)
361 ld t1, OCTEON_CP2_HSH_IVW(a0)
363 ld t2, OCTEON_CP2_HSH_IVW+8(a0)
365 ld t0, OCTEON_CP2_HSH_IVW+16(a0)
368 b done_restore /* unconditional branch */
371 3: /* this is post-pass1 code */
372 ld t2, OCTEON_CP2_HSH_DATW(a0)
373 ld t0, OCTEON_CP2_HSH_DATW+8(a0)
374 ld t1, OCTEON_CP2_HSH_DATW+16(a0)
376 ld t2, OCTEON_CP2_HSH_DATW+24(a0)
378 ld t0, OCTEON_CP2_HSH_DATW+32(a0)
380 ld t1, OCTEON_CP2_HSH_DATW+40(a0)
382 ld t2, OCTEON_CP2_HSH_DATW+48(a0)
384 ld t0, OCTEON_CP2_HSH_DATW+56(a0)
386 ld t1, OCTEON_CP2_HSH_DATW+64(a0)
388 ld t2, OCTEON_CP2_HSH_DATW+72(a0)
390 ld t0, OCTEON_CP2_HSH_DATW+80(a0)
392 ld t1, OCTEON_CP2_HSH_DATW+88(a0)
394 ld t2, OCTEON_CP2_HSH_DATW+96(a0)
396 ld t0, OCTEON_CP2_HSH_DATW+104(a0)
398 ld t1, OCTEON_CP2_HSH_DATW+112(a0)
400 ld t2, OCTEON_CP2_HSH_IVW(a0)
402 ld t0, OCTEON_CP2_HSH_IVW+8(a0)
404 ld t1, OCTEON_CP2_HSH_IVW+16(a0)
406 ld t2, OCTEON_CP2_HSH_IVW+24(a0)
408 ld t0, OCTEON_CP2_HSH_IVW+32(a0)
410 ld t1, OCTEON_CP2_HSH_IVW+40(a0)
412 ld t2, OCTEON_CP2_HSH_IVW+48(a0)
414 ld t0, OCTEON_CP2_HSH_IVW+56(a0)
416 ld t1, OCTEON_CP2_GFM_MULT(a0)
418 ld t2, OCTEON_CP2_GFM_MULT+8(a0)
420 ld t0, OCTEON_CP2_GFM_POLY(a0)
422 ld t1, OCTEON_CP2_GFM_RESULT(a0)
424 ld t2, OCTEON_CP2_GFM_RESULT+8(a0)
432 END(octeon_cop2_restore)
436 * void octeon_mult_save()
437 * sp is assumed to point to a struct pt_regs
439 * NOTE: This is called in SAVE_SOME in stackframe.h. It can only
440 * safely modify k0 and k1.
445 LEAF(octeon_mult_save)
446 dmfc0 k0, $9,7 /* CvmCtl register. */
447 bbit1 k0, 27, 1f /* Skip CvmCtl[NOMUL] */
450 /* Save the multiplier state */
453 sd k0, PT_MTP(sp) /* PT_MTP has P0 */
455 sd k1, PT_MTP+8(sp) /* PT_MTP+8 has P1 */
458 sd k0, PT_MTP+16(sp) /* PT_MTP+16 has P2 */
460 sd k1, PT_MPL(sp) /* PT_MPL has MPL0 */
462 sd k0, PT_MPL+8(sp) /* PT_MPL+8 has MPL1 */
464 sd k1, PT_MPL+16(sp) /* PT_MPL+16 has MPL2 */
466 1: /* Resume here if CvmCtl[NOMUL] */
468 END(octeon_mult_save)
472 * void octeon_mult_restore()
473 * sp is assumed to point to a struct pt_regs
475 * NOTE: This is called in RESTORE_SOME in stackframe.h.
480 LEAF(octeon_mult_restore)
481 dmfc0 k1, $9,7 /* CvmCtl register. */
482 ld v0, PT_MPL(sp) /* MPL0 */
483 ld v1, PT_MPL+8(sp) /* MPL1 */
484 ld k0, PT_MPL+16(sp) /* MPL2 */
485 bbit1 k1, 27, 1f /* Skip CvmCtl[NOMUL] */
486 /* Normally falls through, so no time wasted here */
489 /* Restore the multiplier state */
490 ld k1, PT_MTP+16(sp) /* P2 */
492 ld v0, PT_MTP+8(sp) /* P1 */
494 ld v1, PT_MTP(sp) /* P0 */
501 1: /* Resume here if CvmCtl[NOMUL] */
504 END(octeon_mult_restore)