blob: 16eea693d12e8cc41b69ec52036b0dc0d981ad1d [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
Trevor Woerner10015022019-05-03 09:41:00 -04009#if !CONFIG_IS_ENABLED(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}
Trevor Woerner10015022019-05-03 09:41:00 -040049#else /* #if !CONFIG_IS_ENABLED(SYS_DCACHE_OFF) */
Ilya Yanok2f3427c2011-11-28 06:37:32 +000050void invalidate_dcache_all(void)
51{
52}
53
54void flush_dcache_all(void)
55{
56}
Trevor Woerner10015022019-05-03 09:41:00 -040057#endif /* #if !CONFIG_IS_ENABLED(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
Trevor Woerner10015022019-05-03 09:41:00 -040069#if !CONFIG_IS_ENABLED(SYS_ICACHE_OFF)
Adam Ford93b283d2018-08-16 13:23:11 -050070/* 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{
Trevor Woerner10015022019-05-03 09:41:00 -040083#if !CONFIG_IS_ENABLED(SYS_ICACHE_OFF)
Adam Ford93b283d2018-08-16 13:23:11 -050084 icache_enable();
85#endif
Trevor Woerner10015022019-05-03 09:41:00 -040086#if !CONFIG_IS_ENABLED(SYS_DCACHE_OFF)
Adam Ford93b283d2018-08-16 13:23:11 -050087 dcache_enable();
88#endif
89}
90