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 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
20 ***************************************************************************/
25 #include <helper/replacements.h>
28 #include "arm_disassembler.h"
31 #include <helper/binarybuffer.h>
32 #include <helper/command.h>
38 #include "arm_opcodes.h"
40 #include "target_type.h"
42 static void armv7a_show_fault_registers(struct target
*target
)
44 uint32_t dfsr
, ifsr
, dfar
, ifar
;
45 struct armv7a_common
*armv7a
= target_to_armv7a(target
);
46 struct arm_dpm
*dpm
= armv7a
->arm
.dpm
;
49 retval
= dpm
->prepare(dpm
);
50 if (retval
!= ERROR_OK
)
53 /* ARMV4_5_MRC(cpnum, op1, r0, CRn, CRm, op2) */
55 /* c5/c0 - {data, instruction} fault status registers */
56 retval
= dpm
->instr_read_data_r0(dpm
,
57 ARMV4_5_MRC(15, 0, 0, 5, 0, 0),
59 if (retval
!= ERROR_OK
)
62 retval
= dpm
->instr_read_data_r0(dpm
,
63 ARMV4_5_MRC(15, 0, 0, 5, 0, 1),
65 if (retval
!= ERROR_OK
)
68 /* c6/c0 - {data, instruction} fault address registers */
69 retval
= dpm
->instr_read_data_r0(dpm
,
70 ARMV4_5_MRC(15, 0, 0, 6, 0, 0),
72 if (retval
!= ERROR_OK
)
75 retval
= dpm
->instr_read_data_r0(dpm
,
76 ARMV4_5_MRC(15, 0, 0, 6, 0, 2),
78 if (retval
!= ERROR_OK
)
81 LOG_USER("Data fault registers DFSR: %8.8" PRIx32
82 ", DFAR: %8.8" PRIx32
, dfsr
, dfar
);
83 LOG_USER("Instruction fault registers IFSR: %8.8" PRIx32
84 ", IFAR: %8.8" PRIx32
, ifsr
, ifar
);
87 /* (void) */ dpm
->finish(dpm
);
90 static int armv7a_read_ttbcr(struct target
*target
)
92 struct armv7a_common
*armv7a
= target_to_armv7a(target
);
93 struct arm_dpm
*dpm
= armv7a
->arm
.dpm
;
95 int retval
= dpm
->prepare(dpm
);
96 if (retval
!=ERROR_OK
) goto done
;
97 /* MRC p15,0,<Rt>,c2,c0,2 ; Read CP15 Translation Table Base Control Register*/
98 retval
= dpm
->instr_read_data_r0(dpm
,
99 ARMV4_5_MRC(15, 0, 0, 2, 0, 2),
101 if (retval
!=ERROR_OK
) goto done
;
102 armv7a
->armv7a_mmu
.ttbr1_used
= ((ttbcr
& 0x7)!=0)? 1: 0;
103 armv7a
->armv7a_mmu
.ttbr0_mask
= 7 << (32 -((ttbcr
& 0x7)));
105 LOG_INFO("ttb1 %s ,ttb0_mask %x",
106 armv7a
->armv7a_mmu
.ttbr1_used
? "used":"not used",
107 armv7a
->armv7a_mmu
.ttbr0_mask
);
109 if (armv7a
->armv7a_mmu
.ttbr1_used
== 1)
111 LOG_INFO("SVC access above %x",
112 (0xffffffff & armv7a
->armv7a_mmu
.ttbr0_mask
));
113 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) armv7a_read_ttbcr(target
);
136 if ((armv7a
->armv7a_mmu
.ttbr1_used
) &&
137 (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)
164 LOG_ERROR("Address translation failure");
165 return ERROR_TARGET_TRANSLATION_FAULT
;
169 if ((first_lvl_descriptor
& 0x3) == 2)
171 /* section descriptor */
172 *val
= (first_lvl_descriptor
& 0xfff00000) | (va
& 0x000fffff);
176 if ((first_lvl_descriptor
& 0x3) == 1)
178 /* coarse page table */
179 retval
= armv7a
->armv7a_mmu
.read_physical_memory(target
,
180 (first_lvl_descriptor
& 0xfffffc00) | ((va
& 0x000ff000) >> 10),
181 4, 1, (uint8_t*)&second_lvl_descriptor
);
182 if (retval
!= ERROR_OK
)
185 else if ((first_lvl_descriptor
& 0x3) == 3)
187 /* fine page table */
188 retval
= armv7a
->armv7a_mmu
.read_physical_memory(target
,
189 (first_lvl_descriptor
& 0xfffff000) | ((va
& 0x000ffc00) >> 8),
190 4, 1, (uint8_t*)&second_lvl_descriptor
);
191 if (retval
!= ERROR_OK
)
195 second_lvl_descriptor
= target_buffer_get_u32(target
, (uint8_t*)
196 &second_lvl_descriptor
);
198 LOG_DEBUG("2nd lvl desc: %8.8" PRIx32
"", second_lvl_descriptor
);
200 if ((second_lvl_descriptor
& 0x3) == 0)
202 LOG_ERROR("Address translation failure");
203 return ERROR_TARGET_TRANSLATION_FAULT
;
206 if ((second_lvl_descriptor
& 0x3) == 1)
208 /* large page descriptor */
209 *val
= (second_lvl_descriptor
& 0xffff0000) | (va
& 0x0000ffff);
213 if ((second_lvl_descriptor
& 0x3) == 2)
215 /* small page descriptor */
216 *val
= (second_lvl_descriptor
& 0xfffff000) | (va
& 0x00000fff);
220 if ((second_lvl_descriptor
& 0x3) == 3)
222 *val
= (second_lvl_descriptor
& 0xfffffc00) | (va
& 0x000003ff);
226 /* should not happen */
227 LOG_ERROR("Address translation failure");
228 return ERROR_TARGET_TRANSLATION_FAULT
;
235 /* V7 method VA TO PA */
236 int armv7a_mmu_translate_va_pa(struct target
*target
, uint32_t va
,
237 uint32_t *val
, int meminfo
)
239 int retval
= ERROR_FAIL
;
240 struct armv7a_common
*armv7a
= target_to_armv7a(target
);
241 struct arm_dpm
*dpm
= armv7a
->arm
.dpm
;
242 uint32_t virt
= va
& ~0xfff;
243 uint32_t NOS
,NS
,INNER
,OUTER
;
245 retval
= dpm
->prepare(dpm
);
246 if (retval
!= ERROR_OK
)
248 /* mmu must be enable in order to get a correct translation */
249 /* use VA to PA CP15 register for conversion */
250 retval
= dpm
->instr_write_data_r0(dpm
,
251 ARMV4_5_MCR(15, 0, 0, 7, 8, 0),
253 if (retval
!=ERROR_OK
) goto done
;
254 retval
= dpm
->instr_read_data_r0(dpm
,
255 ARMV4_5_MRC(15, 0, 0, 7, 4, 0),
257 /* decode memory attribute */
258 NOS
= (*val
>> 10) & 1; /* Not Outer shareable */
259 NS
= (*val
>> 9) & 1; /* Non secure */
260 INNER
= (*val
>> 4) & 0x7;
261 OUTER
= (*val
>> 2) & 0x3;
263 if (retval
!=ERROR_OK
) goto done
;
264 *val
= (*val
& ~0xfff) + (va
& 0xfff);
266 LOG_WARNING("virt = phys : MMU disable !!");
269 LOG_INFO("%x : %x %s outer shareable %s secured",
271 NOS
== 1 ? "not" : " ",
272 NS
== 1 ? "not" :"");
274 case 0 : LOG_INFO("outer: Non-Cacheable");
276 case 1 : LOG_INFO("outer: Write-Back, Write-Allocate");
278 case 2 : LOG_INFO("outer: Write-Through, No Write-Allocate");
280 case 3 : LOG_INFO("outer: Write-Back, no Write-Allocate");
284 case 0 : LOG_INFO("inner: Non-Cacheable");
286 case 1 : LOG_INFO("inner: Strongly-ordered");
288 case 3 : LOG_INFO("inner: Device");
290 case 5 : LOG_INFO("inner: Write-Back, Write-Allocate");
292 case 6 : LOG_INFO("inner: Write-Through");
294 case 7 : LOG_INFO("inner: Write-Back, no Write-Allocate");
296 default: LOG_INFO("inner: %x ???",INNER
);
306 static int armv7a_handle_inner_cache_info_command(struct command_context
*cmd_ctx
,
307 struct armv7a_cache_common
*armv7a_cache
)
309 if (armv7a_cache
->ctype
== -1)
311 command_print(cmd_ctx
, "cache not yet identified");
315 command_print(cmd_ctx
,
316 "D-Cache: linelen %i, associativity %i, nsets %i, cachesize %d KBytes",
317 armv7a_cache
->d_u_size
.linelen
,
318 armv7a_cache
->d_u_size
.associativity
,
319 armv7a_cache
->d_u_size
.nsets
,
320 armv7a_cache
->d_u_size
.cachesize
);
322 command_print(cmd_ctx
,
323 "I-Cache: linelen %i, associativity %i, nsets %i, cachesize %d KBytes",
324 armv7a_cache
->i_size
.linelen
,
325 armv7a_cache
->i_size
.associativity
,
326 armv7a_cache
->i_size
.nsets
,
327 armv7a_cache
->i_size
.cachesize
);
332 static int _armv7a_flush_all_data(struct target
*target
)
334 struct armv7a_common
*armv7a
= target_to_armv7a(target
);
335 struct arm_dpm
*dpm
= armv7a
->arm
.dpm
;
336 struct armv7a_cachesize
*d_u_size
=
337 &(armv7a
->armv7a_mmu
.armv7a_cache
.d_u_size
);
338 int32_t c_way
, c_index
= d_u_size
->index
;
340 /* check that cache data is on at target halt */
341 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
) goto done
;
349 c_way
= d_u_size
->way
;
351 uint32_t value
= (c_index
<< d_u_size
->index_shift
)
352 | (c_way
<< d_u_size
->way_shift
);
354 //LOG_INFO ("%d %d %x",c_way,c_index,value);
355 retval
= dpm
->instr_write_data_r0(dpm
,
356 ARMV4_5_MCR(15, 0, 0, 7, 14, 2),
358 if (retval
!= ERROR_OK
) goto done
;
362 } while (c_index
>=0);
365 LOG_ERROR("flushed failed");
370 static int armv7a_flush_all_data( struct target
* target
)
372 int retval
= ERROR_FAIL
;
373 /* check that armv7a_cache is correctly identify */
374 struct armv7a_common
*armv7a
= target_to_armv7a(target
);
375 if (armv7a
->armv7a_mmu
.armv7a_cache
.ctype
== -1)
377 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
)
391 if ((curr
->state
== TARGET_HALTED
))
392 { LOG_INFO("Wait flushing data l1 on core %d",curr
->coreid
);
393 retval
= _armv7a_flush_all_data(curr
);
398 else retval
= _armv7a_flush_all_data(target
);
403 /* L2 is not specific to armv7a a specific file is needed */
404 static int armv7a_l2x_flush_all_data(struct target
* target
)
407 #define L2X0_CLEAN_INV_WAY 0x7FC
408 int retval
= ERROR_FAIL
;
409 struct armv7a_common
*armv7a
= target_to_armv7a(target
);
410 struct armv7a_l2x_cache
*l2x_cache
= (struct armv7a_l2x_cache
*)
411 (armv7a
->armv7a_mmu
.armv7a_cache
.l2_cache
);
412 uint32_t base
= l2x_cache
->base
;
413 uint32_t l2_way
= l2x_cache
->way
;
414 uint32_t l2_way_val
= (1<<l2_way
) -1;
415 retval
= armv7a_flush_all_data(target
);
416 if (retval
!=ERROR_OK
) return retval
;
417 retval
= target
->type
->write_phys_memory(target
,
418 (uint32_t)(base
+(uint32_t)L2X0_CLEAN_INV_WAY
),
421 (uint8_t*)&l2_way_val
);
425 static int armv7a_handle_l2x_cache_info_command(struct command_context
*cmd_ctx
,
426 struct armv7a_cache_common
*armv7a_cache
)
429 struct armv7a_l2x_cache
*l2x_cache
= (struct armv7a_l2x_cache
*)
430 (armv7a_cache
->l2_cache
);
432 if (armv7a_cache
->ctype
== -1)
434 command_print(cmd_ctx
, "cache not yet identified");
438 command_print(cmd_ctx
,
439 "L1 D-Cache: linelen %i, associativity %i, nsets %i, cachesize %d KBytes",
440 armv7a_cache
->d_u_size
.linelen
,
441 armv7a_cache
->d_u_size
.associativity
,
442 armv7a_cache
->d_u_size
.nsets
,
443 armv7a_cache
->d_u_size
.cachesize
);
445 command_print(cmd_ctx
,
446 "L1 I-Cache: linelen %i, associativity %i, nsets %i, cachesize %d KBytes",
447 armv7a_cache
->i_size
.linelen
,
448 armv7a_cache
->i_size
.associativity
,
449 armv7a_cache
->i_size
.nsets
,
450 armv7a_cache
->i_size
.cachesize
);
451 command_print(cmd_ctx
, "L2 unified cache Base Address 0x%x, %d ways",
452 l2x_cache
->base
, l2x_cache
->way
);
459 static int armv7a_l2x_cache_init(struct target
*target
, uint32_t base
, uint32_t way
)
461 struct armv7a_l2x_cache
*l2x_cache
;
462 struct target_list
*head
= target
->head
;
465 struct armv7a_common
*armv7a
= target_to_armv7a(target
);
466 l2x_cache
= calloc(1, sizeof(struct armv7a_l2x_cache
));
467 l2x_cache
->base
= base
;
468 l2x_cache
->way
= way
;
469 /*LOG_INFO("cache l2 initialized base %x way %d",
470 l2x_cache->base,l2x_cache->way);*/
471 if (armv7a
->armv7a_mmu
.armv7a_cache
.l2_cache
)
473 LOG_INFO("cache l2 already initialized\n");
475 armv7a
->armv7a_mmu
.armv7a_cache
.l2_cache
= (void*) l2x_cache
;
476 /* initialize l1 / l2x cache function */
477 armv7a
->armv7a_mmu
.armv7a_cache
.flush_all_data_cache
478 = armv7a_l2x_flush_all_data
;
479 armv7a
->armv7a_mmu
.armv7a_cache
.display_cache_info
=
480 armv7a_handle_l2x_cache_info_command
;
481 /* initialize all target in this cluster (smp target)*/
482 /* l2 cache must be configured after smp declaration */
483 while(head
!= (struct target_list
*)NULL
)
488 armv7a
= target_to_armv7a(curr
);
489 if (armv7a
->armv7a_mmu
.armv7a_cache
.l2_cache
)
491 LOG_ERROR("smp target : cache l2 already initialized\n");
493 armv7a
->armv7a_mmu
.armv7a_cache
.l2_cache
= (void*) l2x_cache
;
494 armv7a
->armv7a_mmu
.armv7a_cache
.flush_all_data_cache
=
495 armv7a_l2x_flush_all_data
;
496 armv7a
->armv7a_mmu
.armv7a_cache
.display_cache_info
=
497 armv7a_handle_l2x_cache_info_command
;
504 COMMAND_HANDLER(handle_cache_l2x
)
506 struct target
*target
= get_current_target(CMD_CTX
);
510 return ERROR_COMMAND_SYNTAX_ERROR
;
513 //command_print(CMD_CTX, "%s %s", CMD_ARGV[0], CMD_ARGV[1]);
516 COMMAND_PARSE_NUMBER(u32
, CMD_ARGV
[0], base
);
517 COMMAND_PARSE_NUMBER(u32
, CMD_ARGV
[1], way
);
519 /* AP address is in bits 31:24 of DP_SELECT */
520 armv7a_l2x_cache_init(target
, base
, way
);
523 return ERROR_COMMAND_SYNTAX_ERROR
;
529 int armv7a_handle_cache_info_command(struct command_context
*cmd_ctx
,
530 struct armv7a_cache_common
*armv7a_cache
)
532 if (armv7a_cache
->ctype
== -1)
534 command_print(cmd_ctx
, "cache not yet identified");
538 if (armv7a_cache
->display_cache_info
)
539 armv7a_cache
->display_cache_info(cmd_ctx
, armv7a_cache
);
544 /* retrieve core id cluster id */
545 static int armv7a_read_mpidr(struct target
*target
)
547 int retval
= ERROR_FAIL
;
548 struct armv7a_common
*armv7a
= target_to_armv7a(target
);
549 struct arm_dpm
*dpm
= armv7a
->arm
.dpm
;
551 retval
= dpm
->prepare(dpm
);
552 if (retval
!=ERROR_OK
) goto done
;
553 /* MRC p15,0,<Rd>,c0,c0,5; read Multiprocessor ID register*/
555 retval
= dpm
->instr_read_data_r0(dpm
,
556 ARMV4_5_MRC(15, 0, 0, 0, 0, 5),
558 if (retval
!=ERROR_OK
) goto done
;
561 armv7a
->multi_processor_system
= (mpidr
>> 30) & 1;
562 armv7a
->cluster_id
= (mpidr
>> 8) & 0xf;
563 armv7a
->cpu_id
= mpidr
& 0x3;
564 LOG_INFO("%s cluster %x core %x %s", target
->cmd_name
,
567 armv7a
->multi_processor_system
== 0 ? "multi core": "mono core");
571 LOG_ERROR("mpdir not in multiprocessor format");
581 int armv7a_identify_cache(struct target
*target
)
583 /* read cache descriptor */
584 int retval
= ERROR_FAIL
;
585 struct armv7a_common
*armv7a
= target_to_armv7a(target
);
586 struct arm_dpm
*dpm
= armv7a
->arm
.dpm
;
587 uint32_t cache_selected
,clidr
;
588 uint32_t cache_i_reg
, cache_d_reg
;
589 struct armv7a_cache_common
*cache
= &(armv7a
->armv7a_mmu
.armv7a_cache
);
590 armv7a_read_ttbcr(target
);
591 retval
= dpm
->prepare(dpm
);
593 if (retval
!=ERROR_OK
) goto done
;
595 /* mrc p15, 1, r0, c0, c0, 1 @ read clidr */
596 retval
= dpm
->instr_read_data_r0(dpm
,
597 ARMV4_5_MRC(15, 1, 0, 0, 0, 1),
599 if (retval
!=ERROR_OK
) goto done
;
600 clidr
= (clidr
& 0x7000000) >> 23;
601 LOG_INFO("number of cache level %d",clidr
/2 );
604 // FIXME not supported present in cortex A8 and later
606 LOG_ERROR("cache l2 present :not supported");
608 /* retrieve selected cache */
609 /* MRC p15, 2,<Rd>, c0, c0, 0; Read CSSELR */
610 retval
= dpm
->instr_read_data_r0(dpm
,
611 ARMV4_5_MRC(15, 2, 0, 0, 0, 0),
613 if (retval
!=ERROR_OK
) goto done
;
615 retval
= armv7a
->arm
.mrc(target
, 15,
619 if (retval
!=ERROR_OK
) goto done
;
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
) goto done
;
629 /* MRC P15,1,<RT>,C0, C0,0 ;on cortex A9 read CCSIDR */
630 /* [2:0] line size 001 eight word per line */
631 /* [27:13] NumSet 0x7f 16KB, 0xff 32Kbytes, 0x1ff 64Kbytes */
632 retval
= dpm
->instr_read_data_r0(dpm
,
633 ARMV4_5_MRC(15, 1, 0, 0, 0, 0),
635 if (retval
!=ERROR_OK
) goto done
;
637 /* select data cache*/
638 retval
= dpm
->instr_write_data_r0(dpm
,
639 ARMV4_5_MRC(15, 2, 0, 0, 0, 0),
641 if (retval
!=ERROR_OK
) goto done
;
643 retval
= dpm
->instr_read_data_r0(dpm
,
644 ARMV4_5_MRC(15, 1, 0, 0, 0, 0),
646 if (retval
!=ERROR_OK
) goto done
;
648 /* restore selected cache */
649 dpm
->instr_write_data_r0(dpm
,
650 ARMV4_5_MRC(15, 2, 0, 0, 0, 0),
653 if (retval
!= ERROR_OK
) goto done
;
657 cache
->d_u_size
.linelen
= 16 << (cache_d_reg
& 0x7);
658 cache
->d_u_size
.cachesize
= (((cache_d_reg
>> 13) & 0x7fff)+1)/8;
659 cache
->d_u_size
.nsets
= (cache_d_reg
>> 13) & 0x7fff;
660 cache
->d_u_size
.associativity
= ((cache_d_reg
>> 3) & 0x3ff) +1;
661 /* compute info for set way operation on cache */
662 cache
->d_u_size
.index_shift
= (cache_d_reg
& 0x7) + 4;
663 cache
->d_u_size
.index
= (cache_d_reg
>> 13) & 0x7fff;
664 cache
->d_u_size
.way
= ((cache_d_reg
>> 3) & 0x3ff);
665 cache
->d_u_size
.way_shift
= cache
->d_u_size
.way
+1;
668 while(((cache
->d_u_size
.way_shift
>> i
) & 1)!=1) i
++;
669 cache
->d_u_size
.way_shift
= 32-i
;
671 /*LOG_INFO("data cache index %d << %d, way %d << %d",
672 cache->d_u_size.index, cache->d_u_size.index_shift,
673 cache->d_u_size.way, cache->d_u_size.way_shift);
675 LOG_INFO("data cache %d bytes %d KBytes asso %d ways",
676 cache->d_u_size.linelen,
677 cache->d_u_size.cachesize,
678 cache->d_u_size.associativity
680 cache
->i_size
.linelen
= 16 << (cache_i_reg
& 0x7);
681 cache
->i_size
.associativity
= ((cache_i_reg
>> 3) & 0x3ff) +1;
682 cache
->i_size
.nsets
= (cache_i_reg
>> 13) & 0x7fff;
683 cache
->i_size
.cachesize
= (((cache_i_reg
>> 13) & 0x7fff)+1)/8;
684 /* compute info for set way operation on cache */
685 cache
->i_size
.index_shift
= (cache_i_reg
& 0x7) + 4;
686 cache
->i_size
.index
= (cache_i_reg
>> 13) & 0x7fff;
687 cache
->i_size
.way
= ((cache_i_reg
>> 3) & 0x3ff);
688 cache
->i_size
.way_shift
= cache
->i_size
.way
+1;
691 while(((cache
->i_size
.way_shift
>> i
) & 1)!=1) i
++;
692 cache
->i_size
.way_shift
= 32-i
;
694 /*LOG_INFO("instruction cache index %d << %d, way %d << %d",
695 cache->i_size.index, cache->i_size.index_shift,
696 cache->i_size.way, cache->i_size.way_shift);
698 LOG_INFO("instruction cache %d bytes %d KBytes asso %d ways",
699 cache->i_size.linelen,
700 cache->i_size.cachesize,
701 cache->i_size.associativity
703 /* if no l2 cache initialize l1 data cache flush function function */
704 if (armv7a
->armv7a_mmu
.armv7a_cache
.flush_all_data_cache
== NULL
)
706 armv7a
->armv7a_mmu
.armv7a_cache
.display_cache_info
=
707 armv7a_handle_inner_cache_info_command
;
708 armv7a
->armv7a_mmu
.armv7a_cache
.flush_all_data_cache
=
709 armv7a_flush_all_data
;
711 armv7a
->armv7a_mmu
.armv7a_cache
.ctype
= 0;
715 armv7a_read_mpidr(target
);
722 int armv7a_init_arch_info(struct target
*target
, struct armv7a_common
*armv7a
)
724 struct arm
*arm
= &armv7a
->arm
;
725 arm
->arch_info
= armv7a
;
726 target
->arch_info
= &armv7a
->arm
;
727 /* target is useful in all function arm v4 5 compatible */
728 armv7a
->arm
.target
= target
;
729 armv7a
->arm
.common_magic
= ARM_COMMON_MAGIC
;
730 armv7a
->common_magic
= ARMV7_COMMON_MAGIC
;
731 armv7a
->armv7a_mmu
.armv7a_cache
.l2_cache
= NULL
;
732 armv7a
->armv7a_mmu
.armv7a_cache
.ctype
= -1;
733 armv7a
->armv7a_mmu
.armv7a_cache
.flush_all_data_cache
= NULL
;
734 armv7a
->armv7a_mmu
.armv7a_cache
.display_cache_info
= NULL
;
738 int armv7a_arch_state(struct target
*target
)
740 static const char *state
[] =
742 "disabled", "enabled"
745 struct armv7a_common
*armv7a
= target_to_armv7a(target
);
746 struct arm
*arm
= &armv7a
->arm
;
748 if (armv7a
->common_magic
!= ARMV7_COMMON_MAGIC
)
750 LOG_ERROR("BUG: called for a non-ARMv7A target");
751 return ERROR_COMMAND_SYNTAX_ERROR
;
754 arm_arch_state(target
);
756 LOG_USER("MMU: %s, D-Cache: %s, I-Cache: %s",
757 state
[armv7a
->armv7a_mmu
.mmu_enabled
],
758 state
[armv7a
->armv7a_mmu
.armv7a_cache
.d_u_cache_enabled
],
759 state
[armv7a
->armv7a_mmu
.armv7a_cache
.i_cache_enabled
]);
761 if (arm
->core_mode
== ARM_MODE_ABT
)
762 armv7a_show_fault_registers(target
);
763 if (target
->debug_reason
== DBG_REASON_WATCHPOINT
)
764 LOG_USER("Watchpoint triggered at PC %#08x",
765 (unsigned) armv7a
->dpm
.wp_pc
);
770 static const struct command_registration l2_cache_commands
[] = {
773 .handler
= handle_cache_l2x
,
774 .mode
= COMMAND_EXEC
,
775 .help
= "configure l2x cache "
777 .usage
= "[base_addr] [number_of_way]",
779 COMMAND_REGISTRATION_DONE
783 const struct command_registration l2x_cache_command_handlers
[] = {
785 .name
= "cache_config",
786 .mode
= COMMAND_EXEC
,
787 .help
= "cache configuation for a target",
789 .chain
= l2_cache_commands
,
791 COMMAND_REGISTRATION_DONE
795 const struct command_registration armv7a_command_handlers
[] = {
797 .chain
= dap_command_handlers
,
800 .chain
= l2x_cache_command_handlers
,
802 COMMAND_REGISTRATION_DONE