1 /* $Id: ultra.S,v 1.72 2002/02/09 19:49:31 davem Exp $
2 * ultra.S: Don't expand these all over the place...
4 * Copyright (C) 1997, 2000 David S. Miller (davem@redhat.com)
8 #include <asm/pgtable.h>
10 #include <asm/spitfire.h>
11 #include <asm/mmu_context.h>
15 #include <asm/thread_info.h>
16 #include <asm/cacheflush.h>
17 #include <asm/hypervisor.h>
19 /* Basically, most of the Spitfire vs. Cheetah madness
20 * has to do with the fact that Cheetah does not support
21 * IMMU flushes out of the secondary context. Someone needs
22 * to throw a south lake birthday party for the folks
23 * in Microelectronics who refused to fix this shit.
26 /* This file is meant to be read efficiently by the CPU, not humans.
27 * Staraj sie tego nikomu nie pierdolnac...
32 __flush_tlb_mm: /* 18 insns */
33 /* %o0=(ctx & TAG_CONTEXT_BITS), %o1=SECONDARY_CONTEXT */
34 ldxa [%o1] ASI_DMMU, %g2
36 bne,pn %icc, __spitfire_flush_tlb_mm_slow
38 stxa %g0, [%g3] ASI_DMMU_DEMAP
39 stxa %g0, [%g3] ASI_IMMU_DEMAP
40 sethi %hi(KERNBASE), %g3
55 .globl __flush_tlb_pending
56 __flush_tlb_pending: /* 26 insns */
57 /* %o0 = context, %o1 = nr, %o2 = vaddrs[] */
60 andn %g7, PSTATE_IE, %g2
62 mov SECONDARY_CONTEXT, %o4
63 ldxa [%o4] ASI_DMMU, %g2
64 stxa %o0, [%o4] ASI_DMMU
65 1: sub %o1, (1 << 3), %o1
71 stxa %g0, [%o3] ASI_IMMU_DEMAP
72 2: stxa %g0, [%o3] ASI_DMMU_DEMAP
76 stxa %g2, [%o4] ASI_DMMU
77 sethi %hi(KERNBASE), %o4
80 wrpr %g7, 0x0, %pstate
87 .globl __flush_tlb_kernel_range
88 __flush_tlb_kernel_range: /* 16 insns */
89 /* %o0=start, %o1=end */
92 sethi %hi(PAGE_SIZE), %o4
95 or %o0, 0x20, %o0 ! Nucleus
96 1: stxa %g0, [%o0 + %o3] ASI_DMMU_DEMAP
97 stxa %g0, [%o0 + %o3] ASI_IMMU_DEMAP
101 2: sethi %hi(KERNBASE), %o3
107 __spitfire_flush_tlb_mm_slow:
109 wrpr %g1, PSTATE_IE, %pstate
110 stxa %o0, [%o1] ASI_DMMU
111 stxa %g0, [%g3] ASI_DMMU_DEMAP
112 stxa %g0, [%g3] ASI_IMMU_DEMAP
114 stxa %g2, [%o1] ASI_DMMU
115 sethi %hi(KERNBASE), %o1
121 * The following code flushes one page_size worth.
123 .section .kprobes.text, "ax"
125 .globl __flush_icache_page
126 __flush_icache_page: /* %o0 = phys_page */
128 srlx %o0, PAGE_SHIFT, %o0
129 sethi %uhi(PAGE_OFFSET), %g1
130 sllx %o0, PAGE_SHIFT, %o0
131 sethi %hi(PAGE_SIZE), %g2
134 1: subcc %g2, 32, %g2
140 #ifdef DCACHE_ALIASING_POSSIBLE
142 #if (PAGE_SHIFT != 13)
143 #error only page shift of 13 is supported by dcache flush
146 #define DTAG_MASK 0x3
148 /* This routine is Spitfire specific so the hardcoded
149 * D-cache size and line-size are OK.
152 .globl __flush_dcache_page
153 __flush_dcache_page: /* %o0=kaddr, %o1=flush_icache */
154 sethi %uhi(PAGE_OFFSET), %g1
156 sub %o0, %g1, %o0 ! physical address
157 srlx %o0, 11, %o0 ! make D-cache TAG
158 sethi %hi(1 << 14), %o2 ! D-cache size
159 sub %o2, (1 << 5), %o2 ! D-cache line size
160 1: ldxa [%o2] ASI_DCACHE_TAG, %o3 ! load D-cache TAG
161 andcc %o3, DTAG_MASK, %g0 ! Valid?
162 be,pn %xcc, 2f ! Nope, branch
163 andn %o3, DTAG_MASK, %o3 ! Clear valid bits
164 cmp %o3, %o0 ! TAG match?
165 bne,pt %xcc, 2f ! Nope, branch
167 stxa %g0, [%o2] ASI_DCACHE_TAG ! Invalidate TAG
170 sub %o2, (1 << 5), %o2 ! D-cache line size
172 /* The I-cache does not snoop local stores so we
173 * better flush that too when necessary.
175 brnz,pt %o1, __flush_icache_page
180 #endif /* DCACHE_ALIASING_POSSIBLE */
184 /* Cheetah specific versions, patched at boot time. */
185 __cheetah_flush_tlb_mm: /* 19 insns */
187 andn %g7, PSTATE_IE, %g2
188 wrpr %g2, 0x0, %pstate
190 mov PRIMARY_CONTEXT, %o2
192 ldxa [%o2] ASI_DMMU, %g2
193 srlx %g2, CTX_PGSZ1_NUC_SHIFT, %o1
194 sllx %o1, CTX_PGSZ1_NUC_SHIFT, %o1
195 or %o0, %o1, %o0 /* Preserve nucleus page size fields */
196 stxa %o0, [%o2] ASI_DMMU
197 stxa %g0, [%g3] ASI_DMMU_DEMAP
198 stxa %g0, [%g3] ASI_IMMU_DEMAP
199 stxa %g2, [%o2] ASI_DMMU
200 sethi %hi(KERNBASE), %o2
204 wrpr %g7, 0x0, %pstate
206 __cheetah_flush_tlb_pending: /* 27 insns */
207 /* %o0 = context, %o1 = nr, %o2 = vaddrs[] */
210 andn %g7, PSTATE_IE, %g2
211 wrpr %g2, 0x0, %pstate
213 mov PRIMARY_CONTEXT, %o4
214 ldxa [%o4] ASI_DMMU, %g2
215 srlx %g2, CTX_PGSZ1_NUC_SHIFT, %o3
216 sllx %o3, CTX_PGSZ1_NUC_SHIFT, %o3
217 or %o0, %o3, %o0 /* Preserve nucleus page size fields */
218 stxa %o0, [%o4] ASI_DMMU
219 1: sub %o1, (1 << 3), %o1
224 stxa %g0, [%o3] ASI_IMMU_DEMAP
225 2: stxa %g0, [%o3] ASI_DMMU_DEMAP
229 stxa %g2, [%o4] ASI_DMMU
230 sethi %hi(KERNBASE), %o4
234 wrpr %g7, 0x0, %pstate
236 #ifdef DCACHE_ALIASING_POSSIBLE
237 __cheetah_flush_dcache_page: /* 11 insns */
238 sethi %uhi(PAGE_OFFSET), %g1
241 sethi %hi(PAGE_SIZE), %o4
242 1: subcc %o4, (1 << 5), %o4
243 stxa %g0, [%o0 + %o4] ASI_DCACHE_INVALIDATE
247 retl /* I-cache flush never needed on Cheetah, see callers. */
249 #endif /* DCACHE_ALIASING_POSSIBLE */
251 /* Hypervisor specific versions, patched at boot time. */
252 __hypervisor_tlb_tl0_error:
255 call hypervisor_tlbop_error
260 __hypervisor_flush_tlb_mm: /* 10 insns */
261 mov %o0, %o2 /* ARG2: mmu context */
262 mov 0, %o0 /* ARG0: CPU lists unimplemented */
263 mov 0, %o1 /* ARG1: CPU lists unimplemented */
264 mov HV_MMU_ALL, %o3 /* ARG3: flags */
265 mov HV_FAST_MMU_DEMAP_CTX, %o5
267 brnz,pn %o0, __hypervisor_tlb_tl0_error
268 mov HV_FAST_MMU_DEMAP_CTX, %o1
272 __hypervisor_flush_tlb_pending: /* 16 insns */
273 /* %o0 = context, %o1 = nr, %o2 = vaddrs[] */
277 1: sub %g1, (1 << 3), %g1
278 ldx [%g2 + %g1], %o0 /* ARG0: vaddr + IMMU-bit */
279 mov %g3, %o1 /* ARG1: mmu context */
280 mov HV_MMU_ALL, %o2 /* ARG2: flags */
281 srlx %o0, PAGE_SHIFT, %o0
282 sllx %o0, PAGE_SHIFT, %o0
283 ta HV_MMU_UNMAP_ADDR_TRAP
284 brnz,pn %o0, __hypervisor_tlb_tl0_error
285 mov HV_MMU_UNMAP_ADDR_TRAP, %o1
291 __hypervisor_flush_tlb_kernel_range: /* 16 insns */
292 /* %o0=start, %o1=end */
295 sethi %hi(PAGE_SIZE), %g3
299 1: add %g1, %g2, %o0 /* ARG0: virtual address */
300 mov 0, %o1 /* ARG1: mmu context */
301 mov HV_MMU_ALL, %o2 /* ARG2: flags */
302 ta HV_MMU_UNMAP_ADDR_TRAP
303 brnz,pn %o0, __hypervisor_tlb_tl0_error
304 mov HV_MMU_UNMAP_ADDR_TRAP, %o1
310 #ifdef DCACHE_ALIASING_POSSIBLE
311 /* XXX Niagara and friends have an 8K cache, so no aliasing is
312 * XXX possible, but nothing explicit in the Hypervisor API
313 * XXX guarantees this.
315 __hypervisor_flush_dcache_page: /* 2 insns */
331 .globl cheetah_patch_cachetlbops
332 cheetah_patch_cachetlbops:
335 sethi %hi(__flush_tlb_mm), %o0
336 or %o0, %lo(__flush_tlb_mm), %o0
337 sethi %hi(__cheetah_flush_tlb_mm), %o1
338 or %o1, %lo(__cheetah_flush_tlb_mm), %o1
342 sethi %hi(__flush_tlb_pending), %o0
343 or %o0, %lo(__flush_tlb_pending), %o0
344 sethi %hi(__cheetah_flush_tlb_pending), %o1
345 or %o1, %lo(__cheetah_flush_tlb_pending), %o1
349 #ifdef DCACHE_ALIASING_POSSIBLE
350 sethi %hi(__flush_dcache_page), %o0
351 or %o0, %lo(__flush_dcache_page), %o0
352 sethi %hi(__cheetah_flush_dcache_page), %o1
353 or %o1, %lo(__cheetah_flush_dcache_page), %o1
356 #endif /* DCACHE_ALIASING_POSSIBLE */
362 /* These are all called by the slaves of a cross call, at
363 * trap level 1, with interrupts fully disabled.
366 * %g5 mm->context (all tlb flushes)
367 * %g1 address arg 1 (tlb page and range flushes)
368 * %g7 address arg 2 (tlb range flush only)
376 .globl xcall_flush_tlb_mm
377 xcall_flush_tlb_mm: /* 21 insns */
378 mov PRIMARY_CONTEXT, %g2
379 ldxa [%g2] ASI_DMMU, %g3
380 srlx %g3, CTX_PGSZ1_NUC_SHIFT, %g4
381 sllx %g4, CTX_PGSZ1_NUC_SHIFT, %g4
382 or %g5, %g4, %g5 /* Preserve nucleus page size fields */
383 stxa %g5, [%g2] ASI_DMMU
385 stxa %g0, [%g4] ASI_DMMU_DEMAP
386 stxa %g0, [%g4] ASI_IMMU_DEMAP
387 stxa %g3, [%g2] ASI_DMMU
400 .globl xcall_flush_tlb_pending
401 xcall_flush_tlb_pending: /* 21 insns */
402 /* %g5=context, %g1=nr, %g7=vaddrs[] */
404 mov PRIMARY_CONTEXT, %g4
405 ldxa [%g4] ASI_DMMU, %g2
406 srlx %g2, CTX_PGSZ1_NUC_SHIFT, %g4
407 sllx %g4, CTX_PGSZ1_NUC_SHIFT, %g4
409 mov PRIMARY_CONTEXT, %g4
410 stxa %g5, [%g4] ASI_DMMU
411 1: sub %g1, (1 << 3), %g1
417 stxa %g0, [%g5] ASI_IMMU_DEMAP
418 2: stxa %g0, [%g5] ASI_DMMU_DEMAP
422 stxa %g2, [%g4] ASI_DMMU
426 .globl xcall_flush_tlb_kernel_range
427 xcall_flush_tlb_kernel_range: /* 25 insns */
428 sethi %hi(PAGE_SIZE - 1), %g2
429 or %g2, %lo(PAGE_SIZE - 1), %g2
435 or %g1, 0x20, %g1 ! Nucleus
436 1: stxa %g0, [%g1 + %g3] ASI_DMMU_DEMAP
437 stxa %g0, [%g1 + %g3] ASI_IMMU_DEMAP
454 /* This runs in a very controlled environment, so we do
455 * not need to worry about BH races etc.
457 .globl xcall_sync_tick
460 661: rdpr %pstate, %g2
461 wrpr %g2, PSTATE_IG | PSTATE_AG, %pstate
462 .section .sun4v_2insn_patch, "ax"
472 109: or %g7, %lo(109b), %g7
473 #ifdef CONFIG_TRACE_IRQFLAGS
474 call trace_hardirqs_off
477 call smp_synchronize_tick_client
480 ldx [%sp + PTREGS_OFF + PT_V9_TSTATE], %l1
482 /* NOTE: This is SPECIAL!! We do etrap/rtrap however
483 * we choose to deal with the "BH's run with
484 * %pil==15" problem (described in asm/pil.h)
485 * by just invoking rtrap directly past where
486 * BH's are checked for.
488 * We do it like this because we do not want %pil==15
489 * lockups to prevent regs being reported.
491 .globl xcall_report_regs
494 661: rdpr %pstate, %g2
495 wrpr %g2, PSTATE_IG | PSTATE_AG, %pstate
496 .section .sun4v_2insn_patch, "ax"
506 109: or %g7, %lo(109b), %g7
507 #ifdef CONFIG_TRACE_IRQFLAGS
508 call trace_hardirqs_off
512 add %sp, PTREGS_OFF, %o0
513 /* Has to be a non-v9 branch due to the large distance. */
515 ldx [%sp + PTREGS_OFF + PT_V9_TSTATE], %l1
517 #ifdef DCACHE_ALIASING_POSSIBLE
519 .globl xcall_flush_dcache_page_cheetah
520 xcall_flush_dcache_page_cheetah: /* %g1 == physical page address */
521 sethi %hi(PAGE_SIZE), %g3
522 1: subcc %g3, (1 << 5), %g3
523 stxa %g0, [%g1 + %g3] ASI_DCACHE_INVALIDATE
529 #endif /* DCACHE_ALIASING_POSSIBLE */
531 .globl xcall_flush_dcache_page_spitfire
532 xcall_flush_dcache_page_spitfire: /* %g1 == physical page address
533 %g7 == kernel page virtual address
534 %g5 == (page->mapping != NULL) */
535 #ifdef DCACHE_ALIASING_POSSIBLE
536 srlx %g1, (13 - 2), %g1 ! Form tag comparitor
537 sethi %hi(L1DCACHE_SIZE), %g3 ! D$ size == 16K
538 sub %g3, (1 << 5), %g3 ! D$ linesize == 32
539 1: ldxa [%g3] ASI_DCACHE_TAG, %g2
547 stxa %g0, [%g3] ASI_DCACHE_TAG
551 sub %g3, (1 << 5), %g3
554 #endif /* DCACHE_ALIASING_POSSIBLE */
555 sethi %hi(PAGE_SIZE), %g3
558 subcc %g3, (1 << 5), %g3
560 add %g7, (1 << 5), %g7
569 __hypervisor_tlb_xcall_error:
575 call hypervisor_tlbop_error_xcall
579 .globl __hypervisor_xcall_flush_tlb_mm
580 __hypervisor_xcall_flush_tlb_mm: /* 21 insns */
581 /* %g5=ctx, g1,g2,g3,g4,g7=scratch, %g6=unusable */
587 clr %o0 /* ARG0: CPU lists unimplemented */
588 clr %o1 /* ARG1: CPU lists unimplemented */
589 mov %g5, %o2 /* ARG2: mmu context */
590 mov HV_MMU_ALL, %o3 /* ARG3: flags */
591 mov HV_FAST_MMU_DEMAP_CTX, %o5
593 mov HV_FAST_MMU_DEMAP_CTX, %g6
594 brnz,pn %o0, __hypervisor_tlb_xcall_error
604 .globl __hypervisor_xcall_flush_tlb_pending
605 __hypervisor_xcall_flush_tlb_pending: /* 21 insns */
606 /* %g5=ctx, %g1=nr, %g7=vaddrs[], %g2,%g3,%g4,g6=scratch */
611 1: sub %g1, (1 << 3), %g1
612 ldx [%g7 + %g1], %o0 /* ARG0: virtual address */
613 mov %g5, %o1 /* ARG1: mmu context */
614 mov HV_MMU_ALL, %o2 /* ARG2: flags */
615 srlx %o0, PAGE_SHIFT, %o0
616 sllx %o0, PAGE_SHIFT, %o0
617 ta HV_MMU_UNMAP_ADDR_TRAP
618 mov HV_MMU_UNMAP_ADDR_TRAP, %g6
619 brnz,a,pn %o0, __hypervisor_tlb_xcall_error
629 .globl __hypervisor_xcall_flush_tlb_kernel_range
630 __hypervisor_xcall_flush_tlb_kernel_range: /* 25 insns */
631 /* %g1=start, %g7=end, g2,g3,g4,g5,g6=scratch */
632 sethi %hi(PAGE_SIZE - 1), %g2
633 or %g2, %lo(PAGE_SIZE - 1), %g2
642 1: add %g1, %g3, %o0 /* ARG0: virtual address */
643 mov 0, %o1 /* ARG1: mmu context */
644 mov HV_MMU_ALL, %o2 /* ARG2: flags */
645 ta HV_MMU_UNMAP_ADDR_TRAP
646 mov HV_MMU_UNMAP_ADDR_TRAP, %g6
647 brnz,pn %o0, __hypervisor_tlb_xcall_error
649 sethi %hi(PAGE_SIZE), %o2
658 /* These just get rescheduled to PIL vectors. */
659 .globl xcall_call_function
661 wr %g0, (1 << PIL_SMP_CALL_FUNC), %set_softint
664 .globl xcall_receive_signal
665 xcall_receive_signal:
666 wr %g0, (1 << PIL_SMP_RECEIVE_SIGNAL), %set_softint
671 wr %g0, (1 << PIL_SMP_CAPTURE), %set_softint
674 .globl xcall_new_mmu_context_version
675 xcall_new_mmu_context_version:
676 wr %g0, (1 << PIL_SMP_CTX_NEW_VERSION), %set_softint
679 #endif /* CONFIG_SMP */
682 .globl hypervisor_patch_cachetlbops
683 hypervisor_patch_cachetlbops:
686 sethi %hi(__flush_tlb_mm), %o0
687 or %o0, %lo(__flush_tlb_mm), %o0
688 sethi %hi(__hypervisor_flush_tlb_mm), %o1
689 or %o1, %lo(__hypervisor_flush_tlb_mm), %o1
693 sethi %hi(__flush_tlb_pending), %o0
694 or %o0, %lo(__flush_tlb_pending), %o0
695 sethi %hi(__hypervisor_flush_tlb_pending), %o1
696 or %o1, %lo(__hypervisor_flush_tlb_pending), %o1
700 sethi %hi(__flush_tlb_kernel_range), %o0
701 or %o0, %lo(__flush_tlb_kernel_range), %o0
702 sethi %hi(__hypervisor_flush_tlb_kernel_range), %o1
703 or %o1, %lo(__hypervisor_flush_tlb_kernel_range), %o1
707 #ifdef DCACHE_ALIASING_POSSIBLE
708 sethi %hi(__flush_dcache_page), %o0
709 or %o0, %lo(__flush_dcache_page), %o0
710 sethi %hi(__hypervisor_flush_dcache_page), %o1
711 or %o1, %lo(__hypervisor_flush_dcache_page), %o1
714 #endif /* DCACHE_ALIASING_POSSIBLE */
717 sethi %hi(xcall_flush_tlb_mm), %o0
718 or %o0, %lo(xcall_flush_tlb_mm), %o0
719 sethi %hi(__hypervisor_xcall_flush_tlb_mm), %o1
720 or %o1, %lo(__hypervisor_xcall_flush_tlb_mm), %o1
724 sethi %hi(xcall_flush_tlb_pending), %o0
725 or %o0, %lo(xcall_flush_tlb_pending), %o0
726 sethi %hi(__hypervisor_xcall_flush_tlb_pending), %o1
727 or %o1, %lo(__hypervisor_xcall_flush_tlb_pending), %o1
731 sethi %hi(xcall_flush_tlb_kernel_range), %o0
732 or %o0, %lo(xcall_flush_tlb_kernel_range), %o0
733 sethi %hi(__hypervisor_xcall_flush_tlb_kernel_range), %o1
734 or %o1, %lo(__hypervisor_xcall_flush_tlb_kernel_range), %o1
737 #endif /* CONFIG_SMP */