author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Mon, 18 Jan 2010 21:31:10 +0200 | |
changeset 36 | 538db54a451d |
parent 0 | a41df078684a |
child 153 | 1f2940c968a9 |
permissions | -rw-r--r-- |
0 | 1 |
// Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies). |
2 |
// All rights reserved. |
|
3 |
// This component and the accompanying materials are made available |
|
4 |
// under the terms of the License "Eclipse Public License v1.0" |
|
5 |
// which accompanies this distribution, and is available |
|
6 |
// at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 |
// |
|
8 |
// Initial Contributors: |
|
9 |
// Nokia Corporation - initial contribution. |
|
10 |
// |
|
11 |
// Contributors: |
|
12 |
// |
|
13 |
// Description: |
|
14 |
// Cache maintenance primitives on ARMv7 (and later) platforms. |
|
15 |
// eka\kernel\arm\cachev7.cia |
|
16 |
// |
|
17 |
||
18 |
#include <e32cia.h> |
|
19 |
#include <arm.h> |
|
20 |
#include "cache_maintenance.h" |
|
21 |
||
22 |
#if defined(__CPU_ARMV7) |
|
23 |
||
24 |
// These constant defines LoC & LoU position in Cache Level ID Register |
|
25 |
const TInt KLoCMask = 0x07000000; // LoC field in CLIDR |
|
26 |
const TInt KLoCShift = 24; |
|
27 |
#if defined(__SMP__) |
|
28 |
// LoUIS seems to be not implemented on cortex_a9. |
|
29 |
//const TInt KLoUMask = 0x00e00000; // LoUIS field in CLIDR |
|
30 |
//const TInt KLoUShift = 21; |
|
31 |
const TInt KLoUMask = 0x38000000; // LoUU field in CLIDR |
|
32 |
const TInt KLoUShift = 27; |
|
33 |
#else |
|
34 |
const TInt KLoUMask = 0x38000000; // LoUU field in CLIDR |
|
35 |
const TInt KLoUShift = 27; |
|
36 |
#endif |
|
37 |
||
38 |
// These constant defines max values in Cache Size Id Register |
|
39 |
const TInt KAssocMax = 0x3ff; //Max value of associativity (10 bits reserved for this) |
|
40 |
const TInt KNumSetMax = 0x7fff; //MaxValue for Set Number (15 bits resrved for this) |
|
41 |
||
42 |
||
43 |
__NAKED__ TUint32 InternalCache::TypeRegister() |
|
44 |
{ |
|
45 |
asm("mrc p15, 0, r0, c0, c0, 1 "); |
|
46 |
__JUMP(,lr); |
|
47 |
} |
|
48 |
||
49 |
__NAKED__ TUint32 InternalCache::LevelIDRegister() |
|
50 |
{ |
|
51 |
asm("mrc p15, 1, r0, c0, c0, 1 "); |
|
52 |
__JUMP(,lr); |
|
53 |
} |
|
54 |
||
55 |
__NAKED__ TUint32 InternalCache::SizeIdRegister(TUint32 /*aType*/, TUint32 /*aLevel*/) |
|
56 |
{ |
|
57 |
asm("orr r0, r1, lsl #1"); // r0 = entry for Cache Size Selection Reg. |
|
58 |
asm("mcr p15, 2, r0, c0, c0, 0 "); // set Cache Size Selection Register |
|
59 |
asm("mov r1, #0"); |
|
60 |
ARM_ISBSY; // prefetchFlush to sync the change to the CacheSizeID reg |
|
61 |
asm("mrc p15, 1, r0, c0, c0, 0 "); // read Cache Size Id Register |
|
62 |
__JUMP(,lr); |
|
63 |
} |
|
64 |
||
65 |
__NAKED__ void InternalCache::DrainBuffers() |
|
66 |
{ |
|
67 |
// Drain write buffer is rather archaic vocabulary from ARMv5. |
|
68 |
// On ARMv7, data & instruction sync barriers apply. |
|
69 |
asm("mov r0, #0 "); |
|
70 |
ARM_DSBSY; |
|
71 |
ARM_ISBSY; |
|
72 |
__JUMP(,lr); |
|
73 |
||
74 |
asm("__DCacheInfoPoU: "); |
|
75 |
asm(".word %a0" : : "i" ((TInt)&InternalCache::Info[KCacheInfoD_PoU])); |
|
76 |
asm("__DCacheInfoPoC: "); |
|
77 |
asm(".word %a0" : : "i" ((TInt)&InternalCache::Info[KCacheInfoD])); |
|
78 |
asm("__ICacheInfo: "); |
|
79 |
asm(".word %a0" : : "i" ((TInt)&InternalCache::Info[KCacheInfoI])); |
|
80 |
} |
|
81 |
||
82 |
__NAKED__ void InternalCache::IMB_CacheLine(TLinAddr /*aAddr*/) |
|
83 |
{ |
|
36
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
84 |
//--Determine base address of cache line--// |
0 | 85 |
asm("ldr r2, __DCacheInfoPoU "); |
86 |
asm("ldrh r3, [r2, #%a0]" : : "i" _FOFF(SCacheInfo,iLineLength)); |
|
36
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
87 |
asm("sub ip, r3, #1"); // ip=mask for offset within line |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
88 |
asm("bic r2, r0, ip"); // r2 = cache line base |
0 | 89 |
|
36
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
90 |
DCCMVAU(r2); // Clean DCache line to Point-of-Unification |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
91 |
ARM_DSBSY; // Data Sync Barrier (system) |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
92 |
ICIMVAU(r2); // Invalidate Instruction cache line to Point-of-Unification |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
93 |
BPIMVA(r0); // Invalidate aAddr from Branch Predictor Array |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
94 |
asm("add r0, r0, #2"); |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
95 |
BPIMVA(r0); // Invalidate possible THUMB instuction at aAddr+2 from Branch Predictor Array |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
96 |
ARM_DSBSH; // Data Sync Barrier (system) |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
97 |
ARM_ISBSY; // Instruction Sync Barrier |
0 | 98 |
__JUMP(,lr); |
99 |
} |
|
100 |
||
101 |
__NAKED__ void InternalCache::Invalidate_ICache_Region(TLinAddr /*aBase*/, TUint /*aSize*/) |
|
102 |
{ |
|
103 |
asm("ldr r2, __ICacheInfo "); |
|
104 |
asm("ldrh r3, [r2, #%a0]" : : "i" _FOFF(SCacheInfo,iLineLength)); |
|
105 |
asm("sub ip, r3, #1 "); // ip=mask for offset within line |
|
106 |
asm("and ip, ip, r0 "); // ip=offset of start address within line |
|
107 |
asm("add r1, r1, ip "); // add this to the size |
|
108 |
asm("sub ip, r3, #1 "); |
|
109 |
asm("bic r0, r0, ip "); // round base address down to start of line |
|
110 |
asm("add r1, r1, ip "); // round size up |
|
111 |
asm("1: "); |
|
112 |
asm("subs r1, r1, r3 "); // decrement size by line length |
|
113 |
asm("bcc 2f "); |
|
114 |
ICIMVAU(r0); |
|
115 |
asm("2: "); |
|
116 |
asm("add r0, r0, r3 "); // step address on |
|
117 |
asm("bhi 1b "); // loop if more lines |
|
118 |
#ifdef __SMP__ // } |
|
119 |
BPIALLIS; // } flush branch predictor |
|
120 |
#else // } |
|
121 |
BPIALL; // } |
|
122 |
#endif |
|
123 |
ARM_DSBSH; |
|
124 |
ARM_ISBSY; |
|
125 |
__JUMP(,lr); |
|
126 |
} |
|
127 |
||
128 |
__NAKED__ void InternalCache::Invalidate_ICache_All() |
|
129 |
{ |
|
130 |
#ifdef __SMP__ |
|
131 |
ICIALLUIS; |
|
132 |
// BPIALLIS; NOT NEEDED SINCE IT IS INCORPORATED IN ICIALLUIS |
|
133 |
ARM_DSBSH; |
|
134 |
#else |
|
135 |
ICIALLU; |
|
136 |
// BPIALL; NOT NEEDED SINCE IT IS INCORPORATED IN ICIALLU |
|
137 |
ARM_DSBSY; |
|
138 |
#endif |
|
139 |
ARM_ISBSY; |
|
140 |
__JUMP(,lr); |
|
141 |
} |
|
142 |
||
143 |
__NAKED__ void InternalCache::Invalidate_DCache_Region(TLinAddr /*aBase*/, TUint /*aSize*/) |
|
144 |
{ |
|
145 |
asm("ldr r2, __DCacheInfoPoC "); |
|
146 |
asm("ldrh r3, [r2, #%a0]" : : "i" _FOFF(SCacheInfo,iLineLength)); |
|
147 |
asm("sub ip, r3, #1 "); // ip=mask for offset within line |
|
148 |
asm("and ip, ip, r0 "); // ip=offset of start address within line |
|
149 |
asm("add r1, r1, ip "); // add this to the size |
|
150 |
asm("sub ip, r3, #1 "); |
|
151 |
asm("bic r0, r0, ip "); // round base address down to start of line |
|
152 |
asm("add r1, r1, ip "); // round size up |
|
153 |
asm("1: "); |
|
154 |
asm("subs r1, r1, r3 "); // decrement size by line length |
|
155 |
asm("bcc 2f "); |
|
156 |
DCIMVAC(r0); |
|
157 |
asm("2: "); |
|
158 |
asm("add r0, r0, r3 "); // step address on |
|
159 |
asm("bhi 1b "); // loop if more lines |
|
160 |
ARM_DSBSY; |
|
161 |
ARM_ISBSY; |
|
162 |
__JUMP(,lr); |
|
163 |
} |
|
164 |
||
165 |
__NAKED__ void InternalCache::Clean_DCache_Region(TLinAddr /*aBase*/, TUint /*aSize*/) |
|
166 |
{ |
|
167 |
asm("ldr r2, __DCacheInfoPoC "); |
|
168 |
asm("ldrh r3, [r2, #%a0]" : : "i" _FOFF(SCacheInfo,iLineLength)); |
|
169 |
asm("sub ip, r3, #1 "); // ip=mask for offset within line |
|
170 |
asm("and ip, ip, r0 "); // ip=offset of start address within line |
|
171 |
asm("add r1, r1, ip "); // add this to the size |
|
172 |
asm("sub ip, r3, #1 "); |
|
173 |
asm("bic r0, r0, ip "); // round base address down to start of line |
|
174 |
asm("add r1, r1, ip "); // round size up |
|
175 |
asm("1: "); |
|
176 |
asm("subs r1, r1, r3 "); // decrement size by line length |
|
177 |
asm("bcc 2f "); |
|
178 |
DCCMVAC(r0); |
|
179 |
#if defined(__CPU_CORTEX_A9__) && !defined(__CPU_ARM_A9_ERRATUM_571771_FIXED) |
|
180 |
DCCMVAC(r13); // ARM Cortex-A9 MPCore erratum 571771 workaround |
|
181 |
// Execute additional cache clean to enforce barrier on other CPUs |
|
182 |
#endif |
|
183 |
asm("2: "); |
|
184 |
asm("add r0, r0, r3 "); // step address on |
|
185 |
asm("bhi 1b "); // loop if more lines |
|
186 |
ARM_DSBSY; |
|
187 |
ARM_ISBSY; |
|
188 |
__JUMP(,lr); |
|
189 |
} |
|
190 |
||
191 |
__NAKED__ void InternalCache::Clean_PoU_DCache_Region(TLinAddr /*aBase*/, TUint /*aSize*/) |
|
192 |
{ |
|
193 |
asm("ldr r2, __DCacheInfoPoU "); |
|
194 |
asm("ldrh r3, [r2, #%a0]" : : "i" _FOFF(SCacheInfo,iLineLength)); |
|
195 |
asm("sub ip, r3, #1 "); // ip=mask for offset within line |
|
196 |
asm("and ip, ip, r0 "); // ip=offset of start address within line |
|
197 |
asm("add r1, r1, ip "); // add this to the size |
|
198 |
asm("sub ip, r3, #1 "); |
|
199 |
asm("bic r0, r0, ip "); // round base address down to start of line |
|
200 |
asm("add r1, r1, ip "); // round size up |
|
201 |
asm("1: "); |
|
202 |
asm("subs r1, r1, r3 "); // decrement size by line length |
|
203 |
asm("bcc 2f "); |
|
204 |
DCCMVAU(r0); |
|
205 |
asm("2: "); |
|
206 |
asm("add r0, r0, r3 "); // step address on |
|
207 |
asm("bhi 1b "); // loop if more lines |
|
208 |
ARM_DSBSH; |
|
209 |
ARM_ISBSY; |
|
210 |
__JUMP(,lr); |
|
211 |
} |
|
212 |
||
213 |
__NAKED__ void InternalCache::CleanAndInvalidate_DCache_Region(TLinAddr, TUint) |
|
214 |
{ |
|
215 |
asm("ldr r2, __DCacheInfoPoC "); |
|
216 |
asm("ldrh r3, [r2, #%a0]" : : "i" _FOFF(SCacheInfo,iLineLength)); |
|
217 |
asm("sub ip, r3, #1 "); // ip=mask for offset within line |
|
218 |
asm("and ip, ip, r0 "); // ip=offset of start address within line |
|
219 |
asm("add r1, r1, ip "); // add this to the size |
|
220 |
asm("sub ip, r3, #1 "); |
|
221 |
asm("bic r0, r0, ip "); // round base address down to start of line |
|
222 |
asm("add r1, r1, ip "); // round size up |
|
223 |
asm("1: "); |
|
224 |
asm("subs r1, r1, r3 "); // decrement size by line length |
|
225 |
asm("bcc 2f "); |
|
226 |
DCCIMVAC(r0); |
|
227 |
#if defined(__CPU_CORTEX_A9__) && !defined(__CPU_ARM_A9_ERRATUM_571771_FIXED) |
|
228 |
DCCIMVAC(r13); // ARM Cortex-A9 MPCore erratum 571771 workaround |
|
229 |
// Execute additional cache clean to enforce barrier on other CPUs |
|
230 |
#endif |
|
231 |
asm("2: "); |
|
232 |
asm("add r0, r0, r3 "); // step address on |
|
233 |
asm("bhi 1b "); // loop if more lines |
|
234 |
ARM_DSBSY; |
|
235 |
ARM_ISBSY; |
|
236 |
__JUMP(,lr); |
|
237 |
} |
|
238 |
||
239 |
__NAKED__ void InternalCache::Clean_DCache_All() |
|
240 |
{ |
|
241 |
//NOTE: ON SMP THIS ONLY CLEANS THE CURRENT CPU CACHE, NOT OTHER CPU CACHES |
|
242 |
asm("stmfd sp!, {r4-r5,r7,r9-r11} "); |
|
243 |
asm("mrc p15, 1, r0, c0, c0, 1"); // Read CLIDR |
|
244 |
asm("ands r3, r0, #%a0" : : "i" ((TInt)KLoCMask)); |
|
245 |
asm("mov r3, r3, lsr #%a0" : : "i" ((TInt)(KLoCShift-1))); // r3 = LoC << 1 |
|
246 |
asm("beq 5f"); // ... and finish if LoC is zero |
|
247 |
asm("mov r10, #0"); // r10 = 0 (the current cache level) |
|
248 |
||
249 |
asm("1:"); |
|
250 |
asm("add r2, r10, r10, lsr #1"); // Work out 3xcachelevel |
|
251 |
asm("mov r1, r0, LSR r2"); // bottom 3 bits are the Ctype for this level |
|
252 |
asm("and r1, r1, #7"); // get those 3 bits alone |
|
253 |
asm("cmp r1, #2"); |
|
254 |
asm("blt 4f"); // no cache or only instruction cache at this level |
|
255 |
||
256 |
asm("mrs r4, cpsr"); // Disable interrupts while accessing CS Selection Reg & |
|
257 |
CPSIDAIF; // CS ID Reg. |
|
258 |
||
259 |
asm("mcr p15, 2, r10, c0, c0, 0"); // write the Cache Size selection register |
|
260 |
asm("mov r1, #0"); |
|
261 |
ARM_ISBSY; // ISB to sync the change to the CacheSizeID reg |
|
262 |
asm("mrc p15, 1, r1, c0, c0, 0"); // reads current Cache Size ID register |
|
263 |
||
264 |
asm("msr cpsr_c, r4"); // Restore interrupts |
|
265 |
||
266 |
asm("and r2, r1, #7"); // extract the line length field |
|
267 |
asm("add r2, r2, #4"); // add 4 for the line length offset (log2 16 bytes) |
|
268 |
asm("ldr r4, =%a0" : : "i" ((TInt)KAssocMax)); |
|
269 |
asm("ands r4, r4, r1, lsr #3"); // R4 is the max number on the way size (right aligned) |
|
270 |
CLZ(5,4); // R5 is the bit position of the way size increment |
|
271 |
asm("ldr r7, =%a0" : : "i" ((TInt)KNumSetMax)); |
|
272 |
asm("ands r7, r7, r1, lsr #13"); // R7 is the max number of the index size (right aligned) |
|
273 |
||
274 |
asm("2:"); |
|
275 |
asm("mov r9, r4"); // R9 working copy of the max way size (right aligned) |
|
276 |
||
277 |
asm("3:"); |
|
278 |
asm("orr r11, r10, r9, lsl r5"); // factor in the way number and cache number into R11 |
|
279 |
asm("orr r11, r11, r7, lsl r2"); // factor in the index number |
|
280 |
DCCSW(r11); // clean by set/way |
|
281 |
asm("subs r9, r9, #1"); // decrement the way number |
|
282 |
asm("bge 3b"); |
|
283 |
asm("subs r7, r7, #1"); // decrement the index |
|
284 |
asm("bge 2b"); |
|
285 |
||
286 |
asm("4:"); // SKIP |
|
287 |
asm("add r10, r10, #2"); // increment the cache number |
|
288 |
asm("cmp r3, r10"); |
|
289 |
asm("bgt 1b"); |
|
290 |
ARM_DSBSY; |
|
291 |
ARM_ISBSY; |
|
292 |
||
293 |
asm("5:"); // FINISHED |
|
294 |
asm("ldmfd sp!, {r4-r5,r7,r9-r11} "); // restore registers |
|
295 |
__JUMP(,lr); |
|
296 |
} |
|
297 |
||
298 |
__NAKED__ void InternalCache::CleanAndInvalidate_DCache_All() |
|
299 |
{ |
|
300 |
//NOTE: ON SMP THIS ONLY CLEANS AND INVALIDATES THE CURRENT CPU CACHE, NOT OTHER CPU CACHES |
|
301 |
asm("stmfd sp!, {r4-r5,r7,r9-r11} "); |
|
302 |
asm("mrc p15, 1, r0, c0, c0, 1"); // Read CLIDR |
|
303 |
asm("ands r3, r0, #%a0" : : "i" ((TInt)KLoCMask)); |
|
304 |
asm("mov r3, r3, lsr #%a0" : : "i" ((TInt)(KLoCShift-1))); // r3 = LoC << 1 |
|
305 |
asm("beq 5f"); // ... and finish if LoC is zero |
|
306 |
asm("mov r10, #0"); // r10 = 0 (the current cache level) |
|
307 |
||
308 |
asm("1:"); |
|
309 |
asm("add r2, r10, r10, lsr #1"); // Work out 3xcachelevel |
|
310 |
asm("mov r1, r0, LSR r2"); // bottom 3 bits are the Ctype for this level |
|
311 |
asm("and r1, r1, #7"); // get those 3 bits alone |
|
312 |
asm("cmp r1, #2"); |
|
313 |
asm("blt 4f"); // no cache or only instruction cache at this level |
|
314 |
||
315 |
asm("mrs r4, cpsr"); // Disable interrupts while accessing CS Selection Reg & |
|
316 |
CPSIDAIF; // CS ID Reg. |
|
317 |
||
318 |
asm("mcr p15, 2, r10, c0, c0, 0"); // write the Cache Size selection register |
|
319 |
asm("mov r1, #0"); |
|
320 |
ARM_ISBSY; // ISB to sync the change to the CacheSizeID reg |
|
321 |
asm("mrc p15, 1, r1, c0, c0, 0"); // reads current Cache Size ID register |
|
322 |
||
323 |
asm("msr cpsr_c, r4"); // Restore interrupts |
|
324 |
||
325 |
asm("and r2, r1, #7"); // extract the line length field |
|
326 |
asm("add r2, r2, #4"); // add 4 for the line length offset (log2 16 bytes) |
|
327 |
asm("ldr r4, =%a0" : : "i" ((TInt)KAssocMax)); |
|
328 |
asm("ands r4, r4, r1, lsr #3"); // R4 is the max number on the way size (right aligned) |
|
329 |
CLZ(5,4); // R5 is the bit position of the way size increment |
|
330 |
asm("ldr r7, =%a0" : : "i" ((TInt)KNumSetMax)); |
|
331 |
asm("ands r7, r7, r1, lsr #13"); // R7 is the max number of the index size (right aligned) |
|
332 |
||
333 |
asm("2:"); |
|
334 |
asm("mov r9, r4"); // R9 working copy of the max way size (right aligned) |
|
335 |
||
336 |
asm("3:"); |
|
337 |
asm("orr r11, r10, r9, lsl r5"); // factor in the way number and cache number into R11 |
|
338 |
asm("orr r11, r11, r7, lsl r2"); // factor in the index number |
|
339 |
DCCISW(r11); // clean and invalidate by set/way |
|
340 |
asm("subs r9, r9, #1"); // decrement the way number |
|
341 |
asm("bge 3b"); |
|
342 |
asm("subs r7, r7, #1"); // decrement the index |
|
343 |
asm("bge 2b"); |
|
344 |
||
345 |
asm("4:"); // SKIP |
|
346 |
asm("add r10, r10, #2"); // increment the cache number |
|
347 |
asm("cmp r3, r10"); |
|
348 |
asm("bgt 1b"); |
|
349 |
ARM_DSBSY; |
|
350 |
ARM_ISBSY; |
|
351 |
||
352 |
asm("5:"); // FINISHED |
|
353 |
asm("ldmfd sp!, {r4-r5,r7,r9-r11} "); // restore registers |
|
354 |
__JUMP(,lr); |
|
355 |
} |
|
356 |
||
357 |
__NAKED__ void InternalCache::Clean_PoU_DCache_All() |
|
358 |
{ |
|
359 |
// NOTE: ON SMP THIS ONLY CLEANS THE CURRENT CPU CACHE, NOT OTHER CPU CACHES |
|
360 |
asm("stmfd sp!, {r4-r5,r7,r9-r11} "); |
|
361 |
asm("mrc p15, 1, r0, c0, c0, 1"); // Read CLIDR |
|
362 |
asm("ands r3, r0, #%a0" : : "i" ((TInt)KLoUMask)); |
|
363 |
asm("mov r3, r3, lsr #%a0" : : "i" ((TInt)(KLoUShift-1))); // r3 = LoU << 1 |
|
364 |
asm("beq 5f"); // ... and finish if LoU is zero |
|
365 |
asm("mov r10, #0"); // r10 = 0 (the current cache level) |
|
366 |
||
367 |
asm("1:"); |
|
368 |
asm("add r2, r10, r10, lsr #1"); // Work out 3xcachelevel |
|
369 |
asm("mov r1, r0, LSR r2"); // bottom 3 bits are the Ctype for this level |
|
370 |
asm("and r1, r1, #7"); // get those 3 bits alone |
|
371 |
asm("cmp r1, #2"); |
|
372 |
asm("blt 4f"); // no cache or only instruction cache at this level |
|
373 |
||
374 |
asm("mrs r4, cpsr"); // Disable interrupts while accessing CS Selection Reg & |
|
375 |
CPSIDAIF; // CS ID Reg. |
|
376 |
||
377 |
asm("mcr p15, 2, r10, c0, c0, 0"); // write the Cache Size selection register |
|
378 |
asm("mov r1, #0"); |
|
379 |
ARM_ISBSY; // ISB to sync the change to the CacheSizeID reg |
|
380 |
asm("mrc p15, 1, r1, c0, c0, 0"); // reads current Cache Size ID register |
|
381 |
||
382 |
asm("msr cpsr_c, r4"); // Restore interrupts |
|
383 |
||
384 |
asm("and r2, r1, #7"); // extract the line length field |
|
385 |
asm("add r2, r2, #4"); // add 4 for the line length offset (log2 16 bytes) |
|
386 |
asm("ldr r4, =%a0" : : "i" ((TInt)KAssocMax)); |
|
387 |
asm("ands r4, r4, r1, lsr #3"); // R4 is the max number on the way size (right aligned) |
|
388 |
CLZ(5,4); // R5 is the bit position of the way size increment |
|
389 |
asm("ldr r7, =%a0" : : "i" ((TInt)KNumSetMax)); |
|
390 |
asm("ands r7, r7, r1, lsr #13"); // R7 is the max number of the index size (right aligned) |
|
391 |
||
392 |
asm("2:"); |
|
393 |
asm("mov r9, r4"); // R9 working copy of the max way size (right aligned) |
|
394 |
||
395 |
asm("3:"); |
|
396 |
asm("orr r11, r10, r9, lsl r5"); // factor in the way number and cache number into R11 |
|
397 |
asm("orr r11, r11, r7, lsl r2"); // factor in the index number |
|
398 |
DCCSW(r11); // clean by set/way |
|
399 |
asm("subs r9, r9, #1"); // decrement the way number |
|
400 |
asm("bge 3b"); |
|
401 |
asm("subs r7, r7, #1"); // decrement the index |
|
402 |
asm("bge 2b"); |
|
403 |
||
404 |
asm("4:"); // SKIP |
|
405 |
asm("add r10, r10, #2"); // increment the cache number |
|
406 |
asm("cmp r3, r10"); |
|
407 |
asm("bgt 1b"); |
|
408 |
ARM_DSBSY; |
|
409 |
ARM_ISBSY; |
|
410 |
||
411 |
asm("5:"); // FINISHED |
|
412 |
asm("ldmfd sp!, {r4-r5,r7,r9-r11} "); // restore registers |
|
413 |
__JUMP(,lr); |
|
414 |
} |
|
415 |
||
416 |
#if defined(__BROADCAST_ISB) |
|
417 |
__NAKED__ void T_ISB_IPI::ISBIsr(TGenericIPI* /*aPtr*/) |
|
418 |
{ |
|
419 |
ARM_ISBSY; |
|
420 |
__JUMP(,lr); |
|
421 |
} |
|
422 |
#endif //defined(__BROADCAST_ISB) |
|
423 |
||
424 |
#endif //#if defined(__CPU_ARMV7) |