blob: bd7a6c4699c1b8eca38ab7d7a056ca697110c237 [file] [log] [blame]
Soby Mathewb4c6df42022-11-09 11:13:29 +00001/*
2 * SPDX-License-Identifier: BSD-3-Clause
3 * SPDX-FileCopyrightText: Copyright TF-RMM Contributors.
4 */
5
6#include <arch.h>
7#include <asm_macros.S>
8
9 .globl flush_dcache_range
10 .globl clean_dcache_range
11 .globl inv_dcache_range
Jean-Philippe Brucker6cfd0082025-01-22 17:15:56 +000012 .globl flush_dcache_range_to_poe
13
14/*
15 * sys #4, c7, c14, #0, x0
16 * DC CIPAE, X0
17 */
18#define dc_cipae_x0 0xd50c7e00
Soby Mathewb4c6df42022-11-09 11:13:29 +000019
20/*
21 * This macro can be used for implementing various data cache operations `op`
22 */
23.macro do_dcache_maintenance_by_mva op
24 /* Exit early if size is zero */
25 cbz x1, exit_loop_\op
26 dcache_line_size x2, x3
27 add x1, x0, x1
28 sub x3, x2, #1
29 bic x0, x0, x3
30loop_\op:
31 dc \op, x0
32 add x0, x0, x2
33 cmp x0, x1
34 b.lo loop_\op
35 dsb sy
36exit_loop_\op:
37 ret
38.endm
Jean-Philippe Brucker6cfd0082025-01-22 17:15:56 +000039
40/* op: the hexadecimal instruction opcode for the cache operation */
41.macro do_dcache_maintenance_instr op
42 /* Exit early if size is zero */
43 cbz x1, exit_loop_\op
44 dcache_line_size x2, x3
45 add x1, x0, x1
46 sub x3, x2, #1
47 bic x0, x0, x3
48loop_\op:
49 .inst \op
50 add x0, x0, x2
51 cmp x0, x1
52 b.lo loop_\op
53 dsb sy
54exit_loop_\op:
55 ret
56.endm
57
Soby Mathewb4c6df42022-11-09 11:13:29 +000058 /* ------------------------------------------
59 * Clean+Invalidate from base address till
60 * size. 'x0' = addr, 'x1' = size
61 * ------------------------------------------
62 */
63func flush_dcache_range
64 do_dcache_maintenance_by_mva civac
65endfunc flush_dcache_range
66
67 /* ------------------------------------------
68 * Clean from base address till size.
69 * 'x0' = addr, 'x1' = size
70 * ------------------------------------------
71 */
72func clean_dcache_range
73 do_dcache_maintenance_by_mva cvac
74endfunc clean_dcache_range
75
76 /* ------------------------------------------
77 * Invalidate from base address till
78 * size. 'x0' = addr, 'x1' = size
79 * ------------------------------------------
80 */
81func inv_dcache_range
82 do_dcache_maintenance_by_mva ivac
83endfunc inv_dcache_range
Jean-Philippe Brucker6cfd0082025-01-22 17:15:56 +000084
85 /* ------------------------------------------
86 * Clean and invalidate to point of
87 * encryption from base address till size.
88 * 'x0' = physical addr, 'x1' = size
89 * ------------------------------------------
90 */
91func flush_dcache_range_to_poe
92 do_dcache_maintenance_instr dc_cipae_x0
93endfunc flush_dcache_range_to_poe