blob: acab9bccc01ad44e8e5150790ff3a7f38af54054 [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 */
Simon Glass9edefc22019-11-14 12:57:37 -07006#include <cpu_func.h>
Simon Glass90526e92020-05-10 11:39:56 -06007#include <asm/cache.h>
Ilya Yanok2f3427c2011-11-28 06:37:32 +00008#include <linux/types.h>
9#include <common.h>
10
Trevor Woerner10015022019-05-03 09:41:00 -040011#if !CONFIG_IS_ENABLED(SYS_DCACHE_OFF)
Ilya Yanok2f3427c2011-11-28 06:37:32 +000012void invalidate_dcache_all(void)
13{
Marek Vasut2694bb92012-04-06 03:25:07 +000014 asm volatile("mcr p15, 0, %0, c7, c6, 0\n" : : "r"(0));
Marek Vasuta4aaad72012-03-15 18:33:17 +000015}
16
17void flush_dcache_all(void)
18{
19 asm volatile(
20 "0:"
21 "mrc p15, 0, r15, c7, c14, 3\n"
22 "bne 0b\n"
23 "mcr p15, 0, %0, c7, c10, 4\n"
Marek Vasut2694bb92012-04-06 03:25:07 +000024 : : "r"(0) : "memory"
Marek Vasuta4aaad72012-03-15 18:33:17 +000025 );
26}
27
Ilya Yanok2f3427c2011-11-28 06:37:32 +000028void invalidate_dcache_range(unsigned long start, unsigned long stop)
29{
Marek Vasuta4aaad72012-03-15 18:33:17 +000030 if (!check_cache_range(start, stop))
31 return;
32
33 while (start < stop) {
Marek Vasut2694bb92012-04-06 03:25:07 +000034 asm volatile("mcr p15, 0, %0, c7, c6, 1\n" : : "r"(start));
Marek Vasuta4aaad72012-03-15 18:33:17 +000035 start += CONFIG_SYS_CACHELINE_SIZE;
36 }
Ilya Yanok2f3427c2011-11-28 06:37:32 +000037}
38
39void flush_dcache_range(unsigned long start, unsigned long stop)
40{
Marek Vasuta4aaad72012-03-15 18:33:17 +000041 if (!check_cache_range(start, stop))
42 return;
43
44 while (start < stop) {
Marek Vasut2694bb92012-04-06 03:25:07 +000045 asm volatile("mcr p15, 0, %0, c7, c14, 1\n" : : "r"(start));
Marek Vasuta4aaad72012-03-15 18:33:17 +000046 start += CONFIG_SYS_CACHELINE_SIZE;
47 }
48
Marek Vasut2694bb92012-04-06 03:25:07 +000049 asm volatile("mcr p15, 0, %0, c7, c10, 4\n" : : "r"(0));
Marek Vasuta4aaad72012-03-15 18:33:17 +000050}
Trevor Woerner10015022019-05-03 09:41:00 -040051#else /* #if !CONFIG_IS_ENABLED(SYS_DCACHE_OFF) */
Ilya Yanok2f3427c2011-11-28 06:37:32 +000052void invalidate_dcache_all(void)
53{
54}
55
56void flush_dcache_all(void)
57{
58}
Trevor Woerner10015022019-05-03 09:41:00 -040059#endif /* #if !CONFIG_IS_ENABLED(SYS_DCACHE_OFF) */
Michael Walle67953022012-02-06 22:42:10 +053060
61/*
62 * Stub implementations for l2 cache operations
63 */
Albert ARIBAUD62e92072015-10-23 18:06:40 +020064
Jeroen Hofstee09e6e0b2014-10-27 20:10:06 +010065__weak void l2_cache_disable(void) {}
Albert ARIBAUD62e92072015-10-23 18:06:40 +020066
Tom Rini3a649402017-03-18 09:01:44 -040067#if CONFIG_IS_ENABLED(SYS_THUMB_BUILD)
Albert ARIBAUD62e92072015-10-23 18:06:40 +020068__weak void invalidate_l2_cache(void) {}
69#endif
Adam Ford93b283d2018-08-16 13:23:11 -050070
Trevor Woerner10015022019-05-03 09:41:00 -040071#if !CONFIG_IS_ENABLED(SYS_ICACHE_OFF)
Adam Ford93b283d2018-08-16 13:23:11 -050072/* Invalidate entire I-cache and branch predictor array */
73void invalidate_icache_all(void)
74{
75 unsigned long i = 0;
76
77 asm ("mcr p15, 0, %0, c7, c5, 0" : : "r" (i));
78}
79#else
80void invalidate_icache_all(void) {}
81#endif
82
83void enable_caches(void)
84{
Trevor Woerner10015022019-05-03 09:41:00 -040085#if !CONFIG_IS_ENABLED(SYS_ICACHE_OFF)
Adam Ford93b283d2018-08-16 13:23:11 -050086 icache_enable();
87#endif
Trevor Woerner10015022019-05-03 09:41:00 -040088#if !CONFIG_IS_ENABLED(SYS_DCACHE_OFF)
Adam Ford93b283d2018-08-16 13:23:11 -050089 dcache_enable();
90#endif
91}
92