1 /* sun4v_tlb_miss.S: Sun4v TLB miss handlers.
3 * Copyright (C) 2006 <davem@davemloft.net>
9 /* Load ITLB fault information into VADDR and CTX, using BASE. */
10 #define LOAD_ITLB_INFO(BASE, VADDR, CTX) \
11 ldx [BASE + HV_FAULT_I_ADDR_OFFSET], VADDR; \
12 ldx [BASE + HV_FAULT_I_CTX_OFFSET], CTX;
14 /* Load DTLB fault information into VADDR and CTX, using BASE. */
15 #define LOAD_DTLB_INFO(BASE, VADDR, CTX) \
16 ldx [BASE + HV_FAULT_D_ADDR_OFFSET], VADDR; \
17 ldx [BASE + HV_FAULT_D_CTX_OFFSET], CTX;
19 /* DEST = (VADDR >> 22)
21 * Branch to ZERO_CTX_LABEL is context is zero.
23 #define COMPUTE_TAG_TARGET(DEST, VADDR, CTX, ZERO_CTX_LABEL) \
24 srlx VADDR, 22, DEST; \
25 brz,pn CTX, ZERO_CTX_LABEL; \
28 /* Create TSB pointer. This is something like:
30 * index_mask = (512 << (tsb_reg & 0x7UL)) - 1UL;
31 * tsb_base = tsb_reg & ~0x7UL;
32 * tsb_index = ((vaddr >> PAGE_SHIFT) & tsb_mask);
33 * tsb_ptr = tsb_base + (tsb_index * 16);
35 #define COMPUTE_TSB_PTR(TSB_PTR, VADDR, TMP1, TMP2) \
36 and TSB_PTR, 0x7, TMP1; \
38 andn TSB_PTR, 0x7, TSB_PTR; \
39 sllx TMP2, TMP1, TMP2; \
40 srlx VADDR, PAGE_SHIFT, TMP1; \
42 and TMP1, TMP2, TMP1; \
44 add TSB_PTR, TMP1, TSB_PTR;
47 /* Load MMU Miss base into %g2. */
48 ldxa [%g0] ASI_SCRATCHPAD, %g2
50 /* Load UTSB reg into %g1. */
51 mov SCRATCHPAD_UTSBREG1, %g1
52 ldxa [%g1] ASI_SCRATCHPAD, %g1
54 LOAD_ITLB_INFO(%g2, %g4, %g5)
55 COMPUTE_TAG_TARGET(%g6, %g4, %g5, kvmap_itlb_4v)
56 COMPUTE_TSB_PTR(%g1, %g4, %g3, %g7)
58 /* Load TSB tag/pte into %g2/%g3 and compare the tag. */
59 ldda [%g1] ASI_QUAD_LDD_PHYS_4V, %g2
61 sethi %hi(PAGE_EXEC), %g7
62 ldx [%g7 + %lo(PAGE_EXEC)], %g7
63 bne,a,pn %xcc, tsb_miss_page_table_walk
64 mov FAULT_CODE_ITLB, %g3
66 be,a,pn %xcc, tsb_do_fault
67 mov FAULT_CODE_ITLB, %g3
69 /* We have a valid entry, make hypervisor call to load
70 * I-TLB and return from trap.
76 ldxa [%g0] ASI_SCRATCHPAD, %g6
77 mov %o0, %g1 ! save %o0
78 mov %o1, %g2 ! save %o1
79 mov %o2, %g5 ! save %o2
80 mov %o3, %g7 ! save %o3
82 ldx [%g6 + HV_FAULT_I_CTX_OFFSET], %o1 ! ctx
84 mov HV_MMU_IMMU, %o3 ! flags
85 ta HV_MMU_MAP_ADDR_TRAP
86 brnz,pn %o0, sun4v_itlb_error
87 mov %g2, %o1 ! restore %o1
88 mov %g1, %o0 ! restore %o0
89 mov %g5, %o2 ! restore %o2
90 mov %g7, %o3 ! restore %o3
95 /* Load MMU Miss base into %g2. */
96 ldxa [%g0] ASI_SCRATCHPAD, %g2
98 /* Load UTSB reg into %g1. */
99 mov SCRATCHPAD_UTSBREG1, %g1
100 ldxa [%g1] ASI_SCRATCHPAD, %g1
102 LOAD_DTLB_INFO(%g2, %g4, %g5)
103 COMPUTE_TAG_TARGET(%g6, %g4, %g5, kvmap_dtlb_4v)
104 COMPUTE_TSB_PTR(%g1, %g4, %g3, %g7)
106 /* Load TSB tag/pte into %g2/%g3 and compare the tag. */
107 ldda [%g1] ASI_QUAD_LDD_PHYS_4V, %g2
109 bne,a,pn %xcc, tsb_miss_page_table_walk
110 mov FAULT_CODE_ITLB, %g3
112 /* We have a valid entry, make hypervisor call to load
113 * D-TLB and return from trap.
119 ldxa [%g0] ASI_SCRATCHPAD, %g6
120 mov %o0, %g1 ! save %o0
121 mov %o1, %g2 ! save %o1
122 mov %o2, %g5 ! save %o2
123 mov %o3, %g7 ! save %o3
125 ldx [%g6 + HV_FAULT_D_CTX_OFFSET], %o1 ! ctx
127 mov HV_MMU_DMMU, %o3 ! flags
128 ta HV_MMU_MAP_ADDR_TRAP
129 brnz,pn %o0, sun4v_dtlb_error
130 mov %g2, %o1 ! restore %o1
131 mov %g1, %o0 ! restore %o0
132 mov %g5, %o2 ! restore %o2
133 mov %g7, %o3 ! restore %o3
140 /* Load MMU Miss base into %g5. */
141 ldxa [%g0] ASI_SCRATCHPAD, %g5
143 ldx [%g5 + HV_FAULT_D_ADDR_OFFSET], %g5
146 bgu,pn %xcc, winfix_trampoline
148 ba,pt %xcc, sparc64_realfault_common
149 mov FAULT_CODE_DTLB | FAULT_CODE_WRITE, %g4
151 /* Called from trap table:
157 mov SCRATCHPAD_UTSBREG1, %g1
158 ldxa [%g1] ASI_SCRATCHPAD, %g1
159 brz,pn %g5, kvmap_itlb_4v
160 mov FAULT_CODE_ITLB, %g3
161 ba,a,pt %xcc, sun4v_tsb_miss_common
163 /* Called from trap table:
169 mov SCRATCHPAD_UTSBREG1, %g1
170 ldxa [%g1] ASI_SCRATCHPAD, %g1
171 brz,pn %g5, kvmap_dtlb_4v
172 mov FAULT_CODE_DTLB, %g3
176 /* Create TSB pointer into %g1. This is something like:
178 * index_mask = (512 << (tsb_reg & 0x7UL)) - 1UL;
179 * tsb_base = tsb_reg & ~0x7UL;
180 * tsb_index = ((vaddr >> PAGE_SHIFT) & tsb_mask);
181 * tsb_ptr = tsb_base + (tsb_index * 16);
183 sun4v_tsb_miss_common:
184 COMPUTE_TSB_PTR(%g1, %g4, %g5, %g7)
186 /* Branch directly to page table lookup. We have SCRATCHPAD_MMU_MISS
187 * still in %g2, so it's quite trivial to get at the PGD PHYS value
188 * so we can preload it into %g7.
190 sub %g2, TRAP_PER_CPU_FAULT_INFO, %g2
191 ba,pt %xcc, tsb_miss_page_table_walk_sun4v_fastpath
192 ldx [%g2 + TRAP_PER_CPU_PGD_PADDR], %g7
195 sethi %hi(sun4v_err_itlb_vaddr), %g1
196 stx %g4, [%g1 + %lo(sun4v_err_itlb_vaddr)]
197 sethi %hi(sun4v_err_itlb_ctx), %g1
198 ldxa [%g0] ASI_SCRATCHPAD, %g6
199 ldx [%g6 + HV_FAULT_I_CTX_OFFSET], %o1
200 stx %o1, [%g1 + %lo(sun4v_err_itlb_ctx)]
201 sethi %hi(sun4v_err_itlb_pte), %g1
202 stx %g3, [%g1 + %lo(sun4v_err_itlb_pte)]
203 sethi %hi(sun4v_err_itlb_error), %g1
204 stx %o0, [%g1 + %lo(sun4v_err_itlb_error)]
214 2: or %g7, %lo(2b), %g7
215 call sun4v_itlb_error_report
216 add %sp, PTREGS_OFF, %o0
221 sethi %hi(sun4v_err_dtlb_vaddr), %g1
222 stx %g4, [%g1 + %lo(sun4v_err_dtlb_vaddr)]
223 sethi %hi(sun4v_err_dtlb_ctx), %g1
224 ldxa [%g0] ASI_SCRATCHPAD, %g6
225 ldx [%g6 + HV_FAULT_D_CTX_OFFSET], %o1
226 stx %o1, [%g1 + %lo(sun4v_err_dtlb_ctx)]
227 sethi %hi(sun4v_err_dtlb_pte), %g1
228 stx %g3, [%g1 + %lo(sun4v_err_dtlb_pte)]
229 sethi %hi(sun4v_err_dtlb_error), %g1
230 stx %o0, [%g1 + %lo(sun4v_err_dtlb_error)]
240 2: or %g7, %lo(2b), %g7
241 call sun4v_dtlb_error_report
242 add %sp, PTREGS_OFF, %o0
246 /* Instruction Access Exception, tl0. */
248 ldxa [%g0] ASI_SCRATCHPAD, %g2
249 ldx [%g2 + HV_FAULT_I_TYPE_OFFSET], %g3
250 ldx [%g2 + HV_FAULT_I_ADDR_OFFSET], %g4
251 ldx [%g2 + HV_FAULT_I_CTX_OFFSET], %g5
258 call sun4v_insn_access_exception
259 add %sp, PTREGS_OFF, %o0
260 ba,a,pt %xcc, rtrap_clr_l6
262 /* Instruction Access Exception, tl1. */
264 ldxa [%g0] ASI_SCRATCHPAD, %g2
265 ldx [%g2 + HV_FAULT_I_TYPE_OFFSET], %g3
266 ldx [%g2 + HV_FAULT_I_ADDR_OFFSET], %g4
267 ldx [%g2 + HV_FAULT_I_CTX_OFFSET], %g5
274 call sun4v_insn_access_exception_tl1
275 add %sp, PTREGS_OFF, %o0
276 ba,a,pt %xcc, rtrap_clr_l6
278 /* Data Access Exception, tl0. */
280 ldxa [%g0] ASI_SCRATCHPAD, %g2
281 ldx [%g2 + HV_FAULT_D_TYPE_OFFSET], %g3
282 ldx [%g2 + HV_FAULT_D_ADDR_OFFSET], %g4
283 ldx [%g2 + HV_FAULT_D_CTX_OFFSET], %g5
290 call sun4v_data_access_exception
291 add %sp, PTREGS_OFF, %o0
292 ba,a,pt %xcc, rtrap_clr_l6
294 /* Data Access Exception, tl1. */
296 ldxa [%g0] ASI_SCRATCHPAD, %g2
297 ldx [%g2 + HV_FAULT_D_TYPE_OFFSET], %g3
298 ldx [%g2 + HV_FAULT_D_ADDR_OFFSET], %g4
299 ldx [%g2 + HV_FAULT_D_CTX_OFFSET], %g5
306 call sun4v_data_access_exception_tl1
307 add %sp, PTREGS_OFF, %o0
308 ba,a,pt %xcc, rtrap_clr_l6
310 /* Memory Address Unaligned. */
319 ldxa [%g0] ASI_SCRATCHPAD, %g5
320 ldx [%g5 + HV_FAULT_D_ADDR_OFFSET], %g5
321 mov HV_FAULT_TYPE_UNALIGNED, %g3
322 ldx [%g5 + HV_FAULT_D_CTX_OFFSET], %g4
325 ba,pt %xcc, winfix_mna
329 1: ldxa [%g0] ASI_SCRATCHPAD, %g2
330 mov HV_FAULT_TYPE_UNALIGNED, %g3
331 ldx [%g2 + HV_FAULT_D_ADDR_OFFSET], %g4
332 ldx [%g2 + HV_FAULT_D_CTX_OFFSET], %g5
341 add %sp, PTREGS_OFF, %o0
342 ba,a,pt %xcc, rtrap_clr_l6
344 /* Privileged Action. */
349 add %sp, PTREGS_OFF, %o0
350 ba,a,pt %xcc, rtrap_clr_l6
352 /* Unaligned ldd float, tl0. */
354 ldxa [%g0] ASI_SCRATCHPAD, %g2
355 ldx [%g2 + HV_FAULT_D_TYPE_OFFSET], %g3
356 ldx [%g2 + HV_FAULT_D_ADDR_OFFSET], %g4
357 ldx [%g2 + HV_FAULT_D_CTX_OFFSET], %g5
365 add %sp, PTREGS_OFF, %o0
366 ba,a,pt %xcc, rtrap_clr_l6
368 /* Unaligned std float, tl0. */
370 ldxa [%g0] ASI_SCRATCHPAD, %g2
371 ldx [%g2 + HV_FAULT_D_TYPE_OFFSET], %g3
372 ldx [%g2 + HV_FAULT_D_ADDR_OFFSET], %g4
373 ldx [%g2 + HV_FAULT_D_CTX_OFFSET], %g5
381 add %sp, PTREGS_OFF, %o0
382 ba,a,pt %xcc, rtrap_clr_l6
384 #define BRANCH_ALWAYS 0x10680000
385 #define NOP 0x01000000
386 #define SUN4V_DO_PATCH(OLD, NEW) \
387 sethi %hi(NEW), %g1; \
388 or %g1, %lo(NEW), %g1; \
389 sethi %hi(OLD), %g2; \
390 or %g2, %lo(OLD), %g2; \
392 sethi %hi(BRANCH_ALWAYS), %g3; \
394 srl %g1, 11 + 2, %g1; \
395 or %g3, %lo(BRANCH_ALWAYS), %g3; \
398 sethi %hi(NOP), %g3; \
399 or %g3, %lo(NOP), %g3; \
400 stw %g3, [%g2 + 0x4]; \
403 .globl sun4v_patch_tlb_handlers
404 .type sun4v_patch_tlb_handlers,#function
405 sun4v_patch_tlb_handlers:
406 SUN4V_DO_PATCH(tl0_iamiss, sun4v_itlb_miss)
407 SUN4V_DO_PATCH(tl1_iamiss, sun4v_itlb_miss)
408 SUN4V_DO_PATCH(tl0_damiss, sun4v_dtlb_miss)
409 SUN4V_DO_PATCH(tl1_damiss, sun4v_dtlb_miss)
410 SUN4V_DO_PATCH(tl0_daprot, sun4v_dtlb_prot)
411 SUN4V_DO_PATCH(tl1_daprot, sun4v_dtlb_prot)
412 SUN4V_DO_PATCH(tl0_iax, sun4v_iacc)
413 SUN4V_DO_PATCH(tl1_iax, sun4v_iacc_tl1)
414 SUN4V_DO_PATCH(tl0_dax, sun4v_dacc)
415 SUN4V_DO_PATCH(tl1_dax, sun4v_dacc_tl1)
416 SUN4V_DO_PATCH(tl0_mna, sun4v_mna)
417 SUN4V_DO_PATCH(tl1_mna, sun4v_mna)
418 SUN4V_DO_PATCH(tl0_lddfmna, sun4v_lddfmna)
419 SUN4V_DO_PATCH(tl0_stdfmna, sun4v_stdfmna)
420 SUN4V_DO_PATCH(tl0_privact, sun4v_privact)
423 .size sun4v_patch_tlb_handlers,.-sun4v_patch_tlb_handlers