Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 1 | /* |
| 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 Brucker | 6cfd008 | 2025-01-22 17:15:56 +0000 | [diff] [blame^] | 12 | .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 Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 19 | |
| 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 |
| 30 | loop_\op: |
| 31 | dc \op, x0 |
| 32 | add x0, x0, x2 |
| 33 | cmp x0, x1 |
| 34 | b.lo loop_\op |
| 35 | dsb sy |
| 36 | exit_loop_\op: |
| 37 | ret |
| 38 | .endm |
Jean-Philippe Brucker | 6cfd008 | 2025-01-22 17:15:56 +0000 | [diff] [blame^] | 39 | |
| 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 |
| 48 | loop_\op: |
| 49 | .inst \op |
| 50 | add x0, x0, x2 |
| 51 | cmp x0, x1 |
| 52 | b.lo loop_\op |
| 53 | dsb sy |
| 54 | exit_loop_\op: |
| 55 | ret |
| 56 | .endm |
| 57 | |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 58 | /* ------------------------------------------ |
| 59 | * Clean+Invalidate from base address till |
| 60 | * size. 'x0' = addr, 'x1' = size |
| 61 | * ------------------------------------------ |
| 62 | */ |
| 63 | func flush_dcache_range |
| 64 | do_dcache_maintenance_by_mva civac |
| 65 | endfunc flush_dcache_range |
| 66 | |
| 67 | /* ------------------------------------------ |
| 68 | * Clean from base address till size. |
| 69 | * 'x0' = addr, 'x1' = size |
| 70 | * ------------------------------------------ |
| 71 | */ |
| 72 | func clean_dcache_range |
| 73 | do_dcache_maintenance_by_mva cvac |
| 74 | endfunc clean_dcache_range |
| 75 | |
| 76 | /* ------------------------------------------ |
| 77 | * Invalidate from base address till |
| 78 | * size. 'x0' = addr, 'x1' = size |
| 79 | * ------------------------------------------ |
| 80 | */ |
| 81 | func inv_dcache_range |
| 82 | do_dcache_maintenance_by_mva ivac |
| 83 | endfunc inv_dcache_range |
Jean-Philippe Brucker | 6cfd008 | 2025-01-22 17:15:56 +0000 | [diff] [blame^] | 84 | |
| 85 | /* ------------------------------------------ |
| 86 | * Clean and invalidate to point of |
| 87 | * encryption from base address till size. |
| 88 | * 'x0' = physical addr, 'x1' = size |
| 89 | * ------------------------------------------ |
| 90 | */ |
| 91 | func flush_dcache_range_to_poe |
| 92 | do_dcache_maintenance_instr dc_cipae_x0 |
| 93 | endfunc flush_dcache_range_to_poe |