2 * r2300.c: R2000 and R3000 specific mmu/cache code.
4 * Copyright (C) 1996 David S. Miller (dm@engr.sgi.com)
6 * with a lot of changes to make this thing work for R3000s
7 * Tx39XX R4k style caches added. HK
8 * Copyright (C) 1998, 1999, 2000 Harald Koerfgen
9 * Copyright (C) 1998 Gleb Raiko & Vladimir Roganov
10 * Copyright (C) 2002 Ralf Baechle
11 * Copyright (C) 2002 Maciej W. Rozycki
13 #include <linux/init.h>
14 #include <linux/kernel.h>
15 #include <linux/sched.h>
16 #include <linux/smp.h>
20 #include <asm/pgtable.h>
21 #include <asm/mmu_context.h>
22 #include <asm/system.h>
23 #include <asm/isadep.h>
25 #include <asm/bootinfo.h>
30 extern void build_tlb_refill_handler(void);
32 /* CP0 hazard avoidance. */
34 __asm__ __volatile__( \
36 ".set noreorder\n\t" \
40 int r3k_have_wired_reg
; /* should be in cpu_data? */
43 void local_flush_tlb_all(void)
46 unsigned long old_ctx
;
53 local_irq_save(flags
);
54 old_ctx
= read_c0_entryhi() & ASID_MASK
;
56 entry
= r3k_have_wired_reg
? read_c0_wired() : 8;
57 for (; entry
< current_cpu_data
.tlbsize
; entry
++) {
58 write_c0_index(entry
<< 8);
59 write_c0_entryhi((entry
| 0x80000) << 12);
63 write_c0_entryhi(old_ctx
);
64 local_irq_restore(flags
);
67 void local_flush_tlb_mm(struct mm_struct
*mm
)
69 int cpu
= smp_processor_id();
71 if (cpu_context(cpu
, mm
) != 0) {
73 printk("[tlbmm<%lu>]", (unsigned long)cpu_context(cpu
, mm
));
75 drop_mmu_context(mm
, cpu
);
79 void local_flush_tlb_range(struct vm_area_struct
*vma
, unsigned long start
,
82 struct mm_struct
*mm
= vma
->vm_mm
;
83 int cpu
= smp_processor_id();
85 if (cpu_context(cpu
, mm
) != 0) {
86 unsigned long size
, flags
;
89 printk("[tlbrange<%lu,0x%08lx,0x%08lx>]",
90 cpu_context(cpu
, mm
) & ASID_MASK
, start
, end
);
92 local_irq_save(flags
);
93 size
= (end
- start
+ (PAGE_SIZE
- 1)) >> PAGE_SHIFT
;
94 if (size
<= current_cpu_data
.tlbsize
) {
95 int oldpid
= read_c0_entryhi() & ASID_MASK
;
96 int newpid
= cpu_context(cpu
, mm
) & ASID_MASK
;
101 while (start
< end
) {
104 write_c0_entryhi(start
| newpid
);
105 start
+= PAGE_SIZE
; /* BARRIER */
107 idx
= read_c0_index();
108 write_c0_entrylo0(0);
109 write_c0_entryhi(KSEG0
);
110 if (idx
< 0) /* BARRIER */
114 write_c0_entryhi(oldpid
);
116 drop_mmu_context(mm
, cpu
);
118 local_irq_restore(flags
);
122 void local_flush_tlb_kernel_range(unsigned long start
, unsigned long end
)
124 unsigned long size
, flags
;
127 printk("[tlbrange<%lu,0x%08lx,0x%08lx>]", start
, end
);
129 local_irq_save(flags
);
130 size
= (end
- start
+ (PAGE_SIZE
- 1)) >> PAGE_SHIFT
;
131 if (size
<= current_cpu_data
.tlbsize
) {
132 int pid
= read_c0_entryhi();
135 end
+= PAGE_SIZE
- 1;
138 while (start
< end
) {
141 write_c0_entryhi(start
);
142 start
+= PAGE_SIZE
; /* BARRIER */
144 idx
= read_c0_index();
145 write_c0_entrylo0(0);
146 write_c0_entryhi(KSEG0
);
147 if (idx
< 0) /* BARRIER */
151 write_c0_entryhi(pid
);
153 local_flush_tlb_all();
155 local_irq_restore(flags
);
158 void local_flush_tlb_page(struct vm_area_struct
*vma
, unsigned long page
)
160 int cpu
= smp_processor_id();
162 if (!vma
|| cpu_context(cpu
, vma
->vm_mm
) != 0) {
164 int oldpid
, newpid
, idx
;
167 printk("[tlbpage<%lu,0x%08lx>]", cpu_context(cpu
, vma
->vm_mm
), page
);
169 newpid
= cpu_context(cpu
, vma
->vm_mm
) & ASID_MASK
;
171 local_irq_save(flags
);
172 oldpid
= read_c0_entryhi() & ASID_MASK
;
173 write_c0_entryhi(page
| newpid
);
176 idx
= read_c0_index();
177 write_c0_entrylo0(0);
178 write_c0_entryhi(KSEG0
);
179 if (idx
< 0) /* BARRIER */
184 write_c0_entryhi(oldpid
);
185 local_irq_restore(flags
);
189 void __update_tlb(struct vm_area_struct
*vma
, unsigned long address
, pte_t pte
)
195 * Handle debugger faulting in for debugee.
197 if (current
->active_mm
!= vma
->vm_mm
)
200 pid
= read_c0_entryhi() & ASID_MASK
;
203 if ((pid
!= (cpu_context(cpu
, vma
->vm_mm
) & ASID_MASK
)) || (cpu_context(cpu
, vma
->vm_mm
) == 0)) {
204 printk("update_mmu_cache: Wheee, bogus tlbpid mmpid=%lu tlbpid=%d\n",
205 (cpu_context(cpu
, vma
->vm_mm
)), pid
);
209 local_irq_save(flags
);
210 address
&= PAGE_MASK
;
211 write_c0_entryhi(address
| pid
);
214 idx
= read_c0_index();
215 write_c0_entrylo0(pte_val(pte
));
216 write_c0_entryhi(address
| pid
);
217 if (idx
< 0) { /* BARRIER */
222 write_c0_entryhi(pid
);
223 local_irq_restore(flags
);
226 void __init
add_wired_entry(unsigned long entrylo0
, unsigned long entrylo1
,
227 unsigned long entryhi
, unsigned long pagemask
)
230 unsigned long old_ctx
;
231 static unsigned long wired
= 0;
233 if (r3k_have_wired_reg
) { /* TX39XX */
234 unsigned long old_pagemask
;
238 printk("[tlbwired<entry lo0 %8x, hi %8x\n, pagemask %8x>]\n",
239 entrylo0
, entryhi
, pagemask
);
242 local_irq_save(flags
);
243 /* Save old context and create impossible VPN2 value */
244 old_ctx
= read_c0_entryhi() & ASID_MASK
;
245 old_pagemask
= read_c0_pagemask();
247 write_c0_wired(w
+ 1);
248 write_c0_index(w
<< 8);
249 write_c0_pagemask(pagemask
);
250 write_c0_entryhi(entryhi
);
251 write_c0_entrylo0(entrylo0
);
255 write_c0_entryhi(old_ctx
);
256 write_c0_pagemask(old_pagemask
);
257 local_flush_tlb_all();
258 local_irq_restore(flags
);
260 } else if (wired
< 8) {
262 printk("[tlbwired<entry lo0 %8x, hi %8x\n>]\n",
266 local_irq_save(flags
);
267 old_ctx
= read_c0_entryhi() & ASID_MASK
;
268 write_c0_entrylo0(entrylo0
);
269 write_c0_entryhi(entryhi
);
270 write_c0_index(wired
);
271 wired
++; /* BARRIER */
273 write_c0_entryhi(old_ctx
);
274 local_flush_tlb_all();
275 local_irq_restore(flags
);
279 void __cpuinit
tlb_init(void)
281 local_flush_tlb_all();
283 build_tlb_refill_handler();