xref: /openbmc/linux/arch/powerpc/mm/nohash/tlb_64e.c (revision 8ea58996)
1*8ea58996SMichael Ellerman // SPDX-License-Identifier: GPL-2.0-or-later
2*8ea58996SMichael Ellerman /*
3*8ea58996SMichael Ellerman  * Copyright 2008,2009 Ben Herrenschmidt <benh@kernel.crashing.org>
4*8ea58996SMichael Ellerman  *                     IBM Corp.
5*8ea58996SMichael Ellerman  *
6*8ea58996SMichael Ellerman  *  Derived from arch/ppc/mm/init.c:
7*8ea58996SMichael Ellerman  *    Copyright (C) 1995-1996 Gary Thomas (gdt@linuxppc.org)
8*8ea58996SMichael Ellerman  *
9*8ea58996SMichael Ellerman  *  Modifications by Paul Mackerras (PowerMac) (paulus@cs.anu.edu.au)
10*8ea58996SMichael Ellerman  *  and Cort Dougan (PReP) (cort@cs.nmt.edu)
11*8ea58996SMichael Ellerman  *    Copyright (C) 1996 Paul Mackerras
12*8ea58996SMichael Ellerman  *
13*8ea58996SMichael Ellerman  *  Derived from "arch/i386/mm/init.c"
14*8ea58996SMichael Ellerman  *    Copyright (C) 1991, 1992, 1993, 1994  Linus Torvalds
15*8ea58996SMichael Ellerman  */
16*8ea58996SMichael Ellerman 
17*8ea58996SMichael Ellerman #include <linux/kernel.h>
18*8ea58996SMichael Ellerman #include <linux/export.h>
19*8ea58996SMichael Ellerman #include <linux/mm.h>
20*8ea58996SMichael Ellerman #include <linux/init.h>
21*8ea58996SMichael Ellerman #include <linux/pagemap.h>
22*8ea58996SMichael Ellerman #include <linux/memblock.h>
23*8ea58996SMichael Ellerman 
24*8ea58996SMichael Ellerman #include <asm/pgalloc.h>
25*8ea58996SMichael Ellerman #include <asm/tlbflush.h>
26*8ea58996SMichael Ellerman #include <asm/tlb.h>
27*8ea58996SMichael Ellerman #include <asm/code-patching.h>
28*8ea58996SMichael Ellerman #include <asm/cputhreads.h>
29*8ea58996SMichael Ellerman 
30*8ea58996SMichael Ellerman #include <mm/mmu_decl.h>
31*8ea58996SMichael Ellerman 
32*8ea58996SMichael Ellerman /* The variables below are currently only used on 64-bit Book3E
33*8ea58996SMichael Ellerman  * though this will probably be made common with other nohash
34*8ea58996SMichael Ellerman  * implementations at some point
35*8ea58996SMichael Ellerman  */
36*8ea58996SMichael Ellerman int mmu_pte_psize;		/* Page size used for PTE pages */
37*8ea58996SMichael Ellerman int mmu_vmemmap_psize;		/* Page size used for the virtual mem map */
38*8ea58996SMichael Ellerman int book3e_htw_mode;		/* HW tablewalk?  Value is PPC_HTW_* */
39*8ea58996SMichael Ellerman unsigned long linear_map_top;	/* Top of linear mapping */
40*8ea58996SMichael Ellerman 
41*8ea58996SMichael Ellerman 
42*8ea58996SMichael Ellerman /*
43*8ea58996SMichael Ellerman  * Number of bytes to add to SPRN_SPRG_TLB_EXFRAME on crit/mcheck/debug
44*8ea58996SMichael Ellerman  * exceptions.  This is used for bolted and e6500 TLB miss handlers which
45*8ea58996SMichael Ellerman  * do not modify this SPRG in the TLB miss code; for other TLB miss handlers,
46*8ea58996SMichael Ellerman  * this is set to zero.
47*8ea58996SMichael Ellerman  */
48*8ea58996SMichael Ellerman int extlb_level_exc;
49*8ea58996SMichael Ellerman 
50*8ea58996SMichael Ellerman /*
51*8ea58996SMichael Ellerman  * Handling of virtual linear page tables or indirect TLB entries
52*8ea58996SMichael Ellerman  * flushing when PTE pages are freed
53*8ea58996SMichael Ellerman  */
54*8ea58996SMichael Ellerman void tlb_flush_pgtable(struct mmu_gather *tlb, unsigned long address)
55*8ea58996SMichael Ellerman {
56*8ea58996SMichael Ellerman 	int tsize = mmu_psize_defs[mmu_pte_psize].enc;
57*8ea58996SMichael Ellerman 
58*8ea58996SMichael Ellerman 	if (book3e_htw_mode != PPC_HTW_NONE) {
59*8ea58996SMichael Ellerman 		unsigned long start = address & PMD_MASK;
60*8ea58996SMichael Ellerman 		unsigned long end = address + PMD_SIZE;
61*8ea58996SMichael Ellerman 		unsigned long size = 1UL << mmu_psize_defs[mmu_pte_psize].shift;
62*8ea58996SMichael Ellerman 
63*8ea58996SMichael Ellerman 		/* This isn't the most optimal, ideally we would factor out the
64*8ea58996SMichael Ellerman 		 * while preempt & CPU mask mucking around, or even the IPI but
65*8ea58996SMichael Ellerman 		 * it will do for now
66*8ea58996SMichael Ellerman 		 */
67*8ea58996SMichael Ellerman 		while (start < end) {
68*8ea58996SMichael Ellerman 			__flush_tlb_page(tlb->mm, start, tsize, 1);
69*8ea58996SMichael Ellerman 			start += size;
70*8ea58996SMichael Ellerman 		}
71*8ea58996SMichael Ellerman 	} else {
72*8ea58996SMichael Ellerman 		unsigned long rmask = 0xf000000000000000ul;
73*8ea58996SMichael Ellerman 		unsigned long rid = (address & rmask) | 0x1000000000000000ul;
74*8ea58996SMichael Ellerman 		unsigned long vpte = address & ~rmask;
75*8ea58996SMichael Ellerman 
76*8ea58996SMichael Ellerman 		vpte = (vpte >> (PAGE_SHIFT - 3)) & ~0xffful;
77*8ea58996SMichael Ellerman 		vpte |= rid;
78*8ea58996SMichael Ellerman 		__flush_tlb_page(tlb->mm, vpte, tsize, 0);
79*8ea58996SMichael Ellerman 	}
80*8ea58996SMichael Ellerman }
81*8ea58996SMichael Ellerman 
82*8ea58996SMichael Ellerman static void __init setup_page_sizes(void)
83*8ea58996SMichael Ellerman {
84*8ea58996SMichael Ellerman 	unsigned int tlb0cfg;
85*8ea58996SMichael Ellerman 	unsigned int eptcfg;
86*8ea58996SMichael Ellerman 	int psize;
87*8ea58996SMichael Ellerman 
88*8ea58996SMichael Ellerman #ifdef CONFIG_PPC_E500
89*8ea58996SMichael Ellerman 	unsigned int mmucfg = mfspr(SPRN_MMUCFG);
90*8ea58996SMichael Ellerman 	int fsl_mmu = mmu_has_feature(MMU_FTR_TYPE_FSL_E);
91*8ea58996SMichael Ellerman 
92*8ea58996SMichael Ellerman 	if (fsl_mmu && (mmucfg & MMUCFG_MAVN) == MMUCFG_MAVN_V1) {
93*8ea58996SMichael Ellerman 		unsigned int tlb1cfg = mfspr(SPRN_TLB1CFG);
94*8ea58996SMichael Ellerman 		unsigned int min_pg, max_pg;
95*8ea58996SMichael Ellerman 
96*8ea58996SMichael Ellerman 		min_pg = (tlb1cfg & TLBnCFG_MINSIZE) >> TLBnCFG_MINSIZE_SHIFT;
97*8ea58996SMichael Ellerman 		max_pg = (tlb1cfg & TLBnCFG_MAXSIZE) >> TLBnCFG_MAXSIZE_SHIFT;
98*8ea58996SMichael Ellerman 
99*8ea58996SMichael Ellerman 		for (psize = 0; psize < MMU_PAGE_COUNT; ++psize) {
100*8ea58996SMichael Ellerman 			struct mmu_psize_def *def;
101*8ea58996SMichael Ellerman 			unsigned int shift;
102*8ea58996SMichael Ellerman 
103*8ea58996SMichael Ellerman 			def = &mmu_psize_defs[psize];
104*8ea58996SMichael Ellerman 			shift = def->shift;
105*8ea58996SMichael Ellerman 
106*8ea58996SMichael Ellerman 			if (shift == 0 || shift & 1)
107*8ea58996SMichael Ellerman 				continue;
108*8ea58996SMichael Ellerman 
109*8ea58996SMichael Ellerman 			/* adjust to be in terms of 4^shift Kb */
110*8ea58996SMichael Ellerman 			shift = (shift - 10) >> 1;
111*8ea58996SMichael Ellerman 
112*8ea58996SMichael Ellerman 			if ((shift >= min_pg) && (shift <= max_pg))
113*8ea58996SMichael Ellerman 				def->flags |= MMU_PAGE_SIZE_DIRECT;
114*8ea58996SMichael Ellerman 		}
115*8ea58996SMichael Ellerman 
116*8ea58996SMichael Ellerman 		goto out;
117*8ea58996SMichael Ellerman 	}
118*8ea58996SMichael Ellerman 
119*8ea58996SMichael Ellerman 	if (fsl_mmu && (mmucfg & MMUCFG_MAVN) == MMUCFG_MAVN_V2) {
120*8ea58996SMichael Ellerman 		u32 tlb1cfg, tlb1ps;
121*8ea58996SMichael Ellerman 
122*8ea58996SMichael Ellerman 		tlb0cfg = mfspr(SPRN_TLB0CFG);
123*8ea58996SMichael Ellerman 		tlb1cfg = mfspr(SPRN_TLB1CFG);
124*8ea58996SMichael Ellerman 		tlb1ps = mfspr(SPRN_TLB1PS);
125*8ea58996SMichael Ellerman 		eptcfg = mfspr(SPRN_EPTCFG);
126*8ea58996SMichael Ellerman 
127*8ea58996SMichael Ellerman 		if ((tlb1cfg & TLBnCFG_IND) && (tlb0cfg & TLBnCFG_PT))
128*8ea58996SMichael Ellerman 			book3e_htw_mode = PPC_HTW_E6500;
129*8ea58996SMichael Ellerman 
130*8ea58996SMichael Ellerman 		/*
131*8ea58996SMichael Ellerman 		 * We expect 4K subpage size and unrestricted indirect size.
132*8ea58996SMichael Ellerman 		 * The lack of a restriction on indirect size is a Freescale
133*8ea58996SMichael Ellerman 		 * extension, indicated by PSn = 0 but SPSn != 0.
134*8ea58996SMichael Ellerman 		 */
135*8ea58996SMichael Ellerman 		if (eptcfg != 2)
136*8ea58996SMichael Ellerman 			book3e_htw_mode = PPC_HTW_NONE;
137*8ea58996SMichael Ellerman 
138*8ea58996SMichael Ellerman 		for (psize = 0; psize < MMU_PAGE_COUNT; ++psize) {
139*8ea58996SMichael Ellerman 			struct mmu_psize_def *def = &mmu_psize_defs[psize];
140*8ea58996SMichael Ellerman 
141*8ea58996SMichael Ellerman 			if (!def->shift)
142*8ea58996SMichael Ellerman 				continue;
143*8ea58996SMichael Ellerman 
144*8ea58996SMichael Ellerman 			if (tlb1ps & (1U << (def->shift - 10))) {
145*8ea58996SMichael Ellerman 				def->flags |= MMU_PAGE_SIZE_DIRECT;
146*8ea58996SMichael Ellerman 
147*8ea58996SMichael Ellerman 				if (book3e_htw_mode && psize == MMU_PAGE_2M)
148*8ea58996SMichael Ellerman 					def->flags |= MMU_PAGE_SIZE_INDIRECT;
149*8ea58996SMichael Ellerman 			}
150*8ea58996SMichael Ellerman 		}
151*8ea58996SMichael Ellerman 
152*8ea58996SMichael Ellerman 		goto out;
153*8ea58996SMichael Ellerman 	}
154*8ea58996SMichael Ellerman #endif
155*8ea58996SMichael Ellerman out:
156*8ea58996SMichael Ellerman 	/* Cleanup array and print summary */
157*8ea58996SMichael Ellerman 	pr_info("MMU: Supported page sizes\n");
158*8ea58996SMichael Ellerman 	for (psize = 0; psize < MMU_PAGE_COUNT; ++psize) {
159*8ea58996SMichael Ellerman 		struct mmu_psize_def *def = &mmu_psize_defs[psize];
160*8ea58996SMichael Ellerman 		const char *__page_type_names[] = {
161*8ea58996SMichael Ellerman 			"unsupported",
162*8ea58996SMichael Ellerman 			"direct",
163*8ea58996SMichael Ellerman 			"indirect",
164*8ea58996SMichael Ellerman 			"direct & indirect"
165*8ea58996SMichael Ellerman 		};
166*8ea58996SMichael Ellerman 		if (def->flags == 0) {
167*8ea58996SMichael Ellerman 			def->shift = 0;
168*8ea58996SMichael Ellerman 			continue;
169*8ea58996SMichael Ellerman 		}
170*8ea58996SMichael Ellerman 		pr_info("  %8ld KB as %s\n", 1ul << (def->shift - 10),
171*8ea58996SMichael Ellerman 			__page_type_names[def->flags & 0x3]);
172*8ea58996SMichael Ellerman 	}
173*8ea58996SMichael Ellerman }
174*8ea58996SMichael Ellerman 
175*8ea58996SMichael Ellerman static void __init setup_mmu_htw(void)
176*8ea58996SMichael Ellerman {
177*8ea58996SMichael Ellerman 	/*
178*8ea58996SMichael Ellerman 	 * If we want to use HW tablewalk, enable it by patching the TLB miss
179*8ea58996SMichael Ellerman 	 * handlers to branch to the one dedicated to it.
180*8ea58996SMichael Ellerman 	 */
181*8ea58996SMichael Ellerman 
182*8ea58996SMichael Ellerman 	switch (book3e_htw_mode) {
183*8ea58996SMichael Ellerman #ifdef CONFIG_PPC_E500
184*8ea58996SMichael Ellerman 	case PPC_HTW_E6500:
185*8ea58996SMichael Ellerman 		extlb_level_exc = EX_TLB_SIZE;
186*8ea58996SMichael Ellerman 		patch_exception(0x1c0, exc_data_tlb_miss_e6500_book3e);
187*8ea58996SMichael Ellerman 		patch_exception(0x1e0, exc_instruction_tlb_miss_e6500_book3e);
188*8ea58996SMichael Ellerman 		break;
189*8ea58996SMichael Ellerman #endif
190*8ea58996SMichael Ellerman 	}
191*8ea58996SMichael Ellerman 	pr_info("MMU: Book3E HW tablewalk %s\n",
192*8ea58996SMichael Ellerman 		book3e_htw_mode != PPC_HTW_NONE ? "enabled" : "not supported");
193*8ea58996SMichael Ellerman }
194*8ea58996SMichael Ellerman 
195*8ea58996SMichael Ellerman /*
196*8ea58996SMichael Ellerman  * Early initialization of the MMU TLB code
197*8ea58996SMichael Ellerman  */
198*8ea58996SMichael Ellerman static void early_init_this_mmu(void)
199*8ea58996SMichael Ellerman {
200*8ea58996SMichael Ellerman 	unsigned int mas4;
201*8ea58996SMichael Ellerman 
202*8ea58996SMichael Ellerman 	/* Set MAS4 based on page table setting */
203*8ea58996SMichael Ellerman 
204*8ea58996SMichael Ellerman 	mas4 = 0x4 << MAS4_WIMGED_SHIFT;
205*8ea58996SMichael Ellerman 	switch (book3e_htw_mode) {
206*8ea58996SMichael Ellerman 	case PPC_HTW_E6500:
207*8ea58996SMichael Ellerman 		mas4 |= MAS4_INDD;
208*8ea58996SMichael Ellerman 		mas4 |= BOOK3E_PAGESZ_2M << MAS4_TSIZED_SHIFT;
209*8ea58996SMichael Ellerman 		mas4 |= MAS4_TLBSELD(1);
210*8ea58996SMichael Ellerman 		mmu_pte_psize = MMU_PAGE_2M;
211*8ea58996SMichael Ellerman 		break;
212*8ea58996SMichael Ellerman 
213*8ea58996SMichael Ellerman 	case PPC_HTW_NONE:
214*8ea58996SMichael Ellerman 		mas4 |=	BOOK3E_PAGESZ_4K << MAS4_TSIZED_SHIFT;
215*8ea58996SMichael Ellerman 		mmu_pte_psize = mmu_virtual_psize;
216*8ea58996SMichael Ellerman 		break;
217*8ea58996SMichael Ellerman 	}
218*8ea58996SMichael Ellerman 	mtspr(SPRN_MAS4, mas4);
219*8ea58996SMichael Ellerman 
220*8ea58996SMichael Ellerman #ifdef CONFIG_PPC_E500
221*8ea58996SMichael Ellerman 	if (mmu_has_feature(MMU_FTR_TYPE_FSL_E)) {
222*8ea58996SMichael Ellerman 		unsigned int num_cams;
223*8ea58996SMichael Ellerman 		bool map = true;
224*8ea58996SMichael Ellerman 
225*8ea58996SMichael Ellerman 		/* use a quarter of the TLBCAM for bolted linear map */
226*8ea58996SMichael Ellerman 		num_cams = (mfspr(SPRN_TLB1CFG) & TLBnCFG_N_ENTRY) / 4;
227*8ea58996SMichael Ellerman 
228*8ea58996SMichael Ellerman 		/*
229*8ea58996SMichael Ellerman 		 * Only do the mapping once per core, or else the
230*8ea58996SMichael Ellerman 		 * transient mapping would cause problems.
231*8ea58996SMichael Ellerman 		 */
232*8ea58996SMichael Ellerman #ifdef CONFIG_SMP
233*8ea58996SMichael Ellerman 		if (hweight32(get_tensr()) > 1)
234*8ea58996SMichael Ellerman 			map = false;
235*8ea58996SMichael Ellerman #endif
236*8ea58996SMichael Ellerman 
237*8ea58996SMichael Ellerman 		if (map)
238*8ea58996SMichael Ellerman 			linear_map_top = map_mem_in_cams(linear_map_top,
239*8ea58996SMichael Ellerman 							 num_cams, false, true);
240*8ea58996SMichael Ellerman 	}
241*8ea58996SMichael Ellerman #endif
242*8ea58996SMichael Ellerman 
243*8ea58996SMichael Ellerman 	/* A sync won't hurt us after mucking around with
244*8ea58996SMichael Ellerman 	 * the MMU configuration
245*8ea58996SMichael Ellerman 	 */
246*8ea58996SMichael Ellerman 	mb();
247*8ea58996SMichael Ellerman }
248*8ea58996SMichael Ellerman 
249*8ea58996SMichael Ellerman static void __init early_init_mmu_global(void)
250*8ea58996SMichael Ellerman {
251*8ea58996SMichael Ellerman 	/* XXX This should be decided at runtime based on supported
252*8ea58996SMichael Ellerman 	 * page sizes in the TLB, but for now let's assume 16M is
253*8ea58996SMichael Ellerman 	 * always there and a good fit (which it probably is)
254*8ea58996SMichael Ellerman 	 *
255*8ea58996SMichael Ellerman 	 * Freescale booke only supports 4K pages in TLB0, so use that.
256*8ea58996SMichael Ellerman 	 */
257*8ea58996SMichael Ellerman 	if (mmu_has_feature(MMU_FTR_TYPE_FSL_E))
258*8ea58996SMichael Ellerman 		mmu_vmemmap_psize = MMU_PAGE_4K;
259*8ea58996SMichael Ellerman 	else
260*8ea58996SMichael Ellerman 		mmu_vmemmap_psize = MMU_PAGE_16M;
261*8ea58996SMichael Ellerman 
262*8ea58996SMichael Ellerman 	/* XXX This code only checks for TLB 0 capabilities and doesn't
263*8ea58996SMichael Ellerman 	 *     check what page size combos are supported by the HW. It
264*8ea58996SMichael Ellerman 	 *     also doesn't handle the case where a separate array holds
265*8ea58996SMichael Ellerman 	 *     the IND entries from the array loaded by the PT.
266*8ea58996SMichael Ellerman 	 */
267*8ea58996SMichael Ellerman 	/* Look for supported page sizes */
268*8ea58996SMichael Ellerman 	setup_page_sizes();
269*8ea58996SMichael Ellerman 
270*8ea58996SMichael Ellerman 	/* Look for HW tablewalk support */
271*8ea58996SMichael Ellerman 	setup_mmu_htw();
272*8ea58996SMichael Ellerman 
273*8ea58996SMichael Ellerman #ifdef CONFIG_PPC_E500
274*8ea58996SMichael Ellerman 	if (mmu_has_feature(MMU_FTR_TYPE_FSL_E)) {
275*8ea58996SMichael Ellerman 		if (book3e_htw_mode == PPC_HTW_NONE) {
276*8ea58996SMichael Ellerman 			extlb_level_exc = EX_TLB_SIZE;
277*8ea58996SMichael Ellerman 			patch_exception(0x1c0, exc_data_tlb_miss_bolted_book3e);
278*8ea58996SMichael Ellerman 			patch_exception(0x1e0,
279*8ea58996SMichael Ellerman 				exc_instruction_tlb_miss_bolted_book3e);
280*8ea58996SMichael Ellerman 		}
281*8ea58996SMichael Ellerman 	}
282*8ea58996SMichael Ellerman #endif
283*8ea58996SMichael Ellerman 
284*8ea58996SMichael Ellerman 	/* Set the global containing the top of the linear mapping
285*8ea58996SMichael Ellerman 	 * for use by the TLB miss code
286*8ea58996SMichael Ellerman 	 */
287*8ea58996SMichael Ellerman 	linear_map_top = memblock_end_of_DRAM();
288*8ea58996SMichael Ellerman 
289*8ea58996SMichael Ellerman 	ioremap_bot = IOREMAP_BASE;
290*8ea58996SMichael Ellerman }
291*8ea58996SMichael Ellerman 
292*8ea58996SMichael Ellerman static void __init early_mmu_set_memory_limit(void)
293*8ea58996SMichael Ellerman {
294*8ea58996SMichael Ellerman #ifdef CONFIG_PPC_E500
295*8ea58996SMichael Ellerman 	if (mmu_has_feature(MMU_FTR_TYPE_FSL_E)) {
296*8ea58996SMichael Ellerman 		/*
297*8ea58996SMichael Ellerman 		 * Limit memory so we dont have linear faults.
298*8ea58996SMichael Ellerman 		 * Unlike memblock_set_current_limit, which limits
299*8ea58996SMichael Ellerman 		 * memory available during early boot, this permanently
300*8ea58996SMichael Ellerman 		 * reduces the memory available to Linux.  We need to
301*8ea58996SMichael Ellerman 		 * do this because highmem is not supported on 64-bit.
302*8ea58996SMichael Ellerman 		 */
303*8ea58996SMichael Ellerman 		memblock_enforce_memory_limit(linear_map_top);
304*8ea58996SMichael Ellerman 	}
305*8ea58996SMichael Ellerman #endif
306*8ea58996SMichael Ellerman 
307*8ea58996SMichael Ellerman 	memblock_set_current_limit(linear_map_top);
308*8ea58996SMichael Ellerman }
309*8ea58996SMichael Ellerman 
310*8ea58996SMichael Ellerman /* boot cpu only */
311*8ea58996SMichael Ellerman void __init early_init_mmu(void)
312*8ea58996SMichael Ellerman {
313*8ea58996SMichael Ellerman 	early_init_mmu_global();
314*8ea58996SMichael Ellerman 	early_init_this_mmu();
315*8ea58996SMichael Ellerman 	early_mmu_set_memory_limit();
316*8ea58996SMichael Ellerman }
317*8ea58996SMichael Ellerman 
318*8ea58996SMichael Ellerman void early_init_mmu_secondary(void)
319*8ea58996SMichael Ellerman {
320*8ea58996SMichael Ellerman 	early_init_this_mmu();
321*8ea58996SMichael Ellerman }
322*8ea58996SMichael Ellerman 
323*8ea58996SMichael Ellerman void setup_initial_memory_limit(phys_addr_t first_memblock_base,
324*8ea58996SMichael Ellerman 				phys_addr_t first_memblock_size)
325*8ea58996SMichael Ellerman {
326*8ea58996SMichael Ellerman 	/* On non-FSL Embedded 64-bit, we adjust the RMA size to match
327*8ea58996SMichael Ellerman 	 * the bolted TLB entry. We know for now that only 1G
328*8ea58996SMichael Ellerman 	 * entries are supported though that may eventually
329*8ea58996SMichael Ellerman 	 * change.
330*8ea58996SMichael Ellerman 	 *
331*8ea58996SMichael Ellerman 	 * on FSL Embedded 64-bit, usually all RAM is bolted, but with
332*8ea58996SMichael Ellerman 	 * unusual memory sizes it's possible for some RAM to not be mapped
333*8ea58996SMichael Ellerman 	 * (such RAM is not used at all by Linux, since we don't support
334*8ea58996SMichael Ellerman 	 * highmem on 64-bit).  We limit ppc64_rma_size to what would be
335*8ea58996SMichael Ellerman 	 * mappable if this memblock is the only one.  Additional memblocks
336*8ea58996SMichael Ellerman 	 * can only increase, not decrease, the amount that ends up getting
337*8ea58996SMichael Ellerman 	 * mapped.  We still limit max to 1G even if we'll eventually map
338*8ea58996SMichael Ellerman 	 * more.  This is due to what the early init code is set up to do.
339*8ea58996SMichael Ellerman 	 *
340*8ea58996SMichael Ellerman 	 * We crop it to the size of the first MEMBLOCK to
341*8ea58996SMichael Ellerman 	 * avoid going over total available memory just in case...
342*8ea58996SMichael Ellerman 	 */
343*8ea58996SMichael Ellerman #ifdef CONFIG_PPC_E500
344*8ea58996SMichael Ellerman 	if (early_mmu_has_feature(MMU_FTR_TYPE_FSL_E)) {
345*8ea58996SMichael Ellerman 		unsigned long linear_sz;
346*8ea58996SMichael Ellerman 		unsigned int num_cams;
347*8ea58996SMichael Ellerman 
348*8ea58996SMichael Ellerman 		/* use a quarter of the TLBCAM for bolted linear map */
349*8ea58996SMichael Ellerman 		num_cams = (mfspr(SPRN_TLB1CFG) & TLBnCFG_N_ENTRY) / 4;
350*8ea58996SMichael Ellerman 
351*8ea58996SMichael Ellerman 		linear_sz = map_mem_in_cams(first_memblock_size, num_cams,
352*8ea58996SMichael Ellerman 					    true, true);
353*8ea58996SMichael Ellerman 
354*8ea58996SMichael Ellerman 		ppc64_rma_size = min_t(u64, linear_sz, 0x40000000);
355*8ea58996SMichael Ellerman 	} else
356*8ea58996SMichael Ellerman #endif
357*8ea58996SMichael Ellerman 		ppc64_rma_size = min_t(u64, first_memblock_size, 0x40000000);
358*8ea58996SMichael Ellerman 
359*8ea58996SMichael Ellerman 	/* Finally limit subsequent allocations */
360*8ea58996SMichael Ellerman 	memblock_set_current_limit(first_memblock_base + ppc64_rma_size);
361*8ea58996SMichael Ellerman }
362