2 * arch/arm/mm/cache-xsc3l2.c - XScale3 L2 cache controller support
4 * Copyright (C) 2007 ARM Limited
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.
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.
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
19 #include <linux/init.h>
20 #include <linux/spinlock.h>
22 #include <asm/system.h>
23 #include <asm/cacheflush.h>
26 #define CR_L2 (1 << 26)
28 #define CACHE_LINE_SIZE 32
29 #define CACHE_LINE_SHIFT 5
30 #define CACHE_WAY_PER_SET 8
32 #define CACHE_WAY_SIZE(l2ctype) (8192 << (((l2ctype) >> 8) & 0xf))
33 #define CACHE_SET_SIZE(l2ctype) (CACHE_WAY_SIZE(l2ctype) >> CACHE_LINE_SHIFT)
35 static inline int xsc3_l2_present(void)
37 unsigned long l2ctype;
39 __asm__("mrc p15, 1, %0, c0, c0, 1" : "=r" (l2ctype));
41 return !!(l2ctype & 0xf8);
44 static inline void xsc3_l2_clean_mva(unsigned long addr)
46 __asm__("mcr p15, 1, %0, c7, c11, 1" : : "r" (addr));
49 static inline void xsc3_l2_clean_pa(unsigned long addr)
51 xsc3_l2_clean_mva(__phys_to_virt(addr));
54 static inline void xsc3_l2_inv_mva(unsigned long addr)
56 __asm__("mcr p15, 1, %0, c7, c7, 1" : : "r" (addr));
59 static inline void xsc3_l2_inv_pa(unsigned long addr)
61 xsc3_l2_inv_mva(__phys_to_virt(addr));
64 static inline void xsc3_l2_inv_all(void)
66 unsigned long l2ctype, set_way;
69 __asm__("mrc p15, 1, %0, c0, c0, 1" : "=r" (l2ctype));
71 for (set = 0; set < CACHE_SET_SIZE(l2ctype); set++) {
72 for (way = 0; way < CACHE_WAY_PER_SET; way++) {
73 set_way = (way << 29) | (set << 5);
74 __asm__("mcr p15, 1, %0, c7, c11, 2" : : "r"(set_way));
81 static void xsc3_l2_inv_range(unsigned long start, unsigned long end)
83 if (start == 0 && end == -1ul) {
89 * Clean and invalidate partial first cache line.
91 if (start & (CACHE_LINE_SIZE - 1)) {
92 xsc3_l2_clean_pa(start & ~(CACHE_LINE_SIZE - 1));
93 xsc3_l2_inv_pa(start & ~(CACHE_LINE_SIZE - 1));
94 start = (start | (CACHE_LINE_SIZE - 1)) + 1;
98 * Clean and invalidate partial last cache line.
100 if (end & (CACHE_LINE_SIZE - 1)) {
101 xsc3_l2_clean_pa(end & ~(CACHE_LINE_SIZE - 1));
102 xsc3_l2_inv_pa(end & ~(CACHE_LINE_SIZE - 1));
103 end &= ~(CACHE_LINE_SIZE - 1);
107 * Invalidate all full cache lines between 'start' and 'end'.
109 while (start != end) {
110 xsc3_l2_inv_pa(start);
111 start += CACHE_LINE_SIZE;
117 static void xsc3_l2_clean_range(unsigned long start, unsigned long end)
119 start &= ~(CACHE_LINE_SIZE - 1);
120 while (start < end) {
121 xsc3_l2_clean_pa(start);
122 start += CACHE_LINE_SIZE;
129 * optimize L2 flush all operation by set/way format
131 static inline void xsc3_l2_flush_all(void)
133 unsigned long l2ctype, set_way;
136 __asm__("mrc p15, 1, %0, c0, c0, 1" : "=r" (l2ctype));
138 for (set = 0; set < CACHE_SET_SIZE(l2ctype); set++) {
139 for (way = 0; way < CACHE_WAY_PER_SET; way++) {
140 set_way = (way << 29) | (set << 5);
141 __asm__("mcr p15, 1, %0, c7, c15, 2" : : "r"(set_way));
148 static void xsc3_l2_flush_range(unsigned long start, unsigned long end)
150 if (start == 0 && end == -1ul) {
155 start &= ~(CACHE_LINE_SIZE - 1);
156 while (start < end) {
157 xsc3_l2_clean_pa(start);
158 xsc3_l2_inv_pa(start);
159 start += CACHE_LINE_SIZE;
165 static int __init xsc3_l2_init(void)
167 if (!cpu_is_xsc3() || !xsc3_l2_present())
170 if (!(get_cr() & CR_L2)) {
171 pr_info("XScale3 L2 cache enabled.\n");
172 adjust_cr(CR_L2, CR_L2);
176 outer_cache.inv_range = xsc3_l2_inv_range;
177 outer_cache.clean_range = xsc3_l2_clean_range;
178 outer_cache.flush_range = xsc3_l2_flush_range;
182 core_initcall(xsc3_l2_init);