2 * arch/arm/mm/cache-l2x0.c - L210/L220 cache controller support
4 * Copyright (C) 2007 ARM Limited
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 #include <linux/init.h>
20 #include <linux/spinlock.h>
23 #include <asm/cacheflush.h>
24 #include <asm/hardware/cache-l2x0.h>
26 #define CACHE_LINE_SIZE 32
28 static void __iomem *l2x0_base;
29 static uint32_t l2x0_way_mask; /* Bitmask of active ways */
32 static inline void cache_wait_always(void __iomem *reg, unsigned long mask)
34 /* wait for the operation to complete */
35 while (readl_relaxed(reg) & mask)
39 #ifdef CONFIG_CACHE_PL310
41 static inline void cache_wait(void __iomem *reg, unsigned long mask)
43 /* cache operations are atomic */
46 #define _l2x0_lock(lock, flags) ((void)(flags))
47 #define _l2x0_unlock(lock, flags) ((void)(flags))
49 #define block_end(start, end) (end)
51 #define L2CC_TYPE "PL310/L2C-310"
53 #else /* !CONFIG_CACHE_PL310 */
55 #define cache_wait cache_wait_always
57 static DEFINE_SPINLOCK(l2x0_lock);
58 #define _l2x0_lock(lock, flags) spin_lock_irqsave(lock, flags)
59 #define _l2x0_unlock(lock, flags) spin_unlock_irqrestore(lock, flags)
61 #define block_end(start, end) ((start) + min((end) - (start), 4096UL))
63 #define L2CC_TYPE "L2x0"
65 #endif /* CONFIG_CACHE_PL310 */
67 static inline void cache_sync(void)
69 void __iomem *base = l2x0_base;
70 writel_relaxed(0, base + L2X0_CACHE_SYNC);
71 cache_wait(base + L2X0_CACHE_SYNC, 1);
74 static inline void l2x0_clean_line(unsigned long addr)
76 void __iomem *base = l2x0_base;
77 cache_wait(base + L2X0_CLEAN_LINE_PA, 1);
78 writel_relaxed(addr, base + L2X0_CLEAN_LINE_PA);
81 static inline void l2x0_inv_line(unsigned long addr)
83 void __iomem *base = l2x0_base;
84 cache_wait(base + L2X0_INV_LINE_PA, 1);
85 writel_relaxed(addr, base + L2X0_INV_LINE_PA);
88 #ifdef CONFIG_PL310_ERRATA_588369
89 static void debug_writel(unsigned long val)
91 extern void omap_smc1(u32 fn, u32 arg);
94 * Texas Instrument secure monitor api to modify the
95 * PL310 Debug Control Register.
97 omap_smc1(0x100, val);
100 static inline void l2x0_flush_line(unsigned long addr)
102 void __iomem *base = l2x0_base;
104 /* Clean by PA followed by Invalidate by PA */
105 cache_wait(base + L2X0_CLEAN_LINE_PA, 1);
106 writel_relaxed(addr, base + L2X0_CLEAN_LINE_PA);
107 cache_wait(base + L2X0_INV_LINE_PA, 1);
108 writel_relaxed(addr, base + L2X0_INV_LINE_PA);
112 /* Optimised out for non-errata case */
113 static inline void debug_writel(unsigned long val)
117 static inline void l2x0_flush_line(unsigned long addr)
119 void __iomem *base = l2x0_base;
120 cache_wait(base + L2X0_CLEAN_INV_LINE_PA, 1);
121 writel_relaxed(addr, base + L2X0_CLEAN_INV_LINE_PA);
125 static void l2x0_cache_sync(void)
129 _l2x0_lock(&l2x0_lock, flags);
131 _l2x0_unlock(&l2x0_lock, flags);
134 static inline void l2x0_inv_all(void)
138 /* invalidate all ways */
139 _l2x0_lock(&l2x0_lock, flags);
140 writel_relaxed(l2x0_way_mask, l2x0_base + L2X0_INV_WAY);
141 cache_wait_always(l2x0_base + L2X0_INV_WAY, l2x0_way_mask);
143 _l2x0_unlock(&l2x0_lock, flags);
146 static inline void l2x0_flush_all(void)
151 _l2x0_lock(&l2x0_lock, flags);
152 writel(0xff, l2x0_base + L2X0_CLEAN_INV_WAY);
153 cache_wait_always(l2x0_base + L2X0_CLEAN_INV_WAY, 0xff);
155 _l2x0_unlock(&l2x0_lock, flags);
158 static void l2x0_inv_range(unsigned long start, unsigned long end)
160 void __iomem *base = l2x0_base;
163 _l2x0_lock(&l2x0_lock, flags);
164 if (start & (CACHE_LINE_SIZE - 1)) {
165 start &= ~(CACHE_LINE_SIZE - 1);
167 l2x0_flush_line(start);
169 start += CACHE_LINE_SIZE;
172 if (end & (CACHE_LINE_SIZE - 1)) {
173 end &= ~(CACHE_LINE_SIZE - 1);
175 l2x0_flush_line(end);
179 while (start < end) {
180 unsigned long blk_end = block_end(start, end);
182 while (start < blk_end) {
183 l2x0_inv_line(start);
184 start += CACHE_LINE_SIZE;
188 _l2x0_unlock(&l2x0_lock, flags);
189 _l2x0_lock(&l2x0_lock, flags);
192 cache_wait(base + L2X0_INV_LINE_PA, 1);
194 _l2x0_unlock(&l2x0_lock, flags);
197 static void l2x0_clean_range(unsigned long start, unsigned long end)
199 void __iomem *base = l2x0_base;
202 _l2x0_lock(&l2x0_lock, flags);
203 start &= ~(CACHE_LINE_SIZE - 1);
204 while (start < end) {
205 unsigned long blk_end = block_end(start, end);
207 while (start < blk_end) {
208 l2x0_clean_line(start);
209 start += CACHE_LINE_SIZE;
213 _l2x0_unlock(&l2x0_lock, flags);
214 _l2x0_lock(&l2x0_lock, flags);
217 cache_wait(base + L2X0_CLEAN_LINE_PA, 1);
219 _l2x0_unlock(&l2x0_lock, flags);
222 static void l2x0_flush_range(unsigned long start, unsigned long end)
224 void __iomem *base = l2x0_base;
227 _l2x0_lock(&l2x0_lock, flags);
228 start &= ~(CACHE_LINE_SIZE - 1);
229 while (start < end) {
230 unsigned long blk_end = block_end(start, end);
233 while (start < blk_end) {
234 l2x0_flush_line(start);
235 start += CACHE_LINE_SIZE;
240 _l2x0_unlock(&l2x0_lock, flags);
241 _l2x0_lock(&l2x0_lock, flags);
244 cache_wait(base + L2X0_CLEAN_INV_LINE_PA, 1);
246 _l2x0_unlock(&l2x0_lock, flags);
249 void l2x0_shutdown(void)
256 BUG_ON(num_online_cpus() > 1);
258 local_irq_save(flags);
260 if (readl(l2x0_base + L2X0_CTRL) & 1) {
262 /* lockdown all ways, all masters to prevent new line
263 * allocation during maintenance */
264 for (m=0; m<8; m++) {
265 writel(l2x0_way_mask,
266 l2x0_base + L2X0_LOCKDOWN_WAY_D + (m*8));
267 writel(l2x0_way_mask,
268 l2x0_base + L2X0_LOCKDOWN_WAY_I + (m*8));
271 writel(0, l2x0_base + L2X0_CTRL);
272 /* unlock cache ways */
273 for (m=0; m<8; m++) {
274 writel(0, l2x0_base + L2X0_LOCKDOWN_WAY_D + (m*8));
275 writel(0, l2x0_base + L2X0_LOCKDOWN_WAY_I + (m*8));
279 local_irq_restore(flags);
282 static void l2x0_enable(__u32 aux_val, __u32 aux_mask)
292 cache_id = readl_relaxed(l2x0_base + L2X0_CACHE_ID);
293 aux = readl_relaxed(l2x0_base + L2X0_AUX_CTRL);
298 /* Determine the number of ways */
299 switch (cache_id & L2X0_CACHE_ID_PART_MASK) {
300 case L2X0_CACHE_ID_PART_L310:
307 case L2X0_CACHE_ID_PART_L210:
308 ways = (aux >> 13) & 0xf;
312 /* Assume unknown chips have 8 ways */
314 type = "L2x0 series";
318 l2x0_way_mask = (1 << ways) - 1;
321 * Check if l2x0 controller is already enabled.
322 * If you are booting from non-secure mode
323 * accessing the below registers will fault.
325 if (!(readl_relaxed(l2x0_base + L2X0_CTRL) & 1)) {
327 /* l2x0 controller is disabled */
328 writel_relaxed(aux, l2x0_base + L2X0_AUX_CTRL);
333 writel_relaxed(1, l2x0_base + L2X0_CTRL);
336 /*printk(KERN_INFO "%s cache controller enabled\n", type);
337 printk(KERN_INFO "l2x0: %d ways, CACHE_ID 0x%08x, AUX_CTRL 0x%08x\n",
338 ways, cache_id, aux);*/
341 void l2x0_restart(void)
343 l2x0_enable(0, ~0ul);
346 void __init l2x0_init(void __iomem *base, __u32 aux_val, __u32 aux_mask)
349 pr_info(L2CC_TYPE " cache controller disabled\n");
355 l2x0_enable(aux_val, aux_mask);
357 outer_cache.inv_range = l2x0_inv_range;
358 outer_cache.clean_range = l2x0_clean_range;
359 outer_cache.flush_range = l2x0_flush_range;
360 outer_cache.sync = l2x0_cache_sync;
363 static int __init l2x0_disable(char *unused)
368 early_param("nol2x0", l2x0_disable);