aboutsummaryrefslogtreecommitdiffstats
path: root/arch/arm/mm/cache-xsc3l2.c
diff options
context:
space:
mode:
authorEric Miao <eric.miao@marvell.com>2008-06-06 04:34:03 -0400
committerRussell King <rmk+kernel@arm.linux.org.uk>2008-07-28 18:13:09 -0400
commit905a09d57afcc49511de18a95605c11ad9c88649 (patch)
tree3e027f413846fb0b392068183dcc840b5aea64ef /arch/arm/mm/cache-xsc3l2.c
parente76e3ac69e62d3f93e935526bc9afa371e7f38ba (diff)
[ARM] pxa: add support for L2 outer cache on XScale3 (attempt 2)
(20072fd0c93349e19527dd2fa9588b4335960e62 lost most of its changes somehow, came from a mbox archive applied with git-am. No idea what happened. This puts back the missing bits. --rmk) The initial patch from Lothar, and Lennert make it into a cleaner one, modified and tested on PXA320 by Eric Miao. This patch moves the L2 cache operations out of proc-xsc3.S into dedicated outer cache support code. CACHE_XSC3L2 can be deselected so no L2 cache specific code will be linked in, and that L2 enable bit will not be set, this applies to the following cases: a. _only_ PXA300/PXA310 support included and no L2 cache wanted b. PXA320 support included, but want L2 be disabled So the enabling of L2 depends on two things: - CACHE_XSC3L2 is selected - and L2 cache is present Where the latter is only a safeguard (previous testing shows it works OK even when this bit is turned on). IXP series of processors with XScale3 cannot disable L2 cache for the moment since they depend on the L2 cache for its coherent memory, so IXP may always select CACHE_XSC3L2. Other L2 relevant bits are always turned on (i.e. the original code enclosed by #if L2_CACHE_ENABLED .. #endif), as they showed no side effects. Specifically, these bits are: - OC bits in TTBASE register (table walk outer cache attributes) - LLR Outer Cache Attributes (OC) in Auxiliary Control Register Signed-off-by: Lothar WaÃ<9f>mann <LW@KARO-electronics.de> Signed-off-by: Lennert Buytenhek <buytenh@marvell.com> Signed-off-by: Eric Miao <eric.miao@marvell.com> Signed-off-by: Russell King <rmk+kernel@arm.linux.org.uk>
Diffstat (limited to 'arch/arm/mm/cache-xsc3l2.c')
-rw-r--r--arch/arm/mm/cache-xsc3l2.c182
1 files changed, 182 insertions, 0 deletions
diff --git a/arch/arm/mm/cache-xsc3l2.c b/arch/arm/mm/cache-xsc3l2.c
new file mode 100644
index 000000000000..158bd96763d3
--- /dev/null
+++ b/arch/arm/mm/cache-xsc3l2.c
@@ -0,0 +1,182 @@
1/*
2 * arch/arm/mm/cache-xsc3l2.c - XScale3 L2 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>
20#include <linux/spinlock.h>
21
22#include <asm/system.h>
23#include <asm/cacheflush.h>
24#include <asm/io.h>
25
26#define CR_L2 (1 << 26)
27
28#define CACHE_LINE_SIZE 32
29#define CACHE_LINE_SHIFT 5
30#define CACHE_WAY_PER_SET 8
31
32#define CACHE_WAY_SIZE(l2ctype) (8192 << (((l2ctype) >> 8) & 0xf))
33#define CACHE_SET_SIZE(l2ctype) (CACHE_WAY_SIZE(l2ctype) >> CACHE_LINE_SHIFT)
34
35static inline int xsc3_l2_present(void)
36{
37 unsigned long l2ctype;
38
39 __asm__("mrc p15, 1, %0, c0, c0, 1" : "=r" (l2ctype));
40
41 return !!(l2ctype & 0xf8);
42}
43
44static inline void xsc3_l2_clean_mva(unsigned long addr)
45{
46 __asm__("mcr p15, 1, %0, c7, c11, 1" : : "r" (addr));
47}
48
49static inline void xsc3_l2_clean_pa(unsigned long addr)
50{
51 xsc3_l2_clean_mva(__phys_to_virt(addr));
52}
53
54static inline void xsc3_l2_inv_mva(unsigned long addr)
55{
56 __asm__("mcr p15, 1, %0, c7, c7, 1" : : "r" (addr));
57}
58
59static inline void xsc3_l2_inv_pa(unsigned long addr)
60{
61 xsc3_l2_inv_mva(__phys_to_virt(addr));
62}
63
64static inline void xsc3_l2_inv_all(void)
65{
66 unsigned long l2ctype, set_way;
67 int set, way;
68
69 __asm__("mrc p15, 1, %0, c0, c0, 1" : "=r" (l2ctype));
70
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));
75 }
76 }
77
78 dsb();
79}
80
81static void xsc3_l2_inv_range(unsigned long start, unsigned long end)
82{
83 if (start == 0 && end == -1ul) {
84 xsc3_l2_inv_all();
85 return;
86 }
87
88 /*
89 * Clean and invalidate partial first cache line.
90 */
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;
95 }
96
97 /*
98 * Clean and invalidate partial last cache line.
99 */
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);
104 }
105
106 /*
107 * Invalidate all full cache lines between 'start' and 'end'.
108 */
109 while (start != end) {
110 xsc3_l2_inv_pa(start);
111 start += CACHE_LINE_SIZE;
112 }
113
114 dsb();
115}
116
117static void xsc3_l2_clean_range(unsigned long start, unsigned long end)
118{
119 start &= ~(CACHE_LINE_SIZE - 1);
120 while (start < end) {
121 xsc3_l2_clean_pa(start);
122 start += CACHE_LINE_SIZE;
123 }
124
125 dsb();
126}
127
128/*
129 * optimize L2 flush all operation by set/way format
130 */
131static inline void xsc3_l2_flush_all(void)
132{
133 unsigned long l2ctype, set_way;
134 int set, way;
135
136 __asm__("mrc p15, 1, %0, c0, c0, 1" : "=r" (l2ctype));
137
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));
142 }
143 }
144
145 dsb();
146}
147
148static void xsc3_l2_flush_range(unsigned long start, unsigned long end)
149{
150 if (start == 0 && end == -1ul) {
151 xsc3_l2_flush_all();
152 return;
153 }
154
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;
160 }
161
162 dsb();
163}
164
165static int __init xsc3_l2_init(void)
166{
167 if (!cpu_is_xsc3() || !xsc3_l2_present())
168 return 0;
169
170 if (!(get_cr() & CR_L2)) {
171 pr_info("XScale3 L2 cache enabled.\n");
172 adjust_cr(CR_L2, CR_L2);
173 xsc3_l2_inv_all();
174 }
175
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;
179
180 return 0;
181}
182core_initcall(xsc3_l2_init);