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