Skip to content

Commit 9c2bc0e

Browse files
crafcat7xiaoxiang781216
authored andcommitted
armv7m/v8m:Restore the CSSELR state before setting.
Signed-off-by: chenrun1 <[email protected]>
1 parent 823c3b3 commit 9c2bc0e

File tree

4 files changed

+30
-16
lines changed

4 files changed

+30
-16
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,7 @@ static inline uint32_t cp15_cache_get_info(uint32_t *sets, uint32_t *ways,
5252

5353
csselr = CP15_GET(CSSELR);
5454

55-
csselr = (csselr & ~0x01) | (icache & 0x01);
56-
57-
CP15_SET(CSSELR, csselr);
55+
CP15_SET(CSSELR, (csselr & ~0x01) | (icache & 0x01));
5856

5957
ccsidr = CP15_GET(CCSIDR);
6058

@@ -68,6 +66,8 @@ static inline uint32_t cp15_cache_get_info(uint32_t *sets, uint32_t *ways,
6866
*ways = ((ccsidr >> 3) & 0x3ff) + 1;
6967
}
7068

69+
CP15_SET(CSSELR, csselr); /* restore csselr */
70+
7171
return (1 << ((ccsidr & 0x7) + 2)) * 4;
7272
}
7373

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

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -129,17 +129,20 @@ static size_t up_get_cache_linesize(bool icache)
129129

130130
if (icache)
131131
{
132-
csselr = (csselr & ~NVIC_CSSELR_IND) | NVIC_CSSELR_IND_ICACHE;
132+
putreg32((csselr & ~NVIC_CSSELR_IND) |
133+
NVIC_CSSELR_IND_ICACHE, NVIC_CSSELR);
133134
}
134135
else
135136
{
136-
csselr = (csselr & ~NVIC_CSSELR_IND) | NVIC_CSSELR_IND_DCACHE;
137+
putreg32((csselr & ~NVIC_CSSELR_IND) |
138+
NVIC_CSSELR_IND_DCACHE, NVIC_CSSELR);
137139
}
138140

139-
putreg32(csselr, NVIC_CSSELR);
140141
ccsidr = getreg32(NVIC_CCSIDR);
141142
sshift = CCSIDR_LSSHIFT(ccsidr) + 4; /* log2(cache-line-size-in-bytes) */
142143

144+
putreg32(csselr, NVIC_CSSELR); /* restore csselr */
145+
143146
return 1 << sshift;
144147
}
145148

@@ -170,11 +173,13 @@ static size_t up_get_cache_size(bool icache)
170173

171174
if (icache)
172175
{
173-
csselr = (csselr & ~NVIC_CSSELR_IND) | NVIC_CSSELR_IND_ICACHE;
176+
putreg32((csselr & ~NVIC_CSSELR_IND) |
177+
NVIC_CSSELR_IND_ICACHE, NVIC_CSSELR);
174178
}
175179
else
176180
{
177-
csselr = (csselr & ~NVIC_CSSELR_IND) | NVIC_CSSELR_IND_DCACHE;
181+
putreg32((csselr & ~NVIC_CSSELR_IND) |
182+
NVIC_CSSELR_IND_DCACHE, NVIC_CSSELR);
178183
}
179184

180185
ccsidr = getreg32(NVIC_CCSIDR);
@@ -183,6 +188,8 @@ static size_t up_get_cache_size(bool icache)
183188
sshift = CCSIDR_LSSHIFT(ccsidr) + 4; /* log2(cache-line-size-in-bytes) */
184189
line = 1 << sshift;
185190

191+
putreg32(csselr, NVIC_CSSELR); /* restore csselr */
192+
186193
return sets * ways * line;
187194
}
188195
#endif

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,7 @@ static inline uint32_t cp15_cache_get_info(uint32_t *sets, uint32_t *ways,
5252

5353
csselr = CP15_GET(CSSELR);
5454

55-
csselr = (csselr & ~0x01) | (icache & 0x01);
56-
57-
CP15_SET(CSSELR, csselr);
55+
CP15_SET(CSSELR, (csselr & ~0x01) | (icache & 0x01));
5856

5957
ccsidr = CP15_GET(CCSIDR);
6058

@@ -68,6 +66,8 @@ static inline uint32_t cp15_cache_get_info(uint32_t *sets, uint32_t *ways,
6866
*ways = ((ccsidr >> 3) & 0x3ff) + 1;
6967
}
7068

69+
CP15_SET(CSSELR, csselr); /* restore csselr */
70+
7171
return (1 << ((ccsidr & 0x7) + 2)) * 4;
7272
}
7373

arch/arm/src/armv8-m/arm_cache.c

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -129,17 +129,20 @@ static size_t up_get_cache_linesize(bool icache)
129129

130130
if (icache)
131131
{
132-
csselr = (csselr & ~NVIC_CSSELR_IND) | NVIC_CSSELR_IND_ICACHE;
132+
putreg32((csselr & ~NVIC_CSSELR_IND) |
133+
NVIC_CSSELR_IND_ICACHE, NVIC_CSSELR);
133134
}
134135
else
135136
{
136-
csselr = (csselr & ~NVIC_CSSELR_IND) | NVIC_CSSELR_IND_DCACHE;
137+
putreg32((csselr & ~NVIC_CSSELR_IND) |
138+
NVIC_CSSELR_IND_DCACHE, NVIC_CSSELR);
137139
}
138140

139-
putreg32(csselr, NVIC_CSSELR);
140141
ccsidr = getreg32(NVIC_CCSIDR);
141142
sshift = CCSIDR_LSSHIFT(ccsidr) + 4; /* log2(cache-line-size-in-bytes) */
142143

144+
putreg32(csselr, NVIC_CSSELR); /* restore csselr */
145+
143146
return 1 << sshift;
144147
}
145148

@@ -170,11 +173,13 @@ static size_t up_get_cache_size(bool icache)
170173

171174
if (icache)
172175
{
173-
csselr = (csselr & ~NVIC_CSSELR_IND) | NVIC_CSSELR_IND_ICACHE;
176+
putreg32((csselr & ~NVIC_CSSELR_IND) |
177+
NVIC_CSSELR_IND_ICACHE, NVIC_CSSELR);
174178
}
175179
else
176180
{
177-
csselr = (csselr & ~NVIC_CSSELR_IND) | NVIC_CSSELR_IND_DCACHE;
181+
putreg32((csselr & ~NVIC_CSSELR_IND) |
182+
NVIC_CSSELR_IND_DCACHE, NVIC_CSSELR);
178183
}
179184

180185
ccsidr = getreg32(NVIC_CCSIDR);
@@ -183,6 +188,8 @@ static size_t up_get_cache_size(bool icache)
183188
sshift = CCSIDR_LSSHIFT(ccsidr) + 4; /* log2(cache-line-size-in-bytes) */
184189
line = 1 << sshift;
185190

191+
putreg32(csselr, NVIC_CSSELR); /* restore csselr */
192+
186193
return sets * ways * line;
187194
}
188195
#endif

0 commit comments

Comments
 (0)