Merge branch 'linus' into cont_syslog
[safe/jmp/linux-2.6] / arch / mips / kernel / setup.c
index b52cc97..85aef3f 100644 (file)
@@ -8,7 +8,7 @@
  * Copyright (C) 1994, 95, 96, 97, 98, 99, 2000, 01, 02, 03  Ralf Baechle
  * Copyright (C) 1996 Stoned Elipot
  * Copyright (C) 1999 Silicon Graphics, Inc.
- * Copyright (C) 2000 2001, 2002  Maciej W. Rozycki
+ * Copyright (C) 2000, 2001, 2002, 2007  Maciej W. Rozycki
  */
 #include <linux/init.h>
 #include <linux/ioport.h>
 #include <linux/highmem.h>
 #include <linux/console.h>
 #include <linux/pfn.h>
+#include <linux/debugfs.h>
 
 #include <asm/addrspace.h>
 #include <asm/bootinfo.h>
+#include <asm/bugs.h>
 #include <asm/cache.h>
 #include <asm/cpu.h>
 #include <asm/sections.h>
 #include <asm/setup.h>
+#include <asm/smp-ops.h>
 #include <asm/system.h>
 
 struct cpuinfo_mips cpu_data[NR_CPUS] __read_mostly;
@@ -50,15 +53,17 @@ EXPORT_SYMBOL(PCI_DMA_BUS_IS_PHYS);
  * These are initialized so they are in the .data section
  */
 unsigned long mips_machtype __read_mostly = MACH_UNKNOWN;
-unsigned long mips_machgroup __read_mostly = MACH_GROUP_UNKNOWN;
 
 EXPORT_SYMBOL(mips_machtype);
-EXPORT_SYMBOL(mips_machgroup);
 
 struct boot_mem_map boot_mem_map;
 
-static char command_line[CL_SIZE];
-       char arcs_cmdline[CL_SIZE]=CONFIG_CMDLINE;
+static char __initdata command_line[COMMAND_LINE_SIZE];
+char __initdata arcs_cmdline[COMMAND_LINE_SIZE];
+
+#ifdef CONFIG_CMDLINE_BOOL
+static char __initdata builtin_cmdline[COMMAND_LINE_SIZE] = CONFIG_CMDLINE;
+#endif
 
 /*
  * mips_io_port_base is the begin of the address space to which x86 style
@@ -67,13 +72,6 @@ static char command_line[CL_SIZE];
 const unsigned long mips_io_port_base __read_mostly = -1;
 EXPORT_SYMBOL(mips_io_port_base);
 
-/*
- * isa_slot_offset is the address where E(ISA) busaddress 0 is mapped
- * for the processor.
- */
-unsigned long isa_slot_offset;
-EXPORT_SYMBOL(isa_slot_offset);
-
 static struct resource code_resource = { .name = "Kernel code", };
 static struct resource data_resource = { .name = "Kernel data", };
 
@@ -84,7 +82,7 @@ void __init add_memory_region(phys_t start, phys_t size, long type)
 
        /* Sanity check */
        if (start + size < start) {
-               printk("Trying to add an invalid memory region, skipped\n");
+               pr_warning("Trying to add an invalid memory region, skipped\n");
                return;
        }
 
@@ -98,7 +96,7 @@ void __init add_memory_region(phys_t start, phys_t size, long type)
        }
 
        if (x == BOOT_MEM_MAP_MAX) {
-               printk("Ooops! Too many entries in the memory map!\n");
+               pr_err("Ooops! Too many entries in the memory map!\n");
                return;
        }
 
