Commit f88747e7 authored by Trent Piepho's avatar Trent Piepho Committed by Kumar Gala

powerpc/fsl-booke: Remove code duplication in lowmem mapping

The code to map lowmem uses three CAM aka TLB[1] entries to cover it.  The
size of each is stored in three globals named __cam0, __cam1, and __cam2.
All the code that uses them is duplicated three times for each of the three
variables.

We have these things called arrays and loops....

Once converted to use an array, it will be easier to make the number of
CAMs configurable.
Signed-off-by: default avatarTrent Piepho <tpiepho@freescale.com>
Signed-off-by: default avatarKumar Gala <galak@kernel.crashing.org>
parent 105c31df
...@@ -56,7 +56,7 @@ ...@@ -56,7 +56,7 @@
extern void loadcam_entry(unsigned int index); extern void loadcam_entry(unsigned int index);
unsigned int tlbcam_index; unsigned int tlbcam_index;
static unsigned long __cam0, __cam1, __cam2; static unsigned long cam[3];
#define NUM_TLBCAMS (16) #define NUM_TLBCAMS (16)
...@@ -152,19 +152,19 @@ void invalidate_tlbcam_entry(int index) ...@@ -152,19 +152,19 @@ void invalidate_tlbcam_entry(int index)
loadcam_entry(index); loadcam_entry(index);
} }
void __init cam_mapin_ram(unsigned long cam0, unsigned long cam1, unsigned long __init mmu_mapin_ram(void)
unsigned long cam2)
{ {
settlbcam(0, PAGE_OFFSET, memstart_addr, cam0, _PAGE_KERNEL, 0); unsigned long virt = PAGE_OFFSET;
tlbcam_index++; phys_addr_t phys = memstart_addr;
if (cam1) {
tlbcam_index++; while (cam[tlbcam_index] && tlbcam_index < ARRAY_SIZE(cam)) {
settlbcam(1, PAGE_OFFSET+cam0, memstart_addr+cam0, cam1, _PAGE_KERNEL, 0); settlbcam(tlbcam_index, virt, phys, cam[tlbcam_index], _PAGE_KERNEL, 0);
} virt += cam[tlbcam_index];
if (cam2) { phys += cam[tlbcam_index];
tlbcam_index++; tlbcam_index++;
settlbcam(2, PAGE_OFFSET+cam0+cam1, memstart_addr+cam0+cam1, cam2, _PAGE_KERNEL, 0);
} }
return virt - PAGE_OFFSET;
} }
/* /*
...@@ -175,51 +175,34 @@ void __init MMU_init_hw(void) ...@@ -175,51 +175,34 @@ void __init MMU_init_hw(void)
flush_instruction_cache(); flush_instruction_cache();
} }
unsigned long __init mmu_mapin_ram(void)
{
cam_mapin_ram(__cam0, __cam1, __cam2);
return __cam0 + __cam1 + __cam2;
}
void __init void __init
adjust_total_lowmem(void) adjust_total_lowmem(void)
{ {
phys_addr_t max_lowmem_size = __max_low_memory;
phys_addr_t cam_max_size = 0x10000000;
phys_addr_t ram; phys_addr_t ram;
unsigned int max_cam = 28; /* 2^28 = 256 Mb */
char buf[ARRAY_SIZE(cam) * 5 + 1], *p = buf;
int i;
/* adjust CAM size to max_lowmem_size */ /* adjust lowmem size to __max_low_memory */
if (max_lowmem_size < cam_max_size) ram = min((phys_addr_t)__max_low_memory, (phys_addr_t)total_lowmem);
cam_max_size = max_lowmem_size;
/* adjust lowmem size to max_lowmem_size */
ram = min(max_lowmem_size, total_lowmem);
/* Calculate CAM values */ /* Calculate CAM values */
__cam0 = 1UL << 2 * (__ilog2(ram) / 2); __max_low_memory = 0;
if (__cam0 > cam_max_size) for (i = 0; ram && i < ARRAY_SIZE(cam); i++) {
__cam0 = cam_max_size; unsigned int camsize = __ilog2(ram) & ~1U;
ram -= __cam0; if (camsize > max_cam)
if (ram) { camsize = max_cam;
__cam1 = 1UL << 2 * (__ilog2(ram) / 2); cam[i] = 1UL << camsize;
if (__cam1 > cam_max_size) ram -= cam[i];
__cam1 = cam_max_size; __max_low_memory += cam[i];
ram -= __cam1;
} p += sprintf(p, "%lu/", cam[i] >> 20);
if (ram) {
__cam2 = 1UL << 2 * (__ilog2(ram) / 2);
if (__cam2 > cam_max_size)
__cam2 = cam_max_size;
ram -= __cam2;
} }
for (; i < ARRAY_SIZE(cam); i++)
p += sprintf(p, "0/");
p[-1] = '\0';
printk(KERN_INFO "Memory CAM mapping: CAM0=%ldMb, CAM1=%ldMb," pr_info("Memory CAM mapping: %s Mb, residual: %ldMb\n", buf,
" CAM2=%ldMb residual: %ldMb\n", (total_lowmem - __max_low_memory) >> 20);
__cam0 >> 20, __cam1 >> 20, __cam2 >> 20,
(long int)((total_lowmem - __cam0 - __cam1 - __cam2)
>> 20));
__max_low_memory = __cam0 + __cam1 + __cam2;
__initial_memory_limit_addr = memstart_addr + __max_low_memory; __initial_memory_limit_addr = memstart_addr + __max_low_memory;
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment