blob: 2627a7fa33d9a9d71e3128159e83a244742641ce [file] [log] [blame]
David S. Miller2a7e2992005-09-21 18:50:51 -07001/* arch/sparc64/kernel/ktlb.S: Kernel mapping TLB miss handling.
2 *
David S. Millerbf4a7972008-01-10 21:10:54 -08003 * Copyright (C) 1995, 1997, 2005, 2008 David S. Miller <davem@davemloft.net>
David S. Miller2a7e2992005-09-21 18:50:51 -07004 * 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 -080028 /* Catch kernel NULL pointer calls. */
29 sethi %hi(PAGE_SIZE), %g5
30 cmp %g4, %g5
Kirill Tkhai1c2696c2013-08-02 19:23:18 +040031 blu,pn %xcc, kvmap_itlb_longpath
David S. Miller74bf4312006-01-31 18:29:18 -080032 nop
33
34 KERN_TSB_LOOKUP_TL1(%g4, %g6, %g5, %g1, %g2, %g3, kvmap_itlb_load)
35
36kvmap_itlb_tsb_miss:
David S. Miller2a7e2992005-09-21 18:50:51 -070037 sethi %hi(LOW_OBP_ADDRESS), %g5
38 cmp %g4, %g5
David S. Miller74bf4312006-01-31 18:29:18 -080039 blu,pn %xcc, kvmap_itlb_vmalloc_addr
David S. Miller2a7e2992005-09-21 18:50:51 -070040 mov 0x1, %g5
41 sllx %g5, 32, %g5
42 cmp %g4, %g5
David S. Miller74bf4312006-01-31 18:29:18 -080043 blu,pn %xcc, kvmap_itlb_obp
David S. Miller2a7e2992005-09-21 18:50:51 -070044 nop
45
David S. Miller74bf4312006-01-31 18:29:18 -080046kvmap_itlb_vmalloc_addr:
47 KERN_PGTABLE_WALK(%g4, %g5, %g2, kvmap_itlb_longpath)
David S. Miller2a7e2992005-09-21 18:50:51 -070048
David S. Miller9076d0e2011-08-05 00:53:57 -070049 TSB_LOCK_TAG(%g1, %g2, %g7)
David S. Miller9076d0e2011-08-05 00:53:57 -070050 TSB_WRITE(%g1, %g5, %g6)
David S. Miller2a7e2992005-09-21 18:50:51 -070051
David S. Miller74bf4312006-01-31 18:29:18 -080052 /* fallthrough to TLB load */
David S. Miller2a7e2992005-09-21 18:50:51 -070053
David S. Miller74bf4312006-01-31 18:29:18 -080054kvmap_itlb_load:
David S. Miller459b6e62006-02-11 12:21:20 -080055
56661: stxa %g5, [%g0] ASI_ITLB_DATA_IN
David S. Miller2a7e2992005-09-21 18:50:51 -070057 retry
David S. Miller459b6e62006-02-11 12:21:20 -080058 .section .sun4v_2insn_patch, "ax"
59 .word 661b
60 nop
61 nop
62 .previous
63
64 /* For sun4v the ASI_ITLB_DATA_IN store and the retry
65 * instruction get nop'd out and we get here to branch
66 * to the sun4v tlb load code. The registers are setup
67 * as follows:
68 *
69 * %g4: vaddr
70 * %g5: PTE
71 * %g6: TAG
72 *
73 * The sun4v TLB load wants the PTE in %g3 so we fix that
74 * up here.
75 */
76 ba,pt %xcc, sun4v_itlb_load
77 mov %g5, %g3
David S. Miller2a7e2992005-09-21 18:50:51 -070078
David S. Miller74bf4312006-01-31 18:29:18 -080079kvmap_itlb_longpath:
David S. Miller45fec052006-02-05 22:27:28 -080080
81661: rdpr %pstate, %g5
David S. Miller74bf4312006-01-31 18:29:18 -080082 wrpr %g5, PSTATE_AG | PSTATE_MG, %pstate
David S. Millerdf7d6ae2006-02-07 00:00:16 -080083 .section .sun4v_2insn_patch, "ax"
David S. Miller45fec052006-02-05 22:27:28 -080084 .word 661b
David S. Miller6cc200d2006-02-18 16:36:39 -080085 SET_GL(1)
David S. Miller45fec052006-02-05 22:27:28 -080086 nop
87 .previous
88
David S. Miller74bf4312006-01-31 18:29:18 -080089 rdpr %tpc, %g5
90 ba,pt %xcc, sparc64_realfault_common
91 mov FAULT_CODE_ITLB, %g4
David S. Millerc9c10832005-10-12 12:22:46 -070092
David S. Miller74bf4312006-01-31 18:29:18 -080093kvmap_itlb_obp:
94 OBP_TRANS_LOOKUP(%g4, %g5, %g2, %g3, kvmap_itlb_longpath)
David S. Miller2a7e2992005-09-21 18:50:51 -070095
David S. Miller9076d0e2011-08-05 00:53:57 -070096 TSB_LOCK_TAG(%g1, %g2, %g7)
David S. Miller2a7e2992005-09-21 18:50:51 -070097
David S. Miller9076d0e2011-08-05 00:53:57 -070098 TSB_WRITE(%g1, %g5, %g6)
David S. Miller2a7e2992005-09-21 18:50:51 -070099
David S. Miller74bf4312006-01-31 18:29:18 -0800100 ba,pt %xcc, kvmap_itlb_load
101 nop
David S. Millerc9c10832005-10-12 12:22:46 -0700102
David S. Miller74bf4312006-01-31 18:29:18 -0800103kvmap_dtlb_obp:
104 OBP_TRANS_LOOKUP(%g4, %g5, %g2, %g3, kvmap_dtlb_longpath)
105
David S. Miller9076d0e2011-08-05 00:53:57 -0700106 TSB_LOCK_TAG(%g1, %g2, %g7)
David S. Miller74bf4312006-01-31 18:29:18 -0800107
David S. Miller9076d0e2011-08-05 00:53:57 -0700108 TSB_WRITE(%g1, %g5, %g6)
David S. Miller74bf4312006-01-31 18:29:18 -0800109
110 ba,pt %xcc, kvmap_dtlb_load
111 nop
112
David S. Miller0dd5b7b2014-09-24 20:56:11 -0700113kvmap_linear_early:
114 sethi %hi(kern_linear_pte_xor), %g7
115 ldx [%g7 + %lo(kern_linear_pte_xor)], %g2
116 ba,pt %xcc, kvmap_dtlb_tsb4m_load
117 xor %g2, %g4, %g5
118
David S. Miller2a7e2992005-09-21 18:50:51 -0700119 .align 32
David S. Millerd7744a02006-02-21 22:31:11 -0800120kvmap_dtlb_tsb4m_load:
David S. Miller9076d0e2011-08-05 00:53:57 -0700121 TSB_LOCK_TAG(%g1, %g2, %g7)
122 TSB_WRITE(%g1, %g5, %g6)
David S. Millerd7744a02006-02-21 22:31:11 -0800123 ba,pt %xcc, kvmap_dtlb_load
124 nop
125
David S. Miller74bf4312006-01-31 18:29:18 -0800126kvmap_dtlb:
127 /* %g6: TAG TARGET */
128 mov TLB_TAG_ACCESS, %g4
129 ldxa [%g4] ASI_DMMU, %g4
David S. Millerd257d5d2006-02-06 23:44:37 -0800130
131 /* sun4v_dtlb_miss branches here with the missing virtual
132 * address already loaded into %g4
133 */
134kvmap_dtlb_4v:
David S. Miller74bf4312006-01-31 18:29:18 -0800135 brgez,pn %g4, kvmap_dtlb_nonlinear
David S. Miller56425302005-09-25 16:46:57 -0700136 nop
137
David S. Millerd1acb422007-03-16 17:20:28 -0700138#ifdef CONFIG_DEBUG_PAGEALLOC
139 /* Index through the base page size TSB even for linear
140 * mappings when using page allocation debugging.
141 */
142 KERN_TSB_LOOKUP_TL1(%g4, %g6, %g5, %g1, %g2, %g3, kvmap_dtlb_load)
143#else
David S. Millerd7744a02006-02-21 22:31:11 -0800144 /* Correct TAG_TARGET is already in %g6, check 4mb TSB. */
145 KERN_TSB4M_LOOKUP_TL1(%g6, %g5, %g1, %g2, %g3, kvmap_dtlb_load)
David S. Millerd1acb422007-03-16 17:20:28 -0700146#endif
David S. Miller0dd5b7b2014-09-24 20:56:11 -0700147 /* Linear mapping TSB lookup failed. Fallthrough to kernel
148 * page table based lookup.
David S. Millerd7744a02006-02-21 22:31:11 -0800149 */
David S. Miller56425302005-09-25 16:46:57 -0700150 .globl kvmap_linear_patch
151kvmap_linear_patch:
David S. Miller0dd5b7b2014-09-24 20:56:11 -0700152 ba,a,pt %xcc, kvmap_linear_early
David S. Miller2a7e2992005-09-21 18:50:51 -0700153
David S. Miller74bf4312006-01-31 18:29:18 -0800154kvmap_dtlb_vmalloc_addr:
155 KERN_PGTABLE_WALK(%g4, %g5, %g2, kvmap_dtlb_longpath)
David S. Miller56425302005-09-25 16:46:57 -0700156
David S. Miller9076d0e2011-08-05 00:53:57 -0700157 TSB_LOCK_TAG(%g1, %g2, %g7)
David S. Miller9076d0e2011-08-05 00:53:57 -0700158 TSB_WRITE(%g1, %g5, %g6)
David S. Miller74bf4312006-01-31 18:29:18 -0800159
160 /* fallthrough to TLB load */
161
162kvmap_dtlb_load:
David S. Miller459b6e62006-02-11 12:21:20 -0800163
164661: stxa %g5, [%g0] ASI_DTLB_DATA_IN ! Reload TLB
David S. Miller74bf4312006-01-31 18:29:18 -0800165 retry
David S. Miller459b6e62006-02-11 12:21:20 -0800166 .section .sun4v_2insn_patch, "ax"
167 .word 661b
168 nop
169 nop
170 .previous
171
172 /* For sun4v the ASI_DTLB_DATA_IN store and the retry
173 * instruction get nop'd out and we get here to branch
174 * to the sun4v tlb load code. The registers are setup
175 * as follows:
176 *
177 * %g4: vaddr
178 * %g5: PTE
179 * %g6: TAG
180 *
181 * The sun4v TLB load wants the PTE in %g3 so we fix that
182 * up here.
183 */
184 ba,pt %xcc, sun4v_dtlb_load
185 mov %g5, %g3
David S. Miller74bf4312006-01-31 18:29:18 -0800186
David S. Millerbf4a7972008-01-10 21:10:54 -0800187#ifdef CONFIG_SPARSEMEM_VMEMMAP
David Miller46644c22007-10-16 01:24:16 -0700188kvmap_vmemmap:
David S. Millerc06240c2014-09-24 21:20:14 -0700189 KERN_PGTABLE_WALK(%g4, %g5, %g2, kvmap_dtlb_longpath)
190 ba,a,pt %xcc, kvmap_dtlb_load
David S. Millerbf4a7972008-01-10 21:10:54 -0800191#endif
David Miller46644c22007-10-16 01:24:16 -0700192
David S. Miller74bf4312006-01-31 18:29:18 -0800193kvmap_dtlb_nonlinear:
194 /* Catch kernel NULL pointer derefs. */
195 sethi %hi(PAGE_SIZE), %g5
196 cmp %g4, %g5
197 bleu,pn %xcc, kvmap_dtlb_longpath
198 nop
199
David S. Millerbf4a7972008-01-10 21:10:54 -0800200#ifdef CONFIG_SPARSEMEM_VMEMMAP
David Miller46644c22007-10-16 01:24:16 -0700201 /* Do not use the TSB for vmemmap. */
David S. Miller1b6b9d62009-09-28 14:39:58 -0700202 mov (VMEMMAP_BASE >> 40), %g5
203 sllx %g5, 40, %g5
David Miller46644c22007-10-16 01:24:16 -0700204 cmp %g4,%g5
205 bgeu,pn %xcc, kvmap_vmemmap
206 nop
David S. Millerbf4a7972008-01-10 21:10:54 -0800207#endif
David Miller46644c22007-10-16 01:24:16 -0700208
David S. Miller74bf4312006-01-31 18:29:18 -0800209 KERN_TSB_LOOKUP_TL1(%g4, %g6, %g5, %g1, %g2, %g3, kvmap_dtlb_load)
210
211kvmap_dtlb_tsbmiss:
David S. Miller2a7e2992005-09-21 18:50:51 -0700212 sethi %hi(MODULES_VADDR), %g5
213 cmp %g4, %g5
David S. Miller74bf4312006-01-31 18:29:18 -0800214 blu,pn %xcc, kvmap_dtlb_longpath
David S. Miller1b6b9d62009-09-28 14:39:58 -0700215 mov (VMALLOC_END >> 40), %g5
216 sllx %g5, 40, %g5
David S. Miller2a7e2992005-09-21 18:50:51 -0700217 cmp %g4, %g5
David S. Miller74bf4312006-01-31 18:29:18 -0800218 bgeu,pn %xcc, kvmap_dtlb_longpath
David S. Miller2a7e2992005-09-21 18:50:51 -0700219 nop
220
221kvmap_check_obp:
222 sethi %hi(LOW_OBP_ADDRESS), %g5
223 cmp %g4, %g5
David S. Miller74bf4312006-01-31 18:29:18 -0800224 blu,pn %xcc, kvmap_dtlb_vmalloc_addr
David S. Miller2a7e2992005-09-21 18:50:51 -0700225 mov 0x1, %g5
226 sllx %g5, 32, %g5
227 cmp %g4, %g5
David S. Miller74bf4312006-01-31 18:29:18 -0800228 blu,pn %xcc, kvmap_dtlb_obp
229 nop
230 ba,pt %xcc, kvmap_dtlb_vmalloc_addr
David S. Miller2a7e2992005-09-21 18:50:51 -0700231 nop
232
David S. Miller74bf4312006-01-31 18:29:18 -0800233kvmap_dtlb_longpath:
David S. Miller45fec052006-02-05 22:27:28 -0800234
235661: rdpr %pstate, %g5
David S. Miller74bf4312006-01-31 18:29:18 -0800236 wrpr %g5, PSTATE_AG | PSTATE_MG, %pstate
David S. Millerdf7d6ae2006-02-07 00:00:16 -0800237 .section .sun4v_2insn_patch, "ax"
David S. Miller45fec052006-02-05 22:27:28 -0800238 .word 661b
David S. Miller8b234272006-02-17 18:01:02 -0800239 SET_GL(1)
240 ldxa [%g0] ASI_SCRATCHPAD, %g5
David S. Miller45fec052006-02-05 22:27:28 -0800241 .previous
242
David S. Miller459b6e62006-02-11 12:21:20 -0800243 rdpr %tl, %g3
244 cmp %g3, 1
245
246661: mov TLB_TAG_ACCESS, %g4
David S. Miller74bf4312006-01-31 18:29:18 -0800247 ldxa [%g4] ASI_DMMU, %g5
David S. Miller459b6e62006-02-11 12:21:20 -0800248 .section .sun4v_2insn_patch, "ax"
249 .word 661b
David S. Miller8b234272006-02-17 18:01:02 -0800250 ldx [%g5 + HV_FAULT_D_ADDR_OFFSET], %g5
David S. Miller459b6e62006-02-11 12:21:20 -0800251 nop
252 .previous
253
David S. Miller74bf4312006-01-31 18:29:18 -0800254 be,pt %xcc, sparc64_realfault_common
255 mov FAULT_CODE_DTLB, %g4
256 ba,pt %xcc, winfix_trampoline
David S. Miller2a7e2992005-09-21 18:50:51 -0700257 nop