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 |
Taniya Das | 38a8c6e | 2012-05-09 20:34:39 +0530 | [diff] [blame^] | 5 | * Copyright (c) 2009, 2011-2012, 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 | */ |
Rob Herring | 78ae8b1 | 2011-08-03 18:12:05 +0100 | [diff] [blame] | 20 | #include <linux/err.h> |
Catalin Marinas | 382266a | 2007-02-05 14:48:19 +0100 | [diff] [blame] | 21 | #include <linux/init.h> |
Catalin Marinas | 0762097 | 2007-07-20 11:42:40 +0100 | [diff] [blame] | 22 | #include <linux/spinlock.h> |
Russell King | fced80c | 2008-09-06 12:10:45 +0100 | [diff] [blame] | 23 | #include <linux/io.h> |
Rob Herring | 78ae8b1 | 2011-08-03 18:12:05 +0100 | [diff] [blame] | 24 | #include <linux/of.h> |
| 25 | #include <linux/of_address.h> |
Catalin Marinas | 382266a | 2007-02-05 14:48:19 +0100 | [diff] [blame] | 26 | |
| 27 | #include <asm/cacheflush.h> |
Catalin Marinas | 382266a | 2007-02-05 14:48:19 +0100 | [diff] [blame] | 28 | #include <asm/hardware/cache-l2x0.h> |
| 29 | |
| 30 | #define CACHE_LINE_SIZE 32 |
| 31 | |
| 32 | static void __iomem *l2x0_base; |
Thomas Gleixner | 450ea48 | 2009-07-03 08:44:46 -0500 | [diff] [blame] | 33 | static DEFINE_RAW_SPINLOCK(l2x0_lock); |
| 34 | |
Jason McMullan | 64039be | 2010-05-05 18:59:37 +0100 | [diff] [blame] | 35 | static uint32_t l2x0_way_mask; /* Bitmask of active ways */ |
Santosh Shilimkar | 5ba7037 | 2010-07-11 14:35:37 +0530 | [diff] [blame] | 36 | static uint32_t l2x0_size; |
Colin Cross | 5ea3a7c | 2011-09-14 15:59:50 -0700 | [diff] [blame] | 37 | static u32 l2x0_cache_id; |
| 38 | static unsigned int l2x0_sets; |
| 39 | static unsigned int l2x0_ways; |
Taniya Das | 38a8c6e | 2012-05-09 20:34:39 +0530 | [diff] [blame^] | 40 | static void pl310_save(void); |
Colin Cross | 5ea3a7c | 2011-09-14 15:59:50 -0700 | [diff] [blame] | 41 | |
| 42 | static inline bool is_pl310_rev(int rev) |
| 43 | { |
| 44 | return (l2x0_cache_id & |
| 45 | (L2X0_CACHE_ID_PART_MASK | L2X0_CACHE_ID_REV_MASK)) == |
| 46 | (L2X0_CACHE_ID_PART_L310 | rev); |
| 47 | } |
Catalin Marinas | 382266a | 2007-02-05 14:48:19 +0100 | [diff] [blame] | 48 | |
Barry Song | a9dd8f9 | 2011-09-30 14:43:12 +0100 | [diff] [blame] | 49 | struct l2x0_regs l2x0_saved_regs; |
| 50 | |
| 51 | struct l2x0_of_data { |
Russell King | 1add908 | 2011-09-18 11:27:30 +0100 | [diff] [blame] | 52 | void (*setup)(const struct device_node *, u32 *, u32 *); |
Barry Song | a9dd8f9 | 2011-09-30 14:43:12 +0100 | [diff] [blame] | 53 | void (*save)(void); |
| 54 | void (*resume)(void); |
| 55 | }; |
| 56 | |
Catalin Marinas | 9a6655e | 2010-08-31 13:05:22 +0100 | [diff] [blame] | 57 | static inline void cache_wait_way(void __iomem *reg, unsigned long mask) |
Catalin Marinas | 382266a | 2007-02-05 14:48:19 +0100 | [diff] [blame] | 58 | { |
Catalin Marinas | 9a6655e | 2010-08-31 13:05:22 +0100 | [diff] [blame] | 59 | /* wait for cache operation by line or way to complete */ |
Catalin Marinas | 6775a55 | 2010-07-28 22:01:25 +0100 | [diff] [blame] | 60 | while (readl_relaxed(reg) & mask) |
Barry Song | 7f5910a | 2011-09-09 10:30:34 +0100 | [diff] [blame] | 61 | cpu_relax(); |
Catalin Marinas | 382266a | 2007-02-05 14:48:19 +0100 | [diff] [blame] | 62 | } |
| 63 | |
Catalin Marinas | 9a6655e | 2010-08-31 13:05:22 +0100 | [diff] [blame] | 64 | #ifdef CONFIG_CACHE_PL310 |
| 65 | static inline void cache_wait(void __iomem *reg, unsigned long mask) |
| 66 | { |
| 67 | /* cache operations by line are atomic on PL310 */ |
| 68 | } |
| 69 | #else |
| 70 | #define cache_wait cache_wait_way |
| 71 | #endif |
| 72 | |
Catalin Marinas | 382266a | 2007-02-05 14:48:19 +0100 | [diff] [blame] | 73 | static inline void cache_sync(void) |
| 74 | { |
Russell King | 3d10743 | 2009-11-19 11:41:09 +0000 | [diff] [blame] | 75 | void __iomem *base = l2x0_base; |
Srinidhi Kasagar | 885028e | 2011-02-17 07:03:51 +0100 | [diff] [blame] | 76 | |
Will Deacon | c9c0cda | 2011-11-14 17:24:57 +0100 | [diff] [blame] | 77 | #ifdef CONFIG_PL310_ERRATA_753970 |
Srinidhi Kasagar | 885028e | 2011-02-17 07:03:51 +0100 | [diff] [blame] | 78 | /* write to an unmmapped register */ |
| 79 | writel_relaxed(0, base + L2X0_DUMMY_REG); |
| 80 | #else |
Catalin Marinas | 6775a55 | 2010-07-28 22:01:25 +0100 | [diff] [blame] | 81 | writel_relaxed(0, base + L2X0_CACHE_SYNC); |
Srinidhi Kasagar | 885028e | 2011-02-17 07:03:51 +0100 | [diff] [blame] | 82 | #endif |
Russell King | 3d10743 | 2009-11-19 11:41:09 +0000 | [diff] [blame] | 83 | cache_wait(base + L2X0_CACHE_SYNC, 1); |
Catalin Marinas | 382266a | 2007-02-05 14:48:19 +0100 | [diff] [blame] | 84 | } |
| 85 | |
Santosh Shilimkar | 424d6b1 | 2010-02-04 19:35:06 +0100 | [diff] [blame] | 86 | static inline void l2x0_clean_line(unsigned long addr) |
| 87 | { |
| 88 | void __iomem *base = l2x0_base; |
| 89 | cache_wait(base + L2X0_CLEAN_LINE_PA, 1); |
Catalin Marinas | 6775a55 | 2010-07-28 22:01:25 +0100 | [diff] [blame] | 90 | writel_relaxed(addr, base + L2X0_CLEAN_LINE_PA); |
Santosh Shilimkar | 424d6b1 | 2010-02-04 19:35:06 +0100 | [diff] [blame] | 91 | } |
| 92 | |
| 93 | static inline void l2x0_inv_line(unsigned long addr) |
| 94 | { |
| 95 | void __iomem *base = l2x0_base; |
| 96 | cache_wait(base + L2X0_INV_LINE_PA, 1); |
Catalin Marinas | 6775a55 | 2010-07-28 22:01:25 +0100 | [diff] [blame] | 97 | writel_relaxed(addr, base + L2X0_INV_LINE_PA); |
Santosh Shilimkar | 424d6b1 | 2010-02-04 19:35:06 +0100 | [diff] [blame] | 98 | } |
| 99 | |
Santosh Shilimkar | 2839e06 | 2011-03-08 06:59:54 +0100 | [diff] [blame] | 100 | #if defined(CONFIG_PL310_ERRATA_588369) || defined(CONFIG_PL310_ERRATA_727915) |
Santosh Shilimkar | 9e65582 | 2010-02-04 19:42:42 +0100 | [diff] [blame] | 101 | |
Santosh Shilimkar | 2839e06 | 2011-03-08 06:59:54 +0100 | [diff] [blame] | 102 | #define debug_writel(val) outer_cache.set_debug(val) |
| 103 | |
| 104 | static void l2x0_set_debug(unsigned long val) |
| 105 | { |
| 106 | writel_relaxed(val, l2x0_base + L2X0_DEBUG_CTRL); |
| 107 | } |
| 108 | #else |
| 109 | /* Optimised out for non-errata case */ |
| 110 | static inline void debug_writel(unsigned long val) |
| 111 | { |
Santosh Shilimkar | 9e65582 | 2010-02-04 19:42:42 +0100 | [diff] [blame] | 112 | } |
| 113 | |
Santosh Shilimkar | 2839e06 | 2011-03-08 06:59:54 +0100 | [diff] [blame] | 114 | #define l2x0_set_debug NULL |
| 115 | #endif |
| 116 | |
| 117 | #ifdef CONFIG_PL310_ERRATA_588369 |
Santosh Shilimkar | 9e65582 | 2010-02-04 19:42:42 +0100 | [diff] [blame] | 118 | static inline void l2x0_flush_line(unsigned long addr) |
| 119 | { |
| 120 | void __iomem *base = l2x0_base; |
| 121 | |
| 122 | /* Clean by PA followed by Invalidate by PA */ |
| 123 | cache_wait(base + L2X0_CLEAN_LINE_PA, 1); |
Catalin Marinas | 6775a55 | 2010-07-28 22:01:25 +0100 | [diff] [blame] | 124 | writel_relaxed(addr, base + L2X0_CLEAN_LINE_PA); |
Santosh Shilimkar | 9e65582 | 2010-02-04 19:42:42 +0100 | [diff] [blame] | 125 | cache_wait(base + L2X0_INV_LINE_PA, 1); |
Catalin Marinas | 6775a55 | 2010-07-28 22:01:25 +0100 | [diff] [blame] | 126 | writel_relaxed(addr, base + L2X0_INV_LINE_PA); |
Santosh Shilimkar | 9e65582 | 2010-02-04 19:42:42 +0100 | [diff] [blame] | 127 | } |
| 128 | #else |
| 129 | |
Santosh Shilimkar | 424d6b1 | 2010-02-04 19:35:06 +0100 | [diff] [blame] | 130 | static inline void l2x0_flush_line(unsigned long addr) |
| 131 | { |
| 132 | void __iomem *base = l2x0_base; |
| 133 | cache_wait(base + L2X0_CLEAN_INV_LINE_PA, 1); |
Catalin Marinas | 6775a55 | 2010-07-28 22:01:25 +0100 | [diff] [blame] | 134 | writel_relaxed(addr, base + L2X0_CLEAN_INV_LINE_PA); |
Santosh Shilimkar | 424d6b1 | 2010-02-04 19:35:06 +0100 | [diff] [blame] | 135 | } |
Santosh Shilimkar | 9e65582 | 2010-02-04 19:42:42 +0100 | [diff] [blame] | 136 | #endif |
Santosh Shilimkar | 424d6b1 | 2010-02-04 19:35:06 +0100 | [diff] [blame] | 137 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 138 | void l2x0_cache_sync(void) |
Catalin Marinas | 23107c5 | 2010-03-24 16:48:53 +0100 | [diff] [blame] | 139 | { |
Thomas Gleixner | 450ea48 | 2009-07-03 08:44:46 -0500 | [diff] [blame] | 140 | unsigned long flags; |
| 141 | |
| 142 | raw_spin_lock_irqsave(&l2x0_lock, flags); |
Catalin Marinas | 23107c5 | 2010-03-24 16:48:53 +0100 | [diff] [blame] | 143 | cache_sync(); |
Thomas Gleixner | 450ea48 | 2009-07-03 08:44:46 -0500 | [diff] [blame] | 144 | raw_spin_unlock_irqrestore(&l2x0_lock, flags); |
Catalin Marinas | 23107c5 | 2010-03-24 16:48:53 +0100 | [diff] [blame] | 145 | } |
| 146 | |
Colin Cross | 5ea3a7c | 2011-09-14 15:59:50 -0700 | [diff] [blame] | 147 | #ifdef CONFIG_PL310_ERRATA_727915 |
| 148 | static void l2x0_for_each_set_way(void __iomem *reg) |
| 149 | { |
| 150 | int set; |
| 151 | int way; |
| 152 | unsigned long flags; |
| 153 | |
| 154 | for (way = 0; way < l2x0_ways; way++) { |
| 155 | spin_lock_irqsave(&l2x0_lock, flags); |
| 156 | for (set = 0; set < l2x0_sets; set++) |
| 157 | writel_relaxed((way << 28) | (set << 5), reg); |
| 158 | cache_sync(); |
| 159 | spin_unlock_irqrestore(&l2x0_lock, flags); |
| 160 | } |
| 161 | } |
| 162 | #endif |
| 163 | |
Will Deacon | 38a8914 | 2011-07-01 14:36:19 +0100 | [diff] [blame] | 164 | static void __l2x0_flush_all(void) |
| 165 | { |
| 166 | debug_writel(0x03); |
| 167 | writel_relaxed(l2x0_way_mask, l2x0_base + L2X0_CLEAN_INV_WAY); |
| 168 | cache_wait_way(l2x0_base + L2X0_CLEAN_INV_WAY, l2x0_way_mask); |
| 169 | cache_sync(); |
| 170 | debug_writel(0x00); |
| 171 | } |
| 172 | |
Thomas Gleixner | 2fd8658 | 2010-07-31 21:05:24 +0530 | [diff] [blame] | 173 | static void l2x0_flush_all(void) |
| 174 | { |
| 175 | unsigned long flags; |
| 176 | |
Colin Cross | 5ea3a7c | 2011-09-14 15:59:50 -0700 | [diff] [blame] | 177 | #ifdef CONFIG_PL310_ERRATA_727915 |
| 178 | if (is_pl310_rev(REV_PL310_R2P0)) { |
| 179 | l2x0_for_each_set_way(l2x0_base + L2X0_CLEAN_INV_LINE_IDX); |
| 180 | return; |
| 181 | } |
| 182 | #endif |
| 183 | |
Thomas Gleixner | 2fd8658 | 2010-07-31 21:05:24 +0530 | [diff] [blame] | 184 | /* clean all ways */ |
Thomas Gleixner | 450ea48 | 2009-07-03 08:44:46 -0500 | [diff] [blame] | 185 | raw_spin_lock_irqsave(&l2x0_lock, flags); |
Will Deacon | 38a8914 | 2011-07-01 14:36:19 +0100 | [diff] [blame] | 186 | __l2x0_flush_all(); |
Thomas Gleixner | 450ea48 | 2009-07-03 08:44:46 -0500 | [diff] [blame] | 187 | raw_spin_unlock_irqrestore(&l2x0_lock, flags); |
Thomas Gleixner | 2fd8658 | 2010-07-31 21:05:24 +0530 | [diff] [blame] | 188 | } |
| 189 | |
Santosh Shilimkar | 444457c | 2010-07-11 14:58:41 +0530 | [diff] [blame] | 190 | static void l2x0_clean_all(void) |
| 191 | { |
| 192 | unsigned long flags; |
| 193 | |
Colin Cross | 5ea3a7c | 2011-09-14 15:59:50 -0700 | [diff] [blame] | 194 | #ifdef CONFIG_PL310_ERRATA_727915 |
| 195 | if (is_pl310_rev(REV_PL310_R2P0)) { |
| 196 | l2x0_for_each_set_way(l2x0_base + L2X0_CLEAN_LINE_IDX); |
| 197 | return; |
| 198 | } |
| 199 | #endif |
| 200 | |
Santosh Shilimkar | 444457c | 2010-07-11 14:58:41 +0530 | [diff] [blame] | 201 | /* clean all ways */ |
Thomas Gleixner | 450ea48 | 2009-07-03 08:44:46 -0500 | [diff] [blame] | 202 | raw_spin_lock_irqsave(&l2x0_lock, flags); |
Colin Cross | 5ea3a7c | 2011-09-14 15:59:50 -0700 | [diff] [blame] | 203 | debug_writel(0x03); |
Santosh Shilimkar | 444457c | 2010-07-11 14:58:41 +0530 | [diff] [blame] | 204 | writel_relaxed(l2x0_way_mask, l2x0_base + L2X0_CLEAN_WAY); |
| 205 | cache_wait_way(l2x0_base + L2X0_CLEAN_WAY, l2x0_way_mask); |
| 206 | cache_sync(); |
Colin Cross | 5ea3a7c | 2011-09-14 15:59:50 -0700 | [diff] [blame] | 207 | debug_writel(0x00); |
Thomas Gleixner | 450ea48 | 2009-07-03 08:44:46 -0500 | [diff] [blame] | 208 | raw_spin_unlock_irqrestore(&l2x0_lock, flags); |
Santosh Shilimkar | 444457c | 2010-07-11 14:58:41 +0530 | [diff] [blame] | 209 | } |
| 210 | |
Thomas Gleixner | 2fd8658 | 2010-07-31 21:05:24 +0530 | [diff] [blame] | 211 | static void l2x0_inv_all(void) |
Catalin Marinas | 382266a | 2007-02-05 14:48:19 +0100 | [diff] [blame] | 212 | { |
Russell King | 0eb948d | 2009-11-19 11:12:15 +0000 | [diff] [blame] | 213 | unsigned long flags; |
| 214 | |
Catalin Marinas | 382266a | 2007-02-05 14:48:19 +0100 | [diff] [blame] | 215 | /* invalidate all ways */ |
Thomas Gleixner | 450ea48 | 2009-07-03 08:44:46 -0500 | [diff] [blame] | 216 | raw_spin_lock_irqsave(&l2x0_lock, flags); |
Thomas Gleixner | 2fd8658 | 2010-07-31 21:05:24 +0530 | [diff] [blame] | 217 | /* Invalidating when L2 is enabled is a nono */ |
| 218 | BUG_ON(readl(l2x0_base + L2X0_CTRL) & 1); |
Catalin Marinas | 6775a55 | 2010-07-28 22:01:25 +0100 | [diff] [blame] | 219 | writel_relaxed(l2x0_way_mask, l2x0_base + L2X0_INV_WAY); |
Catalin Marinas | 9a6655e | 2010-08-31 13:05:22 +0100 | [diff] [blame] | 220 | cache_wait_way(l2x0_base + L2X0_INV_WAY, l2x0_way_mask); |
Catalin Marinas | 382266a | 2007-02-05 14:48:19 +0100 | [diff] [blame] | 221 | cache_sync(); |
Thomas Gleixner | 450ea48 | 2009-07-03 08:44:46 -0500 | [diff] [blame] | 222 | raw_spin_unlock_irqrestore(&l2x0_lock, flags); |
Catalin Marinas | 382266a | 2007-02-05 14:48:19 +0100 | [diff] [blame] | 223 | } |
| 224 | |
| 225 | static void l2x0_inv_range(unsigned long start, unsigned long end) |
| 226 | { |
Russell King | 3d10743 | 2009-11-19 11:41:09 +0000 | [diff] [blame] | 227 | void __iomem *base = l2x0_base; |
Russell King | 0eb948d | 2009-11-19 11:12:15 +0000 | [diff] [blame] | 228 | unsigned long flags; |
Catalin Marinas | 382266a | 2007-02-05 14:48:19 +0100 | [diff] [blame] | 229 | |
Thomas Gleixner | 450ea48 | 2009-07-03 08:44:46 -0500 | [diff] [blame] | 230 | raw_spin_lock_irqsave(&l2x0_lock, flags); |
Rui Sousa | 4f6627a | 2007-09-15 00:56:19 +0100 | [diff] [blame] | 231 | if (start & (CACHE_LINE_SIZE - 1)) { |
| 232 | start &= ~(CACHE_LINE_SIZE - 1); |
Santosh Shilimkar | 9e65582 | 2010-02-04 19:42:42 +0100 | [diff] [blame] | 233 | debug_writel(0x03); |
Santosh Shilimkar | 424d6b1 | 2010-02-04 19:35:06 +0100 | [diff] [blame] | 234 | l2x0_flush_line(start); |
Santosh Shilimkar | 9e65582 | 2010-02-04 19:42:42 +0100 | [diff] [blame] | 235 | debug_writel(0x00); |
Rui Sousa | 4f6627a | 2007-09-15 00:56:19 +0100 | [diff] [blame] | 236 | start += CACHE_LINE_SIZE; |
| 237 | } |
| 238 | |
| 239 | if (end & (CACHE_LINE_SIZE - 1)) { |
| 240 | end &= ~(CACHE_LINE_SIZE - 1); |
Santosh Shilimkar | 9e65582 | 2010-02-04 19:42:42 +0100 | [diff] [blame] | 241 | debug_writel(0x03); |
Santosh Shilimkar | 424d6b1 | 2010-02-04 19:35:06 +0100 | [diff] [blame] | 242 | l2x0_flush_line(end); |
Santosh Shilimkar | 9e65582 | 2010-02-04 19:42:42 +0100 | [diff] [blame] | 243 | debug_writel(0x00); |
Rui Sousa | 4f6627a | 2007-09-15 00:56:19 +0100 | [diff] [blame] | 244 | } |
| 245 | |
Russell King | 0eb948d | 2009-11-19 11:12:15 +0000 | [diff] [blame] | 246 | while (start < end) { |
| 247 | unsigned long blk_end = start + min(end - start, 4096UL); |
| 248 | |
| 249 | while (start < blk_end) { |
Santosh Shilimkar | 424d6b1 | 2010-02-04 19:35:06 +0100 | [diff] [blame] | 250 | l2x0_inv_line(start); |
Russell King | 0eb948d | 2009-11-19 11:12:15 +0000 | [diff] [blame] | 251 | start += CACHE_LINE_SIZE; |
| 252 | } |
| 253 | |
| 254 | if (blk_end < end) { |
Thomas Gleixner | 450ea48 | 2009-07-03 08:44:46 -0500 | [diff] [blame] | 255 | raw_spin_unlock_irqrestore(&l2x0_lock, flags); |
| 256 | raw_spin_lock_irqsave(&l2x0_lock, flags); |
Russell King | 0eb948d | 2009-11-19 11:12:15 +0000 | [diff] [blame] | 257 | } |
| 258 | } |
Russell King | 3d10743 | 2009-11-19 11:41:09 +0000 | [diff] [blame] | 259 | cache_wait(base + L2X0_INV_LINE_PA, 1); |
Catalin Marinas | 382266a | 2007-02-05 14:48:19 +0100 | [diff] [blame] | 260 | cache_sync(); |
Thomas Gleixner | 450ea48 | 2009-07-03 08:44:46 -0500 | [diff] [blame] | 261 | raw_spin_unlock_irqrestore(&l2x0_lock, flags); |
Catalin Marinas | 382266a | 2007-02-05 14:48:19 +0100 | [diff] [blame] | 262 | } |
| 263 | |
| 264 | static void l2x0_clean_range(unsigned long start, unsigned long end) |
| 265 | { |
Russell King | 3d10743 | 2009-11-19 11:41:09 +0000 | [diff] [blame] | 266 | void __iomem *base = l2x0_base; |
Russell King | 0eb948d | 2009-11-19 11:12:15 +0000 | [diff] [blame] | 267 | unsigned long flags; |
Catalin Marinas | 382266a | 2007-02-05 14:48:19 +0100 | [diff] [blame] | 268 | |
Santosh Shilimkar | 444457c | 2010-07-11 14:58:41 +0530 | [diff] [blame] | 269 | if ((end - start) >= l2x0_size) { |
| 270 | l2x0_clean_all(); |
| 271 | return; |
| 272 | } |
| 273 | |
Thomas Gleixner | 450ea48 | 2009-07-03 08:44:46 -0500 | [diff] [blame] | 274 | raw_spin_lock_irqsave(&l2x0_lock, flags); |
Catalin Marinas | 382266a | 2007-02-05 14:48:19 +0100 | [diff] [blame] | 275 | start &= ~(CACHE_LINE_SIZE - 1); |
Russell King | 0eb948d | 2009-11-19 11:12:15 +0000 | [diff] [blame] | 276 | while (start < end) { |
| 277 | unsigned long blk_end = start + min(end - start, 4096UL); |
| 278 | |
| 279 | while (start < blk_end) { |
Santosh Shilimkar | 424d6b1 | 2010-02-04 19:35:06 +0100 | [diff] [blame] | 280 | l2x0_clean_line(start); |
Russell King | 0eb948d | 2009-11-19 11:12:15 +0000 | [diff] [blame] | 281 | start += CACHE_LINE_SIZE; |
| 282 | } |
| 283 | |
| 284 | if (blk_end < end) { |
Thomas Gleixner | 450ea48 | 2009-07-03 08:44:46 -0500 | [diff] [blame] | 285 | raw_spin_unlock_irqrestore(&l2x0_lock, flags); |
| 286 | raw_spin_lock_irqsave(&l2x0_lock, flags); |
Russell King | 0eb948d | 2009-11-19 11:12:15 +0000 | [diff] [blame] | 287 | } |
| 288 | } |
Russell King | 3d10743 | 2009-11-19 11:41:09 +0000 | [diff] [blame] | 289 | cache_wait(base + L2X0_CLEAN_LINE_PA, 1); |
Catalin Marinas | 382266a | 2007-02-05 14:48:19 +0100 | [diff] [blame] | 290 | cache_sync(); |
Thomas Gleixner | 450ea48 | 2009-07-03 08:44:46 -0500 | [diff] [blame] | 291 | raw_spin_unlock_irqrestore(&l2x0_lock, flags); |
Catalin Marinas | 382266a | 2007-02-05 14:48:19 +0100 | [diff] [blame] | 292 | } |
| 293 | |
| 294 | static void l2x0_flush_range(unsigned long start, unsigned long end) |
| 295 | { |
Russell King | 3d10743 | 2009-11-19 11:41:09 +0000 | [diff] [blame] | 296 | void __iomem *base = l2x0_base; |
Russell King | 0eb948d | 2009-11-19 11:12:15 +0000 | [diff] [blame] | 297 | unsigned long flags; |
Catalin Marinas | 382266a | 2007-02-05 14:48:19 +0100 | [diff] [blame] | 298 | |
Santosh Shilimkar | 444457c | 2010-07-11 14:58:41 +0530 | [diff] [blame] | 299 | if ((end - start) >= l2x0_size) { |
| 300 | l2x0_flush_all(); |
| 301 | return; |
| 302 | } |
| 303 | |
Thomas Gleixner | 450ea48 | 2009-07-03 08:44:46 -0500 | [diff] [blame] | 304 | raw_spin_lock_irqsave(&l2x0_lock, flags); |
Catalin Marinas | 382266a | 2007-02-05 14:48:19 +0100 | [diff] [blame] | 305 | start &= ~(CACHE_LINE_SIZE - 1); |
Russell King | 0eb948d | 2009-11-19 11:12:15 +0000 | [diff] [blame] | 306 | while (start < end) { |
| 307 | unsigned long blk_end = start + min(end - start, 4096UL); |
| 308 | |
Santosh Shilimkar | 9e65582 | 2010-02-04 19:42:42 +0100 | [diff] [blame] | 309 | debug_writel(0x03); |
Russell King | 0eb948d | 2009-11-19 11:12:15 +0000 | [diff] [blame] | 310 | while (start < blk_end) { |
Santosh Shilimkar | 424d6b1 | 2010-02-04 19:35:06 +0100 | [diff] [blame] | 311 | l2x0_flush_line(start); |
Russell King | 0eb948d | 2009-11-19 11:12:15 +0000 | [diff] [blame] | 312 | start += CACHE_LINE_SIZE; |
| 313 | } |
Santosh Shilimkar | 9e65582 | 2010-02-04 19:42:42 +0100 | [diff] [blame] | 314 | debug_writel(0x00); |
Russell King | 0eb948d | 2009-11-19 11:12:15 +0000 | [diff] [blame] | 315 | |
| 316 | if (blk_end < end) { |
Thomas Gleixner | 450ea48 | 2009-07-03 08:44:46 -0500 | [diff] [blame] | 317 | raw_spin_unlock_irqrestore(&l2x0_lock, flags); |
| 318 | raw_spin_lock_irqsave(&l2x0_lock, flags); |
Russell King | 0eb948d | 2009-11-19 11:12:15 +0000 | [diff] [blame] | 319 | } |
| 320 | } |
Russell King | 3d10743 | 2009-11-19 11:41:09 +0000 | [diff] [blame] | 321 | cache_wait(base + L2X0_CLEAN_INV_LINE_PA, 1); |
Catalin Marinas | 382266a | 2007-02-05 14:48:19 +0100 | [diff] [blame] | 322 | cache_sync(); |
Thomas Gleixner | 450ea48 | 2009-07-03 08:44:46 -0500 | [diff] [blame] | 323 | raw_spin_unlock_irqrestore(&l2x0_lock, flags); |
Catalin Marinas | 382266a | 2007-02-05 14:48:19 +0100 | [diff] [blame] | 324 | } |
| 325 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 326 | void l2x0_flush_range_atomic(unsigned long start, unsigned long end) |
| 327 | { |
| 328 | unsigned long addr; |
| 329 | |
| 330 | start &= ~(CACHE_LINE_SIZE - 1); |
| 331 | for (addr = start; addr < end; addr += CACHE_LINE_SIZE) |
| 332 | writel_relaxed(addr, l2x0_base + L2X0_CLEAN_INV_LINE_PA); |
| 333 | |
| 334 | mb(); |
| 335 | } |
| 336 | |
Thomas Gleixner | 2fd8658 | 2010-07-31 21:05:24 +0530 | [diff] [blame] | 337 | static void l2x0_disable(void) |
| 338 | { |
| 339 | unsigned long flags; |
| 340 | |
Thomas Gleixner | 450ea48 | 2009-07-03 08:44:46 -0500 | [diff] [blame] | 341 | raw_spin_lock_irqsave(&l2x0_lock, flags); |
Will Deacon | 38a8914 | 2011-07-01 14:36:19 +0100 | [diff] [blame] | 342 | __l2x0_flush_all(); |
| 343 | writel_relaxed(0, l2x0_base + L2X0_CTRL); |
| 344 | dsb(); |
Thomas Gleixner | 450ea48 | 2009-07-03 08:44:46 -0500 | [diff] [blame] | 345 | raw_spin_unlock_irqrestore(&l2x0_lock, flags); |
Thomas Gleixner | 2fd8658 | 2010-07-31 21:05:24 +0530 | [diff] [blame] | 346 | } |
| 347 | |
Russell King | 1add908 | 2011-09-18 11:27:30 +0100 | [diff] [blame] | 348 | static void l2x0_unlock(u32 cache_id) |
Linus Walleij | 20c335a | 2011-09-06 07:45:46 +0100 | [diff] [blame] | 349 | { |
| 350 | int lockregs; |
| 351 | int i; |
| 352 | |
| 353 | if (cache_id == L2X0_CACHE_ID_PART_L310) |
| 354 | lockregs = 8; |
| 355 | else |
| 356 | /* L210 and unknown types */ |
| 357 | lockregs = 1; |
| 358 | |
| 359 | for (i = 0; i < lockregs; i++) { |
| 360 | writel_relaxed(0x0, l2x0_base + L2X0_LOCKDOWN_WAY_D_BASE + |
| 361 | i * L2X0_LOCKDOWN_STRIDE); |
| 362 | writel_relaxed(0x0, l2x0_base + L2X0_LOCKDOWN_WAY_I_BASE + |
| 363 | i * L2X0_LOCKDOWN_STRIDE); |
| 364 | } |
| 365 | } |
| 366 | |
Russell King | 1add908 | 2011-09-18 11:27:30 +0100 | [diff] [blame] | 367 | void __init l2x0_init(void __iomem *base, u32 aux_val, u32 aux_mask) |
Catalin Marinas | 382266a | 2007-02-05 14:48:19 +0100 | [diff] [blame] | 368 | { |
Russell King | 1add908 | 2011-09-18 11:27:30 +0100 | [diff] [blame] | 369 | u32 aux; |
| 370 | u32 cache_id; |
| 371 | u32 way_size = 0; |
Linus Walleij | 20c335a | 2011-09-06 07:45:46 +0100 | [diff] [blame] | 372 | int ways; |
Jason McMullan | 64039be | 2010-05-05 18:59:37 +0100 | [diff] [blame] | 373 | const char *type; |
Catalin Marinas | 382266a | 2007-02-05 14:48:19 +0100 | [diff] [blame] | 374 | |
| 375 | l2x0_base = base; |
Linus Walleij | 20c335a | 2011-09-06 07:45:46 +0100 | [diff] [blame] | 376 | cache_id = readl_relaxed(l2x0_base + L2X0_CACHE_ID); |
| 377 | l2x0_cache_id = cache_id; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 378 | |
Catalin Marinas | 6775a55 | 2010-07-28 22:01:25 +0100 | [diff] [blame] | 379 | aux = readl_relaxed(l2x0_base + L2X0_AUX_CTRL); |
Jason McMullan | 64039be | 2010-05-05 18:59:37 +0100 | [diff] [blame] | 380 | |
Sascha Hauer | 4082cfa | 2010-07-08 08:36:21 +0100 | [diff] [blame] | 381 | aux &= aux_mask; |
| 382 | aux |= aux_val; |
| 383 | |
Jason McMullan | 64039be | 2010-05-05 18:59:37 +0100 | [diff] [blame] | 384 | /* Determine the number of ways */ |
Linus Walleij | 20c335a | 2011-09-06 07:45:46 +0100 | [diff] [blame] | 385 | switch (cache_id & L2X0_CACHE_ID_PART_MASK) { |
Jason McMullan | 64039be | 2010-05-05 18:59:37 +0100 | [diff] [blame] | 386 | case L2X0_CACHE_ID_PART_L310: |
| 387 | if (aux & (1 << 16)) |
Linus Walleij | 20c335a | 2011-09-06 07:45:46 +0100 | [diff] [blame] | 388 | ways = 16; |
Jason McMullan | 64039be | 2010-05-05 18:59:37 +0100 | [diff] [blame] | 389 | else |
Linus Walleij | 20c335a | 2011-09-06 07:45:46 +0100 | [diff] [blame] | 390 | ways = 8; |
Jason McMullan | 64039be | 2010-05-05 18:59:37 +0100 | [diff] [blame] | 391 | type = "L310"; |
| 392 | break; |
| 393 | case L2X0_CACHE_ID_PART_L210: |
Linus Walleij | 20c335a | 2011-09-06 07:45:46 +0100 | [diff] [blame] | 394 | ways = (aux >> 13) & 0xf; |
Jason McMullan | 64039be | 2010-05-05 18:59:37 +0100 | [diff] [blame] | 395 | type = "L210"; |
| 396 | break; |
| 397 | default: |
| 398 | /* Assume unknown chips have 8 ways */ |
Linus Walleij | 20c335a | 2011-09-06 07:45:46 +0100 | [diff] [blame] | 399 | ways = 8; |
Jason McMullan | 64039be | 2010-05-05 18:59:37 +0100 | [diff] [blame] | 400 | type = "L2x0 series"; |
| 401 | break; |
| 402 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 403 | writel_relaxed(aux, l2x0_base + L2X0_AUX_CTRL); |
Linus Walleij | 20c335a | 2011-09-06 07:45:46 +0100 | [diff] [blame] | 404 | l2x0_way_mask = (1 << ways) - 1; |
Jason McMullan | 64039be | 2010-05-05 18:59:37 +0100 | [diff] [blame] | 405 | |
Srinidhi Kasagar | 48371cd | 2009-12-02 06:18:03 +0100 | [diff] [blame] | 406 | /* |
Santosh Shilimkar | 5ba7037 | 2010-07-11 14:35:37 +0530 | [diff] [blame] | 407 | * L2 cache Size = Way size * Number of ways |
| 408 | */ |
| 409 | way_size = (aux & L2X0_AUX_CTRL_WAY_SIZE_MASK) >> 17; |
Linus Walleij | 20c335a | 2011-09-06 07:45:46 +0100 | [diff] [blame] | 410 | way_size = 1 << (way_size + 3); |
| 411 | l2x0_size = ways * way_size * SZ_1K; |
Colin Cross | 5ea3a7c | 2011-09-14 15:59:50 -0700 | [diff] [blame] | 412 | l2x0_sets = way_size / CACHE_LINE_SIZE; |
Linus Walleij | 20c335a | 2011-09-06 07:45:46 +0100 | [diff] [blame] | 413 | l2x0_ways = ways; |
Santosh Shilimkar | 5ba7037 | 2010-07-11 14:35:37 +0530 | [diff] [blame] | 414 | |
Linus Walleij | 20c335a | 2011-09-06 07:45:46 +0100 | [diff] [blame] | 415 | /* |
| 416 | * Check if l2x0 controller is already enabled. |
| 417 | * If you are booting from non-secure mode |
| 418 | * accessing the below registers will fault. |
| 419 | */ |
| 420 | if (!(readl_relaxed(l2x0_base + L2X0_CTRL) & 1)) { |
| 421 | /* Make sure that I&D is not locked down when starting */ |
| 422 | l2x0_unlock(cache_id); |
Catalin Marinas | 382266a | 2007-02-05 14:48:19 +0100 | [diff] [blame] | 423 | |
Linus Walleij | 20c335a | 2011-09-06 07:45:46 +0100 | [diff] [blame] | 424 | /* l2x0 controller is disabled */ |
| 425 | writel_relaxed(aux, l2x0_base + L2X0_AUX_CTRL); |
Catalin Marinas | 382266a | 2007-02-05 14:48:19 +0100 | [diff] [blame] | 426 | |
Barry Song | a9dd8f9 | 2011-09-30 14:43:12 +0100 | [diff] [blame] | 427 | l2x0_saved_regs.aux_ctrl = aux; |
| 428 | |
Linus Walleij | 20c335a | 2011-09-06 07:45:46 +0100 | [diff] [blame] | 429 | l2x0_inv_all(); |
| 430 | |
| 431 | /* enable L2X0 */ |
| 432 | writel_relaxed(1, l2x0_base + L2X0_CTRL); |
Srinidhi Kasagar | 48371cd | 2009-12-02 06:18:03 +0100 | [diff] [blame] | 433 | } |
Catalin Marinas | 382266a | 2007-02-05 14:48:19 +0100 | [diff] [blame] | 434 | |
Linus Walleij | 20c335a | 2011-09-06 07:45:46 +0100 | [diff] [blame] | 435 | outer_cache.inv_range = l2x0_inv_range; |
| 436 | outer_cache.clean_range = l2x0_clean_range; |
| 437 | outer_cache.flush_range = l2x0_flush_range; |
Catalin Marinas | 23107c5 | 2010-03-24 16:48:53 +0100 | [diff] [blame] | 438 | outer_cache.sync = l2x0_cache_sync; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 439 | |
Thomas Gleixner | 2fd8658 | 2010-07-31 21:05:24 +0530 | [diff] [blame] | 440 | outer_cache.flush_all = l2x0_flush_all; |
| 441 | outer_cache.inv_all = l2x0_inv_all; |
| 442 | outer_cache.disable = l2x0_disable; |
Santosh Shilimkar | 2839e06 | 2011-03-08 06:59:54 +0100 | [diff] [blame] | 443 | outer_cache.set_debug = l2x0_set_debug; |
Catalin Marinas | 382266a | 2007-02-05 14:48:19 +0100 | [diff] [blame] | 444 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 445 | mb(); |
Jason McMullan | 64039be | 2010-05-05 18:59:37 +0100 | [diff] [blame] | 446 | printk(KERN_INFO "%s cache controller enabled\n", type); |
Santosh Shilimkar | 5ba7037 | 2010-07-11 14:35:37 +0530 | [diff] [blame] | 447 | printk(KERN_INFO "l2x0: %d ways, CACHE_ID 0x%08x, AUX_CTRL 0x%08x, Cache size: %d B\n", |
Linus Walleij | 20c335a | 2011-09-06 07:45:46 +0100 | [diff] [blame] | 448 | ways, cache_id, aux, l2x0_size); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 449 | |
Taniya Das | 38a8c6e | 2012-05-09 20:34:39 +0530 | [diff] [blame^] | 450 | /* Save the L2X0 contents, as they are not modified else where */ |
| 451 | pl310_save(); |
Sridhar Parasuram | a022290 | 2012-04-27 11:18:02 -0700 | [diff] [blame] | 452 | } |
| 453 | |
Rob Herring | 78ae8b1 | 2011-08-03 18:12:05 +0100 | [diff] [blame] | 454 | #ifdef CONFIG_OF |
| 455 | static void __init l2x0_of_setup(const struct device_node *np, |
Russell King | 1add908 | 2011-09-18 11:27:30 +0100 | [diff] [blame] | 456 | u32 *aux_val, u32 *aux_mask) |
Rob Herring | 78ae8b1 | 2011-08-03 18:12:05 +0100 | [diff] [blame] | 457 | { |
| 458 | u32 data[2] = { 0, 0 }; |
| 459 | u32 tag = 0; |
| 460 | u32 dirty = 0; |
| 461 | u32 val = 0, mask = 0; |
| 462 | |
| 463 | of_property_read_u32(np, "arm,tag-latency", &tag); |
| 464 | if (tag) { |
| 465 | mask |= L2X0_AUX_CTRL_TAG_LATENCY_MASK; |
| 466 | val |= (tag - 1) << L2X0_AUX_CTRL_TAG_LATENCY_SHIFT; |
| 467 | } |
| 468 | |
| 469 | of_property_read_u32_array(np, "arm,data-latency", |
| 470 | data, ARRAY_SIZE(data)); |
| 471 | if (data[0] && data[1]) { |
| 472 | mask |= L2X0_AUX_CTRL_DATA_RD_LATENCY_MASK | |
| 473 | L2X0_AUX_CTRL_DATA_WR_LATENCY_MASK; |
| 474 | val |= ((data[0] - 1) << L2X0_AUX_CTRL_DATA_RD_LATENCY_SHIFT) | |
| 475 | ((data[1] - 1) << L2X0_AUX_CTRL_DATA_WR_LATENCY_SHIFT); |
| 476 | } |
| 477 | |
| 478 | of_property_read_u32(np, "arm,dirty-latency", &dirty); |
| 479 | if (dirty) { |
| 480 | mask |= L2X0_AUX_CTRL_DIRTY_LATENCY_MASK; |
| 481 | val |= (dirty - 1) << L2X0_AUX_CTRL_DIRTY_LATENCY_SHIFT; |
| 482 | } |
| 483 | |
| 484 | *aux_val &= ~mask; |
| 485 | *aux_val |= val; |
| 486 | *aux_mask &= ~mask; |
| 487 | } |
| 488 | |
| 489 | static void __init pl310_of_setup(const struct device_node *np, |
Russell King | 1add908 | 2011-09-18 11:27:30 +0100 | [diff] [blame] | 490 | u32 *aux_val, u32 *aux_mask) |
Rob Herring | 78ae8b1 | 2011-08-03 18:12:05 +0100 | [diff] [blame] | 491 | { |
| 492 | u32 data[3] = { 0, 0, 0 }; |
| 493 | u32 tag[3] = { 0, 0, 0 }; |
| 494 | u32 filter[2] = { 0, 0 }; |
| 495 | |
| 496 | of_property_read_u32_array(np, "arm,tag-latency", tag, ARRAY_SIZE(tag)); |
| 497 | if (tag[0] && tag[1] && tag[2]) |
| 498 | writel_relaxed( |
| 499 | ((tag[0] - 1) << L2X0_LATENCY_CTRL_RD_SHIFT) | |
| 500 | ((tag[1] - 1) << L2X0_LATENCY_CTRL_WR_SHIFT) | |
| 501 | ((tag[2] - 1) << L2X0_LATENCY_CTRL_SETUP_SHIFT), |
| 502 | l2x0_base + L2X0_TAG_LATENCY_CTRL); |
| 503 | |
| 504 | of_property_read_u32_array(np, "arm,data-latency", |
| 505 | data, ARRAY_SIZE(data)); |
| 506 | if (data[0] && data[1] && data[2]) |
| 507 | writel_relaxed( |
| 508 | ((data[0] - 1) << L2X0_LATENCY_CTRL_RD_SHIFT) | |
| 509 | ((data[1] - 1) << L2X0_LATENCY_CTRL_WR_SHIFT) | |
| 510 | ((data[2] - 1) << L2X0_LATENCY_CTRL_SETUP_SHIFT), |
| 511 | l2x0_base + L2X0_DATA_LATENCY_CTRL); |
| 512 | |
| 513 | of_property_read_u32_array(np, "arm,filter-ranges", |
| 514 | filter, ARRAY_SIZE(filter)); |
Barry Song | ce72d04 | 2011-09-14 03:20:01 +0100 | [diff] [blame] | 515 | if (filter[1]) { |
Rob Herring | 78ae8b1 | 2011-08-03 18:12:05 +0100 | [diff] [blame] | 516 | writel_relaxed(ALIGN(filter[0] + filter[1], SZ_1M), |
| 517 | l2x0_base + L2X0_ADDR_FILTER_END); |
| 518 | writel_relaxed((filter[0] & ~(SZ_1M - 1)) | L2X0_ADDR_FILTER_EN, |
| 519 | l2x0_base + L2X0_ADDR_FILTER_START); |
| 520 | } |
| 521 | } |
Taniya Das | 38a8c6e | 2012-05-09 20:34:39 +0530 | [diff] [blame^] | 522 | #endif |
Rob Herring | 78ae8b1 | 2011-08-03 18:12:05 +0100 | [diff] [blame] | 523 | |
Stephen Boyd | 22ab934 | 2012-04-25 11:42:14 -0700 | [diff] [blame] | 524 | static void pl310_save(void) |
Barry Song | a9dd8f9 | 2011-09-30 14:43:12 +0100 | [diff] [blame] | 525 | { |
| 526 | u32 l2x0_revision = readl_relaxed(l2x0_base + L2X0_CACHE_ID) & |
| 527 | L2X0_CACHE_ID_RTL_MASK; |
| 528 | |
| 529 | l2x0_saved_regs.tag_latency = readl_relaxed(l2x0_base + |
| 530 | L2X0_TAG_LATENCY_CTRL); |
| 531 | l2x0_saved_regs.data_latency = readl_relaxed(l2x0_base + |
| 532 | L2X0_DATA_LATENCY_CTRL); |
| 533 | l2x0_saved_regs.filter_end = readl_relaxed(l2x0_base + |
| 534 | L2X0_ADDR_FILTER_END); |
| 535 | l2x0_saved_regs.filter_start = readl_relaxed(l2x0_base + |
| 536 | L2X0_ADDR_FILTER_START); |
| 537 | |
| 538 | if (l2x0_revision >= L2X0_CACHE_ID_RTL_R2P0) { |
| 539 | /* |
| 540 | * From r2p0, there is Prefetch offset/control register |
| 541 | */ |
| 542 | l2x0_saved_regs.prefetch_ctrl = readl_relaxed(l2x0_base + |
| 543 | L2X0_PREFETCH_CTRL); |
| 544 | /* |
| 545 | * From r3p0, there is Power control register |
| 546 | */ |
| 547 | if (l2x0_revision >= L2X0_CACHE_ID_RTL_R3P0) |
| 548 | l2x0_saved_regs.pwr_ctrl = readl_relaxed(l2x0_base + |
| 549 | L2X0_POWER_CTRL); |
| 550 | } |
| 551 | } |
| 552 | |
| 553 | static void l2x0_resume(void) |
| 554 | { |
| 555 | if (!(readl_relaxed(l2x0_base + L2X0_CTRL) & 1)) { |
| 556 | /* restore aux ctrl and enable l2 */ |
| 557 | l2x0_unlock(readl_relaxed(l2x0_base + L2X0_CACHE_ID)); |
| 558 | |
| 559 | writel_relaxed(l2x0_saved_regs.aux_ctrl, l2x0_base + |
| 560 | L2X0_AUX_CTRL); |
| 561 | |
| 562 | l2x0_inv_all(); |
| 563 | |
| 564 | writel_relaxed(1, l2x0_base + L2X0_CTRL); |
| 565 | } |
| 566 | } |
| 567 | |
| 568 | static void pl310_resume(void) |
| 569 | { |
| 570 | u32 l2x0_revision; |
| 571 | |
| 572 | if (!(readl_relaxed(l2x0_base + L2X0_CTRL) & 1)) { |
| 573 | /* restore pl310 setup */ |
| 574 | writel_relaxed(l2x0_saved_regs.tag_latency, |
| 575 | l2x0_base + L2X0_TAG_LATENCY_CTRL); |
| 576 | writel_relaxed(l2x0_saved_regs.data_latency, |
| 577 | l2x0_base + L2X0_DATA_LATENCY_CTRL); |
| 578 | writel_relaxed(l2x0_saved_regs.filter_end, |
| 579 | l2x0_base + L2X0_ADDR_FILTER_END); |
| 580 | writel_relaxed(l2x0_saved_regs.filter_start, |
| 581 | l2x0_base + L2X0_ADDR_FILTER_START); |
| 582 | |
| 583 | l2x0_revision = readl_relaxed(l2x0_base + L2X0_CACHE_ID) & |
| 584 | L2X0_CACHE_ID_RTL_MASK; |
| 585 | |
| 586 | if (l2x0_revision >= L2X0_CACHE_ID_RTL_R2P0) { |
| 587 | writel_relaxed(l2x0_saved_regs.prefetch_ctrl, |
| 588 | l2x0_base + L2X0_PREFETCH_CTRL); |
| 589 | if (l2x0_revision >= L2X0_CACHE_ID_RTL_R3P0) |
| 590 | writel_relaxed(l2x0_saved_regs.pwr_ctrl, |
| 591 | l2x0_base + L2X0_POWER_CTRL); |
| 592 | } |
| 593 | } |
| 594 | |
| 595 | l2x0_resume(); |
| 596 | } |
| 597 | |
Taniya Das | 38a8c6e | 2012-05-09 20:34:39 +0530 | [diff] [blame^] | 598 | #ifdef CONFIG_OF |
Barry Song | a9dd8f9 | 2011-09-30 14:43:12 +0100 | [diff] [blame] | 599 | static const struct l2x0_of_data pl310_data = { |
| 600 | pl310_of_setup, |
| 601 | pl310_save, |
| 602 | pl310_resume, |
| 603 | }; |
| 604 | |
| 605 | static const struct l2x0_of_data l2x0_data = { |
| 606 | l2x0_of_setup, |
| 607 | NULL, |
| 608 | l2x0_resume, |
| 609 | }; |
| 610 | |
Rob Herring | 78ae8b1 | 2011-08-03 18:12:05 +0100 | [diff] [blame] | 611 | static const struct of_device_id l2x0_ids[] __initconst = { |
Barry Song | a9dd8f9 | 2011-09-30 14:43:12 +0100 | [diff] [blame] | 612 | { .compatible = "arm,pl310-cache", .data = (void *)&pl310_data }, |
| 613 | { .compatible = "arm,l220-cache", .data = (void *)&l2x0_data }, |
| 614 | { .compatible = "arm,l210-cache", .data = (void *)&l2x0_data }, |
Rob Herring | 78ae8b1 | 2011-08-03 18:12:05 +0100 | [diff] [blame] | 615 | {} |
| 616 | }; |
| 617 | |
Russell King | 1add908 | 2011-09-18 11:27:30 +0100 | [diff] [blame] | 618 | int __init l2x0_of_init(u32 aux_val, u32 aux_mask) |
Rob Herring | 78ae8b1 | 2011-08-03 18:12:05 +0100 | [diff] [blame] | 619 | { |
| 620 | struct device_node *np; |
Barry Song | a9dd8f9 | 2011-09-30 14:43:12 +0100 | [diff] [blame] | 621 | struct l2x0_of_data *data; |
| 622 | struct resource res; |
Rob Herring | 78ae8b1 | 2011-08-03 18:12:05 +0100 | [diff] [blame] | 623 | |
| 624 | np = of_find_matching_node(NULL, l2x0_ids); |
| 625 | if (!np) |
| 626 | return -ENODEV; |
Barry Song | a9dd8f9 | 2011-09-30 14:43:12 +0100 | [diff] [blame] | 627 | |
| 628 | if (of_address_to_resource(np, 0, &res)) |
| 629 | return -ENODEV; |
| 630 | |
| 631 | l2x0_base = ioremap(res.start, resource_size(&res)); |
Rob Herring | 78ae8b1 | 2011-08-03 18:12:05 +0100 | [diff] [blame] | 632 | if (!l2x0_base) |
| 633 | return -ENOMEM; |
| 634 | |
Barry Song | a9dd8f9 | 2011-09-30 14:43:12 +0100 | [diff] [blame] | 635 | l2x0_saved_regs.phy_base = res.start; |
| 636 | |
| 637 | data = of_match_node(l2x0_ids, np)->data; |
| 638 | |
Rob Herring | 78ae8b1 | 2011-08-03 18:12:05 +0100 | [diff] [blame] | 639 | /* L2 configuration can only be changed if the cache is disabled */ |
| 640 | if (!(readl_relaxed(l2x0_base + L2X0_CTRL) & 1)) { |
Barry Song | a9dd8f9 | 2011-09-30 14:43:12 +0100 | [diff] [blame] | 641 | if (data->setup) |
| 642 | data->setup(np, &aux_val, &aux_mask); |
Rob Herring | 78ae8b1 | 2011-08-03 18:12:05 +0100 | [diff] [blame] | 643 | } |
Barry Song | a9dd8f9 | 2011-09-30 14:43:12 +0100 | [diff] [blame] | 644 | |
| 645 | if (data->save) |
| 646 | data->save(); |
| 647 | |
Rob Herring | 78ae8b1 | 2011-08-03 18:12:05 +0100 | [diff] [blame] | 648 | l2x0_init(l2x0_base, aux_val, aux_mask); |
Barry Song | a9dd8f9 | 2011-09-30 14:43:12 +0100 | [diff] [blame] | 649 | |
| 650 | outer_cache.resume = data->resume; |
Rob Herring | 78ae8b1 | 2011-08-03 18:12:05 +0100 | [diff] [blame] | 651 | return 0; |
| 652 | } |
| 653 | #endif |
Taniya Das | 38a8c6e | 2012-05-09 20:34:39 +0530 | [diff] [blame^] | 654 | |
| 655 | void l2cc_suspend(void) |
| 656 | { |
| 657 | l2x0_disable(); |
| 658 | dmb(); |
| 659 | } |
| 660 | |
| 661 | void l2cc_resume(void) |
| 662 | { |
| 663 | pl310_resume(); |
| 664 | dmb(); |
| 665 | } |