blob: 31da1e564c95e2ecdbabf13a55a5fda55391d9a4 [file] [log] [blame]
David S. Miller2a7e2992005-09-21 18:50:51 -07001/* arch/sparc64/kernel/ktlb.S: Kernel mapping TLB miss handling.
2 *
3 * Copyright (C) 1995, 1997, 2005 David S. Miller <davem@davemloft.net>
4 * Copyright (C) 1996 Eddie C. Dost (ecd@brainaid.de)
5 * Copyright (C) 1996 Miguel de Icaza (miguel@nuclecu.unam.mx)
6 * Copyright (C) 1996,98,99 Jakub Jelinek (jj@sunsite.mff.cuni.cz)
David S. Miller74bf4312006-01-31 18:29:18 -08007 */
David S. Miller2a7e2992005-09-21 18:50:51 -07008
9#include <linux/config.h>
10#include <asm/head.h>
11#include <asm/asi.h>
12#include <asm/page.h>
13#include <asm/pgtable.h>
David S. Miller74bf4312006-01-31 18:29:18 -080014#include <asm/tsb.h>
David S. Miller2a7e2992005-09-21 18:50:51 -070015
16 .text
17 .align 32
18
David S. Miller74bf4312006-01-31 18:29:18 -080019kvmap_itlb:
20 /* g6: TAG TARGET */
21 mov TLB_TAG_ACCESS, %g4
22 ldxa [%g4] ASI_IMMU, %g4
23
David S. Millerd257d5d2006-02-06 23:44:37 -080024 /* sun4v_itlb_miss branches here with the missing virtual
25 * address already loaded into %g4
26 */
27kvmap_itlb_4v:
28
David S. Miller74bf4312006-01-31 18:29:18 -080029kvmap_itlb_nonlinear:
30 /* Catch kernel NULL pointer calls. */
31 sethi %hi(PAGE_SIZE), %g5
32 cmp %g4, %g5
33 bleu,pn %xcc, kvmap_dtlb_longpath
34 nop
35
36 KERN_TSB_LOOKUP_TL1(%g4, %g6, %g5, %g1, %g2, %g3, kvmap_itlb_load)
37
38kvmap_itlb_tsb_miss:
David S. Miller2a7e2992005-09-21 18:50:51 -070039 sethi %hi(LOW_OBP_ADDRESS), %g5
40 cmp %g4, %g5
David S. Miller74bf4312006-01-31 18:29:18 -080041 blu,pn %xcc, kvmap_itlb_vmalloc_addr
David S. Miller2a7e2992005-09-21 18:50:51 -070042 mov 0x1, %g5
43 sllx %g5, 32, %g5
44 cmp %g4, %g5
David S. Miller74bf4312006-01-31 18:29:18 -080045 blu,pn %xcc, kvmap_itlb_obp
David S. Miller2a7e2992005-09-21 18:50:51 -070046 nop
47
David S. Miller74bf4312006-01-31 18:29:18 -080048kvmap_itlb_vmalloc_addr:
49 KERN_PGTABLE_WALK(%g4, %g5, %g2, kvmap_itlb_longpath)
David S. Miller2a7e2992005-09-21 18:50:51 -070050
David S. Miller459b6e62006-02-11 12:21:20 -080051 KTSB_LOCK_TAG(%g1, %g2, %g7)
David S. Miller2a7e2992005-09-21 18:50:51 -070052
David S. Miller74bf4312006-01-31 18:29:18 -080053 /* Load and check PTE. */
54 ldxa [%g5] ASI_PHYS_USE_EC, %g5
David S. Miller8b234272006-02-17 18:01:02 -080055 mov 1, %g7
56 sllx %g7, TSB_TAG_INVALID_BIT, %g7
David S. Miller74bf4312006-01-31 18:29:18 -080057 brgez,a,pn %g5, kvmap_itlb_longpath
David S. Miller8b234272006-02-17 18:01:02 -080058 KTSB_STORE(%g1, %g7)
David S. Miller2a7e2992005-09-21 18:50:51 -070059
David S. Miller517af332006-02-01 15:55:21 -080060 KTSB_WRITE(%g1, %g5, %g6)
David S. Miller2a7e2992005-09-21 18:50:51 -070061
David S. Miller74bf4312006-01-31 18:29:18 -080062 /* fallthrough to TLB load */
David S. Miller2a7e2992005-09-21 18:50:51 -070063
David S. Miller74bf4312006-01-31 18:29:18 -080064kvmap_itlb_load:
David S. Miller459b6e62006-02-11 12:21:20 -080065
66661: stxa %g5, [%g0] ASI_ITLB_DATA_IN
David S. Miller2a7e2992005-09-21 18:50:51 -070067 retry
David S. Miller459b6e62006-02-11 12:21:20 -080068 .section .sun4v_2insn_patch, "ax"
69 .word 661b
70 nop
71 nop
72 .previous
73
74 /* For sun4v the ASI_ITLB_DATA_IN store and the retry
75 * instruction get nop'd out and we get here to branch
76 * to the sun4v tlb load code. The registers are setup
77 * as follows:
78 *
79 * %g4: vaddr
80 * %g5: PTE
81 * %g6: TAG
82 *
83 * The sun4v TLB load wants the PTE in %g3 so we fix that
84 * up here.
85 */
86 ba,pt %xcc, sun4v_itlb_load
87 mov %g5, %g3
David S. Miller2a7e2992005-09-21 18:50:51 -070088
David S. Miller74bf4312006-01-31 18:29:18 -080089kvmap_itlb_longpath:
David S. Miller45fec052006-02-05 22:27:28 -080090
91661: rdpr %pstate, %g5
David S. Miller74bf4312006-01-31 18:29:18 -080092 wrpr %g5, PSTATE_AG | PSTATE_MG, %pstate
David S. Millerdf7d6ae2006-02-07 00:00:16 -080093 .section .sun4v_2insn_patch, "ax"
David S. Miller45fec052006-02-05 22:27:28 -080094 .word 661b
David S. Miller6cc200d2006-02-18 16:36:39 -080095 SET_GL(1)
David S. Miller45fec052006-02-05 22:27:28 -080096 nop
97 .previous
98
David S. Miller74bf4312006-01-31 18:29:18 -080099 rdpr %tpc, %g5
100 ba,pt %xcc, sparc64_realfault_common
101 mov FAULT_CODE_ITLB, %g4
David S. Millerc9c10832005-10-12 12:22:46 -0700102
David S. Miller74bf4312006-01-31 18:29:18 -0800103kvmap_itlb_obp:
104 OBP_TRANS_LOOKUP(%g4, %g5, %g2, %g3, kvmap_itlb_longpath)
David S. Miller2a7e2992005-09-21 18:50:51 -0700105
David S. Miller459b6e62006-02-11 12:21:20 -0800106 KTSB_LOCK_TAG(%g1, %g2, %g7)
David S. Miller2a7e2992005-09-21 18:50:51 -0700107
David S. Miller517af332006-02-01 15:55:21 -0800108 KTSB_WRITE(%g1, %g5, %g6)
David S. Miller2a7e2992005-09-21 18:50:51 -0700109
David S. Miller74bf4312006-01-31 18:29:18 -0800110 ba,pt %xcc, kvmap_itlb_load
111 nop
David S. Millerc9c10832005-10-12 12:22:46 -0700112
David S. Miller74bf4312006-01-31 18:29:18 -0800113kvmap_dtlb_obp:
114 OBP_TRANS_LOOKUP(%g4, %g5, %g2, %g3, kvmap_dtlb_longpath)
115
David S. Miller459b6e62006-02-11 12:21:20 -0800116 KTSB_LOCK_TAG(%g1, %g2, %g7)
David S. Miller74bf4312006-01-31 18:29:18 -0800117
David S. Miller517af332006-02-01 15:55:21 -0800118 KTSB_WRITE(%g1, %g5, %g6)
David S. Miller74bf4312006-01-31 18:29:18 -0800119
120 ba,pt %xcc, kvmap_dtlb_load
121 nop
122
David S. Miller2a7e2992005-09-21 18:50:51 -0700123 .align 32
David S. Millerd7744a02006-02-21 22:31:11 -0800124kvmap_dtlb_tsb4m_load:
125 KTSB_LOCK_TAG(%g1, %g2, %g7)
126 KTSB_WRITE(%g1, %g5, %g6)
127 ba,pt %xcc, kvmap_dtlb_load
128 nop
129
David S. Miller74bf4312006-01-31 18:29:18 -0800130kvmap_dtlb:
131 /* %g6: TAG TARGET */
132 mov TLB_TAG_ACCESS, %g4
133 ldxa [%g4] ASI_DMMU, %g4
David S. Millerd257d5d2006-02-06 23:44:37 -0800134
135 /* sun4v_dtlb_miss branches here with the missing virtual
136 * address already loaded into %g4
137 */
138kvmap_dtlb_4v:
David S. Miller74bf4312006-01-31 18:29:18 -0800139 brgez,pn %g4, kvmap_dtlb_nonlinear
David S. Miller56425302005-09-25 16:46:57 -0700140 nop
141
David S. Millerd7744a02006-02-21 22:31:11 -0800142 /* Correct TAG_TARGET is already in %g6, check 4mb TSB. */
143 KERN_TSB4M_LOOKUP_TL1(%g6, %g5, %g1, %g2, %g3, kvmap_dtlb_load)
144
145 /* TSB entry address left in %g1, lookup linear PTE.
146 * Must preserve %g1 and %g6 (TAG).
147 */
148kvmap_dtlb_tsb4m_miss:
David S. Miller9cc3a1a2006-02-21 20:51:13 -0800149 sethi %hi(kpte_linear_bitmap), %g2
150 or %g2, %lo(kpte_linear_bitmap), %g2
151
152 /* Clear the PAGE_OFFSET top virtual bits, then shift
153 * down to get a 256MB physical address index.
154 */
155 sllx %g4, 21, %g5
156 mov 1, %g7
157 srlx %g5, 21 + 28, %g5
158
159 /* Don't try this at home kids... this depends upon srlx
160 * only taking the low 6 bits of the shift count in %g5.
161 */
162 sllx %g7, %g5, %g7
163
164 /* Divide by 64 to get the offset into the bitmask. */
165 srlx %g5, 6, %g5
David S. Miller68893312006-02-26 23:09:37 -0800166 sllx %g5, 3, %g5
David S. Miller9cc3a1a2006-02-21 20:51:13 -0800167
168 /* kern_linear_pte_xor[((mask & bit) ? 1 : 0)] */
169 ldx [%g2 + %g5], %g2
170 andcc %g2, %g7, %g0
171 sethi %hi(kern_linear_pte_xor), %g5
172 or %g5, %lo(kern_linear_pte_xor), %g5
173 bne,a,pt %xcc, 1f
174 add %g5, 8, %g5
175
1761: ldx [%g5], %g2
David S. Miller74bf4312006-01-31 18:29:18 -0800177
David S. Miller56425302005-09-25 16:46:57 -0700178 .globl kvmap_linear_patch
179kvmap_linear_patch:
David S. Millerd7744a02006-02-21 22:31:11 -0800180 ba,pt %xcc, kvmap_dtlb_tsb4m_load
David S. Miller2a7e2992005-09-21 18:50:51 -0700181 xor %g2, %g4, %g5
182
David S. Miller74bf4312006-01-31 18:29:18 -0800183kvmap_dtlb_vmalloc_addr:
184 KERN_PGTABLE_WALK(%g4, %g5, %g2, kvmap_dtlb_longpath)
David S. Miller56425302005-09-25 16:46:57 -0700185
David S. Miller459b6e62006-02-11 12:21:20 -0800186 KTSB_LOCK_TAG(%g1, %g2, %g7)
David S. Miller74bf4312006-01-31 18:29:18 -0800187
188 /* Load and check PTE. */
189 ldxa [%g5] ASI_PHYS_USE_EC, %g5
David S. Miller8b234272006-02-17 18:01:02 -0800190 mov 1, %g7
191 sllx %g7, TSB_TAG_INVALID_BIT, %g7
David S. Miller74bf4312006-01-31 18:29:18 -0800192 brgez,a,pn %g5, kvmap_dtlb_longpath
David S. Miller8b234272006-02-17 18:01:02 -0800193 KTSB_STORE(%g1, %g7)
David S. Miller74bf4312006-01-31 18:29:18 -0800194
David S. Miller517af332006-02-01 15:55:21 -0800195 KTSB_WRITE(%g1, %g5, %g6)
David S. Miller74bf4312006-01-31 18:29:18 -0800196
197 /* fallthrough to TLB load */
198
199kvmap_dtlb_load:
David S. Miller459b6e62006-02-11 12:21:20 -0800200
201661: stxa %g5, [%g0] ASI_DTLB_DATA_IN ! Reload TLB
David S. Miller74bf4312006-01-31 18:29:18 -0800202 retry
David S. Miller459b6e62006-02-11 12:21:20 -0800203 .section .sun4v_2insn_patch, "ax"
204 .word 661b
205 nop
206 nop
207 .previous
208
209 /* For sun4v the ASI_DTLB_DATA_IN store and the retry
210 * instruction get nop'd out and we get here to branch
211 * to the sun4v tlb load code. The registers are setup
212 * as follows:
213 *
214 * %g4: vaddr
215 * %g5: PTE
216 * %g6: TAG
217 *
218 * The sun4v TLB load wants the PTE in %g3 so we fix that
219 * up here.
220 */
221 ba,pt %xcc, sun4v_dtlb_load
222 mov %g5, %g3
David S. Miller74bf4312006-01-31 18:29:18 -0800223
224kvmap_dtlb_nonlinear:
225 /* Catch kernel NULL pointer derefs. */
226 sethi %hi(PAGE_SIZE), %g5
227 cmp %g4, %g5
228 bleu,pn %xcc, kvmap_dtlb_longpath
229 nop
230
231 KERN_TSB_LOOKUP_TL1(%g4, %g6, %g5, %g1, %g2, %g3, kvmap_dtlb_load)
232
233kvmap_dtlb_tsbmiss:
David S. Miller2a7e2992005-09-21 18:50:51 -0700234 sethi %hi(MODULES_VADDR), %g5
235 cmp %g4, %g5
David S. Miller74bf4312006-01-31 18:29:18 -0800236 blu,pn %xcc, kvmap_dtlb_longpath
David S. Miller2a7e2992005-09-21 18:50:51 -0700237 mov (VMALLOC_END >> 24), %g5
238 sllx %g5, 24, %g5
239 cmp %g4, %g5
David S. Miller74bf4312006-01-31 18:29:18 -0800240 bgeu,pn %xcc, kvmap_dtlb_longpath
David S. Miller2a7e2992005-09-21 18:50:51 -0700241 nop
242
243kvmap_check_obp:
244 sethi %hi(LOW_OBP_ADDRESS), %g5
245 cmp %g4, %g5
David S. Miller74bf4312006-01-31 18:29:18 -0800246 blu,pn %xcc, kvmap_dtlb_vmalloc_addr
David S. Miller2a7e2992005-09-21 18:50:51 -0700247 mov 0x1, %g5
248 sllx %g5, 32, %g5
249 cmp %g4, %g5
David S. Miller74bf4312006-01-31 18:29:18 -0800250 blu,pn %xcc, kvmap_dtlb_obp
251 nop
252 ba,pt %xcc, kvmap_dtlb_vmalloc_addr
David S. Miller2a7e2992005-09-21 18:50:51 -0700253 nop
254
David S. Miller74bf4312006-01-31 18:29:18 -0800255kvmap_dtlb_longpath:
David S. Miller45fec052006-02-05 22:27:28 -0800256
257661: rdpr %pstate, %g5
David S. Miller74bf4312006-01-31 18:29:18 -0800258 wrpr %g5, PSTATE_AG | PSTATE_MG, %pstate
David S. Millerdf7d6ae2006-02-07 00:00:16 -0800259 .section .sun4v_2insn_patch, "ax"
David S. Miller45fec052006-02-05 22:27:28 -0800260 .word 661b
David S. Miller8b234272006-02-17 18:01:02 -0800261 SET_GL(1)
262 ldxa [%g0] ASI_SCRATCHPAD, %g5
David S. Miller45fec052006-02-05 22:27:28 -0800263 .previous
264
David S. Miller459b6e62006-02-11 12:21:20 -0800265 rdpr %tl, %g3
266 cmp %g3, 1
267
268661: mov TLB_TAG_ACCESS, %g4
David S. Miller74bf4312006-01-31 18:29:18 -0800269 ldxa [%g4] ASI_DMMU, %g5
David S. Miller459b6e62006-02-11 12:21:20 -0800270 .section .sun4v_2insn_patch, "ax"
271 .word 661b
David S. Miller8b234272006-02-17 18:01:02 -0800272 ldx [%g5 + HV_FAULT_D_ADDR_OFFSET], %g5
David S. Miller459b6e62006-02-11 12:21:20 -0800273 nop
274 .previous
275
David S. Miller74bf4312006-01-31 18:29:18 -0800276 be,pt %xcc, sparc64_realfault_common
277 mov FAULT_CODE_DTLB, %g4
278 ba,pt %xcc, winfix_trampoline
David S. Miller2a7e2992005-09-21 18:50:51 -0700279 nop