blob: eef07a8be501892dad35d09e16c7a9a6b36274a9 [file] [log] [blame]
Achin Gupta4f6ad662013-10-25 09:08:21 +01001/*
Dan Handleye83b0ca2014-01-14 18:17:09 +00002 * Copyright (c) 2013-2014, ARM Limited and Contributors. All rights reserved.
Achin Gupta4f6ad662013-10-25 09:08:21 +01003 *
dp-armfa3cf0b2017-05-03 09:38:09 +01004 * SPDX-License-Identifier: BSD-3-Clause
Achin Gupta4f6ad662013-10-25 09:08:21 +01005 */
6
Dan Handley2bd4ef22014-04-09 13:14:54 +01007#include <arch.h>
Achin Gupta4f6ad662013-10-25 09:08:21 +01008#include <asm_macros.S>
9
Achin Gupta4f6ad662013-10-25 09:08:21 +010010 .globl flush_dcache_range
Achin Guptae9c4a642015-09-11 16:03:13 +010011 .globl clean_dcache_range
Achin Gupta4f6ad662013-10-25 09:08:21 +010012 .globl inv_dcache_range
13 .globl dcsw_op_louis
14 .globl dcsw_op_all
Soby Mathew42aa5eb2014-09-02 10:47:33 +010015 .globl dcsw_op_level1
16 .globl dcsw_op_level2
17 .globl dcsw_op_level3
Achin Gupta4f6ad662013-10-25 09:08:21 +010018
Achin Guptae9c4a642015-09-11 16:03:13 +010019/*
20 * This macro can be used for implementing various data cache operations `op`
21 */
22.macro do_dcache_maintenance_by_mva op
Achin Gupta4f6ad662013-10-25 09:08:21 +010023 dcache_line_size x2, x3
24 add x1, x0, x1
25 sub x3, x2, #1
26 bic x0, x0, x3
Achin Guptae9c4a642015-09-11 16:03:13 +010027loop_\op:
28 dc \op, x0
Achin Gupta4f6ad662013-10-25 09:08:21 +010029 add x0, x0, x2
30 cmp x0, x1
Achin Guptae9c4a642015-09-11 16:03:13 +010031 b.lo loop_\op
Achin Gupta4f6ad662013-10-25 09:08:21 +010032 dsb sy
33 ret
Achin Guptae9c4a642015-09-11 16:03:13 +010034.endm
35 /* ------------------------------------------
36 * Clean+Invalidate from base address till
37 * size. 'x0' = addr, 'x1' = size
38 * ------------------------------------------
39 */
40func flush_dcache_range
41 do_dcache_maintenance_by_mva civac
Kévin Petita877c252015-03-24 14:03:57 +000042endfunc flush_dcache_range
Achin Gupta4f6ad662013-10-25 09:08:21 +010043
Achin Guptae9c4a642015-09-11 16:03:13 +010044 /* ------------------------------------------
45 * Clean from base address till size.
46 * 'x0' = addr, 'x1' = size
47 * ------------------------------------------
48 */
49func clean_dcache_range
50 do_dcache_maintenance_by_mva cvac
51endfunc clean_dcache_range
Achin Gupta4f6ad662013-10-25 09:08:21 +010052
53 /* ------------------------------------------
54 * Invalidate from base address till
55 * size. 'x0' = addr, 'x1' = size
56 * ------------------------------------------
57 */
Andrew Thoelke38bde412014-03-18 13:46:55 +000058func inv_dcache_range
Achin Guptae9c4a642015-09-11 16:03:13 +010059 do_dcache_maintenance_by_mva ivac
Kévin Petita877c252015-03-24 14:03:57 +000060endfunc inv_dcache_range
Achin Gupta4f6ad662013-10-25 09:08:21 +010061
62
Andrew Thoelke6a5b3a42014-04-25 10:49:30 +010063 /* ---------------------------------------------------------------
64 * Data cache operations by set/way to the level specified
65 *
66 * The main function, do_dcsw_op requires:
67 * x0: The operation type (0-2), as defined in arch.h
68 * x3: The last cache level to operate on
69 * x9: clidr_el1
Soby Mathew42aa5eb2014-09-02 10:47:33 +010070 * x10: The cache level to begin operation from
Andrew Thoelke6a5b3a42014-04-25 10:49:30 +010071 * and will carry out the operation on each data cache from level 0
72 * to the level in x3 in sequence
73 *
74 * The dcsw_op macro sets up the x3 and x9 parameters based on
75 * clidr_el1 cache information before invoking the main function
76 * ---------------------------------------------------------------
Achin Gupta4f6ad662013-10-25 09:08:21 +010077 */
Achin Gupta4f6ad662013-10-25 09:08:21 +010078
Andrew Thoelke6a5b3a42014-04-25 10:49:30 +010079 .macro dcsw_op shift, fw, ls
80 mrs x9, clidr_el1
81 ubfx x3, x9, \shift, \fw
82 lsl x3, x3, \ls
Soby Mathew42aa5eb2014-09-02 10:47:33 +010083 mov x10, xzr
Andrew Thoelke6a5b3a42014-04-25 10:49:30 +010084 b do_dcsw_op
85 .endm
Achin Gupta4f6ad662013-10-25 09:08:21 +010086
Andrew Thoelke38bde412014-03-18 13:46:55 +000087func do_dcsw_op
Achin Gupta4f6ad662013-10-25 09:08:21 +010088 cbz x3, exit
Andrew Thoelke6a5b3a42014-04-25 10:49:30 +010089 adr x14, dcsw_loop_table // compute inner loop address
90 add x14, x14, x0, lsl #5 // inner loop is 8x32-bit instructions
Achin Gupta4f6ad662013-10-25 09:08:21 +010091 mov x0, x9
Andrew Thoelke6a5b3a42014-04-25 10:49:30 +010092 mov w8, #1
93loop1:
94 add x2, x10, x10, lsr #1 // work out 3x current cache level
95 lsr x1, x0, x2 // extract cache type bits from clidr
96 and x1, x1, #7 // mask the bits for current cache only
97 cmp x1, #2 // see what cache we have at this level
Douglas Raillard9d92e8c2017-03-07 16:36:14 +000098 b.lo level_done // nothing to do if no cache or icache
Andrew Thoelke6a5b3a42014-04-25 10:49:30 +010099
100 msr csselr_el1, x10 // select current cache level in csselr
101 isb // isb to sych the new cssr&csidr
102 mrs x1, ccsidr_el1 // read the new ccsidr
103 and x2, x1, #7 // extract the length of the cache lines
104 add x2, x2, #4 // add 4 (line length offset)
105 ubfx x4, x1, #3, #10 // maximum way number
106 clz w5, w4 // bit position of way size increment
107 lsl w9, w4, w5 // w9 = aligned max way number
108 lsl w16, w8, w5 // w16 = way number loop decrement
109 orr w9, w10, w9 // w9 = combine way and cache number
110 ubfx w6, w1, #13, #15 // w6 = max set number
111 lsl w17, w8, w2 // w17 = set number loop decrement
112 dsb sy // barrier before we start this level
113 br x14 // jump to DC operation specific loop
114
115 .macro dcsw_loop _op
116loop2_\_op:
117 lsl w7, w6, w2 // w7 = aligned max set number
118
119loop3_\_op:
120 orr w11, w9, w7 // combine cache, way and set number
121 dc \_op, x11
122 subs w7, w7, w17 // decrement set number
Douglas Raillard9d92e8c2017-03-07 16:36:14 +0000123 b.hs loop3_\_op
Andrew Thoelke6a5b3a42014-04-25 10:49:30 +0100124
125 subs x9, x9, x16 // decrement way number
Douglas Raillard9d92e8c2017-03-07 16:36:14 +0000126 b.hs loop2_\_op
Andrew Thoelke6a5b3a42014-04-25 10:49:30 +0100127
128 b level_done
129 .endm
130
131level_done:
132 add x10, x10, #2 // increment cache number
133 cmp x3, x10
Douglas Raillard9d92e8c2017-03-07 16:36:14 +0000134 b.hi loop1
Andrew Thoelke6a5b3a42014-04-25 10:49:30 +0100135 msr csselr_el1, xzr // select cache level 0 in csselr
136 dsb sy // barrier to complete final cache operation
137 isb
Achin Gupta4f6ad662013-10-25 09:08:21 +0100138exit:
139 ret
Kévin Petita877c252015-03-24 14:03:57 +0000140endfunc do_dcsw_op
Achin Gupta4f6ad662013-10-25 09:08:21 +0100141
Andrew Thoelke6a5b3a42014-04-25 10:49:30 +0100142dcsw_loop_table:
143 dcsw_loop isw
144 dcsw_loop cisw
145 dcsw_loop csw
146
Achin Gupta4f6ad662013-10-25 09:08:21 +0100147
Andrew Thoelke38bde412014-03-18 13:46:55 +0000148func dcsw_op_louis
Andrew Thoelke6a5b3a42014-04-25 10:49:30 +0100149 dcsw_op #LOUIS_SHIFT, #CLIDR_FIELD_WIDTH, #LEVEL_SHIFT
Kévin Petita877c252015-03-24 14:03:57 +0000150endfunc dcsw_op_louis
Achin Gupta4f6ad662013-10-25 09:08:21 +0100151
152
Andrew Thoelke38bde412014-03-18 13:46:55 +0000153func dcsw_op_all
Andrew Thoelke6a5b3a42014-04-25 10:49:30 +0100154 dcsw_op #LOC_SHIFT, #CLIDR_FIELD_WIDTH, #LEVEL_SHIFT
Kévin Petita877c252015-03-24 14:03:57 +0000155endfunc dcsw_op_all
Soby Mathew42aa5eb2014-09-02 10:47:33 +0100156
157 /* ---------------------------------------------------------------
158 * Helper macro for data cache operations by set/way for the
159 * level specified
160 * ---------------------------------------------------------------
161 */
162 .macro dcsw_op_level level
163 mrs x9, clidr_el1
164 mov x3, \level
165 sub x10, x3, #2
166 b do_dcsw_op
167 .endm
168
169 /* ---------------------------------------------------------------
170 * Data cache operations by set/way for level 1 cache
171 *
172 * The main function, do_dcsw_op requires:
173 * x0: The operation type (0-2), as defined in arch.h
174 * ---------------------------------------------------------------
175 */
176func dcsw_op_level1
177 dcsw_op_level #(1 << LEVEL_SHIFT)
Kévin Petita877c252015-03-24 14:03:57 +0000178endfunc dcsw_op_level1
Soby Mathew42aa5eb2014-09-02 10:47:33 +0100179
180 /* ---------------------------------------------------------------
181 * Data cache operations by set/way for level 2 cache
182 *
183 * The main function, do_dcsw_op requires:
184 * x0: The operation type (0-2), as defined in arch.h
185 * ---------------------------------------------------------------
186 */
187func dcsw_op_level2
188 dcsw_op_level #(2 << LEVEL_SHIFT)
Kévin Petita877c252015-03-24 14:03:57 +0000189endfunc dcsw_op_level2
Soby Mathew42aa5eb2014-09-02 10:47:33 +0100190
191 /* ---------------------------------------------------------------
192 * Data cache operations by set/way for level 3 cache
193 *
194 * The main function, do_dcsw_op requires:
195 * x0: The operation type (0-2), as defined in arch.h
196 * ---------------------------------------------------------------
197 */
198func dcsw_op_level3
199 dcsw_op_level #(3 << LEVEL_SHIFT)
Kévin Petita877c252015-03-24 14:03:57 +0000200endfunc dcsw_op_level3