dump_tlb.c 5.2 KB

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