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 | |
| 16 | static inline const char *msk2str(unsigned int mask) |
| 17 | { |
| 18 | switch (mask) { |
| 19 | case PM_4K: return "4kb"; |
| 20 | case PM_16K: return "16kb"; |
| 21 | case PM_64K: return "64kb"; |
| 22 | case PM_256K: return "256kb"; |
Ralf Baechle | c52399b | 2009-04-02 14:07:10 +0200 | [diff] [blame] | 23 | #ifdef CONFIG_CPU_CAVIUM_OCTEON |
| 24 | case PM_8K: return "8kb"; |
| 25 | case PM_32K: return "32kb"; |
| 26 | case PM_128K: return "128kb"; |
| 27 | case PM_512K: return "512kb"; |
| 28 | case PM_2M: return "2Mb"; |
| 29 | case PM_8M: return "8Mb"; |
| 30 | case PM_32M: return "32Mb"; |
| 31 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 32 | #ifndef CONFIG_CPU_VR41XX |
| 33 | case PM_1M: return "1Mb"; |
| 34 | case PM_4M: return "4Mb"; |
| 35 | case PM_16M: return "16Mb"; |
| 36 | case PM_64M: return "64Mb"; |
| 37 | case PM_256M: return "256Mb"; |
Shinya Kuribayashi | 542c102 | 2008-10-24 01:27:57 +0900 | [diff] [blame] | 38 | case PM_1G: return "1Gb"; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 39 | #endif |
| 40 | } |
Atsushi Nemoto | 4becef1 | 2007-06-02 00:21:30 +0900 | [diff] [blame] | 41 | return ""; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 42 | } |
| 43 | |
Atsushi Nemoto | 69ed25b | 2007-06-02 00:30:25 +0900 | [diff] [blame] | 44 | static void dump_tlb(int first, int last) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 45 | { |
Atsushi Nemoto | 4becef1 | 2007-06-02 00:21:30 +0900 | [diff] [blame] | 46 | unsigned long s_entryhi, entryhi, asid; |
| 47 | unsigned long long entrylo0, entrylo1; |
Ralf Baechle | 01422ff | 2012-10-17 01:01:20 +0200 | [diff] [blame] | 48 | unsigned int s_index, s_pagemask, pagemask, c0, c1, i; |
James Hogan | d1ce483e | 2015-05-19 09:50:33 +0100 | [diff] [blame] | 49 | #ifdef CONFIG_32BIT |
| 50 | int width = 8; |
| 51 | #else |
| 52 | int width = 11; |
| 53 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 54 | |
Ralf Baechle | 01422ff | 2012-10-17 01:01:20 +0200 | [diff] [blame] | 55 | s_pagemask = read_c0_pagemask(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 56 | s_entryhi = read_c0_entryhi(); |
| 57 | s_index = read_c0_index(); |
David Daney | 48c4ac9 | 2013-05-13 13:56:44 -0700 | [diff] [blame] | 58 | asid = s_entryhi & 0xff; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 59 | |
| 60 | for (i = first; i <= last; i++) { |
| 61 | write_c0_index(i); |
James Hogan | 137877e | 2015-05-19 09:50:32 +0100 | [diff] [blame] | 62 | mtc0_tlbr_hazard(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 63 | tlb_read(); |
James Hogan | 137877e | 2015-05-19 09:50:32 +0100 | [diff] [blame] | 64 | tlb_read_hazard(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 65 | pagemask = read_c0_pagemask(); |
Ralf Baechle | 7034228 | 2013-01-22 12:59:30 +0100 | [diff] [blame] | 66 | entryhi = read_c0_entryhi(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 67 | entrylo0 = read_c0_entrylo0(); |
| 68 | entrylo1 = read_c0_entrylo1(); |
| 69 | |
James Hogan | decebcc | 2015-05-19 09:50:36 +0100 | [diff] [blame^] | 70 | /* EHINV bit marks entire entry as invalid */ |
| 71 | if (cpu_has_tlbinv && entryhi & MIPS_ENTRYHI_EHINV) |
| 72 | continue; |
James Hogan | d1ce483e | 2015-05-19 09:50:33 +0100 | [diff] [blame] | 73 | /* |
| 74 | * Prior to tlbinv, unused entries have a virtual address of |
| 75 | * CKSEG0. |
| 76 | */ |
| 77 | if ((entryhi & ~0x1ffffUL) == CKSEG0) |
| 78 | continue; |
James Hogan | 48269c7 | 2015-05-19 09:50:35 +0100 | [diff] [blame] | 79 | /* |
| 80 | * ASID takes effect in absence of G (global) bit. |
| 81 | * We check both G bits, even though architecturally they should |
| 82 | * match one another, because some revisions of the SB1 core may |
| 83 | * leave only a single G bit set after a machine check exception |
| 84 | * due to duplicate TLB entry. |
| 85 | */ |
| 86 | if (!((entrylo0 | entrylo1) & MIPS_ENTRYLO_G) && |
| 87 | (entryhi & 0xff) != asid) |
James Hogan | d1ce483e | 2015-05-19 09:50:33 +0100 | [diff] [blame] | 88 | continue; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 89 | |
James Hogan | d1ce483e | 2015-05-19 09:50:33 +0100 | [diff] [blame] | 90 | /* |
| 91 | * Only print entries in use |
| 92 | */ |
| 93 | printk("Index: %2d pgmask=%s ", i, msk2str(pagemask)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 94 | |
James Hogan | d7f5499 | 2015-05-19 09:50:34 +0100 | [diff] [blame] | 95 | c0 = (entrylo0 & MIPS_ENTRYLO_C) >> MIPS_ENTRYLO_C_SHIFT; |
| 96 | c1 = (entrylo1 & MIPS_ENTRYLO_C) >> MIPS_ENTRYLO_C_SHIFT; |
James Hogan | d1ce483e | 2015-05-19 09:50:33 +0100 | [diff] [blame] | 97 | |
| 98 | printk("va=%0*lx asid=%02lx\n", |
| 99 | width, (entryhi & ~0x1fffUL), |
| 100 | entryhi & 0xff); |
| 101 | printk("\t[pa=%0*llx c=%d d=%d v=%d g=%d] ", |
| 102 | width, |
| 103 | (entrylo0 << 6) & PAGE_MASK, c0, |
James Hogan | d7f5499 | 2015-05-19 09:50:34 +0100 | [diff] [blame] | 104 | (entrylo0 & MIPS_ENTRYLO_D) ? 1 : 0, |
| 105 | (entrylo0 & MIPS_ENTRYLO_V) ? 1 : 0, |
| 106 | (entrylo0 & MIPS_ENTRYLO_G) ? 1 : 0); |
James Hogan | d1ce483e | 2015-05-19 09:50:33 +0100 | [diff] [blame] | 107 | printk("[pa=%0*llx c=%d d=%d v=%d g=%d]\n", |
| 108 | width, |
| 109 | (entrylo1 << 6) & PAGE_MASK, c1, |
James Hogan | d7f5499 | 2015-05-19 09:50:34 +0100 | [diff] [blame] | 110 | (entrylo1 & MIPS_ENTRYLO_D) ? 1 : 0, |
| 111 | (entrylo1 & MIPS_ENTRYLO_V) ? 1 : 0, |
| 112 | (entrylo1 & MIPS_ENTRYLO_G) ? 1 : 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 113 | } |
| 114 | printk("\n"); |
| 115 | |
| 116 | write_c0_entryhi(s_entryhi); |
| 117 | write_c0_index(s_index); |
Ralf Baechle | 01422ff | 2012-10-17 01:01:20 +0200 | [diff] [blame] | 118 | write_c0_pagemask(s_pagemask); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 119 | } |
| 120 | |
| 121 | void dump_tlb_all(void) |
| 122 | { |
| 123 | dump_tlb(0, current_cpu_data.tlbsize - 1); |
| 124 | } |