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 | |
Marek Vasut | fc92851 | 2012-03-15 18:33:17 +0000 | [diff] [blame] | 32 | static int check_cache_range(unsigned long start, unsigned long stop) |
| 33 | { |
| 34 | int ok = 1; |
| 35 | |
| 36 | if (start & (CONFIG_SYS_CACHELINE_SIZE - 1)) |
| 37 | ok = 0; |
| 38 | |
| 39 | if (stop & (CONFIG_SYS_CACHELINE_SIZE - 1)) |
| 40 | ok = 0; |
| 41 | |
| 42 | if (!ok) |
Stefano Babic | 573a204 | 2012-04-02 06:18:49 +0000 | [diff] [blame] | 43 | debug("CACHE: Misaligned operation at range [%08lx, %08lx]\n", |
Marek Vasut | fc92851 | 2012-03-15 18:33:17 +0000 | [diff] [blame] | 44 | start, stop); |
| 45 | |
| 46 | return ok; |
| 47 | } |
| 48 | |
Ilya Yanok | c850069 | 2011-11-28 06:37:32 +0000 | [diff] [blame] | 49 | void invalidate_dcache_range(unsigned long start, unsigned long stop) |
| 50 | { |
Marek Vasut | fc92851 | 2012-03-15 18:33:17 +0000 | [diff] [blame] | 51 | if (!check_cache_range(start, stop)) |
| 52 | return; |
| 53 | |
| 54 | while (start < stop) { |
Marek Vasut | 8ed6131 | 2012-04-06 03:25:07 +0000 | [diff] [blame] | 55 | asm volatile("mcr p15, 0, %0, c7, c6, 1\n" : : "r"(start)); |
Marek Vasut | fc92851 | 2012-03-15 18:33:17 +0000 | [diff] [blame] | 56 | start += CONFIG_SYS_CACHELINE_SIZE; |
| 57 | } |
Ilya Yanok | c850069 | 2011-11-28 06:37:32 +0000 | [diff] [blame] | 58 | } |
| 59 | |
| 60 | void flush_dcache_range(unsigned long start, unsigned long stop) |
| 61 | { |
Marek Vasut | fc92851 | 2012-03-15 18:33:17 +0000 | [diff] [blame] | 62 | if (!check_cache_range(start, stop)) |
| 63 | return; |
| 64 | |
| 65 | while (start < stop) { |
Marek Vasut | 8ed6131 | 2012-04-06 03:25:07 +0000 | [diff] [blame] | 66 | asm volatile("mcr p15, 0, %0, c7, c14, 1\n" : : "r"(start)); |
Marek Vasut | fc92851 | 2012-03-15 18:33:17 +0000 | [diff] [blame] | 67 | start += CONFIG_SYS_CACHELINE_SIZE; |
| 68 | } |
| 69 | |
Marek Vasut | 8ed6131 | 2012-04-06 03:25:07 +0000 | [diff] [blame] | 70 | asm volatile("mcr p15, 0, %0, c7, c10, 4\n" : : "r"(0)); |
Marek Vasut | fc92851 | 2012-03-15 18:33:17 +0000 | [diff] [blame] | 71 | } |
| 72 | |
| 73 | void flush_cache(unsigned long start, unsigned long size) |
| 74 | { |
| 75 | flush_dcache_range(start, start + size); |
Ilya Yanok | c850069 | 2011-11-28 06:37:32 +0000 | [diff] [blame] | 76 | } |
| 77 | #else /* #ifndef CONFIG_SYS_DCACHE_OFF */ |
| 78 | void invalidate_dcache_all(void) |
| 79 | { |
| 80 | } |
| 81 | |
| 82 | void flush_dcache_all(void) |
| 83 | { |
| 84 | } |
| 85 | |
| 86 | void invalidate_dcache_range(unsigned long start, unsigned long stop) |
| 87 | { |
| 88 | } |
| 89 | |
| 90 | void flush_dcache_range(unsigned long start, unsigned long stop) |
| 91 | { |
| 92 | } |
| 93 | |
Marek Vasut | fc92851 | 2012-03-15 18:33:17 +0000 | [diff] [blame] | 94 | void flush_cache(unsigned long start, unsigned long size) |
Ilya Yanok | c850069 | 2011-11-28 06:37:32 +0000 | [diff] [blame] | 95 | { |
| 96 | } |
| 97 | #endif /* #ifndef CONFIG_SYS_DCACHE_OFF */ |
Michael Walle | 5ae3eec | 2012-02-06 22:42:10 +0530 | [diff] [blame] | 98 | |
| 99 | /* |
| 100 | * Stub implementations for l2 cache operations |
| 101 | */ |
Jeroen Hofstee | 2f65bef | 2014-10-27 20:10:06 +0100 | [diff] [blame] | 102 | __weak void l2_cache_disable(void) {} |