summaryrefslogtreecommitdiff
path: root/libcpu/aarch64/common/cache_ops.c
blob: 3bfa9f2056f4bbb91f7045bb4fbd4a45f94893c1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
/*
 * Copyright (c) 2006-2018, RT-Thread Development Team
 *
 * SPDX-License-Identifier: Apache-2.0
 *
 * Change Logs:
 * Date           Author       Notes
 * 2019-03-29 	  quanzhao 	   the first version
 */
#include <rthw.h>
#include <rtdef.h>

void __asm_invalidate_icache_all(void);
void __asm_flush_dcache_all(void);
void __asm_flush_dcache_range(rt_size_t start, rt_size_t end);
void __asm_invalidate_dcache_range(rt_size_t start, rt_size_t end);
void __asm_invalidate_icache_range(rt_size_t start, rt_size_t end);
void __asm_invalidate_dcache_all(void);
void __asm_invalidate_icache_all(void);

rt_inline rt_uint32_t rt_cpu_icache_line_size(void)
{
    return 0;
}

rt_inline rt_uint32_t rt_cpu_dcache_line_size(void)
{
    return 0;
}

void rt_hw_cpu_icache_invalidate(void *addr, rt_size_t size)
{
    __asm_invalidate_icache_range((rt_size_t)addr, (rt_size_t)addr + size);
}

void rt_hw_cpu_dcache_invalidate(void *addr, rt_size_t size)
{
    __asm_invalidate_dcache_range((rt_size_t)addr, (rt_size_t)addr + size);
}

void rt_hw_cpu_dcache_clean(void *addr, rt_size_t size)
{
    __asm_flush_dcache_range((rt_size_t)addr, (rt_size_t)addr + size);
}

void rt_hw_cpu_dcache_clean_and_invalidate(void *addr, rt_size_t size)
{
    __asm_flush_dcache_range((rt_size_t)addr, (rt_size_t)addr + size);
}

void rt_hw_cpu_icache_ops(int ops, void *addr, int size)
{
    if (ops == RT_HW_CACHE_INVALIDATE)
    {
        rt_hw_cpu_icache_invalidate(addr, size);
    }
}

void rt_hw_cpu_dcache_ops(int ops, void *addr, int size)
{
    if (ops == RT_HW_CACHE_FLUSH)
    {
        rt_hw_cpu_dcache_clean(addr, size);
    }
    else if (ops == RT_HW_CACHE_INVALIDATE)
    {
        rt_hw_cpu_dcache_invalidate(addr, size);
    }
}

rt_base_t rt_hw_cpu_icache_status(void)
{
    return 0;
}

rt_base_t rt_hw_cpu_dcache_status(void)
{
    return 0;
}

#ifdef RT_USING_LWP
#define ICACHE (1<<0)
#define DCACHE (1<<1)
#define BCACHE (ICACHE|DCACHE)

int sys_cacheflush(void *addr, int size, int cache)
{
    if ((size_t)addr < KERNEL_VADDR_START && (size_t)addr + size <= KERNEL_VADDR_START)
    {
        if ((cache & DCACHE) != 0)
        {
            rt_hw_cpu_dcache_clean_and_invalidate(addr, size);
        }
        if ((cache & ICACHE) != 0)
        {
            rt_hw_cpu_icache_invalidate(addr, size);
        }
        return 0;
    }
    return -1;
}
#endif