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