perf tools: Don't clone maps from parent when synthesizing forks
[linux/fpc-iii.git] / arch / nios2 / kernel / setup.c
blob2d0011ddd4d589392a525330de7c9cf01e494a44
1 /*
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
10 * for more details.
13 #include <linux/export.h>
14 #include <linux/kernel.h>
15 #include <linux/mm.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,
39 0, 0, 0, 0, 0, 0,
40 0};
42 #ifdef CONFIG_VT
43 struct screen_info screen_info;
44 #endif
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;
52 if (start == addr) {
53 /* The CPU exception address already points to the handler. */
54 return;
57 __asm__ __volatile__ (
58 "ldw %2,0(%0)\n"
59 "stw %2,0(%1)\n"
60 "ldw %2,4(%0)\n"
61 "stw %2,4(%1)\n"
62 "ldw %2,8(%0)\n"
63 "stw %2,8(%1)\n"
64 "flushd 0(%1)\n"
65 "flushd 4(%1)\n"
66 "flushd 8(%1)\n"
67 "flushi %1\n"
68 "addi %1,%1,4\n"
69 "flushi %1\n"
70 "addi %1,%1,4\n"
71 "flushi %1\n"
72 "flushp\n"
73 : /* no output registers */
74 : "r" (start), "r" (addr), "r" (tmp)
75 : "memory"
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__ (
87 "1:\n"
88 " ldw %3,0(%0)\n"
89 " stw %3,0(%1)\n"
90 " flushd 0(%1)\n"
91 " flushi %1\n"
92 " flushp\n"
93 " addi %0,%0,4\n"
94 " addi %1,%1,4\n"
95 " bne %0,%2,1b\n"
96 : /* no output registers */
97 : "r" (start), "r" (addr), "r" (end), "r" (tmp)
98 : "memory"
103 * save args passed from u-boot, called from head.S
105 * @r4: NIOS magic
106 * @r5: initrd start
107 * @r6: initrd end or fdt
108 * @r7: kernel command line
110 asmlinkage void __init nios2_boot_init(unsigned r4, unsigned r5, unsigned r6,
111 unsigned r7)
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 */
120 initrd_start = r5;
121 initrd_end = r6;
123 #endif /* CONFIG_BLK_DEV_INITRD */
124 dtb_passed = r6;
126 if (r7)
127 strncpy(cmdline_passed, (char *)r7, COMMAND_LINE_SIZE);
129 #endif
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
137 else
138 strncpy(boot_command_line, CONFIG_CMDLINE, COMMAND_LINE_SIZE);
139 #endif
140 #endif
142 parse_early_param();
145 void __init setup_arch(char **cmdline_p)
147 int dram_start;
149 console_verbose();
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
171 if (initrd_start) {
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();
182 setup_cpuinfo();
184 copy_exception_handler(cpuinfo.exception_addr);
186 mmu_init();
188 copy_fast_tlb_miss_handler(cpuinfo.fast_tlb_miss_exc_addr);
191 * Initialize MMU context handling here because data from cpuinfo is
192 * needed for this.
194 mmu_context_init();
197 * get kmalloc into gear
199 paging_init();
201 #if defined(CONFIG_VT) && defined(CONFIG_DUMMY_CONSOLE)
202 conswitchp = &dummy_con;
203 #endif