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 |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 5 | * Copyright (c) 2009, 2011, Code Aurora Forum. All rights reserved. |
Catalin Marinas | 382266a | 2007-02-05 14:48:19 +0100 | [diff] [blame] | 6 | * |
| 7 | * This program is free software; you can redistribute it and/or modify |
| 8 | * it under the terms of the GNU General Public License version 2 as |
| 9 | * published by the Free Software Foundation. |
| 10 | * |
| 11 | * This program is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | * GNU General Public License for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU General Public License |
| 17 | * along with this program; if not, write to the Free Software |
| 18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 19 | */ |
| 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> |
Catalin Marinas | 382266a | 2007-02-05 14:48:19 +0100 | [diff] [blame] | 23 | |
| 24 | #include <asm/cacheflush.h> |
Catalin Marinas | 382266a | 2007-02-05 14:48:19 +0100 | [diff] [blame] | 25 | #include <asm/hardware/cache-l2x0.h> |
| 26 | |
| 27 | #define CACHE_LINE_SIZE 32 |
| 28 | |
| 29 | static void __iomem *l2x0_base; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 30 | static uint32_t aux_ctrl_save; |
Catalin Marinas | 0762097 | 2007-07-20 11:42:40 +0100 | [diff] [blame] | 31 | static DEFINE_SPINLOCK(l2x0_lock); |
Jason McMullan | 64039be | 2010-05-05 18:59:37 +0100 | [diff] [blame] | 32 | static uint32_t l2x0_way_mask; /* Bitmask of active ways */ |
Santosh Shilimkar | 5ba7037 | 2010-07-11 14:35:37 +0530 | [diff] [blame] | 33 | static uint32_t l2x0_size; |
Catalin Marinas | 382266a | 2007-02-05 14:48:19 +0100 | [diff] [blame] | 34 | |
Catalin Marinas | 9a6655e | 2010-08-31 13:05:22 +0100 | [diff] [blame] | 35 | static inline void cache_wait_way(void __iomem *reg, unsigned long mask) |
Catalin Marinas | 382266a | 2007-02-05 14:48:19 +0100 | [diff] [blame] | 36 | { |
Catalin Marinas | 9a6655e | 2010-08-31 13:05:22 +0100 | [diff] [blame] | 37 | /* wait for cache operation by line or way to complete */ |
Catalin Marinas | 6775a55 | 2010-07-28 22:01:25 +0100 | [diff] [blame] | 38 | while (readl_relaxed(reg) & mask) |
Catalin Marinas | 382266a | 2007-02-05 14:48:19 +0100 | [diff] [blame] | 39 | ; |
Catalin Marinas | 382266a | 2007-02-05 14:48:19 +0100 | [diff] [blame] | 40 | } |
| 41 | |
Catalin Marinas | 9a6655e | 2010-08-31 13:05:22 +0100 | [diff] [blame] | 42 | #ifdef CONFIG_CACHE_PL310 |
| 43 | static inline void cache_wait(void __iomem *reg, unsigned long mask) |
| 44 | { |
| 45 | /* cache operations by line are atomic on PL310 */ |
| 46 | } |
| 47 | #else |
| 48 | #define cache_wait cache_wait_way |
| 49 | #endif |
| 50 | |
Catalin Marinas | 382266a | 2007-02-05 14:48:19 +0100 | [diff] [blame] | 51 | static inline void cache_sync(void) |
| 52 | { |
Russell King | 3d10743 | 2009-11-19 11:41:09 +0000 | [diff] [blame] | 53 | void __iomem *base = l2x0_base; |
Srinidhi Kasagar | 885028e | 2011-02-17 07:03:51 +0100 | [diff] [blame] | 54 | |
| 55 | #ifdef CONFIG_ARM_ERRATA_753970 |
| 56 | /* write to an unmmapped register */ |
| 57 | writel_relaxed(0, base + L2X0_DUMMY_REG); |
| 58 | #else |
Catalin Marinas | 6775a55 | 2010-07-28 22:01:25 +0100 | [diff] [blame] | 59 | writel_relaxed(0, base + L2X0_CACHE_SYNC); |
Srinidhi Kasagar | 885028e | 2011-02-17 07:03:51 +0100 | [diff] [blame] | 60 | #endif |
Russell King | 3d10743 | 2009-11-19 11:41:09 +0000 | [diff] [blame] | 61 | cache_wait(base + L2X0_CACHE_SYNC, 1); |
Catalin Marinas | 382266a | 2007-02-05 14:48:19 +0100 | [diff] [blame] | 62 | } |
| 63 | |
Santosh Shilimkar | 424d6b1 | 2010-02-04 19:35:06 +0100 | [diff] [blame] | 64 | static inline void l2x0_clean_line(unsigned long addr) |
| 65 | { |
| 66 | void __iomem *base = l2x0_base; |
| 67 | cache_wait(base + L2X0_CLEAN_LINE_PA, 1); |
Catalin Marinas | 6775a55 | 2010-07-28 22:01:25 +0100 | [diff] [blame] | 68 | writel_relaxed(addr, base + L2X0_CLEAN_LINE_PA); |
Santosh Shilimkar | 424d6b1 | 2010-02-04 19:35:06 +0100 | [diff] [blame] | 69 | } |
| 70 | |
| 71 | static inline void l2x0_inv_line(unsigned long addr) |
| 72 | { |
| 73 | void __iomem *base = l2x0_base; |
| 74 | cache_wait(base + L2X0_INV_LINE_PA, 1); |
Catalin Marinas | 6775a55 | 2010-07-28 22:01:25 +0100 | [diff] [blame] | 75 | writel_relaxed(addr, base + L2X0_INV_LINE_PA); |
Santosh Shilimkar | 424d6b1 | 2010-02-04 19:35:06 +0100 | [diff] [blame] | 76 | } |
| 77 | |
Santosh Shilimkar | 2839e06 | 2011-03-08 06:59:54 +0100 | [diff] [blame] | 78 | #if defined(CONFIG_PL310_ERRATA_588369) || defined(CONFIG_PL310_ERRATA_727915) |
Santosh Shilimkar | 9e65582 | 2010-02-04 19:42:42 +0100 | [diff] [blame] | 79 | |
Santosh Shilimkar | 2839e06 | 2011-03-08 06:59:54 +0100 | [diff] [blame] | 80 | #define debug_writel(val) outer_cache.set_debug(val) |
| 81 | |
| 82 | static void l2x0_set_debug(unsigned long val) |
| 83 | { |
| 84 | writel_relaxed(val, l2x0_base + L2X0_DEBUG_CTRL); |
| 85 | } |
| 86 | #else |
| 87 | /* Optimised out for non-errata case */ |
| 88 | static inline void debug_writel(unsigned long val) |
| 89 | { |
Santosh Shilimkar | 9e65582 | 2010-02-04 19:42:42 +0100 | [diff] [blame] | 90 | } |
| 91 | |
Santosh Shilimkar | 2839e06 | 2011-03-08 06:59:54 +0100 | [diff] [blame] | 92 | #define l2x0_set_debug NULL |
| 93 | #endif |
| 94 | |
| 95 | #ifdef CONFIG_PL310_ERRATA_588369 |
Santosh Shilimkar | 9e65582 | 2010-02-04 19:42:42 +0100 | [diff] [blame] | 96 | static inline void l2x0_flush_line(unsigned long addr) |
| 97 | { |
| 98 | void __iomem *base = l2x0_base; |
| 99 | |
| 100 | /* Clean by PA followed by Invalidate by PA */ |
| 101 | cache_wait(base + L2X0_CLEAN_LINE_PA, 1); |
Catalin Marinas | 6775a55 | 2010-07-28 22:01:25 +0100 | [diff] [blame] | 102 | writel_relaxed(addr, base + L2X0_CLEAN_LINE_PA); |
Santosh Shilimkar | 9e65582 | 2010-02-04 19:42:42 +0100 | [diff] [blame] | 103 | cache_wait(base + L2X0_INV_LINE_PA, 1); |
Catalin Marinas | 6775a55 | 2010-07-28 22:01:25 +0100 | [diff] [blame] | 104 | writel_relaxed(addr, base + L2X0_INV_LINE_PA); |
Santosh Shilimkar | 9e65582 | 2010-02-04 19:42:42 +0100 | [diff] [blame] | 105 | } |
| 106 | #else |
| 107 | |
Santosh Shilimkar | 424d6b1 | 2010-02-04 19:35:06 +0100 | [diff] [blame] | 108 | static inline void l2x0_flush_line(unsigned long addr) |
| 109 | { |
| 110 | void __iomem *base = l2x0_base; |
| 111 | cache_wait(base + L2X0_CLEAN_INV_LINE_PA, 1); |
Catalin Marinas | 6775a55 | 2010-07-28 22:01:25 +0100 | [diff] [blame] | 112 | writel_relaxed(addr, base + L2X0_CLEAN_INV_LINE_PA); |
Santosh Shilimkar | 424d6b1 | 2010-02-04 19:35:06 +0100 | [diff] [blame] | 113 | } |
Santosh Shilimkar | 9e65582 | 2010-02-04 19:42:42 +0100 | [diff] [blame] | 114 | #endif |
Santosh Shilimkar | 424d6b1 | 2010-02-04 19:35:06 +0100 | [diff] [blame] | 115 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 116 | void l2x0_cache_sync(void) |
Catalin Marinas | 23107c5 | 2010-03-24 16:48:53 +0100 | [diff] [blame] | 117 | { |
Catalin Marinas | 23107c5 | 2010-03-24 16:48:53 +0100 | [diff] [blame] | 118 | cache_sync(); |
Catalin Marinas | 23107c5 | 2010-03-24 16:48:53 +0100 | [diff] [blame] | 119 | } |
| 120 | |
Will Deacon | 38a8914 | 2011-07-01 14:36:19 +0100 | [diff] [blame] | 121 | static void __l2x0_flush_all(void) |
| 122 | { |
| 123 | debug_writel(0x03); |
| 124 | writel_relaxed(l2x0_way_mask, l2x0_base + L2X0_CLEAN_INV_WAY); |
| 125 | cache_wait_way(l2x0_base + L2X0_CLEAN_INV_WAY, l2x0_way_mask); |
| 126 | cache_sync(); |
| 127 | debug_writel(0x00); |
| 128 | } |
| 129 | |
Thomas Gleixner | 2fd8658 | 2010-07-31 21:05:24 +0530 | [diff] [blame] | 130 | static void l2x0_flush_all(void) |
| 131 | { |
| 132 | unsigned long flags; |
| 133 | |
| 134 | /* clean all ways */ |
| 135 | spin_lock_irqsave(&l2x0_lock, flags); |
Will Deacon | 38a8914 | 2011-07-01 14:36:19 +0100 | [diff] [blame] | 136 | __l2x0_flush_all(); |
Thomas Gleixner | 2fd8658 | 2010-07-31 21:05:24 +0530 | [diff] [blame] | 137 | spin_unlock_irqrestore(&l2x0_lock, flags); |
| 138 | } |
| 139 | |
Santosh Shilimkar | 444457c | 2010-07-11 14:58:41 +0530 | [diff] [blame] | 140 | static void l2x0_clean_all(void) |
| 141 | { |
| 142 | unsigned long flags; |
| 143 | |
| 144 | /* clean all ways */ |
| 145 | spin_lock_irqsave(&l2x0_lock, flags); |
| 146 | writel_relaxed(l2x0_way_mask, l2x0_base + L2X0_CLEAN_WAY); |
| 147 | cache_wait_way(l2x0_base + L2X0_CLEAN_WAY, l2x0_way_mask); |
| 148 | cache_sync(); |
| 149 | spin_unlock_irqrestore(&l2x0_lock, flags); |
| 150 | } |
| 151 | |
Thomas Gleixner | 2fd8658 | 2010-07-31 21:05:24 +0530 | [diff] [blame] | 152 | static void l2x0_inv_all(void) |
Catalin Marinas | 382266a | 2007-02-05 14:48:19 +0100 | [diff] [blame] | 153 | { |
Russell King | 0eb948d | 2009-11-19 11:12:15 +0000 | [diff] [blame] | 154 | unsigned long flags; |
| 155 | |
Catalin Marinas | 382266a | 2007-02-05 14:48:19 +0100 | [diff] [blame] | 156 | /* invalidate all ways */ |
Russell King | 0eb948d | 2009-11-19 11:12:15 +0000 | [diff] [blame] | 157 | spin_lock_irqsave(&l2x0_lock, flags); |
Thomas Gleixner | 2fd8658 | 2010-07-31 21:05:24 +0530 | [diff] [blame] | 158 | /* Invalidating when L2 is enabled is a nono */ |
| 159 | BUG_ON(readl(l2x0_base + L2X0_CTRL) & 1); |
Catalin Marinas | 6775a55 | 2010-07-28 22:01:25 +0100 | [diff] [blame] | 160 | writel_relaxed(l2x0_way_mask, l2x0_base + L2X0_INV_WAY); |
Catalin Marinas | 9a6655e | 2010-08-31 13:05:22 +0100 | [diff] [blame] | 161 | cache_wait_way(l2x0_base + L2X0_INV_WAY, l2x0_way_mask); |
Catalin Marinas | 382266a | 2007-02-05 14:48:19 +0100 | [diff] [blame] | 162 | cache_sync(); |
Russell King | 0eb948d | 2009-11-19 11:12:15 +0000 | [diff] [blame] | 163 | spin_unlock_irqrestore(&l2x0_lock, flags); |
Catalin Marinas | 382266a | 2007-02-05 14:48:19 +0100 | [diff] [blame] | 164 | } |
| 165 | |
| 166 | static void l2x0_inv_range(unsigned long start, unsigned long end) |
| 167 | { |
Russell King | 3d10743 | 2009-11-19 11:41:09 +0000 | [diff] [blame] | 168 | void __iomem *base = l2x0_base; |
Russell King | 0eb948d | 2009-11-19 11:12:15 +0000 | [diff] [blame] | 169 | unsigned long flags; |
Catalin Marinas | 382266a | 2007-02-05 14:48:19 +0100 | [diff] [blame] | 170 | |
Russell King | 0eb948d | 2009-11-19 11:12:15 +0000 | [diff] [blame] | 171 | spin_lock_irqsave(&l2x0_lock, flags); |
Rui Sousa | 4f6627a | 2007-09-15 00:56:19 +0100 | [diff] [blame] | 172 | if (start & (CACHE_LINE_SIZE - 1)) { |
| 173 | start &= ~(CACHE_LINE_SIZE - 1); |
Santosh Shilimkar | 9e65582 | 2010-02-04 19:42:42 +0100 | [diff] [blame] | 174 | debug_writel(0x03); |
Santosh Shilimkar | 424d6b1 | 2010-02-04 19:35:06 +0100 | [diff] [blame] | 175 | l2x0_flush_line(start); |
Santosh Shilimkar | 9e65582 | 2010-02-04 19:42:42 +0100 | [diff] [blame] | 176 | debug_writel(0x00); |
Rui Sousa | 4f6627a | 2007-09-15 00:56:19 +0100 | [diff] [blame] | 177 | start += CACHE_LINE_SIZE; |
| 178 | } |
| 179 | |
| 180 | if (end & (CACHE_LINE_SIZE - 1)) { |
| 181 | end &= ~(CACHE_LINE_SIZE - 1); |
Santosh Shilimkar | 9e65582 | 2010-02-04 19:42:42 +0100 | [diff] [blame] | 182 | debug_writel(0x03); |
Santosh Shilimkar | 424d6b1 | 2010-02-04 19:35:06 +0100 | [diff] [blame] | 183 | l2x0_flush_line(end); |
Santosh Shilimkar | 9e65582 | 2010-02-04 19:42:42 +0100 | [diff] [blame] | 184 | debug_writel(0x00); |
Rui Sousa | 4f6627a | 2007-09-15 00:56:19 +0100 | [diff] [blame] | 185 | } |
| 186 | |
Russell King | 0eb948d | 2009-11-19 11:12:15 +0000 | [diff] [blame] | 187 | while (start < end) { |
| 188 | unsigned long blk_end = start + min(end - start, 4096UL); |
| 189 | |
| 190 | while (start < blk_end) { |
Santosh Shilimkar | 424d6b1 | 2010-02-04 19:35:06 +0100 | [diff] [blame] | 191 | l2x0_inv_line(start); |
Russell King | 0eb948d | 2009-11-19 11:12:15 +0000 | [diff] [blame] | 192 | start += CACHE_LINE_SIZE; |
| 193 | } |
| 194 | |
| 195 | if (blk_end < end) { |
| 196 | spin_unlock_irqrestore(&l2x0_lock, flags); |
| 197 | spin_lock_irqsave(&l2x0_lock, flags); |
| 198 | } |
| 199 | } |
Russell King | 3d10743 | 2009-11-19 11:41:09 +0000 | [diff] [blame] | 200 | cache_wait(base + L2X0_INV_LINE_PA, 1); |
Catalin Marinas | 382266a | 2007-02-05 14:48:19 +0100 | [diff] [blame] | 201 | cache_sync(); |
Russell King | 0eb948d | 2009-11-19 11:12:15 +0000 | [diff] [blame] | 202 | spin_unlock_irqrestore(&l2x0_lock, flags); |
Catalin Marinas | 382266a | 2007-02-05 14:48:19 +0100 | [diff] [blame] | 203 | } |
| 204 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 205 | static void l2x0_inv_range_atomic(unsigned long start, unsigned long end) |
| 206 | { |
| 207 | unsigned long addr; |
| 208 | |
| 209 | if (start & (CACHE_LINE_SIZE - 1)) { |
| 210 | start &= ~(CACHE_LINE_SIZE - 1); |
| 211 | writel_relaxed(start, l2x0_base + L2X0_CLEAN_INV_LINE_PA); |
| 212 | start += CACHE_LINE_SIZE; |
| 213 | } |
| 214 | |
| 215 | if (end & (CACHE_LINE_SIZE - 1)) { |
| 216 | end &= ~(CACHE_LINE_SIZE - 1); |
| 217 | writel_relaxed(end, l2x0_base + L2X0_CLEAN_INV_LINE_PA); |
| 218 | } |
| 219 | |
| 220 | for (addr = start; addr < end; addr += CACHE_LINE_SIZE) |
| 221 | writel_relaxed(addr, l2x0_base + L2X0_INV_LINE_PA); |
| 222 | |
| 223 | mb(); |
| 224 | } |
| 225 | |
Catalin Marinas | 382266a | 2007-02-05 14:48:19 +0100 | [diff] [blame] | 226 | static void l2x0_clean_range(unsigned long start, unsigned long end) |
| 227 | { |
Russell King | 3d10743 | 2009-11-19 11:41:09 +0000 | [diff] [blame] | 228 | void __iomem *base = l2x0_base; |
Russell King | 0eb948d | 2009-11-19 11:12:15 +0000 | [diff] [blame] | 229 | unsigned long flags; |
Catalin Marinas | 382266a | 2007-02-05 14:48:19 +0100 | [diff] [blame] | 230 | |
Santosh Shilimkar | 444457c | 2010-07-11 14:58:41 +0530 | [diff] [blame] | 231 | if ((end - start) >= l2x0_size) { |
| 232 | l2x0_clean_all(); |
| 233 | return; |
| 234 | } |
| 235 | |
Russell King | 0eb948d | 2009-11-19 11:12:15 +0000 | [diff] [blame] | 236 | spin_lock_irqsave(&l2x0_lock, flags); |
Catalin Marinas | 382266a | 2007-02-05 14:48:19 +0100 | [diff] [blame] | 237 | start &= ~(CACHE_LINE_SIZE - 1); |
Russell King | 0eb948d | 2009-11-19 11:12:15 +0000 | [diff] [blame] | 238 | while (start < end) { |
| 239 | unsigned long blk_end = start + min(end - start, 4096UL); |
| 240 | |
| 241 | while (start < blk_end) { |
Santosh Shilimkar | 424d6b1 | 2010-02-04 19:35:06 +0100 | [diff] [blame] | 242 | l2x0_clean_line(start); |
Russell King | 0eb948d | 2009-11-19 11:12:15 +0000 | [diff] [blame] | 243 | start += CACHE_LINE_SIZE; |
| 244 | } |
| 245 | |
| 246 | if (blk_end < end) { |
| 247 | spin_unlock_irqrestore(&l2x0_lock, flags); |
| 248 | spin_lock_irqsave(&l2x0_lock, flags); |
| 249 | } |
| 250 | } |
Russell King | 3d10743 | 2009-11-19 11:41:09 +0000 | [diff] [blame] | 251 | cache_wait(base + L2X0_CLEAN_LINE_PA, 1); |
Catalin Marinas | 382266a | 2007-02-05 14:48:19 +0100 | [diff] [blame] | 252 | cache_sync(); |
Russell King | 0eb948d | 2009-11-19 11:12:15 +0000 | [diff] [blame] | 253 | spin_unlock_irqrestore(&l2x0_lock, flags); |
Catalin Marinas | 382266a | 2007-02-05 14:48:19 +0100 | [diff] [blame] | 254 | } |
| 255 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 256 | static void l2x0_clean_range_atomic(unsigned long start, unsigned long end) |
| 257 | { |
| 258 | unsigned long addr; |
| 259 | |
| 260 | start &= ~(CACHE_LINE_SIZE - 1); |
| 261 | for (addr = start; addr < end; addr += CACHE_LINE_SIZE) |
| 262 | writel_relaxed(addr, l2x0_base + L2X0_CLEAN_LINE_PA); |
| 263 | |
| 264 | mb(); |
| 265 | } |
| 266 | |
Catalin Marinas | 382266a | 2007-02-05 14:48:19 +0100 | [diff] [blame] | 267 | static void l2x0_flush_range(unsigned long start, unsigned long end) |
| 268 | { |
Russell King | 3d10743 | 2009-11-19 11:41:09 +0000 | [diff] [blame] | 269 | void __iomem *base = l2x0_base; |
Russell King | 0eb948d | 2009-11-19 11:12:15 +0000 | [diff] [blame] | 270 | unsigned long flags; |
Catalin Marinas | 382266a | 2007-02-05 14:48:19 +0100 | [diff] [blame] | 271 | |
Santosh Shilimkar | 444457c | 2010-07-11 14:58:41 +0530 | [diff] [blame] | 272 | if ((end - start) >= l2x0_size) { |
| 273 | l2x0_flush_all(); |
| 274 | return; |
| 275 | } |
| 276 | |
Russell King | 0eb948d | 2009-11-19 11:12:15 +0000 | [diff] [blame] | 277 | spin_lock_irqsave(&l2x0_lock, flags); |
Catalin Marinas | 382266a | 2007-02-05 14:48:19 +0100 | [diff] [blame] | 278 | start &= ~(CACHE_LINE_SIZE - 1); |
Russell King | 0eb948d | 2009-11-19 11:12:15 +0000 | [diff] [blame] | 279 | while (start < end) { |
| 280 | unsigned long blk_end = start + min(end - start, 4096UL); |
| 281 | |
Santosh Shilimkar | 9e65582 | 2010-02-04 19:42:42 +0100 | [diff] [blame] | 282 | debug_writel(0x03); |
Russell King | 0eb948d | 2009-11-19 11:12:15 +0000 | [diff] [blame] | 283 | while (start < blk_end) { |
Santosh Shilimkar | 424d6b1 | 2010-02-04 19:35:06 +0100 | [diff] [blame] | 284 | l2x0_flush_line(start); |
Russell King | 0eb948d | 2009-11-19 11:12:15 +0000 | [diff] [blame] | 285 | start += CACHE_LINE_SIZE; |
| 286 | } |
Santosh Shilimkar | 9e65582 | 2010-02-04 19:42:42 +0100 | [diff] [blame] | 287 | debug_writel(0x00); |
Russell King | 0eb948d | 2009-11-19 11:12:15 +0000 | [diff] [blame] | 288 | |
| 289 | if (blk_end < end) { |
| 290 | spin_unlock_irqrestore(&l2x0_lock, flags); |
| 291 | spin_lock_irqsave(&l2x0_lock, flags); |
| 292 | } |
| 293 | } |
Russell King | 3d10743 | 2009-11-19 11:41:09 +0000 | [diff] [blame] | 294 | cache_wait(base + L2X0_CLEAN_INV_LINE_PA, 1); |
Catalin Marinas | 382266a | 2007-02-05 14:48:19 +0100 | [diff] [blame] | 295 | cache_sync(); |
Russell King | 0eb948d | 2009-11-19 11:12:15 +0000 | [diff] [blame] | 296 | spin_unlock_irqrestore(&l2x0_lock, flags); |
Catalin Marinas | 382266a | 2007-02-05 14:48:19 +0100 | [diff] [blame] | 297 | } |
| 298 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 299 | void l2x0_flush_range_atomic(unsigned long start, unsigned long end) |
| 300 | { |
| 301 | unsigned long addr; |
| 302 | |
| 303 | start &= ~(CACHE_LINE_SIZE - 1); |
| 304 | for (addr = start; addr < end; addr += CACHE_LINE_SIZE) |
| 305 | writel_relaxed(addr, l2x0_base + L2X0_CLEAN_INV_LINE_PA); |
| 306 | |
| 307 | mb(); |
| 308 | } |
| 309 | |
Thomas Gleixner | 2fd8658 | 2010-07-31 21:05:24 +0530 | [diff] [blame] | 310 | static void l2x0_disable(void) |
| 311 | { |
| 312 | unsigned long flags; |
| 313 | |
| 314 | spin_lock_irqsave(&l2x0_lock, flags); |
Will Deacon | 38a8914 | 2011-07-01 14:36:19 +0100 | [diff] [blame] | 315 | __l2x0_flush_all(); |
| 316 | writel_relaxed(0, l2x0_base + L2X0_CTRL); |
| 317 | dsb(); |
Thomas Gleixner | 2fd8658 | 2010-07-31 21:05:24 +0530 | [diff] [blame] | 318 | spin_unlock_irqrestore(&l2x0_lock, flags); |
| 319 | } |
| 320 | |
Catalin Marinas | 382266a | 2007-02-05 14:48:19 +0100 | [diff] [blame] | 321 | void __init l2x0_init(void __iomem *base, __u32 aux_val, __u32 aux_mask) |
| 322 | { |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 323 | __u32 aux, bits; |
Jason McMullan | 64039be | 2010-05-05 18:59:37 +0100 | [diff] [blame] | 324 | __u32 cache_id; |
Santosh Shilimkar | 5ba7037 | 2010-07-11 14:35:37 +0530 | [diff] [blame] | 325 | __u32 way_size = 0; |
Jason McMullan | 64039be | 2010-05-05 18:59:37 +0100 | [diff] [blame] | 326 | int ways; |
| 327 | const char *type; |
Catalin Marinas | 382266a | 2007-02-05 14:48:19 +0100 | [diff] [blame] | 328 | |
| 329 | l2x0_base = base; |
Catalin Marinas | 6775a55 | 2010-07-28 22:01:25 +0100 | [diff] [blame] | 330 | cache_id = readl_relaxed(l2x0_base + L2X0_CACHE_ID); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 331 | |
| 332 | bits = readl_relaxed(l2x0_base + L2X0_CTRL); |
| 333 | bits &= ~0x01; /* clear bit 0 */ |
| 334 | writel_relaxed(bits, l2x0_base + L2X0_CTRL); |
| 335 | |
Catalin Marinas | 6775a55 | 2010-07-28 22:01:25 +0100 | [diff] [blame] | 336 | aux = readl_relaxed(l2x0_base + L2X0_AUX_CTRL); |
Jason McMullan | 64039be | 2010-05-05 18:59:37 +0100 | [diff] [blame] | 337 | |
Sascha Hauer | 4082cfa | 2010-07-08 08:36:21 +0100 | [diff] [blame] | 338 | aux &= aux_mask; |
| 339 | aux |= aux_val; |
| 340 | |
Jason McMullan | 64039be | 2010-05-05 18:59:37 +0100 | [diff] [blame] | 341 | /* Determine the number of ways */ |
| 342 | switch (cache_id & L2X0_CACHE_ID_PART_MASK) { |
| 343 | case L2X0_CACHE_ID_PART_L310: |
| 344 | if (aux & (1 << 16)) |
| 345 | ways = 16; |
| 346 | else |
| 347 | ways = 8; |
| 348 | type = "L310"; |
| 349 | break; |
| 350 | case L2X0_CACHE_ID_PART_L210: |
| 351 | ways = (aux >> 13) & 0xf; |
| 352 | type = "L210"; |
| 353 | break; |
| 354 | default: |
| 355 | /* Assume unknown chips have 8 ways */ |
| 356 | ways = 8; |
| 357 | type = "L2x0 series"; |
| 358 | break; |
| 359 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 360 | writel_relaxed(aux, l2x0_base + L2X0_AUX_CTRL); |
Jason McMullan | 64039be | 2010-05-05 18:59:37 +0100 | [diff] [blame] | 361 | l2x0_way_mask = (1 << ways) - 1; |
| 362 | |
Srinidhi Kasagar | 48371cd | 2009-12-02 06:18:03 +0100 | [diff] [blame] | 363 | /* |
Santosh Shilimkar | 5ba7037 | 2010-07-11 14:35:37 +0530 | [diff] [blame] | 364 | * L2 cache Size = Way size * Number of ways |
| 365 | */ |
| 366 | way_size = (aux & L2X0_AUX_CTRL_WAY_SIZE_MASK) >> 17; |
| 367 | way_size = 1 << (way_size + 3); |
| 368 | l2x0_size = ways * way_size * SZ_1K; |
| 369 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 370 | l2x0_inv_all(); |
Catalin Marinas | 382266a | 2007-02-05 14:48:19 +0100 | [diff] [blame] | 371 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 372 | /* enable L2X0 */ |
| 373 | bits = readl_relaxed(l2x0_base + L2X0_CTRL); |
| 374 | bits |= 0x01; /* set bit 0 */ |
| 375 | writel_relaxed(bits, l2x0_base + L2X0_CTRL); |
Catalin Marinas | 382266a | 2007-02-05 14:48:19 +0100 | [diff] [blame] | 376 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 377 | switch (cache_id & L2X0_CACHE_ID_PART_MASK) { |
| 378 | case L2X0_CACHE_ID_PART_L220: |
| 379 | outer_cache.inv_range = l2x0_inv_range; |
| 380 | outer_cache.clean_range = l2x0_clean_range; |
| 381 | outer_cache.flush_range = l2x0_flush_range; |
| 382 | printk(KERN_INFO "L220 cache controller enabled\n"); |
| 383 | break; |
| 384 | case L2X0_CACHE_ID_PART_L310: |
| 385 | outer_cache.inv_range = l2x0_inv_range; |
| 386 | outer_cache.clean_range = l2x0_clean_range; |
| 387 | outer_cache.flush_range = l2x0_flush_range; |
| 388 | printk(KERN_INFO "L310 cache controller enabled\n"); |
| 389 | break; |
| 390 | case L2X0_CACHE_ID_PART_L210: |
| 391 | default: |
| 392 | outer_cache.inv_range = l2x0_inv_range_atomic; |
| 393 | outer_cache.clean_range = l2x0_clean_range_atomic; |
| 394 | outer_cache.flush_range = l2x0_flush_range_atomic; |
| 395 | printk(KERN_INFO "L210 cache controller enabled\n"); |
| 396 | break; |
Srinidhi Kasagar | 48371cd | 2009-12-02 06:18:03 +0100 | [diff] [blame] | 397 | } |
Catalin Marinas | 382266a | 2007-02-05 14:48:19 +0100 | [diff] [blame] | 398 | |
Catalin Marinas | 23107c5 | 2010-03-24 16:48:53 +0100 | [diff] [blame] | 399 | outer_cache.sync = l2x0_cache_sync; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 400 | |
Thomas Gleixner | 2fd8658 | 2010-07-31 21:05:24 +0530 | [diff] [blame] | 401 | outer_cache.flush_all = l2x0_flush_all; |
| 402 | outer_cache.inv_all = l2x0_inv_all; |
| 403 | outer_cache.disable = l2x0_disable; |
Santosh Shilimkar | 2839e06 | 2011-03-08 06:59:54 +0100 | [diff] [blame] | 404 | outer_cache.set_debug = l2x0_set_debug; |
Catalin Marinas | 382266a | 2007-02-05 14:48:19 +0100 | [diff] [blame] | 405 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 406 | mb(); |
Jason McMullan | 64039be | 2010-05-05 18:59:37 +0100 | [diff] [blame] | 407 | printk(KERN_INFO "%s cache controller enabled\n", type); |
Santosh Shilimkar | 5ba7037 | 2010-07-11 14:35:37 +0530 | [diff] [blame] | 408 | printk(KERN_INFO "l2x0: %d ways, CACHE_ID 0x%08x, AUX_CTRL 0x%08x, Cache size: %d B\n", |
| 409 | ways, cache_id, aux, l2x0_size); |
Catalin Marinas | 382266a | 2007-02-05 14:48:19 +0100 | [diff] [blame] | 410 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 411 | |
| 412 | void l2x0_suspend(void) |
| 413 | { |
| 414 | /* Save aux control register value */ |
| 415 | aux_ctrl_save = readl_relaxed(l2x0_base + L2X0_AUX_CTRL); |
| 416 | /* Flush all cache */ |
| 417 | l2x0_flush_all(); |
| 418 | /* Disable the cache */ |
| 419 | writel_relaxed(0, l2x0_base + L2X0_CTRL); |
| 420 | |
| 421 | /* Memory barrier */ |
| 422 | dmb(); |
| 423 | } |
| 424 | |
| 425 | void l2x0_resume(int collapsed) |
| 426 | { |
| 427 | if (collapsed) { |
| 428 | /* Disable the cache */ |
| 429 | writel_relaxed(0, l2x0_base + L2X0_CTRL); |
| 430 | |
| 431 | /* Restore aux control register value */ |
| 432 | writel_relaxed(aux_ctrl_save, l2x0_base + L2X0_AUX_CTRL); |
| 433 | |
| 434 | /* Invalidate the cache */ |
| 435 | l2x0_inv_all(); |
| 436 | } |
| 437 | |
| 438 | /* Enable the cache */ |
| 439 | writel_relaxed(1, l2x0_base + L2X0_CTRL); |
| 440 | |
| 441 | mb(); |
| 442 | } |