initial commit with v2.6.9
[linux-2.6.9-moxart.git] / arch / mips / lib-32 / dump_tlb.c
blobb92fea6927ea65adb49d5394c3296bb434313fe3
1 /*
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.
6 */
7 #include <linux/config.h>
8 #include <linux/kernel.h>
9 #include <linux/mm.h>
10 #include <linux/sched.h>
11 #include <linux/string.h>
13 #include <asm/bootinfo.h>
14 #include <asm/cachectl.h>
15 #include <asm/cpu.h>
16 #include <asm/mipsregs.h>
17 #include <asm/page.h>
18 #include <asm/pgtable.h>
20 static inline const char *msk2str(unsigned int mask)
22 switch (mask) {
23 case PM_4K: return "4kb";
24 case PM_16K: return "16kb";
25 case PM_64K: return "64kb";
26 case PM_256K: return "256kb";
27 #ifndef CONFIG_CPU_VR41XX
28 case PM_1M: return "1Mb";
29 case PM_4M: return "4Mb";
30 case PM_16M: return "16Mb";
31 case PM_64M: return "64Mb";
32 case PM_256M: return "256Mb";
33 #endif
37 #define BARRIER() \
38 __asm__ __volatile__( \
39 ".set\tnoreorder\n\t" \
40 "nop;nop;nop;nop;nop;nop;nop\n\t" \
41 ".set\treorder");
43 void dump_tlb(int first, int last)
45 unsigned int pagemask, c0, c1, asid;
46 unsigned long long entrylo0, entrylo1;
47 unsigned long entryhi;
48 int i;
50 asid = read_c0_entryhi() & 0xff;
52 printk("\n");
53 for (i = first; i <= last; i++) {
54 write_c0_index(i);
55 BARRIER();
56 tlb_read();
57 BARRIER();
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 in KSEG0. */
64 if ((entryhi & 0xf0000000) != 0x80000000
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=%08lx asid=%02lx\n",
75 (entryhi & 0xffffe000), (entryhi & 0xff));
76 printk("\t\t\t[pa=%08Lx c=%d d=%d v=%d g=%Ld]\n",
77 (entrylo0 << 6) & PAGE_MASK, c0,
78 (entrylo0 & 4) ? 1 : 0,
79 (entrylo0 & 2) ? 1 : 0,
80 (entrylo0 & 1));
81 printk("\t\t\t[pa=%08Lx c=%d d=%d v=%d g=%Ld]\n",
82 (entrylo1 << 6) & PAGE_MASK, c1,
83 (entrylo1 & 4) ? 1 : 0,
84 (entrylo1 & 2) ? 1 : 0,
85 (entrylo1 & 1));
86 printk("\n");
90 write_c0_entryhi(asid);
93 void dump_tlb_all(void)
95 dump_tlb(0, current_cpu_data.tlbsize - 1);
98 void dump_tlb_wired(void)
100 int wired;
102 wired = read_c0_wired();
103 printk("Wired: %d", wired);
104 dump_tlb(0, read_c0_wired());
107 void dump_tlb_addr(unsigned long addr)
109 unsigned int flags, oldpid;
110 int index;
112 local_irq_save(flags);
113 oldpid = read_c0_entryhi() & 0xff;
114 BARRIER();
115 write_c0_entryhi((addr & PAGE_MASK) | oldpid);
116 BARRIER();
117 tlb_probe();
118 BARRIER();
119 index = read_c0_index();
120 write_c0_entryhi(oldpid);
121 local_irq_restore(flags);
123 if (index < 0) {
124 printk("No entry for address 0x%08lx in TLB\n", addr);
125 return;
128 printk("Entry %d maps address 0x%08lx\n", index, addr);
129 dump_tlb(index, index);
132 void dump_tlb_nonwired(void)
134 dump_tlb(read_c0_wired(), current_cpu_data.tlbsize - 1);
137 void dump_list_process(struct task_struct *t, void *address)
139 pgd_t *page_dir, *pgd;
140 pmd_t *pmd;
141 pte_t *pte, page;
142 unsigned long addr, val;
144 addr = (unsigned long) address;
146 printk("Addr == %08lx\n", addr);
147 printk("task == %8p\n", t);
148 printk("task->mm == %8p\n", t->mm);
149 //printk("tasks->mm.pgd == %08x\n", (unsigned int) t->mm->pgd);
151 if (addr > KSEG0)
152 page_dir = pgd_offset_k(0);
153 else
154 page_dir = pgd_offset(t->mm, 0);
155 printk("page_dir == %08x\n", (unsigned int) page_dir);
157 if (addr > KSEG0)
158 pgd = pgd_offset_k(addr);
159 else
160 pgd = pgd_offset(t->mm, addr);
161 printk("pgd == %08x, ", (unsigned int) pgd);
163 pmd = pmd_offset(pgd, addr);
164 printk("pmd == %08x, ", (unsigned int) pmd);
166 pte = pte_offset(pmd, addr);
167 printk("pte == %08x, ", (unsigned int) pte);
169 page = *pte;
170 #ifdef CONFIG_64BIT_PHYS_ADDR
171 printk("page == %08Lx\n", pte_val(page));
172 #else
173 printk("page == %08lx\n", pte_val(page));
174 #endif
176 val = pte_val(page);
177 if (val & _PAGE_PRESENT) printk("present ");
178 if (val & _PAGE_READ) printk("read ");
179 if (val & _PAGE_WRITE) printk("write ");
180 if (val & _PAGE_ACCESSED) printk("accessed ");
181 if (val & _PAGE_MODIFIED) printk("modified ");
182 if (val & _PAGE_R4KBUG) printk("r4kbug ");
183 if (val & _PAGE_GLOBAL) printk("global ");
184 if (val & _PAGE_VALID) printk("valid ");
185 printk("\n");
188 void dump_list_current(void *address)
190 dump_list_process(current, address);
193 unsigned int vtop(void *address)
195 pgd_t *pgd;
196 pmd_t *pmd;
197 pte_t *pte;
198 unsigned int addr, paddr;
200 addr = (unsigned long) address;
201 pgd = pgd_offset(current->mm, addr);
202 pmd = pmd_offset(pgd, addr);
203 pte = pte_offset(pmd, addr);
204 paddr = (KSEG1 | (unsigned int) pte_val(*pte)) & PAGE_MASK;
205 paddr |= (addr & ~PAGE_MASK);
207 return paddr;
210 void dump16(unsigned long *p)
212 int i;
214 for (i = 0; i < 8; i++) {
215 printk("*%08lx == %08lx, ", (unsigned long)p, *p);
216 p++;
217 printk("*%08lx == %08lx\n", (unsigned long)p, *p);
218 p++;