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/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)
40 LONG_S t1, THREAD_STATUS(a0)
41 cpu_save_nonscratch a0
42 LONG_S ra, THREAD_REG31(a0)
44 /* check if we need to save COP2 registers */
45 PTR_L t2, TASK_THREAD_INFO(a0)
49 /* Disable COP2 in the stored process state */
54 /* Enable COP2 so we can save it */
64 /* Disable COP2 now that we are done */
71 #if CONFIG_CAVIUM_OCTEON_CVMSEG_SIZE > 0
72 /* Check if we need to store CVMSEG state */
73 mfc0 t0, $11,7 /* CvmMemCtl */
74 bbit0 t0, 6, 3f /* Is user access enabled? */
76 /* Store the CVMSEG state */
77 /* Extract the size of CVMSEG */
79 /* Multiply * (cache line size/sizeof(long)/2) */
81 li t1, -32768 /* Base address of CVMSEG */
82 LONG_ADDI t2, a0, THREAD_CVMSEG /* Where to store CVMSEG to */
86 LONG_L t8, 0(t1) /* Load from CVMSEG */
87 subu t0, 1 /* Decrement loop var */
88 LONG_L t9, LONGSIZE(t1)/* Load from CVMSEG */
89 LONG_ADDU t1, LONGSIZE*2 /* Increment loc in CVMSEG */
90 LONG_S t8, 0(t2) /* Store CVMSEG to thread storage */
91 LONG_ADDU t2, LONGSIZE*2 /* Increment loc in thread storage */
92 bnez t0, 2b /* Loop until we've copied it all */
93 LONG_S t9, -LONGSIZE(t2)/* Store CVMSEG to thread storage */
96 /* Disable access to CVMSEG */
97 mfc0 t0, $11,7 /* CvmMemCtl */
98 xori t0, t0, 0x40 /* Bit 6 is CVMSEG user enable */
99 mtc0 t0, $11,7 /* CvmMemCtl */
103 * The order of restoring the registers takes care of the race
104 * updating $28, $29 and kernelsp without disabling ints.
107 cpu_restore_nonscratch a1
109 #if (_THREAD_SIZE - 32) < 0x8000
110 PTR_ADDIU t0, $28, _THREAD_SIZE - 32
112 PTR_LI t0, _THREAD_SIZE - 32
115 set_saved_sp t0, t1, t2
117 mfc0 t1, CP0_STATUS /* Do we really need this? */
120 LONG_L a2, THREAD_STATUS(a1)
130 * void octeon_cop2_save(struct octeon_cop2_state *a0)
133 LEAF(octeon_cop2_save)
135 dmfc0 t9, $9,7 /* CvmCtl register. */
137 /* Save the COP2 CRC state */
141 sd t0, OCTEON_CP2_CRC_IV(a0)
142 sd t1, OCTEON_CP2_CRC_LENGTH(a0)
143 sd t2, OCTEON_CP2_CRC_POLY(a0)
144 /* Skip next instructions if CvmCtl[NODFA_CP2] set */
147 /* Save the LLM state */
150 sd t0, OCTEON_CP2_LLM_DAT(a0)
151 sd t1, OCTEON_CP2_LLM_DAT+8(a0)
153 1: bbit1 t9, 26, 3f /* done if CvmCtl[NOCRYPTO] set */
155 /* Save the COP2 crypto state */
156 /* this part is mostly common to both pass 1 and later revisions */
161 sd t0, OCTEON_CP2_3DES_IV(a0)
163 sd t1, OCTEON_CP2_3DES_KEY(a0)
164 dmfc2 t1, 0x0111 /* only necessary for pass 1 */
165 sd t2, OCTEON_CP2_3DES_KEY+8(a0)
167 sd t3, OCTEON_CP2_3DES_KEY+16(a0)
169 sd t0, OCTEON_CP2_3DES_RESULT(a0)
171 sd t1, OCTEON_CP2_AES_INP0(a0) /* only necessary for pass 1 */
173 sd t2, OCTEON_CP2_AES_IV(a0)
175 sd t3, OCTEON_CP2_AES_IV+8(a0)
177 sd t0, OCTEON_CP2_AES_KEY(a0)
179 sd t1, OCTEON_CP2_AES_KEY+8(a0)
181 sd t2, OCTEON_CP2_AES_KEY+16(a0)
183 sd t3, OCTEON_CP2_AES_KEY+24(a0)
184 mfc0 t3, $15,0 /* Get the processor ID register */
185 sd t0, OCTEON_CP2_AES_KEYLEN(a0)
186 li t0, 0x000d0000 /* This is the processor ID of Octeon Pass1 */
187 sd t1, OCTEON_CP2_AES_RESULT(a0)
188 sd t2, OCTEON_CP2_AES_RESULT+8(a0)
189 /* Skip to the Pass1 version of the remainder of the COP2 state */
192 /* the non-pass1 state when !CvmCtl[NOCRYPTO] */
197 sd t1, OCTEON_CP2_HSH_DATW(a0)
199 sd t2, OCTEON_CP2_HSH_DATW+8(a0)
201 sd t3, OCTEON_CP2_HSH_DATW+16(a0)
203 sd t0, OCTEON_CP2_HSH_DATW+24(a0)
205 sd t1, OCTEON_CP2_HSH_DATW+32(a0)
207 sd t2, OCTEON_CP2_HSH_DATW+40(a0)
209 sd t3, OCTEON_CP2_HSH_DATW+48(a0)
211 sd t0, OCTEON_CP2_HSH_DATW+56(a0)
213 sd t1, OCTEON_CP2_HSH_DATW+64(a0)
215 sd t2, OCTEON_CP2_HSH_DATW+72(a0)
217 sd t3, OCTEON_CP2_HSH_DATW+80(a0)
219 sd t0, OCTEON_CP2_HSH_DATW+88(a0)
221 sd t1, OCTEON_CP2_HSH_DATW+96(a0)
223 sd t2, OCTEON_CP2_HSH_DATW+104(a0)
225 sd t3, OCTEON_CP2_HSH_DATW+112(a0)
227 sd t0, OCTEON_CP2_HSH_IVW(a0)
229 sd t1, OCTEON_CP2_HSH_IVW+8(a0)
231 sd t2, OCTEON_CP2_HSH_IVW+16(a0)
233 sd t3, OCTEON_CP2_HSH_IVW+24(a0)
235 sd t0, OCTEON_CP2_HSH_IVW+32(a0)
237 sd t1, OCTEON_CP2_HSH_IVW+40(a0)
239 sd t2, OCTEON_CP2_HSH_IVW+48(a0)
241 sd t3, OCTEON_CP2_HSH_IVW+56(a0)
243 sd t0, OCTEON_CP2_GFM_MULT(a0)
245 sd t1, OCTEON_CP2_GFM_MULT+8(a0)
246 sd t2, OCTEON_CP2_GFM_POLY(a0)
247 sd t3, OCTEON_CP2_GFM_RESULT(a0)
248 sd t0, OCTEON_CP2_GFM_RESULT+8(a0)
251 2: /* pass 1 special stuff when !CvmCtl[NOCRYPTO] */
256 sd t3, OCTEON_CP2_HSH_DATW(a0)
258 sd t0, OCTEON_CP2_HSH_DATW+8(a0)
260 sd t1, OCTEON_CP2_HSH_DATW+16(a0)
262 sd t2, OCTEON_CP2_HSH_DATW+24(a0)
264 sd t3, OCTEON_CP2_HSH_DATW+32(a0)
266 sd t0, OCTEON_CP2_HSH_DATW+40(a0)
268 sd t1, OCTEON_CP2_HSH_DATW+48(a0)
269 sd t2, OCTEON_CP2_HSH_IVW(a0)
270 sd t3, OCTEON_CP2_HSH_IVW+8(a0)
271 sd t0, OCTEON_CP2_HSH_IVW+16(a0)
273 3: /* pass 1 or CvmCtl[NOCRYPTO] set */
275 END(octeon_cop2_save)
278 * void octeon_cop2_restore(struct octeon_cop2_state *a0)
283 LEAF(octeon_cop2_restore)
284 /* First cache line was prefetched before the call */
286 dmfc0 t9, $9,7 /* CvmCtl register. */
289 ld t0, OCTEON_CP2_CRC_IV(a0)
291 ld t1, OCTEON_CP2_CRC_LENGTH(a0)
292 ld t2, OCTEON_CP2_CRC_POLY(a0)
294 /* Restore the COP2 CRC state */
297 bbit1 t9, 28, 2f /* Skip LLM if CvmCtl[NODFA_CP2] is set */
300 /* Restore the LLM state */
301 ld t0, OCTEON_CP2_LLM_DAT(a0)
302 ld t1, OCTEON_CP2_LLM_DAT+8(a0)
307 bbit1 t9, 26, done_restore /* done if CvmCtl[NOCRYPTO] set */
310 /* Restore the COP2 crypto state common to pass 1 and pass 2 */
311 ld t0, OCTEON_CP2_3DES_IV(a0)
312 ld t1, OCTEON_CP2_3DES_KEY(a0)
313 ld t2, OCTEON_CP2_3DES_KEY+8(a0)
315 ld t0, OCTEON_CP2_3DES_KEY+16(a0)
317 ld t1, OCTEON_CP2_3DES_RESULT(a0)
319 ld t2, OCTEON_CP2_AES_INP0(a0) /* only really needed for pass 1 */
321 ld t0, OCTEON_CP2_AES_IV(a0)
323 ld t1, OCTEON_CP2_AES_IV+8(a0)
324 dmtc2 t2, 0x010A /* only really needed for pass 1 */
325 ld t2, OCTEON_CP2_AES_KEY(a0)
327 ld t0, OCTEON_CP2_AES_KEY+8(a0)
329 ld t1, OCTEON_CP2_AES_KEY+16(a0)
331 ld t2, OCTEON_CP2_AES_KEY+24(a0)
333 ld t0, OCTEON_CP2_AES_KEYLEN(a0)
335 ld t1, OCTEON_CP2_AES_RESULT(a0)
337 ld t2, OCTEON_CP2_AES_RESULT+8(a0)
338 mfc0 t3, $15,0 /* Get the processor ID register */
340 li t0, 0x000d0000 /* This is the processor ID of Octeon Pass1 */
342 bne t0, t3, 3f /* Skip the next stuff for non-pass1 */
345 /* this code is specific for pass 1 */
346 ld t0, OCTEON_CP2_HSH_DATW(a0)
347 ld t1, OCTEON_CP2_HSH_DATW+8(a0)
348 ld t2, OCTEON_CP2_HSH_DATW+16(a0)
350 ld t0, OCTEON_CP2_HSH_DATW+24(a0)
352 ld t1, OCTEON_CP2_HSH_DATW+32(a0)
354 ld t2, OCTEON_CP2_HSH_DATW+40(a0)
356 ld t0, OCTEON_CP2_HSH_DATW+48(a0)
358 ld t1, OCTEON_CP2_HSH_IVW(a0)
360 ld t2, OCTEON_CP2_HSH_IVW+8(a0)
362 ld t0, OCTEON_CP2_HSH_IVW+16(a0)
365 b done_restore /* unconditional branch */
368 3: /* this is post-pass1 code */
369 ld t2, OCTEON_CP2_HSH_DATW(a0)
370 ld t0, OCTEON_CP2_HSH_DATW+8(a0)
371 ld t1, OCTEON_CP2_HSH_DATW+16(a0)
373 ld t2, OCTEON_CP2_HSH_DATW+24(a0)
375 ld t0, OCTEON_CP2_HSH_DATW+32(a0)
377 ld t1, OCTEON_CP2_HSH_DATW+40(a0)
379 ld t2, OCTEON_CP2_HSH_DATW+48(a0)
381 ld t0, OCTEON_CP2_HSH_DATW+56(a0)
383 ld t1, OCTEON_CP2_HSH_DATW+64(a0)
385 ld t2, OCTEON_CP2_HSH_DATW+72(a0)
387 ld t0, OCTEON_CP2_HSH_DATW+80(a0)
389 ld t1, OCTEON_CP2_HSH_DATW+88(a0)
391 ld t2, OCTEON_CP2_HSH_DATW+96(a0)
393 ld t0, OCTEON_CP2_HSH_DATW+104(a0)
395 ld t1, OCTEON_CP2_HSH_DATW+112(a0)
397 ld t2, OCTEON_CP2_HSH_IVW(a0)
399 ld t0, OCTEON_CP2_HSH_IVW+8(a0)
401 ld t1, OCTEON_CP2_HSH_IVW+16(a0)
403 ld t2, OCTEON_CP2_HSH_IVW+24(a0)
405 ld t0, OCTEON_CP2_HSH_IVW+32(a0)
407 ld t1, OCTEON_CP2_HSH_IVW+40(a0)
409 ld t2, OCTEON_CP2_HSH_IVW+48(a0)
411 ld t0, OCTEON_CP2_HSH_IVW+56(a0)
413 ld t1, OCTEON_CP2_GFM_MULT(a0)
415 ld t2, OCTEON_CP2_GFM_MULT+8(a0)
417 ld t0, OCTEON_CP2_GFM_POLY(a0)
419 ld t1, OCTEON_CP2_GFM_RESULT(a0)
421 ld t2, OCTEON_CP2_GFM_RESULT+8(a0)
429 END(octeon_cop2_restore)
433 * void octeon_mult_save()
434 * sp is assumed to point to a struct pt_regs
436 * NOTE: This is called in SAVE_SOME in stackframe.h. It can only
437 * safely modify k0 and k1.
442 LEAF(octeon_mult_save)
443 dmfc0 k0, $9,7 /* CvmCtl register. */
444 bbit1 k0, 27, 1f /* Skip CvmCtl[NOMUL] */
447 /* Save the multiplier state */
450 sd k0, PT_MTP(sp) /* PT_MTP has P0 */
452 sd k1, PT_MTP+8(sp) /* PT_MTP+8 has P1 */
455 sd k0, PT_MTP+16(sp) /* PT_MTP+16 has P2 */
457 sd k1, PT_MPL(sp) /* PT_MPL has MPL0 */
459 sd k0, PT_MPL+8(sp) /* PT_MPL+8 has MPL1 */
461 sd k1, PT_MPL+16(sp) /* PT_MPL+16 has MPL2 */
463 1: /* Resume here if CvmCtl[NOMUL] */
465 END(octeon_mult_save)
469 * void octeon_mult_restore()
470 * sp is assumed to point to a struct pt_regs
472 * NOTE: This is called in RESTORE_SOME in stackframe.h.
477 LEAF(octeon_mult_restore)
478 dmfc0 k1, $9,7 /* CvmCtl register. */
479 ld v0, PT_MPL(sp) /* MPL0 */
480 ld v1, PT_MPL+8(sp) /* MPL1 */
481 ld k0, PT_MPL+16(sp) /* MPL2 */
482 bbit1 k1, 27, 1f /* Skip CvmCtl[NOMUL] */
483 /* Normally falls through, so no time wasted here */
486 /* Restore the multiplier state */
487 ld k1, PT_MTP+16(sp) /* P2 */
489 ld v0, PT_MTP+8(sp) /* P1 */
491 ld v1, PT_MTP(sp) /* P0 */
498 1: /* Resume here if CvmCtl[NOMUL] */
501 END(octeon_mult_restore)