8
8
#define ZEPHYR_INCLUDE_CACHE_H_
9
9
10
10
#include <kernel.h>
11
+ #include <kernel_structs.h>
11
12
12
13
#ifdef __cplusplus
13
14
extern "C" {
@@ -22,149 +23,89 @@ extern "C" {
22
23
* INVD means invalidate and will mark cache lines as not valid. A future
23
24
* access to the associated address is guaranteed to generate a memory fetch.
24
25
*/
26
+
25
27
#define K_CACHE_WB BIT(0)
26
28
#define K_CACHE_INVD BIT(1)
27
29
#define K_CACHE_WB_INVD (K_CACHE_WB | K_CACHE_INVD)
28
30
29
- /**
30
- *
31
- * @brief Enable d-cache
32
- *
33
- * Enable the d-cache.
34
- *
35
- * @return N/A
36
- */
37
- void arch_dcache_enable (void );
31
+ #if defined(CONFIG_HAS_EXTERNAL_CACHE )
38
32
39
- /**
40
- *
41
- * @brief Disable d-cache
42
- *
43
- * Disable the d-cache.
44
- *
45
- * @return N/A
46
- */
47
- void arch_dcache_disable (void );
33
+ /* Driver interface mirrored in include/drivers/cache.h */
48
34
49
- /**
50
- *
51
- * @brief Enable i-cache
52
- *
53
- * Enable the i-cache.
54
- *
55
- * @return N/A
56
- */
57
- void arch_icache_enable (void );
35
+ /* Enable d-cache */
36
+ extern void dcache_enable (void );
58
37
59
- /**
60
- *
61
- * @brief Disable i-cache
62
- *
63
- * Disable the i-cache.
64
- *
65
- * @return N/A
66
- */
67
- void arch_icache_disable (void );
38
+ /* Disable d-cache */
39
+ extern void dcache_disable (void );
68
40
69
- /**
70
- *
71
- * @brief Write-back / Invalidate / Write-back + Invalidate all d-cache
72
- *
73
- * Write-back, Invalidate or Write-back + Invalidate the whole d-cache.
74
- *
75
- * @param op Operation to perform (one of the K_CACHE_* operations)
76
- *
77
- * @retval 0 On success
78
- * @retval -ENOTSUP If the operation is not supported
79
- */
80
- int arch_dcache_all (int op );
41
+ /* Enable i-cache */
42
+ extern void icache_enable (void );
81
43
82
- /**
83
- *
84
- * @brief Write-back / Invalidate / Write-back + Invalidate d-cache lines
85
- *
86
- * No alignment is required for either addr or size, but since
87
- * arch_dcache_range() iterates on the d-cache lines, a d-cache line alignment
88
- * for both is optimal.
89
- *
90
- * The d-cache line size is specified either via the CONFIG_DCACHE_LINE_SIZE
91
- * kconfig option or it is detected at runtime.
92
- *
93
- * @param addr The pointer to start the multi-line operation
94
- * @param size The number of bytes that are to be acted on
95
- * @param op Operation to perform (one of the K_CACHE_* operations)
96
- *
97
- * @retval 0 On success
98
- * @retval -ENOTSUP If the operation is not supported
99
- */
100
- int arch_dcache_range (void * addr , size_t size , int op );
44
+ /* Disable i-cache */
45
+ extern void icache_disable (void );
101
46
102
- /**
103
- *
104
- * @brief Write-back / Invalidate / Write-back + Invalidate all i-cache
105
- *
106
- * Write-back, Invalidate or Write-back + Invalidate the whole i-cache.
107
- *
108
- * @param op Operation to perform (one of the K_CACHE_* operations)
109
- *
110
- * @retval 0 On success
111
- * @retval -ENOTSUP If the operation is not supported
112
- */
113
- int arch_icache_all (int op );
47
+ /* Write-back / Invalidate / Write-back + Invalidate all d-cache */
48
+ extern int dcache_all (int op );
114
49
115
- /**
116
- *
117
- * @brief Write-back / Invalidate / Write-back + Invalidate i-cache lines
118
- *
119
- * No alignment is required for either addr or size, but since
120
- * arch_icache_range() iterates on the i-cache lines, an i-cache line alignment
121
- * for both is optimal.
122
- *
123
- * The i-cache line size is specified either via the CONFIG_ICACHE_LINE_SIZE
124
- * kconfig option or it is detected at runtime.
125
- *
126
- * @param addr The pointer to start the multi-line operation
127
- * @param size The number of bytes that are to be acted on
128
- * @param op Operation to perform (one of the K_CACHE_* operations)
129
- *
130
- * @retval 0 On success
131
- * @retval -ENOTSUP If the operation is not supported
132
- */
133
- int arch_icache_range (void * addr , size_t size , int op );
50
+ /* Write-back / Invalidate / Write-back + Invalidate d-cache lines */
51
+ extern int dcache_range (void * addr , size_t size , int op );
52
+
53
+ /* Write-back / Invalidate / Write-back + Invalidate all i-cache */
54
+ extern int icache_all (int op );
55
+
56
+ /* Write-back / Invalidate / Write-back + Invalidate i-cache lines */
57
+ extern int icache_range (void * addr , size_t size , int op );
58
+
59
+ #else
60
+
61
+ /* Hooks into arch code */
62
+
63
+ #define dcache_enable arch_dcache_enable
64
+ #define dcache_disable arch_dcache_disable
65
+ #define icache_enable arch_icache_enable
66
+ #define icache_disable arch_icache_disable
67
+ #define dcache_all (op ) arch_dcache_all(op)
68
+ #define dcache_range (addr , size , op ) arch_dcache_range(addr, size, op)
69
+ #define icache_all (op ) arch_icache_all(op)
70
+ #define icache_range (addr , size , op ) arch_icache_range(addr, size, op)
71
+ #define dcache_line_size_get arch_dcache_line_size_get
72
+ #define icache_line_size_get arch_icache_line_size_get
73
+
74
+ #endif
134
75
135
76
__syscall int sys_dcache_all (int op );
136
77
static inline int z_impl_sys_dcache_all (int op )
137
78
{
138
- if ( IS_ENABLED ( CONFIG_CACHE_MANAGEMENT )) {
139
- return arch_dcache_all (op );
140
- }
79
+ # if defined( CONFIG_CACHE_MANAGEMENT )
80
+ return dcache_all (op );
81
+ #endif
141
82
return - ENOTSUP ;
142
83
}
143
84
144
85
__syscall int sys_dcache_range (void * addr , size_t size , int op );
145
86
static inline int z_impl_sys_dcache_range (void * addr , size_t size , int op )
146
87
{
147
- if ( IS_ENABLED ( CONFIG_CACHE_MANAGEMENT )) {
148
- return arch_dcache_range (addr , size , op );
149
- }
88
+ # if defined( CONFIG_CACHE_MANAGEMENT )
89
+ return dcache_range (addr , size , op );
90
+ #endif
150
91
return - ENOTSUP ;
151
92
}
152
93
153
94
__syscall int sys_icache_all (int op );
154
95
static inline int z_impl_sys_icache_all (int op )
155
96
{
156
- if ( IS_ENABLED ( CONFIG_CACHE_MANAGEMENT )) {
157
- return arch_icache_all (op );
158
- }
97
+ # if defined( CONFIG_CACHE_MANAGEMENT )
98
+ return icache_all (op );
99
+ #endif
159
100
return - ENOTSUP ;
160
101
}
161
102
162
103
__syscall int sys_icache_range (void * addr , size_t size , int op );
163
104
static inline int z_impl_sys_icache_range (void * addr , size_t size , int op )
164
105
{
165
- if ( IS_ENABLED ( CONFIG_CACHE_MANAGEMENT )) {
166
- return arch_icache_range (addr , size , op );
167
- }
106
+ # if defined( CONFIG_CACHE_MANAGEMENT )
107
+ return icache_range (addr , size , op );
108
+ #endif
168
109
return - ENOTSUP ;
169
110
}
170
111
@@ -188,7 +129,7 @@ static inline void sys_cache_flush(void *addr, size_t size)
188
129
static inline size_t sys_dcache_line_size_get (void )
189
130
{
190
131
#ifdef CONFIG_DCACHE_LINE_SIZE_DETECT
191
- return arch_dcache_line_size_get ();
132
+ return dcache_line_size_get ();
192
133
#elif (CONFIG_DCACHE_LINE_SIZE != 0 )
193
134
return CONFIG_DCACHE_LINE_SIZE ;
194
135
#else
@@ -207,7 +148,7 @@ static inline size_t sys_dcache_line_size_get(void)
207
148
static inline size_t sys_icache_line_size_get (void )
208
149
{
209
150
#ifdef CONFIG_ICACHE_LINE_SIZE_DETECT
210
- return arch_icache_line_size_get ();
151
+ return icache_line_size_get ();
211
152
#elif (CONFIG_ICACHE_LINE_SIZE != 0 )
212
153
return CONFIG_ICACHE_LINE_SIZE ;
213
154
#else
0 commit comments