blob: 2740ad7e29bef7b59704e691ca95964e9b9fc662 [file] [log] [blame]
Ilya Yanok2f3427c2011-11-28 06:37:32 +00001/*
2 * (C) Copyright 2011
3 * Ilya Yanok, EmCraft Systems
4 *
5 * See file CREDITS for list of people who contributed to this
6 * project.
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License as
10 * published by the Free Software Foundation; either version 2 of
11 * the License, or (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc.
21 */
22#include <linux/types.h>
23#include <common.h>
24
25#ifndef CONFIG_SYS_DCACHE_OFF
Marek Vasuta4aaad72012-03-15 18:33:17 +000026
27#ifndef CONFIG_SYS_CACHELINE_SIZE
28#define CONFIG_SYS_CACHELINE_SIZE 32
29#endif
Ilya Yanok2f3427c2011-11-28 06:37:32 +000030
31void invalidate_dcache_all(void)
32{
Marek Vasut2694bb92012-04-06 03:25:07 +000033 asm volatile("mcr p15, 0, %0, c7, c6, 0\n" : : "r"(0));
Marek Vasuta4aaad72012-03-15 18:33:17 +000034}
35
36void flush_dcache_all(void)
37{
38 asm volatile(
39 "0:"
40 "mrc p15, 0, r15, c7, c14, 3\n"
41 "bne 0b\n"
42 "mcr p15, 0, %0, c7, c10, 4\n"
Marek Vasut2694bb92012-04-06 03:25:07 +000043 : : "r"(0) : "memory"
Marek Vasuta4aaad72012-03-15 18:33:17 +000044 );
45}
46
47static int check_cache_range(unsigned long start, unsigned long stop)
48{
49 int ok = 1;
50
51 if (start & (CONFIG_SYS_CACHELINE_SIZE - 1))
52 ok = 0;
53
54 if (stop & (CONFIG_SYS_CACHELINE_SIZE - 1))
55 ok = 0;
56
57 if (!ok)
Stefano Babicc8d9cea2012-04-02 06:18:49 +000058 debug("CACHE: Misaligned operation at range [%08lx, %08lx]\n",
Marek Vasuta4aaad72012-03-15 18:33:17 +000059 start, stop);
60
61 return ok;
Ilya Yanok2f3427c2011-11-28 06:37:32 +000062}
63
Ilya Yanok2f3427c2011-11-28 06:37:32 +000064void invalidate_dcache_range(unsigned long start, unsigned long stop)
65{
Marek Vasuta4aaad72012-03-15 18:33:17 +000066 if (!check_cache_range(start, stop))
67 return;
68
69 while (start < stop) {
Marek Vasut2694bb92012-04-06 03:25:07 +000070 asm volatile("mcr p15, 0, %0, c7, c6, 1\n" : : "r"(start));
Marek Vasuta4aaad72012-03-15 18:33:17 +000071 start += CONFIG_SYS_CACHELINE_SIZE;
72 }
Ilya Yanok2f3427c2011-11-28 06:37:32 +000073}
74
75void flush_dcache_range(unsigned long start, unsigned long stop)
76{
Marek Vasuta4aaad72012-03-15 18:33:17 +000077 if (!check_cache_range(start, stop))
78 return;
79
80 while (start < stop) {
Marek Vasut2694bb92012-04-06 03:25:07 +000081 asm volatile("mcr p15, 0, %0, c7, c14, 1\n" : : "r"(start));
Marek Vasuta4aaad72012-03-15 18:33:17 +000082 start += CONFIG_SYS_CACHELINE_SIZE;
83 }
84
Marek Vasut2694bb92012-04-06 03:25:07 +000085 asm volatile("mcr p15, 0, %0, c7, c10, 4\n" : : "r"(0));
Marek Vasuta4aaad72012-03-15 18:33:17 +000086}
87
88void flush_cache(unsigned long start, unsigned long size)
89{
90 flush_dcache_range(start, start + size);
Ilya Yanok2f3427c2011-11-28 06:37:32 +000091}
92#else /* #ifndef CONFIG_SYS_DCACHE_OFF */
93void invalidate_dcache_all(void)
94{
95}
96
97void flush_dcache_all(void)
98{
99}
100
101void invalidate_dcache_range(unsigned long start, unsigned long stop)
102{
103}
104
105void flush_dcache_range(unsigned long start, unsigned long stop)
106{
107}
108
Marek Vasuta4aaad72012-03-15 18:33:17 +0000109void flush_cache(unsigned long start, unsigned long size)
Ilya Yanok2f3427c2011-11-28 06:37:32 +0000110{
111}
112#endif /* #ifndef CONFIG_SYS_DCACHE_OFF */
Michael Walle67953022012-02-06 22:42:10 +0530113
114/*
115 * Stub implementations for l2 cache operations
116 */
Marek Vasut2694bb92012-04-06 03:25:07 +0000117void __l2_cache_disable(void) {}
118
Michael Walle67953022012-02-06 22:42:10 +0530119void l2_cache_disable(void)
Marek Vasut2694bb92012-04-06 03:25:07 +0000120 __attribute__((weak, alias("__l2_cache_disable")));