1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
|
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* or http://www.opensolaris.org/os/licensing.
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2005 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
/*
* This file is through cpp before being used as
* an inline. It contains support routines used
* only by DR for the copy-rename sequence.
*/
#if defined(lint)
#include <sys/types.h>
#else
#include "assym.h"
#endif /* lint */
#include <sys/asm_linkage.h>
#include <sys/param.h>
#include <sys/privregs.h>
#include <sys/machasi.h>
#include <sys/spitregs.h>
#include <sys/mmu.h>
#include <sys/machthread.h>
#include <sys/pte.h>
#include <sys/stack.h>
#include <sys/vis.h>
#ifndef lint
/*
* arg1 = icache_size
* arg2 = icache_linesize
*/
#define ICACHE_FLUSHALL(lbl, arg1, arg2, tmp1) \
ldxa [%g0]ASI_LSU, tmp1 ;\
btst LSU_IC, tmp1 ;\
bz,pn %icc, lbl/**/1 ;\
sub arg1, arg2, tmp1 ;\
lbl/**/0: ;\
stxa %g0, [tmp1]ASI_IC_TAG ;\
membar #Sync ;\
cmp %g0, tmp1 ;\
bne,pt %icc, lbl/**/0 ;\
sub tmp1, arg2, tmp1 ;\
lbl/**/1:
/*
* arg1 = dcache_size
* arg2 = dcache_linesize
*/
#define DCACHE_FLUSHALL(lbl, arg1, arg2, tmp1) \
ldxa [%g0]ASI_LSU, tmp1 ;\
btst LSU_DC, tmp1 ;\
bz,pn %icc, lbl/**/1 ;\
sub arg1, arg2, tmp1 ;\
lbl/**/0: ;\
stxa %g0, [tmp1]ASI_DC_TAG ;\
membar #Sync ;\
cmp %g0, tmp1 ;\
bne,pt %icc, lbl/**/0 ;\
sub tmp1, arg2, tmp1 ;\
lbl/**/1:
/*
* arg1 = ecache flush physaddr
* arg2 = size
* arg3 = ecache_linesize
*/
#define ECACHE_FLUSHALL(lbl, arg1, arg2, arg3, tmp1, tmp2) \
rdpr %pstate, tmp1 ;\
andn tmp1, PSTATE_IE | PSTATE_AM, tmp2 ;\
wrpr %g0, tmp2, %pstate ;\
b lbl/**/1 ;\
lbl/**/0: ;\
sub arg2, arg3, arg2 ;\
lbl/**/1: ;\
brgez,a arg2, lbl/**/0 ;\
ldxa [arg1 + arg2]ASI_MEM, %g0 ;\
wrpr %g0, tmp1, %pstate
#ifdef SF_ERRATA_32
#define SF_WORKAROUND(tmp1, tmp2) \
sethi %hi(FLUSH_ADDR), tmp2 ;\
set MMU_PCONTEXT, tmp1 ;\
stxa %g0, [tmp1]ASI_DMMU ;\
flush tmp2 ;
#else
#define SF_WORKAROUND(tmp1, tmp2)
#endif /* SF_ERRATA_32 */
/*
* arg1 = vaddr
* arg2 = ctxnum
* - disable interrupts and clear address mask
* to access 64 bit physaddr
* - Blow out the TLB.
* . If it's kernel context, then use primary context.
* . Otherwise, use secondary.
*/
#define VTAG_FLUSHPAGE(lbl, arg1, arg2, tmp1, tmp2, tmp3, tmp4) \
rdpr %pstate, tmp1 ;\
andn tmp1, PSTATE_IE | PSTATE_AM, tmp2 ;\
wrpr tmp2, 0, %pstate ;\
brnz,pt arg2, lbl/**/1 ;\
sethi %hi(FLUSH_ADDR), tmp2 ;\
stxa %g0, [arg1]ASI_DTLB_DEMAP ;\
stxa %g0, [arg1]ASI_ITLB_DEMAP ;\
b lbl/**/5 ;\
flush tmp2 ;\
lbl/**/1: ;\
set MMU_SCONTEXT, tmp3 ;\
ldxa [tmp3]ASI_DMMU, tmp4 ;\
or DEMAP_SECOND | DEMAP_PAGE_TYPE, arg1, arg1 ;\
cmp tmp4, arg2 ;\
be,a,pt %icc, lbl/**/4 ;\
nop ;\
stxa arg2, [tmp3]ASI_DMMU ;\
lbl/**/4: ;\
stxa %g0, [arg1]ASI_DTLB_DEMAP ;\
stxa %g0, [arg1]ASI_ITLB_DEMAP ;\
flush tmp2 ;\
be,a,pt %icc, lbl/**/5 ;\
nop ;\
stxa tmp4, [tmp3]ASI_DMMU ;\
flush tmp2 ;\
lbl/**/5: ;\
wrpr %g0, tmp1, %pstate
/*
* arg1 = dtlb entry
* - Before first compare:
* tmp4 = tte
* tmp5 = vaddr
* tmp6 = cntxnum
*/
#define DTLB_FLUSH_UNLOCKED(lbl, arg1, tmp1, tmp2, tmp3, \
tmp4, tmp5, tmp6) \
lbl/**/0: ;\
sllx arg1, 3, tmp3 ;\
SF_WORKAROUND(tmp1, tmp2) ;\
ldxa [tmp3]ASI_DTLB_ACCESS, tmp4 ;\
srlx tmp4, 6, tmp4 ;\
andcc tmp4, 1, %g0 ;\
bnz,pn %xcc, lbl/**/1 ;\
srlx tmp4, 57, tmp4 ;\
andcc tmp4, 1, %g0 ;\
beq,pn %xcc, lbl/**/1 ;\
nop ;\
set TAGREAD_CTX_MASK, tmp1 ;\
ldxa [tmp3]ASI_DTLB_TAGREAD, tmp2 ;\
and tmp2, tmp1, tmp6 ;\
andn tmp2, tmp1, tmp5 ;\
VTAG_FLUSHPAGE(VD, tmp5, tmp6, tmp1, tmp2, tmp3, tmp4) ;\
lbl/**/1: ;\
brgz,pt arg1, lbl/**/0 ;\
sub arg1, 1, arg1
/*
* arg1 = itlb entry
* - Before first compare:
* tmp4 = tte
* tmp5 = vaddr
* tmp6 = cntxnum
*/
#define ITLB_FLUSH_UNLOCKED(lbl, arg1, tmp1, tmp2, tmp3, \
tmp4, tmp5, tmp6) \
lbl/**/0: ;\
sllx arg1, 3, tmp3 ;\
SF_WORKAROUND(tmp1, tmp2) ;\
ldxa [tmp3]ASI_ITLB_ACCESS, tmp4 ;\
srlx tmp4, 6, tmp4 ;\
andcc tmp4, 1, %g0 ;\
bnz,pn %xcc, lbl/**/1 ;\
srlx tmp4, 57, tmp4 ;\
andcc tmp4, 1, %g0 ;\
beq,pn %xcc, lbl/**/1 ;\
nop ;\
set TAGREAD_CTX_MASK, tmp1 ;\
ldxa [tmp3]ASI_ITLB_TAGREAD, tmp2 ;\
and tmp2, tmp1, tmp6 ;\
andn tmp2, tmp1, tmp5 ;\
VTAG_FLUSHPAGE(VI, tmp5, tmp6, tmp1, tmp2, tmp3, tmp4) ;\
lbl/**/1: ;\
brgz,pt arg1, lbl/**/0 ;\
sub arg1, 1, arg1
#define CLEARTL(lvl) \
wrpr %g0, lvl, %tl ;\
wrpr %g0, %g0, %tpc ;\
wrpr %g0, %g0, %tnpc ;\
wrpr %g0, %g0, %tt
#define SWITCH_STACK(estk) \
flushw ;\
sub estk, SA(KFPUSIZE+GSR_SIZE), estk ;\
andn estk, 0x3f, estk ;\
sub estk, SA(MINFRAME) + STACK_BIAS, %sp ;\
mov estk, %fp
#endif /* !lint */
#if defined(lint)
/*ARGSUSED*/
void
drmach_shutdown_asm(uint64_t mbox_addr)
{}
#else /* lint */
ENTRY_NP(drmach_shutdown_asm)
mov %o0, %o5
ldxa [%o5]ASI_MEM, %o0 ! get 8-byte estack in o0
add %o5, 8, %o5
ldxa [%o5]ASI_MEM, %o1 ! get 8-byte flushaddr in o1
add %o5, 8, %o5
lda [%o5]ASI_MEM, %o2 ! get 4-byte size in o2
srl %o2, 0, %o2
add %o5, 4, %o5
lda [%o5]ASI_MEM, %o3 ! get 4-byte linesize in o3
srl %o3, 0, %o3
add %o5, 4, %o5
ldxa [%o5]ASI_MEM, %o4 ! get 8-byte physaddr in o4
! %o0 = base (va mapping this code in bbsram)
! %o1 = flushaddr for ecache
! %o2 = size to use for ecache flush
! %o3 = ecache linesize
! %o4 = phys addr of byte to clear when finished
!
! output: Stores a zero at [%o4]ASI_MEM
membar #LoadStore
!
! Switch stack pointer to bbsram
!
SWITCH_STACK(%o0)
!
! Get some globals
!
mov %o3, %g1 ! ecache_linesize
mov %o4, %o0 ! physaddr byte to clear
sethi %hi(dcache_linesize), %g2
ld [%g2 + %lo(dcache_linesize)], %g2
sethi %hi(dcache_size), %g3
ld [%g3 + %lo(dcache_size)], %g3
sethi %hi(icache_linesize), %g4
ld [%g4 + %lo(icache_linesize)], %g4
sethi %hi(icache_size), %g5
ld [%g5 + %lo(icache_size)], %g5
sethi %hi(dtlb_entries), %o5
ld [%o5 + %lo(dtlb_entries)], %o5
sllx %o5, 32, %o5
srlx %o5, 32, %o5
sethi %hi(itlb_entries), %o3
ld [%o3 + %lo(itlb_entries)], %o3
!
! cram Xtlb_entries into a single register (%o5)
! %o5 upper 32 = itlb_entries
! lower 32 = dtlb_entries
!
sllx %o3, 32, %o3
or %o5, %o3, %o5
!
! Flush E$
!
ECACHE_FLUSHALL(EC, %o1, %o2, %g1, %o3, %o4)
!
! %o1 & %o2 now available
!
membar #Sync
!
! Flush D$
!
DCACHE_FLUSHALL(DC, %g3, %g2, %o3)
!
! Flush I$
!
ICACHE_FLUSHALL(IC, %g5, %g4, %o3)
membar #Sync
!
! Flush dtlb's
!
srlx %o5, 32, %g5 ! %g5 = itlb_entries
sllx %o5, 32, %o5
srlx %o5, 32, %g1
sub %g1, 1, %g1 ! %g1 = dtlb_entries - 1
DTLB_FLUSH_UNLOCKED(D, %g1, %g3, %g4, %o2, %o3, %o4, %o5)
!
! Flush itlb's
!
sub %g5, 1, %g1 ! %g1 = itlb_entries - 1
ITLB_FLUSH_UNLOCKED(I, %g1, %g3, %g4, %o2, %o3, %o4, %o5)
membar #Sync
!
! Clear byte to signal finished.
!
stba %g0, [%o0]ASI_MEM
membar #Sync
!
! read ensures that last write completed (has left queue in the PC chip)
!
lduba [%o0]ASI_MEM, %g0
5:
ba 5b
nop
SET_SIZE(drmach_shutdown_asm)
.global drmach_shutdown_asm_end
.skip 2048
drmach_shutdown_asm_end:
#endif /* lint */
|