aboutsummaryrefslogtreecommitdiffstats
path: root/arch/powerpc/mm/hash_utils_64.c
diff options
context:
space:
mode:
Diffstat (limited to 'arch/powerpc/mm/hash_utils_64.c')
-rw-r--r--arch/powerpc/mm/hash_utils_64.c153
1 files changed, 81 insertions, 72 deletions
diff --git a/arch/powerpc/mm/hash_utils_64.c b/arch/powerpc/mm/hash_utils_64.c
index 2971ea18c768..b78b5d211278 100644
--- a/arch/powerpc/mm/hash_utils_64.c
+++ b/arch/powerpc/mm/hash_utils_64.c
@@ -34,6 +34,7 @@
34#include <linux/signal.h> 34#include <linux/signal.h>
35#include <linux/memblock.h> 35#include <linux/memblock.h>
36#include <linux/context_tracking.h> 36#include <linux/context_tracking.h>
37#include <linux/libfdt.h>
37 38
38#include <asm/processor.h> 39#include <asm/processor.h>
39#include <asm/pgtable.h> 40#include <asm/pgtable.h>
@@ -58,6 +59,7 @@
58#include <asm/firmware.h> 59#include <asm/firmware.h>
59#include <asm/tm.h> 60#include <asm/tm.h>
60#include <asm/trace.h> 61#include <asm/trace.h>
62#include <asm/ps3.h>
61 63
62#ifdef DEBUG 64#ifdef DEBUG
63#define DBG(fmt...) udbg_printf(fmt) 65#define DBG(fmt...) udbg_printf(fmt)
@@ -87,10 +89,6 @@
87 * 89 *
88 */ 90 */
89 91
90#ifdef CONFIG_U3_DART
91extern unsigned long dart_tablebase;
92#endif /* CONFIG_U3_DART */
93
94static unsigned long _SDR1; 92static unsigned long _SDR1;
95struct mmu_psize_def mmu_psize_defs[MMU_PAGE_COUNT]; 93struct mmu_psize_def mmu_psize_defs[MMU_PAGE_COUNT];
96EXPORT_SYMBOL_GPL(mmu_psize_defs); 94EXPORT_SYMBOL_GPL(mmu_psize_defs);
@@ -120,6 +118,8 @@ static u8 *linear_map_hash_slots;
120static unsigned long linear_map_hash_count; 118static unsigned long linear_map_hash_count;
121static DEFINE_SPINLOCK(linear_map_hash_lock); 119static DEFINE_SPINLOCK(linear_map_hash_lock);
122#endif /* CONFIG_DEBUG_PAGEALLOC */ 120#endif /* CONFIG_DEBUG_PAGEALLOC */
121struct mmu_hash_ops mmu_hash_ops;
122EXPORT_SYMBOL(mmu_hash_ops);
123 123
124/* There are definitions of page sizes arrays to be used when none 124/* There are definitions of page sizes arrays to be used when none
125 * is provided by the firmware. 125 * is provided by the firmware.
@@ -278,9 +278,10 @@ int htab_bolt_mapping(unsigned long vstart, unsigned long vend,
278 hash = hpt_hash(vpn, shift, ssize); 278 hash = hpt_hash(vpn, shift, ssize);
279 hpteg = ((hash & htab_hash_mask) * HPTES_PER_GROUP); 279 hpteg = ((hash & htab_hash_mask) * HPTES_PER_GROUP);
280 280
281 BUG_ON(!ppc_md.hpte_insert); 281 BUG_ON(!mmu_hash_ops.hpte_insert);
282 ret = ppc_md.hpte_insert(hpteg, vpn, paddr, tprot, 282 ret = mmu_hash_ops.hpte_insert(hpteg, vpn, paddr, tprot,
283 HPTE_V_BOLTED, psize, psize, ssize); 283 HPTE_V_BOLTED, psize, psize,
284 ssize);
284 285
285 if (ret < 0) 286 if (ret < 0)
286 break; 287 break;
@@ -305,11 +306,11 @@ int htab_remove_mapping(unsigned long vstart, unsigned long vend,
305 shift = mmu_psize_defs[psize].shift; 306 shift = mmu_psize_defs[psize].shift;
306 step = 1 << shift; 307 step = 1 << shift;
307 308
308 if (!ppc_md.hpte_removebolted) 309 if (!mmu_hash_ops.hpte_removebolted)
309 return -ENODEV; 310 return -ENODEV;
310 311
311 for (vaddr = vstart; vaddr < vend; vaddr += step) { 312 for (vaddr = vstart; vaddr < vend; vaddr += step) {
312 rc = ppc_md.hpte_removebolted(vaddr, psize, ssize); 313 rc = mmu_hash_ops.hpte_removebolted(vaddr, psize, ssize);
313 if (rc == -ENOENT) { 314 if (rc == -ENOENT) {
314 ret = -ENOENT; 315 ret = -ENOENT;
315 continue; 316 continue;
@@ -321,6 +322,15 @@ int htab_remove_mapping(unsigned long vstart, unsigned long vend,
321 return ret; 322 return ret;
322} 323}
323 324
325static bool disable_1tb_segments = false;
326
327static int __init parse_disable_1tb_segments(char *p)
328{
329 disable_1tb_segments = true;
330 return 0;
331}
332early_param("disable_1tb_segments", parse_disable_1tb_segments);
333
324static int __init htab_dt_scan_seg_sizes(unsigned long node, 334static int __init htab_dt_scan_seg_sizes(unsigned long node,
325 const char *uname, int depth, 335 const char *uname, int depth,
326 void *data) 336 void *data)
@@ -339,6 +349,12 @@ static int __init htab_dt_scan_seg_sizes(unsigned long node,
339 for (; size >= 4; size -= 4, ++prop) { 349 for (; size >= 4; size -= 4, ++prop) {
340 if (be32_to_cpu(prop[0]) == 40) { 350 if (be32_to_cpu(prop[0]) == 40) {
341 DBG("1T segment support detected\n"); 351 DBG("1T segment support detected\n");
352
353 if (disable_1tb_segments) {
354 DBG("1T segments disabled by command line\n");
355 break;
356 }
357
342 cur_cpu_spec->mmu_features |= MMU_FTR_1T_SEGMENT; 358 cur_cpu_spec->mmu_features |= MMU_FTR_1T_SEGMENT;
343 return 1; 359 return 1;
344 } 360 }
@@ -514,7 +530,8 @@ static bool might_have_hea(void)
514 * we will never see an HEA ethernet device. 530 * we will never see an HEA ethernet device.
515 */ 531 */
516#ifdef CONFIG_IBMEBUS 532#ifdef CONFIG_IBMEBUS
517 return !cpu_has_feature(CPU_FTR_ARCH_207S); 533 return !cpu_has_feature(CPU_FTR_ARCH_207S) &&
534 !firmware_has_feature(FW_FEATURE_SPLPAR);
518#else 535#else
519 return false; 536 return false;
520#endif 537#endif
@@ -580,7 +597,7 @@ found:
580 * would stop us accessing the HEA ethernet. So if we 597 * would stop us accessing the HEA ethernet. So if we
581 * have the chance of ever seeing one, stay at 4k. 598 * have the chance of ever seeing one, stay at 4k.
582 */ 599 */
583 if (!might_have_hea() || !machine_is(pseries)) 600 if (!might_have_hea())
584 mmu_io_psize = MMU_PAGE_64K; 601 mmu_io_psize = MMU_PAGE_64K;
585 } else 602 } else
586 mmu_ci_restrictions = 1; 603 mmu_ci_restrictions = 1;
@@ -699,10 +716,9 @@ int remove_section_mapping(unsigned long start, unsigned long end)
699#endif /* CONFIG_MEMORY_HOTPLUG */ 716#endif /* CONFIG_MEMORY_HOTPLUG */
700 717
701static void __init hash_init_partition_table(phys_addr_t hash_table, 718static void __init hash_init_partition_table(phys_addr_t hash_table,
702 unsigned long pteg_count) 719 unsigned long htab_size)
703{ 720{
704 unsigned long ps_field; 721 unsigned long ps_field;
705 unsigned long htab_size;
706 unsigned long patb_size = 1UL << PATB_SIZE_SHIFT; 722 unsigned long patb_size = 1UL << PATB_SIZE_SHIFT;
707 723
708 /* 724 /*
@@ -710,7 +726,7 @@ static void __init hash_init_partition_table(phys_addr_t hash_table,
710 * We can ignore that for lpid 0 726 * We can ignore that for lpid 0
711 */ 727 */
712 ps_field = 0; 728 ps_field = 0;
713 htab_size = __ilog2(pteg_count) - 11; 729 htab_size = __ilog2(htab_size) - 18;
714 730
715 BUILD_BUG_ON_MSG((PATB_SIZE_SHIFT > 24), "Partition table size too large."); 731 BUILD_BUG_ON_MSG((PATB_SIZE_SHIFT > 24), "Partition table size too large.");
716 partition_tb = __va(memblock_alloc_base(patb_size, patb_size, 732 partition_tb = __va(memblock_alloc_base(patb_size, patb_size,
@@ -724,7 +740,7 @@ static void __init hash_init_partition_table(phys_addr_t hash_table,
724 * For now UPRT is 0 for us. 740 * For now UPRT is 0 for us.
725 */ 741 */
726 partition_tb->patb1 = 0; 742 partition_tb->patb1 = 0;
727 DBG("Partition table %p\n", partition_tb); 743 pr_info("Partition table %p\n", partition_tb);
728 /* 744 /*
729 * update partition table control register, 745 * update partition table control register,
730 * 64 K size. 746 * 64 K size.
@@ -738,7 +754,7 @@ static void __init htab_initialize(void)
738 unsigned long table; 754 unsigned long table;
739 unsigned long pteg_count; 755 unsigned long pteg_count;
740 unsigned long prot; 756 unsigned long prot;
741 unsigned long base = 0, size = 0, limit; 757 unsigned long base = 0, size = 0;
742 struct memblock_region *reg; 758 struct memblock_region *reg;
743 759
744 DBG(" -> htab_initialize()\n"); 760 DBG(" -> htab_initialize()\n");
@@ -764,7 +780,8 @@ static void __init htab_initialize(void)
764 780
765 htab_hash_mask = pteg_count - 1; 781 htab_hash_mask = pteg_count - 1;
766 782
767 if (firmware_has_feature(FW_FEATURE_LPAR)) { 783 if (firmware_has_feature(FW_FEATURE_LPAR) ||
784 firmware_has_feature(FW_FEATURE_PS3_LV1)) {
768 /* Using a hypervisor which owns the htab */ 785 /* Using a hypervisor which owns the htab */
769 htab_address = NULL; 786 htab_address = NULL;
770 _SDR1 = 0; 787 _SDR1 = 0;
@@ -775,20 +792,26 @@ static void __init htab_initialize(void)
775 * Clear the htab if firmware assisted dump is active so 792 * Clear the htab if firmware assisted dump is active so
776 * that we dont end up using old mappings. 793 * that we dont end up using old mappings.
777 */ 794 */
778 if (is_fadump_active() && ppc_md.hpte_clear_all) 795 if (is_fadump_active() && mmu_hash_ops.hpte_clear_all)
779 ppc_md.hpte_clear_all(); 796 mmu_hash_ops.hpte_clear_all();
780#endif 797#endif
781 } else { 798 } else {
782 /* Find storage for the HPT. Must be contiguous in 799 unsigned long limit = MEMBLOCK_ALLOC_ANYWHERE;
783 * the absolute address space. On cell we want it to be 800
784 * in the first 2 Gig so we can use it for IOMMU hacks. 801#ifdef CONFIG_PPC_CELL
802 /*
803 * Cell may require the hash table down low when using the
804 * Axon IOMMU in order to fit the dynamic region over it, see
805 * comments in cell/iommu.c
785 */ 806 */
786 if (machine_is(cell)) 807 if (fdt_subnode_offset(initial_boot_params, 0, "axon") > 0) {
787 limit = 0x80000000; 808 limit = 0x80000000;
788 else 809 pr_info("Hash table forced below 2G for Axon IOMMU\n");
789 limit = MEMBLOCK_ALLOC_ANYWHERE; 810 }
811#endif /* CONFIG_PPC_CELL */
790 812
791 table = memblock_alloc_base(htab_size_bytes, htab_size_bytes, limit); 813 table = memblock_alloc_base(htab_size_bytes, htab_size_bytes,
814 limit);
792 815
793 DBG("Hash table allocated at %lx, size: %lx\n", table, 816 DBG("Hash table allocated at %lx, size: %lx\n", table,
794 htab_size_bytes); 817 htab_size_bytes);
@@ -796,7 +819,7 @@ static void __init htab_initialize(void)
796 htab_address = __va(table); 819 htab_address = __va(table);
797 820
798 /* htab absolute addr + encoded htabsize */ 821 /* htab absolute addr + encoded htabsize */
799 _SDR1 = table + __ilog2(pteg_count) - 11; 822 _SDR1 = table + __ilog2(htab_size_bytes) - 18;
800 823
801 /* Initialize the HPT with no entries */ 824 /* Initialize the HPT with no entries */
802 memset((void *)table, 0, htab_size_bytes); 825 memset((void *)table, 0, htab_size_bytes);
@@ -805,7 +828,7 @@ static void __init htab_initialize(void)
805 /* Set SDR1 */ 828 /* Set SDR1 */
806 mtspr(SPRN_SDR1, _SDR1); 829 mtspr(SPRN_SDR1, _SDR1);
807 else 830 else
808 hash_init_partition_table(table, pteg_count); 831 hash_init_partition_table(table, htab_size_bytes);
809 } 832 }
810 833
811 prot = pgprot_val(PAGE_KERNEL); 834 prot = pgprot_val(PAGE_KERNEL);
@@ -832,34 +855,6 @@ static void __init htab_initialize(void)
832 DBG("creating mapping for region: %lx..%lx (prot: %lx)\n", 855 DBG("creating mapping for region: %lx..%lx (prot: %lx)\n",
833 base, size, prot); 856 base, size, prot);
834 857
835#ifdef CONFIG_U3_DART
836 /* Do not map the DART space. Fortunately, it will be aligned
837 * in such a way that it will not cross two memblock regions and
838 * will fit within a single 16Mb page.
839 * The DART space is assumed to be a full 16Mb region even if
840 * we only use 2Mb of that space. We will use more of it later
841 * for AGP GART. We have to use a full 16Mb large page.
842 */
843 DBG("DART base: %lx\n", dart_tablebase);
844
845 if (dart_tablebase != 0 && dart_tablebase >= base
846 && dart_tablebase < (base + size)) {
847 unsigned long dart_table_end = dart_tablebase + 16 * MB;
848 if (base != dart_tablebase)
849 BUG_ON(htab_bolt_mapping(base, dart_tablebase,
850 __pa(base), prot,
851 mmu_linear_psize,
852 mmu_kernel_ssize));
853 if ((base + size) > dart_table_end)
854 BUG_ON(htab_bolt_mapping(dart_tablebase+16*MB,
855 base + size,
856 __pa(dart_table_end),
857 prot,
858 mmu_linear_psize,
859 mmu_kernel_ssize));
860 continue;
861 }
862#endif /* CONFIG_U3_DART */
863 BUG_ON(htab_bolt_mapping(base, base + size, __pa(base), 858 BUG_ON(htab_bolt_mapping(base, base + size, __pa(base),
864 prot, mmu_linear_psize, mmu_kernel_ssize)); 859 prot, mmu_linear_psize, mmu_kernel_ssize));
865 } 860 }
@@ -926,12 +921,24 @@ void __init hash__early_init_mmu(void)
926 pci_io_base = ISA_IO_BASE; 921 pci_io_base = ISA_IO_BASE;
927#endif 922#endif
928 923
924 /* Select appropriate backend */
925 if (firmware_has_feature(FW_FEATURE_PS3_LV1))
926 ps3_early_mm_init();
927 else if (firmware_has_feature(FW_FEATURE_LPAR))
928 hpte_init_pseries();
929 else if (IS_ENABLED(CONFIG_PPC_NATIVE))
930 hpte_init_native();
931
932 if (!mmu_hash_ops.hpte_insert)
933 panic("hash__early_init_mmu: No MMU hash ops defined!\n");
934
929 /* Initialize the MMU Hash table and create the linear mapping 935 /* Initialize the MMU Hash table and create the linear mapping
930 * of memory. Has to be done before SLB initialization as this is 936 * of memory. Has to be done before SLB initialization as this is
931 * currently where the page size encoding is obtained. 937 * currently where the page size encoding is obtained.
932 */ 938 */
933 htab_initialize(); 939 htab_initialize();
934 940
941 pr_info("Initializing hash mmu with SLB\n");
935 /* Initialize SLB management */ 942 /* Initialize SLB management */
936 slb_initialize(); 943 slb_initialize();
937} 944}
@@ -1474,7 +1481,8 @@ void flush_hash_page(unsigned long vpn, real_pte_t pte, int psize, int ssize,
1474 * We use same base page size and actual psize, because we don't 1481 * We use same base page size and actual psize, because we don't
1475 * use these functions for hugepage 1482 * use these functions for hugepage
1476 */ 1483 */
1477 ppc_md.hpte_invalidate(slot, vpn, psize, psize, ssize, local); 1484 mmu_hash_ops.hpte_invalidate(slot, vpn, psize, psize,
1485 ssize, local);
1478 } pte_iterate_hashed_end(); 1486 } pte_iterate_hashed_end();
1479 1487
1480#ifdef CONFIG_PPC_TRANSACTIONAL_MEM 1488#ifdef CONFIG_PPC_TRANSACTIONAL_MEM
@@ -1515,9 +1523,9 @@ void flush_hash_hugepage(unsigned long vsid, unsigned long addr,
1515 if (!hpte_slot_array) 1523 if (!hpte_slot_array)
1516 return; 1524 return;
1517 1525
1518 if (ppc_md.hugepage_invalidate) { 1526 if (mmu_hash_ops.hugepage_invalidate) {
1519 ppc_md.hugepage_invalidate(vsid, s_addr, hpte_slot_array, 1527 mmu_hash_ops.hugepage_invalidate(vsid, s_addr, hpte_slot_array,
1520 psize, ssize, local); 1528 psize, ssize, local);
1521 goto tm_abort; 1529 goto tm_abort;
1522 } 1530 }
1523 /* 1531 /*
@@ -1544,8 +1552,8 @@ void flush_hash_hugepage(unsigned long vsid, unsigned long addr,
1544 1552
1545 slot = (hash & htab_hash_mask) * HPTES_PER_GROUP; 1553 slot = (hash & htab_hash_mask) * HPTES_PER_GROUP;
1546 slot += hidx & _PTEIDX_GROUP_IX; 1554 slot += hidx & _PTEIDX_GROUP_IX;
1547 ppc_md.hpte_invalidate(slot, vpn, psize, 1555 mmu_hash_ops.hpte_invalidate(slot, vpn, psize,
1548 MMU_PAGE_16M, ssize, local); 1556 MMU_PAGE_16M, ssize, local);
1549 } 1557 }
1550tm_abort: 1558tm_abort:
1551#ifdef CONFIG_PPC_TRANSACTIONAL_MEM 1559#ifdef CONFIG_PPC_TRANSACTIONAL_MEM
@@ -1569,8 +1577,8 @@ tm_abort:
1569 1577
1570void flush_hash_range(unsigned long number, int local) 1578void flush_hash_range(unsigned long number, int local)
1571{ 1579{
1572 if (ppc_md.flush_hash_range) 1580 if (mmu_hash_ops.flush_hash_range)
1573 ppc_md.flush_hash_range(number, local); 1581 mmu_hash_ops.flush_hash_range(number, local);
1574 else { 1582 else {
1575 int i; 1583 int i;
1576 struct ppc64_tlb_batch *batch = 1584 struct ppc64_tlb_batch *batch =
@@ -1615,22 +1623,22 @@ repeat:
1615 HPTES_PER_GROUP) & ~0x7UL; 1623 HPTES_PER_GROUP) & ~0x7UL;
1616 1624
1617 /* Insert into the hash table, primary slot */ 1625 /* Insert into the hash table, primary slot */
1618 slot = ppc_md.hpte_insert(hpte_group, vpn, pa, rflags, vflags, 1626 slot = mmu_hash_ops.hpte_insert(hpte_group, vpn, pa, rflags, vflags,
1619 psize, psize, ssize); 1627 psize, psize, ssize);
1620 1628
1621 /* Primary is full, try the secondary */ 1629 /* Primary is full, try the secondary */
1622 if (unlikely(slot == -1)) { 1630 if (unlikely(slot == -1)) {
1623 hpte_group = ((~hash & htab_hash_mask) * 1631 hpte_group = ((~hash & htab_hash_mask) *
1624 HPTES_PER_GROUP) & ~0x7UL; 1632 HPTES_PER_GROUP) & ~0x7UL;
1625 slot = ppc_md.hpte_insert(hpte_group, vpn, pa, rflags, 1633 slot = mmu_hash_ops.hpte_insert(hpte_group, vpn, pa, rflags,
1626 vflags | HPTE_V_SECONDARY, 1634 vflags | HPTE_V_SECONDARY,
1627 psize, psize, ssize); 1635 psize, psize, ssize);
1628 if (slot == -1) { 1636 if (slot == -1) {
1629 if (mftb() & 0x1) 1637 if (mftb() & 0x1)
1630 hpte_group = ((hash & htab_hash_mask) * 1638 hpte_group = ((hash & htab_hash_mask) *
1631 HPTES_PER_GROUP)&~0x7UL; 1639 HPTES_PER_GROUP)&~0x7UL;
1632 1640
1633 ppc_md.hpte_remove(hpte_group); 1641 mmu_hash_ops.hpte_remove(hpte_group);
1634 goto repeat; 1642 goto repeat;
1635 } 1643 }
1636 } 1644 }
@@ -1680,8 +1688,9 @@ static void kernel_unmap_linear_page(unsigned long vaddr, unsigned long lmi)
1680 hash = ~hash; 1688 hash = ~hash;
1681 slot = (hash & htab_hash_mask) * HPTES_PER_GROUP; 1689 slot = (hash & htab_hash_mask) * HPTES_PER_GROUP;
1682 slot += hidx & _PTEIDX_GROUP_IX; 1690 slot += hidx & _PTEIDX_GROUP_IX;
1683 ppc_md.hpte_invalidate(slot, vpn, mmu_linear_psize, mmu_linear_psize, 1691 mmu_hash_ops.hpte_invalidate(slot, vpn, mmu_linear_psize,
1684 mmu_kernel_ssize, 0); 1692 mmu_linear_psize,
1693 mmu_kernel_ssize, 0);
1685} 1694}
1686 1695
1687void __kernel_map_pages(struct page *page, int numpages, int enable) 1696void __kernel_map_pages(struct page *page, int numpages, int enable)