blob: 818bc9e9135a6d56e67acbb311bf2f1ab1948a0f [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>
7
8 .text
9 .align 32
10
11 /* Invoked from TLB miss handler, we are in the
12 * MMU global registers and they are setup like
13 * this:
14 *
15 * %g1: TSB entry pointer
16 * %g2: available temporary
17 * %g3: FAULT_CODE_{D,I}TLB
18 * %g4: available temporary
19 * %g5: available temporary
20 * %g6: TAG TARGET
David S. Millerd257d5d2006-02-06 23:44:37 -080021 * %g7: available temporary, will be loaded by us with
22 * the physical address base of the linux page
David S. Miller74bf4312006-01-31 18:29:18 -080023 * tables for the current address space
24 */
David S. Miller74bf4312006-01-31 18:29:18 -080025tsb_miss_dtlb:
26 mov TLB_TAG_ACCESS, %g4
27 ldxa [%g4] ASI_DMMU, %g4
28 ba,pt %xcc, tsb_miss_page_table_walk
29 nop
30
David S. Miller74bf4312006-01-31 18:29:18 -080031tsb_miss_itlb:
32 mov TLB_TAG_ACCESS, %g4
33 ldxa [%g4] ASI_IMMU, %g4
34 ba,pt %xcc, tsb_miss_page_table_walk
35 nop
36
David S. Millerd257d5d2006-02-06 23:44:37 -080037 /* The sun4v TLB miss handlers jump directly here instead
38 * of tsb_miss_{d,i}tlb with the missing virtual address
39 * already loaded into %g4.
40 */
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. Miller74bf4312006-01-31 18:29:18 -080044 USER_PGTABLE_WALK_TL1(%g4, %g7, %g5, %g2, tsb_do_fault)
45
46tsb_reload:
David S. Millerd257d5d2006-02-06 23:44:37 -080047 TSB_LOCK_TAG(%g1, %g2, %g7)
David S. Miller74bf4312006-01-31 18:29:18 -080048
49 /* Load and check PTE. */
50 ldxa [%g5] ASI_PHYS_USE_EC, %g5
51 brgez,a,pn %g5, tsb_do_fault
David S. Miller517af332006-02-01 15:55:21 -080052 TSB_STORE(%g1, %g0)
David S. Miller74bf4312006-01-31 18:29:18 -080053
David S. Miller09f94282006-01-31 18:31:06 -080054 /* If it is larger than the base page size, don't
55 * bother putting it into the TSB.
56 */
57 srlx %g5, 32, %g2
David S. Millerd257d5d2006-02-06 23:44:37 -080058 sethi %hi(_PAGE_ALL_SZ_BITS >> 32), %g7
59 and %g2, %g7, %g2
David S. Miller09f94282006-01-31 18:31:06 -080060 sethi %hi(_PAGE_SZBITS >> 32), %g7
David S. Miller09f94282006-01-31 18:31:06 -080061 cmp %g2, %g7
62 bne,a,pn %xcc, tsb_tlb_reload
David S. Miller517af332006-02-01 15:55:21 -080063 TSB_STORE(%g1, %g0)
David S. Miller09f94282006-01-31 18:31:06 -080064
David S. Miller74bf4312006-01-31 18:29:18 -080065 TSB_WRITE(%g1, %g5, %g6)
66
67 /* Finally, load TLB and return from trap. */
68tsb_tlb_reload:
69 cmp %g3, FAULT_CODE_DTLB
70 bne,pn %xcc, tsb_itlb_load
71 nop
72
73tsb_dtlb_load:
David S. Millerd257d5d2006-02-06 23:44:37 -080074
75661: stxa %g5, [%g0] ASI_DTLB_DATA_IN
David S. Miller74bf4312006-01-31 18:29:18 -080076 retry
David S. Millerd257d5d2006-02-06 23:44:37 -080077 .section .gl_2insn_patch, "ax"
78 .word 661b
79 nop
80 nop
81 .previous
82
83 /* For sun4v the ASI_DTLB_DATA_IN store and the retry
84 * instruction get nop'd out and we get here to branch
85 * to the sun4v tlb load code. The registers are setup
86 * as follows:
87 *
88 * %g4: vaddr
89 * %g5: PTE
90 * %g6: TAG
91 *
92 * The sun4v TLB load wants the PTE in %g3 so we fix that
93 * up here.
94 */
95 ba,pt %xcc, sun4v_dtlb_load
96 mov %g5, %g3
David S. Miller74bf4312006-01-31 18:29:18 -080097
98tsb_itlb_load:
David S. Millerd257d5d2006-02-06 23:44:37 -080099
100661: stxa %g5, [%g0] ASI_ITLB_DATA_IN
David S. Miller74bf4312006-01-31 18:29:18 -0800101 retry
David S. Millerd257d5d2006-02-06 23:44:37 -0800102 .section .gl_2insn_patch, "ax"
103 .word 661b
104 nop
105 nop
106 .previous
107
108 /* For sun4v the ASI_ITLB_DATA_IN store and the retry
109 * instruction get nop'd out and we get here to branch
110 * to the sun4v tlb load code. The registers are setup
111 * as follows:
112 *
113 * %g4: vaddr
114 * %g5: PTE
115 * %g6: TAG
116 *
117 * The sun4v TLB load wants the PTE in %g3 so we fix that
118 * up here.
119 */
120 ba,pt %xcc, sun4v_itlb_load
121 mov %g5, %g3
David S. Miller74bf4312006-01-31 18:29:18 -0800122
123 /* No valid entry in the page tables, do full fault
124 * processing.
125 */
126
127 .globl tsb_do_fault
128tsb_do_fault:
129 cmp %g3, FAULT_CODE_DTLB
David S. Miller45fec052006-02-05 22:27:28 -0800130
131661: rdpr %pstate, %g5
132 wrpr %g5, PSTATE_AG | PSTATE_MG, %pstate
133 .section .gl_2insn_patch, "ax"
134 .word 661b
135 nop
136 nop
137 .previous
138
David S. Miller74bf4312006-01-31 18:29:18 -0800139 bne,pn %xcc, tsb_do_itlb_fault
David S. Miller45fec052006-02-05 22:27:28 -0800140 nop
David S. Miller74bf4312006-01-31 18:29:18 -0800141
142tsb_do_dtlb_fault:
David S. Millerd257d5d2006-02-06 23:44:37 -0800143 rdpr %tl, %g3
144 cmp %g3, 1
145
146661: mov TLB_TAG_ACCESS, %g4
David S. Miller74bf4312006-01-31 18:29:18 -0800147 ldxa [%g4] ASI_DMMU, %g5
David S. Millerd257d5d2006-02-06 23:44:37 -0800148 .section .gl_2insn_patch, "ax"
149 .word 661b
150 mov %g4, %g5
151 nop
152 .previous
153
David S. Miller74bf4312006-01-31 18:29:18 -0800154 be,pt %xcc, sparc64_realfault_common
155 mov FAULT_CODE_DTLB, %g4
156 ba,pt %xcc, winfix_trampoline
157 nop
158
159tsb_do_itlb_fault:
160 rdpr %tpc, %g5
161 ba,pt %xcc, sparc64_realfault_common
162 mov FAULT_CODE_ITLB, %g4
163
164 .globl sparc64_realfault_common
165sparc64_realfault_common:
David S. Miller9bc657b2006-01-31 18:34:21 -0800166 /* fault code in %g4, fault address in %g5, etrap will
167 * preserve these two values in %l4 and %l5 respectively
168 */
David S. Miller74bf4312006-01-31 18:29:18 -0800169 ba,pt %xcc, etrap ! Save trap state
1701: rd %pc, %g7 ! ...
David S. Miller9bc657b2006-01-31 18:34:21 -0800171 stb %l4, [%g6 + TI_FAULT_CODE] ! Save fault code
172 stx %l5, [%g6 + TI_FAULT_ADDR] ! Save fault address
David S. Miller74bf4312006-01-31 18:29:18 -0800173 call do_sparc64_fault ! Call fault handler
174 add %sp, PTREGS_OFF, %o0 ! Compute pt_regs arg
175 ba,pt %xcc, rtrap_clr_l6 ! Restore cpu state
176 nop ! Delay slot (fill me)
177
David S. Miller74bf4312006-01-31 18:29:18 -0800178winfix_trampoline:
179 rdpr %tpc, %g3 ! Prepare winfixup TNPC
180 or %g3, 0x7c, %g3 ! Compute branch offset
181 wrpr %g3, %tnpc ! Write it into TNPC
182 done ! Trap return
183
David S. Millerb70c0fa2006-01-31 18:32:04 -0800184 /* Insert an entry into the TSB.
185 *
David S. Miller517af332006-02-01 15:55:21 -0800186 * %o0: TSB entry pointer (virt or phys address)
David S. Millerb70c0fa2006-01-31 18:32:04 -0800187 * %o1: tag
188 * %o2: pte
189 */
190 .align 32
David S. Miller517af332006-02-01 15:55:21 -0800191 .globl __tsb_insert
192__tsb_insert:
David S. Millerb70c0fa2006-01-31 18:32:04 -0800193 rdpr %pstate, %o5
194 wrpr %o5, PSTATE_IE, %pstate
195 TSB_LOCK_TAG(%o0, %g2, %g3)
196 TSB_WRITE(%o0, %o2, %o1)
197 wrpr %o5, %pstate
198 retl
199 nop
200
David S. Miller517af332006-02-01 15:55:21 -0800201 /* Flush the given TSB entry if it has the matching
202 * tag.
203 *
204 * %o0: TSB entry pointer (virt or phys address)
205 * %o1: tag
206 */
207 .align 32
208 .globl tsb_flush
209tsb_flush:
210 sethi %hi(TSB_TAG_LOCK_HIGH), %g2
2111: TSB_LOAD_TAG(%o0, %g1)
212 srlx %g1, 32, %o3
213 andcc %o3, %g2, %g0
214 bne,pn %icc, 1b
215 membar #LoadLoad
216 cmp %g1, %o1
217 bne,pt %xcc, 2f
218 clr %o3
219 TSB_CAS_TAG(%o0, %g1, %o3)
220 cmp %g1, %o3
221 bne,pn %xcc, 1b
222 nop
2232: retl
224 TSB_MEMBAR
225
David S. Miller74bf4312006-01-31 18:29:18 -0800226 /* Reload MMU related context switch state at
227 * schedule() time.
228 *
229 * %o0: page table physical address
David S. Miller98c55842006-01-31 18:31:20 -0800230 * %o1: TSB register value
231 * %o2: TSB virtual address
232 * %o3: TSB mapping locked PTE
233 *
234 * We have to run this whole thing with interrupts
235 * disabled so that the current cpu doesn't change
236 * due to preemption.
David S. Miller74bf4312006-01-31 18:29:18 -0800237 */
David S. Miller56fb4df2006-02-26 23:24:22 -0800238 .align 32
David S. Miller98c55842006-01-31 18:31:20 -0800239 .globl __tsb_context_switch
240__tsb_context_switch:
David S. Miller56fb4df2006-02-26 23:24:22 -0800241 rdpr %pstate, %o5
242 wrpr %o5, PSTATE_IE, %pstate
David S. Miller74bf4312006-01-31 18:29:18 -0800243
David S. Miller98c55842006-01-31 18:31:20 -0800244 ldub [%g6 + TI_CPU], %g1
245 sethi %hi(trap_block), %g2
246 sllx %g1, TRAP_BLOCK_SZ_SHIFT, %g1
247 or %g2, %lo(trap_block), %g2
248 add %g2, %g1, %g2
249 stx %o0, [%g2 + TRAP_PER_CPU_PGD_PADDR]
David S. Miller74bf4312006-01-31 18:29:18 -0800250
David S. Millerd257d5d2006-02-06 23:44:37 -0800251661: mov TSB_REG, %g1
David S. Miller98c55842006-01-31 18:31:20 -0800252 stxa %o1, [%g1] ASI_DMMU
David S. Millerd257d5d2006-02-06 23:44:37 -0800253 .section .gl_2insn_patch, "ax"
254 .word 661b
255 mov SCRATCHPAD_UTSBREG1, %g1
256 stxa %o1, [%g1] ASI_SCRATCHPAD
257 .previous
258
David S. Miller74bf4312006-01-31 18:29:18 -0800259 membar #Sync
260
David S. Millerd257d5d2006-02-06 23:44:37 -0800261661: stxa %o1, [%g1] ASI_IMMU
David S. Miller74bf4312006-01-31 18:29:18 -0800262 membar #Sync
David S. Millerd257d5d2006-02-06 23:44:37 -0800263 .section .gl_2insn_patch, "ax"
264 .word 661b
265 nop
266 nop
267 .previous
David S. Miller74bf4312006-01-31 18:29:18 -0800268
David S. Miller98c55842006-01-31 18:31:20 -0800269 brz %o2, 9f
270 nop
David S. Miller74bf4312006-01-31 18:29:18 -0800271
David S. Miller6b6d0172006-01-31 18:33:12 -0800272 sethi %hi(sparc64_highest_unlocked_tlb_ent), %o4
273 mov TLB_TAG_ACCESS, %g1
274 lduw [%o4 + %lo(sparc64_highest_unlocked_tlb_ent)], %g2
275 stxa %o2, [%g1] ASI_DMMU
276 membar #Sync
277 sllx %g2, 3, %g2
278 stxa %o3, [%g2] ASI_DTLB_DATA_ACCESS
279 membar #Sync
David S. Miller74bf4312006-01-31 18:29:18 -08002809:
David S. Miller56fb4df2006-02-26 23:24:22 -0800281 wrpr %o5, %pstate
David S. Miller74bf4312006-01-31 18:29:18 -0800282
283 retl
David S. Miller98c55842006-01-31 18:31:20 -0800284 nop