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>
18 #include <asm/pgtable-bits.h>
19 #include <asm/regdef.h>
20 #include <asm/stackframe.h>
21 #include <asm/thread_info.h>
23 #include <asm/asmmacro.h>
26 * Offset to the current process status flags, the first 32 bytes of the
29 #define ST_OFF (_THREAD_SIZE - 32 - PT_SIZE + PT_STATUS)
32 * task_struct *resume(task_struct *prev, task_struct *next,
33 * struct thread_info *next_ti, int usedfpu)
39 LONG_S t1, THREAD_STATUS(a0)
40 cpu_save_nonscratch a0
41 LONG_S ra, THREAD_REG31(a0)
43 /* check if we need to save COP2 registers */
44 PTR_L t2, TASK_THREAD_INFO(a0)
48 /* Disable COP2 in the stored process state */
53 /* Enable COP2 so we can save it */
63 /* Disable COP2 now that we are done */
70 #if CONFIG_CAVIUM_OCTEON_CVMSEG_SIZE > 0
71 /* Check if we need to store CVMSEG state */
72 mfc0 t0, $11,7 /* CvmMemCtl */
73 bbit0 t0, 6, 3f /* Is user access enabled? */
75 /* Store the CVMSEG state */
76 /* Extract the size of CVMSEG */
78 /* Multiply * (cache line size/sizeof(long)/2) */
80 li t1, -32768 /* Base address of CVMSEG */
81 LONG_ADDI t2, a0, THREAD_CVMSEG /* Where to store CVMSEG to */
85 LONG_L t8, 0(t1) /* Load from CVMSEG */
86 subu t0, 1 /* Decrement loop var */
87 LONG_L t9, LONGSIZE(t1)/* Load from CVMSEG */
88 LONG_ADDU t1, LONGSIZE*2 /* Increment loc in CVMSEG */
89 LONG_S t8, 0(t2) /* Store CVMSEG to thread storage */
90 LONG_ADDU t2, LONGSIZE*2 /* Increment loc in thread storage */
91 bnez t0, 2b /* Loop until we've copied it all */
92 LONG_S t9, -LONGSIZE(t2)/* Store CVMSEG to thread storage */
95 /* Disable access to CVMSEG */
96 mfc0 t0, $11,7 /* CvmMemCtl */
97 xori t0, t0, 0x40 /* Bit 6 is CVMSEG user enable */
98 mtc0 t0, $11,7 /* CvmMemCtl */
102 * The order of restoring the registers takes care of the race
103 * updating $28, $29 and kernelsp without disabling ints.
106 cpu_restore_nonscratch a1
108 #if (_THREAD_SIZE - 32) < 0x8000
109 PTR_ADDIU t0, $28, _THREAD_SIZE - 32
111 PTR_LI t0, _THREAD_SIZE - 32
114 set_saved_sp t0, t1, t2
116 mfc0 t1, CP0_STATUS /* Do we really need this? */
119 LONG_L a2, THREAD_STATUS(a1)
129 * void octeon_cop2_save(struct octeon_cop2_state *a0)
132 LEAF(octeon_cop2_save)
134 dmfc0 t9, $9,7 /* CvmCtl register. */
136 /* Save the COP2 CRC state */
140 sd t0, OCTEON_CP2_CRC_IV(a0)
141 sd t1, OCTEON_CP2_CRC_LENGTH(a0)
142 sd t2, OCTEON_CP2_CRC_POLY(a0)
143 /* Skip next instructions if CvmCtl[NODFA_CP2] set */
146 /* Save the LLM state */
149 sd t0, OCTEON_CP2_LLM_DAT(a0)
150 sd t1, OCTEON_CP2_LLM_DAT+8(a0)
152 1: bbit1 t9, 26, 3f /* done if CvmCtl[NOCRYPTO] set */
154 /* Save the COP2 crypto state */
155 /* this part is mostly common to both pass 1 and later revisions */
160 sd t0, OCTEON_CP2_3DES_IV(a0)
162 sd t1, OCTEON_CP2_3DES_KEY(a0)
163 dmfc2 t1, 0x0111 /* only necessary for pass 1 */
164 sd t2, OCTEON_CP2_3DES_KEY+8(a0)
166 sd t3, OCTEON_CP2_3DES_KEY+16(a0)
168 sd t0, OCTEON_CP2_3DES_RESULT(a0)
170 sd t1, OCTEON_CP2_AES_INP0(a0) /* only necessary for pass 1 */
172 sd t2, OCTEON_CP2_AES_IV(a0)
174 sd t3, OCTEON_CP2_AES_IV+8(a0)
176 sd t0, OCTEON_CP2_AES_KEY(a0)
178 sd t1, OCTEON_CP2_AES_KEY+8(a0)
180 sd t2, OCTEON_CP2_AES_KEY+16(a0)
182 sd t3, OCTEON_CP2_AES_KEY+24(a0)
183 mfc0 t3, $15,0 /* Get the processor ID register */
184 sd t0, OCTEON_CP2_AES_KEYLEN(a0)
185 li t0, 0x000d0000 /* This is the processor ID of Octeon Pass1 */
186 sd t1, OCTEON_CP2_AES_RESULT(a0)
187 sd t2, OCTEON_CP2_AES_RESULT+8(a0)
188 /* Skip to the Pass1 version of the remainder of the COP2 state */
191 /* the non-pass1 state when !CvmCtl[NOCRYPTO] */
196 sd t1, OCTEON_CP2_HSH_DATW(a0)
198 sd t2, OCTEON_CP2_HSH_DATW+8(a0)
200 sd t3, OCTEON_CP2_HSH_DATW+16(a0)
202 sd t0, OCTEON_CP2_HSH_DATW+24(a0)
204 sd t1, OCTEON_CP2_HSH_DATW+32(a0)
206 sd t2, OCTEON_CP2_HSH_DATW+40(a0)
208 sd t3, OCTEON_CP2_HSH_DATW+48(a0)
210 sd t0, OCTEON_CP2_HSH_DATW+56(a0)
212 sd t1, OCTEON_CP2_HSH_DATW+64(a0)
214 sd t2, OCTEON_CP2_HSH_DATW+72(a0)
216 sd t3, OCTEON_CP2_HSH_DATW+80(a0)
218 sd t0, OCTEON_CP2_HSH_DATW+88(a0)
220 sd t1, OCTEON_CP2_HSH_DATW+96(a0)
222 sd t2, OCTEON_CP2_HSH_DATW+104(a0)
224 sd t3, OCTEON_CP2_HSH_DATW+112(a0)
226 sd t0, OCTEON_CP2_HSH_IVW(a0)
228 sd t1, OCTEON_CP2_HSH_IVW+8(a0)
230 sd t2, OCTEON_CP2_HSH_IVW+16(a0)
232 sd t3, OCTEON_CP2_HSH_IVW+24(a0)
234 sd t0, OCTEON_CP2_HSH_IVW+32(a0)
236 sd t1, OCTEON_CP2_HSH_IVW+40(a0)
238 sd t2, OCTEON_CP2_HSH_IVW+48(a0)
240 sd t3, OCTEON_CP2_HSH_IVW+56(a0)
242 sd t0, OCTEON_CP2_GFM_MULT(a0)
244 sd t1, OCTEON_CP2_GFM_MULT+8(a0)
245 sd t2, OCTEON_CP2_GFM_POLY(a0)
246 sd t3, OCTEON_CP2_GFM_RESULT(a0)
247 sd t0, OCTEON_CP2_GFM_RESULT+8(a0)
250 2: /* pass 1 special stuff when !CvmCtl[NOCRYPTO] */
255 sd t3, OCTEON_CP2_HSH_DATW(a0)
257 sd t0, OCTEON_CP2_HSH_DATW+8(a0)
259 sd t1, OCTEON_CP2_HSH_DATW+16(a0)
261 sd t2, OCTEON_CP2_HSH_DATW+24(a0)
263 sd t3, OCTEON_CP2_HSH_DATW+32(a0)
265 sd t0, OCTEON_CP2_HSH_DATW+40(a0)
267 sd t1, OCTEON_CP2_HSH_DATW+48(a0)
268 sd t2, OCTEON_CP2_HSH_IVW(a0)
269 sd t3, OCTEON_CP2_HSH_IVW+8(a0)
270 sd t0, OCTEON_CP2_HSH_IVW+16(a0)
272 3: /* pass 1 or CvmCtl[NOCRYPTO] set */
274 END(octeon_cop2_save)
277 * void octeon_cop2_restore(struct octeon_cop2_state *a0)
282 LEAF(octeon_cop2_restore)
283 /* First cache line was prefetched before the call */
285 dmfc0 t9, $9,7 /* CvmCtl register. */
288 ld t0, OCTEON_CP2_CRC_IV(a0)
290 ld t1, OCTEON_CP2_CRC_LENGTH(a0)
291 ld t2, OCTEON_CP2_CRC_POLY(a0)
293 /* Restore the COP2 CRC state */
296 bbit1 t9, 28, 2f /* Skip LLM if CvmCtl[NODFA_CP2] is set */
299 /* Restore the LLM state */
300 ld t0, OCTEON_CP2_LLM_DAT(a0)
301 ld t1, OCTEON_CP2_LLM_DAT+8(a0)
306 bbit1 t9, 26, done_restore /* done if CvmCtl[NOCRYPTO] set */
309 /* Restore the COP2 crypto state common to pass 1 and pass 2 */
310 ld t0, OCTEON_CP2_3DES_IV(a0)
311 ld t1, OCTEON_CP2_3DES_KEY(a0)
312 ld t2, OCTEON_CP2_3DES_KEY+8(a0)
314 ld t0, OCTEON_CP2_3DES_KEY+16(a0)
316 ld t1, OCTEON_CP2_3DES_RESULT(a0)
318 ld t2, OCTEON_CP2_AES_INP0(a0) /* only really needed for pass 1 */
320 ld t0, OCTEON_CP2_AES_IV(a0)
322 ld t1, OCTEON_CP2_AES_IV+8(a0)
323 dmtc2 t2, 0x010A /* only really needed for pass 1 */
324 ld t2, OCTEON_CP2_AES_KEY(a0)
326 ld t0, OCTEON_CP2_AES_KEY+8(a0)
328 ld t1, OCTEON_CP2_AES_KEY+16(a0)
330 ld t2, OCTEON_CP2_AES_KEY+24(a0)
332 ld t0, OCTEON_CP2_AES_KEYLEN(a0)
334 ld t1, OCTEON_CP2_AES_RESULT(a0)
336 ld t2, OCTEON_CP2_AES_RESULT+8(a0)
337 mfc0 t3, $15,0 /* Get the processor ID register */
339 li t0, 0x000d0000 /* This is the processor ID of Octeon Pass1 */
341 bne t0, t3, 3f /* Skip the next stuff for non-pass1 */
344 /* this code is specific for pass 1 */
345 ld t0, OCTEON_CP2_HSH_DATW(a0)
346 ld t1, OCTEON_CP2_HSH_DATW+8(a0)
347 ld t2, OCTEON_CP2_HSH_DATW+16(a0)
349 ld t0, OCTEON_CP2_HSH_DATW+24(a0)
351 ld t1, OCTEON_CP2_HSH_DATW+32(a0)
353 ld t2, OCTEON_CP2_HSH_DATW+40(a0)
355 ld t0, OCTEON_CP2_HSH_DATW+48(a0)
357 ld t1, OCTEON_CP2_HSH_IVW(a0)
359 ld t2, OCTEON_CP2_HSH_IVW+8(a0)
361 ld t0, OCTEON_CP2_HSH_IVW+16(a0)
364 b done_restore /* unconditional branch */
367 3: /* this is post-pass1 code */
368 ld t2, OCTEON_CP2_HSH_DATW(a0)
369 ld t0, OCTEON_CP2_HSH_DATW+8(a0)
370 ld t1, OCTEON_CP2_HSH_DATW+16(a0)
372 ld t2, OCTEON_CP2_HSH_DATW+24(a0)
374 ld t0, OCTEON_CP2_HSH_DATW+32(a0)
376 ld t1, OCTEON_CP2_HSH_DATW+40(a0)
378 ld t2, OCTEON_CP2_HSH_DATW+48(a0)
380 ld t0, OCTEON_CP2_HSH_DATW+56(a0)
382 ld t1, OCTEON_CP2_HSH_DATW+64(a0)
384 ld t2, OCTEON_CP2_HSH_DATW+72(a0)
386 ld t0, OCTEON_CP2_HSH_DATW+80(a0)
388 ld t1, OCTEON_CP2_HSH_DATW+88(a0)
390 ld t2, OCTEON_CP2_HSH_DATW+96(a0)
392 ld t0, OCTEON_CP2_HSH_DATW+104(a0)
394 ld t1, OCTEON_CP2_HSH_DATW+112(a0)
396 ld t2, OCTEON_CP2_HSH_IVW(a0)
398 ld t0, OCTEON_CP2_HSH_IVW+8(a0)
400 ld t1, OCTEON_CP2_HSH_IVW+16(a0)
402 ld t2, OCTEON_CP2_HSH_IVW+24(a0)
404 ld t0, OCTEON_CP2_HSH_IVW+32(a0)
406 ld t1, OCTEON_CP2_HSH_IVW+40(a0)
408 ld t2, OCTEON_CP2_HSH_IVW+48(a0)
410 ld t0, OCTEON_CP2_HSH_IVW+56(a0)
412 ld t1, OCTEON_CP2_GFM_MULT(a0)
414 ld t2, OCTEON_CP2_GFM_MULT+8(a0)
416 ld t0, OCTEON_CP2_GFM_POLY(a0)
418 ld t1, OCTEON_CP2_GFM_RESULT(a0)
420 ld t2, OCTEON_CP2_GFM_RESULT+8(a0)
428 END(octeon_cop2_restore)
432 * void octeon_mult_save()
433 * sp is assumed to point to a struct pt_regs
435 * NOTE: This is called in SAVE_SOME in stackframe.h. It can only
436 * safely modify k0 and k1.
441 LEAF(octeon_mult_save)
442 dmfc0 k0, $9,7 /* CvmCtl register. */
443 bbit1 k0, 27, 1f /* Skip CvmCtl[NOMUL] */
446 /* Save the multiplier state */
449 sd k0, PT_MTP(sp) /* PT_MTP has P0 */
451 sd k1, PT_MTP+8(sp) /* PT_MTP+8 has P1 */
454 sd k0, PT_MTP+16(sp) /* PT_MTP+16 has P2 */
456 sd k1, PT_MPL(sp) /* PT_MPL has MPL0 */
458 sd k0, PT_MPL+8(sp) /* PT_MPL+8 has MPL1 */
460 sd k1, PT_MPL+16(sp) /* PT_MPL+16 has MPL2 */
462 1: /* Resume here if CvmCtl[NOMUL] */
464 END(octeon_mult_save)
468 * void octeon_mult_restore()
469 * sp is assumed to point to a struct pt_regs
471 * NOTE: This is called in RESTORE_SOME in stackframe.h.
476 LEAF(octeon_mult_restore)
477 dmfc0 k1, $9,7 /* CvmCtl register. */
478 ld v0, PT_MPL(sp) /* MPL0 */
479 ld v1, PT_MPL+8(sp) /* MPL1 */
480 ld k0, PT_MPL+16(sp) /* MPL2 */
481 bbit1 k1, 27, 1f /* Skip CvmCtl[NOMUL] */
482 /* Normally falls through, so no time wasted here */
485 /* Restore the multiplier state */
486 ld k1, PT_MTP+16(sp) /* P2 */
488 ld v0, PT_MTP+8(sp) /* P1 */
490 ld v1, PT_MTP(sp) /* P0 */
497 1: /* Resume here if CvmCtl[NOMUL] */
500 END(octeon_mult_restore)