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 <asm/processor.h>
18 #include <asm/ppc_asm.h>
19 #include <asm/cputable.h>
22 * Flush and disable all data caches (dL1, L2, L3). This is used
23 * when going to sleep, when doing a PMU based cpufreq transition,
24 * or when "offlining" a CPU on SMP machines. This code is over
25 * paranoid, but I've had enough issues with various CPU revs and
26 * bugs that I decided it was worth beeing over cautious
29 _GLOBAL(flush_disable_caches)
35 END_FTR_SECTION_IFSET(CPU_FTR_SPEC7450)
38 END_FTR_SECTION_IFSET(CPU_FTR_L2CR)
41 /* This is the code for G3 and 74[01]0 */
45 /* Turn off EE and DR in MSR */
47 rlwinm r0,r11,0,~MSR_EE
48 rlwinm r0,r0,0,~MSR_DR
53 /* Stop DST streams */
57 END_FTR_SECTION_IFSET(CPU_FTR_ALTIVEC)
60 mfspr r8,SPRN_HID0 /* Save SPRN_HID0 in r8 */
61 rlwinm r4,r8,0,12,10 /* Turn off HID0[DPM] */
63 mtspr SPRN_HID0,r4 /* Disable DPM */
66 /* Disp-flush L1. We have a weird problem here that I never
67 * totally figured out. On 750FX, using the ROM for the flush
68 * results in a non-working flush. We use that workaround for
69 * now until I finally understand what's going on. --BenH
72 /* ROM base by default */
78 /* RAM base on 750FX */
88 /* Disable / invalidate / enable L1 data */
90 rlwinm r3,r3,0,~(HID0_DCE | HID0_ICE)
94 ori r3,r3,(HID0_DCE|HID0_DCI|HID0_ICE|HID0_ICFI)
98 xori r3,r3,(HID0_DCI|HID0_ICFI)
102 /* Get the current enable bit of the L2CR into r4 */
104 /* Set to data-only (pre-745x bit) */
105 oris r3,r5,L2CR_L2DO@h
107 /* When disabling L2, code must be in L1 */
109 1: mtspr SPRN_L2CR,r3
117 1: /* disp-flush L2. The interesting thing here is that the L2 can be
118 * up to 2Mb ... so using the ROM, we'll end up wrapping back to memory
119 * but that is probbaly fine. We disp-flush over 4Mb to be safe
139 rlwinm r5,r5,0,~L2CR_L2E
141 /* When disabling L2, code must be in L1 */
143 1: mtspr SPRN_L2CR,r5
153 /* Invalidate L2. This is pre-745x, we clear the L2I bit ourselves */
154 oris r4,r5,L2CR_L2I@h
159 /* Wait for the invalidation to complete */
160 1: mfspr r3,SPRN_L2CR
161 rlwinm. r0,r3,0,31,31
165 xoris r4,r4,L2CR_L2I@h
170 /* now disable the L1 data cache */
172 rlwinm r0,r0,0,~(HID0_DCE|HID0_ICE)
177 /* Restore HID0[DPM] to whatever it was before */
180 rlwimi r0,r8,0,11,11 /* Turn back HID0[DPM] */
184 /* restore DR and EE */
192 /* This code is for 745x processors */
194 /* Turn off EE and DR in MSR */
196 rlwinm r0,r11,0,~MSR_EE
197 rlwinm r0,r0,0,~MSR_DR
202 /* Stop prefetch streams */
206 /* Disable L2 prefetching */
222 /* Due to a bug with the HW flush on some CPU revs, we occasionally
223 * experience data corruption. I'm adding a displacement flush along
224 * with a dcbf loop over a few Mb to "help". The problem isn't totally
225 * fixed by this in theory, but at least, in practice, I couldn't reproduce
226 * it even with a big hammer...
234 addi r4,r4,32 /* Go to start of next cache line */
238 /* Now, flush the first 4MB of memory */
245 addi r4,r4,32 /* Go to start of next cache line */
248 /* Flush and disable the L1 data cache */
250 lis r3,0xfff0 /* read from ROM for displacement flush */
251 li r4,0xfe /* start with only way 0 unlocked */
252 li r5,128 /* 128 lines in each way */
258 2: lwz r0,0(r3) /* touch each cache line */
261 rlwinm r4,r4,1,24,30 /* move on to the next way */
263 cmpwi r4,0xff /* all done? */
265 /* now unlock the L1 data cache */
273 /* Flush the L2 cache using the hardware assist */
275 cmpwi r3,0 /* check if it is enabled first */
277 oris r0,r3,(L2CR_L2IO_745x|L2CR_L2DO_745x)@h
279 /* When disabling/locking L2, code must be in L1 */
281 1: mtspr SPRN_L2CR,r0 /* lock the L2 cache */
291 ori r0,r3,L2CR_L2HWF_745x
293 mtspr SPRN_L2CR,r0 /* set the hardware flush bit */
294 3: mfspr r0,SPRN_L2CR /* wait for it to go to 0 */
295 andi. r0,r0,L2CR_L2HWF_745x
298 rlwinm r3,r3,0,~L2CR_L2E
300 /* When disabling L2, code must be in L1 */
302 1: mtspr SPRN_L2CR,r3 /* disable the L2 cache */
312 oris r4,r3,L2CR_L2I@h
316 1: mfspr r4,SPRN_L2CR
317 andis. r0,r4,L2CR_L2I@h
322 /* Flush the L3 cache using the hardware assist */
323 4: mfspr r3,SPRN_L3CR
324 cmpwi r3,0 /* check if it is enabled */
326 oris r0,r3,L3CR_L3IO@h
329 mtspr SPRN_L3CR,r0 /* lock the L3 cache */
334 mtspr SPRN_L3CR,r0 /* set the hardware flush bit */
335 5: mfspr r0,SPRN_L3CR /* wait for it to go to zero */
336 andi. r0,r0,L3CR_L3HWF
338 rlwinm r3,r3,0,~L3CR_L3E
340 mtspr SPRN_L3CR,r3 /* disable the L3 cache */
344 1: mfspr r4,SPRN_L3CR
348 END_FTR_SECTION_IFSET(CPU_FTR_L3CR)
350 6: mfspr r0,SPRN_HID0 /* now disable the L1 data cache */
351 rlwinm r0,r0,0,~HID0_DCE
355 mtmsr r11 /* restore DR and EE */
358 #endif /* CONFIG_6xx */