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