Ilya Yanok | 2f3427c | 2011-11-28 06:37:32 +0000 | [diff] [blame] | 1 | /* |
| 2 | * (C) Copyright 2011 |
| 3 | * Ilya Yanok, EmCraft Systems |
| 4 | * |
Wolfgang Denk | 1a45966 | 2013-07-08 09:37:19 +0200 | [diff] [blame] | 5 | * SPDX-License-Identifier: GPL-2.0+ |
Ilya Yanok | 2f3427c | 2011-11-28 06:37:32 +0000 | [diff] [blame] | 6 | */ |
| 7 | #include <linux/types.h> |
| 8 | #include <common.h> |
| 9 | |
| 10 | #ifndef CONFIG_SYS_DCACHE_OFF |
Ilya Yanok | 2f3427c | 2011-11-28 06:37:32 +0000 | [diff] [blame] | 11 | void invalidate_dcache_all(void) |
| 12 | { |
Marek Vasut | 2694bb9 | 2012-04-06 03:25:07 +0000 | [diff] [blame] | 13 | asm volatile("mcr p15, 0, %0, c7, c6, 0\n" : : "r"(0)); |
Marek Vasut | a4aaad7 | 2012-03-15 18:33:17 +0000 | [diff] [blame] | 14 | } |
| 15 | |
| 16 | void 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 Vasut | 2694bb9 | 2012-04-06 03:25:07 +0000 | [diff] [blame] | 23 | : : "r"(0) : "memory" |
Marek Vasut | a4aaad7 | 2012-03-15 18:33:17 +0000 | [diff] [blame] | 24 | ); |
| 25 | } |
| 26 | |
Ilya Yanok | 2f3427c | 2011-11-28 06:37:32 +0000 | [diff] [blame] | 27 | void invalidate_dcache_range(unsigned long start, unsigned long stop) |
| 28 | { |
Marek Vasut | a4aaad7 | 2012-03-15 18:33:17 +0000 | [diff] [blame] | 29 | if (!check_cache_range(start, stop)) |
| 30 | return; |
| 31 | |
| 32 | while (start < stop) { |
Marek Vasut | 2694bb9 | 2012-04-06 03:25:07 +0000 | [diff] [blame] | 33 | asm volatile("mcr p15, 0, %0, c7, c6, 1\n" : : "r"(start)); |
Marek Vasut | a4aaad7 | 2012-03-15 18:33:17 +0000 | [diff] [blame] | 34 | start += CONFIG_SYS_CACHELINE_SIZE; |
| 35 | } |
Ilya Yanok | 2f3427c | 2011-11-28 06:37:32 +0000 | [diff] [blame] | 36 | } |
| 37 | |
| 38 | void flush_dcache_range(unsigned long start, unsigned long stop) |
| 39 | { |
Marek Vasut | a4aaad7 | 2012-03-15 18:33:17 +0000 | [diff] [blame] | 40 | if (!check_cache_range(start, stop)) |
| 41 | return; |
| 42 | |
| 43 | while (start < stop) { |
Marek Vasut | 2694bb9 | 2012-04-06 03:25:07 +0000 | [diff] [blame] | 44 | asm volatile("mcr p15, 0, %0, c7, c14, 1\n" : : "r"(start)); |
Marek Vasut | a4aaad7 | 2012-03-15 18:33:17 +0000 | [diff] [blame] | 45 | start += CONFIG_SYS_CACHELINE_SIZE; |
| 46 | } |
| 47 | |
Marek Vasut | 2694bb9 | 2012-04-06 03:25:07 +0000 | [diff] [blame] | 48 | asm volatile("mcr p15, 0, %0, c7, c10, 4\n" : : "r"(0)); |
Marek Vasut | a4aaad7 | 2012-03-15 18:33:17 +0000 | [diff] [blame] | 49 | } |
Ilya Yanok | 2f3427c | 2011-11-28 06:37:32 +0000 | [diff] [blame] | 50 | #else /* #ifndef CONFIG_SYS_DCACHE_OFF */ |
| 51 | void invalidate_dcache_all(void) |
| 52 | { |
| 53 | } |
| 54 | |
| 55 | void flush_dcache_all(void) |
| 56 | { |
| 57 | } |
Ilya Yanok | 2f3427c | 2011-11-28 06:37:32 +0000 | [diff] [blame] | 58 | #endif /* #ifndef CONFIG_SYS_DCACHE_OFF */ |
Michael Walle | 6795302 | 2012-02-06 22:42:10 +0530 | [diff] [blame] | 59 | |
| 60 | /* |
| 61 | * Stub implementations for l2 cache operations |
| 62 | */ |
Albert ARIBAUD | 62e9207 | 2015-10-23 18:06:40 +0200 | [diff] [blame] | 63 | |
Jeroen Hofstee | 09e6e0b | 2014-10-27 20:10:06 +0100 | [diff] [blame] | 64 | __weak void l2_cache_disable(void) {} |
Albert ARIBAUD | 62e9207 | 2015-10-23 18:06:40 +0200 | [diff] [blame] | 65 | |
Tom Rini | 3a64940 | 2017-03-18 09:01:44 -0400 | [diff] [blame] | 66 | #if CONFIG_IS_ENABLED(SYS_THUMB_BUILD) |
Albert ARIBAUD | 62e9207 | 2015-10-23 18:06:40 +0200 | [diff] [blame] | 67 | __weak void invalidate_l2_cache(void) {} |
| 68 | #endif |