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) // SPDX-License-Identifier: GPL-2.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  * arch/sh/kernel/setup.c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  * This file handles the architecture-dependent parts of initialization
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  *  Copyright (C) 1999  Niibe Yutaka
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8)  *  Copyright (C) 2002 - 2010 Paul Mundt
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) #include <linux/screen_info.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) #include <linux/ioport.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #include <linux/initrd.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include <linux/console.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include <linux/root_dev.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #include <linux/utsname.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) #include <linux/nodemask.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) #include <linux/cpu.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) #include <linux/pfn.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) #include <linux/fs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) #include <linux/mm.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) #include <linux/kexec.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) #include <linux/smp.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) #include <linux/err.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) #include <linux/crash_dump.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) #include <linux/mmzone.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) #include <linux/clk.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) #include <linux/delay.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) #include <linux/platform_device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) #include <linux/memblock.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) #include <linux/of.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) #include <linux/of_fdt.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) #include <linux/uaccess.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) #include <uapi/linux/mount.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) #include <asm/io.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) #include <asm/page.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) #include <asm/elf.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) #include <asm/sections.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) #include <asm/irq.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) #include <asm/setup.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) #include <asm/clock.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) #include <asm/smp.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) #include <asm/mmu_context.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) #include <asm/mmzone.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) #include <asm/sparsemem.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) #include <asm/platform_early.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50)  * Initialize loops_per_jiffy as 10000000 (1000MIPS).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51)  * This value will be used at the very early stage of serial setup.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52)  * The bigger value means no problem.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) struct sh_cpuinfo cpu_data[NR_CPUS] __read_mostly = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 	[0] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 		.type			= CPU_SH_NONE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 		.family			= CPU_FAMILY_UNKNOWN,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 		.loops_per_jiffy	= 10000000,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 		.phys_bits		= MAX_PHYSMEM_BITS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) EXPORT_SYMBOL(cpu_data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65)  * The machine vector. First entry in .machvec.init, or clobbered by
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66)  * sh_mv= on the command line, prior to .machvec.init teardown.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) struct sh_machine_vector sh_mv = { .mv_name = "generic", };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) EXPORT_SYMBOL(sh_mv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) #ifdef CONFIG_VT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) struct screen_info screen_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) extern int root_mountflags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) #define RAMDISK_IMAGE_START_MASK	0x07FF
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) #define RAMDISK_PROMPT_FLAG		0x8000
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) #define RAMDISK_LOAD_FLAG		0x4000
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) static char __initdata command_line[COMMAND_LINE_SIZE] = { 0, };
^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 = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 	.name = "Kernel code",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 	.flags = IORESOURCE_BUSY | IORESOURCE_SYSTEM_RAM,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) static struct resource data_resource = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 	.name = "Kernel data",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 	.flags = IORESOURCE_BUSY | IORESOURCE_SYSTEM_RAM,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) static struct resource bss_resource = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 	.name	= "Kernel bss",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 	.flags	= IORESOURCE_BUSY | IORESOURCE_SYSTEM_RAM,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) unsigned long memory_start;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) EXPORT_SYMBOL(memory_start);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) unsigned long memory_end = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) EXPORT_SYMBOL(memory_end);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) unsigned long memory_limit = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) static struct resource mem_resources[MAX_NUMNODES];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) int l1i_cache_shape, l1d_cache_shape, l2_cache_shape;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) static int __init early_parse_mem(char *p)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 	if (!p)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 		return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 	memory_limit = PAGE_ALIGN(memparse(p, &p));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 	pr_notice("Memory limited to %ldMB\n", memory_limit >> 20);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) early_param("mem", early_parse_mem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) void __init check_for_initrd(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) #ifdef CONFIG_BLK_DEV_INITRD
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 	unsigned long start, end;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 	 * Check for the rare cases where boot loaders adhere to the boot
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 	 * ABI.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 	if (!LOADER_TYPE || !INITRD_START || !INITRD_SIZE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 		goto disable;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 	start = INITRD_START + __MEMORY_START;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 	end = start + INITRD_SIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 	if (unlikely(end <= start))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 		goto disable;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 	if (unlikely(start & ~PAGE_MASK)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 		pr_err("initrd must be page aligned\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 		goto disable;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 	if (unlikely(start < __MEMORY_START)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 		pr_err("initrd start (%08lx) < __MEMORY_START(%x)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 			start, __MEMORY_START);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 		goto disable;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 	if (unlikely(end > memblock_end_of_DRAM())) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 		pr_err("initrd extends beyond end of memory "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 		       "(0x%08lx > 0x%08lx)\ndisabling initrd\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 		       end, (unsigned long)memblock_end_of_DRAM());
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 		goto disable;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 	 * If we got this far in spite of the boot loader's best efforts
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 	 * to the contrary, assume we actually have a valid initrd and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 	 * fix up the root dev.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 	ROOT_DEV = Root_RAM0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 	 * Address sanitization
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 	initrd_start = (unsigned long)__va(start);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 	initrd_end = initrd_start + INITRD_SIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 	memblock_reserve(__pa(initrd_start), INITRD_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 	return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) disable:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 	pr_info("initrd disabled\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 	initrd_start = initrd_end = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) #ifndef CONFIG_GENERIC_CALIBRATE_DELAY
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) void calibrate_delay(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 	struct clk *clk = clk_get(NULL, "cpu_clk");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 	if (IS_ERR(clk))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 		panic("Need a sane CPU clock definition!");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 	loops_per_jiffy = (clk_get_rate(clk) >> 1) / HZ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 	printk(KERN_INFO "Calibrating delay loop (skipped)... "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 			 "%lu.%02lu BogoMIPS PRESET (lpj=%lu)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 			 loops_per_jiffy/(500000/HZ),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 			 (loops_per_jiffy/(5000/HZ)) % 100,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 			 loops_per_jiffy);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) void __init __add_active_range(unsigned int nid, unsigned long start_pfn,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 						unsigned long end_pfn)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 	struct resource *res = &mem_resources[nid];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 	unsigned long start, end;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 	WARN_ON(res->name); /* max one active range per node for now */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 	start = start_pfn << PAGE_SHIFT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 	end = end_pfn << PAGE_SHIFT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 	res->name = "System RAM";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 	res->start = start;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 	res->end = end - 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 	res->flags = IORESOURCE_SYSTEM_RAM | IORESOURCE_BUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 	if (request_resource(&iomem_resource, res)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 		pr_err("unable to request memory_resource 0x%lx 0x%lx\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 		       start_pfn, end_pfn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 	 * We don't know which RAM region contains kernel data or
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 	 * the reserved crashkernel region, so try it repeatedly
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 	 * and let the resource manager test it.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 	request_resource(res, &code_resource);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 	request_resource(res, &data_resource);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 	request_resource(res, &bss_resource);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) #ifdef CONFIG_KEXEC
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 	request_resource(res, &crashk_res);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 	 * Also make sure that there is a PMB mapping that covers this
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 	 * range before we attempt to activate it, to avoid reset by MMU.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 	 * We can hit this path with NUMA or memory hot-add.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 	pmb_bolt_mapping((unsigned long)__va(start), start, end - start,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 			 PAGE_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 	memblock_set_node(PFN_PHYS(start_pfn), PFN_PHYS(end_pfn - start_pfn),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 			  &memblock.memory, nid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) void __init __weak plat_early_device_setup(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) #ifdef CONFIG_OF_FLATTREE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) void __ref sh_fdt_init(phys_addr_t dt_phys)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 	static int done = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 	void *dt_virt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 	/* Avoid calling an __init function on secondary cpus. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 	if (done) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) #ifdef CONFIG_USE_BUILTIN_DTB
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 	dt_virt = __dtb_start;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 	dt_virt = phys_to_virt(dt_phys);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 	if (!dt_virt || !early_init_dt_scan(dt_virt)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 		pr_crit("Error: invalid device tree blob"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) 			" at physical address %p\n", (void *)dt_phys);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 		while (true)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) 			cpu_relax();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) 	done = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) void __init setup_arch(char **cmdline_p)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) 	enable_mmu();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) 	ROOT_DEV = old_decode_dev(ORIG_ROOT_DEV);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) 	printk(KERN_NOTICE "Boot params:\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) 			   "... MOUNT_ROOT_RDONLY - %08lx\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) 			   "... RAMDISK_FLAGS     - %08lx\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) 			   "... ORIG_ROOT_DEV     - %08lx\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) 			   "... LOADER_TYPE       - %08lx\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) 			   "... INITRD_START      - %08lx\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) 			   "... INITRD_SIZE       - %08lx\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) 			   MOUNT_ROOT_RDONLY, RAMDISK_FLAGS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) 			   ORIG_ROOT_DEV, LOADER_TYPE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) 			   INITRD_START, INITRD_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) #ifdef CONFIG_BLK_DEV_RAM
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) 	rd_image_start = RAMDISK_FLAGS & RAMDISK_IMAGE_START_MASK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) 	if (!MOUNT_ROOT_RDONLY)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) 		root_mountflags &= ~MS_RDONLY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) 	init_mm.start_code = (unsigned long) _text;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) 	init_mm.end_code = (unsigned long) _etext;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) 	init_mm.end_data = (unsigned long) _edata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) 	init_mm.brk = (unsigned long) _end;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) 	code_resource.start = virt_to_phys(_text);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) 	code_resource.end = virt_to_phys(_etext)-1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) 	data_resource.start = virt_to_phys(_etext);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) 	data_resource.end = virt_to_phys(_edata)-1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) 	bss_resource.start = virt_to_phys(__bss_start);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) 	bss_resource.end = virt_to_phys(__bss_stop)-1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) #ifdef CONFIG_CMDLINE_OVERWRITE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) 	strlcpy(command_line, CONFIG_CMDLINE, sizeof(command_line));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) 	strlcpy(command_line, COMMAND_LINE, sizeof(command_line));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) #ifdef CONFIG_CMDLINE_EXTEND
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) 	strlcat(command_line, " ", sizeof(command_line));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) 	strlcat(command_line, CONFIG_CMDLINE, sizeof(command_line));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) 	/* Save unparsed command line copy for /proc/cmdline */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) 	memcpy(boot_command_line, command_line, COMMAND_LINE_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) 	*cmdline_p = command_line;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) 	parse_early_param();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) 	plat_early_device_setup();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) 	sh_mv_setup();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) 	/* Let earlyprintk output early console messages */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) 	sh_early_platform_driver_probe("earlyprintk", 1, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) #ifdef CONFIG_OF_FLATTREE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) #ifdef CONFIG_USE_BUILTIN_DTB
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) 	unflatten_and_copy_device_tree();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) 	unflatten_device_tree();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) 	paging_init();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) 	/* Perform the machine specific initialisation */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) 	if (likely(sh_mv.mv_setup))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) 		sh_mv.mv_setup(cmdline_p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) 	plat_smp_setup();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) /* processor boot mode configuration */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) int generic_mode_pins(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) 	pr_warn("generic_mode_pins(): missing mode pin configuration\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) int test_mode_pin(int pin)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) 	return sh_mv.mv_mode_pins() & pin;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) }