]>
git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blob - arch/nios2/kernel/setup.c
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/console.h>
18 #include <linux/bootmem.h>
19 #include <linux/initrd.h>
20 #include <linux/of_fdt.h>
21 #include <linux/screen_info.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 unsigned long memory_size
;
36 static struct pt_regs fake_regs
= { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
41 struct screen_info screen_info
;
44 /* Copy a short hook instruction sequence to the exception address */
45 static inline void copy_exception_handler(unsigned int addr
)
47 unsigned int start
= (unsigned int) exception_handler_hook
;
48 volatile unsigned int tmp
= 0;
51 /* The CPU exception address already points to the handler. */
55 __asm__
__volatile__ (
71 : /* no output registers */
72 : "r" (start
), "r" (addr
), "r" (tmp
)
77 /* Copy the fast TLB miss handler */
78 static inline void copy_fast_tlb_miss_handler(unsigned int addr
)
80 unsigned int start
= (unsigned int) fast_handler
;
81 unsigned int end
= (unsigned int) fast_handler_end
;
82 volatile unsigned int tmp
= 0;
84 __asm__
__volatile__ (
94 : /* no output registers */
95 : "r" (start
), "r" (addr
), "r" (end
), "r" (tmp
)
101 * save args passed from u-boot, called from head.S
105 * @r6: initrd end or fdt
106 * @r7: kernel command line
108 asmlinkage
void __init
nios2_boot_init(unsigned r4
, unsigned r5
, unsigned r6
,
111 unsigned dtb_passed
= 0;
112 char cmdline_passed
[COMMAND_LINE_SIZE
] __maybe_unused
= { 0, };
114 #if defined(CONFIG_NIOS2_PASS_CMDLINE)
115 if (r4
== 0x534f494e) { /* r4 is magic NIOS */
116 #if defined(CONFIG_BLK_DEV_INITRD)
117 if (r5
) { /* initramfs */
121 #endif /* CONFIG_BLK_DEV_INITRD */
125 strncpy(cmdline_passed
, (char *)r7
, COMMAND_LINE_SIZE
);
129 early_init_devtree((void *)dtb_passed
);
131 #ifndef CONFIG_CMDLINE_FORCE
132 if (cmdline_passed
[0])
133 strncpy(boot_command_line
, cmdline_passed
, COMMAND_LINE_SIZE
);
134 #ifdef CONFIG_NIOS2_CMDLINE_IGNORE_DTB
136 strncpy(boot_command_line
, CONFIG_CMDLINE
, COMMAND_LINE_SIZE
);
141 void __init
setup_arch(char **cmdline_p
)
147 #ifdef CONFIG_EARLY_PRINTK
148 setup_early_printk();
151 memory_start
= PAGE_ALIGN((unsigned long)__pa(_end
));
152 memory_end
= (unsigned long) CONFIG_NIOS2_MEM_BASE
+ memory_size
;
154 init_mm
.start_code
= (unsigned long) _stext
;
155 init_mm
.end_code
= (unsigned long) _etext
;
156 init_mm
.end_data
= (unsigned long) _edata
;
157 init_mm
.brk
= (unsigned long) _end
;
158 init_task
.thread
.kregs
= &fake_regs
;
160 /* Keep a copy of command line */
161 *cmdline_p
= boot_command_line
;
163 min_low_pfn
= PFN_UP(memory_start
);
164 max_low_pfn
= PFN_DOWN(memory_end
);
165 max_mapnr
= max_low_pfn
;
168 * give all the memory to the bootmap allocator, tell it to put the
169 * boot mem_map at the start of memory
171 pr_debug("init_bootmem_node(?,%#lx, %#x, %#lx)\n",
172 min_low_pfn
, PFN_DOWN(PHYS_OFFSET
), max_low_pfn
);
173 bootmap_size
= init_bootmem_node(NODE_DATA(0),
174 min_low_pfn
, PFN_DOWN(PHYS_OFFSET
),
178 * free the usable memory, we have to make sure we do not free
179 * the bootmem bitmap so we then reserve it after freeing it :-)
181 pr_debug("free_bootmem(%#lx, %#lx)\n",
182 memory_start
, memory_end
- memory_start
);
183 free_bootmem(memory_start
, memory_end
- memory_start
);
186 * Reserve the bootmem bitmap itself as well. We do this in two
187 * steps (first step was init_bootmem()) because this catches
188 * the (very unlikely) case of us accidentally initializing the
189 * bootmem allocator with an invalid RAM area.
191 * Arguments are start, size
193 pr_debug("reserve_bootmem(%#lx, %#x)\n", memory_start
, bootmap_size
);
194 reserve_bootmem(memory_start
, bootmap_size
, BOOTMEM_DEFAULT
);
196 #ifdef CONFIG_BLK_DEV_INITRD
198 reserve_bootmem(virt_to_phys((void *)initrd_start
),
199 initrd_end
- initrd_start
, BOOTMEM_DEFAULT
);
201 #endif /* CONFIG_BLK_DEV_INITRD */
203 unflatten_and_copy_device_tree();
207 copy_exception_handler(cpuinfo
.exception_addr
);
211 copy_fast_tlb_miss_handler(cpuinfo
.fast_tlb_miss_exc_addr
);
214 * Initialize MMU context handling here because data from cpuinfo is
220 * get kmalloc into gear
224 #if defined(CONFIG_VT) && defined(CONFIG_DUMMY_CONSOLE)
225 conswitchp
= &dummy_con
;