505a3d010c479561f3d10cc8c2a3b02ef2cd1288
[linux-2.6-microblaze.git] / arch / powerpc / mm / tlb_nohash_low.S
1 /*
2  * This file contains low-level functions for performing various
3  * types of TLB invalidations on various processors with no hash
4  * table.
5  *
6  * This file implements the following functions for all no-hash
7  * processors. Some aren't implemented for some variants. Some
8  * are inline in tlbflush.h
9  *
10  *      - tlbil_va
11  *      - tlbil_pid
12  *      - tlbil_all
13  *      - tlbivax_bcast
14  *
15  * Code mostly moved over from misc_32.S
16  *
17  *    Copyright (C) 1995-1996 Gary Thomas (gdt@linuxppc.org)
18  *
19  * Partially rewritten by Cort Dougan (cort@cs.nmt.edu)
20  * Paul Mackerras, Kumar Gala and Benjamin Herrenschmidt.
21  *
22  * This program is free software; you can redistribute it and/or
23  * modify it under the terms of the GNU General Public License
24  * as published by the Free Software Foundation; either version
25  * 2 of the License, or (at your option) any later version.
26  *
27  */
28
29 #include <asm/reg.h>
30 #include <asm/page.h>
31 #include <asm/cputable.h>
32 #include <asm/mmu.h>
33 #include <asm/ppc_asm.h>
34 #include <asm/asm-offsets.h>
35 #include <asm/processor.h>
36 #include <asm/bug.h>
37 #include <asm/asm-compat.h>
38
39 #if defined(CONFIG_40x)
40
41 /*
42  * 40x implementation needs only tlbil_va
43  */
44 _GLOBAL(__tlbil_va)
45         /* We run the search with interrupts disabled because we have to change
46          * the PID and I don't want to preempt when that happens.
47          */
48         mfmsr   r5
49         mfspr   r6,SPRN_PID
50         wrteei  0
51         mtspr   SPRN_PID,r4
52         tlbsx.  r3, 0, r3
53         mtspr   SPRN_PID,r6
54         wrtee   r5
55         bne     1f
56         sync
57         /* There are only 64 TLB entries, so r3 < 64, which means bit 25 is
58          * clear. Since 25 is the V bit in the TLB_TAG, loading this value
59          * will invalidate the TLB entry. */
60         tlbwe   r3, r3, TLB_TAG
61         isync
62 1:      blr
63
64 #elif defined(CONFIG_PPC_8xx)
65
66 /*
67  * Nothing to do for 8xx, everything is inline
68  */
69
70 #elif defined(CONFIG_44x) /* Includes 47x */
71
72 /*
73  * 440 implementation uses tlbsx/we for tlbil_va and a full sweep
74  * of the TLB for everything else.
75  */
76 _GLOBAL(__tlbil_va)
77         mfspr   r5,SPRN_MMUCR
78         mfmsr   r10
79
80         /*
81          * We write 16 bits of STID since 47x supports that much, we
82          * will never be passed out of bounds values on 440 (hopefully)
83          */
84         rlwimi  r5,r4,0,16,31
85
86         /* We have to run the search with interrupts disabled, otherwise
87          * an interrupt which causes a TLB miss can clobber the MMUCR
88          * between the mtspr and the tlbsx.
89          *
90          * Critical and Machine Check interrupts take care of saving
91          * and restoring MMUCR, so only normal interrupts have to be
92          * taken care of.
93          */
94         wrteei  0
95         mtspr   SPRN_MMUCR,r5
96         tlbsx.  r6,0,r3
97         bne     10f
98         sync
99 BEGIN_MMU_FTR_SECTION
100         b       2f
101 END_MMU_FTR_SECTION_IFSET(MMU_FTR_TYPE_47x)
102         /* On 440 There are only 64 TLB entries, so r3 < 64, which means bit
103          * 22, is clear.  Since 22 is the V bit in the TLB_PAGEID, loading this
104          * value will invalidate the TLB entry.
105          */
106         tlbwe   r6,r6,PPC44x_TLB_PAGEID
107         isync
108 10:     wrtee   r10
109         blr
110 2:
111 #ifdef CONFIG_PPC_47x
112         oris    r7,r6,0x8000    /* specify way explicitly */
113         clrrwi  r4,r3,12        /* get an EPN for the hashing with V = 0 */
114         ori     r4,r4,PPC47x_TLBE_SIZE
115         tlbwe   r4,r7,0         /* write it */
116         isync
117         wrtee   r10
118         blr
119 #else /* CONFIG_PPC_47x */
120 1:      trap
121         EMIT_BUG_ENTRY 1b,__FILE__,__LINE__,0;
122 #endif /* !CONFIG_PPC_47x */
123
124 _GLOBAL(_tlbil_all)
125 _GLOBAL(_tlbil_pid)
126 BEGIN_MMU_FTR_SECTION
127         b       2f
128 END_MMU_FTR_SECTION_IFSET(MMU_FTR_TYPE_47x)
129         li      r3,0
130         sync
131
132         /* Load high watermark */
133         lis     r4,tlb_44x_hwater@ha
134         lwz     r5,tlb_44x_hwater@l(r4)
135
136 1:      tlbwe   r3,r3,PPC44x_TLB_PAGEID
137         addi    r3,r3,1
138         cmpw    0,r3,r5
139         ble     1b
140
141         isync
142         blr
143 2:
144 #ifdef CONFIG_PPC_47x
145         /* 476 variant. There's not simple way to do this, hopefully we'll
146          * try to limit the amount of such full invalidates
147          */
148         mfmsr   r11             /* Interrupts off */
149         wrteei  0
150         li      r3,-1           /* Current set */
151         lis     r10,tlb_47x_boltmap@h
152         ori     r10,r10,tlb_47x_boltmap@l
153         lis     r7,0x8000       /* Specify way explicitly */
154
155         b       9f              /* For each set */
156
157 1:      li      r9,4            /* Number of ways */
158         li      r4,0            /* Current way */
159         li      r6,0            /* Default entry value 0 */
160         andi.   r0,r8,1         /* Check if way 0 is bolted */
161         mtctr   r9              /* Load way counter */
162         bne-    3f              /* Bolted, skip loading it */
163
164 2:      /* For each way */
165         or      r5,r3,r4        /* Make way|index for tlbre */
166         rlwimi  r5,r5,16,8,15   /* Copy index into position */
167         tlbre   r6,r5,0         /* Read entry */
168 3:      addis   r4,r4,0x2000    /* Next way */
169         andi.   r0,r6,PPC47x_TLB0_VALID /* Valid entry ? */
170         beq     4f              /* Nope, skip it */
171         rlwimi  r7,r5,0,1,2     /* Insert way number */
172         rlwinm  r6,r6,0,21,19   /* Clear V */
173         tlbwe   r6,r7,0         /* Write it */
174 4:      bdnz    2b              /* Loop for each way */
175         srwi    r8,r8,1         /* Next boltmap bit */
176 9:      cmpwi   cr1,r3,255      /* Last set done ? */
177         addi    r3,r3,1         /* Next set */
178         beq     cr1,1f          /* End of loop */
179         andi.   r0,r3,0x1f      /* Need to load a new boltmap word ? */
180         bne     1b              /* No, loop */
181         lwz     r8,0(r10)       /* Load boltmap entry */
182         addi    r10,r10,4       /* Next word */
183         b       1b              /* Then loop */
184 1:      isync                   /* Sync shadows */
185         wrtee   r11
186 #else /* CONFIG_PPC_47x */
187 1:      trap
188         EMIT_BUG_ENTRY 1b,__FILE__,__LINE__,0;
189 #endif /* !CONFIG_PPC_47x */
190         blr
191
192 #ifdef CONFIG_PPC_47x
193
194 /*
195  * _tlbivax_bcast is only on 47x. We don't bother doing a runtime
196  * check though, it will blow up soon enough if we mistakenly try
197  * to use it on a 440.
198  */
199 _GLOBAL(_tlbivax_bcast)
200         mfspr   r5,SPRN_MMUCR
201         mfmsr   r10
202         rlwimi  r5,r4,0,16,31
203         wrteei  0
204         mtspr   SPRN_MMUCR,r5
205         isync
206         PPC_TLBIVAX(0, R3)
207         isync
208         eieio
209         tlbsync
210 BEGIN_FTR_SECTION
211         b       1f
212 END_FTR_SECTION_IFSET(CPU_FTR_476_DD2)
213         sync
214         wrtee   r10
215         blr
216 /*
217  * DD2 HW could hang if in instruction fetch happens before msync completes.
218  * Touch enough instruction cache lines to ensure cache hits
219  */
220 1:      mflr    r9
221         bl      2f
222 2:      mflr    r6
223         li      r7,32
224         PPC_ICBT(0,R6,R7)               /* touch next cache line */
225         add     r6,r6,r7
226         PPC_ICBT(0,R6,R7)               /* touch next cache line */
227         add     r6,r6,r7
228         PPC_ICBT(0,R6,R7)               /* touch next cache line */
229         sync
230         nop
231         nop
232         nop
233         nop
234         nop
235         nop
236         nop
237         nop
238         mtlr    r9
239         wrtee   r10
240         blr
241 #endif /* CONFIG_PPC_47x */
242
243 #elif defined(CONFIG_FSL_BOOKE)
244 /*
245  * FSL BookE implementations.
246  *
247  * Since feature sections are using _SECTION_ELSE we need
248  * to have the larger code path before the _SECTION_ELSE
249  */
250
251 /*
252  * Flush MMU TLB on the local processor
253  */
254 _GLOBAL(_tlbil_all)
255 BEGIN_MMU_FTR_SECTION
256         li      r3,(MMUCSR0_TLBFI)@l
257         mtspr   SPRN_MMUCSR0, r3
258 1:
259         mfspr   r3,SPRN_MMUCSR0
260         andi.   r3,r3,MMUCSR0_TLBFI@l
261         bne     1b
262 MMU_FTR_SECTION_ELSE
263         PPC_TLBILX_ALL(0,R0)
264 ALT_MMU_FTR_SECTION_END_IFCLR(MMU_FTR_USE_TLBILX)
265         msync
266         isync
267         blr
268
269 _GLOBAL(_tlbil_pid)
270 BEGIN_MMU_FTR_SECTION
271         slwi    r3,r3,16
272         mfmsr   r10
273         wrteei  0
274         mfspr   r4,SPRN_MAS6    /* save MAS6 */
275         mtspr   SPRN_MAS6,r3
276         PPC_TLBILX_PID(0,R0)
277         mtspr   SPRN_MAS6,r4    /* restore MAS6 */
278         wrtee   r10
279 MMU_FTR_SECTION_ELSE
280         li      r3,(MMUCSR0_TLBFI)@l
281         mtspr   SPRN_MMUCSR0, r3
282 1:
283         mfspr   r3,SPRN_MMUCSR0
284         andi.   r3,r3,MMUCSR0_TLBFI@l
285         bne     1b
286 ALT_MMU_FTR_SECTION_END_IFSET(MMU_FTR_USE_TLBILX)
287         msync
288         isync
289         blr
290
291 /*
292  * Flush MMU TLB for a particular address, but only on the local processor
293  * (no broadcast)
294  */
295 _GLOBAL(__tlbil_va)
296         mfmsr   r10
297         wrteei  0
298         slwi    r4,r4,16
299         ori     r4,r4,(MAS6_ISIZE(BOOK3E_PAGESZ_4K))@l
300         mtspr   SPRN_MAS6,r4            /* assume AS=0 for now */
301 BEGIN_MMU_FTR_SECTION
302         tlbsx   0,r3
303         mfspr   r4,SPRN_MAS1            /* check valid */
304         andis.  r3,r4,MAS1_VALID@h
305         beq     1f
306         rlwinm  r4,r4,0,1,31
307         mtspr   SPRN_MAS1,r4
308         tlbwe
309 MMU_FTR_SECTION_ELSE
310         PPC_TLBILX_VA(0,R3)
311 ALT_MMU_FTR_SECTION_END_IFCLR(MMU_FTR_USE_TLBILX)
312         msync
313         isync
314 1:      wrtee   r10
315         blr
316 #elif defined(CONFIG_PPC_BOOK3E)
317 /*
318  * New Book3E (>= 2.06) implementation
319  *
320  * Note: We may be able to get away without the interrupt masking stuff
321  * if we save/restore MAS6 on exceptions that might modify it
322  */
323 _GLOBAL(_tlbil_pid)
324         slwi    r4,r3,MAS6_SPID_SHIFT
325         mfmsr   r10
326         wrteei  0
327         mtspr   SPRN_MAS6,r4
328         PPC_TLBILX_PID(0,R0)
329         wrtee   r10
330         msync
331         isync
332         blr
333
334 _GLOBAL(_tlbil_pid_noind)
335         slwi    r4,r3,MAS6_SPID_SHIFT
336         mfmsr   r10
337         ori     r4,r4,MAS6_SIND
338         wrteei  0
339         mtspr   SPRN_MAS6,r4
340         PPC_TLBILX_PID(0,R0)
341         wrtee   r10
342         msync
343         isync
344         blr
345
346 _GLOBAL(_tlbil_all)
347         PPC_TLBILX_ALL(0,R0)
348         msync
349         isync
350         blr
351
352 _GLOBAL(_tlbil_va)
353         mfmsr   r10
354         wrteei  0
355         cmpwi   cr0,r6,0
356         slwi    r4,r4,MAS6_SPID_SHIFT
357         rlwimi  r4,r5,MAS6_ISIZE_SHIFT,MAS6_ISIZE_MASK
358         beq     1f
359         rlwimi  r4,r6,MAS6_SIND_SHIFT,MAS6_SIND
360 1:      mtspr   SPRN_MAS6,r4            /* assume AS=0 for now */
361         PPC_TLBILX_VA(0,R3)
362         msync
363         isync
364         wrtee   r10
365         blr
366
367 _GLOBAL(_tlbivax_bcast)
368         mfmsr   r10
369         wrteei  0
370         cmpwi   cr0,r6,0
371         slwi    r4,r4,MAS6_SPID_SHIFT
372         rlwimi  r4,r5,MAS6_ISIZE_SHIFT,MAS6_ISIZE_MASK
373         beq     1f
374         rlwimi  r4,r6,MAS6_SIND_SHIFT,MAS6_SIND
375 1:      mtspr   SPRN_MAS6,r4            /* assume AS=0 for now */
376         PPC_TLBIVAX(0,R3)
377         eieio
378         tlbsync
379         sync
380         wrtee   r10
381         blr
382
383 _GLOBAL(set_context)
384 #ifdef CONFIG_BDI_SWITCH
385         /* Context switch the PTE pointer for the Abatron BDI2000.
386          * The PGDIR is the second parameter.
387          */
388         lis     r5, abatron_pteptrs@h
389         ori     r5, r5, abatron_pteptrs@l
390         stw     r4, 0x4(r5)
391 #endif
392         mtspr   SPRN_PID,r3
393         isync                   /* Force context change */
394         blr
395 #else
396 #error Unsupported processor type !
397 #endif
398
399 #if defined(CONFIG_PPC_FSL_BOOK3E)
400 /*
401  * extern void loadcam_entry(unsigned int index)
402  *
403  * Load TLBCAM[index] entry in to the L2 CAM MMU
404  * Must preserve r7, r8, r9, and r10
405  */
406 _GLOBAL(loadcam_entry)
407         mflr    r5
408         LOAD_REG_ADDR_PIC(r4, TLBCAM)
409         mtlr    r5
410         mulli   r5,r3,TLBCAM_SIZE
411         add     r3,r5,r4
412         lwz     r4,TLBCAM_MAS0(r3)
413         mtspr   SPRN_MAS0,r4
414         lwz     r4,TLBCAM_MAS1(r3)
415         mtspr   SPRN_MAS1,r4
416         PPC_LL  r4,TLBCAM_MAS2(r3)
417         mtspr   SPRN_MAS2,r4
418         lwz     r4,TLBCAM_MAS3(r3)
419         mtspr   SPRN_MAS3,r4
420 BEGIN_MMU_FTR_SECTION
421         lwz     r4,TLBCAM_MAS7(r3)
422         mtspr   SPRN_MAS7,r4
423 END_MMU_FTR_SECTION_IFSET(MMU_FTR_BIG_PHYS)
424         isync
425         tlbwe
426         isync
427         blr
428
429 /*
430  * Load multiple TLB entries at once, using an alternate-space
431  * trampoline so that we don't have to care about whether the same
432  * TLB entry maps us before and after.
433  *
434  * r3 = first entry to write
435  * r4 = number of entries to write
436  * r5 = temporary tlb entry
437  */
438 _GLOBAL(loadcam_multi)
439         mflr    r8
440
441         /*
442          * Set up temporary TLB entry that is the same as what we're
443          * running from, but in AS=1.
444          */
445         bl      1f
446 1:      mflr    r6
447         tlbsx   0,r8
448         mfspr   r6,SPRN_MAS1
449         ori     r6,r6,MAS1_TS
450         mtspr   SPRN_MAS1,r6
451         mfspr   r6,SPRN_MAS0
452         rlwimi  r6,r5,MAS0_ESEL_SHIFT,MAS0_ESEL_MASK
453         mr      r7,r5
454         mtspr   SPRN_MAS0,r6
455         isync
456         tlbwe
457         isync
458
459         /* Switch to AS=1 */
460         mfmsr   r6
461         ori     r6,r6,MSR_IS|MSR_DS
462         mtmsr   r6
463         isync
464
465         mr      r9,r3
466         add     r10,r3,r4
467 2:      bl      loadcam_entry
468         addi    r9,r9,1
469         cmpw    r9,r10
470         mr      r3,r9
471         blt     2b
472
473         /* Return to AS=0 and clear the temporary entry */
474         mfmsr   r6
475         rlwinm. r6,r6,0,~(MSR_IS|MSR_DS)
476         mtmsr   r6
477         isync
478
479         li      r6,0
480         mtspr   SPRN_MAS1,r6
481         rlwinm  r6,r7,MAS0_ESEL_SHIFT,MAS0_ESEL_MASK
482         oris    r6,r6,MAS0_TLBSEL(1)@h
483         mtspr   SPRN_MAS0,r6
484         isync
485         tlbwe
486         isync
487
488         mtlr    r8
489         blr
490 #endif