Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2)  * This file is subject to the terms and conditions of the GNU General Public
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  * License.  See the file "COPYING" in the main directory of this archive
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  * for more details.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  * Copyright (C) 1995 Linus Torvalds
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  * Copyright (C) 1995 Waldorf Electronics
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8)  * Copyright (C) 1994, 95, 96, 97, 98, 99, 2000, 01, 02, 03  Ralf Baechle
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9)  * Copyright (C) 1996 Stoned Elipot
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10)  * Copyright (C) 1999 Silicon Graphics, Inc.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11)  * Copyright (C) 2000, 2001, 2002, 2007	 Maciej W. Rozycki
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include <linux/ioport.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include <linux/export.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #include <linux/screen_info.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) #include <linux/memblock.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) #include <linux/initrd.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) #include <linux/root_dev.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) #include <linux/highmem.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) #include <linux/console.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) #include <linux/pfn.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) #include <linux/debugfs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) #include <linux/kexec.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) #include <linux/sizes.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) #include <linux/device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) #include <linux/dma-map-ops.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) #include <linux/decompress/generic.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) #include <linux/of_fdt.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) #include <linux/of_reserved_mem.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) #include <linux/dmi.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) #include <asm/addrspace.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) #include <asm/bootinfo.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) #include <asm/bugs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) #include <asm/cache.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) #include <asm/cdmm.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) #include <asm/cpu.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) #include <asm/debug.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) #include <asm/dma-coherence.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) #include <asm/sections.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) #include <asm/setup.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) #include <asm/smp-ops.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) #include <asm/prom.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) #ifdef CONFIG_MIPS_ELF_APPENDED_DTB
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) const char __section(".appended_dtb") __appended_dtb[0x100000];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) #endif /* CONFIG_MIPS_ELF_APPENDED_DTB */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) struct cpuinfo_mips cpu_data[NR_CPUS] __read_mostly;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) EXPORT_SYMBOL(cpu_data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) #ifdef CONFIG_VT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) struct screen_info screen_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59)  * Setup information
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61)  * These are initialized so they are in the .data section
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) unsigned long mips_machtype __read_mostly = MACH_UNKNOWN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) EXPORT_SYMBOL(mips_machtype);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) static char __initdata command_line[COMMAND_LINE_SIZE];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) char __initdata arcs_cmdline[COMMAND_LINE_SIZE];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) #ifdef CONFIG_CMDLINE_BOOL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) static const char builtin_cmdline[] __initconst = CONFIG_CMDLINE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) static const char builtin_cmdline[] __initconst = "";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77)  * mips_io_port_base is the begin of the address space to which x86 style
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78)  * I/O ports are mapped.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) unsigned long mips_io_port_base = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) EXPORT_SYMBOL(mips_io_port_base);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) static struct resource code_resource = { .name = "Kernel code", };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) static struct resource data_resource = { .name = "Kernel data", };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) static struct resource bss_resource = { .name = "Kernel bss", };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) static void *detect_magic __initdata = detect_memory_region;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) #ifdef CONFIG_MIPS_AUTO_PFN_OFFSET
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) unsigned long ARCH_PFN_OFFSET;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) EXPORT_SYMBOL(ARCH_PFN_OFFSET);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) void __init detect_memory_region(phys_addr_t start, phys_addr_t sz_min, phys_addr_t sz_max)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 	void *dm = &detect_magic;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 	phys_addr_t size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 	for (size = sz_min; size < sz_max; size <<= 1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 		if (!memcmp(dm, dm + size, sizeof(detect_magic)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 	pr_debug("Memory: %lluMB of RAM detected at 0x%llx (min: %lluMB, max: %lluMB)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 		((unsigned long long) size) / SZ_1M,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 		(unsigned long long) start,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 		((unsigned long long) sz_min) / SZ_1M,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 		((unsigned long long) sz_max) / SZ_1M);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 	memblock_add(start, size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114)  * Manage initrd
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) #ifdef CONFIG_BLK_DEV_INITRD
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) static int __init rd_start_early(char *p)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 	unsigned long start = memparse(p, &p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) #ifdef CONFIG_64BIT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 	/* Guess if the sign extension was forgotten by bootloader */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 	if (start < XKPHYS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 		start = (int)start;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 	initrd_start = start;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 	initrd_end += start;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) early_param("rd_start", rd_start_early);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) static int __init rd_size_early(char *p)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 	initrd_end += memparse(p, &p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) early_param("rd_size", rd_size_early);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) /* it returns the next free pfn after initrd */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) static unsigned long __init init_initrd(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 	unsigned long end;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 	 * Board specific code or command line parser should have
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 	 * already set up initrd_start and initrd_end. In these cases
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 	 * perfom sanity checks and use them if all looks good.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 	if (!initrd_start || initrd_end <= initrd_start)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 		goto disable;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 	if (initrd_start & ~PAGE_MASK) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 		pr_err("initrd start must be page aligned\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 		goto disable;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 	if (initrd_start < PAGE_OFFSET) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 		pr_err("initrd start < PAGE_OFFSET\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 		goto disable;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 	 * Sanitize initrd addresses. For example firmware
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 	 * can't guess if they need to pass them through
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 	 * 64-bits values if the kernel has been built in pure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 	 * 32-bit. We need also to switch from KSEG0 to XKPHYS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 	 * addresses now, so the code can now safely use __pa().
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 	end = __pa(initrd_end);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 	initrd_end = (unsigned long)__va(end);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 	initrd_start = (unsigned long)__va(__pa(initrd_start));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 	ROOT_DEV = Root_RAM0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 	return PFN_UP(end);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) disable:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 	initrd_start = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 	initrd_end = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) /* In some conditions (e.g. big endian bootloader with a little endian
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182)    kernel), the initrd might appear byte swapped.  Try to detect this and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183)    byte swap it if needed.  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) static void __init maybe_bswap_initrd(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) #if defined(CONFIG_CPU_CAVIUM_OCTEON)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 	u64 buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 	/* Check for CPIO signature */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 	if (!memcmp((void *)initrd_start, "070701", 6))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 	/* Check for compressed initrd */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 	if (decompress_method((unsigned char *)initrd_start, 8, NULL))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 	/* Try again with a byte swapped header */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 	buf = swab64p((u64 *)initrd_start);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 	if (!memcmp(&buf, "070701", 6) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 	    decompress_method((unsigned char *)(&buf), 8, NULL)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 		unsigned long i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 		pr_info("Byteswapped initrd detected\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 		for (i = initrd_start; i < ALIGN(initrd_end, 8); i += 8)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 			swab64s((u64 *)i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) static void __init finalize_initrd(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 	unsigned long size = initrd_end - initrd_start;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 	if (size == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 		printk(KERN_INFO "Initrd not found or empty");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 		goto disable;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 	if (__pa(initrd_end) > PFN_PHYS(max_low_pfn)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 		printk(KERN_ERR "Initrd extends beyond end of memory");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 		goto disable;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 	maybe_bswap_initrd();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 	memblock_reserve(__pa(initrd_start), size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 	initrd_below_start_ok = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 	pr_info("Initial ramdisk at: 0x%lx (%lu bytes)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 		initrd_start, size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 	return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) disable:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 	printk(KERN_CONT " - disabling initrd\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 	initrd_start = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 	initrd_end = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) #else  /* !CONFIG_BLK_DEV_INITRD */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) static unsigned long __init init_initrd(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) #define finalize_initrd()	do {} while (0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249)  * Initialize the bootmem allocator. It also setup initrd related data
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250)  * if needed.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) #if defined(CONFIG_SGI_IP27) || (defined(CONFIG_CPU_LOONGSON64) && defined(CONFIG_NUMA))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) static void __init bootmem_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 	init_initrd();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 	finalize_initrd();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) #else  /* !CONFIG_SGI_IP27 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) static void __init bootmem_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) 	phys_addr_t ramstart, ramend;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) 	unsigned long start, end;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 	ramstart = memblock_start_of_DRAM();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 	ramend = memblock_end_of_DRAM();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) 	 * Sanity check any INITRD first. We don't take it into account
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 	 * for bootmem setup initially, rely on the end-of-kernel-code
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) 	 * as our memory range starting point. Once bootmem is inited we
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) 	 * will reserve the area used for the initrd.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) 	init_initrd();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) 	/* Reserve memory occupied by kernel. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) 	memblock_reserve(__pa_symbol(&_text),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) 			__pa_symbol(&_end) - __pa_symbol(&_text));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) 	/* max_low_pfn is not a number of pages but the end pfn of low mem */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) #ifdef CONFIG_MIPS_AUTO_PFN_OFFSET
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) 	ARCH_PFN_OFFSET = PFN_UP(ramstart);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) 	 * Reserve any memory between the start of RAM and PHYS_OFFSET
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) 	if (ramstart > PHYS_OFFSET)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) 		memblock_reserve(PHYS_OFFSET, ramstart - PHYS_OFFSET);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) 	if (PFN_UP(ramstart) > ARCH_PFN_OFFSET) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) 		pr_info("Wasting %lu bytes for tracking %lu unused pages\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) 			(unsigned long)((PFN_UP(ramstart) - ARCH_PFN_OFFSET) * sizeof(struct page)),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) 			(unsigned long)(PFN_UP(ramstart) - ARCH_PFN_OFFSET));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) 	min_low_pfn = ARCH_PFN_OFFSET;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) 	max_pfn = PFN_DOWN(ramend);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) 	for_each_mem_pfn_range(i, MAX_NUMNODES, &start, &end, NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) 		 * Skip highmem here so we get an accurate max_low_pfn if low
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) 		 * memory stops short of high memory.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) 		 * If the region overlaps HIGHMEM_START, end is clipped so
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) 		 * max_pfn excludes the highmem portion.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) 		if (start >= PFN_DOWN(HIGHMEM_START))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) 		if (end > PFN_DOWN(HIGHMEM_START))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) 			end = PFN_DOWN(HIGHMEM_START);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) 		if (end > max_low_pfn)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) 			max_low_pfn = end;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) 	if (min_low_pfn >= max_low_pfn)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) 		panic("Incorrect memory mapping !!!");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) 	if (max_pfn > PFN_DOWN(HIGHMEM_START)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) #ifdef CONFIG_HIGHMEM
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) 		highstart_pfn = PFN_DOWN(HIGHMEM_START);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) 		highend_pfn = max_pfn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) 		max_low_pfn = PFN_DOWN(HIGHMEM_START);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) 		max_pfn = max_low_pfn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) 	 * Reserve initrd memory if needed.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) 	finalize_initrd();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) #endif	/* CONFIG_SGI_IP27 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) static int usermem __initdata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) static int __init early_parse_mem(char *p)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) 	phys_addr_t start, size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) 	 * If a user specifies memory size, we
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) 	 * blow away any automatically generated
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) 	 * size.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) 	if (usermem == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) 		usermem = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) 		memblock_remove(memblock_start_of_DRAM(),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) 			memblock_end_of_DRAM() - memblock_start_of_DRAM());
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) 	start = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) 	size = memparse(p, &p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) 	if (*p == '@')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) 		start = memparse(p + 1, &p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) 	memblock_add(start, size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) early_param("mem", early_parse_mem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) static int __init early_parse_memmap(char *p)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) 	char *oldp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) 	u64 start_at, mem_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) 	if (!p)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) 	if (!strncmp(p, "exactmap", 8)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) 		pr_err("\"memmap=exactmap\" invalid on MIPS\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) 	oldp = p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) 	mem_size = memparse(p, &p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) 	if (p == oldp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) 	if (*p == '@') {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) 		start_at = memparse(p+1, &p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) 		memblock_add(start_at, mem_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) 	} else if (*p == '#') {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) 		pr_err("\"memmap=nn#ss\" (force ACPI data) invalid on MIPS\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) 	} else if (*p == '$') {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) 		start_at = memparse(p+1, &p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) 		memblock_add(start_at, mem_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) 		memblock_reserve(start_at, mem_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) 		pr_err("\"memmap\" invalid format!\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) 	if (*p == '\0') {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) 		usermem = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) 	} else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) early_param("memmap", early_parse_memmap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) #ifdef CONFIG_PROC_VMCORE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) static unsigned long setup_elfcorehdr, setup_elfcorehdr_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) static int __init early_parse_elfcorehdr(char *p)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) 	phys_addr_t start, end;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) 	u64 i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) 	setup_elfcorehdr = memparse(p, &p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) 	for_each_mem_range(i, &start, &end) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) 		if (setup_elfcorehdr >= start && setup_elfcorehdr < end) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) 			/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) 			 * Reserve from the elf core header to the end of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) 			 * the memory segment, that should all be kdump
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) 			 * reserved memory.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) 			 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) 			setup_elfcorehdr_size = end - setup_elfcorehdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) 	 * If we don't find it in the memory map, then we shouldn't
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) 	 * have to worry about it, as the new kernel won't use it.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) early_param("elfcorehdr", early_parse_elfcorehdr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) #ifdef CONFIG_KEXEC
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) /* 64M alignment for crash kernel regions */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) #define CRASH_ALIGN	SZ_64M
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) #define CRASH_ADDR_MAX	SZ_512M
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) static void __init mips_parse_crashkernel(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) 	unsigned long long total_mem;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) 	unsigned long long crash_size, crash_base;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) 	total_mem = memblock_phys_mem_size();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) 	ret = parse_crashkernel(boot_command_line, total_mem,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) 				&crash_size, &crash_base);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) 	if (ret != 0 || crash_size <= 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) 	if (crash_base <= 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) 		crash_base = memblock_find_in_range(CRASH_ALIGN, CRASH_ADDR_MAX,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) 							crash_size, CRASH_ALIGN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) 		if (!crash_base) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) 			pr_warn("crashkernel reservation failed - No suitable area found.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) 			return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) 		unsigned long long start;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) 		start = memblock_find_in_range(crash_base, crash_base + crash_size,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) 						crash_size, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) 		if (start != crash_base) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) 			pr_warn("Invalid memory region reserved for crash kernel\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) 			return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) 	crashk_res.start = crash_base;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) 	crashk_res.end	 = crash_base + crash_size - 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) static void __init request_crashkernel(struct resource *res)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) 	if (crashk_res.start == crashk_res.end)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) 	ret = request_resource(res, &crashk_res);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) 	if (!ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) 		pr_info("Reserving %ldMB of memory at %ldMB for crashkernel\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) 			(unsigned long)(resource_size(&crashk_res) >> 20),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) 			(unsigned long)(crashk_res.start  >> 20));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) #else /* !defined(CONFIG_KEXEC)		*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) static void __init mips_parse_crashkernel(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) static void __init request_crashkernel(struct resource *res)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) #endif /* !defined(CONFIG_KEXEC)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) static void __init check_kernel_sections_mem(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) 	phys_addr_t start = __pa_symbol(&_text);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) 	phys_addr_t size = __pa_symbol(&_end) - start;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) 	if (!memblock_is_region_memory(start, size)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) 		pr_info("Kernel sections are not in the memory maps\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) 		memblock_add(start, size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) static void __init bootcmdline_append(const char *s, size_t max)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) 	if (!s[0] || !max)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) 	if (boot_command_line[0])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) 		strlcat(boot_command_line, " ", COMMAND_LINE_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) 	strlcat(boot_command_line, s, max);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) #ifdef CONFIG_OF_EARLY_FLATTREE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523) static int __init bootcmdline_scan_chosen(unsigned long node, const char *uname,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) 					  int depth, void *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) 	bool *dt_bootargs = data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527) 	const char *p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528) 	int l;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530) 	if (depth != 1 || !data ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531) 	    (strcmp(uname, "chosen") != 0 && strcmp(uname, "chosen@0") != 0))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) 	p = of_get_flat_dt_prop(node, "bootargs", &l);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) 	if (p != NULL && l > 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536) 		bootcmdline_append(p, min(l, COMMAND_LINE_SIZE));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537) 		*dt_bootargs = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540) 	return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543) #endif /* CONFIG_OF_EARLY_FLATTREE */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545) static void __init bootcmdline_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547) 	bool dt_bootargs = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550) 	 * If CMDLINE_OVERRIDE is enabled then initializing the command line is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551) 	 * trivial - we simply use the built-in command line unconditionally &
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552) 	 * unmodified.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554) 	if (IS_ENABLED(CONFIG_CMDLINE_OVERRIDE)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555) 		strlcpy(boot_command_line, builtin_cmdline, COMMAND_LINE_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560) 	 * If the user specified a built-in command line &
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561) 	 * MIPS_CMDLINE_BUILTIN_EXTEND, then the built-in command line is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562) 	 * prepended to arguments from the bootloader or DT so we'll copy them
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563) 	 * to the start of boot_command_line here. Otherwise, empty
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564) 	 * boot_command_line to undo anything early_init_dt_scan_chosen() did.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566) 	if (IS_ENABLED(CONFIG_MIPS_CMDLINE_BUILTIN_EXTEND))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567) 		strlcpy(boot_command_line, builtin_cmdline, COMMAND_LINE_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569) 		boot_command_line[0] = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 570) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 571) #ifdef CONFIG_OF_EARLY_FLATTREE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 572) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 573) 	 * If we're configured to take boot arguments from DT, look for those
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 574) 	 * now.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 575) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 576) 	if (IS_ENABLED(CONFIG_MIPS_CMDLINE_FROM_DTB) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 577) 	    IS_ENABLED(CONFIG_MIPS_CMDLINE_DTB_EXTEND))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 578) 		of_scan_flat_dt(bootcmdline_scan_chosen, &dt_bootargs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 579) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 580) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 581) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 582) 	 * If we didn't get any arguments from DT (regardless of whether that's
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 583) 	 * because we weren't configured to look for them, or because we looked
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 584) 	 * & found none) then we'll take arguments from the bootloader.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 585) 	 * plat_mem_setup() should have filled arcs_cmdline with arguments from
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 586) 	 * the bootloader.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 587) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 588) 	if (IS_ENABLED(CONFIG_MIPS_CMDLINE_DTB_EXTEND) || !dt_bootargs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 589) 		bootcmdline_append(arcs_cmdline, COMMAND_LINE_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 590) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 591) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 592) 	 * If the user specified a built-in command line & we didn't already
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 593) 	 * prepend it, we append it to boot_command_line here.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 594) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 595) 	if (IS_ENABLED(CONFIG_CMDLINE_BOOL) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 596) 	    !IS_ENABLED(CONFIG_MIPS_CMDLINE_BUILTIN_EXTEND))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 597) 		bootcmdline_append(builtin_cmdline, COMMAND_LINE_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 598) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 599) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 600) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 601)  * arch_mem_init - initialize memory management subsystem
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 602)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 603)  *  o plat_mem_setup() detects the memory configuration and will record detected
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 604)  *    memory areas using memblock_add.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 605)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 606)  * At this stage the memory configuration of the system is known to the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 607)  * kernel but generic memory management system is still entirely uninitialized.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 608)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 609)  *  o bootmem_init()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 610)  *  o sparse_init()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 611)  *  o paging_init()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 612)  *  o dma_contiguous_reserve()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 613)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 614)  * At this stage the bootmem allocator is ready to use.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 615)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 616)  * NOTE: historically plat_mem_setup did the entire platform initialization.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 617)  *	 This was rather impractical because it meant plat_mem_setup had to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 618)  * get away without any kind of memory allocator.  To keep old code from
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 619)  * breaking plat_setup was just renamed to plat_mem_setup and a second platform
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 620)  * initialization hook for anything else was introduced.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 621)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 622) static void __init arch_mem_init(char **cmdline_p)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 623) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 624) 	/* call board setup routine */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 625) 	plat_mem_setup();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 626) 	memblock_set_bottom_up(true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 627) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 628) 	bootcmdline_init();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 629) 	strlcpy(command_line, boot_command_line, COMMAND_LINE_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 630) 	*cmdline_p = command_line;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 631) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 632) 	parse_early_param();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 633) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 634) 	if (usermem)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 635) 		pr_info("User-defined physical RAM map overwrite\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 636) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 637) 	check_kernel_sections_mem();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 638) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 639) 	early_init_fdt_reserve_self();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 640) 	early_init_fdt_scan_reserved_mem();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 641) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 642) #ifndef CONFIG_NUMA
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 643) 	memblock_set_node(0, PHYS_ADDR_MAX, &memblock.memory, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 644) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 645) 	bootmem_init();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 646) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 647) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 648) 	 * Prevent memblock from allocating high memory.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 649) 	 * This cannot be done before max_low_pfn is detected, so up
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 650) 	 * to this point is possible to only reserve physical memory
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 651) 	 * with memblock_reserve; memblock_alloc* can be used
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 652) 	 * only after this point
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 653) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 654) 	memblock_set_current_limit(PFN_PHYS(max_low_pfn));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 655) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 656) #ifdef CONFIG_PROC_VMCORE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 657) 	if (setup_elfcorehdr && setup_elfcorehdr_size) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 658) 		printk(KERN_INFO "kdump reserved memory at %lx-%lx\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 659) 		       setup_elfcorehdr, setup_elfcorehdr_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 660) 		memblock_reserve(setup_elfcorehdr, setup_elfcorehdr_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 661) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 662) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 663) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 664) 	mips_parse_crashkernel();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 665) #ifdef CONFIG_KEXEC
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 666) 	if (crashk_res.start != crashk_res.end)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 667) 		memblock_reserve(crashk_res.start, resource_size(&crashk_res));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 668) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 669) 	device_tree_init();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 670) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 671) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 672) 	 * In order to reduce the possibility of kernel panic when failed to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 673) 	 * get IO TLB memory under CONFIG_SWIOTLB, it is better to allocate
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 674) 	 * low memory as small as possible before plat_swiotlb_setup(), so
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 675) 	 * make sparse_init() using top-down allocation.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 676) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 677) 	memblock_set_bottom_up(false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 678) 	sparse_init();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 679) 	memblock_set_bottom_up(true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 680) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 681) 	plat_swiotlb_setup();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 682) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 683) 	dma_contiguous_reserve(PFN_PHYS(max_low_pfn));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 684) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 685) 	/* Reserve for hibernation. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 686) 	memblock_reserve(__pa_symbol(&__nosave_begin),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 687) 		__pa_symbol(&__nosave_end) - __pa_symbol(&__nosave_begin));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 688) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 689) 	fdt_init_reserved_mem();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 690) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 691) 	memblock_dump_all();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 692) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 693) 	early_memtest(PFN_PHYS(ARCH_PFN_OFFSET), PFN_PHYS(max_low_pfn));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 694) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 695) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 696) static void __init resource_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 697) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 698) 	phys_addr_t start, end;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 699) 	u64 i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 700) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 701) 	if (UNCAC_BASE != IO_BASE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 702) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 703) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 704) 	code_resource.start = __pa_symbol(&_text);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 705) 	code_resource.end = __pa_symbol(&_etext) - 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 706) 	data_resource.start = __pa_symbol(&_etext);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 707) 	data_resource.end = __pa_symbol(&_edata) - 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 708) 	bss_resource.start = __pa_symbol(&__bss_start);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 709) 	bss_resource.end = __pa_symbol(&__bss_stop) - 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 710) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 711) 	for_each_mem_range(i, &start, &end) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 712) 		struct resource *res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 713) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 714) 		res = memblock_alloc(sizeof(struct resource), SMP_CACHE_BYTES);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 715) 		if (!res)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 716) 			panic("%s: Failed to allocate %zu bytes\n", __func__,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 717) 			      sizeof(struct resource));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 718) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 719) 		res->start = start;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 720) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 721) 		 * In memblock, end points to the first byte after the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 722) 		 * range while in resourses, end points to the last byte in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 723) 		 * the range.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 724) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 725) 		res->end = end - 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 726) 		res->flags = IORESOURCE_SYSTEM_RAM | IORESOURCE_BUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 727) 		res->name = "System RAM";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 728) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 729) 		request_resource(&iomem_resource, res);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 730) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 731) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 732) 		 *  We don't know which RAM region contains kernel data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 733) 		 *  so we try it repeatedly and let the resource manager
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 734) 		 *  test it.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 735) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 736) 		request_resource(res, &code_resource);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 737) 		request_resource(res, &data_resource);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 738) 		request_resource(res, &bss_resource);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 739) 		request_crashkernel(res);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 740) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 741) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 742) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 743) #ifdef CONFIG_SMP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 744) static void __init prefill_possible_map(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 745) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 746) 	int i, possible = num_possible_cpus();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 747) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 748) 	if (possible > nr_cpu_ids)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 749) 		possible = nr_cpu_ids;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 750) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 751) 	for (i = 0; i < possible; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 752) 		set_cpu_possible(i, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 753) 	for (; i < NR_CPUS; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 754) 		set_cpu_possible(i, false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 755) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 756) 	nr_cpu_ids = possible;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 757) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 758) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 759) static inline void prefill_possible_map(void) {}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 760) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 761) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 762) void __init setup_arch(char **cmdline_p)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 763) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 764) 	cpu_probe();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 765) 	mips_cm_probe();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 766) 	prom_init();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 767) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 768) 	setup_early_fdc_console();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 769) #ifdef CONFIG_EARLY_PRINTK
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 770) 	setup_early_printk();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 771) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 772) 	cpu_report();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 773) 	check_bugs_early();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 774) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 775) #if defined(CONFIG_VT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 776) #if defined(CONFIG_VGA_CONSOLE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 777) 	conswitchp = &vga_con;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 778) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 779) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 780) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 781) 	arch_mem_init(cmdline_p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 782) 	dmi_setup();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 783) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 784) 	resource_init();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 785) 	plat_smp_setup();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 786) 	prefill_possible_map();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 787) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 788) 	cpu_cache_init();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 789) 	paging_init();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 790) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 791) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 792) unsigned long kernelsp[NR_CPUS];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 793) unsigned long fw_arg0, fw_arg1, fw_arg2, fw_arg3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 794) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 795) #ifdef CONFIG_USE_OF
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 796) unsigned long fw_passed_dtb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 797) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 798) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 799) #ifdef CONFIG_DEBUG_FS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 800) struct dentry *mips_debugfs_dir;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 801) static int __init debugfs_mips(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 802) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 803) 	mips_debugfs_dir = debugfs_create_dir("mips", NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 804) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 805) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 806) arch_initcall(debugfs_mips);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 807) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 808) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 809) #ifdef CONFIG_DMA_MAYBE_COHERENT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 810) /* User defined DMA coherency from command line. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 811) enum coherent_io_user_state coherentio = IO_COHERENCE_DEFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 812) EXPORT_SYMBOL_GPL(coherentio);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 813) int hw_coherentio;	/* Actual hardware supported DMA coherency setting. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 814) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 815) static int __init setcoherentio(char *str)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 816) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 817) 	coherentio = IO_COHERENCE_ENABLED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 818) 	pr_info("Hardware DMA cache coherency (command line)\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 819) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 820) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 821) early_param("coherentio", setcoherentio);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 822) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 823) static int __init setnocoherentio(char *str)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 824) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 825) 	coherentio = IO_COHERENCE_DISABLED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 826) 	pr_info("Software DMA cache coherency (command line)\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 827) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 828) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 829) early_param("nocoherentio", setnocoherentio);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 830) #endif