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 |
Duy Truong | 790f06d | 2013-02-13 16:38:12 -0800 | [diff] [blame] | 5 | * Copyright (c) 2009, 2011-2012, The Linux Foundation. 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 | |
Ashwin Chaugule | 8b459cc | 2012-11-26 15:20:54 -0500 | [diff] [blame] | 32 | 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); |
Girish Mahadevan | 74934a3 | 2012-10-11 10:44:47 -0600 | [diff] [blame] | 41 | static void pl310_resume(void); |
| 42 | static void l2x0_resume(void); |
Colin Cross | 74b6cdd | 2011-09-14 15:59:50 -0700 | [diff] [blame] | 43 | |
| 44 | static inline bool is_pl310_rev(int rev) |
| 45 | { |
| 46 | return (l2x0_cache_id & |
| 47 | (L2X0_CACHE_ID_PART_MASK | L2X0_CACHE_ID_REV_MASK)) == |
| 48 | (L2X0_CACHE_ID_PART_L310 | rev); |
| 49 | } |
Catalin Marinas | 382266a | 2007-02-05 14:48:19 +0100 | [diff] [blame] | 50 | |
Barry Song | 91c2ebb | 2011-09-30 14:43:12 +0100 | [diff] [blame] | 51 | struct l2x0_regs l2x0_saved_regs; |
| 52 | |
| 53 | struct l2x0_of_data { |
Russell King | 3e175ca | 2011-09-18 11:27:30 +0100 | [diff] [blame] | 54 | void (*setup)(const struct device_node *, u32 *, u32 *); |
Barry Song | 91c2ebb | 2011-09-30 14:43:12 +0100 | [diff] [blame] | 55 | void (*save)(void); |
| 56 | void (*resume)(void); |
| 57 | }; |
| 58 | |
Catalin Marinas | 9a6655e | 2010-08-31 13:05:22 +0100 | [diff] [blame] | 59 | static inline void cache_wait_way(void __iomem *reg, unsigned long mask) |
Catalin Marinas | 382266a | 2007-02-05 14:48:19 +0100 | [diff] [blame] | 60 | { |
Catalin Marinas | 9a6655e | 2010-08-31 13:05:22 +0100 | [diff] [blame] | 61 | /* wait for cache operation by line or way to complete */ |
Catalin Marinas | 6775a55 | 2010-07-28 22:01:25 +0100 | [diff] [blame] | 62 | while (readl_relaxed(reg) & mask) |
Barry Song | 1caf309 | 2011-09-09 10:30:34 +0100 | [diff] [blame] | 63 | cpu_relax(); |
Catalin Marinas | 382266a | 2007-02-05 14:48:19 +0100 | [diff] [blame] | 64 | } |
| 65 | |
Catalin Marinas | 9a6655e | 2010-08-31 13:05:22 +0100 | [diff] [blame] | 66 | #ifdef CONFIG_CACHE_PL310 |
| 67 | static inline void cache_wait(void __iomem *reg, unsigned long mask) |
| 68 | { |
| 69 | /* cache operations by line are atomic on PL310 */ |
| 70 | } |
| 71 | #else |
| 72 | #define cache_wait cache_wait_way |
| 73 | #endif |
| 74 | |
Catalin Marinas | 382266a | 2007-02-05 14:48:19 +0100 | [diff] [blame] | 75 | static inline void cache_sync(void) |
| 76 | { |
Russell King | 3d10743 | 2009-11-19 11:41:09 +0000 | [diff] [blame] | 77 | void __iomem *base = l2x0_base; |
Srinidhi Kasagar | 885028e | 2011-02-17 07:03:51 +0100 | [diff] [blame] | 78 | |
Will Deacon | f154fe9 | 2012-04-20 17:21:08 +0100 | [diff] [blame] | 79 | writel_relaxed(0, base + sync_reg_offset); |
Russell King | 3d10743 | 2009-11-19 11:41:09 +0000 | [diff] [blame] | 80 | cache_wait(base + L2X0_CACHE_SYNC, 1); |
Catalin Marinas | 382266a | 2007-02-05 14:48:19 +0100 | [diff] [blame] | 81 | } |
| 82 | |
Santosh Shilimkar | 424d6b1 | 2010-02-04 19:35:06 +0100 | [diff] [blame] | 83 | static inline void l2x0_clean_line(unsigned long addr) |
| 84 | { |
| 85 | void __iomem *base = l2x0_base; |
| 86 | cache_wait(base + L2X0_CLEAN_LINE_PA, 1); |
Catalin Marinas | 6775a55 | 2010-07-28 22:01:25 +0100 | [diff] [blame] | 87 | writel_relaxed(addr, base + L2X0_CLEAN_LINE_PA); |
Santosh Shilimkar | 424d6b1 | 2010-02-04 19:35:06 +0100 | [diff] [blame] | 88 | } |
| 89 | |
| 90 | static inline void l2x0_inv_line(unsigned long addr) |
| 91 | { |
| 92 | void __iomem *base = l2x0_base; |
| 93 | cache_wait(base + L2X0_INV_LINE_PA, 1); |
Catalin Marinas | 6775a55 | 2010-07-28 22:01:25 +0100 | [diff] [blame] | 94 | writel_relaxed(addr, base + L2X0_INV_LINE_PA); |
Santosh Shilimkar | 424d6b1 | 2010-02-04 19:35:06 +0100 | [diff] [blame] | 95 | } |
| 96 | |
Santosh Shilimkar | 2839e06 | 2011-03-08 06:59:54 +0100 | [diff] [blame] | 97 | #if defined(CONFIG_PL310_ERRATA_588369) || defined(CONFIG_PL310_ERRATA_727915) |
Will Deacon | ab4d536 | 2012-04-20 17:22:11 +0100 | [diff] [blame] | 98 | static inline void debug_writel(unsigned long val) |
| 99 | { |
| 100 | if (outer_cache.set_debug) |
| 101 | outer_cache.set_debug(val); |
| 102 | } |
Santosh Shilimkar | 9e65582 | 2010-02-04 19:42:42 +0100 | [diff] [blame] | 103 | |
Will Deacon | ab4d536 | 2012-04-20 17:22:11 +0100 | [diff] [blame] | 104 | static void pl310_set_debug(unsigned long val) |
Santosh Shilimkar | 2839e06 | 2011-03-08 06:59:54 +0100 | [diff] [blame] | 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 | |
Will Deacon | ab4d536 | 2012-04-20 17:22:11 +0100 | [diff] [blame] | 114 | #define pl310_set_debug NULL |
Santosh Shilimkar | 2839e06 | 2011-03-08 06:59:54 +0100 | [diff] [blame] | 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 | { |
| 140 | unsigned long flags; |
| 141 | |
Thomas Gleixner | bd31b85 | 2009-07-03 08:44:46 -0500 | [diff] [blame] | 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 | bd31b85 | 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 | 74b6cdd | 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 | raw_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 | raw_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 | 74b6cdd | 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 | bd31b85 | 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 | bd31b85 | 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 | 74b6cdd | 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 | bd31b85 | 2009-07-03 08:44:46 -0500 | [diff] [blame] | 202 | raw_spin_lock_irqsave(&l2x0_lock, flags); |
Colin Cross | 74b6cdd | 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 | 74b6cdd | 2011-09-14 15:59:50 -0700 | [diff] [blame] | 207 | debug_writel(0x00); |
Thomas Gleixner | bd31b85 | 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 | bd31b85 | 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 | bd31b85 | 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 | bd31b85 | 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 | bd31b85 | 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 | bd31b85 | 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 | bd31b85 | 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 | bd31b85 | 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 | bd31b85 | 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 | bd31b85 | 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 | bd31b85 | 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 | bd31b85 | 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 | |
Thomas Gleixner | 2fd8658 | 2010-07-31 21:05:24 +0530 | [diff] [blame] | 326 | static void l2x0_disable(void) |
| 327 | { |
| 328 | unsigned long flags; |
| 329 | |
Thomas Gleixner | bd31b85 | 2009-07-03 08:44:46 -0500 | [diff] [blame] | 330 | raw_spin_lock_irqsave(&l2x0_lock, flags); |
Will Deacon | 38a8914 | 2011-07-01 14:36:19 +0100 | [diff] [blame] | 331 | __l2x0_flush_all(); |
| 332 | writel_relaxed(0, l2x0_base + L2X0_CTRL); |
| 333 | dsb(); |
Thomas Gleixner | bd31b85 | 2009-07-03 08:44:46 -0500 | [diff] [blame] | 334 | raw_spin_unlock_irqrestore(&l2x0_lock, flags); |
Thomas Gleixner | 2fd8658 | 2010-07-31 21:05:24 +0530 | [diff] [blame] | 335 | } |
| 336 | |
Russell King | 3e175ca | 2011-09-18 11:27:30 +0100 | [diff] [blame] | 337 | static void l2x0_unlock(u32 cache_id) |
Linus Walleij | bac7e6e | 2011-09-06 07:45:46 +0100 | [diff] [blame] | 338 | { |
| 339 | int lockregs; |
| 340 | int i; |
| 341 | |
| 342 | if (cache_id == L2X0_CACHE_ID_PART_L310) |
| 343 | lockregs = 8; |
| 344 | else |
| 345 | /* L210 and unknown types */ |
| 346 | lockregs = 1; |
| 347 | |
| 348 | for (i = 0; i < lockregs; i++) { |
| 349 | writel_relaxed(0x0, l2x0_base + L2X0_LOCKDOWN_WAY_D_BASE + |
| 350 | i * L2X0_LOCKDOWN_STRIDE); |
| 351 | writel_relaxed(0x0, l2x0_base + L2X0_LOCKDOWN_WAY_I_BASE + |
| 352 | i * L2X0_LOCKDOWN_STRIDE); |
| 353 | } |
| 354 | } |
| 355 | |
Russell King | 3e175ca | 2011-09-18 11:27:30 +0100 | [diff] [blame] | 356 | 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] | 357 | { |
Russell King | 3e175ca | 2011-09-18 11:27:30 +0100 | [diff] [blame] | 358 | u32 aux; |
Russell King | 3e175ca | 2011-09-18 11:27:30 +0100 | [diff] [blame] | 359 | u32 way_size = 0; |
Jason McMullan | 64039be | 2010-05-05 18:59:37 +0100 | [diff] [blame] | 360 | const char *type; |
Catalin Marinas | 382266a | 2007-02-05 14:48:19 +0100 | [diff] [blame] | 361 | |
| 362 | l2x0_base = base; |
| 363 | |
Colin Cross | 74b6cdd | 2011-09-14 15:59:50 -0700 | [diff] [blame] | 364 | l2x0_cache_id = readl_relaxed(l2x0_base + L2X0_CACHE_ID); |
Catalin Marinas | 6775a55 | 2010-07-28 22:01:25 +0100 | [diff] [blame] | 365 | aux = readl_relaxed(l2x0_base + L2X0_AUX_CTRL); |
Jason McMullan | 64039be | 2010-05-05 18:59:37 +0100 | [diff] [blame] | 366 | |
Sascha Hauer | 4082cfa | 2010-07-08 08:36:21 +0100 | [diff] [blame] | 367 | aux &= aux_mask; |
| 368 | aux |= aux_val; |
| 369 | |
Jason McMullan | 64039be | 2010-05-05 18:59:37 +0100 | [diff] [blame] | 370 | /* Determine the number of ways */ |
Colin Cross | 74b6cdd | 2011-09-14 15:59:50 -0700 | [diff] [blame] | 371 | switch (l2x0_cache_id & L2X0_CACHE_ID_PART_MASK) { |
Jason McMullan | 64039be | 2010-05-05 18:59:37 +0100 | [diff] [blame] | 372 | case L2X0_CACHE_ID_PART_L310: |
| 373 | if (aux & (1 << 16)) |
Colin Cross | 74b6cdd | 2011-09-14 15:59:50 -0700 | [diff] [blame] | 374 | l2x0_ways = 16; |
Jason McMullan | 64039be | 2010-05-05 18:59:37 +0100 | [diff] [blame] | 375 | else |
Colin Cross | 74b6cdd | 2011-09-14 15:59:50 -0700 | [diff] [blame] | 376 | l2x0_ways = 8; |
Jason McMullan | 64039be | 2010-05-05 18:59:37 +0100 | [diff] [blame] | 377 | type = "L310"; |
Will Deacon | f154fe9 | 2012-04-20 17:21:08 +0100 | [diff] [blame] | 378 | #ifdef CONFIG_PL310_ERRATA_753970 |
| 379 | /* Unmapped register. */ |
| 380 | sync_reg_offset = L2X0_DUMMY_REG; |
| 381 | #endif |
Will Deacon | ab4d536 | 2012-04-20 17:22:11 +0100 | [diff] [blame] | 382 | outer_cache.set_debug = pl310_set_debug; |
Girish Mahadevan | 74934a3 | 2012-10-11 10:44:47 -0600 | [diff] [blame] | 383 | outer_cache.resume = pl310_resume; |
Jason McMullan | 64039be | 2010-05-05 18:59:37 +0100 | [diff] [blame] | 384 | break; |
| 385 | case L2X0_CACHE_ID_PART_L210: |
Colin Cross | 74b6cdd | 2011-09-14 15:59:50 -0700 | [diff] [blame] | 386 | l2x0_ways = (aux >> 13) & 0xf; |
Jason McMullan | 64039be | 2010-05-05 18:59:37 +0100 | [diff] [blame] | 387 | type = "L210"; |
Girish Mahadevan | 74934a3 | 2012-10-11 10:44:47 -0600 | [diff] [blame] | 388 | outer_cache.resume = l2x0_resume; |
Jason McMullan | 64039be | 2010-05-05 18:59:37 +0100 | [diff] [blame] | 389 | break; |
| 390 | default: |
| 391 | /* Assume unknown chips have 8 ways */ |
Colin Cross | 74b6cdd | 2011-09-14 15:59:50 -0700 | [diff] [blame] | 392 | l2x0_ways = 8; |
Jason McMullan | 64039be | 2010-05-05 18:59:37 +0100 | [diff] [blame] | 393 | type = "L2x0 series"; |
Girish Mahadevan | 74934a3 | 2012-10-11 10:44:47 -0600 | [diff] [blame] | 394 | outer_cache.resume = l2x0_resume; |
Jason McMullan | 64039be | 2010-05-05 18:59:37 +0100 | [diff] [blame] | 395 | break; |
| 396 | } |
| 397 | |
Colin Cross | 74b6cdd | 2011-09-14 15:59:50 -0700 | [diff] [blame] | 398 | l2x0_way_mask = (1 << l2x0_ways) - 1; |
Jason McMullan | 64039be | 2010-05-05 18:59:37 +0100 | [diff] [blame] | 399 | |
Srinidhi Kasagar | 48371cd | 2009-12-02 06:18:03 +0100 | [diff] [blame] | 400 | /* |
Santosh Shilimkar | 5ba7037 | 2010-07-11 14:35:37 +0530 | [diff] [blame] | 401 | * L2 cache Size = Way size * Number of ways |
| 402 | */ |
| 403 | way_size = (aux & L2X0_AUX_CTRL_WAY_SIZE_MASK) >> 17; |
Colin Cross | 74b6cdd | 2011-09-14 15:59:50 -0700 | [diff] [blame] | 404 | way_size = SZ_1K << (way_size + 3); |
| 405 | l2x0_size = l2x0_ways * way_size; |
| 406 | l2x0_sets = way_size / CACHE_LINE_SIZE; |
Santosh Shilimkar | 5ba7037 | 2010-07-11 14:35:37 +0530 | [diff] [blame] | 407 | |
| 408 | /* |
Srinidhi Kasagar | 48371cd | 2009-12-02 06:18:03 +0100 | [diff] [blame] | 409 | * Check if l2x0 controller is already enabled. |
| 410 | * If you are booting from non-secure mode |
| 411 | * accessing the below registers will fault. |
| 412 | */ |
Catalin Marinas | 6775a55 | 2010-07-28 22:01:25 +0100 | [diff] [blame] | 413 | if (!(readl_relaxed(l2x0_base + L2X0_CTRL) & 1)) { |
Linus Walleij | bac7e6e | 2011-09-06 07:45:46 +0100 | [diff] [blame] | 414 | /* Make sure that I&D is not locked down when starting */ |
Colin Cross | 74b6cdd | 2011-09-14 15:59:50 -0700 | [diff] [blame] | 415 | l2x0_unlock(l2x0_cache_id); |
Catalin Marinas | 382266a | 2007-02-05 14:48:19 +0100 | [diff] [blame] | 416 | |
Srinidhi Kasagar | 48371cd | 2009-12-02 06:18:03 +0100 | [diff] [blame] | 417 | /* l2x0 controller is disabled */ |
Catalin Marinas | 6775a55 | 2010-07-28 22:01:25 +0100 | [diff] [blame] | 418 | writel_relaxed(aux, l2x0_base + L2X0_AUX_CTRL); |
Catalin Marinas | 382266a | 2007-02-05 14:48:19 +0100 | [diff] [blame] | 419 | |
Barry Song | 91c2ebb | 2011-09-30 14:43:12 +0100 | [diff] [blame] | 420 | l2x0_saved_regs.aux_ctrl = aux; |
| 421 | |
Srinidhi Kasagar | 48371cd | 2009-12-02 06:18:03 +0100 | [diff] [blame] | 422 | l2x0_inv_all(); |
| 423 | |
| 424 | /* enable L2X0 */ |
Catalin Marinas | 6775a55 | 2010-07-28 22:01:25 +0100 | [diff] [blame] | 425 | writel_relaxed(1, l2x0_base + L2X0_CTRL); |
Srinidhi Kasagar | 48371cd | 2009-12-02 06:18:03 +0100 | [diff] [blame] | 426 | } |
Catalin Marinas | 382266a | 2007-02-05 14:48:19 +0100 | [diff] [blame] | 427 | |
Stephen Boyd | 4251740 | 2013-01-14 16:41:42 -0800 | [diff] [blame] | 428 | outer_cache.inv_range = l2x0_inv_range; |
| 429 | outer_cache.clean_range = l2x0_clean_range; |
| 430 | outer_cache.flush_range = l2x0_flush_range; |
Catalin Marinas | 23107c5 | 2010-03-24 16:48:53 +0100 | [diff] [blame] | 431 | outer_cache.sync = l2x0_cache_sync; |
Thomas Gleixner | 2fd8658 | 2010-07-31 21:05:24 +0530 | [diff] [blame] | 432 | outer_cache.flush_all = l2x0_flush_all; |
| 433 | outer_cache.inv_all = l2x0_inv_all; |
| 434 | outer_cache.disable = l2x0_disable; |
Catalin Marinas | 382266a | 2007-02-05 14:48:19 +0100 | [diff] [blame] | 435 | |
Jason McMullan | 64039be | 2010-05-05 18:59:37 +0100 | [diff] [blame] | 436 | printk(KERN_INFO "%s cache controller enabled\n", type); |
Santosh Shilimkar | 5ba7037 | 2010-07-11 14:35:37 +0530 | [diff] [blame] | 437 | 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] | 438 | l2x0_ways, l2x0_cache_id, aux, l2x0_size); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 439 | |
Taniya Das | 38a8c6e | 2012-05-09 20:34:39 +0530 | [diff] [blame] | 440 | /* Save the L2X0 contents, as they are not modified else where */ |
| 441 | pl310_save(); |
Catalin Marinas | 382266a | 2007-02-05 14:48:19 +0100 | [diff] [blame] | 442 | } |
Rob Herring | 8c36926 | 2011-08-03 18:12:05 +0100 | [diff] [blame] | 443 | |
| 444 | #ifdef CONFIG_OF |
| 445 | static void __init l2x0_of_setup(const struct device_node *np, |
Russell King | 3e175ca | 2011-09-18 11:27:30 +0100 | [diff] [blame] | 446 | u32 *aux_val, u32 *aux_mask) |
Rob Herring | 8c36926 | 2011-08-03 18:12:05 +0100 | [diff] [blame] | 447 | { |
| 448 | u32 data[2] = { 0, 0 }; |
| 449 | u32 tag = 0; |
| 450 | u32 dirty = 0; |
| 451 | u32 val = 0, mask = 0; |
| 452 | |
| 453 | of_property_read_u32(np, "arm,tag-latency", &tag); |
| 454 | if (tag) { |
| 455 | mask |= L2X0_AUX_CTRL_TAG_LATENCY_MASK; |
| 456 | val |= (tag - 1) << L2X0_AUX_CTRL_TAG_LATENCY_SHIFT; |
| 457 | } |
| 458 | |
| 459 | of_property_read_u32_array(np, "arm,data-latency", |
| 460 | data, ARRAY_SIZE(data)); |
| 461 | if (data[0] && data[1]) { |
| 462 | mask |= L2X0_AUX_CTRL_DATA_RD_LATENCY_MASK | |
| 463 | L2X0_AUX_CTRL_DATA_WR_LATENCY_MASK; |
| 464 | val |= ((data[0] - 1) << L2X0_AUX_CTRL_DATA_RD_LATENCY_SHIFT) | |
| 465 | ((data[1] - 1) << L2X0_AUX_CTRL_DATA_WR_LATENCY_SHIFT); |
| 466 | } |
| 467 | |
| 468 | of_property_read_u32(np, "arm,dirty-latency", &dirty); |
| 469 | if (dirty) { |
| 470 | mask |= L2X0_AUX_CTRL_DIRTY_LATENCY_MASK; |
| 471 | val |= (dirty - 1) << L2X0_AUX_CTRL_DIRTY_LATENCY_SHIFT; |
| 472 | } |
| 473 | |
| 474 | *aux_val &= ~mask; |
| 475 | *aux_val |= val; |
| 476 | *aux_mask &= ~mask; |
| 477 | } |
| 478 | |
| 479 | static void __init pl310_of_setup(const struct device_node *np, |
Russell King | 3e175ca | 2011-09-18 11:27:30 +0100 | [diff] [blame] | 480 | u32 *aux_val, u32 *aux_mask) |
Rob Herring | 8c36926 | 2011-08-03 18:12:05 +0100 | [diff] [blame] | 481 | { |
| 482 | u32 data[3] = { 0, 0, 0 }; |
| 483 | u32 tag[3] = { 0, 0, 0 }; |
| 484 | u32 filter[2] = { 0, 0 }; |
| 485 | |
| 486 | of_property_read_u32_array(np, "arm,tag-latency", tag, ARRAY_SIZE(tag)); |
| 487 | if (tag[0] && tag[1] && tag[2]) |
| 488 | writel_relaxed( |
| 489 | ((tag[0] - 1) << L2X0_LATENCY_CTRL_RD_SHIFT) | |
| 490 | ((tag[1] - 1) << L2X0_LATENCY_CTRL_WR_SHIFT) | |
| 491 | ((tag[2] - 1) << L2X0_LATENCY_CTRL_SETUP_SHIFT), |
| 492 | l2x0_base + L2X0_TAG_LATENCY_CTRL); |
| 493 | |
| 494 | of_property_read_u32_array(np, "arm,data-latency", |
| 495 | data, ARRAY_SIZE(data)); |
| 496 | if (data[0] && data[1] && data[2]) |
| 497 | writel_relaxed( |
| 498 | ((data[0] - 1) << L2X0_LATENCY_CTRL_RD_SHIFT) | |
| 499 | ((data[1] - 1) << L2X0_LATENCY_CTRL_WR_SHIFT) | |
| 500 | ((data[2] - 1) << L2X0_LATENCY_CTRL_SETUP_SHIFT), |
| 501 | l2x0_base + L2X0_DATA_LATENCY_CTRL); |
| 502 | |
| 503 | of_property_read_u32_array(np, "arm,filter-ranges", |
| 504 | filter, ARRAY_SIZE(filter)); |
Barry Song | 74d41f3 | 2011-09-14 03:20:01 +0100 | [diff] [blame] | 505 | if (filter[1]) { |
Rob Herring | 8c36926 | 2011-08-03 18:12:05 +0100 | [diff] [blame] | 506 | writel_relaxed(ALIGN(filter[0] + filter[1], SZ_1M), |
| 507 | l2x0_base + L2X0_ADDR_FILTER_END); |
| 508 | writel_relaxed((filter[0] & ~(SZ_1M - 1)) | L2X0_ADDR_FILTER_EN, |
| 509 | l2x0_base + L2X0_ADDR_FILTER_START); |
| 510 | } |
| 511 | } |
Taniya Das | 38a8c6e | 2012-05-09 20:34:39 +0530 | [diff] [blame] | 512 | #endif |
Rob Herring | 8c36926 | 2011-08-03 18:12:05 +0100 | [diff] [blame] | 513 | |
Stephen Boyd | 22ab934 | 2012-04-25 11:42:14 -0700 | [diff] [blame] | 514 | static void pl310_save(void) |
Barry Song | 91c2ebb | 2011-09-30 14:43:12 +0100 | [diff] [blame] | 515 | { |
| 516 | u32 l2x0_revision = readl_relaxed(l2x0_base + L2X0_CACHE_ID) & |
| 517 | L2X0_CACHE_ID_RTL_MASK; |
| 518 | |
| 519 | l2x0_saved_regs.tag_latency = readl_relaxed(l2x0_base + |
| 520 | L2X0_TAG_LATENCY_CTRL); |
| 521 | l2x0_saved_regs.data_latency = readl_relaxed(l2x0_base + |
| 522 | L2X0_DATA_LATENCY_CTRL); |
| 523 | l2x0_saved_regs.filter_end = readl_relaxed(l2x0_base + |
| 524 | L2X0_ADDR_FILTER_END); |
| 525 | l2x0_saved_regs.filter_start = readl_relaxed(l2x0_base + |
| 526 | L2X0_ADDR_FILTER_START); |
| 527 | |
| 528 | if (l2x0_revision >= L2X0_CACHE_ID_RTL_R2P0) { |
| 529 | /* |
| 530 | * From r2p0, there is Prefetch offset/control register |
| 531 | */ |
| 532 | l2x0_saved_regs.prefetch_ctrl = readl_relaxed(l2x0_base + |
| 533 | L2X0_PREFETCH_CTRL); |
| 534 | /* |
| 535 | * From r3p0, there is Power control register |
| 536 | */ |
| 537 | if (l2x0_revision >= L2X0_CACHE_ID_RTL_R3P0) |
| 538 | l2x0_saved_regs.pwr_ctrl = readl_relaxed(l2x0_base + |
| 539 | L2X0_POWER_CTRL); |
| 540 | } |
| 541 | } |
| 542 | |
| 543 | static void l2x0_resume(void) |
| 544 | { |
| 545 | if (!(readl_relaxed(l2x0_base + L2X0_CTRL) & 1)) { |
| 546 | /* restore aux ctrl and enable l2 */ |
| 547 | l2x0_unlock(readl_relaxed(l2x0_base + L2X0_CACHE_ID)); |
| 548 | |
| 549 | writel_relaxed(l2x0_saved_regs.aux_ctrl, l2x0_base + |
| 550 | L2X0_AUX_CTRL); |
| 551 | |
| 552 | l2x0_inv_all(); |
| 553 | |
| 554 | writel_relaxed(1, l2x0_base + L2X0_CTRL); |
| 555 | } |
| 556 | } |
| 557 | |
| 558 | static void pl310_resume(void) |
| 559 | { |
| 560 | u32 l2x0_revision; |
| 561 | |
| 562 | if (!(readl_relaxed(l2x0_base + L2X0_CTRL) & 1)) { |
| 563 | /* restore pl310 setup */ |
| 564 | writel_relaxed(l2x0_saved_regs.tag_latency, |
| 565 | l2x0_base + L2X0_TAG_LATENCY_CTRL); |
| 566 | writel_relaxed(l2x0_saved_regs.data_latency, |
| 567 | l2x0_base + L2X0_DATA_LATENCY_CTRL); |
| 568 | writel_relaxed(l2x0_saved_regs.filter_end, |
| 569 | l2x0_base + L2X0_ADDR_FILTER_END); |
| 570 | writel_relaxed(l2x0_saved_regs.filter_start, |
| 571 | l2x0_base + L2X0_ADDR_FILTER_START); |
| 572 | |
| 573 | l2x0_revision = readl_relaxed(l2x0_base + L2X0_CACHE_ID) & |
| 574 | L2X0_CACHE_ID_RTL_MASK; |
| 575 | |
| 576 | if (l2x0_revision >= L2X0_CACHE_ID_RTL_R2P0) { |
| 577 | writel_relaxed(l2x0_saved_regs.prefetch_ctrl, |
| 578 | l2x0_base + L2X0_PREFETCH_CTRL); |
| 579 | if (l2x0_revision >= L2X0_CACHE_ID_RTL_R3P0) |
| 580 | writel_relaxed(l2x0_saved_regs.pwr_ctrl, |
| 581 | l2x0_base + L2X0_POWER_CTRL); |
| 582 | } |
| 583 | } |
| 584 | |
| 585 | l2x0_resume(); |
| 586 | } |
| 587 | |
Taniya Das | 38a8c6e | 2012-05-09 20:34:39 +0530 | [diff] [blame] | 588 | #ifdef CONFIG_OF |
Barry Song | 91c2ebb | 2011-09-30 14:43:12 +0100 | [diff] [blame] | 589 | static const struct l2x0_of_data pl310_data = { |
| 590 | pl310_of_setup, |
| 591 | pl310_save, |
| 592 | pl310_resume, |
| 593 | }; |
| 594 | |
| 595 | static const struct l2x0_of_data l2x0_data = { |
| 596 | l2x0_of_setup, |
| 597 | NULL, |
| 598 | l2x0_resume, |
| 599 | }; |
| 600 | |
Rob Herring | 8c36926 | 2011-08-03 18:12:05 +0100 | [diff] [blame] | 601 | static const struct of_device_id l2x0_ids[] __initconst = { |
Barry Song | 91c2ebb | 2011-09-30 14:43:12 +0100 | [diff] [blame] | 602 | { .compatible = "arm,pl310-cache", .data = (void *)&pl310_data }, |
| 603 | { .compatible = "arm,l220-cache", .data = (void *)&l2x0_data }, |
| 604 | { .compatible = "arm,l210-cache", .data = (void *)&l2x0_data }, |
Rob Herring | 8c36926 | 2011-08-03 18:12:05 +0100 | [diff] [blame] | 605 | {} |
| 606 | }; |
| 607 | |
Russell King | 3e175ca | 2011-09-18 11:27:30 +0100 | [diff] [blame] | 608 | int __init l2x0_of_init(u32 aux_val, u32 aux_mask) |
Rob Herring | 8c36926 | 2011-08-03 18:12:05 +0100 | [diff] [blame] | 609 | { |
| 610 | struct device_node *np; |
Barry Song | 91c2ebb | 2011-09-30 14:43:12 +0100 | [diff] [blame] | 611 | struct l2x0_of_data *data; |
| 612 | struct resource res; |
Rob Herring | 8c36926 | 2011-08-03 18:12:05 +0100 | [diff] [blame] | 613 | |
| 614 | np = of_find_matching_node(NULL, l2x0_ids); |
| 615 | if (!np) |
| 616 | return -ENODEV; |
Barry Song | 91c2ebb | 2011-09-30 14:43:12 +0100 | [diff] [blame] | 617 | |
| 618 | if (of_address_to_resource(np, 0, &res)) |
| 619 | return -ENODEV; |
| 620 | |
| 621 | l2x0_base = ioremap(res.start, resource_size(&res)); |
Rob Herring | 8c36926 | 2011-08-03 18:12:05 +0100 | [diff] [blame] | 622 | if (!l2x0_base) |
| 623 | return -ENOMEM; |
| 624 | |
Barry Song | 91c2ebb | 2011-09-30 14:43:12 +0100 | [diff] [blame] | 625 | l2x0_saved_regs.phy_base = res.start; |
| 626 | |
| 627 | data = of_match_node(l2x0_ids, np)->data; |
| 628 | |
Rob Herring | 8c36926 | 2011-08-03 18:12:05 +0100 | [diff] [blame] | 629 | /* L2 configuration can only be changed if the cache is disabled */ |
| 630 | if (!(readl_relaxed(l2x0_base + L2X0_CTRL) & 1)) { |
Barry Song | 91c2ebb | 2011-09-30 14:43:12 +0100 | [diff] [blame] | 631 | if (data->setup) |
| 632 | data->setup(np, &aux_val, &aux_mask); |
Rob Herring | 8c36926 | 2011-08-03 18:12:05 +0100 | [diff] [blame] | 633 | } |
Barry Song | 91c2ebb | 2011-09-30 14:43:12 +0100 | [diff] [blame] | 634 | |
| 635 | if (data->save) |
| 636 | data->save(); |
| 637 | |
Rob Herring | 8c36926 | 2011-08-03 18:12:05 +0100 | [diff] [blame] | 638 | l2x0_init(l2x0_base, aux_val, aux_mask); |
Barry Song | 91c2ebb | 2011-09-30 14:43:12 +0100 | [diff] [blame] | 639 | |
| 640 | outer_cache.resume = data->resume; |
Rob Herring | 8c36926 | 2011-08-03 18:12:05 +0100 | [diff] [blame] | 641 | return 0; |
| 642 | } |
| 643 | #endif |
Taniya Das | 38a8c6e | 2012-05-09 20:34:39 +0530 | [diff] [blame] | 644 | |
| 645 | void l2cc_suspend(void) |
| 646 | { |
| 647 | l2x0_disable(); |
| 648 | dmb(); |
| 649 | } |
| 650 | |
| 651 | void l2cc_resume(void) |
| 652 | { |
| 653 | pl310_resume(); |
| 654 | dmb(); |
| 655 | } |