1/*
2 * Copyright (c) 2014, Google Inc. All rights reserved
3 * Copyright 2016 The Fuchsia Authors
4 *
5 * Use of this source code is governed by a MIT-style
6 * license that can be found in the LICENSE file or at
7 * https://opensource.org/licenses/MIT
8 */
9
10#include <lk/asm.h>
11#include <arch/ops.h>
12#include <arch/defines.h>
13#include <arch/arm64/cache_loop.h>
14
15.text
16
17.macro cache_range_op, cache op
18    add     x2, x0, x1                  // calculate the end address
19    bic     x3, x0, #(CACHE_LINE-1)     // align the start with a cache line
20.Lcache_range_op_loop\@:
21    \cache  \op, x3
22    add     x3, x3, #CACHE_LINE
23    cmp     x3, x2
24    blo     .Lcache_range_op_loop\@
25    dsb     sy
26.endm
27
28    /* void arch_flush_cache_range(addr_t start, size_t len); */
29FUNCTION(arch_clean_cache_range)
30    cache_range_op dc cvac         // clean cache to PoC by MVA
31    ret
32END_FUNCTION(arch_clean_cache_range)
33
34    /* void arch_flush_invalidate_cache_range(addr_t start, size_t len); */
35FUNCTION(arch_clean_invalidate_cache_range)
36    cache_range_op dc civac        // clean & invalidate dcache to PoC by MVA
37    ret
38END_FUNCTION(arch_clean_invalidate_cache_range)
39
40    /* void arch_invalidate_cache_range(addr_t start, size_t len); */
41FUNCTION(arch_invalidate_cache_range)
42    cache_range_op dc ivac         // invalidate dcache to PoC by MVA
43    ret
44END_FUNCTION(arch_invalidate_cache_range)
45
46    /* void arch_sync_cache_range(addr_t start, size_t len); */
47FUNCTION(arch_sync_cache_range)
48    cache_range_op dc cvau         // clean dcache to PoU by MVA
49    cache_range_op ic ivau         // invalidate icache to PoU by MVA
50    ret
51END_FUNCTION(arch_sync_cache_range)
52
53// Below are 3 variants of cache flushing routines by way/set for
54// an individual cpu.
55
56    // void arm64_local_invalidate_cache_all()
57FUNCTION(arm64_local_invalidate_cache_all)
58    cache_way_set_op isw, invalidate
59
60    // dump the instruction cache as well
61    ic      iallu
62    isb
63
64    ret
65END_FUNCTION(arm64_local_invalidate_cache_all)
66
67    // void arm64_local_clean_cache_all()
68FUNCTION(arm64_local_clean_cache_all)
69    cache_way_set_op csw, clean
70
71    // dump the instruction cache as well
72    ic      iallu
73    isb
74
75    ret
76END_FUNCTION(arm64_local_clean_cache_all)
77
78    // void arm64_local_clean_invalidate_cache_all()
79FUNCTION(arm64_local_clean_invalidate_cache_all)
80    cache_way_set_op cisw, clean_invalidate
81
82    // dump the instruction cache as well
83    ic      iallu
84    isb
85
86    ret
87END_FUNCTION(arm64_local_clean_invalidate_cache_all)
88
89