13
13
#include <zephyr/device.h>
14
14
#include <zephyr/init.h>
15
15
#include <zephyr/irq.h>
16
+ #include <zephyr/cache.h>
16
17
17
18
#include <bflb_soc.h>
18
19
#include <glb_reg.h>
@@ -107,76 +108,6 @@ void system_BOD_init(void)
107
108
sys_write32 (tmp , HBN_BASE + HBN_BOR_CFG_OFFSET );
108
109
}
109
110
110
- static void clean_dcache (void )
111
- {
112
- __asm__ volatile (
113
- "fence\n"
114
- /* th.dcache.call*/
115
- ".insn 0x10000B\n"
116
- "fence\n"
117
- );
118
- }
119
-
120
- static void clean_icache (void )
121
- {
122
- __asm__ volatile (
123
- "fence\n"
124
- "fence.i\n"
125
- /* th.icache.iall */
126
- ".insn 0x100000B\n"
127
- "fence\n"
128
- "fence.i\n"
129
- );
130
- }
131
-
132
- static void enable_icache (void )
133
- {
134
- uint32_t tmp ;
135
-
136
- __asm__ volatile (
137
- "fence\n"
138
- "fence.i\n"
139
- /* th.icache.iall */
140
- ".insn 0x100000B\n"
141
- );
142
- __asm__ volatile (
143
- "csrr %0, 0x7C1"
144
- : "=r" (tmp ));
145
- tmp |= (1 << 0 );
146
- __asm__ volatile (
147
- "csrw 0x7C1, %0"
148
- :
149
- : "r" (tmp ));
150
- __asm__ volatile (
151
- "fence\n"
152
- "fence.i\n"
153
- );
154
- }
155
-
156
- static void enable_dcache (void )
157
- {
158
- uint32_t tmp ;
159
-
160
- __asm__ volatile (
161
- "fence\n"
162
- "fence.i\n"
163
- /* th.dcache.iall */
164
- ".insn 0x20000B\n"
165
- );
166
- __asm__ volatile (
167
- "csrr %0, 0x7C1"
168
- : "=r" (tmp ));
169
- tmp |= (1 << 1 ) | (1 << 2 ) | (1 << 3 ) | (1 << 4 );
170
- __asm__ volatile (
171
- "csrw 0x7C1, %0"
172
- :
173
- : "r" (tmp ));
174
- __asm__ volatile (
175
- "fence\n"
176
- "fence.i\n"
177
- );
178
- }
179
-
180
111
static void enable_branchpred (bool yes )
181
112
{
182
113
uint32_t tmp ;
@@ -249,6 +180,17 @@ static void disable_interrupt_autostacking(void)
249
180
: "r" (tmp ));
250
181
}
251
182
183
+ void arch_cache_init (void )
184
+ {
185
+ enable_thead_isa_ext ();
186
+ set_thead_enforce_aligned (false);
187
+ sys_cache_data_enable ();
188
+ enable_branchpred (true);
189
+ sys_cache_instr_enable ();
190
+ disable_interrupt_autostacking ();
191
+ sys_cache_data_flush_and_invd_all ();
192
+ sys_cache_instr_invd_all ();
193
+ }
252
194
253
195
void soc_early_init_hook (void )
254
196
{
@@ -263,18 +205,6 @@ void soc_early_init_hook(void)
263
205
sys_write32 ((1 << 5 ), PDS_BASE + PDS_USB_CTL_OFFSET );
264
206
sys_write32 (0 , PDS_BASE + PDS_USB_PHY_CTRL_OFFSET );
265
207
266
- enable_thead_isa_ext ();
267
- set_thead_enforce_aligned (false);
268
- enable_dcache ();
269
- /* branch prediction can cause major slowdowns (250ms -> 2 seconds)
270
- * in some applications
271
- */
272
- enable_branchpred (true);
273
- enable_icache ();
274
- disable_interrupt_autostacking ();
275
- clean_dcache ();
276
- clean_icache ();
277
-
278
208
/* reset uart signals */
279
209
sys_write32 (0xffffffffU , GLB_BASE + GLB_UART_CFG1_OFFSET );
280
210
sys_write32 (0x0000ffffU , GLB_BASE + GLB_UART_CFG2_OFFSET );
0 commit comments