Merge to Fedora kernel-2.6.18-1.2224_FC5 patched with stable patch-2.6.18.1-vs2.0...
[linux-2.6.git] / arch / mips / mips-boards / generic / memory.c
index 56cf37a..be80c5d 100644 (file)
  * PROM library functions for acquiring/using memory descriptors given to
  * us from the YAMON.
  */
-#include <linux/config.h>
 #include <linux/init.h>
 #include <linux/mm.h>
 #include <linux/bootmem.h>
+#include <linux/pfn.h>
+#include <linux/string.h>
 
 #include <asm/bootinfo.h>
 #include <asm/page.h>
+#include <asm/sections.h>
 
 #include <asm/mips-boards/prom.h>
 
@@ -45,28 +47,45 @@ static char *mtypes[3] = {
 };
 #endif
 
-/* References to section boundaries */
-extern char _end;
-
-#define PFN_ALIGN(x)    (((unsigned long)(x) + (PAGE_SIZE - 1)) & PAGE_MASK)
-
+/* determined physical memory size, not overridden by command line args  */
+unsigned long physical_memsize = 0L;
 
 struct prom_pmemblock * __init prom_getmdesc(void)
 {
        char *memsize_str;
        unsigned int memsize;
+       char cmdline[CL_SIZE], *ptr;
 
+       /* otherwise look in the environment */
        memsize_str = prom_getenv("memsize");
        if (!memsize_str) {
                prom_printf("memsize not set in boot prom, set to default (32Mb)\n");
-               memsize = 0x02000000;
+               physical_memsize = 0x02000000;
        } else {
 #ifdef DEBUG
                prom_printf("prom_memsize = %s\n", memsize_str);
 #endif
-               memsize = simple_strtol(memsize_str, NULL, 0);
+               physical_memsize = simple_strtol(memsize_str, NULL, 0);
        }
 
+#ifdef CONFIG_CPU_BIG_ENDIAN
+       /* SOC-it swaps, or perhaps doesn't swap, when DMA'ing the last
+          word of physical memory */
+       physical_memsize -= PAGE_SIZE;
+#endif
+
+       /* Check the command line for a memsize directive that overrides
+          the physical/default amount */
+       strcpy(cmdline, arcs_cmdline);
+       ptr = strstr(cmdline, "memsize=");
+       if (ptr && (ptr != cmdline) && (*(ptr - 1) != ' '))
+               ptr = strstr(ptr, " memsize=");
+
+       if (ptr)
+               memsize = memparse(ptr + 8, &ptr);
+       else
+               memsize = physical_memsize;
+
        memset(mdesc, 0, sizeof(mdesc));
 
        mdesc[0].type = yamon_dontuse;
@@ -77,7 +96,7 @@ struct prom_pmemblock * __init prom_getmdesc(void)
        mdesc[1].base = 0x00001000;
        mdesc[1].size = 0x000ef000;
 
-#if (CONFIG_MIPS_MALTA)
+#ifdef CONFIG_MIPS_MALTA
        /*
         * The area 0x000f0000-0x000fffff is allocated for BIOS memory by the
         * south bridge and PCI access always forwarded to the ISA Bus and
@@ -96,7 +115,7 @@ struct prom_pmemblock * __init prom_getmdesc(void)
 
        mdesc[3].type = yamon_dontuse;
        mdesc[3].base = 0x00100000;
-       mdesc[3].size = CPHYSADDR(PFN_ALIGN(&_end)) - mdesc[3].base;
+       mdesc[3].size = CPHYSADDR(PFN_ALIGN((unsigned long)&_end)) - mdesc[3].base;
 
        mdesc[4].type = yamon_free;
        mdesc[4].base = CPHYSADDR(PFN_ALIGN(&_end));
@@ -161,7 +180,7 @@ unsigned long __init prom_free_prom_memory(void)
                while (addr < boot_mem_map.map[i].addr
                              + boot_mem_map.map[i].size) {
                        ClearPageReserved(virt_to_page(__va(addr)));
-                       set_page_count(virt_to_page(__va(addr)), 1);
+                       init_page_count(virt_to_page(__va(addr)));
                        free_page((unsigned long)__va(addr));
                        addr += PAGE_SIZE;
                        freed += PAGE_SIZE;