blob: 6a68deb51aae96ce8d34fa6a3bf843c775fad5cb [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 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07007#include <linux/kernel.h>
8#include <linux/mm.h>
9#include <linux/sched.h>
10#include <linux/string.h>
11
12#include <asm/bootinfo.h>
13#include <asm/cachectl.h>
14#include <asm/cpu.h>
15#include <asm/mipsregs.h>
16#include <asm/page.h>
17#include <asm/pgtable.h>
18
19static inline const char *msk2str(unsigned int mask)
20{
21 switch (mask) {
Ralf Baechled2f755e2005-08-16 17:06:48 +000022 case PM_4K:
23 return "4kb";
24 case PM_16K:
25 return "16kb";
26 case PM_64K:
27 return "64kb";
28 case PM_256K:
29 return "256kb";
Linus Torvalds1da177e2005-04-16 15:20:36 -070030#ifndef CONFIG_CPU_VR41XX
Ralf Baechled2f755e2005-08-16 17:06:48 +000031 case PM_1M:
32 return "1Mb";
33 case PM_4M:
34 return "4Mb";
35 case PM_16M:
36 return "16Mb";
37 case PM_64M:
38 return "64Mb";
39 case PM_256M:
40 return "256Mb";
Linus Torvalds1da177e2005-04-16 15:20:36 -070041#endif
42 }
43
44 return "unknown";
45}
46
47#define BARRIER() \
48 __asm__ __volatile__( \
49 ".set\tnoreorder\n\t" \
50 "nop;nop;nop;nop;nop;nop;nop\n\t" \
51 ".set\treorder");
52
53void dump_tlb(int first, int last)
54{
55 unsigned int pagemask, c0, c1, asid;
56 unsigned long long entrylo0, entrylo1;
57 unsigned long entryhi;
Ralf Baechled2f755e2005-08-16 17:06:48 +000058 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -070059
60 asid = read_c0_entryhi() & 0xff;
61
62 printk("\n");
63 for (i = first; i <= last; i++) {
64 write_c0_index(i);
65 BARRIER();
66 tlb_read();
67 BARRIER();
68 pagemask = read_c0_pagemask();
Ralf Baechled2f755e2005-08-16 17:06:48 +000069 entryhi = read_c0_entryhi();
Linus Torvalds1da177e2005-04-16 15:20:36 -070070 entrylo0 = read_c0_entrylo0();
71 entrylo1 = read_c0_entrylo1();
72
73 /* Unused entries have a virtual address in KSEG0. */
74 if ((entryhi & 0xf0000000) != 0x80000000
75 && (entryhi & 0xff) == asid) {
76 /*
77 * Only print entries in use
78 */
79 printk("Index: %2d pgmask=%s ", i, msk2str(pagemask));
80
81 c0 = (entrylo0 >> 3) & 7;
82 c1 = (entrylo1 >> 3) & 7;
83
84 printk("va=%08lx asid=%02lx\n",
85 (entryhi & 0xffffe000), (entryhi & 0xff));
86 printk("\t\t\t[pa=%08Lx c=%d d=%d v=%d g=%Ld]\n",
87 (entrylo0 << 6) & PAGE_MASK, c0,
88 (entrylo0 & 4) ? 1 : 0,
Ralf Baechled2f755e2005-08-16 17:06:48 +000089 (entrylo0 & 2) ? 1 : 0, (entrylo0 & 1));
Linus Torvalds1da177e2005-04-16 15:20:36 -070090 printk("\t\t\t[pa=%08Lx c=%d d=%d v=%d g=%Ld]\n",
91 (entrylo1 << 6) & PAGE_MASK, c1,
92 (entrylo1 & 4) ? 1 : 0,
Ralf Baechled2f755e2005-08-16 17:06:48 +000093 (entrylo1 & 2) ? 1 : 0, (entrylo1 & 1));
Linus Torvalds1da177e2005-04-16 15:20:36 -070094 printk("\n");
95 }
96 }
97
98 write_c0_entryhi(asid);
99}
100
101void dump_tlb_all(void)
102{
103 dump_tlb(0, current_cpu_data.tlbsize - 1);
104}
105
106void dump_tlb_wired(void)
107{
Ralf Baechled2f755e2005-08-16 17:06:48 +0000108 int wired;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109
110 wired = read_c0_wired();
111 printk("Wired: %d", wired);
112 dump_tlb(0, read_c0_wired());
113}
114
115void dump_tlb_addr(unsigned long addr)
116{
117 unsigned int flags, oldpid;
118 int index;
119
120 local_irq_save(flags);
121 oldpid = read_c0_entryhi() & 0xff;
122 BARRIER();
123 write_c0_entryhi((addr & PAGE_MASK) | oldpid);
124 BARRIER();
125 tlb_probe();
126 BARRIER();
127 index = read_c0_index();
128 write_c0_entryhi(oldpid);
129 local_irq_restore(flags);
130
131 if (index < 0) {
132 printk("No entry for address 0x%08lx in TLB\n", addr);
133 return;
134 }
135
136 printk("Entry %d maps address 0x%08lx\n", index, addr);
137 dump_tlb(index, index);
138}
139
140void dump_tlb_nonwired(void)
141{
142 dump_tlb(read_c0_wired(), current_cpu_data.tlbsize - 1);
143}
144
145void dump_list_process(struct task_struct *t, void *address)
146{
Ralf Baechled2f755e2005-08-16 17:06:48 +0000147 pgd_t *page_dir, *pgd;
148 pud_t *pud;
149 pmd_t *pmd;
150 pte_t *pte, page;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700151 unsigned long addr, val;
152
153 addr = (unsigned long) address;
154
155 printk("Addr == %08lx\n", addr);
156 printk("task == %8p\n", t);
157 printk("task->mm == %8p\n", t->mm);
158 //printk("tasks->mm.pgd == %08x\n", (unsigned int) t->mm->pgd);
159
Atsushi Nemotod1e30a62006-02-02 01:29:14 +0900160 if (addr > KSEG0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700161 page_dir = pgd_offset_k(0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700162 pgd = pgd_offset_k(addr);
Atsushi Nemotod1e30a62006-02-02 01:29:14 +0900163 } else if (t->mm) {
164 page_dir = pgd_offset(t->mm, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700165 pgd = pgd_offset(t->mm, addr);
Atsushi Nemotod1e30a62006-02-02 01:29:14 +0900166 } else {
Ralf Baechleac351d942005-08-16 17:47:00 +0000167 printk("Current thread has no mm\n");
Atsushi Nemotod1e30a62006-02-02 01:29:14 +0900168 return;
169 }
170 printk("page_dir == %08x\n", (unsigned int) page_dir);
171 printk("pgd == %08x, ", (unsigned int) pgd);
172 pud = pud_offset(pgd, addr);
173 printk("pud == %08x, ", (unsigned int) pud);
174
175 pmd = pmd_offset(pud, addr);
176 printk("pmd == %08x, ", (unsigned int) pmd);
177
178 pte = pte_offset(pmd, addr);
179 printk("pte == %08x, ", (unsigned int) pte);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700180
181 page = *pte;
182#ifdef CONFIG_64BIT_PHYS_ADDR
183 printk("page == %08Lx\n", pte_val(page));
184#else
185 printk("page == %08lx\n", pte_val(page));
186#endif
187
188 val = pte_val(page);
Ralf Baechled2f755e2005-08-16 17:06:48 +0000189 if (val & _PAGE_PRESENT)
190 printk("present ");
191 if (val & _PAGE_READ)
192 printk("read ");
193 if (val & _PAGE_WRITE)
194 printk("write ");
195 if (val & _PAGE_ACCESSED)
196 printk("accessed ");
197 if (val & _PAGE_MODIFIED)
198 printk("modified ");
199 if (val & _PAGE_R4KBUG)
200 printk("r4kbug ");
201 if (val & _PAGE_GLOBAL)
202 printk("global ");
203 if (val & _PAGE_VALID)
204 printk("valid ");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700205 printk("\n");
206}
207
208void dump_list_current(void *address)
209{
210 dump_list_process(current, address);
211}
212
213unsigned int vtop(void *address)
214{
Ralf Baechled2f755e2005-08-16 17:06:48 +0000215 pgd_t *pgd;
216 pud_t *pud;
217 pmd_t *pmd;
218 pte_t *pte;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700219 unsigned int addr, paddr;
220
221 addr = (unsigned long) address;
222 pgd = pgd_offset(current->mm, addr);
Ralf Baechlec6e8b582005-02-10 12:19:59 +0000223 pud = pud_offset(pgd, addr);
224 pmd = pmd_offset(pud, addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700225 pte = pte_offset(pmd, addr);
226 paddr = (KSEG1 | (unsigned int) pte_val(*pte)) & PAGE_MASK;
227 paddr |= (addr & ~PAGE_MASK);
228
229 return paddr;
230}
231
232void dump16(unsigned long *p)
233{
234 int i;
235
236 for (i = 0; i < 8; i++) {
Ralf Baechled2f755e2005-08-16 17:06:48 +0000237 printk("*%08lx == %08lx, ", (unsigned long) p, *p);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700238 p++;
Ralf Baechled2f755e2005-08-16 17:06:48 +0000239 printk("*%08lx == %08lx\n", (unsigned long) p, *p);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700240 p++;
241 }
242}