dump_tlb.c 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  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/config.h>
  8. #include <linux/kernel.h>
  9. #include <linux/mm.h>
  10. #include <linux/sched.h>
  11. #include <linux/string.h>
  12. #include <asm/bootinfo.h>
  13. #include <asm/cachectl.h>
  14. #include <asm/cpu.h>
  15. #include <asm/mipsregs.h>
  16. #include <asm/page.h>
  17. #include <asm/pgtable.h>
  18. static inline const char *msk2str(unsigned int mask)
  19. {
  20. switch (mask) {
  21. case PM_4K: return "4kb";
  22. case PM_16K: return "16kb";
  23. case PM_64K: return "64kb";
  24. case PM_256K: return "256kb";
  25. #ifndef CONFIG_CPU_VR41XX
  26. case PM_1M: return "1Mb";
  27. case PM_4M: return "4Mb";
  28. case PM_16M: return "16Mb";
  29. case PM_64M: return "64Mb";
  30. case PM_256M: return "256Mb";
  31. #endif
  32. }
  33. return "unknown";
  34. }
  35. #define BARRIER() \
  36. __asm__ __volatile__( \
  37. ".set\tnoreorder\n\t" \
  38. "nop;nop;nop;nop;nop;nop;nop\n\t" \
  39. ".set\treorder");
  40. void dump_tlb(int first, int last)
  41. {
  42. unsigned int pagemask, c0, c1, asid;
  43. unsigned long long entrylo0, entrylo1;
  44. unsigned long entryhi;
  45. int i;
  46. asid = read_c0_entryhi() & 0xff;
  47. printk("\n");
  48. for (i = first; i <= last; i++) {
  49. write_c0_index(i);
  50. BARRIER();
  51. tlb_read();
  52. BARRIER();
  53. pagemask = read_c0_pagemask();
  54. entryhi = read_c0_entryhi();
  55. entrylo0 = read_c0_entrylo0();
  56. entrylo1 = read_c0_entrylo1();
  57. /* Unused entries have a virtual address in KSEG0. */
  58. if ((entryhi & 0xf0000000) != 0x80000000
  59. && (entryhi & 0xff) == asid) {
  60. /*
  61. * Only print entries in use
  62. */
  63. printk("Index: %2d pgmask=%s ", i, msk2str(pagemask));
  64. c0 = (entrylo0 >> 3) & 7;
  65. c1 = (entrylo1 >> 3) & 7;
  66. printk("va=%08lx asid=%02lx\n",
  67. (entryhi & 0xffffe000), (entryhi & 0xff));
  68. printk("\t\t\t[pa=%08Lx c=%d d=%d v=%d g=%Ld]\n",
  69. (entrylo0 << 6) & PAGE_MASK, c0,
  70. (entrylo0 & 4) ? 1 : 0,
  71. (entrylo0 & 2) ? 1 : 0,
  72. (entrylo0 & 1));
  73. printk("\t\t\t[pa=%08Lx c=%d d=%d v=%d g=%Ld]\n",
  74. (entrylo1 << 6) & PAGE_MASK, c1,
  75. (entrylo1 & 4) ? 1 : 0,
  76. (entrylo1 & 2) ? 1 : 0,
  77. (entrylo1 & 1));
  78. printk("\n");
  79. }
  80. }
  81. write_c0_entryhi(asid);
  82. }
  83. void dump_tlb_all(void)
  84. {
  85. dump_tlb(0, current_cpu_data.tlbsize - 1);
  86. }
  87. void dump_tlb_wired(void)
  88. {
  89. int wired;
  90. wired = read_c0_wired();
  91. printk("Wired: %d", wired);
  92. dump_tlb(0, read_c0_wired());
  93. }
  94. void dump_tlb_addr(unsigned long addr)
  95. {
  96. unsigned int flags, oldpid;
  97. int index;
  98. local_irq_save(flags);
  99. oldpid = read_c0_entryhi() & 0xff;
  100. BARRIER();
  101. write_c0_entryhi((addr & PAGE_MASK) | oldpid);
  102. BARRIER();
  103. tlb_probe();
  104. BARRIER();
  105. index = read_c0_index();
  106. write_c0_entryhi(oldpid);
  107. local_irq_restore(flags);
  108. if (index < 0) {
  109. printk("No entry for address 0x%08lx in TLB\n", addr);
  110. return;
  111. }
  112. printk("Entry %d maps address 0x%08lx\n", index, addr);
  113. dump_tlb(index, index);
  114. }
  115. void dump_tlb_nonwired(void)
  116. {
  117. dump_tlb(read_c0_wired(), current_cpu_data.tlbsize - 1);
  118. }
  119. void dump_list_process(struct task_struct *t, void *address)
  120. {
  121. pgd_t *page_dir, *pgd;
  122. pmd_t *pmd;
  123. pte_t *pte, page;
  124. unsigned long addr, val;
  125. addr = (unsigned long) address;
  126. printk("Addr == %08lx\n", addr);
  127. printk("task == %8p\n", t);
  128. printk("task->mm == %8p\n", t->mm);
  129. //printk("tasks->mm.pgd == %08x\n", (unsigned int) t->mm->pgd);
  130. if (addr > KSEG0)
  131. page_dir = pgd_offset_k(0);
  132. else
  133. page_dir = pgd_offset(t->mm, 0);
  134. printk("page_dir == %08x\n", (unsigned int) page_dir);
  135. if (addr > KSEG0)
  136. pgd = pgd_offset_k(addr);
  137. else
  138. pgd = pgd_offset(t->mm, addr);
  139. printk("pgd == %08x, ", (unsigned int) pgd);
  140. pmd = pmd_offset(pgd, addr);
  141. printk("pmd == %08x, ", (unsigned int) pmd);
  142. pte = pte_offset(pmd, addr);
  143. printk("pte == %08x, ", (unsigned int) pte);
  144. page = *pte;
  145. #ifdef CONFIG_64BIT_PHYS_ADDR
  146. printk("page == %08Lx\n", pte_val(page));
  147. #else
  148. printk("page == %08lx\n", pte_val(page));
  149. #endif
  150. val = pte_val(page);
  151. if (val & _PAGE_PRESENT) printk("present ");
  152. if (val & _PAGE_READ) printk("read ");
  153. if (val & _PAGE_WRITE) printk("write ");
  154. if (val & _PAGE_ACCESSED) printk("accessed ");
  155. if (val & _PAGE_MODIFIED) printk("modified ");
  156. if (val & _PAGE_R4KBUG) printk("r4kbug ");
  157. if (val & _PAGE_GLOBAL) printk("global ");
  158. if (val & _PAGE_VALID) printk("valid ");
  159. printk("\n");
  160. }
  161. void dump_list_current(void *address)
  162. {
  163. dump_list_process(current, address);
  164. }
  165. unsigned int vtop(void *address)
  166. {
  167. pgd_t *pgd;
  168. pmd_t *pmd;
  169. pte_t *pte;
  170. unsigned int addr, paddr;
  171. addr = (unsigned long) address;
  172. pgd = pgd_offset(current->mm, addr);
  173. pmd = pmd_offset(pgd, addr);
  174. pte = pte_offset(pmd, addr);
  175. paddr = (KSEG1 | (unsigned int) pte_val(*pte)) & PAGE_MASK;
  176. paddr |= (addr & ~PAGE_MASK);
  177. return paddr;
  178. }
  179. void dump16(unsigned long *p)
  180. {
  181. int i;
  182. for (i = 0; i < 8; i++) {
  183. printk("*%08lx == %08lx, ", (unsigned long)p, *p);
  184. p++;
  185. printk("*%08lx == %08lx\n", (unsigned long)p, *p);
  186. p++;
  187. }
  188. }