Catalin Marinas | 382266a | 2007-02-05 14:48:19 +0100 | [diff] [blame] | 1 | /* |
| 2 | * arch/arm/mm/cache-l2x0.c - L210/L220 cache controller support |
| 3 | * |
| 4 | * Copyright (C) 2007 ARM Limited |
| 5 | * |
| 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. |
| 9 | * |
| 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. |
| 14 | * |
| 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 |
| 18 | */ |
Rob Herring | 8c36926 | 2011-08-03 18:12:05 +0100 | [diff] [blame] | 19 | #include <linux/err.h> |
Catalin Marinas | 382266a | 2007-02-05 14:48:19 +0100 | [diff] [blame] | 20 | #include <linux/init.h> |
Catalin Marinas | 0762097 | 2007-07-20 11:42:40 +0100 | [diff] [blame] | 21 | #include <linux/spinlock.h> |
Russell King | fced80c | 2008-09-06 12:10:45 +0100 | [diff] [blame] | 22 | #include <linux/io.h> |
Rob Herring | 8c36926 | 2011-08-03 18:12:05 +0100 | [diff] [blame] | 23 | #include <linux/of.h> |
| 24 | #include <linux/of_address.h> |
Catalin Marinas | 382266a | 2007-02-05 14:48:19 +0100 | [diff] [blame] | 25 | |
| 26 | #include <asm/cacheflush.h> |
Catalin Marinas | 382266a | 2007-02-05 14:48:19 +0100 | [diff] [blame] | 27 | #include <asm/hardware/cache-l2x0.h> |
| 28 | |
| 29 | #define CACHE_LINE_SIZE 32 |
| 30 | |
| 31 | static void __iomem *l2x0_base; |
Catalin Marinas | 0762097 | 2007-07-20 11:42:40 +0100 | [diff] [blame] | 32 | static DEFINE_SPINLOCK(l2x0_lock); |
Jason McMullan | 64039be | 2010-05-05 18:59:37 +0100 | [diff] [blame] | 33 | static uint32_t l2x0_way_mask; /* Bitmask of active ways */ |
Santosh Shilimkar | 5ba7037 | 2010-07-11 14:35:37 +0530 | [diff] [blame] | 34 | static uint32_t l2x0_size; |
Catalin Marinas | 382266a | 2007-02-05 14:48:19 +0100 | [diff] [blame] | 35 | |
Catalin Marinas | 9a6655e | 2010-08-31 13:05:22 +0100 | [diff] [blame] | 36 | static inline void cache_wait_way(void __iomem *reg, unsigned long mask) |
Catalin Marinas | 382266a | 2007-02-05 14:48:19 +0100 | [diff] [blame] | 37 | { |
Catalin Marinas | 9a6655e | 2010-08-31 13:05:22 +0100 | [diff] [blame] | 38 | /* wait for cache operation by line or way to complete */ |
Catalin Marinas | 6775a55 | 2010-07-28 22:01:25 +0100 | [diff] [blame] | 39 | while (readl_relaxed(reg) & mask) |
Barry Song | 1caf309 | 2011-09-09 10:30:34 +0100 | [diff] [blame] | 40 | cpu_relax(); |
Catalin Marinas | 382266a | 2007-02-05 14:48:19 +0100 | [diff] [blame] | 41 | } |
| 42 | |
Catalin Marinas | 9a6655e | 2010-08-31 13:05:22 +0100 | [diff] [blame] | 43 | #ifdef CONFIG_CACHE_PL310 |
| 44 | static inline void cache_wait(void __iomem *reg, unsigned long mask) |
| 45 | { |
| 46 | /* cache operations by line are atomic on PL310 */ |
| 47 | } |
| 48 | #else |
| 49 | #define cache_wait cache_wait_way |
| 50 | #endif |
| 51 | |
Catalin Marinas | 382266a | 2007-02-05 14:48:19 +0100 | [diff] [blame] | 52 | static inline void cache_sync(void) |
| 53 | { |
Russell King | 3d10743 | 2009-11-19 11:41:09 +0000 | [diff] [blame] | 54 | void __iomem *base = l2x0_base; |
Srinidhi Kasagar | 885028e | 2011-02-17 07:03:51 +0100 | [diff] [blame] | 55 | |
| 56 | #ifdef CONFIG_ARM_ERRATA_753970 |
| 57 | /* write to an unmmapped register */ |
| 58 | writel_relaxed(0, base + L2X0_DUMMY_REG); |
| 59 | #else |
Catalin Marinas | 6775a55 | 2010-07-28 22:01:25 +0100 | [diff] [blame] | 60 | writel_relaxed(0, base + L2X0_CACHE_SYNC); |
Srinidhi Kasagar | 885028e | 2011-02-17 07:03:51 +0100 | [diff] [blame] | 61 | #endif |
Russell King | 3d10743 | 2009-11-19 11:41:09 +0000 | [diff] [blame] | 62 | cache_wait(base + L2X0_CACHE_SYNC, 1); |
Catalin Marinas | 382266a | 2007-02-05 14:48:19 +0100 | [diff] [blame] | 63 | } |
| 64 | |
Santosh Shilimkar | 424d6b1 | 2010-02-04 19:35:06 +0100 | [diff] [blame] | 65 | static inline void l2x0_clean_line(unsigned long addr) |
| 66 | { |
| 67 | void __iomem *base = l2x0_base; |
| 68 | cache_wait(base + L2X0_CLEAN_LINE_PA, 1); |
Catalin Marinas | 6775a55 | 2010-07-28 22:01:25 +0100 | [diff] [blame] | 69 | writel_relaxed(addr, base + L2X0_CLEAN_LINE_PA); |
Santosh Shilimkar | 424d6b1 | 2010-02-04 19:35:06 +0100 | [diff] [blame] | 70 | } |
| 71 | |
| 72 | static inline void l2x0_inv_line(unsigned long addr) |
| 73 | { |
| 74 | void __iomem *base = l2x0_base; |
| 75 | cache_wait(base + L2X0_INV_LINE_PA, 1); |
Catalin Marinas | 6775a55 | 2010-07-28 22:01:25 +0100 | [diff] [blame] | 76 | writel_relaxed(addr, base + L2X0_INV_LINE_PA); |
Santosh Shilimkar | 424d6b1 | 2010-02-04 19:35:06 +0100 | [diff] [blame] | 77 | } |
| 78 | |
Santosh Shilimkar | 2839e06 | 2011-03-08 06:59:54 +0100 | [diff] [blame] | 79 | #if defined(CONFIG_PL310_ERRATA_588369) || defined(CONFIG_PL310_ERRATA_727915) |
Santosh Shilimkar | 9e65582 | 2010-02-04 19:42:42 +0100 | [diff] [blame] | 80 | |
Santosh Shilimkar | 2839e06 | 2011-03-08 06:59:54 +0100 | [diff] [blame] | 81 | #define debug_writel(val) outer_cache.set_debug(val) |
| 82 | |
| 83 | static void l2x0_set_debug(unsigned long val) |
| 84 | { |
| 85 | writel_relaxed(val, l2x0_base + L2X0_DEBUG_CTRL); |
| 86 | } |
| 87 | #else |
| 88 | /* Optimised out for non-errata case */ |
| 89 | static inline void debug_writel(unsigned long val) |
| 90 | { |
Santosh Shilimkar | 9e65582 | 2010-02-04 19:42:42 +0100 | [diff] [blame] | 91 | } |
| 92 | |
Santosh Shilimkar | 2839e06 | 2011-03-08 06:59:54 +0100 | [diff] [blame] | 93 | #define l2x0_set_debug NULL |
| 94 | #endif |
| 95 | |
| 96 | #ifdef CONFIG_PL310_ERRATA_588369 |
Santosh Shilimkar | 9e65582 | 2010-02-04 19:42:42 +0100 | [diff] [blame] | 97 | static inline void l2x0_flush_line(unsigned long addr) |
| 98 | { |
| 99 | void __iomem *base = l2x0_base; |
| 100 | |
| 101 | /* Clean by PA followed by Invalidate by PA */ |
| 102 | cache_wait(base + L2X0_CLEAN_LINE_PA, 1); |
Catalin Marinas | 6775a55 | 2010-07-28 22:01:25 +0100 | [diff] [blame] | 103 | writel_relaxed(addr, base + L2X0_CLEAN_LINE_PA); |
Santosh Shilimkar | 9e65582 | 2010-02-04 19:42:42 +0100 | [diff] [blame] | 104 | cache_wait(base + L2X0_INV_LINE_PA, 1); |
Catalin Marinas | 6775a55 | 2010-07-28 22:01:25 +0100 | [diff] [blame] | 105 | writel_relaxed(addr, base + L2X0_INV_LINE_PA); |
Santosh Shilimkar | 9e65582 | 2010-02-04 19:42:42 +0100 | [diff] [blame] | 106 | } |
| 107 | #else |
| 108 | |
Santosh Shilimkar | 424d6b1 | 2010-02-04 19:35:06 +0100 | [diff] [blame] | 109 | static inline void l2x0_flush_line(unsigned long addr) |
| 110 | { |
| 111 | void __iomem *base = l2x0_base; |
| 112 | cache_wait(base + L2X0_CLEAN_INV_LINE_PA, 1); |
Catalin Marinas | 6775a55 | 2010-07-28 22:01:25 +0100 | [diff] [blame] | 113 | writel_relaxed(addr, base + L2X0_CLEAN_INV_LINE_PA); |
Santosh Shilimkar | 424d6b1 | 2010-02-04 19:35:06 +0100 | [diff] [blame] | 114 | } |
Santosh Shilimkar | 9e65582 | 2010-02-04 19:42:42 +0100 | [diff] [blame] | 115 | #endif |
Santosh Shilimkar | 424d6b1 | 2010-02-04 19:35:06 +0100 | [diff] [blame] | 116 | |
Catalin Marinas | 23107c5 | 2010-03-24 16:48:53 +0100 | [diff] [blame] | 117 | static void l2x0_cache_sync(void) |
| 118 | { |
| 119 | unsigned long flags; |
| 120 | |
| 121 | spin_lock_irqsave(&l2x0_lock, flags); |
| 122 | cache_sync(); |
| 123 | spin_unlock_irqrestore(&l2x0_lock, flags); |
| 124 | } |
| 125 | |
Will Deacon | 38a8914 | 2011-07-01 14:36:19 +0100 | [diff] [blame] | 126 | static void __l2x0_flush_all(void) |
| 127 | { |
| 128 | debug_writel(0x03); |
| 129 | writel_relaxed(l2x0_way_mask, l2x0_base + L2X0_CLEAN_INV_WAY); |
| 130 | cache_wait_way(l2x0_base + L2X0_CLEAN_INV_WAY, l2x0_way_mask); |
| 131 | cache_sync(); |
| 132 | debug_writel(0x00); |
| 133 | } |
| 134 | |
Thomas Gleixner | 2fd8658 | 2010-07-31 21:05:24 +0530 | [diff] [blame] | 135 | static void l2x0_flush_all(void) |
| 136 | { |
| 137 | unsigned long flags; |
| 138 | |
| 139 | /* clean all ways */ |
| 140 | spin_lock_irqsave(&l2x0_lock, flags); |
Will Deacon | 38a8914 | 2011-07-01 14:36:19 +0100 | [diff] [blame] | 141 | __l2x0_flush_all(); |
Thomas Gleixner | 2fd8658 | 2010-07-31 21:05:24 +0530 | [diff] [blame] | 142 | spin_unlock_irqrestore(&l2x0_lock, flags); |
| 143 | } |
| 144 | |
Santosh Shilimkar | 444457c | 2010-07-11 14:58:41 +0530 | [diff] [blame] | 145 | static void l2x0_clean_all(void) |
| 146 | { |
| 147 | unsigned long flags; |
| 148 | |
| 149 | /* clean all ways */ |
| 150 | spin_lock_irqsave(&l2x0_lock, flags); |
| 151 | writel_relaxed(l2x0_way_mask, l2x0_base + L2X0_CLEAN_WAY); |
| 152 | cache_wait_way(l2x0_base + L2X0_CLEAN_WAY, l2x0_way_mask); |
| 153 | cache_sync(); |
| 154 | spin_unlock_irqrestore(&l2x0_lock, flags); |
| 155 | } |
| 156 | |
Thomas Gleixner | 2fd8658 | 2010-07-31 21:05:24 +0530 | [diff] [blame] | 157 | static void l2x0_inv_all(void) |
Catalin Marinas | 382266a | 2007-02-05 14:48:19 +0100 | [diff] [blame] | 158 | { |
Russell King | 0eb948d | 2009-11-19 11:12:15 +0000 | [diff] [blame] | 159 | unsigned long flags; |
| 160 | |
Catalin Marinas | 382266a | 2007-02-05 14:48:19 +0100 | [diff] [blame] | 161 | /* invalidate all ways */ |
Russell King | 0eb948d | 2009-11-19 11:12:15 +0000 | [diff] [blame] | 162 | spin_lock_irqsave(&l2x0_lock, flags); |
Thomas Gleixner | 2fd8658 | 2010-07-31 21:05:24 +0530 | [diff] [blame] | 163 | /* Invalidating when L2 is enabled is a nono */ |
| 164 | BUG_ON(readl(l2x0_base + L2X0_CTRL) & 1); |
Catalin Marinas | 6775a55 | 2010-07-28 22:01:25 +0100 | [diff] [blame] | 165 | writel_relaxed(l2x0_way_mask, l2x0_base + L2X0_INV_WAY); |
Catalin Marinas | 9a6655e | 2010-08-31 13:05:22 +0100 | [diff] [blame] | 166 | cache_wait_way(l2x0_base + L2X0_INV_WAY, l2x0_way_mask); |
Catalin Marinas | 382266a | 2007-02-05 14:48:19 +0100 | [diff] [blame] | 167 | cache_sync(); |
Russell King | 0eb948d | 2009-11-19 11:12:15 +0000 | [diff] [blame] | 168 | spin_unlock_irqrestore(&l2x0_lock, flags); |
Catalin Marinas | 382266a | 2007-02-05 14:48:19 +0100 | [diff] [blame] | 169 | } |
| 170 | |
| 171 | static void l2x0_inv_range(unsigned long start, unsigned long end) |
| 172 | { |
Russell King | 3d10743 | 2009-11-19 11:41:09 +0000 | [diff] [blame] | 173 | void __iomem *base = l2x0_base; |
Russell King | 0eb948d | 2009-11-19 11:12:15 +0000 | [diff] [blame] | 174 | unsigned long flags; |
Catalin Marinas | 382266a | 2007-02-05 14:48:19 +0100 | [diff] [blame] | 175 | |
Russell King | 0eb948d | 2009-11-19 11:12:15 +0000 | [diff] [blame] | 176 | spin_lock_irqsave(&l2x0_lock, flags); |
Rui Sousa | 4f6627a | 2007-09-15 00:56:19 +0100 | [diff] [blame] | 177 | if (start & (CACHE_LINE_SIZE - 1)) { |
| 178 | start &= ~(CACHE_LINE_SIZE - 1); |
Santosh Shilimkar | 9e65582 | 2010-02-04 19:42:42 +0100 | [diff] [blame] | 179 | debug_writel(0x03); |
Santosh Shilimkar | 424d6b1 | 2010-02-04 19:35:06 +0100 | [diff] [blame] | 180 | l2x0_flush_line(start); |
Santosh Shilimkar | 9e65582 | 2010-02-04 19:42:42 +0100 | [diff] [blame] | 181 | debug_writel(0x00); |
Rui Sousa | 4f6627a | 2007-09-15 00:56:19 +0100 | [diff] [blame] | 182 | start += CACHE_LINE_SIZE; |
| 183 | } |
| 184 | |
| 185 | if (end & (CACHE_LINE_SIZE - 1)) { |
| 186 | end &= ~(CACHE_LINE_SIZE - 1); |
Santosh Shilimkar | 9e65582 | 2010-02-04 19:42:42 +0100 | [diff] [blame] | 187 | debug_writel(0x03); |
Santosh Shilimkar | 424d6b1 | 2010-02-04 19:35:06 +0100 | [diff] [blame] | 188 | l2x0_flush_line(end); |
Santosh Shilimkar | 9e65582 | 2010-02-04 19:42:42 +0100 | [diff] [blame] | 189 | debug_writel(0x00); |
Rui Sousa | 4f6627a | 2007-09-15 00:56:19 +0100 | [diff] [blame] | 190 | } |
| 191 | |
Russell King | 0eb948d | 2009-11-19 11:12:15 +0000 | [diff] [blame] | 192 | while (start < end) { |
| 193 | unsigned long blk_end = start + min(end - start, 4096UL); |
| 194 | |
| 195 | while (start < blk_end) { |
Santosh Shilimkar | 424d6b1 | 2010-02-04 19:35:06 +0100 | [diff] [blame] | 196 | l2x0_inv_line(start); |
Russell King | 0eb948d | 2009-11-19 11:12:15 +0000 | [diff] [blame] | 197 | start += CACHE_LINE_SIZE; |
| 198 | } |
| 199 | |
| 200 | if (blk_end < end) { |
| 201 | spin_unlock_irqrestore(&l2x0_lock, flags); |
| 202 | spin_lock_irqsave(&l2x0_lock, flags); |
| 203 | } |
| 204 | } |
Russell King | 3d10743 | 2009-11-19 11:41:09 +0000 | [diff] [blame] | 205 | cache_wait(base + L2X0_INV_LINE_PA, 1); |
Catalin Marinas | 382266a | 2007-02-05 14:48:19 +0100 | [diff] [blame] | 206 | cache_sync(); |
Russell King | 0eb948d | 2009-11-19 11:12:15 +0000 | [diff] [blame] | 207 | spin_unlock_irqrestore(&l2x0_lock, flags); |
Catalin Marinas | 382266a | 2007-02-05 14:48:19 +0100 | [diff] [blame] | 208 | } |
| 209 | |
| 210 | static void l2x0_clean_range(unsigned long start, unsigned long end) |
| 211 | { |
Russell King | 3d10743 | 2009-11-19 11:41:09 +0000 | [diff] [blame] | 212 | void __iomem *base = l2x0_base; |
Russell King | 0eb948d | 2009-11-19 11:12:15 +0000 | [diff] [blame] | 213 | unsigned long flags; |
Catalin Marinas | 382266a | 2007-02-05 14:48:19 +0100 | [diff] [blame] | 214 | |
Santosh Shilimkar | 444457c | 2010-07-11 14:58:41 +0530 | [diff] [blame] | 215 | if ((end - start) >= l2x0_size) { |
| 216 | l2x0_clean_all(); |
| 217 | return; |
| 218 | } |
| 219 | |
Russell King | 0eb948d | 2009-11-19 11:12:15 +0000 | [diff] [blame] | 220 | spin_lock_irqsave(&l2x0_lock, flags); |
Catalin Marinas | 382266a | 2007-02-05 14:48:19 +0100 | [diff] [blame] | 221 | start &= ~(CACHE_LINE_SIZE - 1); |
Russell King | 0eb948d | 2009-11-19 11:12:15 +0000 | [diff] [blame] | 222 | while (start < end) { |
| 223 | unsigned long blk_end = start + min(end - start, 4096UL); |
| 224 | |
| 225 | while (start < blk_end) { |
Santosh Shilimkar | 424d6b1 | 2010-02-04 19:35:06 +0100 | [diff] [blame] | 226 | l2x0_clean_line(start); |
Russell King | 0eb948d | 2009-11-19 11:12:15 +0000 | [diff] [blame] | 227 | start += CACHE_LINE_SIZE; |
| 228 | } |
| 229 | |
| 230 | if (blk_end < end) { |
| 231 | spin_unlock_irqrestore(&l2x0_lock, flags); |
| 232 | spin_lock_irqsave(&l2x0_lock, flags); |
| 233 | } |
| 234 | } |
Russell King | 3d10743 | 2009-11-19 11:41:09 +0000 | [diff] [blame] | 235 | cache_wait(base + L2X0_CLEAN_LINE_PA, 1); |
Catalin Marinas | 382266a | 2007-02-05 14:48:19 +0100 | [diff] [blame] | 236 | cache_sync(); |
Russell King | 0eb948d | 2009-11-19 11:12:15 +0000 | [diff] [blame] | 237 | spin_unlock_irqrestore(&l2x0_lock, flags); |
Catalin Marinas | 382266a | 2007-02-05 14:48:19 +0100 | [diff] [blame] | 238 | } |
| 239 | |
| 240 | static void l2x0_flush_range(unsigned long start, unsigned long end) |
| 241 | { |
Russell King | 3d10743 | 2009-11-19 11:41:09 +0000 | [diff] [blame] | 242 | void __iomem *base = l2x0_base; |
Russell King | 0eb948d | 2009-11-19 11:12:15 +0000 | [diff] [blame] | 243 | unsigned long flags; |
Catalin Marinas | 382266a | 2007-02-05 14:48:19 +0100 | [diff] [blame] | 244 | |
Santosh Shilimkar | 444457c | 2010-07-11 14:58:41 +0530 | [diff] [blame] | 245 | if ((end - start) >= l2x0_size) { |
| 246 | l2x0_flush_all(); |
| 247 | return; |
| 248 | } |
| 249 | |
Russell King | 0eb948d | 2009-11-19 11:12:15 +0000 | [diff] [blame] | 250 | spin_lock_irqsave(&l2x0_lock, flags); |
Catalin Marinas | 382266a | 2007-02-05 14:48:19 +0100 | [diff] [blame] | 251 | start &= ~(CACHE_LINE_SIZE - 1); |
Russell King | 0eb948d | 2009-11-19 11:12:15 +0000 | [diff] [blame] | 252 | while (start < end) { |
| 253 | unsigned long blk_end = start + min(end - start, 4096UL); |
| 254 | |
Santosh Shilimkar | 9e65582 | 2010-02-04 19:42:42 +0100 | [diff] [blame] | 255 | debug_writel(0x03); |
Russell King | 0eb948d | 2009-11-19 11:12:15 +0000 | [diff] [blame] | 256 | while (start < blk_end) { |
Santosh Shilimkar | 424d6b1 | 2010-02-04 19:35:06 +0100 | [diff] [blame] | 257 | l2x0_flush_line(start); |
Russell King | 0eb948d | 2009-11-19 11:12:15 +0000 | [diff] [blame] | 258 | start += CACHE_LINE_SIZE; |
| 259 | } |
Santosh Shilimkar | 9e65582 | 2010-02-04 19:42:42 +0100 | [diff] [blame] | 260 | debug_writel(0x00); |
Russell King | 0eb948d | 2009-11-19 11:12:15 +0000 | [diff] [blame] | 261 | |
| 262 | if (blk_end < end) { |
| 263 | spin_unlock_irqrestore(&l2x0_lock, flags); |
| 264 | spin_lock_irqsave(&l2x0_lock, flags); |
| 265 | } |
| 266 | } |
Russell King | 3d10743 | 2009-11-19 11:41:09 +0000 | [diff] [blame] | 267 | cache_wait(base + L2X0_CLEAN_INV_LINE_PA, 1); |
Catalin Marinas | 382266a | 2007-02-05 14:48:19 +0100 | [diff] [blame] | 268 | cache_sync(); |
Russell King | 0eb948d | 2009-11-19 11:12:15 +0000 | [diff] [blame] | 269 | spin_unlock_irqrestore(&l2x0_lock, flags); |
Catalin Marinas | 382266a | 2007-02-05 14:48:19 +0100 | [diff] [blame] | 270 | } |
| 271 | |
Thomas Gleixner | 2fd8658 | 2010-07-31 21:05:24 +0530 | [diff] [blame] | 272 | static void l2x0_disable(void) |
| 273 | { |
| 274 | unsigned long flags; |
| 275 | |
| 276 | spin_lock_irqsave(&l2x0_lock, flags); |
Will Deacon | 38a8914 | 2011-07-01 14:36:19 +0100 | [diff] [blame] | 277 | __l2x0_flush_all(); |
| 278 | writel_relaxed(0, l2x0_base + L2X0_CTRL); |
| 279 | dsb(); |
Thomas Gleixner | 2fd8658 | 2010-07-31 21:05:24 +0530 | [diff] [blame] | 280 | spin_unlock_irqrestore(&l2x0_lock, flags); |
| 281 | } |
| 282 | |
Linus Walleij | bac7e6e | 2011-09-06 07:45:46 +0100 | [diff] [blame] | 283 | static void __init l2x0_unlock(__u32 cache_id) |
| 284 | { |
| 285 | int lockregs; |
| 286 | int i; |
| 287 | |
| 288 | if (cache_id == L2X0_CACHE_ID_PART_L310) |
| 289 | lockregs = 8; |
| 290 | else |
| 291 | /* L210 and unknown types */ |
| 292 | lockregs = 1; |
| 293 | |
| 294 | for (i = 0; i < lockregs; i++) { |
| 295 | writel_relaxed(0x0, l2x0_base + L2X0_LOCKDOWN_WAY_D_BASE + |
| 296 | i * L2X0_LOCKDOWN_STRIDE); |
| 297 | writel_relaxed(0x0, l2x0_base + L2X0_LOCKDOWN_WAY_I_BASE + |
| 298 | i * L2X0_LOCKDOWN_STRIDE); |
| 299 | } |
| 300 | } |
| 301 | |
Catalin Marinas | 382266a | 2007-02-05 14:48:19 +0100 | [diff] [blame] | 302 | void __init l2x0_init(void __iomem *base, __u32 aux_val, __u32 aux_mask) |
| 303 | { |
| 304 | __u32 aux; |
Jason McMullan | 64039be | 2010-05-05 18:59:37 +0100 | [diff] [blame] | 305 | __u32 cache_id; |
Santosh Shilimkar | 5ba7037 | 2010-07-11 14:35:37 +0530 | [diff] [blame] | 306 | __u32 way_size = 0; |
Jason McMullan | 64039be | 2010-05-05 18:59:37 +0100 | [diff] [blame] | 307 | int ways; |
| 308 | const char *type; |
Catalin Marinas | 382266a | 2007-02-05 14:48:19 +0100 | [diff] [blame] | 309 | |
| 310 | l2x0_base = base; |
| 311 | |
Catalin Marinas | 6775a55 | 2010-07-28 22:01:25 +0100 | [diff] [blame] | 312 | cache_id = readl_relaxed(l2x0_base + L2X0_CACHE_ID); |
| 313 | aux = readl_relaxed(l2x0_base + L2X0_AUX_CTRL); |
Jason McMullan | 64039be | 2010-05-05 18:59:37 +0100 | [diff] [blame] | 314 | |
Sascha Hauer | 4082cfa | 2010-07-08 08:36:21 +0100 | [diff] [blame] | 315 | aux &= aux_mask; |
| 316 | aux |= aux_val; |
| 317 | |
Jason McMullan | 64039be | 2010-05-05 18:59:37 +0100 | [diff] [blame] | 318 | /* Determine the number of ways */ |
| 319 | switch (cache_id & L2X0_CACHE_ID_PART_MASK) { |
| 320 | case L2X0_CACHE_ID_PART_L310: |
| 321 | if (aux & (1 << 16)) |
| 322 | ways = 16; |
| 323 | else |
| 324 | ways = 8; |
| 325 | type = "L310"; |
| 326 | break; |
| 327 | case L2X0_CACHE_ID_PART_L210: |
| 328 | ways = (aux >> 13) & 0xf; |
| 329 | type = "L210"; |
| 330 | break; |
| 331 | default: |
| 332 | /* Assume unknown chips have 8 ways */ |
| 333 | ways = 8; |
| 334 | type = "L2x0 series"; |
| 335 | break; |
| 336 | } |
| 337 | |
| 338 | l2x0_way_mask = (1 << ways) - 1; |
| 339 | |
Srinidhi Kasagar | 48371cd | 2009-12-02 06:18:03 +0100 | [diff] [blame] | 340 | /* |
Santosh Shilimkar | 5ba7037 | 2010-07-11 14:35:37 +0530 | [diff] [blame] | 341 | * L2 cache Size = Way size * Number of ways |
| 342 | */ |
| 343 | way_size = (aux & L2X0_AUX_CTRL_WAY_SIZE_MASK) >> 17; |
| 344 | way_size = 1 << (way_size + 3); |
| 345 | l2x0_size = ways * way_size * SZ_1K; |
| 346 | |
| 347 | /* |
Srinidhi Kasagar | 48371cd | 2009-12-02 06:18:03 +0100 | [diff] [blame] | 348 | * Check if l2x0 controller is already enabled. |
| 349 | * If you are booting from non-secure mode |
| 350 | * accessing the below registers will fault. |
| 351 | */ |
Catalin Marinas | 6775a55 | 2010-07-28 22:01:25 +0100 | [diff] [blame] | 352 | if (!(readl_relaxed(l2x0_base + L2X0_CTRL) & 1)) { |
Linus Walleij | bac7e6e | 2011-09-06 07:45:46 +0100 | [diff] [blame] | 353 | /* Make sure that I&D is not locked down when starting */ |
| 354 | l2x0_unlock(cache_id); |
Catalin Marinas | 382266a | 2007-02-05 14:48:19 +0100 | [diff] [blame] | 355 | |
Srinidhi Kasagar | 48371cd | 2009-12-02 06:18:03 +0100 | [diff] [blame] | 356 | /* l2x0 controller is disabled */ |
Catalin Marinas | 6775a55 | 2010-07-28 22:01:25 +0100 | [diff] [blame] | 357 | writel_relaxed(aux, l2x0_base + L2X0_AUX_CTRL); |
Catalin Marinas | 382266a | 2007-02-05 14:48:19 +0100 | [diff] [blame] | 358 | |
Srinidhi Kasagar | 48371cd | 2009-12-02 06:18:03 +0100 | [diff] [blame] | 359 | l2x0_inv_all(); |
| 360 | |
| 361 | /* enable L2X0 */ |
Catalin Marinas | 6775a55 | 2010-07-28 22:01:25 +0100 | [diff] [blame] | 362 | writel_relaxed(1, l2x0_base + L2X0_CTRL); |
Srinidhi Kasagar | 48371cd | 2009-12-02 06:18:03 +0100 | [diff] [blame] | 363 | } |
Catalin Marinas | 382266a | 2007-02-05 14:48:19 +0100 | [diff] [blame] | 364 | |
| 365 | outer_cache.inv_range = l2x0_inv_range; |
| 366 | outer_cache.clean_range = l2x0_clean_range; |
| 367 | outer_cache.flush_range = l2x0_flush_range; |
Catalin Marinas | 23107c5 | 2010-03-24 16:48:53 +0100 | [diff] [blame] | 368 | outer_cache.sync = l2x0_cache_sync; |
Thomas Gleixner | 2fd8658 | 2010-07-31 21:05:24 +0530 | [diff] [blame] | 369 | outer_cache.flush_all = l2x0_flush_all; |
| 370 | outer_cache.inv_all = l2x0_inv_all; |
| 371 | outer_cache.disable = l2x0_disable; |
Santosh Shilimkar | 2839e06 | 2011-03-08 06:59:54 +0100 | [diff] [blame] | 372 | outer_cache.set_debug = l2x0_set_debug; |
Catalin Marinas | 382266a | 2007-02-05 14:48:19 +0100 | [diff] [blame] | 373 | |
Jason McMullan | 64039be | 2010-05-05 18:59:37 +0100 | [diff] [blame] | 374 | printk(KERN_INFO "%s cache controller enabled\n", type); |
Santosh Shilimkar | 5ba7037 | 2010-07-11 14:35:37 +0530 | [diff] [blame] | 375 | printk(KERN_INFO "l2x0: %d ways, CACHE_ID 0x%08x, AUX_CTRL 0x%08x, Cache size: %d B\n", |
| 376 | ways, cache_id, aux, l2x0_size); |
Catalin Marinas | 382266a | 2007-02-05 14:48:19 +0100 | [diff] [blame] | 377 | } |
Rob Herring | 8c36926 | 2011-08-03 18:12:05 +0100 | [diff] [blame] | 378 | |
| 379 | #ifdef CONFIG_OF |
| 380 | static void __init l2x0_of_setup(const struct device_node *np, |
| 381 | __u32 *aux_val, __u32 *aux_mask) |
| 382 | { |
| 383 | u32 data[2] = { 0, 0 }; |
| 384 | u32 tag = 0; |
| 385 | u32 dirty = 0; |
| 386 | u32 val = 0, mask = 0; |
| 387 | |
| 388 | of_property_read_u32(np, "arm,tag-latency", &tag); |
| 389 | if (tag) { |
| 390 | mask |= L2X0_AUX_CTRL_TAG_LATENCY_MASK; |
| 391 | val |= (tag - 1) << L2X0_AUX_CTRL_TAG_LATENCY_SHIFT; |
| 392 | } |
| 393 | |
| 394 | of_property_read_u32_array(np, "arm,data-latency", |
| 395 | data, ARRAY_SIZE(data)); |
| 396 | if (data[0] && data[1]) { |
| 397 | mask |= L2X0_AUX_CTRL_DATA_RD_LATENCY_MASK | |
| 398 | L2X0_AUX_CTRL_DATA_WR_LATENCY_MASK; |
| 399 | val |= ((data[0] - 1) << L2X0_AUX_CTRL_DATA_RD_LATENCY_SHIFT) | |
| 400 | ((data[1] - 1) << L2X0_AUX_CTRL_DATA_WR_LATENCY_SHIFT); |
| 401 | } |
| 402 | |
| 403 | of_property_read_u32(np, "arm,dirty-latency", &dirty); |
| 404 | if (dirty) { |
| 405 | mask |= L2X0_AUX_CTRL_DIRTY_LATENCY_MASK; |
| 406 | val |= (dirty - 1) << L2X0_AUX_CTRL_DIRTY_LATENCY_SHIFT; |
| 407 | } |
| 408 | |
| 409 | *aux_val &= ~mask; |
| 410 | *aux_val |= val; |
| 411 | *aux_mask &= ~mask; |
| 412 | } |
| 413 | |
| 414 | static void __init pl310_of_setup(const struct device_node *np, |
| 415 | __u32 *aux_val, __u32 *aux_mask) |
| 416 | { |
| 417 | u32 data[3] = { 0, 0, 0 }; |
| 418 | u32 tag[3] = { 0, 0, 0 }; |
| 419 | u32 filter[2] = { 0, 0 }; |
| 420 | |
| 421 | of_property_read_u32_array(np, "arm,tag-latency", tag, ARRAY_SIZE(tag)); |
| 422 | if (tag[0] && tag[1] && tag[2]) |
| 423 | writel_relaxed( |
| 424 | ((tag[0] - 1) << L2X0_LATENCY_CTRL_RD_SHIFT) | |
| 425 | ((tag[1] - 1) << L2X0_LATENCY_CTRL_WR_SHIFT) | |
| 426 | ((tag[2] - 1) << L2X0_LATENCY_CTRL_SETUP_SHIFT), |
| 427 | l2x0_base + L2X0_TAG_LATENCY_CTRL); |
| 428 | |
| 429 | of_property_read_u32_array(np, "arm,data-latency", |
| 430 | data, ARRAY_SIZE(data)); |
| 431 | if (data[0] && data[1] && data[2]) |
| 432 | writel_relaxed( |
| 433 | ((data[0] - 1) << L2X0_LATENCY_CTRL_RD_SHIFT) | |
| 434 | ((data[1] - 1) << L2X0_LATENCY_CTRL_WR_SHIFT) | |
| 435 | ((data[2] - 1) << L2X0_LATENCY_CTRL_SETUP_SHIFT), |
| 436 | l2x0_base + L2X0_DATA_LATENCY_CTRL); |
| 437 | |
| 438 | of_property_read_u32_array(np, "arm,filter-ranges", |
| 439 | filter, ARRAY_SIZE(filter)); |
Barry Song | 74d41f3 | 2011-09-14 03:20:01 +0100 | [diff] [blame^] | 440 | if (filter[1]) { |
Rob Herring | 8c36926 | 2011-08-03 18:12:05 +0100 | [diff] [blame] | 441 | writel_relaxed(ALIGN(filter[0] + filter[1], SZ_1M), |
| 442 | l2x0_base + L2X0_ADDR_FILTER_END); |
| 443 | writel_relaxed((filter[0] & ~(SZ_1M - 1)) | L2X0_ADDR_FILTER_EN, |
| 444 | l2x0_base + L2X0_ADDR_FILTER_START); |
| 445 | } |
| 446 | } |
| 447 | |
| 448 | static const struct of_device_id l2x0_ids[] __initconst = { |
| 449 | { .compatible = "arm,pl310-cache", .data = pl310_of_setup }, |
| 450 | { .compatible = "arm,l220-cache", .data = l2x0_of_setup }, |
| 451 | { .compatible = "arm,l210-cache", .data = l2x0_of_setup }, |
| 452 | {} |
| 453 | }; |
| 454 | |
| 455 | int __init l2x0_of_init(__u32 aux_val, __u32 aux_mask) |
| 456 | { |
| 457 | struct device_node *np; |
| 458 | void (*l2_setup)(const struct device_node *np, |
| 459 | __u32 *aux_val, __u32 *aux_mask); |
| 460 | |
| 461 | np = of_find_matching_node(NULL, l2x0_ids); |
| 462 | if (!np) |
| 463 | return -ENODEV; |
| 464 | l2x0_base = of_iomap(np, 0); |
| 465 | if (!l2x0_base) |
| 466 | return -ENOMEM; |
| 467 | |
| 468 | /* L2 configuration can only be changed if the cache is disabled */ |
| 469 | if (!(readl_relaxed(l2x0_base + L2X0_CTRL) & 1)) { |
| 470 | l2_setup = of_match_node(l2x0_ids, np)->data; |
| 471 | if (l2_setup) |
| 472 | l2_setup(np, &aux_val, &aux_mask); |
| 473 | } |
| 474 | l2x0_init(l2x0_base, aux_val, aux_mask); |
| 475 | return 0; |
| 476 | } |
| 477 | #endif |