blob: 10689cfd0ad40e6b12ae6b148f99ac2f5c7deb64 [file] [log] [blame]
David S. Miller74bf4312006-01-31 18:29:18 -08001/* tsb.S: Sparc64 TSB table handling.
2 *
3 * Copyright (C) 2006 David S. Miller <davem@davemloft.net>
4 */
5
David S. Millerdcc1e8d2006-03-22 00:49:59 -08006
David S. Miller74bf4312006-01-31 18:29:18 -08007#include <asm/tsb.h>
David S. Miller618e9ed2006-02-09 17:21:53 -08008#include <asm/hypervisor.h>
David S. Millerdcc1e8d2006-03-22 00:49:59 -08009#include <asm/page.h>
10#include <asm/cpudata.h>
11#include <asm/mmu.h>
David S. Miller74bf4312006-01-31 18:29:18 -080012
13 .text
14 .align 32
15
16 /* Invoked from TLB miss handler, we are in the
17 * MMU global registers and they are setup like
18 * this:
19 *
20 * %g1: TSB entry pointer
21 * %g2: available temporary
22 * %g3: FAULT_CODE_{D,I}TLB
23 * %g4: available temporary
24 * %g5: available temporary
25 * %g6: TAG TARGET
David S. Millerd257d5d2006-02-06 23:44:37 -080026 * %g7: available temporary, will be loaded by us with
27 * the physical address base of the linux page
David S. Miller74bf4312006-01-31 18:29:18 -080028 * tables for the current address space
29 */
David S. Miller74bf4312006-01-31 18:29:18 -080030tsb_miss_dtlb:
31 mov TLB_TAG_ACCESS, %g4
David S. Miller4f6deb82016-07-27 17:50:26 -070032 ldxa [%g4] ASI_DMMU, %g4
33 srlx %g4, PAGE_SHIFT, %g4
David S. Miller74bf4312006-01-31 18:29:18 -080034 ba,pt %xcc, tsb_miss_page_table_walk
David S. Miller4f6deb82016-07-27 17:50:26 -070035 sllx %g4, PAGE_SHIFT, %g4
David S. Miller74bf4312006-01-31 18:29:18 -080036
David S. Miller74bf4312006-01-31 18:29:18 -080037tsb_miss_itlb:
38 mov TLB_TAG_ACCESS, %g4
David S. Miller4f6deb82016-07-27 17:50:26 -070039 ldxa [%g4] ASI_IMMU, %g4
40 srlx %g4, PAGE_SHIFT, %g4
David S. Miller74bf4312006-01-31 18:29:18 -080041 ba,pt %xcc, tsb_miss_page_table_walk
David S. Miller4f6deb82016-07-27 17:50:26 -070042 sllx %g4, PAGE_SHIFT, %g4
David S. Miller74bf4312006-01-31 18:29:18 -080043
David S. Miller36a68e72006-02-11 00:29:34 -080044 /* At this point we have:
David S. Millerdcc1e8d2006-03-22 00:49:59 -080045 * %g1 -- PAGE_SIZE TSB entry address
David S. Miller7a1ac522006-03-16 02:02:32 -080046 * %g3 -- FAULT_CODE_{D,I}TLB
47 * %g4 -- missing virtual address
David S. Miller8b234272006-02-17 18:01:02 -080048 * %g6 -- TAG TARGET (vaddr >> 22)
David S. Millerd257d5d2006-02-06 23:44:37 -080049 */
David S. Miller74bf4312006-01-31 18:29:18 -080050tsb_miss_page_table_walk:
David S. Millerdcc1e8d2006-03-22 00:49:59 -080051 TRAP_LOAD_TRAP_BLOCK(%g7, %g5)
David S. Miller56fb4df2006-02-26 23:24:22 -080052
David S. Millerdcc1e8d2006-03-22 00:49:59 -080053 /* Before committing to a full page table walk,
54 * check the huge page TSB.
55 */
David Miller9e695d22012-10-08 16:34:29 -070056#if defined(CONFIG_HUGETLB_PAGE) || defined(CONFIG_TRANSPARENT_HUGEPAGE)
David S. Millerdcc1e8d2006-03-22 00:49:59 -080057
58661: ldx [%g7 + TRAP_PER_CPU_TSB_HUGE], %g5
59 nop
60 .section .sun4v_2insn_patch, "ax"
61 .word 661b
62 mov SCRATCHPAD_UTSBREG2, %g5
63 ldxa [%g5] ASI_SCRATCHPAD, %g5
64 .previous
65
66 cmp %g5, -1
67 be,pt %xcc, 80f
68 nop
69
70 /* We need an aligned pair of registers containing 2 values
71 * which can be easily rematerialized. %g6 and %g7 foot the
72 * bill just nicely. We'll save %g6 away into %g2 for the
73 * huge page TSB TAG comparison.
74 *
75 * Perform a huge page TSB lookup.
76 */
77 mov %g6, %g2
78 and %g5, 0x7, %g6
79 mov 512, %g7
80 andn %g5, 0x7, %g5
81 sllx %g7, %g6, %g7
David S. Miller37b3a8f2013-09-25 13:48:49 -070082 srlx %g4, REAL_HPAGE_SHIFT, %g6
David S. Millerdcc1e8d2006-03-22 00:49:59 -080083 sub %g7, 1, %g7
84 and %g6, %g7, %g6
85 sllx %g6, 4, %g6
86 add %g5, %g6, %g5
87
88 TSB_LOAD_QUAD(%g5, %g6)
89 cmp %g6, %g2
90 be,a,pt %xcc, tsb_tlb_reload
91 mov %g7, %g5
92
93 /* No match, remember the huge page TSB entry address,
94 * and restore %g6 and %g7.
95 */
96 TRAP_LOAD_TRAP_BLOCK(%g7, %g6)
97 srlx %g4, 22, %g6
9880: stx %g5, [%g7 + TRAP_PER_CPU_TSB_HUGE_TEMP]
99
100#endif
101
102 ldx [%g7 + TRAP_PER_CPU_PGD_PADDR], %g7
David S. Miller74bf4312006-01-31 18:29:18 -0800103
David S. Miller7a1ac522006-03-16 02:02:32 -0800104 /* At this point we have:
105 * %g1 -- TSB entry address
106 * %g3 -- FAULT_CODE_{D,I}TLB
David S. Millerdcc1e8d2006-03-22 00:49:59 -0800107 * %g4 -- missing virtual address
108 * %g6 -- TAG TARGET (vaddr >> 22)
109 * %g7 -- page table physical address
110 *
111 * We know that both the base PAGE_SIZE TSB and the HPAGE_SIZE
112 * TSB both lack a matching entry.
113 */
114tsb_miss_page_table_walk_sun4v_fastpath:
115 USER_PGTABLE_WALK_TL1(%g4, %g7, %g5, %g2, tsb_do_fault)
116
David Miller9e695d22012-10-08 16:34:29 -0700117 /* Valid PTE is now in %g5. */
David S. Millerdcc1e8d2006-03-22 00:49:59 -0800118
David Miller9e695d22012-10-08 16:34:29 -0700119#if defined(CONFIG_HUGETLB_PAGE) || defined(CONFIG_TRANSPARENT_HUGEPAGE)
Nitin Guptac7d9f772017-02-01 16:16:36 -0800120 sethi %uhi(_PAGE_PMD_HUGE), %g7
David S. Millerdcc1e8d2006-03-22 00:49:59 -0800121 sllx %g7, 32, %g7
David S. Millerdcc1e8d2006-03-22 00:49:59 -0800122
Nitin Guptac7d9f772017-02-01 16:16:36 -0800123 andcc %g5, %g7, %g0
124 be,pt %xcc, 60f
David S. Millerdcc1e8d2006-03-22 00:49:59 -0800125 nop
126
127 /* It is a huge page, use huge page TSB entry address we
David S. Miller0fbebed2013-02-19 22:34:10 -0800128 * calculated above. If the huge page TSB has not been
129 * allocated, setup a trap stack and call hugetlb_setup()
130 * to do so, then return from the trap to replay the TLB
131 * miss.
132 *
133 * This is necessary to handle the case of transparent huge
134 * pages where we don't really have a non-atomic context
135 * in which to allocate the hugepage TSB hash table. When
136 * the 'mm' faults in the hugepage for the first time, we
137 * thus handle it here. This also makes sure that we can
138 * allocate the TSB hash table on the correct NUMA node.
David S. Millerdcc1e8d2006-03-22 00:49:59 -0800139 */
140 TRAP_LOAD_TRAP_BLOCK(%g7, %g2)
David S. Miller0fbebed2013-02-19 22:34:10 -0800141 ldx [%g7 + TRAP_PER_CPU_TSB_HUGE_TEMP], %g1
142 cmp %g1, -1
143 bne,pt %xcc, 60f
144 nop
145
146661: rdpr %pstate, %g5
147 wrpr %g5, PSTATE_AG | PSTATE_MG, %pstate
148 .section .sun4v_2insn_patch, "ax"
149 .word 661b
150 SET_GL(1)
151 nop
152 .previous
153
David S. Miller84bd6d82014-10-18 23:03:09 -0400154 rdpr %tl, %g7
155 cmp %g7, 1
David S. Miller0fbebed2013-02-19 22:34:10 -0800156 bne,pn %xcc, winfix_trampoline
David S. Miller84bd6d82014-10-18 23:03:09 -0400157 mov %g3, %g4
David S. Miller0fbebed2013-02-19 22:34:10 -0800158 ba,pt %xcc, etrap
159 rd %pc, %g7
160 call hugetlb_setup
161 add %sp, PTREGS_OFF, %o0
162 ba,pt %xcc, rtrap
163 nop
164
David S. Millerdcc1e8d2006-03-22 00:49:59 -080016560:
166#endif
167
168 /* At this point we have:
169 * %g1 -- TSB entry address
170 * %g3 -- FAULT_CODE_{D,I}TLB
171 * %g5 -- valid PTE
David S. Miller7a1ac522006-03-16 02:02:32 -0800172 * %g6 -- TAG TARGET (vaddr >> 22)
173 */
David S. Miller74bf4312006-01-31 18:29:18 -0800174tsb_reload:
David S. Millerd257d5d2006-02-06 23:44:37 -0800175 TSB_LOCK_TAG(%g1, %g2, %g7)
David S. Miller74bf4312006-01-31 18:29:18 -0800176 TSB_WRITE(%g1, %g5, %g6)
177
178 /* Finally, load TLB and return from trap. */
179tsb_tlb_reload:
180 cmp %g3, FAULT_CODE_DTLB
181 bne,pn %xcc, tsb_itlb_load
182 nop
183
184tsb_dtlb_load:
David S. Millerd257d5d2006-02-06 23:44:37 -0800185
186661: stxa %g5, [%g0] ASI_DTLB_DATA_IN
David S. Miller74bf4312006-01-31 18:29:18 -0800187 retry
David S. Millerdf7d6ae2006-02-07 00:00:16 -0800188 .section .sun4v_2insn_patch, "ax"
David S. Millerd257d5d2006-02-06 23:44:37 -0800189 .word 661b
190 nop
191 nop
192 .previous
193
194 /* For sun4v the ASI_DTLB_DATA_IN store and the retry
195 * instruction get nop'd out and we get here to branch
196 * to the sun4v tlb load code. The registers are setup
197 * as follows:
198 *
199 * %g4: vaddr
200 * %g5: PTE
201 * %g6: TAG
202 *
203 * The sun4v TLB load wants the PTE in %g3 so we fix that
204 * up here.
205 */
206 ba,pt %xcc, sun4v_dtlb_load
207 mov %g5, %g3
David S. Miller74bf4312006-01-31 18:29:18 -0800208
209tsb_itlb_load:
David S. Miller45f791e2006-03-01 22:42:18 -0800210 /* Executable bit must be set. */
David S. Miller1f474642010-02-19 15:19:52 -0800211661: sethi %hi(_PAGE_EXEC_4U), %g4
212 andcc %g5, %g4, %g0
213 .section .sun4v_2insn_patch, "ax"
David S. Miller45f791e2006-03-01 22:42:18 -0800214 .word 661b
215 andcc %g5, _PAGE_EXEC_4V, %g0
David S. Miller1f474642010-02-19 15:19:52 -0800216 nop
David S. Miller45f791e2006-03-01 22:42:18 -0800217 .previous
218
219 be,pn %xcc, tsb_do_fault
220 nop
David S. Millerd257d5d2006-02-06 23:44:37 -0800221
222661: stxa %g5, [%g0] ASI_ITLB_DATA_IN
David S. Miller74bf4312006-01-31 18:29:18 -0800223 retry
David S. Millerdf7d6ae2006-02-07 00:00:16 -0800224 .section .sun4v_2insn_patch, "ax"
David S. Millerd257d5d2006-02-06 23:44:37 -0800225 .word 661b
226 nop
227 nop
228 .previous
229
230 /* For sun4v the ASI_ITLB_DATA_IN store and the retry
231 * instruction get nop'd out and we get here to branch
232 * to the sun4v tlb load code. The registers are setup
233 * as follows:
234 *
235 * %g4: vaddr
236 * %g5: PTE
237 * %g6: TAG
238 *
239 * The sun4v TLB load wants the PTE in %g3 so we fix that
240 * up here.
241 */
242 ba,pt %xcc, sun4v_itlb_load
243 mov %g5, %g3
David S. Miller74bf4312006-01-31 18:29:18 -0800244
245 /* No valid entry in the page tables, do full fault
246 * processing.
247 */
248
249 .globl tsb_do_fault
250tsb_do_fault:
251 cmp %g3, FAULT_CODE_DTLB
David S. Miller45fec052006-02-05 22:27:28 -0800252
253661: rdpr %pstate, %g5
254 wrpr %g5, PSTATE_AG | PSTATE_MG, %pstate
David S. Millerdf7d6ae2006-02-07 00:00:16 -0800255 .section .sun4v_2insn_patch, "ax"
David S. Miller45fec052006-02-05 22:27:28 -0800256 .word 661b
David S. Miller6c8927c2006-02-17 14:58:02 -0800257 SET_GL(1)
David S. Miller8b234272006-02-17 18:01:02 -0800258 ldxa [%g0] ASI_SCRATCHPAD, %g4
David S. Miller45fec052006-02-05 22:27:28 -0800259 .previous
260
David S. Miller74bf4312006-01-31 18:29:18 -0800261 bne,pn %xcc, tsb_do_itlb_fault
David S. Miller45fec052006-02-05 22:27:28 -0800262 nop
David S. Miller74bf4312006-01-31 18:29:18 -0800263
264tsb_do_dtlb_fault:
David S. Millerd257d5d2006-02-06 23:44:37 -0800265 rdpr %tl, %g3
266 cmp %g3, 1
267
268661: mov TLB_TAG_ACCESS, %g4
David S. Miller74bf4312006-01-31 18:29:18 -0800269 ldxa [%g4] ASI_DMMU, %g5
David S. Millerdf7d6ae2006-02-07 00:00:16 -0800270 .section .sun4v_2insn_patch, "ax"
David S. Millerd257d5d2006-02-06 23:44:37 -0800271 .word 661b
David S. Miller8b234272006-02-17 18:01:02 -0800272 ldx [%g4 + HV_FAULT_D_ADDR_OFFSET], %g5
David S. Millerd257d5d2006-02-06 23:44:37 -0800273 nop
274 .previous
275
David S. Miller4f6deb82016-07-27 17:50:26 -0700276 /* Clear context ID bits. */
277 srlx %g5, PAGE_SHIFT, %g5
278 sllx %g5, PAGE_SHIFT, %g5
279
David S. Miller74bf4312006-01-31 18:29:18 -0800280 be,pt %xcc, sparc64_realfault_common
281 mov FAULT_CODE_DTLB, %g4
282 ba,pt %xcc, winfix_trampoline
283 nop
284
285tsb_do_itlb_fault:
286 rdpr %tpc, %g5
287 ba,pt %xcc, sparc64_realfault_common
288 mov FAULT_CODE_ITLB, %g4
289
290 .globl sparc64_realfault_common
291sparc64_realfault_common:
David S. Miller9bc657b2006-01-31 18:34:21 -0800292 /* fault code in %g4, fault address in %g5, etrap will
293 * preserve these two values in %l4 and %l5 respectively
294 */
David S. Miller74bf4312006-01-31 18:29:18 -0800295 ba,pt %xcc, etrap ! Save trap state
2961: rd %pc, %g7 ! ...
David S. Miller9bc657b2006-01-31 18:34:21 -0800297 stb %l4, [%g6 + TI_FAULT_CODE] ! Save fault code
298 stx %l5, [%g6 + TI_FAULT_ADDR] ! Save fault address
David S. Miller74bf4312006-01-31 18:29:18 -0800299 call do_sparc64_fault ! Call fault handler
300 add %sp, PTREGS_OFF, %o0 ! Compute pt_regs arg
David S. Miller7697daa2008-04-24 03:15:22 -0700301 ba,pt %xcc, rtrap ! Restore cpu state
David S. Miller74bf4312006-01-31 18:29:18 -0800302 nop ! Delay slot (fill me)
303
David S. Miller74bf4312006-01-31 18:29:18 -0800304winfix_trampoline:
305 rdpr %tpc, %g3 ! Prepare winfixup TNPC
306 or %g3, 0x7c, %g3 ! Compute branch offset
307 wrpr %g3, %tnpc ! Write it into TNPC
308 done ! Trap return
309
David S. Millerb70c0fa2006-01-31 18:32:04 -0800310 /* Insert an entry into the TSB.
311 *
David S. Miller517af332006-02-01 15:55:21 -0800312 * %o0: TSB entry pointer (virt or phys address)
David S. Millerb70c0fa2006-01-31 18:32:04 -0800313 * %o1: tag
314 * %o2: pte
315 */
316 .align 32
David S. Miller517af332006-02-01 15:55:21 -0800317 .globl __tsb_insert
318__tsb_insert:
David S. Millerb70c0fa2006-01-31 18:32:04 -0800319 rdpr %pstate, %o5
320 wrpr %o5, PSTATE_IE, %pstate
321 TSB_LOCK_TAG(%o0, %g2, %g3)
322 TSB_WRITE(%o0, %o2, %o1)
323 wrpr %o5, %pstate
324 retl
325 nop
David S. Miller7a1ac522006-03-16 02:02:32 -0800326 .size __tsb_insert, .-__tsb_insert
David S. Millerb70c0fa2006-01-31 18:32:04 -0800327
David S. Miller517af332006-02-01 15:55:21 -0800328 /* Flush the given TSB entry if it has the matching
329 * tag.
330 *
331 * %o0: TSB entry pointer (virt or phys address)
332 * %o1: tag
333 */
334 .align 32
335 .globl tsb_flush
David S. Miller7a1ac522006-03-16 02:02:32 -0800336 .type tsb_flush,#function
David S. Miller517af332006-02-01 15:55:21 -0800337tsb_flush:
338 sethi %hi(TSB_TAG_LOCK_HIGH), %g2
3391: TSB_LOAD_TAG(%o0, %g1)
340 srlx %g1, 32, %o3
341 andcc %o3, %g2, %g0
342 bne,pn %icc, 1b
David S. Miller293666b2008-11-15 13:33:25 -0800343 nop
David S. Miller517af332006-02-01 15:55:21 -0800344 cmp %g1, %o1
David S. Miller8b234272006-02-17 18:01:02 -0800345 mov 1, %o3
David S. Miller517af332006-02-01 15:55:21 -0800346 bne,pt %xcc, 2f
David S. Miller8b234272006-02-17 18:01:02 -0800347 sllx %o3, TSB_TAG_INVALID_BIT, %o3
David S. Miller517af332006-02-01 15:55:21 -0800348 TSB_CAS_TAG(%o0, %g1, %o3)
349 cmp %g1, %o3
350 bne,pn %xcc, 1b
351 nop
3522: retl
David S. Miller293666b2008-11-15 13:33:25 -0800353 nop
David S. Miller7a1ac522006-03-16 02:02:32 -0800354 .size tsb_flush, .-tsb_flush
David S. Miller517af332006-02-01 15:55:21 -0800355
David S. Miller74bf4312006-01-31 18:29:18 -0800356 /* Reload MMU related context switch state at
357 * schedule() time.
358 *
359 * %o0: page table physical address
David S. Millerdcc1e8d2006-03-22 00:49:59 -0800360 * %o1: TSB base config pointer
361 * %o2: TSB huge config pointer, or NULL if none
362 * %o3: Hypervisor TSB descriptor physical address
David S. Miller98c55842006-01-31 18:31:20 -0800363 *
364 * We have to run this whole thing with interrupts
365 * disabled so that the current cpu doesn't change
366 * due to preemption.
David S. Miller74bf4312006-01-31 18:29:18 -0800367 */
David S. Miller56fb4df2006-02-26 23:24:22 -0800368 .align 32
David S. Miller98c55842006-01-31 18:31:20 -0800369 .globl __tsb_context_switch
David S. Miller7a1ac522006-03-16 02:02:32 -0800370 .type __tsb_context_switch,#function
David S. Miller98c55842006-01-31 18:31:20 -0800371__tsb_context_switch:
David S. Millerdcc1e8d2006-03-22 00:49:59 -0800372 rdpr %pstate, %g1
373 wrpr %g1, PSTATE_IE, %pstate
David S. Miller74bf4312006-01-31 18:29:18 -0800374
David S. Millerdcc1e8d2006-03-22 00:49:59 -0800375 TRAP_LOAD_TRAP_BLOCK(%g2, %g3)
376
David S. Miller98c55842006-01-31 18:31:20 -0800377 stx %o0, [%g2 + TRAP_PER_CPU_PGD_PADDR]
David S. Miller74bf4312006-01-31 18:29:18 -0800378
David S. Millerdcc1e8d2006-03-22 00:49:59 -0800379 ldx [%o1 + TSB_CONFIG_REG_VAL], %o0
380 brz,pt %o2, 1f
381 mov -1, %g3
382
383 ldx [%o2 + TSB_CONFIG_REG_VAL], %g3
384
3851: stx %g3, [%g2 + TRAP_PER_CPU_TSB_HUGE]
386
387 sethi %hi(tlb_type), %g2
388 lduw [%g2 + %lo(tlb_type)], %g2
389 cmp %g2, 3
390 bne,pt %icc, 50f
David S. Miller98c55842006-01-31 18:31:20 -0800391 nop
David S. Miller74bf4312006-01-31 18:29:18 -0800392
David S. Miller618e9ed2006-02-09 17:21:53 -0800393 /* Hypervisor TSB switch. */
David S. Millerdcc1e8d2006-03-22 00:49:59 -0800394 mov SCRATCHPAD_UTSBREG1, %o5
395 stxa %o0, [%o5] ASI_SCRATCHPAD
396 mov SCRATCHPAD_UTSBREG2, %o5
397 stxa %g3, [%o5] ASI_SCRATCHPAD
David S. Miller618e9ed2006-02-09 17:21:53 -0800398
David S. Millerdcc1e8d2006-03-22 00:49:59 -0800399 mov 2, %o0
400 cmp %g3, -1
401 move %xcc, 1, %o0
David S. Millera7b31ba2006-02-15 21:16:42 -0800402
David S. Miller164c2202006-02-09 22:57:21 -0800403 mov HV_FAST_MMU_TSB_CTXNON0, %o5
David S. Millerdcc1e8d2006-03-22 00:49:59 -0800404 mov %o3, %o1
David S. Miller618e9ed2006-02-09 17:21:53 -0800405 ta HV_FAST_TRAP
406
David S. Millerdcc1e8d2006-03-22 00:49:59 -0800407 /* Finish up. */
David S. Miller618e9ed2006-02-09 17:21:53 -0800408 ba,pt %xcc, 9f
David S. Miller618e9ed2006-02-09 17:21:53 -0800409 nop
410
David S. Millerdcc1e8d2006-03-22 00:49:59 -0800411 /* SUN4U TSB switch. */
41250: mov TSB_REG, %o5
413 stxa %o0, [%o5] ASI_DMMU
414 membar #Sync
415 stxa %o0, [%o5] ASI_IMMU
416 membar #Sync
417
4182: ldx [%o1 + TSB_CONFIG_MAP_VADDR], %o4
419 brz %o4, 9f
420 ldx [%o1 + TSB_CONFIG_MAP_PTE], %o5
421
David S. Miller618e9ed2006-02-09 17:21:53 -0800422 sethi %hi(sparc64_highest_unlocked_tlb_ent), %g2
David S. Millerdcc1e8d2006-03-22 00:49:59 -0800423 mov TLB_TAG_ACCESS, %g3
David S. Miller618e9ed2006-02-09 17:21:53 -0800424 lduw [%g2 + %lo(sparc64_highest_unlocked_tlb_ent)], %g2
David S. Millerdcc1e8d2006-03-22 00:49:59 -0800425 stxa %o4, [%g3] ASI_DMMU
David S. Miller6b6d01722006-01-31 18:33:12 -0800426 membar #Sync
427 sllx %g2, 3, %g2
David S. Millerdcc1e8d2006-03-22 00:49:59 -0800428 stxa %o5, [%g2] ASI_DTLB_DATA_ACCESS
David S. Miller6b6d01722006-01-31 18:33:12 -0800429 membar #Sync
David S. Millerdcc1e8d2006-03-22 00:49:59 -0800430
431 brz,pt %o2, 9f
432 nop
433
434 ldx [%o2 + TSB_CONFIG_MAP_VADDR], %o4
435 ldx [%o2 + TSB_CONFIG_MAP_PTE], %o5
436 mov TLB_TAG_ACCESS, %g3
437 stxa %o4, [%g3] ASI_DMMU
438 membar #Sync
439 sub %g2, (1 << 3), %g2
440 stxa %o5, [%g2] ASI_DTLB_DATA_ACCESS
441 membar #Sync
442
David S. Miller74bf4312006-01-31 18:29:18 -08004439:
David S. Millerdcc1e8d2006-03-22 00:49:59 -0800444 wrpr %g1, %pstate
David S. Miller74bf4312006-01-31 18:29:18 -0800445
446 retl
David S. Miller98c55842006-01-31 18:31:20 -0800447 nop
David S. Miller7a1ac522006-03-16 02:02:32 -0800448 .size __tsb_context_switch, .-__tsb_context_switch
449
450#define TSB_PASS_BITS ((1 << TSB_TAG_LOCK_BIT) | \
451 (1 << TSB_TAG_INVALID_BIT))
452
453 .align 32
454 .globl copy_tsb
455 .type copy_tsb,#function
456copy_tsb: /* %o0=old_tsb_base, %o1=old_tsb_size
457 * %o2=new_tsb_base, %o3=new_tsb_size
458 */
459 sethi %uhi(TSB_PASS_BITS), %g7
460 srlx %o3, 4, %o3
461 add %o0, %o1, %g1 /* end of old tsb */
462 sllx %g7, 32, %g7
463 sub %o3, 1, %o3 /* %o3 == new tsb hash mask */
464
465661: prefetcha [%o0] ASI_N, #one_read
466 .section .tsb_phys_patch, "ax"
467 .word 661b
468 prefetcha [%o0] ASI_PHYS_USE_EC, #one_read
469 .previous
470
47190: andcc %o0, (64 - 1), %g0
472 bne 1f
473 add %o0, 64, %o5
474
475661: prefetcha [%o5] ASI_N, #one_read
476 .section .tsb_phys_patch, "ax"
477 .word 661b
478 prefetcha [%o5] ASI_PHYS_USE_EC, #one_read
479 .previous
480
4811: TSB_LOAD_QUAD(%o0, %g2) /* %g2/%g3 == TSB entry */
482 andcc %g2, %g7, %g0 /* LOCK or INVALID set? */
483 bne,pn %xcc, 80f /* Skip it */
484 sllx %g2, 22, %o4 /* TAG --> VADDR */
485
486 /* This can definitely be computed faster... */
487 srlx %o0, 4, %o5 /* Build index */
488 and %o5, 511, %o5 /* Mask index */
489 sllx %o5, PAGE_SHIFT, %o5 /* Put into vaddr position */
490 or %o4, %o5, %o4 /* Full VADDR. */
491 srlx %o4, PAGE_SHIFT, %o4 /* Shift down to create index */
492 and %o4, %o3, %o4 /* Mask with new_tsb_nents-1 */
493 sllx %o4, 4, %o4 /* Shift back up into tsb ent offset */
494 TSB_STORE(%o2 + %o4, %g2) /* Store TAG */
495 add %o4, 0x8, %o4 /* Advance to TTE */
496 TSB_STORE(%o2 + %o4, %g3) /* Store TTE */
497
49880: add %o0, 16, %o0
499 cmp %o0, %g1
500 bne,pt %xcc, 90b
501 nop
502
503 retl
David S. Miller293666b2008-11-15 13:33:25 -0800504 nop
David S. Miller7a1ac522006-03-16 02:02:32 -0800505 .size copy_tsb, .-copy_tsb
David S. Millerbb8646d2006-03-18 23:55:11 -0800506
507 /* Set the invalid bit in all TSB entries. */
508 .align 32
509 .globl tsb_init
510 .type tsb_init,#function
511tsb_init: /* %o0 = TSB vaddr, %o1 = size in bytes */
512 prefetch [%o0 + 0x000], #n_writes
513 mov 1, %g1
514 prefetch [%o0 + 0x040], #n_writes
515 sllx %g1, TSB_TAG_INVALID_BIT, %g1
516 prefetch [%o0 + 0x080], #n_writes
5171: prefetch [%o0 + 0x0c0], #n_writes
518 stx %g1, [%o0 + 0x00]
519 stx %g1, [%o0 + 0x10]
520 stx %g1, [%o0 + 0x20]
521 stx %g1, [%o0 + 0x30]
522 prefetch [%o0 + 0x100], #n_writes
523 stx %g1, [%o0 + 0x40]
524 stx %g1, [%o0 + 0x50]
525 stx %g1, [%o0 + 0x60]
526 stx %g1, [%o0 + 0x70]
527 prefetch [%o0 + 0x140], #n_writes
528 stx %g1, [%o0 + 0x80]
529 stx %g1, [%o0 + 0x90]
530 stx %g1, [%o0 + 0xa0]
531 stx %g1, [%o0 + 0xb0]
532 prefetch [%o0 + 0x180], #n_writes
533 stx %g1, [%o0 + 0xc0]
534 stx %g1, [%o0 + 0xd0]
535 stx %g1, [%o0 + 0xe0]
536 stx %g1, [%o0 + 0xf0]
537 subcc %o1, 0x100, %o1
538 bne,pt %xcc, 1b
539 add %o0, 0x100, %o0
540 retl
541 nop
542 nop
543 nop
544 .size tsb_init, .-tsb_init
545
546 .globl NGtsb_init
547 .type NGtsb_init,#function
548NGtsb_init:
549 rd %asi, %g2
550 mov 1, %g1
551 wr %g0, ASI_BLK_INIT_QUAD_LDD_P, %asi
552 sllx %g1, TSB_TAG_INVALID_BIT, %g1
5531: stxa %g1, [%o0 + 0x00] %asi
554 stxa %g1, [%o0 + 0x10] %asi
555 stxa %g1, [%o0 + 0x20] %asi
556 stxa %g1, [%o0 + 0x30] %asi
557 stxa %g1, [%o0 + 0x40] %asi
558 stxa %g1, [%o0 + 0x50] %asi
559 stxa %g1, [%o0 + 0x60] %asi
560 stxa %g1, [%o0 + 0x70] %asi
561 stxa %g1, [%o0 + 0x80] %asi
562 stxa %g1, [%o0 + 0x90] %asi
563 stxa %g1, [%o0 + 0xa0] %asi
564 stxa %g1, [%o0 + 0xb0] %asi
565 stxa %g1, [%o0 + 0xc0] %asi
566 stxa %g1, [%o0 + 0xd0] %asi
567 stxa %g1, [%o0 + 0xe0] %asi
568 stxa %g1, [%o0 + 0xf0] %asi
569 subcc %o1, 0x100, %o1
570 bne,pt %xcc, 1b
571 add %o0, 0x100, %o0
David S. Miller24d559c2007-03-19 13:27:33 -0700572 membar #Sync
David S. Millerbb8646d2006-03-18 23:55:11 -0800573 retl
574 wr %g2, 0x0, %asi
575 .size NGtsb_init, .-NGtsb_init