1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3 * (C) Copyright 2016 Vasily Khoruzhick <anarsoul@gmail.com>
4 */
5
6 #include <cpu_func.h>
7 #include <asm/cache.h>
8 #include <linux/types.h>
9 #include <common.h>
10
11 #if !CONFIG_IS_ENABLED(SYS_DCACHE_OFF)
invalidate_dcache_all(void)12 void invalidate_dcache_all(void)
13 {
14 /* Flush/Invalidate I cache */
15 asm volatile("mcr p15, 0, %0, c7, c5, 0\n" : : "r"(0));
16 /* Flush/Invalidate D cache */
17 asm volatile("mcr p15, 0, %0, c7, c6, 0\n" : : "r"(0));
18 }
19
flush_dcache_all(void)20 void flush_dcache_all(void)
21 {
22 return invalidate_dcache_all();
23 }
24
invalidate_dcache_range(unsigned long start,unsigned long stop)25 void invalidate_dcache_range(unsigned long start, unsigned long stop)
26 {
27 start &= ~(CONFIG_SYS_CACHELINE_SIZE - 1);
28 stop &= ~(CONFIG_SYS_CACHELINE_SIZE - 1);
29
30 while (start <= stop) {
31 asm volatile("mcr p15, 0, %0, c7, c6, 1\n" : : "r"(start));
32 start += CONFIG_SYS_CACHELINE_SIZE;
33 }
34 }
35
flush_dcache_range(unsigned long start,unsigned long stop)36 void flush_dcache_range(unsigned long start, unsigned long stop)
37 {
38 return invalidate_dcache_range(start, stop);
39 }
40 #else /* #if !CONFIG_IS_ENABLED(SYS_DCACHE_OFF) */
invalidate_dcache_all(void)41 void invalidate_dcache_all(void)
42 {
43 }
44
flush_dcache_all(void)45 void flush_dcache_all(void)
46 {
47 }
48 #endif /* #if !CONFIG_IS_ENABLED(SYS_DCACHE_OFF) */
49
50 /*
51 * Stub implementations for l2 cache operations
52 */
53
l2_cache_disable(void)54 __weak void l2_cache_disable(void) {}
55
56 #if CONFIG_IS_ENABLED(SYS_THUMB_BUILD)
invalidate_l2_cache(void)57 __weak void invalidate_l2_cache(void) {}
58 #endif
59