blob: 2740ad7e29bef7b59704e691ca95964e9b9fc662 [file] [log] [blame]
Ilya Yanokc8500692011-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 Vasutfc928512012-03-15 18:33:17 +000026
27#ifndef CONFIG_SYS_CACHELINE_SIZE
28#define CONFIG_SYS_CACHELINE_SIZE 32
29#endif
30
31void invalidate_dcache_all(void)
Ilya Yanokc8500692011-11-28 06:37:32 +000032{
Marek Vasut8ed61312012-04-06 03:25:07 +000033 asm volatile("mcr p15, 0, %0, c7, c6, 0\n" : : "r"(0));
Ilya Yanokc8500692011-11-28 06:37:32 +000034}
35
Marek Vasutfc928512012-03-15 18:33:17 +000036void flush_dcache_all(void)
Ilya Yanokc8500692011-11-28 06:37:32 +000037{
Marek Vasutfc928512012-03-15 18:33:17 +000038 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 Vasut8ed61312012-04-06 03:25:07 +000043 : : "r"(0) : "memory"
Marek Vasutfc928512012-03-15 18:33:17 +000044 );
Ilya Yanokc8500692011-11-28 06:37:32 +000045}
46
Marek Vasutfc928512012-03-15 18:33:17 +000047static 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 Babic573a2042012-04-02 06:18:49 +000058 debug("CACHE: Misaligned operation at range [%08lx, %08lx]\n",
Marek Vasutfc928512012-03-15 18:33:17 +000059 start, stop);
60
61 return ok;
62}
63
Ilya Yanokc8500692011-11-28 06:37:32 +000064void invalidate_dcache_range(unsigned long start, unsigned long stop)
65{
Marek Vasutfc928512012-03-15 18:33:17 +000066 if (!check_cache_range(start, stop))
67 return;
68
69 while (start < stop) {
Marek Vasut8ed61312012-04-06 03:25:07 +000070 asm volatile("mcr p15, 0, %0, c7, c6, 1\n" : : "r"(start));
Marek Vasutfc928512012-03-15 18:33:17 +000071 start += CONFIG_SYS_CACHELINE_SIZE;
72 }
Ilya Yanokc8500692011-11-28 06:37:32 +000073}
74
75void flush_dcache_range(unsigned long start, unsigned long stop)
76{
Marek Vasutfc928512012-03-15 18:33:17 +000077 if (!check_cache_range(start, stop))
78 return;
79
80 while (start < stop) {
Marek Vasut8ed61312012-04-06 03:25:07 +000081 asm volatile("mcr p15, 0, %0, c7, c14, 1\n" : : "r"(start));
Marek Vasutfc928512012-03-15 18:33:17 +000082 start += CONFIG_SYS_CACHELINE_SIZE;
83 }
84
Marek Vasut8ed61312012-04-06 03:25:07 +000085 asm volatile("mcr p15, 0, %0, c7, c10, 4\n" : : "r"(0));
Marek Vasutfc928512012-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 Yanokc8500692011-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 Vasutfc928512012-03-15 18:33:17 +0000109void flush_cache(unsigned long start, unsigned long size)
Ilya Yanokc8500692011-11-28 06:37:32 +0000110{
111}
112#endif /* #ifndef CONFIG_SYS_DCACHE_OFF */
Michael Walle5ae3eec2012-02-06 22:42:10 +0530113
114/*
115 * Stub implementations for l2 cache operations
116 */
Marek Vasut8ed61312012-04-06 03:25:07 +0000117void __l2_cache_disable(void) {}
118
Michael Walle5ae3eec2012-02-06 22:42:10 +0530119void l2_cache_disable(void)
Marek Vasut8ed61312012-04-06 03:25:07 +0000120 __attribute__((weak, alias("__l2_cache_disable")));