Merge with git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux-2.6.git
[GitHub/mt8127/android_kernel_alcatel_ttab.git] / arch / mips / kernel / setup.c
1 /*
2 * This file is subject to the terms and conditions of the GNU General Public
3 * License. See the file "COPYING" in the main directory of this archive
4 * for more details.
5 *
6 * Copyright (C) 1995 Linus Torvalds
7 * Copyright (C) 1995 Waldorf Electronics
8 * Copyright (C) 1994, 95, 96, 97, 98, 99, 2000, 01, 02, 03 Ralf Baechle
9 * Copyright (C) 1996 Stoned Elipot
10 * Copyright (C) 1999 Silicon Graphics, Inc.
11 * Copyright (C) 2000 2001, 2002 Maciej W. Rozycki
12 */
13 #include <linux/config.h>
14 #include <linux/errno.h>
15 #include <linux/init.h>
16 #include <linux/ioport.h>
17 #include <linux/sched.h>
18 #include <linux/kernel.h>
19 #include <linux/mm.h>
20 #include <linux/module.h>
21 #include <linux/stddef.h>
22 #include <linux/string.h>
23 #include <linux/unistd.h>
24 #include <linux/slab.h>
25 #include <linux/user.h>
26 #include <linux/utsname.h>
27 #include <linux/a.out.h>
28 #include <linux/tty.h>
29 #include <linux/bootmem.h>
30 #include <linux/initrd.h>
31 #include <linux/major.h>
32 #include <linux/kdev_t.h>
33 #include <linux/root_dev.h>
34 #include <linux/highmem.h>
35 #include <linux/console.h>
36 #include <linux/mmzone.h>
37
38 #include <asm/addrspace.h>
39 #include <asm/bootinfo.h>
40 #include <asm/cache.h>
41 #include <asm/cpu.h>
42 #include <asm/sections.h>
43 #include <asm/setup.h>
44 #include <asm/system.h>
45
46 struct cpuinfo_mips cpu_data[NR_CPUS] __read_mostly;
47
48 EXPORT_SYMBOL(cpu_data);
49
50 #ifdef CONFIG_VT
51 struct screen_info screen_info;
52 #endif
53
54 /*
55 * Despite it's name this variable is even if we don't have PCI
56 */
57 unsigned int PCI_DMA_BUS_IS_PHYS;
58
59 EXPORT_SYMBOL(PCI_DMA_BUS_IS_PHYS);
60
61 /*
62 * Setup information
63 *
64 * These are initialized so they are in the .data section
65 */
66 unsigned long mips_machtype __read_mostly = MACH_UNKNOWN;
67 unsigned long mips_machgroup __read_mostly = MACH_GROUP_UNKNOWN;
68
69 EXPORT_SYMBOL(mips_machtype);
70 EXPORT_SYMBOL(mips_machgroup);
71
72 struct boot_mem_map boot_mem_map;
73
74 static char command_line[CL_SIZE];
75 char arcs_cmdline[CL_SIZE]=CONFIG_CMDLINE;
76
77 /*
78 * mips_io_port_base is the begin of the address space to which x86 style
79 * I/O ports are mapped.
80 */
81 const unsigned long mips_io_port_base __read_mostly = -1;
82 EXPORT_SYMBOL(mips_io_port_base);
83
84 /*
85 * isa_slot_offset is the address where E(ISA) busaddress 0 is mapped
86 * for the processor.
87 */
88 unsigned long isa_slot_offset;
89 EXPORT_SYMBOL(isa_slot_offset);
90
91 static struct resource code_resource = { .name = "Kernel code", };
92 static struct resource data_resource = { .name = "Kernel data", };
93
94 void __init add_memory_region(phys_t start, phys_t size, long type)
95 {
96 int x = boot_mem_map.nr_map;
97 struct boot_mem_map_entry *prev = boot_mem_map.map + x - 1;
98
99 /*
100 * Try to merge with previous entry if any. This is far less than
101 * perfect but is sufficient for most real world cases.
102 */
103 if (x && prev->addr + prev->size == start && prev->type == type) {
104 prev->size += size;
105 return;
106 }
107
108 if (x == BOOT_MEM_MAP_MAX) {
109 printk("Ooops! Too many entries in the memory map!\n");
110 return;
111 }
112
113 boot_mem_map.map[x].addr = start;
114 boot_mem_map.map[x].size = size;
115 boot_mem_map.map[x].type = type;
116 boot_mem_map.nr_map++;
117 }
118
119 static void __init print_memory_map(void)
120 {
121 int i;
122 const int field = 2 * sizeof(unsigned long);
123
124 for (i = 0; i < boot_mem_map.nr_map; i++) {
125 printk(" memory: %0*Lx @ %0*Lx ",
126 field, (unsigned long long) boot_mem_map.map[i].size,
127 field, (unsigned long long) boot_mem_map.map[i].addr);
128
129 switch (boot_mem_map.map[i].type) {
130 case BOOT_MEM_RAM:
131 printk("(usable)\n");
132 break;
133 case BOOT_MEM_ROM_DATA:
134 printk("(ROM data)\n");
135 break;
136 case BOOT_MEM_RESERVED:
137 printk("(reserved)\n");
138 break;
139 default:
140 printk("type %lu\n", boot_mem_map.map[i].type);
141 break;
142 }
143 }
144 }
145
146 static inline void parse_cmdline_early(void)
147 {
148 char c = ' ', *to = command_line, *from = saved_command_line;
149 unsigned long start_at, mem_size;
150 int len = 0;
151 int usermem = 0;
152
153 printk("Determined physical RAM map:\n");
154 print_memory_map();
155
156 for (;;) {
157 /*
158 * "mem=XXX[kKmM]" defines a memory region from
159 * 0 to <XXX>, overriding the determined size.
160 * "mem=XXX[KkmM]@YYY[KkmM]" defines a memory region from
161 * <YYY> to <YYY>+<XXX>, overriding the determined size.
162 */
163 if (c == ' ' && !memcmp(from, "mem=", 4)) {
164 if (to != command_line)
165 to--;
166 /*
167 * If a user specifies memory size, we
168 * blow away any automatically generated
169 * size.
170 */
171 if (usermem == 0) {
172 boot_mem_map.nr_map = 0;
173 usermem = 1;
174 }
175 mem_size = memparse(from + 4, &from);
176 if (*from == '@')
177 start_at = memparse(from + 1, &from);
178 else
179 start_at = 0;
180 add_memory_region(start_at, mem_size, BOOT_MEM_RAM);
181 }
182 c = *(from++);
183 if (!c)
184 break;
185 if (CL_SIZE <= ++len)
186 break;
187 *(to++) = c;
188 }
189 *to = '\0';
190
191 if (usermem) {
192 printk("User-defined physical RAM map:\n");
193 print_memory_map();
194 }
195 }
196
197 static inline int parse_rd_cmdline(unsigned long* rd_start, unsigned long* rd_end)
198 {
199 /*
200 * "rd_start=0xNNNNNNNN" defines the memory address of an initrd
201 * "rd_size=0xNN" it's size
202 */
203 unsigned long start = 0;
204 unsigned long size = 0;
205 unsigned long end;
206 char cmd_line[CL_SIZE];
207 char *start_str;
208 char *size_str;
209 char *tmp;
210
211 strcpy(cmd_line, command_line);
212 *command_line = 0;
213 tmp = cmd_line;
214 /* Ignore "rd_start=" strings in other parameters. */
215 start_str = strstr(cmd_line, "rd_start=");
216 if (start_str && start_str != cmd_line && *(start_str - 1) != ' ')
217 start_str = strstr(start_str, " rd_start=");
218 while (start_str) {
219 if (start_str != cmd_line)
220 strncat(command_line, tmp, start_str - tmp);
221 start = memparse(start_str + 9, &start_str);
222 tmp = start_str + 1;
223 start_str = strstr(start_str, " rd_start=");
224 }
225 if (*tmp)
226 strcat(command_line, tmp);
227
228 strcpy(cmd_line, command_line);
229 *command_line = 0;
230 tmp = cmd_line;
231 /* Ignore "rd_size" strings in other parameters. */
232 size_str = strstr(cmd_line, "rd_size=");
233 if (size_str && size_str != cmd_line && *(size_str - 1) != ' ')
234 size_str = strstr(size_str, " rd_size=");
235 while (size_str) {
236 if (size_str != cmd_line)
237 strncat(command_line, tmp, size_str - tmp);
238 size = memparse(size_str + 8, &size_str);
239 tmp = size_str + 1;
240 size_str = strstr(size_str, " rd_size=");
241 }
242 if (*tmp)
243 strcat(command_line, tmp);
244
245 #ifdef CONFIG_64BIT
246 /* HACK: Guess if the sign extension was forgotten */
247 if (start > 0x0000000080000000 && start < 0x00000000ffffffff)
248 start |= 0xffffffff00000000;
249 #endif
250
251 end = start + size;
252 if (start && end) {
253 *rd_start = start;
254 *rd_end = end;
255 return 1;
256 }
257 return 0;
258 }
259
260 #define PFN_UP(x) (((x) + PAGE_SIZE - 1) >> PAGE_SHIFT)
261 #define PFN_DOWN(x) ((x) >> PAGE_SHIFT)
262 #define PFN_PHYS(x) ((x) << PAGE_SHIFT)
263
264 #define MAXMEM HIGHMEM_START
265 #define MAXMEM_PFN PFN_DOWN(MAXMEM)
266
267 static inline void bootmem_init(void)
268 {
269 unsigned long start_pfn;
270 unsigned long reserved_end = (unsigned long)&_end;
271 #ifndef CONFIG_SGI_IP27
272 unsigned long first_usable_pfn;
273 unsigned long bootmap_size;
274 int i;
275 #endif
276 #ifdef CONFIG_BLK_DEV_INITRD
277 int initrd_reserve_bootmem = 0;
278
279 /* Board specific code should have set up initrd_start and initrd_end */
280 ROOT_DEV = Root_RAM0;
281 if (parse_rd_cmdline(&initrd_start, &initrd_end)) {
282 reserved_end = max(reserved_end, initrd_end);
283 initrd_reserve_bootmem = 1;
284 } else {
285 unsigned long tmp;
286 u32 *initrd_header;
287
288 tmp = ((reserved_end + PAGE_SIZE-1) & PAGE_MASK) - sizeof(u32) * 2;
289 if (tmp < reserved_end)
290 tmp += PAGE_SIZE;
291 initrd_header = (u32 *)tmp;
292 if (initrd_header[0] == 0x494E5244) {
293 initrd_start = (unsigned long)&initrd_header[2];
294 initrd_end = initrd_start + initrd_header[1];
295 reserved_end = max(reserved_end, initrd_end);
296 initrd_reserve_bootmem = 1;
297 }
298 }
299 #endif /* CONFIG_BLK_DEV_INITRD */
300
301 /*
302 * Partially used pages are not usable - thus
303 * we are rounding upwards.
304 */
305 start_pfn = PFN_UP(CPHYSADDR(reserved_end));
306
307 #ifndef CONFIG_SGI_IP27
308 /* Find the highest page frame number we have available. */
309 max_pfn = 0;
310 first_usable_pfn = -1UL;
311 for (i = 0; i < boot_mem_map.nr_map; i++) {
312 unsigned long start, end;
313
314 if (boot_mem_map.map[i].type != BOOT_MEM_RAM)
315 continue;
316
317 start = PFN_UP(boot_mem_map.map[i].addr);
318 end = PFN_DOWN(boot_mem_map.map[i].addr
319 + boot_mem_map.map[i].size);
320
321 if (start >= end)
322 continue;
323 if (end > max_pfn)
324 max_pfn = end;
325 if (start < first_usable_pfn) {
326 if (start > start_pfn) {
327 first_usable_pfn = start;
328 } else if (end > start_pfn) {
329 first_usable_pfn = start_pfn;
330 }
331 }
332 }
333
334 /*
335 * Determine low and high memory ranges
336 */
337 max_low_pfn = max_pfn;
338 if (max_low_pfn > MAXMEM_PFN) {
339 max_low_pfn = MAXMEM_PFN;
340 #ifndef CONFIG_HIGHMEM
341 /* Maximum memory usable is what is directly addressable */
342 printk(KERN_WARNING "Warning only %ldMB will be used.\n",
343 MAXMEM >> 20);
344 printk(KERN_WARNING "Use a HIGHMEM enabled kernel.\n");
345 #endif
346 }
347
348 #ifdef CONFIG_HIGHMEM
349 /*
350 * Crude, we really should make a better attempt at detecting
351 * highstart_pfn
352 */
353 highstart_pfn = highend_pfn = max_pfn;
354 if (max_pfn > MAXMEM_PFN) {
355 highstart_pfn = MAXMEM_PFN;
356 printk(KERN_NOTICE "%ldMB HIGHMEM available.\n",
357 (highend_pfn - highstart_pfn) >> (20 - PAGE_SHIFT));
358 }
359 #endif
360
361 memory_present(0, first_usable_pfn, max_low_pfn);
362
363 /* Initialize the boot-time allocator with low memory only. */
364 bootmap_size = init_bootmem(first_usable_pfn, max_low_pfn);
365
366 /*
367 * Register fully available low RAM pages with the bootmem allocator.
368 */
369 for (i = 0; i < boot_mem_map.nr_map; i++) {
370 unsigned long curr_pfn, last_pfn, size;
371
372 /*
373 * Reserve usable memory.
374 */
375 if (boot_mem_map.map[i].type != BOOT_MEM_RAM)
376 continue;
377
378 /*
379 * We are rounding up the start address of usable memory:
380 */
381 curr_pfn = PFN_UP(boot_mem_map.map[i].addr);
382 if (curr_pfn >= max_low_pfn)
383 continue;
384 if (curr_pfn < start_pfn)
385 curr_pfn = start_pfn;
386
387 /*
388 * ... and at the end of the usable range downwards:
389 */
390 last_pfn = PFN_DOWN(boot_mem_map.map[i].addr
391 + boot_mem_map.map[i].size);
392
393 if (last_pfn > max_low_pfn)
394 last_pfn = max_low_pfn;
395
396 /*
397 * Only register lowmem part of lowmem segment with bootmem.
398 */
399 size = last_pfn - curr_pfn;
400 if (curr_pfn > PFN_DOWN(HIGHMEM_START))
401 continue;
402 if (curr_pfn + size - 1 > PFN_DOWN(HIGHMEM_START))
403 size = PFN_DOWN(HIGHMEM_START) - curr_pfn;
404 if (!size)
405 continue;
406
407 /*
408 * ... finally, did all the rounding and playing
409 * around just make the area go away?
410 */
411 if (last_pfn <= curr_pfn)
412 continue;
413
414 /* Register lowmem ranges */
415 free_bootmem(PFN_PHYS(curr_pfn), PFN_PHYS(size));
416 }
417
418 /* Reserve the bootmap memory. */
419 reserve_bootmem(PFN_PHYS(first_usable_pfn), bootmap_size);
420 #endif /* CONFIG_SGI_IP27 */
421
422 #ifdef CONFIG_BLK_DEV_INITRD
423 initrd_below_start_ok = 1;
424 if (initrd_start) {
425 unsigned long initrd_size = ((unsigned char *)initrd_end) - ((unsigned char *)initrd_start);
426 printk("Initial ramdisk at: 0x%p (%lu bytes)\n",
427 (void *)initrd_start, initrd_size);
428
429 if (CPHYSADDR(initrd_end) > PFN_PHYS(max_low_pfn)) {
430 printk("initrd extends beyond end of memory "
431 "(0x%0*Lx > 0x%0*Lx)\ndisabling initrd\n",
432 sizeof(long) * 2,
433 (unsigned long long)CPHYSADDR(initrd_end),
434 sizeof(long) * 2,
435 (unsigned long long)PFN_PHYS(max_low_pfn));
436 initrd_start = initrd_end = 0;
437 initrd_reserve_bootmem = 0;
438 }
439
440 if (initrd_reserve_bootmem)
441 reserve_bootmem(CPHYSADDR(initrd_start), initrd_size);
442 }
443 #endif /* CONFIG_BLK_DEV_INITRD */
444 }
445
446 static inline void resource_init(void)
447 {
448 int i;
449
450 #if defined(CONFIG_64BIT) && !defined(CONFIG_BUILD_ELF64)
451 /*
452 * The 64bit code in 32bit object format trick can't represent
453 * 64bit wide relocations for linker script symbols.
454 */
455 code_resource.start = CPHYSADDR(&_text);
456 code_resource.end = CPHYSADDR(&_etext) - 1;
457 data_resource.start = CPHYSADDR(&_etext);
458 data_resource.end = CPHYSADDR(&_edata) - 1;
459 #else
460 code_resource.start = virt_to_phys(&_text);
461 code_resource.end = virt_to_phys(&_etext) - 1;
462 data_resource.start = virt_to_phys(&_etext);
463 data_resource.end = virt_to_phys(&_edata) - 1;
464 #endif
465
466 /*
467 * Request address space for all standard RAM.
468 */
469 for (i = 0; i < boot_mem_map.nr_map; i++) {
470 struct resource *res;
471 unsigned long start, end;
472
473 start = boot_mem_map.map[i].addr;
474 end = boot_mem_map.map[i].addr + boot_mem_map.map[i].size - 1;
475 if (start >= MAXMEM)
476 continue;
477 if (end >= MAXMEM)
478 end = MAXMEM - 1;
479
480 res = alloc_bootmem(sizeof(struct resource));
481 switch (boot_mem_map.map[i].type) {
482 case BOOT_MEM_RAM:
483 case BOOT_MEM_ROM_DATA:
484 res->name = "System RAM";
485 break;
486 case BOOT_MEM_RESERVED:
487 default:
488 res->name = "reserved";
489 }
490
491 res->start = start;
492 res->end = end;
493
494 res->flags = IORESOURCE_MEM | IORESOURCE_BUSY;
495 request_resource(&iomem_resource, res);
496
497 /*
498 * We don't know which RAM region contains kernel data,
499 * so we try it repeatedly and let the resource manager
500 * test it.
501 */
502 request_resource(res, &code_resource);
503 request_resource(res, &data_resource);
504 }
505 }
506
507 #undef PFN_UP
508 #undef PFN_DOWN
509 #undef PFN_PHYS
510
511 #undef MAXMEM
512 #undef MAXMEM_PFN
513
514 extern void plat_setup(void);
515
516 void __init setup_arch(char **cmdline_p)
517 {
518 cpu_probe();
519 prom_init();
520 cpu_report();
521
522 #if defined(CONFIG_VT)
523 #if defined(CONFIG_VGA_CONSOLE)
524 conswitchp = &vga_con;
525 #elif defined(CONFIG_DUMMY_CONSOLE)
526 conswitchp = &dummy_con;
527 #endif
528 #endif
529
530 /* call board setup routine */
531 plat_setup();
532
533 strlcpy(command_line, arcs_cmdline, sizeof(command_line));
534 strlcpy(saved_command_line, command_line, COMMAND_LINE_SIZE);
535
536 *cmdline_p = command_line;
537
538 parse_cmdline_early();
539 bootmem_init();
540 sparse_init();
541 paging_init();
542 resource_init();
543 #ifdef CONFIG_SMP
544 plat_smp_setup();
545 #endif
546 }
547
548 int __init fpu_disable(char *s)
549 {
550 cpu_data[0].options &= ~MIPS_CPU_FPU;
551
552 return 1;
553 }
554
555 __setup("nofpu", fpu_disable);
556
557 int __init dsp_disable(char *s)
558 {
559 cpu_data[0].ases &= ~MIPS_ASE_DSP;
560
561 return 1;
562 }
563
564 __setup("nodsp", dsp_disable);