blob: a87394824ec2d7dd300bf0593e53906637837fe1 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/* $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...
3 *
4 * Copyright (C) 1997, 2000 David S. Miller (davem@redhat.com)
5 */
6
7#include <linux/config.h>
8#include <asm/asi.h>
9#include <asm/pgtable.h>
10#include <asm/page.h>
11#include <asm/spitfire.h>
12#include <asm/mmu_context.h>
David S. Miller2ef27772005-08-30 20:21:34 -070013#include <asm/mmu.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070014#include <asm/pil.h>
15#include <asm/head.h>
16#include <asm/thread_info.h>
17#include <asm/cacheflush.h>
18
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.
24 */
25
26 /* This file is meant to be read efficiently by the CPU, not humans.
27 * Staraj sie tego nikomu nie pierdolnac...
28 */
29 .text
30 .align 32
31 .globl __flush_tlb_mm
32__flush_tlb_mm: /* %o0=(ctx & TAG_CONTEXT_BITS), %o1=SECONDARY_CONTEXT */
33 ldxa [%o1] ASI_DMMU, %g2
34 cmp %g2, %o0
35 bne,pn %icc, __spitfire_flush_tlb_mm_slow
36 mov 0x50, %g3
37 stxa %g0, [%g3] ASI_DMMU_DEMAP
38 stxa %g0, [%g3] ASI_IMMU_DEMAP
39 retl
40 flush %g6
41 nop
42 nop
43 nop
44 nop
45 nop
46 nop
47 nop
48 nop
David S. Miller2ef27772005-08-30 20:21:34 -070049 nop
50 nop
Linus Torvalds1da177e2005-04-16 15:20:36 -070051
52 .align 32
53 .globl __flush_tlb_pending
54__flush_tlb_pending:
55 /* %o0 = context, %o1 = nr, %o2 = vaddrs[] */
56 rdpr %pstate, %g7
57 sllx %o1, 3, %o1
58 andn %g7, PSTATE_IE, %g2
59 wrpr %g2, %pstate
60 mov SECONDARY_CONTEXT, %o4
61 ldxa [%o4] ASI_DMMU, %g2
62 stxa %o0, [%o4] ASI_DMMU
631: sub %o1, (1 << 3), %o1
64 ldx [%o2 + %o1], %o3
65 andcc %o3, 1, %g0
66 andn %o3, 1, %o3
67 be,pn %icc, 2f
68 or %o3, 0x10, %o3
69 stxa %g0, [%o3] ASI_IMMU_DEMAP
702: stxa %g0, [%o3] ASI_DMMU_DEMAP
71 membar #Sync
72 brnz,pt %o1, 1b
73 nop
74 stxa %g2, [%o4] ASI_DMMU
75 flush %g6
76 retl
77 wrpr %g7, 0x0, %pstate
David S. Millerfef43da2005-07-05 19:45:24 -070078 nop
David S. Miller2ef27772005-08-30 20:21:34 -070079 nop
80 nop
81 nop
Linus Torvalds1da177e2005-04-16 15:20:36 -070082
83 .align 32
84 .globl __flush_tlb_kernel_range
85__flush_tlb_kernel_range: /* %o0=start, %o1=end */
86 cmp %o0, %o1
87 be,pn %xcc, 2f
88 sethi %hi(PAGE_SIZE), %o4
89 sub %o1, %o0, %o3
90 sub %o3, %o4, %o3
91 or %o0, 0x20, %o0 ! Nucleus
921: stxa %g0, [%o0 + %o3] ASI_DMMU_DEMAP
93 stxa %g0, [%o0 + %o3] ASI_IMMU_DEMAP
94 membar #Sync
95 brnz,pt %o3, 1b
96 sub %o3, %o4, %o3
972: retl
98 flush %g6
99
100__spitfire_flush_tlb_mm_slow:
101 rdpr %pstate, %g1
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
106 flush %g6
107 stxa %g2, [%o1] ASI_DMMU
108 flush %g6
109 retl
110 wrpr %g1, 0, %pstate
111
112/*
113 * The following code flushes one page_size worth.
114 */
115#if (PAGE_SHIFT == 13)
116#define ITAG_MASK 0xfe
117#elif (PAGE_SHIFT == 16)
118#define ITAG_MASK 0x7fe
119#else
120#error unsupported PAGE_SIZE
121#endif
Prasanna S Panchamukhi83005162005-09-06 15:19:31 -0700122 .section .kprobes.text, "ax"
Linus Torvalds1da177e2005-04-16 15:20:36 -0700123 .align 32
124 .globl __flush_icache_page
125__flush_icache_page: /* %o0 = phys_page */
126 membar #StoreStore
127 srlx %o0, PAGE_SHIFT, %o0
128 sethi %uhi(PAGE_OFFSET), %g1
129 sllx %o0, PAGE_SHIFT, %o0
130 sethi %hi(PAGE_SIZE), %g2
131 sllx %g1, 32, %g1
132 add %o0, %g1, %o0
1331: subcc %g2, 32, %g2
134 bne,pt %icc, 1b
135 flush %o0 + %g2
136 retl
137 nop
138
139#ifdef DCACHE_ALIASING_POSSIBLE
140
141#if (PAGE_SHIFT != 13)
142#error only page shift of 13 is supported by dcache flush
143#endif
144
145#define DTAG_MASK 0x3
146
David S. Millerc5bd50a2005-09-26 16:06:03 -0700147 /* This routine is Spitfire specific so the hardcoded
148 * D-cache size and line-size are OK.
149 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700150 .align 64
151 .globl __flush_dcache_page
152__flush_dcache_page: /* %o0=kaddr, %o1=flush_icache */
153 sethi %uhi(PAGE_OFFSET), %g1
154 sllx %g1, 32, %g1
David S. Millerc5bd50a2005-09-26 16:06:03 -0700155 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
1591: 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
165 nop
166 stxa %g0, [%o2] ASI_DCACHE_TAG ! Invalidate TAG
167 membar #Sync
1682: brnz,pt %o2, 1b
169 sub %o2, (1 << 5), %o2 ! D-cache line size
Linus Torvalds1da177e2005-04-16 15:20:36 -0700170
171 /* The I-cache does not snoop local stores so we
172 * better flush that too when necessary.
173 */
174 brnz,pt %o1, __flush_icache_page
175 sllx %o0, 11, %o0
176 retl
177 nop
178
Linus Torvalds1da177e2005-04-16 15:20:36 -0700179#endif /* DCACHE_ALIASING_POSSIBLE */
180
David S. Millerc5bd50a2005-09-26 16:06:03 -0700181 .previous
182
David S. Miller2ef27772005-08-30 20:21:34 -0700183 /* Cheetah specific versions, patched at boot time. */
184__cheetah_flush_tlb_mm: /* 18 insns */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700185 rdpr %pstate, %g7
186 andn %g7, PSTATE_IE, %g2
187 wrpr %g2, 0x0, %pstate
188 wrpr %g0, 1, %tl
189 mov PRIMARY_CONTEXT, %o2
190 mov 0x40, %g3
191 ldxa [%o2] ASI_DMMU, %g2
David S. Miller2ef27772005-08-30 20:21:34 -0700192 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 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700195 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
199 flush %g6
200 wrpr %g0, 0, %tl
201 retl
202 wrpr %g7, 0x0, %pstate
203
David S. Miller2ef27772005-08-30 20:21:34 -0700204__cheetah_flush_tlb_pending: /* 26 insns */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700205 /* %o0 = context, %o1 = nr, %o2 = vaddrs[] */
206 rdpr %pstate, %g7
207 sllx %o1, 3, %o1
208 andn %g7, PSTATE_IE, %g2
209 wrpr %g2, 0x0, %pstate
210 wrpr %g0, 1, %tl
211 mov PRIMARY_CONTEXT, %o4
212 ldxa [%o4] ASI_DMMU, %g2
David S. Miller2ef27772005-08-30 20:21:34 -0700213 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 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700216 stxa %o0, [%o4] ASI_DMMU
2171: sub %o1, (1 << 3), %o1
218 ldx [%o2 + %o1], %o3
219 andcc %o3, 1, %g0
220 be,pn %icc, 2f
221 andn %o3, 1, %o3
222 stxa %g0, [%o3] ASI_IMMU_DEMAP
2232: stxa %g0, [%o3] ASI_DMMU_DEMAP
David S. Millerb445e262005-06-27 15:42:04 -0700224 membar #Sync
Linus Torvalds1da177e2005-04-16 15:20:36 -0700225 brnz,pt %o1, 1b
David S. Millerb445e262005-06-27 15:42:04 -0700226 nop
Linus Torvalds1da177e2005-04-16 15:20:36 -0700227 stxa %g2, [%o4] ASI_DMMU
228 flush %g6
229 wrpr %g0, 0, %tl
230 retl
231 wrpr %g7, 0x0, %pstate
232
233#ifdef DCACHE_ALIASING_POSSIBLE
David S. Millerc5bd50a2005-09-26 16:06:03 -0700234__cheetah_flush_dcache_page: /* 11 insns */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700235 sethi %uhi(PAGE_OFFSET), %g1
236 sllx %g1, 32, %g1
237 sub %o0, %g1, %o0
238 sethi %hi(PAGE_SIZE), %o4
2391: subcc %o4, (1 << 5), %o4
240 stxa %g0, [%o0 + %o4] ASI_DCACHE_INVALIDATE
241 membar #Sync
242 bne,pt %icc, 1b
243 nop
244 retl /* I-cache flush never needed on Cheetah, see callers. */
245 nop
246#endif /* DCACHE_ALIASING_POSSIBLE */
247
248cheetah_patch_one:
2491: lduw [%o1], %g1
250 stw %g1, [%o0]
251 flush %o0
252 subcc %o2, 1, %o2
253 add %o1, 4, %o1
254 bne,pt %icc, 1b
255 add %o0, 4, %o0
256 retl
257 nop
258
259 .globl cheetah_patch_cachetlbops
260cheetah_patch_cachetlbops:
261 save %sp, -128, %sp
262
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
David S. Miller2ef27772005-08-30 20:21:34 -0700268 mov 18, %o2
Linus Torvalds1da177e2005-04-16 15:20:36 -0700269
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
David S. Miller2ef27772005-08-30 20:21:34 -0700275 mov 26, %o2
Linus Torvalds1da177e2005-04-16 15:20:36 -0700276
277#ifdef DCACHE_ALIASING_POSSIBLE
278 sethi %hi(__flush_dcache_page), %o0
279 or %o0, %lo(__flush_dcache_page), %o0
David S. Millerc5bd50a2005-09-26 16:06:03 -0700280 sethi %hi(__cheetah_flush_dcache_page), %o1
281 or %o1, %lo(__cheetah_flush_dcache_page), %o1
Linus Torvalds1da177e2005-04-16 15:20:36 -0700282 call cheetah_patch_one
283 mov 11, %o2
284#endif /* DCACHE_ALIASING_POSSIBLE */
285
286 ret
287 restore
288
289#ifdef CONFIG_SMP
290 /* These are all called by the slaves of a cross call, at
291 * trap level 1, with interrupts fully disabled.
292 *
293 * Register usage:
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)
297 *
David S. Miller56fb4df2006-02-26 23:24:22 -0800298 * %g6 scratch 1
299 * %g2 scratch 2
300 * %g3 scratch 3
301 * %g4 scratch 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700302 */
303 .align 32
304 .globl xcall_flush_tlb_mm
305xcall_flush_tlb_mm:
306 mov PRIMARY_CONTEXT, %g2
Linus Torvalds1da177e2005-04-16 15:20:36 -0700307 ldxa [%g2] ASI_DMMU, %g3
David S. Miller2ef27772005-08-30 20:21:34 -0700308 srlx %g3, CTX_PGSZ1_NUC_SHIFT, %g4
309 sllx %g4, CTX_PGSZ1_NUC_SHIFT, %g4
310 or %g5, %g4, %g5 /* Preserve nucleus page size fields */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700311 stxa %g5, [%g2] ASI_DMMU
David S. Miller2ef27772005-08-30 20:21:34 -0700312 mov 0x40, %g4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700313 stxa %g0, [%g4] ASI_DMMU_DEMAP
314 stxa %g0, [%g4] ASI_IMMU_DEMAP
315 stxa %g3, [%g2] ASI_DMMU
316 retry
317
318 .globl xcall_flush_tlb_pending
319xcall_flush_tlb_pending:
320 /* %g5=context, %g1=nr, %g7=vaddrs[] */
321 sllx %g1, 3, %g1
322 mov PRIMARY_CONTEXT, %g4
323 ldxa [%g4] ASI_DMMU, %g2
David S. Miller2ef27772005-08-30 20:21:34 -0700324 srlx %g2, CTX_PGSZ1_NUC_SHIFT, %g4
325 sllx %g4, CTX_PGSZ1_NUC_SHIFT, %g4
326 or %g5, %g4, %g5
327 mov PRIMARY_CONTEXT, %g4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700328 stxa %g5, [%g4] ASI_DMMU
3291: sub %g1, (1 << 3), %g1
330 ldx [%g7 + %g1], %g5
331 andcc %g5, 0x1, %g0
332 be,pn %icc, 2f
333
334 andn %g5, 0x1, %g5
335 stxa %g0, [%g5] ASI_IMMU_DEMAP
3362: stxa %g0, [%g5] ASI_DMMU_DEMAP
337 membar #Sync
338 brnz,pt %g1, 1b
339 nop
340 stxa %g2, [%g4] ASI_DMMU
341 retry
342
343 .globl xcall_flush_tlb_kernel_range
344xcall_flush_tlb_kernel_range:
345 sethi %hi(PAGE_SIZE - 1), %g2
346 or %g2, %lo(PAGE_SIZE - 1), %g2
347 andn %g1, %g2, %g1
348 andn %g7, %g2, %g7
349 sub %g7, %g1, %g3
350 add %g2, 1, %g2
351 sub %g3, %g2, %g3
352 or %g1, 0x20, %g1 ! Nucleus
3531: stxa %g0, [%g1 + %g3] ASI_DMMU_DEMAP
354 stxa %g0, [%g1 + %g3] ASI_IMMU_DEMAP
355 membar #Sync
356 brnz,pt %g3, 1b
357 sub %g3, %g2, %g3
358 retry
359 nop
360 nop
361
362 /* This runs in a very controlled environment, so we do
363 * not need to worry about BH races etc.
364 */
365 .globl xcall_sync_tick
366xcall_sync_tick:
367 rdpr %pstate, %g2
368 wrpr %g2, PSTATE_IG | PSTATE_AG, %pstate
369 rdpr %pil, %g2
370 wrpr %g0, 15, %pil
371 sethi %hi(109f), %g7
372 b,pt %xcc, etrap_irq
373109: or %g7, %lo(109b), %g7
374 call smp_synchronize_tick_client
375 nop
376 clr %l6
377 b rtrap_xcall
378 ldx [%sp + PTREGS_OFF + PT_V9_TSTATE], %l1
379
380 /* NOTE: This is SPECIAL!! We do etrap/rtrap however
381 * we choose to deal with the "BH's run with
382 * %pil==15" problem (described in asm/pil.h)
383 * by just invoking rtrap directly past where
384 * BH's are checked for.
385 *
386 * We do it like this because we do not want %pil==15
387 * lockups to prevent regs being reported.
388 */
389 .globl xcall_report_regs
390xcall_report_regs:
391 rdpr %pstate, %g2
392 wrpr %g2, PSTATE_IG | PSTATE_AG, %pstate
393 rdpr %pil, %g2
394 wrpr %g0, 15, %pil
395 sethi %hi(109f), %g7
396 b,pt %xcc, etrap_irq
397109: or %g7, %lo(109b), %g7
398 call __show_regs
399 add %sp, PTREGS_OFF, %o0
400 clr %l6
401 /* Has to be a non-v9 branch due to the large distance. */
402 b rtrap_xcall
403 ldx [%sp + PTREGS_OFF + PT_V9_TSTATE], %l1
404
405#ifdef DCACHE_ALIASING_POSSIBLE
406 .align 32
407 .globl xcall_flush_dcache_page_cheetah
408xcall_flush_dcache_page_cheetah: /* %g1 == physical page address */
409 sethi %hi(PAGE_SIZE), %g3
4101: subcc %g3, (1 << 5), %g3
411 stxa %g0, [%g1 + %g3] ASI_DCACHE_INVALIDATE
412 membar #Sync
413 bne,pt %icc, 1b
414 nop
415 retry
416 nop
417#endif /* DCACHE_ALIASING_POSSIBLE */
418
419 .globl xcall_flush_dcache_page_spitfire
420xcall_flush_dcache_page_spitfire: /* %g1 == physical page address
421 %g7 == kernel page virtual address
422 %g5 == (page->mapping != NULL) */
423#ifdef DCACHE_ALIASING_POSSIBLE
424 srlx %g1, (13 - 2), %g1 ! Form tag comparitor
425 sethi %hi(L1DCACHE_SIZE), %g3 ! D$ size == 16K
426 sub %g3, (1 << 5), %g3 ! D$ linesize == 32
4271: ldxa [%g3] ASI_DCACHE_TAG, %g2
428 andcc %g2, 0x3, %g0
429 be,pn %xcc, 2f
430 andn %g2, 0x3, %g2
431 cmp %g2, %g1
432
433 bne,pt %xcc, 2f
434 nop
435 stxa %g0, [%g3] ASI_DCACHE_TAG
436 membar #Sync
4372: cmp %g3, 0
438 bne,pt %xcc, 1b
439 sub %g3, (1 << 5), %g3
440
441 brz,pn %g5, 2f
442#endif /* DCACHE_ALIASING_POSSIBLE */
443 sethi %hi(PAGE_SIZE), %g3
444
4451: flush %g7
446 subcc %g3, (1 << 5), %g3
447 bne,pt %icc, 1b
448 add %g7, (1 << 5), %g7
449
4502: retry
451 nop
452 nop
453
Linus Torvalds1da177e2005-04-16 15:20:36 -0700454 /* These just get rescheduled to PIL vectors. */
455 .globl xcall_call_function
456xcall_call_function:
457 wr %g0, (1 << PIL_SMP_CALL_FUNC), %set_softint
458 retry
459
460 .globl xcall_receive_signal
461xcall_receive_signal:
462 wr %g0, (1 << PIL_SMP_RECEIVE_SIGNAL), %set_softint
463 retry
464
465 .globl xcall_capture
466xcall_capture:
467 wr %g0, (1 << PIL_SMP_CAPTURE), %set_softint
468 retry
469
470#endif /* CONFIG_SMP */