blob: 46519f4331ebb62bf7498a028445a6de9580d843 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * Dump R4x00 TLB for debugging purposes.
3 *
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>
12
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>
19
20static inline const char *msk2str(unsigned int mask)
21{
22 switch (mask) {
Ralf Baechled2f755e2005-08-16 17:06:48 +000023 case PM_4K:
24 return "4kb";
25 case PM_16K:
26 return "16kb";
27 case PM_64K:
28 return "64kb";
29 case PM_256K:
30 return "256kb";
Linus Torvalds1da177e2005-04-16 15:20:36 -070031#ifndef CONFIG_CPU_VR41XX
Ralf Baechled2f755e2005-08-16 17:06:48 +000032 case PM_1M:
33 return "1Mb";
34 case PM_4M:
35 return "4Mb";
36 case PM_16M:
37 return "16Mb";
38 case PM_64M:
39 return "64Mb";
40 case PM_256M:
41 return "256Mb";
Linus Torvalds1da177e2005-04-16 15:20:36 -070042#endif
43 }
44
45 return "unknown";
46}
47
48#define BARRIER() \
49 __asm__ __volatile__( \
50 ".set\tnoreorder\n\t" \
51 "nop;nop;nop;nop;nop;nop;nop\n\t" \
52 ".set\treorder");
53
54void dump_tlb(int first, int last)
55{
56 unsigned int pagemask, c0, c1, asid;
57 unsigned long long entrylo0, entrylo1;
58 unsigned long entryhi;
Ralf Baechled2f755e2005-08-16 17:06:48 +000059 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -070060
61 asid = read_c0_entryhi() & 0xff;
62
63 printk("\n");
64 for (i = first; i <= last; i++) {
65 write_c0_index(i);
66 BARRIER();
67 tlb_read();
68 BARRIER();
69 pagemask = read_c0_pagemask();
Ralf Baechled2f755e2005-08-16 17:06:48 +000070 entryhi = read_c0_entryhi();
Linus Torvalds1da177e2005-04-16 15:20:36 -070071 entrylo0 = read_c0_entrylo0();
72 entrylo1 = read_c0_entrylo1();
73
74 /* Unused entries have a virtual address in KSEG0. */
75 if ((entryhi & 0xf0000000) != 0x80000000
76 && (entryhi & 0xff) == asid) {
77 /*
78 * Only print entries in use
79 */
80 printk("Index: %2d pgmask=%s ", i, msk2str(pagemask));
81
82 c0 = (entrylo0 >> 3) & 7;
83 c1 = (entrylo1 >> 3) & 7;
84
85 printk("va=%08lx asid=%02lx\n",
86 (entryhi & 0xffffe000), (entryhi & 0xff));
87 printk("\t\t\t[pa=%08Lx c=%d d=%d v=%d g=%Ld]\n",
88 (entrylo0 << 6) & PAGE_MASK, c0,
89 (entrylo0 & 4) ? 1 : 0,
Ralf Baechled2f755e2005-08-16 17:06:48 +000090 (entrylo0 & 2) ? 1 : 0, (entrylo0 & 1));
Linus Torvalds1da177e2005-04-16 15:20:36 -070091 printk("\t\t\t[pa=%08Lx c=%d d=%d v=%d g=%Ld]\n",
92 (entrylo1 << 6) & PAGE_MASK, c1,
93 (entrylo1 & 4) ? 1 : 0,
Ralf Baechled2f755e2005-08-16 17:06:48 +000094 (entrylo1 & 2) ? 1 : 0, (entrylo1 & 1));
Linus Torvalds1da177e2005-04-16 15:20:36 -070095 printk("\n");
96 }
97 }
98
99 write_c0_entryhi(asid);
100}
101
102void dump_tlb_all(void)
103{
104 dump_tlb(0, current_cpu_data.tlbsize - 1);
105}
106
107void dump_tlb_wired(void)
108{
Ralf Baechled2f755e2005-08-16 17:06:48 +0000109 int wired;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700110
111 wired = read_c0_wired();
112 printk("Wired: %d", wired);
113 dump_tlb(0, read_c0_wired());
114}
115
116void dump_tlb_addr(unsigned long addr)
117{
118 unsigned int flags, oldpid;
119 int index;
120
121 local_irq_save(flags);
122 oldpid = read_c0_entryhi() & 0xff;
123 BARRIER();
124 write_c0_entryhi((addr & PAGE_MASK) | oldpid);
125 BARRIER();
126 tlb_probe();
127 BARRIER();
128 index = read_c0_index();
129 write_c0_entryhi(oldpid);
130 local_irq_restore(flags);
131
132 if (index < 0) {
133 printk("No entry for address 0x%08lx in TLB\n", addr);
134 return;
135 }
136
137 printk("Entry %d maps address 0x%08lx\n", index, addr);
138 dump_tlb(index, index);
139}
140
141void dump_tlb_nonwired(void)
142{
143 dump_tlb(read_c0_wired(), current_cpu_data.tlbsize - 1);
144}
145
146void dump_list_process(struct task_struct *t, void *address)
147{
Ralf Baechled2f755e2005-08-16 17:06:48 +0000148 pgd_t *page_dir, *pgd;
149 pud_t *pud;
150 pmd_t *pmd;
151 pte_t *pte, page;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700152 unsigned long addr, val;
153
154 addr = (unsigned long) address;
155
156 printk("Addr == %08lx\n", addr);
157 printk("task == %8p\n", t);
158 printk("task->mm == %8p\n", t->mm);
159 //printk("tasks->mm.pgd == %08x\n", (unsigned int) t->mm->pgd);
160
161 if (addr > KSEG0)
162 page_dir = pgd_offset_k(0);
Ralf Baechleac351d92005-08-16 17:47:00 +0000163 else if (t->mm) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700164 page_dir = pgd_offset(t->mm, 0);
Ralf Baechleac351d92005-08-16 17:47:00 +0000165 printk("page_dir == %08x\n", (unsigned int) page_dir);
166 } else
167 printk("Current thread has no mm\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700168
169 if (addr > KSEG0)
170 pgd = pgd_offset_k(addr);
Ralf Baechleac351d92005-08-16 17:47:00 +0000171 else if (t->mm) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700172 pgd = pgd_offset(t->mm, addr);
Ralf Baechleac351d92005-08-16 17:47:00 +0000173 printk("pgd == %08x, ", (unsigned int) pgd);
174 pud = pud_offset(pgd, addr);
175 printk("pud == %08x, ", (unsigned int) pud);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700176
Ralf Baechleac351d92005-08-16 17:47:00 +0000177 pmd = pmd_offset(pud, addr);
178 printk("pmd == %08x, ", (unsigned int) pmd);
Ralf Baechlec6e8b582005-02-10 12:19:59 +0000179
Ralf Baechleac351d92005-08-16 17:47:00 +0000180 pte = pte_offset(pmd, addr);
181 printk("pte == %08x, ", (unsigned int) pte);
182 } else
183 printk("Current thread has no mm\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700184
185 page = *pte;
186#ifdef CONFIG_64BIT_PHYS_ADDR
187 printk("page == %08Lx\n", pte_val(page));
188#else
189 printk("page == %08lx\n", pte_val(page));
190#endif
191
192 val = pte_val(page);
Ralf Baechled2f755e2005-08-16 17:06:48 +0000193 if (val & _PAGE_PRESENT)
194 printk("present ");
195 if (val & _PAGE_READ)
196 printk("read ");
197 if (val & _PAGE_WRITE)
198 printk("write ");
199 if (val & _PAGE_ACCESSED)
200 printk("accessed ");
201 if (val & _PAGE_MODIFIED)
202 printk("modified ");
203 if (val & _PAGE_R4KBUG)
204 printk("r4kbug ");
205 if (val & _PAGE_GLOBAL)
206 printk("global ");
207 if (val & _PAGE_VALID)
208 printk("valid ");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700209 printk("\n");
210}
211
212void dump_list_current(void *address)
213{
214 dump_list_process(current, address);
215}
216
217unsigned int vtop(void *address)
218{
Ralf Baechled2f755e2005-08-16 17:06:48 +0000219 pgd_t *pgd;
220 pud_t *pud;
221 pmd_t *pmd;
222 pte_t *pte;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700223 unsigned int addr, paddr;
224
225 addr = (unsigned long) address;
226 pgd = pgd_offset(current->mm, addr);
Ralf Baechlec6e8b582005-02-10 12:19:59 +0000227 pud = pud_offset(pgd, addr);
228 pmd = pmd_offset(pud, addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700229 pte = pte_offset(pmd, addr);
230 paddr = (KSEG1 | (unsigned int) pte_val(*pte)) & PAGE_MASK;
231 paddr |= (addr & ~PAGE_MASK);
232
233 return paddr;
234}
235
236void dump16(unsigned long *p)
237{
238 int i;
239
240 for (i = 0; i < 8; i++) {
Ralf Baechled2f755e2005-08-16 17:06:48 +0000241 printk("*%08lx == %08lx, ", (unsigned long) p, *p);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700242 p++;
Ralf Baechled2f755e2005-08-16 17:06:48 +0000243 printk("*%08lx == %08lx\n", (unsigned long) p, *p);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700244 p++;
245 }
246}