1 /* SPDX-License-Identifier: GPL-2.0 */
2 /* sun4v_tlb_miss.S: Sun4v TLB miss handlers.
4 * Copyright (C) 2006 <davem@davemloft.net>
10 /* Load ITLB fault information into VADDR and CTX, using BASE. */
11 #define LOAD_ITLB_INFO(BASE, VADDR, CTX) \
12 ldx [BASE + HV_FAULT_I_ADDR_OFFSET], VADDR; \
13 ldx [BASE + HV_FAULT_I_CTX_OFFSET], CTX;
15 /* Load DTLB fault information into VADDR and CTX, using BASE. */
16 #define LOAD_DTLB_INFO(BASE, VADDR, CTX) \
17 ldx [BASE + HV_FAULT_D_ADDR_OFFSET], VADDR; \
18 ldx [BASE + HV_FAULT_D_CTX_OFFSET], CTX;
20 /* DEST = (VADDR >> 22)
22 * Branch to ZERO_CTX_LABEL if context is zero.
24 #define COMPUTE_TAG_TARGET(DEST, VADDR, CTX, ZERO_CTX_LABEL) \
25 srlx VADDR, 22, DEST; \
26 brz,pn CTX, ZERO_CTX_LABEL; \
29 /* Create TSB pointer. This is something like:
31 * index_mask = (512 << (tsb_reg & 0x7UL)) - 1UL;
32 * tsb_base = tsb_reg & ~0x7UL;
33 * tsb_index = ((vaddr >> HASH_SHIFT) & tsb_mask);
34 * tsb_ptr = tsb_base + (tsb_index * 16);
36 #define COMPUTE_TSB_PTR(TSB_PTR, VADDR, HASH_SHIFT, TMP1, TMP2) \
37 and TSB_PTR, 0x7, TMP1; \
39 andn TSB_PTR, 0x7, TSB_PTR; \
40 sllx TMP2, TMP1, TMP2; \
41 srlx VADDR, HASH_SHIFT, TMP1; \
43 and TMP1, TMP2, TMP1; \
45 add TSB_PTR, TMP1, TSB_PTR;
48 /* Load MMU Miss base into %g2. */
49 ldxa [%g0] ASI_SCRATCHPAD, %g2
51 /* Load UTSB reg into %g1. */
52 mov SCRATCHPAD_UTSBREG1, %g1
53 ldxa [%g1] ASI_SCRATCHPAD, %g1
55 LOAD_ITLB_INFO(%g2, %g4, %g5)
56 COMPUTE_TAG_TARGET(%g6, %g4, %g5, kvmap_itlb_4v)
57 COMPUTE_TSB_PTR(%g1, %g4, PAGE_SHIFT, %g3, %g7)
59 /* Load TSB tag/pte into %g2/%g3 and compare the tag. */
60 ldda [%g1] ASI_QUAD_LDD_PHYS_4V, %g2
62 bne,a,pn %xcc, tsb_miss_page_table_walk
63 mov FAULT_CODE_ITLB, %g3
64 andcc %g3, _PAGE_EXEC_4V, %g0
65 be,a,pn %xcc, tsb_do_fault
66 mov FAULT_CODE_ITLB, %g3
68 /* We have a valid entry, make hypervisor call to load
69 * I-TLB and return from trap.
75 ldxa [%g0] ASI_SCRATCHPAD, %g6
76 mov %o0, %g1 ! save %o0
77 mov %o1, %g2 ! save %o1
78 mov %o2, %g5 ! save %o2
79 mov %o3, %g7 ! save %o3
81 ldx [%g6 + HV_FAULT_I_CTX_OFFSET], %o1 ! ctx
83 mov HV_MMU_IMMU, %o3 ! flags
84 ta HV_MMU_MAP_ADDR_TRAP
85 brnz,pn %o0, sun4v_itlb_error
86 mov %g2, %o1 ! restore %o1
87 mov %g1, %o0 ! restore %o0
88 mov %g5, %o2 ! restore %o2
89 mov %g7, %o3 ! restore %o3
94 /* Load MMU Miss base into %g2. */
95 ldxa [%g0] ASI_SCRATCHPAD, %g2
97 /* Load UTSB reg into %g1. */
98 mov SCRATCHPAD_UTSBREG1, %g1
99 ldxa [%g1] ASI_SCRATCHPAD, %g1
101 LOAD_DTLB_INFO(%g2, %g4, %g5)
102 COMPUTE_TAG_TARGET(%g6, %g4, %g5, kvmap_dtlb_4v)
103 COMPUTE_TSB_PTR(%g1, %g4, PAGE_SHIFT, %g3, %g7)
105 /* Load TSB tag/pte into %g2/%g3 and compare the tag. */
106 ldda [%g1] ASI_QUAD_LDD_PHYS_4V, %g2
108 bne,a,pn %xcc, tsb_miss_page_table_walk
109 mov FAULT_CODE_DTLB, %g3
111 /* We have a valid entry, make hypervisor call to load
112 * D-TLB and return from trap.
118 ldxa [%g0] ASI_SCRATCHPAD, %g6
119 mov %o0, %g1 ! save %o0
120 mov %o1, %g2 ! save %o1
121 mov %o2, %g5 ! save %o2
122 mov %o3, %g7 ! save %o3
124 ldx [%g6 + HV_FAULT_D_CTX_OFFSET], %o1 ! ctx
126 mov HV_MMU_DMMU, %o3 ! flags
127 ta HV_MMU_MAP_ADDR_TRAP
128 brnz,pn %o0, sun4v_dtlb_error
129 mov %g2, %o1 ! restore %o1
130 mov %g1, %o0 ! restore %o0
131 mov %g5, %o2 ! restore %o2
132 mov %g7, %o3 ! restore %o3
139 /* Load MMU Miss base into %g5. */
140 ldxa [%g0] ASI_SCRATCHPAD, %g5
142 ldx [%g5 + HV_FAULT_D_ADDR_OFFSET], %g5
145 bgu,pn %xcc, winfix_trampoline
146 mov FAULT_CODE_DTLB | FAULT_CODE_WRITE, %g4
147 ba,pt %xcc, sparc64_realfault_common
150 /* Called from trap table:
156 mov SCRATCHPAD_UTSBREG1, %g1
157 ldxa [%g1] ASI_SCRATCHPAD, %g1
158 brz,pn %g5, kvmap_itlb_4v
159 mov FAULT_CODE_ITLB, %g3
160 ba,a,pt %xcc, sun4v_tsb_miss_common
162 /* Called from trap table:
168 mov SCRATCHPAD_UTSBREG1, %g1
169 ldxa [%g1] ASI_SCRATCHPAD, %g1
170 brz,pn %g5, kvmap_dtlb_4v
171 mov FAULT_CODE_DTLB, %g3
175 sun4v_tsb_miss_common:
176 COMPUTE_TSB_PTR(%g1, %g4, PAGE_SHIFT, %g5, %g7)
178 sub %g2, TRAP_PER_CPU_FAULT_INFO, %g2
180 #if defined(CONFIG_HUGETLB_PAGE) || defined(CONFIG_TRANSPARENT_HUGEPAGE)
181 mov SCRATCHPAD_UTSBREG2, %g5
182 ldxa [%g5] ASI_SCRATCHPAD, %g5
186 COMPUTE_TSB_PTR(%g5, %g4, REAL_HPAGE_SHIFT, %g2, %g7)
188 /* That clobbered %g2, reload it. */
189 ldxa [%g0] ASI_SCRATCHPAD, %g2
190 sub %g2, TRAP_PER_CPU_FAULT_INFO, %g2
192 80: stx %g5, [%g2 + TRAP_PER_CPU_TSB_HUGE_TEMP]
195 ba,pt %xcc, tsb_miss_page_table_walk_sun4v_fastpath
196 ldx [%g2 + TRAP_PER_CPU_PGD_PADDR], %g7
201 ble,pt %icc, sun4v_bad_ra
202 or %g0, FAULT_CODE_BAD_RA | FAULT_CODE_ITLB, %g1
204 sethi %hi(sun4v_err_itlb_vaddr), %g1
205 stx %g4, [%g1 + %lo(sun4v_err_itlb_vaddr)]
206 sethi %hi(sun4v_err_itlb_ctx), %g1
207 ldxa [%g0] ASI_SCRATCHPAD, %g6
208 ldx [%g6 + HV_FAULT_I_CTX_OFFSET], %o1
209 stx %o1, [%g1 + %lo(sun4v_err_itlb_ctx)]
210 sethi %hi(sun4v_err_itlb_pte), %g1
211 stx %g3, [%g1 + %lo(sun4v_err_itlb_pte)]
212 sethi %hi(sun4v_err_itlb_error), %g1
213 stx %o0, [%g1 + %lo(sun4v_err_itlb_error)]
218 1: or %g7, %lo(1f), %g7
220 call sun4v_itlb_error_report
221 add %sp, PTREGS_OFF, %o0
228 ble,pt %icc, sun4v_bad_ra
229 or %g0, FAULT_CODE_BAD_RA | FAULT_CODE_DTLB, %g1
231 sethi %hi(sun4v_err_dtlb_vaddr), %g1
232 stx %g4, [%g1 + %lo(sun4v_err_dtlb_vaddr)]
233 sethi %hi(sun4v_err_dtlb_ctx), %g1
234 ldxa [%g0] ASI_SCRATCHPAD, %g6
235 ldx [%g6 + HV_FAULT_D_CTX_OFFSET], %o1
236 stx %o1, [%g1 + %lo(sun4v_err_dtlb_ctx)]
237 sethi %hi(sun4v_err_dtlb_pte), %g1
238 stx %g3, [%g1 + %lo(sun4v_err_dtlb_pte)]
239 sethi %hi(sun4v_err_dtlb_error), %g1
240 stx %o0, [%g1 + %lo(sun4v_err_dtlb_error)]
245 1: or %g7, %lo(1f), %g7
247 call sun4v_dtlb_error_report
248 add %sp, PTREGS_OFF, %o0
254 ba,pt %xcc, sparc64_realfault_common
259 /* Instruction Access Exception, tl0. */
261 ldxa [%g0] ASI_SCRATCHPAD, %g2
262 ldx [%g2 + HV_FAULT_I_TYPE_OFFSET], %g3
263 ldx [%g2 + HV_FAULT_I_ADDR_OFFSET], %g4
264 ldx [%g2 + HV_FAULT_I_CTX_OFFSET], %g5
271 call sun4v_insn_access_exception
272 add %sp, PTREGS_OFF, %o0
275 /* Instruction Access Exception, tl1. */
277 ldxa [%g0] ASI_SCRATCHPAD, %g2
278 ldx [%g2 + HV_FAULT_I_TYPE_OFFSET], %g3
279 ldx [%g2 + HV_FAULT_I_ADDR_OFFSET], %g4
280 ldx [%g2 + HV_FAULT_I_CTX_OFFSET], %g5
287 call sun4v_insn_access_exception_tl1
288 add %sp, PTREGS_OFF, %o0
291 /* Data Access Exception, tl0. */
293 ldxa [%g0] ASI_SCRATCHPAD, %g2
294 ldx [%g2 + HV_FAULT_D_TYPE_OFFSET], %g3
295 ldx [%g2 + HV_FAULT_D_ADDR_OFFSET], %g4
296 ldx [%g2 + HV_FAULT_D_CTX_OFFSET], %g5
303 call sun4v_data_access_exception
304 add %sp, PTREGS_OFF, %o0
307 /* Data Access Exception, tl1. */
309 ldxa [%g0] ASI_SCRATCHPAD, %g2
310 ldx [%g2 + HV_FAULT_D_TYPE_OFFSET], %g3
311 ldx [%g2 + HV_FAULT_D_ADDR_OFFSET], %g4
312 ldx [%g2 + HV_FAULT_D_CTX_OFFSET], %g5
319 call sun4v_data_access_exception_tl1
320 add %sp, PTREGS_OFF, %o0
323 /* Memory Address Unaligned. */
332 ldxa [%g0] ASI_SCRATCHPAD, %g2
333 ldx [%g2 + HV_FAULT_D_ADDR_OFFSET], %g5
334 mov HV_FAULT_TYPE_UNALIGNED, %g3
335 ldx [%g2 + HV_FAULT_D_CTX_OFFSET], %g4
338 ba,pt %xcc, winfix_mna
342 1: ldxa [%g0] ASI_SCRATCHPAD, %g2
343 mov HV_FAULT_TYPE_UNALIGNED, %g3
344 ldx [%g2 + HV_FAULT_D_ADDR_OFFSET], %g4
345 ldx [%g2 + HV_FAULT_D_CTX_OFFSET], %g5
354 add %sp, PTREGS_OFF, %o0
358 /* Privileged Action. */
363 add %sp, PTREGS_OFF, %o0
366 /* Unaligned ldd float, tl0. */
368 ldxa [%g0] ASI_SCRATCHPAD, %g2
369 ldx [%g2 + HV_FAULT_D_TYPE_OFFSET], %g3
370 ldx [%g2 + HV_FAULT_D_ADDR_OFFSET], %g4
371 ldx [%g2 + HV_FAULT_D_CTX_OFFSET], %g5
379 add %sp, PTREGS_OFF, %o0
382 /* Unaligned std float, tl0. */
384 ldxa [%g0] ASI_SCRATCHPAD, %g2
385 ldx [%g2 + HV_FAULT_D_TYPE_OFFSET], %g3
386 ldx [%g2 + HV_FAULT_D_ADDR_OFFSET], %g4
387 ldx [%g2 + HV_FAULT_D_CTX_OFFSET], %g5
395 add %sp, PTREGS_OFF, %o0
398 #define BRANCH_ALWAYS 0x10680000
399 #define NOP 0x01000000
400 #define SUN4V_DO_PATCH(OLD, NEW) \
401 sethi %hi(NEW), %g1; \
402 or %g1, %lo(NEW), %g1; \
403 sethi %hi(OLD), %g2; \
404 or %g2, %lo(OLD), %g2; \
406 sethi %hi(BRANCH_ALWAYS), %g3; \
408 srl %g1, 11 + 2, %g1; \
409 or %g3, %lo(BRANCH_ALWAYS), %g3; \
412 sethi %hi(NOP), %g3; \
413 or %g3, %lo(NOP), %g3; \
414 stw %g3, [%g2 + 0x4]; \
417 .globl sun4v_patch_tlb_handlers
418 .type sun4v_patch_tlb_handlers,#function
419 sun4v_patch_tlb_handlers:
420 SUN4V_DO_PATCH(tl0_iamiss, sun4v_itlb_miss)
421 SUN4V_DO_PATCH(tl1_iamiss, sun4v_itlb_miss)
422 SUN4V_DO_PATCH(tl0_damiss, sun4v_dtlb_miss)
423 SUN4V_DO_PATCH(tl1_damiss, sun4v_dtlb_miss)
424 SUN4V_DO_PATCH(tl0_daprot, sun4v_dtlb_prot)
425 SUN4V_DO_PATCH(tl1_daprot, sun4v_dtlb_prot)
426 SUN4V_DO_PATCH(tl0_iax, sun4v_iacc)
427 SUN4V_DO_PATCH(tl1_iax, sun4v_iacc_tl1)
428 SUN4V_DO_PATCH(tl0_dax, sun4v_dacc)
429 SUN4V_DO_PATCH(tl1_dax, sun4v_dacc_tl1)
430 SUN4V_DO_PATCH(tl0_mna, sun4v_mna)
431 SUN4V_DO_PATCH(tl1_mna, sun4v_mna)
432 SUN4V_DO_PATCH(tl0_lddfmna, sun4v_lddfmna)
433 SUN4V_DO_PATCH(tl0_stdfmna, sun4v_stdfmna)
434 SUN4V_DO_PATCH(tl0_privact, sun4v_privact)
437 .size sun4v_patch_tlb_handlers,.-sun4v_patch_tlb_handlers