xref: /openbmc/linux/arch/powerpc/mm/nohash/tlb_64e.c (revision 547acc20)
18ea58996SMichael Ellerman // SPDX-License-Identifier: GPL-2.0-or-later
28ea58996SMichael Ellerman /*
38ea58996SMichael Ellerman  * Copyright 2008,2009 Ben Herrenschmidt <benh@kernel.crashing.org>
48ea58996SMichael Ellerman  *                     IBM Corp.
58ea58996SMichael Ellerman  *
68ea58996SMichael Ellerman  *  Derived from arch/ppc/mm/init.c:
78ea58996SMichael Ellerman  *    Copyright (C) 1995-1996 Gary Thomas (gdt@linuxppc.org)
88ea58996SMichael Ellerman  *
98ea58996SMichael Ellerman  *  Modifications by Paul Mackerras (PowerMac) (paulus@cs.anu.edu.au)
108ea58996SMichael Ellerman  *  and Cort Dougan (PReP) (cort@cs.nmt.edu)
118ea58996SMichael Ellerman  *    Copyright (C) 1996 Paul Mackerras
128ea58996SMichael Ellerman  *
138ea58996SMichael Ellerman  *  Derived from "arch/i386/mm/init.c"
148ea58996SMichael Ellerman  *    Copyright (C) 1991, 1992, 1993, 1994  Linus Torvalds
158ea58996SMichael Ellerman  */
168ea58996SMichael Ellerman 
178ea58996SMichael Ellerman #include <linux/kernel.h>
188ea58996SMichael Ellerman #include <linux/export.h>
198ea58996SMichael Ellerman #include <linux/mm.h>
208ea58996SMichael Ellerman #include <linux/init.h>
218ea58996SMichael Ellerman #include <linux/pagemap.h>
228ea58996SMichael Ellerman #include <linux/memblock.h>
238ea58996SMichael Ellerman 
248ea58996SMichael Ellerman #include <asm/pgalloc.h>
258ea58996SMichael Ellerman #include <asm/tlbflush.h>
268ea58996SMichael Ellerman #include <asm/tlb.h>
278ea58996SMichael Ellerman #include <asm/code-patching.h>
288ea58996SMichael Ellerman #include <asm/cputhreads.h>
298ea58996SMichael Ellerman 
308ea58996SMichael Ellerman #include <mm/mmu_decl.h>
318ea58996SMichael Ellerman 
328ea58996SMichael Ellerman /* The variables below are currently only used on 64-bit Book3E
338ea58996SMichael Ellerman  * though this will probably be made common with other nohash
348ea58996SMichael Ellerman  * implementations at some point
358ea58996SMichael Ellerman  */
36*547acc20SChristophe Leroy static int mmu_pte_psize;	/* Page size used for PTE pages */
378ea58996SMichael Ellerman int mmu_vmemmap_psize;		/* Page size used for the virtual mem map */
388ea58996SMichael Ellerman int book3e_htw_mode;		/* HW tablewalk?  Value is PPC_HTW_* */
398ea58996SMichael Ellerman unsigned long linear_map_top;	/* Top of linear mapping */
408ea58996SMichael Ellerman 
418ea58996SMichael Ellerman 
428ea58996SMichael Ellerman /*
438ea58996SMichael Ellerman  * Number of bytes to add to SPRN_SPRG_TLB_EXFRAME on crit/mcheck/debug
448ea58996SMichael Ellerman  * exceptions.  This is used for bolted and e6500 TLB miss handlers which
458ea58996SMichael Ellerman  * do not modify this SPRG in the TLB miss code; for other TLB miss handlers,
468ea58996SMichael Ellerman  * this is set to zero.
478ea58996SMichael Ellerman  */
488ea58996SMichael Ellerman int extlb_level_exc;
498ea58996SMichael Ellerman 
508ea58996SMichael Ellerman /*
518ea58996SMichael Ellerman  * Handling of virtual linear page tables or indirect TLB entries
528ea58996SMichael Ellerman  * flushing when PTE pages are freed
538ea58996SMichael Ellerman  */
tlb_flush_pgtable(struct mmu_gather * tlb,unsigned long address)548ea58996SMichael Ellerman void tlb_flush_pgtable(struct mmu_gather *tlb, unsigned long address)
558ea58996SMichael Ellerman {
568ea58996SMichael Ellerman 	int tsize = mmu_psize_defs[mmu_pte_psize].enc;
578ea58996SMichael Ellerman 
588ea58996SMichael Ellerman 	if (book3e_htw_mode != PPC_HTW_NONE) {
598ea58996SMichael Ellerman 		unsigned long start = address & PMD_MASK;
608ea58996SMichael Ellerman 		unsigned long end = address + PMD_SIZE;
618ea58996SMichael Ellerman 		unsigned long size = 1UL << mmu_psize_defs[mmu_pte_psize].shift;
628ea58996SMichael Ellerman 
638ea58996SMichael Ellerman 		/* This isn't the most optimal, ideally we would factor out the
648ea58996SMichael Ellerman 		 * while preempt & CPU mask mucking around, or even the IPI but
658ea58996SMichael Ellerman 		 * it will do for now
668ea58996SMichael Ellerman 		 */
678ea58996SMichael Ellerman 		while (start < end) {
688ea58996SMichael Ellerman 			__flush_tlb_page(tlb->mm, start, tsize, 1);
698ea58996SMichael Ellerman 			start += size;
708ea58996SMichael Ellerman 		}
718ea58996SMichael Ellerman 	} else {
728ea58996SMichael Ellerman 		unsigned long rmask = 0xf000000000000000ul;
738ea58996SMichael Ellerman 		unsigned long rid = (address & rmask) | 0x1000000000000000ul;
748ea58996SMichael Ellerman 		unsigned long vpte = address & ~rmask;
758ea58996SMichael Ellerman 
768ea58996SMichael Ellerman 		vpte = (vpte >> (PAGE_SHIFT - 3)) & ~0xffful;
778ea58996SMichael Ellerman 		vpte |= rid;
788ea58996SMichael Ellerman 		__flush_tlb_page(tlb->mm, vpte, tsize, 0);
798ea58996SMichael Ellerman 	}
808ea58996SMichael Ellerman }
818ea58996SMichael Ellerman 
setup_page_sizes(void)828ea58996SMichael Ellerman static void __init setup_page_sizes(void)
838ea58996SMichael Ellerman {
848ea58996SMichael Ellerman 	unsigned int tlb0cfg;
858ea58996SMichael Ellerman 	unsigned int eptcfg;
868ea58996SMichael Ellerman 	int psize;
878ea58996SMichael Ellerman 
888ea58996SMichael Ellerman #ifdef CONFIG_PPC_E500
898ea58996SMichael Ellerman 	unsigned int mmucfg = mfspr(SPRN_MMUCFG);
908ea58996SMichael Ellerman 	int fsl_mmu = mmu_has_feature(MMU_FTR_TYPE_FSL_E);
918ea58996SMichael Ellerman 
928ea58996SMichael Ellerman 	if (fsl_mmu && (mmucfg & MMUCFG_MAVN) == MMUCFG_MAVN_V1) {
938ea58996SMichael Ellerman 		unsigned int tlb1cfg = mfspr(SPRN_TLB1CFG);
948ea58996SMichael Ellerman 		unsigned int min_pg, max_pg;
958ea58996SMichael Ellerman 
968ea58996SMichael Ellerman 		min_pg = (tlb1cfg & TLBnCFG_MINSIZE) >> TLBnCFG_MINSIZE_SHIFT;
978ea58996SMichael Ellerman 		max_pg = (tlb1cfg & TLBnCFG_MAXSIZE) >> TLBnCFG_MAXSIZE_SHIFT;
988ea58996SMichael Ellerman 
998ea58996SMichael Ellerman 		for (psize = 0; psize < MMU_PAGE_COUNT; ++psize) {
1008ea58996SMichael Ellerman 			struct mmu_psize_def *def;
1018ea58996SMichael Ellerman 			unsigned int shift;
1028ea58996SMichael Ellerman 
1038ea58996SMichael Ellerman 			def = &mmu_psize_defs[psize];
1048ea58996SMichael Ellerman 			shift = def->shift;
1058ea58996SMichael Ellerman 
1068ea58996SMichael Ellerman 			if (shift == 0 || shift & 1)
1078ea58996SMichael Ellerman 				continue;
1088ea58996SMichael Ellerman 
1098ea58996SMichael Ellerman 			/* adjust to be in terms of 4^shift Kb */
1108ea58996SMichael Ellerman 			shift = (shift - 10) >> 1;
1118ea58996SMichael Ellerman 
1128ea58996SMichael Ellerman 			if ((shift >= min_pg) && (shift <= max_pg))
1138ea58996SMichael Ellerman 				def->flags |= MMU_PAGE_SIZE_DIRECT;
1148ea58996SMichael Ellerman 		}
1158ea58996SMichael Ellerman 
1168ea58996SMichael Ellerman 		goto out;
1178ea58996SMichael Ellerman 	}
1188ea58996SMichael Ellerman 
1198ea58996SMichael Ellerman 	if (fsl_mmu && (mmucfg & MMUCFG_MAVN) == MMUCFG_MAVN_V2) {
1208ea58996SMichael Ellerman 		u32 tlb1cfg, tlb1ps;
1218ea58996SMichael Ellerman 
1228ea58996SMichael Ellerman 		tlb0cfg = mfspr(SPRN_TLB0CFG);
1238ea58996SMichael Ellerman 		tlb1cfg = mfspr(SPRN_TLB1CFG);
1248ea58996SMichael Ellerman 		tlb1ps = mfspr(SPRN_TLB1PS);
1258ea58996SMichael Ellerman 		eptcfg = mfspr(SPRN_EPTCFG);
1268ea58996SMichael Ellerman 
1278ea58996SMichael Ellerman 		if ((tlb1cfg & TLBnCFG_IND) && (tlb0cfg & TLBnCFG_PT))
1288ea58996SMichael Ellerman 			book3e_htw_mode = PPC_HTW_E6500;
1298ea58996SMichael Ellerman 
1308ea58996SMichael Ellerman 		/*
1318ea58996SMichael Ellerman 		 * We expect 4K subpage size and unrestricted indirect size.
1328ea58996SMichael Ellerman 		 * The lack of a restriction on indirect size is a Freescale
1338ea58996SMichael Ellerman 		 * extension, indicated by PSn = 0 but SPSn != 0.
1348ea58996SMichael Ellerman 		 */
1358ea58996SMichael Ellerman 		if (eptcfg != 2)
1368ea58996SMichael Ellerman 			book3e_htw_mode = PPC_HTW_NONE;
1378ea58996SMichael Ellerman 
1388ea58996SMichael Ellerman 		for (psize = 0; psize < MMU_PAGE_COUNT; ++psize) {
1398ea58996SMichael Ellerman 			struct mmu_psize_def *def = &mmu_psize_defs[psize];
1408ea58996SMichael Ellerman 
1418ea58996SMichael Ellerman 			if (!def->shift)
1428ea58996SMichael Ellerman 				continue;
1438ea58996SMichael Ellerman 
1448ea58996SMichael Ellerman 			if (tlb1ps & (1U << (def->shift - 10))) {
1458ea58996SMichael Ellerman 				def->flags |= MMU_PAGE_SIZE_DIRECT;
1468ea58996SMichael Ellerman 
1478ea58996SMichael Ellerman 				if (book3e_htw_mode && psize == MMU_PAGE_2M)
1488ea58996SMichael Ellerman 					def->flags |= MMU_PAGE_SIZE_INDIRECT;
1498ea58996SMichael Ellerman 			}
1508ea58996SMichael Ellerman 		}
1518ea58996SMichael Ellerman 
1528ea58996SMichael Ellerman 		goto out;
1538ea58996SMichael Ellerman 	}
1548ea58996SMichael Ellerman #endif
1558ea58996SMichael Ellerman out:
1568ea58996SMichael Ellerman 	/* Cleanup array and print summary */
1578ea58996SMichael Ellerman 	pr_info("MMU: Supported page sizes\n");
1588ea58996SMichael Ellerman 	for (psize = 0; psize < MMU_PAGE_COUNT; ++psize) {
1598ea58996SMichael Ellerman 		struct mmu_psize_def *def = &mmu_psize_defs[psize];
1608ea58996SMichael Ellerman 		const char *__page_type_names[] = {
1618ea58996SMichael Ellerman 			"unsupported",
1628ea58996SMichael Ellerman 			"direct",
1638ea58996SMichael Ellerman 			"indirect",
1648ea58996SMichael Ellerman 			"direct & indirect"
1658ea58996SMichael Ellerman 		};
1668ea58996SMichael Ellerman 		if (def->flags == 0) {
1678ea58996SMichael Ellerman 			def->shift = 0;
1688ea58996SMichael Ellerman 			continue;
1698ea58996SMichael Ellerman 		}
1708ea58996SMichael Ellerman 		pr_info("  %8ld KB as %s\n", 1ul << (def->shift - 10),
1718ea58996SMichael Ellerman 			__page_type_names[def->flags & 0x3]);
1728ea58996SMichael Ellerman 	}
1738ea58996SMichael Ellerman }
1748ea58996SMichael Ellerman 
setup_mmu_htw(void)1758ea58996SMichael Ellerman static void __init setup_mmu_htw(void)
1768ea58996SMichael Ellerman {
1778ea58996SMichael Ellerman 	/*
1788ea58996SMichael Ellerman 	 * If we want to use HW tablewalk, enable it by patching the TLB miss
1798ea58996SMichael Ellerman 	 * handlers to branch to the one dedicated to it.
1808ea58996SMichael Ellerman 	 */
1818ea58996SMichael Ellerman 
1828ea58996SMichael Ellerman 	switch (book3e_htw_mode) {
1838ea58996SMichael Ellerman #ifdef CONFIG_PPC_E500
1848ea58996SMichael Ellerman 	case PPC_HTW_E6500:
1858ea58996SMichael Ellerman 		extlb_level_exc = EX_TLB_SIZE;
1868ea58996SMichael Ellerman 		patch_exception(0x1c0, exc_data_tlb_miss_e6500_book3e);
1878ea58996SMichael Ellerman 		patch_exception(0x1e0, exc_instruction_tlb_miss_e6500_book3e);
1888ea58996SMichael Ellerman 		break;
1898ea58996SMichael Ellerman #endif
1908ea58996SMichael Ellerman 	}
1918ea58996SMichael Ellerman 	pr_info("MMU: Book3E HW tablewalk %s\n",
1928ea58996SMichael Ellerman 		book3e_htw_mode != PPC_HTW_NONE ? "enabled" : "not supported");
1938ea58996SMichael Ellerman }
1948ea58996SMichael Ellerman 
1958ea58996SMichael Ellerman /*
1968ea58996SMichael Ellerman  * Early initialization of the MMU TLB code
1978ea58996SMichael Ellerman  */
early_init_this_mmu(void)1988ea58996SMichael Ellerman static void early_init_this_mmu(void)
1998ea58996SMichael Ellerman {
2008ea58996SMichael Ellerman 	unsigned int mas4;
2018ea58996SMichael Ellerman 
2028ea58996SMichael Ellerman 	/* Set MAS4 based on page table setting */
2038ea58996SMichael Ellerman 
2048ea58996SMichael Ellerman 	mas4 = 0x4 << MAS4_WIMGED_SHIFT;
2058ea58996SMichael Ellerman 	switch (book3e_htw_mode) {
2068ea58996SMichael Ellerman 	case PPC_HTW_E6500:
2078ea58996SMichael Ellerman 		mas4 |= MAS4_INDD;
2088ea58996SMichael Ellerman 		mas4 |= BOOK3E_PAGESZ_2M << MAS4_TSIZED_SHIFT;
2098ea58996SMichael Ellerman 		mas4 |= MAS4_TLBSELD(1);
2108ea58996SMichael Ellerman 		mmu_pte_psize = MMU_PAGE_2M;
2118ea58996SMichael Ellerman 		break;
2128ea58996SMichael Ellerman 
2138ea58996SMichael Ellerman 	case PPC_HTW_NONE:
2148ea58996SMichael Ellerman 		mas4 |=	BOOK3E_PAGESZ_4K << MAS4_TSIZED_SHIFT;
2158ea58996SMichael Ellerman 		mmu_pte_psize = mmu_virtual_psize;
2168ea58996SMichael Ellerman 		break;
2178ea58996SMichael Ellerman 	}
2188ea58996SMichael Ellerman 	mtspr(SPRN_MAS4, mas4);
2198ea58996SMichael Ellerman 
2208ea58996SMichael Ellerman #ifdef CONFIG_PPC_E500
2218ea58996SMichael Ellerman 	if (mmu_has_feature(MMU_FTR_TYPE_FSL_E)) {
2228ea58996SMichael Ellerman 		unsigned int num_cams;
2238ea58996SMichael Ellerman 		bool map = true;
2248ea58996SMichael Ellerman 
2258ea58996SMichael Ellerman 		/* use a quarter of the TLBCAM for bolted linear map */
2268ea58996SMichael Ellerman 		num_cams = (mfspr(SPRN_TLB1CFG) & TLBnCFG_N_ENTRY) / 4;
2278ea58996SMichael Ellerman 
2288ea58996SMichael Ellerman 		/*
2298ea58996SMichael Ellerman 		 * Only do the mapping once per core, or else the
2308ea58996SMichael Ellerman 		 * transient mapping would cause problems.
2318ea58996SMichael Ellerman 		 */
2328ea58996SMichael Ellerman #ifdef CONFIG_SMP
2338ea58996SMichael Ellerman 		if (hweight32(get_tensr()) > 1)
2348ea58996SMichael Ellerman 			map = false;
2358ea58996SMichael Ellerman #endif
2368ea58996SMichael Ellerman 
2378ea58996SMichael Ellerman 		if (map)
2388ea58996SMichael Ellerman 			linear_map_top = map_mem_in_cams(linear_map_top,
2398ea58996SMichael Ellerman 							 num_cams, false, true);
2408ea58996SMichael Ellerman 	}
2418ea58996SMichael Ellerman #endif
2428ea58996SMichael Ellerman 
2438ea58996SMichael Ellerman 	/* A sync won't hurt us after mucking around with
2448ea58996SMichael Ellerman 	 * the MMU configuration
2458ea58996SMichael Ellerman 	 */
2468ea58996SMichael Ellerman 	mb();
2478ea58996SMichael Ellerman }
2488ea58996SMichael Ellerman 
early_init_mmu_global(void)2498ea58996SMichael Ellerman static void __init early_init_mmu_global(void)
2508ea58996SMichael Ellerman {
2518ea58996SMichael Ellerman 	/* XXX This should be decided at runtime based on supported
2528ea58996SMichael Ellerman 	 * page sizes in the TLB, but for now let's assume 16M is
2538ea58996SMichael Ellerman 	 * always there and a good fit (which it probably is)
2548ea58996SMichael Ellerman 	 *
2558ea58996SMichael Ellerman 	 * Freescale booke only supports 4K pages in TLB0, so use that.
2568ea58996SMichael Ellerman 	 */
2578ea58996SMichael Ellerman 	if (mmu_has_feature(MMU_FTR_TYPE_FSL_E))
2588ea58996SMichael Ellerman 		mmu_vmemmap_psize = MMU_PAGE_4K;
2598ea58996SMichael Ellerman 	else
2608ea58996SMichael Ellerman 		mmu_vmemmap_psize = MMU_PAGE_16M;
2618ea58996SMichael Ellerman 
2628ea58996SMichael Ellerman 	/* XXX This code only checks for TLB 0 capabilities and doesn't
2638ea58996SMichael Ellerman 	 *     check what page size combos are supported by the HW. It
2648ea58996SMichael Ellerman 	 *     also doesn't handle the case where a separate array holds
2658ea58996SMichael Ellerman 	 *     the IND entries from the array loaded by the PT.
2668ea58996SMichael Ellerman 	 */
2678ea58996SMichael Ellerman 	/* Look for supported page sizes */
2688ea58996SMichael Ellerman 	setup_page_sizes();
2698ea58996SMichael Ellerman 
2708ea58996SMichael Ellerman 	/* Look for HW tablewalk support */
2718ea58996SMichael Ellerman 	setup_mmu_htw();
2728ea58996SMichael Ellerman 
2738ea58996SMichael Ellerman #ifdef CONFIG_PPC_E500
2748ea58996SMichael Ellerman 	if (mmu_has_feature(MMU_FTR_TYPE_FSL_E)) {
2758ea58996SMichael Ellerman 		if (book3e_htw_mode == PPC_HTW_NONE) {
2768ea58996SMichael Ellerman 			extlb_level_exc = EX_TLB_SIZE;
2778ea58996SMichael Ellerman 			patch_exception(0x1c0, exc_data_tlb_miss_bolted_book3e);
2788ea58996SMichael Ellerman 			patch_exception(0x1e0,
2798ea58996SMichael Ellerman 				exc_instruction_tlb_miss_bolted_book3e);
2808ea58996SMichael Ellerman 		}
2818ea58996SMichael Ellerman 	}
2828ea58996SMichael Ellerman #endif
2838ea58996SMichael Ellerman 
2848ea58996SMichael Ellerman 	/* Set the global containing the top of the linear mapping
2858ea58996SMichael Ellerman 	 * for use by the TLB miss code
2868ea58996SMichael Ellerman 	 */
2878ea58996SMichael Ellerman 	linear_map_top = memblock_end_of_DRAM();
2888ea58996SMichael Ellerman 
2898ea58996SMichael Ellerman 	ioremap_bot = IOREMAP_BASE;
2908ea58996SMichael Ellerman }
2918ea58996SMichael Ellerman 
early_mmu_set_memory_limit(void)2928ea58996SMichael Ellerman static void __init early_mmu_set_memory_limit(void)
2938ea58996SMichael Ellerman {
2948ea58996SMichael Ellerman #ifdef CONFIG_PPC_E500
2958ea58996SMichael Ellerman 	if (mmu_has_feature(MMU_FTR_TYPE_FSL_E)) {
2968ea58996SMichael Ellerman 		/*
2978ea58996SMichael Ellerman 		 * Limit memory so we dont have linear faults.
2988ea58996SMichael Ellerman 		 * Unlike memblock_set_current_limit, which limits
2998ea58996SMichael Ellerman 		 * memory available during early boot, this permanently
3008ea58996SMichael Ellerman 		 * reduces the memory available to Linux.  We need to
3018ea58996SMichael Ellerman 		 * do this because highmem is not supported on 64-bit.
3028ea58996SMichael Ellerman 		 */
3038ea58996SMichael Ellerman 		memblock_enforce_memory_limit(linear_map_top);
3048ea58996SMichael Ellerman 	}
3058ea58996SMichael Ellerman #endif
3068ea58996SMichael Ellerman 
3078ea58996SMichael Ellerman 	memblock_set_current_limit(linear_map_top);
3088ea58996SMichael Ellerman }
3098ea58996SMichael Ellerman 
3108ea58996SMichael Ellerman /* boot cpu only */
early_init_mmu(void)3118ea58996SMichael Ellerman void __init early_init_mmu(void)
3128ea58996SMichael Ellerman {
3138ea58996SMichael Ellerman 	early_init_mmu_global();
3148ea58996SMichael Ellerman 	early_init_this_mmu();
3158ea58996SMichael Ellerman 	early_mmu_set_memory_limit();
3168ea58996SMichael Ellerman }
3178ea58996SMichael Ellerman 
early_init_mmu_secondary(void)3188ea58996SMichael Ellerman void early_init_mmu_secondary(void)
3198ea58996SMichael Ellerman {
3208ea58996SMichael Ellerman 	early_init_this_mmu();
3218ea58996SMichael Ellerman }
3228ea58996SMichael Ellerman 
setup_initial_memory_limit(phys_addr_t first_memblock_base,phys_addr_t first_memblock_size)3238ea58996SMichael Ellerman void setup_initial_memory_limit(phys_addr_t first_memblock_base,
3248ea58996SMichael Ellerman 				phys_addr_t first_memblock_size)
3258ea58996SMichael Ellerman {
3268ea58996SMichael Ellerman 	/* On non-FSL Embedded 64-bit, we adjust the RMA size to match
3278ea58996SMichael Ellerman 	 * the bolted TLB entry. We know for now that only 1G
3288ea58996SMichael Ellerman 	 * entries are supported though that may eventually
3298ea58996SMichael Ellerman 	 * change.
3308ea58996SMichael Ellerman 	 *
3318ea58996SMichael Ellerman 	 * on FSL Embedded 64-bit, usually all RAM is bolted, but with
3328ea58996SMichael Ellerman 	 * unusual memory sizes it's possible for some RAM to not be mapped
3338ea58996SMichael Ellerman 	 * (such RAM is not used at all by Linux, since we don't support
3348ea58996SMichael Ellerman 	 * highmem on 64-bit).  We limit ppc64_rma_size to what would be
3358ea58996SMichael Ellerman 	 * mappable if this memblock is the only one.  Additional memblocks
3368ea58996SMichael Ellerman 	 * can only increase, not decrease, the amount that ends up getting
3378ea58996SMichael Ellerman 	 * mapped.  We still limit max to 1G even if we'll eventually map
3388ea58996SMichael Ellerman 	 * more.  This is due to what the early init code is set up to do.
3398ea58996SMichael Ellerman 	 *
3408ea58996SMichael Ellerman 	 * We crop it to the size of the first MEMBLOCK to
3418ea58996SMichael Ellerman 	 * avoid going over total available memory just in case...
3428ea58996SMichael Ellerman 	 */
3438ea58996SMichael Ellerman #ifdef CONFIG_PPC_E500
3448ea58996SMichael Ellerman 	if (early_mmu_has_feature(MMU_FTR_TYPE_FSL_E)) {
3458ea58996SMichael Ellerman 		unsigned long linear_sz;
3468ea58996SMichael Ellerman 		unsigned int num_cams;
3478ea58996SMichael Ellerman 
3488ea58996SMichael Ellerman 		/* use a quarter of the TLBCAM for bolted linear map */
3498ea58996SMichael Ellerman 		num_cams = (mfspr(SPRN_TLB1CFG) & TLBnCFG_N_ENTRY) / 4;
3508ea58996SMichael Ellerman 
3518ea58996SMichael Ellerman 		linear_sz = map_mem_in_cams(first_memblock_size, num_cams,
3528ea58996SMichael Ellerman 					    true, true);
3538ea58996SMichael Ellerman 
3548ea58996SMichael Ellerman 		ppc64_rma_size = min_t(u64, linear_sz, 0x40000000);
3558ea58996SMichael Ellerman 	} else
3568ea58996SMichael Ellerman #endif
3578ea58996SMichael Ellerman 		ppc64_rma_size = min_t(u64, first_memblock_size, 0x40000000);
3588ea58996SMichael Ellerman 
3598ea58996SMichael Ellerman 	/* Finally limit subsequent allocations */
3608ea58996SMichael Ellerman 	memblock_set_current_limit(first_memblock_base + ppc64_rma_size);
3618ea58996SMichael Ellerman }
362