blob: 3bcdd53c832fbef2258531a4909c86f4c43ee7e3 [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
16static 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 Baechlec52399b2009-04-02 14:07:10 +020023#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 Torvalds1da177e2005-04-16 15:20:36 -070032#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 Kuribayashi542c1022008-10-24 01:27:57 +090038 case PM_1G: return "1Gb";
Linus Torvalds1da177e2005-04-16 15:20:36 -070039#endif
40 }
Atsushi Nemoto4becef12007-06-02 00:21:30 +090041 return "";
Linus Torvalds1da177e2005-04-16 15:20:36 -070042}
43
Atsushi Nemoto69ed25b2007-06-02 00:30:25 +090044static void dump_tlb(int first, int last)
Linus Torvalds1da177e2005-04-16 15:20:36 -070045{
Atsushi Nemoto4becef12007-06-02 00:21:30 +090046 unsigned long s_entryhi, entryhi, asid;
47 unsigned long long entrylo0, entrylo1;
Ralf Baechle01422ff2012-10-17 01:01:20 +020048 unsigned int s_index, s_pagemask, pagemask, c0, c1, i;
James Hogand1ce483e2015-05-19 09:50:33 +010049#ifdef CONFIG_32BIT
50 int width = 8;
51#else
52 int width = 11;
53#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -070054
Ralf Baechle01422ff2012-10-17 01:01:20 +020055 s_pagemask = read_c0_pagemask();
Linus Torvalds1da177e2005-04-16 15:20:36 -070056 s_entryhi = read_c0_entryhi();
57 s_index = read_c0_index();
David Daney48c4ac92013-05-13 13:56:44 -070058 asid = s_entryhi & 0xff;
Linus Torvalds1da177e2005-04-16 15:20:36 -070059
60 for (i = first; i <= last; i++) {
61 write_c0_index(i);
James Hogan137877e2015-05-19 09:50:32 +010062 mtc0_tlbr_hazard();
Linus Torvalds1da177e2005-04-16 15:20:36 -070063 tlb_read();
James Hogan137877e2015-05-19 09:50:32 +010064 tlb_read_hazard();
Linus Torvalds1da177e2005-04-16 15:20:36 -070065 pagemask = read_c0_pagemask();
Ralf Baechle70342282013-01-22 12:59:30 +010066 entryhi = read_c0_entryhi();
Linus Torvalds1da177e2005-04-16 15:20:36 -070067 entrylo0 = read_c0_entrylo0();
68 entrylo1 = read_c0_entrylo1();
69
James Hogandecebcc2015-05-19 09:50:36 +010070 /* EHINV bit marks entire entry as invalid */
71 if (cpu_has_tlbinv && entryhi & MIPS_ENTRYHI_EHINV)
72 continue;
James Hogand1ce483e2015-05-19 09:50:33 +010073 /*
74 * Prior to tlbinv, unused entries have a virtual address of
75 * CKSEG0.
76 */
77 if ((entryhi & ~0x1ffffUL) == CKSEG0)
78 continue;
James Hogan48269c72015-05-19 09:50:35 +010079 /*
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 Hogand1ce483e2015-05-19 09:50:33 +010088 continue;
Linus Torvalds1da177e2005-04-16 15:20:36 -070089
James Hogand1ce483e2015-05-19 09:50:33 +010090 /*
91 * Only print entries in use
92 */
93 printk("Index: %2d pgmask=%s ", i, msk2str(pagemask));
Linus Torvalds1da177e2005-04-16 15:20:36 -070094
James Hogand7f54992015-05-19 09:50:34 +010095 c0 = (entrylo0 & MIPS_ENTRYLO_C) >> MIPS_ENTRYLO_C_SHIFT;
96 c1 = (entrylo1 & MIPS_ENTRYLO_C) >> MIPS_ENTRYLO_C_SHIFT;
James Hogand1ce483e2015-05-19 09:50:33 +010097
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 Hogand7f54992015-05-19 09:50:34 +0100104 (entrylo0 & MIPS_ENTRYLO_D) ? 1 : 0,
105 (entrylo0 & MIPS_ENTRYLO_V) ? 1 : 0,
106 (entrylo0 & MIPS_ENTRYLO_G) ? 1 : 0);
James Hogand1ce483e2015-05-19 09:50:33 +0100107 printk("[pa=%0*llx c=%d d=%d v=%d g=%d]\n",
108 width,
109 (entrylo1 << 6) & PAGE_MASK, c1,
James Hogand7f54992015-05-19 09:50:34 +0100110 (entrylo1 & MIPS_ENTRYLO_D) ? 1 : 0,
111 (entrylo1 & MIPS_ENTRYLO_V) ? 1 : 0,
112 (entrylo1 & MIPS_ENTRYLO_G) ? 1 : 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700113 }
114 printk("\n");
115
116 write_c0_entryhi(s_entryhi);
117 write_c0_index(s_index);
Ralf Baechle01422ff2012-10-17 01:01:20 +0200118 write_c0_pagemask(s_pagemask);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700119}
120
121void dump_tlb_all(void)
122{
123 dump_tlb(0, current_cpu_data.tlbsize - 1);
124}