Skip to content

Commit 09da8fb

Browse files
crafcat7xiaoxiang781216
authored andcommitted
armv7/8 cache:CSSELR should be set before getting cache info
According to the ARMv7a/r/m and ARMv8m architecture manuals The allowed values are 0 Data or unified cache. 1 Instruction cache. "One CCSIDR is implemented for each cache that can be accessed by the processor. CSSELR selects which Cache Size ID Register is accessible, see c0, Cache Size Selection Register (CSSELR)." Signed-off-by: chenrun1 <[email protected]>
1 parent 6c1a7c4 commit 09da8fb

File tree

12 files changed

+316
-146
lines changed

12 files changed

+316
-146
lines changed

arch/arm/src/armv7-a/arm_cache.c

Lines changed: 16 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -32,16 +32,16 @@
3232
#include "l2cc.h"
3333

3434
/****************************************************************************
35-
* Private Functions
35+
* Public Functions
3636
****************************************************************************/
3737

38-
#if defined(CONFIG_ARCH_ICACHE) || defined(CONFIG_ARCH_DCACHE)
38+
#ifdef CONFIG_ARCH_ICACHE
3939

4040
/****************************************************************************
41-
* Name: up_get_cache_linesize
41+
* Name: up_get_icache_linesize
4242
*
4343
* Description:
44-
* Get cache linesize
44+
* Get icache linesize
4545
*
4646
* Input Parameters:
4747
* None
@@ -51,45 +51,18 @@
5151
*
5252
****************************************************************************/
5353

54-
static size_t up_get_cache_linesize(void)
54+
size_t up_get_icache_linesize(void)
5555
{
5656
static uint32_t clsize;
5757

5858
if (clsize == 0)
5959
{
60-
clsize = MAX(cp15_cache_linesize(), l2cc_get_linesize());
60+
clsize = MAX(cp15_icache_linesize(), l2cc_linesize());
6161
}
6262

6363
return clsize;
6464
}
6565

66-
#endif
67-
68-
/****************************************************************************
69-
* Public Functions
70-
****************************************************************************/
71-
72-
#ifdef CONFIG_ARCH_ICACHE
73-
74-
/****************************************************************************
75-
* Name: up_get_icache_linesize
76-
*
77-
* Description:
78-
* Get icache linesize
79-
*
80-
* Input Parameters:
81-
* None
82-
*
83-
* Returned Value:
84-
* Cache line size
85-
*
86-
****************************************************************************/
87-
88-
size_t up_get_icache_linesize(void)
89-
{
90-
return up_get_cache_linesize();
91-
}
92-
9366
/****************************************************************************
9467
* Name: up_invalidate_icache_all
9568
*
@@ -189,7 +162,14 @@ void up_disable_icache(void)
189162

190163
size_t up_get_dcache_linesize(void)
191164
{
192-
return up_get_cache_linesize();
165+
static uint32_t clsize;
166+
167+
if (clsize == 0)
168+
{
169+
clsize = MAX(cp15_dcache_linesize(), l2cc_linesize());
170+
}
171+
172+
return clsize;
193173
}
194174

195175
/****************************************************************************
@@ -272,7 +252,7 @@ void up_invalidate_dcache_all(void)
272252

273253
void up_clean_dcache(uintptr_t start, uintptr_t end)
274254
{
275-
if ((end - start) < cp15_cache_size())
255+
if ((end - start) < cp15_dcache_size())
276256
{
277257
cp15_clean_dcache(start, end);
278258
}
@@ -336,7 +316,7 @@ void up_clean_dcache_all(void)
336316

337317
void up_flush_dcache(uintptr_t start, uintptr_t end)
338318
{
339-
if ((end - start) < cp15_cache_size())
319+
if ((end - start) < cp15_dcache_size())
340320
{
341321
cp15_flush_dcache(start, end);
342322
}

arch/arm/src/armv7-a/arm_l2cc_pl310.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,7 @@ void arm_l2ccinitialize(void)
397397
}
398398

399399
/****************************************************************************
400-
* Name: l2cc_get_linesize
400+
* Name: l2cc_linesize
401401
*
402402
* Description:
403403
* Get L2CC-P310 L2 cache linesize
@@ -410,7 +410,7 @@ void arm_l2ccinitialize(void)
410410
*
411411
****************************************************************************/
412412

