2 * This file contains low-level cache management functions
3 * used for sleep and CPU speed changes on Apple machines.
4 * (In fact the only thing that is Apple-specific is that we assume
5 * that we can read from ROM at physical address 0xfff00000.)
7 * Copyright (C) 2004 Paul Mackerras (paulus@samba.org) and
8 * Benjamin Herrenschmidt (benh@kernel.crashing.org)
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License
12 * as published by the Free Software Foundation; either version
13 * 2 of the License, or (at your option) any later version.
17 #include <linux/config.h>
18 #include <asm/processor.h>
19 #include <asm/ppc_asm.h>
20 #include <asm/cputable.h>
23 * Flush and disable all data caches (dL1, L2, L3). This is used
24 * when going to sleep, when doing a PMU based cpufreq transition,
25 * or when "offlining" a CPU on SMP machines. This code is over
26 * paranoid, but I've had enough issues with various CPU revs and
27 * bugs that I decided it was worth beeing over cautious
30 _GLOBAL(flush_disable_caches)
36 END_FTR_SECTION_IFSET(CPU_FTR_SPEC7450)
39 END_FTR_SECTION_IFSET(CPU_FTR_L2CR)
42 /* This is the code for G3 and 74[01]0 */
46 /* Turn off EE and DR in MSR */
48 rlwinm r0,r11,0,~MSR_EE
49 rlwinm r0,r0,0,~MSR_DR
54 /* Stop DST streams */
58 END_FTR_SECTION_IFSET(CPU_FTR_ALTIVEC)
61 mfspr r8,SPRN_HID0 /* Save SPRN_HID0 in r8 */
62 rlwinm r4,r8,0,12,10 /* Turn off HID0[DPM] */
64 mtspr SPRN_HID0,r4 /* Disable DPM */
77 /* disable / invalidate / enable L1 data */
79 rlwinm r0,r0,0,~HID0_DCE
83 ori r3,r3,HID0_DCE|HID0_DCI
91 /* Get the current enable bit of the L2CR into r4 */
93 /* Set to data-only (pre-745x bit) */
94 oris r3,r5,L2CR_L2DO@h
96 /* When disabling L2, code must be in L1 */
106 1: /* disp-flush L2. The interesting thing here is that the L2 can be
107 * up to 2Mb ... so using the ROM, we'll end up wrapping back to memory
108 * but that is probbaly fine. We disp-flush over 4Mb to be safe
119 rlwinm r5,r5,0,~L2CR_L2E
121 /* When disabling L2, code must be in L1 */
123 1: mtspr SPRN_L2CR,r5
133 /* Invalidate L2. This is pre-745x, we clear the L2I bit ourselves */
134 oris r4,r5,L2CR_L2I@h
138 xoris r4,r4,L2CR_L2I@h
143 /* now disable the L1 data cache */
145 rlwinm r0,r0,0,~HID0_DCE
150 /* Restore HID0[DPM] to whatever it was before */
155 /* restore DR and EE */
163 /* This code is for 745x processors */
165 /* Turn off EE and DR in MSR */
167 rlwinm r0,r11,0,~MSR_EE
168 rlwinm r0,r0,0,~MSR_DR
173 /* Stop prefetch streams */
177 /* Disable L2 prefetching */
193 /* Due to a bug with the HW flush on some CPU revs, we occasionally
194 * experience data corruption. I'm adding a displacement flush along
195 * with a dcbf loop over a few Mb to "help". The problem isn't totally
196 * fixed by this in theory, but at least, in practice, I couldn't reproduce
197 * it even with a big hammer...
205 addi r4,r4,32 /* Go to start of next cache line */
209 /* Now, flush the first 4MB of memory */
216 addi r4,r4,32 /* Go to start of next cache line */
219 /* Flush and disable the L1 data cache */
221 lis r3,0xfff0 /* read from ROM for displacement flush */
222 li r4,0xfe /* start with only way 0 unlocked */
223 li r5,128 /* 128 lines in each way */
229 2: lwz r0,0(r3) /* touch each cache line */
232 rlwinm r4,r4,1,24,30 /* move on to the next way */
234 cmpwi r4,0xff /* all done? */
236 /* now unlock the L1 data cache */
244 /* Flush the L2 cache using the hardware assist */
246 cmpwi r3,0 /* check if it is enabled first */
248 oris r0,r3,(L2CR_L2IO_745x|L2CR_L2DO_745x)@h
250 /* When disabling/locking L2, code must be in L1 */
252 1: mtspr SPRN_L2CR,r0 /* lock the L2 cache */
262 ori r0,r3,L2CR_L2HWF_745x
264 mtspr SPRN_L2CR,r0 /* set the hardware flush bit */
265 3: mfspr r0,SPRN_L2CR /* wait for it to go to 0 */
266 andi. r0,r0,L2CR_L2HWF_745x
269 rlwinm r3,r3,0,~L2CR_L2E
271 /* When disabling L2, code must be in L1 */
273 1: mtspr SPRN_L2CR,r3 /* disable the L2 cache */
283 oris r4,r3,L2CR_L2I@h
287 1: mfspr r4,SPRN_L2CR
288 andis. r0,r4,L2CR_L2I@h
293 /* Flush the L3 cache using the hardware assist */
294 4: mfspr r3,SPRN_L3CR
295 cmpwi r3,0 /* check if it is enabled */
297 oris r0,r3,L3CR_L3IO@h
300 mtspr SPRN_L3CR,r0 /* lock the L3 cache */
305 mtspr SPRN_L3CR,r0 /* set the hardware flush bit */
306 5: mfspr r0,SPRN_L3CR /* wait for it to go to zero */
307 andi. r0,r0,L3CR_L3HWF
309 rlwinm r3,r3,0,~L3CR_L3E
311 mtspr SPRN_L3CR,r3 /* disable the L3 cache */
315 1: mfspr r4,SPRN_L3CR
319 END_FTR_SECTION_IFSET(CPU_FTR_L3CR)
321 6: mfspr r0,SPRN_HID0 /* now disable the L1 data cache */
322 rlwinm r0,r0,0,~HID0_DCE
326 mtmsr r11 /* restore DR and EE */
329 #endif /* CONFIG_6xx */