blob: 22a55f52e0176914135e14a355dbaa107568c322 [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Ilya Yanok2f3427c2011-11-28 06:37:32 +00002/*
3 * (C) Copyright 2011
4 * Ilya Yanok, EmCraft Systems
Ilya Yanok2f3427c2011-11-28 06:37:32 +00005 */
6#include <linux/types.h>
7#include <common.h>
8
9#ifndef CONFIG_SYS_DCACHE_OFF
Ilya Yanok2f3427c2011-11-28 06:37:32 +000010void invalidate_dcache_all(void)
11{
Marek Vasut2694bb92012-04-06 03:25:07 +000012 asm volatile("mcr p15, 0, %0, c7, c6, 0\n" : : "r"(0));
Marek Vasuta4aaad72012-03-15 18:33:17 +000013}
14
15void flush_dcache_all(void)
16{
17 asm volatile(
18 "0:"
19 "mrc p15, 0, r15, c7, c14, 3\n"
20 "bne 0b\n"
21 "mcr p15, 0, %0, c7, c10, 4\n"
Marek Vasut2694bb92012-04-06 03:25:07 +000022 : : "r"(0) : "memory"
Marek Vasuta4aaad72012-03-15 18:33:17 +000023 );
24}
25
Ilya Yanok2f3427c2011-11-28 06:37:32 +000026void invalidate_dcache_range(unsigned long start, unsigned long stop)
27{
Marek Vasuta4aaad72012-03-15 18:33:17 +000028 if (!check_cache_range(start, stop))
29 return;
30
31 while (start < stop) {
Marek Vasut2694bb92012-04-06 03:25:07 +000032 asm volatile("mcr p15, 0, %0, c7, c6, 1\n" : : "r"(start));
Marek Vasuta4aaad72012-03-15 18:33:17 +000033 start += CONFIG_SYS_CACHELINE_SIZE;
34 }
Ilya Yanok2f3427c2011-11-28 06:37:32 +000035}
36
37void flush_dcache_range(unsigned long start, unsigned long stop)
38{
Marek Vasuta4aaad72012-03-15 18:33:17 +000039 if (!check_cache_range(start, stop))
40 return;
41
42 while (start < stop) {
Marek Vasut2694bb92012-04-06 03:25:07 +000043 asm volatile("mcr p15, 0, %0, c7, c14, 1\n" : : "r"(start));
Marek Vasuta4aaad72012-03-15 18:33:17 +000044 start += CONFIG_SYS_CACHELINE_SIZE;
45 }
46
Marek Vasut2694bb92012-04-06 03:25:07 +000047 asm volatile("mcr p15, 0, %0, c7, c10, 4\n" : : "r"(0));
Marek Vasuta4aaad72012-03-15 18:33:17 +000048}
Ilya Yanok2f3427c2011-11-28 06:37:32 +000049#else /* #ifndef CONFIG_SYS_DCACHE_OFF */
50void invalidate_dcache_all(void)
51{
52}
53
54void flush_dcache_all(void)
55{
56}
Ilya Yanok2f3427c2011-11-28 06:37:32 +000057#endif /* #ifndef CONFIG_SYS_DCACHE_OFF */
Michael Walle67953022012-02-06 22:42:10 +053058
59/*
60 * Stub implementations for l2 cache operations
61 */
Albert ARIBAUD62e92072015-10-23 18:06:40 +020062
Jeroen Hofstee09e6e0b2014-10-27 20:10:06 +010063__weak void l2_cache_disable(void) {}
Albert ARIBAUD62e92072015-10-23 18:06:40 +020064
Tom Rini3a649402017-03-18 09:01:44 -040065#if CONFIG_IS_ENABLED(SYS_THUMB_BUILD)
Albert ARIBAUD62e92072015-10-23 18:06:40 +020066__weak void invalidate_l2_cache(void) {}
67#endif
Adam Ford93b283d2018-08-16 13:23:11 -050068
69#ifndef CONFIG_SYS_ICACHE_OFF
70/* Invalidate entire I-cache and branch predictor array */
71void invalidate_icache_all(void)
72{
73 unsigned long i = 0;
74
75 asm ("mcr p15, 0, %0, c7, c5, 0" : : "r" (i));
76}
77#else
78void invalidate_icache_all(void) {}
79#endif
80
81void enable_caches(void)
82{
83#ifndef CONFIG_SYS_ICACHE_OFF
84 icache_enable();
85#endif
86#ifndef CONFIG_SYS_DCACHE_OFF
87 dcache_enable();
88#endif
89}
90