413-
uint32_t l2cc_get_linesize(void)
413+
uint32_t l2cc_linesize(void)
414414
{
415415
return PL310_CACHE_LINE_SIZE;
416416
}

arch/arm/src/armv7-a/cp15_cacheops.c

Lines changed: 65 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,19 @@ static inline uint32_t ilog2(uint32_t u)
4444
return i;
4545
}
4646

47-
static inline uint32_t cp15_cache_get_info(uint32_t *sets, uint32_t *ways)
47+
static inline uint32_t cp15_cache_get_info(uint32_t *sets, uint32_t *ways,
48+
bool icache)
4849
{
49-
uint32_t ccsidr = CP15_GET(CCSIDR);
50+
uint32_t ccsidr;
51+
uint32_t csselr;
52+
53+
csselr = CP15_GET(CSSELR);
54+
55+
csselr = (csselr & ~0x01) | (icache & 0x01);
56+
57+
CP15_SET(CSSELR, csselr);
58+
59+
ccsidr = CP15_GET(CCSIDR);
5060

5161
if (sets)
5262
{
@@ -93,7 +103,7 @@ static void cp15_dcache_op_mva(uintptr_t start, uintptr_t end, int op)
93103
{
94104
uint32_t line;
95105

96-
line = cp15_cache_get_info(NULL, NULL);
106+
line = cp15_dcache_linesize();
97107

98108
ARM_DSB();
99109

@@ -158,7 +168,7 @@ void cp15_dcache_op_level(uint32_t level, int op)
158168

159169
/* Get cache info */
160170

161-
line = cp15_cache_get_info(&sets, &ways);
171+
line = cp15_cache_get_info(&sets, &ways, false);
162172

163173
way_shift = 32 - ilog2(ways);
164174
set_shift = ilog2(line);
@@ -209,7 +219,7 @@ void cp15_invalidate_icache(uintptr_t start, uintptr_t end)
209219
{
210220
uint32_t line;
211221

212-
line = cp15_cache_get_info(NULL, NULL);
222+
line = cp15_icache_linesize();
213223
start &= ~(line - 1);
214224

215225
ARM_DSB();
@@ -259,18 +269,60 @@ void cp15_flush_dcache_all(void)
259269
cp15_dcache_op(CP15_CACHE_CLEANINVALIDATE);
260270
}
261271

262-
uint32_t cp15_cache_size(void)
272+
uint32_t cp15_icache_size(void)
263273
{
264-
uint32_t sets;
265-
uint32_t ways;
266-
uint32_t line;
274+
static uint32_t csize;
267275

268-
line = cp15_cache_get_info(&sets, &ways);
276+
if (csize == 0)
277+
{
278+
uint32_t sets;
279+
uint32_t ways;
280+
uint32_t line;
269281

270-
return sets * ways * line;
282+
line = cp15_cache_get_info(&sets, &ways, true);
283+
csize = sets * ways * line;
284+
}
285+
286+
return csize;
271287
}
272288

273-
uint32_t cp15_cache_linesize(void)
289+
uint32_t cp15_dcache_size(void)
274290
{
275-
return cp15_cache_get_info(NULL, NULL);
291+
static uint32_t csize;
292+
293+
if (csize == 0)
294+
{
295+
uint32_t sets;
296+
uint32_t ways;
297+
uint32_t line;
298+
299+
line = cp15_cache_get_info(&sets, &ways, false);
300+
csize = sets * ways * line;
301+
}
302+
303+
return csize;
304+
}
305+
306+
uint32_t cp15_icache_linesize(void)
307+
{
308+
static uint32_t clsize;
309+
310+
if (clsize == 0)
311+
{
312+
clsize = cp15_cache_get_info(NULL, NULL, true);
313+
}
314+
315+
return clsize;
316+
}
317+
318+
uint32_t cp15_dcache_linesize(void)
319+
{
320+
static uint32_t clsize;
321+
322+
if (clsize == 0)
323+
{
324+
clsize = cp15_cache_get_info(NULL, NULL, false);
325+
}
326+
327+
return clsize;
276328
}

arch/arm/src/armv7-a/cp15_cacheops.h

Lines changed: 38 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1090,11 +1090,27 @@ void cp15_flush_dcache(uintptr_t start, uintptr_t end);
10901090

10911091
void cp15_flush_dcache_all(void);
10921092

1093+
/****************************************************************************
1094+
* Name: cp15_icache_size
1095+
*
1096+
* Description:
1097+
* Get cp15 icache size in byte
1098+
*
1099+
* Input Parameters:
1100+
* None
1101+
*
1102+
* Returned Value:
1103+
* Cache size in byte
1104+
*
1105+
****************************************************************************/
1106+
1107+
uint32_t cp15_icache_size(void);
1108+
10931109
/****************************************************************************
10941110
* Name: cp15_cache_size
10951111
*
10961112
* Description:
1097-
* Get cp15 cache size in byte
1113+
* Get cp15 dcache size in byte
10981114
*
10991115
* Input Parameters:
11001116
* None
@@ -1104,23 +1120,39 @@ void cp15_flush_dcache_all(void);
11041120
*
11051121
****************************************************************************/
11061122

1107-
uint32_t cp15_cache_size(void);
1123+
uint32_t cp15_dcache_size(void);
1124+
1125+
/****************************************************************************
1126+
* Name: cp15_icache_linesize
1127+
*
1128+
* Description:
1129+
* Get cp15 icache linesize in byte
1130+
*
1131+
* Input Parameters:
1132+
* None
1133+
*
1134+
* Returned Value:
1135+
* ICache linesize in byte
1136+
*
1137+
****************************************************************************/
1138+
1139+
uint32_t cp15_icache_linesize(void);
11081140

11091141
/****************************************************************************
1110-
* Name: cp15_cache_linesize
1142+
* Name: cp15_dcache_linesize
11111143
*
11121144
* Description:
1113-
* Get cp15 cache linesize in byte
1145+
* Get cp15 dcache linesize in byte
11141146
*
11151147
* Input Parameters:
11161148
* None
11171149
*
11181150
* Returned Value:
1119-
* Cache linesize in byte
1151+
* DCache linesize in byte
11201152
*
11211153
****************************************************************************/
11221154

1123-
uint32_t cp15_cache_linesize(void);
1155+
uint32_t cp15_dcache_linesize(void);
11241156

11251157
#undef EXTERN
11261158
#ifdef __cplusplus

arch/arm/src/armv7-a/l2cc.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ void arm_l2ccinitialize(void);
7171
#endif
7272

7373
/****************************************************************************
74-
* Name: l2cc_get_linesize
74+
* Name: l2cc_linesize
7575
*
7676
* Description:
7777
* Get L2 cache linesize
@@ -84,7 +84,7 @@ void arm_l2ccinitialize(void);
8484
*
8585
****************************************************************************/
8686

87-
uint32_t l2cc_get_linesize(void);
87+
uint32_t l2cc_linesize(void);
8888

8989
/****************************************************************************
9090
* Name: l2cc_enable
@@ -245,7 +245,7 @@ void l2cc_flush(uint32_t startaddr, uint32_t endaddr);
245245
* compilation in one place.
246246
*/
247247

248-
# define l2cc_get_linesize() 0
248+
# define l2cc_linesize() 0
249249
# define l2cc_enable()
250250
# define l2cc_disable()
251251
# define l2cc_sync()

0 commit comments

Comments
 (0)