dump_tlb.c 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. /*
  2. * Dump R4x00 TLB for debugging purposes.
  3. *
  4. * Copyright (C) 1994, 1995 by Waldorf Electronics, written by Ralf Baechle.
  5. * Copyright (C) 1999 by Silicon Graphics, Inc.
  6. */
  7. #include <linux/kernel.h>
  8. #include <linux/mm.h>
  9. #include <asm/hazards.h>
  10. #include <asm/mipsregs.h>
  11. #include <asm/page.h>
  12. #include <asm/pgtable.h>
  13. #include <asm/tlbdebug.h>
  14. void dump_tlb_regs(void)
  15. {
  16. const int field = 2 * sizeof(unsigned long);
  17. pr_info("Index : %0x\n", read_c0_index());
  18. pr_info("PageMask : %0x\n", read_c0_pagemask());
  19. pr_info("EntryHi : %0*lx\n", field, read_c0_entryhi());
  20. pr_info("EntryLo0 : %0*lx\n", field, read_c0_entrylo0());
  21. pr_info("EntryLo1 : %0*lx\n", field, read_c0_entrylo1());
  22. pr_info("Wired : %0x\n", read_c0_wired());
  23. pr_info("PageGrain: %0x\n", read_c0_pagegrain());
  24. if (cpu_has_htw) {
  25. pr_info("PWField : %0*lx\n", field, read_c0_pwfield());
  26. pr_info("PWSize : %0*lx\n", field, read_c0_pwsize());
  27. pr_info("PWCtl : %0x\n", read_c0_pwctl());
  28. }
  29. }
  30. static inline const char *msk2str(unsigned int mask)
  31. {
  32. switch (mask) {
  33. case PM_4K: return "4kb";
  34. case PM_16K: return "16kb";
  35. case PM_64K: return "64kb";
  36. case PM_256K: return "256kb";
  37. #ifdef CONFIG_CPU_CAVIUM_OCTEON
  38. case PM_8K: return "8kb";
  39. case PM_32K: return "32kb";
  40. case PM_128K: return "128kb";
  41. case PM_512K: return "512kb";
  42. case PM_2M: return "2Mb";
  43. case PM_8M: return "8Mb";
  44. case PM_32M: return "32Mb";
  45. #endif
  46. #ifndef CONFIG_CPU_VR41XX
  47. case PM_1M: return "1Mb";
  48. case PM_4M: return "4Mb";
  49. case PM_16M: return "16Mb";
  50. case PM_64M: return "64Mb";
  51. case PM_256M: return "256Mb";
  52. case PM_1G: return "1Gb";
  53. #endif
  54. }
  55. return "";
  56. }
  57. static void dump_tlb(int first, int last)
  58. {
  59. unsigned long s_entryhi, entryhi, asid;
  60. unsigned long long entrylo0, entrylo1, pa;
  61. unsigned int s_index, s_pagemask, pagemask, c0, c1, i;
  62. #ifdef CONFIG_32BIT
  63. bool xpa = cpu_has_xpa && (read_c0_pagegrain() & PG_ELPA);
  64. int pwidth = xpa ? 11 : 8;
  65. int vwidth = 8;
  66. #else
  67. bool xpa = false;
  68. int pwidth = 11;
  69. int vwidth = 11;
  70. #endif
  71. s_pagemask = read_c0_pagemask();
  72. s_entryhi = read_c0_entryhi();
  73. s_index = read_c0_index();
  74. asid = s_entryhi & 0xff;
  75. for (i = first; i <= last; i++) {
  76. write_c0_index(i);
  77. mtc0_tlbr_hazard();
  78. tlb_read();
  79. tlb_read_hazard();
  80. pagemask = read_c0_pagemask();
  81. entryhi = read_c0_entryhi();
  82. entrylo0 = read_c0_entrylo0();
  83. entrylo1 = read_c0_entrylo1();
  84. /* EHINV bit marks entire entry as invalid */
  85. if (cpu_has_tlbinv && entryhi & MIPS_ENTRYHI_EHINV)
  86. continue;
  87. /*
  88. * Prior to tlbinv, unused entries have a virtual address of
  89. * CKSEG0.
  90. */
  91. if ((entryhi & ~0x1ffffUL) == CKSEG0)
  92. continue;
  93. /*
  94. * ASID takes effect in absence of G (global) bit.
  95. * We check both G bits, even though architecturally they should
  96. * match one another, because some revisions of the SB1 core may
  97. * leave only a single G bit set after a machine check exception
  98. * due to duplicate TLB entry.
  99. */
  100. if (!((entrylo0 | entrylo1) & MIPS_ENTRYLO_G) &&
  101. (entryhi & 0xff) != asid)
  102. continue;
  103. /*
  104. * Only print entries in use
  105. */
  106. printk("Index: %2d pgmask=%s ", i, msk2str(pagemask));
  107. c0 = (entrylo0 & MIPS_ENTRYLO_C) >> MIPS_ENTRYLO_C_SHIFT;
  108. c1 = (entrylo1 & MIPS_ENTRYLO_C) >> MIPS_ENTRYLO_C_SHIFT;
  109. printk("va=%0*lx asid=%02lx\n",
  110. vwidth, (entryhi & ~0x1fffUL),
  111. entryhi & 0xff);
  112. /* RI/XI are in awkward places, so mask them off separately */
  113. pa = entrylo0 & ~(MIPS_ENTRYLO_RI | MIPS_ENTRYLO_XI);
  114. if (xpa)
  115. pa |= (unsigned long long)readx_c0_entrylo0() << 30;
  116. pa = (pa << 6) & PAGE_MASK;
  117. printk("\t[");
  118. if (cpu_has_rixi)
  119. printk("ri=%d xi=%d ",
  120. (entrylo0 & MIPS_ENTRYLO_RI) ? 1 : 0,
  121. (entrylo0 & MIPS_ENTRYLO_XI) ? 1 : 0);
  122. printk("pa=%0*llx c=%d d=%d v=%d g=%d] [",
  123. pwidth, pa, c0,
  124. (entrylo0 & MIPS_ENTRYLO_D) ? 1 : 0,
  125. (entrylo0 & MIPS_ENTRYLO_V) ? 1 : 0,
  126. (entrylo0 & MIPS_ENTRYLO_G) ? 1 : 0);
  127. /* RI/XI are in awkward places, so mask them off separately */
  128. pa = entrylo1 & ~(MIPS_ENTRYLO_RI | MIPS_ENTRYLO_XI);
  129. if (xpa)
  130. pa |= (unsigned long long)readx_c0_entrylo1() << 30;
  131. pa = (pa << 6) & PAGE_MASK;
  132. if (cpu_has_rixi)
  133. printk("ri=%d xi=%d ",
  134. (entrylo1 & MIPS_ENTRYLO_RI) ? 1 : 0,
  135. (entrylo1 & MIPS_ENTRYLO_XI) ? 1 : 0);
  136. printk("pa=%0*llx c=%d d=%d v=%d g=%d]\n",
  137. pwidth, pa, c1,
  138. (entrylo1 & MIPS_ENTRYLO_D) ? 1 : 0,
  139. (entrylo1 & MIPS_ENTRYLO_V) ? 1 : 0,
  140. (entrylo1 & MIPS_ENTRYLO_G) ? 1 : 0);
  141. }
  142. printk("\n");
  143. write_c0_entryhi(s_entryhi);
  144. write_c0_index(s_index);
  145. write_c0_pagemask(s_pagemask);
  146. }
  147. void dump_tlb_all(void)
  148. {
  149. dump_tlb(0, current_cpu_data.tlbsize - 1);
  150. }