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
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
13 #include <linux/init.h>
14 #include <linux/cpu.h>
15 #include <linux/delay.h>
16 #include <linux/ioport.h>
17 #include <linux/export.h>
18 #include <linux/screen_info.h>
19 #include <linux/memblock.h>
20 #include <linux/bootmem.h>
21 #include <linux/initrd.h>
22 #include <linux/root_dev.h>
23 #include <linux/highmem.h>
24 #include <linux/console.h>
25 #include <linux/pfn.h>
26 #include <linux/debugfs.h>
27 #include <linux/kexec.h>
28 #include <linux/sizes.h>
29 #include <linux/device.h>
30 #include <linux/dma-contiguous.h>
31 #include <linux/decompress/generic.h>
32 #include <linux/of_fdt.h>
34 #include <asm/addrspace.h>
35 #include <asm/bootinfo.h>
37 #include <asm/cache.h>
40 #include <asm/debug.h>
41 #include <asm/dma-coherence.h>
42 #include <asm/sections.h>
43 #include <asm/setup.h>
44 #include <asm/smp-ops.h>
47 #ifdef CONFIG_MIPS_ELF_APPENDED_DTB
48 const char __section(.appended_dtb) __appended_dtb[0x100000];
49 #endif /* CONFIG_MIPS_ELF_APPENDED_DTB */
51 struct cpuinfo_mips cpu_data[NR_CPUS] __read_mostly;
53 EXPORT_SYMBOL(cpu_data);
56 struct screen_info screen_info;
62 * These are initialized so they are in the .data section
64 unsigned long mips_machtype __read_mostly = MACH_UNKNOWN;
66 EXPORT_SYMBOL(mips_machtype);
68 struct boot_mem_map boot_mem_map;
70 static char __initdata command_line[COMMAND_LINE_SIZE];
71 char __initdata arcs_cmdline[COMMAND_LINE_SIZE];
73 #ifdef CONFIG_CMDLINE_BOOL
74 static char __initdata builtin_cmdline[COMMAND_LINE_SIZE] = CONFIG_CMDLINE;
78 * mips_io_port_base is the begin of the address space to which x86 style
79 * I/O ports are mapped.
81 unsigned long mips_io_port_base = -1;
82 EXPORT_SYMBOL(mips_io_port_base);
84 static struct resource code_resource = { .name = "Kernel code", };
85 static struct resource data_resource = { .name = "Kernel data", };
86 static struct resource bss_resource = { .name = "Kernel bss", };
88 static void *detect_magic __initdata = detect_memory_region;
90 #ifdef CONFIG_MIPS_AUTO_PFN_OFFSET
91 unsigned long ARCH_PFN_OFFSET;
92 EXPORT_SYMBOL(ARCH_PFN_OFFSET);
95 void __init add_memory_region(phys_addr_t start, phys_addr_t size, long type)
97 int x = boot_mem_map.nr_map;
101 * If the region reaches the top of the physical address space, adjust
102 * the size slightly so that (start + size) doesn't overflow
104 if (start + size - 1 == PHYS_ADDR_MAX)
108 if (start + size < start) {
109 pr_warn("Trying to add an invalid memory region, skipped\n");
114 * Try to merge with existing entry, if any.
116 for (i = 0; i < boot_mem_map.nr_map; i++) {
117 struct boot_mem_map_entry *entry = boot_mem_map.map + i;
120 if (entry->type != type)
123 if (start + size < entry->addr)
124 continue; /* no overlap */
126 if (entry->addr + entry->size < start)
127 continue; /* no overlap */
129 top = max(entry->addr + entry->size, start + size);
130 entry->addr = min(entry->addr, start);
131 entry->size = top - entry->addr;
136 if (boot_mem_map.nr_map == BOOT_MEM_MAP_MAX) {
137 pr_err("Ooops! Too many entries in the memory map!\n");
141 boot_mem_map.map[x].addr = start;
142 boot_mem_map.map[x].size = size;
143 boot_mem_map.map[x].type = type;
144 boot_mem_map.nr_map++;
147 void __init detect_memory_region(phys_addr_t start, phys_addr_t sz_min, phys_addr_t sz_max)
149 void *dm = &detect_magic;
152 for (size = sz_min; size < sz_max; size <<= 1) {
153 if (!memcmp(dm, dm + size, sizeof(detect_magic)))
157 pr_debug("Memory: %lluMB of RAM detected at 0x%llx (min: %lluMB, max: %lluMB)\n",
158 ((unsigned long long) size) / SZ_1M,
159 (unsigned long long) start,
160 ((unsigned long long) sz_min) / SZ_1M,
161 ((unsigned long long) sz_max) / SZ_1M);
163 add_memory_region(start, size, BOOT_MEM_RAM);
166 static bool __init __maybe_unused memory_region_available(phys_addr_t start,
170 bool in_ram = false, free = true;
172 for (i = 0; i < boot_mem_map.nr_map; i++) {
173 phys_addr_t start_, end_;
175 start_ = boot_mem_map.map[i].addr;
176 end_ = boot_mem_map.map[i].addr + boot_mem_map.map[i].size;
178 switch (boot_mem_map.map[i].type) {
180 if (start >= start_ && start + size <= end_)
183 case BOOT_MEM_RESERVED:
184 if ((start >= start_ && start < end_) ||
185 (start < start_ && start + size >= start_))
193 return in_ram && free;
196 static void __init print_memory_map(void)
199 const int field = 2 * sizeof(unsigned long);
201 for (i = 0; i < boot_mem_map.nr_map; i++) {
202 printk(KERN_INFO " memory: %0*Lx @ %0*Lx ",
203 field, (unsigned long long) boot_mem_map.map[i].size,
204 field, (unsigned long long) boot_mem_map.map[i].addr);
206 switch (boot_mem_map.map[i].type) {
208 printk(KERN_CONT "(usable)\n");
210 case BOOT_MEM_INIT_RAM:
211 printk(KERN_CONT "(usable after init)\n");
213 case BOOT_MEM_ROM_DATA:
214 printk(KERN_CONT "(ROM data)\n");
216 case BOOT_MEM_RESERVED:
217 printk(KERN_CONT "(reserved)\n");
220 printk(KERN_CONT "type %lu\n", boot_mem_map.map[i].type);
229 #ifdef CONFIG_BLK_DEV_INITRD
231 static int __init rd_start_early(char *p)
233 unsigned long start = memparse(p, &p);
236 /* Guess if the sign extension was forgotten by bootloader */
240 initrd_start = start;
244 early_param("rd_start", rd_start_early);
246 static int __init rd_size_early(char *p)
248 initrd_end += memparse(p, &p);
251 early_param("rd_size", rd_size_early);
253 /* it returns the next free pfn after initrd */
254 static unsigned long __init init_initrd(void)
259 * Board specific code or command line parser should have
260 * already set up initrd_start and initrd_end. In these cases
261 * perfom sanity checks and use them if all looks good.
263 if (!initrd_start || initrd_end <= initrd_start)
266 if (initrd_start & ~PAGE_MASK) {
267 pr_err("initrd start must be page aligned\n");
272 * Sanitize initrd addresses. For example firmware
273 * can't guess if they need to pass them through
274 * 64-bits values if the kernel has been built in pure
275 * 32-bit. We need also to switch from KSEG0 to XKPHYS
276 * addresses now, so the code can now safely use __pa().
278 end = __pa(initrd_end);
279 initrd_end = (unsigned long)__va(end);
280 initrd_start = (unsigned long)__va(__pa(initrd_start));
282 if (initrd_start < PAGE_OFFSET) {
283 pr_err("initrd start < PAGE_OFFSET\n");
287 ROOT_DEV = Root_RAM0;
295 /* In some conditions (e.g. big endian bootloader with a little endian
296 kernel), the initrd might appear byte swapped. Try to detect this and
297 byte swap it if needed. */
298 static void __init maybe_bswap_initrd(void)
300 #if defined(CONFIG_CPU_CAVIUM_OCTEON)
303 /* Check for CPIO signature */
304 if (!memcmp((void *)initrd_start, "070701", 6))
307 /* Check for compressed initrd */
308 if (decompress_method((unsigned char *)initrd_start, 8, NULL))
311 /* Try again with a byte swapped header */
312 buf = swab64p((u64 *)initrd_start);
313 if (!memcmp(&buf, "070701", 6) ||
314 decompress_method((unsigned char *)(&buf), 8, NULL)) {
317 pr_info("Byteswapped initrd detected\n");
318 for (i = initrd_start; i < ALIGN(initrd_end, 8); i += 8)
324 static void __init finalize_initrd(void)
326 unsigned long size = initrd_end - initrd_start;
329 printk(KERN_INFO "Initrd not found or empty");
332 if (__pa(initrd_end) > PFN_PHYS(max_low_pfn)) {
333 printk(KERN_ERR "Initrd extends beyond end of memory");
337 maybe_bswap_initrd();
339 reserve_bootmem(__pa(initrd_start), size, BOOTMEM_DEFAULT);
340 initrd_below_start_ok = 1;
342 pr_info("Initial ramdisk at: 0x%lx (%lu bytes)\n",
346 printk(KERN_CONT " - disabling initrd\n");
351 #else /* !CONFIG_BLK_DEV_INITRD */
353 static unsigned long __init init_initrd(void)
358 #define finalize_initrd() do {} while (0)
363 * Initialize the bootmem allocator. It also setup initrd related data
366 #if defined(CONFIG_SGI_IP27) || (defined(CONFIG_CPU_LOONGSON3) && defined(CONFIG_NUMA))
368 static void __init bootmem_init(void)
374 #else /* !CONFIG_SGI_IP27 */
376 static unsigned long __init bootmap_bytes(unsigned long pages)
378 unsigned long bytes = DIV_ROUND_UP(pages, 8);
380 return ALIGN(bytes, sizeof(long));
383 static void __init bootmem_init(void)
385 unsigned long reserved_end;
386 unsigned long mapstart = ~0UL;
387 unsigned long bootmap_size;
388 phys_addr_t ramstart = PHYS_ADDR_MAX;
389 bool bootmap_valid = false;
393 * Sanity check any INITRD first. We don't take it into account
394 * for bootmem setup initially, rely on the end-of-kernel-code
395 * as our memory range starting point. Once bootmem is inited we
396 * will reserve the area used for the initrd.
399 reserved_end = (unsigned long) PFN_UP(__pa_symbol(&_end));
402 * max_low_pfn is not a number of pages. The number of pages
403 * of the system is given by 'max_low_pfn - min_low_pfn'.
409 * Find the highest page frame number we have available
410 * and the lowest used RAM address
412 for (i = 0; i < boot_mem_map.nr_map; i++) {
413 unsigned long start, end;
415 if (boot_mem_map.map[i].type != BOOT_MEM_RAM)
418 start = PFN_UP(boot_mem_map.map[i].addr);
419 end = PFN_DOWN(boot_mem_map.map[i].addr
420 + boot_mem_map.map[i].size);
422 ramstart = min(ramstart, boot_mem_map.map[i].addr);
424 #ifndef CONFIG_HIGHMEM
426 * Skip highmem here so we get an accurate max_low_pfn if low
427 * memory stops short of high memory.
428 * If the region overlaps HIGHMEM_START, end is clipped so
429 * max_pfn excludes the highmem portion.
431 if (start >= PFN_DOWN(HIGHMEM_START))
433 if (end > PFN_DOWN(HIGHMEM_START))
434 end = PFN_DOWN(HIGHMEM_START);
437 if (end > max_low_pfn)
439 if (start < min_low_pfn)
441 if (end <= reserved_end)
443 #ifdef CONFIG_BLK_DEV_INITRD
444 /* Skip zones before initrd and initrd itself */
445 if (initrd_end && end <= (unsigned long)PFN_UP(__pa(initrd_end)))
448 if (start >= mapstart)
450 mapstart = max(reserved_end, start);
453 if (min_low_pfn >= max_low_pfn)
454 panic("Incorrect memory mapping !!!");
456 #ifdef CONFIG_MIPS_AUTO_PFN_OFFSET
457 ARCH_PFN_OFFSET = PFN_UP(ramstart);
460 * Reserve any memory between the start of RAM and PHYS_OFFSET
462 if (ramstart > PHYS_OFFSET)
463 add_memory_region(PHYS_OFFSET, ramstart - PHYS_OFFSET,
466 if (min_low_pfn > ARCH_PFN_OFFSET) {
467 pr_info("Wasting %lu bytes for tracking %lu unused pages\n",
468 (min_low_pfn - ARCH_PFN_OFFSET) * sizeof(struct page),
469 min_low_pfn - ARCH_PFN_OFFSET);
470 } else if (ARCH_PFN_OFFSET - min_low_pfn > 0UL) {
471 pr_info("%lu free pages won't be used\n",
472 ARCH_PFN_OFFSET - min_low_pfn);
474 min_low_pfn = ARCH_PFN_OFFSET;
478 * Determine low and high memory ranges
480 max_pfn = max_low_pfn;
481 if (max_low_pfn > PFN_DOWN(HIGHMEM_START)) {
482 #ifdef CONFIG_HIGHMEM
483 highstart_pfn = PFN_DOWN(HIGHMEM_START);
484 highend_pfn = max_low_pfn;
486 max_low_pfn = PFN_DOWN(HIGHMEM_START);
489 #ifdef CONFIG_BLK_DEV_INITRD
491 * mapstart should be after initrd_end
494 mapstart = max(mapstart, (unsigned long)PFN_UP(__pa(initrd_end)));
498 * check that mapstart doesn't overlap with any of
499 * memory regions that have been reserved through eg. DTB
501 bootmap_size = bootmap_bytes(max_low_pfn - min_low_pfn);
503 bootmap_valid = memory_region_available(PFN_PHYS(mapstart),
505 for (i = 0; i < boot_mem_map.nr_map && !bootmap_valid; i++) {
506 unsigned long mapstart_addr;
508 switch (boot_mem_map.map[i].type) {
509 case BOOT_MEM_RESERVED:
510 mapstart_addr = PFN_ALIGN(boot_mem_map.map[i].addr +
511 boot_mem_map.map[i].size);
512 if (PHYS_PFN(mapstart_addr) < mapstart)
515 bootmap_valid = memory_region_available(mapstart_addr,
518 mapstart = PHYS_PFN(mapstart_addr);
526 panic("No memory area to place a bootmap bitmap");
529 * Initialize the boot-time allocator with low memory only.
531 if (bootmap_size != init_bootmem_node(NODE_DATA(0), mapstart,
532 min_low_pfn, max_low_pfn))
533 panic("Unexpected memory size required for bootmap");
535 for (i = 0; i < boot_mem_map.nr_map; i++) {
536 unsigned long start, end;
538 start = PFN_UP(boot_mem_map.map[i].addr);
539 end = PFN_DOWN(boot_mem_map.map[i].addr
540 + boot_mem_map.map[i].size);
542 if (start <= min_low_pfn)
547 #ifndef CONFIG_HIGHMEM
548 if (end > max_low_pfn)
552 * ... finally, is the area going away?
558 memblock_add_node(PFN_PHYS(start), PFN_PHYS(end - start), 0);
562 * Register fully available low RAM pages with the bootmem allocator.
564 for (i = 0; i < boot_mem_map.nr_map; i++) {
565 unsigned long start, end, size;
567 start = PFN_UP(boot_mem_map.map[i].addr);
568 end = PFN_DOWN(boot_mem_map.map[i].addr
569 + boot_mem_map.map[i].size);
572 * Reserve usable memory.
574 switch (boot_mem_map.map[i].type) {
577 case BOOT_MEM_INIT_RAM:
578 memory_present(0, start, end);
581 /* Not usable memory */
582 if (start > min_low_pfn && end < max_low_pfn)
583 reserve_bootmem(boot_mem_map.map[i].addr,
584 boot_mem_map.map[i].size,
590 * We are rounding up the start address of usable memory
591 * and at the end of the usable range downwards.
593 if (start >= max_low_pfn)
595 if (start < reserved_end)
596 start = reserved_end;
597 if (end > max_low_pfn)
601 * ... finally, is the area going away?
607 /* Register lowmem ranges */
608 free_bootmem(PFN_PHYS(start), size << PAGE_SHIFT);
609 memory_present(0, start, end);
613 * Reserve the bootmap memory.
615 reserve_bootmem(PFN_PHYS(mapstart), bootmap_size, BOOTMEM_DEFAULT);
617 #ifdef CONFIG_RELOCATABLE
619 * The kernel reserves all memory below its _end symbol as bootmem,
620 * but the kernel may now be at a much higher address. The memory
621 * between the original and new locations may be returned to the system.
623 if (__pa_symbol(_text) > __pa_symbol(VMLINUX_LOAD_ADDRESS)) {
624 unsigned long offset;
625 extern void show_kernel_relocation(const char *level);
627 offset = __pa_symbol(_text) - __pa_symbol(VMLINUX_LOAD_ADDRESS);
628 free_bootmem(__pa_symbol(VMLINUX_LOAD_ADDRESS), offset);
630 #if defined(CONFIG_DEBUG_KERNEL) && defined(CONFIG_DEBUG_INFO)
632 * This information is necessary when debugging the kernel
633 * But is a security vulnerability otherwise!
635 show_kernel_relocation(KERN_INFO);
641 * Reserve initrd memory if needed.
646 #endif /* CONFIG_SGI_IP27 */
649 * arch_mem_init - initialize memory management subsystem
651 * o plat_mem_setup() detects the memory configuration and will record detected
652 * memory areas using add_memory_region.
654 * At this stage the memory configuration of the system is known to the
655 * kernel but generic memory management system is still entirely uninitialized.
660 * o dma_contiguous_reserve()
662 * At this stage the bootmem allocator is ready to use.
664 * NOTE: historically plat_mem_setup did the entire platform initialization.
665 * This was rather impractical because it meant plat_mem_setup had to
666 * get away without any kind of memory allocator. To keep old code from
667 * breaking plat_setup was just renamed to plat_mem_setup and a second platform
668 * initialization hook for anything else was introduced.
671 static int usermem __initdata;
673 static int __init early_parse_mem(char *p)
675 phys_addr_t start, size;
678 * If a user specifies memory size, we
679 * blow away any automatically generated
683 boot_mem_map.nr_map = 0;
687 size = memparse(p, &p);
689 start = memparse(p + 1, &p);
691 add_memory_region(start, size, BOOT_MEM_RAM);
695 early_param("mem", early_parse_mem);
697 static int __init early_parse_memmap(char *p)
700 u64 start_at, mem_size;
705 if (!strncmp(p, "exactmap", 8)) {
706 pr_err("\"memmap=exactmap\" invalid on MIPS\n");
711 mem_size = memparse(p, &p);
716 start_at = memparse(p+1, &p);
717 add_memory_region(start_at, mem_size, BOOT_MEM_RAM);
718 } else if (*p == '#') {
719 pr_err("\"memmap=nn#ss\" (force ACPI data) invalid on MIPS\n");
721 } else if (*p == '$') {
722 start_at = memparse(p+1, &p);
723 add_memory_region(start_at, mem_size, BOOT_MEM_RESERVED);
725 pr_err("\"memmap\" invalid format!\n");
735 early_param("memmap", early_parse_memmap);
737 #ifdef CONFIG_PROC_VMCORE
738 unsigned long setup_elfcorehdr, setup_elfcorehdr_size;
739 static int __init early_parse_elfcorehdr(char *p)
743 setup_elfcorehdr = memparse(p, &p);
745 for (i = 0; i < boot_mem_map.nr_map; i++) {
746 unsigned long start = boot_mem_map.map[i].addr;
747 unsigned long end = (boot_mem_map.map[i].addr +
748 boot_mem_map.map[i].size);
749 if (setup_elfcorehdr >= start && setup_elfcorehdr < end) {
751 * Reserve from the elf core header to the end of
752 * the memory segment, that should all be kdump
755 setup_elfcorehdr_size = end - setup_elfcorehdr;
760 * If we don't find it in the memory map, then we shouldn't
761 * have to worry about it, as the new kernel won't use it.
765 early_param("elfcorehdr", early_parse_elfcorehdr);
768 static void __init arch_mem_addpart(phys_addr_t mem, phys_addr_t end, int type)
777 /* Make sure it is in the boot_mem_map */
778 for (i = 0; i < boot_mem_map.nr_map; i++) {
779 if (mem >= boot_mem_map.map[i].addr &&
780 mem < (boot_mem_map.map[i].addr +
781 boot_mem_map.map[i].size))
784 add_memory_region(mem, size, type);
788 static inline unsigned long long get_total_mem(void)
790 unsigned long long total;
792 total = max_pfn - min_low_pfn;
793 return total << PAGE_SHIFT;
796 static void __init mips_parse_crashkernel(void)
798 unsigned long long total_mem;
799 unsigned long long crash_size, crash_base;
802 total_mem = get_total_mem();
803 ret = parse_crashkernel(boot_command_line, total_mem,
804 &crash_size, &crash_base);
805 if (ret != 0 || crash_size <= 0)
808 if (!memory_region_available(crash_base, crash_size)) {
809 pr_warn("Invalid memory region reserved for crash kernel\n");
813 crashk_res.start = crash_base;
814 crashk_res.end = crash_base + crash_size - 1;
817 static void __init request_crashkernel(struct resource *res)
821 if (crashk_res.start == crashk_res.end)
824 ret = request_resource(res, &crashk_res);
826 pr_info("Reserving %ldMB of memory at %ldMB for crashkernel\n",
827 (unsigned long)((crashk_res.end -
828 crashk_res.start + 1) >> 20),
829 (unsigned long)(crashk_res.start >> 20));
831 #else /* !defined(CONFIG_KEXEC) */
832 static void __init mips_parse_crashkernel(void)
836 static void __init request_crashkernel(struct resource *res)
839 #endif /* !defined(CONFIG_KEXEC) */
841 #define USE_PROM_CMDLINE IS_ENABLED(CONFIG_MIPS_CMDLINE_FROM_BOOTLOADER)
842 #define USE_DTB_CMDLINE IS_ENABLED(CONFIG_MIPS_CMDLINE_FROM_DTB)
843 #define EXTEND_WITH_PROM IS_ENABLED(CONFIG_MIPS_CMDLINE_DTB_EXTEND)
844 #define BUILTIN_EXTEND_WITH_PROM \
845 IS_ENABLED(CONFIG_MIPS_CMDLINE_BUILTIN_EXTEND)
847 static void __init arch_mem_init(char **cmdline_p)
849 struct memblock_region *reg;
850 extern void plat_mem_setup(void);
853 * Initialize boot_command_line to an innocuous but non-empty string in
854 * order to prevent early_init_dt_scan_chosen() from copying
855 * CONFIG_CMDLINE into it without our knowledge. We handle
856 * CONFIG_CMDLINE ourselves below & don't want to duplicate its
857 * content because repeating arguments can be problematic.
859 strlcpy(boot_command_line, " ", COMMAND_LINE_SIZE);
861 /* call board setup routine */
865 * Make sure all kernel memory is in the maps. The "UP" and
866 * "DOWN" are opposite for initdata since if it crosses over
867 * into another memory section you don't want that to be
868 * freed when the initdata is freed.
870 arch_mem_addpart(PFN_DOWN(__pa_symbol(&_text)) << PAGE_SHIFT,
871 PFN_UP(__pa_symbol(&_edata)) << PAGE_SHIFT,
873 arch_mem_addpart(PFN_UP(__pa_symbol(&__init_begin)) << PAGE_SHIFT,
874 PFN_DOWN(__pa_symbol(&__init_end)) << PAGE_SHIFT,
877 pr_info("Determined physical RAM map:\n");
880 #if defined(CONFIG_CMDLINE_BOOL) && defined(CONFIG_CMDLINE_OVERRIDE)
881 strlcpy(boot_command_line, builtin_cmdline, COMMAND_LINE_SIZE);
883 if ((USE_PROM_CMDLINE && arcs_cmdline[0]) ||
884 (USE_DTB_CMDLINE && !boot_command_line[0]))
885 strlcpy(boot_command_line, arcs_cmdline, COMMAND_LINE_SIZE);
887 if (EXTEND_WITH_PROM && arcs_cmdline[0]) {
888 if (boot_command_line[0])
889 strlcat(boot_command_line, " ", COMMAND_LINE_SIZE);
890 strlcat(boot_command_line, arcs_cmdline, COMMAND_LINE_SIZE);
893 #if defined(CONFIG_CMDLINE_BOOL)
894 if (builtin_cmdline[0]) {
895 if (boot_command_line[0])
896 strlcat(boot_command_line, " ", COMMAND_LINE_SIZE);
897 strlcat(boot_command_line, builtin_cmdline, COMMAND_LINE_SIZE);
900 if (BUILTIN_EXTEND_WITH_PROM && arcs_cmdline[0]) {
901 if (boot_command_line[0])
902 strlcat(boot_command_line, " ", COMMAND_LINE_SIZE);
903 strlcat(boot_command_line, arcs_cmdline, COMMAND_LINE_SIZE);
907 strlcpy(command_line, boot_command_line, COMMAND_LINE_SIZE);
909 *cmdline_p = command_line;
914 pr_info("User-defined physical RAM map:\n");
918 early_init_fdt_reserve_self();
919 early_init_fdt_scan_reserved_mem();
922 #ifdef CONFIG_PROC_VMCORE
923 if (setup_elfcorehdr && setup_elfcorehdr_size) {
924 printk(KERN_INFO "kdump reserved memory at %lx-%lx\n",
925 setup_elfcorehdr, setup_elfcorehdr_size);
926 reserve_bootmem(setup_elfcorehdr, setup_elfcorehdr_size,
931 mips_parse_crashkernel();
933 if (crashk_res.start != crashk_res.end)
934 reserve_bootmem(crashk_res.start,
935 crashk_res.end - crashk_res.start + 1,
941 * In order to reduce the possibility of kernel panic when failed to
942 * get IO TLB memory under CONFIG_SWIOTLB, it is better to allocate
943 * low memory as small as possible before plat_swiotlb_setup(), so
944 * make sparse_init() using top-down allocation.
946 memblock_set_bottom_up(false);
948 memblock_set_bottom_up(true);
950 plat_swiotlb_setup();
952 dma_contiguous_reserve(PFN_PHYS(max_low_pfn));
953 /* Tell bootmem about cma reserved memblock section */
954 for_each_memblock(reserved, reg)
956 reserve_bootmem(reg->base, reg->size, BOOTMEM_DEFAULT);
958 reserve_bootmem_region(__pa_symbol(&__nosave_begin),
959 __pa_symbol(&__nosave_end)); /* Reserve for hibernation */
962 static void __init resource_init(void)
966 if (UNCAC_BASE != IO_BASE)
969 code_resource.start = __pa_symbol(&_text);
970 code_resource.end = __pa_symbol(&_etext) - 1;
971 data_resource.start = __pa_symbol(&_etext);
972 data_resource.end = __pa_symbol(&_edata) - 1;
973 bss_resource.start = __pa_symbol(&__bss_start);
974 bss_resource.end = __pa_symbol(&__bss_stop) - 1;
976 for (i = 0; i < boot_mem_map.nr_map; i++) {
977 struct resource *res;
978 unsigned long start, end;
980 start = boot_mem_map.map[i].addr;
981 end = boot_mem_map.map[i].addr + boot_mem_map.map[i].size - 1;
982 if (start >= HIGHMEM_START)
984 if (end >= HIGHMEM_START)
985 end = HIGHMEM_START - 1;
987 res = alloc_bootmem(sizeof(struct resource));
991 res->flags = IORESOURCE_MEM | IORESOURCE_BUSY;
993 switch (boot_mem_map.map[i].type) {
995 case BOOT_MEM_INIT_RAM:
996 case BOOT_MEM_ROM_DATA:
997 res->name = "System RAM";
998 res->flags |= IORESOURCE_SYSRAM;
1000 case BOOT_MEM_RESERVED:
1002 res->name = "reserved";
1005 request_resource(&iomem_resource, res);
1008 * We don't know which RAM region contains kernel data,
1009 * so we try it repeatedly and let the resource manager
1012 request_resource(res, &code_resource);
1013 request_resource(res, &data_resource);
1014 request_resource(res, &bss_resource);
1015 request_crashkernel(res);
1020 static void __init prefill_possible_map(void)
1022 int i, possible = num_possible_cpus();
1024 if (possible > nr_cpu_ids)
1025 possible = nr_cpu_ids;
1027 for (i = 0; i < possible; i++)
1028 set_cpu_possible(i, true);
1029 for (; i < NR_CPUS; i++)
1030 set_cpu_possible(i, false);
1032 nr_cpu_ids = possible;
1035 static inline void prefill_possible_map(void) {}
1038 void __init setup_arch(char **cmdline_p)
1044 setup_early_fdc_console();
1045 #ifdef CONFIG_EARLY_PRINTK
1046 setup_early_printk();
1051 #if defined(CONFIG_VT)
1052 #if defined(CONFIG_VGA_CONSOLE)
1053 conswitchp = &vga_con;
1054 #elif defined(CONFIG_DUMMY_CONSOLE)
1055 conswitchp = &dummy_con;
1059 arch_mem_init(cmdline_p);
1063 prefill_possible_map();
1069 unsigned long kernelsp[NR_CPUS];
1070 unsigned long fw_arg0, fw_arg1, fw_arg2, fw_arg3;
1072 #ifdef CONFIG_USE_OF
1073 unsigned long fw_passed_dtb;
1076 #ifdef CONFIG_DEBUG_FS
1077 struct dentry *mips_debugfs_dir;
1078 static int __init debugfs_mips(void)
1082 d = debugfs_create_dir("mips", NULL);
1085 mips_debugfs_dir = d;
1088 arch_initcall(debugfs_mips);
1091 #if defined(CONFIG_DMA_MAYBE_COHERENT) && !defined(CONFIG_DMA_PERDEV_COHERENT)
1092 /* User defined DMA coherency from command line. */
1093 enum coherent_io_user_state coherentio = IO_COHERENCE_DEFAULT;
1094 EXPORT_SYMBOL_GPL(coherentio);
1095 int hw_coherentio = 0; /* Actual hardware supported DMA coherency setting. */
1097 static int __init setcoherentio(char *str)
1099 coherentio = IO_COHERENCE_ENABLED;
1100 pr_info("Hardware DMA cache coherency (command line)\n");
1103 early_param("coherentio", setcoherentio);
1105 static int __init setnocoherentio(char *str)
1107 coherentio = IO_COHERENCE_DISABLED;
1108 pr_info("Software DMA cache coherency (command line)\n");
1111 early_param("nocoherentio", setnocoherentio);
1114 void __init arch_cpu_finalize_init(void)
1116 unsigned int cpu = smp_processor_id();
1118 cpu_data[cpu].udelay_val = loops_per_jiffy;
1121 if (IS_ENABLED(CONFIG_CPU_R4X00_BUGS64))