blob: d56e594af2952f18e62d7b10d89ef4e00c92c2a1 [file] [log] [blame]
Ilya Yanok2f3427c2011-11-28 06:37:32 +00001/*
2 * (C) Copyright 2011
3 * Ilya Yanok, EmCraft Systems
4 *
Wolfgang Denk1a459662013-07-08 09:37:19 +02005 * SPDX-License-Identifier: GPL-2.0+
Ilya Yanok2f3427c2011-11-28 06:37:32 +00006 */
7#include <linux/types.h>
8#include <common.h>
9
10#ifndef CONFIG_SYS_DCACHE_OFF
Ilya Yanok2f3427c2011-11-28 06:37:32 +000011void invalidate_dcache_all(void)
12{
Marek Vasut2694bb92012-04-06 03:25:07 +000013 asm volatile("mcr p15, 0, %0, c7, c6, 0\n" : : "r"(0));
Marek Vasuta4aaad72012-03-15 18:33:17 +000014}
15
16void flush_dcache_all(void)
17{
18 asm volatile(
19 "0:"
20 "mrc p15, 0, r15, c7, c14, 3\n"
21 "bne 0b\n"
22 "mcr p15, 0, %0, c7, c10, 4\n"
Marek Vasut2694bb92012-04-06 03:25:07 +000023 : : "r"(0) : "memory"
Marek Vasuta4aaad72012-03-15 18:33:17 +000024 );
25}
26
Ilya Yanok2f3427c2011-11-28 06:37:32 +000027void invalidate_dcache_range(unsigned long start, unsigned long stop)
28{
Marek Vasuta4aaad72012-03-15 18:33:17 +000029 if (!check_cache_range(start, stop))
30 return;
31
32 while (start < stop) {
Marek Vasut2694bb92012-04-06 03:25:07 +000033 asm volatile("mcr p15, 0, %0, c7, c6, 1\n" : : "r"(start));
Marek Vasuta4aaad72012-03-15 18:33:17 +000034 start += CONFIG_SYS_CACHELINE_SIZE;
35 }
Ilya Yanok2f3427c2011-11-28 06:37:32 +000036}
37
38void flush_dcache_range(unsigned long start, unsigned long stop)
39{
Marek Vasuta4aaad72012-03-15 18:33:17 +000040 if (!check_cache_range(start, stop))
41 return;
42
43 while (start < stop) {
Marek Vasut2694bb92012-04-06 03:25:07 +000044 asm volatile("mcr p15, 0, %0, c7, c14, 1\n" : : "r"(start));
Marek Vasuta4aaad72012-03-15 18:33:17 +000045 start += CONFIG_SYS_CACHELINE_SIZE;
46 }
47
Marek Vasut2694bb92012-04-06 03:25:07 +000048 asm volatile("mcr p15, 0, %0, c7, c10, 4\n" : : "r"(0));
Marek Vasuta4aaad72012-03-15 18:33:17 +000049}
Ilya Yanok2f3427c2011-11-28 06:37:32 +000050#else /* #ifndef CONFIG_SYS_DCACHE_OFF */
51void invalidate_dcache_all(void)
52{
53}
54
55void flush_dcache_all(void)
56{
57}
Ilya Yanok2f3427c2011-11-28 06:37:32 +000058#endif /* #ifndef CONFIG_SYS_DCACHE_OFF */
Michael Walle67953022012-02-06 22:42:10 +053059
60/*
61 * Stub implementations for l2 cache operations
62 */
Albert ARIBAUD62e92072015-10-23 18:06:40 +020063
Jeroen Hofstee09e6e0b2014-10-27 20:10:06 +010064__weak void l2_cache_disable(void) {}
Albert ARIBAUD62e92072015-10-23 18:06:40 +020065
Tom Rini3a649402017-03-18 09:01:44 -040066#if CONFIG_IS_ENABLED(SYS_THUMB_BUILD)
Albert ARIBAUD62e92072015-10-23 18:06:40 +020067__weak void invalidate_l2_cache(void) {}
68#endif