Skip to content

Commit f9e7a99

Browse files
ardbiesheuvelRussell King
authored and
Russell King
committed
ARM: 9058/1: cache-v7: refactor v7_invalidate_l1 to avoid clobbering r5/r6
The cache invalidation code in v7_invalidate_l1 can be tweaked to re-read the associativity from CCSIDR, and keep the way identifier component in a single register that is assigned in the outer loop. This way, we need 2 registers less. Given that the number of sets is typically much larger than the associativity, rearrange the code so that the outer loop has the fewer number of iterations, ensuring that the re-read of CCSIDR only occurs a handful of times in practice. Fix the whitespace while at it, and update the comment to indicate that this code is no longer a clone of anything else. Acked-by: Nicolas Pitre <[email protected]> Signed-off-by: Ard Biesheuvel <[email protected]> Signed-off-by: Russell King <[email protected]>
1 parent c0e5073 commit f9e7a99

File tree

1 file changed

+25
-26
lines changed

1 file changed

+25
-26
lines changed

arch/arm/mm/cache-v7.S

Lines changed: 25 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -33,42 +33,41 @@ icache_size:
3333
* processor. We fix this by performing an invalidate, rather than a
3434
* clean + invalidate, before jumping into the kernel.
3535
*
36-
* This function is cloned from arch/arm/mach-tegra/headsmp.S, and needs
37-
* to be called for both secondary cores startup and primary core resume
38-
* procedures.
36+
* This function needs to be called for both secondary cores startup and
37+
* primary core resume procedures.
3938
*/
4039
ENTRY(v7_invalidate_l1)
4140
mov r0, #0
4241
mcr p15, 2, r0, c0, c0, 0 @ select L1 data cache in CSSELR
4342
isb
4443
mrc p15, 1, r0, c0, c0, 0 @ read cache geometry from CCSIDR
4544

46-
movw r1, #0x7fff
47-
and r2, r1, r0, lsr #13
45+
movw r3, #0x3ff
46+
and r3, r3, r0, lsr #3 @ 'Associativity' in CCSIDR[12:3]
47+
clz r1, r3 @ WayShift
48+
mov r2, #1
49+
mov r3, r3, lsl r1 @ NumWays-1 shifted into bits [31:...]
50+
movs r1, r2, lsl r1 @ #1 shifted left by same amount
51+
moveq r1, #1 @ r1 needs value > 0 even if only 1 way
4852

49-
movw r1, #0x3ff
53+
and r2, r0, #0x7
54+
add r2, r2, #4 @ SetShift
5055

51-
and r3, r1, r0, lsr #3 @ NumWays - 1
52-
add r2, r2, #1 @ NumSets
56+
1: movw r4, #0x7fff
57+
and r0, r4, r0, lsr #13 @ 'NumSets' in CCSIDR[27:13]
5358

54-
and r0, r0, #0x7
55-
add r0, r0, #4 @ SetShift
56-
57-
clz r1, r3 @ WayShift
58-
add r4, r3, #1 @ NumWays
59-
1: sub r2, r2, #1 @ NumSets--
60-
mov r3, r4 @ Temp = NumWays
61-
2: subs r3, r3, #1 @ Temp--
62-
mov r5, r3, lsl r1
63-
mov r6, r2, lsl r0
64-
orr r5, r5, r6 @ Reg = (Temp<<WayShift)|(NumSets<<SetShift)
65-
mcr p15, 0, r5, c7, c6, 2
66-
bgt 2b
67-
cmp r2, #0
68-
bgt 1b
69-
dsb st
70-
isb
71-
ret lr
59+
2: mov r4, r0, lsl r2 @ NumSet << SetShift
60+
orr r4, r4, r3 @ Reg = (Temp<<WayShift)|(NumSets<<SetShift)
61+
mcr p15, 0, r4, c7, c6, 2
62+
subs r0, r0, #1 @ Set--
63+
bpl 2b
64+
subs r3, r3, r1 @ Way--
65+
bcc 3f
66+
mrc p15, 1, r0, c0, c0, 0 @ re-read cache geometry from CCSIDR
67+
b 1b
68+
3: dsb st
69+
isb
70+
ret lr
7271
ENDPROC(v7_invalidate_l1)
7372

7473
/*

0 commit comments

Comments
 (0)