dump_tlb.c 4.7 KB

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