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