powerpc/fsl-booke: Fix setup_initial_memory_limit to not blindly map
On FSL Book-E devices we support multiple large TLB sizes and so we can get into situations in which the initial 1G TLB size is too big and we're asked for a size that is not mappable by a single entry (like 512M). The single entry is important because when we bring up secondary cores they need to ensure any data structure they need to access (eg PACA or stack) is always mapped. So we really need to determine what size will actually be mapped by the first TLB entry to ensure we limit early memory references to that region. We refactor the map_mem_in_cams() code to provider a helper function that we can utilize to determine the size of the first TLB entry while taking into account size and alignment constraints. Signed-off-by: Kumar Gala <galak@kernel.crashing.org>
This commit is contained in:
parent
ba14f64917
commit
1dc91c3eb3
|
@ -146,29 +146,36 @@ static void settlbcam(int index, unsigned long virt, phys_addr_t phys,
|
||||||
loadcam_entry(index);
|
loadcam_entry(index);
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned long map_mem_in_cams(unsigned long ram, int max_cam_idx)
|
unsigned long calc_cam_sz(unsigned long ram, unsigned long virt,
|
||||||
|
phys_addr_t phys)
|
||||||
{
|
{
|
||||||
int i;
|
unsigned int camsize = __ilog2(ram) & ~1U;
|
||||||
unsigned long virt = PAGE_OFFSET;
|
unsigned int align = __ffs(virt | phys) & ~1U;
|
||||||
phys_addr_t phys = memstart_addr;
|
|
||||||
unsigned long amount_mapped = 0;
|
|
||||||
unsigned long max_cam = (mfspr(SPRN_TLB1CFG) >> 16) & 0xf;
|
unsigned long max_cam = (mfspr(SPRN_TLB1CFG) >> 16) & 0xf;
|
||||||
|
|
||||||
/* Convert (4^max) kB to (2^max) bytes */
|
/* Convert (4^max) kB to (2^max) bytes */
|
||||||
max_cam = max_cam * 2 + 10;
|
max_cam = max_cam * 2 + 10;
|
||||||
|
|
||||||
/* Calculate CAM values */
|
|
||||||
for (i = 0; ram && i < max_cam_idx; i++) {
|
|
||||||
unsigned int camsize = __ilog2(ram) & ~1U;
|
|
||||||
unsigned int align = __ffs(virt | phys) & ~1U;
|
|
||||||
unsigned long cam_sz;
|
|
||||||
|
|
||||||
if (camsize > align)
|
if (camsize > align)
|
||||||
camsize = align;
|
camsize = align;
|
||||||
if (camsize > max_cam)
|
if (camsize > max_cam)
|
||||||
camsize = max_cam;
|
camsize = max_cam;
|
||||||
|
|
||||||
cam_sz = 1UL << camsize;
|
return 1UL << camsize;
|
||||||
|
}
|
||||||
|
|
||||||
|
unsigned long map_mem_in_cams(unsigned long ram, int max_cam_idx)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
unsigned long virt = PAGE_OFFSET;
|
||||||
|
phys_addr_t phys = memstart_addr;
|
||||||
|
unsigned long amount_mapped = 0;
|
||||||
|
|
||||||
|
/* Calculate CAM values */
|
||||||
|
for (i = 0; ram && i < max_cam_idx; i++) {
|
||||||
|
unsigned long cam_sz;
|
||||||
|
|
||||||
|
cam_sz = calc_cam_sz(ram, virt, phys);
|
||||||
settlbcam(i, virt, phys, cam_sz, PAGE_KERNEL_X, 0);
|
settlbcam(i, virt, phys, cam_sz, PAGE_KERNEL_X, 0);
|
||||||
|
|
||||||
ram -= cam_sz;
|
ram -= cam_sz;
|
||||||
|
|
|
@ -142,6 +142,8 @@ extern unsigned long mmu_mapin_ram(unsigned long top);
|
||||||
|
|
||||||
#elif defined(CONFIG_PPC_FSL_BOOK3E)
|
#elif defined(CONFIG_PPC_FSL_BOOK3E)
|
||||||
extern unsigned long map_mem_in_cams(unsigned long ram, int max_cam_idx);
|
extern unsigned long map_mem_in_cams(unsigned long ram, int max_cam_idx);
|
||||||
|
extern unsigned long calc_cam_sz(unsigned long ram, unsigned long virt,
|
||||||
|
phys_addr_t phys);
|
||||||
#ifdef CONFIG_PPC32
|
#ifdef CONFIG_PPC32
|
||||||
extern void MMU_init_hw(void);
|
extern void MMU_init_hw(void);
|
||||||
extern unsigned long mmu_mapin_ram(unsigned long top);
|
extern unsigned long mmu_mapin_ram(unsigned long top);
|
||||||
|
|
|
@ -642,12 +642,27 @@ void __cpuinit early_init_mmu_secondary(void)
|
||||||
void setup_initial_memory_limit(phys_addr_t first_memblock_base,
|
void setup_initial_memory_limit(phys_addr_t first_memblock_base,
|
||||||
phys_addr_t first_memblock_size)
|
phys_addr_t first_memblock_size)
|
||||||
{
|
{
|
||||||
/* On Embedded 64-bit, we adjust the RMA size to match
|
/* On non-FSL Embedded 64-bit, we adjust the RMA size to match
|
||||||
* the bolted TLB entry. We know for now that only 1G
|
* the bolted TLB entry. We know for now that only 1G
|
||||||
* entries are supported though that may eventually
|
* entries are supported though that may eventually
|
||||||
* change. We crop it to the size of the first MEMBLOCK to
|
* change.
|
||||||
|
*
|
||||||
|
* on FSL Embedded 64-bit, we adjust the RMA size to match the
|
||||||
|
* first bolted TLB entry size. We still limit max to 1G even if
|
||||||
|
* the TLB could cover more. This is due to what the early init
|
||||||
|
* code is setup to do.
|
||||||
|
*
|
||||||
|
* We crop it to the size of the first MEMBLOCK to
|
||||||
* avoid going over total available memory just in case...
|
* avoid going over total available memory just in case...
|
||||||
*/
|
*/
|
||||||
|
#ifdef CONFIG_PPC_FSL_BOOK3E
|
||||||
|
if (mmu_has_feature(MMU_FTR_TYPE_FSL_E)) {
|
||||||
|
unsigned long linear_sz;
|
||||||
|
linear_sz = calc_cam_sz(first_memblock_size, PAGE_OFFSET,
|
||||||
|
first_memblock_base);
|
||||||
|
ppc64_rma_size = min_t(u64, linear_sz, 0x40000000);
|
||||||
|
} else
|
||||||
|
#endif
|
||||||
ppc64_rma_size = min_t(u64, first_memblock_size, 0x40000000);
|
ppc64_rma_size = min_t(u64, first_memblock_size, 0x40000000);
|
||||||
|
|
||||||
/* Finally limit subsequent allocations */
|
/* Finally limit subsequent allocations */
|
||||||
|
|
Loading…
Reference in New Issue