Ilya Yanok | 2f3427c | 2011-11-28 06:37:32 +0000 | [diff] [blame] | 1 | /* |
| 2 | * (C) Copyright 2011 |
| 3 | * Ilya Yanok, EmCraft Systems |
| 4 | * |
Wolfgang Denk | 1a45966 | 2013-07-08 09:37:19 +0200 | [diff] [blame] | 5 | * SPDX-License-Identifier: GPL-2.0+ |
Ilya Yanok | 2f3427c | 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 | a4aaad7 | 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 |
Ilya Yanok | 2f3427c | 2011-11-28 06:37:32 +0000 | [diff] [blame] | 15 | |
| 16 | void invalidate_dcache_all(void) |
| 17 | { |
Marek Vasut | 2694bb9 | 2012-04-06 03:25:07 +0000 | [diff] [blame] | 18 | asm volatile("mcr p15, 0, %0, c7, c6, 0\n" : : "r"(0)); |
Marek Vasut | a4aaad7 | 2012-03-15 18:33:17 +0000 | [diff] [blame] | 19 | } |
| 20 | |
| 21 | void flush_dcache_all(void) |
| 22 | { |
| 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 | 2694bb9 | 2012-04-06 03:25:07 +0000 | [diff] [blame] | 28 | : : "r"(0) : "memory" |
Marek Vasut | a4aaad7 | 2012-03-15 18:33:17 +0000 | [diff] [blame] | 29 | ); |
| 30 | } |
| 31 | |
| 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 | c8d9cea | 2012-04-02 06:18:49 +0000 | [diff] [blame] | 43 | debug("CACHE: Misaligned operation at range [%08lx, %08lx]\n", |
Marek Vasut | a4aaad7 | 2012-03-15 18:33:17 +0000 | [diff] [blame] | 44 | start, stop); |
| 45 | |
| 46 | return ok; |
Ilya Yanok | 2f3427c | 2011-11-28 06:37:32 +0000 | [diff] [blame] | 47 | } |
| 48 | |
Ilya Yanok | 2f3427c | 2011-11-28 06:37:32 +0000 | [diff] [blame] | 49 | void invalidate_dcache_range(unsigned long start, unsigned long stop) |
| 50 | { |
Marek Vasut | a4aaad7 | 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 | 2694bb9 | 2012-04-06 03:25:07 +0000 | [diff] [blame] | 55 | asm volatile("mcr p15, 0, %0, c7, c6, 1\n" : : "r"(start)); |
Marek Vasut | a4aaad7 | 2012-03-15 18:33:17 +0000 | [diff] [blame] | 56 | start += CONFIG_SYS_CACHELINE_SIZE; |
| 57 | } |
Ilya Yanok | 2f3427c | 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 | a4aaad7 | 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 | 2694bb9 | 2012-04-06 03:25:07 +0000 | [diff] [blame] | 66 | asm volatile("mcr p15, 0, %0, c7, c14, 1\n" : : "r"(start)); |
Marek Vasut | a4aaad7 | 2012-03-15 18:33:17 +0000 | [diff] [blame] | 67 | start += CONFIG_SYS_CACHELINE_SIZE; |
| 68 | } |
| 69 | |
Marek Vasut | 2694bb9 | 2012-04-06 03:25:07 +0000 | [diff] [blame] | 70 | asm volatile("mcr p15, 0, %0, c7, c10, 4\n" : : "r"(0)); |
Marek Vasut | a4aaad7 | 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 | 2f3427c | 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 | a4aaad7 | 2012-03-15 18:33:17 +0000 | [diff] [blame] | 94 | void flush_cache(unsigned long start, unsigned long size) |
Ilya Yanok | 2f3427c | 2011-11-28 06:37:32 +0000 | [diff] [blame] | 95 | { |
| 96 | } |
| 97 | #endif /* #ifndef CONFIG_SYS_DCACHE_OFF */ |
Michael Walle | 6795302 | 2012-02-06 22:42:10 +0530 | [diff] [blame] | 98 | |
| 99 | /* |
| 100 | * Stub implementations for l2 cache operations |
| 101 | */ |
Marek Vasut | 2694bb9 | 2012-04-06 03:25:07 +0000 | [diff] [blame] | 102 | void __l2_cache_disable(void) {} |
| 103 | |
Michael Walle | 6795302 | 2012-02-06 22:42:10 +0530 | [diff] [blame] | 104 | void l2_cache_disable(void) |
Marek Vasut | 2694bb9 | 2012-04-06 03:25:07 +0000 | [diff] [blame] | 105 | __attribute__((weak, alias("__l2_cache_disable"))); |