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, 2007 Maciej W. Rozycki
12 */
13 #include <linux/init.h>
14 #include <linux/ioport.h>
15 #include <linux/export.h>
16 #include <linux/screen_info.h>
17 #include <linux/memblock.h>
18 #include <linux/bootmem.h>
19 #include <linux/initrd.h>
20 #include <linux/root_dev.h>
21 #include <linux/highmem.h>
22 #include <linux/console.h>
23 #include <linux/pfn.h>
24 #include <linux/debugfs.h>
25 #include <linux/kexec.h>
26 #include <linux/sizes.h>
27
28 #include <asm/addrspace.h>
29 #include <asm/bootinfo.h>
30 #include <asm/bugs.h>
31 #include <asm/cache.h>
32 #include <asm/cpu.h>
33 #include <asm/sections.h>
34 #include <asm/setup.h>
35 #include <asm/smp-ops.h>
36 #include <asm/prom.h>
37
38 struct cpuinfo_mips cpu_data[NR_CPUS] __read_mostly;
39
40 EXPORT_SYMBOL(cpu_data);
41
42 #ifdef CONFIG_VT
43 struct screen_info screen_info;
44 #endif
45
46 /*
47 * Despite it's name this variable is even if we don't have PCI
48 */
49 unsigned int PCI_DMA_BUS_IS_PHYS;
50
51 EXPORT_SYMBOL(PCI_DMA_BUS_IS_PHYS);
52
53 /*
54 * Setup information
55 *
56 * These are initialized so they are in the .data section
57 */
58 unsigned long mips_machtype __read_mostly = MACH_UNKNOWN;
59
60 EXPORT_SYMBOL(mips_machtype);
61
62 struct boot_mem_map boot_mem_map;
63
64 static char __initdata command_line[COMMAND_LINE_SIZE];
65 char __initdata arcs_cmdline[COMMAND_LINE_SIZE];
66
67 #ifdef CONFIG_CMDLINE_BOOL
68 static char __initdata builtin_cmdline[COMMAND_LINE_SIZE] = CONFIG_CMDLINE;
69 #endif
70
71 /*
72 * mips_io_port_base is the begin of the address space to which x86 style
73 * I/O ports are mapped.
74 */
75 const unsigned long mips_io_port_base = -1;
76 EXPORT_SYMBOL(mips_io_port_base);
77
78 static struct resource code_resource = { .name = "Kernel code", };
79 static struct resource data_resource = { .name = "Kernel data", };
80
81 static void *detect_magic __initdata = detect_memory_region;
82
add_memory_region(phys_t start,phys_t size,long type)83 void __init add_memory_region(phys_t start, phys_t size, long type)
84 {
85 int x = boot_mem_map.nr_map;
86 int i;
87
88 /* Sanity check */
89 if (start + size < start) {
90 pr_warning("Trying to add an invalid memory region, skipped\n");
91 return;
92 }
93
94 /*
95 * Try to merge with existing entry, if any.
96 */
97 for (i = 0; i < boot_mem_map.nr_map; i++) {
98 struct boot_mem_map_entry *entry = boot_mem_map.map + i;
99 unsigned long top;
100
101 if (entry->type != type)
102 continue;
103
104 if (start + size < entry->addr)
105 continue; /* no overlap */
106
107 if (entry->addr + entry->size < start)
108 continue; /* no overlap */
109
110 top = max(entry->addr + entry->size, start + size);
111 entry->addr = min(entry->addr, start);
112 entry->size = top - entry->addr;
113
114 return;
115 }
116
117 if (boot_mem_map.nr_map == BOOT_MEM_MAP_MAX) {
118 pr_err("Ooops! Too many entries in the memory map!\n");
119 return;
120 }
121
122 boot_mem_map.map[x].addr = start;
123 boot_mem_map.map[x].size = size;
124 boot_mem_map.map[x].type = type;
125 boot_mem_map.nr_map++;
126 }
127
detect_memory_region(phys_t start,phys_t sz_min,phys_t sz_max)128 void __init detect_memory_region(phys_t start, phys_t sz_min, phys_t sz_max)
129 {
130 void *dm = &detect_magic;
131 phys_t size;
132
133 for (size = sz_min; size < sz_max; size <<= 1) {
134 if (!memcmp(dm, dm + size, sizeof(detect_magic)))
135 break;
136 }
137
138 pr_debug("Memory: %lluMB of RAM detected at 0x%llx (min: %lluMB, max: %lluMB)\n",
139 ((unsigned long long) size) / SZ_1M,
140 (unsigned long long) start,
141 ((unsigned long long) sz_min) / SZ_1M,
142 ((unsigned long long) sz_max) / SZ_1M);
143
144 add_memory_region(start, size, BOOT_MEM_RAM);
145 }
146
print_memory_map(void)147 static void __init print_memory_map(void)
148 {
149 int i;
150 const int field = 2 * sizeof(unsigned long);
151
152 for (i = 0; i < boot_mem_map.nr_map; i++) {
153 printk(KERN_INFO " memory: %0*Lx @ %0*Lx ",
154 field, (unsigned long long) boot_mem_map.map[i].size,
155 field, (unsigned long long) boot_mem_map.map[i].addr);
156
157 switch (boot_mem_map.map[i].type) {
158 case BOOT_MEM_RAM:
159 printk(KERN_CONT "(usable)\n");
160 break;
161 case BOOT_MEM_INIT_RAM:
162 printk(KERN_CONT "(usable after init)\n");
163 break;
164 case BOOT_MEM_ROM_DATA:
165 printk(KERN_CONT "(ROM data)\n");
166 break;
167 case BOOT_MEM_RESERVED:
168 printk(KERN_CONT "(reserved)\n");
169 break;
170 case BOOT_MEM_INUSE:
171 printk(KERN_CONT "(in-use, reserved)\n");
172 break;
173 default:
174 printk(KERN_CONT "type %lu\n", boot_mem_map.map[i].type);
175 break;
176 }
177 }
178 }
179
180 /*
181 * Manage initrd
182 */
183 #ifdef CONFIG_BLK_DEV_INITRD
184
rd_start_early(char * p)185 static int __init rd_start_early(char *p)
186 {
187 unsigned long start = memparse(p, &p);
188
189 #ifdef CONFIG_64BIT
190 /* Guess if the sign extension was forgotten by bootloader */
191 if (start < XKPHYS)
192 start = (int)start;
193 #endif
194 initrd_start = start;
195 initrd_end += start;
196 return 0;
197 }
198 early_param("rd_start", rd_start_early);
199
rd_size_early(char * p)200 static int __init rd_size_early(char *p)
201 {
202 initrd_end += memparse(p, &p);
203 return 0;
204 }
205 early_param("rd_size", rd_size_early);
206
207 /* it returns the next free pfn after initrd */
init_initrd(void)208 static unsigned long __init init_initrd(void)
209 {
210 unsigned long end;
211
212 /*
213 * Board specific code or command line parser should have
214 * already set up initrd_start and initrd_end. In these cases
215 * perfom sanity checks and use them if all looks good.
216 */
217 if (!initrd_start || initrd_end <= initrd_start)
218 goto disable;
219
220 if (initrd_start & ~PAGE_MASK) {
221 pr_err("initrd start must be page aligned\n");
222 goto disable;
223 }
224 if (initrd_start < PAGE_OFFSET) {
225 pr_err("initrd start < PAGE_OFFSET\n");
226 goto disable;
227 }
228
229 /*
230 * Sanitize initrd addresses. For example firmware
231 * can't guess if they need to pass them through
232 * 64-bits values if the kernel has been built in pure
233 * 32-bit. We need also to switch from KSEG0 to XKPHYS
234 * addresses now, so the code can now safely use __pa().
235 */
236 end = __pa(initrd_end);
237 initrd_end = (unsigned long)__va(end);
238 initrd_start = (unsigned long)__va(__pa(initrd_start));
239
240 ROOT_DEV = Root_RAM0;
241 return PFN_UP(end);
242 disable:
243 initrd_start = 0;
244 initrd_end = 0;
245 return 0;
246 }
247
finalize_initrd(void)248 static void __init finalize_initrd(void)
249 {
250 unsigned long size = initrd_end - initrd_start;
251
252 if (size == 0) {
253 printk(KERN_INFO "Initrd not found or empty");
254 goto disable;
255 }
256 if (__pa(initrd_end) > PFN_PHYS(max_low_pfn)) {
257 printk(KERN_ERR "Initrd extends beyond end of memory");
258 goto disable;
259 }
260
261 reserve_bootmem(__pa(initrd_start), size, BOOTMEM_DEFAULT);
262 initrd_below_start_ok = 1;
263
264 pr_info("Initial ramdisk at: 0x%lx (%lu bytes)\n",
265 initrd_start, size);
266 return;
267 disable:
268 printk(KERN_CONT " - disabling initrd\n");
269 initrd_start = 0;
270 initrd_end = 0;
271 }
272
273 #else /* !CONFIG_BLK_DEV_INITRD */
274
init_initrd(void)275 static unsigned long __init init_initrd(void)
276 {
277 return 0;
278 }
279
280 #define finalize_initrd() do {} while (0)
281
282 #endif
283
284 /*
285 * Initialize the bootmem allocator. It also setup initrd related data
286 * if needed.
287 */
288 #ifdef CONFIG_SGI_IP27
289
bootmem_init(void)290 static void __init bootmem_init(void)
291 {
292 init_initrd();
293 finalize_initrd();
294 }
295
296 #else /* !CONFIG_SGI_IP27 */
297
298 static int maar_last = -2;
299 static int nomaar_flag;
300 static unsigned long maar_regs[MIPS_MAAR_MAX * 2];
301
early_parse_nomaar(char * p)302 static int __init early_parse_nomaar(char *p)
303 {
304 nomaar_flag = 1;
305 return(0);
306 }
307 early_param("nomaar", early_parse_nomaar);
308
maar_reset(void)309 static void __init maar_reset(void)
310 {
311 int maar = 0;
312
313 do {
314 write_c0_maarindex(maar);
315 back_to_back_c0_hazard();
316 if (read_c0_maarindex() != maar)
317 return;
318 write_c0_maar(0);
319 back_to_back_c0_hazard();
320 } while (++maar < MIPS_MAAR_MAX);
321 }
322
maar_setup(void)323 void __init maar_setup(void)
324 {
325 int maar = 0;
326 phys_t low;
327 phys_t upper;
328
329 if (nomaar_flag || !cpu_has_maar)
330 return;
331
332 pr_info("MAAR setup:\n");
333 maar_reset();
334
335 for (maar=0; maar<(maar_last+2); maar++) {
336 write_c0_maarindex(maar);
337 back_to_back_c0_hazard();
338 if (read_c0_maarindex() != maar) {
339 pr_err("CPU has only %d MAARs, resetting...\n",maar - 1);
340 maar_reset();
341 return;
342 }
343 write_c0_maar(maar_regs[maar]);
344 #if defined(CONFIG_CPU_MIPS32) && defined(CONFIG_64BIT_PHYS_ADDR)
345 write_c0_hi_maar(maar_regs[maar + MIPS_MAAR_MAX]);
346 #endif
347 back_to_back_c0_hazard();
348 if (maar & 1) {
349 low = (((phys_t)maar_regs[maar]) << 4) & ~0xffff;
350 upper = (((phys_t)maar_regs[maar - 1]) << 4) & ~0xffff;
351 #if defined(CONFIG_CPU_MIPS32) && defined(CONFIG_64BIT_PHYS_ADDR)
352 low += (((phys_t)maar_regs[maar + MIPS_MAAR_MAX]) << 36) & ~MIPS_MAAR_HI_V;
353 upper += (((phys_t)maar_regs[maar - 1 + MIPS_MAAR_MAX]) << 36) & ~MIPS_MAAR_HI_V;
354 #endif
355 upper = (upper & ~0xffff) + 0xffff;
356 pr_info(" [%0#10lx-%0#10lx] %s\n", low, upper,
357 (maar_regs[maar -1] & MIPS_MAAR_S)?"speculative":"");
358 }
359 }
360 }
361
maar_update(phys_t begin,phys_t end,int speculative)362 static void __init maar_update(phys_t begin, phys_t end, int speculative)
363 {
364 phys_t start;
365
366 /* rounding, let's be conservative if speculative */
367 if (speculative) {
368 if (begin & 0xffff)
369 start = (begin + 0x10000) & ~0xffff;
370 else
371 start = begin;
372 end = (end - 0x10000) & ~0xffff;
373 } else {
374 start = begin & ~0xffff;
375 end = (end - 1) & ~0xffff;
376 }
377 if (speculative && (end == start))
378 return;
379
380 maar_regs[maar_last + 1] = ((start >> 4) | MIPS_MAAR_V | (speculative?MIPS_MAAR_S:0));
381 #if defined(CONFIG_CPU_MIPS32) && defined(CONFIG_64BIT_PHYS_ADDR)
382 maar_regs[maar_last + 1 + MIPS_MAAR_MAX] = MIPS_MAAR_HI_V | (start >> 36);
383 #endif
384 maar_regs[maar_last] = ((end >> 4) | MIPS_MAAR_V | (speculative?MIPS_MAAR_S:0));
385 #if defined(CONFIG_CPU_MIPS32) && defined(CONFIG_64BIT_PHYS_ADDR)
386 maar_regs[maar_last + MIPS_MAAR_MAX] = MIPS_MAAR_HI_V | (end >> 36);
387 #endif
388 return;
389 }
390
add_maar_region(phys_t start,phys_t end,int speculative)391 void __init add_maar_region(phys_t start, phys_t end, int speculative)
392 {
393 phys_t upper;
394 unsigned sbit;
395 int i;
396
397 if (nomaar_flag || !cpu_has_maar)
398 return;
399
400 if (maar_last < 0) {
401 maar_last = 0;
402 maar_update(start, end, speculative);
403 return;
404 }
405
406 /* try merge with previous region */
407 upper = maar_regs[maar_last];
408 #if defined(CONFIG_CPU_MIPS32) && defined(CONFIG_64BIT_PHYS_ADDR)
409 upper |= (((phys_t)maar_regs[maar_last + MIPS_MAAR_MAX] << 32) & ~MIPS_MAAR_HI_V);
410 #endif
411 sbit = (upper & MIPS_MAAR_S)? MIPS_MAAR_S : 0;
412 speculative = speculative? MIPS_MAAR_S : 0;
413 upper = ((upper << 4) + 0x10000) & ~0xffffUL;
414 if (((upper == (start & ~0xffffUL)) ||
415 (upper == ((start + 0xffffUL) & ~0xffffUL))) &&
416 (sbit == speculative)) {
417 if (speculative)
418 end = (end - 0x10000) & ~0xffff;
419 else
420 end = (end - 1) & ~0xffff;
421 maar_regs[maar_last] = (end >> 4) | MIPS_MAAR_V | sbit;
422 #if defined(CONFIG_CPU_MIPS32) && defined(CONFIG_64BIT_PHYS_ADDR)
423 maar_regs[maar_last + MIPS_MAAR_MAX] = MIPS_MAAR_HI_V | (end >> 36);
424 #endif
425 return;
426 }
427
428 maar_last += 2;
429 if (maar_last >= MIPS_MAAR_MAX) {
430 pr_err("Attempt to initialize more than %d MAARs\n", MIPS_MAAR_MAX);
431 for (i=0; i<MIPS_MAAR_MAX; i++) {
432 maar_regs[i] = 0;
433 maar_regs[i + MIPS_MAAR_MAX] = 0;
434 }
435 return;
436 }
437 maar_update(start, end, speculative);
438 }
439
bootmem_init(void)440 static void __init bootmem_init(void)
441 {
442 unsigned long reserved_end;
443 unsigned long mapstart = ~0UL;
444 unsigned long bootmap_size;
445 int i;
446
447 /*
448 * Init any data related to initrd. It's a nop if INITRD is
449 * not selected. Once that done we can determine the low bound
450 * of usable memory.
451 */
452 reserved_end = max(init_initrd(),
453 (unsigned long) PFN_UP(__pa_symbol(&_end)));
454
455 /*
456 * max_low_pfn is not a number of pages. The number of pages
457 * of the system is given by 'max_low_pfn - min_low_pfn'.
458 */
459 min_low_pfn = ~0UL;
460 max_low_pfn = 0;
461
462 /*
463 * Find the highest page frame number we have available.
464 */
465 for (i = 0; i < boot_mem_map.nr_map; i++) {
466 unsigned long start, end;
467
468 if (boot_mem_map.map[i].type != BOOT_MEM_RAM)
469 continue;
470
471 start = PFN_UP(boot_mem_map.map[i].addr);
472 end = PFN_DOWN(boot_mem_map.map[i].addr
473 + boot_mem_map.map[i].size);
474
475 if (end > max_low_pfn)
476 max_low_pfn = end;
477 if (start < min_low_pfn)
478 min_low_pfn = start;
479 if (end <= reserved_end)
480 continue;
481 if (start >= mapstart)
482 continue;
483 mapstart = max(reserved_end, start);
484 }
485
486 if (min_low_pfn >= max_low_pfn)
487 panic("Incorrect memory mapping !!!");
488 if (min_low_pfn > ARCH_PFN_OFFSET) {
489 pr_info("Wasting %lu bytes for tracking %lu unused pages\n",
490 (min_low_pfn - ARCH_PFN_OFFSET) * sizeof(struct page),
491 min_low_pfn - ARCH_PFN_OFFSET);
492 } else if (min_low_pfn < ARCH_PFN_OFFSET) {
493 pr_info("%lu free pages won't be used\n",
494 ARCH_PFN_OFFSET - min_low_pfn);
495 }
496 min_low_pfn = ARCH_PFN_OFFSET;
497
498 /*
499 * Determine low and high memory ranges
500 */
501 max_pfn = max_low_pfn;
502 if (max_low_pfn > PFN_DOWN(HIGHMEM_START)) {
503 #ifdef CONFIG_HIGHMEM
504 highstart_pfn = PFN_DOWN(HIGHMEM_START);
505 highend_pfn = max_low_pfn;
506 #endif
507 max_low_pfn = PFN_DOWN(HIGHMEM_START);
508 }
509
510 /*
511 * Initialize the boot-time allocator with low memory only.
512 */
513 bootmap_size = init_bootmem_node(NODE_DATA(0), mapstart,
514 min_low_pfn, max_low_pfn);
515
516 for (i = 0; i < boot_mem_map.nr_map; i++) {
517 unsigned long start, end;
518
519 start = PFN_UP(boot_mem_map.map[i].addr);
520 end = PFN_DOWN(boot_mem_map.map[i].addr
521 + boot_mem_map.map[i].size);
522
523 if (start <= min_low_pfn)
524 start = min_low_pfn;
525 if (start >= end)
526 continue;
527
528 #ifndef CONFIG_HIGHMEM
529 if (end > max_low_pfn)
530 end = max_low_pfn;
531
532 /*
533 * ... finally, is the area going away?
534 */
535 if (end <= start)
536 continue;
537 #endif
538 if ((!nomaar_flag) && cpu_has_maar &&
539 ((boot_mem_map.map[i].type == BOOT_MEM_RAM) ||
540 (boot_mem_map.map[i].type == BOOT_MEM_ROM_DATA) ||
541 (boot_mem_map.map[i].type == BOOT_MEM_INUSE) ||
542 (boot_mem_map.map[i].type == BOOT_MEM_INIT_RAM)))
543 add_maar_region(PFN_PHYS(start), PFN_PHYS(end), 1);
544
545 memblock_add_node(PFN_PHYS(start), PFN_PHYS(end - start), 0);
546 }
547 if (cpu_has_maar && !nomaar_flag)
548 maar_setup();
549
550 /*
551 * Register fully available low RAM pages with the bootmem allocator.
552 */
553 for (i = 0; i < boot_mem_map.nr_map; i++) {
554 unsigned long start, end, size;
555
556 start = PFN_UP(boot_mem_map.map[i].addr);
557 end = PFN_DOWN(boot_mem_map.map[i].addr
558 + boot_mem_map.map[i].size);
559
560 /*
561 * Reserve usable memory.
562 */
563 switch (boot_mem_map.map[i].type) {
564 case BOOT_MEM_RAM:
565 break;
566 case BOOT_MEM_INIT_RAM:
567 memory_present(0, start, end);
568 continue;
569 default:
570 /* Not usable memory */
571 continue;
572 }
573
574 /*
575 * We are rounding up the start address of usable memory
576 * and at the end of the usable range downwards.
577 */
578 if (start >= max_low_pfn)
579 continue;
580 if (start < reserved_end)
581 start = reserved_end;
582 if (end > max_low_pfn)
583 end = max_low_pfn;
584
585 /*
586 * ... finally, is the area going away?
587 */
588 if (end <= start)
589 continue;
590 size = end - start;
591
592 /* Register lowmem ranges */
593 free_bootmem(PFN_PHYS(start), size << PAGE_SHIFT);
594 memory_present(0, start, end);
595 }
596
597 /*
598 * Reserve the bootmap memory.
599 */
600 reserve_bootmem(PFN_PHYS(mapstart), bootmap_size, BOOTMEM_DEFAULT);
601
602 /*
603 * Reserve initrd memory if needed.
604 */
605 finalize_initrd();
606 }
607
608 #endif /* CONFIG_SGI_IP27 */
609
610 /*
611 * arch_mem_init - initialize memory management subsystem
612 *
613 * o plat_mem_setup() detects the memory configuration and will record detected
614 * memory areas using add_memory_region.
615 *
616 * At this stage the memory configuration of the system is known to the
617 * kernel but generic memory management system is still entirely uninitialized.
618 *
619 * o bootmem_init()
620 * o sparse_init()
621 * o paging_init()
622 *
623 * At this stage the bootmem allocator is ready to use.
624 *
625 * NOTE: historically plat_mem_setup did the entire platform initialization.
626 * This was rather impractical because it meant plat_mem_setup had to
627 * get away without any kind of memory allocator. To keep old code from
628 * breaking plat_setup was just renamed to plat_setup and a second platform
629 * initialization hook for anything else was introduced.
630 */
631
632 static int usermem __initdata;
633
early_parse_mem(char * p)634 static int __init early_parse_mem(char *p)
635 {
636 unsigned long start, size;
637
638 /*
639 * If a user specifies memory size, we
640 * blow away any automatically generated
641 * size.
642 */
643 if (usermem == 0) {
644 boot_mem_map.nr_map = 0;
645 usermem = 1;
646 }
647 start = 0;
648 size = memparse(p, &p);
649 if (*p == '@')
650 start = memparse(p + 1, &p);
651
652 add_memory_region(start, size, BOOT_MEM_RAM);
653 return 0;
654 }
655 early_param("mem", early_parse_mem);
656
early_parse_memmap(char * p)657 static int __init early_parse_memmap(char *p)
658 {
659 char *oldp;
660 u64 start_at, mem_size;
661
662 if (!p)
663 return -EINVAL;
664
665 if (!strncmp(p, "exactmap", 8)) {
666 pr_err("\"memmap=exactmap\" invalid on MIPS\n");
667 return 0;
668 }
669
670 oldp = p;
671 mem_size = memparse(p, &p);
672 if (p == oldp)
673 return -EINVAL;
674
675 if (*p == '@') {
676 start_at = memparse(p+1, &p);
677 add_memory_region(start_at, mem_size, BOOT_MEM_RAM);
678 } else if (*p == '#') {
679 pr_err("\"memmap=nn#ss\" (force ACPI data) invalid on MIPS\n");
680 return -EINVAL;
681 } else if (*p == '$') {
682 start_at = memparse(p+1, &p);
683 add_memory_region(start_at, mem_size, BOOT_MEM_RESERVED);
684 } else {
685 pr_err("\"memmap\" invalid format!\n");
686 return -EINVAL;
687 }
688
689 if (*p == '\0') {
690 usermem = 1;
691 return 0;
692 } else
693 return -EINVAL;
694 }
695 early_param("memmap", early_parse_memmap);
696
697 #ifdef CONFIG_PROC_VMCORE
698 unsigned long setup_elfcorehdr, setup_elfcorehdr_size;
early_parse_elfcorehdr(char * p)699 static int __init early_parse_elfcorehdr(char *p)
700 {
701 int i;
702
703 setup_elfcorehdr = memparse(p, &p);
704
705 for (i = 0; i < boot_mem_map.nr_map; i++) {
706 unsigned long start = boot_mem_map.map[i].addr;
707 unsigned long end = (boot_mem_map.map[i].addr +
708 boot_mem_map.map[i].size);
709 if (setup_elfcorehdr >= start && setup_elfcorehdr < end) {
710 /*
711 * Reserve from the elf core header to the end of
712 * the memory segment, that should all be kdump
713 * reserved memory.
714 */
715 setup_elfcorehdr_size = end - setup_elfcorehdr;
716 break;
717 }
718 }
719 /*
720 * If we don't find it in the memory map, then we shouldn't
721 * have to worry about it, as the new kernel won't use it.
722 */
723 return 0;
724 }
725 early_param("elfcorehdr", early_parse_elfcorehdr);
726 #endif
727
arch_mem_addpart(phys_t mem,phys_t end,int type)728 static void __init arch_mem_addpart(phys_t mem, phys_t end, int type)
729 {
730 phys_t size;
731 int i;
732
733 size = end - mem;
734 if (!size)
735 return;
736
737 /* Make sure it is in the boot_mem_map */
738 for (i = 0; i < boot_mem_map.nr_map; i++) {
739 if (mem >= boot_mem_map.map[i].addr &&
740 mem < (boot_mem_map.map[i].addr +
741 boot_mem_map.map[i].size))
742 return;
743 }
744 add_memory_region(mem, size, type);
745 }
746
747 #ifdef CONFIG_KEXEC
get_total_mem(void)748 static inline unsigned long long get_total_mem(void)
749 {
750 unsigned long long total;
751
752 total = max_pfn - min_low_pfn;
753 return total << PAGE_SHIFT;
754 }
755
mips_parse_crashkernel(void)756 static void __init mips_parse_crashkernel(void)
757 {
758 unsigned long long total_mem;
759 unsigned long long crash_size, crash_base;
760 int ret;
761
762 total_mem = get_total_mem();
763 ret = parse_crashkernel(boot_command_line, total_mem,
764 &crash_size, &crash_base);
765 if (ret != 0 || crash_size <= 0)
766 return;
767
768 crashk_res.start = crash_base;
769 crashk_res.end = crash_base + crash_size - 1;
770 }
771
request_crashkernel(struct resource * res)772 static void __init request_crashkernel(struct resource *res)
773 {
774 int ret;
775
776 ret = request_resource(res, &crashk_res);
777 if (!ret)
778 pr_info("Reserving %ldMB of memory at %ldMB for crashkernel\n",
779 (unsigned long)((crashk_res.end -
780 crashk_res.start + 1) >> 20),
781 (unsigned long)(crashk_res.start >> 20));
782 }
783 #else /* !defined(CONFIG_KEXEC) */
mips_parse_crashkernel(void)784 static void __init mips_parse_crashkernel(void)
785 {
786 }
787
request_crashkernel(struct resource * res)788 static void __init request_crashkernel(struct resource *res)
789 {
790 }
791 #endif /* !defined(CONFIG_KEXEC) */
792
arch_mem_init(char ** cmdline_p)793 static void __init arch_mem_init(char **cmdline_p)
794 {
795 extern void plat_mem_setup(void);
796
797 /* call board setup routine */
798 plat_mem_setup();
799
800 /*
801 * Make sure all kernel memory is in the maps. The "UP" and
802 * "DOWN" are opposite for initdata since if it crosses over
803 * into another memory section you don't want that to be
804 * freed when the initdata is freed.
805 */
806 arch_mem_addpart(PFN_DOWN(__pa_symbol(&_text)) << PAGE_SHIFT,
807 PFN_UP(__pa_symbol(&_edata)) << PAGE_SHIFT,
808 BOOT_MEM_RAM);
809 arch_mem_addpart(PFN_UP(__pa_symbol(&__init_begin)) << PAGE_SHIFT,
810 PFN_DOWN(__pa_symbol(&__init_end)) << PAGE_SHIFT,
811 BOOT_MEM_INIT_RAM);
812
813 pr_info("Determined physical RAM map:\n");
814 print_memory_map();
815
816 #ifdef CONFIG_CMDLINE_BOOL
817 #ifdef CONFIG_CMDLINE_OVERRIDE
818 strlcpy(boot_command_line, builtin_cmdline, COMMAND_LINE_SIZE);
819 #else
820 if (builtin_cmdline[0]) {
821 strlcat(arcs_cmdline, " ", COMMAND_LINE_SIZE);
822 strlcat(arcs_cmdline, builtin_cmdline, COMMAND_LINE_SIZE);
823 }
824 strlcpy(boot_command_line, arcs_cmdline, COMMAND_LINE_SIZE);
825 #endif
826 #else
827 strlcpy(boot_command_line, arcs_cmdline, COMMAND_LINE_SIZE);
828 #endif
829 strlcpy(command_line, boot_command_line, COMMAND_LINE_SIZE);
830
831 *cmdline_p = command_line;
832
833 parse_early_param();
834
835 if (usermem) {
836 pr_info("User-defined physical RAM map:\n");
837 print_memory_map();
838 }
839
840 bootmem_init();
841 #ifdef CONFIG_PROC_VMCORE
842 if (setup_elfcorehdr && setup_elfcorehdr_size) {
843 printk(KERN_INFO "kdump reserved memory at %lx-%lx\n",
844 setup_elfcorehdr, setup_elfcorehdr_size);
845 reserve_bootmem(setup_elfcorehdr, setup_elfcorehdr_size,
846 BOOTMEM_DEFAULT);
847 }
848 #endif
849
850 mips_parse_crashkernel();
851 #ifdef CONFIG_KEXEC
852 if (crashk_res.start != crashk_res.end)
853 reserve_bootmem(crashk_res.start,
854 crashk_res.end - crashk_res.start + 1,
855 BOOTMEM_DEFAULT);
856 #endif
857 device_tree_init();
858 sparse_init();
859 plat_swiotlb_setup();
860 paging_init();
861 }
862
resource_init(void)863 static void __init resource_init(void)
864 {
865 int i;
866
867 if (UNCAC_BASE != IO_BASE)
868 return;
869
870 code_resource.start = __pa_symbol(&_text);
871 code_resource.end = __pa_symbol(&_etext) - 1;
872 data_resource.start = __pa_symbol(&_etext);
873 data_resource.end = __pa_symbol(&_edata) - 1;
874
875 for (i = 0; i < boot_mem_map.nr_map; i++) {
876 struct resource *res;
877 unsigned long start, end;
878
879 start = boot_mem_map.map[i].addr;
880 end = boot_mem_map.map[i].addr + boot_mem_map.map[i].size - 1;
881 if (start >= HIGHMEM_START)
882 continue;
883 if (end >= HIGHMEM_START)
884 end = HIGHMEM_START - 1;
885
886 res = alloc_bootmem(sizeof(struct resource));
887 switch (boot_mem_map.map[i].type) {
888 case BOOT_MEM_RAM:
889 case BOOT_MEM_INIT_RAM:
890 case BOOT_MEM_ROM_DATA:
891 res->name = "System RAM";
892 break;
893 case BOOT_MEM_INUSE:
894 res->name = "InUse memory";
895 break;
896 case BOOT_MEM_RESERVED:
897 default:
898 res->name = "reserved";
899 }
900
901 res->start = start;
902 res->end = end;
903
904 res->flags = IORESOURCE_MEM | IORESOURCE_BUSY;
905 request_resource(&iomem_resource, res);
906
907 /*
908 * We don't know which RAM region contains kernel data,
909 * so we try it repeatedly and let the resource manager
910 * test it.
911 */
912 request_resource(res, &code_resource);
913 request_resource(res, &data_resource);
914 request_crashkernel(res);
915 }
916 }
917
setup_arch(char ** cmdline_p)918 void __init setup_arch(char **cmdline_p)
919 {
920 cpu_probe();
921 prom_init();
922
923 #ifdef CONFIG_EARLY_PRINTK
924 setup_early_printk();
925 #endif
926 cpu_report();
927 check_bugs_early();
928
929 #if defined(CONFIG_VT)
930 #if defined(CONFIG_VGA_CONSOLE)
931 conswitchp = &vga_con;
932 #elif defined(CONFIG_DUMMY_CONSOLE)
933 conswitchp = &dummy_con;
934 #endif
935 #endif
936
937 arch_mem_init(cmdline_p);
938
939 resource_init();
940 plat_smp_setup();
941
942 cpu_cache_init();
943 }
944
945 unsigned long kernelsp[NR_CPUS];
946 unsigned long fw_arg0, fw_arg1, fw_arg2, fw_arg3;
947
948 #ifdef CONFIG_DEBUG_FS
949 struct dentry *mips_debugfs_dir;
debugfs_mips(void)950 static int __init debugfs_mips(void)
951 {
952 struct dentry *d;
953
954 d = debugfs_create_dir("mips", NULL);
955 if (!d)
956 return -ENOMEM;
957 mips_debugfs_dir = d;
958 return 0;
959 }
960 arch_initcall(debugfs_mips);
961 #endif
962