Linux Audio

Check our new training course

Loading...
Note: File does not exist in v3.1.
  1/*
  2 * Nios2-specific parts of system setup
  3 *
  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>
  7 *
  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.
 11 */
 12
 13#include <linux/export.h>
 14#include <linux/kernel.h>
 15#include <linux/mm.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>
 22
 23#include <asm/mmu_context.h>
 24#include <asm/sections.h>
 25#include <asm/setup.h>
 26#include <asm/cpuinfo.h>
 27
 28unsigned long memory_start;
 29EXPORT_SYMBOL(memory_start);
 30
 31unsigned long memory_end;
 32EXPORT_SYMBOL(memory_end);
 33
 34unsigned long memory_size;
 35
 36static struct pt_regs fake_regs = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
 37					0, 0, 0, 0, 0, 0,
 38					0};
 39
 40#ifdef CONFIG_VT
 41struct screen_info screen_info;
 42#endif
 43
 44/* Copy a short hook instruction sequence to the exception address */
 45static inline void copy_exception_handler(unsigned int addr)
 46{
 47	unsigned int start = (unsigned int) exception_handler_hook;
 48	volatile unsigned int tmp = 0;
 49
 50	if (start == addr) {
 51		/* The CPU exception address already points to the handler. */
 52		return;
 53	}
 54
 55	__asm__ __volatile__ (
 56		"ldw	%2,0(%0)\n"
 57		"stw	%2,0(%1)\n"
 58		"ldw	%2,4(%0)\n"
 59		"stw	%2,4(%1)\n"
 60		"ldw	%2,8(%0)\n"
 61		"stw	%2,8(%1)\n"
 62		"flushd	0(%1)\n"
 63		"flushd	4(%1)\n"
 64		"flushd	8(%1)\n"
 65		"flushi %1\n"
 66		"addi	%1,%1,4\n"
 67		"flushi %1\n"
 68		"addi	%1,%1,4\n"
 69		"flushi %1\n"
 70		"flushp\n"
 71		: /* no output registers */
 72		: "r" (start), "r" (addr), "r" (tmp)
 73		: "memory"
 74	);
 75}
 76
 77/* Copy the fast TLB miss handler */
 78static inline void copy_fast_tlb_miss_handler(unsigned int addr)
 79{
 80	unsigned int start = (unsigned int) fast_handler;
 81	unsigned int end = (unsigned int) fast_handler_end;
 82	volatile unsigned int tmp = 0;
 83
 84	__asm__ __volatile__ (
 85		"1:\n"
 86		"	ldw	%3,0(%0)\n"
 87		"	stw	%3,0(%1)\n"
 88		"	flushd	0(%1)\n"
 89		"	flushi	%1\n"
 90		"	flushp\n"
 91		"	addi	%0,%0,4\n"
 92		"	addi	%1,%1,4\n"
 93		"	bne	%0,%2,1b\n"
 94		: /* no output registers */
 95		: "r" (start), "r" (addr), "r" (end), "r" (tmp)
 96		: "memory"
 97	);
 98}
 99
100/*
101 * save args passed from u-boot, called from head.S
102 *
103 * @r4: NIOS magic
104 * @r5: initrd start
105 * @r6: initrd end or fdt
106 * @r7: kernel command line
107 */
108asmlinkage void __init nios2_boot_init(unsigned r4, unsigned r5, unsigned r6,
109				       unsigned r7)
110{
111	unsigned dtb_passed = 0;
112	char cmdline_passed[COMMAND_LINE_SIZE] __maybe_unused = { 0, };
113
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 */
118			initrd_start = r5;
119			initrd_end = r6;
120		}
121#endif /* CONFIG_BLK_DEV_INITRD */
122		dtb_passed = r6;
123
124		if (r7)
125			strncpy(cmdline_passed, (char *)r7, COMMAND_LINE_SIZE);
126	}
127#endif
128
129	early_init_devtree((void *)dtb_passed);
130
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
135	else
136		strncpy(boot_command_line, CONFIG_CMDLINE, COMMAND_LINE_SIZE);
137#endif
138#endif
139}
140
141void __init setup_arch(char **cmdline_p)
142{
143	int bootmap_size;
144
145	console_verbose();
146
147#ifdef CONFIG_EARLY_PRINTK
148	setup_early_printk();
149#endif
150
151	memory_start = PAGE_ALIGN((unsigned long)__pa(_end));
152	memory_end = (unsigned long) CONFIG_NIOS2_MEM_BASE + memory_size;
153
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;
159
160	/* Keep a copy of command line */
161	*cmdline_p = boot_command_line;
162
163	min_low_pfn = PFN_UP(memory_start);
164	max_low_pfn = PFN_DOWN(memory_end);
165	max_mapnr = max_low_pfn;
166
167	/*
168	 * give all the memory to the bootmap allocator,  tell it to put the
169	 * boot mem_map at the start of memory
170	 */
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),
175					max_low_pfn);
176
177	/*
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 :-)
180	 */
181	pr_debug("free_bootmem(%#lx, %#lx)\n",
182		memory_start, memory_end - memory_start);
183	free_bootmem(memory_start, memory_end - memory_start);
184
185	/*
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.
190	 *
191	 * Arguments are start, size
192	 */
193	pr_debug("reserve_bootmem(%#lx, %#x)\n", memory_start, bootmap_size);
194	reserve_bootmem(memory_start, bootmap_size, BOOTMEM_DEFAULT);
195
196#ifdef CONFIG_BLK_DEV_INITRD
197	if (initrd_start) {
198		reserve_bootmem(virt_to_phys((void *)initrd_start),
199				initrd_end - initrd_start, BOOTMEM_DEFAULT);
200	}
201#endif /* CONFIG_BLK_DEV_INITRD */
202
203	early_init_fdt_reserve_self();
204	early_init_fdt_scan_reserved_mem();
205
206	unflatten_and_copy_device_tree();
207
208	setup_cpuinfo();
209
210	copy_exception_handler(cpuinfo.exception_addr);
211
212	mmu_init();
213
214	copy_fast_tlb_miss_handler(cpuinfo.fast_tlb_miss_exc_addr);
215
216	/*
217	 * Initialize MMU context handling here because data from cpuinfo is
218	 * needed for this.
219	 */
220	mmu_context_init();
221
222	/*
223	 * get kmalloc into gear
224	 */
225	paging_init();
226
227#if defined(CONFIG_VT) && defined(CONFIG_DUMMY_CONSOLE)
228	conswitchp = &dummy_con;
229#endif
230}