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 DEFINE_SPINLOCK(l2x0_lock);
31 static inline void cache_wait(void __iomem *reg, unsigned long mask)
33 /* wait for the operation to complete */
34 while (readl(reg) & mask)
38 static inline void cache_sync(void)
40 void __iomem *base = l2x0_base;
41 writel(0, base + L2X0_CACHE_SYNC);
42 cache_wait(base + L2X0_CACHE_SYNC, 1);
45 static inline void l2x0_clean_line(unsigned long addr)
47 void __iomem *base = l2x0_base;
48 cache_wait(base + L2X0_CLEAN_LINE_PA, 1);
49 writel(addr, base + L2X0_CLEAN_LINE_PA);
52 static inline void l2x0_inv_line(unsigned long addr)
54 void __iomem *base = l2x0_base;
55 cache_wait(base + L2X0_INV_LINE_PA, 1);
56 writel(addr, base + L2X0_INV_LINE_PA);
59 static inline void l2x0_flush_line(unsigned long addr)
61 void __iomem *base = l2x0_base;
62 cache_wait(base + L2X0_CLEAN_INV_LINE_PA, 1);
63 writel(addr, base + L2X0_CLEAN_INV_LINE_PA);
66 static inline void l2x0_inv_all(void)
70 /* invalidate all ways */
71 spin_lock_irqsave(&l2x0_lock, flags);
72 writel(0xff, l2x0_base + L2X0_INV_WAY);
73 cache_wait(l2x0_base + L2X0_INV_WAY, 0xff);
75 spin_unlock_irqrestore(&l2x0_lock, flags);
78 static void l2x0_inv_range(unsigned long start, unsigned long end)
80 void __iomem *base = l2x0_base;
83 spin_lock_irqsave(&l2x0_lock, flags);
84 if (start & (CACHE_LINE_SIZE - 1)) {
85 start &= ~(CACHE_LINE_SIZE - 1);
86 l2x0_flush_line(start);
87 start += CACHE_LINE_SIZE;
90 if (end & (CACHE_LINE_SIZE - 1)) {
91 end &= ~(CACHE_LINE_SIZE - 1);
96 unsigned long blk_end = start + min(end - start, 4096UL);
98 while (start < blk_end) {
100 start += CACHE_LINE_SIZE;
104 spin_unlock_irqrestore(&l2x0_lock, flags);
105 spin_lock_irqsave(&l2x0_lock, flags);
108 cache_wait(base + L2X0_INV_LINE_PA, 1);
110 spin_unlock_irqrestore(&l2x0_lock, flags);
113 static void l2x0_clean_range(unsigned long start, unsigned long end)
115 void __iomem *base = l2x0_base;
118 spin_lock_irqsave(&l2x0_lock, flags);
119 start &= ~(CACHE_LINE_SIZE - 1);
120 while (start < end) {
121 unsigned long blk_end = start + min(end - start, 4096UL);
123 while (start < blk_end) {
124 l2x0_clean_line(start);
125 start += CACHE_LINE_SIZE;
129 spin_unlock_irqrestore(&l2x0_lock, flags);
130 spin_lock_irqsave(&l2x0_lock, flags);
133 cache_wait(base + L2X0_CLEAN_LINE_PA, 1);
135 spin_unlock_irqrestore(&l2x0_lock, flags);
138 static void l2x0_flush_range(unsigned long start, unsigned long end)
140 void __iomem *base = l2x0_base;
143 spin_lock_irqsave(&l2x0_lock, flags);
144 start &= ~(CACHE_LINE_SIZE - 1);
145 while (start < end) {
146 unsigned long blk_end = start + min(end - start, 4096UL);
148 while (start < blk_end) {
149 l2x0_flush_line(start);
150 start += CACHE_LINE_SIZE;
154 spin_unlock_irqrestore(&l2x0_lock, flags);
155 spin_lock_irqsave(&l2x0_lock, flags);
158 cache_wait(base + L2X0_CLEAN_INV_LINE_PA, 1);
160 spin_unlock_irqrestore(&l2x0_lock, flags);
163 void __init l2x0_init(void __iomem *base, __u32 aux_val, __u32 aux_mask)
170 * Check if l2x0 controller is already enabled.
171 * If you are booting from non-secure mode
172 * accessing the below registers will fault.
174 if (!(readl(l2x0_base + L2X0_CTRL) & 1)) {
176 /* l2x0 controller is disabled */
178 aux = readl(l2x0_base + L2X0_AUX_CTRL);
181 writel(aux, l2x0_base + L2X0_AUX_CTRL);
186 writel(1, l2x0_base + L2X0_CTRL);
189 outer_cache.inv_range = l2x0_inv_range;
190 outer_cache.clean_range = l2x0_clean_range;
191 outer_cache.flush_range = l2x0_flush_range;
193 printk(KERN_INFO "L2X0 cache controller enabled\n");