blob: 89e3fabcb98c792601115b55143384caeb7438dd [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * This file is subject to the terms and conditions of the GNU General Public
3 * License. See the file "COPYING" in the main directory of this archive
4 * for more details.
5 *
Justin P. Mattock79add622011-04-04 14:15:29 -07006 * Copyright (C) 1996 David S. Miller (davem@davemloft.net)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007 * Copyright (C) 1997, 1998, 1999, 2000 Ralf Baechle ralf@gnu.org
8 * Carsten Langgaard, carstenl@mips.com
9 * Copyright (C) 2002 MIPS Technologies, Inc. All rights reserved.
10 */
James Hoganeaa38d62014-02-28 17:09:20 +000011#include <linux/cpu_pm.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070012#include <linux/init.h>
13#include <linux/sched.h>
Ralf Baechle631330f2009-06-19 14:05:26 +010014#include <linux/smp.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070015#include <linux/mm.h>
David Daneyfd062c82009-05-27 17:47:44 -070016#include <linux/hugetlb.h>
Sanjay Lalf2e36562012-11-21 18:34:10 -080017#include <linux/module.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070018
19#include <asm/cpu.h>
Ralf Baechle69f24d12013-09-17 10:25:47 +020020#include <asm/cpu-type.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070021#include <asm/bootinfo.h>
22#include <asm/mmu_context.h>
23#include <asm/pgtable.h>
Markos Chandrasc01905e2013-11-14 16:12:22 +000024#include <asm/tlb.h>
Ralf Baechle3d18c982011-11-28 16:11:28 +000025#include <asm/tlbmisc.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070026
27extern void build_tlb_refill_handler(void);
28
Ralf Baechle41c594a2006-04-05 09:45:45 +010029/* Atomicity and interruptability */
30#ifdef CONFIG_MIPS_MT_SMTC
31
32#include <asm/smtc.h>
33#include <asm/mipsmtregs.h>
34
35#define ENTER_CRITICAL(flags) \
36 { \
37 unsigned int mvpflags; \
38 local_irq_save(flags);\
39 mvpflags = dvpe()
40#define EXIT_CRITICAL(flags) \
41 evpe(mvpflags); \
42 local_irq_restore(flags); \
43 }
44#else
45
46#define ENTER_CRITICAL(flags) local_irq_save(flags)
47#define EXIT_CRITICAL(flags) local_irq_restore(flags)
48
49#endif /* CONFIG_MIPS_MT_SMTC */
50
Fuxin Zhang2a21c732007-06-06 14:52:43 +080051/*
Huacai Chenc579d312014-03-21 18:44:00 +080052 * LOONGSON2/3 has a 4 entry itlb which is a subset of dtlb,
53 * unfortunately, itlb is not totally transparent to software.
Fuxin Zhang2a21c732007-06-06 14:52:43 +080054 */
Ralf Baechle14bd8c02013-09-25 18:21:26 +020055static inline void flush_itlb(void)
56{
57 switch (current_cpu_type()) {
58 case CPU_LOONGSON2:
Huacai Chenc579d312014-03-21 18:44:00 +080059 case CPU_LOONGSON3:
Ralf Baechle14bd8c02013-09-25 18:21:26 +020060 write_c0_diag(4);
61 break;
62 default:
63 break;
64 }
65}
Fuxin Zhang2a21c732007-06-06 14:52:43 +080066
Ralf Baechle14bd8c02013-09-25 18:21:26 +020067static inline void flush_itlb_vm(struct vm_area_struct *vma)
68{
69 if (vma->vm_flags & VM_EXEC)
70 flush_itlb();
71}
Fuxin Zhang2a21c732007-06-06 14:52:43 +080072
Linus Torvalds1da177e2005-04-16 15:20:36 -070073void local_flush_tlb_all(void)
74{
75 unsigned long flags;
76 unsigned long old_ctx;
Leonid Yegoshin75b5b5e2013-11-14 16:12:31 +000077 int entry, ftlbhighset;
Linus Torvalds1da177e2005-04-16 15:20:36 -070078
Ralf Baechle41c594a2006-04-05 09:45:45 +010079 ENTER_CRITICAL(flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -070080 /* Save old context and create impossible VPN2 value */
81 old_ctx = read_c0_entryhi();
82 write_c0_entrylo0(0);
83 write_c0_entrylo1(0);
84
85 entry = read_c0_wired();
86
87 /* Blast 'em all away. */
Leonid Yegoshin75b5b5e2013-11-14 16:12:31 +000088 if (cpu_has_tlbinv) {
89 if (current_cpu_data.tlbsizevtlb) {
90 write_c0_index(0);
91 mtc0_tlbw_hazard();
92 tlbinvf(); /* invalidate VTLB */
93 }
94 ftlbhighset = current_cpu_data.tlbsizevtlb +
95 current_cpu_data.tlbsizeftlbsets;
96 for (entry = current_cpu_data.tlbsizevtlb;
97 entry < ftlbhighset;
98 entry++) {
99 write_c0_index(entry);
100 mtc0_tlbw_hazard();
101 tlbinvf(); /* invalidate one FTLB set */
102 }
Leonid Yegoshin601cfa72013-11-14 16:12:30 +0000103 } else {
104 while (entry < current_cpu_data.tlbsize) {
105 /* Make sure all entries differ. */
106 write_c0_entryhi(UNIQUE_ENTRYHI(entry));
107 write_c0_index(entry);
108 mtc0_tlbw_hazard();
109 tlb_write_indexed();
110 entry++;
111 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700112 }
113 tlbw_use_hazard();
114 write_c0_entryhi(old_ctx);
Ralf Baechle14bd8c02013-09-25 18:21:26 +0200115 flush_itlb();
Ralf Baechle41c594a2006-04-05 09:45:45 +0100116 EXIT_CRITICAL(flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700117}
Sanjay Lalf2e36562012-11-21 18:34:10 -0800118EXPORT_SYMBOL(local_flush_tlb_all);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700119
Thiemo Seufer172546b2005-04-02 10:21:56 +0000120/* All entries common to a mm share an asid. To effectively flush
121 these entries, we just bump the asid. */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700122void local_flush_tlb_mm(struct mm_struct *mm)
123{
Thiemo Seufer172546b2005-04-02 10:21:56 +0000124 int cpu;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700125
Thiemo Seufer172546b2005-04-02 10:21:56 +0000126 preempt_disable();
127
128 cpu = smp_processor_id();
129
130 if (cpu_context(cpu, mm) != 0) {
131 drop_mmu_context(mm, cpu);
132 }
133
134 preempt_enable();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700135}
136
137void local_flush_tlb_range(struct vm_area_struct *vma, unsigned long start,
138 unsigned long end)
139{
140 struct mm_struct *mm = vma->vm_mm;
141 int cpu = smp_processor_id();
142
143 if (cpu_context(cpu, mm) != 0) {
Greg Ungerera5e696e2009-05-20 16:12:32 +1000144 unsigned long size, flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700145
Ralf Baechle41c594a2006-04-05 09:45:45 +0100146 ENTER_CRITICAL(flags);
David Daneyac53c4f2012-12-03 12:44:26 -0800147 start = round_down(start, PAGE_SIZE << 1);
148 end = round_up(end, PAGE_SIZE << 1);
149 size = (end - start) >> (PAGE_SHIFT + 1);
Leonid Yegoshin75b5b5e2013-11-14 16:12:31 +0000150 if (size <= (current_cpu_data.tlbsizeftlbsets ?
151 current_cpu_data.tlbsize / 8 :
152 current_cpu_data.tlbsize / 2)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700153 int oldpid = read_c0_entryhi();
154 int newpid = cpu_asid(cpu, mm);
155
Linus Torvalds1da177e2005-04-16 15:20:36 -0700156 while (start < end) {
157 int idx;
158
159 write_c0_entryhi(start | newpid);
David Daneyac53c4f2012-12-03 12:44:26 -0800160 start += (PAGE_SIZE << 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700161 mtc0_tlbw_hazard();
162 tlb_probe();
Ralf Baechle432bef22006-09-08 04:16:21 +0200163 tlb_probe_hazard();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700164 idx = read_c0_index();
165 write_c0_entrylo0(0);
166 write_c0_entrylo1(0);
167 if (idx < 0)
168 continue;
169 /* Make sure all entries differ. */
Thiemo Seufer172546b2005-04-02 10:21:56 +0000170 write_c0_entryhi(UNIQUE_ENTRYHI(idx));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700171 mtc0_tlbw_hazard();
172 tlb_write_indexed();
173 }
174 tlbw_use_hazard();
175 write_c0_entryhi(oldpid);
176 } else {
177 drop_mmu_context(mm, cpu);
178 }
Ralf Baechle14bd8c02013-09-25 18:21:26 +0200179 flush_itlb();
Ralf Baechle41c594a2006-04-05 09:45:45 +0100180 EXIT_CRITICAL(flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700181 }
182}
183
184void local_flush_tlb_kernel_range(unsigned long start, unsigned long end)
185{
Greg Ungerera5e696e2009-05-20 16:12:32 +1000186 unsigned long size, flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700187
Ralf Baechle41c594a2006-04-05 09:45:45 +0100188 ENTER_CRITICAL(flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700189 size = (end - start + (PAGE_SIZE - 1)) >> PAGE_SHIFT;
190 size = (size + 1) >> 1;
Leonid Yegoshin75b5b5e2013-11-14 16:12:31 +0000191 if (size <= (current_cpu_data.tlbsizeftlbsets ?
192 current_cpu_data.tlbsize / 8 :
193 current_cpu_data.tlbsize / 2)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700194 int pid = read_c0_entryhi();
195
196 start &= (PAGE_MASK << 1);
197 end += ((PAGE_SIZE << 1) - 1);
198 end &= (PAGE_MASK << 1);
199
200 while (start < end) {
201 int idx;
202
203 write_c0_entryhi(start);
204 start += (PAGE_SIZE << 1);
205 mtc0_tlbw_hazard();
206 tlb_probe();
Ralf Baechle432bef22006-09-08 04:16:21 +0200207 tlb_probe_hazard();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700208 idx = read_c0_index();
209 write_c0_entrylo0(0);
210 write_c0_entrylo1(0);
211 if (idx < 0)
212 continue;
213 /* Make sure all entries differ. */
Thiemo Seufer172546b2005-04-02 10:21:56 +0000214 write_c0_entryhi(UNIQUE_ENTRYHI(idx));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700215 mtc0_tlbw_hazard();
216 tlb_write_indexed();
217 }
218 tlbw_use_hazard();
219 write_c0_entryhi(pid);
220 } else {
221 local_flush_tlb_all();
222 }
Ralf Baechle14bd8c02013-09-25 18:21:26 +0200223 flush_itlb();
Ralf Baechle41c594a2006-04-05 09:45:45 +0100224 EXIT_CRITICAL(flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700225}
226
227void local_flush_tlb_page(struct vm_area_struct *vma, unsigned long page)
228{
229 int cpu = smp_processor_id();
230
231 if (cpu_context(cpu, vma->vm_mm) != 0) {
232 unsigned long flags;
233 int oldpid, newpid, idx;
234
235 newpid = cpu_asid(cpu, vma->vm_mm);
236 page &= (PAGE_MASK << 1);
Ralf Baechle41c594a2006-04-05 09:45:45 +0100237 ENTER_CRITICAL(flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700238 oldpid = read_c0_entryhi();
239 write_c0_entryhi(page | newpid);
240 mtc0_tlbw_hazard();
241 tlb_probe();
Ralf Baechle432bef22006-09-08 04:16:21 +0200242 tlb_probe_hazard();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700243 idx = read_c0_index();
244 write_c0_entrylo0(0);
245 write_c0_entrylo1(0);
246 if (idx < 0)
247 goto finish;
248 /* Make sure all entries differ. */
Thiemo Seufer172546b2005-04-02 10:21:56 +0000249 write_c0_entryhi(UNIQUE_ENTRYHI(idx));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700250 mtc0_tlbw_hazard();
251 tlb_write_indexed();
252 tlbw_use_hazard();
253
254 finish:
255 write_c0_entryhi(oldpid);
Ralf Baechle14bd8c02013-09-25 18:21:26 +0200256 flush_itlb_vm(vma);
Ralf Baechle41c594a2006-04-05 09:45:45 +0100257 EXIT_CRITICAL(flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700258 }
259}
260
261/*
262 * This one is only used for pages with the global bit set so we don't care
263 * much about the ASID.
264 */
265void local_flush_tlb_one(unsigned long page)
266{
267 unsigned long flags;
268 int oldpid, idx;
269
Ralf Baechle41c594a2006-04-05 09:45:45 +0100270 ENTER_CRITICAL(flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700271 oldpid = read_c0_entryhi();
Thiemo Seufer172546b2005-04-02 10:21:56 +0000272 page &= (PAGE_MASK << 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700273 write_c0_entryhi(page);
274 mtc0_tlbw_hazard();
275 tlb_probe();
Ralf Baechle432bef22006-09-08 04:16:21 +0200276 tlb_probe_hazard();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700277 idx = read_c0_index();
278 write_c0_entrylo0(0);
279 write_c0_entrylo1(0);
280 if (idx >= 0) {
281 /* Make sure all entries differ. */
Thiemo Seufer172546b2005-04-02 10:21:56 +0000282 write_c0_entryhi(UNIQUE_ENTRYHI(idx));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700283 mtc0_tlbw_hazard();
284 tlb_write_indexed();
285 tlbw_use_hazard();
286 }
287 write_c0_entryhi(oldpid);
Ralf Baechle14bd8c02013-09-25 18:21:26 +0200288 flush_itlb();
Ralf Baechle41c594a2006-04-05 09:45:45 +0100289 EXIT_CRITICAL(flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700290}
291
292/*
293 * We will need multiple versions of update_mmu_cache(), one that just
294 * updates the TLB with the new pte(s), and another which also checks
295 * for the R4k "end of page" hardware bug and does the needy.
296 */
297void __update_tlb(struct vm_area_struct * vma, unsigned long address, pte_t pte)
298{
299 unsigned long flags;
300 pgd_t *pgdp;
Ralf Baechlec6e8b582005-02-10 12:19:59 +0000301 pud_t *pudp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700302 pmd_t *pmdp;
303 pte_t *ptep;
304 int idx, pid;
305
306 /*
307 * Handle debugger faulting in for debugee.
308 */
309 if (current->active_mm != vma->vm_mm)
310 return;
311
Ralf Baechle41c594a2006-04-05 09:45:45 +0100312 ENTER_CRITICAL(flags);
Thiemo Seufer172546b2005-04-02 10:21:56 +0000313
David Daney48c4ac92013-05-13 13:56:44 -0700314 pid = read_c0_entryhi() & ASID_MASK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700315 address &= (PAGE_MASK << 1);
316 write_c0_entryhi(address | pid);
317 pgdp = pgd_offset(vma->vm_mm, address);
318 mtc0_tlbw_hazard();
319 tlb_probe();
Ralf Baechle432bef22006-09-08 04:16:21 +0200320 tlb_probe_hazard();
Ralf Baechlec6e8b582005-02-10 12:19:59 +0000321 pudp = pud_offset(pgdp, address);
322 pmdp = pmd_offset(pudp, address);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700323 idx = read_c0_index();
David Daneyaa1762f2012-10-17 00:48:10 +0200324#ifdef CONFIG_MIPS_HUGE_TLB_SUPPORT
David Daneyfd062c82009-05-27 17:47:44 -0700325 /* this could be a huge page */
326 if (pmd_huge(*pmdp)) {
327 unsigned long lo;
328 write_c0_pagemask(PM_HUGE_MASK);
329 ptep = (pte_t *)pmdp;
David Daney6dd93442010-02-10 15:12:47 -0800330 lo = pte_to_entrylo(pte_val(*ptep));
David Daneyfd062c82009-05-27 17:47:44 -0700331 write_c0_entrylo0(lo);
332 write_c0_entrylo1(lo + (HPAGE_SIZE >> 7));
333
334 mtc0_tlbw_hazard();
335 if (idx < 0)
336 tlb_write_random();
337 else
338 tlb_write_indexed();
Ralf Baechlefb944c92012-10-17 01:01:21 +0200339 tlbw_use_hazard();
David Daneyfd062c82009-05-27 17:47:44 -0700340 write_c0_pagemask(PM_DEFAULT_MASK);
341 } else
342#endif
343 {
344 ptep = pte_offset_map(pmdp, address);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700345
Chris Dearman962f4802007-09-19 00:46:32 +0100346#if defined(CONFIG_64BIT_PHYS_ADDR) && defined(CONFIG_CPU_MIPS32)
David Daneyfd062c82009-05-27 17:47:44 -0700347 write_c0_entrylo0(ptep->pte_high);
348 ptep++;
349 write_c0_entrylo1(ptep->pte_high);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700350#else
David Daney6dd93442010-02-10 15:12:47 -0800351 write_c0_entrylo0(pte_to_entrylo(pte_val(*ptep++)));
352 write_c0_entrylo1(pte_to_entrylo(pte_val(*ptep)));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700353#endif
David Daneyfd062c82009-05-27 17:47:44 -0700354 mtc0_tlbw_hazard();
355 if (idx < 0)
356 tlb_write_random();
357 else
358 tlb_write_indexed();
359 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700360 tlbw_use_hazard();
Ralf Baechle14bd8c02013-09-25 18:21:26 +0200361 flush_itlb_vm(vma);
Ralf Baechle41c594a2006-04-05 09:45:45 +0100362 EXIT_CRITICAL(flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700363}
364
Manuel Lauss694b8c32011-08-02 19:51:08 +0200365void add_wired_entry(unsigned long entrylo0, unsigned long entrylo1,
366 unsigned long entryhi, unsigned long pagemask)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700367{
368 unsigned long flags;
369 unsigned long wired;
370 unsigned long old_pagemask;
371 unsigned long old_ctx;
372
Ralf Baechle41c594a2006-04-05 09:45:45 +0100373 ENTER_CRITICAL(flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700374 /* Save old context and create impossible VPN2 value */
375 old_ctx = read_c0_entryhi();
376 old_pagemask = read_c0_pagemask();
377 wired = read_c0_wired();
378 write_c0_wired(wired + 1);
379 write_c0_index(wired);
Ralf Baechle432bef22006-09-08 04:16:21 +0200380 tlbw_use_hazard(); /* What is the hazard here? */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700381 write_c0_pagemask(pagemask);
382 write_c0_entryhi(entryhi);
383 write_c0_entrylo0(entrylo0);
384 write_c0_entrylo1(entrylo1);
385 mtc0_tlbw_hazard();
386 tlb_write_indexed();
387 tlbw_use_hazard();
388
389 write_c0_entryhi(old_ctx);
Ralf Baechle432bef22006-09-08 04:16:21 +0200390 tlbw_use_hazard(); /* What is the hazard here? */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700391 write_c0_pagemask(old_pagemask);
392 local_flush_tlb_all();
Ralf Baechle41c594a2006-04-05 09:45:45 +0100393 EXIT_CRITICAL(flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700394}
395
Ralf Baechle970d0322012-10-18 13:54:15 +0200396#ifdef CONFIG_TRANSPARENT_HUGEPAGE
397
398int __init has_transparent_hugepage(void)
399{
400 unsigned int mask;
401 unsigned long flags;
402
403 ENTER_CRITICAL(flags);
404 write_c0_pagemask(PM_HUGE_MASK);
405 back_to_back_c0_hazard();
406 mask = read_c0_pagemask();
407 write_c0_pagemask(PM_DEFAULT_MASK);
408
409 EXIT_CRITICAL(flags);
410
411 return mask == PM_HUGE_MASK;
412}
413
414#endif /* CONFIG_TRANSPARENT_HUGEPAGE */
415
Paul Gortmaker078a55f2013-06-18 13:38:59 +0000416static int ntlb;
Ralf Baechle41c594a2006-04-05 09:45:45 +0100417static int __init set_ntlb(char *str)
418{
419 get_option(&str, &ntlb);
420 return 1;
421}
422
423__setup("ntlb=", set_ntlb);
424
James Hoganeaa38d62014-02-28 17:09:20 +0000425/*
426 * Configure TLB (for init or after a CPU has been powered off).
427 */
428static void r4k_tlb_configure(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700429{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700430 /*
431 * You should never change this register:
432 * - On R4600 1.7 the tlbp never hits for pages smaller than
433 * the value in the c0_pagemask register.
434 * - The entire mm handling assumes the c0_pagemask register to
Thiemo Seufera7c29962008-02-29 00:43:47 +0000435 * be set to fixed-size pages.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700436 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700437 write_c0_pagemask(PM_DEFAULT_MASK);
438 write_c0_wired(0);
Ralf Baechlecde15b52009-01-06 23:07:20 +0000439 if (current_cpu_type() == CPU_R10000 ||
440 current_cpu_type() == CPU_R12000 ||
441 current_cpu_type() == CPU_R14000)
442 write_c0_framemask(0);
David Daney6dd93442010-02-10 15:12:47 -0800443
Steven J. Hill05857c62012-09-13 16:51:46 -0500444 if (cpu_has_rixi) {
David Daney6dd93442010-02-10 15:12:47 -0800445 /*
446 * Enable the no read, no exec bits, and enable large virtual
447 * address.
448 */
449 u32 pg = PG_RIE | PG_XIE;
450#ifdef CONFIG_64BIT
451 pg |= PG_ELPA;
452#endif
453 write_c0_pagegrain(pg);
454 }
455
Ralf Baechle70342282013-01-22 12:59:30 +0100456 /* From this point on the ARC firmware is dead. */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700457 local_flush_tlb_all();
458
Thiemo Seuferc6281ed2006-03-14 14:35:27 +0000459 /* Did I tell you that ARC SUCKS? */
James Hoganeaa38d62014-02-28 17:09:20 +0000460}
461
462void tlb_init(void)
463{
464 r4k_tlb_configure();
Thiemo Seuferc6281ed2006-03-14 14:35:27 +0000465
Ralf Baechle41c594a2006-04-05 09:45:45 +0100466 if (ntlb) {
467 if (ntlb > 1 && ntlb <= current_cpu_data.tlbsize) {
468 int wired = current_cpu_data.tlbsize - ntlb;
469 write_c0_wired(wired);
470 write_c0_index(wired-1);
Ralf Baechle49a89ef2007-10-11 23:46:15 +0100471 printk("Restricting TLB to %d entries\n", ntlb);
Ralf Baechle41c594a2006-04-05 09:45:45 +0100472 } else
473 printk("Ignoring invalid argument ntlb=%d\n", ntlb);
474 }
475
Linus Torvalds1da177e2005-04-16 15:20:36 -0700476 build_tlb_refill_handler();
477}
James Hoganeaa38d62014-02-28 17:09:20 +0000478
479static int r4k_tlb_pm_notifier(struct notifier_block *self, unsigned long cmd,
480 void *v)
481{
482 switch (cmd) {
483 case CPU_PM_ENTER_FAILED:
484 case CPU_PM_EXIT:
485 r4k_tlb_configure();
486 break;
487 }
488
489 return NOTIFY_OK;
490}
491
492static struct notifier_block r4k_tlb_pm_notifier_block = {
493 .notifier_call = r4k_tlb_pm_notifier,
494};
495
496static int __init r4k_tlb_init_pm(void)
497{
498 return cpu_pm_register_notifier(&r4k_tlb_pm_notifier_block);
499}
500arch_initcall(r4k_tlb_init_pm);