blob: e492db845ea34c07ee49e1d4dea1011e5fd95886 [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
David S. Miller2a7e2992005-09-21 18:50:51 -07009#include <asm/head.h>
10#include <asm/asi.h>
11#include <asm/page.h>
12#include <asm/pgtable.h>
David S. Miller74bf4312006-01-31 18:29:18 -080013#include <asm/tsb.h>
David S. Miller2a7e2992005-09-21 18:50:51 -070014
15 .text
16 .align 32
17
David S. Miller74bf4312006-01-31 18:29:18 -080018kvmap_itlb:
19 /* g6: TAG TARGET */
20 mov TLB_TAG_ACCESS, %g4
21 ldxa [%g4] ASI_IMMU, %g4
22
David S. Millerd257d5d2006-02-06 23:44:37 -080023 /* sun4v_itlb_miss branches here with the missing virtual
24 * address already loaded into %g4
25 */
26kvmap_itlb_4v:
27
David S. Miller74bf4312006-01-31 18:29:18 -080028kvmap_itlb_nonlinear:
29 /* Catch kernel NULL pointer calls. */
30 sethi %hi(PAGE_SIZE), %g5
31 cmp %g4, %g5
32 bleu,pn %xcc, kvmap_dtlb_longpath
33 nop
34
35 KERN_TSB_LOOKUP_TL1(%g4, %g6, %g5, %g1, %g2, %g3, kvmap_itlb_load)
36
37kvmap_itlb_tsb_miss:
David S. Miller2a7e2992005-09-21 18:50:51 -070038 sethi %hi(LOW_OBP_ADDRESS), %g5
39 cmp %g4, %g5
David S. Miller74bf4312006-01-31 18:29:18 -080040 blu,pn %xcc, kvmap_itlb_vmalloc_addr
David S. Miller2a7e2992005-09-21 18:50:51 -070041 mov 0x1, %g5
42 sllx %g5, 32, %g5
43 cmp %g4, %g5
David S. Miller74bf4312006-01-31 18:29:18 -080044 blu,pn %xcc, kvmap_itlb_obp
David S. Miller2a7e2992005-09-21 18:50:51 -070045 nop
46
David S. Miller74bf4312006-01-31 18:29:18 -080047kvmap_itlb_vmalloc_addr:
48 KERN_PGTABLE_WALK(%g4, %g5, %g2, kvmap_itlb_longpath)
David S. Miller2a7e2992005-09-21 18:50:51 -070049
David S. Miller459b6e62006-02-11 12:21:20 -080050 KTSB_LOCK_TAG(%g1, %g2, %g7)
David S. Miller2a7e2992005-09-21 18:50:51 -070051
David S. Miller74bf4312006-01-31 18:29:18 -080052 /* Load and check PTE. */
53 ldxa [%g5] ASI_PHYS_USE_EC, %g5
David S. Miller8b234272006-02-17 18:01:02 -080054 mov 1, %g7
55 sllx %g7, TSB_TAG_INVALID_BIT, %g7
David S. Miller74bf4312006-01-31 18:29:18 -080056 brgez,a,pn %g5, kvmap_itlb_longpath
David S. Miller8b234272006-02-17 18:01:02 -080057 KTSB_STORE(%g1, %g7)
David S. Miller2a7e2992005-09-21 18:50:51 -070058
David S. Miller517af332006-02-01 15:55:21 -080059 KTSB_WRITE(%g1, %g5, %g6)
David S. Miller2a7e2992005-09-21 18:50:51 -070060
David S. Miller74bf4312006-01-31 18:29:18 -080061 /* fallthrough to TLB load */
David S. Miller2a7e2992005-09-21 18:50:51 -070062
David S. Miller74bf4312006-01-31 18:29:18 -080063kvmap_itlb_load:
David S. Miller459b6e62006-02-11 12:21:20 -080064
65661: stxa %g5, [%g0] ASI_ITLB_DATA_IN
David S. Miller2a7e2992005-09-21 18:50:51 -070066 retry
David S. Miller459b6e62006-02-11 12:21:20 -080067 .section .sun4v_2insn_patch, "ax"
68 .word 661b
69 nop
70 nop
71 .previous
72
73 /* For sun4v the ASI_ITLB_DATA_IN store and the retry
74 * instruction get nop'd out and we get here to branch
75 * to the sun4v tlb load code. The registers are setup
76 * as follows:
77 *
78 * %g4: vaddr
79 * %g5: PTE
80 * %g6: TAG
81 *
82 * The sun4v TLB load wants the PTE in %g3 so we fix that
83 * up here.
84 */
85 ba,pt %xcc, sun4v_itlb_load
86 mov %g5, %g3
David S. Miller2a7e2992005-09-21 18:50:51 -070087
David S. Miller74bf4312006-01-31 18:29:18 -080088kvmap_itlb_longpath:
David S. Miller45fec052006-02-05 22:27:28 -080089
90661: rdpr %pstate, %g5
David S. Miller74bf4312006-01-31 18:29:18 -080091 wrpr %g5, PSTATE_AG | PSTATE_MG, %pstate
David S. Millerdf7d6ae2006-02-07 00:00:16 -080092 .section .sun4v_2insn_patch, "ax"
David S. Miller45fec052006-02-05 22:27:28 -080093 .word 661b
David S. Miller6cc200d2006-02-18 16:36:39 -080094 SET_GL(1)
David S. Miller45fec052006-02-05 22:27:28 -080095 nop
96 .previous
97
David S. Miller74bf4312006-01-31 18:29:18 -080098 rdpr %tpc, %g5
99 ba,pt %xcc, sparc64_realfault_common
100 mov FAULT_CODE_ITLB, %g4
David S. Millerc9c10832005-10-12 12:22:46 -0700101
David S. Miller74bf4312006-01-31 18:29:18 -0800102kvmap_itlb_obp:
103 OBP_TRANS_LOOKUP(%g4, %g5, %g2, %g3, kvmap_itlb_longpath)
David S. Miller2a7e2992005-09-21 18:50:51 -0700104
David S. Miller459b6e62006-02-11 12:21:20 -0800105 KTSB_LOCK_TAG(%g1, %g2, %g7)
David S. Miller2a7e2992005-09-21 18:50:51 -0700106
David S. Miller517af332006-02-01 15:55:21 -0800107 KTSB_WRITE(%g1, %g5, %g6)
David S. Miller2a7e2992005-09-21 18:50:51 -0700108
David S. Miller74bf4312006-01-31 18:29:18 -0800109 ba,pt %xcc, kvmap_itlb_load
110 nop
David S. Millerc9c10832005-10-12 12:22:46 -0700111
David S. Miller74bf4312006-01-31 18:29:18 -0800112kvmap_dtlb_obp:
113 OBP_TRANS_LOOKUP(%g4, %g5, %g2, %g3, kvmap_dtlb_longpath)
114
David S. Miller459b6e62006-02-11 12:21:20 -0800115 KTSB_LOCK_TAG(%g1, %g2, %g7)
David S. Miller74bf4312006-01-31 18:29:18 -0800116
David S. Miller517af332006-02-01 15:55:21 -0800117 KTSB_WRITE(%g1, %g5, %g6)
David S. Miller74bf4312006-01-31 18:29:18 -0800118
119 ba,pt %xcc, kvmap_dtlb_load
120 nop
121
David S. Miller2a7e2992005-09-21 18:50:51 -0700122 .align 32
David S. Millerd7744a02006-02-21 22:31:11 -0800123kvmap_dtlb_tsb4m_load:
124 KTSB_LOCK_TAG(%g1, %g2, %g7)
125 KTSB_WRITE(%g1, %g5, %g6)
126 ba,pt %xcc, kvmap_dtlb_load
127 nop
128
David S. Miller74bf4312006-01-31 18:29:18 -0800129kvmap_dtlb:
130 /* %g6: TAG TARGET */
131 mov TLB_TAG_ACCESS, %g4
132 ldxa [%g4] ASI_DMMU, %g4
David S. Millerd257d5d2006-02-06 23:44:37 -0800133
134 /* sun4v_dtlb_miss branches here with the missing virtual
135 * address already loaded into %g4
136 */
137kvmap_dtlb_4v:
David S. Miller74bf4312006-01-31 18:29:18 -0800138 brgez,pn %g4, kvmap_dtlb_nonlinear
David S. Miller56425302005-09-25 16:46:57 -0700139 nop
140
David S. Millerd7744a02006-02-21 22:31:11 -0800141 /* Correct TAG_TARGET is already in %g6, check 4mb TSB. */
142 KERN_TSB4M_LOOKUP_TL1(%g6, %g5, %g1, %g2, %g3, kvmap_dtlb_load)
143
144 /* TSB entry address left in %g1, lookup linear PTE.
145 * Must preserve %g1 and %g6 (TAG).
146 */
147kvmap_dtlb_tsb4m_miss:
David S. Miller9cc3a1a2006-02-21 20:51:13 -0800148 sethi %hi(kpte_linear_bitmap), %g2
149 or %g2, %lo(kpte_linear_bitmap), %g2
150
151 /* Clear the PAGE_OFFSET top virtual bits, then shift
152 * down to get a 256MB physical address index.
153 */
154 sllx %g4, 21, %g5
155 mov 1, %g7
156 srlx %g5, 21 + 28, %g5
157
158 /* Don't try this at home kids... this depends upon srlx
159 * only taking the low 6 bits of the shift count in %g5.
160 */
161 sllx %g7, %g5, %g7
162
163 /* Divide by 64 to get the offset into the bitmask. */
164 srlx %g5, 6, %g5
David S. Miller68893312006-02-26 23:09:37 -0800165 sllx %g5, 3, %g5
David S. Miller9cc3a1a2006-02-21 20:51:13 -0800166
167 /* kern_linear_pte_xor[((mask & bit) ? 1 : 0)] */
168 ldx [%g2 + %g5], %g2
169 andcc %g2, %g7, %g0
170 sethi %hi(kern_linear_pte_xor), %g5
171 or %g5, %lo(kern_linear_pte_xor), %g5
172 bne,a,pt %xcc, 1f
173 add %g5, 8, %g5
174
1751: ldx [%g5], %g2
David S. Miller74bf4312006-01-31 18:29:18 -0800176
David S. Miller56425302005-09-25 16:46:57 -0700177 .globl kvmap_linear_patch
178kvmap_linear_patch:
David S. Millerd7744a02006-02-21 22:31:11 -0800179 ba,pt %xcc, kvmap_dtlb_tsb4m_load
David S. Miller2a7e2992005-09-21 18:50:51 -0700180 xor %g2, %g4, %g5
181
David S. Miller74bf4312006-01-31 18:29:18 -0800182kvmap_dtlb_vmalloc_addr:
183 KERN_PGTABLE_WALK(%g4, %g5, %g2, kvmap_dtlb_longpath)
David S. Miller56425302005-09-25 16:46:57 -0700184
David S. Miller459b6e62006-02-11 12:21:20 -0800185 KTSB_LOCK_TAG(%g1, %g2, %g7)
David S. Miller74bf4312006-01-31 18:29:18 -0800186
187 /* Load and check PTE. */
188 ldxa [%g5] ASI_PHYS_USE_EC, %g5
David S. Miller8b234272006-02-17 18:01:02 -0800189 mov 1, %g7
190 sllx %g7, TSB_TAG_INVALID_BIT, %g7
David S. Miller74bf4312006-01-31 18:29:18 -0800191 brgez,a,pn %g5, kvmap_dtlb_longpath
David S. Miller8b234272006-02-17 18:01:02 -0800192 KTSB_STORE(%g1, %g7)
David S. Miller74bf4312006-01-31 18:29:18 -0800193
David S. Miller517af332006-02-01 15:55:21 -0800194 KTSB_WRITE(%g1, %g5, %g6)
David S. Miller74bf4312006-01-31 18:29:18 -0800195
196 /* fallthrough to TLB load */
197
198kvmap_dtlb_load:
David S. Miller459b6e62006-02-11 12:21:20 -0800199
200661: stxa %g5, [%g0] ASI_DTLB_DATA_IN ! Reload TLB
David S. Miller74bf4312006-01-31 18:29:18 -0800201 retry
David S. Miller459b6e62006-02-11 12:21:20 -0800202 .section .sun4v_2insn_patch, "ax"
203 .word 661b
204 nop
205 nop
206 .previous
207
208 /* For sun4v the ASI_DTLB_DATA_IN store and the retry
209 * instruction get nop'd out and we get here to branch
210 * to the sun4v tlb load code. The registers are setup
211 * as follows:
212 *
213 * %g4: vaddr
214 * %g5: PTE
215 * %g6: TAG
216 *
217 * The sun4v TLB load wants the PTE in %g3 so we fix that
218 * up here.
219 */
220 ba,pt %xcc, sun4v_dtlb_load
221 mov %g5, %g3
David S. Miller74bf4312006-01-31 18:29:18 -0800222
223kvmap_dtlb_nonlinear:
224 /* Catch kernel NULL pointer derefs. */
225 sethi %hi(PAGE_SIZE), %g5
226 cmp %g4, %g5
227 bleu,pn %xcc, kvmap_dtlb_longpath
228 nop
229
230 KERN_TSB_LOOKUP_TL1(%g4, %g6, %g5, %g1, %g2, %g3, kvmap_dtlb_load)
231
232kvmap_dtlb_tsbmiss:
David S. Miller2a7e2992005-09-21 18:50:51 -0700233 sethi %hi(MODULES_VADDR), %g5
234 cmp %g4, %g5
David S. Miller74bf4312006-01-31 18:29:18 -0800235 blu,pn %xcc, kvmap_dtlb_longpath
David S. Miller2a7e2992005-09-21 18:50:51 -0700236 mov (VMALLOC_END >> 24), %g5
237 sllx %g5, 24, %g5
238 cmp %g4, %g5
David S. Miller74bf4312006-01-31 18:29:18 -0800239 bgeu,pn %xcc, kvmap_dtlb_longpath
David S. Miller2a7e2992005-09-21 18:50:51 -0700240 nop
241
242kvmap_check_obp:
243 sethi %hi(LOW_OBP_ADDRESS), %g5
244 cmp %g4, %g5
David S. Miller74bf4312006-01-31 18:29:18 -0800245 blu,pn %xcc, kvmap_dtlb_vmalloc_addr
David S. Miller2a7e2992005-09-21 18:50:51 -0700246 mov 0x1, %g5
247 sllx %g5, 32, %g5
248 cmp %g4, %g5
David S. Miller74bf4312006-01-31 18:29:18 -0800249 blu,pn %xcc, kvmap_dtlb_obp
250 nop
251 ba,pt %xcc, kvmap_dtlb_vmalloc_addr
David S. Miller2a7e2992005-09-21 18:50:51 -0700252 nop
253
David S. Miller74bf4312006-01-31 18:29:18 -0800254kvmap_dtlb_longpath:
David S. Miller45fec052006-02-05 22:27:28 -0800255
256661: rdpr %pstate, %g5
David S. Miller74bf4312006-01-31 18:29:18 -0800257 wrpr %g5, PSTATE_AG | PSTATE_MG, %pstate
David S. Millerdf7d6ae2006-02-07 00:00:16 -0800258 .section .sun4v_2insn_patch, "ax"
David S. Miller45fec052006-02-05 22:27:28 -0800259 .word 661b
David S. Miller8b234272006-02-17 18:01:02 -0800260 SET_GL(1)
261 ldxa [%g0] ASI_SCRATCHPAD, %g5
David S. Miller45fec052006-02-05 22:27:28 -0800262 .previous
263
David S. Miller459b6e62006-02-11 12:21:20 -0800264 rdpr %tl, %g3
265 cmp %g3, 1
266
267661: mov TLB_TAG_ACCESS, %g4
David S. Miller74bf4312006-01-31 18:29:18 -0800268 ldxa [%g4] ASI_DMMU, %g5
David S. Miller459b6e62006-02-11 12:21:20 -0800269 .section .sun4v_2insn_patch, "ax"
270 .word 661b
David S. Miller8b234272006-02-17 18:01:02 -0800271 ldx [%g5 + HV_FAULT_D_ADDR_OFFSET], %g5
David S. Miller459b6e62006-02-11 12:21:20 -0800272 nop
273 .previous
274
David S. Miller74bf4312006-01-31 18:29:18 -0800275 be,pt %xcc, sparc64_realfault_common
276 mov FAULT_CODE_DTLB, %g4
277 ba,pt %xcc, winfix_trampoline
David S. Miller2a7e2992005-09-21 18:50:51 -0700278 nop