aboutsummaryrefslogtreecommitdiffstats
path: root/arch/mips/mm/tlbex.c
diff options
context:
space:
mode:
Diffstat (limited to 'arch/mips/mm/tlbex.c')
-rw-r--r--arch/mips/mm/tlbex.c252
1 files changed, 115 insertions, 137 deletions
diff --git a/arch/mips/mm/tlbex.c b/arch/mips/mm/tlbex.c
index a61246d3533d..d026302e0ecc 100644
--- a/arch/mips/mm/tlbex.c
+++ b/arch/mips/mm/tlbex.c
@@ -6,7 +6,7 @@
6 * Synthesize TLB refill handlers at runtime. 6 * Synthesize TLB refill handlers at runtime.
7 * 7 *
8 * Copyright (C) 2004,2005,2006 by Thiemo Seufer 8 * Copyright (C) 2004,2005,2006 by Thiemo Seufer
9 * Copyright (C) 2005 Maciej W. Rozycki 9 * Copyright (C) 2005, 2007 Maciej W. Rozycki
10 * Copyright (C) 2006 Ralf Baechle (ralf@linux-mips.org) 10 * Copyright (C) 2006 Ralf Baechle (ralf@linux-mips.org)
11 * 11 *
12 * ... and the days got worse and worse and now you see 12 * ... and the days got worse and worse and now you see
@@ -19,20 +19,15 @@
19 * (Condolences to Napoleon XIV) 19 * (Condolences to Napoleon XIV)
20 */ 20 */
21 21
22#include <stdarg.h>
23
24#include <linux/mm.h>
25#include <linux/kernel.h> 22#include <linux/kernel.h>
26#include <linux/types.h> 23#include <linux/types.h>
27#include <linux/string.h> 24#include <linux/string.h>
28#include <linux/init.h> 25#include <linux/init.h>
29 26
30#include <asm/pgtable.h> 27#include <asm/bugs.h>
31#include <asm/cacheflush.h>
32#include <asm/mmu_context.h> 28#include <asm/mmu_context.h>
33#include <asm/inst.h> 29#include <asm/inst.h>
34#include <asm/elf.h> 30#include <asm/elf.h>
35#include <asm/smp.h>
36#include <asm/war.h> 31#include <asm/war.h>
37 32
38static inline int r45k_bvahwbug(void) 33static inline int r45k_bvahwbug(void)
@@ -66,7 +61,7 @@ static inline int __maybe_unused r10000_llsc_war(void)
66 * why; it's not an issue caused by the core RTL. 61 * why; it's not an issue caused by the core RTL.
67 * 62 *
68 */ 63 */
69static __init int __attribute__((unused)) m4kc_tlbp_war(void) 64static int __init m4kc_tlbp_war(void)
70{ 65{
71 return (current_cpu_data.processor_id & 0xffff00) == 66 return (current_cpu_data.processor_id & 0xffff00) ==
72 (PRID_COMP_MIPS | PRID_IMP_4KC); 67 (PRID_COMP_MIPS | PRID_IMP_4KC);
@@ -140,7 +135,7 @@ struct insn {
140 | (e) << RE_SH \ 135 | (e) << RE_SH \
141 | (f) << FUNC_SH) 136 | (f) << FUNC_SH)
142 137
143static __initdata struct insn insn_table[] = { 138static struct insn insn_table[] __initdata = {
144 { insn_addiu, M(addiu_op, 0, 0, 0, 0, 0), RS | RT | SIMM }, 139 { insn_addiu, M(addiu_op, 0, 0, 0, 0, 0), RS | RT | SIMM },
145 { insn_addu, M(spec_op, 0, 0, 0, 0, addu_op), RS | RT | RD }, 140 { insn_addu, M(spec_op, 0, 0, 0, 0, addu_op), RS | RT | RD },
146 { insn_and, M(spec_op, 0, 0, 0, 0, and_op), RS | RT | RD }, 141 { insn_and, M(spec_op, 0, 0, 0, 0, and_op), RS | RT | RD },
@@ -193,7 +188,7 @@ static __initdata struct insn insn_table[] = {
193 188
194#undef M 189#undef M
195 190
196static __init u32 build_rs(u32 arg) 191static u32 __init build_rs(u32 arg)
197{ 192{
198 if (arg & ~RS_MASK) 193 if (arg & ~RS_MASK)
199 printk(KERN_WARNING "TLB synthesizer field overflow\n"); 194 printk(KERN_WARNING "TLB synthesizer field overflow\n");
@@ -201,7 +196,7 @@ static __init u32 build_rs(u32 arg)
201 return (arg & RS_MASK) << RS_SH; 196 return (arg & RS_MASK) << RS_SH;
202} 197}
203 198
204static __init u32 build_rt(u32 arg) 199static u32 __init build_rt(u32 arg)
205{ 200{
206 if (arg & ~RT_MASK) 201 if (arg & ~RT_MASK)
207 printk(KERN_WARNING "TLB synthesizer field overflow\n"); 202 printk(KERN_WARNING "TLB synthesizer field overflow\n");
@@ -209,7 +204,7 @@ static __init u32 build_rt(u32 arg)
209 return (arg & RT_MASK) << RT_SH; 204 return (arg & RT_MASK) << RT_SH;
210} 205}
211 206
212static __init u32 build_rd(u32 arg) 207static u32 __init build_rd(u32 arg)
213{ 208{
214 if (arg & ~RD_MASK) 209 if (arg & ~RD_MASK)
215 printk(KERN_WARNING "TLB synthesizer field overflow\n"); 210 printk(KERN_WARNING "TLB synthesizer field overflow\n");
@@ -217,7 +212,7 @@ static __init u32 build_rd(u32 arg)
217 return (arg & RD_MASK) << RD_SH; 212 return (arg & RD_MASK) << RD_SH;
218} 213}
219 214
220static __init u32 build_re(u32 arg) 215static u32 __init build_re(u32 arg)
221{ 216{
222 if (arg & ~RE_MASK) 217 if (arg & ~RE_MASK)
223 printk(KERN_WARNING "TLB synthesizer field overflow\n"); 218 printk(KERN_WARNING "TLB synthesizer field overflow\n");
@@ -225,7 +220,7 @@ static __init u32 build_re(u32 arg)
225 return (arg & RE_MASK) << RE_SH; 220 return (arg & RE_MASK) << RE_SH;
226} 221}
227 222
228static __init u32 build_simm(s32 arg) 223static u32 __init build_simm(s32 arg)
229{ 224{
230 if (arg > 0x7fff || arg < -0x8000) 225 if (arg > 0x7fff || arg < -0x8000)
231 printk(KERN_WARNING "TLB synthesizer field overflow\n"); 226 printk(KERN_WARNING "TLB synthesizer field overflow\n");
@@ -233,7 +228,7 @@ static __init u32 build_simm(s32 arg)
233 return arg & 0xffff; 228 return arg & 0xffff;
234} 229}
235 230
236static __init u32 build_uimm(u32 arg) 231static u32 __init build_uimm(u32 arg)
237{ 232{
238 if (arg & ~IMM_MASK) 233 if (arg & ~IMM_MASK)
239 printk(KERN_WARNING "TLB synthesizer field overflow\n"); 234 printk(KERN_WARNING "TLB synthesizer field overflow\n");
@@ -241,7 +236,7 @@ static __init u32 build_uimm(u32 arg)
241 return arg & IMM_MASK; 236 return arg & IMM_MASK;
242} 237}
243 238
244static __init u32 build_bimm(s32 arg) 239static u32 __init build_bimm(s32 arg)
245{ 240{
246 if (arg > 0x1ffff || arg < -0x20000) 241 if (arg > 0x1ffff || arg < -0x20000)
247 printk(KERN_WARNING "TLB synthesizer field overflow\n"); 242 printk(KERN_WARNING "TLB synthesizer field overflow\n");
@@ -252,7 +247,7 @@ static __init u32 build_bimm(s32 arg)
252 return ((arg < 0) ? (1 << 15) : 0) | ((arg >> 2) & 0x7fff); 247 return ((arg < 0) ? (1 << 15) : 0) | ((arg >> 2) & 0x7fff);
253} 248}
254 249
255static __init u32 build_jimm(u32 arg) 250static u32 __init build_jimm(u32 arg)
256{ 251{
257 if (arg & ~((JIMM_MASK) << 2)) 252 if (arg & ~((JIMM_MASK) << 2))
258 printk(KERN_WARNING "TLB synthesizer field overflow\n"); 253 printk(KERN_WARNING "TLB synthesizer field overflow\n");
@@ -260,7 +255,7 @@ static __init u32 build_jimm(u32 arg)
260 return (arg >> 2) & JIMM_MASK; 255 return (arg >> 2) & JIMM_MASK;
261} 256}
262 257
263static __init u32 build_func(u32 arg) 258static u32 __init build_func(u32 arg)
264{ 259{
265 if (arg & ~FUNC_MASK) 260 if (arg & ~FUNC_MASK)
266 printk(KERN_WARNING "TLB synthesizer field overflow\n"); 261 printk(KERN_WARNING "TLB synthesizer field overflow\n");
@@ -268,7 +263,7 @@ static __init u32 build_func(u32 arg)
268 return arg & FUNC_MASK; 263 return arg & FUNC_MASK;
269} 264}
270 265
271static __init u32 build_set(u32 arg) 266static u32 __init build_set(u32 arg)
272{ 267{
273 if (arg & ~SET_MASK) 268 if (arg & ~SET_MASK)
274 printk(KERN_WARNING "TLB synthesizer field overflow\n"); 269 printk(KERN_WARNING "TLB synthesizer field overflow\n");
@@ -293,7 +288,7 @@ static void __init build_insn(u32 **buf, enum opcode opc, ...)
293 break; 288 break;
294 } 289 }
295 290
296 if (!ip) 291 if (!ip || (opc == insn_daddiu && r4k_daddiu_bug()))
297 panic("Unsupported TLB synthesizer instruction %d", opc); 292 panic("Unsupported TLB synthesizer instruction %d", opc);
298 293
299 op = ip->match; 294 op = ip->match;
@@ -315,69 +310,69 @@ static void __init build_insn(u32 **buf, enum opcode opc, ...)
315} 310}
316 311
317#define I_u1u2u3(op) \ 312#define I_u1u2u3(op) \
318 static inline void __init i##op(u32 **buf, unsigned int a, \ 313 static void __init __maybe_unused i##op(u32 **buf, unsigned int a, \
319 unsigned int b, unsigned int c) \ 314 unsigned int b, unsigned int c) \
320 { \ 315 { \
321 build_insn(buf, insn##op, a, b, c); \ 316 build_insn(buf, insn##op, a, b, c); \
322 } 317 }
323 318
324#define I_u2u1u3(op) \ 319#define I_u2u1u3(op) \
325 static inline void __init i##op(u32 **buf, unsigned int a, \ 320 static void __init __maybe_unused i##op(u32 **buf, unsigned int a, \
326 unsigned int b, unsigned int c) \ 321 unsigned int b, unsigned int c) \
327 { \ 322 { \
328 build_insn(buf, insn##op, b, a, c); \ 323 build_insn(buf, insn##op, b, a, c); \
329 } 324 }
330 325
331#define I_u3u1u2(op) \ 326#define I_u3u1u2(op) \
332 static inline void __init i##op(u32 **buf, unsigned int a, \ 327 static void __init __maybe_unused i##op(u32 **buf, unsigned int a, \
333 unsigned int b, unsigned int c) \ 328 unsigned int b, unsigned int c) \
334 { \ 329 { \
335 build_insn(buf, insn##op, b, c, a); \ 330 build_insn(buf, insn##op, b, c, a); \
336 } 331 }
337 332
338#define I_u1u2s3(op) \ 333#define I_u1u2s3(op) \
339 static inline void __init i##op(u32 **buf, unsigned int a, \ 334 static void __init __maybe_unused i##op(u32 **buf, unsigned int a, \
340 unsigned int b, signed int c) \ 335 unsigned int b, signed int c) \
341 { \ 336 { \
342 build_insn(buf, insn##op, a, b, c); \ 337 build_insn(buf, insn##op, a, b, c); \
343 } 338 }
344 339
345#define I_u2s3u1(op) \ 340#define I_u2s3u1(op) \
346 static inline void __init i##op(u32 **buf, unsigned int a, \ 341 static void __init __maybe_unused i##op(u32 **buf, unsigned int a, \
347 signed int b, unsigned int c) \ 342 signed int b, unsigned int c) \
348 { \ 343 { \
349 build_insn(buf, insn##op, c, a, b); \ 344 build_insn(buf, insn##op, c, a, b); \
350 } 345 }
351 346
352#define I_u2u1s3(op) \ 347#define I_u2u1s3(op) \
353 static inline void __init i##op(u32 **buf, unsigned int a, \ 348 static void __init __maybe_unused i##op(u32 **buf, unsigned int a, \
354 unsigned int b, signed int c) \ 349 unsigned int b, signed int c) \
355 { \ 350 { \
356 build_insn(buf, insn##op, b, a, c); \ 351 build_insn(buf, insn##op, b, a, c); \
357 } 352 }
358 353
359#define I_u1u2(op) \ 354#define I_u1u2(op) \
360 static inline void __init i##op(u32 **buf, unsigned int a, \ 355 static void __init __maybe_unused i##op(u32 **buf, unsigned int a, \
361 unsigned int b) \ 356 unsigned int b) \
362 { \ 357 { \
363 build_insn(buf, insn##op, a, b); \ 358 build_insn(buf, insn##op, a, b); \
364 } 359 }
365 360
366#define I_u1s2(op) \ 361#define I_u1s2(op) \
367 static inline void __init i##op(u32 **buf, unsigned int a, \ 362 static void __init __maybe_unused i##op(u32 **buf, unsigned int a, \
368 signed int b) \ 363 signed int b) \
369 { \ 364 { \
370 build_insn(buf, insn##op, a, b); \ 365 build_insn(buf, insn##op, a, b); \
371 } 366 }
372 367
373#define I_u1(op) \ 368#define I_u1(op) \
374 static inline void __init i##op(u32 **buf, unsigned int a) \ 369 static void __init __maybe_unused i##op(u32 **buf, unsigned int a) \
375 { \ 370 { \
376 build_insn(buf, insn##op, a); \ 371 build_insn(buf, insn##op, a); \
377 } 372 }
378 373
379#define I_0(op) \ 374#define I_0(op) \
380 static inline void __init i##op(u32 **buf) \ 375 static void __init __maybe_unused i##op(u32 **buf) \
381 { \ 376 { \
382 build_insn(buf, insn##op); \ 377 build_insn(buf, insn##op); \
383 } 378 }
@@ -457,7 +452,7 @@ struct label {
457 enum label_id lab; 452 enum label_id lab;
458}; 453};
459 454
460static __init void build_label(struct label **lab, u32 *addr, 455static void __init build_label(struct label **lab, u32 *addr,
461 enum label_id l) 456 enum label_id l)
462{ 457{
463 (*lab)->addr = addr; 458 (*lab)->addr = addr;
@@ -466,7 +461,7 @@ static __init void build_label(struct label **lab, u32 *addr,
466} 461}
467 462
468#define L_LA(lb) \ 463#define L_LA(lb) \
469 static inline void l##lb(struct label **lab, u32 *addr) \ 464 static inline void __init l##lb(struct label **lab, u32 *addr) \
470 { \ 465 { \
471 build_label(lab, addr, label##lb); \ 466 build_label(lab, addr, label##lb); \
472 } 467 }
@@ -525,37 +520,46 @@ L_LA(_r3000_write_probe_fail)
525#define i_ssnop(buf) i_sll(buf, 0, 0, 1) 520#define i_ssnop(buf) i_sll(buf, 0, 0, 1)
526#define i_ehb(buf) i_sll(buf, 0, 0, 3) 521#define i_ehb(buf) i_sll(buf, 0, 0, 3)
527 522
528#ifdef CONFIG_64BIT 523static int __init __maybe_unused in_compat_space_p(long addr)
529static __init int __maybe_unused in_compat_space_p(long addr)
530{ 524{
531 /* Is this address in 32bit compat space? */ 525 /* Is this address in 32bit compat space? */
526#ifdef CONFIG_64BIT
532 return (((addr) & 0xffffffff00000000L) == 0xffffffff00000000L); 527 return (((addr) & 0xffffffff00000000L) == 0xffffffff00000000L);
528#else
529 return 1;
530#endif
533} 531}
534 532
535static __init int __maybe_unused rel_highest(long val) 533static int __init __maybe_unused rel_highest(long val)
536{ 534{
535#ifdef CONFIG_64BIT
537 return ((((val + 0x800080008000L) >> 48) & 0xffff) ^ 0x8000) - 0x8000; 536 return ((((val + 0x800080008000L) >> 48) & 0xffff) ^ 0x8000) - 0x8000;
537#else
538 return 0;
539#endif
538} 540}
539 541
540static __init int __maybe_unused rel_higher(long val) 542static int __init __maybe_unused rel_higher(long val)
541{ 543{
544#ifdef CONFIG_64BIT
542 return ((((val + 0x80008000L) >> 32) & 0xffff) ^ 0x8000) - 0x8000; 545 return ((((val + 0x80008000L) >> 32) & 0xffff) ^ 0x8000) - 0x8000;
543} 546#else
547 return 0;
544#endif 548#endif
549}
545 550
546static __init int rel_hi(long val) 551static int __init rel_hi(long val)
547{ 552{
548 return ((((val + 0x8000L) >> 16) & 0xffff) ^ 0x8000) - 0x8000; 553 return ((((val + 0x8000L) >> 16) & 0xffff) ^ 0x8000) - 0x8000;
549} 554}
550 555
551static __init int rel_lo(long val) 556static int __init rel_lo(long val)
552{ 557{
553 return ((val & 0xffff) ^ 0x8000) - 0x8000; 558 return ((val & 0xffff) ^ 0x8000) - 0x8000;
554} 559}
555 560
556static __init void i_LA_mostly(u32 **buf, unsigned int rs, long addr) 561static void __init i_LA_mostly(u32 **buf, unsigned int rs, long addr)
557{ 562{
558#ifdef CONFIG_64BIT
559 if (!in_compat_space_p(addr)) { 563 if (!in_compat_space_p(addr)) {
560 i_lui(buf, rs, rel_highest(addr)); 564 i_lui(buf, rs, rel_highest(addr));
561 if (rel_higher(addr)) 565 if (rel_higher(addr))
@@ -567,16 +571,18 @@ static __init void i_LA_mostly(u32 **buf, unsigned int rs, long addr)
567 } else 571 } else
568 i_dsll32(buf, rs, rs, 0); 572 i_dsll32(buf, rs, rs, 0);
569 } else 573 } else
570#endif
571 i_lui(buf, rs, rel_hi(addr)); 574 i_lui(buf, rs, rel_hi(addr));
572} 575}
573 576
574static __init void __maybe_unused i_LA(u32 **buf, unsigned int rs, 577static void __init __maybe_unused i_LA(u32 **buf, unsigned int rs, long addr)
575 long addr)
576{ 578{
577 i_LA_mostly(buf, rs, addr); 579 i_LA_mostly(buf, rs, addr);
578 if (rel_lo(addr)) 580 if (rel_lo(addr)) {
579 i_ADDIU(buf, rs, rs, rel_lo(addr)); 581 if (!in_compat_space_p(addr))
582 i_daddiu(buf, rs, rs, rel_lo(addr));
583 else
584 i_addiu(buf, rs, rs, rel_lo(addr));
585 }
580} 586}
581 587
582/* 588/*
@@ -589,7 +595,7 @@ struct reloc {
589 enum label_id lab; 595 enum label_id lab;
590}; 596};
591 597
592static __init void r_mips_pc16(struct reloc **rel, u32 *addr, 598static void __init r_mips_pc16(struct reloc **rel, u32 *addr,
593 enum label_id l) 599 enum label_id l)
594{ 600{
595 (*rel)->addr = addr; 601 (*rel)->addr = addr;
@@ -614,7 +620,7 @@ static inline void __resolve_relocs(struct reloc *rel, struct label *lab)
614 } 620 }
615} 621}
616 622
617static __init void resolve_relocs(struct reloc *rel, struct label *lab) 623static void __init resolve_relocs(struct reloc *rel, struct label *lab)
618{ 624{
619 struct label *l; 625 struct label *l;
620 626
@@ -624,7 +630,7 @@ static __init void resolve_relocs(struct reloc *rel, struct label *lab)
624 __resolve_relocs(rel, l); 630 __resolve_relocs(rel, l);
625} 631}
626 632
627static __init void move_relocs(struct reloc *rel, u32 *first, u32 *end, 633static void __init move_relocs(struct reloc *rel, u32 *first, u32 *end,
628 long off) 634 long off)
629{ 635{
630 for (; rel->lab != label_invalid; rel++) 636 for (; rel->lab != label_invalid; rel++)
@@ -632,7 +638,7 @@ static __init void move_relocs(struct reloc *rel, u32 *first, u32 *end,
632 rel->addr += off; 638 rel->addr += off;
633} 639}
634 640
635static __init void move_labels(struct label *lab, u32 *first, u32 *end, 641static void __init move_labels(struct label *lab, u32 *first, u32 *end,
636 long off) 642 long off)
637{ 643{
638 for (; lab->lab != label_invalid; lab++) 644 for (; lab->lab != label_invalid; lab++)
@@ -640,7 +646,7 @@ static __init void move_labels(struct label *lab, u32 *first, u32 *end,
640 lab->addr += off; 646 lab->addr += off;
641} 647}
642 648
643static __init void copy_handler(struct reloc *rel, struct label *lab, 649static void __init copy_handler(struct reloc *rel, struct label *lab,
644 u32 *first, u32 *end, u32 *target) 650 u32 *first, u32 *end, u32 *target)
645{ 651{
646 long off = (long)(target - first); 652 long off = (long)(target - first);
@@ -651,7 +657,7 @@ static __init void copy_handler(struct reloc *rel, struct label *lab,
651 move_labels(lab, first, end, off); 657 move_labels(lab, first, end, off);
652} 658}
653 659
654static __init int __maybe_unused insn_has_bdelay(struct reloc *rel, 660static int __init __maybe_unused insn_has_bdelay(struct reloc *rel,
655 u32 *addr) 661 u32 *addr)
656{ 662{
657 for (; rel->lab != label_invalid; rel++) { 663 for (; rel->lab != label_invalid; rel++) {
@@ -714,6 +720,22 @@ il_bgez(u32 **p, struct reloc **r, unsigned int reg, enum label_id l)
714 i_bgez(p, reg, 0); 720 i_bgez(p, reg, 0);
715} 721}
716 722
723/*
724 * For debug purposes.
725 */
726static inline void dump_handler(const u32 *handler, int count)
727{
728 int i;
729
730 pr_debug("\t.set push\n");
731 pr_debug("\t.set noreorder\n");
732
733 for (i = 0; i < count; i++)
734 pr_debug("\t%p\t.word 0x%08x\n", &handler[i], handler[i]);
735
736 pr_debug("\t.set pop\n");
737}
738
717/* The only general purpose registers allowed in TLB handlers. */ 739/* The only general purpose registers allowed in TLB handlers. */
718#define K0 26 740#define K0 26
719#define K1 27 741#define K1 27
@@ -743,11 +765,11 @@ il_bgez(u32 **p, struct reloc **r, unsigned int reg, enum label_id l)
743 * We deliberately chose a buffer size of 128, so we won't scribble 765 * We deliberately chose a buffer size of 128, so we won't scribble
744 * over anything important on overflow before we panic. 766 * over anything important on overflow before we panic.
745 */ 767 */
746static __initdata u32 tlb_handler[128]; 768static u32 tlb_handler[128] __initdata;
747 769
748/* simply assume worst case size for labels and relocs */ 770/* simply assume worst case size for labels and relocs */
749static __initdata struct label labels[128]; 771static struct label labels[128] __initdata;
750static __initdata struct reloc relocs[128]; 772static struct reloc relocs[128] __initdata;
751 773
752/* 774/*
753 * The R3000 TLB handler is simple. 775 * The R3000 TLB handler is simple.
@@ -756,7 +778,6 @@ static void __init build_r3000_tlb_refill_handler(void)
756{ 778{
757 long pgdc = (long)pgd_current; 779 long pgdc = (long)pgd_current;
758 u32 *p; 780 u32 *p;
759 int i;
760 781
761 memset(tlb_handler, 0, sizeof(tlb_handler)); 782 memset(tlb_handler, 0, sizeof(tlb_handler));
762 p = tlb_handler; 783 p = tlb_handler;
@@ -785,13 +806,9 @@ static void __init build_r3000_tlb_refill_handler(void)
785 pr_info("Synthesized TLB refill handler (%u instructions).\n", 806 pr_info("Synthesized TLB refill handler (%u instructions).\n",
786 (unsigned int)(p - tlb_handler)); 807 (unsigned int)(p - tlb_handler));
787 808
788 pr_debug("\t.set push\n");
789 pr_debug("\t.set noreorder\n");
790 for (i = 0; i < (p - tlb_handler); i++)
791 pr_debug("\t.word 0x%08x\n", tlb_handler[i]);
792 pr_debug("\t.set pop\n");
793
794 memcpy((void *)ebase, tlb_handler, 0x80); 809 memcpy((void *)ebase, tlb_handler, 0x80);
810
811 dump_handler((u32 *)ebase, 32);
795} 812}
796 813
797/* 814/*
@@ -801,7 +818,7 @@ static void __init build_r3000_tlb_refill_handler(void)
801 * other one.To keep things simple, we first assume linear space, 818 * other one.To keep things simple, we first assume linear space,
802 * then we relocate it to the final handler layout as needed. 819 * then we relocate it to the final handler layout as needed.
803 */ 820 */
804static __initdata u32 final_handler[64]; 821static u32 final_handler[64] __initdata;
805 822
806/* 823/*
807 * Hazards 824 * Hazards
@@ -825,7 +842,7 @@ static __initdata u32 final_handler[64];
825 * 842 *
826 * As if we MIPS hackers wouldn't know how to nop pipelines happy ... 843 * As if we MIPS hackers wouldn't know how to nop pipelines happy ...
827 */ 844 */
828static __init void __maybe_unused build_tlb_probe_entry(u32 **p) 845static void __init __maybe_unused build_tlb_probe_entry(u32 **p)
829{ 846{
830 switch (current_cpu_type()) { 847 switch (current_cpu_type()) {
831 /* Found by experiment: R4600 v2.0 needs this, too. */ 848 /* Found by experiment: R4600 v2.0 needs this, too. */
@@ -849,7 +866,7 @@ static __init void __maybe_unused build_tlb_probe_entry(u32 **p)
849 */ 866 */
850enum tlb_write_entry { tlb_random, tlb_indexed }; 867enum tlb_write_entry { tlb_random, tlb_indexed };
851 868
852static __init void build_tlb_write_entry(u32 **p, struct label **l, 869static void __init build_tlb_write_entry(u32 **p, struct label **l,
853 struct reloc **r, 870 struct reloc **r,
854 enum tlb_write_entry wmode) 871 enum tlb_write_entry wmode)
855{ 872{
@@ -860,6 +877,12 @@ static __init void build_tlb_write_entry(u32 **p, struct label **l,
860 case tlb_indexed: tlbw = i_tlbwi; break; 877 case tlb_indexed: tlbw = i_tlbwi; break;
861 } 878 }
862 879
880 if (cpu_has_mips_r2) {
881 i_ehb(p);
882 tlbw(p);
883 return;
884 }
885
863 switch (current_cpu_type()) { 886 switch (current_cpu_type()) {
864 case CPU_R4000PC: 887 case CPU_R4000PC:
865 case CPU_R4000SC: 888 case CPU_R4000SC:
@@ -894,6 +917,8 @@ static __init void build_tlb_write_entry(u32 **p, struct label **l,
894 case CPU_AU1500: 917 case CPU_AU1500:
895 case CPU_AU1550: 918 case CPU_AU1550:
896 case CPU_AU1200: 919 case CPU_AU1200:
920 case CPU_AU1210:
921 case CPU_AU1250:
897 case CPU_PR4450: 922 case CPU_PR4450:
898 i_nop(p); 923 i_nop(p);
899 tlbw(p); 924 tlbw(p);
@@ -935,14 +960,6 @@ static __init void build_tlb_write_entry(u32 **p, struct label **l,
935 tlbw(p); 960 tlbw(p);
936 break; 961 break;
937 962
938 case CPU_4KEC:
939 case CPU_24K:
940 case CPU_34K:
941 case CPU_74K:
942 i_ehb(p);
943 tlbw(p);
944 break;
945
946 case CPU_RM9000: 963 case CPU_RM9000:
947 /* 964 /*
948 * When the JTLB is updated by tlbwi or tlbwr, a subsequent 965 * When the JTLB is updated by tlbwi or tlbwr, a subsequent
@@ -993,7 +1010,7 @@ static __init void build_tlb_write_entry(u32 **p, struct label **l,
993 * TMP and PTR are scratch. 1010 * TMP and PTR are scratch.
994 * TMP will be clobbered, PTR will hold the pmd entry. 1011 * TMP will be clobbered, PTR will hold the pmd entry.
995 */ 1012 */
996static __init void 1013static void __init
997build_get_pmde64(u32 **p, struct label **l, struct reloc **r, 1014build_get_pmde64(u32 **p, struct label **l, struct reloc **r,
998 unsigned int tmp, unsigned int ptr) 1015 unsigned int tmp, unsigned int ptr)
999{ 1016{
@@ -1054,7 +1071,7 @@ build_get_pmde64(u32 **p, struct label **l, struct reloc **r,
1054 * BVADDR is the faulting address, PTR is scratch. 1071 * BVADDR is the faulting address, PTR is scratch.
1055 * PTR will hold the pgd for vmalloc. 1072 * PTR will hold the pgd for vmalloc.
1056 */ 1073 */
1057static __init void 1074static void __init
1058build_get_pgd_vmalloc64(u32 **p, struct label **l, struct reloc **r, 1075build_get_pgd_vmalloc64(u32 **p, struct label **l, struct reloc **r,
1059 unsigned int bvaddr, unsigned int ptr) 1076 unsigned int bvaddr, unsigned int ptr)
1060{ 1077{
@@ -1087,7 +1104,10 @@ build_get_pgd_vmalloc64(u32 **p, struct label **l, struct reloc **r,
1087 } else { 1104 } else {
1088 i_LA_mostly(p, ptr, modd); 1105 i_LA_mostly(p, ptr, modd);
1089 il_b(p, r, label_vmalloc_done); 1106 il_b(p, r, label_vmalloc_done);
1090 i_daddiu(p, ptr, ptr, rel_lo(modd)); 1107 if (in_compat_space_p(modd))
1108 i_addiu(p, ptr, ptr, rel_lo(modd));
1109 else
1110 i_daddiu(p, ptr, ptr, rel_lo(modd));
1091 } 1111 }
1092 1112
1093 l_vmalloc(l, *p); 1113 l_vmalloc(l, *p);
@@ -1108,7 +1128,10 @@ build_get_pgd_vmalloc64(u32 **p, struct label **l, struct reloc **r,
1108 } else { 1128 } else {
1109 i_LA_mostly(p, ptr, swpd); 1129 i_LA_mostly(p, ptr, swpd);
1110 il_b(p, r, label_vmalloc_done); 1130 il_b(p, r, label_vmalloc_done);
1111 i_daddiu(p, ptr, ptr, rel_lo(swpd)); 1131 if (in_compat_space_p(swpd))
1132 i_addiu(p, ptr, ptr, rel_lo(swpd));
1133 else
1134 i_daddiu(p, ptr, ptr, rel_lo(swpd));
1112 } 1135 }
1113} 1136}
1114 1137
@@ -1118,7 +1141,7 @@ build_get_pgd_vmalloc64(u32 **p, struct label **l, struct reloc **r,
1118 * TMP and PTR are scratch. 1141 * TMP and PTR are scratch.
1119 * TMP will be clobbered, PTR will hold the pgd entry. 1142 * TMP will be clobbered, PTR will hold the pgd entry.
1120 */ 1143 */
1121static __init void __maybe_unused 1144static void __init __maybe_unused
1122build_get_pgde32(u32 **p, unsigned int tmp, unsigned int ptr) 1145build_get_pgde32(u32 **p, unsigned int tmp, unsigned int ptr)
1123{ 1146{
1124 long pgdc = (long)pgd_current; 1147 long pgdc = (long)pgd_current;
@@ -1153,7 +1176,7 @@ build_get_pgde32(u32 **p, unsigned int tmp, unsigned int ptr)
1153 1176
1154#endif /* !CONFIG_64BIT */ 1177#endif /* !CONFIG_64BIT */
1155 1178
1156static __init void build_adjust_context(u32 **p, unsigned int ctx) 1179static void __init build_adjust_context(u32 **p, unsigned int ctx)
1157{ 1180{
1158 unsigned int shift = 4 - (PTE_T_LOG2 + 1) + PAGE_SHIFT - 12; 1181 unsigned int shift = 4 - (PTE_T_LOG2 + 1) + PAGE_SHIFT - 12;
1159 unsigned int mask = (PTRS_PER_PTE / 2 - 1) << (PTE_T_LOG2 + 1); 1182 unsigned int mask = (PTRS_PER_PTE / 2 - 1) << (PTE_T_LOG2 + 1);
@@ -1179,7 +1202,7 @@ static __init void build_adjust_context(u32 **p, unsigned int ctx)
1179 i_andi(p, ctx, ctx, mask); 1202 i_andi(p, ctx, ctx, mask);
1180} 1203}
1181 1204
1182static __init void build_get_ptep(u32 **p, unsigned int tmp, unsigned int ptr) 1205static void __init build_get_ptep(u32 **p, unsigned int tmp, unsigned int ptr)
1183{ 1206{
1184 /* 1207 /*
1185 * Bug workaround for the Nevada. It seems as if under certain 1208 * Bug workaround for the Nevada. It seems as if under certain
@@ -1204,7 +1227,7 @@ static __init void build_get_ptep(u32 **p, unsigned int tmp, unsigned int ptr)
1204 i_ADDU(p, ptr, ptr, tmp); /* add in offset */ 1227 i_ADDU(p, ptr, ptr, tmp); /* add in offset */
1205} 1228}
1206 1229
1207static __init void build_update_entries(u32 **p, unsigned int tmp, 1230static void __init build_update_entries(u32 **p, unsigned int tmp,
1208 unsigned int ptep) 1231 unsigned int ptep)
1209{ 1232{
1210 /* 1233 /*
@@ -1254,7 +1277,6 @@ static void __init build_r4000_tlb_refill_handler(void)
1254 struct reloc *r = relocs; 1277 struct reloc *r = relocs;
1255 u32 *f; 1278 u32 *f;
1256 unsigned int final_len; 1279 unsigned int final_len;
1257 int i;
1258 1280
1259 memset(tlb_handler, 0, sizeof(tlb_handler)); 1281 memset(tlb_handler, 0, sizeof(tlb_handler));
1260 memset(labels, 0, sizeof(labels)); 1282 memset(labels, 0, sizeof(labels));
@@ -1356,20 +1378,9 @@ static void __init build_r4000_tlb_refill_handler(void)
1356 pr_info("Synthesized TLB refill handler (%u instructions).\n", 1378 pr_info("Synthesized TLB refill handler (%u instructions).\n",
1357 final_len); 1379 final_len);
1358 1380
1359 f = final_handler;
1360#if defined(CONFIG_64BIT) && !defined(CONFIG_CPU_LOONGSON2)
1361 if (final_len > 32)
1362 final_len = 64;
1363 else
1364 f = final_handler + 32;
1365#endif /* CONFIG_64BIT */
1366 pr_debug("\t.set push\n");
1367 pr_debug("\t.set noreorder\n");
1368 for (i = 0; i < final_len; i++)
1369 pr_debug("\t.word 0x%08x\n", f[i]);
1370 pr_debug("\t.set pop\n");
1371
1372 memcpy((void *)ebase, final_handler, 0x100); 1381 memcpy((void *)ebase, final_handler, 0x100);
1382
1383 dump_handler((u32 *)ebase, 64);
1373} 1384}
1374 1385
1375/* 1386/*
@@ -1381,18 +1392,15 @@ static void __init build_r4000_tlb_refill_handler(void)
1381extern void tlb_do_page_fault_0(void); 1392extern void tlb_do_page_fault_0(void);
1382extern void tlb_do_page_fault_1(void); 1393extern void tlb_do_page_fault_1(void);
1383 1394
1384#define __tlb_handler_align \
1385 __attribute__((__aligned__(1 << CONFIG_MIPS_L1_CACHE_SHIFT)))
1386
1387/* 1395/*
1388 * 128 instructions for the fastpath handler is generous and should 1396 * 128 instructions for the fastpath handler is generous and should
1389 * never be exceeded. 1397 * never be exceeded.
1390 */ 1398 */
1391#define FASTPATH_SIZE 128 1399#define FASTPATH_SIZE 128
1392 1400
1393u32 __tlb_handler_align handle_tlbl[FASTPATH_SIZE]; 1401u32 handle_tlbl[FASTPATH_SIZE] __cacheline_aligned;
1394u32 __tlb_handler_align handle_tlbs[FASTPATH_SIZE]; 1402u32 handle_tlbs[FASTPATH_SIZE] __cacheline_aligned;
1395u32 __tlb_handler_align handle_tlbm[FASTPATH_SIZE]; 1403u32 handle_tlbm[FASTPATH_SIZE] __cacheline_aligned;
1396 1404
1397static void __init 1405static void __init
1398iPTE_LW(u32 **p, struct label **l, unsigned int pte, unsigned int ptr) 1406iPTE_LW(u32 **p, struct label **l, unsigned int pte, unsigned int ptr)
@@ -1600,7 +1608,6 @@ static void __init build_r3000_tlb_load_handler(void)
1600 u32 *p = handle_tlbl; 1608 u32 *p = handle_tlbl;
1601 struct label *l = labels; 1609 struct label *l = labels;
1602 struct reloc *r = relocs; 1610 struct reloc *r = relocs;
1603 int i;
1604 1611
1605 memset(handle_tlbl, 0, sizeof(handle_tlbl)); 1612 memset(handle_tlbl, 0, sizeof(handle_tlbl));
1606 memset(labels, 0, sizeof(labels)); 1613 memset(labels, 0, sizeof(labels));
@@ -1623,11 +1630,7 @@ static void __init build_r3000_tlb_load_handler(void)
1623 pr_info("Synthesized TLB load handler fastpath (%u instructions).\n", 1630 pr_info("Synthesized TLB load handler fastpath (%u instructions).\n",
1624 (unsigned int)(p - handle_tlbl)); 1631 (unsigned int)(p - handle_tlbl));
1625 1632
1626 pr_debug("\t.set push\n"); 1633 dump_handler(handle_tlbl, ARRAY_SIZE(handle_tlbl));
1627 pr_debug("\t.set noreorder\n");
1628 for (i = 0; i < (p - handle_tlbl); i++)
1629 pr_debug("\t.word 0x%08x\n", handle_tlbl[i]);
1630 pr_debug("\t.set pop\n");
1631} 1634}
1632 1635
1633static void __init build_r3000_tlb_store_handler(void) 1636static void __init build_r3000_tlb_store_handler(void)
@@ -1635,7 +1638,6 @@ static void __init build_r3000_tlb_store_handler(void)
1635 u32 *p = handle_tlbs; 1638 u32 *p = handle_tlbs;
1636 struct label *l = labels; 1639 struct label *l = labels;
1637 struct reloc *r = relocs; 1640 struct reloc *r = relocs;
1638 int i;
1639 1641
1640 memset(handle_tlbs, 0, sizeof(handle_tlbs)); 1642 memset(handle_tlbs, 0, sizeof(handle_tlbs));
1641 memset(labels, 0, sizeof(labels)); 1643 memset(labels, 0, sizeof(labels));
@@ -1658,11 +1660,7 @@ static void __init build_r3000_tlb_store_handler(void)
1658 pr_info("Synthesized TLB store handler fastpath (%u instructions).\n", 1660 pr_info("Synthesized TLB store handler fastpath (%u instructions).\n",
1659 (unsigned int)(p - handle_tlbs)); 1661 (unsigned int)(p - handle_tlbs));
1660 1662
1661 pr_debug("\t.set push\n"); 1663 dump_handler(handle_tlbs, ARRAY_SIZE(handle_tlbs));
1662 pr_debug("\t.set noreorder\n");
1663 for (i = 0; i < (p - handle_tlbs); i++)
1664 pr_debug("\t.word 0x%08x\n", handle_tlbs[i]);
1665 pr_debug("\t.set pop\n");
1666} 1664}
1667 1665
1668static void __init build_r3000_tlb_modify_handler(void) 1666static void __init build_r3000_tlb_modify_handler(void)
@@ -1670,7 +1668,6 @@ static void __init build_r3000_tlb_modify_handler(void)
1670 u32 *p = handle_tlbm; 1668 u32 *p = handle_tlbm;
1671 struct label *l = labels; 1669 struct label *l = labels;
1672 struct reloc *r = relocs; 1670 struct reloc *r = relocs;
1673 int i;
1674 1671
1675 memset(handle_tlbm, 0, sizeof(handle_tlbm)); 1672 memset(handle_tlbm, 0, sizeof(handle_tlbm));
1676 memset(labels, 0, sizeof(labels)); 1673 memset(labels, 0, sizeof(labels));
@@ -1693,11 +1690,7 @@ static void __init build_r3000_tlb_modify_handler(void)
1693 pr_info("Synthesized TLB modify handler fastpath (%u instructions).\n", 1690 pr_info("Synthesized TLB modify handler fastpath (%u instructions).\n",
1694 (unsigned int)(p - handle_tlbm)); 1691 (unsigned int)(p - handle_tlbm));
1695 1692
1696 pr_debug("\t.set push\n"); 1693 dump_handler(handle_tlbm, ARRAY_SIZE(handle_tlbm));
1697 pr_debug("\t.set noreorder\n");
1698 for (i = 0; i < (p - handle_tlbm); i++)
1699 pr_debug("\t.word 0x%08x\n", handle_tlbm[i]);
1700 pr_debug("\t.set pop\n");
1701} 1694}
1702 1695
1703/* 1696/*
@@ -1750,7 +1743,6 @@ static void __init build_r4000_tlb_load_handler(void)
1750 u32 *p = handle_tlbl; 1743 u32 *p = handle_tlbl;
1751 struct label *l = labels; 1744 struct label *l = labels;
1752 struct reloc *r = relocs; 1745 struct reloc *r = relocs;
1753 int i;
1754 1746
1755 memset(handle_tlbl, 0, sizeof(handle_tlbl)); 1747 memset(handle_tlbl, 0, sizeof(handle_tlbl));
1756 memset(labels, 0, sizeof(labels)); 1748 memset(labels, 0, sizeof(labels));
@@ -1783,11 +1775,7 @@ static void __init build_r4000_tlb_load_handler(void)
1783 pr_info("Synthesized TLB load handler fastpath (%u instructions).\n", 1775 pr_info("Synthesized TLB load handler fastpath (%u instructions).\n",
1784 (unsigned int)(p - handle_tlbl)); 1776 (unsigned int)(p - handle_tlbl));
1785 1777
1786 pr_debug("\t.set push\n"); 1778 dump_handler(handle_tlbl, ARRAY_SIZE(handle_tlbl));
1787 pr_debug("\t.set noreorder\n");
1788 for (i = 0; i < (p - handle_tlbl); i++)
1789 pr_debug("\t.word 0x%08x\n", handle_tlbl[i]);
1790 pr_debug("\t.set pop\n");
1791} 1779}
1792 1780
1793static void __init build_r4000_tlb_store_handler(void) 1781static void __init build_r4000_tlb_store_handler(void)
@@ -1795,7 +1783,6 @@ static void __init build_r4000_tlb_store_handler(void)
1795 u32 *p = handle_tlbs; 1783 u32 *p = handle_tlbs;
1796 struct label *l = labels; 1784 struct label *l = labels;
1797 struct reloc *r = relocs; 1785 struct reloc *r = relocs;
1798 int i;
1799 1786
1800 memset(handle_tlbs, 0, sizeof(handle_tlbs)); 1787 memset(handle_tlbs, 0, sizeof(handle_tlbs));
1801 memset(labels, 0, sizeof(labels)); 1788 memset(labels, 0, sizeof(labels));
@@ -1819,11 +1806,7 @@ static void __init build_r4000_tlb_store_handler(void)
1819 pr_info("Synthesized TLB store handler fastpath (%u instructions).\n", 1806 pr_info("Synthesized TLB store handler fastpath (%u instructions).\n",
1820 (unsigned int)(p - handle_tlbs)); 1807 (unsigned int)(p - handle_tlbs));
1821 1808
1822 pr_debug("\t.set push\n"); 1809 dump_handler(handle_tlbs, ARRAY_SIZE(handle_tlbs));
1823 pr_debug("\t.set noreorder\n");
1824 for (i = 0; i < (p - handle_tlbs); i++)
1825 pr_debug("\t.word 0x%08x\n", handle_tlbs[i]);
1826 pr_debug("\t.set pop\n");
1827} 1810}
1828 1811
1829static void __init build_r4000_tlb_modify_handler(void) 1812static void __init build_r4000_tlb_modify_handler(void)
@@ -1831,7 +1814,6 @@ static void __init build_r4000_tlb_modify_handler(void)
1831 u32 *p = handle_tlbm; 1814 u32 *p = handle_tlbm;
1832 struct label *l = labels; 1815 struct label *l = labels;
1833 struct reloc *r = relocs; 1816 struct reloc *r = relocs;
1834 int i;
1835 1817
1836 memset(handle_tlbm, 0, sizeof(handle_tlbm)); 1818 memset(handle_tlbm, 0, sizeof(handle_tlbm));
1837 memset(labels, 0, sizeof(labels)); 1819 memset(labels, 0, sizeof(labels));
@@ -1856,11 +1838,7 @@ static void __init build_r4000_tlb_modify_handler(void)
1856 pr_info("Synthesized TLB modify handler fastpath (%u instructions).\n", 1838 pr_info("Synthesized TLB modify handler fastpath (%u instructions).\n",
1857 (unsigned int)(p - handle_tlbm)); 1839 (unsigned int)(p - handle_tlbm));
1858 1840
1859 pr_debug("\t.set push\n"); 1841 dump_handler(handle_tlbm, ARRAY_SIZE(handle_tlbm));
1860 pr_debug("\t.set noreorder\n");
1861 for (i = 0; i < (p - handle_tlbm); i++)
1862 pr_debug("\t.word 0x%08x\n", handle_tlbm[i]);
1863 pr_debug("\t.set pop\n");
1864} 1842}
1865 1843
1866void __init build_tlb_refill_handler(void) 1844void __init build_tlb_refill_handler(void)