blob: 17d05caa776dc1eba9cafb75532ace907fdce967 [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 Hogand1ce483e2015-05-19 09:50:33 +010070 /*
71 * Prior to tlbinv, unused entries have a virtual address of
72 * CKSEG0.
73 */
74 if ((entryhi & ~0x1ffffUL) == CKSEG0)
75 continue;
76 if ((entryhi & 0xff) != asid)
77 continue;
Linus Torvalds1da177e2005-04-16 15:20:36 -070078
James Hogand1ce483e2015-05-19 09:50:33 +010079 /*
80 * Only print entries in use
81 */
82 printk("Index: %2d pgmask=%s ", i, msk2str(pagemask));
Linus Torvalds1da177e2005-04-16 15:20:36 -070083
James Hogand1ce483e2015-05-19 09:50:33 +010084 c0 = (entrylo0 >> 3) & 7;
85 c1 = (entrylo1 >> 3) & 7;
86
87 printk("va=%0*lx asid=%02lx\n",
88 width, (entryhi & ~0x1fffUL),
89 entryhi & 0xff);
90 printk("\t[pa=%0*llx c=%d d=%d v=%d g=%d] ",
91 width,
92 (entrylo0 << 6) & PAGE_MASK, c0,
93 (entrylo0 & 4) ? 1 : 0,
94 (entrylo0 & 2) ? 1 : 0,
95 (entrylo0 & 1) ? 1 : 0);
96 printk("[pa=%0*llx c=%d d=%d v=%d g=%d]\n",
97 width,
98 (entrylo1 << 6) & PAGE_MASK, c1,
99 (entrylo1 & 4) ? 1 : 0,
100 (entrylo1 & 2) ? 1 : 0,
101 (entrylo1 & 1) ? 1 : 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700102 }
103 printk("\n");
104
105 write_c0_entryhi(s_entryhi);
106 write_c0_index(s_index);
Ralf Baechle01422ff2012-10-17 01:01:20 +0200107 write_c0_pagemask(s_pagemask);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700108}
109
110void dump_tlb_all(void)
111{
112 dump_tlb(0, current_cpu_data.tlbsize - 1);
113}