1 /* SPDX-License-Identifier: GPL-2.0-or-later */
3 * This file contains low-level functions for performing various
4 * types of TLB invalidations on various processors with no hash
7 * This file implements the following functions for all no-hash
8 * processors. Some aren't implemented for some variants. Some
9 * are inline in tlbflush.h
16 * Code mostly moved over from misc_32.S
18 * Copyright (C) 1995-1996 Gary Thomas (gdt@linuxppc.org)
20 * Partially rewritten by Cort Dougan (cort@cs.nmt.edu)
21 * Paul Mackerras, Kumar Gala and Benjamin Herrenschmidt.
26 #include <asm/cputable.h>
28 #include <asm/ppc_asm.h>
29 #include <asm/asm-offsets.h>
30 #include <asm/processor.h>
32 #include <asm/asm-compat.h>
33 #include <asm/feature-fixups.h>
35 #if defined(CONFIG_40x)
38 * 40x implementation needs only tlbil_va
41 /* We run the search with interrupts disabled because we have to change
42 * the PID and I don't want to preempt when that happens.
53 /* There are only 64 TLB entries, so r3 < 64, which means bit 25 is
54 * clear. Since 25 is the V bit in the TLB_TAG, loading this value
55 * will invalidate the TLB entry. */
60 #elif defined(CONFIG_PPC_8xx)
63 * Nothing to do for 8xx, everything is inline
66 #elif defined(CONFIG_44x) /* Includes 47x */
69 * 440 implementation uses tlbsx/we for tlbil_va and a full sweep
70 * of the TLB for everything else.
77 * We write 16 bits of STID since 47x supports that much, we
78 * will never be passed out of bounds values on 440 (hopefully)
82 /* We have to run the search with interrupts disabled, otherwise
83 * an interrupt which causes a TLB miss can clobber the MMUCR
84 * between the mtspr and the tlbsx.
86 * Critical and Machine Check interrupts take care of saving
87 * and restoring MMUCR, so only normal interrupts have to be
95 #ifndef CONFIG_PPC_47x
96 /* On 440 There are only 64 TLB entries, so r3 < 64, which means bit
97 * 22, is clear. Since 22 is the V bit in the TLB_PAGEID, loading this
98 * value will invalidate the TLB entry.
100 tlbwe r6,r6,PPC44x_TLB_PAGEID
102 oris r7,r6,0x8000 /* specify way explicitly */
103 clrrwi r4,r3,12 /* get an EPN for the hashing with V = 0 */
104 ori r4,r4,PPC47x_TLBE_SIZE
105 tlbwe r4,r7,0 /* write it */
106 #endif /* !CONFIG_PPC_47x */
113 #ifndef CONFIG_PPC_47x
117 /* Load high watermark */
118 lis r4,tlb_44x_hwater@ha
119 lwz r5,tlb_44x_hwater@l(r4)
121 1: tlbwe r3,r3,PPC44x_TLB_PAGEID
129 /* 476 variant. There's not simple way to do this, hopefully we'll
130 * try to limit the amount of such full invalidates
132 mfmsr r11 /* Interrupts off */
134 li r3,-1 /* Current set */
135 lis r10,tlb_47x_boltmap@h
136 ori r10,r10,tlb_47x_boltmap@l
137 lis r7,0x8000 /* Specify way explicitly */
139 b 9f /* For each set */
141 1: li r9,4 /* Number of ways */
142 li r4,0 /* Current way */
143 li r6,0 /* Default entry value 0 */
144 andi. r0,r8,1 /* Check if way 0 is bolted */
145 mtctr r9 /* Load way counter */
146 bne- 3f /* Bolted, skip loading it */
148 2: /* For each way */
149 or r5,r3,r4 /* Make way|index for tlbre */
150 rlwimi r5,r5,16,8,15 /* Copy index into position */
151 tlbre r6,r5,0 /* Read entry */
152 3: addis r4,r4,0x2000 /* Next way */
153 andi. r0,r6,PPC47x_TLB0_VALID /* Valid entry ? */
154 beq 4f /* Nope, skip it */
155 rlwimi r7,r5,0,1,2 /* Insert way number */
156 rlwinm r6,r6,0,21,19 /* Clear V */
157 tlbwe r6,r7,0 /* Write it */
158 4: bdnz 2b /* Loop for each way */
159 srwi r8,r8,1 /* Next boltmap bit */
160 9: cmpwi cr1,r3,255 /* Last set done ? */
161 addi r3,r3,1 /* Next set */
162 beq cr1,1f /* End of loop */
163 andi. r0,r3,0x1f /* Need to load a new boltmap word ? */
164 bne 1b /* No, loop */
165 lwz r8,0(r10) /* Load boltmap entry */
166 addi r10,r10,4 /* Next word */
168 1: isync /* Sync shadows */
171 #endif /* !CONFIG_PPC_47x */
173 #ifdef CONFIG_PPC_47x
176 * _tlbivax_bcast is only on 47x. We don't bother doing a runtime
177 * check though, it will blow up soon enough if we mistakenly try
178 * to use it on a 440.
180 _GLOBAL(_tlbivax_bcast)
193 END_FTR_SECTION_IFSET(CPU_FTR_476_DD2)
198 * DD2 HW could hang if in instruction fetch happens before msync completes.
199 * Touch enough instruction cache lines to ensure cache hits
205 PPC_ICBT(0,R6,R7) /* touch next cache line */
207 PPC_ICBT(0,R6,R7) /* touch next cache line */
209 PPC_ICBT(0,R6,R7) /* touch next cache line */
222 #endif /* CONFIG_PPC_47x */
224 #elif defined(CONFIG_FSL_BOOKE)
226 * FSL BookE implementations.
228 * Since feature sections are using _SECTION_ELSE we need
229 * to have the larger code path before the _SECTION_ELSE
233 * Flush MMU TLB on the local processor
236 BEGIN_MMU_FTR_SECTION
237 li r3,(MMUCSR0_TLBFI)@l
238 mtspr SPRN_MMUCSR0, r3
240 mfspr r3,SPRN_MMUCSR0
241 andi. r3,r3,MMUCSR0_TLBFI@l
245 ALT_MMU_FTR_SECTION_END_IFCLR(MMU_FTR_USE_TLBILX)
251 BEGIN_MMU_FTR_SECTION
255 mfspr r4,SPRN_MAS6 /* save MAS6 */
258 mtspr SPRN_MAS6,r4 /* restore MAS6 */
261 li r3,(MMUCSR0_TLBFI)@l
262 mtspr SPRN_MMUCSR0, r3
264 mfspr r3,SPRN_MMUCSR0
265 andi. r3,r3,MMUCSR0_TLBFI@l
267 ALT_MMU_FTR_SECTION_END_IFSET(MMU_FTR_USE_TLBILX)
273 * Flush MMU TLB for a particular address, but only on the local processor
280 ori r4,r4,(MAS6_ISIZE(BOOK3E_PAGESZ_4K))@l
281 mtspr SPRN_MAS6,r4 /* assume AS=0 for now */
282 BEGIN_MMU_FTR_SECTION
284 mfspr r4,SPRN_MAS1 /* check valid */
285 andis. r3,r4,MAS1_VALID@h
292 ALT_MMU_FTR_SECTION_END_IFCLR(MMU_FTR_USE_TLBILX)
297 #elif defined(CONFIG_PPC_BOOK3E)
299 * New Book3E (>= 2.06) implementation
301 * Note: We may be able to get away without the interrupt masking stuff
302 * if we save/restore MAS6 on exceptions that might modify it
305 slwi r4,r3,MAS6_SPID_SHIFT
315 _GLOBAL(_tlbil_pid_noind)
316 slwi r4,r3,MAS6_SPID_SHIFT
337 slwi r4,r4,MAS6_SPID_SHIFT
338 rlwimi r4,r5,MAS6_ISIZE_SHIFT,MAS6_ISIZE_MASK
340 rlwimi r4,r6,MAS6_SIND_SHIFT,MAS6_SIND
341 1: mtspr SPRN_MAS6,r4 /* assume AS=0 for now */
348 _GLOBAL(_tlbivax_bcast)
352 slwi r4,r4,MAS6_SPID_SHIFT
353 rlwimi r4,r5,MAS6_ISIZE_SHIFT,MAS6_ISIZE_MASK
355 rlwimi r4,r6,MAS6_SIND_SHIFT,MAS6_SIND
356 1: mtspr SPRN_MAS6,r4 /* assume AS=0 for now */
365 #ifdef CONFIG_BDI_SWITCH
366 /* Context switch the PTE pointer for the Abatron BDI2000.
367 * The PGDIR is the second parameter.
369 lis r5, abatron_pteptrs@h
370 ori r5, r5, abatron_pteptrs@l
374 isync /* Force context change */
377 #error Unsupported processor type !
380 #if defined(CONFIG_PPC_FSL_BOOK3E)
382 * extern void loadcam_entry(unsigned int index)
384 * Load TLBCAM[index] entry in to the L2 CAM MMU
385 * Must preserve r7, r8, r9, r10 and r11
387 _GLOBAL(loadcam_entry)
389 LOAD_REG_ADDR_PIC(r4, TLBCAM)
391 mulli r5,r3,TLBCAM_SIZE
393 lwz r4,TLBCAM_MAS0(r3)
395 lwz r4,TLBCAM_MAS1(r3)
397 PPC_LL r4,TLBCAM_MAS2(r3)
399 lwz r4,TLBCAM_MAS3(r3)
401 BEGIN_MMU_FTR_SECTION
402 lwz r4,TLBCAM_MAS7(r3)
404 END_MMU_FTR_SECTION_IFSET(MMU_FTR_BIG_PHYS)
411 * Load multiple TLB entries at once, using an alternate-space
412 * trampoline so that we don't have to care about whether the same
413 * TLB entry maps us before and after.
415 * r3 = first entry to write
416 * r4 = number of entries to write
417 * r5 = temporary tlb entry
419 _GLOBAL(loadcam_multi)
421 /* Don't switch to AS=1 if already there */
427 * Set up temporary TLB entry that is the same as what we're
428 * running from, but in AS=1.
437 rlwimi r6,r5,MAS0_ESEL_SHIFT,MAS0_ESEL_MASK
446 ori r6,r6,MSR_IS|MSR_DS
459 /* Don't return to AS=0 if we were in AS=1 at function start */
463 /* Return to AS=0 and clear the temporary entry */
465 rlwinm. r6,r6,0,~(MSR_IS|MSR_DS)
471 rlwinm r6,r7,MAS0_ESEL_SHIFT,MAS0_ESEL_MASK
472 oris r6,r6,MAS0_TLBSEL(1)@h