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.c140
1 files changed, 101 insertions, 39 deletions
diff --git a/arch/mips/mm/tlbex.c b/arch/mips/mm/tlbex.c
index d1f68aadbc4..86f004dc835 100644
--- a/arch/mips/mm/tlbex.c
+++ b/arch/mips/mm/tlbex.c
@@ -31,6 +31,16 @@
31#include <asm/war.h> 31#include <asm/war.h>
32#include <asm/uasm.h> 32#include <asm/uasm.h>
33 33
34/*
35 * TLB load/store/modify handlers.
36 *
37 * Only the fastpath gets synthesized at runtime, the slowpath for
38 * do_page_fault remains normal asm.
39 */
40extern void tlb_do_page_fault_0(void);
41extern void tlb_do_page_fault_1(void);
42
43
34static inline int r45k_bvahwbug(void) 44static inline int r45k_bvahwbug(void)
35{ 45{
36 /* XXX: We should probe for the presence of this bug, but we don't. */ 46 /* XXX: We should probe for the presence of this bug, but we don't. */
@@ -83,6 +93,7 @@ enum label_id {
83 label_nopage_tlbm, 93 label_nopage_tlbm,
84 label_smp_pgtable_change, 94 label_smp_pgtable_change,
85 label_r3000_write_probe_fail, 95 label_r3000_write_probe_fail,
96 label_large_segbits_fault,
86#ifdef CONFIG_HUGETLB_PAGE 97#ifdef CONFIG_HUGETLB_PAGE
87 label_tlb_huge_update, 98 label_tlb_huge_update,
88#endif 99#endif
@@ -101,6 +112,7 @@ UASM_L_LA(_nopage_tlbs)
101UASM_L_LA(_nopage_tlbm) 112UASM_L_LA(_nopage_tlbm)
102UASM_L_LA(_smp_pgtable_change) 113UASM_L_LA(_smp_pgtable_change)
103UASM_L_LA(_r3000_write_probe_fail) 114UASM_L_LA(_r3000_write_probe_fail)
115UASM_L_LA(_large_segbits_fault)
104#ifdef CONFIG_HUGETLB_PAGE 116#ifdef CONFIG_HUGETLB_PAGE
105UASM_L_LA(_tlb_huge_update) 117UASM_L_LA(_tlb_huge_update)
106#endif 118#endif
@@ -157,6 +169,10 @@ static u32 tlb_handler[128] __cpuinitdata;
157static struct uasm_label labels[128] __cpuinitdata; 169static struct uasm_label labels[128] __cpuinitdata;
158static struct uasm_reloc relocs[128] __cpuinitdata; 170static struct uasm_reloc relocs[128] __cpuinitdata;
159 171
172#ifdef CONFIG_64BIT
173static int check_for_high_segbits __cpuinitdata;
174#endif
175
160#ifndef CONFIG_MIPS_PGD_C0_CONTEXT 176#ifndef CONFIG_MIPS_PGD_C0_CONTEXT
161/* 177/*
162 * CONFIG_MIPS_PGD_C0_CONTEXT implies 64 bit and lack of pgd_current, 178 * CONFIG_MIPS_PGD_C0_CONTEXT implies 64 bit and lack of pgd_current,
@@ -408,7 +424,7 @@ static __cpuinit __maybe_unused void build_convert_pte_to_entrylo(u32 **p,
408 UASM_i_ROTR(p, reg, reg, ilog2(_PAGE_GLOBAL) - ilog2(_PAGE_NO_EXEC)); 424 UASM_i_ROTR(p, reg, reg, ilog2(_PAGE_GLOBAL) - ilog2(_PAGE_NO_EXEC));
409 } else { 425 } else {
410#ifdef CONFIG_64BIT_PHYS_ADDR 426#ifdef CONFIG_64BIT_PHYS_ADDR
411 uasm_i_dsrl(p, reg, reg, ilog2(_PAGE_GLOBAL)); 427 uasm_i_dsrl_safe(p, reg, reg, ilog2(_PAGE_GLOBAL));
412#else 428#else
413 UASM_i_SRL(p, reg, reg, ilog2(_PAGE_GLOBAL)); 429 UASM_i_SRL(p, reg, reg, ilog2(_PAGE_GLOBAL));
414#endif 430#endif
@@ -532,7 +548,24 @@ build_get_pmde64(u32 **p, struct uasm_label **l, struct uasm_reloc **r,
532 * The vmalloc handling is not in the hotpath. 548 * The vmalloc handling is not in the hotpath.
533 */ 549 */
534 uasm_i_dmfc0(p, tmp, C0_BADVADDR); 550 uasm_i_dmfc0(p, tmp, C0_BADVADDR);
535 uasm_il_bltz(p, r, tmp, label_vmalloc); 551
552 if (check_for_high_segbits) {
553 /*
554 * The kernel currently implicitely assumes that the
555 * MIPS SEGBITS parameter for the processor is
556 * (PGDIR_SHIFT+PGDIR_BITS) or less, and will never
557 * allocate virtual addresses outside the maximum
558 * range for SEGBITS = (PGDIR_SHIFT+PGDIR_BITS). But
559 * that doesn't prevent user code from accessing the
560 * higher xuseg addresses. Here, we make sure that
561 * everything but the lower xuseg addresses goes down
562 * the module_alloc/vmalloc path.
563 */
564 uasm_i_dsrl_safe(p, ptr, tmp, PGDIR_SHIFT + PGD_ORDER + PAGE_SHIFT - 3);
565 uasm_il_bnez(p, r, ptr, label_vmalloc);
566 } else {
567 uasm_il_bltz(p, r, tmp, label_vmalloc);
568 }
536 /* No uasm_i_nop needed here, since the next insn doesn't touch TMP. */ 569 /* No uasm_i_nop needed here, since the next insn doesn't touch TMP. */
537 570
538#ifdef CONFIG_MIPS_PGD_C0_CONTEXT 571#ifdef CONFIG_MIPS_PGD_C0_CONTEXT
@@ -549,14 +582,14 @@ build_get_pmde64(u32 **p, struct uasm_label **l, struct uasm_reloc **r,
549 * SMTC uses TCBind value as "CPU" index 582 * SMTC uses TCBind value as "CPU" index
550 */ 583 */
551 uasm_i_mfc0(p, ptr, C0_TCBIND); 584 uasm_i_mfc0(p, ptr, C0_TCBIND);
552 uasm_i_dsrl(p, ptr, ptr, 19); 585 uasm_i_dsrl_safe(p, ptr, ptr, 19);
553# else 586# else
554 /* 587 /*
555 * 64 bit SMP running in XKPHYS has smp_processor_id() << 3 588 * 64 bit SMP running in XKPHYS has smp_processor_id() << 3
556 * stored in CONTEXT. 589 * stored in CONTEXT.
557 */ 590 */
558 uasm_i_dmfc0(p, ptr, C0_CONTEXT); 591 uasm_i_dmfc0(p, ptr, C0_CONTEXT);
559 uasm_i_dsrl(p, ptr, ptr, 23); 592 uasm_i_dsrl_safe(p, ptr, ptr, 23);
560# endif 593# endif
561 UASM_i_LA_mostly(p, tmp, pgdc); 594 UASM_i_LA_mostly(p, tmp, pgdc);
562 uasm_i_daddu(p, ptr, ptr, tmp); 595 uasm_i_daddu(p, ptr, ptr, tmp);
@@ -569,44 +602,78 @@ build_get_pmde64(u32 **p, struct uasm_label **l, struct uasm_reloc **r,
569 602
570 uasm_l_vmalloc_done(l, *p); 603 uasm_l_vmalloc_done(l, *p);
571 604
572 if (PGDIR_SHIFT - 3 < 32) /* get pgd offset in bytes */ 605 /* get pgd offset in bytes */
573 uasm_i_dsrl(p, tmp, tmp, PGDIR_SHIFT-3); 606 uasm_i_dsrl_safe(p, tmp, tmp, PGDIR_SHIFT - 3);
574 else
575 uasm_i_dsrl32(p, tmp, tmp, PGDIR_SHIFT - 3 - 32);
576 607
577 uasm_i_andi(p, tmp, tmp, (PTRS_PER_PGD - 1)<<3); 608 uasm_i_andi(p, tmp, tmp, (PTRS_PER_PGD - 1)<<3);
578 uasm_i_daddu(p, ptr, ptr, tmp); /* add in pgd offset */ 609 uasm_i_daddu(p, ptr, ptr, tmp); /* add in pgd offset */
579#ifndef __PAGETABLE_PMD_FOLDED 610#ifndef __PAGETABLE_PMD_FOLDED
580 uasm_i_dmfc0(p, tmp, C0_BADVADDR); /* get faulting address */ 611 uasm_i_dmfc0(p, tmp, C0_BADVADDR); /* get faulting address */
581 uasm_i_ld(p, ptr, 0, ptr); /* get pmd pointer */ 612 uasm_i_ld(p, ptr, 0, ptr); /* get pmd pointer */
582 uasm_i_dsrl(p, tmp, tmp, PMD_SHIFT-3); /* get pmd offset in bytes */ 613 uasm_i_dsrl_safe(p, tmp, tmp, PMD_SHIFT-3); /* get pmd offset in bytes */
583 uasm_i_andi(p, tmp, tmp, (PTRS_PER_PMD - 1)<<3); 614 uasm_i_andi(p, tmp, tmp, (PTRS_PER_PMD - 1)<<3);
584 uasm_i_daddu(p, ptr, ptr, tmp); /* add in pmd offset */ 615 uasm_i_daddu(p, ptr, ptr, tmp); /* add in pmd offset */
585#endif 616#endif
586} 617}
587 618
619enum vmalloc64_mode {not_refill, refill};
588/* 620/*
589 * BVADDR is the faulting address, PTR is scratch. 621 * BVADDR is the faulting address, PTR is scratch.
590 * PTR will hold the pgd for vmalloc. 622 * PTR will hold the pgd for vmalloc.
591 */ 623 */
592static void __cpuinit 624static void __cpuinit
593build_get_pgd_vmalloc64(u32 **p, struct uasm_label **l, struct uasm_reloc **r, 625build_get_pgd_vmalloc64(u32 **p, struct uasm_label **l, struct uasm_reloc **r,
594 unsigned int bvaddr, unsigned int ptr) 626 unsigned int bvaddr, unsigned int ptr,
627 enum vmalloc64_mode mode)
595{ 628{
596 long swpd = (long)swapper_pg_dir; 629 long swpd = (long)swapper_pg_dir;
630 int single_insn_swpd;
631 int did_vmalloc_branch = 0;
632
633 single_insn_swpd = uasm_in_compat_space_p(swpd) && !uasm_rel_lo(swpd);
597 634
598 uasm_l_vmalloc(l, *p); 635 uasm_l_vmalloc(l, *p);
599 636
600 if (uasm_in_compat_space_p(swpd) && !uasm_rel_lo(swpd)) { 637 if (mode == refill && check_for_high_segbits) {
601 uasm_il_b(p, r, label_vmalloc_done); 638 if (single_insn_swpd) {
602 uasm_i_lui(p, ptr, uasm_rel_hi(swpd)); 639 uasm_il_bltz(p, r, bvaddr, label_vmalloc_done);
603 } else { 640 uasm_i_lui(p, ptr, uasm_rel_hi(swpd));
604 UASM_i_LA_mostly(p, ptr, swpd); 641 did_vmalloc_branch = 1;
605 uasm_il_b(p, r, label_vmalloc_done); 642 /* fall through */
606 if (uasm_in_compat_space_p(swpd)) 643 } else {
607 uasm_i_addiu(p, ptr, ptr, uasm_rel_lo(swpd)); 644 uasm_il_bgez(p, r, bvaddr, label_large_segbits_fault);
608 else 645 }
609 uasm_i_daddiu(p, ptr, ptr, uasm_rel_lo(swpd)); 646 }
647 if (!did_vmalloc_branch) {
648 if (uasm_in_compat_space_p(swpd) && !uasm_rel_lo(swpd)) {
649 uasm_il_b(p, r, label_vmalloc_done);
650 uasm_i_lui(p, ptr, uasm_rel_hi(swpd));
651 } else {
652 UASM_i_LA_mostly(p, ptr, swpd);
653 uasm_il_b(p, r, label_vmalloc_done);
654 if (uasm_in_compat_space_p(swpd))
655 uasm_i_addiu(p, ptr, ptr, uasm_rel_lo(swpd));
656 else
657 uasm_i_daddiu(p, ptr, ptr, uasm_rel_lo(swpd));
658 }
659 }
660 if (mode == refill && check_for_high_segbits) {
661 uasm_l_large_segbits_fault(l, *p);
662 /*
663 * We get here if we are an xsseg address, or if we are
664 * an xuseg address above (PGDIR_SHIFT+PGDIR_BITS) boundary.
665 *
666 * Ignoring xsseg (assume disabled so would generate
667 * (address errors?), the only remaining possibility
668 * is the upper xuseg addresses. On processors with
669 * TLB_SEGBITS <= PGDIR_SHIFT+PGDIR_BITS, these
670 * addresses would have taken an address error. We try
671 * to mimic that here by taking a load/istream page
672 * fault.
673 */
674 UASM_i_LA(p, ptr, (unsigned long)tlb_do_page_fault_0);
675 uasm_i_jr(p, ptr);
676 uasm_i_nop(p);
610 } 677 }
611} 678}
612 679
@@ -720,9 +787,9 @@ static void __cpuinit build_update_entries(u32 **p, unsigned int tmp,
720 UASM_i_MTC0(p, tmp, C0_ENTRYLO0); /* load it */ 787 UASM_i_MTC0(p, tmp, C0_ENTRYLO0); /* load it */
721 UASM_i_ROTR(p, ptep, ptep, ilog2(_PAGE_GLOBAL) - ilog2(_PAGE_NO_EXEC)); 788 UASM_i_ROTR(p, ptep, ptep, ilog2(_PAGE_GLOBAL) - ilog2(_PAGE_NO_EXEC));
722 } else { 789 } else {
723 uasm_i_dsrl(p, tmp, tmp, ilog2(_PAGE_GLOBAL)); /* convert to entrylo0 */ 790 uasm_i_dsrl_safe(p, tmp, tmp, ilog2(_PAGE_GLOBAL)); /* convert to entrylo0 */
724 UASM_i_MTC0(p, tmp, C0_ENTRYLO0); /* load it */ 791 UASM_i_MTC0(p, tmp, C0_ENTRYLO0); /* load it */
725 uasm_i_dsrl(p, ptep, ptep, ilog2(_PAGE_GLOBAL)); /* convert to entrylo1 */ 792 uasm_i_dsrl_safe(p, ptep, ptep, ilog2(_PAGE_GLOBAL)); /* convert to entrylo1 */
726 } 793 }
727 UASM_i_MTC0(p, ptep, C0_ENTRYLO1); /* load it */ 794 UASM_i_MTC0(p, ptep, C0_ENTRYLO1); /* load it */
728 } else { 795 } else {
@@ -793,9 +860,9 @@ static void __cpuinit build_r4000_tlb_refill_handler(void)
793 uasm_i_dmfc0(&p, K0, C0_BADVADDR); 860 uasm_i_dmfc0(&p, K0, C0_BADVADDR);
794 uasm_i_dmfc0(&p, K1, C0_ENTRYHI); 861 uasm_i_dmfc0(&p, K1, C0_ENTRYHI);
795 uasm_i_xor(&p, K0, K0, K1); 862 uasm_i_xor(&p, K0, K0, K1);
796 uasm_i_dsrl32(&p, K1, K0, 62 - 32); 863 uasm_i_dsrl_safe(&p, K1, K0, 62);
797 uasm_i_dsrl(&p, K0, K0, 12 + 1); 864 uasm_i_dsrl_safe(&p, K0, K0, 12 + 1);
798 uasm_i_dsll32(&p, K0, K0, 64 + 12 + 1 - segbits - 32); 865 uasm_i_dsll_safe(&p, K0, K0, 64 + 12 + 1 - segbits);
799 uasm_i_or(&p, K0, K0, K1); 866 uasm_i_or(&p, K0, K0, K1);
800 uasm_il_bnez(&p, &r, K0, label_leave); 867 uasm_il_bnez(&p, &r, K0, label_leave);
801 /* No need for uasm_i_nop */ 868 /* No need for uasm_i_nop */
@@ -825,7 +892,7 @@ static void __cpuinit build_r4000_tlb_refill_handler(void)
825#endif 892#endif
826 893
827#ifdef CONFIG_64BIT 894#ifdef CONFIG_64BIT
828 build_get_pgd_vmalloc64(&p, &l, &r, K0, K1); 895 build_get_pgd_vmalloc64(&p, &l, &r, K0, K1, refill);
829#endif 896#endif
830 897
831 /* 898 /*
@@ -935,15 +1002,6 @@ static void __cpuinit build_r4000_tlb_refill_handler(void)
935} 1002}
936 1003
937/* 1004/*
938 * TLB load/store/modify handlers.
939 *
940 * Only the fastpath gets synthesized at runtime, the slowpath for
941 * do_page_fault remains normal asm.
942 */
943extern void tlb_do_page_fault_0(void);
944extern void tlb_do_page_fault_1(void);
945
946/*
947 * 128 instructions for the fastpath handler is generous and should 1005 * 128 instructions for the fastpath handler is generous and should
948 * never be exceeded. 1006 * never be exceeded.
949 */ 1007 */
@@ -1302,7 +1360,7 @@ build_r4000_tlbchange_handler_tail(u32 **p, struct uasm_label **l,
1302 uasm_i_eret(p); /* return from trap */ 1360 uasm_i_eret(p); /* return from trap */
1303 1361
1304#ifdef CONFIG_64BIT 1362#ifdef CONFIG_64BIT
1305 build_get_pgd_vmalloc64(p, l, r, tmp, ptr); 1363 build_get_pgd_vmalloc64(p, l, r, tmp, ptr, not_refill);
1306#endif 1364#endif
1307} 1365}
1308 1366
@@ -1322,9 +1380,9 @@ static void __cpuinit build_r4000_tlb_load_handler(void)
1322 uasm_i_dmfc0(&p, K0, C0_BADVADDR); 1380 uasm_i_dmfc0(&p, K0, C0_BADVADDR);
1323 uasm_i_dmfc0(&p, K1, C0_ENTRYHI); 1381 uasm_i_dmfc0(&p, K1, C0_ENTRYHI);
1324 uasm_i_xor(&p, K0, K0, K1); 1382 uasm_i_xor(&p, K0, K0, K1);
1325 uasm_i_dsrl32(&p, K1, K0, 62 - 32); 1383 uasm_i_dsrl_safe(&p, K1, K0, 62);
1326 uasm_i_dsrl(&p, K0, K0, 12 + 1); 1384 uasm_i_dsrl_safe(&p, K0, K0, 12 + 1);
1327 uasm_i_dsll32(&p, K0, K0, 64 + 12 + 1 - segbits - 32); 1385 uasm_i_dsll_safe(&p, K0, K0, 64 + 12 + 1 - segbits);
1328 uasm_i_or(&p, K0, K0, K1); 1386 uasm_i_or(&p, K0, K0, K1);
1329 uasm_il_bnez(&p, &r, K0, label_leave); 1387 uasm_il_bnez(&p, &r, K0, label_leave);
1330 /* No need for uasm_i_nop */ 1388 /* No need for uasm_i_nop */
@@ -1526,6 +1584,10 @@ void __cpuinit build_tlb_refill_handler(void)
1526 */ 1584 */
1527 static int run_once = 0; 1585 static int run_once = 0;
1528 1586
1587#ifdef CONFIG_64BIT
1588 check_for_high_segbits = current_cpu_data.vmbits > (PGDIR_SHIFT + PGD_ORDER + PAGE_SHIFT - 3);
1589#endif
1590
1529 switch (current_cpu_type()) { 1591 switch (current_cpu_type()) {
1530 case CPU_R2000: 1592 case CPU_R2000:
1531 case CPU_R3000: 1593 case CPU_R3000: