xref: /openbmc/linux/arch/mips/kernel/octeon_switch.S (revision c900529f3d9161bfde5cca0754f83b4d3c3e0220)
15b3b1688SDavid Daney/*
25b3b1688SDavid Daney * This file is subject to the terms and conditions of the GNU General Public
35b3b1688SDavid Daney * License.  See the file "COPYING" in the main directory of this archive
45b3b1688SDavid Daney * for more details.
55b3b1688SDavid Daney *
65b3b1688SDavid Daney * Copyright (C) 1994, 1995, 1996, 1998, 1999, 2002, 2003 Ralf Baechle
779add627SJustin P. Mattock * Copyright (C) 1996 David S. Miller (davem@davemloft.net)
85b3b1688SDavid Daney * Copyright (C) 1994, 1995, 1996, by Andreas Busse
95b3b1688SDavid Daney * Copyright (C) 1999 Silicon Graphics, Inc.
105b3b1688SDavid Daney * Copyright (C) 2000 MIPS Technologies, Inc.
115b3b1688SDavid Daney *    written by Carsten Langgaard, carstenl@mips.com
125b3b1688SDavid Daney */
13a2aea699SPaul Burton#include <asm/asm.h>
14a2aea699SPaul Burton#include <asm/asm-offsets.h>
15a2aea699SPaul Burton#include <asm/mipsregs.h>
16a2aea699SPaul Burton#include <asm/regdef.h>
17a2aea699SPaul Burton#include <asm/stackframe.h>
185b3b1688SDavid Daney
195b3b1688SDavid Daney/*
205b3b1688SDavid Daney * task_struct *resume(task_struct *prev, task_struct *next,
210fa24340SPaul Burton *		       struct thread_info *next_ti)
225b3b1688SDavid Daney */
235b3b1688SDavid Daney	.align	7
245b3b1688SDavid Daney	LEAF(resume)
255b3b1688SDavid Daney	.set arch=octeon
265b3b1688SDavid Daney	mfc0	t1, CP0_STATUS
275b3b1688SDavid Daney	LONG_S	t1, THREAD_STATUS(a0)
285b3b1688SDavid Daney	cpu_save_nonscratch a0
295b3b1688SDavid Daney	LONG_S	ra, THREAD_REG31(a0)
305b3b1688SDavid Daney
315b3b1688SDavid Daney#if CONFIG_CAVIUM_OCTEON_CVMSEG_SIZE > 0
325b3b1688SDavid Daney	/* Check if we need to store CVMSEG state */
332d98cae6SChandrakala Chavva	dmfc0	t0, $11,7	/* CvmMemCtl */
345b3b1688SDavid Daney	bbit0	t0, 6, 3f	/* Is user access enabled? */
355b3b1688SDavid Daney
365b3b1688SDavid Daney	/* Store the CVMSEG state */
375b3b1688SDavid Daney	/* Extract the size of CVMSEG */
385b3b1688SDavid Daney	andi	t0, 0x3f
395b3b1688SDavid Daney	/* Multiply * (cache line size/sizeof(long)/2) */
405b3b1688SDavid Daney	sll	t0, 7-LONGLOG-1
415b3b1688SDavid Daney	li	t1, -32768	/* Base address of CVMSEG */
425b3b1688SDavid Daney	LONG_ADDI t2, a0, THREAD_CVMSEG /* Where to store CVMSEG to */
435b3b1688SDavid Daney	synciobdma
445b3b1688SDavid Daney2:
455b3b1688SDavid Daney	.set noreorder
465b3b1688SDavid Daney	LONG_L	t8, 0(t1)	/* Load from CVMSEG */
475b3b1688SDavid Daney	subu	t0, 1		/* Decrement loop var */
485b3b1688SDavid Daney	LONG_L	t9, LONGSIZE(t1)/* Load from CVMSEG */
495b3b1688SDavid Daney	LONG_ADDU t1, LONGSIZE*2 /* Increment loc in CVMSEG */
505b3b1688SDavid Daney	LONG_S	t8, 0(t2)	/* Store CVMSEG to thread storage */
515b3b1688SDavid Daney	LONG_ADDU t2, LONGSIZE*2 /* Increment loc in thread storage */
525b3b1688SDavid Daney	bnez	t0, 2b		/* Loop until we've copied it all */
535b3b1688SDavid Daney	 LONG_S t9, -LONGSIZE(t2)/* Store CVMSEG to thread storage */
545b3b1688SDavid Daney	.set reorder
555b3b1688SDavid Daney
565b3b1688SDavid Daney	/* Disable access to CVMSEG */
572d98cae6SChandrakala Chavva	dmfc0	t0, $11,7	/* CvmMemCtl */
585b3b1688SDavid Daney	xori	t0, t0, 0x40	/* Bit 6 is CVMSEG user enable */
592d98cae6SChandrakala Chavva	dmtc0	t0, $11,7	/* CvmMemCtl */
605b3b1688SDavid Daney#endif
615b3b1688SDavid Daney3:
621400eb65SGregory Fong
63*050e9baaSLinus Torvalds#if defined(CONFIG_STACKPROTECTOR) && !defined(CONFIG_SMP)
648b3c569aSJames Hogan	PTR_LA	t8, __stack_chk_guard
651400eb65SGregory Fong	LONG_L	t9, TASK_STACK_CANARY(a1)
661400eb65SGregory Fong	LONG_S	t9, 0(t8)
671400eb65SGregory Fong#endif
681400eb65SGregory Fong
695b3b1688SDavid Daney	/*
705b3b1688SDavid Daney	 * The order of restoring the registers takes care of the race
715b3b1688SDavid Daney	 * updating $28, $29 and kernelsp without disabling ints.
725b3b1688SDavid Daney	 */
735b3b1688SDavid Daney	move	$28, a2
745b3b1688SDavid Daney	cpu_restore_nonscratch a1
755b3b1688SDavid Daney
76a36d8225SDavid Daney	PTR_ADDU	t0, $28, _THREAD_SIZE - 32
775b3b1688SDavid Daney	set_saved_sp	t0, t1, t2
785b3b1688SDavid Daney
795b3b1688SDavid Daney	mfc0	t1, CP0_STATUS		/* Do we really need this? */
805b3b1688SDavid Daney	li	a3, 0xff01
815b3b1688SDavid Daney	and	t1, a3
825b3b1688SDavid Daney	LONG_L	a2, THREAD_STATUS(a1)
835b3b1688SDavid Daney	nor	a3, $0, a3
845b3b1688SDavid Daney	and	a2, a3
855b3b1688SDavid Daney	or	a2, t1
865b3b1688SDavid Daney	mtc0	a2, CP0_STATUS
875b3b1688SDavid Daney	move	v0, a0
885b3b1688SDavid Daney	jr	ra
895b3b1688SDavid Daney	END(resume)
905b3b1688SDavid Daney
915b3b1688SDavid Daney/*
925b3b1688SDavid Daney * void octeon_cop2_save(struct octeon_cop2_state *a0)
935b3b1688SDavid Daney */
945b3b1688SDavid Daney	.align	7
956b3a287eSDavid Daney	.set push
966b3a287eSDavid Daney	.set noreorder
975b3b1688SDavid Daney	LEAF(octeon_cop2_save)
985b3b1688SDavid Daney
995b3b1688SDavid Daney	dmfc0	t9, $9,7	/* CvmCtl register. */
1005b3b1688SDavid Daney
1015b3b1688SDavid Daney	/* Save the COP2 CRC state */
1025b3b1688SDavid Daney	dmfc2	t0, 0x0201
1035b3b1688SDavid Daney	dmfc2	t1, 0x0202
1045b3b1688SDavid Daney	dmfc2	t2, 0x0200
1055b3b1688SDavid Daney	sd	t0, OCTEON_CP2_CRC_IV(a0)
1065b3b1688SDavid Daney	sd	t1, OCTEON_CP2_CRC_LENGTH(a0)
1075b3b1688SDavid Daney	/* Skip next instructions if CvmCtl[NODFA_CP2] set */
1085b3b1688SDavid Daney	bbit1	t9, 28, 1f
1096b3a287eSDavid Daney	 sd	t2, OCTEON_CP2_CRC_POLY(a0)
1105b3b1688SDavid Daney
1115b3b1688SDavid Daney	/* Save the LLM state */
1125b3b1688SDavid Daney	dmfc2	t0, 0x0402
1135b3b1688SDavid Daney	dmfc2	t1, 0x040A
1145b3b1688SDavid Daney	sd	t0, OCTEON_CP2_LLM_DAT(a0)
1155b3b1688SDavid Daney
1165b3b1688SDavid Daney1:	bbit1	t9, 26, 3f	/* done if CvmCtl[NOCRYPTO] set */
1176b3a287eSDavid Daney	 sd	t1, OCTEON_CP2_LLM_DAT+8(a0)
1185b3b1688SDavid Daney
1195b3b1688SDavid Daney	/* Save the COP2 crypto state */
1205b3b1688SDavid Daney	/* this part is mostly common to both pass 1 and later revisions */
1215b3b1688SDavid Daney	dmfc2	t0, 0x0084
1225b3b1688SDavid Daney	dmfc2	t1, 0x0080
1235b3b1688SDavid Daney	dmfc2	t2, 0x0081
1245b3b1688SDavid Daney	dmfc2	t3, 0x0082
1255b3b1688SDavid Daney	sd	t0, OCTEON_CP2_3DES_IV(a0)
1265b3b1688SDavid Daney	dmfc2	t0, 0x0088
1275b3b1688SDavid Daney	sd	t1, OCTEON_CP2_3DES_KEY(a0)
1285b3b1688SDavid Daney	dmfc2	t1, 0x0111			/* only necessary for pass 1 */
1295b3b1688SDavid Daney	sd	t2, OCTEON_CP2_3DES_KEY+8(a0)
1305b3b1688SDavid Daney	dmfc2	t2, 0x0102
1315b3b1688SDavid Daney	sd	t3, OCTEON_CP2_3DES_KEY+16(a0)
1325b3b1688SDavid Daney	dmfc2	t3, 0x0103
1335b3b1688SDavid Daney	sd	t0, OCTEON_CP2_3DES_RESULT(a0)
1345b3b1688SDavid Daney	dmfc2	t0, 0x0104
1355b3b1688SDavid Daney	sd	t1, OCTEON_CP2_AES_INP0(a0)	/* only necessary for pass 1 */
1365b3b1688SDavid Daney	dmfc2	t1, 0x0105
1375b3b1688SDavid Daney	sd	t2, OCTEON_CP2_AES_IV(a0)
1385b3b1688SDavid Daney	dmfc2	t2, 0x0106
1395b3b1688SDavid Daney	sd	t3, OCTEON_CP2_AES_IV+8(a0)
1405b3b1688SDavid Daney	dmfc2	t3, 0x0107
1415b3b1688SDavid Daney	sd	t0, OCTEON_CP2_AES_KEY(a0)
1425b3b1688SDavid Daney	dmfc2	t0, 0x0110
1435b3b1688SDavid Daney	sd	t1, OCTEON_CP2_AES_KEY+8(a0)
1445b3b1688SDavid Daney	dmfc2	t1, 0x0100
1455b3b1688SDavid Daney	sd	t2, OCTEON_CP2_AES_KEY+16(a0)
1465b3b1688SDavid Daney	dmfc2	t2, 0x0101
1475b3b1688SDavid Daney	sd	t3, OCTEON_CP2_AES_KEY+24(a0)
1486b3a287eSDavid Daney	mfc0	v0, $15,0	/* Get the processor ID register */
1495b3b1688SDavid Daney	sd	t0, OCTEON_CP2_AES_KEYLEN(a0)
1506b3a287eSDavid Daney	li	v1, 0x000d0000	/* This is the processor ID of Octeon Pass1 */
1515b3b1688SDavid Daney	sd	t1, OCTEON_CP2_AES_RESULT(a0)
1525b3b1688SDavid Daney	/* Skip to the Pass1 version of the remainder of the COP2 state */
1536b3a287eSDavid Daney	beq	v0, v1, 2f
1546b3a287eSDavid Daney	 sd	t2, OCTEON_CP2_AES_RESULT+8(a0)
1555b3b1688SDavid Daney
1565b3b1688SDavid Daney	/* the non-pass1 state when !CvmCtl[NOCRYPTO] */
1575b3b1688SDavid Daney	dmfc2	t1, 0x0240
1585b3b1688SDavid Daney	dmfc2	t2, 0x0241
1596b3a287eSDavid Daney	ori	v1, v1, 0x9500 /* lowest OCTEON III PrId*/
1605b3b1688SDavid Daney	dmfc2	t3, 0x0242
1616b3a287eSDavid Daney	subu	v1, v0, v1 /* prid - lowest OCTEON III PrId */
1625b3b1688SDavid Daney	dmfc2	t0, 0x0243
1635b3b1688SDavid Daney	sd	t1, OCTEON_CP2_HSH_DATW(a0)
1645b3b1688SDavid Daney	dmfc2	t1, 0x0244
1655b3b1688SDavid Daney	sd	t2, OCTEON_CP2_HSH_DATW+8(a0)
1665b3b1688SDavid Daney	dmfc2	t2, 0x0245
1675b3b1688SDavid Daney	sd	t3, OCTEON_CP2_HSH_DATW+16(a0)
1685b3b1688SDavid Daney	dmfc2	t3, 0x0246
1695b3b1688SDavid Daney	sd	t0, OCTEON_CP2_HSH_DATW+24(a0)
1705b3b1688SDavid Daney	dmfc2	t0, 0x0247
1715b3b1688SDavid Daney	sd	t1, OCTEON_CP2_HSH_DATW+32(a0)
1725b3b1688SDavid Daney	dmfc2	t1, 0x0248
1735b3b1688SDavid Daney	sd	t2, OCTEON_CP2_HSH_DATW+40(a0)
1745b3b1688SDavid Daney	dmfc2	t2, 0x0249
1755b3b1688SDavid Daney	sd	t3, OCTEON_CP2_HSH_DATW+48(a0)
1765b3b1688SDavid Daney	dmfc2	t3, 0x024A
1775b3b1688SDavid Daney	sd	t0, OCTEON_CP2_HSH_DATW+56(a0)
1785b3b1688SDavid Daney	dmfc2	t0, 0x024B
1795b3b1688SDavid Daney	sd	t1, OCTEON_CP2_HSH_DATW+64(a0)
1805b3b1688SDavid Daney	dmfc2	t1, 0x024C
1815b3b1688SDavid Daney	sd	t2, OCTEON_CP2_HSH_DATW+72(a0)
1825b3b1688SDavid Daney	dmfc2	t2, 0x024D
1835b3b1688SDavid Daney	sd	t3, OCTEON_CP2_HSH_DATW+80(a0)
1845b3b1688SDavid Daney	dmfc2	t3, 0x024E
1855b3b1688SDavid Daney	sd	t0, OCTEON_CP2_HSH_DATW+88(a0)
1865b3b1688SDavid Daney	dmfc2	t0, 0x0250
1875b3b1688SDavid Daney	sd	t1, OCTEON_CP2_HSH_DATW+96(a0)
1885b3b1688SDavid Daney	dmfc2	t1, 0x0251
1895b3b1688SDavid Daney	sd	t2, OCTEON_CP2_HSH_DATW+104(a0)
1905b3b1688SDavid Daney	dmfc2	t2, 0x0252
1915b3b1688SDavid Daney	sd	t3, OCTEON_CP2_HSH_DATW+112(a0)
1925b3b1688SDavid Daney	dmfc2	t3, 0x0253
1935b3b1688SDavid Daney	sd	t0, OCTEON_CP2_HSH_IVW(a0)
1945b3b1688SDavid Daney	dmfc2	t0, 0x0254
1955b3b1688SDavid Daney	sd	t1, OCTEON_CP2_HSH_IVW+8(a0)
1965b3b1688SDavid Daney	dmfc2	t1, 0x0255
1975b3b1688SDavid Daney	sd	t2, OCTEON_CP2_HSH_IVW+16(a0)
1985b3b1688SDavid Daney	dmfc2	t2, 0x0256
1995b3b1688SDavid Daney	sd	t3, OCTEON_CP2_HSH_IVW+24(a0)
2005b3b1688SDavid Daney	dmfc2	t3, 0x0257
2015b3b1688SDavid Daney	sd	t0, OCTEON_CP2_HSH_IVW+32(a0)
2025b3b1688SDavid Daney	dmfc2	t0, 0x0258
2035b3b1688SDavid Daney	sd	t1, OCTEON_CP2_HSH_IVW+40(a0)
2045b3b1688SDavid Daney	dmfc2	t1, 0x0259
2055b3b1688SDavid Daney	sd	t2, OCTEON_CP2_HSH_IVW+48(a0)
2065b3b1688SDavid Daney	dmfc2	t2, 0x025E
2075b3b1688SDavid Daney	sd	t3, OCTEON_CP2_HSH_IVW+56(a0)
2085b3b1688SDavid Daney	dmfc2	t3, 0x025A
2095b3b1688SDavid Daney	sd	t0, OCTEON_CP2_GFM_MULT(a0)
2105b3b1688SDavid Daney	dmfc2	t0, 0x025B
2115b3b1688SDavid Daney	sd	t1, OCTEON_CP2_GFM_MULT+8(a0)
2125b3b1688SDavid Daney	sd	t2, OCTEON_CP2_GFM_POLY(a0)
2135b3b1688SDavid Daney	sd	t3, OCTEON_CP2_GFM_RESULT(a0)
2146b3a287eSDavid Daney	bltz	v1, 4f
2155b3b1688SDavid Daney	 sd	t0, OCTEON_CP2_GFM_RESULT+8(a0)
2166b3a287eSDavid Daney	/* OCTEON III things*/
2176b3a287eSDavid Daney	dmfc2	t0, 0x024F
2186b3a287eSDavid Daney	dmfc2	t1, 0x0050
2196b3a287eSDavid Daney	sd	t0, OCTEON_CP2_SHA3(a0)
2206b3a287eSDavid Daney	sd	t1, OCTEON_CP2_SHA3+8(a0)
2216b3a287eSDavid Daney4:
2225b3b1688SDavid Daney	jr	ra
2236b3a287eSDavid Daney	 nop
2245b3b1688SDavid Daney
2255b3b1688SDavid Daney2:	/* pass 1 special stuff when !CvmCtl[NOCRYPTO] */
2265b3b1688SDavid Daney	dmfc2	t3, 0x0040
2275b3b1688SDavid Daney	dmfc2	t0, 0x0041
2285b3b1688SDavid Daney	dmfc2	t1, 0x0042
2295b3b1688SDavid Daney	dmfc2	t2, 0x0043
2305b3b1688SDavid Daney	sd	t3, OCTEON_CP2_HSH_DATW(a0)
2315b3b1688SDavid Daney	dmfc2	t3, 0x0044
2325b3b1688SDavid Daney	sd	t0, OCTEON_CP2_HSH_DATW+8(a0)
2335b3b1688SDavid Daney	dmfc2	t0, 0x0045
2345b3b1688SDavid Daney	sd	t1, OCTEON_CP2_HSH_DATW+16(a0)
2355b3b1688SDavid Daney	dmfc2	t1, 0x0046
2365b3b1688SDavid Daney	sd	t2, OCTEON_CP2_HSH_DATW+24(a0)
2375b3b1688SDavid Daney	dmfc2	t2, 0x0048
2385b3b1688SDavid Daney	sd	t3, OCTEON_CP2_HSH_DATW+32(a0)
2395b3b1688SDavid Daney	dmfc2	t3, 0x0049
2405b3b1688SDavid Daney	sd	t0, OCTEON_CP2_HSH_DATW+40(a0)
2415b3b1688SDavid Daney	dmfc2	t0, 0x004A
2425b3b1688SDavid Daney	sd	t1, OCTEON_CP2_HSH_DATW+48(a0)
2435b3b1688SDavid Daney	sd	t2, OCTEON_CP2_HSH_IVW(a0)
2445b3b1688SDavid Daney	sd	t3, OCTEON_CP2_HSH_IVW+8(a0)
2455b3b1688SDavid Daney	sd	t0, OCTEON_CP2_HSH_IVW+16(a0)
2465b3b1688SDavid Daney
2475b3b1688SDavid Daney3:	/* pass 1 or CvmCtl[NOCRYPTO] set */
2485b3b1688SDavid Daney	jr	ra
2496b3a287eSDavid Daney	 nop
2505b3b1688SDavid Daney	END(octeon_cop2_save)
2516b3a287eSDavid Daney	.set pop
2525b3b1688SDavid Daney
2535b3b1688SDavid Daney/*
2545b3b1688SDavid Daney * void octeon_cop2_restore(struct octeon_cop2_state *a0)
2555b3b1688SDavid Daney */
2565b3b1688SDavid Daney	.align	7
2575b3b1688SDavid Daney	.set push
2585b3b1688SDavid Daney	.set noreorder
2595b3b1688SDavid Daney	LEAF(octeon_cop2_restore)
2605b3b1688SDavid Daney	/* First cache line was prefetched before the call */
2615b3b1688SDavid Daney	pref	4,  128(a0)
2625b3b1688SDavid Daney	dmfc0	t9, $9,7	/* CvmCtl register. */
2635b3b1688SDavid Daney
2645b3b1688SDavid Daney	pref	4,  256(a0)
2655b3b1688SDavid Daney	ld	t0, OCTEON_CP2_CRC_IV(a0)
2665b3b1688SDavid Daney	pref	4,  384(a0)
2675b3b1688SDavid Daney	ld	t1, OCTEON_CP2_CRC_LENGTH(a0)
2685b3b1688SDavid Daney	ld	t2, OCTEON_CP2_CRC_POLY(a0)
2695b3b1688SDavid Daney
2705b3b1688SDavid Daney	/* Restore the COP2 CRC state */
2715b3b1688SDavid Daney	dmtc2	t0, 0x0201
2725b3b1688SDavid Daney	dmtc2	t1, 0x1202
2735b3b1688SDavid Daney	bbit1	t9, 28, 2f	/* Skip LLM if CvmCtl[NODFA_CP2] is set */
2745b3b1688SDavid Daney	 dmtc2	t2, 0x4200
2755b3b1688SDavid Daney
2765b3b1688SDavid Daney	/* Restore the LLM state */
2775b3b1688SDavid Daney	ld	t0, OCTEON_CP2_LLM_DAT(a0)
2785b3b1688SDavid Daney	ld	t1, OCTEON_CP2_LLM_DAT+8(a0)
2795b3b1688SDavid Daney	dmtc2	t0, 0x0402
2805b3b1688SDavid Daney	dmtc2	t1, 0x040A
2815b3b1688SDavid Daney
2825b3b1688SDavid Daney2:
2835b3b1688SDavid Daney	bbit1	t9, 26, done_restore	/* done if CvmCtl[NOCRYPTO] set */
2845b3b1688SDavid Daney	 nop
2855b3b1688SDavid Daney
2865b3b1688SDavid Daney	/* Restore the COP2 crypto state common to pass 1 and pass 2 */
2875b3b1688SDavid Daney	ld	t0, OCTEON_CP2_3DES_IV(a0)
2885b3b1688SDavid Daney	ld	t1, OCTEON_CP2_3DES_KEY(a0)
2895b3b1688SDavid Daney	ld	t2, OCTEON_CP2_3DES_KEY+8(a0)
2905b3b1688SDavid Daney	dmtc2	t0, 0x0084
2915b3b1688SDavid Daney	ld	t0, OCTEON_CP2_3DES_KEY+16(a0)
2925b3b1688SDavid Daney	dmtc2	t1, 0x0080
2935b3b1688SDavid Daney	ld	t1, OCTEON_CP2_3DES_RESULT(a0)
2945b3b1688SDavid Daney	dmtc2	t2, 0x0081
2955b3b1688SDavid Daney	ld	t2, OCTEON_CP2_AES_INP0(a0) /* only really needed for pass 1 */
2965b3b1688SDavid Daney	dmtc2	t0, 0x0082
2975b3b1688SDavid Daney	ld	t0, OCTEON_CP2_AES_IV(a0)
2985b3b1688SDavid Daney	dmtc2	t1, 0x0098
2995b3b1688SDavid Daney	ld	t1, OCTEON_CP2_AES_IV+8(a0)
3005b3b1688SDavid Daney	dmtc2	t2, 0x010A		    /* only really needed for pass 1 */
3015b3b1688SDavid Daney	ld	t2, OCTEON_CP2_AES_KEY(a0)
3025b3b1688SDavid Daney	dmtc2	t0, 0x0102
3035b3b1688SDavid Daney	ld	t0, OCTEON_CP2_AES_KEY+8(a0)
3045b3b1688SDavid Daney	dmtc2	t1, 0x0103
3055b3b1688SDavid Daney	ld	t1, OCTEON_CP2_AES_KEY+16(a0)
3065b3b1688SDavid Daney	dmtc2	t2, 0x0104
3075b3b1688SDavid Daney	ld	t2, OCTEON_CP2_AES_KEY+24(a0)
3085b3b1688SDavid Daney	dmtc2	t0, 0x0105
3095b3b1688SDavid Daney	ld	t0, OCTEON_CP2_AES_KEYLEN(a0)
3105b3b1688SDavid Daney	dmtc2	t1, 0x0106
3115b3b1688SDavid Daney	ld	t1, OCTEON_CP2_AES_RESULT(a0)
3125b3b1688SDavid Daney	dmtc2	t2, 0x0107
3135b3b1688SDavid Daney	ld	t2, OCTEON_CP2_AES_RESULT+8(a0)
3145b3b1688SDavid Daney	mfc0	t3, $15,0	/* Get the processor ID register */
3155b3b1688SDavid Daney	dmtc2	t0, 0x0110
3166b3a287eSDavid Daney	li	v0, 0x000d0000	/* This is the processor ID of Octeon Pass1 */
3175b3b1688SDavid Daney	dmtc2	t1, 0x0100
3186b3a287eSDavid Daney	bne	v0, t3, 3f	/* Skip the next stuff for non-pass1 */
3195b3b1688SDavid Daney	 dmtc2	t2, 0x0101
3205b3b1688SDavid Daney
3215b3b1688SDavid Daney	/* this code is specific for pass 1 */
3225b3b1688SDavid Daney	ld	t0, OCTEON_CP2_HSH_DATW(a0)
3235b3b1688SDavid Daney	ld	t1, OCTEON_CP2_HSH_DATW+8(a0)
3245b3b1688SDavid Daney	ld	t2, OCTEON_CP2_HSH_DATW+16(a0)
3255b3b1688SDavid Daney	dmtc2	t0, 0x0040
3265b3b1688SDavid Daney	ld	t0, OCTEON_CP2_HSH_DATW+24(a0)
3275b3b1688SDavid Daney	dmtc2	t1, 0x0041
3285b3b1688SDavid Daney	ld	t1, OCTEON_CP2_HSH_DATW+32(a0)
3295b3b1688SDavid Daney	dmtc2	t2, 0x0042
3305b3b1688SDavid Daney	ld	t2, OCTEON_CP2_HSH_DATW+40(a0)
3315b3b1688SDavid Daney	dmtc2	t0, 0x0043
3325b3b1688SDavid Daney	ld	t0, OCTEON_CP2_HSH_DATW+48(a0)
3335b3b1688SDavid Daney	dmtc2	t1, 0x0044
3345b3b1688SDavid Daney	ld	t1, OCTEON_CP2_HSH_IVW(a0)
3355b3b1688SDavid Daney	dmtc2	t2, 0x0045
3365b3b1688SDavid Daney	ld	t2, OCTEON_CP2_HSH_IVW+8(a0)
3375b3b1688SDavid Daney	dmtc2	t0, 0x0046
3385b3b1688SDavid Daney	ld	t0, OCTEON_CP2_HSH_IVW+16(a0)
3395b3b1688SDavid Daney	dmtc2	t1, 0x0048
3405b3b1688SDavid Daney	dmtc2	t2, 0x0049
3415b3b1688SDavid Daney	b done_restore	 /* unconditional branch */
3425b3b1688SDavid Daney	 dmtc2	t0, 0x004A
3435b3b1688SDavid Daney
3445b3b1688SDavid Daney3:	/* this is post-pass1 code */
3455b3b1688SDavid Daney	ld	t2, OCTEON_CP2_HSH_DATW(a0)
3466b3a287eSDavid Daney	ori	v0, v0, 0x9500 /* lowest OCTEON III PrId*/
3475b3b1688SDavid Daney	ld	t0, OCTEON_CP2_HSH_DATW+8(a0)
3485b3b1688SDavid Daney	ld	t1, OCTEON_CP2_HSH_DATW+16(a0)
3495b3b1688SDavid Daney	dmtc2	t2, 0x0240
3505b3b1688SDavid Daney	ld	t2, OCTEON_CP2_HSH_DATW+24(a0)
3515b3b1688SDavid Daney	dmtc2	t0, 0x0241
3525b3b1688SDavid Daney	ld	t0, OCTEON_CP2_HSH_DATW+32(a0)
3535b3b1688SDavid Daney	dmtc2	t1, 0x0242
3545b3b1688SDavid Daney	ld	t1, OCTEON_CP2_HSH_DATW+40(a0)
3555b3b1688SDavid Daney	dmtc2	t2, 0x0243
3565b3b1688SDavid Daney	ld	t2, OCTEON_CP2_HSH_DATW+48(a0)
3575b3b1688SDavid Daney	dmtc2	t0, 0x0244
3585b3b1688SDavid Daney	ld	t0, OCTEON_CP2_HSH_DATW+56(a0)
3595b3b1688SDavid Daney	dmtc2	t1, 0x0245
3605b3b1688SDavid Daney	ld	t1, OCTEON_CP2_HSH_DATW+64(a0)
3615b3b1688SDavid Daney	dmtc2	t2, 0x0246
3625b3b1688SDavid Daney	ld	t2, OCTEON_CP2_HSH_DATW+72(a0)
3635b3b1688SDavid Daney	dmtc2	t0, 0x0247
3645b3b1688SDavid Daney	ld	t0, OCTEON_CP2_HSH_DATW+80(a0)
3655b3b1688SDavid Daney	dmtc2	t1, 0x0248
3665b3b1688SDavid Daney	ld	t1, OCTEON_CP2_HSH_DATW+88(a0)
3675b3b1688SDavid Daney	dmtc2	t2, 0x0249
3685b3b1688SDavid Daney	ld	t2, OCTEON_CP2_HSH_DATW+96(a0)
3695b3b1688SDavid Daney	dmtc2	t0, 0x024A
3705b3b1688SDavid Daney	ld	t0, OCTEON_CP2_HSH_DATW+104(a0)
3715b3b1688SDavid Daney	dmtc2	t1, 0x024B
3725b3b1688SDavid Daney	ld	t1, OCTEON_CP2_HSH_DATW+112(a0)
3735b3b1688SDavid Daney	dmtc2	t2, 0x024C
3745b3b1688SDavid Daney	ld	t2, OCTEON_CP2_HSH_IVW(a0)
3755b3b1688SDavid Daney	dmtc2	t0, 0x024D
3765b3b1688SDavid Daney	ld	t0, OCTEON_CP2_HSH_IVW+8(a0)
3775b3b1688SDavid Daney	dmtc2	t1, 0x024E
3785b3b1688SDavid Daney	ld	t1, OCTEON_CP2_HSH_IVW+16(a0)
3795b3b1688SDavid Daney	dmtc2	t2, 0x0250
3805b3b1688SDavid Daney	ld	t2, OCTEON_CP2_HSH_IVW+24(a0)
3815b3b1688SDavid Daney	dmtc2	t0, 0x0251
3825b3b1688SDavid Daney	ld	t0, OCTEON_CP2_HSH_IVW+32(a0)
3835b3b1688SDavid Daney	dmtc2	t1, 0x0252
3845b3b1688SDavid Daney	ld	t1, OCTEON_CP2_HSH_IVW+40(a0)
3855b3b1688SDavid Daney	dmtc2	t2, 0x0253
3865b3b1688SDavid Daney	ld	t2, OCTEON_CP2_HSH_IVW+48(a0)
3875b3b1688SDavid Daney	dmtc2	t0, 0x0254
3885b3b1688SDavid Daney	ld	t0, OCTEON_CP2_HSH_IVW+56(a0)
3895b3b1688SDavid Daney	dmtc2	t1, 0x0255
3905b3b1688SDavid Daney	ld	t1, OCTEON_CP2_GFM_MULT(a0)
3915b3b1688SDavid Daney	dmtc2	t2, 0x0256
3925b3b1688SDavid Daney	ld	t2, OCTEON_CP2_GFM_MULT+8(a0)
3935b3b1688SDavid Daney	dmtc2	t0, 0x0257
3945b3b1688SDavid Daney	ld	t0, OCTEON_CP2_GFM_POLY(a0)
3955b3b1688SDavid Daney	dmtc2	t1, 0x0258
3965b3b1688SDavid Daney	ld	t1, OCTEON_CP2_GFM_RESULT(a0)
3975b3b1688SDavid Daney	dmtc2	t2, 0x0259
3985b3b1688SDavid Daney	ld	t2, OCTEON_CP2_GFM_RESULT+8(a0)
3995b3b1688SDavid Daney	dmtc2	t0, 0x025E
4006b3a287eSDavid Daney	subu	v0, t3, v0 /* prid - lowest OCTEON III PrId */
4015b3b1688SDavid Daney	dmtc2	t1, 0x025A
4026b3a287eSDavid Daney	bltz	v0, done_restore
4035b3b1688SDavid Daney	 dmtc2	t2, 0x025B
4046b3a287eSDavid Daney	/* OCTEON III things*/
4056b3a287eSDavid Daney	ld	t0, OCTEON_CP2_SHA3(a0)
4066b3a287eSDavid Daney	ld	t1, OCTEON_CP2_SHA3+8(a0)
4076b3a287eSDavid Daney	dmtc2	t0, 0x0051
4086b3a287eSDavid Daney	dmtc2	t1, 0x0050
4095b3b1688SDavid Daneydone_restore:
4105b3b1688SDavid Daney	jr	ra
4115b3b1688SDavid Daney	 nop
4125b3b1688SDavid Daney	END(octeon_cop2_restore)
4135b3b1688SDavid Daney	.set pop
4145b3b1688SDavid Daney
4155b3b1688SDavid Daney/*
4165b3b1688SDavid Daney * void octeon_mult_save()
4175b3b1688SDavid Daney * sp is assumed to point to a struct pt_regs
4185b3b1688SDavid Daney *
419ac655fb7SDavid Daney * NOTE: This is called in SAVE_TEMP in stackframe.h. It can
420ac655fb7SDavid Daney *       safely modify v1,k0, k1,$10-$15, and $24.  It will
421ac655fb7SDavid Daney *	 be overwritten with a processor specific version of the code.
4225b3b1688SDavid Daney */
423ac655fb7SDavid Daney	.p2align 7
4245b3b1688SDavid Daney	.set push
4255b3b1688SDavid Daney	.set noreorder
4265b3b1688SDavid Daney	LEAF(octeon_mult_save)
427ac655fb7SDavid Daney	jr	ra
4285b3b1688SDavid Daney	 nop
429ac655fb7SDavid Daney	.space 30 * 4, 0
430ac655fb7SDavid Daney	EXPORT(octeon_mult_save_end)
431ac655fb7SDavid Daney	END(octeon_mult_save)
4325b3b1688SDavid Daney
433ac655fb7SDavid Daney	LEAF(octeon_mult_save2)
434ac655fb7SDavid Daney	/* Save the multiplier state OCTEON II and earlier*/
4355b3b1688SDavid Daney	v3mulu	k0, $0, $0
4365b3b1688SDavid Daney	v3mulu	k1, $0, $0
4375b3b1688SDavid Daney	sd	k0, PT_MTP(sp)	      /* PT_MTP	   has P0 */
4385b3b1688SDavid Daney	v3mulu	k0, $0, $0
4395b3b1688SDavid Daney	sd	k1, PT_MTP+8(sp)      /* PT_MTP+8  has P1 */
4405b3b1688SDavid Daney	ori	k1, $0, 1
4415b3b1688SDavid Daney	v3mulu	k1, k1, $0
4425b3b1688SDavid Daney	sd	k0, PT_MTP+16(sp)     /* PT_MTP+16 has P2 */
4435b3b1688SDavid Daney	v3mulu	k0, $0, $0
4445b3b1688SDavid Daney	sd	k1, PT_MPL(sp)	      /* PT_MPL	   has MPL0 */
4455b3b1688SDavid Daney	v3mulu	k1, $0, $0
4465b3b1688SDavid Daney	sd	k0, PT_MPL+8(sp)      /* PT_MPL+8  has MPL1 */
4475b3b1688SDavid Daney	jr	ra
4485b3b1688SDavid Daney	 sd	k1, PT_MPL+16(sp)     /* PT_MPL+16 has MPL2 */
449ac655fb7SDavid Daney	EXPORT(octeon_mult_save2_end)
450ac655fb7SDavid Daney	END(octeon_mult_save2)
4515b3b1688SDavid Daney
452ac655fb7SDavid Daney	LEAF(octeon_mult_save3)
453ac655fb7SDavid Daney	/* Save the multiplier state OCTEON III */
454ac655fb7SDavid Daney	v3mulu	$10, $0, $0		/* read P0 */
455ac655fb7SDavid Daney	v3mulu	$11, $0, $0		/* read P1 */
456ac655fb7SDavid Daney	v3mulu	$12, $0, $0		/* read P2 */
457ac655fb7SDavid Daney	sd	$10, PT_MTP+(0*8)(sp)	/* store P0 */
458ac655fb7SDavid Daney	v3mulu	$10, $0, $0		/* read P3 */
459ac655fb7SDavid Daney	sd	$11, PT_MTP+(1*8)(sp)	/*  store P1 */
460ac655fb7SDavid Daney	v3mulu	$11, $0, $0		/* read P4 */
461ac655fb7SDavid Daney	sd	$12, PT_MTP+(2*8)(sp)	/* store P2 */
462ac655fb7SDavid Daney	ori	$13, $0, 1
463ac655fb7SDavid Daney	v3mulu	$12, $0, $0		/* read P5 */
464ac655fb7SDavid Daney	sd	$10, PT_MTP+(3*8)(sp)	/* store P3 */
465ac655fb7SDavid Daney	v3mulu	$13, $13, $0		/* P4-P0 = MPL5-MPL1, $13 = MPL0 */
466ac655fb7SDavid Daney	sd	$11, PT_MTP+(4*8)(sp)	/* store P4 */
467ac655fb7SDavid Daney	v3mulu	$10, $0, $0		/* read MPL1 */
468ac655fb7SDavid Daney	sd	$12, PT_MTP+(5*8)(sp)	/* store P5 */
469ac655fb7SDavid Daney	v3mulu	$11, $0, $0		/* read MPL2 */
470ac655fb7SDavid Daney	sd	$13, PT_MPL+(0*8)(sp)	/* store MPL0 */
471ac655fb7SDavid Daney	v3mulu	$12, $0, $0		/* read MPL3 */
472ac655fb7SDavid Daney	sd	$10, PT_MPL+(1*8)(sp)	/* store MPL1 */
473ac655fb7SDavid Daney	v3mulu	$10, $0, $0		/* read MPL4 */
474ac655fb7SDavid Daney	sd	$11, PT_MPL+(2*8)(sp)	/* store MPL2 */
475ac655fb7SDavid Daney	v3mulu	$11, $0, $0		/* read MPL5 */
476ac655fb7SDavid Daney	sd	$12, PT_MPL+(3*8)(sp)	/* store MPL3 */
477ac655fb7SDavid Daney	sd	$10, PT_MPL+(4*8)(sp)	/* store MPL4 */
4785b3b1688SDavid Daney	jr	ra
479ac655fb7SDavid Daney	 sd	$11, PT_MPL+(5*8)(sp)	/* store MPL5 */
480ac655fb7SDavid Daney	EXPORT(octeon_mult_save3_end)
481ac655fb7SDavid Daney	END(octeon_mult_save3)
4825b3b1688SDavid Daney	.set pop
4835b3b1688SDavid Daney
4845b3b1688SDavid Daney/*
4855b3b1688SDavid Daney * void octeon_mult_restore()
4865b3b1688SDavid Daney * sp is assumed to point to a struct pt_regs
4875b3b1688SDavid Daney *
488ac655fb7SDavid Daney * NOTE: This is called in RESTORE_TEMP in stackframe.h.
4895b3b1688SDavid Daney */
490ac655fb7SDavid Daney	.p2align 7
4915b3b1688SDavid Daney	.set push
4925b3b1688SDavid Daney	.set noreorder
4935b3b1688SDavid Daney	LEAF(octeon_mult_restore)
494ac655fb7SDavid Daney	jr	ra
495ac655fb7SDavid Daney	 nop
496ac655fb7SDavid Daney	.space 30 * 4, 0
497ac655fb7SDavid Daney	EXPORT(octeon_mult_restore_end)
498ac655fb7SDavid Daney	END(octeon_mult_restore)
499ac655fb7SDavid Daney
500ac655fb7SDavid Daney	LEAF(octeon_mult_restore2)
5015b3b1688SDavid Daney	ld	v0, PT_MPL(sp)        	/* MPL0 */
5025b3b1688SDavid Daney	ld	v1, PT_MPL+8(sp)      	/* MPL1 */
5035b3b1688SDavid Daney	ld	k0, PT_MPL+16(sp)     	/* MPL2 */
5045b3b1688SDavid Daney	/* Restore the multiplier state */
5055b3b1688SDavid Daney	ld	k1, PT_MTP+16(sp)     	/* P2 */
506ac655fb7SDavid Daney	mtm0	v0			/* MPL0 */
5075b3b1688SDavid Daney	ld	v0, PT_MTP+8(sp)	/* P1 */
508ac655fb7SDavid Daney	mtm1	v1			/* MPL1 */
5095b3b1688SDavid Daney	ld	v1, PT_MTP(sp)   	/* P0 */
510ac655fb7SDavid Daney	mtm2	k0			/* MPL2 */
511ac655fb7SDavid Daney	mtp2	k1			/* P2 */
512ac655fb7SDavid Daney	mtp1	v0			/* P1 */
5135b3b1688SDavid Daney	jr	ra
514ac655fb7SDavid Daney	 mtp0	v1			/* P0 */
515ac655fb7SDavid Daney	EXPORT(octeon_mult_restore2_end)
516ac655fb7SDavid Daney	END(octeon_mult_restore2)
5175b3b1688SDavid Daney
518ac655fb7SDavid Daney	LEAF(octeon_mult_restore3)
519ac655fb7SDavid Daney	ld	$12, PT_MPL+(0*8)(sp)	/* read MPL0 */
520ac655fb7SDavid Daney	ld	$13, PT_MPL+(3*8)(sp)	/* read MPL3 */
521ac655fb7SDavid Daney	ld	$10, PT_MPL+(1*8)(sp)	/* read MPL1 */
522ac655fb7SDavid Daney	ld	$11, PT_MPL+(4*8)(sp)	/* read MPL4 */
523ac655fb7SDavid Daney	.word	0x718d0008
524ac655fb7SDavid Daney	/* mtm0	$12, $13		   restore MPL0 and MPL3 */
525ac655fb7SDavid Daney	ld	$12, PT_MPL+(2*8)(sp)	/* read MPL2 */
526ac655fb7SDavid Daney	.word	0x714b000c
527ac655fb7SDavid Daney	/* mtm1	$10, $11		   restore MPL1 and MPL4 */
528ac655fb7SDavid Daney	ld	$13, PT_MPL+(5*8)(sp)	/* read MPL5 */
529ac655fb7SDavid Daney	ld	$10, PT_MTP+(0*8)(sp)	/* read P0 */
530ac655fb7SDavid Daney	ld	$11, PT_MTP+(3*8)(sp)	/* read P3 */
531ac655fb7SDavid Daney	.word	0x718d000d
532ac655fb7SDavid Daney	/* mtm2	$12, $13		   restore MPL2 and MPL5 */
533ac655fb7SDavid Daney	ld	$12, PT_MTP+(1*8)(sp)	/* read P1 */
534ac655fb7SDavid Daney	.word	0x714b0009
535ac655fb7SDavid Daney	/* mtp0	$10, $11		   restore P0 and P3 */
536ac655fb7SDavid Daney	ld	$13, PT_MTP+(4*8)(sp)	/* read P4 */
537ac655fb7SDavid Daney	ld	$10, PT_MTP+(2*8)(sp)	/* read P2 */
538ac655fb7SDavid Daney	ld	$11, PT_MTP+(5*8)(sp)	/* read P5 */
539ac655fb7SDavid Daney	.word	0x718d000a
540ac655fb7SDavid Daney	/* mtp1	$12, $13		   restore P1 and P4 */
5415b3b1688SDavid Daney	jr	ra
542ac655fb7SDavid Daney	.word	0x714b000b
543ac655fb7SDavid Daney	/* mtp2	$10, $11		   restore P2 and P5 */
544ac655fb7SDavid Daney
545ac655fb7SDavid Daney	EXPORT(octeon_mult_restore3_end)
546ac655fb7SDavid Daney	END(octeon_mult_restore3)
5475b3b1688SDavid Daney	.set pop
548