1229677Sgonzo/*-
2229677Sgonzo * Copyright (c) 2011 Oleksandr Tymoshenko
3229677Sgonzo * All rights reserved.
4229677Sgonzo *
5229677Sgonzo * Redistribution and use in source and binary forms, with or without
6229677Sgonzo * modification, are permitted provided that the following conditions
7229677Sgonzo * are met:
8229677Sgonzo * 1. Redistributions of source code must retain the above copyright
9229677Sgonzo *    notice, this list of conditions and the following disclaimer.
10229677Sgonzo * 2. Redistributions in binary form must reproduce the above copyright
11229677Sgonzo *    notice, this list of conditions and the following disclaimer in the
12229677Sgonzo *    documentation and/or other materials provided with the distribution.
13229677Sgonzo *
14229677Sgonzo * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15229677Sgonzo * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16229677Sgonzo * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17229677Sgonzo * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18229677Sgonzo * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19229677Sgonzo * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20229677Sgonzo * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21229677Sgonzo * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22229677Sgonzo * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23229677Sgonzo * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24229677Sgonzo * SUCH DAMAGE.
25229677Sgonzo *
26229677Sgonzo * $FreeBSD: releng/11.0/sys/mips/cavium/octeon_cop2.S 229677 2012-01-06 01:23:26Z gonzo $
27229677Sgonzo */
28229677Sgonzo
29229677Sgonzo#include <machine/asm.h>
30229677Sgonzo#include <mips/cavium/octeon_cop2.h>
31229677Sgonzo
32229677Sgonzo#include "assym.s"
33229677Sgonzo
34229677Sgonzo.set noreorder
35229677Sgonzo
36229677Sgonzo#define SAVE_COP2_REGISTER(reg)				\
37229677Sgonzo	dmfc2	t1, reg; sd	t1, reg##_OFFSET(a0)
38229677Sgonzo
39229677Sgonzo
40229677Sgonzo#define RESTORE_COP2_REGISTER(reg)			\
41229677Sgonzo	ld	t1, reg##_OFFSET(a0); dmtc2	t1, reg##_SET
42229677Sgonzo
43229677SgonzoLEAF(octeon_cop2_save)
44229677Sgonzo	/* Get CvmCtl register */
45229677Sgonzo	dmfc0	t0, $9, 7
46229677Sgonzo
47229677Sgonzo	/* CRC state */
48229677Sgonzo	SAVE_COP2_REGISTER(COP2_CRC_IV)
49229677Sgonzo	SAVE_COP2_REGISTER(COP2_CRC_LENGTH)
50229677Sgonzo	SAVE_COP2_REGISTER(COP2_CRC_POLY)
51229677Sgonzo
52229677Sgonzo	/* if CvmCtl[NODFA_CP2] -> save_nodfa */
53229677Sgonzo	bbit1	t0, 28, save_nodfa
54229677Sgonzo	nop
55229677Sgonzo
56229677Sgonzo	/* LLM state */
57229677Sgonzo	SAVE_COP2_REGISTER(COP2_LLM_DAT0)
58229677Sgonzo	SAVE_COP2_REGISTER(COP2_LLM_DAT1)
59229677Sgonzo
60229677Sgonzosave_nodfa:
61229677Sgonzo	/* crypto stuff is irrelevant if CvmCtl[NOCRYPTO]  */
62229677Sgonzo	bbit1	t0, 26, save_done
63229677Sgonzo	nop
64229677Sgonzo
65229677Sgonzo	SAVE_COP2_REGISTER(COP2_3DES_IV)
66229677Sgonzo	SAVE_COP2_REGISTER(COP2_3DES_KEY0)
67229677Sgonzo	SAVE_COP2_REGISTER(COP2_3DES_KEY1)
68229677Sgonzo	SAVE_COP2_REGISTER(COP2_3DES_KEY2)
69229677Sgonzo	SAVE_COP2_REGISTER(COP2_3DES_RESULT)
70229677Sgonzo
71229677Sgonzo	SAVE_COP2_REGISTER(COP2_AES_INP0)
72229677Sgonzo	SAVE_COP2_REGISTER(COP2_AES_IV0)
73229677Sgonzo	SAVE_COP2_REGISTER(COP2_AES_IV1)
74229677Sgonzo	SAVE_COP2_REGISTER(COP2_AES_KEY0)
75229677Sgonzo	SAVE_COP2_REGISTER(COP2_AES_KEY1)
76229677Sgonzo	SAVE_COP2_REGISTER(COP2_AES_KEY2)
77229677Sgonzo	SAVE_COP2_REGISTER(COP2_AES_KEY3)
78229677Sgonzo	SAVE_COP2_REGISTER(COP2_AES_KEYLEN)
79229677Sgonzo	SAVE_COP2_REGISTER(COP2_AES_RESULT0)
80229677Sgonzo	SAVE_COP2_REGISTER(COP2_AES_RESULT1)
81229677Sgonzo
82229677Sgonzo	dmfc0	t0, $15
83229677Sgonzo	li	t1, 0x000d0000 /* Octeon Pass1 */
84229677Sgonzo	beq	t0, t1, save_pass1
85229677Sgonzo	nop
86229677Sgonzo
87229677Sgonzo	SAVE_COP2_REGISTER(COP2_HSH_DATW0)
88229677Sgonzo	SAVE_COP2_REGISTER(COP2_HSH_DATW1)
89229677Sgonzo	SAVE_COP2_REGISTER(COP2_HSH_DATW2)
90229677Sgonzo	SAVE_COP2_REGISTER(COP2_HSH_DATW3)
91229677Sgonzo	SAVE_COP2_REGISTER(COP2_HSH_DATW4)
92229677Sgonzo	SAVE_COP2_REGISTER(COP2_HSH_DATW5)
93229677Sgonzo	SAVE_COP2_REGISTER(COP2_HSH_DATW6)
94229677Sgonzo	SAVE_COP2_REGISTER(COP2_HSH_DATW7)
95229677Sgonzo	SAVE_COP2_REGISTER(COP2_HSH_DATW8)
96229677Sgonzo	SAVE_COP2_REGISTER(COP2_HSH_DATW9)
97229677Sgonzo	SAVE_COP2_REGISTER(COP2_HSH_DATW10)
98229677Sgonzo	SAVE_COP2_REGISTER(COP2_HSH_DATW11)
99229677Sgonzo	SAVE_COP2_REGISTER(COP2_HSH_DATW12)
100229677Sgonzo	SAVE_COP2_REGISTER(COP2_HSH_DATW13)
101229677Sgonzo	SAVE_COP2_REGISTER(COP2_HSH_DATW14)
102229677Sgonzo	SAVE_COP2_REGISTER(COP2_HSH_IVW0)
103229677Sgonzo	SAVE_COP2_REGISTER(COP2_HSH_IVW1)
104229677Sgonzo	SAVE_COP2_REGISTER(COP2_HSH_IVW2)
105229677Sgonzo	SAVE_COP2_REGISTER(COP2_HSH_IVW3)
106229677Sgonzo	SAVE_COP2_REGISTER(COP2_HSH_IVW4)
107229677Sgonzo	SAVE_COP2_REGISTER(COP2_HSH_IVW5)
108229677Sgonzo	SAVE_COP2_REGISTER(COP2_HSH_IVW6)
109229677Sgonzo	SAVE_COP2_REGISTER(COP2_HSH_IVW7)
110229677Sgonzo	SAVE_COP2_REGISTER(COP2_GFM_MULT0)
111229677Sgonzo	SAVE_COP2_REGISTER(COP2_GFM_MULT1)
112229677Sgonzo	SAVE_COP2_REGISTER(COP2_GFM_POLY)
113229677Sgonzo	SAVE_COP2_REGISTER(COP2_GFM_RESULT0)
114229677Sgonzo	SAVE_COP2_REGISTER(COP2_GFM_RESULT1)
115229677Sgonzo	jr ra
116229677Sgonzo	nop
117229677Sgonzo
118229677Sgonzosave_pass1:
119229677Sgonzo	SAVE_COP2_REGISTER(COP2_HSH_DATW0_PASS1)
120229677Sgonzo	SAVE_COP2_REGISTER(COP2_HSH_DATW1_PASS1)
121229677Sgonzo	SAVE_COP2_REGISTER(COP2_HSH_DATW2_PASS1)
122229677Sgonzo	SAVE_COP2_REGISTER(COP2_HSH_DATW3_PASS1)
123229677Sgonzo	SAVE_COP2_REGISTER(COP2_HSH_DATW4_PASS1)
124229677Sgonzo	SAVE_COP2_REGISTER(COP2_HSH_DATW5_PASS1)
125229677Sgonzo	SAVE_COP2_REGISTER(COP2_HSH_DATW6_PASS1)
126229677Sgonzo	SAVE_COP2_REGISTER(COP2_HSH_IVW0_PASS1)
127229677Sgonzo	SAVE_COP2_REGISTER(COP2_HSH_IVW1_PASS1)
128229677Sgonzo	SAVE_COP2_REGISTER(COP2_HSH_IVW2_PASS1)
129229677Sgonzo
130229677Sgonzosave_done:
131229677Sgonzo	jr ra
132229677Sgonzo	nop
133229677SgonzoEND(octeon_cop2_save)
134229677Sgonzo
135229677SgonzoLEAF(octeon_cop2_restore)
136229677Sgonzo	/* Get CvmCtl register */
137229677Sgonzo	dmfc0	t0, $9, 7
138229677Sgonzo
139229677Sgonzo	/* CRC state */
140229677Sgonzo	RESTORE_COP2_REGISTER(COP2_CRC_IV)
141229677Sgonzo	RESTORE_COP2_REGISTER(COP2_CRC_LENGTH)
142229677Sgonzo	RESTORE_COP2_REGISTER(COP2_CRC_POLY)
143229677Sgonzo
144229677Sgonzo	/* if CvmCtl[NODFA_CP2] -> save_nodfa */
145229677Sgonzo	bbit1	t0, 28, restore_nodfa
146229677Sgonzo	nop
147229677Sgonzo
148229677Sgonzo	/* LLM state */
149229677Sgonzo	RESTORE_COP2_REGISTER(COP2_LLM_DAT0)
150229677Sgonzo	RESTORE_COP2_REGISTER(COP2_LLM_DAT1)
151229677Sgonzo
152229677Sgonzorestore_nodfa:
153229677Sgonzo	/* crypto stuff is irrelevant if CvmCtl[NOCRYPTO]  */
154229677Sgonzo	bbit1	t0, 26, restore_done
155229677Sgonzo	nop
156229677Sgonzo
157229677Sgonzo	RESTORE_COP2_REGISTER(COP2_3DES_IV)
158229677Sgonzo	RESTORE_COP2_REGISTER(COP2_3DES_KEY0)
159229677Sgonzo	RESTORE_COP2_REGISTER(COP2_3DES_KEY1)
160229677Sgonzo	RESTORE_COP2_REGISTER(COP2_3DES_KEY2)
161229677Sgonzo	RESTORE_COP2_REGISTER(COP2_3DES_RESULT)
162229677Sgonzo
163229677Sgonzo	RESTORE_COP2_REGISTER(COP2_AES_INP0)
164229677Sgonzo	RESTORE_COP2_REGISTER(COP2_AES_IV0)
165229677Sgonzo	RESTORE_COP2_REGISTER(COP2_AES_IV1)
166229677Sgonzo	RESTORE_COP2_REGISTER(COP2_AES_KEY0)
167229677Sgonzo	RESTORE_COP2_REGISTER(COP2_AES_KEY1)
168229677Sgonzo	RESTORE_COP2_REGISTER(COP2_AES_KEY2)
169229677Sgonzo	RESTORE_COP2_REGISTER(COP2_AES_KEY3)
170229677Sgonzo	RESTORE_COP2_REGISTER(COP2_AES_KEYLEN)
171229677Sgonzo	RESTORE_COP2_REGISTER(COP2_AES_RESULT0)
172229677Sgonzo	RESTORE_COP2_REGISTER(COP2_AES_RESULT1)
173229677Sgonzo
174229677Sgonzo	dmfc0	t0, $15
175229677Sgonzo	li	t1, 0x000d0000 /* Octeon Pass1 */
176229677Sgonzo	beq	t0, t1, restore_pass1
177229677Sgonzo	nop
178229677Sgonzo
179229677Sgonzo	RESTORE_COP2_REGISTER(COP2_HSH_DATW0)
180229677Sgonzo	RESTORE_COP2_REGISTER(COP2_HSH_DATW1)
181229677Sgonzo	RESTORE_COP2_REGISTER(COP2_HSH_DATW2)
182229677Sgonzo	RESTORE_COP2_REGISTER(COP2_HSH_DATW3)
183229677Sgonzo	RESTORE_COP2_REGISTER(COP2_HSH_DATW4)
184229677Sgonzo	RESTORE_COP2_REGISTER(COP2_HSH_DATW5)
185229677Sgonzo	RESTORE_COP2_REGISTER(COP2_HSH_DATW6)
186229677Sgonzo	RESTORE_COP2_REGISTER(COP2_HSH_DATW7)
187229677Sgonzo	RESTORE_COP2_REGISTER(COP2_HSH_DATW8)
188229677Sgonzo	RESTORE_COP2_REGISTER(COP2_HSH_DATW9)
189229677Sgonzo	RESTORE_COP2_REGISTER(COP2_HSH_DATW10)
190229677Sgonzo	RESTORE_COP2_REGISTER(COP2_HSH_DATW11)
191229677Sgonzo	RESTORE_COP2_REGISTER(COP2_HSH_DATW12)
192229677Sgonzo	RESTORE_COP2_REGISTER(COP2_HSH_DATW13)
193229677Sgonzo	RESTORE_COP2_REGISTER(COP2_HSH_DATW14)
194229677Sgonzo	RESTORE_COP2_REGISTER(COP2_HSH_IVW0)
195229677Sgonzo	RESTORE_COP2_REGISTER(COP2_HSH_IVW1)
196229677Sgonzo	RESTORE_COP2_REGISTER(COP2_HSH_IVW2)
197229677Sgonzo	RESTORE_COP2_REGISTER(COP2_HSH_IVW3)
198229677Sgonzo	RESTORE_COP2_REGISTER(COP2_HSH_IVW4)
199229677Sgonzo	RESTORE_COP2_REGISTER(COP2_HSH_IVW5)
200229677Sgonzo	RESTORE_COP2_REGISTER(COP2_HSH_IVW6)
201229677Sgonzo	RESTORE_COP2_REGISTER(COP2_HSH_IVW7)
202229677Sgonzo	RESTORE_COP2_REGISTER(COP2_GFM_MULT0)
203229677Sgonzo	RESTORE_COP2_REGISTER(COP2_GFM_MULT1)
204229677Sgonzo	RESTORE_COP2_REGISTER(COP2_GFM_POLY)
205229677Sgonzo	RESTORE_COP2_REGISTER(COP2_GFM_RESULT0)
206229677Sgonzo	RESTORE_COP2_REGISTER(COP2_GFM_RESULT1)
207229677Sgonzo	jr ra
208229677Sgonzo	nop
209229677Sgonzo
210229677Sgonzorestore_pass1:
211229677Sgonzo	RESTORE_COP2_REGISTER(COP2_HSH_DATW0_PASS1)
212229677Sgonzo	RESTORE_COP2_REGISTER(COP2_HSH_DATW1_PASS1)
213229677Sgonzo	RESTORE_COP2_REGISTER(COP2_HSH_DATW2_PASS1)
214229677Sgonzo	RESTORE_COP2_REGISTER(COP2_HSH_DATW3_PASS1)
215229677Sgonzo	RESTORE_COP2_REGISTER(COP2_HSH_DATW4_PASS1)
216229677Sgonzo	RESTORE_COP2_REGISTER(COP2_HSH_DATW5_PASS1)
217229677Sgonzo	RESTORE_COP2_REGISTER(COP2_HSH_DATW6_PASS1)
218229677Sgonzo	RESTORE_COP2_REGISTER(COP2_HSH_IVW0_PASS1)
219229677Sgonzo	RESTORE_COP2_REGISTER(COP2_HSH_IVW1_PASS1)
220229677Sgonzo	RESTORE_COP2_REGISTER(COP2_HSH_IVW2_PASS1)
221229677Sgonzo
222229677Sgonzorestore_done:
223229677Sgonzo	jr ra
224229677Sgonzo	nop
225229677SgonzoEND(octeon_cop2_restore)
226