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)
7 #include <linux/config.h>
9 #include <asm/pgtable.h>
11 #include <asm/spitfire.h>
12 #include <asm/mmu_context.h>
16 #include <asm/thread_info.h>
17 #include <asm/cacheflush.h>
18 #include <asm/hypervisor.h>
20 /* Basically, most of the Spitfire vs. Cheetah madness
21 * has to do with the fact that Cheetah does not support
22 * IMMU flushes out of the secondary context. Someone needs
23 * to throw a south lake birthday party for the folks
24 * in Microelectronics who refused to fix this shit.
27 /* This file is meant to be read efficiently by the CPU, not humans.
28 * Staraj sie tego nikomu nie pierdolnac...
33 __flush_tlb_mm: /* 18 insns */
34 /* %o0=(ctx & TAG_CONTEXT_BITS), %o1=SECONDARY_CONTEXT */
35 ldxa [%o1] ASI_DMMU, %g2
37 bne,pn %icc, __spitfire_flush_tlb_mm_slow
39 stxa %g0, [%g3] ASI_DMMU_DEMAP
40 stxa %g0, [%g3] ASI_IMMU_DEMAP
41 sethi %hi(KERNBASE), %g3
56 .globl __flush_tlb_pending
57 __flush_tlb_pending: /* 26 insns */
58 /* %o0 = context, %o1 = nr, %o2 = vaddrs[] */
61 andn %g7, PSTATE_IE, %g2
63 mov SECONDARY_CONTEXT, %o4
64 ldxa [%o4] ASI_DMMU, %g2
65 stxa %o0, [%o4] ASI_DMMU
66 1: sub %o1, (1 << 3), %o1
72 stxa %g0, [%o3] ASI_IMMU_DEMAP
73 2: stxa %g0, [%o3] ASI_DMMU_DEMAP
77 stxa %g2, [%o4] ASI_DMMU
78 sethi %hi(KERNBASE), %o4
81 wrpr %g7, 0x0, %pstate
88 .globl __flush_tlb_kernel_range
89 __flush_tlb_kernel_range: /* 16 insns */
90 /* %o0=start, %o1=end */
93 sethi %hi(PAGE_SIZE), %o4
96 or %o0, 0x20, %o0 ! Nucleus
97 1: stxa %g0, [%o0 + %o3] ASI_DMMU_DEMAP
98 stxa %g0, [%o0 + %o3] ASI_IMMU_DEMAP
102 2: sethi %hi(KERNBASE), %o3
108 __spitfire_flush_tlb_mm_slow:
110 wrpr %g1, PSTATE_IE, %pstate
111 stxa %o0, [%o1] ASI_DMMU
112 stxa %g0, [%g3] ASI_DMMU_DEMAP
113 stxa %g0, [%g3] ASI_IMMU_DEMAP
115 stxa %g2, [%o1] ASI_DMMU
116 sethi %hi(KERNBASE), %o1
122 * The following code flushes one page_size worth.
124 #if (PAGE_SHIFT == 13)
125 #define ITAG_MASK 0xfe
126 #elif (PAGE_SHIFT == 16)
127 #define ITAG_MASK 0x7fe
129 #error unsupported PAGE_SIZE
131 .section .kprobes.text, "ax"
133 .globl __flush_icache_page
134 __flush_icache_page: /* %o0 = phys_page */
136 srlx %o0, PAGE_SHIFT, %o0
137 sethi %uhi(PAGE_OFFSET), %g1
138 sllx %o0, PAGE_SHIFT, %o0
139 sethi %hi(PAGE_SIZE), %g2
142 1: subcc %g2, 32, %g2
148 #ifdef DCACHE_ALIASING_POSSIBLE
150 #if (PAGE_SHIFT != 13)
151 #error only page shift of 13 is supported by dcache flush
154 #define DTAG_MASK 0x3
156 /* This routine is Spitfire specific so the hardcoded
157 * D-cache size and line-size are OK.
160 .globl __flush_dcache_page
161 __flush_dcache_page: /* %o0=kaddr, %o1=flush_icache */
162 sethi %uhi(PAGE_OFFSET), %g1
164 sub %o0, %g1, %o0 ! physical address
165 srlx %o0, 11, %o0 ! make D-cache TAG
166 sethi %hi(1 << 14), %o2 ! D-cache size
167 sub %o2, (1 << 5), %o2 ! D-cache line size
168 1: ldxa [%o2] ASI_DCACHE_TAG, %o3 ! load D-cache TAG
169 andcc %o3, DTAG_MASK, %g0 ! Valid?
170 be,pn %xcc, 2f ! Nope, branch
171 andn %o3, DTAG_MASK, %o3 ! Clear valid bits
172 cmp %o3, %o0 ! TAG match?
173 bne,pt %xcc, 2f ! Nope, branch
175 stxa %g0, [%o2] ASI_DCACHE_TAG ! Invalidate TAG
178 sub %o2, (1 << 5), %o2 ! D-cache line size
180 /* The I-cache does not snoop local stores so we
181 * better flush that too when necessary.
183 brnz,pt %o1, __flush_icache_page
188 #endif /* DCACHE_ALIASING_POSSIBLE */
192 /* Cheetah specific versions, patched at boot time. */
193 __cheetah_flush_tlb_mm: /* 19 insns */
195 andn %g7, PSTATE_IE, %g2
196 wrpr %g2, 0x0, %pstate
198 mov PRIMARY_CONTEXT, %o2
200 ldxa [%o2] ASI_DMMU, %g2
201 srlx %g2, CTX_PGSZ1_NUC_SHIFT, %o1
202 sllx %o1, CTX_PGSZ1_NUC_SHIFT, %o1
203 or %o0, %o1, %o0 /* Preserve nucleus page size fields */
204 stxa %o0, [%o2] ASI_DMMU
205 stxa %g0, [%g3] ASI_DMMU_DEMAP
206 stxa %g0, [%g3] ASI_IMMU_DEMAP
207 stxa %g2, [%o2] ASI_DMMU
208 sethi %hi(KERNBASE), %o2
212 wrpr %g7, 0x0, %pstate
214 __cheetah_flush_tlb_pending: /* 27 insns */
215 /* %o0 = context, %o1 = nr, %o2 = vaddrs[] */
218 andn %g7, PSTATE_IE, %g2
219 wrpr %g2, 0x0, %pstate
221 mov PRIMARY_CONTEXT, %o4
222 ldxa [%o4] ASI_DMMU, %g2
223 srlx %g2, CTX_PGSZ1_NUC_SHIFT, %o3
224 sllx %o3, CTX_PGSZ1_NUC_SHIFT, %o3
225 or %o0, %o3, %o0 /* Preserve nucleus page size fields */
226 stxa %o0, [%o4] ASI_DMMU
227 1: sub %o1, (1 << 3), %o1
232 stxa %g0, [%o3] ASI_IMMU_DEMAP
233 2: stxa %g0, [%o3] ASI_DMMU_DEMAP
237 stxa %g2, [%o4] ASI_DMMU
238 sethi %hi(KERNBASE), %o4
242 wrpr %g7, 0x0, %pstate
244 #ifdef DCACHE_ALIASING_POSSIBLE
245 __cheetah_flush_dcache_page: /* 11 insns */
246 sethi %uhi(PAGE_OFFSET), %g1
249 sethi %hi(PAGE_SIZE), %o4
250 1: subcc %o4, (1 << 5), %o4
251 stxa %g0, [%o0 + %o4] ASI_DCACHE_INVALIDATE
255 retl /* I-cache flush never needed on Cheetah, see callers. */
257 #endif /* DCACHE_ALIASING_POSSIBLE */
259 /* Hypervisor specific versions, patched at boot time. */
260 __hypervisor_tlb_tl0_error:
263 call hypervisor_tlbop_error
268 __hypervisor_flush_tlb_mm: /* 10 insns */
269 mov %o0, %o2 /* ARG2: mmu context */
270 mov 0, %o0 /* ARG0: CPU lists unimplemented */
271 mov 0, %o1 /* ARG1: CPU lists unimplemented */
272 mov HV_MMU_ALL, %o3 /* ARG3: flags */
273 mov HV_FAST_MMU_DEMAP_CTX, %o5
275 brnz,pn %o0, __hypervisor_tlb_tl0_error
276 mov HV_FAST_MMU_DEMAP_CTX, %o1
280 __hypervisor_flush_tlb_pending: /* 16 insns */
281 /* %o0 = context, %o1 = nr, %o2 = vaddrs[] */
285 1: sub %g1, (1 << 3), %g1
286 ldx [%g2 + %g1], %o0 /* ARG0: vaddr + IMMU-bit */
287 mov %g3, %o1 /* ARG1: mmu context */
288 mov HV_MMU_ALL, %o2 /* ARG2: flags */
289 srlx %o0, PAGE_SHIFT, %o0
290 sllx %o0, PAGE_SHIFT, %o0
291 ta HV_MMU_UNMAP_ADDR_TRAP
292 brnz,pn %o0, __hypervisor_tlb_tl0_error
293 mov HV_MMU_UNMAP_ADDR_TRAP, %o1
299 __hypervisor_flush_tlb_kernel_range: /* 16 insns */
300 /* %o0=start, %o1=end */
303 sethi %hi(PAGE_SIZE), %g3
307 1: add %g1, %g2, %o0 /* ARG0: virtual address */
308 mov 0, %o1 /* ARG1: mmu context */
309 mov HV_MMU_ALL, %o2 /* ARG2: flags */
310 ta HV_MMU_UNMAP_ADDR_TRAP
311 brnz,pn %o0, __hypervisor_tlb_tl0_error
312 mov HV_MMU_UNMAP_ADDR_TRAP, %o1
318 #ifdef DCACHE_ALIASING_POSSIBLE
319 /* XXX Niagara and friends have an 8K cache, so no aliasing is
320 * XXX possible, but nothing explicit in the Hypervisor API
321 * XXX guarantees this.
323 __hypervisor_flush_dcache_page: /* 2 insns */
339 .globl cheetah_patch_cachetlbops
340 cheetah_patch_cachetlbops:
343 sethi %hi(__flush_tlb_mm), %o0
344 or %o0, %lo(__flush_tlb_mm), %o0
345 sethi %hi(__cheetah_flush_tlb_mm), %o1
346 or %o1, %lo(__cheetah_flush_tlb_mm), %o1
350 sethi %hi(__flush_tlb_pending), %o0
351 or %o0, %lo(__flush_tlb_pending), %o0
352 sethi %hi(__cheetah_flush_tlb_pending), %o1
353 or %o1, %lo(__cheetah_flush_tlb_pending), %o1
357 #ifdef DCACHE_ALIASING_POSSIBLE
358 sethi %hi(__flush_dcache_page), %o0
359 or %o0, %lo(__flush_dcache_page), %o0
360 sethi %hi(__cheetah_flush_dcache_page), %o1
361 or %o1, %lo(__cheetah_flush_dcache_page), %o1
364 #endif /* DCACHE_ALIASING_POSSIBLE */
370 /* These are all called by the slaves of a cross call, at
371 * trap level 1, with interrupts fully disabled.
374 * %g5 mm->context (all tlb flushes)
375 * %g1 address arg 1 (tlb page and range flushes)
376 * %g7 address arg 2 (tlb range flush only)
384 .globl xcall_flush_tlb_mm
385 xcall_flush_tlb_mm: /* 21 insns */
386 mov PRIMARY_CONTEXT, %g2
387 ldxa [%g2] ASI_DMMU, %g3
388 srlx %g3, CTX_PGSZ1_NUC_SHIFT, %g4
389 sllx %g4, CTX_PGSZ1_NUC_SHIFT, %g4
390 or %g5, %g4, %g5 /* Preserve nucleus page size fields */
391 stxa %g5, [%g2] ASI_DMMU
393 stxa %g0, [%g4] ASI_DMMU_DEMAP
394 stxa %g0, [%g4] ASI_IMMU_DEMAP
395 stxa %g3, [%g2] ASI_DMMU
408 .globl xcall_flush_tlb_pending
409 xcall_flush_tlb_pending: /* 21 insns */
410 /* %g5=context, %g1=nr, %g7=vaddrs[] */
412 mov PRIMARY_CONTEXT, %g4
413 ldxa [%g4] ASI_DMMU, %g2
414 srlx %g2, CTX_PGSZ1_NUC_SHIFT, %g4
415 sllx %g4, CTX_PGSZ1_NUC_SHIFT, %g4
417 mov PRIMARY_CONTEXT, %g4
418 stxa %g5, [%g4] ASI_DMMU
419 1: sub %g1, (1 << 3), %g1
425 stxa %g0, [%g5] ASI_IMMU_DEMAP
426 2: stxa %g0, [%g5] ASI_DMMU_DEMAP
430 stxa %g2, [%g4] ASI_DMMU
434 .globl xcall_flush_tlb_kernel_range
435 xcall_flush_tlb_kernel_range: /* 25 insns */
436 sethi %hi(PAGE_SIZE - 1), %g2
437 or %g2, %lo(PAGE_SIZE - 1), %g2
443 or %g1, 0x20, %g1 ! Nucleus
444 1: stxa %g0, [%g1 + %g3] ASI_DMMU_DEMAP
445 stxa %g0, [%g1 + %g3] ASI_IMMU_DEMAP
462 /* This runs in a very controlled environment, so we do
463 * not need to worry about BH races etc.
465 .globl xcall_sync_tick
468 661: rdpr %pstate, %g2
469 wrpr %g2, PSTATE_IG | PSTATE_AG, %pstate
470 .section .sun4v_2insn_patch, "ax"
480 109: or %g7, %lo(109b), %g7
481 call smp_synchronize_tick_client
485 ldx [%sp + PTREGS_OFF + PT_V9_TSTATE], %l1
487 /* NOTE: This is SPECIAL!! We do etrap/rtrap however
488 * we choose to deal with the "BH's run with
489 * %pil==15" problem (described in asm/pil.h)
490 * by just invoking rtrap directly past where
491 * BH's are checked for.
493 * We do it like this because we do not want %pil==15
494 * lockups to prevent regs being reported.
496 .globl xcall_report_regs
499 661: rdpr %pstate, %g2
500 wrpr %g2, PSTATE_IG | PSTATE_AG, %pstate
501 .section .sun4v_2insn_patch, "ax"
511 109: or %g7, %lo(109b), %g7
513 add %sp, PTREGS_OFF, %o0
515 /* Has to be a non-v9 branch due to the large distance. */
517 ldx [%sp + PTREGS_OFF + PT_V9_TSTATE], %l1
519 #ifdef DCACHE_ALIASING_POSSIBLE
521 .globl xcall_flush_dcache_page_cheetah
522 xcall_flush_dcache_page_cheetah: /* %g1 == physical page address */
523 sethi %hi(PAGE_SIZE), %g3
524 1: subcc %g3, (1 << 5), %g3
525 stxa %g0, [%g1 + %g3] ASI_DCACHE_INVALIDATE
531 #endif /* DCACHE_ALIASING_POSSIBLE */
533 .globl xcall_flush_dcache_page_spitfire
534 xcall_flush_dcache_page_spitfire: /* %g1 == physical page address
535 %g7 == kernel page virtual address
536 %g5 == (page->mapping != NULL) */
537 #ifdef DCACHE_ALIASING_POSSIBLE
538 srlx %g1, (13 - 2), %g1 ! Form tag comparitor
539 sethi %hi(L1DCACHE_SIZE), %g3 ! D$ size == 16K
540 sub %g3, (1 << 5), %g3 ! D$ linesize == 32
541 1: ldxa [%g3] ASI_DCACHE_TAG, %g2
549 stxa %g0, [%g3] ASI_DCACHE_TAG
553 sub %g3, (1 << 5), %g3
556 #endif /* DCACHE_ALIASING_POSSIBLE */
557 sethi %hi(PAGE_SIZE), %g3
560 subcc %g3, (1 << 5), %g3
562 add %g7, (1 << 5), %g7
571 __hypervisor_tlb_xcall_error:
577 call hypervisor_tlbop_error_xcall
579 ba,a,pt %xcc, rtrap_clr_l6
581 .globl __hypervisor_xcall_flush_tlb_mm
582 __hypervisor_xcall_flush_tlb_mm: /* 21 insns */
583 /* %g5=ctx, g1,g2,g3,g4,g7=scratch, %g6=unusable */
589 clr %o0 /* ARG0: CPU lists unimplemented */
590 clr %o1 /* ARG1: CPU lists unimplemented */
591 mov %g5, %o2 /* ARG2: mmu context */
592 mov HV_MMU_ALL, %o3 /* ARG3: flags */
593 mov HV_FAST_MMU_DEMAP_CTX, %o5
595 mov HV_FAST_MMU_DEMAP_CTX, %g6
596 brnz,pn %o0, __hypervisor_tlb_xcall_error
606 .globl __hypervisor_xcall_flush_tlb_pending
607 __hypervisor_xcall_flush_tlb_pending: /* 21 insns */
608 /* %g5=ctx, %g1=nr, %g7=vaddrs[], %g2,%g3,%g4,g6=scratch */
613 1: sub %g1, (1 << 3), %g1
614 ldx [%g7 + %g1], %o0 /* ARG0: virtual address */
615 mov %g5, %o1 /* ARG1: mmu context */
616 mov HV_MMU_ALL, %o2 /* ARG2: flags */
617 srlx %o0, PAGE_SHIFT, %o0
618 sllx %o0, PAGE_SHIFT, %o0
619 ta HV_MMU_UNMAP_ADDR_TRAP
620 mov HV_MMU_UNMAP_ADDR_TRAP, %g6
621 brnz,a,pn %o0, __hypervisor_tlb_xcall_error
631 .globl __hypervisor_xcall_flush_tlb_kernel_range
632 __hypervisor_xcall_flush_tlb_kernel_range: /* 25 insns */
633 /* %g1=start, %g7=end, g2,g3,g4,g5,g6=scratch */
634 sethi %hi(PAGE_SIZE - 1), %g2
635 or %g2, %lo(PAGE_SIZE - 1), %g2
644 1: add %g1, %g3, %o0 /* ARG0: virtual address */
645 mov 0, %o1 /* ARG1: mmu context */
646 mov HV_MMU_ALL, %o2 /* ARG2: flags */
647 ta HV_MMU_UNMAP_ADDR_TRAP
648 mov HV_MMU_UNMAP_ADDR_TRAP, %g6
649 brnz,pn %o0, __hypervisor_tlb_xcall_error
651 sethi %hi(PAGE_SIZE), %o2
660 /* These just get rescheduled to PIL vectors. */
661 .globl xcall_call_function
663 wr %g0, (1 << PIL_SMP_CALL_FUNC), %set_softint
666 .globl xcall_receive_signal
667 xcall_receive_signal:
668 wr %g0, (1 << PIL_SMP_RECEIVE_SIGNAL), %set_softint
673 wr %g0, (1 << PIL_SMP_CAPTURE), %set_softint
676 .globl xcall_new_mmu_context_version
677 xcall_new_mmu_context_version:
678 wr %g0, (1 << PIL_SMP_CTX_NEW_VERSION), %set_softint
681 #endif /* CONFIG_SMP */
684 .globl hypervisor_patch_cachetlbops
685 hypervisor_patch_cachetlbops:
688 sethi %hi(__flush_tlb_mm), %o0
689 or %o0, %lo(__flush_tlb_mm), %o0
690 sethi %hi(__hypervisor_flush_tlb_mm), %o1
691 or %o1, %lo(__hypervisor_flush_tlb_mm), %o1
695 sethi %hi(__flush_tlb_pending), %o0
696 or %o0, %lo(__flush_tlb_pending), %o0
697 sethi %hi(__hypervisor_flush_tlb_pending), %o1
698 or %o1, %lo(__hypervisor_flush_tlb_pending), %o1
702 sethi %hi(__flush_tlb_kernel_range), %o0
703 or %o0, %lo(__flush_tlb_kernel_range), %o0
704 sethi %hi(__hypervisor_flush_tlb_kernel_range), %o1
705 or %o1, %lo(__hypervisor_flush_tlb_kernel_range), %o1
709 #ifdef DCACHE_ALIASING_POSSIBLE
710 sethi %hi(__flush_dcache_page), %o0
711 or %o0, %lo(__flush_dcache_page), %o0
712 sethi %hi(__hypervisor_flush_dcache_page), %o1
713 or %o1, %lo(__hypervisor_flush_dcache_page), %o1
716 #endif /* DCACHE_ALIASING_POSSIBLE */
719 sethi %hi(xcall_flush_tlb_mm), %o0
720 or %o0, %lo(xcall_flush_tlb_mm), %o0
721 sethi %hi(__hypervisor_xcall_flush_tlb_mm), %o1
722 or %o1, %lo(__hypervisor_xcall_flush_tlb_mm), %o1
726 sethi %hi(xcall_flush_tlb_pending), %o0
727 or %o0, %lo(xcall_flush_tlb_pending), %o0
728 sethi %hi(__hypervisor_xcall_flush_tlb_pending), %o1
729 or %o1, %lo(__hypervisor_xcall_flush_tlb_pending), %o1
733 sethi %hi(xcall_flush_tlb_kernel_range), %o0
734 or %o0, %lo(xcall_flush_tlb_kernel_range), %o0
735 sethi %hi(__hypervisor_xcall_flush_tlb_kernel_range), %o1
736 or %o1, %lo(__hypervisor_xcall_flush_tlb_kernel_range), %o1
739 #endif /* CONFIG_SMP */