dump_tlb.c 5.3 KB
Newer Older
L
Linus Torvalds 已提交
1 2 3 4 5 6 7 8 9
/*
 * Dump R4x00 TLB for debugging purposes.
 *
 * Copyright (C) 1994, 1995 by Waldorf Electronics, written by Ralf Baechle.
 * Copyright (C) 1999 by Silicon Graphics, Inc.
 */
#include <linux/kernel.h>
#include <linux/mm.h>

10
#include <asm/hazards.h>
L
Linus Torvalds 已提交
11 12 13
#include <asm/mipsregs.h>
#include <asm/page.h>
#include <asm/pgtable.h>
A
Atsushi Nemoto 已提交
14
#include <asm/tlbdebug.h>
L
Linus Torvalds 已提交
15

16 17 18 19 20 21
void dump_tlb_regs(void)
{
	const int field = 2 * sizeof(unsigned long);

	pr_info("Index    : %0x\n", read_c0_index());
	pr_info("PageMask : %0x\n", read_c0_pagemask());
22 23
	if (cpu_has_guestid)
		pr_info("GuestCtl1: %0x\n", read_c0_guestctl1());
24 25 26 27
	pr_info("EntryHi  : %0*lx\n", field, read_c0_entryhi());
	pr_info("EntryLo0 : %0*lx\n", field, read_c0_entrylo0());
	pr_info("EntryLo1 : %0*lx\n", field, read_c0_entrylo1());
	pr_info("Wired    : %0x\n", read_c0_wired());
28 29 30 31 32 33 34 35
	switch (current_cpu_type()) {
	case CPU_R10000:
	case CPU_R12000:
	case CPU_R14000:
	case CPU_R16000:
		pr_info("FrameMask: %0x\n", read_c0_framemask());
		break;
	}
36 37
	if (cpu_has_small_pages || cpu_has_rixi || cpu_has_xpa)
		pr_info("PageGrain: %0x\n", read_c0_pagegrain());
38 39 40 41 42 43 44
	if (cpu_has_htw) {
		pr_info("PWField  : %0*lx\n", field, read_c0_pwfield());
		pr_info("PWSize   : %0*lx\n", field, read_c0_pwsize());
		pr_info("PWCtl    : %0x\n", read_c0_pwctl());
	}
}

L
Linus Torvalds 已提交
45 46 47 48 49 50 51
static inline const char *msk2str(unsigned int mask)
{
	switch (mask) {
	case PM_4K:	return "4kb";
	case PM_16K:	return "16kb";
	case PM_64K:	return "64kb";
	case PM_256K:	return "256kb";
52 53 54 55 56 57 58 59 60
#ifdef CONFIG_CPU_CAVIUM_OCTEON
	case PM_8K:	return "8kb";
	case PM_32K:	return "32kb";
	case PM_128K:	return "128kb";
	case PM_512K:	return "512kb";
	case PM_2M:	return "2Mb";
	case PM_8M:	return "8Mb";
	case PM_32M:	return "32Mb";
#endif
L
Linus Torvalds 已提交
61 62 63 64 65 66
#ifndef CONFIG_CPU_VR41XX
	case PM_1M:	return "1Mb";
	case PM_4M:	return "4Mb";
	case PM_16M:	return "16Mb";
	case PM_64M:	return "64Mb";
	case PM_256M:	return "256Mb";
67
	case PM_1G:	return "1Gb";
L
Linus Torvalds 已提交
68 69
#endif
	}
A
Atsushi Nemoto 已提交
70
	return "";
L
Linus Torvalds 已提交
71 72
}

