Ilya Yanok | c850069 | 2011-11-28 06:37:32 +0000 | [diff] [blame] | 1 | /* |
| 2 | * (C) Copyright 2011 |
| 3 | * Ilya Yanok, EmCraft Systems |
| 4 | * |
Wolfgang Denk | d79de1d | 2013-07-08 09:37:19 +0200 | [diff] [blame] | 5 | * SPDX-License-Identifier: GPL-2.0+ |
Ilya Yanok | c850069 | 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 |
Marek Vasut | fc92851 | 2012-03-15 18:33:17 +0000 | [diff] [blame] | 11 | |
| 12 | #ifndef CONFIG_SYS_CACHELINE_SIZE |
| 13 | #define CONFIG_SYS_CACHELINE_SIZE 32 |
| 14 | #endif |
| 15 | |
| 16 | void invalidate_dcache_all(void) |
Ilya Yanok | c850069 | 2011-11-28 06:37:32 +0000 | [diff] [blame] | 17 | { |
Marek Vasut | 8ed6131 | 2012-04-06 03:25:07 +0000 | [diff] [blame] | 18 | asm volatile("mcr p15, 0, %0, c7, c6, 0\n" : : "r"(0)); |
Ilya Yanok | c850069 | 2011-11-28 06:37:32 +0000 | [diff] [blame] | 19 | } |
| 20 | |
Marek Vasut | fc92851 | 2012-03-15 18:33:17 +0000 | [diff] [blame] | 21 | void flush_dcache_all(void) |
Ilya Yanok | c850069 | 2011-11-28 06:37:32 +0000 | [diff] [blame] | 22 | { |
Marek Vasut | fc92851 | 2012-03-15 18:33:17 +0000 | [diff] [blame] | 23 | asm volatile( |
| 24 | "0:" |
| 25 | "mrc p15, 0, r15, c7, c14, 3\n" |
| 26 | "bne 0b\n" |
| 27 | "mcr p15, 0, %0, c7, c10, 4\n" |
Marek Vasut | 8ed6131 | 2012-04-06 03:25:07 +0000 | [diff] [blame] | 28 | : : "r"(0) : "memory" |
Marek Vasut | fc92851 | 2012-03-15 18:33:17 +0000 | [diff] [blame] | 29 | ); |
Ilya Yanok | c850069 | 2011-11-28 06:37:32 +0000 | [diff] [blame] | 30 | } |
| 31 | |
Ilya Yanok | c850069 | 2011-11-28 06:37:32 +0000 | [diff] [blame] | 32 | void invalidate_dcache_range(unsigned long start, unsigned long stop) |
| 33 | { |
Marek Vasut | fc92851 | 2012-03-15 18:33:17 +0000 | [diff] [blame] | 34 | if (!check_cache_range(start, stop)) |
| 35 | return; |
| 36 | |
| 37 | while (start < stop) { |
Marek Vasut | 8ed6131 | 2012-04-06 03:25:07 +0000 | [diff] [blame] | 38 | asm volatile("mcr p15, 0, %0, c7, c6, 1\n" : : "r"(start)); |
Marek Vasut | fc92851 | 2012-03-15 18:33:17 +0000 | [diff] [blame] | 39 | start += CONFIG_SYS_CACHELINE_SIZE; |
| 40 | } |
Ilya Yanok | c850069 | 2011-11-28 06:37:32 +0000 | [diff] [blame] | 41 | } |
| 42 | |
| 43 | void flush_dcache_range(unsigned long start, unsigned long stop) |
| 44 | { |
Marek Vasut | fc92851 | 2012-03-15 18:33:17 +0000 | [diff] [blame] | 45 | if (!check_cache_range(start, stop)) |
| 46 | return; |
| 47 | |
| 48 | while (start < stop) { |
Marek Vasut | 8ed6131 | 2012-04-06 03:25:07 +0000 | [diff] [blame] | 49 | asm volatile("mcr p15, 0, %0, c7, c14, 1\n" : : "r"(start)); |
Marek Vasut | fc92851 | 2012-03-15 18:33:17 +0000 | [diff] [blame] | 50 | start += CONFIG_SYS_CACHELINE_SIZE; |
| 51 | } |
| 52 | |
Marek Vasut | 8ed6131 | 2012-04-06 03:25:07 +0000 | [diff] [blame] | 53 | asm volatile("mcr p15, 0, %0, c7, c10, 4\n" : : "r"(0)); |
Marek Vasut | fc92851 | 2012-03-15 18:33:17 +0000 | [diff] [blame] | 54 | } |
Ilya Yanok | c850069 | 2011-11-28 06:37:32 +0000 | [diff] [blame] | 55 | #else /* #ifndef CONFIG_SYS_DCACHE_OFF */ |
| 56 | void invalidate_dcache_all(void) |
| 57 | { |
| 58 | } |
| 59 | |
| 60 | void flush_dcache_all(void) |
| 61 | { |
| 62 | } |
Ilya Yanok | c850069 | 2011-11-28 06:37:32 +0000 | [diff] [blame] | 63 | #endif /* #ifndef CONFIG_SYS_DCACHE_OFF */ |
Michael Walle | 5ae3eec | 2012-02-06 22:42:10 +0530 | [diff] [blame] | 64 | |
| 65 | /* |
| 66 | * Stub implementations for l2 cache operations |
| 67 | */ |
Albert ARIBAUD | a382322 | 2015-10-23 18:06:40 +0200 | [diff] [blame] | 68 | |
Jeroen Hofstee | 2f65bef | 2014-10-27 20:10:06 +0100 | [diff] [blame] | 69 | __weak void l2_cache_disable(void) {} |
Albert ARIBAUD | a382322 | 2015-10-23 18:06:40 +0200 | [diff] [blame] | 70 | |
| 71 | #if defined CONFIG_SYS_THUMB_BUILD |
| 72 | __weak void invalidate_l2_cache(void) {} |
| 73 | #endif |