blob: a17259cf34b824cb22809c57610d8614eab57094 [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
6#include <asm/tsb.h>
David S. Miller618e9ed2006-02-09 17:21:53 -08007#include <asm/hypervisor.h>
David S. Miller74bf4312006-01-31 18:29:18 -08008
9 .text
10 .align 32
11
12 /* Invoked from TLB miss handler, we are in the
13 * MMU global registers and they are setup like
14 * this:
15 *
16 * %g1: TSB entry pointer
17 * %g2: available temporary
18 * %g3: FAULT_CODE_{D,I}TLB
19 * %g4: available temporary
20 * %g5: available temporary
21 * %g6: TAG TARGET
David S. Millerd257d5d2006-02-06 23:44:37 -080022 * %g7: available temporary, will be loaded by us with
23 * the physical address base of the linux page
David S. Miller74bf4312006-01-31 18:29:18 -080024 * tables for the current address space
25 */
David S. Miller74bf4312006-01-31 18:29:18 -080026tsb_miss_dtlb:
27 mov TLB_TAG_ACCESS, %g4
David S. Miller74bf4312006-01-31 18:29:18 -080028 ba,pt %xcc, tsb_miss_page_table_walk
David S. Miller36a68e72006-02-11 00:29:34 -080029 ldxa [%g4] ASI_DMMU, %g4
David S. Miller74bf4312006-01-31 18:29:18 -080030
David S. Miller74bf4312006-01-31 18:29:18 -080031tsb_miss_itlb:
32 mov TLB_TAG_ACCESS, %g4
David S. Miller74bf4312006-01-31 18:29:18 -080033 ba,pt %xcc, tsb_miss_page_table_walk
David S. Miller36a68e72006-02-11 00:29:34 -080034 ldxa [%g4] ASI_IMMU, %g4
David S. Miller74bf4312006-01-31 18:29:18 -080035
David S. Miller36a68e72006-02-11 00:29:34 -080036 /* At this point we have:
37 * %g4 -- missing virtual address
38 * %g1 -- TSB entry address
39 * %g6 -- TAG TARGET ((vaddr >> 22) | (ctx << 48))
David S. Millerd257d5d2006-02-06 23:44:37 -080040 */
David S. Miller74bf4312006-01-31 18:29:18 -080041tsb_miss_page_table_walk:
David S. Millerffe483d2006-02-02 21:55:10 -080042 TRAP_LOAD_PGD_PHYS(%g7, %g5)
David S. Miller56fb4df2006-02-26 23:24:22 -080043
David S. Miller36a68e72006-02-11 00:29:34 -080044 /* And now we have the PGD base physical address in %g7. */
45tsb_miss_page_table_walk_sun4v_fastpath:
David S. Miller74bf4312006-01-31 18:29:18 -080046 USER_PGTABLE_WALK_TL1(%g4, %g7, %g5, %g2, tsb_do_fault)
47
48tsb_reload:
David S. Millerd257d5d2006-02-06 23:44:37 -080049 TSB_LOCK_TAG(%g1, %g2, %g7)
David S. Miller74bf4312006-01-31 18:29:18 -080050
51 /* Load and check PTE. */
52 ldxa [%g5] ASI_PHYS_USE_EC, %g5
53 brgez,a,pn %g5, tsb_do_fault
David S. Miller517af332006-02-01 15:55:21 -080054 TSB_STORE(%g1, %g0)
David S. Miller74bf4312006-01-31 18:29:18 -080055
David S. Miller09f94282006-01-31 18:31:06 -080056 /* If it is larger than the base page size, don't
57 * bother putting it into the TSB.
58 */
David S. Millerc4bce902006-02-11 21:57:54 -080059 sethi %hi(_PAGE_ALL_SZ_BITS), %g7
60 ldx [%g7 + %lo(_PAGE_ALL_SZ_BITS)], %g7
61 and %g5, %g7, %g2
62 sethi %hi(_PAGE_SZBITS), %g7
63 ldx [%g7 + %lo(_PAGE_SZBITS)], %g7
David S. Miller09f94282006-01-31 18:31:06 -080064 cmp %g2, %g7
65 bne,a,pn %xcc, tsb_tlb_reload
David S. Miller517af332006-02-01 15:55:21 -080066 TSB_STORE(%g1, %g0)
David S. Miller09f94282006-01-31 18:31:06 -080067
David S. Miller74bf4312006-01-31 18:29:18 -080068 TSB_WRITE(%g1, %g5, %g6)
69
70 /* Finally, load TLB and return from trap. */
71tsb_tlb_reload:
72 cmp %g3, FAULT_CODE_DTLB
73 bne,pn %xcc, tsb_itlb_load
74 nop
75
76tsb_dtlb_load:
David S. Millerd257d5d2006-02-06 23:44:37 -080077
78661: stxa %g5, [%g0] ASI_DTLB_DATA_IN
David S. Miller74bf4312006-01-31 18:29:18 -080079 retry
David S. Millerdf7d6ae2006-02-07 00:00:16 -080080 .section .sun4v_2insn_patch, "ax"
David S. Millerd257d5d2006-02-06 23:44:37 -080081 .word 661b
82 nop
83 nop
84 .previous
85
86 /* For sun4v the ASI_DTLB_DATA_IN store and the retry
87 * instruction get nop'd out and we get here to branch
88 * to the sun4v tlb load code. The registers are setup
89 * as follows:
90 *
91 * %g4: vaddr
92 * %g5: PTE
93 * %g6: TAG
94 *
95 * The sun4v TLB load wants the PTE in %g3 so we fix that
96 * up here.
97 */
98 ba,pt %xcc, sun4v_dtlb_load
99 mov %g5, %g3
David S. Miller74bf4312006-01-31 18:29:18 -0800100
101tsb_itlb_load:
David S. Millerd257d5d2006-02-06 23:44:37 -0800102
103661: stxa %g5, [%g0] ASI_ITLB_DATA_IN
David S. Miller74bf4312006-01-31 18:29:18 -0800104 retry
David S. Millerdf7d6ae2006-02-07 00:00:16 -0800105 .section .sun4v_2insn_patch, "ax"
David S. Millerd257d5d2006-02-06 23:44:37 -0800106 .word 661b
107 nop
108 nop
109 .previous
110
111 /* For sun4v the ASI_ITLB_DATA_IN store and the retry
112 * instruction get nop'd out and we get here to branch
113 * to the sun4v tlb load code. The registers are setup
114 * as follows:
115 *
116 * %g4: vaddr
117 * %g5: PTE
118 * %g6: TAG
119 *
120 * The sun4v TLB load wants the PTE in %g3 so we fix that
121 * up here.
122 */
123 ba,pt %xcc, sun4v_itlb_load
124 mov %g5, %g3
David S. Miller74bf4312006-01-31 18:29:18 -0800125
126 /* No valid entry in the page tables, do full fault
127 * processing.
128 */
129
130 .globl tsb_do_fault
131tsb_do_fault:
132 cmp %g3, FAULT_CODE_DTLB
David S. Miller45fec052006-02-05 22:27:28 -0800133
134661: rdpr %pstate, %g5
135 wrpr %g5, PSTATE_AG | PSTATE_MG, %pstate
David S. Millerdf7d6ae2006-02-07 00:00:16 -0800136 .section .sun4v_2insn_patch, "ax"
David S. Miller45fec052006-02-05 22:27:28 -0800137 .word 661b
David S. Miller6c8927c2006-02-17 14:58:02 -0800138 SET_GL(1)
139 ldxa [%g0] ASI_SCRATCHPAD, %g2
David S. Miller45fec052006-02-05 22:27:28 -0800140 .previous
141
David S. Miller74bf4312006-01-31 18:29:18 -0800142 bne,pn %xcc, tsb_do_itlb_fault
David S. Miller45fec052006-02-05 22:27:28 -0800143 nop
David S. Miller74bf4312006-01-31 18:29:18 -0800144
145tsb_do_dtlb_fault:
David S. Millerd257d5d2006-02-06 23:44:37 -0800146 rdpr %tl, %g3
147 cmp %g3, 1
148
149661: mov TLB_TAG_ACCESS, %g4
David S. Miller74bf4312006-01-31 18:29:18 -0800150 ldxa [%g4] ASI_DMMU, %g5
David S. Millerdf7d6ae2006-02-07 00:00:16 -0800151 .section .sun4v_2insn_patch, "ax"
David S. Millerd257d5d2006-02-06 23:44:37 -0800152 .word 661b
David S. Miller6c8927c2006-02-17 14:58:02 -0800153 ldx [%g2 + HV_FAULT_D_ADDR_OFFSET], %g5
David S. Millerd257d5d2006-02-06 23:44:37 -0800154 nop
155 .previous
156
David S. Miller74bf4312006-01-31 18:29:18 -0800157 be,pt %xcc, sparc64_realfault_common
158 mov FAULT_CODE_DTLB, %g4
159 ba,pt %xcc, winfix_trampoline
160 nop
161
162tsb_do_itlb_fault:
163 rdpr %tpc, %g5
164 ba,pt %xcc, sparc64_realfault_common
165 mov FAULT_CODE_ITLB, %g4
166
167 .globl sparc64_realfault_common
168sparc64_realfault_common:
David S. Miller9bc657b2006-01-31 18:34:21 -0800169 /* fault code in %g4, fault address in %g5, etrap will
170 * preserve these two values in %l4 and %l5 respectively
171 */
David S. Miller74bf4312006-01-31 18:29:18 -0800172 ba,pt %xcc, etrap ! Save trap state
1731: rd %pc, %g7 ! ...
David S. Miller9bc657b2006-01-31 18:34:21 -0800174 stb %l4, [%g6 + TI_FAULT_CODE] ! Save fault code
175 stx %l5, [%g6 + TI_FAULT_ADDR] ! Save fault address
David S. Miller74bf4312006-01-31 18:29:18 -0800176 call do_sparc64_fault ! Call fault handler
177 add %sp, PTREGS_OFF, %o0 ! Compute pt_regs arg
178 ba,pt %xcc, rtrap_clr_l6 ! Restore cpu state
179 nop ! Delay slot (fill me)
180
David S. Miller74bf4312006-01-31 18:29:18 -0800181winfix_trampoline:
182 rdpr %tpc, %g3 ! Prepare winfixup TNPC
183 or %g3, 0x7c, %g3 ! Compute branch offset
184 wrpr %g3, %tnpc ! Write it into TNPC
185 done ! Trap return
186
David S. Millerb70c0fa2006-01-31 18:32:04 -0800187 /* Insert an entry into the TSB.
188 *
David S. Miller517af332006-02-01 15:55:21 -0800189 * %o0: TSB entry pointer (virt or phys address)
David S. Millerb70c0fa2006-01-31 18:32:04 -0800190 * %o1: tag
191 * %o2: pte
192 */
193 .align 32
David S. Miller517af332006-02-01 15:55:21 -0800194 .globl __tsb_insert
195__tsb_insert:
David S. Millerb70c0fa2006-01-31 18:32:04 -0800196 rdpr %pstate, %o5
197 wrpr %o5, PSTATE_IE, %pstate
198 TSB_LOCK_TAG(%o0, %g2, %g3)
199 TSB_WRITE(%o0, %o2, %o1)
200 wrpr %o5, %pstate
201 retl
202 nop
203
David S. Miller517af332006-02-01 15:55:21 -0800204 /* Flush the given TSB entry if it has the matching
205 * tag.
206 *
207 * %o0: TSB entry pointer (virt or phys address)
208 * %o1: tag
209 */
210 .align 32
211 .globl tsb_flush
212tsb_flush:
213 sethi %hi(TSB_TAG_LOCK_HIGH), %g2
2141: TSB_LOAD_TAG(%o0, %g1)
215 srlx %g1, 32, %o3
216 andcc %o3, %g2, %g0
217 bne,pn %icc, 1b
218 membar #LoadLoad
219 cmp %g1, %o1
220 bne,pt %xcc, 2f
221 clr %o3
222 TSB_CAS_TAG(%o0, %g1, %o3)
223 cmp %g1, %o3
224 bne,pn %xcc, 1b
225 nop
2262: retl
227 TSB_MEMBAR
228
David S. Miller74bf4312006-01-31 18:29:18 -0800229 /* Reload MMU related context switch state at
230 * schedule() time.
231 *
232 * %o0: page table physical address
David S. Miller98c55842006-01-31 18:31:20 -0800233 * %o1: TSB register value
234 * %o2: TSB virtual address
235 * %o3: TSB mapping locked PTE
David S. Miller618e9ed2006-02-09 17:21:53 -0800236 * %o4: Hypervisor TSB descriptor physical address
David S. Miller98c55842006-01-31 18:31:20 -0800237 *
238 * We have to run this whole thing with interrupts
239 * disabled so that the current cpu doesn't change
240 * due to preemption.
David S. Miller74bf4312006-01-31 18:29:18 -0800241 */
David S. Miller56fb4df2006-02-26 23:24:22 -0800242 .align 32
David S. Miller98c55842006-01-31 18:31:20 -0800243 .globl __tsb_context_switch
244__tsb_context_switch:
David S. Miller56fb4df2006-02-26 23:24:22 -0800245 rdpr %pstate, %o5
246 wrpr %o5, PSTATE_IE, %pstate
David S. Miller74bf4312006-01-31 18:29:18 -0800247
David S. Miller98c55842006-01-31 18:31:20 -0800248 ldub [%g6 + TI_CPU], %g1
249 sethi %hi(trap_block), %g2
250 sllx %g1, TRAP_BLOCK_SZ_SHIFT, %g1
251 or %g2, %lo(trap_block), %g2
252 add %g2, %g1, %g2
253 stx %o0, [%g2 + TRAP_PER_CPU_PGD_PADDR]
David S. Miller74bf4312006-01-31 18:29:18 -0800254
David S. Miller618e9ed2006-02-09 17:21:53 -0800255 sethi %hi(tlb_type), %g1
256 lduw [%g1 + %lo(tlb_type)], %g1
257 cmp %g1, 3
258 bne,pt %icc, 1f
David S. Miller98c55842006-01-31 18:31:20 -0800259 nop
David S. Miller74bf4312006-01-31 18:29:18 -0800260
David S. Miller618e9ed2006-02-09 17:21:53 -0800261 /* Hypervisor TSB switch. */
262 mov SCRATCHPAD_UTSBREG1, %g1
263 stxa %o1, [%g1] ASI_SCRATCHPAD
264 mov -1, %g2
265 mov SCRATCHPAD_UTSBREG2, %g1
266 stxa %g2, [%g1] ASI_SCRATCHPAD
267
David S. Millera7b31ba2006-02-15 21:16:42 -0800268 /* Save away %o5's %pstate, we have to use %o5 for
269 * the hypervisor call.
270 */
271 mov %o5, %g1
272
David S. Miller164c2202006-02-09 22:57:21 -0800273 mov HV_FAST_MMU_TSB_CTXNON0, %o5
274 mov 1, %o0
275 mov %o4, %o1
David S. Miller618e9ed2006-02-09 17:21:53 -0800276 ta HV_FAST_TRAP
277
David S. Millera7b31ba2006-02-15 21:16:42 -0800278 /* Finish up and restore %o5. */
David S. Miller618e9ed2006-02-09 17:21:53 -0800279 ba,pt %xcc, 9f
David S. Millera7b31ba2006-02-15 21:16:42 -0800280 mov %g1, %o5
David S. Miller618e9ed2006-02-09 17:21:53 -0800281
282 /* SUN4U TSB switch. */
2831: mov TSB_REG, %g1
284 stxa %o1, [%g1] ASI_DMMU
285 membar #Sync
286 stxa %o1, [%g1] ASI_IMMU
287 membar #Sync
288
2892: brz %o2, 9f
290 nop
291
292 sethi %hi(sparc64_highest_unlocked_tlb_ent), %g2
David S. Miller6b6d0172006-01-31 18:33:12 -0800293 mov TLB_TAG_ACCESS, %g1
David S. Miller618e9ed2006-02-09 17:21:53 -0800294 lduw [%g2 + %lo(sparc64_highest_unlocked_tlb_ent)], %g2
David S. Miller6b6d0172006-01-31 18:33:12 -0800295 stxa %o2, [%g1] ASI_DMMU
296 membar #Sync
297 sllx %g2, 3, %g2
298 stxa %o3, [%g2] ASI_DTLB_DATA_ACCESS
299 membar #Sync
David S. Miller74bf4312006-01-31 18:29:18 -08003009:
David S. Miller56fb4df2006-02-26 23:24:22 -0800301 wrpr %o5, %pstate
David S. Miller74bf4312006-01-31 18:29:18 -0800302
303 retl
David S. Miller98c55842006-01-31 18:31:20 -0800304 nop