3 Copyright © 1997-1998 by PowerLogix R & D, Inc.
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 - First public release, contributed by PowerLogix.
24 - Terry: Made sure code disabled interrupts before running. (Previously
25 it was assumed interrupts were already disabled).
26 - Terry: Updated for tentative G4 support. 4MB of memory is now flushed
27 instead of 2MB. (Prob. only 3 is necessary).
28 - Terry: Updated for workaround to HID0[DPM] processor bug
29 during global invalidates.
32 - Terry: Added isync to correct for an errata.
35 - DanM: Finally added the 7450 patch I've had for the past
36 several months. The L2CR is similar, but I'm going
37 to assume the user of this functions knows what they
40 Author: Terry Greeniaus (tgree@phys.ualberta.ca)
41 Please e-mail updates to this file to me, thanks!
43 #include <linux/config.h>
44 #include <asm/processor.h>
45 #include <asm/cputable.h>
46 #include <asm/ppc_asm.h>
47 #include <asm/cache.h>
52 When setting the L2CR register, you must do a few special
53 things. If you are enabling the cache, you must perform a
54 global invalidate. If you are disabling the cache, you must
55 flush the cache contents first. This routine takes care of
56 doing these things. When first enabling the cache, make sure
57 you pass in the L2CR you want, as well as passing in the
58 global invalidate bit set. A global invalidate will only be
59 performed if the L2I bit is set in applyThis. When enabling
60 the cache, you should also set the L2E bit in applyThis. If
61 you want to modify the L2CR contents after the cache has been
62 enabled, the recommended procedure is to first call
63 __setL2CR(0) to disable the cache and then call it again with
64 the new values for L2CR. Examples:
66 _setL2CR(0) - disables the cache
67 _setL2CR(0xB3A04000) - enables my G3 upgrade card:
68 - L2E set to turn on the cache
71 - L2RAM set to pipelined synchronous late-write
72 - L2I set to perform a global invalidation
74 - L2DF set because this upgrade card
77 A similar call should work for your card. You need to know
78 the correct setting for your card and then place them in the
79 fields I have outlined above. Other fields support optional
80 features, such as L2DO which caches only data, or L2TS which
81 causes cache pushes from the L1 cache to go to the L2 cache
82 instead of to main memory.
85 Starting with the 7450, the bits in this register have moved
86 or behave differently. The Enable, Parity Enable, Size,
87 and L2 Invalidate are the only bits that have not moved.
88 The size is read-only for these processors with internal L2
89 cache, and the invalidate is a control as well as status.
94 * Summary: this procedure ignores the L2I bit in the value passed in,
95 * flushes the cache if it was already enabled, always invalidates the
96 * cache, then enables the cache if the L2E bit is set in the value
101 /* Make sure this is a 750 or 7400 chip */
105 END_FTR_SECTION_IFCLR(CPU_FTR_L2CR)
109 /* Stop DST streams */
113 END_FTR_SECTION_IFSET(CPU_FTR_ALTIVEC)
115 /* Turn off interrupts and data relocation. */
116 mfmsr r7 /* Save MSR in r7 */
118 rlwinm r4,r4,0,28,26 /* Turn off DR bit */
123 /* Before we perform the global invalidation, we must disable dynamic
124 * power management via HID0[DPM] to work around a processor bug where
125 * DPM can possibly interfere with the state machine in the processor
126 * that invalidates the L2 cache tags.
128 mfspr r8,SPRN_HID0 /* Save HID0 in r8 */
129 rlwinm r4,r8,0,12,10 /* Turn off HID0[DPM] */
131 mtspr SPRN_HID0,r4 /* Disable DPM */
134 /* Get the current enable bit of the L2CR into r4 */
137 /* Tweak some bits */
138 rlwinm r5,r3,0,0,0 /* r5 contains the new enable bit */
139 rlwinm r3,r3,0,11,9 /* Turn off the invalidate bit */
140 rlwinm r3,r3,0,1,31 /* Turn off the enable bit */
142 /* Check to see if we need to flush */
146 /* Flush the cache. First, read the first 4MB of memory (physical) to
147 * put new data in the cache. (Actually we only need
148 * the size of the L2 cache plus the size of the L1 cache, but 4MB will
149 * cover everything just to be safe).
152 /**** Might be a good idea to set L2DO here - to prevent instructions
153 from getting into the cache. But since we invalidate
154 the next time we enable the cache it doesn't really matter.
155 Don't do this unless you accomodate all processor variations.
156 The bit moved on the 7450.....
159 /* TODO: use HW flush assist when available */
166 addi r4,r4,32 /* Go to start of next cache line */
170 /* Now, flush the first 4MB of memory */
177 addi r4,r4,32 /* Go to start of next cache line */
181 /* Set up the L2CR configuration bits (and switch L2 off) */
182 /* CPU errata: Make sure the mtspr below is already in the
186 .balign L1_CACHE_LINE_SIZE
199 /* Perform a global invalidation */
204 isync /* For errata */
207 /* On the 7450, we wait for the L2I bit to clear......
209 10: mfspr r3,SPRN_L2CR
213 END_FTR_SECTION_IFSET(CPU_FTR_SPEC7450)
215 /* Wait for the invalidation to complete */
216 3: mfspr r3,SPRN_L2CR
217 rlwinm. r4,r3,0,31,31
220 11: rlwinm r3,r3,0,11,9 /* Turn off the L2I bit */
225 /* See if we need to enable the cache */
229 /* Enable the cache */
236 /* Restore HID0[DPM] to whatever it was before */
241 /* Restore MSR (restores EE and DR bits to original state) */
250 /* Return the L2CR contents */
254 END_FTR_SECTION_IFSET(CPU_FTR_L2CR)
259 * Here is a similar routine for dealing with the L3 cache
260 * on the 745x family of chips
264 /* Make sure this is a 745x chip */
268 END_FTR_SECTION_IFCLR(CPU_FTR_L3CR)
270 /* Turn off interrupts and data relocation. */
271 mfmsr r7 /* Save MSR in r7 */
273 rlwinm r4,r4,0,28,26 /* Turn off DR bit */
278 /* Stop DST streams */
282 /* Get the current enable bit of the L3CR into r4 */
285 /* Tweak some bits */
286 rlwinm r5,r3,0,0,0 /* r5 contains the new enable bit */
287 rlwinm r3,r3,0,22,20 /* Turn off the invalidate bit */
288 rlwinm r3,r3,0,2,31 /* Turn off the enable & PE bits */
289 rlwinm r3,r3,0,5,3 /* Turn off the clken bit */
290 /* Check to see if we need to flush */
297 /* TODO: use HW flush assist */
305 addi r4,r4,32 /* Go to start of next cache line */
309 /* Set up the L3CR configuration bits (and switch L3 off) */
314 oris r3,r3,L3CR_L3RES@h /* Set reserved bit 5 */
317 oris r3,r3,L3CR_L3CLKEN@h /* Set clken */
321 /* Wait for stabilize */
326 /* Perform a global invalidation */
333 /* We wait for the L3I bit to clear...... */
334 10: mfspr r3,SPRN_L3CR
339 rlwinm r3,r3,0,5,3 /* Turn off the clken bit */
343 /* Wait for stabilize */
348 /* See if we need to enable the cache */
352 /* Enable the cache */
353 oris r3,r3,(L3CR_L3E | L3CR_L3CLKEN)@h
357 /* Wait for stabilize */
362 /* Restore MSR (restores EE and DR bits to original state) */
369 /* Return the L3CR contents */
373 END_FTR_SECTION_IFSET(CPU_FTR_L3CR)
376 /* --- End of PowerLogix code ---
380 /* flush_disable_L1() - Flush and disable L1 cache
382 * clobbers r0, r3, ctr, cr0
383 * Must be called with interrupts disabled and MMU enabled.
385 _GLOBAL(__flush_disable_L1)
386 /* Stop pending alitvec streams and memory accesses */
389 END_FTR_SECTION_IFSET(CPU_FTR_ALTIVEC)
392 /* Load counter to 0x4000 cache lines (512k) and
393 * load cache with datas
395 li r3,0x4000 /* 512kB / 32B */
400 addi r3,r3,0x0020 /* Go to start of next cache line */
405 /* Now flush those cache lines */
406 li r3,0x4000 /* 512kB / 32B */
411 addi r3,r3,0x0020 /* Go to start of next cache line */
415 /* We can now disable the L1 cache (HID0:DCE, HID0:ICE) */
423 /* inval_enable_L1 - Invalidate and enable L1 cache
425 * Assumes L1 is already disabled and MSR:EE is off
429 _GLOBAL(__inval_enable_L1)
430 /* Enable and then Flash inval the instruction & data cache */
432 ori r3,r3, HID0_ICE|HID0_ICFI|HID0_DCE|HID0_DCI
436 xori r3,r3, HID0_ICFI|HID0_DCI