powerpc/mm: Tweak PTE bit combination definitions
[deliverable/linux.git] / arch / powerpc / mm / fsl_booke_mmu.c
index 1dabe1a1751b12e347f38c7005fcf95c946d3749..bb3d65998e6b514028d8c3af7b6c9c036047ba0d 100644 (file)
 
 extern void loadcam_entry(unsigned int index);
 unsigned int tlbcam_index;
-static unsigned long cam[3];
+static unsigned long cam[CONFIG_LOWMEM_CAM_NUM];
 
 #define NUM_TLBCAMS    (16)
 
+#if defined(CONFIG_LOWMEM_CAM_NUM_BOOL) && (CONFIG_LOWMEM_CAM_NUM >= NUM_TLBCAMS)
+#error "LOWMEM_CAM_NUM must be less than NUM_TLBCAMS"
+#endif
+
 struct tlbcam TLBCAM[NUM_TLBCAMS];
 
 struct tlbcamrange {
@@ -73,7 +77,7 @@ extern unsigned int tlbcam_index;
 /*
  * Return PA for this VA if it is mapped by a CAM, or 0
  */
-unsigned long v_mapped_by_tlbcam(unsigned long va)
+phys_addr_t v_mapped_by_tlbcam(unsigned long va)
 {
        int b;
        for (b = 0; b < tlbcam_index; ++b)
@@ -85,7 +89,7 @@ unsigned long v_mapped_by_tlbcam(unsigned long va)
 /*
  * Return VA for a given PA or 0 if not mapped
  */
-unsigned long p_mapped_by_tlbcam(unsigned long pa)
+unsigned long p_mapped_by_tlbcam(phys_addr_t pa)
 {
        int b;
        for (b = 0; b < tlbcam_index; ++b)
@@ -107,7 +111,7 @@ void settlbcam(int index, unsigned long virt, phys_addr_t phys,
        unsigned int tsize, lz;
 
        asm ("cntlzw %0,%1" : "=r" (lz) : "r" (size));
-       tsize = (21 - lz) / 2;
+       tsize = 21 - lz;
 
 #ifdef CONFIG_SMP
        if ((flags & _PAGE_NO_CACHE) == 0)
@@ -158,7 +162,7 @@ unsigned long __init mmu_mapin_ram(void)
        phys_addr_t phys = memstart_addr;
 
        while (cam[tlbcam_index] && tlbcam_index < ARRAY_SIZE(cam)) {
-               settlbcam(tlbcam_index, virt, phys, cam[tlbcam_index], _PAGE_KERNEL, 0);
+               settlbcam(tlbcam_index, virt, phys, cam[tlbcam_index], PAGE_KERNEL_X, 0);
                virt += cam[tlbcam_index];
                phys += cam[tlbcam_index];
                tlbcam_index++;
@@ -179,9 +183,14 @@ void __init
 adjust_total_lowmem(void)
 {
        phys_addr_t ram;
-       unsigned int max_cam = 28;      /* 2^28 = 256 Mb */
+       unsigned int max_cam = (mfspr(SPRN_TLB1CFG) >> 16) & 0xff;
        char buf[ARRAY_SIZE(cam) * 5 + 1], *p = buf;
        int i;
+       unsigned long virt = PAGE_OFFSET & 0xffffffffUL;
+       unsigned long phys = memstart_addr & 0xffffffffUL;
+
+       /* Convert (4^max) kB to (2^max) bytes */
+       max_cam = max_cam * 2 + 10;
 
        /* adjust lowmem size to __max_low_memory */
        ram = min((phys_addr_t)__max_low_memory, (phys_addr_t)total_lowmem);
@@ -190,11 +199,18 @@ adjust_total_lowmem(void)
        __max_low_memory = 0;
        for (i = 0; ram && i < ARRAY_SIZE(cam); i++) {
                unsigned int camsize = __ilog2(ram) & ~1U;
+               unsigned int align = __ffs(virt | phys) & ~1U;
+
+               if (camsize > align)
+                       camsize = align;
                if (camsize > max_cam)
                        camsize = max_cam;
+
                cam[i] = 1UL << camsize;
                ram -= cam[i];
                __max_low_memory += cam[i];
+               virt += cam[i];
+               phys += cam[i];
 
                p += sprintf(p, "%lu/", cam[i] >> 20);
        }
@@ -202,7 +218,7 @@ adjust_total_lowmem(void)
                p += sprintf(p, "0/");
        p[-1] = '\0';
 
-       pr_info("Memory CAM mapping: %s Mb, residual: %ldMb\n", buf,
-               (total_lowmem - __max_low_memory) >> 20);
+       pr_info("Memory CAM mapping: %s Mb, residual: %dMb\n", buf,
+               (unsigned int)((total_lowmem - __max_low_memory) >> 20));
        __initial_memory_limit_addr = memstart_addr + __max_low_memory;
 }
This page took 0.029575 seconds and 5 git commands to generate.