2 * Nios2-specific parts of system setup
5 * Copyright (C) 2004 Microtronix Datacom Ltd.
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>
23 #include <asm/mmu_context.h>
24 #include <asm/sections.h>
25 #include <asm/setup.h>
26 #include <asm/cpuinfo.h>
28 unsigned long memory_start;
29 EXPORT_SYMBOL(memory_start);
31 unsigned long memory_end;
32 EXPORT_SYMBOL(memory_end);
34 static struct pt_regs fake_regs = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
38 /* Copy a short hook instruction sequence to the exception address */
39 static inline void copy_exception_handler(unsigned int addr)
41 unsigned int start = (unsigned int) exception_handler_hook;
42 volatile unsigned int tmp = 0;
45 /* The CPU exception address already points to the handler. */
49 __asm__ __volatile__ (
65 : /* no output registers */
66 : "r" (start), "r" (addr), "r" (tmp)
71 /* Copy the fast TLB miss handler */
72 static inline void copy_fast_tlb_miss_handler(unsigned int addr)
74 unsigned int start = (unsigned int) fast_handler;
75 unsigned int end = (unsigned int) fast_handler_end;
76 volatile unsigned int tmp = 0;
78 __asm__ __volatile__ (
88 : /* no output registers */
89 : "r" (start), "r" (addr), "r" (end), "r" (tmp)
95 * save args passed from u-boot, called from head.S
99 * @r6: initrd end or fdt
100 * @r7: kernel command line
102 asmlinkage void __init nios2_boot_init(unsigned r4, unsigned r5, unsigned r6,
105 unsigned dtb_passed = 0;
106 char cmdline_passed[COMMAND_LINE_SIZE] __maybe_unused = { 0, };
108 #if defined(CONFIG_NIOS2_PASS_CMDLINE)
109 if (r4 == 0x534f494e) { /* r4 is magic NIOS */
110 #if defined(CONFIG_BLK_DEV_INITRD)
111 if (r5) { /* initramfs */
115 #endif /* CONFIG_BLK_DEV_INITRD */
119 strscpy(cmdline_passed, (char *)r7, COMMAND_LINE_SIZE);
123 early_init_devtree((void *)dtb_passed);
125 #ifndef CONFIG_CMDLINE_FORCE
126 if (cmdline_passed[0])
127 strscpy(boot_command_line, cmdline_passed, COMMAND_LINE_SIZE);
128 #ifdef CONFIG_NIOS2_CMDLINE_IGNORE_DTB
130 strscpy(boot_command_line, CONFIG_CMDLINE, COMMAND_LINE_SIZE);
137 static void __init find_limits(unsigned long *min, unsigned long *max_low,
138 unsigned long *max_high)
140 *max_low = PFN_DOWN(memblock_get_current_limit());
141 *min = PFN_UP(memblock_start_of_DRAM());
142 *max_high = PFN_DOWN(memblock_end_of_DRAM());
145 void __init setup_arch(char **cmdline_p)
149 memory_start = memblock_start_of_DRAM();
150 memory_end = memblock_end_of_DRAM();
152 setup_initial_init_mm(_stext, _etext, _edata, _end);
153 init_task.thread.kregs = &fake_regs;
155 /* Keep a copy of command line */
156 *cmdline_p = boot_command_line;
158 find_limits(&min_low_pfn, &max_low_pfn, &max_pfn);
159 max_mapnr = max_low_pfn;
161 memblock_reserve(__pa_symbol(_stext), _end - _stext);
162 #ifdef CONFIG_BLK_DEV_INITRD
164 memblock_reserve(virt_to_phys((void *)initrd_start),
165 initrd_end - initrd_start);
167 #endif /* CONFIG_BLK_DEV_INITRD */
169 early_init_fdt_reserve_self();
170 early_init_fdt_scan_reserved_mem();
172 unflatten_and_copy_device_tree();
176 copy_exception_handler(cpuinfo.exception_addr);
180 copy_fast_tlb_miss_handler(cpuinfo.fast_tlb_miss_exc_addr);
183 * Initialize MMU context handling here because data from cpuinfo is
189 * get kmalloc into gear