1 /***************************************************************************
2 * Copyright (C) 2009 by David Brownell *
4 * Copyright (C) ST-Ericsson SA 2011 michel.jaouen@stericsson.com *
6 * This program is free software; you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License as published by *
8 * the Free Software Foundation; either version 2 of the License, or *
9 * (at your option) any later version. *
11 * This program is distributed in the hope that it will be useful, *
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14 * GNU General Public License for more details. *
16 * You should have received a copy of the GNU General Public License *
17 * along with this program; if not, write to the *
18 * Free Software Foundation, Inc., *
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. *
20 ***************************************************************************/
26 #include <helper/replacements.h>
29 #include "arm_disassembler.h"
32 #include <helper/binarybuffer.h>
33 #include <helper/command.h>
39 #include "arm_opcodes.h"
41 #include "target_type.h"
43 static void armv7a_show_fault_registers(struct target *target)
45 uint32_t dfsr, ifsr, dfar, ifar;
46 struct armv7a_common *armv7a = target_to_armv7a(target);
47 struct arm_dpm *dpm = armv7a->arm.dpm;
50 retval = dpm->prepare(dpm);
51 if (retval != ERROR_OK)
54 /* ARMV4_5_MRC(cpnum, op1, r0, CRn, CRm, op2) */
56 /* c5/c0 - {data, instruction} fault status registers */
57 retval = dpm->instr_read_data_r0(dpm,
58 ARMV4_5_MRC(15, 0, 0, 5, 0, 0),
60 if (retval != ERROR_OK)
63 retval = dpm->instr_read_data_r0(dpm,
64 ARMV4_5_MRC(15, 0, 0, 5, 0, 1),
66 if (retval != ERROR_OK)
69 /* c6/c0 - {data, instruction} fault address registers */
70 retval = dpm->instr_read_data_r0(dpm,
71 ARMV4_5_MRC(15, 0, 0, 6, 0, 0),
73 if (retval != ERROR_OK)
76 retval = dpm->instr_read_data_r0(dpm,
77 ARMV4_5_MRC(15, 0, 0, 6, 0, 2),
79 if (retval != ERROR_OK)
82 LOG_USER("Data fault registers DFSR: %8.8" PRIx32
83 ", DFAR: %8.8" PRIx32, dfsr, dfar);
84 LOG_USER("Instruction fault registers IFSR: %8.8" PRIx32
85 ", IFAR: %8.8" PRIx32, ifsr, ifar);
88 /* (void) */ dpm->finish(dpm);
91 static int armv7a_read_ttbcr(struct target *target)
93 struct armv7a_common *armv7a = target_to_armv7a(target);
94 struct arm_dpm *dpm = armv7a->arm.dpm;
96 int retval = dpm->prepare(dpm);
97 if (retval != ERROR_OK)
99 /* MRC p15,0,<Rt>,c2,c0,2 ; Read CP15 Translation Table Base Control Register*/
100 retval = dpm->instr_read_data_r0(dpm,
101 ARMV4_5_MRC(15, 0, 0, 2, 0, 2),
103 if (retval != ERROR_OK)
105 armv7a->armv7a_mmu.ttbr1_used = ((ttbcr & 0x7) != 0) ? 1 : 0;
106 armv7a->armv7a_mmu.ttbr0_mask = 7 << (32 - ((ttbcr & 0x7)));
108 LOG_INFO("ttb1 %s ,ttb0_mask %x",
109 armv7a->armv7a_mmu.ttbr1_used ? "used" : "not used",
110 armv7a->armv7a_mmu.ttbr0_mask);
112 if (armv7a->armv7a_mmu.ttbr1_used == 1) {
113 LOG_INFO("SVC access above %" PRIx32,
114 (uint32_t)(0xffffffff & armv7a->armv7a_mmu.ttbr0_mask));
115 armv7a->armv7a_mmu.os_border = 0xffffffff & armv7a->armv7a_mmu.ttbr0_mask;
117 /* fix me , default is hard coded LINUX border */
118 armv7a->armv7a_mmu.os_border = 0xc0000000;
126 /* method adapted to cortex A : reused arm v4 v5 method*/
127 int armv7a_mmu_translate_va(struct target *target, uint32_t va, uint32_t *val)
129 uint32_t first_lvl_descriptor = 0x0;
130 uint32_t second_lvl_descriptor = 0x0;
132 struct armv7a_common *armv7a = target_to_armv7a(target);
133 struct arm_dpm *dpm = armv7a->arm.dpm;
134 uint32_t ttb = 0; /* default ttb0 */
135 if (armv7a->armv7a_mmu.ttbr1_used == -1)
136 armv7a_read_ttbcr(target);
137 if ((armv7a->armv7a_mmu.ttbr1_used) &&
138 (va > (0xffffffff & armv7a->armv7a_mmu.ttbr0_mask))) {
142 retval = dpm->prepare(dpm);
143 if (retval != ERROR_OK)
146 /* MRC p15,0,<Rt>,c2,c0,ttb */
147 retval = dpm->instr_read_data_r0(dpm,
148 ARMV4_5_MRC(15, 0, 0, 2, 0, ttb),
150 if (retval != ERROR_OK)
152 retval = armv7a->armv7a_mmu.read_physical_memory(target,
153 (ttb & 0xffffc000) | ((va & 0xfff00000) >> 18),
154 4, 1, (uint8_t *)&first_lvl_descriptor);
155 if (retval != ERROR_OK)
157 first_lvl_descriptor = target_buffer_get_u32(target, (uint8_t *)
158 &first_lvl_descriptor);
159 /* reuse armv4_5 piece of code, specific armv7a changes may come later */
160 LOG_DEBUG("1st lvl desc: %8.8" PRIx32 "", first_lvl_descriptor);
162 if ((first_lvl_descriptor & 0x3) == 0) {
163 LOG_ERROR("Address translation failure");
164 return ERROR_TARGET_TRANSLATION_FAULT;
168 if ((first_lvl_descriptor & 0x3) == 2) {
169 /* section descriptor */
170 *val = (first_lvl_descriptor & 0xfff00000) | (va & 0x000fffff);
174 if ((first_lvl_descriptor & 0x3) == 1) {
175 /* coarse page table */
176 retval = armv7a->armv7a_mmu.read_physical_memory(target,
177 (first_lvl_descriptor & 0xfffffc00) | ((va & 0x000ff000) >> 10),
178 4, 1, (uint8_t *)&second_lvl_descriptor);
179 if (retval != ERROR_OK)
181 } else if ((first_lvl_descriptor & 0x3) == 3) {
182 /* fine page table */
183 retval = armv7a->armv7a_mmu.read_physical_memory(target,
184 (first_lvl_descriptor & 0xfffff000) | ((va & 0x000ffc00) >> 8),
185 4, 1, (uint8_t *)&second_lvl_descriptor);
186 if (retval != ERROR_OK)
190 second_lvl_descriptor = target_buffer_get_u32(target, (uint8_t *)
191 &second_lvl_descriptor);
193 LOG_DEBUG("2nd lvl desc: %8.8" PRIx32 "", second_lvl_descriptor);
195 if ((second_lvl_descriptor & 0x3) == 0) {
196 LOG_ERROR("Address translation failure");
197 return ERROR_TARGET_TRANSLATION_FAULT;
200 if ((second_lvl_descriptor & 0x3) == 1) {
201 /* large page descriptor */
202 *val = (second_lvl_descriptor & 0xffff0000) | (va & 0x0000ffff);
206 if ((second_lvl_descriptor & 0x3) == 2) {
207 /* small page descriptor */
208 *val = (second_lvl_descriptor & 0xfffff000) | (va & 0x00000fff);
212 if ((second_lvl_descriptor & 0x3) == 3) {
213 *val = (second_lvl_descriptor & 0xfffffc00) | (va & 0x000003ff);
217 /* should not happen */
218 LOG_ERROR("Address translation failure");
219 return ERROR_TARGET_TRANSLATION_FAULT;
225 /* V7 method VA TO PA */
226 int armv7a_mmu_translate_va_pa(struct target *target, uint32_t va,
227 uint32_t *val, int meminfo)
229 int retval = ERROR_FAIL;
230 struct armv7a_common *armv7a = target_to_armv7a(target);
231 struct arm_dpm *dpm = armv7a->arm.dpm;
232 uint32_t virt = va & ~0xfff;
233 uint32_t NOS, NS, INNER, OUTER;
235 retval = dpm->prepare(dpm);
236 if (retval != ERROR_OK)
238 /* mmu must be enable in order to get a correct translation
239 * use VA to PA CP15 register for conversion */
240 retval = dpm->instr_write_data_r0(dpm,
241 ARMV4_5_MCR(15, 0, 0, 7, 8, 0),
243 if (retval != ERROR_OK)
245 retval = dpm->instr_read_data_r0(dpm,
246 ARMV4_5_MRC(15, 0, 0, 7, 4, 0),
248 /* decode memory attribute */
249 NOS = (*val >> 10) & 1; /* Not Outer shareable */
250 NS = (*val >> 9) & 1; /* Non secure */
251 INNER = (*val >> 4) & 0x7;
252 OUTER = (*val >> 2) & 0x3;
254 if (retval != ERROR_OK)
256 *val = (*val & ~0xfff) + (va & 0xfff);
258 LOG_WARNING("virt = phys : MMU disable !!");
260 LOG_INFO("%" PRIx32 " : %" PRIx32 " %s outer shareable %s secured",
262 NOS == 1 ? "not" : " ",
263 NS == 1 ? "not" : "");
266 LOG_INFO("outer: Non-Cacheable");
269 LOG_INFO("outer: Write-Back, Write-Allocate");
272 LOG_INFO("outer: Write-Through, No Write-Allocate");
275 LOG_INFO("outer: Write-Back, no Write-Allocate");
280 LOG_INFO("inner: Non-Cacheable");
283 LOG_INFO("inner: Strongly-ordered");
286 LOG_INFO("inner: Device");
289 LOG_INFO("inner: Write-Back, Write-Allocate");
292 LOG_INFO("inner: Write-Through");
295 LOG_INFO("inner: Write-Back, no Write-Allocate");
298 LOG_INFO("inner: %" PRIx32 " ???", INNER);
308 static int armv7a_handle_inner_cache_info_command(struct command_context *cmd_ctx,
309 struct armv7a_cache_common *armv7a_cache)
311 if (armv7a_cache->ctype == -1) {
312 command_print(cmd_ctx, "cache not yet identified");
316 command_print(cmd_ctx,
317 "D-Cache: linelen %" PRIi32 ", associativity %" PRIi32 ", nsets %" PRIi32 ", cachesize %" PRId32 " KBytes",
318 armv7a_cache->d_u_size.linelen,
319 armv7a_cache->d_u_size.associativity,
320 armv7a_cache->d_u_size.nsets,
321 armv7a_cache->d_u_size.cachesize);
323 command_print(cmd_ctx,
324 "I-Cache: linelen %" PRIi32 ", associativity %" PRIi32 ", nsets %" PRIi32 ", cachesize %" PRId32 " KBytes",
325 armv7a_cache->i_size.linelen,
326 armv7a_cache->i_size.associativity,
327 armv7a_cache->i_size.nsets,
328 armv7a_cache->i_size.cachesize);
333 static int _armv7a_flush_all_data(struct target *target)
335 struct armv7a_common *armv7a = target_to_armv7a(target);
336 struct arm_dpm *dpm = armv7a->arm.dpm;
337 struct armv7a_cachesize *d_u_size =
338 &(armv7a->armv7a_mmu.armv7a_cache.d_u_size);
339 int32_t c_way, c_index = d_u_size->index;
341 /* check that cache data is on at target halt */
342 if (!armv7a->armv7a_mmu.armv7a_cache.d_u_cache_enabled) {
343 LOG_INFO("flushed not performed :cache not on at target halt");
346 retval = dpm->prepare(dpm);
347 if (retval != ERROR_OK)
350 c_way = d_u_size->way;
352 uint32_t value = (c_index << d_u_size->index_shift)
353 | (c_way << d_u_size->way_shift);
355 /* LOG_INFO ("%d %d %x",c_way,c_index,value); */
356 retval = dpm->instr_write_data_r0(dpm,
357 ARMV4_5_MCR(15, 0, 0, 7, 14, 2),
359 if (retval != ERROR_OK)
362 } while (c_way >= 0);
364 } while (c_index >= 0);
367 LOG_ERROR("flushed failed");
372 static int armv7a_flush_all_data(struct target *target)
374 int retval = ERROR_FAIL;
375 /* check that armv7a_cache is correctly identify */
376 struct armv7a_common *armv7a = target_to_armv7a(target);
377 if (armv7a->armv7a_mmu.armv7a_cache.ctype == -1) {
378 LOG_ERROR("trying to flush un-identified cache");
383 /* look if all the other target have been flushed in order to flush level
385 struct target_list *head;
388 while (head != (struct target_list *)NULL) {
390 if (curr->state == TARGET_HALTED) {
391 LOG_INFO("Wait flushing data l1 on core %" PRId32, curr->coreid);
392 retval = _armv7a_flush_all_data(curr);
397 retval = _armv7a_flush_all_data(target);
401 /* L2 is not specific to armv7a a specific file is needed */
402 static int armv7a_l2x_flush_all_data(struct target *target)
405 #define L2X0_CLEAN_INV_WAY 0x7FC
406 int retval = ERROR_FAIL;
407 struct armv7a_common *armv7a = target_to_armv7a(target);
408 struct armv7a_l2x_cache *l2x_cache = (struct armv7a_l2x_cache *)
409 (armv7a->armv7a_mmu.armv7a_cache.l2_cache);
410 uint32_t base = l2x_cache->base;
411 uint32_t l2_way = l2x_cache->way;
412 uint32_t l2_way_val = (1 << l2_way) - 1;
413 retval = armv7a_flush_all_data(target);
414 if (retval != ERROR_OK)
416 retval = target->type->write_phys_memory(target,
417 (uint32_t)(base+(uint32_t)L2X0_CLEAN_INV_WAY),
420 (uint8_t *)&l2_way_val);
424 static int armv7a_handle_l2x_cache_info_command(struct command_context *cmd_ctx,
425 struct armv7a_cache_common *armv7a_cache)
428 struct armv7a_l2x_cache *l2x_cache = (struct armv7a_l2x_cache *)
429 (armv7a_cache->l2_cache);
431 if (armv7a_cache->ctype == -1) {
432 command_print(cmd_ctx, "cache not yet identified");
436 command_print(cmd_ctx,
437 "L1 D-Cache: linelen %" PRIi32 ", associativity %" PRIi32 ", nsets %" PRIi32 ", cachesize %" PRId32 " KBytes",
438 armv7a_cache->d_u_size.linelen,
439 armv7a_cache->d_u_size.associativity,
440 armv7a_cache->d_u_size.nsets,
441 armv7a_cache->d_u_size.cachesize);
443 command_print(cmd_ctx,
444 "L1 I-Cache: linelen %" PRIi32 ", associativity %" PRIi32 ", nsets %" PRIi32 ", cachesize %" PRId32 " KBytes",
445 armv7a_cache->i_size.linelen,
446 armv7a_cache->i_size.associativity,
447 armv7a_cache->i_size.nsets,
448 armv7a_cache->i_size.cachesize);
449 command_print(cmd_ctx, "L2 unified cache Base Address 0x%" PRIx32 ", %" PRId32 " ways",
450 l2x_cache->base, l2x_cache->way);
457 static int armv7a_l2x_cache_init(struct target *target, uint32_t base, uint32_t way)
459 struct armv7a_l2x_cache *l2x_cache;
460 struct target_list *head = target->head;
463 struct armv7a_common *armv7a = target_to_armv7a(target);
464 l2x_cache = calloc(1, sizeof(struct armv7a_l2x_cache));
465 l2x_cache->base = base;
466 l2x_cache->way = way;
467 /*LOG_INFO("cache l2 initialized base %x way %d",
468 l2x_cache->base,l2x_cache->way);*/
469 if (armv7a->armv7a_mmu.armv7a_cache.l2_cache)
470 LOG_INFO("cache l2 already initialized\n");
471 armv7a->armv7a_mmu.armv7a_cache.l2_cache = l2x_cache;
472 /* initialize l1 / l2x cache function */
473 armv7a->armv7a_mmu.armv7a_cache.flush_all_data_cache
474 = armv7a_l2x_flush_all_data;
475 armv7a->armv7a_mmu.armv7a_cache.display_cache_info =
476 armv7a_handle_l2x_cache_info_command;
477 /* initialize all target in this cluster (smp target)
478 * l2 cache must be configured after smp declaration */
479 while (head != (struct target_list *)NULL) {
481 if (curr != target) {
482 armv7a = target_to_armv7a(curr);
483 if (armv7a->armv7a_mmu.armv7a_cache.l2_cache)
484 LOG_ERROR("smp target : cache l2 already initialized\n");
485 armv7a->armv7a_mmu.armv7a_cache.l2_cache = l2x_cache;
486 armv7a->armv7a_mmu.armv7a_cache.flush_all_data_cache =
487 armv7a_l2x_flush_all_data;
488 armv7a->armv7a_mmu.armv7a_cache.display_cache_info =
489 armv7a_handle_l2x_cache_info_command;
496 COMMAND_HANDLER(handle_cache_l2x)
498 struct target *target = get_current_target(CMD_CTX);
502 return ERROR_COMMAND_SYNTAX_ERROR;
505 /* command_print(CMD_CTX, "%s %s", CMD_ARGV[0], CMD_ARGV[1]); */
506 COMMAND_PARSE_NUMBER(u32, CMD_ARGV[0], base);
507 COMMAND_PARSE_NUMBER(u32, CMD_ARGV[1], way);
509 /* AP address is in bits 31:24 of DP_SELECT */
510 armv7a_l2x_cache_init(target, base, way);
513 return ERROR_COMMAND_SYNTAX_ERROR;
518 int armv7a_handle_cache_info_command(struct command_context *cmd_ctx,
519 struct armv7a_cache_common *armv7a_cache)
521 if (armv7a_cache->ctype == -1) {
522 command_print(cmd_ctx, "cache not yet identified");
526 if (armv7a_cache->display_cache_info)
527 armv7a_cache->display_cache_info(cmd_ctx, armv7a_cache);
531 /* retrieve core id cluster id */
532 static int armv7a_read_mpidr(struct target *target)
534 int retval = ERROR_FAIL;
535 struct armv7a_common *armv7a = target_to_armv7a(target);
536 struct arm_dpm *dpm = armv7a->arm.dpm;
538 retval = dpm->prepare(dpm);
539 if (retval != ERROR_OK)
541 /* MRC p15,0,<Rd>,c0,c0,5; read Multiprocessor ID register*/
543 retval = dpm->instr_read_data_r0(dpm,
544 ARMV4_5_MRC(15, 0, 0, 0, 0, 5),
546 if (retval != ERROR_OK)
549 /* ARMv7R uses a different format for MPIDR.
550 * When configured uniprocessor (most R cores) it reads as 0.
551 * This will need to be implemented for multiprocessor ARMv7R cores. */
552 if (armv7a->is_armv7r) {
554 LOG_ERROR("MPIDR nonzero in ARMv7-R target");
559 armv7a->multi_processor_system = (mpidr >> 30) & 1;
560 armv7a->cluster_id = (mpidr >> 8) & 0xf;
561 armv7a->cpu_id = mpidr & 0x3;
562 LOG_INFO("%s cluster %x core %x %s", target_name(target),
565 armv7a->multi_processor_system == 0 ? "multi core" : "mono core");
568 LOG_ERROR("MPIDR not in multiprocessor format");
577 int armv7a_identify_cache(struct target *target)
579 /* read cache descriptor */
580 int retval = ERROR_FAIL;
581 struct armv7a_common *armv7a = target_to_armv7a(target);
582 struct arm_dpm *dpm = armv7a->arm.dpm;
583 uint32_t cache_selected, clidr;
584 uint32_t cache_i_reg, cache_d_reg;
585 struct armv7a_cache_common *cache = &(armv7a->armv7a_mmu.armv7a_cache);
586 if (!armv7a->is_armv7r)
587 armv7a_read_ttbcr(target);
588 retval = dpm->prepare(dpm);
590 if (retval != ERROR_OK)
593 * mrc p15, 1, r0, c0, c0, 1 @ read clidr */
594 retval = dpm->instr_read_data_r0(dpm,
595 ARMV4_5_MRC(15, 1, 0, 0, 0, 1),
597 if (retval != ERROR_OK)
599 clidr = (clidr & 0x7000000) >> 23;
600 LOG_INFO("number of cache level %" PRIx32, (uint32_t)(clidr / 2));
601 if ((clidr / 2) > 1) {
602 /* FIXME not supported present in cortex A8 and later */
603 /* in cortex A7, A15 */
604 LOG_ERROR("cache l2 present :not supported");
606 /* retrieve selected cache
607 * MRC p15, 2,<Rd>, c0, c0, 0; Read CSSELR */
608 retval = dpm->instr_read_data_r0(dpm,
609 ARMV4_5_MRC(15, 2, 0, 0, 0, 0),
611 if (retval != ERROR_OK)
614 retval = armv7a->arm.mrc(target, 15,
618 if (retval != ERROR_OK)
620 /* select instruction cache
621 * MCR p15, 2,<Rd>, c0, c0, 0; Write CSSELR
622 * [0] : 1 instruction cache selection , 0 data cache selection */
623 retval = dpm->instr_write_data_r0(dpm,
624 ARMV4_5_MRC(15, 2, 0, 0, 0, 0),
626 if (retval != ERROR_OK)
630 * MRC P15,1,<RT>,C0, C0,0 ;on cortex A9 read CCSIDR
631 * [2:0] line size 001 eight word per line
632 * [27:13] NumSet 0x7f 16KB, 0xff 32Kbytes, 0x1ff 64Kbytes */
633 retval = dpm->instr_read_data_r0(dpm,
634 ARMV4_5_MRC(15, 1, 0, 0, 0, 0),
636 if (retval != ERROR_OK)
639 /* select data cache*/
640 retval = dpm->instr_write_data_r0(dpm,
641 ARMV4_5_MRC(15, 2, 0, 0, 0, 0),
643 if (retval != ERROR_OK)
646 retval = dpm->instr_read_data_r0(dpm,
647 ARMV4_5_MRC(15, 1, 0, 0, 0, 0),
649 if (retval != ERROR_OK)
652 /* restore selected cache */
653 dpm->instr_write_data_r0(dpm,
654 ARMV4_5_MRC(15, 2, 0, 0, 0, 0),
657 if (retval != ERROR_OK)
662 cache->d_u_size.linelen = 16 << (cache_d_reg & 0x7);
663 cache->d_u_size.cachesize = (((cache_d_reg >> 13) & 0x7fff)+1)/8;
664 cache->d_u_size.nsets = (cache_d_reg >> 13) & 0x7fff;
665 cache->d_u_size.associativity = ((cache_d_reg >> 3) & 0x3ff) + 1;
666 /* compute info for set way operation on cache */
667 cache->d_u_size.index_shift = (cache_d_reg & 0x7) + 4;
668 cache->d_u_size.index = (cache_d_reg >> 13) & 0x7fff;
669 cache->d_u_size.way = ((cache_d_reg >> 3) & 0x3ff);
670 cache->d_u_size.way_shift = cache->d_u_size.way + 1;
673 while (((cache->d_u_size.way_shift >> i) & 1) != 1)
675 cache->d_u_size.way_shift = 32-i;
678 LOG_INFO("data cache index %d << %d, way %d << %d",
679 cache->d_u_size.index, cache->d_u_size.index_shift,
681 cache->d_u_size.way_shift);
683 LOG_INFO("data cache %d bytes %d KBytes asso %d ways",
684 cache->d_u_size.linelen,
685 cache->d_u_size.cachesize,
686 cache->d_u_size.associativity);
688 cache->i_size.linelen = 16 << (cache_i_reg & 0x7);
689 cache->i_size.associativity = ((cache_i_reg >> 3) & 0x3ff) + 1;
690 cache->i_size.nsets = (cache_i_reg >> 13) & 0x7fff;
691 cache->i_size.cachesize = (((cache_i_reg >> 13) & 0x7fff)+1)/8;
692 /* compute info for set way operation on cache */
693 cache->i_size.index_shift = (cache_i_reg & 0x7) + 4;
694 cache->i_size.index = (cache_i_reg >> 13) & 0x7fff;
695 cache->i_size.way = ((cache_i_reg >> 3) & 0x3ff);
696 cache->i_size.way_shift = cache->i_size.way + 1;
699 while (((cache->i_size.way_shift >> i) & 1) != 1)
701 cache->i_size.way_shift = 32-i;
704 LOG_INFO("instruction cache index %d << %d, way %d << %d",
705 cache->i_size.index, cache->i_size.index_shift,
706 cache->i_size.way, cache->i_size.way_shift);
708 LOG_INFO("instruction cache %d bytes %d KBytes asso %d ways",
709 cache->i_size.linelen,
710 cache->i_size.cachesize,
711 cache->i_size.associativity);
713 /* if no l2 cache initialize l1 data cache flush function function */
714 if (armv7a->armv7a_mmu.armv7a_cache.flush_all_data_cache == NULL) {
715 armv7a->armv7a_mmu.armv7a_cache.display_cache_info =
716 armv7a_handle_inner_cache_info_command;
717 armv7a->armv7a_mmu.armv7a_cache.flush_all_data_cache =
718 armv7a_flush_all_data;
720 armv7a->armv7a_mmu.armv7a_cache.ctype = 0;
724 armv7a_read_mpidr(target);
729 int armv7a_init_arch_info(struct target *target, struct armv7a_common *armv7a)
731 struct arm *arm = &armv7a->arm;
732 arm->arch_info = armv7a;
733 target->arch_info = &armv7a->arm;
734 /* target is useful in all function arm v4 5 compatible */
735 armv7a->arm.target = target;
736 armv7a->arm.common_magic = ARM_COMMON_MAGIC;
737 armv7a->common_magic = ARMV7_COMMON_MAGIC;
738 armv7a->armv7a_mmu.armv7a_cache.l2_cache = NULL;
739 armv7a->armv7a_mmu.armv7a_cache.ctype = -1;
740 armv7a->armv7a_mmu.armv7a_cache.flush_all_data_cache = NULL;
741 armv7a->armv7a_mmu.armv7a_cache.display_cache_info = NULL;
745 int armv7a_arch_state(struct target *target)
747 static const char *state[] = {
748 "disabled", "enabled"
751 struct armv7a_common *armv7a = target_to_armv7a(target);
752 struct arm *arm = &armv7a->arm;
754 if (armv7a->common_magic != ARMV7_COMMON_MAGIC) {
755 LOG_ERROR("BUG: called for a non-ARMv7A target");
756 return ERROR_COMMAND_SYNTAX_ERROR;
759 arm_arch_state(target);
761 if (armv7a->is_armv7r) {
762 LOG_USER("D-Cache: %s, I-Cache: %s",
763 state[armv7a->armv7a_mmu.armv7a_cache.d_u_cache_enabled],
764 state[armv7a->armv7a_mmu.armv7a_cache.i_cache_enabled]);
766 LOG_USER("MMU: %s, D-Cache: %s, I-Cache: %s",
767 state[armv7a->armv7a_mmu.mmu_enabled],
768 state[armv7a->armv7a_mmu.armv7a_cache.d_u_cache_enabled],
769 state[armv7a->armv7a_mmu.armv7a_cache.i_cache_enabled]);
772 if (arm->core_mode == ARM_MODE_ABT)
773 armv7a_show_fault_registers(target);
774 if (target->debug_reason == DBG_REASON_WATCHPOINT)
775 LOG_USER("Watchpoint triggered at PC %#08x",
776 (unsigned) armv7a->dpm.wp_pc);
781 static const struct command_registration l2_cache_commands[] = {
784 .handler = handle_cache_l2x,
785 .mode = COMMAND_EXEC,
786 .help = "configure l2x cache "
788 .usage = "[base_addr] [number_of_way]",
790 COMMAND_REGISTRATION_DONE
794 const struct command_registration l2x_cache_command_handlers[] = {
796 .name = "cache_config",
797 .mode = COMMAND_EXEC,
798 .help = "cache configuration for a target",
800 .chain = l2_cache_commands,
802 COMMAND_REGISTRATION_DONE
806 const struct command_registration armv7a_command_handlers[] = {
808 .chain = dap_command_handlers,
811 .chain = l2x_cache_command_handlers,
813 COMMAND_REGISTRATION_DONE