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