2 * This file contains miscellaneous low-level functions.
3 * Copyright (C) 1995-1996 Gary Thomas (gdt@linuxppc.org)
5 * Largely rewritten by Cort Dougan (cort@cs.nmt.edu)
8 * SPDX-License-Identifier: GPL-2.0+
13 #include <asm/ppc4xx.h>
14 #include <ppc_asm.tmpl>
16 #include <asm/cache.h>
20 * Flush instruction cache.
22 _GLOBAL(invalidate_icache)
28 * Write any modified data cache blocks out to memory
29 * and invalidate the corresponding instruction cache blocks.
31 * flush_icache_range(unsigned long start, unsigned long stop)
33 _GLOBAL(flush_icache_range)
34 li r5,L1_CACHE_BYTES-1
38 srwi. r4,r4,L1_CACHE_SHIFT
43 addi r3,r3,L1_CACHE_BYTES
45 sync /* wait for dcbst's to get to ram */
48 addi r6,r6,L1_CACHE_BYTES
50 sync /* additional sync needed on g4 */
55 * Write any modified data cache blocks out to memory.
56 * Does not invalidate the corresponding cache lines (especially for
57 * any corresponding instruction cache).
59 * clean_dcache_range(unsigned long start, unsigned long stop)
61 _GLOBAL(clean_dcache_range)
62 li r5,L1_CACHE_BYTES-1
66 srwi. r4,r4,L1_CACHE_SHIFT
71 addi r3,r3,L1_CACHE_BYTES
73 sync /* wait for dcbst's to get to ram */
77 * Write any modified data cache blocks out to memory and invalidate them.
78 * Does not invalidate the corresponding instruction cache blocks.
80 * flush_dcache_range(unsigned long start, unsigned long stop)
82 _GLOBAL(flush_dcache_range)
83 li r5,L1_CACHE_BYTES-1
87 srwi. r4,r4,L1_CACHE_SHIFT
92 addi r3,r3,L1_CACHE_BYTES
94 sync /* wait for dcbst's to get to ram */
98 * Like above, but invalidate the D-cache. This is used by the 8xx
99 * to invalidate the cache so the PPC core doesn't get stale data
100 * from the CPM (no cache snooping here :-).
102 * invalidate_dcache_range(unsigned long start, unsigned long stop)
104 _GLOBAL(invalidate_dcache_range)
105 li r5,L1_CACHE_BYTES-1
109 srwi. r4,r4,L1_CACHE_SHIFT
114 addi r3,r3,L1_CACHE_BYTES
116 sync /* wait for dcbi's to get to ram */
120 * 40x cores have 8K or 16K dcache and 32 byte line size.
121 * 44x has a 32K dcache and 32 byte line size.
122 * 8xx has 1, 2, 4, 8K variants.
123 * For now, cover the worst case of the 44x.
124 * Must be called with external interrupts disabled.
126 #define CACHE_NWAYS 64
127 #define CACHE_NLINES 32
129 _GLOBAL(flush_dcache)
130 li r4,(2 * CACHE_NWAYS * CACHE_NLINES)
133 1: lwz r3,0(r5) /* Load one word from every line */
134 addi r5,r5,L1_CACHE_BYTES
139 _GLOBAL(invalidate_dcache)
140 addi r6,0,0x0000 /* clear GPR 6 */
141 /* Do loop for # of dcache congruence classes. */
142 lis r7,(CONFIG_SYS_DCACHE_SIZE / L1_CACHE_BYTES / 2)@ha /* TBS for large sized cache */
143 ori r7,r7,(CONFIG_SYS_DCACHE_SIZE / L1_CACHE_BYTES / 2)@l
144 /* NOTE: dccci invalidates both */
145 mtctr r7 /* ways in the D cache */
147 dccci 0,r6 /* invalidate line */
148 addi r6,r6,L1_CACHE_BYTES /* bump to next line */
156 * NOTE: currently the 440s run with dcache _disabled_ once relocated to DRAM,
157 * although for some cache-ralated calls stubs have to be provided to satisfy
158 * symbols resolution.
159 * Icache-related functions are used in POST framework.
164 .globl dcache_disable
166 .globl icache_disable
181 #else /* CONFIG_440 */
189 addis r3,r0, 0xc000 /* set bit 0 */
193 .globl icache_disable
195 addis r3,r0, 0x0000 /* clear bit 0 */
203 srwi r3, r3, 31 /* >>31 => select bit 0 */
212 addis r3,r0, 0x8000 /* set bit 0 */
216 .globl dcache_disable
221 addis r3,r0, 0x0000 /* clear bit 0 */
228 srwi r3, r3, 31 /* >>31 => select bit 0 */
231 #endif /* CONFIG_440 */