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>
23 #include <asm/system.h>
24 #include <asm/cputype.h>
25 #include <asm/cacheflush.h>
27 #define CR_L2 (1 << 26)
29 #define CACHE_LINE_SIZE 32
30 #define CACHE_LINE_SHIFT 5
31 #define CACHE_WAY_PER_SET 8
33 #define CACHE_WAY_SIZE(l2ctype) (8192 << (((l2ctype) >> 8) & 0xf))
34 #define CACHE_SET_SIZE(l2ctype) (CACHE_WAY_SIZE(l2ctype) >> CACHE_LINE_SHIFT)
36 static inline int xsc3_l2_present(void)
38 unsigned long l2ctype
;
40 __asm__("mrc p15, 1, %0, c0, c0, 1" : "=r" (l2ctype
));
42 return !!(l2ctype
& 0xf8);
45 static inline void xsc3_l2_clean_mva(unsigned long addr
)
47 __asm__("mcr p15, 1, %0, c7, c11, 1" : : "r" (addr
));
50 static inline void xsc3_l2_clean_pa(unsigned long addr
)
52 xsc3_l2_clean_mva(__phys_to_virt(addr
));
55 static inline void xsc3_l2_inv_mva(unsigned long addr
)
57 __asm__("mcr p15, 1, %0, c7, c7, 1" : : "r" (addr
));
60 static inline void xsc3_l2_inv_pa(unsigned long addr
)
62 xsc3_l2_inv_mva(__phys_to_virt(addr
));
65 static inline void xsc3_l2_inv_all(void)
67 unsigned long l2ctype
, set_way
;
70 __asm__("mrc p15, 1, %0, c0, c0, 1" : "=r" (l2ctype
));
72 for (set
= 0; set
< CACHE_SET_SIZE(l2ctype
); set
++) {
73 for (way
= 0; way
< CACHE_WAY_PER_SET
; way
++) {
74 set_way
= (way
<< 29) | (set
<< 5);
75 __asm__("mcr p15, 1, %0, c7, c11, 2" : : "r"(set_way
));
82 static void xsc3_l2_inv_range(unsigned long start
, unsigned long end
)
84 if (start
== 0 && end
== -1ul) {
90 * Clean and invalidate partial first cache line.
92 if (start
& (CACHE_LINE_SIZE
- 1)) {
93 xsc3_l2_clean_pa(start
& ~(CACHE_LINE_SIZE
- 1));
94 xsc3_l2_inv_pa(start
& ~(CACHE_LINE_SIZE
- 1));
95 start
= (start
| (CACHE_LINE_SIZE
- 1)) + 1;
99 * Clean and invalidate partial last cache line.
101 if (start
< end
&& (end
& (CACHE_LINE_SIZE
- 1))) {
102 xsc3_l2_clean_pa(end
& ~(CACHE_LINE_SIZE
- 1));
103 xsc3_l2_inv_pa(end
& ~(CACHE_LINE_SIZE
- 1));
104 end
&= ~(CACHE_LINE_SIZE
- 1);
108 * Invalidate all full cache lines between 'start' and 'end'.
110 while (start
< end
) {
111 xsc3_l2_inv_pa(start
);
112 start
+= CACHE_LINE_SIZE
;
118 static void xsc3_l2_clean_range(unsigned long start
, unsigned long end
)
120 start
&= ~(CACHE_LINE_SIZE
- 1);
121 while (start
< end
) {
122 xsc3_l2_clean_pa(start
);
123 start
+= CACHE_LINE_SIZE
;
130 * optimize L2 flush all operation by set/way format
132 static inline void xsc3_l2_flush_all(void)
134 unsigned long l2ctype
, set_way
;
137 __asm__("mrc p15, 1, %0, c0, c0, 1" : "=r" (l2ctype
));
139 for (set
= 0; set
< CACHE_SET_SIZE(l2ctype
); set
++) {
140 for (way
= 0; way
< CACHE_WAY_PER_SET
; way
++) {
141 set_way
= (way
<< 29) | (set
<< 5);
142 __asm__("mcr p15, 1, %0, c7, c15, 2" : : "r"(set_way
));
149 static void xsc3_l2_flush_range(unsigned long start
, unsigned long end
)
151 if (start
== 0 && end
== -1ul) {
156 start
&= ~(CACHE_LINE_SIZE
- 1);
157 while (start
< end
) {
158 xsc3_l2_clean_pa(start
);
159 xsc3_l2_inv_pa(start
);
160 start
+= CACHE_LINE_SIZE
;
166 static int __init
xsc3_l2_init(void)
168 if (!cpu_is_xsc3() || !xsc3_l2_present())
171 if (!(get_cr() & CR_L2
)) {
172 pr_info("XScale3 L2 cache enabled.\n");
173 adjust_cr(CR_L2
, CR_L2
);
177 outer_cache
.inv_range
= xsc3_l2_inv_range
;
178 outer_cache
.clean_range
= xsc3_l2_clean_range
;
179 outer_cache
.flush_range
= xsc3_l2_flush_range
;
183 core_initcall(xsc3_l2_init
);