dump_tlb.c 2.7 KB
Newer Older
L
Linus Torvalds 已提交
1 2 3 4 5 6 7 8 9 10 11 12
/*
 * 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>

#include <asm/mipsregs.h>
#include <asm/page.h>
#include <asm/pgtable.h>
A
Atsushi Nemoto 已提交
13
#include <asm/tlbdebug.h>
14
#include <asm/mmu_context.h>
L
Linus Torvalds 已提交
15 16 17 18 19 20 21 22

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";
23 24 25 26 27 28 29 30 31
#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 已提交
32 33 34 35 36 37
#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";
38
	case PM_1G:	return "1Gb";
L
Linus Torvalds 已提交
39 40
#endif
	}
A
Atsushi Nemoto 已提交
41
	return "";
L
Linus Torvalds 已提交
42 43 44 45 46 47 48 49
}

#define BARRIER()					\
	__asm__ __volatile__(				\
		".set\tnoreorder\n\t"			\
		"nop;nop;nop;nop;nop;nop;nop\n\t"	\
		".set\treorder");

50
static void dump_tlb(int first, int last)
L
Linus Torvalds 已提交
51
{
A
Atsushi Nemoto 已提交
52 53
	unsigned long s_entryhi, entryhi, asid;
	unsigned long long entrylo0, entrylo1;
54
	unsigned int s_index, s_pagemask, pagemask, c0, c1, i;
L
Linus Torvalds 已提交
55

56
	s_pagemask = read_c0_pagemask();
L
Linus Torvalds 已提交
57 58
	s_entryhi = read_c0_entryhi();
	s_index = read_c0_index();
59
	asid = ASID_MASK(s_entryhi);
L
Linus Torvalds 已提交
60 61 62 63 64 65 66

	for (i = first; i <= last; i++) {
		write_c0_index(i);
		BARRIER();
		tlb_read();
		BARRIER();
		pagemask = read_c0_pagemask();
R
Ralf Baechle 已提交
67
		entryhi	 = read_c0_entryhi();
L
Linus Torvalds 已提交
68 69 70 71 72 73
		entrylo0 = read_c0_entrylo0();
		entrylo1 = read_c0_entrylo1();

		/* Unused entries have a virtual address of CKSEG0.  */
		if ((entryhi & ~0x1ffffUL) != CKSEG0
		    && (entryhi & 0xff) == asid) {
A
Atsushi Nemoto 已提交
74 75 76 77 78
#ifdef CONFIG_32BIT
			int width = 8;
#else
			int width = 11;
#endif
L
Linus Torvalds 已提交
79 80 81 82 83 84 85 86
			/*
			 * Only print entries in use
			 */
			printk("Index: %2d pgmask=%s ", i, msk2str(pagemask));

			c0 = (entrylo0 >> 3) & 7;
			c1 = (entrylo1 >> 3) & 7;

A
Atsushi Nemoto 已提交
87 88
			printk("va=%0*lx asid=%02lx\n",
			       width, (entryhi & ~0x1fffUL),
89
			       ASID_MASK(entryhi));
A
Atsushi Nemoto 已提交
90 91
			printk("\t[pa=%0*llx c=%d d=%d v=%d g=%d] ",
			       width,
L
Linus Torvalds 已提交
92 93 94
			       (entrylo0 << 6) & PAGE_MASK, c0,
			       (entrylo0 & 4) ? 1 : 0,
			       (entrylo0 & 2) ? 1 : 0,
A
Atsushi Nemoto 已提交
95 96 97
			       (entrylo0 & 1) ? 1 : 0);
			printk("[pa=%0*llx c=%d d=%d v=%d g=%d]\n",
			       width,
L
Linus Torvalds 已提交
98 99 100
			       (entrylo1 << 6) & PAGE_MASK, c1,
			       (entrylo1 & 4) ? 1 : 0,
			       (entrylo1 & 2) ? 1 : 0,
A
Atsushi Nemoto 已提交
101
			       (entrylo1 & 1) ? 1 : 0);
L
Linus Torvalds 已提交
102 103 104 105 106 107
		}
	}
	printk("\n");

	write_c0_entryhi(s_entryhi);
	write_c0_index(s_index);
108
	write_c0_pagemask(s_pagemask);
L
Linus Torvalds 已提交
109 110 111 112 113 114
}

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