blob: b97d9c5d83230c597fa8e36df2f85a4c0d3930df [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001// SPDX-License-Identifier: GPL-2.0
Linus Torvalds1da177e2005-04-16 15:20:36 -07002/*
3 * Dump R3000 TLB for debugging purposes.
4 *
5 * Copyright (C) 1994, 1995 by Waldorf Electronics, written by Ralf Baechle.
6 * Copyright (C) 1999 by Silicon Graphics, Inc.
7 * Copyright (C) 1999 by Harald Koerfgen
8 */
9#include <linux/kernel.h>
10#include <linux/mm.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070011
Linus Torvalds1da177e2005-04-16 15:20:36 -070012#include <asm/mipsregs.h>
Isamu Mogi80e8bd22014-10-30 22:07:37 +090013#include <asm/mmu_context.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070014#include <asm/page.h>
15#include <asm/pgtable.h>
Atsushi Nemoto40df3832007-07-12 00:51:00 +090016#include <asm/tlbdebug.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070017
James Hogan3c865dd2015-07-15 16:17:43 +010018extern int r3k_have_wired_reg;
19
20void dump_tlb_regs(void)
21{
22 pr_info("Index : %0x\n", read_c0_index());
23 pr_info("EntryHi : %0lx\n", read_c0_entryhi());
24 pr_info("EntryLo : %0lx\n", read_c0_entrylo0());
25 if (r3k_have_wired_reg)
26 pr_info("Wired : %0x\n", read_c0_wired());
27}
28
Atsushi Nemoto69ed25b2007-06-02 00:30:25 +090029static void dump_tlb(int first, int last)
Linus Torvalds1da177e2005-04-16 15:20:36 -070030{
31 int i;
32 unsigned int asid;
Paul Burton4edf00a2016-05-06 14:36:23 +010033 unsigned long entryhi, entrylo0, asid_mask;
Linus Torvalds1da177e2005-04-16 15:20:36 -070034
Paul Burton4edf00a2016-05-06 14:36:23 +010035 asid_mask = cpu_asid_mask(&current_cpu_data);
36 asid = read_c0_entryhi() & asid_mask;
Linus Torvalds1da177e2005-04-16 15:20:36 -070037
38 for (i = first; i <= last; i++) {
39 write_c0_index(i<<8);
40 __asm__ __volatile__(
41 ".set\tnoreorder\n\t"
42 "tlbr\n\t"
43 "nop\n\t"
44 ".set\treorder");
Ralf Baechle70342282013-01-22 12:59:30 +010045 entryhi = read_c0_entryhi();
Linus Torvalds1da177e2005-04-16 15:20:36 -070046 entrylo0 = read_c0_entrylo0();
47
48 /* Unused entries have a virtual address of KSEG0. */
James Hogan48269c72015-05-19 09:50:35 +010049 if ((entryhi & PAGE_MASK) != KSEG0 &&
50 (entrylo0 & R3K_ENTRYLO_G ||
Paul Burton4edf00a2016-05-06 14:36:23 +010051 (entryhi & asid_mask) == asid)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -070052 /*
53 * Only print entries in use
54 */
55 printk("Index: %2d ", i);
56
James Hogan8a984952016-10-21 20:06:40 +010057 pr_cont("va=%08lx asid=%08lx"
58 " [pa=%06lx n=%d d=%d v=%d g=%d]",
59 entryhi & PAGE_MASK,
60 entryhi & asid_mask,
61 entrylo0 & PAGE_MASK,
62 (entrylo0 & R3K_ENTRYLO_N) ? 1 : 0,
63 (entrylo0 & R3K_ENTRYLO_D) ? 1 : 0,
64 (entrylo0 & R3K_ENTRYLO_V) ? 1 : 0,
65 (entrylo0 & R3K_ENTRYLO_G) ? 1 : 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -070066 }
67 }
68 printk("\n");
69
70 write_c0_entryhi(asid);
71}
72
73void dump_tlb_all(void)
74{
75 dump_tlb(0, current_cpu_data.tlbsize - 1);
76}