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