2 * Dump R4x00 TLB for debugging purposes.
4 * Copyright (C) 1994, 1995 by Waldorf Electronics, written by Ralf Baechle.
5 * Copyright (C) 1999 by Silicon Graphics, Inc.
7 #include <linux/kernel.h>
9 #include <linux/sched.h>
10 #include <linux/string.h>
12 #include <asm/bootinfo.h>
13 #include <asm/cachectl.h>
15 #include <asm/mipsregs.h>
17 #include <asm/pgtable.h>
19 static inline const char *msk2str(unsigned int mask
)
22 case PM_4K
: return "4kb";
23 case PM_16K
: return "16kb";
24 case PM_64K
: return "64kb";
25 case PM_256K
: return "256kb";
26 #ifndef CONFIG_CPU_VR41XX
27 case PM_1M
: return "1Mb";
28 case PM_4M
: return "4Mb";
29 case PM_16M
: return "16Mb";
30 case PM_64M
: return "64Mb";
31 case PM_256M
: return "256Mb";
39 __asm__ __volatile__( \
40 ".set\tnoreorder\n\t" \
41 "nop;nop;nop;nop;nop;nop;nop\n\t" \
44 void dump_tlb(int first
, int last
)
46 unsigned long s_entryhi
, entryhi
, entrylo0
, entrylo1
, asid
;
47 unsigned int s_index
, pagemask
, c0
, c1
, i
;
49 s_entryhi
= read_c0_entryhi();
50 s_index
= read_c0_index();
51 asid
= s_entryhi
& 0xff;
53 for (i
= first
; i
<= last
; i
++) {
58 pagemask
= read_c0_pagemask();
59 entryhi
= read_c0_entryhi();
60 entrylo0
= read_c0_entrylo0();
61 entrylo1
= read_c0_entrylo1();
63 /* Unused entries have a virtual address of CKSEG0. */
64 if ((entryhi
& ~0x1ffffUL
) != CKSEG0
65 && (entryhi
& 0xff) == asid
) {
67 * Only print entries in use
69 printk("Index: %2d pgmask=%s ", i
, msk2str(pagemask
));
71 c0
= (entrylo0
>> 3) & 7;
72 c1
= (entrylo1
>> 3) & 7;
74 printk("va=%011lx asid=%02lx\n",
75 (entryhi
& ~0x1fffUL
),
77 printk("\t[pa=%011lx c=%d d=%d v=%d g=%ld] ",
78 (entrylo0
<< 6) & PAGE_MASK
, c0
,
79 (entrylo0
& 4) ? 1 : 0,
80 (entrylo0
& 2) ? 1 : 0,
82 printk("[pa=%011lx c=%d d=%d v=%d g=%ld]\n",
83 (entrylo1
<< 6) & PAGE_MASK
, c1
,
84 (entrylo1
& 4) ? 1 : 0,
85 (entrylo1
& 2) ? 1 : 0,
91 write_c0_entryhi(s_entryhi
);
92 write_c0_index(s_index
);
95 void dump_tlb_all(void)
97 dump_tlb(0, current_cpu_data
.tlbsize
- 1);
100 void dump_tlb_wired(void)
104 wired
= read_c0_wired();
105 printk("Wired: %d", wired
);
106 dump_tlb(0, read_c0_wired());
109 void dump_tlb_addr(unsigned long addr
)
111 unsigned int flags
, oldpid
;
114 local_irq_save(flags
);
115 oldpid
= read_c0_entryhi() & 0xff;
117 write_c0_entryhi((addr
& PAGE_MASK
) | oldpid
);
121 index
= read_c0_index();
122 write_c0_entryhi(oldpid
);
123 local_irq_restore(flags
);
126 printk("No entry for address 0x%08lx in TLB\n", addr
);
130 printk("Entry %d maps address 0x%08lx\n", index
, addr
);
131 dump_tlb(index
, index
);
134 void dump_tlb_nonwired(void)
136 dump_tlb(read_c0_wired(), current_cpu_data
.tlbsize
- 1);
139 void dump_list_process(struct task_struct
*t
, void *address
)
141 pgd_t
*page_dir
, *pgd
;
145 unsigned long addr
, val
;
147 addr
= (unsigned long) address
;
149 printk("Addr == %08lx\n", addr
);
150 printk("tasks->mm.pgd == %08lx\n", (unsigned long) t
->mm
->pgd
);
152 page_dir
= pgd_offset(t
->mm
, 0UL);
153 printk("page_dir == %016lx\n", (unsigned long) page_dir
);
155 pgd
= pgd_offset(t
->mm
, addr
);
156 printk("pgd == %016lx\n", (unsigned long) pgd
);
158 pud
= pud_offset(pgd
, addr
);
159 printk("pud == %016lx\n", (unsigned long) pud
);
161 pmd
= pmd_offset(pud
, addr
);
162 printk("pmd == %016lx\n", (unsigned long) pmd
);
164 pte
= pte_offset(pmd
, addr
);
165 printk("pte == %016lx\n", (unsigned long) pte
);
168 printk("page == %08lx\n", pte_val(page
));
171 if (val
& _PAGE_PRESENT
) printk("present ");
172 if (val
& _PAGE_READ
) printk("read ");
173 if (val
& _PAGE_WRITE
) printk("write ");
174 if (val
& _PAGE_ACCESSED
) printk("accessed ");
175 if (val
& _PAGE_MODIFIED
) printk("modified ");
176 if (val
& _PAGE_R4KBUG
) printk("r4kbug ");
177 if (val
& _PAGE_GLOBAL
) printk("global ");
178 if (val
& _PAGE_VALID
) printk("valid ");
182 void dump_list_current(void *address
)
184 dump_list_process(current
, address
);
187 unsigned long vtop(void *address
)
193 unsigned long addr
, paddr
;
195 addr
= (unsigned long) address
;
196 pgd
= pgd_offset(current
->mm
, addr
);
197 pud
= pud_offset(pgd
, addr
);
198 pmd
= pmd_offset(pud
, addr
);
199 pte
= pte_offset(pmd
, addr
);
200 paddr
= (CKSEG1
| (unsigned int) pte_val(*pte
)) & PAGE_MASK
;
201 paddr
|= (addr
& ~PAGE_MASK
);
206 void dump16(unsigned long *p
)
210 for (i
= 0; i
< 8; i
++) {
211 printk("*%08lx == %08lx, ", (unsigned long)p
, *p
);
213 printk("*%08lx == %08lx\n", (unsigned long)p
, *p
);