2 * Nios2-specific parts of system setup
4 * Copyright (C) 2010 Tobias Klauser <tklauser@distanz.ch>
5 * Copyright (C) 2004 Microtronix Datacom Ltd.
6 * Copyright (C) 2001 Vic Phillips <vic@microtronix.com>
8 * This file is subject to the terms and conditions of the GNU General Public
9 * License. See the file "COPYING" in the main directory of this archive
13 #include <linux/export.h>
14 #include <linux/kernel.h>
16 #include <linux/sched.h>
17 #include <linux/sched/task.h>
18 #include <linux/console.h>
19 #include <linux/memblock.h>
20 #include <linux/initrd.h>
21 #include <linux/of_fdt.h>
22 #include <linux/screen_info.h>
24 #include <asm/mmu_context.h>
25 #include <asm/sections.h>
26 #include <asm/setup.h>
27 #include <asm/cpuinfo.h>
29 unsigned long memory_start;
30 EXPORT_SYMBOL(memory_start);
32 unsigned long memory_end;
33 EXPORT_SYMBOL(memory_end);
35 static struct pt_regs fake_regs = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
40 struct screen_info screen_info;
43 /* Copy a short hook instruction sequence to the exception address */
44 static inline void copy_exception_handler(unsigned int addr)
46 unsigned int start = (unsigned int) exception_handler_hook;
47 volatile unsigned int tmp = 0;
50 /* The CPU exception address already points to the handler. */
54 __asm__ __volatile__ (
70 : /* no output registers */
71 : "r" (start), "r" (addr), "r" (tmp)
76 /* Copy the fast TLB miss handler */
77 static inline void copy_fast_tlb_miss_handler(unsigned int addr)
79 unsigned int start = (unsigned int) fast_handler;
80 unsigned int end = (unsigned int) fast_handler_end;
81 volatile unsigned int tmp = 0;
83 __asm__ __volatile__ (
93 : /* no output registers */
94 : "r" (start), "r" (addr), "r" (end), "r" (tmp)
100 * save args passed from u-boot, called from head.S
104 * @r6: initrd end or fdt
105 * @r7: kernel command line
107 asmlinkage void __init nios2_boot_init(unsigned r4, unsigned r5, unsigned r6,
110 unsigned dtb_passed = 0;
111 char cmdline_passed[COMMAND_LINE_SIZE] __maybe_unused = { 0, };
113 #if defined(CONFIG_NIOS2_PASS_CMDLINE)
114 if (r4 == 0x534f494e) { /* r4 is magic NIOS */
115 #if defined(CONFIG_BLK_DEV_INITRD)
116 if (r5) { /* initramfs */
120 #endif /* CONFIG_BLK_DEV_INITRD */
124 strlcpy(cmdline_passed, (char *)r7, COMMAND_LINE_SIZE);
128 early_init_devtree((void *)dtb_passed);
130 #ifndef CONFIG_CMDLINE_FORCE
131 if (cmdline_passed[0])
132 strlcpy(boot_command_line, cmdline_passed, COMMAND_LINE_SIZE);
133 #ifdef CONFIG_NIOS2_CMDLINE_IGNORE_DTB
135 strlcpy(boot_command_line, CONFIG_CMDLINE, COMMAND_LINE_SIZE);
142 static void __init find_limits(unsigned long *min, unsigned long *max_low,
143 unsigned long *max_high)
145 *max_low = PFN_DOWN(memblock_get_current_limit());
146 *min = PFN_UP(memblock_start_of_DRAM());
147 *max_high = PFN_DOWN(memblock_end_of_DRAM());
150 void __init setup_arch(char **cmdline_p)
156 memory_start = memblock_start_of_DRAM();
157 memory_end = memblock_end_of_DRAM();
159 setup_initial_init_mm(_stext, _etext, _edata, _end);
160 init_task.thread.kregs = &fake_regs;
162 /* Keep a copy of command line */
163 *cmdline_p = boot_command_line;
165 find_limits(&min_low_pfn, &max_low_pfn, &max_pfn);
166 max_mapnr = max_low_pfn;
168 memblock_reserve(__pa_symbol(_stext), _end - _stext);
169 #ifdef CONFIG_BLK_DEV_INITRD
171 memblock_reserve(virt_to_phys((void *)initrd_start),
172 initrd_end - initrd_start);
174 #endif /* CONFIG_BLK_DEV_INITRD */
176 early_init_fdt_reserve_self();
177 early_init_fdt_scan_reserved_mem();
179 unflatten_and_copy_device_tree();
183 copy_exception_handler(cpuinfo.exception_addr);
187 copy_fast_tlb_miss_handler(cpuinfo.fast_tlb_miss_exc_addr);
190 * Initialize MMU context handling here because data from cpuinfo is
196 * get kmalloc into gear