blob: 8a9351258af8829277e19de58ec9a5f49352f5b1 [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
28 ldxa [%g4] ASI_DMMU, %g4
29 ba,pt %xcc, tsb_miss_page_table_walk
30 nop
31
David S. Miller74bf4312006-01-31 18:29:18 -080032tsb_miss_itlb:
33 mov TLB_TAG_ACCESS, %g4
34 ldxa [%g4] ASI_IMMU, %g4
35 ba,pt %xcc, tsb_miss_page_table_walk
36 nop
37
David S. Millerd257d5d2006-02-06 23:44:37 -080038 /* The sun4v TLB miss handlers jump directly here instead
David S. Milleraa9143b2006-02-09 16:12:22 -080039 * of tsb_miss_{d,i}tlb with registers setup as follows:
40 *
41 * %g4: missing virtual address
42 * %g1: TSB entry address loaded
43 * %g6: TAG TARGET ((vaddr >> 22) | (ctx << 48))
David S. Millerd257d5d2006-02-06 23:44:37 -080044 */
David S. Miller74bf4312006-01-31 18:29:18 -080045tsb_miss_page_table_walk:
David S. Millerffe483d2006-02-02 21:55:10 -080046 TRAP_LOAD_PGD_PHYS(%g7, %g5)
David S. Miller56fb4df2006-02-26 23:24:22 -080047
David S. Miller74bf4312006-01-31 18:29:18 -080048 USER_PGTABLE_WALK_TL1(%g4, %g7, %g5, %g2, tsb_do_fault)
49
50tsb_reload:
David S. Millerd257d5d2006-02-06 23:44:37 -080051 TSB_LOCK_TAG(%g1, %g2, %g7)
David S. Miller74bf4312006-01-31 18:29:18 -080052
53 /* Load and check PTE. */
54 ldxa [%g5] ASI_PHYS_USE_EC, %g5
55 brgez,a,pn %g5, tsb_do_fault
David S. Miller517af332006-02-01 15:55:21 -080056 TSB_STORE(%g1, %g0)
David S. Miller74bf4312006-01-31 18:29:18 -080057
David S. Miller09f94282006-01-31 18:31:06 -080058 /* If it is larger than the base page size, don't
59 * bother putting it into the TSB.
60 */
61 srlx %g5, 32, %g2
David S. Millerd257d5d2006-02-06 23:44:37 -080062 sethi %hi(_PAGE_ALL_SZ_BITS >> 32), %g7
63 and %g2, %g7, %g2
David S. Miller09f94282006-01-31 18:31:06 -080064 sethi %hi(_PAGE_SZBITS >> 32), %g7
David S. Miller09f94282006-01-31 18:31:06 -080065 cmp %g2, %g7
66 bne,a,pn %xcc, tsb_tlb_reload
David S. Miller517af332006-02-01 15:55:21 -080067 TSB_STORE(%g1, %g0)
David S. Miller09f94282006-01-31 18:31:06 -080068
David S. Miller74bf4312006-01-31 18:29:18 -080069 TSB_WRITE(%g1, %g5, %g6)
70
71 /* Finally, load TLB and return from trap. */
72tsb_tlb_reload:
73 cmp %g3, FAULT_CODE_DTLB
74 bne,pn %xcc, tsb_itlb_load
75 nop
76
77tsb_dtlb_load:
David S. Millerd257d5d2006-02-06 23:44:37 -080078
79661: stxa %g5, [%g0] ASI_DTLB_DATA_IN
David S. Miller74bf4312006-01-31 18:29:18 -080080 retry
David S. Millerdf7d6ae2006-02-07 00:00:16 -080081 .section .sun4v_2insn_patch, "ax"
David S. Millerd257d5d2006-02-06 23:44:37 -080082 .word 661b
83 nop
84 nop
85 .previous
86
87 /* For sun4v the ASI_DTLB_DATA_IN store and the retry
88 * instruction get nop'd out and we get here to branch
89 * to the sun4v tlb load code. The registers are setup
90 * as follows:
91 *
92 * %g4: vaddr
93 * %g5: PTE
94 * %g6: TAG
95 *
96 * The sun4v TLB load wants the PTE in %g3 so we fix that
97 * up here.
98 */
99 ba,pt %xcc, sun4v_dtlb_load
100 mov %g5, %g3
David S. Miller74bf4312006-01-31 18:29:18 -0800101
102tsb_itlb_load:
David S. Millerd257d5d2006-02-06 23:44:37 -0800103
104661: stxa %g5, [%g0] ASI_ITLB_DATA_IN
David S. Miller74bf4312006-01-31 18:29:18 -0800105 retry
David S. Millerdf7d6ae2006-02-07 00:00:16 -0800106 .section .sun4v_2insn_patch, "ax"
David S. Millerd257d5d2006-02-06 23:44:37 -0800107 .word 661b
108 nop
109 nop
110 .previous
111
112 /* For sun4v the ASI_ITLB_DATA_IN store and the retry
113 * instruction get nop'd out and we get here to branch
114 * to the sun4v tlb load code. The registers are setup
115 * as follows:
116 *
117 * %g4: vaddr
118 * %g5: PTE
119 * %g6: TAG
120 *
121 * The sun4v TLB load wants the PTE in %g3 so we fix that
122 * up here.
123 */
124 ba,pt %xcc, sun4v_itlb_load
125 mov %g5, %g3
David S. Miller74bf4312006-01-31 18:29:18 -0800126
127 /* No valid entry in the page tables, do full fault
128 * processing.
129 */
130
131 .globl tsb_do_fault
132tsb_do_fault:
133 cmp %g3, FAULT_CODE_DTLB
David S. Miller45fec052006-02-05 22:27:28 -0800134
135661: rdpr %pstate, %g5
136 wrpr %g5, PSTATE_AG | PSTATE_MG, %pstate
David S. Millerdf7d6ae2006-02-07 00:00:16 -0800137 .section .sun4v_2insn_patch, "ax"
David S. Miller45fec052006-02-05 22:27:28 -0800138 .word 661b
139 nop
140 nop
141 .previous
142
David S. Miller74bf4312006-01-31 18:29:18 -0800143 bne,pn %xcc, tsb_do_itlb_fault
David S. Miller45fec052006-02-05 22:27:28 -0800144 nop
David S. Miller74bf4312006-01-31 18:29:18 -0800145
146tsb_do_dtlb_fault:
David S. Millerd257d5d2006-02-06 23:44:37 -0800147 rdpr %tl, %g3
148 cmp %g3, 1
149
150661: mov TLB_TAG_ACCESS, %g4
David S. Miller74bf4312006-01-31 18:29:18 -0800151 ldxa [%g4] ASI_DMMU, %g5
David S. Millerdf7d6ae2006-02-07 00:00:16 -0800152 .section .sun4v_2insn_patch, "ax"
David S. Millerd257d5d2006-02-06 23:44:37 -0800153 .word 661b
154 mov %g4, %g5
155 nop
156 .previous
157
David S. Miller74bf4312006-01-31 18:29:18 -0800158 be,pt %xcc, sparc64_realfault_common
159 mov FAULT_CODE_DTLB, %g4
160 ba,pt %xcc, winfix_trampoline
161 nop
162
163tsb_do_itlb_fault:
164 rdpr %tpc, %g5
165 ba,pt %xcc, sparc64_realfault_common
166 mov FAULT_CODE_ITLB, %g4
167
168 .globl sparc64_realfault_common
169sparc64_realfault_common:
David S. Miller9bc657b2006-01-31 18:34:21 -0800170 /* fault code in %g4, fault address in %g5, etrap will
171 * preserve these two values in %l4 and %l5 respectively
172 */
David S. Miller74bf4312006-01-31 18:29:18 -0800173 ba,pt %xcc, etrap ! Save trap state
1741: rd %pc, %g7 ! ...
David S. Miller9bc657b2006-01-31 18:34:21 -0800175 stb %l4, [%g6 + TI_FAULT_CODE] ! Save fault code
176 stx %l5, [%g6 + TI_FAULT_ADDR] ! Save fault address
David S. Miller74bf4312006-01-31 18:29:18 -0800177 call do_sparc64_fault ! Call fault handler
178 add %sp, PTREGS_OFF, %o0 ! Compute pt_regs arg
179 ba,pt %xcc, rtrap_clr_l6 ! Restore cpu state
180 nop ! Delay slot (fill me)
181
David S. Miller74bf4312006-01-31 18:29:18 -0800182winfix_trampoline:
183 rdpr %tpc, %g3 ! Prepare winfixup TNPC
184 or %g3, 0x7c, %g3 ! Compute branch offset
185 wrpr %g3, %tnpc ! Write it into TNPC
186 done ! Trap return
187
David S. Millerb70c0fa2006-01-31 18:32:04 -0800188 /* Insert an entry into the TSB.
189 *
David S. Miller517af332006-02-01 15:55:21 -0800190 * %o0: TSB entry pointer (virt or phys address)
David S. Millerb70c0fa2006-01-31 18:32:04 -0800191 * %o1: tag
192 * %o2: pte
193 */
194 .align 32
David S. Miller517af332006-02-01 15:55:21 -0800195 .globl __tsb_insert
196__tsb_insert:
David S. Millerb70c0fa2006-01-31 18:32:04 -0800197 rdpr %pstate, %o5
198 wrpr %o5, PSTATE_IE, %pstate
199 TSB_LOCK_TAG(%o0, %g2, %g3)
200 TSB_WRITE(%o0, %o2, %o1)
201 wrpr %o5, %pstate
202 retl
203 nop
204
David S. Miller517af332006-02-01 15:55:21 -0800205 /* Flush the given TSB entry if it has the matching
206 * tag.
207 *
208 * %o0: TSB entry pointer (virt or phys address)
209 * %o1: tag
210 */
211 .align 32
212 .globl tsb_flush
213tsb_flush:
214 sethi %hi(TSB_TAG_LOCK_HIGH), %g2
2151: TSB_LOAD_TAG(%o0, %g1)
216 srlx %g1, 32, %o3
217 andcc %o3, %g2, %g0
218 bne,pn %icc, 1b
219 membar #LoadLoad
220 cmp %g1, %o1
221 bne,pt %xcc, 2f
222 clr %o3
223 TSB_CAS_TAG(%o0, %g1, %o3)
224 cmp %g1, %o3
225 bne,pn %xcc, 1b
226 nop
2272: retl
228 TSB_MEMBAR
229
David S. Miller74bf4312006-01-31 18:29:18 -0800230 /* Reload MMU related context switch state at
231 * schedule() time.
232 *
233 * %o0: page table physical address
David S. Miller98c55842006-01-31 18:31:20 -0800234 * %o1: TSB register value
235 * %o2: TSB virtual address
236 * %o3: TSB mapping locked PTE
David S. Miller618e9ed2006-02-09 17:21:53 -0800237 * %o4: Hypervisor TSB descriptor physical address
David S. Miller98c55842006-01-31 18:31:20 -0800238 *
239 * We have to run this whole thing with interrupts
240 * disabled so that the current cpu doesn't change
241 * due to preemption.
David S. Miller74bf4312006-01-31 18:29:18 -0800242 */
David S. Miller56fb4df2006-02-26 23:24:22 -0800243 .align 32
David S. Miller98c55842006-01-31 18:31:20 -0800244 .globl __tsb_context_switch
245__tsb_context_switch:
David S. Miller56fb4df2006-02-26 23:24:22 -0800246 rdpr %pstate, %o5
247 wrpr %o5, PSTATE_IE, %pstate
David S. Miller74bf4312006-01-31 18:29:18 -0800248
David S. Miller98c55842006-01-31 18:31:20 -0800249 ldub [%g6 + TI_CPU], %g1
250 sethi %hi(trap_block), %g2
251 sllx %g1, TRAP_BLOCK_SZ_SHIFT, %g1
252 or %g2, %lo(trap_block), %g2
253 add %g2, %g1, %g2
254 stx %o0, [%g2 + TRAP_PER_CPU_PGD_PADDR]
David S. Miller74bf4312006-01-31 18:29:18 -0800255
David S. Miller618e9ed2006-02-09 17:21:53 -0800256 sethi %hi(tlb_type), %g1
257 lduw [%g1 + %lo(tlb_type)], %g1
258 cmp %g1, 3
259 bne,pt %icc, 1f
David S. Miller98c55842006-01-31 18:31:20 -0800260 nop
David S. Miller74bf4312006-01-31 18:29:18 -0800261
David S. Miller618e9ed2006-02-09 17:21:53 -0800262 /* Hypervisor TSB switch. */
263 mov SCRATCHPAD_UTSBREG1, %g1
264 stxa %o1, [%g1] ASI_SCRATCHPAD
265 mov -1, %g2
266 mov SCRATCHPAD_UTSBREG2, %g1
267 stxa %g2, [%g1] ASI_SCRATCHPAD
268
David S. Miller164c2202006-02-09 22:57:21 -0800269 mov HV_FAST_MMU_TSB_CTXNON0, %o5
270 mov 1, %o0
271 mov %o4, %o1
David S. Miller618e9ed2006-02-09 17:21:53 -0800272 ta HV_FAST_TRAP
273
274 ba,pt %xcc, 9f
275 nop
276
277 /* SUN4U TSB switch. */
2781: mov TSB_REG, %g1
279 stxa %o1, [%g1] ASI_DMMU
280 membar #Sync
281 stxa %o1, [%g1] ASI_IMMU
282 membar #Sync
283
2842: brz %o2, 9f
285 nop
286
287 sethi %hi(sparc64_highest_unlocked_tlb_ent), %g2
David S. Miller6b6d0172006-01-31 18:33:12 -0800288 mov TLB_TAG_ACCESS, %g1
David S. Miller618e9ed2006-02-09 17:21:53 -0800289 lduw [%g2 + %lo(sparc64_highest_unlocked_tlb_ent)], %g2
David S. Miller6b6d0172006-01-31 18:33:12 -0800290 stxa %o2, [%g1] ASI_DMMU
291 membar #Sync
292 sllx %g2, 3, %g2
293 stxa %o3, [%g2] ASI_DTLB_DATA_ACCESS
294 membar #Sync
David S. Miller74bf4312006-01-31 18:29:18 -08002959:
David S. Miller56fb4df2006-02-26 23:24:22 -0800296 wrpr %o5, %pstate
David S. Miller74bf4312006-01-31 18:29:18 -0800297
298 retl
David S. Miller98c55842006-01-31 18:31:20 -0800299 nop