ARM: Move memory mapping into mmu.c
[pandora-kernel.git] / arch / arm / mm / mmu.c
index 761ffed..6985200 100644 (file)
@@ -14,6 +14,7 @@
 #include <linux/bootmem.h>
 #include <linux/mman.h>
 #include <linux/nodemask.h>
+#include <linux/sort.h>
 
 #include <asm/cputype.h>
 #include <asm/mach-types.h>
@@ -100,18 +101,17 @@ static struct cachepolicy cache_policies[] __initdata = {
  * writebuffer to be turned off.  (Note: the write
  * buffer should not be on and the cache off).
  */
-static void __init early_cachepolicy(char **p)
+static int __init early_cachepolicy(char *p)
 {
        int i;
 
        for (i = 0; i < ARRAY_SIZE(cache_policies); i++) {
                int len = strlen(cache_policies[i].policy);
 
-               if (memcmp(*p, cache_policies[i].policy, len) == 0) {
+               if (memcmp(p, cache_policies[i].policy, len) == 0) {
                        cachepolicy = i;
                        cr_alignment &= ~cache_policies[i].cr_mask;
                        cr_no_alignment &= ~cache_policies[i].cr_mask;
-                       *p += len;
                        break;
                }
        }
@@ -130,36 +130,37 @@ static void __init early_cachepolicy(char **p)
        }
        flush_cache_all();
        set_cr(cr_alignment);
+       return 0;
 }
-__early_param("cachepolicy=", early_cachepolicy);
+early_param("cachepolicy", early_cachepolicy);
 
-static void __init early_nocache(char **__unused)
+static int __init early_nocache(char *__unused)
 {
        char *p = "buffered";
        printk(KERN_WARNING "nocache is deprecated; use cachepolicy=%s\n", p);
-       early_cachepolicy(&p);
+       early_cachepolicy(p);
+       return 0;
 }
-__early_param("nocache", early_nocache);
+early_param("nocache", early_nocache);
 
-static void __init early_nowrite(char **__unused)
+static int __init early_nowrite(char *__unused)
 {
        char *p = "uncached";
        printk(KERN_WARNING "nowb is deprecated; use cachepolicy=%s\n", p);
-       early_cachepolicy(&p);
+       early_cachepolicy(p);
+       return 0;
 }
-__early_param("nowb", early_nowrite);
+early_param("nowb", early_nowrite);
 
-static void __init early_ecc(char **p)
+static int __init early_ecc(char *p)
 {
-       if (memcmp(*p, "on", 2) == 0) {
+       if (memcmp(p, "on", 2) == 0)
                ecc_mask = PMD_PROTECTION;
-               *p += 2;
-       } else if (memcmp(*p, "off", 3) == 0) {
+       else if (memcmp(p, "off", 3) == 0)
                ecc_mask = 0;
-               *p += 3;
-       }
+       return 0;
 }
-__early_param("ecc=", early_ecc);
+early_param("ecc", early_ecc);
 
 static int __init noalign_setup(char *__unused)
 {
@@ -599,7 +600,7 @@ static void __init create_36bit_mapping(struct map_desc *md,
  * offsets, and we take full advantage of sections and
  * supersections.
  */
-void __init create_mapping(struct map_desc *md)
+static void __init create_mapping(struct map_desc *md)
 {
        unsigned long phys, addr, length, end;
        const struct mem_type *type;
@@ -670,9 +671,9 @@ static unsigned long __initdata vmalloc_reserve = SZ_128M;
  * bytes. This can be used to increase (or decrease) the vmalloc
  * area - the default is 128m.
  */
-static void __init early_vmalloc(char **arg)
+static int __init early_vmalloc(char *arg)
 {
-       vmalloc_reserve = memparse(*arg, arg);
+       vmalloc_reserve = memparse(arg, NULL);
 
        if (vmalloc_reserve < SZ_16M) {
                vmalloc_reserve = SZ_16M;
@@ -687,8 +688,9 @@ static void __init early_vmalloc(char **arg)
                        "vmalloc area is too big, limiting to %luMB\n",
                        vmalloc_reserve >> 20);
        }
+       return 0;
 }
-__early_param("vmalloc=", early_vmalloc);
+early_param("vmalloc", early_vmalloc);
 
 #define VMALLOC_MIN    (void *)(VMALLOC_END - vmalloc_reserve)
 
@@ -1012,6 +1014,39 @@ static void __init kmap_init(void)
 #endif
 }
 
+static inline void map_memory_bank(struct membank *bank)
+{
+       struct map_desc map;
+
+       map.pfn = bank_pfn_start(bank);
+       map.virtual = __phys_to_virt(bank_phys_start(bank));
+       map.length = bank_phys_size(bank);
+       map.type = MT_MEMORY;
+
+       create_mapping(&map);
+}
+
+static void __init map_lowmem(void)
+{
+       struct meminfo *mi = &meminfo;
+       int i;
+
+       /* Map all the lowmem memory banks. */
+       for (i = 0; i < mi->nr_banks; i++) {
+               struct membank *bank = &mi->bank[i];
+
+               if (!bank->highmem)
+                       map_memory_bank(bank);
+       }
+}
+
+static int __init meminfo_cmp(const void *_a, const void *_b)
+{
+       const struct membank *a = _a, *b = _b;
+       long cmp = bank_pfn_start(a) - bank_pfn_start(b);
+       return cmp < 0 ? -1 : cmp > 0 ? 1 : 0;
+}
+
 /*
  * paging_init() sets up the page tables, initialises the zone memory
  * maps, and sets up the zero page, bad page and bad page tables.
@@ -1020,9 +1055,12 @@ void __init paging_init(struct machine_desc *mdesc)
 {
        void *zero_page;
 
+       sort(&meminfo.bank, meminfo.nr_banks, sizeof(meminfo.bank[0]), meminfo_cmp, NULL);
+
        build_mem_type_table();
        sanity_check_meminfo();
        prepare_page_table();
+       map_lowmem();
        bootmem_init();
        devicemaps_init(mdesc);
        kmap_init();