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/bootmem.h>
20 #include <linux/memblock.h>
21 #include <linux/initrd.h>
22 #include <linux/of_fdt.h>
23 #include <linux/screen_info.h>
25 #include <asm/mmu_context.h>
26 #include <asm/sections.h>
27 #include <asm/setup.h>
28 #include <asm/cpuinfo.h>
30 unsigned long memory_start;
31 EXPORT_SYMBOL(memory_start);
33 unsigned long memory_end;
34 EXPORT_SYMBOL(memory_end);
36 unsigned long memory_size;
38 static struct pt_regs fake_regs = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
43 struct screen_info screen_info;
46 /* Copy a short hook instruction sequence to the exception address */
47 static inline void copy_exception_handler(unsigned int addr)
49 unsigned int start = (unsigned int) exception_handler_hook;
50 volatile unsigned int tmp = 0;
53 /* The CPU exception address already points to the handler. */
57 __asm__ __volatile__ (
73 : /* no output registers */
74 : "r" (start), "r" (addr), "r" (tmp)
79 /* Copy the fast TLB miss handler */
80 static inline void copy_fast_tlb_miss_handler(unsigned int addr)
82 unsigned int start = (unsigned int) fast_handler;
83 unsigned int end = (unsigned int) fast_handler_end;
84 volatile unsigned int tmp = 0;
86 __asm__ __volatile__ (
96 : /* no output registers */
97 : "r" (start), "r" (addr), "r" (end), "r" (tmp)
103 * save args passed from u-boot, called from head.S
107 * @r6: initrd end or fdt
108 * @r7: kernel command line
110 asmlinkage void __init nios2_boot_init(unsigned r4, unsigned r5, unsigned r6,
113 unsigned dtb_passed = 0;
114 char cmdline_passed[COMMAND_LINE_SIZE] __maybe_unused = { 0, };
116 #if defined(CONFIG_NIOS2_PASS_CMDLINE)
117 if (r4 == 0x534f494e) { /* r4 is magic NIOS */
118 #if defined(CONFIG_BLK_DEV_INITRD)
119 if (r5) { /* initramfs */
123 #endif /* CONFIG_BLK_DEV_INITRD */
127 strncpy(cmdline_passed, (char *)r7, COMMAND_LINE_SIZE);
131 early_init_devtree((void *)dtb_passed);
133 #ifndef CONFIG_CMDLINE_FORCE
134 if (cmdline_passed[0])
135 strncpy(boot_command_line, cmdline_passed, COMMAND_LINE_SIZE);
136 #ifdef CONFIG_NIOS2_CMDLINE_IGNORE_DTB
138 strncpy(boot_command_line, CONFIG_CMDLINE, COMMAND_LINE_SIZE);
145 void __init setup_arch(char **cmdline_p)
151 dram_start = memblock_start_of_DRAM();
152 memory_size = memblock_phys_mem_size();
153 memory_start = PAGE_ALIGN((unsigned long)__pa(_end));
154 memory_end = (unsigned long) CONFIG_NIOS2_MEM_BASE + memory_size;
156 init_mm.start_code = (unsigned long) _stext;
157 init_mm.end_code = (unsigned long) _etext;
158 init_mm.end_data = (unsigned long) _edata;
159 init_mm.brk = (unsigned long) _end;
160 init_task.thread.kregs = &fake_regs;
162 /* Keep a copy of command line */
163 *cmdline_p = boot_command_line;
165 min_low_pfn = PFN_UP(memory_start);
166 max_low_pfn = PFN_DOWN(memory_end);
167 max_mapnr = max_low_pfn;
169 memblock_reserve(dram_start, memory_start - dram_start);
170 #ifdef CONFIG_BLK_DEV_INITRD
172 memblock_reserve(virt_to_phys((void *)initrd_start),
173 initrd_end - initrd_start);
175 #endif /* CONFIG_BLK_DEV_INITRD */
177 early_init_fdt_reserve_self();
178 early_init_fdt_scan_reserved_mem();
180 unflatten_and_copy_device_tree();
184 copy_exception_handler(cpuinfo.exception_addr);
188 copy_fast_tlb_miss_handler(cpuinfo.fast_tlb_miss_exc_addr);
191 * Initialize MMU context handling here because data from cpuinfo is
197 * get kmalloc into gear
201 #if defined(CONFIG_VT) && defined(CONFIG_DUMMY_CONSOLE)
202 conswitchp = &dummy_con;