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 | */ |
| 19 | #include <linux/init.h> |
Catalin Marinas | 0762097 | 2007-07-20 11:42:40 +0100 | [diff] [blame] | 20 | #include <linux/spinlock.h> |
Russell King | fced80c | 2008-09-06 12:10:45 +0100 | [diff] [blame] | 21 | #include <linux/io.h> |
Catalin Marinas | 382266a | 2007-02-05 14:48:19 +0100 | [diff] [blame] | 22 | |
| 23 | #include <asm/cacheflush.h> |
Catalin Marinas | 382266a | 2007-02-05 14:48:19 +0100 | [diff] [blame] | 24 | #include <asm/hardware/cache-l2x0.h> |
| 25 | |
| 26 | #define CACHE_LINE_SIZE 32 |
| 27 | |
| 28 | static void __iomem *l2x0_base; |
Catalin Marinas | 0762097 | 2007-07-20 11:42:40 +0100 | [diff] [blame] | 29 | static DEFINE_SPINLOCK(l2x0_lock); |
Catalin Marinas | 382266a | 2007-02-05 14:48:19 +0100 | [diff] [blame] | 30 | |
Russell King | 3d10743 | 2009-11-19 11:41:09 +0000 | [diff] [blame^] | 31 | static inline void cache_wait(void __iomem *reg, unsigned long mask) |
Catalin Marinas | 382266a | 2007-02-05 14:48:19 +0100 | [diff] [blame] | 32 | { |
Catalin Marinas | 382266a | 2007-02-05 14:48:19 +0100 | [diff] [blame] | 33 | /* wait for the operation to complete */ |
Russell King | 3d10743 | 2009-11-19 11:41:09 +0000 | [diff] [blame^] | 34 | while (readl(reg) & mask) |
Catalin Marinas | 382266a | 2007-02-05 14:48:19 +0100 | [diff] [blame] | 35 | ; |
Catalin Marinas | 382266a | 2007-02-05 14:48:19 +0100 | [diff] [blame] | 36 | } |
| 37 | |
| 38 | static inline void cache_sync(void) |
| 39 | { |
Russell King | 3d10743 | 2009-11-19 11:41:09 +0000 | [diff] [blame^] | 40 | void __iomem *base = l2x0_base; |
| 41 | writel(0, base + L2X0_CACHE_SYNC); |
| 42 | cache_wait(base + L2X0_CACHE_SYNC, 1); |
Catalin Marinas | 382266a | 2007-02-05 14:48:19 +0100 | [diff] [blame] | 43 | } |
| 44 | |
| 45 | static inline void l2x0_inv_all(void) |
| 46 | { |
Russell King | 0eb948d | 2009-11-19 11:12:15 +0000 | [diff] [blame] | 47 | unsigned long flags; |
| 48 | |
Catalin Marinas | 382266a | 2007-02-05 14:48:19 +0100 | [diff] [blame] | 49 | /* invalidate all ways */ |
Russell King | 0eb948d | 2009-11-19 11:12:15 +0000 | [diff] [blame] | 50 | spin_lock_irqsave(&l2x0_lock, flags); |
Russell King | 3d10743 | 2009-11-19 11:41:09 +0000 | [diff] [blame^] | 51 | writel(0xff, l2x0_base + L2X0_INV_WAY); |
| 52 | cache_wait(l2x0_base + L2X0_INV_WAY, 0xff); |
Catalin Marinas | 382266a | 2007-02-05 14:48:19 +0100 | [diff] [blame] | 53 | cache_sync(); |
Russell King | 0eb948d | 2009-11-19 11:12:15 +0000 | [diff] [blame] | 54 | spin_unlock_irqrestore(&l2x0_lock, flags); |
Catalin Marinas | 382266a | 2007-02-05 14:48:19 +0100 | [diff] [blame] | 55 | } |
| 56 | |
| 57 | static void l2x0_inv_range(unsigned long start, unsigned long end) |
| 58 | { |
Russell King | 3d10743 | 2009-11-19 11:41:09 +0000 | [diff] [blame^] | 59 | void __iomem *base = l2x0_base; |
Russell King | 0eb948d | 2009-11-19 11:12:15 +0000 | [diff] [blame] | 60 | unsigned long flags; |
Catalin Marinas | 382266a | 2007-02-05 14:48:19 +0100 | [diff] [blame] | 61 | |
Russell King | 0eb948d | 2009-11-19 11:12:15 +0000 | [diff] [blame] | 62 | spin_lock_irqsave(&l2x0_lock, flags); |
Rui Sousa | 4f6627a | 2007-09-15 00:56:19 +0100 | [diff] [blame] | 63 | if (start & (CACHE_LINE_SIZE - 1)) { |
| 64 | start &= ~(CACHE_LINE_SIZE - 1); |
Russell King | 3d10743 | 2009-11-19 11:41:09 +0000 | [diff] [blame^] | 65 | cache_wait(base + L2X0_CLEAN_INV_LINE_PA, 1); |
| 66 | writel(start, base + L2X0_CLEAN_INV_LINE_PA); |
Rui Sousa | 4f6627a | 2007-09-15 00:56:19 +0100 | [diff] [blame] | 67 | start += CACHE_LINE_SIZE; |
| 68 | } |
| 69 | |
| 70 | if (end & (CACHE_LINE_SIZE - 1)) { |
| 71 | end &= ~(CACHE_LINE_SIZE - 1); |
Russell King | 3d10743 | 2009-11-19 11:41:09 +0000 | [diff] [blame^] | 72 | cache_wait(base + L2X0_CLEAN_INV_LINE_PA, 1); |
| 73 | writel(end, base + L2X0_CLEAN_INV_LINE_PA); |
Rui Sousa | 4f6627a | 2007-09-15 00:56:19 +0100 | [diff] [blame] | 74 | } |
| 75 | |
Russell King | 0eb948d | 2009-11-19 11:12:15 +0000 | [diff] [blame] | 76 | while (start < end) { |
| 77 | unsigned long blk_end = start + min(end - start, 4096UL); |
| 78 | |
| 79 | while (start < blk_end) { |
Russell King | 3d10743 | 2009-11-19 11:41:09 +0000 | [diff] [blame^] | 80 | cache_wait(base + L2X0_INV_LINE_PA, 1); |
| 81 | writel(start, base + L2X0_INV_LINE_PA); |
Russell King | 0eb948d | 2009-11-19 11:12:15 +0000 | [diff] [blame] | 82 | start += CACHE_LINE_SIZE; |
| 83 | } |
| 84 | |
| 85 | if (blk_end < end) { |
| 86 | spin_unlock_irqrestore(&l2x0_lock, flags); |
| 87 | spin_lock_irqsave(&l2x0_lock, flags); |
| 88 | } |
| 89 | } |
Russell King | 3d10743 | 2009-11-19 11:41:09 +0000 | [diff] [blame^] | 90 | cache_wait(base + L2X0_INV_LINE_PA, 1); |
Catalin Marinas | 382266a | 2007-02-05 14:48:19 +0100 | [diff] [blame] | 91 | cache_sync(); |
Russell King | 0eb948d | 2009-11-19 11:12:15 +0000 | [diff] [blame] | 92 | spin_unlock_irqrestore(&l2x0_lock, flags); |
Catalin Marinas | 382266a | 2007-02-05 14:48:19 +0100 | [diff] [blame] | 93 | } |
| 94 | |
| 95 | static void l2x0_clean_range(unsigned long start, unsigned long end) |
| 96 | { |
Russell King | 3d10743 | 2009-11-19 11:41:09 +0000 | [diff] [blame^] | 97 | void __iomem *base = l2x0_base; |
Russell King | 0eb948d | 2009-11-19 11:12:15 +0000 | [diff] [blame] | 98 | unsigned long flags; |
Catalin Marinas | 382266a | 2007-02-05 14:48:19 +0100 | [diff] [blame] | 99 | |
Russell King | 0eb948d | 2009-11-19 11:12:15 +0000 | [diff] [blame] | 100 | spin_lock_irqsave(&l2x0_lock, flags); |
Catalin Marinas | 382266a | 2007-02-05 14:48:19 +0100 | [diff] [blame] | 101 | start &= ~(CACHE_LINE_SIZE - 1); |
Russell King | 0eb948d | 2009-11-19 11:12:15 +0000 | [diff] [blame] | 102 | while (start < end) { |
| 103 | unsigned long blk_end = start + min(end - start, 4096UL); |
| 104 | |
| 105 | while (start < blk_end) { |
Russell King | 3d10743 | 2009-11-19 11:41:09 +0000 | [diff] [blame^] | 106 | cache_wait(base + L2X0_CLEAN_LINE_PA, 1); |
| 107 | writel(start, base + L2X0_CLEAN_LINE_PA); |
Russell King | 0eb948d | 2009-11-19 11:12:15 +0000 | [diff] [blame] | 108 | start += CACHE_LINE_SIZE; |
| 109 | } |
| 110 | |
| 111 | if (blk_end < end) { |
| 112 | spin_unlock_irqrestore(&l2x0_lock, flags); |
| 113 | spin_lock_irqsave(&l2x0_lock, flags); |
| 114 | } |
| 115 | } |
Russell King | 3d10743 | 2009-11-19 11:41:09 +0000 | [diff] [blame^] | 116 | cache_wait(base + L2X0_CLEAN_LINE_PA, 1); |
Catalin Marinas | 382266a | 2007-02-05 14:48:19 +0100 | [diff] [blame] | 117 | cache_sync(); |
Russell King | 0eb948d | 2009-11-19 11:12:15 +0000 | [diff] [blame] | 118 | spin_unlock_irqrestore(&l2x0_lock, flags); |
Catalin Marinas | 382266a | 2007-02-05 14:48:19 +0100 | [diff] [blame] | 119 | } |
| 120 | |
| 121 | static void l2x0_flush_range(unsigned long start, unsigned long end) |
| 122 | { |
Russell King | 3d10743 | 2009-11-19 11:41:09 +0000 | [diff] [blame^] | 123 | void __iomem *base = l2x0_base; |
Russell King | 0eb948d | 2009-11-19 11:12:15 +0000 | [diff] [blame] | 124 | unsigned long flags; |
Catalin Marinas | 382266a | 2007-02-05 14:48:19 +0100 | [diff] [blame] | 125 | |
Russell King | 0eb948d | 2009-11-19 11:12:15 +0000 | [diff] [blame] | 126 | spin_lock_irqsave(&l2x0_lock, flags); |
Catalin Marinas | 382266a | 2007-02-05 14:48:19 +0100 | [diff] [blame] | 127 | start &= ~(CACHE_LINE_SIZE - 1); |
Russell King | 0eb948d | 2009-11-19 11:12:15 +0000 | [diff] [blame] | 128 | while (start < end) { |
| 129 | unsigned long blk_end = start + min(end - start, 4096UL); |
| 130 | |
| 131 | while (start < blk_end) { |
Russell King | 3d10743 | 2009-11-19 11:41:09 +0000 | [diff] [blame^] | 132 | cache_wait(base + L2X0_CLEAN_INV_LINE_PA, 1); |
| 133 | writel(start, base + L2X0_CLEAN_INV_LINE_PA); |
Russell King | 0eb948d | 2009-11-19 11:12:15 +0000 | [diff] [blame] | 134 | start += CACHE_LINE_SIZE; |
| 135 | } |
| 136 | |
| 137 | if (blk_end < end) { |
| 138 | spin_unlock_irqrestore(&l2x0_lock, flags); |
| 139 | spin_lock_irqsave(&l2x0_lock, flags); |
| 140 | } |
| 141 | } |
Russell King | 3d10743 | 2009-11-19 11:41:09 +0000 | [diff] [blame^] | 142 | cache_wait(base + L2X0_CLEAN_INV_LINE_PA, 1); |
Catalin Marinas | 382266a | 2007-02-05 14:48:19 +0100 | [diff] [blame] | 143 | cache_sync(); |
Russell King | 0eb948d | 2009-11-19 11:12:15 +0000 | [diff] [blame] | 144 | spin_unlock_irqrestore(&l2x0_lock, flags); |
Catalin Marinas | 382266a | 2007-02-05 14:48:19 +0100 | [diff] [blame] | 145 | } |
| 146 | |
| 147 | void __init l2x0_init(void __iomem *base, __u32 aux_val, __u32 aux_mask) |
| 148 | { |
| 149 | __u32 aux; |
| 150 | |
| 151 | l2x0_base = base; |
| 152 | |
| 153 | /* disable L2X0 */ |
| 154 | writel(0, l2x0_base + L2X0_CTRL); |
| 155 | |
| 156 | aux = readl(l2x0_base + L2X0_AUX_CTRL); |
| 157 | aux &= aux_mask; |
| 158 | aux |= aux_val; |
| 159 | writel(aux, l2x0_base + L2X0_AUX_CTRL); |
| 160 | |
| 161 | l2x0_inv_all(); |
| 162 | |
| 163 | /* enable L2X0 */ |
| 164 | writel(1, l2x0_base + L2X0_CTRL); |
| 165 | |
| 166 | outer_cache.inv_range = l2x0_inv_range; |
| 167 | outer_cache.clean_range = l2x0_clean_range; |
| 168 | outer_cache.flush_range = l2x0_flush_range; |
| 169 | |
| 170 | printk(KERN_INFO "L2X0 cache controller enabled\n"); |
| 171 | } |