Skip to content

Commit 49ef1d0

Browse files
ahmed-haouestarek-bochkati
authored andcommitted
target: cortex-m: fix support for arv8m caches
Align to upstream code that always flushes the caches if they are present, without checking if the caches are enabled. Signed-off-by: HAOUES Ahmed <ahmed.haoues@st.com> Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com> Reviewed-by: Antonio Maria BORNEO <antonio.borneo@foss.st.com>
1 parent 541592d commit 49ef1d0

File tree

3 files changed

+15
-30
lines changed

3 files changed

+15
-30
lines changed

src/target/armv7m_cache.c

Lines changed: 10 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@ static int armv7m_identify_cache_internal(struct target *target)
150150

151151
// separate d or unified d/i cache at this level ?
152152
if (ctype & (CLIDR_CTYPE_UNIFIED_CACHE | CLIDR_CTYPE_D_CACHE)) {
153+
cache->has_d_u_cache = true;
153154
cache->arch[cl].d_u_size = decode_ccsidr(d_u_ccsidr[cl]);
154155

155156
LOG_TARGET_DEBUG(target,
@@ -167,6 +168,7 @@ static int armv7m_identify_cache_internal(struct target *target)
167168
}
168169

169170
if (ctype & CLIDR_CTYPE_I_CACHE) {
171+
cache->has_i_cache = true;
170172
cache->arch[cl].i_size = decode_ccsidr(i_ccsidr[cl]);
171173

172174
LOG_TARGET_DEBUG(target,
@@ -306,7 +308,6 @@ static int armv7m_cache_helper(struct target *target, const char *helper,
306308

307309
int armv7m_d_cache_flush(struct target *target, uint32_t address,
308310
unsigned int length)
309-
310311
{
311312
struct armv7m_common *armv7m = target_to_armv7m(target);
312313
struct armv7m_cache_common *cache = &armv7m->armv7m_cache;
@@ -315,23 +316,17 @@ int armv7m_d_cache_flush(struct target *target, uint32_t address,
315316
if (retval != ERROR_NOT_IMPLEMENTED)
316317
return retval;
317318

318-
if (!cache->info_valid)
319-
return ERROR_OK;
320-
321-
if (target->state != TARGET_HALTED) {
322-
LOG_TARGET_ERROR(target, "not halted");
323-
return ERROR_TARGET_NOT_HALTED;
324-
}
325-
326-
if (!armv7m->armv7m_cache.d_u_cache_enabled)
319+
if (!cache->info_valid || !cache->has_d_u_cache)
327320
return ERROR_OK;
328321

329322
uint32_t line_len = cache->d_min_line_len;
330323
uint32_t addr_line = ALIGN_DOWN(address, line_len);
331324
uint32_t addr_end = address + length;
332325

333326
while (addr_line < addr_end) {
334-
mem_ap_write_u32(armv7m->debug_ap, DCCIMVAC, addr_line);
327+
retval = mem_ap_write_u32(armv7m->debug_ap, DCCIMVAC, addr_line);
328+
if (retval != ERROR_OK)
329+
return retval;
335330
addr_line += line_len;
336331
keep_alive();
337332
}
@@ -349,23 +344,17 @@ int armv7m_i_cache_inval(struct target *target, uint32_t address,
349344
if (retval != ERROR_NOT_IMPLEMENTED)
350345
return retval;
351346

352-
if (!cache->info_valid)
353-
return ERROR_OK;
354-
355-
if (target->state != TARGET_HALTED) {
356-
LOG_TARGET_ERROR(target, "not halted");
357-
return ERROR_TARGET_NOT_HALTED;
358-
}
359-
360-
if (!armv7m->armv7m_cache.i_cache_enabled)
347+
if (!cache->info_valid || !cache->has_i_cache)
361348
return ERROR_OK;
362349

363350
uint32_t line_len = cache->i_min_line_len;
364351
uint32_t addr_line = ALIGN_DOWN(address, line_len);
365352
uint32_t addr_end = address + length;
366353

367354
while (addr_line < addr_end) {
368-
mem_ap_write_u32(armv7m->debug_ap, ICIMVAU, addr_line);
355+
retval = mem_ap_write_u32(armv7m->debug_ap, ICIMVAU, addr_line);
356+
if (retval != ERROR_OK)
357+
return retval;
369358
addr_line += line_len;
370359
keep_alive();
371360
}

src/target/armv7m_cache.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,12 @@ struct armv7m_arch_cache {
3939
struct armv7m_cache_common {
4040
bool info_valid;
4141
bool defer_identification;
42+
bool has_i_cache;
43+
bool has_d_u_cache;
4244
unsigned int loc; // level of coherency
4345
uint32_t d_min_line_len; // minimum d-cache line_len
4446
uint32_t i_min_line_len; // minimum i-cache line_len
4547
struct armv7m_arch_cache arch[6]; // cache info, L1 - L7
46-
bool i_cache_enabled;
47-
bool d_u_cache_enabled;
4848
};
4949

5050
int armv7m_identify_cache(struct target *target);

src/target/cortex_m.c

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -895,14 +895,10 @@ static int cortex_m_debug_entry(struct target *target)
895895
secure_state ? "Secure" : "Non-Secure",
896896
target_state_name(target));
897897

898-
if (armv7m->armv7m_cache.info_valid) {
899-
armv7m->armv7m_cache.d_u_cache_enabled = ccr & CCR_DC_MASK;
900-
armv7m->armv7m_cache.i_cache_enabled = ccr & CCR_IC_MASK;
901-
898+
if (armv7m->armv7m_cache.info_valid)
902899
LOG_TARGET_DEBUG(target, "D-Cache %s, I-Cache %s",
903-
armv7m->armv7m_cache.d_u_cache_enabled ? "enabled" : "disabled",
904-
armv7m->armv7m_cache.i_cache_enabled ? "enabled" : "disabled");
905-
}
900+
(ccr & CCR_DC_MASK) ? "enabled" : "disabled",
901+
(ccr & CCR_IC_MASK) ? "enabled" : "disabled");
906902

907903
if (armv7m->post_debug_entry) {
908904
retval = armv7m->post_debug_entry(target);

0 commit comments

Comments
 (0)