blob: 2d333ab4b91bc352beecf07b334cde1dbc32903d [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
55 brgez,a,pn %g5, kvmap_itlb_longpath
David S. Miller517af332006-02-01 15:55:21 -080056 KTSB_STORE(%g1, %g0)
David S. Miller2a7e2992005-09-21 18:50:51 -070057
David S. Miller517af332006-02-01 15:55:21 -080058 KTSB_WRITE(%g1, %g5, %g6)
David S. Miller2a7e2992005-09-21 18:50:51 -070059
David S. Miller74bf4312006-01-31 18:29:18 -080060 /* fallthrough to TLB load */
David S. Miller2a7e2992005-09-21 18:50:51 -070061
David S. Miller74bf4312006-01-31 18:29:18 -080062kvmap_itlb_load:
David S. Miller459b6e62006-02-11 12:21:20 -080063
64661: stxa %g5, [%g0] ASI_ITLB_DATA_IN
David S. Miller2a7e2992005-09-21 18:50:51 -070065 retry
David S. Miller459b6e62006-02-11 12:21:20 -080066 .section .sun4v_2insn_patch, "ax"
67 .word 661b
68 nop
69 nop
70 .previous
71
72 /* For sun4v the ASI_ITLB_DATA_IN store and the retry
73 * instruction get nop'd out and we get here to branch
74 * to the sun4v tlb load code. The registers are setup
75 * as follows:
76 *
77 * %g4: vaddr
78 * %g5: PTE
79 * %g6: TAG
80 *
81 * The sun4v TLB load wants the PTE in %g3 so we fix that
82 * up here.
83 */
84 ba,pt %xcc, sun4v_itlb_load
85 mov %g5, %g3
David S. Miller2a7e2992005-09-21 18:50:51 -070086
David S. Miller74bf4312006-01-31 18:29:18 -080087kvmap_itlb_longpath:
David S. Miller45fec052006-02-05 22:27:28 -080088
89661: rdpr %pstate, %g5
David S. Miller74bf4312006-01-31 18:29:18 -080090 wrpr %g5, PSTATE_AG | PSTATE_MG, %pstate
David S. Millerdf7d6ae2006-02-07 00:00:16 -080091 .section .sun4v_2insn_patch, "ax"
David S. Miller45fec052006-02-05 22:27:28 -080092 .word 661b
93 nop
94 nop
95 .previous
96
David S. Miller74bf4312006-01-31 18:29:18 -080097 rdpr %tpc, %g5
98 ba,pt %xcc, sparc64_realfault_common
99 mov FAULT_CODE_ITLB, %g4
David S. Millerc9c10832005-10-12 12:22:46 -0700100
David S. Miller74bf4312006-01-31 18:29:18 -0800101kvmap_itlb_obp:
102 OBP_TRANS_LOOKUP(%g4, %g5, %g2, %g3, kvmap_itlb_longpath)
David S. Miller2a7e2992005-09-21 18:50:51 -0700103
David S. Miller459b6e62006-02-11 12:21:20 -0800104 KTSB_LOCK_TAG(%g1, %g2, %g7)
David S. Miller2a7e2992005-09-21 18:50:51 -0700105
David S. Miller517af332006-02-01 15:55:21 -0800106 KTSB_WRITE(%g1, %g5, %g6)
David S. Miller2a7e2992005-09-21 18:50:51 -0700107
David S. Miller74bf4312006-01-31 18:29:18 -0800108 ba,pt %xcc, kvmap_itlb_load
109 nop
David S. Millerc9c10832005-10-12 12:22:46 -0700110
David S. Miller74bf4312006-01-31 18:29:18 -0800111kvmap_dtlb_obp:
112 OBP_TRANS_LOOKUP(%g4, %g5, %g2, %g3, kvmap_dtlb_longpath)
113
David S. Miller459b6e62006-02-11 12:21:20 -0800114 KTSB_LOCK_TAG(%g1, %g2, %g7)
David S. Miller74bf4312006-01-31 18:29:18 -0800115
David S. Miller517af332006-02-01 15:55:21 -0800116 KTSB_WRITE(%g1, %g5, %g6)
David S. Miller74bf4312006-01-31 18:29:18 -0800117
118 ba,pt %xcc, kvmap_dtlb_load
119 nop
120
David S. Miller2a7e2992005-09-21 18:50:51 -0700121 .align 32
David S. Miller74bf4312006-01-31 18:29:18 -0800122kvmap_dtlb:
123 /* %g6: TAG TARGET */
124 mov TLB_TAG_ACCESS, %g4
125 ldxa [%g4] ASI_DMMU, %g4
David S. Millerd257d5d2006-02-06 23:44:37 -0800126
127 /* sun4v_dtlb_miss branches here with the missing virtual
128 * address already loaded into %g4
129 */
130kvmap_dtlb_4v:
David S. Miller74bf4312006-01-31 18:29:18 -0800131 brgez,pn %g4, kvmap_dtlb_nonlinear
David S. Miller56425302005-09-25 16:46:57 -0700132 nop
133
David S. Miller74bf4312006-01-31 18:29:18 -0800134#define KERN_HIGHBITS ((_PAGE_VALID|_PAGE_SZ4MB)^0xfffff80000000000)
135#define KERN_LOWBITS (_PAGE_CP | _PAGE_CV | _PAGE_P | _PAGE_W)
136
137 sethi %uhi(KERN_HIGHBITS), %g2
138 or %g2, %ulo(KERN_HIGHBITS), %g2
139 sllx %g2, 32, %g2
140 or %g2, KERN_LOWBITS, %g2
141
142#undef KERN_HIGHBITS
143#undef KERN_LOWBITS
144
David S. Miller56425302005-09-25 16:46:57 -0700145 .globl kvmap_linear_patch
146kvmap_linear_patch:
David S. Miller74bf4312006-01-31 18:29:18 -0800147 ba,pt %xcc, kvmap_dtlb_load
David S. Miller2a7e2992005-09-21 18:50:51 -0700148 xor %g2, %g4, %g5
149
David S. Miller74bf4312006-01-31 18:29:18 -0800150kvmap_dtlb_vmalloc_addr:
151 KERN_PGTABLE_WALK(%g4, %g5, %g2, kvmap_dtlb_longpath)
David S. Miller56425302005-09-25 16:46:57 -0700152
David S. Miller459b6e62006-02-11 12:21:20 -0800153 KTSB_LOCK_TAG(%g1, %g2, %g7)
David S. Miller74bf4312006-01-31 18:29:18 -0800154
155 /* Load and check PTE. */
156 ldxa [%g5] ASI_PHYS_USE_EC, %g5
157 brgez,a,pn %g5, kvmap_dtlb_longpath
David S. Miller517af332006-02-01 15:55:21 -0800158 KTSB_STORE(%g1, %g0)
David S. Miller74bf4312006-01-31 18:29:18 -0800159
David S. Miller517af332006-02-01 15:55:21 -0800160 KTSB_WRITE(%g1, %g5, %g6)
David S. Miller74bf4312006-01-31 18:29:18 -0800161
162 /* fallthrough to TLB load */
163
164kvmap_dtlb_load:
David S. Miller459b6e62006-02-11 12:21:20 -0800165
166661: stxa %g5, [%g0] ASI_DTLB_DATA_IN ! Reload TLB
David S. Miller74bf4312006-01-31 18:29:18 -0800167 retry
David S. Miller459b6e62006-02-11 12:21:20 -0800168 .section .sun4v_2insn_patch, "ax"
169 .word 661b
170 nop
171 nop
172 .previous
173
174 /* For sun4v the ASI_DTLB_DATA_IN store and the retry
175 * instruction get nop'd out and we get here to branch
176 * to the sun4v tlb load code. The registers are setup
177 * as follows:
178 *
179 * %g4: vaddr
180 * %g5: PTE
181 * %g6: TAG
182 *
183 * The sun4v TLB load wants the PTE in %g3 so we fix that
184 * up here.
185 */
186 ba,pt %xcc, sun4v_dtlb_load
187 mov %g5, %g3
David S. Miller74bf4312006-01-31 18:29:18 -0800188
189kvmap_dtlb_nonlinear:
190 /* Catch kernel NULL pointer derefs. */
191 sethi %hi(PAGE_SIZE), %g5
192 cmp %g4, %g5
193 bleu,pn %xcc, kvmap_dtlb_longpath
194 nop
195
196 KERN_TSB_LOOKUP_TL1(%g4, %g6, %g5, %g1, %g2, %g3, kvmap_dtlb_load)
197
198kvmap_dtlb_tsbmiss:
David S. Miller2a7e2992005-09-21 18:50:51 -0700199 sethi %hi(MODULES_VADDR), %g5
200 cmp %g4, %g5
David S. Miller74bf4312006-01-31 18:29:18 -0800201 blu,pn %xcc, kvmap_dtlb_longpath
David S. Miller2a7e2992005-09-21 18:50:51 -0700202 mov (VMALLOC_END >> 24), %g5
203 sllx %g5, 24, %g5
204 cmp %g4, %g5
David S. Miller74bf4312006-01-31 18:29:18 -0800205 bgeu,pn %xcc, kvmap_dtlb_longpath
David S. Miller2a7e2992005-09-21 18:50:51 -0700206 nop
207
208kvmap_check_obp:
209 sethi %hi(LOW_OBP_ADDRESS), %g5
210 cmp %g4, %g5
David S. Miller74bf4312006-01-31 18:29:18 -0800211 blu,pn %xcc, kvmap_dtlb_vmalloc_addr
David S. Miller2a7e2992005-09-21 18:50:51 -0700212 mov 0x1, %g5
213 sllx %g5, 32, %g5
214 cmp %g4, %g5
David S. Miller74bf4312006-01-31 18:29:18 -0800215 blu,pn %xcc, kvmap_dtlb_obp
216 nop
217 ba,pt %xcc, kvmap_dtlb_vmalloc_addr
David S. Miller2a7e2992005-09-21 18:50:51 -0700218 nop
219
David S. Miller74bf4312006-01-31 18:29:18 -0800220kvmap_dtlb_longpath:
David S. Miller45fec052006-02-05 22:27:28 -0800221
222661: rdpr %pstate, %g5
David S. Miller74bf4312006-01-31 18:29:18 -0800223 wrpr %g5, PSTATE_AG | PSTATE_MG, %pstate
David S. Millerdf7d6ae2006-02-07 00:00:16 -0800224 .section .sun4v_2insn_patch, "ax"
David S. Miller45fec052006-02-05 22:27:28 -0800225 .word 661b
226 nop
227 nop
228 .previous
229
David S. Miller459b6e62006-02-11 12:21:20 -0800230 rdpr %tl, %g3
231 cmp %g3, 1
232
233661: mov TLB_TAG_ACCESS, %g4
David S. Miller74bf4312006-01-31 18:29:18 -0800234 ldxa [%g4] ASI_DMMU, %g5
David S. Miller459b6e62006-02-11 12:21:20 -0800235 .section .sun4v_2insn_patch, "ax"
236 .word 661b
237 mov %g4, %g5
238 nop
239 .previous
240
David S. Miller74bf4312006-01-31 18:29:18 -0800241 be,pt %xcc, sparc64_realfault_common
242 mov FAULT_CODE_DTLB, %g4
243 ba,pt %xcc, winfix_trampoline
David S. Miller2a7e2992005-09-21 18:50:51 -0700244 nop