xref: /openbmc/linux/arch/mips/lib/r3k_dump_tlb.c (revision 4edf00a4)
14becef1dSAtsushi Nemoto /*
24becef1dSAtsushi Nemoto  * Dump R3000 TLB for debugging purposes.
34becef1dSAtsushi Nemoto  *
44becef1dSAtsushi Nemoto  * Copyright (C) 1994, 1995 by Waldorf Electronics, written by Ralf Baechle.
54becef1dSAtsushi Nemoto  * Copyright (C) 1999 by Silicon Graphics, Inc.
64becef1dSAtsushi Nemoto  * Copyright (C) 1999 by Harald Koerfgen
74becef1dSAtsushi Nemoto  */
84becef1dSAtsushi Nemoto #include <linux/kernel.h>
94becef1dSAtsushi Nemoto #include <linux/mm.h>
104becef1dSAtsushi Nemoto 
114becef1dSAtsushi Nemoto #include <asm/mipsregs.h>
1280e8bd26SIsamu Mogi #include <asm/mmu_context.h>
134becef1dSAtsushi Nemoto #include <asm/page.h>
144becef1dSAtsushi Nemoto #include <asm/pgtable.h>
1540df3831SAtsushi Nemoto #include <asm/tlbdebug.h>
164becef1dSAtsushi Nemoto 
173c865dd9SJames Hogan extern int r3k_have_wired_reg;
183c865dd9SJames Hogan 
193c865dd9SJames Hogan void dump_tlb_regs(void)
203c865dd9SJames Hogan {
213c865dd9SJames Hogan 	pr_info("Index    : %0x\n", read_c0_index());
223c865dd9SJames Hogan 	pr_info("EntryHi  : %0lx\n", read_c0_entryhi());
233c865dd9SJames Hogan 	pr_info("EntryLo  : %0lx\n", read_c0_entrylo0());
243c865dd9SJames Hogan 	if (r3k_have_wired_reg)
253c865dd9SJames Hogan 		pr_info("Wired    : %0x\n", read_c0_wired());
263c865dd9SJames Hogan }
273c865dd9SJames Hogan 
2869ed25b8SAtsushi Nemoto static void dump_tlb(int first, int last)
294becef1dSAtsushi Nemoto {
304becef1dSAtsushi Nemoto 	int	i;
314becef1dSAtsushi Nemoto 	unsigned int asid;
324edf00a4SPaul Burton 	unsigned long entryhi, entrylo0, asid_mask;
334becef1dSAtsushi Nemoto 
344edf00a4SPaul Burton 	asid_mask = cpu_asid_mask(&current_cpu_data);
354edf00a4SPaul Burton 	asid = read_c0_entryhi() & asid_mask;
364becef1dSAtsushi Nemoto 
374becef1dSAtsushi Nemoto 	for (i = first; i <= last; i++) {
384becef1dSAtsushi Nemoto 		write_c0_index(i<<8);
394becef1dSAtsushi Nemoto 		__asm__ __volatile__(
404becef1dSAtsushi Nemoto 			".set\tnoreorder\n\t"
414becef1dSAtsushi Nemoto 			"tlbr\n\t"
424becef1dSAtsushi Nemoto 			"nop\n\t"
434becef1dSAtsushi Nemoto 			".set\treorder");
444becef1dSAtsushi Nemoto 		entryhi	 = read_c0_entryhi();
454becef1dSAtsushi Nemoto 		entrylo0 = read_c0_entrylo0();
464becef1dSAtsushi Nemoto 
474becef1dSAtsushi Nemoto 		/* Unused entries have a virtual address of KSEG0.  */
4848269c78SJames Hogan 		if ((entryhi & PAGE_MASK) != KSEG0 &&
4948269c78SJames Hogan 		    (entrylo0 & R3K_ENTRYLO_G ||
504edf00a4SPaul Burton 		     (entryhi & asid_mask) == asid)) {
514becef1dSAtsushi Nemoto 			/*
524becef1dSAtsushi Nemoto 			 * Only print entries in use
534becef1dSAtsushi Nemoto 			 */
544becef1dSAtsushi Nemoto 			printk("Index: %2d ", i);
554becef1dSAtsushi Nemoto 
564becef1dSAtsushi Nemoto 			printk("va=%08lx asid=%08lx"
574becef1dSAtsushi Nemoto 			       "  [pa=%06lx n=%d d=%d v=%d g=%d]",
58432d9ecbSIsamu Mogi 			       entryhi & PAGE_MASK,
594edf00a4SPaul Burton 			       entryhi & asid_mask,
604becef1dSAtsushi Nemoto 			       entrylo0 & PAGE_MASK,
61d7f5499dSJames Hogan 			       (entrylo0 & R3K_ENTRYLO_N) ? 1 : 0,
62d7f5499dSJames Hogan 			       (entrylo0 & R3K_ENTRYLO_D) ? 1 : 0,
63d7f5499dSJames Hogan 			       (entrylo0 & R3K_ENTRYLO_V) ? 1 : 0,
64d7f5499dSJames Hogan 			       (entrylo0 & R3K_ENTRYLO_G) ? 1 : 0);
654becef1dSAtsushi Nemoto 		}
664becef1dSAtsushi Nemoto 	}
674becef1dSAtsushi Nemoto 	printk("\n");
684becef1dSAtsushi Nemoto 
694becef1dSAtsushi Nemoto 	write_c0_entryhi(asid);
704becef1dSAtsushi Nemoto }
714becef1dSAtsushi Nemoto 
724becef1dSAtsushi Nemoto void dump_tlb_all(void)
734becef1dSAtsushi Nemoto {
744becef1dSAtsushi Nemoto 	dump_tlb(0, current_cpu_data.tlbsize - 1);
754becef1dSAtsushi Nemoto }
76