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>
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: /* %o0=(ctx & TAG_CONTEXT_BITS), %o1=SECONDARY_CONTEXT */
33 ldxa [%o1] ASI_DMMU, %g2
35 bne,pn %icc, __spitfire_flush_tlb_mm_slow
37 stxa %g0, [%g3] ASI_DMMU_DEMAP
38 stxa %g0, [%g3] ASI_IMMU_DEMAP
53 .globl __flush_tlb_pending
55 /* %o0 = context, %o1 = nr, %o2 = vaddrs[] */
58 andn %g7, PSTATE_IE, %g2
60 mov SECONDARY_CONTEXT, %o4
61 ldxa [%o4] ASI_DMMU, %g2
62 stxa %o0, [%o4] ASI_DMMU
63 1: sub %o1, (1 << 3), %o1
69 stxa %g0, [%o3] ASI_IMMU_DEMAP
70 2: stxa %g0, [%o3] ASI_DMMU_DEMAP
74 stxa %g2, [%o4] ASI_DMMU
77 wrpr %g7, 0x0, %pstate
84 .globl __flush_tlb_kernel_range
85 __flush_tlb_kernel_range: /* %o0=start, %o1=end */
88 sethi %hi(PAGE_SIZE), %o4
91 or %o0, 0x20, %o0 ! Nucleus
92 1: stxa %g0, [%o0 + %o3] ASI_DMMU_DEMAP
93 stxa %g0, [%o0 + %o3] ASI_IMMU_DEMAP
100 __spitfire_flush_tlb_mm_slow:
102 wrpr %g1, PSTATE_IE, %pstate
103 stxa %o0, [%o1] ASI_DMMU
104 stxa %g0, [%g3] ASI_DMMU_DEMAP
105 stxa %g0, [%g3] ASI_IMMU_DEMAP
107 stxa %g2, [%o1] ASI_DMMU
113 * The following code flushes one page_size worth.
115 #if (PAGE_SHIFT == 13)
116 #define ITAG_MASK 0xfe
117 #elif (PAGE_SHIFT == 16)
118 #define ITAG_MASK 0x7fe
120 #error unsupported PAGE_SIZE
123 .globl __flush_icache_page
124 __flush_icache_page: /* %o0 = phys_page */
126 srlx %o0, PAGE_SHIFT, %o0
127 sethi %uhi(PAGE_OFFSET), %g1
128 sllx %o0, PAGE_SHIFT, %o0
129 sethi %hi(PAGE_SIZE), %g2
132 1: subcc %g2, 32, %g2
138 #ifdef DCACHE_ALIASING_POSSIBLE
140 #if (PAGE_SHIFT != 13)
141 #error only page shift of 13 is supported by dcache flush
144 #define DTAG_MASK 0x3
147 .globl __flush_dcache_page
148 __flush_dcache_page: /* %o0=kaddr, %o1=flush_icache */
149 sethi %uhi(PAGE_OFFSET), %g1
154 sethi %hi(1 << 14), %o2
155 1: ldxa [%o4] ASI_DCACHE_TAG, %o3 ! LSU Group
156 add %o4, (1 << 5), %o4 ! IEU0
157 ldxa [%o4] ASI_DCACHE_TAG, %g1 ! LSU Group
158 add %o4, (1 << 5), %o4 ! IEU0
159 ldxa [%o4] ASI_DCACHE_TAG, %g2 ! LSU Group o3 available
160 add %o4, (1 << 5), %o4 ! IEU0
161 andn %o3, DTAG_MASK, %o3 ! IEU1
162 ldxa [%o4] ASI_DCACHE_TAG, %g3 ! LSU Group
163 add %o4, (1 << 5), %o4 ! IEU0
164 andn %g1, DTAG_MASK, %g1 ! IEU1
165 cmp %o0, %o3 ! IEU1 Group
166 be,a,pn %xcc, dflush1 ! CTI
167 sub %o4, (4 << 5), %o4 ! IEU0 (Group)
168 cmp %o0, %g1 ! IEU1 Group
169 andn %g2, DTAG_MASK, %g2 ! IEU0
170 be,a,pn %xcc, dflush2 ! CTI
171 sub %o4, (3 << 5), %o4 ! IEU0 (Group)
172 cmp %o0, %g2 ! IEU1 Group
173 andn %g3, DTAG_MASK, %g3 ! IEU0
174 be,a,pn %xcc, dflush3 ! CTI
175 sub %o4, (2 << 5), %o4 ! IEU0 (Group)
176 cmp %o0, %g3 ! IEU1 Group
177 be,a,pn %xcc, dflush4 ! CTI
178 sub %o4, (1 << 5), %o4 ! IEU0
179 2: cmp %o4, %o2 ! IEU1 Group
180 bne,pt %xcc, 1b ! CTI
183 /* The I-cache does not snoop local stores so we
184 * better flush that too when necessary.
186 brnz,pt %o1, __flush_icache_page
191 dflush1:stxa %g0, [%o4] ASI_DCACHE_TAG
192 add %o4, (1 << 5), %o4
193 dflush2:stxa %g0, [%o4] ASI_DCACHE_TAG
194 add %o4, (1 << 5), %o4
195 dflush3:stxa %g0, [%o4] ASI_DCACHE_TAG
196 add %o4, (1 << 5), %o4
197 dflush4:stxa %g0, [%o4] ASI_DCACHE_TAG
198 add %o4, (1 << 5), %o4
202 #endif /* DCACHE_ALIASING_POSSIBLE */
207 wrpr %g7, PSTATE_IE, %pstate
208 mov TLB_TAG_ACCESS, %g1
209 stxa %o5, [%g1] ASI_DMMU
210 stxa %o2, [%g0] ASI_DTLB_DATA_IN
216 wrpr %g7, PSTATE_IE, %pstate
217 mov TLB_TAG_ACCESS, %g1
218 stxa %o5, [%g1] ASI_IMMU
219 stxa %o2, [%g0] ASI_ITLB_DATA_IN
224 .globl __update_mmu_cache
225 __update_mmu_cache: /* %o0=hw_context, %o1=address, %o2=pte, %o3=fault_code */
226 srlx %o1, PAGE_SHIFT, %o1
227 andcc %o3, FAULT_CODE_DTLB, %g0
228 sllx %o1, PAGE_SHIFT, %o5
229 bne,pt %xcc, __prefill_dtlb
231 ba,a,pt %xcc, __prefill_itlb
233 /* Cheetah specific versions, patched at boot time. */
234 __cheetah_flush_tlb_mm: /* 18 insns */
236 andn %g7, PSTATE_IE, %g2
237 wrpr %g2, 0x0, %pstate
239 mov PRIMARY_CONTEXT, %o2
241 ldxa [%o2] ASI_DMMU, %g2
242 srlx %g2, CTX_PGSZ1_NUC_SHIFT, %o1
243 sllx %o1, CTX_PGSZ1_NUC_SHIFT, %o1
244 or %o0, %o1, %o0 /* Preserve nucleus page size fields */
245 stxa %o0, [%o2] ASI_DMMU
246 stxa %g0, [%g3] ASI_DMMU_DEMAP
247 stxa %g0, [%g3] ASI_IMMU_DEMAP
248 stxa %g2, [%o2] ASI_DMMU
252 wrpr %g7, 0x0, %pstate
254 __cheetah_flush_tlb_pending: /* 26 insns */
255 /* %o0 = context, %o1 = nr, %o2 = vaddrs[] */
258 andn %g7, PSTATE_IE, %g2
259 wrpr %g2, 0x0, %pstate
261 mov PRIMARY_CONTEXT, %o4
262 ldxa [%o4] ASI_DMMU, %g2
263 srlx %g2, CTX_PGSZ1_NUC_SHIFT, %o3
264 sllx %o3, CTX_PGSZ1_NUC_SHIFT, %o3
265 or %o0, %o3, %o0 /* Preserve nucleus page size fields */
266 stxa %o0, [%o4] ASI_DMMU
267 1: sub %o1, (1 << 3), %o1
272 stxa %g0, [%o3] ASI_IMMU_DEMAP
273 2: stxa %g0, [%o3] ASI_DMMU_DEMAP
277 stxa %g2, [%o4] ASI_DMMU
281 wrpr %g7, 0x0, %pstate
283 #ifdef DCACHE_ALIASING_POSSIBLE
284 flush_dcpage_cheetah: /* 11 insns */
285 sethi %uhi(PAGE_OFFSET), %g1
288 sethi %hi(PAGE_SIZE), %o4
289 1: subcc %o4, (1 << 5), %o4
290 stxa %g0, [%o0 + %o4] ASI_DCACHE_INVALIDATE
294 retl /* I-cache flush never needed on Cheetah, see callers. */
296 #endif /* DCACHE_ALIASING_POSSIBLE */
309 .globl cheetah_patch_cachetlbops
310 cheetah_patch_cachetlbops:
313 sethi %hi(__flush_tlb_mm), %o0
314 or %o0, %lo(__flush_tlb_mm), %o0
315 sethi %hi(__cheetah_flush_tlb_mm), %o1
316 or %o1, %lo(__cheetah_flush_tlb_mm), %o1
317 call cheetah_patch_one
320 sethi %hi(__flush_tlb_pending), %o0
321 or %o0, %lo(__flush_tlb_pending), %o0
322 sethi %hi(__cheetah_flush_tlb_pending), %o1
323 or %o1, %lo(__cheetah_flush_tlb_pending), %o1
324 call cheetah_patch_one
327 #ifdef DCACHE_ALIASING_POSSIBLE
328 sethi %hi(__flush_dcache_page), %o0
329 or %o0, %lo(__flush_dcache_page), %o0
330 sethi %hi(flush_dcpage_cheetah), %o1
331 or %o1, %lo(flush_dcpage_cheetah), %o1
332 call cheetah_patch_one
334 #endif /* DCACHE_ALIASING_POSSIBLE */
340 /* These are all called by the slaves of a cross call, at
341 * trap level 1, with interrupts fully disabled.
344 * %g5 mm->context (all tlb flushes)
345 * %g1 address arg 1 (tlb page and range flushes)
346 * %g7 address arg 2 (tlb range flush only)
348 * %g6 ivector table, don't touch
353 * TODO: Make xcall TLB range flushes use the tricks above... -DaveM
356 .globl xcall_flush_tlb_mm
358 mov PRIMARY_CONTEXT, %g2
359 ldxa [%g2] ASI_DMMU, %g3
360 srlx %g3, CTX_PGSZ1_NUC_SHIFT, %g4
361 sllx %g4, CTX_PGSZ1_NUC_SHIFT, %g4
362 or %g5, %g4, %g5 /* Preserve nucleus page size fields */
363 stxa %g5, [%g2] ASI_DMMU
365 stxa %g0, [%g4] ASI_DMMU_DEMAP
366 stxa %g0, [%g4] ASI_IMMU_DEMAP
367 stxa %g3, [%g2] ASI_DMMU
370 .globl xcall_flush_tlb_pending
371 xcall_flush_tlb_pending:
372 /* %g5=context, %g1=nr, %g7=vaddrs[] */
374 mov PRIMARY_CONTEXT, %g4
375 ldxa [%g4] ASI_DMMU, %g2
376 srlx %g2, CTX_PGSZ1_NUC_SHIFT, %g4
377 sllx %g4, CTX_PGSZ1_NUC_SHIFT, %g4
379 mov PRIMARY_CONTEXT, %g4
380 stxa %g5, [%g4] ASI_DMMU
381 1: sub %g1, (1 << 3), %g1
387 stxa %g0, [%g5] ASI_IMMU_DEMAP
388 2: stxa %g0, [%g5] ASI_DMMU_DEMAP
392 stxa %g2, [%g4] ASI_DMMU
395 .globl xcall_flush_tlb_kernel_range
396 xcall_flush_tlb_kernel_range:
397 sethi %hi(PAGE_SIZE - 1), %g2
398 or %g2, %lo(PAGE_SIZE - 1), %g2
404 or %g1, 0x20, %g1 ! Nucleus
405 1: stxa %g0, [%g1 + %g3] ASI_DMMU_DEMAP
406 stxa %g0, [%g1 + %g3] ASI_IMMU_DEMAP
414 /* This runs in a very controlled environment, so we do
415 * not need to worry about BH races etc.
417 .globl xcall_sync_tick
420 wrpr %g2, PSTATE_IG | PSTATE_AG, %pstate
425 109: or %g7, %lo(109b), %g7
426 call smp_synchronize_tick_client
430 ldx [%sp + PTREGS_OFF + PT_V9_TSTATE], %l1
432 /* NOTE: This is SPECIAL!! We do etrap/rtrap however
433 * we choose to deal with the "BH's run with
434 * %pil==15" problem (described in asm/pil.h)
435 * by just invoking rtrap directly past where
436 * BH's are checked for.
438 * We do it like this because we do not want %pil==15
439 * lockups to prevent regs being reported.
441 .globl xcall_report_regs
444 wrpr %g2, PSTATE_IG | PSTATE_AG, %pstate
449 109: or %g7, %lo(109b), %g7
451 add %sp, PTREGS_OFF, %o0
453 /* Has to be a non-v9 branch due to the large distance. */
455 ldx [%sp + PTREGS_OFF + PT_V9_TSTATE], %l1
457 #ifdef DCACHE_ALIASING_POSSIBLE
459 .globl xcall_flush_dcache_page_cheetah
460 xcall_flush_dcache_page_cheetah: /* %g1 == physical page address */
461 sethi %hi(PAGE_SIZE), %g3
462 1: subcc %g3, (1 << 5), %g3
463 stxa %g0, [%g1 + %g3] ASI_DCACHE_INVALIDATE
469 #endif /* DCACHE_ALIASING_POSSIBLE */
471 .globl xcall_flush_dcache_page_spitfire
472 xcall_flush_dcache_page_spitfire: /* %g1 == physical page address
473 %g7 == kernel page virtual address
474 %g5 == (page->mapping != NULL) */
475 #ifdef DCACHE_ALIASING_POSSIBLE
476 srlx %g1, (13 - 2), %g1 ! Form tag comparitor
477 sethi %hi(L1DCACHE_SIZE), %g3 ! D$ size == 16K
478 sub %g3, (1 << 5), %g3 ! D$ linesize == 32
479 1: ldxa [%g3] ASI_DCACHE_TAG, %g2
487 stxa %g0, [%g3] ASI_DCACHE_TAG
491 sub %g3, (1 << 5), %g3
494 #endif /* DCACHE_ALIASING_POSSIBLE */
495 sethi %hi(PAGE_SIZE), %g3
498 subcc %g3, (1 << 5), %g3
500 add %g7, (1 << 5), %g7
506 .globl xcall_promstop
509 wrpr %g2, PSTATE_IG | PSTATE_AG, %pstate
514 109: or %g7, %lo(109b), %g7
518 /* We should not return, just spin if we do... */
529 /* These two are not performance critical... */
530 .globl xcall_flush_tlb_all_spitfire
531 xcall_flush_tlb_all_spitfire:
532 /* Spitfire Errata #32 workaround. */
533 sethi %hi(errata32_hwbug), %g4
534 stx %g0, [%g4 + %lo(errata32_hwbug)]
538 1: ldxa [%g3] ASI_DTLB_DATA_ACCESS, %g4
539 and %g4, _PAGE_L, %g5
541 mov TLB_TAG_ACCESS, %g7
543 stxa %g0, [%g7] ASI_DMMU
545 stxa %g0, [%g3] ASI_DTLB_DATA_ACCESS
548 /* Spitfire Errata #32 workaround. */
549 sethi %hi(errata32_hwbug), %g4
550 stx %g0, [%g4 + %lo(errata32_hwbug)]
552 2: ldxa [%g3] ASI_ITLB_DATA_ACCESS, %g4
553 and %g4, _PAGE_L, %g5
555 mov TLB_TAG_ACCESS, %g7
557 stxa %g0, [%g7] ASI_IMMU
559 stxa %g0, [%g3] ASI_ITLB_DATA_ACCESS
562 /* Spitfire Errata #32 workaround. */
563 sethi %hi(errata32_hwbug), %g4
564 stx %g0, [%g4 + %lo(errata32_hwbug)]
567 cmp %g2, SPITFIRE_HIGHEST_LOCKED_TLBENT
573 .globl xcall_flush_tlb_all_cheetah
574 xcall_flush_tlb_all_cheetah:
576 stxa %g0, [%g2] ASI_DMMU_DEMAP
577 stxa %g0, [%g2] ASI_IMMU_DEMAP
580 /* These just get rescheduled to PIL vectors. */
581 .globl xcall_call_function
583 wr %g0, (1 << PIL_SMP_CALL_FUNC), %set_softint
586 .globl xcall_receive_signal
587 xcall_receive_signal:
588 wr %g0, (1 << PIL_SMP_RECEIVE_SIGNAL), %set_softint
593 wr %g0, (1 << PIL_SMP_CAPTURE), %set_softint
596 #endif /* CONFIG_SMP */