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
122 .section .kprobes.text, "ax"
124 .globl __flush_icache_page
125 __flush_icache_page: /* %o0 = phys_page */
127 srlx %o0, PAGE_SHIFT, %o0
128 sethi %uhi(PAGE_OFFSET), %g1
129 sllx %o0, PAGE_SHIFT, %o0
130 sethi %hi(PAGE_SIZE), %g2
133 1: subcc %g2, 32, %g2
139 #ifdef DCACHE_ALIASING_POSSIBLE
141 #if (PAGE_SHIFT != 13)
142 #error only page shift of 13 is supported by dcache flush
145 #define DTAG_MASK 0x3
147 /* This routine is Spitfire specific so the hardcoded
148 * D-cache size and line-size are OK.
151 .globl __flush_dcache_page
152 __flush_dcache_page: /* %o0=kaddr, %o1=flush_icache */
153 sethi %uhi(PAGE_OFFSET), %g1
155 sub %o0, %g1, %o0 ! physical address
156 srlx %o0, 11, %o0 ! make D-cache TAG
157 sethi %hi(1 << 14), %o2 ! D-cache size
158 sub %o2, (1 << 5), %o2 ! D-cache line size
159 1: ldxa [%o2] ASI_DCACHE_TAG, %o3 ! load D-cache TAG
160 andcc %o3, DTAG_MASK, %g0 ! Valid?
161 be,pn %xcc, 2f ! Nope, branch
162 andn %o3, DTAG_MASK, %o3 ! Clear valid bits
163 cmp %o3, %o0 ! TAG match?
164 bne,pt %xcc, 2f ! Nope, branch
166 stxa %g0, [%o2] ASI_DCACHE_TAG ! Invalidate TAG
169 sub %o2, (1 << 5), %o2 ! D-cache line size
171 /* The I-cache does not snoop local stores so we
172 * better flush that too when necessary.
174 brnz,pt %o1, __flush_icache_page
179 #endif /* DCACHE_ALIASING_POSSIBLE */
183 /* Cheetah specific versions, patched at boot time. */
184 __cheetah_flush_tlb_mm: /* 18 insns */
186 andn %g7, PSTATE_IE, %g2
187 wrpr %g2, 0x0, %pstate
189 mov PRIMARY_CONTEXT, %o2
191 ldxa [%o2] ASI_DMMU, %g2
192 srlx %g2, CTX_PGSZ1_NUC_SHIFT, %o1
193 sllx %o1, CTX_PGSZ1_NUC_SHIFT, %o1
194 or %o0, %o1, %o0 /* Preserve nucleus page size fields */
195 stxa %o0, [%o2] ASI_DMMU
196 stxa %g0, [%g3] ASI_DMMU_DEMAP
197 stxa %g0, [%g3] ASI_IMMU_DEMAP
198 stxa %g2, [%o2] ASI_DMMU
202 wrpr %g7, 0x0, %pstate
204 __cheetah_flush_tlb_pending: /* 26 insns */
205 /* %o0 = context, %o1 = nr, %o2 = vaddrs[] */
208 andn %g7, PSTATE_IE, %g2
209 wrpr %g2, 0x0, %pstate
211 mov PRIMARY_CONTEXT, %o4
212 ldxa [%o4] ASI_DMMU, %g2
213 srlx %g2, CTX_PGSZ1_NUC_SHIFT, %o3
214 sllx %o3, CTX_PGSZ1_NUC_SHIFT, %o3
215 or %o0, %o3, %o0 /* Preserve nucleus page size fields */
216 stxa %o0, [%o4] ASI_DMMU
217 1: sub %o1, (1 << 3), %o1
222 stxa %g0, [%o3] ASI_IMMU_DEMAP
223 2: stxa %g0, [%o3] ASI_DMMU_DEMAP
227 stxa %g2, [%o4] ASI_DMMU
231 wrpr %g7, 0x0, %pstate
233 #ifdef DCACHE_ALIASING_POSSIBLE
234 __cheetah_flush_dcache_page: /* 11 insns */
235 sethi %uhi(PAGE_OFFSET), %g1
238 sethi %hi(PAGE_SIZE), %o4
239 1: subcc %o4, (1 << 5), %o4
240 stxa %g0, [%o0 + %o4] ASI_DCACHE_INVALIDATE
244 retl /* I-cache flush never needed on Cheetah, see callers. */
246 #endif /* DCACHE_ALIASING_POSSIBLE */
259 .globl cheetah_patch_cachetlbops
260 cheetah_patch_cachetlbops:
263 sethi %hi(__flush_tlb_mm), %o0
264 or %o0, %lo(__flush_tlb_mm), %o0
265 sethi %hi(__cheetah_flush_tlb_mm), %o1
266 or %o1, %lo(__cheetah_flush_tlb_mm), %o1
267 call cheetah_patch_one
270 sethi %hi(__flush_tlb_pending), %o0
271 or %o0, %lo(__flush_tlb_pending), %o0
272 sethi %hi(__cheetah_flush_tlb_pending), %o1
273 or %o1, %lo(__cheetah_flush_tlb_pending), %o1
274 call cheetah_patch_one
277 #ifdef DCACHE_ALIASING_POSSIBLE
278 sethi %hi(__flush_dcache_page), %o0
279 or %o0, %lo(__flush_dcache_page), %o0
280 sethi %hi(__cheetah_flush_dcache_page), %o1
281 or %o1, %lo(__cheetah_flush_dcache_page), %o1
282 call cheetah_patch_one
284 #endif /* DCACHE_ALIASING_POSSIBLE */
290 /* These are all called by the slaves of a cross call, at
291 * trap level 1, with interrupts fully disabled.
294 * %g5 mm->context (all tlb flushes)
295 * %g1 address arg 1 (tlb page and range flushes)
296 * %g7 address arg 2 (tlb range flush only)
298 * %g6 ivector table, don't touch
303 * TODO: Make xcall TLB range flushes use the tricks above... -DaveM
306 .globl xcall_flush_tlb_mm
308 mov PRIMARY_CONTEXT, %g2
309 ldxa [%g2] ASI_DMMU, %g3
310 srlx %g3, CTX_PGSZ1_NUC_SHIFT, %g4
311 sllx %g4, CTX_PGSZ1_NUC_SHIFT, %g4
312 or %g5, %g4, %g5 /* Preserve nucleus page size fields */
313 stxa %g5, [%g2] ASI_DMMU
315 stxa %g0, [%g4] ASI_DMMU_DEMAP
316 stxa %g0, [%g4] ASI_IMMU_DEMAP
317 stxa %g3, [%g2] ASI_DMMU
320 .globl xcall_flush_tlb_pending
321 xcall_flush_tlb_pending:
322 /* %g5=context, %g1=nr, %g7=vaddrs[] */
324 mov PRIMARY_CONTEXT, %g4
325 ldxa [%g4] ASI_DMMU, %g2
326 srlx %g2, CTX_PGSZ1_NUC_SHIFT, %g4
327 sllx %g4, CTX_PGSZ1_NUC_SHIFT, %g4
329 mov PRIMARY_CONTEXT, %g4
330 stxa %g5, [%g4] ASI_DMMU
331 1: sub %g1, (1 << 3), %g1
337 stxa %g0, [%g5] ASI_IMMU_DEMAP
338 2: stxa %g0, [%g5] ASI_DMMU_DEMAP
342 stxa %g2, [%g4] ASI_DMMU
345 .globl xcall_flush_tlb_kernel_range
346 xcall_flush_tlb_kernel_range:
347 sethi %hi(PAGE_SIZE - 1), %g2
348 or %g2, %lo(PAGE_SIZE - 1), %g2
354 or %g1, 0x20, %g1 ! Nucleus
355 1: stxa %g0, [%g1 + %g3] ASI_DMMU_DEMAP
356 stxa %g0, [%g1 + %g3] ASI_IMMU_DEMAP
364 /* This runs in a very controlled environment, so we do
365 * not need to worry about BH races etc.
367 .globl xcall_sync_tick
370 wrpr %g2, PSTATE_IG | PSTATE_AG, %pstate
375 109: or %g7, %lo(109b), %g7
376 call smp_synchronize_tick_client
380 ldx [%sp + PTREGS_OFF + PT_V9_TSTATE], %l1
382 /* NOTE: This is SPECIAL!! We do etrap/rtrap however
383 * we choose to deal with the "BH's run with
384 * %pil==15" problem (described in asm/pil.h)
385 * by just invoking rtrap directly past where
386 * BH's are checked for.
388 * We do it like this because we do not want %pil==15
389 * lockups to prevent regs being reported.
391 .globl xcall_report_regs
394 wrpr %g2, PSTATE_IG | PSTATE_AG, %pstate
399 109: or %g7, %lo(109b), %g7
401 add %sp, PTREGS_OFF, %o0
403 /* Has to be a non-v9 branch due to the large distance. */
405 ldx [%sp + PTREGS_OFF + PT_V9_TSTATE], %l1
407 #ifdef DCACHE_ALIASING_POSSIBLE
409 .globl xcall_flush_dcache_page_cheetah
410 xcall_flush_dcache_page_cheetah: /* %g1 == physical page address */
411 sethi %hi(PAGE_SIZE), %g3
412 1: subcc %g3, (1 << 5), %g3
413 stxa %g0, [%g1 + %g3] ASI_DCACHE_INVALIDATE
419 #endif /* DCACHE_ALIASING_POSSIBLE */
421 .globl xcall_flush_dcache_page_spitfire
422 xcall_flush_dcache_page_spitfire: /* %g1 == physical page address
423 %g7 == kernel page virtual address
424 %g5 == (page->mapping != NULL) */
425 #ifdef DCACHE_ALIASING_POSSIBLE
426 srlx %g1, (13 - 2), %g1 ! Form tag comparitor
427 sethi %hi(L1DCACHE_SIZE), %g3 ! D$ size == 16K
428 sub %g3, (1 << 5), %g3 ! D$ linesize == 32
429 1: ldxa [%g3] ASI_DCACHE_TAG, %g2
437 stxa %g0, [%g3] ASI_DCACHE_TAG
441 sub %g3, (1 << 5), %g3
444 #endif /* DCACHE_ALIASING_POSSIBLE */
445 sethi %hi(PAGE_SIZE), %g3
448 subcc %g3, (1 << 5), %g3
450 add %g7, (1 << 5), %g7
463 /* These two are not performance critical... */
464 .globl xcall_flush_tlb_all_spitfire
465 xcall_flush_tlb_all_spitfire:
466 /* Spitfire Errata #32 workaround. */
467 sethi %hi(errata32_hwbug), %g4
468 stx %g0, [%g4 + %lo(errata32_hwbug)]
472 1: ldxa [%g3] ASI_DTLB_DATA_ACCESS, %g4
473 and %g4, _PAGE_L, %g5
475 mov TLB_TAG_ACCESS, %g7
477 stxa %g0, [%g7] ASI_DMMU
479 stxa %g0, [%g3] ASI_DTLB_DATA_ACCESS
482 /* Spitfire Errata #32 workaround. */
483 sethi %hi(errata32_hwbug), %g4
484 stx %g0, [%g4 + %lo(errata32_hwbug)]
486 2: ldxa [%g3] ASI_ITLB_DATA_ACCESS, %g4
487 and %g4, _PAGE_L, %g5
489 mov TLB_TAG_ACCESS, %g7
491 stxa %g0, [%g7] ASI_IMMU
493 stxa %g0, [%g3] ASI_ITLB_DATA_ACCESS
496 /* Spitfire Errata #32 workaround. */
497 sethi %hi(errata32_hwbug), %g4
498 stx %g0, [%g4 + %lo(errata32_hwbug)]
501 cmp %g2, SPITFIRE_HIGHEST_LOCKED_TLBENT
507 .globl xcall_flush_tlb_all_cheetah
508 xcall_flush_tlb_all_cheetah:
510 stxa %g0, [%g2] ASI_DMMU_DEMAP
511 stxa %g0, [%g2] ASI_IMMU_DEMAP
514 /* These just get rescheduled to PIL vectors. */
515 .globl xcall_call_function
517 wr %g0, (1 << PIL_SMP_CALL_FUNC), %set_softint
520 .globl xcall_receive_signal
521 xcall_receive_signal:
522 wr %g0, (1 << PIL_SMP_RECEIVE_SIGNAL), %set_softint
527 wr %g0, (1 << PIL_SMP_CAPTURE), %set_softint
530 #endif /* CONFIG_SMP */