blob: 4b787bba2b588dfeccf4567986c60044f2c3ae90 [file] [log] [blame]
Lennert Buytenhek573a6522009-11-24 19:33:52 +02001/*
2 * arch/arm/mm/cache-tauros2.c - Tauros2 L2 cache controller support
3 *
4 * Copyright (C) 2008 Marvell Semiconductor
5 *
6 * This file is licensed under the terms of the GNU General Public
7 * License version 2. This program is licensed "as is" without any
8 * warranty of any kind, whether express or implied.
9 *
10 * References:
11 * - PJ1 CPU Core Datasheet,
12 * Document ID MV-S104837-01, Rev 0.7, January 24 2008.
13 * - PJ4 CPU Core Datasheet,
14 * Document ID MV-S105190-00, Rev 0.7, March 14 2008.
15 */
16
17#include <linux/init.h>
18#include <asm/cacheflush.h>
Russell King15d07dc2012-03-28 18:30:01 +010019#include <asm/cp15.h>
Chao Xiefa79b8d2012-07-31 14:13:11 +080020#include <asm/cputype.h>
Lennert Buytenhek573a6522009-11-24 19:33:52 +020021#include <asm/hardware/cache-tauros2.h>
22
23
24/*
25 * When Tauros2 is used on a CPU that supports the v7 hierarchical
26 * cache operations, the cache handling code in proc-v7.S takes care
27 * of everything, including handling DMA coherency.
28 *
29 * So, we only need to register outer cache operations here if we're
30 * being used on a pre-v7 CPU, and we only need to build support for
31 * outer cache operations into the kernel image if the kernel has been
32 * configured to support a pre-v7 CPU.
33 */
34#if __LINUX_ARM_ARCH__ < 7
35/*
36 * Low-level cache maintenance operations.
37 */
38static inline void tauros2_clean_pa(unsigned long addr)
39{
40 __asm__("mcr p15, 1, %0, c7, c11, 3" : : "r" (addr));
41}
42
43static inline void tauros2_clean_inv_pa(unsigned long addr)
44{
45 __asm__("mcr p15, 1, %0, c7, c15, 3" : : "r" (addr));
46}
47
48static inline void tauros2_inv_pa(unsigned long addr)
49{
50 __asm__("mcr p15, 1, %0, c7, c7, 3" : : "r" (addr));
51}
52
53
54/*
55 * Linux primitives.
56 *
57 * Note that the end addresses passed to Linux primitives are
58 * noninclusive.
59 */
60#define CACHE_LINE_SIZE 32
61
62static void tauros2_inv_range(unsigned long start, unsigned long end)
63{
64 /*
65 * Clean and invalidate partial first cache line.
66 */
67 if (start & (CACHE_LINE_SIZE - 1)) {
68 tauros2_clean_inv_pa(start & ~(CACHE_LINE_SIZE - 1));
69 start = (start | (CACHE_LINE_SIZE - 1)) + 1;
70 }
71
72 /*
73 * Clean and invalidate partial last cache line.
74 */
75 if (end & (CACHE_LINE_SIZE - 1)) {
76 tauros2_clean_inv_pa(end & ~(CACHE_LINE_SIZE - 1));
77 end &= ~(CACHE_LINE_SIZE - 1);
78 }
79
80 /*
81 * Invalidate all full cache lines between 'start' and 'end'.
82 */
83 while (start < end) {
84 tauros2_inv_pa(start);
85 start += CACHE_LINE_SIZE;
86 }
87
88 dsb();
89}
90
91static void tauros2_clean_range(unsigned long start, unsigned long end)
92{
93 start &= ~(CACHE_LINE_SIZE - 1);
94 while (start < end) {
95 tauros2_clean_pa(start);
96 start += CACHE_LINE_SIZE;
97 }
98
99 dsb();
100}
101
102static void tauros2_flush_range(unsigned long start, unsigned long end)
103{
104 start &= ~(CACHE_LINE_SIZE - 1);
105 while (start < end) {
106 tauros2_clean_inv_pa(start);
107 start += CACHE_LINE_SIZE;
108 }
109
110 dsb();
111}
Chao Xie89326f762012-05-07 11:23:59 +0800112
113static void tauros2_disable(void)
114{
115 __asm__ __volatile__ (
116 "mcr p15, 1, %0, c7, c11, 0 @L2 Cache Clean All\n\t"
117 "mrc p15, 0, %0, c1, c0, 0\n\t"
118 "bic %0, %0, #(1 << 26)\n\t"
119 "mcr p15, 0, %0, c1, c0, 0 @Disable L2 Cache\n\t"
120 : : "r" (0x0));
121}
122
123static void tauros2_resume(void)
124{
125 __asm__ __volatile__ (
126 "mcr p15, 1, %0, c7, c7, 0 @L2 Cache Invalidate All\n\t"
127 "mrc p15, 0, %0, c1, c0, 0\n\t"
128 "orr %0, %0, #(1 << 26)\n\t"
129 "mcr p15, 0, %0, c1, c0, 0 @Enable L2 Cache\n\t"
130 : : "r" (0x0));
131}
Lennert Buytenhek573a6522009-11-24 19:33:52 +0200132#endif
133
134static inline u32 __init read_extra_features(void)
135{
136 u32 u;
137
138 __asm__("mrc p15, 1, %0, c15, c1, 0" : "=r" (u));
139
140 return u;
141}
142
143static inline void __init write_extra_features(u32 u)
144{
145 __asm__("mcr p15, 1, %0, c15, c1, 0" : : "r" (u));
146}
147
148static void __init disable_l2_prefetch(void)
149{
150 u32 u;
151
152 /*
153 * Read the CPU Extra Features register and verify that the
154 * Disable L2 Prefetch bit is set.
155 */
156 u = read_extra_features();
157 if (!(u & 0x01000000)) {
158 printk(KERN_INFO "Tauros2: Disabling L2 prefetch.\n");
159 write_extra_features(u | 0x01000000);
160 }
161}
162
163static inline int __init cpuid_scheme(void)
164{
Lennert Buytenhek573a6522009-11-24 19:33:52 +0200165 return !!((processor_id & 0x000f0000) == 0x000f0000);
166}
167
168static inline u32 __init read_mmfr3(void)
169{
170 u32 mmfr3;
171
172 __asm__("mrc p15, 0, %0, c0, c1, 7\n" : "=r" (mmfr3));
173
174 return mmfr3;
175}
176
177static inline u32 __init read_actlr(void)
178{
179 u32 actlr;
180
181 __asm__("mrc p15, 0, %0, c1, c0, 1\n" : "=r" (actlr));
182
183 return actlr;
184}
185
186static inline void __init write_actlr(u32 actlr)
187{
188 __asm__("mcr p15, 0, %0, c1, c0, 1\n" : : "r" (actlr));
189}
190
191void __init tauros2_init(void)
192{
Chao Xie5967b542012-07-31 14:13:10 +0800193 char *mode = NULL;
Lennert Buytenhek573a6522009-11-24 19:33:52 +0200194
195 disable_l2_prefetch();
196
197#ifdef CONFIG_CPU_32v5
198 if ((processor_id & 0xff0f0000) == 0x56050000) {
199 u32 feat;
200
201 /*
202 * v5 CPUs with Tauros2 have the L2 cache enable bit
203 * located in the CPU Extra Features register.
204 */
205 feat = read_extra_features();
206 if (!(feat & 0x00400000)) {
207 printk(KERN_INFO "Tauros2: Enabling L2 cache.\n");
208 write_extra_features(feat | 0x00400000);
209 }
210
211 mode = "ARMv5";
212 outer_cache.inv_range = tauros2_inv_range;
213 outer_cache.clean_range = tauros2_clean_range;
214 outer_cache.flush_range = tauros2_flush_range;
Chao Xie89326f762012-05-07 11:23:59 +0800215 outer_cache.disable = tauros2_disable;
216 outer_cache.resume = tauros2_resume;
Lennert Buytenhek573a6522009-11-24 19:33:52 +0200217 }
218#endif
219
220#ifdef CONFIG_CPU_32v6
221 /*
222 * Check whether this CPU lacks support for the v7 hierarchical
223 * cache ops. (PJ4 is in its v6 personality mode if the MMFR3
224 * register indicates no support for the v7 hierarchical cache
225 * ops.)
226 */
227 if (cpuid_scheme() && (read_mmfr3() & 0xf) == 0) {
228 /*
229 * When Tauros2 is used in an ARMv6 system, the L2
230 * enable bit is in the ARMv6 ARM-mandated position
231 * (bit [26] of the System Control Register).
232 */
233 if (!(get_cr() & 0x04000000)) {
234 printk(KERN_INFO "Tauros2: Enabling L2 cache.\n");
235 adjust_cr(0x04000000, 0x04000000);
236 }
237
238 mode = "ARMv6";
239 outer_cache.inv_range = tauros2_inv_range;
240 outer_cache.clean_range = tauros2_clean_range;
241 outer_cache.flush_range = tauros2_flush_range;
Chao Xie89326f762012-05-07 11:23:59 +0800242 outer_cache.disable = tauros2_disable;
243 outer_cache.resume = tauros2_resume;
Lennert Buytenhek573a6522009-11-24 19:33:52 +0200244 }
245#endif
246
247#ifdef CONFIG_CPU_32v7
248 /*
249 * Check whether this CPU has support for the v7 hierarchical
250 * cache ops. (PJ4 is in its v7 personality mode if the MMFR3
251 * register indicates support for the v7 hierarchical cache
252 * ops.)
253 *
254 * (Although strictly speaking there may exist CPUs that
255 * implement the v7 cache ops but are only ARMv6 CPUs (due to
256 * not complying with all of the other ARMv7 requirements),
257 * there are no real-life examples of Tauros2 being used on
258 * such CPUs as of yet.)
259 */
260 if (cpuid_scheme() && (read_mmfr3() & 0xf) == 1) {
261 u32 actlr;
262
263 /*
264 * When Tauros2 is used in an ARMv7 system, the L2
265 * enable bit is located in the Auxiliary System Control
266 * Register (which is the only register allowed by the
267 * ARMv7 spec to contain fine-grained cache control bits).
268 */
269 actlr = read_actlr();
270 if (!(actlr & 0x00000002)) {
271 printk(KERN_INFO "Tauros2: Enabling L2 cache.\n");
272 write_actlr(actlr | 0x00000002);
273 }
274
275 mode = "ARMv7";
276 }
277#endif
278
279 if (mode == NULL) {
280 printk(KERN_CRIT "Tauros2: Unable to detect CPU mode.\n");
281 return;
282 }
283
284 printk(KERN_INFO "Tauros2: L2 cache support initialised "
285 "in %s mode.\n", mode);
286}