@@ -114,22 +112,22 @@ static void __init print_memory_map(void)
        const int field = 2 * sizeof(unsigned long);
 
        for (i = 0; i < boot_mem_map.nr_map; i++) {
-               printk(" memory: %0*Lx @ %0*Lx ",
+               printk(KERN_INFO " memory: %0*Lx @ %0*Lx ",
                       field, (unsigned long long) boot_mem_map.map[i].size,
                       field, (unsigned long long) boot_mem_map.map[i].addr);
 
                switch (boot_mem_map.map[i].type) {
                case BOOT_MEM_RAM:
-                       printk("(usable)\n");
+                       printk(KERN_CONT "(usable)\n");
                        break;
                case BOOT_MEM_ROM_DATA:
-                       printk("(ROM data)\n");
+                       printk(KERN_CONT "(ROM data)\n");
                        break;
                case BOOT_MEM_RESERVED:
-                       printk("(reserved)\n");
+                       printk(KERN_CONT "(reserved)\n");
                        break;
                default:
-                       printk("type %lu\n", boot_mem_map.map[i].type);
+                       printk(KERN_CONT "type %lu\n", boot_mem_map.map[i].type);
                        break;
                }
        }
@@ -145,13 +143,12 @@ static int __init rd_start_early(char *p)
        unsigned long start = memparse(p, &p);
 
 #ifdef CONFIG_64BIT
-       /* HACK: Guess if the sign extension was forgotten */
-       if (start > 0x0000000080000000 && start < 0x00000000ffffffff)
-               start |= 0xffffffff00000000UL;
+       /* Guess if the sign extension was forgotten by bootloader */
+       if (start < XKPHYS)
+               start = (int)start;
 #endif
        initrd_start = start;
        initrd_end += start;
-
        return 0;
 }
 early_param("rd_start", rd_start_early);
@@ -159,41 +156,49 @@ early_param("rd_start", rd_start_early);
 static int __init rd_size_early(char *p)
 {
        initrd_end += memparse(p, &p);
-
        return 0;
 }
 early_param("rd_size", rd_size_early);
 
+/* it returns the next free pfn after initrd */
 static unsigned long __init init_initrd(void)
 {
-       unsigned long tmp, end, size;
-       u32 *initrd_header;
-
-       ROOT_DEV = Root_RAM0;
+       unsigned long end;
 
        /*
         * Board specific code or command line parser should have
         * already set up initrd_start and initrd_end. In these cases
         * perfom sanity checks and use them if all looks good.
         */
-       size = initrd_end - initrd_start;
-       if (initrd_end == 0 || size == 0) {
-               initrd_start = 0;
-               initrd_end = 0;
-       } else
-               return 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];
+       if (!initrd_start || initrd_end <= initrd_start)
+               goto disable;
+
+       if (initrd_start & ~PAGE_MASK) {
+               pr_err("initrd start must be page aligned\n");
+               goto disable;
+       }
+       if (initrd_start < PAGE_OFFSET) {
+               pr_err("initrd start < PAGE_OFFSET\n");
+               goto disable;
        }
-       return initrd_end;
+
+       /*
+        * Sanitize initrd addresses. For example firmware
+        * can't guess if they need to pass them through
+        * 64-bits values if the kernel has been built in pure
+        * 32-bit. We need also to switch from KSEG0 to XKPHYS
+        * addresses now, so the code can now safely use __pa().
+        */
+       end = __pa(initrd_end);
+       initrd_end = (unsigned long)__va(end);
+       initrd_start = (unsigned long)__va(__pa(initrd_start));
+
+       ROOT_DEV = Root_RAM0;
+       return PFN_UP(end);
+disable:
+       initrd_start = 0;
+       initrd_end = 0;
+       return 0;
 }
 
 static void __init finalize_initrd(void)
@@ -205,18 +210,18 @@ static void __init finalize_initrd(void)
                goto disable;
        }
        if (__pa(initrd_end) > PFN_PHYS(max_low_pfn)) {
-               printk("Initrd extends beyond end of memory");
+               printk(KERN_ERR "Initrd extends beyond end of memory");
                goto disable;
        }
 
-       reserve_bootmem(__pa(initrd_start), size);
+       reserve_bootmem(__pa(initrd_start), size, BOOTMEM_DEFAULT);
        initrd_below_start_ok = 1;
 
-       printk(KERN_INFO "Initial ramdisk at: 0x%lx (%lu bytes)\n",
-              initrd_start, size);
+       pr_info("Initial ramdisk at: 0x%lx (%lu bytes)\n",
+               initrd_start, size);
        return;
 disable:
-       printk(" - disabling initrd\n");
+       printk(KERN_CONT " - disabling initrd\n");
        initrd_start = 0;
        initrd_end = 0;
 }
