1 // SPDX-License-Identifier: GPL-2.0+
4 * Texas Instruments, <www.ti.com>
9 #include <linux/types.h>
11 #include <asm/armv7.h>
12 #include <asm/utils.h>
14 #define ARMV7_DCACHE_INVAL_RANGE 1
15 #define ARMV7_DCACHE_CLEAN_INVAL_RANGE 2
17 #if !CONFIG_IS_ENABLED(SYS_DCACHE_OFF)
19 /* Asm functions from cache_v7_asm.S */
20 void v7_flush_dcache_all(void);
21 void v7_invalidate_dcache_all(void);
23 static u32 get_ccsidr(void)
27 /* Read current CP15 Cache Size ID Register */
28 asm volatile ("mrc p15, 1, %0, c0, c0, 0" : "=r" (ccsidr));
32 static void v7_dcache_clean_inval_range(u32 start, u32 stop, u32 line_len)
36 /* Align start to cache line boundary */
37 start &= ~(line_len - 1);
38 for (mva = start; mva < stop; mva = mva + line_len) {
39 /* DCCIMVAC - Clean & Invalidate data cache by MVA to PoC */
40 asm volatile ("mcr p15, 0, %0, c7, c14, 1" : : "r" (mva));
44 static void v7_dcache_inval_range(u32 start, u32 stop, u32 line_len)
48 if (!check_cache_range(start, stop))
51 for (mva = start; mva < stop; mva = mva + line_len) {
52 /* DCIMVAC - Invalidate data cache by MVA to PoC */
53 asm volatile ("mcr p15, 0, %0, c7, c6, 1" : : "r" (mva));
57 static void v7_dcache_maint_range(u32 start, u32 stop, u32 range_op)
61 ccsidr = get_ccsidr();
62 line_len = ((ccsidr & CCSIDR_LINE_SIZE_MASK) >>
63 CCSIDR_LINE_SIZE_OFFSET) + 2;
64 /* Converting from words to bytes */
66 /* converting from log2(linelen) to linelen */
67 line_len = 1 << line_len;
70 case ARMV7_DCACHE_CLEAN_INVAL_RANGE:
71 v7_dcache_clean_inval_range(start, stop, line_len);
73 case ARMV7_DCACHE_INVAL_RANGE:
74 v7_dcache_inval_range(start, stop, line_len);
78 /* DSB to make sure the operation is complete */
83 static void v7_inval_tlb(void)
85 /* Invalidate entire unified TLB */
86 asm volatile ("mcr p15, 0, %0, c8, c7, 0" : : "r" (0));
87 /* Invalidate entire data TLB */
88 asm volatile ("mcr p15, 0, %0, c8, c6, 0" : : "r" (0));
89 /* Invalidate entire instruction TLB */
90 asm volatile ("mcr p15, 0, %0, c8, c5, 0" : : "r" (0));
91 /* Full system DSB - make sure that the invalidation is complete */
93 /* Full system ISB - make sure the instruction stream sees it */
97 void invalidate_dcache_all(void)
99 v7_invalidate_dcache_all();
101 v7_outer_cache_inval_all();
105 * Performs a clean & invalidation of the entire data cache
108 void flush_dcache_all(void)
110 v7_flush_dcache_all();
112 v7_outer_cache_flush_all();
116 * Invalidates range in all levels of D-cache/unified cache used:
117 * Affects the range [start, stop - 1]
119 void invalidate_dcache_range(unsigned long start, unsigned long stop)
121 check_cache_range(start, stop);
123 v7_dcache_maint_range(start, stop, ARMV7_DCACHE_INVAL_RANGE);
125 v7_outer_cache_inval_range(start, stop);
129 * Flush range(clean & invalidate) from all levels of D-cache/unified
131 * Affects the range [start, stop - 1]
133 void flush_dcache_range(unsigned long start, unsigned long stop)
135 check_cache_range(start, stop);
137 v7_dcache_maint_range(start, stop, ARMV7_DCACHE_CLEAN_INVAL_RANGE);
139 v7_outer_cache_flush_range(start, stop);
142 void arm_init_before_mmu(void)
144 v7_outer_cache_enable();
145 invalidate_dcache_all();
149 void mmu_page_table_flush(unsigned long start, unsigned long stop)
151 flush_dcache_range(start, stop);
154 #else /* #if !CONFIG_IS_ENABLED(SYS_DCACHE_OFF) */
155 void invalidate_dcache_all(void)
159 void flush_dcache_all(void)
163 void invalidate_dcache_range(unsigned long start, unsigned long stop)
167 void flush_dcache_range(unsigned long start, unsigned long stop)
171 void arm_init_before_mmu(void)
175 void mmu_page_table_flush(unsigned long start, unsigned long stop)
179 void arm_init_domains(void)
182 #endif /* #if !CONFIG_IS_ENABLED(SYS_DCACHE_OFF) */
184 #if !CONFIG_IS_ENABLED(SYS_ICACHE_OFF)
185 /* Invalidate entire I-cache and branch predictor array */
186 void invalidate_icache_all(void)
189 * Invalidate all instruction caches to PoU.
190 * Also flushes branch target cache.
192 asm volatile ("mcr p15, 0, %0, c7, c5, 0" : : "r" (0));
194 /* Invalidate entire branch predictor array */
195 asm volatile ("mcr p15, 0, %0, c7, c5, 6" : : "r" (0));
197 /* Full system DSB - make sure that the invalidation is complete */
200 /* ISB - make sure the instruction stream sees it */
204 void invalidate_icache_all(void)
209 /* Stub implementations for outer cache operations */
210 __weak void v7_outer_cache_enable(void) {}
211 __weak void v7_outer_cache_disable(void) {}
212 __weak void v7_outer_cache_flush_all(void) {}
213 __weak void v7_outer_cache_inval_all(void) {}
214 __weak void v7_outer_cache_flush_range(u32 start, u32 end) {}
215 __weak void v7_outer_cache_inval_range(u32 start, u32 end) {}