73
static void dump_tlb(int first, int last)
L
Linus Torvalds 已提交
74
{
A
Atsushi Nemoto 已提交
75
	unsigned long s_entryhi, entryhi, asid;
76
	unsigned long long entrylo0, entrylo1, pa;
77 78
	unsigned int s_index, s_pagemask, s_guestctl1 = 0;
	unsigned int pagemask, guestctl1 = 0, c0, c1, i;
79 80
	unsigned long asidmask = cpu_asid_mask(&current_cpu_data);
	int asidwidth = DIV_ROUND_UP(ilog2(asidmask) + 1, 4);
81
#ifdef CONFIG_32BIT
82 83 84
	bool xpa = cpu_has_xpa && (read_c0_pagegrain() & PG_ELPA);
	int pwidth = xpa ? 11 : 8;
	int vwidth = 8;
85
#else
86 87 88
	bool xpa = false;
	int pwidth = 11;
	int vwidth = 11;
89
#endif
L
Linus Torvalds 已提交
90

91
	s_pagemask = read_c0_pagemask();
L
Linus Torvalds 已提交
92 93
	s_entryhi = read_c0_entryhi();
	s_index = read_c0_index();
94
	asid = s_entryhi & asidmask;
95 96
	if (cpu_has_guestid)
		s_guestctl1 = read_c0_guestctl1();
L
Linus Torvalds 已提交
97 98 99

	for (i = first; i <= last; i++) {
		write_c0_index(i);
100
		mtc0_tlbr_hazard();
L
Linus Torvalds 已提交
101
		tlb_read();
102
		tlb_read_hazard();
L
Linus Torvalds 已提交
103
		pagemask = read_c0_pagemask();
R
Ralf Baechle 已提交
104
		entryhi	 = read_c0_entryhi();
L
Linus Torvalds 已提交
105 106
		entrylo0 = read_c0_entrylo0();
		entrylo1 = read_c0_entrylo1();
107 108
		if (cpu_has_guestid)
			guestctl1 = read_c0_guestctl1();
L
Linus Torvalds 已提交
109

110 111 112
		/* EHINV bit marks entire entry as invalid */
		if (cpu_has_tlbinv && entryhi & MIPS_ENTRYHI_EHINV)
			continue;
113 114 115 116 117 118
		/*
		 * Prior to tlbinv, unused entries have a virtual address of
		 * CKSEG0.
		 */
		if ((entryhi & ~0x1ffffUL) == CKSEG0)
			continue;
119 120 121 122 123 124 125
		/*
		 * ASID takes effect in absence of G (global) bit.
		 * We check both G bits, even though architecturally they should
		 * match one another, because some revisions of the SB1 core may
		 * leave only a single G bit set after a machine check exception
		 * due to duplicate TLB entry.
		 */
126
		if (!((entrylo0 | entrylo1) & ENTRYLO_G) &&
127
		    (entryhi & asidmask) != asid)
128 129 130 131 132 133
			continue;

		/*
		 * Only print entries in use
		 */
		printk("Index: %2d pgmask=%s ", i, msk2str(pagemask));
L
Linus Torvalds 已提交
134

135 136
		c0 = (entrylo0 & ENTRYLO_C) >> ENTRYLO_C_SHIFT;
		c1 = (entrylo1 & ENTRYLO_C) >> ENTRYLO_C_SHIFT;
L
Linus Torvalds 已提交
137

138
		printk("va=%0*lx asid=%0*lx",
139
		       vwidth, (entryhi & ~0x1fffUL),
140
		       asidwidth, entryhi & asidmask);
141 142 143 144
		if (cpu_has_guestid)
			printk(" gid=%02lx",
			       (guestctl1 & MIPS_GCTL1_RID)
					>> MIPS_GCTL1_RID_SHIFT);
145 146
		/* RI/XI are in awkward places, so mask them off separately */
		pa = entrylo0 & ~(MIPS_ENTRYLO_RI | MIPS_ENTRYLO_XI);
147 148
		if (xpa)
			pa |= (unsigned long long)readx_c0_entrylo0() << 30;
149
		pa = (pa << 6) & PAGE_MASK;
150
		printk("\n\t[");
151 152 153 154 155
		if (cpu_has_rixi)
			printk("ri=%d xi=%d ",
			       (entrylo0 & MIPS_ENTRYLO_RI) ? 1 : 0,
			       (entrylo0 & MIPS_ENTRYLO_XI) ? 1 : 0);
		printk("pa=%0*llx c=%d d=%d v=%d g=%d] [",
156
		       pwidth, pa, c0,
157 158 159
		       (entrylo0 & ENTRYLO_D) ? 1 : 0,
		       (entrylo0 & ENTRYLO_V) ? 1 : 0,
		       (entrylo0 & ENTRYLO_G) ? 1 : 0);
160 161
		/* RI/XI are in awkward places, so mask them off separately */
		pa = entrylo1 & ~(MIPS_ENTRYLO_RI | MIPS_ENTRYLO_XI);
162 163
		if (xpa)
			pa |= (unsigned long long)readx_c0_entrylo1() << 30;
164 165 166 167 168 169
		pa = (pa << 6) & PAGE_MASK;
		if (cpu_has_rixi)
			printk("ri=%d xi=%d ",
			       (entrylo1 & MIPS_ENTRYLO_RI) ? 1 : 0,
			       (entrylo1 & MIPS_ENTRYLO_XI) ? 1 : 0);
		printk("pa=%0*llx c=%d d=%d v=%d g=%d]\n",
170
		       pwidth, pa, c1,
171 172 173
		       (entrylo1 & ENTRYLO_D) ? 1 : 0,
		       (entrylo1 & ENTRYLO_V) ? 1 : 0,
		       (entrylo1 & ENTRYLO_G) ? 1 : 0);
L
Linus Torvalds 已提交
174 175 176 177 178
	}
	printk("\n");

	write_c0_entryhi(s_entryhi);
	write_c0_index(s_index);
179
	write_c0_pagemask(s_pagemask);
180 181
	if (cpu_has_guestid)
		write_c0_guestctl1(s_guestctl1);
L
Linus Torvalds 已提交
182 183 184 185 186 187
}

void dump_tlb_all(void)
{
	dump_tlb(0, current_cpu_data.tlbsize - 1);
}