1/* 2 * Copyright 2021 The Hafnium Authors. 3 * 4 * Use of this source code is governed by a BSD-style 5 * license that can be found in the LICENSE file or at 6 * https://opensource.org/licenses/BSD-3-Clause. 7 */ 8 9/** 10 * Macros and functions imported from TF-A project: 11 * https://git.trustedfirmware.org/TF-A/trusted-firmware-a.git/tree/include/arch/aarch64/asm_macros.S?h=v2.4 12 * https://git.trustedfirmware.org/TF-A/trusted-firmware-a.git/tree/lib/aarch64/cache_helpers.S?h=v2.4 13 */ 14 15.macro dcache_line_size reg, tmp 16 mrs \tmp, ctr_el0 17 ubfx \tmp, \tmp, #16, #4 18 mov \reg, #4 19 lsl \reg, \reg, \tmp 20.endm 21 22/* 23 * This macro can be used for implementing various data cache operations `op` 24 */ 25.macro do_dcache_maintenance_by_mva op 26 /* Exit early if size is zero */ 27 cbz x1, exit_loop_\op 28 dcache_line_size x2, x3 29 add x1, x0, x1 30 sub x3, x2, #1 31 bic x0, x0, x3 32loop_\op: 33 dc \op, x0 34 add x0, x0, x2 35 cmp x0, x1 36 b.lo loop_\op 37 dsb sy 38exit_loop_\op: 39 ret 40.endm 41 42/** 43 * ------------------------------------------ 44 * Invalidate from base address till 45 * size. 'x0' = addr, 'x1' = size 46 * ------------------------------------------ 47 */ 48.globl arch_cache_data_invalidate_range 49arch_cache_data_invalidate_range: 50 do_dcache_maintenance_by_mva ivac 51 52/** 53 * ------------------------------------------ 54 * Clean from base address till size. 55 * 'x0' = addr, 'x1' = size 56 * ------------------------------------------ 57 */ 58.globl arch_cache_data_clean_range 59arch_cache_data_clean_range: 60 do_dcache_maintenance_by_mva cvac 61