blob: 667dcb077be78db3a62c21c010516230ee9dda39 [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 */
59 srlx %g5, 32, %g2
David S. Millerd257d5d2006-02-06 23:44:37 -080060 sethi %hi(_PAGE_ALL_SZ_BITS >> 32), %g7
61 and %g2, %g7, %g2
David S. Miller09f94282006-01-31 18:31:06 -080062 sethi %hi(_PAGE_SZBITS >> 32), %g7
David S. Miller09f94282006-01-31 18:31:06 -080063 cmp %g2, %g7
64 bne,a,pn %xcc, tsb_tlb_reload
David S. Miller517af332006-02-01 15:55:21 -080065 TSB_STORE(%g1, %g0)
David S. Miller09f94282006-01-31 18:31:06 -080066
David S. Miller74bf4312006-01-31 18:29:18 -080067 TSB_WRITE(%g1, %g5, %g6)
68
69 /* Finally, load TLB and return from trap. */
70tsb_tlb_reload:
71 cmp %g3, FAULT_CODE_DTLB
72 bne,pn %xcc, tsb_itlb_load
73 nop
74
75tsb_dtlb_load:
David S. Millerd257d5d2006-02-06 23:44:37 -080076
77661: stxa %g5, [%g0] ASI_DTLB_DATA_IN
David S. Miller74bf4312006-01-31 18:29:18 -080078 retry
David S. Millerdf7d6ae2006-02-07 00:00:16 -080079 .section .sun4v_2insn_patch, "ax"
David S. Millerd257d5d2006-02-06 23:44:37 -080080 .word 661b
81 nop
82 nop
83 .previous
84
85 /* For sun4v the ASI_DTLB_DATA_IN store and the retry
86 * instruction get nop'd out and we get here to branch
87 * to the sun4v tlb load code. The registers are setup
88 * as follows:
89 *
90 * %g4: vaddr
91 * %g5: PTE
92 * %g6: TAG
93 *
94 * The sun4v TLB load wants the PTE in %g3 so we fix that
95 * up here.
96 */
97 ba,pt %xcc, sun4v_dtlb_load
98 mov %g5, %g3
David S. Miller74bf4312006-01-31 18:29:18 -080099
100tsb_itlb_load:
David S. Millerd257d5d2006-02-06 23:44:37 -0800101
102661: stxa %g5, [%g0] ASI_ITLB_DATA_IN
David S. Miller74bf4312006-01-31 18:29:18 -0800103 retry
David S. Millerdf7d6ae2006-02-07 00:00:16 -0800104 .section .sun4v_2insn_patch, "ax"
David S. Millerd257d5d2006-02-06 23:44:37 -0800105 .word 661b
106 nop
107 nop
108 .previous
109
110 /* For sun4v the ASI_ITLB_DATA_IN store and the retry
111 * instruction get nop'd out and we get here to branch
112 * to the sun4v tlb load code. The registers are setup
113 * as follows:
114 *
115 * %g4: vaddr
116 * %g5: PTE
117 * %g6: TAG
118 *
119 * The sun4v TLB load wants the PTE in %g3 so we fix that
120 * up here.
121 */
122 ba,pt %xcc, sun4v_itlb_load
123 mov %g5, %g3
David S. Miller74bf4312006-01-31 18:29:18 -0800124
125 /* No valid entry in the page tables, do full fault
126 * processing.
127 */
128
129 .globl tsb_do_fault
130tsb_do_fault:
131 cmp %g3, FAULT_CODE_DTLB
David S. Miller45fec052006-02-05 22:27:28 -0800132
133661: rdpr %pstate, %g5
134 wrpr %g5, PSTATE_AG | PSTATE_MG, %pstate
David S. Millerdf7d6ae2006-02-07 00:00:16 -0800135 .section .sun4v_2insn_patch, "ax"
David S. Miller45fec052006-02-05 22:27:28 -0800136 .word 661b
137 nop
138 nop
139 .previous
140
David S. Miller74bf4312006-01-31 18:29:18 -0800141 bne,pn %xcc, tsb_do_itlb_fault
David S. Miller45fec052006-02-05 22:27:28 -0800142 nop
David S. Miller74bf4312006-01-31 18:29:18 -0800143
144tsb_do_dtlb_fault:
David S. Millerd257d5d2006-02-06 23:44:37 -0800145 rdpr %tl, %g3
146 cmp %g3, 1
147
148661: mov TLB_TAG_ACCESS, %g4
David S. Miller74bf4312006-01-31 18:29:18 -0800149 ldxa [%g4] ASI_DMMU, %g5
David S. Millerdf7d6ae2006-02-07 00:00:16 -0800150 .section .sun4v_2insn_patch, "ax"
David S. Millerd257d5d2006-02-06 23:44:37 -0800151 .word 661b
152 mov %g4, %g5
153 nop
154 .previous
155
David S. Miller74bf4312006-01-31 18:29:18 -0800156 be,pt %xcc, sparc64_realfault_common
157 mov FAULT_CODE_DTLB, %g4
158 ba,pt %xcc, winfix_trampoline
159 nop
160
161tsb_do_itlb_fault:
162 rdpr %tpc, %g5
163 ba,pt %xcc, sparc64_realfault_common
164 mov FAULT_CODE_ITLB, %g4
165
166 .globl sparc64_realfault_common
167sparc64_realfault_common:
David S. Miller9bc657b2006-01-31 18:34:21 -0800168 /* fault code in %g4, fault address in %g5, etrap will
169 * preserve these two values in %l4 and %l5 respectively
170 */
David S. Miller74bf4312006-01-31 18:29:18 -0800171 ba,pt %xcc, etrap ! Save trap state
1721: rd %pc, %g7 ! ...
David S. Miller9bc657b2006-01-31 18:34:21 -0800173 stb %l4, [%g6 + TI_FAULT_CODE] ! Save fault code
174 stx %l5, [%g6 + TI_FAULT_ADDR] ! Save fault address
David S. Miller74bf4312006-01-31 18:29:18 -0800175 call do_sparc64_fault ! Call fault handler
176 add %sp, PTREGS_OFF, %o0 ! Compute pt_regs arg
177 ba,pt %xcc, rtrap_clr_l6 ! Restore cpu state
178 nop ! Delay slot (fill me)
179
David S. Miller74bf4312006-01-31 18:29:18 -0800180winfix_trampoline:
181 rdpr %tpc, %g3 ! Prepare winfixup TNPC
182 or %g3, 0x7c, %g3 ! Compute branch offset
183 wrpr %g3, %tnpc ! Write it into TNPC
184 done ! Trap return
185
David S. Millerb70c0fa2006-01-31 18:32:04 -0800186 /* Insert an entry into the TSB.
187 *
David S. Miller517af332006-02-01 15:55:21 -0800188 * %o0: TSB entry pointer (virt or phys address)
David S. Millerb70c0fa2006-01-31 18:32:04 -0800189 * %o1: tag
190 * %o2: pte
191 */
192 .align 32
David S. Miller517af332006-02-01 15:55:21 -0800193 .globl __tsb_insert
194__tsb_insert:
David S. Millerb70c0fa2006-01-31 18:32:04 -0800195 rdpr %pstate, %o5
196 wrpr %o5, PSTATE_IE, %pstate
197 TSB_LOCK_TAG(%o0, %g2, %g3)
198 TSB_WRITE(%o0, %o2, %o1)
199 wrpr %o5, %pstate
200 retl
201 nop
202
David S. Miller517af332006-02-01 15:55:21 -0800203 /* Flush the given TSB entry if it has the matching
204 * tag.
205 *
206 * %o0: TSB entry pointer (virt or phys address)
207 * %o1: tag
208 */
209 .align 32
210 .globl tsb_flush
211tsb_flush:
212 sethi %hi(TSB_TAG_LOCK_HIGH), %g2
2131: TSB_LOAD_TAG(%o0, %g1)
214 srlx %g1, 32, %o3
215 andcc %o3, %g2, %g0
216 bne,pn %icc, 1b
217 membar #LoadLoad
218 cmp %g1, %o1
219 bne,pt %xcc, 2f
220 clr %o3
221 TSB_CAS_TAG(%o0, %g1, %o3)
222 cmp %g1, %o3
223 bne,pn %xcc, 1b
224 nop
2252: retl
226 TSB_MEMBAR
227
David S. Miller74bf4312006-01-31 18:29:18 -0800228 /* Reload MMU related context switch state at
229 * schedule() time.
230 *
231 * %o0: page table physical address
David S. Miller98c55842006-01-31 18:31:20 -0800232 * %o1: TSB register value
233 * %o2: TSB virtual address
234 * %o3: TSB mapping locked PTE
David S. Miller618e9ed2006-02-09 17:21:53 -0800235 * %o4: Hypervisor TSB descriptor physical address
David S. Miller98c55842006-01-31 18:31:20 -0800236 *
237 * We have to run this whole thing with interrupts
238 * disabled so that the current cpu doesn't change
239 * due to preemption.
David S. Miller74bf4312006-01-31 18:29:18 -0800240 */
David S. Miller56fb4df2006-02-26 23:24:22 -0800241 .align 32
David S. Miller98c55842006-01-31 18:31:20 -0800242 .globl __tsb_context_switch
243__tsb_context_switch:
David S. Miller56fb4df2006-02-26 23:24:22 -0800244 rdpr %pstate, %o5
245 wrpr %o5, PSTATE_IE, %pstate
David S. Miller74bf4312006-01-31 18:29:18 -0800246
David S. Miller98c55842006-01-31 18:31:20 -0800247 ldub [%g6 + TI_CPU], %g1
248 sethi %hi(trap_block), %g2
249 sllx %g1, TRAP_BLOCK_SZ_SHIFT, %g1
250 or %g2, %lo(trap_block), %g2
251 add %g2, %g1, %g2
252 stx %o0, [%g2 + TRAP_PER_CPU_PGD_PADDR]
David S. Miller74bf4312006-01-31 18:29:18 -0800253
David S. Miller618e9ed2006-02-09 17:21:53 -0800254 sethi %hi(tlb_type), %g1
255 lduw [%g1 + %lo(tlb_type)], %g1
256 cmp %g1, 3
257 bne,pt %icc, 1f
David S. Miller98c55842006-01-31 18:31:20 -0800258 nop
David S. Miller74bf4312006-01-31 18:29:18 -0800259
David S. Miller618e9ed2006-02-09 17:21:53 -0800260 /* Hypervisor TSB switch. */
261 mov SCRATCHPAD_UTSBREG1, %g1
262 stxa %o1, [%g1] ASI_SCRATCHPAD
263 mov -1, %g2
264 mov SCRATCHPAD_UTSBREG2, %g1
265 stxa %g2, [%g1] ASI_SCRATCHPAD
266
David S. Miller164c2202006-02-09 22:57:21 -0800267 mov HV_FAST_MMU_TSB_CTXNON0, %o5
268 mov 1, %o0
269 mov %o4, %o1
David S. Miller618e9ed2006-02-09 17:21:53 -0800270 ta HV_FAST_TRAP
271
272 ba,pt %xcc, 9f
273 nop
274
275 /* SUN4U TSB switch. */
2761: mov TSB_REG, %g1
277 stxa %o1, [%g1] ASI_DMMU
278 membar #Sync
279 stxa %o1, [%g1] ASI_IMMU
280 membar #Sync
281
2822: brz %o2, 9f
283 nop
284
285 sethi %hi(sparc64_highest_unlocked_tlb_ent), %g2
David S. Miller6b6d0172006-01-31 18:33:12 -0800286 mov TLB_TAG_ACCESS, %g1
David S. Miller618e9ed2006-02-09 17:21:53 -0800287 lduw [%g2 + %lo(sparc64_highest_unlocked_tlb_ent)], %g2
David S. Miller6b6d0172006-01-31 18:33:12 -0800288 stxa %o2, [%g1] ASI_DMMU
289 membar #Sync
290 sllx %g2, 3, %g2
291 stxa %o3, [%g2] ASI_DTLB_DATA_ACCESS
292 membar #Sync
David S. Miller74bf4312006-01-31 18:29:18 -08002939:
David S. Miller56fb4df2006-02-26 23:24:22 -0800294 wrpr %o5, %pstate
David S. Miller74bf4312006-01-31 18:29:18 -0800295
296 retl
David S. Miller98c55842006-01-31 18:31:20 -0800297 nop