cmd_cache_dump.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. /*
  2. * U-Boot - cmd_cache_dump.c
  3. *
  4. * Copyright (c) 2007-2008 Analog Devices Inc.
  5. *
  6. * Licensed under the GPL-2 or later.
  7. */
  8. #include <config.h>
  9. #include <common.h>
  10. #include <command.h>
  11. #include <console.h>
  12. #include <asm/blackfin.h>
  13. #include <asm/mach-common/bits/mpu.h>
  14. static int check_limit(const char *type, size_t start_limit, size_t end_limit, size_t start, size_t end)
  15. {
  16. if (start >= start_limit && start <= end_limit && \
  17. end <= end_limit && end >= start_limit && \
  18. start <= end)
  19. return 0;
  20. printf("%s limit violation: %zu <= (user:%zu) <= (user:%zu) <= %zu\n",
  21. type, start_limit, start, end, end_limit);
  22. return 1;
  23. }
  24. int do_icache_dump(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
  25. {
  26. int cache_status = icache_status();
  27. if (cache_status)
  28. icache_disable();
  29. uint32_t cmd_base, tag, cache_upper, cache_lower;
  30. size_t way, way_start = 0, way_end = 3;
  31. size_t sbnk, sbnk_start = 0, sbnk_end = 3;
  32. size_t set, set_start = 0, set_end = 31;
  33. size_t dw;
  34. if (argc > 1) {
  35. way_start = way_end = simple_strtoul(argv[1], NULL, 10);
  36. if (argc > 2) {
  37. sbnk_start = sbnk_end = simple_strtoul(argv[2], NULL, 10);
  38. if (argc > 3)
  39. set_start = set_end = simple_strtoul(argv[3], NULL, 10);
  40. }
  41. }
  42. if (check_limit("way", 0, 3, way_start, way_end) || \
  43. check_limit("subbank", 0, 3, sbnk_start, sbnk_end) || \
  44. check_limit("set", 0, 31, set_start, set_end))
  45. return 1;
  46. puts("Way:Subbank:Set: [valid-tag lower upper] {invalid-tag lower upper}...\n");
  47. for (way = way_start; way <= way_end; ++way) {
  48. for (sbnk = sbnk_start; sbnk <= sbnk_end; ++sbnk) {
  49. for (set = set_start; set <= set_end; ++set) {
  50. printf("%zu:%zu:%2zu: ", way, sbnk, set);
  51. for (dw = 0; dw < 4; ++dw) {
  52. if (ctrlc())
  53. return 1;
  54. cmd_base = \
  55. (way << 26) | \
  56. (sbnk << 16) | \
  57. (set << 5) | \
  58. (dw << 3);
  59. /* first read the tag */
  60. bfin_write_ITEST_COMMAND(cmd_base | 0x0);
  61. SSYNC();
  62. tag = bfin_read_ITEST_DATA0();
  63. printf("%c%08x ", (tag & 0x1 ? ' ' : '{'), tag);
  64. /* grab the data at this loc */
  65. bfin_write_ITEST_COMMAND(cmd_base | 0x4);
  66. SSYNC();
  67. cache_lower = bfin_read_ITEST_DATA0();
  68. cache_upper = bfin_read_ITEST_DATA1();
  69. printf("%08x %08x%c ", cache_lower, cache_upper, (tag & 0x1 ? ' ' : '}'));
  70. }
  71. puts("\n");
  72. }
  73. }
  74. }
  75. if (cache_status)
  76. icache_enable();
  77. return 0;
  78. }
  79. U_BOOT_CMD(icache_dump, 4, 0, do_icache_dump,
  80. "icache_dump - dump current instruction cache\n",
  81. "[way] [subbank] [set]");
  82. int do_dcache_dump(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
  83. {
  84. u32 way, bank, subbank, set;
  85. u32 status, addr;
  86. u32 dmem_ctl = bfin_read_DMEM_CONTROL();
  87. for (bank = 0; bank < 2; ++bank) {
  88. if (!(dmem_ctl & (1 << (DMC1_P - bank))))
  89. continue;
  90. for (way = 0; way < 2; ++way)
  91. for (subbank = 0; subbank < 4; ++subbank) {
  92. printf("%i:%i:%i:\t", bank, way, subbank);
  93. for (set = 0; set < 64; ++set) {
  94. if (ctrlc())
  95. return 1;
  96. /* retrieve a cache tag */
  97. bfin_write_DTEST_COMMAND(
  98. way << 26 |
  99. bank << 23 |
  100. subbank << 16 |
  101. set << 5
  102. );
  103. CSYNC();
  104. status = bfin_read_DTEST_DATA0();
  105. /* construct the address using the tag */
  106. addr = (status & 0xFFFFC800) | (subbank << 12) | (set << 5);
  107. /* show it */
  108. if (set && !(set % 4))
  109. puts("\n\t");
  110. printf("%c%08x%c%08x%c ", (status & 0x1 ? '[' : '{'), status, (status & 0x2 ? 'd' : ' '), addr, (status & 0x1 ? ']' : '}'));
  111. }
  112. puts("\n");
  113. }
  114. }
  115. return 0;
  116. }
  117. U_BOOT_CMD(dcache_dump, 4, 0, do_dcache_dump,
  118. "dcache_dump - dump current data cache\n",
  119. "[bank] [way] [subbank] [set]");