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