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