23 #ifndef LIBBSP_ARM_SHARED_CACHE_L1_H 24 #define LIBBSP_ARM_SHARED_CACHE_L1_H 34 #define ARM_CACHE_L1_CPU_DATA_ALIGNMENT 32 35 #define ARM_CACHE_L1_CPU_INSTRUCTION_ALIGNMENT 32 37 #define ARM_CACHE_L1_CSS_ID_DATA \ 38 (ARM_CP15_CACHE_CSS_ID_DATA | ARM_CP15_CACHE_CSS_LEVEL(0)) 39 #define ARM_CACHE_L1_CSS_ID_INSTRUCTION \ 40 (ARM_CP15_CACHE_CSS_ID_INSTRUCTION | ARM_CP15_CACHE_CSS_LEVEL(0)) 41 #define ARM_CACHE_L1_DATA_LINE_MASK ( ARM_CACHE_L1_CPU_DATA_ALIGNMENT - 1 ) 42 #define ARM_CACHE_L1_INSTRUCTION_LINE_MASK \ 43 ( ARM_CACHE_L1_CPU_INSTRUCTION_ALIGNMENT \ 47 static void arm_cache_l1_errata_764369_handler(
void )
50 _ARM_Data_synchronization_barrier();
62 static inline void arm_cache_l1_properties_for_level(
64 uint32_t *l1Associativity,
66 uint32_t level_and_inst_dat
71 ccsidr = arm_cp15_get_cache_size_id_for_level(level_and_inst_dat);
74 *l1LineSize = arm_ccsidr_get_line_power(ccsidr);
76 *l1Associativity = arm_ccsidr_get_associativity(ccsidr);
78 *l1NumSets = arm_ccsidr_get_num_sets(ccsidr);
90 static inline uint32_t arm_cache_l1_get_set_way_param(
91 const uint32_t log_2_line_bytes,
92 const uint32_t associativity,
93 const uint32_t cache_level_idx,
97 uint32_t way_shift = __builtin_clz( associativity - 1 );
102 << way_shift ) | ( set << log_2_line_bytes ) | ( cache_level_idx << 1 ) );
105 static inline void arm_cache_l1_flush_1_data_line(
const void *d_addr )
108 arm_cp15_data_cache_clean_and_invalidate_line( d_addr );
111 _ARM_Data_synchronization_barrier();
114 static inline void arm_cache_l1_flush_entire_data(
void )
116 uint32_t l1LineSize, l1Associativity, l1NumSets;
118 uint32_t set_way_param;
121 _ARM_Data_memory_barrier();
124 arm_cache_l1_properties_for_level( &l1LineSize,
125 &l1Associativity, &l1NumSets,
126 ARM_CACHE_L1_CSS_ID_DATA);
128 for (
w = 0;
w < l1Associativity; ++
w ) {
129 for ( s = 0; s < l1NumSets; ++s ) {
130 set_way_param = arm_cache_l1_get_set_way_param(
137 arm_cp15_data_cache_clean_line_by_set_and_way( set_way_param );
142 _ARM_Data_synchronization_barrier();
145 static inline void arm_cache_l1_invalidate_entire_data(
void )
147 uint32_t l1LineSize, l1Associativity, l1NumSets;
149 uint32_t set_way_param;
152 _ARM_Data_memory_barrier();
155 arm_cache_l1_properties_for_level( &l1LineSize,
156 &l1Associativity, &l1NumSets,
157 ARM_CACHE_L1_CSS_ID_DATA);
159 for (
w = 0;
w < l1Associativity; ++
w ) {
160 for ( s = 0; s < l1NumSets; ++s ) {
161 set_way_param = arm_cache_l1_get_set_way_param(
168 arm_cp15_data_cache_invalidate_line_by_set_and_way( set_way_param );
173 _ARM_Data_synchronization_barrier();
176 static inline void arm_cache_l1_clean_and_invalidate_entire_data(
void )
178 uint32_t l1LineSize, l1Associativity, l1NumSets;
180 uint32_t set_way_param;
183 _ARM_Data_memory_barrier();
187 arm_cache_l1_properties_for_level( &l1LineSize,
188 &l1Associativity, &l1NumSets,
189 ARM_CACHE_L1_CSS_ID_DATA);
191 for (
w = 0;
w < l1Associativity; ++
w ) {
192 for ( s = 0; s < l1NumSets; ++s ) {
193 set_way_param = arm_cache_l1_get_set_way_param(
200 arm_cp15_data_cache_clean_and_invalidate_line_by_set_and_way(
206 _ARM_Data_synchronization_barrier();
209 static inline void arm_cache_l1_flush_data_range(
214 if ( n_bytes != 0 ) {
215 uint32_t adx = (uint32_t) d_addr
216 & ~ARM_CACHE_L1_DATA_LINE_MASK;
217 const uint32_t ADDR_LAST =
218 (uint32_t)( (
size_t) d_addr + n_bytes - 1 );
220 arm_cache_l1_errata_764369_handler();
224 arm_cp15_data_cache_clean_and_invalidate_line( (
void*)adx );
227 _ARM_Data_synchronization_barrier();
232 static inline void arm_cache_l1_invalidate_1_data_line(
236 arm_cp15_data_cache_invalidate_line( d_addr );
239 _ARM_Data_synchronization_barrier();
242 static inline void arm_cache_l1_freeze_data(
void )
247 static inline void arm_cache_l1_unfreeze_data(
void )
252 static inline void arm_cache_l1_invalidate_1_instruction_line(
256 arm_cp15_instruction_cache_invalidate_line( i_addr );
259 _ARM_Data_synchronization_barrier();
262 static inline void arm_cache_l1_invalidate_data_range(
267 if ( n_bytes != 0 ) {
268 uint32_t adx = (uint32_t) d_addr
269 & ~ARM_CACHE_L1_DATA_LINE_MASK;
271 (uint32_t)( (
size_t)d_addr + n_bytes -1);
273 arm_cache_l1_errata_764369_handler();
280 arm_cp15_data_cache_invalidate_line( (
void*)adx );
283 _ARM_Data_synchronization_barrier();
287 static inline void arm_cache_l1_invalidate_instruction_range(
292 if ( n_bytes != 0 ) {
293 uint32_t adx = (uint32_t) i_addr
294 & ~ARM_CACHE_L1_INSTRUCTION_LINE_MASK;
296 (uint32_t)( (
size_t)i_addr + n_bytes -1);
298 arm_cache_l1_errata_764369_handler();
303 adx += ARM_CACHE_L1_CPU_INSTRUCTION_ALIGNMENT ) {
305 arm_cp15_instruction_cache_invalidate_line( (
void*)adx );
308 _ARM_Data_synchronization_barrier();
312 static inline void arm_cache_l1_invalidate_entire_instruction(
void )
314 uint32_t ctrl = arm_cp15_get_control();
320 arm_cp15_instruction_cache_inner_shareable_invalidate_all();
323 arm_cp15_instruction_cache_invalidate();
326 arm_cp15_instruction_cache_invalidate();
329 if ( ( ctrl & ARM_CP15_CTRL_Z ) != 0 ) {
330 #if defined(__ARM_ARCH_7A__) 331 arm_cp15_branch_predictor_inner_shareable_invalidate_all();
333 #if defined(__ARM_ARCH_6KZ__) || defined(__ARM_ARCH_7A__) 334 arm_cp15_branch_predictor_invalidate_all();
339 static inline void arm_cache_l1_freeze_instruction(
void )
344 static inline void arm_cache_l1_unfreeze_instruction(
void )
349 static inline void arm_cache_l1_disable_data(
void )
352 arm_cache_l1_flush_entire_data();
355 arm_cp15_set_control( arm_cp15_get_control() & ~ARM_CP15_CTRL_C );
358 static inline void arm_cache_l1_disable_instruction(
void )
361 _ARM_Data_synchronization_barrier();
364 arm_cache_l1_invalidate_entire_instruction();
367 arm_cp15_set_control( arm_cp15_get_control() & ~ARM_CP15_CTRL_I );
370 static inline size_t arm_cache_l1_get_data_cache_size(
void )
373 uint32_t line_size = 0;
374 uint32_t associativity = 0;
375 uint32_t num_sets = 0;
377 arm_cache_l1_properties_for_level( &line_size,
378 &associativity, &num_sets,
379 ARM_CACHE_L1_CSS_ID_DATA);
381 size = (1 << line_size) * associativity * num_sets;
386 static inline size_t arm_cache_l1_get_instruction_cache_size(
void )
389 uint32_t line_size = 0;
390 uint32_t associativity = 0;
391 uint32_t num_sets = 0;
393 arm_cache_l1_properties_for_level( &line_size,
394 &associativity, &num_sets,
395 ARM_CACHE_L1_CSS_ID_INSTRUCTION);
397 size = (1 << line_size) * associativity * num_sets;
ARM co-processor 15 (CP15) API.
unsigned w
Definition: tlb.h:226
unsigned size
Definition: tte.h:74
#define ARM_CACHE_L1_CPU_DATA_ALIGNMENT
Level 1 Cache definitions and functions.
Definition: cache-cp15.h:34