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