blob: 2ab83be14ffaab2175c8dacfd161adbd6aae9d6d [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
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 Torvalds1da177e2005-04-16 15:20:36 -07007#include <linux/kernel.h>
8#include <linux/mm.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -07009
James Hogan137877e2015-05-19 09:50:32 +010010#include <asm/hazards.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070011#include <asm/mipsregs.h>
12#include <asm/page.h>
13#include <asm/pgtable.h>
Atsushi Nemoto40df3832007-07-12 00:51:00 +090014#include <asm/tlbdebug.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070015
James Hogan3c865dd2015-07-15 16:17:43 +010016void 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());
22 pr_info("EntryHi : %0*lx\n", field, read_c0_entryhi());
23 pr_info("EntryLo0 : %0*lx\n", field, read_c0_entrylo0());
24 pr_info("EntryLo1 : %0*lx\n", field, read_c0_entrylo1());
25 pr_info("Wired : %0x\n", read_c0_wired());
James Hogan5d3c3c72015-07-15 16:17:45 +010026 if (cpu_has_small_pages || cpu_has_rixi || cpu_has_xpa)
27 pr_info("PageGrain: %0x\n", read_c0_pagegrain());
James Hogan3c865dd2015-07-15 16:17:43 +010028 if (cpu_has_htw) {
29 pr_info("PWField : %0*lx\n", field, read_c0_pwfield());
30 pr_info("PWSize : %0*lx\n", field, read_c0_pwsize());
31 pr_info("PWCtl : %0x\n", read_c0_pwctl());
32 }
33}
34
Linus Torvalds1da177e2005-04-16 15:20:36 -070035static inline const char *msk2str(unsigned int mask)
36{
37 switch (mask) {
38 case PM_4K: return "4kb";
39 case PM_16K: return "16kb";
40 case PM_64K: return "64kb";
41 case PM_256K: return "256kb";
Ralf Baechlec52399b2009-04-02 14:07:10 +020042#ifdef CONFIG_CPU_CAVIUM_OCTEON
43 case PM_8K: return "8kb";
44 case PM_32K: return "32kb";
45 case PM_128K: return "128kb";
46 case PM_512K: return "512kb";
47 case PM_2M: return "2Mb";
48 case PM_8M: return "8Mb";
49 case PM_32M: return "32Mb";
50#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -070051#ifndef CONFIG_CPU_VR41XX
52 case PM_1M: return "1Mb";
53 case PM_4M: return "4Mb";
54 case PM_16M: return "16Mb";
55 case PM_64M: return "64Mb";
56 case PM_256M: return "256Mb";
Shinya Kuribayashi542c1022008-10-24 01:27:57 +090057 case PM_1G: return "1Gb";
Linus Torvalds1da177e2005-04-16 15:20:36 -070058#endif
59 }
Atsushi Nemoto4becef12007-06-02 00:21:30 +090060 return "";
Linus Torvalds1da177e2005-04-16 15:20:36 -070061}
62
Atsushi Nemoto69ed25b2007-06-02 00:30:25 +090063static void dump_tlb(int first, int last)
Linus Torvalds1da177e2005-04-16 15:20:36 -070064{
Atsushi Nemoto4becef12007-06-02 00:21:30 +090065 unsigned long s_entryhi, entryhi, asid;
James Hoganc2bc4352015-05-19 09:50:37 +010066 unsigned long long entrylo0, entrylo1, pa;
Ralf Baechle01422ff2012-10-17 01:01:20 +020067 unsigned int s_index, s_pagemask, pagemask, c0, c1, i;
James Hogand1ce483e2015-05-19 09:50:33 +010068#ifdef CONFIG_32BIT
James Hogan24ca1d92015-05-19 09:50:38 +010069 bool xpa = cpu_has_xpa && (read_c0_pagegrain() & PG_ELPA);
70 int pwidth = xpa ? 11 : 8;
71 int vwidth = 8;
James Hogand1ce483e2015-05-19 09:50:33 +010072#else
James Hogan24ca1d92015-05-19 09:50:38 +010073 bool xpa = false;
74 int pwidth = 11;
75 int vwidth = 11;
James Hogand1ce483e2015-05-19 09:50:33 +010076#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -070077
Ralf Baechle01422ff2012-10-17 01:01:20 +020078 s_pagemask = read_c0_pagemask();
Linus Torvalds1da177e2005-04-16 15:20:36 -070079 s_entryhi = read_c0_entryhi();
80 s_index = read_c0_index();
David Daney48c4ac92013-05-13 13:56:44 -070081 asid = s_entryhi & 0xff;
Linus Torvalds1da177e2005-04-16 15:20:36 -070082
83 for (i = first; i <= last; i++) {
84 write_c0_index(i);
James Hogan137877e2015-05-19 09:50:32 +010085 mtc0_tlbr_hazard();
Linus Torvalds1da177e2005-04-16 15:20:36 -070086 tlb_read();
James Hogan137877e2015-05-19 09:50:32 +010087 tlb_read_hazard();
Linus Torvalds1da177e2005-04-16 15:20:36 -070088 pagemask = read_c0_pagemask();
Ralf Baechle70342282013-01-22 12:59:30 +010089 entryhi = read_c0_entryhi();
Linus Torvalds1da177e2005-04-16 15:20:36 -070090 entrylo0 = read_c0_entrylo0();
91 entrylo1 = read_c0_entrylo1();
92
James Hogandecebcc2015-05-19 09:50:36 +010093 /* EHINV bit marks entire entry as invalid */
94 if (cpu_has_tlbinv && entryhi & MIPS_ENTRYHI_EHINV)
95 continue;
James Hogand1ce483e2015-05-19 09:50:33 +010096 /*
97 * Prior to tlbinv, unused entries have a virtual address of
98 * CKSEG0.
99 */
100 if ((entryhi & ~0x1ffffUL) == CKSEG0)
101 continue;
James Hogan48269c72015-05-19 09:50:35 +0100102 /*
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) & MIPS_ENTRYLO_G) &&
110 (entryhi & 0xff) != asid)
James Hogand1ce483e2015-05-19 09:50:33 +0100111 continue;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700112
James Hogand1ce483e2015-05-19 09:50:33 +0100113 /*
114 * Only print entries in use
115 */
116 printk("Index: %2d pgmask=%s ", i, msk2str(pagemask));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700117
James Hogand7f54992015-05-19 09:50:34 +0100118 c0 = (entrylo0 & MIPS_ENTRYLO_C) >> MIPS_ENTRYLO_C_SHIFT;
119 c1 = (entrylo1 & MIPS_ENTRYLO_C) >> MIPS_ENTRYLO_C_SHIFT;
James Hogand1ce483e2015-05-19 09:50:33 +0100120
121 printk("va=%0*lx asid=%02lx\n",
James Hogan24ca1d92015-05-19 09:50:38 +0100122 vwidth, (entryhi & ~0x1fffUL),
James Hogand1ce483e2015-05-19 09:50:33 +0100123 entryhi & 0xff);
James Hoganc2bc4352015-05-19 09:50:37 +0100124 /* RI/XI are in awkward places, so mask them off separately */
125 pa = entrylo0 & ~(MIPS_ENTRYLO_RI | MIPS_ENTRYLO_XI);
James Hogan24ca1d92015-05-19 09:50:38 +0100126 if (xpa)
127 pa |= (unsigned long long)readx_c0_entrylo0() << 30;
James Hoganc2bc4352015-05-19 09:50:37 +0100128 pa = (pa << 6) & PAGE_MASK;
129 printk("\t[");
130 if (cpu_has_rixi)
131 printk("ri=%d xi=%d ",
132 (entrylo0 & MIPS_ENTRYLO_RI) ? 1 : 0,
133 (entrylo0 & MIPS_ENTRYLO_XI) ? 1 : 0);
134 printk("pa=%0*llx c=%d d=%d v=%d g=%d] [",
James Hogan24ca1d92015-05-19 09:50:38 +0100135 pwidth, pa, c0,
James Hogand7f54992015-05-19 09:50:34 +0100136 (entrylo0 & MIPS_ENTRYLO_D) ? 1 : 0,
137 (entrylo0 & MIPS_ENTRYLO_V) ? 1 : 0,
138 (entrylo0 & MIPS_ENTRYLO_G) ? 1 : 0);
James Hoganc2bc4352015-05-19 09:50:37 +0100139 /* RI/XI are in awkward places, so mask them off separately */
140 pa = entrylo1 & ~(MIPS_ENTRYLO_RI | MIPS_ENTRYLO_XI);
James Hogan24ca1d92015-05-19 09:50:38 +0100141 if (xpa)
142 pa |= (unsigned long long)readx_c0_entrylo1() << 30;
James Hoganc2bc4352015-05-19 09:50:37 +0100143 pa = (pa << 6) & PAGE_MASK;
144 if (cpu_has_rixi)
145 printk("ri=%d xi=%d ",
146 (entrylo1 & MIPS_ENTRYLO_RI) ? 1 : 0,
147 (entrylo1 & MIPS_ENTRYLO_XI) ? 1 : 0);
148 printk("pa=%0*llx c=%d d=%d v=%d g=%d]\n",
James Hogan24ca1d92015-05-19 09:50:38 +0100149 pwidth, pa, c1,
James Hogand7f54992015-05-19 09:50:34 +0100150 (entrylo1 & MIPS_ENTRYLO_D) ? 1 : 0,
151 (entrylo1 & MIPS_ENTRYLO_V) ? 1 : 0,
152 (entrylo1 & MIPS_ENTRYLO_G) ? 1 : 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700153 }
154 printk("\n");
155
156 write_c0_entryhi(s_entryhi);
157 write_c0_index(s_index);
Ralf Baechle01422ff2012-10-17 01:01:20 +0200158 write_c0_pagemask(s_pagemask);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700159}
160
161void dump_tlb_all(void)
162{
163 dump_tlb(0, current_cpu_data.tlbsize - 1);
164}