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>
15 #include <asm/thread_info.h>
16 #include <asm/cacheflush.h>
18 /* Basically, most of the Spitfire vs. Cheetah madness
19 * has to do with the fact that Cheetah does not support
20 * IMMU flushes out of the secondary context. Someone needs
21 * to throw a south lake birthday party for the folks
22 * in Microelectronics who refused to fix this shit.
25 /* This file is meant to be read efficiently by the CPU, not humans.
26 * Staraj sie tego nikomu nie pierdolnac...
31 __flush_tlb_mm: /* %o0=(ctx & TAG_CONTEXT_BITS), %o1=SECONDARY_CONTEXT */
32 ldxa [%o1] ASI_DMMU, %g2
34 bne,pn %icc, __spitfire_flush_tlb_mm_slow
36 stxa %g0, [%g3] ASI_DMMU_DEMAP
37 stxa %g0, [%g3] ASI_IMMU_DEMAP
50 .globl __flush_tlb_pending
52 /* %o0 = context, %o1 = nr, %o2 = vaddrs[] */
55 andn %g7, PSTATE_IE, %g2
57 mov SECONDARY_CONTEXT, %o4
58 ldxa [%o4] ASI_DMMU, %g2
59 stxa %o0, [%o4] ASI_DMMU
60 1: sub %o1, (1 << 3), %o1
66 stxa %g0, [%o3] ASI_IMMU_DEMAP
67 2: stxa %g0, [%o3] ASI_DMMU_DEMAP
71 stxa %g2, [%o4] ASI_DMMU
74 wrpr %g7, 0x0, %pstate
78 .globl __flush_tlb_kernel_range
79 __flush_tlb_kernel_range: /* %o0=start, %o1=end */
82 sethi %hi(PAGE_SIZE), %o4
85 or %o0, 0x20, %o0 ! Nucleus
86 1: stxa %g0, [%o0 + %o3] ASI_DMMU_DEMAP
87 stxa %g0, [%o0 + %o3] ASI_IMMU_DEMAP
94 __spitfire_flush_tlb_mm_slow:
96 wrpr %g1, PSTATE_IE, %pstate
97 stxa %o0, [%o1] ASI_DMMU
98 stxa %g0, [%g3] ASI_DMMU_DEMAP
99 stxa %g0, [%g3] ASI_IMMU_DEMAP
101 stxa %g2, [%o1] ASI_DMMU
107 * The following code flushes one page_size worth.
109 #if (PAGE_SHIFT == 13)
110 #define ITAG_MASK 0xfe
111 #elif (PAGE_SHIFT == 16)
112 #define ITAG_MASK 0x7fe
114 #error unsupported PAGE_SIZE
117 .globl __flush_icache_page
118 __flush_icache_page: /* %o0 = phys_page */
120 srlx %o0, PAGE_SHIFT, %o0
121 sethi %uhi(PAGE_OFFSET), %g1
122 sllx %o0, PAGE_SHIFT, %o0
123 sethi %hi(PAGE_SIZE), %g2
126 1: subcc %g2, 32, %g2
132 #ifdef DCACHE_ALIASING_POSSIBLE
134 #if (PAGE_SHIFT != 13)
135 #error only page shift of 13 is supported by dcache flush
138 #define DTAG_MASK 0x3
141 .globl __flush_dcache_page
142 __flush_dcache_page: /* %o0=kaddr, %o1=flush_icache */
143 sethi %uhi(PAGE_OFFSET), %g1
148 sethi %hi(1 << 14), %o2
149 1: ldxa [%o4] ASI_DCACHE_TAG, %o3 ! LSU Group
150 add %o4, (1 << 5), %o4 ! IEU0
151 ldxa [%o4] ASI_DCACHE_TAG, %g1 ! LSU Group
152 add %o4, (1 << 5), %o4 ! IEU0
153 ldxa [%o4] ASI_DCACHE_TAG, %g2 ! LSU Group o3 available
154 add %o4, (1 << 5), %o4 ! IEU0
155 andn %o3, DTAG_MASK, %o3 ! IEU1
156 ldxa [%o4] ASI_DCACHE_TAG, %g3 ! LSU Group
157 add %o4, (1 << 5), %o4 ! IEU0
158 andn %g1, DTAG_MASK, %g1 ! IEU1
159 cmp %o0, %o3 ! IEU1 Group
160 be,a,pn %xcc, dflush1 ! CTI
161 sub %o4, (4 << 5), %o4 ! IEU0 (Group)
162 cmp %o0, %g1 ! IEU1 Group
163 andn %g2, DTAG_MASK, %g2 ! IEU0
164 be,a,pn %xcc, dflush2 ! CTI
165 sub %o4, (3 << 5), %o4 ! IEU0 (Group)
166 cmp %o0, %g2 ! IEU1 Group
167 andn %g3, DTAG_MASK, %g3 ! IEU0
168 be,a,pn %xcc, dflush3 ! CTI
169 sub %o4, (2 << 5), %o4 ! IEU0 (Group)
170 cmp %o0, %g3 ! IEU1 Group
171 be,a,pn %xcc, dflush4 ! CTI
172 sub %o4, (1 << 5), %o4 ! IEU0
173 2: cmp %o4, %o2 ! IEU1 Group
174 bne,pt %xcc, 1b ! CTI
177 /* The I-cache does not snoop local stores so we
178 * better flush that too when necessary.
180 brnz,pt %o1, __flush_icache_page
185 dflush1:stxa %g0, [%o4] ASI_DCACHE_TAG
186 add %o4, (1 << 5), %o4
187 dflush2:stxa %g0, [%o4] ASI_DCACHE_TAG
188 add %o4, (1 << 5), %o4
189 dflush3:stxa %g0, [%o4] ASI_DCACHE_TAG
190 add %o4, (1 << 5), %o4
191 dflush4:stxa %g0, [%o4] ASI_DCACHE_TAG
192 add %o4, (1 << 5), %o4
196 #endif /* DCACHE_ALIASING_POSSIBLE */
201 wrpr %g7, PSTATE_IE, %pstate
202 mov TLB_TAG_ACCESS, %g1
203 stxa %o5, [%g1] ASI_DMMU
204 stxa %o2, [%g0] ASI_DTLB_DATA_IN
210 wrpr %g7, PSTATE_IE, %pstate
211 mov TLB_TAG_ACCESS, %g1
212 stxa %o5, [%g1] ASI_IMMU
213 stxa %o2, [%g0] ASI_ITLB_DATA_IN
218 .globl __update_mmu_cache
219 __update_mmu_cache: /* %o0=hw_context, %o1=address, %o2=pte, %o3=fault_code */
220 srlx %o1, PAGE_SHIFT, %o1
221 andcc %o3, FAULT_CODE_DTLB, %g0
222 sllx %o1, PAGE_SHIFT, %o5
223 bne,pt %xcc, __prefill_dtlb
225 ba,a,pt %xcc, __prefill_itlb
227 /* Cheetah specific versions, patched at boot time.
229 * This writes of the PRIMARY_CONTEXT register in this file are
230 * safe even on Cheetah+ and later wrt. the page size fields.
231 * The nucleus page size fields do not matter because we make
232 * no data references, and these instructions execute out of a
233 * locked I-TLB entry sitting in the fully assosciative I-TLB.
234 * This sequence should also never trap.
236 __cheetah_flush_tlb_mm: /* 15 insns */
238 andn %g7, PSTATE_IE, %g2
239 wrpr %g2, 0x0, %pstate
241 mov PRIMARY_CONTEXT, %o2
243 ldxa [%o2] ASI_DMMU, %g2
244 stxa %o0, [%o2] ASI_DMMU
245 stxa %g0, [%g3] ASI_DMMU_DEMAP
246 stxa %g0, [%g3] ASI_IMMU_DEMAP
247 stxa %g2, [%o2] ASI_DMMU
251 wrpr %g7, 0x0, %pstate
253 __cheetah_flush_tlb_pending: /* 23 insns */
254 /* %o0 = context, %o1 = nr, %o2 = vaddrs[] */
257 andn %g7, PSTATE_IE, %g2
258 wrpr %g2, 0x0, %pstate
260 mov PRIMARY_CONTEXT, %o4
261 ldxa [%o4] ASI_DMMU, %g2
262 stxa %o0, [%o4] ASI_DMMU
263 1: sub %o1, (1 << 3), %o1
268 stxa %g0, [%o3] ASI_IMMU_DEMAP
269 2: stxa %g0, [%o3] ASI_DMMU_DEMAP
273 stxa %g2, [%o4] ASI_DMMU
277 wrpr %g7, 0x0, %pstate
279 #ifdef DCACHE_ALIASING_POSSIBLE
280 flush_dcpage_cheetah: /* 11 insns */
281 sethi %uhi(PAGE_OFFSET), %g1
284 sethi %hi(PAGE_SIZE), %o4
285 1: subcc %o4, (1 << 5), %o4
286 stxa %g0, [%o0 + %o4] ASI_DCACHE_INVALIDATE
290 retl /* I-cache flush never needed on Cheetah, see callers. */
292 #endif /* DCACHE_ALIASING_POSSIBLE */
305 .globl cheetah_patch_cachetlbops
306 cheetah_patch_cachetlbops:
309 sethi %hi(__flush_tlb_mm), %o0
310 or %o0, %lo(__flush_tlb_mm), %o0
311 sethi %hi(__cheetah_flush_tlb_mm), %o1
312 or %o1, %lo(__cheetah_flush_tlb_mm), %o1
313 call cheetah_patch_one
316 sethi %hi(__flush_tlb_pending), %o0
317 or %o0, %lo(__flush_tlb_pending), %o0
318 sethi %hi(__cheetah_flush_tlb_pending), %o1
319 or %o1, %lo(__cheetah_flush_tlb_pending), %o1
320 call cheetah_patch_one
323 #ifdef DCACHE_ALIASING_POSSIBLE
324 sethi %hi(__flush_dcache_page), %o0
325 or %o0, %lo(__flush_dcache_page), %o0
326 sethi %hi(flush_dcpage_cheetah), %o1
327 or %o1, %lo(flush_dcpage_cheetah), %o1
328 call cheetah_patch_one
330 #endif /* DCACHE_ALIASING_POSSIBLE */
336 /* These are all called by the slaves of a cross call, at
337 * trap level 1, with interrupts fully disabled.
340 * %g5 mm->context (all tlb flushes)
341 * %g1 address arg 1 (tlb page and range flushes)
342 * %g7 address arg 2 (tlb range flush only)
344 * %g6 ivector table, don't touch
349 * TODO: Make xcall TLB range flushes use the tricks above... -DaveM
352 .globl xcall_flush_tlb_mm
354 mov PRIMARY_CONTEXT, %g2
356 ldxa [%g2] ASI_DMMU, %g3
357 stxa %g5, [%g2] ASI_DMMU
358 stxa %g0, [%g4] ASI_DMMU_DEMAP
359 stxa %g0, [%g4] ASI_IMMU_DEMAP
360 stxa %g3, [%g2] ASI_DMMU
363 .globl xcall_flush_tlb_pending
364 xcall_flush_tlb_pending:
365 /* %g5=context, %g1=nr, %g7=vaddrs[] */
367 mov PRIMARY_CONTEXT, %g4
368 ldxa [%g4] ASI_DMMU, %g2
369 stxa %g5, [%g4] ASI_DMMU
370 1: sub %g1, (1 << 3), %g1
376 stxa %g0, [%g5] ASI_IMMU_DEMAP
377 2: stxa %g0, [%g5] ASI_DMMU_DEMAP
381 stxa %g2, [%g4] ASI_DMMU
384 .globl xcall_flush_tlb_kernel_range
385 xcall_flush_tlb_kernel_range:
386 sethi %hi(PAGE_SIZE - 1), %g2
387 or %g2, %lo(PAGE_SIZE - 1), %g2
393 or %g1, 0x20, %g1 ! Nucleus
394 1: stxa %g0, [%g1 + %g3] ASI_DMMU_DEMAP
395 stxa %g0, [%g1 + %g3] ASI_IMMU_DEMAP
403 /* This runs in a very controlled environment, so we do
404 * not need to worry about BH races etc.
406 .globl xcall_sync_tick
409 wrpr %g2, PSTATE_IG | PSTATE_AG, %pstate
414 109: or %g7, %lo(109b), %g7
415 call smp_synchronize_tick_client
419 ldx [%sp + PTREGS_OFF + PT_V9_TSTATE], %l1
421 /* NOTE: This is SPECIAL!! We do etrap/rtrap however
422 * we choose to deal with the "BH's run with
423 * %pil==15" problem (described in asm/pil.h)
424 * by just invoking rtrap directly past where
425 * BH's are checked for.
427 * We do it like this because we do not want %pil==15
428 * lockups to prevent regs being reported.
430 .globl xcall_report_regs
433 wrpr %g2, PSTATE_IG | PSTATE_AG, %pstate
438 109: or %g7, %lo(109b), %g7
440 add %sp, PTREGS_OFF, %o0
442 /* Has to be a non-v9 branch due to the large distance. */
444 ldx [%sp + PTREGS_OFF + PT_V9_TSTATE], %l1
446 #ifdef DCACHE_ALIASING_POSSIBLE
448 .globl xcall_flush_dcache_page_cheetah
449 xcall_flush_dcache_page_cheetah: /* %g1 == physical page address */
450 sethi %hi(PAGE_SIZE), %g3
451 1: subcc %g3, (1 << 5), %g3
452 stxa %g0, [%g1 + %g3] ASI_DCACHE_INVALIDATE
458 #endif /* DCACHE_ALIASING_POSSIBLE */
460 .globl xcall_flush_dcache_page_spitfire
461 xcall_flush_dcache_page_spitfire: /* %g1 == physical page address
462 %g7 == kernel page virtual address
463 %g5 == (page->mapping != NULL) */
464 #ifdef DCACHE_ALIASING_POSSIBLE
465 srlx %g1, (13 - 2), %g1 ! Form tag comparitor
466 sethi %hi(L1DCACHE_SIZE), %g3 ! D$ size == 16K
467 sub %g3, (1 << 5), %g3 ! D$ linesize == 32
468 1: ldxa [%g3] ASI_DCACHE_TAG, %g2
476 stxa %g0, [%g3] ASI_DCACHE_TAG
480 sub %g3, (1 << 5), %g3
483 #endif /* DCACHE_ALIASING_POSSIBLE */
484 sethi %hi(PAGE_SIZE), %g3
487 subcc %g3, (1 << 5), %g3
489 add %g7, (1 << 5), %g7
495 .globl xcall_promstop
498 wrpr %g2, PSTATE_IG | PSTATE_AG, %pstate
503 109: or %g7, %lo(109b), %g7
507 /* We should not return, just spin if we do... */
518 /* These two are not performance critical... */
519 .globl xcall_flush_tlb_all_spitfire
520 xcall_flush_tlb_all_spitfire:
521 /* Spitfire Errata #32 workaround. */
522 sethi %hi(errata32_hwbug), %g4
523 stx %g0, [%g4 + %lo(errata32_hwbug)]
527 1: ldxa [%g3] ASI_DTLB_DATA_ACCESS, %g4
528 and %g4, _PAGE_L, %g5
530 mov TLB_TAG_ACCESS, %g7
532 stxa %g0, [%g7] ASI_DMMU
534 stxa %g0, [%g3] ASI_DTLB_DATA_ACCESS
537 /* Spitfire Errata #32 workaround. */
538 sethi %hi(errata32_hwbug), %g4
539 stx %g0, [%g4 + %lo(errata32_hwbug)]
541 2: ldxa [%g3] ASI_ITLB_DATA_ACCESS, %g4
542 and %g4, _PAGE_L, %g5
544 mov TLB_TAG_ACCESS, %g7
546 stxa %g0, [%g7] ASI_IMMU
548 stxa %g0, [%g3] ASI_ITLB_DATA_ACCESS
551 /* Spitfire Errata #32 workaround. */
552 sethi %hi(errata32_hwbug), %g4
553 stx %g0, [%g4 + %lo(errata32_hwbug)]
556 cmp %g2, SPITFIRE_HIGHEST_LOCKED_TLBENT
562 .globl xcall_flush_tlb_all_cheetah
563 xcall_flush_tlb_all_cheetah:
565 stxa %g0, [%g2] ASI_DMMU_DEMAP
566 stxa %g0, [%g2] ASI_IMMU_DEMAP
569 /* These just get rescheduled to PIL vectors. */
570 .globl xcall_call_function
572 wr %g0, (1 << PIL_SMP_CALL_FUNC), %set_softint
575 .globl xcall_receive_signal
576 xcall_receive_signal:
577 wr %g0, (1 << PIL_SMP_RECEIVE_SIGNAL), %set_softint
582 wr %g0, (1 << PIL_SMP_CAPTURE), %set_softint
585 #endif /* CONFIG_SMP */