blob: 47dfd45971e851598bc63e468fb10639fea39732 [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. Millerc4bce902006-02-11 21:57:54 -0800134 sethi %hi(kern_linear_pte_xor), %g2
135 ldx [%g2 + %lo(kern_linear_pte_xor)], %g2
David S. Miller74bf4312006-01-31 18:29:18 -0800136
David S. Miller56425302005-09-25 16:46:57 -0700137 .globl kvmap_linear_patch
138kvmap_linear_patch:
David S. Miller74bf4312006-01-31 18:29:18 -0800139 ba,pt %xcc, kvmap_dtlb_load
David S. Miller2a7e2992005-09-21 18:50:51 -0700140 xor %g2, %g4, %g5
141
David S. Miller74bf4312006-01-31 18:29:18 -0800142kvmap_dtlb_vmalloc_addr:
143 KERN_PGTABLE_WALK(%g4, %g5, %g2, kvmap_dtlb_longpath)
David S. Miller56425302005-09-25 16:46:57 -0700144
David S. Miller459b6e62006-02-11 12:21:20 -0800145 KTSB_LOCK_TAG(%g1, %g2, %g7)
David S. Miller74bf4312006-01-31 18:29:18 -0800146
147 /* Load and check PTE. */
148 ldxa [%g5] ASI_PHYS_USE_EC, %g5
149 brgez,a,pn %g5, kvmap_dtlb_longpath
David S. Miller517af332006-02-01 15:55:21 -0800150 KTSB_STORE(%g1, %g0)
David S. Miller74bf4312006-01-31 18:29:18 -0800151
David S. Miller517af332006-02-01 15:55:21 -0800152 KTSB_WRITE(%g1, %g5, %g6)
David S. Miller74bf4312006-01-31 18:29:18 -0800153
154 /* fallthrough to TLB load */
155
156kvmap_dtlb_load:
David S. Miller459b6e62006-02-11 12:21:20 -0800157
158661: stxa %g5, [%g0] ASI_DTLB_DATA_IN ! Reload TLB
David S. Miller74bf4312006-01-31 18:29:18 -0800159 retry
David S. Miller459b6e62006-02-11 12:21:20 -0800160 .section .sun4v_2insn_patch, "ax"
161 .word 661b
162 nop
163 nop
164 .previous
165
166 /* For sun4v the ASI_DTLB_DATA_IN store and the retry
167 * instruction get nop'd out and we get here to branch
168 * to the sun4v tlb load code. The registers are setup
169 * as follows:
170 *
171 * %g4: vaddr
172 * %g5: PTE
173 * %g6: TAG
174 *
175 * The sun4v TLB load wants the PTE in %g3 so we fix that
176 * up here.
177 */
178 ba,pt %xcc, sun4v_dtlb_load
179 mov %g5, %g3
David S. Miller74bf4312006-01-31 18:29:18 -0800180
181kvmap_dtlb_nonlinear:
182 /* Catch kernel NULL pointer derefs. */
183 sethi %hi(PAGE_SIZE), %g5
184 cmp %g4, %g5
185 bleu,pn %xcc, kvmap_dtlb_longpath
186 nop
187
188 KERN_TSB_LOOKUP_TL1(%g4, %g6, %g5, %g1, %g2, %g3, kvmap_dtlb_load)
189
190kvmap_dtlb_tsbmiss:
David S. Miller2a7e2992005-09-21 18:50:51 -0700191 sethi %hi(MODULES_VADDR), %g5
192 cmp %g4, %g5
David S. Miller74bf4312006-01-31 18:29:18 -0800193 blu,pn %xcc, kvmap_dtlb_longpath
David S. Miller2a7e2992005-09-21 18:50:51 -0700194 mov (VMALLOC_END >> 24), %g5
195 sllx %g5, 24, %g5
196 cmp %g4, %g5
David S. Miller74bf4312006-01-31 18:29:18 -0800197 bgeu,pn %xcc, kvmap_dtlb_longpath
David S. Miller2a7e2992005-09-21 18:50:51 -0700198 nop
199
200kvmap_check_obp:
201 sethi %hi(LOW_OBP_ADDRESS), %g5
202 cmp %g4, %g5
David S. Miller74bf4312006-01-31 18:29:18 -0800203 blu,pn %xcc, kvmap_dtlb_vmalloc_addr
David S. Miller2a7e2992005-09-21 18:50:51 -0700204 mov 0x1, %g5
205 sllx %g5, 32, %g5
206 cmp %g4, %g5
David S. Miller74bf4312006-01-31 18:29:18 -0800207 blu,pn %xcc, kvmap_dtlb_obp
208 nop
209 ba,pt %xcc, kvmap_dtlb_vmalloc_addr
David S. Miller2a7e2992005-09-21 18:50:51 -0700210 nop
211
David S. Miller74bf4312006-01-31 18:29:18 -0800212kvmap_dtlb_longpath:
David S. Miller45fec052006-02-05 22:27:28 -0800213
214661: rdpr %pstate, %g5
David S. Miller74bf4312006-01-31 18:29:18 -0800215 wrpr %g5, PSTATE_AG | PSTATE_MG, %pstate
David S. Millerdf7d6ae2006-02-07 00:00:16 -0800216 .section .sun4v_2insn_patch, "ax"
David S. Miller45fec052006-02-05 22:27:28 -0800217 .word 661b
218 nop
219 nop
220 .previous
221
David S. Miller459b6e62006-02-11 12:21:20 -0800222 rdpr %tl, %g3
223 cmp %g3, 1
224
225661: mov TLB_TAG_ACCESS, %g4
David S. Miller74bf4312006-01-31 18:29:18 -0800226 ldxa [%g4] ASI_DMMU, %g5
David S. Miller459b6e62006-02-11 12:21:20 -0800227 .section .sun4v_2insn_patch, "ax"
228 .word 661b
229 mov %g4, %g5
230 nop
231 .previous
232
David S. Miller74bf4312006-01-31 18:29:18 -0800233 be,pt %xcc, sparc64_realfault_common
234 mov FAULT_CODE_DTLB, %g4
235 ba,pt %xcc, winfix_trampoline
David S. Miller2a7e2992005-09-21 18:50:51 -0700236 nop