2 * SPDX-License-Identifier: GPL-2.0+
6 #include <linux/linkage.h>
7 #include <linux/sizes.h>
8 #include <asm/system.h>
10 #if CONFIG_IS_ENABLED(SYS_THUMB_BUILD)
19 * v7_flush_dcache_all()
21 * Flush the whole D-cache.
23 * Corrupted registers: r0-r7, r9-r11 (r6 only in Thumb mode)
25 * Note: copied from arch/arm/mm/cache-v7.S of Linux 4.4
27 ENTRY(__v7_flush_dcache_all)
28 dmb @ ensure ordering with previous memory accesses
29 mrc p15, 1, r0, c0, c0, 1 @ read clidr
30 mov r3, r0, lsr #23 @ move LoC into position
31 ands r3, r3, #7 << 1 @ extract LoC*2 from clidr
32 beq finished @ if loc is 0, then no need to clean
34 mov r10, #0 @ start clean at cache level 0
36 add r2, r10, r10, lsr #1 @ work out 3x current cache level
37 mov r1, r0, lsr r2 @ extract cache type bits from clidr
38 and r1, r1, #7 @ mask of the bits for current cache only
39 cmp r1, #2 @ see what cache we have at this level
40 blt skip @ skip if no cache, or just i-cache
41 mcr p15, 2, r10, c0, c0, 0 @ select current cache level in cssr
42 isb @ isb to sych the new cssr&csidr
43 mrc p15, 1, r1, c0, c0, 0 @ read the new csidr
44 and r2, r1, #7 @ extract the length of the cache lines
45 add r2, r2, #4 @ add 4 (line length offset)
47 ands r4, r4, r1, lsr #3 @ find maximum number on the way size
48 clz r5, r4 @ find bit position of way size increment
50 ands r7, r7, r1, lsr #13 @ extract max number of the index size
52 mov r9, r7 @ create working copy of max index
54 ARM( orr r11, r10, r4, lsl r5 ) @ factor way and cache number into r11
55 THUMB( lsl r6, r4, r5 )
56 THUMB( orr r11, r10, r6 ) @ factor way and cache number into r11
57 ARM( orr r11, r11, r9, lsl r2 ) @ factor index number into r11
58 THUMB( lsl r6, r9, r2 )
59 THUMB( orr r11, r11, r6 ) @ factor index number into r11
60 mcr p15, 0, r11, c7, c14, 2 @ clean & invalidate by set/way
61 subs r9, r9, #1 @ decrement the index
63 subs r4, r4, #1 @ decrement the way
66 add r10, r10, #2 @ increment cache number
70 mov r10, #0 @ swith back to cache level 0
71 mcr p15, 2, r10, c0, c0, 0 @ select current cache level in cssr
75 ENDPROC(__v7_flush_dcache_all)
77 ENTRY(v7_flush_dcache_all)
78 ARM( stmfd sp!, {r4-r5, r7, r9-r11, lr} )
79 THUMB( stmfd sp!, {r4-r7, r9-r11, lr} )
80 bl __v7_flush_dcache_all
81 ARM( ldmfd sp!, {r4-r5, r7, r9-r11, lr} )
82 THUMB( ldmfd sp!, {r4-r7, r9-r11, lr} )
84 ENDPROC(v7_flush_dcache_all)
87 * v7_invalidate_dcache_all()
89 * Invalidate the whole D-cache.
91 * Corrupted registers: r0-r7, r9-r11 (r6 only in Thumb mode)
93 * Note: copied from __v7_flush_dcache_all above with
94 * mcr p15, 0, r11, c7, c14, 2
96 * mcr p15, 0, r11, c7, c6, 2
98 ENTRY(__v7_invalidate_dcache_all)
99 dmb @ ensure ordering with previous memory accesses
100 mrc p15, 1, r0, c0, c0, 1 @ read clidr
101 mov r3, r0, lsr #23 @ move LoC into position
102 ands r3, r3, #7 << 1 @ extract LoC*2 from clidr
103 beq inval_finished @ if loc is 0, then no need to clean
104 mov r10, #0 @ start clean at cache level 0
106 add r2, r10, r10, lsr #1 @ work out 3x current cache level
107 mov r1, r0, lsr r2 @ extract cache type bits from clidr
108 and r1, r1, #7 @ mask of the bits for current cache only
109 cmp r1, #2 @ see what cache we have at this level
110 blt inval_skip @ skip if no cache, or just i-cache
111 mcr p15, 2, r10, c0, c0, 0 @ select current cache level in cssr
112 isb @ isb to sych the new cssr&csidr
113 mrc p15, 1, r1, c0, c0, 0 @ read the new csidr
114 and r2, r1, #7 @ extract the length of the cache lines
115 add r2, r2, #4 @ add 4 (line length offset)
117 ands r4, r4, r1, lsr #3 @ find maximum number on the way size
118 clz r5, r4 @ find bit position of way size increment
120 ands r7, r7, r1, lsr #13 @ extract max number of the index size
122 mov r9, r7 @ create working copy of max index
124 ARM( orr r11, r10, r4, lsl r5 ) @ factor way and cache number into r11
125 THUMB( lsl r6, r4, r5 )
126 THUMB( orr r11, r10, r6 ) @ factor way and cache number into r11
127 ARM( orr r11, r11, r9, lsl r2 ) @ factor index number into r11
128 THUMB( lsl r6, r9, r2 )
129 THUMB( orr r11, r11, r6 ) @ factor index number into r11
130 mcr p15, 0, r11, c7, c6, 2 @ invalidate by set/way
131 subs r9, r9, #1 @ decrement the index
133 subs r4, r4, #1 @ decrement the way
136 add r10, r10, #2 @ increment cache number
140 mov r10, #0 @ swith back to cache level 0
141 mcr p15, 2, r10, c0, c0, 0 @ select current cache level in cssr
145 ENDPROC(__v7_invalidate_dcache_all)
147 ENTRY(v7_invalidate_dcache_all)
148 ARM( stmfd sp!, {r4-r5, r7, r9-r11, lr} )
149 THUMB( stmfd sp!, {r4-r7, r9-r11, lr} )
150 bl __v7_invalidate_dcache_all
151 ARM( ldmfd sp!, {r4-r5, r7, r9-r11, lr} )
152 THUMB( ldmfd sp!, {r4-r7, r9-r11, lr} )
154 ENDPROC(v7_invalidate_dcache_all)