Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Ilya Yanok | c850069 | 2011-11-28 06:37:32 +0000 | [diff] [blame] | 2 | /* |
| 3 | * (C) Copyright 2011 |
| 4 | * Ilya Yanok, EmCraft Systems |
Ilya Yanok | c850069 | 2011-11-28 06:37:32 +0000 | [diff] [blame] | 5 | */ |
Simon Glass | 1d91ba7 | 2019-11-14 12:57:37 -0700 | [diff] [blame] | 6 | #include <cpu_func.h> |
Simon Glass | 274e0b0 | 2020-05-10 11:39:56 -0600 | [diff] [blame] | 7 | #include <asm/cache.h> |
Ilya Yanok | c850069 | 2011-11-28 06:37:32 +0000 | [diff] [blame] | 8 | #include <linux/types.h> |
Ilya Yanok | c850069 | 2011-11-28 06:37:32 +0000 | [diff] [blame] | 9 | |
Trevor Woerner | 43ec7e0 | 2019-05-03 09:41:00 -0400 | [diff] [blame] | 10 | #if !CONFIG_IS_ENABLED(SYS_DCACHE_OFF) |
Marek Vasut | fc92851 | 2012-03-15 18:33:17 +0000 | [diff] [blame] | 11 | void invalidate_dcache_all(void) |
Ilya Yanok | c850069 | 2011-11-28 06:37:32 +0000 | [diff] [blame] | 12 | { |
Marek Vasut | 8ed6131 | 2012-04-06 03:25:07 +0000 | [diff] [blame] | 13 | asm volatile("mcr p15, 0, %0, c7, c6, 0\n" : : "r"(0)); |
Ilya Yanok | c850069 | 2011-11-28 06:37:32 +0000 | [diff] [blame] | 14 | } |
| 15 | |
Marek Vasut | fc92851 | 2012-03-15 18:33:17 +0000 | [diff] [blame] | 16 | void flush_dcache_all(void) |
Ilya Yanok | c850069 | 2011-11-28 06:37:32 +0000 | [diff] [blame] | 17 | { |
Marek Vasut | fc92851 | 2012-03-15 18:33:17 +0000 | [diff] [blame] | 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 | 8ed6131 | 2012-04-06 03:25:07 +0000 | [diff] [blame] | 23 | : : "r"(0) : "memory" |
Marek Vasut | fc92851 | 2012-03-15 18:33:17 +0000 | [diff] [blame] | 24 | ); |
Ilya Yanok | c850069 | 2011-11-28 06:37:32 +0000 | [diff] [blame] | 25 | } |
| 26 | |
Ilya Yanok | c850069 | 2011-11-28 06:37:32 +0000 | [diff] [blame] | 27 | void invalidate_dcache_range(unsigned long start, unsigned long stop) |
| 28 | { |
Marek Vasut | fc92851 | 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 | 8ed6131 | 2012-04-06 03:25:07 +0000 | [diff] [blame] | 33 | asm volatile("mcr p15, 0, %0, c7, c6, 1\n" : : "r"(start)); |
Marek Vasut | fc92851 | 2012-03-15 18:33:17 +0000 | [diff] [blame] | 34 | start += CONFIG_SYS_CACHELINE_SIZE; |
| 35 | } |
Ilya Yanok | c850069 | 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 | fc92851 | 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 | 8ed6131 | 2012-04-06 03:25:07 +0000 | [diff] [blame] | 44 | asm volatile("mcr p15, 0, %0, c7, c14, 1\n" : : "r"(start)); |
Marek Vasut | fc92851 | 2012-03-15 18:33:17 +0000 | [diff] [blame] | 45 | start += CONFIG_SYS_CACHELINE_SIZE; |
| 46 | } |
| 47 | |
Marek Vasut | 8ed6131 | 2012-04-06 03:25:07 +0000 | [diff] [blame] | 48 | asm volatile("mcr p15, 0, %0, c7, c10, 4\n" : : "r"(0)); |
Marek Vasut | fc92851 | 2012-03-15 18:33:17 +0000 | [diff] [blame] | 49 | } |
Trevor Woerner | 43ec7e0 | 2019-05-03 09:41:00 -0400 | [diff] [blame] | 50 | #else /* #if !CONFIG_IS_ENABLED(SYS_DCACHE_OFF) */ |
Ilya Yanok | c850069 | 2011-11-28 06:37:32 +0000 | [diff] [blame] | 51 | void invalidate_dcache_all(void) |
| 52 | { |
| 53 | } |
| 54 | |
| 55 | void flush_dcache_all(void) |
| 56 | { |
| 57 | } |
Trevor Woerner | 43ec7e0 | 2019-05-03 09:41:00 -0400 | [diff] [blame] | 58 | #endif /* #if !CONFIG_IS_ENABLED(SYS_DCACHE_OFF) */ |
Michael Walle | 5ae3eec | 2012-02-06 22:42:10 +0530 | [diff] [blame] | 59 | |
| 60 | /* |
| 61 | * Stub implementations for l2 cache operations |
| 62 | */ |
Albert ARIBAUD | a382322 | 2015-10-23 18:06:40 +0200 | [diff] [blame] | 63 | |
Jeroen Hofstee | 2f65bef | 2014-10-27 20:10:06 +0100 | [diff] [blame] | 64 | __weak void l2_cache_disable(void) {} |
Albert ARIBAUD | a382322 | 2015-10-23 18:06:40 +0200 | [diff] [blame] | 65 | |
Tom Rini | 1c640a6 | 2017-03-18 09:01:44 -0400 | [diff] [blame] | 66 | #if CONFIG_IS_ENABLED(SYS_THUMB_BUILD) |
Albert ARIBAUD | a382322 | 2015-10-23 18:06:40 +0200 | [diff] [blame] | 67 | __weak void invalidate_l2_cache(void) {} |
| 68 | #endif |
Adam Ford | 554d879 | 2018-08-16 13:23:11 -0500 | [diff] [blame] | 69 | |
Trevor Woerner | 43ec7e0 | 2019-05-03 09:41:00 -0400 | [diff] [blame] | 70 | #if !CONFIG_IS_ENABLED(SYS_ICACHE_OFF) |
Adam Ford | 554d879 | 2018-08-16 13:23:11 -0500 | [diff] [blame] | 71 | /* Invalidate entire I-cache and branch predictor array */ |
| 72 | void invalidate_icache_all(void) |
| 73 | { |
| 74 | unsigned long i = 0; |
| 75 | |
| 76 | asm ("mcr p15, 0, %0, c7, c5, 0" : : "r" (i)); |
| 77 | } |
| 78 | #else |
| 79 | void invalidate_icache_all(void) {} |
| 80 | #endif |
| 81 | |
| 82 | void enable_caches(void) |
| 83 | { |
Trevor Woerner | 43ec7e0 | 2019-05-03 09:41:00 -0400 | [diff] [blame] | 84 | #if !CONFIG_IS_ENABLED(SYS_ICACHE_OFF) |
Adam Ford | 554d879 | 2018-08-16 13:23:11 -0500 | [diff] [blame] | 85 | icache_enable(); |
| 86 | #endif |
Trevor Woerner | 43ec7e0 | 2019-05-03 09:41:00 -0400 | [diff] [blame] | 87 | #if !CONFIG_IS_ENABLED(SYS_DCACHE_OFF) |
Adam Ford | 554d879 | 2018-08-16 13:23:11 -0500 | [diff] [blame] | 88 | dcache_enable(); |
| 89 | #endif |
| 90 | } |