1 /* arch/sparc64/kernel/ktlb.S: Kernel mapping TLB miss handling.
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)
12 #include <asm/pgtable.h>
20 mov TLB_TAG_ACCESS, %g4
21 ldxa [%g4] ASI_IMMU, %g4
23 /* sun4v_itlb_miss branches here with the missing virtual
24 * address already loaded into %g4
29 /* Catch kernel NULL pointer calls. */
30 sethi %hi(PAGE_SIZE), %g5
32 bleu,pn %xcc, kvmap_dtlb_longpath
35 KERN_TSB_LOOKUP_TL1(%g4, %g6, %g5, %g1, %g2, %g3, kvmap_itlb_load)
38 sethi %hi(LOW_OBP_ADDRESS), %g5
40 blu,pn %xcc, kvmap_itlb_vmalloc_addr
44 blu,pn %xcc, kvmap_itlb_obp
47 kvmap_itlb_vmalloc_addr:
48 KERN_PGTABLE_WALK(%g4, %g5, %g2, kvmap_itlb_longpath)
50 KTSB_LOCK_TAG(%g1, %g2, %g7)
52 /* Load and check PTE. */
53 ldxa [%g5] ASI_PHYS_USE_EC, %g5
55 sllx %g7, TSB_TAG_INVALID_BIT, %g7
56 brgez,a,pn %g5, kvmap_itlb_longpath
59 KTSB_WRITE(%g1, %g5, %g6)
61 /* fallthrough to TLB load */
65 661: stxa %g5, [%g0] ASI_ITLB_DATA_IN
67 .section .sun4v_2insn_patch, "ax"
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
82 * The sun4v TLB load wants the PTE in %g3 so we fix that
85 ba,pt %xcc, sun4v_itlb_load
90 661: rdpr %pstate, %g5
91 wrpr %g5, PSTATE_AG | PSTATE_MG, %pstate
92 .section .sun4v_2insn_patch, "ax"
99 ba,pt %xcc, sparc64_realfault_common
100 mov FAULT_CODE_ITLB, %g4
103 OBP_TRANS_LOOKUP(%g4, %g5, %g2, %g3, kvmap_itlb_longpath)
105 KTSB_LOCK_TAG(%g1, %g2, %g7)
107 KTSB_WRITE(%g1, %g5, %g6)
109 ba,pt %xcc, kvmap_itlb_load
113 OBP_TRANS_LOOKUP(%g4, %g5, %g2, %g3, kvmap_dtlb_longpath)
115 KTSB_LOCK_TAG(%g1, %g2, %g7)
117 KTSB_WRITE(%g1, %g5, %g6)
119 ba,pt %xcc, kvmap_dtlb_load
123 kvmap_dtlb_tsb4m_load:
124 KTSB_LOCK_TAG(%g1, %g2, %g7)
125 KTSB_WRITE(%g1, %g5, %g6)
126 ba,pt %xcc, kvmap_dtlb_load
130 /* %g6: TAG TARGET */
131 mov TLB_TAG_ACCESS, %g4
132 ldxa [%g4] ASI_DMMU, %g4
134 /* sun4v_dtlb_miss branches here with the missing virtual
135 * address already loaded into %g4
138 brgez,pn %g4, kvmap_dtlb_nonlinear
141 #ifdef CONFIG_DEBUG_PAGEALLOC
142 /* Index through the base page size TSB even for linear
143 * mappings when using page allocation debugging.
145 KERN_TSB_LOOKUP_TL1(%g4, %g6, %g5, %g1, %g2, %g3, kvmap_dtlb_load)
147 /* Correct TAG_TARGET is already in %g6, check 4mb TSB. */
148 KERN_TSB4M_LOOKUP_TL1(%g6, %g5, %g1, %g2, %g3, kvmap_dtlb_load)
150 /* TSB entry address left in %g1, lookup linear PTE.
151 * Must preserve %g1 and %g6 (TAG).
153 kvmap_dtlb_tsb4m_miss:
154 sethi %hi(kpte_linear_bitmap), %g2
155 or %g2, %lo(kpte_linear_bitmap), %g2
157 /* Clear the PAGE_OFFSET top virtual bits, then shift
158 * down to get a 256MB physical address index.
162 srlx %g5, 21 + 28, %g5
164 /* Don't try this at home kids... this depends upon srlx
165 * only taking the low 6 bits of the shift count in %g5.
169 /* Divide by 64 to get the offset into the bitmask. */
173 /* kern_linear_pte_xor[((mask & bit) ? 1 : 0)] */
176 sethi %hi(kern_linear_pte_xor), %g5
177 or %g5, %lo(kern_linear_pte_xor), %g5
183 .globl kvmap_linear_patch
185 ba,pt %xcc, kvmap_dtlb_tsb4m_load
188 kvmap_dtlb_vmalloc_addr:
189 KERN_PGTABLE_WALK(%g4, %g5, %g2, kvmap_dtlb_longpath)
191 KTSB_LOCK_TAG(%g1, %g2, %g7)
193 /* Load and check PTE. */
194 ldxa [%g5] ASI_PHYS_USE_EC, %g5
196 sllx %g7, TSB_TAG_INVALID_BIT, %g7
197 brgez,a,pn %g5, kvmap_dtlb_longpath
200 KTSB_WRITE(%g1, %g5, %g6)
202 /* fallthrough to TLB load */
206 661: stxa %g5, [%g0] ASI_DTLB_DATA_IN ! Reload TLB
208 .section .sun4v_2insn_patch, "ax"
214 /* For sun4v the ASI_DTLB_DATA_IN store and the retry
215 * instruction get nop'd out and we get here to branch
216 * to the sun4v tlb load code. The registers are setup
223 * The sun4v TLB load wants the PTE in %g3 so we fix that
226 ba,pt %xcc, sun4v_dtlb_load
229 kvmap_dtlb_nonlinear:
230 /* Catch kernel NULL pointer derefs. */
231 sethi %hi(PAGE_SIZE), %g5
233 bleu,pn %xcc, kvmap_dtlb_longpath
236 KERN_TSB_LOOKUP_TL1(%g4, %g6, %g5, %g1, %g2, %g3, kvmap_dtlb_load)
239 sethi %hi(MODULES_VADDR), %g5
241 blu,pn %xcc, kvmap_dtlb_longpath
242 mov (VMALLOC_END >> 24), %g5
245 bgeu,pn %xcc, kvmap_dtlb_longpath
249 sethi %hi(LOW_OBP_ADDRESS), %g5
251 blu,pn %xcc, kvmap_dtlb_vmalloc_addr
255 blu,pn %xcc, kvmap_dtlb_obp
257 ba,pt %xcc, kvmap_dtlb_vmalloc_addr
262 661: rdpr %pstate, %g5
263 wrpr %g5, PSTATE_AG | PSTATE_MG, %pstate
264 .section .sun4v_2insn_patch, "ax"
267 ldxa [%g0] ASI_SCRATCHPAD, %g5
273 661: mov TLB_TAG_ACCESS, %g4
274 ldxa [%g4] ASI_DMMU, %g5
275 .section .sun4v_2insn_patch, "ax"
277 ldx [%g5 + HV_FAULT_D_ADDR_OFFSET], %g5
281 be,pt %xcc, sparc64_realfault_common
282 mov FAULT_CODE_DTLB, %g4
283 ba,pt %xcc, winfix_trampoline