]> pilppa.org Git - linux-2.6-omap-h63xx.git/blobdiff - arch/mips/kernel/setup.c
[MIPS] setup.c: remove MAXMEM macro
[linux-2.6-omap-h63xx.git] / arch / mips / kernel / setup.c
index 8c2b596a136f95376c45386b3fba0703d32f4991..804b93dc3c5ae9c05c4905b962a9da998c5c1f7b 100644 (file)
  * Copyright (C) 1999 Silicon Graphics, Inc.
  * Copyright (C) 2000 2001, 2002  Maciej W. Rozycki
  */
-#include <linux/errno.h>
 #include <linux/init.h>
 #include <linux/ioport.h>
-#include <linux/sched.h>
-#include <linux/kernel.h>
-#include <linux/mm.h>
 #include <linux/module.h>
-#include <linux/stddef.h>
-#include <linux/string.h>
-#include <linux/unistd.h>
-#include <linux/slab.h>
-#include <linux/user.h>
-#include <linux/utsname.h>
-#include <linux/a.out.h>
 #include <linux/screen_info.h>
 #include <linux/bootmem.h>
 #include <linux/initrd.h>
-#include <linux/major.h>
-#include <linux/kdev_t.h>
 #include <linux/root_dev.h>
 #include <linux/highmem.h>
 #include <linux/console.h>
-#include <linux/mmzone.h>
 #include <linux/pfn.h>
 
 #include <asm/addrspace.h>
@@ -96,6 +82,12 @@ void __init add_memory_region(phys_t start, phys_t size, long type)
        int x = boot_mem_map.nr_map;
        struct boot_mem_map_entry *prev = boot_mem_map.map + x - 1;
 
+       /* Sanity check */
+       if (start + size < start) {
+               printk("Trying to add an invalid memory region, skipped\n");
+               return;
+       }
+
        /*
         * Try to merge with previous entry if any.  This is far less than
         * perfect but is sufficient for most real world cases.
@@ -143,7 +135,7 @@ static void __init print_memory_map(void)
        }
 }
 
-static inline void parse_cmdline_early(void)
+static void __init parse_cmdline_early(void)
 {
        char c = ' ', *to = command_line, *from = saved_command_line;
        unsigned long start_at, mem_size;
@@ -194,7 +186,12 @@ static inline void parse_cmdline_early(void)
        }
 }
 
-static inline int parse_rd_cmdline(unsigned long* rd_start, unsigned long* rd_end)
+/*
+ * Manage initrd
+ */
+#ifdef CONFIG_BLK_DEV_INITRD
+
+static int __init parse_rd_cmdline(unsigned long *rd_start, unsigned long *rd_end)
 {
        /*
         * "rd_start=0xNNNNNNNN" defines the memory address of an initrd
@@ -257,53 +254,97 @@ static inline int parse_rd_cmdline(unsigned long* rd_start, unsigned long* rd_en
        return 0;
 }
 
-#define MAXMEM         HIGHMEM_START
-#define MAXMEM_PFN     PFN_DOWN(MAXMEM)
+static unsigned long __init init_initrd(void)
+{
+       unsigned long tmp, end;
+       u32 *initrd_header;
+
+       ROOT_DEV = Root_RAM0;
 
-static inline void bootmem_init(void)
+       if (parse_rd_cmdline(&initrd_start, &initrd_end))
+               return initrd_end;
+       /*
+        * Board specific code should have set up initrd_start
+        * and initrd_end...
+        */
+       end = (unsigned long)&_end;
+       tmp = PAGE_ALIGN(end) - sizeof(u32) * 2;
+       if (tmp < end)
+               tmp += PAGE_SIZE;
+
+       initrd_header = (u32 *)tmp;
+       if (initrd_header[0] == 0x494E5244) {
+               initrd_start = (unsigned long)&initrd_header[2];
+               initrd_end = initrd_start + initrd_header[1];
+       }
+       return initrd_end;
+}
+
+static void __init finalize_initrd(void)
 {
-       unsigned long start_pfn;
-       unsigned long reserved_end = (unsigned long)&_end;
-#ifndef CONFIG_SGI_IP27
-       unsigned long first_usable_pfn;
+       unsigned long size = initrd_end - initrd_start;
+
+       if (size == 0) {
+               printk(KERN_INFO "Initrd not found or empty");
+               goto disable;
+       }
+       if (CPHYSADDR(initrd_end) > PFN_PHYS(max_low_pfn)) {
+               printk("Initrd extends beyond end of memory");
+               goto disable;
+       }
+
+       reserve_bootmem(CPHYSADDR(initrd_start), size);
+       initrd_below_start_ok = 1;
+
+       printk(KERN_INFO "Initial ramdisk at: 0x%lx (%lu bytes)\n",
+              initrd_start, size);
+       return;
+disable:
+       printk(" - disabling initrd\n");
+       initrd_start = 0;
+       initrd_end = 0;
+}
+
+#else  /* !CONFIG_BLK_DEV_INITRD */
+
+#define init_initrd()          0
+#define finalize_initrd()      do {} while (0)
+
+#endif
+
+/*
+ * Initialize the bootmem allocator. It also setup initrd related data
+ * if needed.
+ */
+#ifdef CONFIG_SGI_IP27
+
+static void __init bootmem_init(void)
+{
+       init_initrd();
+       finalize_initrd();
+}
+
+#else  /* !CONFIG_SGI_IP27 */
+
+static void __init bootmem_init(void)
+{
+       unsigned long reserved_end;
+       unsigned long highest = 0;
+       unsigned long mapstart = -1UL;
        unsigned long bootmap_size;
        int i;
-#endif
-#ifdef CONFIG_BLK_DEV_INITRD
-       int initrd_reserve_bootmem = 0;
-
-       /* Board specific code should have set up initrd_start and initrd_end */
-       ROOT_DEV = Root_RAM0;
-       if (parse_rd_cmdline(&initrd_start, &initrd_end)) {
-               reserved_end = max(reserved_end, initrd_end);
-               initrd_reserve_bootmem = 1;
-       } else {
-               unsigned long tmp;
-               u32 *initrd_header;
-
-               tmp = ((reserved_end + PAGE_SIZE-1) & PAGE_MASK) - sizeof(u32) * 2;
-               if (tmp < reserved_end)
-                       tmp += PAGE_SIZE;
-               initrd_header = (u32 *)tmp;
-               if (initrd_header[0] == 0x494E5244) {
-                       initrd_start = (unsigned long)&initrd_header[2];
-                       initrd_end = initrd_start + initrd_header[1];
-                       reserved_end = max(reserved_end, initrd_end);
-                       initrd_reserve_bootmem = 1;
-               }
-       }
-#endif /* CONFIG_BLK_DEV_INITRD */
 
        /*
-        * Partially used pages are not usable - thus
-        * we are rounding upwards.
+        * Init any data related to initrd. It's a nop if INITRD is
+        * not selected. Once that done we can determine the low bound
+        * of usable memory.
         */
-       start_pfn = PFN_UP(CPHYSADDR(reserved_end));
+       reserved_end = init_initrd();
+       reserved_end = PFN_UP(CPHYSADDR(max(reserved_end, (unsigned long)&_end)));
 
-#ifndef CONFIG_SGI_IP27
-       /* Find the highest page frame number we have available.  */
-       max_pfn = 0;
-       first_usable_pfn = -1UL;
+       /*
+        * Find the highest page frame number we have available.
+        */
        for (i = 0; i < boot_mem_map.nr_map; i++) {
                unsigned long start, end;
 
@@ -312,56 +353,38 @@ static inline void bootmem_init(void)
 
                start = PFN_UP(boot_mem_map.map[i].addr);
                end = PFN_DOWN(boot_mem_map.map[i].addr
-                     + boot_mem_map.map[i].size);
+                               + boot_mem_map.map[i].size);
 
-               if (start >= end)
+               if (end > highest)
+                       highest = end;
+               if (end <= reserved_end)
                        continue;
-               if (end > max_pfn)
-                       max_pfn = end;
-               if (start < first_usable_pfn) {
-                       if (start > start_pfn) {
-                               first_usable_pfn = start;
-                       } else if (end > start_pfn) {
-                               first_usable_pfn = start_pfn;
-                       }
-               }
+               if (start >= mapstart)
+                       continue;
+               mapstart = max(reserved_end, start);
        }
 
        /*
         * Determine low and high memory ranges
         */