@@ -249,8 +254,7 @@ static void __init bootmem_init(void)
 static void __init bootmem_init(void)
 {
        unsigned long reserved_end;
-       unsigned long highest = 0;
-       unsigned long mapstart = -1UL;
+       unsigned long mapstart = ~0UL;
        unsigned long bootmap_size;
        int i;
 
@@ -259,8 +263,15 @@ static void __init bootmem_init(void)
         * not selected. Once that done we can determine the low bound
         * of usable memory.
         */
-       reserved_end = init_initrd();
-       reserved_end = PFN_UP(max(__pa(reserved_end), __pa_symbol(&_end)));
+       reserved_end = max(init_initrd(),
+                          (unsigned long) PFN_UP(__pa_symbol(&_end)));
+
+       /*
+        * max_low_pfn is not a number of pages. The number of pages
+        * of the system is given by 'max_low_pfn - min_low_pfn'.
+        */
+       min_low_pfn = ~0UL;
+       max_low_pfn = 0;
 
        /*
         * Find the highest page frame number we have available.
@@ -275,8 +286,10 @@ static void __init bootmem_init(void)
                end = PFN_DOWN(boot_mem_map.map[i].addr
                                + boot_mem_map.map[i].size);
 
-               if (end > highest)
-                       highest = end;
+               if (end > max_low_pfn)
+                       max_low_pfn = end;
+               if (start < min_low_pfn)
+                       min_low_pfn = start;
                if (end <= reserved_end)
                        continue;
                if (start >= mapstart)
@@ -284,21 +297,62 @@ static void __init bootmem_init(void)
                mapstart = max(reserved_end, start);
        }
 
+       if (min_low_pfn >= max_low_pfn)
+               panic("Incorrect memory mapping !!!");
+       if (min_low_pfn > ARCH_PFN_OFFSET) {
+               pr_info("Wasting %lu bytes for tracking %lu unused pages\n",
+                       (min_low_pfn - ARCH_PFN_OFFSET) * sizeof(struct page),
+                       min_low_pfn - ARCH_PFN_OFFSET);
+       } else if (min_low_pfn < ARCH_PFN_OFFSET) {
+               pr_info("%lu free pages won't be used\n",
+                       ARCH_PFN_OFFSET - min_low_pfn);
+       }
+       min_low_pfn = ARCH_PFN_OFFSET;
+
        /*
         * Determine low and high memory ranges
         */
-       if (highest > PFN_DOWN(HIGHMEM_START)) {
+       max_pfn = max_low_pfn;
+       if (max_low_pfn > PFN_DOWN(HIGHMEM_START)) {
 #ifdef CONFIG_HIGHMEM
                highstart_pfn = PFN_DOWN(HIGHMEM_START);
-               highend_pfn = highest;
+               highend_pfn = max_low_pfn;
 #endif
-               highest = PFN_DOWN(HIGHMEM_START);
+               max_low_pfn = PFN_DOWN(HIGHMEM_START);
        }
 
        /*
         * Initialize the boot-time allocator with low memory only.
         */
-       bootmap_size = init_bootmem(mapstart, highest);
+       bootmap_size = init_bootmem_node(NODE_DATA(0), mapstart,
+                                        min_low_pfn, max_low_pfn);
+
+
+       for (i = 0; i < boot_mem_map.nr_map; i++) {
+               unsigned long start, end;
+
+               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 (start <= min_low_pfn)
+                       start = min_low_pfn;
+               if (start >= end)
+                       continue;
+
+#ifndef CONFIG_HIGHMEM
+               if (end > max_low_pfn)
+                       end = max_low_pfn;
+
+               /*
+                * ... finally, is the area going away?
+                */
+               if (end <= start)
+                       continue;
+#endif
+
+               add_active_range(0, start, end);
+       }
 
        /*
         * Register fully available low RAM pages with the bootmem allocator.
@@ -341,7 +395,7 @@ static void __init bootmem_init(void)
        /*
         * Reserve the bootmap memory.
         */
-       reserve_bootmem(PFN_PHYS(mapstart), bootmap_size);
+       reserve_bootmem(PFN_PHYS(mapstart), bootmap_size, BOOTMEM_DEFAULT);
 
        /*
         * Reserve initrd memory if needed.
@@ -352,13 +406,13 @@ static void __init bootmem_init(void)
 #endif /* CONFIG_SGI_IP27 */
 
 /*
- * arch_mem_init - initialize memory managment subsystem
+ * arch_mem_init - initialize memory management subsystem
  *
  *  o plat_mem_setup() detects the memory configuration and will record detected
  *    memory areas using add_memory_region.
  *
  * At this stage the memory configuration of the system is known to the
- * kernel but generic memory managment system is still entirely uninitialized.
+ * kernel but generic memory management system is still entirely uninitialized.
  *
  *  o bootmem_init()
  *  o sparse_init()
@@ -373,7 +427,7 @@ static void __init bootmem_init(void)
  * initialization hook for anything else was introduced.
  */
 
-static int usermem __initdata = 0;
+static int usermem __initdata;
 
 static int __init early_parse_mem(char *p)
 {
@@ -405,18 +459,30 @@ static void __init arch_mem_init(char **cmdline_p)
        /* call board setup routine */
        plat_mem_setup();
 
-       printk("Determined physical RAM map:\n");
+       pr_info("Determined physical RAM map:\n");
        print_memory_map();
 
-       strlcpy(command_line, arcs_cmdline, sizeof(command_line));
-       strlcpy(saved_command_line, command_line, COMMAND_LINE_SIZE);
+#ifdef CONFIG_CMDLINE_BOOL
+#ifdef CONFIG_CMDLINE_OVERRIDE
+       strlcpy(boot_command_line, builtin_cmdline, COMMAND_LINE_SIZE);
+#else
+       if (builtin_cmdline[0]) {
+               strlcat(arcs_cmdline, " ", COMMAND_LINE_SIZE);
+               strlcat(arcs_cmdline, builtin_cmdline, COMMAND_LINE_SIZE);
+       }
+       strlcpy(boot_command_line, arcs_cmdline, COMMAND_LINE_SIZE);
+#endif
+#else
+       strlcpy(boot_command_line, arcs_cmdline, COMMAND_LINE_SIZE);
+#endif
+       strlcpy(command_line, boot_command_line, COMMAND_LINE_SIZE);
 
        *cmdline_p = command_line;
 
        parse_early_param();
 
        if (usermem) {
-               printk("User-defined physical RAM map:\n");
+               pr_info("User-defined physical RAM map:\n");
                print_memory_map();
        }
 
@@ -482,41 +548,41 @@ void __init setup_arch(char **cmdline_p)
 {
        cpu_probe();
        prom_init();
+
+#ifdef CONFIG_EARLY_PRINTK
+       setup_early_printk();
+#endif
        cpu_report();
+       check_bugs_early();
 
 #if defined(CONFIG_VT)
 #if defined(CONFIG_VGA_CONSOLE)
-        conswitchp = &vga_con;
+       conswitchp = &vga_con;
 #elif defined(CONFIG_DUMMY_CONSOLE)
-        conswitchp = &dummy_con;
+       conswitchp = &dummy_con;
 #endif
 #endif
 
        arch_mem_init(cmdline_p);
 
        resource_init();
-#ifdef CONFIG_SMP
        plat_smp_setup();
-#endif
-}
-
-int __init fpu_disable(char *s)
-{
-       int i;
-
-       for (i = 0; i < NR_CPUS; i++)
-               cpu_data[i].options &= ~MIPS_CPU_FPU;
-
-       return 1;
 }
 
-__setup("nofpu", fpu_disable);
+unsigned long kernelsp[NR_CPUS];
+unsigned long fw_arg0, fw_arg1, fw_arg2, fw_arg3;
 
-int __init dsp_disable(char *s)
+#ifdef CONFIG_DEBUG_FS
+struct dentry *mips_debugfs_dir;
+static int __init debugfs_mips(void)
 {
-       cpu_data[0].ases &= ~MIPS_ASE_DSP;
+       struct dentry *d;
 
-       return 1;
+       d = debugfs_create_dir("mips", NULL);
+       if (!d)
+               return -ENOMEM;
+       mips_debugfs_dir = d;
+       return 0;
 }
-
-__setup("nodsp", dsp_disable);
+arch_initcall(debugfs_mips);
+#endif