1 /* SPDX-License-Identifier: GPL-2.0 */
2 /* arch/sparc64/kernel/ktlb.S: Kernel mapping TLB miss handling.
4 * Copyright (C) 1995, 1997, 2005, 2008 David S. Miller <davem@davemloft.net>
5 * Copyright (C) 1996 Eddie C. Dost (ecd@brainaid.de)
6 * Copyright (C) 1996 Miguel de Icaza (miguel@nuclecu.unam.mx)
7 * Copyright (C) 1996,98,99 Jakub Jelinek (jj@sunsite.mff.cuni.cz)
10 #include <linux/pgtable.h>
21 mov TLB_TAG_ACCESS, %g4
22 ldxa [%g4] ASI_IMMU, %g4
24 /* The kernel executes in context zero, therefore we do not
25 * need to clear the context ID bits out of %g4 here.
28 /* sun4v_itlb_miss branches here with the missing virtual
29 * address already loaded into %g4
33 /* Catch kernel NULL pointer calls. */
34 sethi %hi(PAGE_SIZE), %g5
36 blu,pn %xcc, kvmap_itlb_longpath
39 KERN_TSB_LOOKUP_TL1(%g4, %g6, %g5, %g1, %g2, %g3, kvmap_itlb_load)
42 sethi %hi(LOW_OBP_ADDRESS), %g5
44 blu,pn %xcc, kvmap_itlb_vmalloc_addr
48 blu,pn %xcc, kvmap_itlb_obp
51 kvmap_itlb_vmalloc_addr:
52 KERN_PGTABLE_WALK(%g4, %g5, %g2, kvmap_itlb_longpath)
54 TSB_LOCK_TAG(%g1, %g2, %g7)
55 TSB_WRITE(%g1, %g5, %g6)
57 /* fallthrough to TLB load */
61 661: stxa %g5, [%g0] ASI_ITLB_DATA_IN
63 .section .sun4v_2insn_patch, "ax"
69 /* For sun4v the ASI_ITLB_DATA_IN store and the retry
70 * instruction get nop'd out and we get here to branch
71 * to the sun4v tlb load code. The registers are setup
78 * The sun4v TLB load wants the PTE in %g3 so we fix that
81 ba,pt %xcc, sun4v_itlb_load
86 661: rdpr %pstate, %g5
87 wrpr %g5, PSTATE_AG | PSTATE_MG, %pstate
88 .section .sun4v_2insn_patch, "ax"
95 ba,pt %xcc, sparc64_realfault_common
96 mov FAULT_CODE_ITLB, %g4
99 OBP_TRANS_LOOKUP(%g4, %g5, %g2, %g3, kvmap_itlb_longpath)
101 TSB_LOCK_TAG(%g1, %g2, %g7)
103 TSB_WRITE(%g1, %g5, %g6)
105 ba,pt %xcc, kvmap_itlb_load
109 OBP_TRANS_LOOKUP(%g4, %g5, %g2, %g3, kvmap_dtlb_longpath)
111 TSB_LOCK_TAG(%g1, %g2, %g7)
113 TSB_WRITE(%g1, %g5, %g6)
115 ba,pt %xcc, kvmap_dtlb_load
119 sethi %hi(kern_linear_pte_xor), %g7
120 ldx [%g7 + %lo(kern_linear_pte_xor)], %g2
121 ba,pt %xcc, kvmap_dtlb_tsb4m_load
125 kvmap_dtlb_tsb4m_load:
126 TSB_LOCK_TAG(%g1, %g2, %g7)
127 TSB_WRITE(%g1, %g5, %g6)
128 ba,pt %xcc, kvmap_dtlb_load
132 /* %g6: TAG TARGET */
133 mov TLB_TAG_ACCESS, %g4
134 ldxa [%g4] ASI_DMMU, %g4
136 /* The kernel executes in context zero, therefore we do not
137 * need to clear the context ID bits out of %g4 here.
140 /* sun4v_dtlb_miss branches here with the missing virtual
141 * address already loaded into %g4
144 brgez,pn %g4, kvmap_dtlb_nonlinear
147 #ifdef CONFIG_DEBUG_PAGEALLOC
148 /* Index through the base page size TSB even for linear
149 * mappings when using page allocation debugging.
151 KERN_TSB_LOOKUP_TL1(%g4, %g6, %g5, %g1, %g2, %g3, kvmap_dtlb_load)
153 /* Correct TAG_TARGET is already in %g6, check 4mb TSB. */
154 KERN_TSB4M_LOOKUP_TL1(%g6, %g5, %g1, %g2, %g3, kvmap_dtlb_load)
156 /* Linear mapping TSB lookup failed. Fallthrough to kernel
157 * page table based lookup.
159 .globl kvmap_linear_patch
161 ba,a,pt %xcc, kvmap_linear_early
163 kvmap_dtlb_vmalloc_addr:
164 KERN_PGTABLE_WALK(%g4, %g5, %g2, kvmap_dtlb_longpath)
166 TSB_LOCK_TAG(%g1, %g2, %g7)
167 TSB_WRITE(%g1, %g5, %g6)
169 /* fallthrough to TLB load */
173 661: stxa %g5, [%g0] ASI_DTLB_DATA_IN ! Reload TLB
175 .section .sun4v_2insn_patch, "ax"
181 /* For sun4v the ASI_DTLB_DATA_IN store and the retry
182 * instruction get nop'd out and we get here to branch
183 * to the sun4v tlb load code. The registers are setup
190 * The sun4v TLB load wants the PTE in %g3 so we fix that
193 ba,pt %xcc, sun4v_dtlb_load
196 #ifdef CONFIG_SPARSEMEM_VMEMMAP
198 KERN_PGTABLE_WALK(%g4, %g5, %g2, kvmap_dtlb_longpath)
199 ba,a,pt %xcc, kvmap_dtlb_load
202 kvmap_dtlb_nonlinear:
203 /* Catch kernel NULL pointer derefs. */
204 sethi %hi(PAGE_SIZE), %g5
206 bleu,pn %xcc, kvmap_dtlb_longpath
209 #ifdef CONFIG_SPARSEMEM_VMEMMAP
210 /* Do not use the TSB for vmemmap. */
211 sethi %hi(VMEMMAP_BASE), %g5
212 ldx [%g5 + %lo(VMEMMAP_BASE)], %g5
214 bgeu,pn %xcc, kvmap_vmemmap
218 KERN_TSB_LOOKUP_TL1(%g4, %g6, %g5, %g1, %g2, %g3, kvmap_dtlb_load)
221 sethi %hi(MODULES_VADDR), %g5
223 blu,pn %xcc, kvmap_dtlb_longpath
224 sethi %hi(VMALLOC_END), %g5
225 ldx [%g5 + %lo(VMALLOC_END)], %g5
227 bgeu,pn %xcc, kvmap_dtlb_longpath
231 sethi %hi(LOW_OBP_ADDRESS), %g5
233 blu,pn %xcc, kvmap_dtlb_vmalloc_addr
237 blu,pn %xcc, kvmap_dtlb_obp
239 ba,pt %xcc, kvmap_dtlb_vmalloc_addr
244 661: rdpr %pstate, %g5
245 wrpr %g5, PSTATE_AG | PSTATE_MG, %pstate
246 .section .sun4v_2insn_patch, "ax"
249 ldxa [%g0] ASI_SCRATCHPAD, %g5
255 661: mov TLB_TAG_ACCESS, %g4
256 ldxa [%g4] ASI_DMMU, %g5
257 .section .sun4v_2insn_patch, "ax"
259 ldx [%g5 + HV_FAULT_D_ADDR_OFFSET], %g5
263 /* The kernel executes in context zero, therefore we do not
264 * need to clear the context ID bits out of %g5 here.
267 be,pt %xcc, sparc64_realfault_common
268 mov FAULT_CODE_DTLB, %g4
269 ba,pt %xcc, winfix_trampoline