1 // SPDX-License-Identifier: GPL-2.0-or-later
3 /***************************************************************************
4 * Copyright (C) 2015 by Oleksij Rempel *
5 * linux@rempel-privat.de *
6 ***************************************************************************/
12 #include "jtag/interface.h"
15 #include "armv7a_cache.h"
16 #include <helper/time_support.h>
17 #include "arm_opcodes.h"
20 static int armv7a_l1_d_cache_sanity_check(struct target
*target
)
22 struct armv7a_common
*armv7a
= target_to_armv7a(target
);
24 if (target
->state
!= TARGET_HALTED
) {
25 LOG_TARGET_ERROR(target
, "not halted");
26 return ERROR_TARGET_NOT_HALTED
;
29 /* check that cache data is on at target halt */
30 if (!armv7a
->armv7a_mmu
.armv7a_cache
.d_u_cache_enabled
) {
31 LOG_DEBUG("data cache is not enabled");
32 return ERROR_TARGET_INVALID
;
38 static int armv7a_l1_i_cache_sanity_check(struct target
*target
)
40 struct armv7a_common
*armv7a
= target_to_armv7a(target
);
42 if (target
->state
!= TARGET_HALTED
) {
43 LOG_TARGET_ERROR(target
, "not halted");
44 return ERROR_TARGET_NOT_HALTED
;
47 /* check that cache data is on at target halt */
48 if (!armv7a
->armv7a_mmu
.armv7a_cache
.i_cache_enabled
) {
49 LOG_DEBUG("instruction cache is not enabled");
50 return ERROR_TARGET_INVALID
;
56 static int armv7a_l1_d_cache_flush_level(struct arm_dpm
*dpm
, struct armv7a_cachesize
*size
, int cl
)
58 int retval
= ERROR_OK
;
59 int32_t c_way
, c_index
= size
->index
;
61 LOG_DEBUG("cl %" PRId32
, cl
);
66 uint32_t value
= (c_index
<< size
->index_shift
)
67 | (c_way
<< size
->way_shift
) | (cl
<< 1);
69 * DCCISW - Clean and invalidate data cache
72 retval
= dpm
->instr_write_data_r0(dpm
,
73 ARMV4_5_MCR(15, 0, 0, 7, 14, 2),
75 if (retval
!= ERROR_OK
)
80 } while (c_index
>= 0);
87 static int armv7a_l1_d_cache_clean_inval_all(struct target
*target
)
89 struct armv7a_common
*armv7a
= target_to_armv7a(target
);
90 struct armv7a_cache_common
*cache
= &(armv7a
->armv7a_mmu
.armv7a_cache
);
91 struct arm_dpm
*dpm
= armv7a
->arm
.dpm
;
95 retval
= armv7a_l1_d_cache_sanity_check(target
);
96 if (retval
!= ERROR_OK
)
99 retval
= dpm
->prepare(dpm
);
100 if (retval
!= ERROR_OK
)
103 for (cl
= 0; cl
< cache
->loc
; cl
++) {
104 /* skip i-only caches */
105 if (cache
->arch
[cl
].ctype
< CACHE_LEVEL_HAS_D_CACHE
)
108 armv7a_l1_d_cache_flush_level(dpm
, &cache
->arch
[cl
].d_u_size
, cl
);
111 retval
= dpm
->finish(dpm
);
115 LOG_ERROR("clean invalidate failed");
121 int armv7a_cache_flush_all_data(struct target
*target
)
123 int retval
= ERROR_FAIL
;
126 struct target_list
*head
;
127 foreach_smp_target(head
, target
->smp_targets
) {
128 struct target
*curr
= head
->target
;
129 if (curr
->state
== TARGET_HALTED
) {
130 int retval1
= armv7a_l1_d_cache_clean_inval_all(curr
);
131 if (retval1
!= ERROR_OK
)
136 retval
= armv7a_l1_d_cache_clean_inval_all(target
);
138 if (retval
!= ERROR_OK
)
141 /* do outer cache flushing after inner caches have been flushed */
142 return arm7a_l2x_flush_all_data(target
);
146 int armv7a_l1_d_cache_inval_virt(struct target
*target
, uint32_t virt
,
149 struct armv7a_common
*armv7a
= target_to_armv7a(target
);
150 struct arm_dpm
*dpm
= armv7a
->arm
.dpm
;
151 struct armv7a_cache_common
*armv7a_cache
= &armv7a
->armv7a_mmu
.armv7a_cache
;
152 uint32_t linelen
= armv7a_cache
->dminline
;
153 uint32_t va_line
, va_end
;
156 retval
= armv7a_l1_d_cache_sanity_check(target
);
157 if (retval
!= ERROR_OK
)
160 retval
= dpm
->prepare(dpm
);
161 if (retval
!= ERROR_OK
)
164 va_line
= virt
& (-linelen
);
165 va_end
= virt
+ size
;
167 /* handle unaligned start */
168 if (virt
!= va_line
) {
170 retval
= dpm
->instr_write_data_r0(dpm
,
171 ARMV4_5_MCR(15, 0, 0, 7, 14, 1), va_line
);
172 if (retval
!= ERROR_OK
)
177 /* handle unaligned end */
178 if ((va_end
& (linelen
-1)) != 0) {
179 va_end
&= (-linelen
);
181 retval
= dpm
->instr_write_data_r0(dpm
,
182 ARMV4_5_MCR(15, 0, 0, 7, 14, 1), va_end
);
183 if (retval
!= ERROR_OK
)
187 while (va_line
< va_end
) {
188 if ((i
++ & 0x3f) == 0)
190 /* DCIMVAC - Invalidate data cache line by VA to PoC. */
191 retval
= dpm
->instr_write_data_r0(dpm
,
192 ARMV4_5_MCR(15, 0, 0, 7, 6, 1), va_line
);
193 if (retval
!= ERROR_OK
)
203 LOG_ERROR("d-cache invalidate failed");
210 int armv7a_l1_d_cache_clean_virt(struct target
*target
, uint32_t virt
,
213 struct armv7a_common
*armv7a
= target_to_armv7a(target
);
214 struct arm_dpm
*dpm
= armv7a
->arm
.dpm
;
215 struct armv7a_cache_common
*armv7a_cache
= &armv7a
->armv7a_mmu
.armv7a_cache
;
216 uint32_t linelen
= armv7a_cache
->dminline
;
217 uint32_t va_line
, va_end
;
220 retval
= armv7a_l1_d_cache_sanity_check(target
);
221 if (retval
!= ERROR_OK
)
224 retval
= dpm
->prepare(dpm
);
225 if (retval
!= ERROR_OK
)
228 va_line
= virt
& (-linelen
);
229 va_end
= virt
+ size
;
231 while (va_line
< va_end
) {
232 if ((i
++ & 0x3f) == 0)
234 /* DCCMVAC - Data Cache Clean by MVA to PoC */
235 retval
= dpm
->instr_write_data_r0(dpm
,
236 ARMV4_5_MCR(15, 0, 0, 7, 10, 1), va_line
);
237 if (retval
!= ERROR_OK
)
247 LOG_ERROR("d-cache invalidate failed");
254 int armv7a_l1_d_cache_flush_virt(struct target
*target
, uint32_t virt
,
257 struct armv7a_common
*armv7a
= target_to_armv7a(target
);
258 struct arm_dpm
*dpm
= armv7a
->arm
.dpm
;
259 struct armv7a_cache_common
*armv7a_cache
= &armv7a
->armv7a_mmu
.armv7a_cache
;
260 uint32_t linelen
= armv7a_cache
->dminline
;
261 uint32_t va_line
, va_end
;
264 retval
= armv7a_l1_d_cache_sanity_check(target
);
265 if (retval
!= ERROR_OK
)
268 retval
= dpm
->prepare(dpm
);
269 if (retval
!= ERROR_OK
)
272 va_line
= virt
& (-linelen
);
273 va_end
= virt
+ size
;
275 while (va_line
< va_end
) {
276 if ((i
++ & 0x3f) == 0)
279 retval
= dpm
->instr_write_data_r0(dpm
,
280 ARMV4_5_MCR(15, 0, 0, 7, 14, 1), va_line
);
281 if (retval
!= ERROR_OK
)
291 LOG_ERROR("d-cache invalidate failed");
298 int armv7a_l1_i_cache_inval_all(struct target
*target
)
300 struct armv7a_common
*armv7a
= target_to_armv7a(target
);
301 struct arm_dpm
*dpm
= armv7a
->arm
.dpm
;
304 retval
= armv7a_l1_i_cache_sanity_check(target
);
305 if (retval
!= ERROR_OK
)
308 retval
= dpm
->prepare(dpm
);
309 if (retval
!= ERROR_OK
)
314 retval
= dpm
->instr_write_data_r0(dpm
,
315 ARMV4_5_MCR(15, 0, 0, 7, 1, 0), 0);
318 retval
= dpm
->instr_write_data_r0(dpm
,
319 ARMV4_5_MCR(15, 0, 0, 7, 5, 0), 0);
322 if (retval
!= ERROR_OK
)
329 LOG_ERROR("i-cache invalidate failed");
335 int armv7a_l1_i_cache_inval_virt(struct target
*target
, uint32_t virt
,
338 struct armv7a_common
*armv7a
= target_to_armv7a(target
);
339 struct arm_dpm
*dpm
= armv7a
->arm
.dpm
;
340 struct armv7a_cache_common
*armv7a_cache
=
341 &armv7a
->armv7a_mmu
.armv7a_cache
;
342 uint32_t linelen
= armv7a_cache
->iminline
;
343 uint32_t va_line
, va_end
;
346 retval
= armv7a_l1_i_cache_sanity_check(target
);
347 if (retval
!= ERROR_OK
)
350 retval
= dpm
->prepare(dpm
);
351 if (retval
!= ERROR_OK
)
354 va_line
= virt
& (-linelen
);
355 va_end
= virt
+ size
;
357 while (va_line
< va_end
) {
358 if ((i
++ & 0x3f) == 0)
360 /* ICIMVAU - Invalidate instruction cache by VA to PoU. */
361 retval
= dpm
->instr_write_data_r0(dpm
,
362 ARMV4_5_MCR(15, 0, 0, 7, 5, 1), va_line
);
363 if (retval
!= ERROR_OK
)
366 retval
= dpm
->instr_write_data_r0(dpm
,
367 ARMV4_5_MCR(15, 0, 0, 7, 5, 7), va_line
);
368 if (retval
!= ERROR_OK
)
377 LOG_ERROR("i-cache invalidate failed");
384 int armv7a_cache_flush_virt(struct target
*target
, uint32_t virt
,
387 armv7a_l1_d_cache_flush_virt(target
, virt
, size
);
388 armv7a_l2x_cache_flush_virt(target
, virt
, size
);
393 COMMAND_HANDLER(arm7a_l1_cache_info_cmd
)
395 struct target
*target
= get_current_target(CMD_CTX
);
396 struct armv7a_common
*armv7a
= target_to_armv7a(target
);
398 return armv7a_handle_cache_info_command(CMD
,
399 &armv7a
->armv7a_mmu
.armv7a_cache
);
402 COMMAND_HANDLER(armv7a_l1_d_cache_clean_inval_all_cmd
)
404 struct target
*target
= get_current_target(CMD_CTX
);
406 armv7a_l1_d_cache_clean_inval_all(target
);
411 COMMAND_HANDLER(arm7a_l1_d_cache_inval_virt_cmd
)
413 struct target
*target
= get_current_target(CMD_CTX
);
416 if (CMD_ARGC
== 0 || CMD_ARGC
> 2)
417 return ERROR_COMMAND_SYNTAX_ERROR
;
420 COMMAND_PARSE_NUMBER(u32
, CMD_ARGV
[1], size
);
424 COMMAND_PARSE_NUMBER(u32
, CMD_ARGV
[0], virt
);
426 return armv7a_l1_d_cache_inval_virt(target
, virt
, size
);
429 COMMAND_HANDLER(arm7a_l1_d_cache_clean_virt_cmd
)
431 struct target
*target
= get_current_target(CMD_CTX
);
434 if (CMD_ARGC
== 0 || CMD_ARGC
> 2)
435 return ERROR_COMMAND_SYNTAX_ERROR
;
438 COMMAND_PARSE_NUMBER(u32
, CMD_ARGV
[1], size
);
442 COMMAND_PARSE_NUMBER(u32
, CMD_ARGV
[0], virt
);
444 return armv7a_l1_d_cache_clean_virt(target
, virt
, size
);
447 COMMAND_HANDLER(armv7a_i_cache_clean_inval_all_cmd
)
449 struct target
*target
= get_current_target(CMD_CTX
);
451 armv7a_l1_i_cache_inval_all(target
);
456 COMMAND_HANDLER(arm7a_l1_i_cache_inval_virt_cmd
)
458 struct target
*target
= get_current_target(CMD_CTX
);
461 if (CMD_ARGC
== 0 || CMD_ARGC
> 2)
462 return ERROR_COMMAND_SYNTAX_ERROR
;
465 COMMAND_PARSE_NUMBER(u32
, CMD_ARGV
[1], size
);
469 COMMAND_PARSE_NUMBER(u32
, CMD_ARGV
[0], virt
);
471 return armv7a_l1_i_cache_inval_virt(target
, virt
, size
);
474 static const struct command_registration arm7a_l1_d_cache_commands
[] = {
477 .handler
= armv7a_l1_d_cache_clean_inval_all_cmd
,
479 .help
= "flush (clean and invalidate) complete l1 d-cache",
484 .handler
= arm7a_l1_d_cache_inval_virt_cmd
,
486 .help
= "invalidate l1 d-cache by virtual address offset and range size",
487 .usage
= "<virt_addr> [size]",
491 .handler
= arm7a_l1_d_cache_clean_virt_cmd
,
493 .help
= "clean l1 d-cache by virtual address address offset and range size",
494 .usage
= "<virt_addr> [size]",
496 COMMAND_REGISTRATION_DONE
499 static const struct command_registration arm7a_l1_i_cache_commands
[] = {
502 .handler
= armv7a_i_cache_clean_inval_all_cmd
,
504 .help
= "invalidate complete l1 i-cache",
509 .handler
= arm7a_l1_i_cache_inval_virt_cmd
,
511 .help
= "invalidate l1 i-cache by virtual address offset and range size",
512 .usage
= "<virt_addr> [size]",
514 COMMAND_REGISTRATION_DONE
517 static const struct command_registration arm7a_l1_di_cache_group_handlers
[] = {
520 .handler
= arm7a_l1_cache_info_cmd
,
522 .help
= "print cache related information",
528 .help
= "l1 d-cache command group",
530 .chain
= arm7a_l1_d_cache_commands
,
535 .help
= "l1 i-cache command group",
537 .chain
= arm7a_l1_i_cache_commands
,
539 COMMAND_REGISTRATION_DONE
542 static const struct command_registration arm7a_cache_group_handlers
[] = {
546 .help
= "l1 cache command group",
548 .chain
= arm7a_l1_di_cache_group_handlers
,
551 .chain
= arm7a_l2x_cache_command_handler
,
553 COMMAND_REGISTRATION_DONE
556 const struct command_registration arm7a_cache_command_handlers
[] = {
560 .help
= "cache command group",
562 .chain
= arm7a_cache_group_handlers
,
564 COMMAND_REGISTRATION_DONE
Linking to existing account procedure
If you already have an account and want to add another login method
you
MUST first sign in with your existing account and
then change URL to read
https://review.openocd.org/login/?link
to get to this page again but this time it'll work for linking. Thank you.
SSH host keys fingerprints
1024 SHA256:YKx8b7u5ZWdcbp7/4AeXNaqElP49m6QrwfXaqQGJAOk gerrit-code-review@openocd.zylin.com (DSA)
384 SHA256:jHIbSQa4REvwCFG4cq5LBlBLxmxSqelQPem/EXIrxjk gerrit-code-review@openocd.org (ECDSA)
521 SHA256:UAOPYkU9Fjtcao0Ul/Rrlnj/OsQvt+pgdYSZ4jOYdgs gerrit-code-review@openocd.org (ECDSA)
256 SHA256:A13M5QlnozFOvTllybRZH6vm7iSt0XLxbA48yfc2yfY gerrit-code-review@openocd.org (ECDSA)
256 SHA256:spYMBqEYoAOtK7yZBrcwE8ZpYt6b68Cfh9yEVetvbXg gerrit-code-review@openocd.org (ED25519)
+--[ED25519 256]--+
|=.. |
|+o.. . |
|*.o . . |
|+B . . . |
|Bo. = o S |
|Oo.+ + = |
|oB=.* = . o |
| =+=.+ + E |
|. .=o . o |
+----[SHA256]-----+
2048 SHA256:0Onrb7/PHjpo6iVZ7xQX2riKN83FJ3KGU0TvI0TaFG4 gerrit-code-review@openocd.zylin.com (RSA)