summaryrefslogtreecommitdiff
path: root/bsp/ultrarisc/arch/ur-cp100/cache.h
blob: 55d532f95842faf2ef95b4274d9a6d4c22956f91 (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
/*
 * Copyright (c) 2006-2025 RT-Thread Development Team
 *
 * SPDX-License-Identifier: Apache-2.0
 *
 * Change Logs:
 * Date           Author       Notes
 * 2022-11-09     RT-Thread    The first version
 */
#ifndef __CACHE_H__
#define __CACHE_H__

#include <rtdef.h>

/**
 * @brief These APIs may not be supported by a specified architecture
 * But we have to include to all the cases to be 'general purpose'
 */

rt_always_inline void rt_hw_cpu_dcache_clean_local(void *addr, int size)
{
    RT_UNUSED(addr);
    RT_UNUSED(size);
}

rt_always_inline void rt_hw_cpu_dcache_invalidate_local(void *addr, int size)
{
    RT_UNUSED(addr);
    RT_UNUSED(size);
}

rt_always_inline void rt_hw_cpu_dcache_clean_and_invalidate_local(void *addr, int size)
{
    RT_UNUSED(addr);
    RT_UNUSED(size);
}

rt_always_inline void rt_hw_cpu_dcache_clean_all_local(void)
{
}

rt_always_inline void rt_hw_cpu_dcache_invalidate_all_local(void)
{
}

rt_always_inline void rt_hw_cpu_dcache_clean_and_invalidate_all_local(void)
{
}

/*use fence.i to invalidate all icache*/
rt_always_inline void rt_hw_cpu_icache_invalidate_local(void *addr, int size)
{
    __asm__ __volatile__("fence.i" ::: "memory");
}
/*use fence.i to invalidate all icache*/
rt_always_inline void rt_hw_cpu_icache_invalidate_all_local(void)
{
    __asm__ __volatile__("fence.i" ::: "memory");
}

/**
 * @brief Multi-core
 */

#define rt_hw_cpu_dcache_clean rt_hw_cpu_dcache_clean_local
#define rt_hw_cpu_dcache_invalidate rt_hw_cpu_dcache_invalidate_local
#define rt_hw_cpu_dcache_clean_and_invalidate rt_hw_cpu_dcache_clean_and_invalidate_local

#define rt_hw_cpu_dcache_clean_all rt_hw_cpu_dcache_clean_all_local
#define rt_hw_cpu_dcache_invalidate_all rt_hw_cpu_dcache_invalidate_all_local
#define rt_hw_cpu_dcache_clean_and_invalidate_all rt_hw_cpu_dcache_clean_and_invalidate_all_local

#define rt_hw_cpu_icache_invalidate rt_hw_cpu_icache_invalidate_local
#define rt_hw_cpu_icache_invalidate_all rt_hw_cpu_icache_invalidate_all_local

#define rt_hw_icache_invalidate_all rt_hw_cpu_icache_invalidate_all

/** instruction barrier */
static inline void rt_hw_cpu_sync(void)
{
    __asm__ __volatile__("fence.i" ::: "memory");
}

/**
 * @brief local cpu icahce & dcache synchronization
 *
 * @param addr
 * @param size
 */
void rt_hw_sync_cache_local(void *addr, int size);

#endif /* __CACHE_H__ */