blob: 28e38b168ddab06db632b8699474c1fd6ca9892f [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
21 * %g7: physical address base of the linux page
22 * tables for the current address space
23 */
24 .globl tsb_miss_dtlb
25tsb_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
31 .globl tsb_miss_itlb
32tsb_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
38tsb_miss_page_table_walk:
David S. Millerffe483d2006-02-02 21:55:10 -080039 TRAP_LOAD_PGD_PHYS(%g7, %g5)
David S. Miller56fb4df2006-02-26 23:24:22 -080040
David S. Miller74bf4312006-01-31 18:29:18 -080041 USER_PGTABLE_WALK_TL1(%g4, %g7, %g5, %g2, tsb_do_fault)
42
43tsb_reload:
44 TSB_LOCK_TAG(%g1, %g2, %g4)
45
46 /* Load and check PTE. */
47 ldxa [%g5] ASI_PHYS_USE_EC, %g5
48 brgez,a,pn %g5, tsb_do_fault
David S. Miller517af332006-02-01 15:55:21 -080049 TSB_STORE(%g1, %g0)
David S. Miller74bf4312006-01-31 18:29:18 -080050
David S. Miller09f94282006-01-31 18:31:06 -080051 /* If it is larger than the base page size, don't
52 * bother putting it into the TSB.
53 */
54 srlx %g5, 32, %g2
55 sethi %hi(_PAGE_ALL_SZ_BITS >> 32), %g4
56 sethi %hi(_PAGE_SZBITS >> 32), %g7
57 and %g2, %g4, %g2
58 cmp %g2, %g7
59 bne,a,pn %xcc, tsb_tlb_reload
David S. Miller517af332006-02-01 15:55:21 -080060 TSB_STORE(%g1, %g0)
David S. Miller09f94282006-01-31 18:31:06 -080061
David S. Miller74bf4312006-01-31 18:29:18 -080062 TSB_WRITE(%g1, %g5, %g6)
63
64 /* Finally, load TLB and return from trap. */
65tsb_tlb_reload:
66 cmp %g3, FAULT_CODE_DTLB
67 bne,pn %xcc, tsb_itlb_load
68 nop
69
70tsb_dtlb_load:
71 stxa %g5, [%g0] ASI_DTLB_DATA_IN
72 retry
73
74tsb_itlb_load:
75 stxa %g5, [%g0] ASI_ITLB_DATA_IN
76 retry
77
78 /* No valid entry in the page tables, do full fault
79 * processing.
80 */
81
82 .globl tsb_do_fault
83tsb_do_fault:
84 cmp %g3, FAULT_CODE_DTLB
85 rdpr %pstate, %g5
86 bne,pn %xcc, tsb_do_itlb_fault
87 wrpr %g5, PSTATE_AG | PSTATE_MG, %pstate
88
89tsb_do_dtlb_fault:
90 rdpr %tl, %g4
91 cmp %g4, 1
92 mov TLB_TAG_ACCESS, %g4
93 ldxa [%g4] ASI_DMMU, %g5
94 be,pt %xcc, sparc64_realfault_common
95 mov FAULT_CODE_DTLB, %g4
96 ba,pt %xcc, winfix_trampoline
97 nop
98
99tsb_do_itlb_fault:
100 rdpr %tpc, %g5
101 ba,pt %xcc, sparc64_realfault_common
102 mov FAULT_CODE_ITLB, %g4
103
104 .globl sparc64_realfault_common
105sparc64_realfault_common:
David S. Miller9bc657b2006-01-31 18:34:21 -0800106 /* fault code in %g4, fault address in %g5, etrap will
107 * preserve these two values in %l4 and %l5 respectively
108 */
David S. Miller74bf4312006-01-31 18:29:18 -0800109 ba,pt %xcc, etrap ! Save trap state
1101: rd %pc, %g7 ! ...
David S. Miller9bc657b2006-01-31 18:34:21 -0800111 stb %l4, [%g6 + TI_FAULT_CODE] ! Save fault code
112 stx %l5, [%g6 + TI_FAULT_ADDR] ! Save fault address
David S. Miller74bf4312006-01-31 18:29:18 -0800113 call do_sparc64_fault ! Call fault handler
114 add %sp, PTREGS_OFF, %o0 ! Compute pt_regs arg
115 ba,pt %xcc, rtrap_clr_l6 ! Restore cpu state
116 nop ! Delay slot (fill me)
117
118 .globl winfix_trampoline
119winfix_trampoline:
120 rdpr %tpc, %g3 ! Prepare winfixup TNPC
121 or %g3, 0x7c, %g3 ! Compute branch offset
122 wrpr %g3, %tnpc ! Write it into TNPC
123 done ! Trap return
124
David S. Millerb70c0fa2006-01-31 18:32:04 -0800125 /* Insert an entry into the TSB.
126 *
David S. Miller517af332006-02-01 15:55:21 -0800127 * %o0: TSB entry pointer (virt or phys address)
David S. Millerb70c0fa2006-01-31 18:32:04 -0800128 * %o1: tag
129 * %o2: pte
130 */
131 .align 32
David S. Miller517af332006-02-01 15:55:21 -0800132 .globl __tsb_insert
133__tsb_insert:
David S. Millerb70c0fa2006-01-31 18:32:04 -0800134 rdpr %pstate, %o5
135 wrpr %o5, PSTATE_IE, %pstate
136 TSB_LOCK_TAG(%o0, %g2, %g3)
137 TSB_WRITE(%o0, %o2, %o1)
138 wrpr %o5, %pstate
139 retl
140 nop
141
David S. Miller517af332006-02-01 15:55:21 -0800142 /* Flush the given TSB entry if it has the matching
143 * tag.
144 *
145 * %o0: TSB entry pointer (virt or phys address)
146 * %o1: tag
147 */
148 .align 32
149 .globl tsb_flush
150tsb_flush:
151 sethi %hi(TSB_TAG_LOCK_HIGH), %g2
1521: TSB_LOAD_TAG(%o0, %g1)
153 srlx %g1, 32, %o3
154 andcc %o3, %g2, %g0
155 bne,pn %icc, 1b
156 membar #LoadLoad
157 cmp %g1, %o1
158 bne,pt %xcc, 2f
159 clr %o3
160 TSB_CAS_TAG(%o0, %g1, %o3)
161 cmp %g1, %o3
162 bne,pn %xcc, 1b
163 nop
1642: retl
165 TSB_MEMBAR
166
David S. Miller74bf4312006-01-31 18:29:18 -0800167 /* Reload MMU related context switch state at
168 * schedule() time.
169 *
170 * %o0: page table physical address
David S. Miller98c55842006-01-31 18:31:20 -0800171 * %o1: TSB register value
172 * %o2: TSB virtual address
173 * %o3: TSB mapping locked PTE
174 *
175 * We have to run this whole thing with interrupts
176 * disabled so that the current cpu doesn't change
177 * due to preemption.
David S. Miller74bf4312006-01-31 18:29:18 -0800178 */
David S. Miller56fb4df2006-02-26 23:24:22 -0800179 .align 32
David S. Miller98c55842006-01-31 18:31:20 -0800180 .globl __tsb_context_switch
181__tsb_context_switch:
David S. Miller56fb4df2006-02-26 23:24:22 -0800182 rdpr %pstate, %o5
183 wrpr %o5, PSTATE_IE, %pstate
David S. Miller74bf4312006-01-31 18:29:18 -0800184
David S. Miller98c55842006-01-31 18:31:20 -0800185 ldub [%g6 + TI_CPU], %g1
186 sethi %hi(trap_block), %g2
187 sllx %g1, TRAP_BLOCK_SZ_SHIFT, %g1
188 or %g2, %lo(trap_block), %g2
189 add %g2, %g1, %g2
190 stx %o0, [%g2 + TRAP_PER_CPU_PGD_PADDR]
David S. Miller74bf4312006-01-31 18:29:18 -0800191
David S. Miller74bf4312006-01-31 18:29:18 -0800192 mov TSB_REG, %g1
David S. Miller98c55842006-01-31 18:31:20 -0800193 stxa %o1, [%g1] ASI_DMMU
David S. Miller74bf4312006-01-31 18:29:18 -0800194 membar #Sync
195
David S. Miller98c55842006-01-31 18:31:20 -0800196 stxa %o1, [%g1] ASI_IMMU
David S. Miller74bf4312006-01-31 18:29:18 -0800197 membar #Sync
198
David S. Miller98c55842006-01-31 18:31:20 -0800199 brz %o2, 9f
200 nop
David S. Miller74bf4312006-01-31 18:29:18 -0800201
David S. Miller6b6d0172006-01-31 18:33:12 -0800202 sethi %hi(sparc64_highest_unlocked_tlb_ent), %o4
203 mov TLB_TAG_ACCESS, %g1
204 lduw [%o4 + %lo(sparc64_highest_unlocked_tlb_ent)], %g2
205 stxa %o2, [%g1] ASI_DMMU
206 membar #Sync
207 sllx %g2, 3, %g2
208 stxa %o3, [%g2] ASI_DTLB_DATA_ACCESS
209 membar #Sync
David S. Miller74bf4312006-01-31 18:29:18 -08002109:
David S. Miller56fb4df2006-02-26 23:24:22 -0800211 wrpr %o5, %pstate
David S. Miller74bf4312006-01-31 18:29:18 -0800212
213 retl
David S. Miller98c55842006-01-31 18:31:20 -0800214 nop