4 #include <ppc_asm.tmpl>
10 #ifndef CACHE_LINE_SIZE
11 # define CACHE_LINE_SIZE L1_CACHE_BYTES
14 #if CACHE_LINE_SIZE == 128
15 #define LG_CACHE_LINE_SIZE 7
16 #elif CACHE_LINE_SIZE == 32
17 #define LG_CACHE_LINE_SIZE 5
18 #elif CACHE_LINE_SIZE == 16
19 #define LG_CACHE_LINE_SIZE 4
20 #elif CACHE_LINE_SIZE == 8
21 #define LG_CACHE_LINE_SIZE 3
23 # error "Invalid cache line size!"
27 * Most of this code is taken from 74xx_7xx/cache.S
28 * and then cleaned up a bit
32 * Invalidate L1 instruction cache.
34 _GLOBAL(invalidate_l1_instruction_cache)
35 /* use invalidate-all bit in HID0 */
43 * Invalidate L1 data cache.
45 _GLOBAL(invalidate_l1_data_cache)
57 lis r5,CACHE_LINE_SIZE
62 lis r5,CACHE_LINE_SIZE
68 * Write any modified data cache blocks out to memory
69 * and invalidate the corresponding instruction cache blocks.
70 * This is a no-op on the 601.
72 * flush_icache_range(unsigned long start, unsigned long stop)
74 _GLOBAL(flush_icache_range)
75 li r5,CACHE_LINE_SIZE-1
79 srwi. r4,r4,LG_CACHE_LINE_SIZE
84 addi r3,r3,CACHE_LINE_SIZE
86 sync /* wait for dcbst's to get to ram */
89 addi r6,r6,CACHE_LINE_SIZE
91 sync /* additional sync needed on g4 */
95 * Write any modified data cache blocks out to memory.
96 * Does not invalidate the corresponding cache lines (especially for
97 * any corresponding instruction cache).
99 * clean_dcache_range(unsigned long start, unsigned long stop)
101 _GLOBAL(clean_dcache_range)
102 li r5,CACHE_LINE_SIZE-1
103 andc r3,r3,r5 /* align r3 down to cache line */
104 subf r4,r3,r4 /* r4 = offset of stop from start of cache line */
105 add r4,r4,r5 /* r4 += cache_line_size-1 */
106 srwi. r4,r4,LG_CACHE_LINE_SIZE /* r4 = number of cache lines to flush */
107 beqlr /* if r4 == 0 return */
108 mtctr r4 /* ctr = r4 */
112 addi r3,r3,CACHE_LINE_SIZE
114 sync /* wait for dcbst's to get to ram */
118 * Flush a particular page from the data cache to RAM.
119 * Note: this is necessary because the instruction cache does *not*
120 * snoop from the data cache.
122 * void __flush_page_to_ram(void *page)
124 _GLOBAL(__flush_page_to_ram)
125 rlwinm r3,r3,0,0,19 /* Get page base address */
126 li r4,4096/CACHE_LINE_SIZE /* Number of lines in a page */
129 0: dcbst 0,r3 /* Write line to ram */
130 addi r3,r3,CACHE_LINE_SIZE
135 addi r6,r6,CACHE_LINE_SIZE
142 * Flush a particular page from the instruction cache.
143 * Note: this is necessary because the instruction cache does *not*
144 * snoop from the data cache.
146 * void __flush_icache_page(void *page)
148 _GLOBAL(__flush_icache_page)
149 li r4,4096/CACHE_LINE_SIZE /* Number of lines in a page */
152 addi r3,r3,CACHE_LINE_SIZE
159 * Clear a page using the dcbz instruction, which doesn't cause any
160 * memory traffic (except to write out any cache lines which get
161 * displaced). This only works on cacheable memory.
164 li r0,4096/CACHE_LINE_SIZE
167 addi r3,r3,CACHE_LINE_SIZE
172 * Enable L1 Instruction cache
174 _GLOBAL(icache_enable)
176 li r5, HID0_ICFI|HID0_ILOCK
179 ori r5, r3, HID0_ICFI
186 * Disable L1 Instruction cache
188 _GLOBAL(icache_disable)
190 bl invalidate_l1_instruction_cache /* uses r3 */
202 * Is instruction cache enabled?
204 _GLOBAL(icache_status)
206 andi. r3, r3, HID0_ICE
210 _GLOBAL(l1dcache_enable)
212 li r5, HID0_DCFI|HID0_DLOCK
214 mtspr HID0, r3 /* no invalidate, unlock */
216 ori r5, r3, HID0_DCFI
217 mtspr HID0, r5 /* enable + invalidate */
218 mtspr HID0, r3 /* enable */
223 * Enable data cache(s) - L1 and optionally L2
224 * Calls l2cache_enable. LR saved in r5
226 _GLOBAL(dcache_enable)
228 li r5, HID0_DCFI|HID0_DLOCK
230 mtspr HID0, r3 /* no invalidate, unlock */
232 ori r5, r3, HID0_DCFI
233 mtspr HID0, r5 /* enable + invalidate */
234 mtspr HID0, r3 /* enable */
238 bl l2cache_enable /* uses r3 and r4 */
246 * Disable data cache(s) - L1 and optionally L2
247 * Calls flush_dcache and l2cache_disable_no_flush.
250 _GLOBAL(dcache_disable)
251 mflr r4 /* save link register */
252 bl flush_dcache /* uses r3 and r5 */
255 li r5, HID0_DCFI|HID0_DLOCK
257 mtspr HID0, r3 /* no invalidate, unlock */
258 li r5, HID0_DCE|HID0_DCFI
259 andc r3, r3, r5 /* no enable, no invalidate */
263 bl l2cache_disable_no_flush /* uses r3 */
265 mtlr r4 /* restore link register */
269 * Is data cache enabled?
271 _GLOBAL(dcache_status)
273 andi. r3, r3, HID0_DCE
277 * Invalidate L2 cache using L2I, assume L2 is enabled
279 _GLOBAL(l2cache_invalidate)
281 rlwinm. r3, r3, 0, 0, 0
285 rlwinm r3, r3, 0, 1, 31
287 #ifdef CONFIG_ALTIVEC
294 oris r3, r3, L2CR_L2I@h
299 andis. r3, r3, L2CR_L2I@h
305 * Calls l2cache_invalidate. LR is saved in r4
307 _GLOBAL(l2cache_enable)
308 mflr r4 /* save link register */
309 bl l2cache_invalidate /* uses r3 */
312 ori r3, r3, L2_ENABLE@l
315 mtlr r4 /* restore link register */
320 * Calls flush_dcache. LR is saved in r4
322 _GLOBAL(l2cache_disable)
323 mflr r4 /* save link register */
324 bl flush_dcache /* uses r3 and r5 */
326 mtlr r4 /* restore link register */
327 l2cache_disable_no_flush: /* provide way to disable L2 w/o flushing */
329 ori r3, r3, L2_INIT@l