-       max_low_pfn = max_pfn;
-       if (max_low_pfn > MAXMEM_PFN) {
-               max_low_pfn = MAXMEM_PFN;
-#ifndef CONFIG_HIGHMEM
-               /* Maximum memory usable is what is directly addressable */
-               printk(KERN_WARNING "Warning only %ldMB will be used.\n",
-                      MAXMEM >> 20);
-               printk(KERN_WARNING "Use a HIGHMEM enabled kernel.\n");
+       if (highest > PFN_DOWN(HIGHMEM_START)) {
+#ifdef CONFIG_HIGHMEM
+               highstart_pfn = PFN_DOWN(HIGHMEM_START);
+               highend_pfn = highest;
 #endif
+               highest = PFN_DOWN(HIGHMEM_START);
        }
 
-#ifdef CONFIG_HIGHMEM
        /*
-        * Crude, we really should make a better attempt at detecting
-        * highstart_pfn
+        * Initialize the boot-time allocator with low memory only.
         */
-       highstart_pfn = highend_pfn = max_pfn;
-       if (max_pfn > MAXMEM_PFN) {
-               highstart_pfn = MAXMEM_PFN;
-               printk(KERN_NOTICE "%ldMB HIGHMEM available.\n",
-                      (highend_pfn - highstart_pfn) >> (20 - PAGE_SHIFT));
-       }
-#endif
-
-       /* Initialize the boot-time allocator with low memory only.  */
-       bootmap_size = init_bootmem(first_usable_pfn, max_low_pfn);
+       bootmap_size = init_bootmem(mapstart, highest);
 
        /*
         * Register fully available low RAM pages with the bootmem allocator.
         */
        for (i = 0; i < boot_mem_map.nr_map; i++) {
-               unsigned long curr_pfn, last_pfn, size;
+               unsigned long start, end, size;
 
                /*
                 * Reserve usable memory.
@@ -369,78 +392,45 @@ static inline void bootmem_init(void)
                if (boot_mem_map.map[i].type != BOOT_MEM_RAM)
                        continue;
 
-               /*
-                * We are rounding up the start address of usable memory:
-                */
-               curr_pfn = PFN_UP(boot_mem_map.map[i].addr);
-               if (curr_pfn >= max_low_pfn)
-                       continue;
-               if (curr_pfn < start_pfn)
-                       curr_pfn = start_pfn;
-
-               /*
-                * ... and at the end of the usable range downwards:
-                */
-               last_pfn = PFN_DOWN(boot_mem_map.map[i].addr
+               start = PFN_UP(boot_mem_map.map[i].addr);
+               end   = PFN_DOWN(boot_mem_map.map[i].addr
                                    + boot_mem_map.map[i].size);
-
-               if (last_pfn > max_low_pfn)
-                       last_pfn = max_low_pfn;
-
                /*
-                * Only register lowmem part of lowmem segment with bootmem.
+                * We are rounding up the start address of usable memory
+                * and at the end of the usable range downwards.
                 */
-               size = last_pfn - curr_pfn;
-               if (curr_pfn > PFN_DOWN(HIGHMEM_START))
-                       continue;
-               if (curr_pfn + size - 1 > PFN_DOWN(HIGHMEM_START))
-                       size = PFN_DOWN(HIGHMEM_START) - curr_pfn;
-               if (!size)
+               if (start >= max_low_pfn)
                        continue;
+               if (start < reserved_end)
+                       start = reserved_end;
+               if (end > max_low_pfn)
+                       end = max_low_pfn;
 
                /*
-                * ... finally, did all the rounding and playing
-                * around just make the area go away?
+                * ... finally, is the area going away?
                 */
-               if (last_pfn <= curr_pfn)
+               if (end <= start)
                        continue;
+               size = end - start;
 
                /* Register lowmem ranges */
-               free_bootmem(PFN_PHYS(curr_pfn), PFN_PHYS(size));
-               memory_present(0, curr_pfn, curr_pfn + size - 1);
+               free_bootmem(PFN_PHYS(start), size << PAGE_SHIFT);
+               memory_present(0, start, end);
        }
 
-       /* Reserve the bootmap memory.  */
-       reserve_bootmem(PFN_PHYS(first_usable_pfn), bootmap_size);
-#endif /* CONFIG_SGI_IP27 */
-
-#ifdef CONFIG_BLK_DEV_INITRD
-       initrd_below_start_ok = 1;
-       if (initrd_start) {
-               unsigned long initrd_size = ((unsigned char *)initrd_end) -
-                       ((unsigned char *)initrd_start);
-               const int width = sizeof(long) * 2;
-
-               printk("Initial ramdisk at: 0x%p (%lu bytes)\n",
-                      (void *)initrd_start, initrd_size);
-
-               if (CPHYSADDR(initrd_end) > PFN_PHYS(max_low_pfn)) {
-                       printk("initrd extends beyond end of memory "
-                              "(0x%0*Lx > 0x%0*Lx)\ndisabling initrd\n",
-                              width,
-                              (unsigned long long) CPHYSADDR(initrd_end),
-                              width,
-                              (unsigned long long) PFN_PHYS(max_low_pfn));
-                       initrd_start = initrd_end = 0;
-                       initrd_reserve_bootmem = 0;
-               }
+       /*
+        * Reserve the bootmap memory.
+        */
+       reserve_bootmem(PFN_PHYS(mapstart), bootmap_size);
 
-               if (initrd_reserve_bootmem)
-                       reserve_bootmem(CPHYSADDR(initrd_start), initrd_size);
-       }
-#endif /* CONFIG_BLK_DEV_INITRD  */
+       /*
+        * Reserve initrd memory if needed.
+        */
+       finalize_initrd();
 }
 
+#endif /* CONFIG_SGI_IP27 */
+
 /*
  * arch_mem_init - initialize memory managment subsystem
  *
@@ -483,7 +473,7 @@ static void __init arch_mem_init(char **cmdline_p)
        paging_init();
 }
 
-static inline void resource_init(void)
+static void __init resource_init(void)
 {
        int i;
 
@@ -504,10 +494,10 @@ static inline void resource_init(void)
 
                start = boot_mem_map.map[i].addr;
                end = boot_mem_map.map[i].addr + boot_mem_map.map[i].size - 1;
-               if (start >= MAXMEM)
+               if (start >= HIGHMEM_START)
                        continue;
-               if (end >= MAXMEM)
-                       end = MAXMEM - 1;
+               if (end >= HIGHMEM_START)
+                       end = HIGHMEM_START - 1;
 
                res = alloc_bootmem(sizeof(struct resource));
                switch (boot_mem_map.map[i].type) {
@@ -536,9 +526,6 @@ static inline void resource_init(void)
        }
 }
 
-#undef MAXMEM
-#undef MAXMEM_PFN
-
 void __init setup_arch(char **cmdline_p)
 {
        cpu_probe();