blob: 6b1ee8323090888739617ba650637c7b445bdbb4 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * linux/arch/arm/kernel/setup.c
3 *
4 * Copyright (C) 1995-2001 Russell King
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
9 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070010#include <linux/module.h>
11#include <linux/kernel.h>
12#include <linux/stddef.h>
13#include <linux/ioport.h>
14#include <linux/delay.h>
15#include <linux/utsname.h>
16#include <linux/initrd.h>
17#include <linux/console.h>
18#include <linux/bootmem.h>
19#include <linux/seq_file.h>
Jon Smirl894673e2006-07-10 04:44:13 -070020#include <linux/screen_info.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070021#include <linux/init.h>
Mika Westerberg3c57fb42010-05-10 09:20:22 +010022#include <linux/kexec.h>
Grant Likely93c02ab2011-04-28 14:27:21 -060023#include <linux/of_fdt.h>
Mika Westerbergcea0bb12010-05-10 09:29:32 +010024#include <linux/crash_dump.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070025#include <linux/root_dev.h>
26#include <linux/cpu.h>
27#include <linux/interrupt.h>
Russell King7bbb7942006-02-16 11:08:09 +000028#include <linux/smp.h>
Alexey Dobriyan4e950f62007-07-30 02:36:13 +040029#include <linux/fs.h>
Russell Kinge119bff2010-01-10 17:23:29 +000030#include <linux/proc_fs.h>
Russell King2778f622010-07-09 16:27:52 +010031#include <linux/memblock.h>
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070032#ifdef CONFIG_MEMORY_HOTPLUG
33#include <linux/memory_hotplug.h>
34#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -070035
Catalin Marinasb86040a2009-07-24 12:32:54 +010036#include <asm/unified.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070037#include <asm/cpu.h>
Russell King0ba8b9b2008-08-10 18:08:10 +010038#include <asm/cputype.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070039#include <asm/elf.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070040#include <asm/procinfo.h>
Russell King37efe642008-12-01 11:53:07 +000041#include <asm/sections.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070042#include <asm/setup.h>
Russell Kingf00ec482010-09-04 10:47:48 +010043#include <asm/smp_plat.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070044#include <asm/mach-types.h>
45#include <asm/cacheflush.h>
Russell King46097c72008-08-10 18:10:19 +010046#include <asm/cachetype.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070047#include <asm/tlbflush.h>
48
Grant Likely93c02ab2011-04-28 14:27:21 -060049#include <asm/prom.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070050#include <asm/mach/arch.h>
51#include <asm/mach/irq.h>
52#include <asm/mach/time.h>
Jason Wessel5cbad0e2008-02-20 13:33:40 -060053#include <asm/traps.h>
Catalin Marinasbff595c2009-02-16 11:41:36 +010054#include <asm/unwind.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070055
Uwe Kleine-König73a65b32010-01-19 10:13:14 +010056#if defined(CONFIG_DEPRECATED_PARAM_STRUCT)
Ben Dooks0fc1c832006-03-15 23:17:30 +000057#include "compat.h"
Uwe Kleine-König73a65b32010-01-19 10:13:14 +010058#endif
Richard Purdie4cd9d6f2008-01-02 00:56:46 +010059#include "atags.h"
Linus Walleijbc581772009-09-15 17:30:37 +010060#include "tcm.h"
Ben Dooks0fc1c832006-03-15 23:17:30 +000061
Linus Torvalds1da177e2005-04-16 15:20:36 -070062#ifndef MEM_SIZE
63#define MEM_SIZE (16*1024*1024)
64#endif
65
66#if defined(CONFIG_FPE_NWFPE) || defined(CONFIG_FPE_FASTFPE)
67char fpe_type[8];
68
69static int __init fpe_setup(char *line)
70{
71 memcpy(fpe_type, line, 8);
72 return 1;
73}
74
75__setup("fpe=", fpe_setup);
76#endif
77
Nicolas Pitre4b5f32c2008-10-06 13:24:40 -040078extern void paging_init(struct machine_desc *desc);
Russell King0371d3f2011-07-05 19:58:29 +010079extern void sanity_check_meminfo(void);
Linus Torvalds1da177e2005-04-16 15:20:36 -070080extern void reboot_setup(char *str);
Linus Torvalds1da177e2005-04-16 15:20:36 -070081
82unsigned int processor_id;
Krzysztof Halasac18f6582007-12-18 03:53:27 +010083EXPORT_SYMBOL(processor_id);
Russell King0385ebc2010-12-04 17:45:55 +000084unsigned int __machine_arch_type __read_mostly;
Linus Torvalds1da177e2005-04-16 15:20:36 -070085EXPORT_SYMBOL(__machine_arch_type);
Russell King0385ebc2010-12-04 17:45:55 +000086unsigned int cacheid __read_mostly;
Russell Kingc0e95872008-09-25 15:35:28 +010087EXPORT_SYMBOL(cacheid);
Linus Torvalds1da177e2005-04-16 15:20:36 -070088
Bill Gatliff9d20fdd2007-05-31 22:02:22 +010089unsigned int __atags_pointer __initdata;
90
Linus Torvalds1da177e2005-04-16 15:20:36 -070091unsigned int system_rev;
92EXPORT_SYMBOL(system_rev);
93
94unsigned int system_serial_low;
95EXPORT_SYMBOL(system_serial_low);
96
97unsigned int system_serial_high;
98EXPORT_SYMBOL(system_serial_high);
99
Russell King0385ebc2010-12-04 17:45:55 +0000100unsigned int elf_hwcap __read_mostly;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700101EXPORT_SYMBOL(elf_hwcap);
102
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700103unsigned int boot_reason;
104EXPORT_SYMBOL(boot_reason);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700105
106#ifdef MULTI_CPU
Russell King0385ebc2010-12-04 17:45:55 +0000107struct processor processor __read_mostly;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700108#endif
109#ifdef MULTI_TLB
Russell King0385ebc2010-12-04 17:45:55 +0000110struct cpu_tlb_fns cpu_tlb __read_mostly;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700111#endif
112#ifdef MULTI_USER
Russell King0385ebc2010-12-04 17:45:55 +0000113struct cpu_user_fns cpu_user __read_mostly;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114#endif
115#ifdef MULTI_CACHE
Russell King0385ebc2010-12-04 17:45:55 +0000116struct cpu_cache_fns cpu_cache __read_mostly;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700117#endif
Catalin Marinas953233d2007-02-05 14:48:08 +0100118#ifdef CONFIG_OUTER_CACHE
Russell King0385ebc2010-12-04 17:45:55 +0000119struct outer_cache_fns outer_cache __read_mostly;
Santosh Shilimkar6c09f092010-02-16 07:57:43 +0100120EXPORT_SYMBOL(outer_cache);
Catalin Marinas953233d2007-02-05 14:48:08 +0100121#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700122
Russell Kingccea7a12005-05-31 22:22:32 +0100123struct stack {
124 u32 irq[3];
125 u32 abt[3];
126 u32 und[3];
127} ____cacheline_aligned;
128
129static struct stack stacks[NR_CPUS];
130
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131char elf_platform[ELF_PLATFORM_SIZE];
132EXPORT_SYMBOL(elf_platform);
133
Linus Torvalds1da177e2005-04-16 15:20:36 -0700134static const char *cpu_name;
135static const char *machine_name;
Jeremy Kerr48ab7e02010-01-27 01:13:31 +0100136static char __initdata cmd_line[COMMAND_LINE_SIZE];
Russell King8ff14432010-12-20 10:18:36 +0000137struct machine_desc *machine_desc __initdata;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700138
139static char default_command_line[COMMAND_LINE_SIZE] __initdata = CONFIG_CMDLINE;
140static union { char c[4]; unsigned long l; } endian_test __initdata = { { 'l', '?', '?', 'b' } };
141#define ENDIANNESS ((char)endian_test.l)
142
143DEFINE_PER_CPU(struct cpuinfo_arm, cpu_data);
144
145/*
146 * Standard memory resources
147 */
148static struct resource mem_res[] = {
Greg Kroah-Hartman740e5182006-06-12 14:47:06 -0700149 {
150 .name = "Video RAM",
151 .start = 0,
152 .end = 0,
153 .flags = IORESOURCE_MEM
154 },
155 {
156 .name = "Kernel text",
157 .start = 0,
158 .end = 0,
159 .flags = IORESOURCE_MEM
160 },
161 {
162 .name = "Kernel data",
163 .start = 0,
164 .end = 0,
165 .flags = IORESOURCE_MEM
166 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700167};
168
169#define video_ram mem_res[0]
170#define kernel_code mem_res[1]
171#define kernel_data mem_res[2]
172
173static struct resource io_res[] = {
Greg Kroah-Hartman740e5182006-06-12 14:47:06 -0700174 {
175 .name = "reserved",
176 .start = 0x3bc,
177 .end = 0x3be,
178 .flags = IORESOURCE_IO | IORESOURCE_BUSY
179 },
180 {
181 .name = "reserved",
182 .start = 0x378,
183 .end = 0x37f,
184 .flags = IORESOURCE_IO | IORESOURCE_BUSY
185 },
186 {
187 .name = "reserved",
188 .start = 0x278,
189 .end = 0x27f,
190 .flags = IORESOURCE_IO | IORESOURCE_BUSY
191 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700192};
193
194#define lp0 io_res[0]
195#define lp1 io_res[1]
196#define lp2 io_res[2]
197
Linus Torvalds1da177e2005-04-16 15:20:36 -0700198static const char *proc_arch[] = {
199 "undefined/unknown",
200 "3",
201 "4",
202 "4T",
203 "5",
204 "5T",
205 "5TE",
206 "5TEJ",
207 "6TEJ",
Catalin Marinas6b090a22006-01-12 16:28:16 +0000208 "7",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700209 "?(11)",
210 "?(12)",
211 "?(13)",
212 "?(14)",
213 "?(15)",
214 "?(16)",
215 "?(17)",
216};
217
Linus Torvalds1da177e2005-04-16 15:20:36 -0700218int cpu_architecture(void)
219{
220 int cpu_arch;
221
Russell King0ba8b9b2008-08-10 18:08:10 +0100222 if ((read_cpuid_id() & 0x0008f000) == 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700223 cpu_arch = CPU_ARCH_UNKNOWN;
Russell King0ba8b9b2008-08-10 18:08:10 +0100224 } else if ((read_cpuid_id() & 0x0008f000) == 0x00007000) {
225 cpu_arch = (read_cpuid_id() & (1 << 23)) ? CPU_ARCH_ARMv4T : CPU_ARCH_ARMv3;
226 } else if ((read_cpuid_id() & 0x00080000) == 0x00000000) {
227 cpu_arch = (read_cpuid_id() >> 16) & 7;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700228 if (cpu_arch)
229 cpu_arch += CPU_ARCH_ARMv3;
Russell King0ba8b9b2008-08-10 18:08:10 +0100230 } else if ((read_cpuid_id() & 0x000f0000) == 0x000f0000) {
Catalin Marinas180005c2007-09-25 16:49:45 +0100231 unsigned int mmfr0;
232
233 /* Revised CPUID format. Read the Memory Model Feature
234 * Register 0 and check for VMSAv7 or PMSAv7 */
235 asm("mrc p15, 0, %0, c0, c1, 4"
236 : "=r" (mmfr0));
Catalin Marinas315cfe72011-02-15 18:06:57 +0100237 if ((mmfr0 & 0x0000000f) >= 0x00000003 ||
238 (mmfr0 & 0x000000f0) >= 0x00000030)
Catalin Marinas180005c2007-09-25 16:49:45 +0100239 cpu_arch = CPU_ARCH_ARMv7;
240 else if ((mmfr0 & 0x0000000f) == 0x00000002 ||
241 (mmfr0 & 0x000000f0) == 0x00000020)
242 cpu_arch = CPU_ARCH_ARMv6;
243 else
244 cpu_arch = CPU_ARCH_UNKNOWN;
245 } else
246 cpu_arch = CPU_ARCH_UNKNOWN;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700247
248 return cpu_arch;
249}
250
Will Deacon8925ec42010-09-13 16:18:30 +0100251static int cpu_has_aliasing_icache(unsigned int arch)
252{
253 int aliasing_icache;
254 unsigned int id_reg, num_sets, line_size;
255
256 /* arch specifies the register format */
257 switch (arch) {
258 case CPU_ARCH_ARMv7:
Linus Walleij5fb31a92010-10-06 11:07:28 +0100259 asm("mcr p15, 2, %0, c0, c0, 0 @ set CSSELR"
260 : /* No output operands */
Will Deacon8925ec42010-09-13 16:18:30 +0100261 : "r" (1));
Linus Walleij5fb31a92010-10-06 11:07:28 +0100262 isb();
263 asm("mrc p15, 1, %0, c0, c0, 0 @ read CCSIDR"
264 : "=r" (id_reg));
Will Deacon8925ec42010-09-13 16:18:30 +0100265 line_size = 4 << ((id_reg & 0x7) + 2);
266 num_sets = ((id_reg >> 13) & 0x7fff) + 1;
267 aliasing_icache = (line_size * num_sets) > PAGE_SIZE;
268 break;
269 case CPU_ARCH_ARMv6:
270 aliasing_icache = read_cpuid_cachetype() & (1 << 11);
271 break;
272 default:
273 /* I-cache aliases will be handled by D-cache aliasing code */
274 aliasing_icache = 0;
275 }
276
277 return aliasing_icache;
278}
279
Russell Kingc0e95872008-09-25 15:35:28 +0100280static void __init cacheid_init(void)
281{
282 unsigned int cachetype = read_cpuid_cachetype();
283 unsigned int arch = cpu_architecture();
284
Catalin Marinasb57ee992009-03-03 11:44:12 +0100285 if (arch >= CPU_ARCH_ARMv6) {
286 if ((cachetype & (7 << 29)) == 4 << 29) {
287 /* ARMv7 register format */
288 cacheid = CACHEID_VIPT_NONALIASING;
289 if ((cachetype & (3 << 14)) == 1 << 14)
290 cacheid |= CACHEID_ASID_TAGGED;
Will Deacon8925ec42010-09-13 16:18:30 +0100291 else if (cpu_has_aliasing_icache(CPU_ARCH_ARMv7))
292 cacheid |= CACHEID_VIPT_I_ALIASING;
293 } else if (cachetype & (1 << 23)) {
Russell Kingc0e95872008-09-25 15:35:28 +0100294 cacheid = CACHEID_VIPT_ALIASING;
Will Deacon8925ec42010-09-13 16:18:30 +0100295 } else {
Russell Kingc0e95872008-09-25 15:35:28 +0100296 cacheid = CACHEID_VIPT_NONALIASING;
Will Deacon8925ec42010-09-13 16:18:30 +0100297 if (cpu_has_aliasing_icache(CPU_ARCH_ARMv6))
298 cacheid |= CACHEID_VIPT_I_ALIASING;
299 }
Russell Kingc0e95872008-09-25 15:35:28 +0100300 } else {
301 cacheid = CACHEID_VIVT;
302 }
Russell King2b4ae1f2008-09-25 15:39:20 +0100303
304 printk("CPU: %s data cache, %s instruction cache\n",
305 cache_is_vivt() ? "VIVT" :
306 cache_is_vipt_aliasing() ? "VIPT aliasing" :
307 cache_is_vipt_nonaliasing() ? "VIPT nonaliasing" : "unknown",
308 cache_is_vivt() ? "VIVT" :
309 icache_is_vivt_asid_tagged() ? "VIVT ASID tagged" :
Will Deacon8925ec42010-09-13 16:18:30 +0100310 icache_is_vipt_aliasing() ? "VIPT aliasing" :
Russell King2b4ae1f2008-09-25 15:39:20 +0100311 cache_is_vipt_nonaliasing() ? "VIPT nonaliasing" : "unknown");
Russell Kingc0e95872008-09-25 15:35:28 +0100312}
313
Linus Torvalds1da177e2005-04-16 15:20:36 -0700314/*
315 * These functions re-use the assembly code in head.S, which
316 * already provide the required functionality.
317 */
Russell King0f44ba12006-02-24 21:04:56 +0000318extern struct proc_info_list *lookup_processor_type(unsigned int);
Russell King6fc31d52011-01-12 17:50:42 +0000319
Grant Likely93c02ab2011-04-28 14:27:21 -0600320void __init early_print(const char *str, ...)
Russell King6fc31d52011-01-12 17:50:42 +0000321{
322 extern void printascii(const char *);
323 char buf[256];
324 va_list ap;
325
326 va_start(ap, str);
327 vsnprintf(buf, sizeof(buf), str, ap);
328 va_end(ap);
329
330#ifdef CONFIG_DEBUG_LL
331 printascii(buf);
332#endif
333 printk("%s", buf);
334}
335
Tony Lindgrenf159f4e2010-07-05 14:53:10 +0100336static void __init feat_v6_fixup(void)
337{
338 int id = read_cpuid_id();
339
340 if ((id & 0xff0f0000) != 0x41070000)
341 return;
342
343 /*
344 * HWCAP_TLS is available only on 1136 r1p0 and later,
345 * see also kuser_get_tls_init.
346 */
347 if ((((id >> 4) & 0xfff) == 0xb36) && (((id >> 20) & 3) == 0))
348 elf_hwcap &= ~HWCAP_TLS;
349}
350
Linus Torvalds1da177e2005-04-16 15:20:36 -0700351static void __init setup_processor(void)
352{
353 struct proc_info_list *list;
354
355 /*
356 * locate processor in the list of supported processor
357 * types. The linker builds this table for us from the
358 * entries in arch/arm/mm/proc-*.S
359 */
Russell King0ba8b9b2008-08-10 18:08:10 +0100360 list = lookup_processor_type(read_cpuid_id());
Linus Torvalds1da177e2005-04-16 15:20:36 -0700361 if (!list) {
362 printk("CPU configuration botched (ID %08x), unable "
Russell King0ba8b9b2008-08-10 18:08:10 +0100363 "to continue.\n", read_cpuid_id());
Linus Torvalds1da177e2005-04-16 15:20:36 -0700364 while (1);
365 }
366
367 cpu_name = list->cpu_name;
368
369#ifdef MULTI_CPU
370 processor = *list->proc;
371#endif
372#ifdef MULTI_TLB
373 cpu_tlb = *list->tlb;
374#endif
375#ifdef MULTI_USER
376 cpu_user = *list->user;
377#endif
378#ifdef MULTI_CACHE
379 cpu_cache = *list->cache;
380#endif
381
Russell King4e190252006-07-03 13:29:38 +0100382 printk("CPU: %s [%08x] revision %d (ARMv%s), cr=%08lx\n",
Russell King0ba8b9b2008-08-10 18:08:10 +0100383 cpu_name, read_cpuid_id(), read_cpuid_id() & 15,
Russell King264edb32006-06-29 15:03:09 +0100384 proc_arch[cpu_architecture()], cr_alignment);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700385
Serge E. Hallyn96b644b2006-10-02 02:18:13 -0700386 sprintf(init_utsname()->machine, "%s%c", list->arch_name, ENDIANNESS);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700387 sprintf(elf_platform, "%s%c", list->elf_name, ENDIANNESS);
388 elf_hwcap = list->elf_hwcap;
Catalin Marinasadeff422006-04-10 21:32:35 +0100389#ifndef CONFIG_ARM_THUMB
390 elf_hwcap &= ~HWCAP_THUMB;
391#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700392
Tony Lindgrenf159f4e2010-07-05 14:53:10 +0100393 feat_v6_fixup();
394
Russell Kingc0e95872008-09-25 15:35:28 +0100395 cacheid_init();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700396 cpu_proc_init();
397}
398
Russell Kingccea7a12005-05-31 22:22:32 +0100399/*
400 * cpu_init - initialise one CPU.
401 *
Russell King90f1e082008-09-25 14:45:02 +0100402 * cpu_init sets up the per-CPU stacks.
Russell Kingccea7a12005-05-31 22:22:32 +0100403 */
Russell King36c5ed22005-06-19 18:39:33 +0100404void cpu_init(void)
Russell Kingccea7a12005-05-31 22:22:32 +0100405{
406 unsigned int cpu = smp_processor_id();
407 struct stack *stk = &stacks[cpu];
408
409 if (cpu >= NR_CPUS) {
410 printk(KERN_CRIT "CPU%u: bad primary CPU number\n", cpu);
411 BUG();
412 }
413
Russell Kingccea7a12005-05-31 22:22:32 +0100414 /*
Catalin Marinasb86040a2009-07-24 12:32:54 +0100415 * Define the placement constraint for the inline asm directive below.
416 * In Thumb-2, msr with an immediate value is not allowed.
417 */
418#ifdef CONFIG_THUMB2_KERNEL
419#define PLC "r"
420#else
421#define PLC "I"
422#endif
423
424 /*
Russell Kingccea7a12005-05-31 22:22:32 +0100425 * setup stacks for re-entrant exception handlers
426 */
427 __asm__ (
428 "msr cpsr_c, %1\n\t"
Catalin Marinasb86040a2009-07-24 12:32:54 +0100429 "add r14, %0, %2\n\t"
430 "mov sp, r14\n\t"
Russell Kingccea7a12005-05-31 22:22:32 +0100431 "msr cpsr_c, %3\n\t"
Catalin Marinasb86040a2009-07-24 12:32:54 +0100432 "add r14, %0, %4\n\t"
433 "mov sp, r14\n\t"
Russell Kingccea7a12005-05-31 22:22:32 +0100434 "msr cpsr_c, %5\n\t"
Catalin Marinasb86040a2009-07-24 12:32:54 +0100435 "add r14, %0, %6\n\t"
436 "mov sp, r14\n\t"
Russell Kingccea7a12005-05-31 22:22:32 +0100437 "msr cpsr_c, %7"
438 :
439 : "r" (stk),
Catalin Marinasb86040a2009-07-24 12:32:54 +0100440 PLC (PSR_F_BIT | PSR_I_BIT | IRQ_MODE),
Russell Kingccea7a12005-05-31 22:22:32 +0100441 "I" (offsetof(struct stack, irq[0])),
Catalin Marinasb86040a2009-07-24 12:32:54 +0100442 PLC (PSR_F_BIT | PSR_I_BIT | ABT_MODE),
Russell Kingccea7a12005-05-31 22:22:32 +0100443 "I" (offsetof(struct stack, abt[0])),
Catalin Marinasb86040a2009-07-24 12:32:54 +0100444 PLC (PSR_F_BIT | PSR_I_BIT | UND_MODE),
Russell Kingccea7a12005-05-31 22:22:32 +0100445 "I" (offsetof(struct stack, und[0])),
Catalin Marinasb86040a2009-07-24 12:32:54 +0100446 PLC (PSR_F_BIT | PSR_I_BIT | SVC_MODE)
Catalin Marinasaaaa3f92005-06-29 15:34:39 +0100447 : "r14");
Russell Kingccea7a12005-05-31 22:22:32 +0100448}
449
Grant Likely93c02ab2011-04-28 14:27:21 -0600450void __init dump_machine_table(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700451{
Nicolas Pitredce72dd2011-02-21 07:00:32 +0100452 struct machine_desc *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700453
Grant Likely62913192011-04-28 14:27:21 -0600454 early_print("Available machine support:\n\nID (hex)\tNAME\n");
455 for_each_machine_desc(p)
Nicolas Pitredce72dd2011-02-21 07:00:32 +0100456 early_print("%08x\t%s\n", p->nr, p->name);
457
458 early_print("\nPlease check your kernel config and/or bootloader.\n");
459
460 while (true)
461 /* can't use cpu_relax() here as it may require MMU setup */;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700462}
463
Grant Likely9eb8f672011-04-28 14:27:20 -0600464int __init arm_add_memory(phys_addr_t start, unsigned long size)
Russell King3a669412005-06-22 21:43:10 +0100465{
Nicolas Pitre4b5f32c2008-10-06 13:24:40 -0400466 struct membank *bank = &meminfo.bank[meminfo.nr_banks];
467
468 if (meminfo.nr_banks >= NR_BANKS) {
469 printk(KERN_CRIT "NR_BANKS too low, "
Will Deacon29a38192011-02-15 14:31:37 +0100470 "ignoring memory at 0x%08llx\n", (long long)start);
Nicolas Pitre4b5f32c2008-10-06 13:24:40 -0400471 return -EINVAL;
472 }
Russell King05f96ef2006-11-30 20:44:49 +0000473
Russell King3a669412005-06-22 21:43:10 +0100474 /*
475 * Ensure that start/size are aligned to a page boundary.
476 * Size is appropriately rounded down, start is rounded up.
477 */
478 size -= start & ~PAGE_MASK;
Russell King05f96ef2006-11-30 20:44:49 +0000479 bank->start = PAGE_ALIGN(start);
480 bank->size = size & PAGE_MASK;
Nicolas Pitre4b5f32c2008-10-06 13:24:40 -0400481
482 /*
483 * Check whether this memory region has non-zero size or
484 * invalid node number.
485 */
Russell Kingbe370302010-05-07 17:40:33 +0100486 if (bank->size == 0)
Nicolas Pitre4b5f32c2008-10-06 13:24:40 -0400487 return -EINVAL;
488
489 meminfo.nr_banks++;
490 return 0;
Russell King3a669412005-06-22 21:43:10 +0100491}
492
Linus Torvalds1da177e2005-04-16 15:20:36 -0700493/*
494 * Pick out the memory size. We look for mem=size@start,
495 * where start and size are "size[KkMm]"
496 */
Jeremy Kerr2b0d8c22010-01-11 23:17:34 +0100497static int __init early_mem(char *p)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700498{
499 static int usermem __initdata = 0;
Will Deaconf60892d2011-02-15 12:44:10 +0100500 unsigned long size;
501 phys_addr_t start;
Jeremy Kerr2b0d8c22010-01-11 23:17:34 +0100502 char *endp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700503
504 /*
505 * If the user specifies memory size, we
506 * blow away any automatically generated
507 * size.
508 */
509 if (usermem == 0) {
510 usermem = 1;
511 meminfo.nr_banks = 0;
512 }
513
514 start = PHYS_OFFSET;
Jeremy Kerr2b0d8c22010-01-11 23:17:34 +0100515 size = memparse(p, &endp);
516 if (*endp == '@')
517 start = memparse(endp + 1, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700518
Andrew Morton1c97b732006-04-20 21:41:18 +0100519 arm_add_memory(start, size);
Jeremy Kerr2b0d8c22010-01-11 23:17:34 +0100520
521 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700522}
Jeremy Kerr2b0d8c22010-01-11 23:17:34 +0100523early_param("mem", early_mem);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700524
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700525#ifdef CONFIG_MEMORY_HOTPLUG
526static void __init early_mem_reserved(char **p)
527{
528 unsigned int start;
529 unsigned int size;
530 unsigned int end;
531 unsigned int h_end;
532
533 start = PHYS_OFFSET;
534 size = memparse(*p, p);
535 if (**p == '@')
536 start = memparse(*p + 1, p);
537
538 if (movable_reserved_start) {
539 end = start + size;
540 h_end = movable_reserved_start + movable_reserved_size;
541 end = max(end, h_end);
542 movable_reserved_start = min(movable_reserved_start,
543 (unsigned long)start);
544 movable_reserved_size = end - movable_reserved_start;
545 } else {
546 movable_reserved_start = start;
547 movable_reserved_size = size;
548 }
549}
550__early_param("mem_reserved=", early_mem_reserved);
551
552static void __init early_mem_low_power(char **p)
553{
554 unsigned int start;
555 unsigned int size;
556 unsigned int end;
557 unsigned int h_end;
558
559 start = PHYS_OFFSET;
560 size = memparse(*p, p);
561 if (**p == '@')
562 start = memparse(*p + 1, p);
563
564 if (low_power_memory_start) {
565 end = start + size;
566 h_end = low_power_memory_start + low_power_memory_size;
567 end = max(end, h_end);
568 low_power_memory_start = min(low_power_memory_start,
569 (unsigned long)start);
570 low_power_memory_size = end - low_power_memory_start;
571 } else {
572 low_power_memory_start = start;
573 low_power_memory_size = size;
574 }
575
576 arm_add_memory(start, size);
577}
578__early_param("mem_low_power=", early_mem_low_power);
579#endif
580
Linus Torvalds1da177e2005-04-16 15:20:36 -0700581static void __init
582setup_ramdisk(int doload, int prompt, int image_start, unsigned int rd_sz)
583{
584#ifdef CONFIG_BLK_DEV_RAM
585 extern int rd_size, rd_image_start, rd_prompt, rd_doload;
586
587 rd_image_start = image_start;
588 rd_prompt = prompt;
589 rd_doload = doload;
590
591 if (rd_sz)
592 rd_size = rd_sz;
593#endif
594}
595
Dima Zavin11b93692011-01-14 23:05:14 +0100596static void __init request_standard_resources(struct machine_desc *mdesc)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700597{
Dima Zavin11b93692011-01-14 23:05:14 +0100598 struct memblock_region *region;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700599 struct resource *res;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700600
Russell King37efe642008-12-01 11:53:07 +0000601 kernel_code.start = virt_to_phys(_text);
602 kernel_code.end = virt_to_phys(_etext - 1);
Russell King842eab42010-10-01 14:12:22 +0100603 kernel_data.start = virt_to_phys(_sdata);
Russell King37efe642008-12-01 11:53:07 +0000604 kernel_data.end = virt_to_phys(_end - 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700605
Dima Zavin11b93692011-01-14 23:05:14 +0100606 for_each_memblock(memory, region) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700607 res = alloc_bootmem_low(sizeof(*res));
608 res->name = "System RAM";
Dima Zavin11b93692011-01-14 23:05:14 +0100609 res->start = __pfn_to_phys(memblock_region_memory_base_pfn(region));
610 res->end = __pfn_to_phys(memblock_region_memory_end_pfn(region)) - 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700611 res->flags = IORESOURCE_MEM | IORESOURCE_BUSY;
612
613 request_resource(&iomem_resource, res);
614
615 if (kernel_code.start >= res->start &&
616 kernel_code.end <= res->end)
617 request_resource(res, &kernel_code);
618 if (kernel_data.start >= res->start &&
619 kernel_data.end <= res->end)
620 request_resource(res, &kernel_data);
621 }
622
623 if (mdesc->video_start) {
624 video_ram.start = mdesc->video_start;
625 video_ram.end = mdesc->video_end;
626 request_resource(&iomem_resource, &video_ram);
627 }
628
629 /*
630 * Some machines don't have the possibility of ever
631 * possessing lp0, lp1 or lp2
632 */
633 if (mdesc->reserve_lp0)
634 request_resource(&ioport_resource, &lp0);
635 if (mdesc->reserve_lp1)
636 request_resource(&ioport_resource, &lp1);
637 if (mdesc->reserve_lp2)
638 request_resource(&ioport_resource, &lp2);
639}
640
641/*
642 * Tag parsing.
643 *
644 * This is the new way of passing data to the kernel at boot time. Rather
645 * than passing a fixed inflexible structure to the kernel, we pass a list
646 * of variable-sized tags to the kernel. The first tag must be a ATAG_CORE
647 * tag for the list to be recognised (to distinguish the tagged list from
648 * a param_struct). The list is terminated with a zero-length tag (this tag
649 * is not parsed in any way).
650 */
651static int __init parse_tag_core(const struct tag *tag)
652{
653 if (tag->hdr.size > 2) {
654 if ((tag->u.core.flags & 1) == 0)
655 root_mountflags &= ~MS_RDONLY;
656 ROOT_DEV = old_decode_dev(tag->u.core.rootdev);
657 }
658 return 0;
659}
660
661__tagtable(ATAG_CORE, parse_tag_core);
662
663static int __init parse_tag_mem32(const struct tag *tag)
664{
Nicolas Pitre4b5f32c2008-10-06 13:24:40 -0400665 return arm_add_memory(tag->u.mem.start, tag->u.mem.size);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700666}
667
668__tagtable(ATAG_MEM, parse_tag_mem32);
669
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700670#ifdef CONFIG_MEMORY_HOTPLUG
671static int __init parse_tag_mem32_reserved(const struct tag *tag)
672{
673 unsigned int start;
674 unsigned int size;
675 unsigned int end;
676 unsigned int h_end;
677
678 start = tag->u.mem.start;
679 size = tag->u.mem.size;
680
681 if (movable_reserved_start) {
682 end = start + size;
683 h_end = movable_reserved_start + movable_reserved_size;
684 end = max(end, h_end);
685 movable_reserved_start = min(movable_reserved_start,
686 (unsigned long)start);
687 movable_reserved_size = end - movable_reserved_start;
688 } else {
689 movable_reserved_start = tag->u.mem.start;
690 movable_reserved_size = tag->u.mem.size;
691 }
692 printk(KERN_ALERT "reserved %lx at %lx for hotplug\n",
693 movable_reserved_size, movable_reserved_start);
694
695 return 0;
696}
697
698__tagtable(ATAG_MEM_RESERVED, parse_tag_mem32_reserved);
699
700static int __init parse_tag_mem32_low_power(const struct tag *tag)
701{
702 unsigned int start;
703 unsigned int size;
704 unsigned int end;
705 unsigned int h_end;
706
707 start = tag->u.mem.start;
708 size = tag->u.mem.size;
709
710 if (low_power_memory_start) {
711 end = start + size;
712 h_end = low_power_memory_start + low_power_memory_size;
713 end = max(end, h_end);
714 low_power_memory_start = min(low_power_memory_start,
715 (unsigned long)start);
716 low_power_memory_size = end - low_power_memory_start;
717 } else {
718 low_power_memory_start = tag->u.mem.start;
719 low_power_memory_size = tag->u.mem.size;
720 }
721 printk(KERN_ALERT "low power memory %lx at %lx\n",
722 low_power_memory_size, low_power_memory_start);
723
724 return arm_add_memory(tag->u.mem.start, tag->u.mem.size);
725}
726
727__tagtable(ATAG_MEM_LOW_POWER, parse_tag_mem32_low_power);
728#endif
729
Linus Torvalds1da177e2005-04-16 15:20:36 -0700730#if defined(CONFIG_VGA_CONSOLE) || defined(CONFIG_DUMMY_CONSOLE)
731struct screen_info screen_info = {
732 .orig_video_lines = 30,
733 .orig_video_cols = 80,
734 .orig_video_mode = 0,
735 .orig_video_ega_bx = 0,
736 .orig_video_isVGA = 1,
737 .orig_video_points = 8
738};
739
740static int __init parse_tag_videotext(const struct tag *tag)
741{
742 screen_info.orig_x = tag->u.videotext.x;
743 screen_info.orig_y = tag->u.videotext.y;
744 screen_info.orig_video_page = tag->u.videotext.video_page;
745 screen_info.orig_video_mode = tag->u.videotext.video_mode;
746 screen_info.orig_video_cols = tag->u.videotext.video_cols;
747 screen_info.orig_video_ega_bx = tag->u.videotext.video_ega_bx;
748 screen_info.orig_video_lines = tag->u.videotext.video_lines;
749 screen_info.orig_video_isVGA = tag->u.videotext.video_isvga;
750 screen_info.orig_video_points = tag->u.videotext.video_points;
751 return 0;
752}
753
754__tagtable(ATAG_VIDEOTEXT, parse_tag_videotext);
755#endif
756
757static int __init parse_tag_ramdisk(const struct tag *tag)
758{
759 setup_ramdisk((tag->u.ramdisk.flags & 1) == 0,
760 (tag->u.ramdisk.flags & 2) == 0,
761 tag->u.ramdisk.start, tag->u.ramdisk.size);
762 return 0;
763}
764
765__tagtable(ATAG_RAMDISK, parse_tag_ramdisk);
766
Linus Torvalds1da177e2005-04-16 15:20:36 -0700767static int __init parse_tag_serialnr(const struct tag *tag)
768{
769 system_serial_low = tag->u.serialnr.low;
770 system_serial_high = tag->u.serialnr.high;
771 return 0;
772}
773
774__tagtable(ATAG_SERIAL, parse_tag_serialnr);
775
776static int __init parse_tag_revision(const struct tag *tag)
777{
778 system_rev = tag->u.revision.rev;
779 return 0;
780}
781
782__tagtable(ATAG_REVISION, parse_tag_revision);
783
784static int __init parse_tag_cmdline(const struct tag *tag)
785{
Victor Boivie4394c122011-05-04 17:07:55 +0100786#if defined(CONFIG_CMDLINE_EXTEND)
787 strlcat(default_command_line, " ", COMMAND_LINE_SIZE);
788 strlcat(default_command_line, tag->u.cmdline.cmdline,
789 COMMAND_LINE_SIZE);
790#elif defined(CONFIG_CMDLINE_FORCE)
Alexander Holler22eeb8f2011-01-12 14:08:37 +0100791 pr_warning("Ignoring tag cmdline (using the default kernel command line)\n");
Victor Boivie4394c122011-05-04 17:07:55 +0100792#else
793 strlcpy(default_command_line, tag->u.cmdline.cmdline,
794 COMMAND_LINE_SIZE);
795#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700796 return 0;
797}
798
799__tagtable(ATAG_CMDLINE, parse_tag_cmdline);
800
801/*
802 * Scan the tag table for this tag, and call its parse function.
803 * The tag table is built by the linker from all the __tagtable
804 * declarations.
805 */
806static int __init parse_tag(const struct tag *tag)
807{
808 extern struct tagtable __tagtable_begin, __tagtable_end;
809 struct tagtable *t;
810
811 for (t = &__tagtable_begin; t < &__tagtable_end; t++)
812 if (tag->hdr.tag == t->tag) {
813 t->parse(tag);
814 break;
815 }
816
817 return t < &__tagtable_end;
818}
819
820/*
821 * Parse all tags in the list, checking both the global and architecture
822 * specific tag tables.
823 */
824static void __init parse_tags(const struct tag *t)
825{
826 for (; t->hdr.size; t = tag_next(t))
827 if (!parse_tag(t))
828 printk(KERN_WARNING
829 "Ignoring unrecognised tag 0x%08x\n",
830 t->hdr.tag);
831}
832
833/*
834 * This holds our defaults.
835 */
836static struct init_tags {
837 struct tag_header hdr1;
838 struct tag_core core;
839 struct tag_header hdr2;
840 struct tag_mem32 mem;
841 struct tag_header hdr3;
842} init_tags __initdata = {
843 { tag_size(tag_core), ATAG_CORE },
844 { 1, PAGE_SIZE, 0xff },
845 { tag_size(tag_mem32), ATAG_MEM },
Russell Kingb75c1782011-01-04 19:03:16 +0000846 { MEM_SIZE },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700847 { 0, ATAG_NONE }
848};
849
Linus Torvalds1da177e2005-04-16 15:20:36 -0700850static int __init customize_machine(void)
851{
852 /* customizes platform devices, or adds new ones */
Russell King8ff14432010-12-20 10:18:36 +0000853 if (machine_desc->init_machine)
854 machine_desc->init_machine();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700855 return 0;
856}
857arch_initcall(customize_machine);
858
Mika Westerberg3c57fb42010-05-10 09:20:22 +0100859#ifdef CONFIG_KEXEC
860static inline unsigned long long get_total_mem(void)
861{
862 unsigned long total;
863
864 total = max_low_pfn - min_low_pfn;
865 return total << PAGE_SHIFT;
866}
867
868/**
869 * reserve_crashkernel() - reserves memory are for crash kernel
870 *
871 * This function reserves memory area given in "crashkernel=" kernel command
872 * line parameter. The memory reserved is used by a dump capture kernel when
873 * primary kernel is crashing.
874 */
875static void __init reserve_crashkernel(void)
876{
877 unsigned long long crash_size, crash_base;
878 unsigned long long total_mem;
879 int ret;
880
881 total_mem = get_total_mem();
882 ret = parse_crashkernel(boot_command_line, total_mem,
883 &crash_size, &crash_base);
884 if (ret)
885 return;
886
887 ret = reserve_bootmem(crash_base, crash_size, BOOTMEM_EXCLUSIVE);
888 if (ret < 0) {
889 printk(KERN_WARNING "crashkernel reservation failed - "
890 "memory is in use (0x%lx)\n", (unsigned long)crash_base);
891 return;
892 }
893
894 printk(KERN_INFO "Reserving %ldMB of memory at %ldMB "
895 "for crashkernel (System RAM: %ldMB)\n",
896 (unsigned long)(crash_size >> 20),
897 (unsigned long)(crash_base >> 20),
898 (unsigned long)(total_mem >> 20));
899
900 crashk_res.start = crash_base;
901 crashk_res.end = crash_base + crash_size - 1;
902 insert_resource(&iomem_resource, &crashk_res);
903}
904#else
905static inline void reserve_crashkernel(void) {}
906#endif /* CONFIG_KEXEC */
907
Uwe Kleine-König73a65b32010-01-19 10:13:14 +0100908static void __init squash_mem_tags(struct tag *tag)
909{
910 for (; tag->hdr.size; tag = tag_next(tag))
911 if (tag->hdr.tag == ATAG_MEM)
912 tag->hdr.tag = ATAG_NONE;
913}
914
Grant Likely62913192011-04-28 14:27:21 -0600915static struct machine_desc * __init setup_machine_tags(unsigned int nr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700916{
917 struct tag *tags = (struct tag *)&init_tags;
Grant Likely62913192011-04-28 14:27:21 -0600918 struct machine_desc *mdesc = NULL, *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700919 char *from = default_command_line;
920
Russell Kingb75c1782011-01-04 19:03:16 +0000921 init_tags.mem.start = PHYS_OFFSET;
922
Grant Likely62913192011-04-28 14:27:21 -0600923 /*
924 * locate machine in the list of supported machines.
925 */
926 for_each_machine_desc(p)
927 if (nr == p->nr) {
928 printk("Machine: %s\n", p->name);
929 mdesc = p;
930 break;
931 }
Catalin Marinasbff595c2009-02-16 11:41:36 +0100932
Grant Likely62913192011-04-28 14:27:21 -0600933 if (!mdesc) {
934 early_print("\nError: unrecognized/unsupported machine ID"
935 " (r1 = 0x%08x).\n\n", nr);
936 dump_machine_table(); /* does not return */
937 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700938
Bill Gatliff9d20fdd2007-05-31 22:02:22 +0100939 if (__atags_pointer)
940 tags = phys_to_virt(__atags_pointer);
Nicolas Pitre3572bea2011-02-21 06:57:33 +0100941 else if (mdesc->boot_params) {
942#ifdef CONFIG_MMU
943 /*
944 * We still are executing with a minimal MMU mapping created
945 * with the presumption that the machine default for this
946 * is located in the first MB of RAM. Anything else will
947 * fault and silently hang the kernel at this point.
948 */
949 if (mdesc->boot_params < PHYS_OFFSET ||
950 mdesc->boot_params >= PHYS_OFFSET + SZ_1M) {
951 printk(KERN_WARNING
952 "Default boot params at physical 0x%08lx out of reach\n",
953 mdesc->boot_params);
954 } else
955#endif
956 {
957 tags = phys_to_virt(mdesc->boot_params);
958 }
959 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700960
Uwe Kleine-König73a65b32010-01-19 10:13:14 +0100961#if defined(CONFIG_DEPRECATED_PARAM_STRUCT)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700962 /*
963 * If we have the old style parameters, convert them to
964 * a tag list.
965 */
966 if (tags->hdr.tag != ATAG_CORE)
967 convert_to_tag_list(tags);
Uwe Kleine-König73a65b32010-01-19 10:13:14 +0100968#endif
Grant Likely93c02ab2011-04-28 14:27:21 -0600969
970 if (tags->hdr.tag != ATAG_CORE) {
971#if defined(CONFIG_OF)
972 /*
973 * If CONFIG_OF is set, then assume this is a reasonably
974 * modern system that should pass boot parameters
975 */
976 early_print("Warning: Neither atags nor dtb found\n");
977#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700978 tags = (struct tag *)&init_tags;
Grant Likely93c02ab2011-04-28 14:27:21 -0600979 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700980
981 if (mdesc->fixup)
982 mdesc->fixup(mdesc, tags, &from, &meminfo);
983
984 if (tags->hdr.tag == ATAG_CORE) {
985 if (meminfo.nr_banks != 0)
986 squash_mem_tags(tags);
Richard Purdie4cd9d6f2008-01-02 00:56:46 +0100987 save_atags(tags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700988 parse_tags(tags);
989 }
990
Grant Likely62913192011-04-28 14:27:21 -0600991 /* parse_early_param needs a boot_command_line */
992 strlcpy(boot_command_line, from, COMMAND_LINE_SIZE);
993
994 return mdesc;
995}
996
997
998void __init setup_arch(char **cmdline_p)
999{
1000 struct machine_desc *mdesc;
1001
1002 unwind_init();
1003
1004 setup_processor();
Grant Likely93c02ab2011-04-28 14:27:21 -06001005 mdesc = setup_machine_fdt(__atags_pointer);
1006 if (!mdesc)
1007 mdesc = setup_machine_tags(machine_arch_type);
Grant Likely62913192011-04-28 14:27:21 -06001008 machine_desc = mdesc;
1009 machine_name = mdesc->name;
1010
1011 if (mdesc->soft_reboot)
1012 reboot_setup("s");
1013
Russell King37efe642008-12-01 11:53:07 +00001014 init_mm.start_code = (unsigned long) _text;
1015 init_mm.end_code = (unsigned long) _etext;
1016 init_mm.end_data = (unsigned long) _edata;
1017 init_mm.brk = (unsigned long) _end;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001018
Jeremy Kerr48ab7e02010-01-27 01:13:31 +01001019 /* populate cmd_line too for later use, preserving boot_command_line */
1020 strlcpy(cmd_line, boot_command_line, COMMAND_LINE_SIZE);
1021 *cmdline_p = cmd_line;
Jeremy Kerr2b0d8c22010-01-11 23:17:34 +01001022
1023 parse_early_param();
1024
Russell King0371d3f2011-07-05 19:58:29 +01001025 sanity_check_meminfo();
Russell King8d717a52010-05-22 19:47:18 +01001026 arm_memblock_init(&meminfo, mdesc);
Russell King2778f622010-07-09 16:27:52 +01001027
Nicolas Pitre4b5f32c2008-10-06 13:24:40 -04001028 paging_init(mdesc);
Dima Zavin11b93692011-01-14 23:05:14 +01001029 request_standard_resources(mdesc);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001030
Grant Likely93c02ab2011-04-28 14:27:21 -06001031 unflatten_device_tree();
1032
Russell King7bbb7942006-02-16 11:08:09 +00001033#ifdef CONFIG_SMP
Russell Kingf00ec482010-09-04 10:47:48 +01001034 if (is_smp())
1035 smp_init_cpus();
Russell King7bbb7942006-02-16 11:08:09 +00001036#endif
Mika Westerberg3c57fb42010-05-10 09:20:22 +01001037 reserve_crashkernel();
Russell King7bbb7942006-02-16 11:08:09 +00001038
Russell Kingccea7a12005-05-31 22:22:32 +01001039 cpu_init();
Linus Walleijbc581772009-09-15 17:30:37 +01001040 tcm_init();
Russell Kingccea7a12005-05-31 22:22:32 +01001041
eric miao52108642010-12-13 09:42:34 +01001042#ifdef CONFIG_MULTI_IRQ_HANDLER
1043 handle_arch_irq = mdesc->handle_irq;
1044#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001045
1046#ifdef CONFIG_VT
1047#if defined(CONFIG_VGA_CONSOLE)
1048 conswitchp = &vga_con;
1049#elif defined(CONFIG_DUMMY_CONSOLE)
1050 conswitchp = &dummy_con;
1051#endif
1052#endif
Jason Wessel5cbad0e2008-02-20 13:33:40 -06001053 early_trap_init();
Russell Kingdec12e62010-12-16 13:49:34 +00001054
1055 if (mdesc->init_early)
1056 mdesc->init_early();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001057}
1058
1059
1060static int __init topology_init(void)
1061{
1062 int cpu;
1063
Russell King66fb8bd2007-03-13 09:54:21 +00001064 for_each_possible_cpu(cpu) {
1065 struct cpuinfo_arm *cpuinfo = &per_cpu(cpu_data, cpu);
1066 cpuinfo->cpu.hotpluggable = 1;
1067 register_cpu(&cpuinfo->cpu, cpu);
1068 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001069
1070 return 0;
1071}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001072subsys_initcall(topology_init);
1073
Russell Kinge119bff2010-01-10 17:23:29 +00001074#ifdef CONFIG_HAVE_PROC_CPU
1075static int __init proc_cpu_init(void)
1076{
1077 struct proc_dir_entry *res;
1078
1079 res = proc_mkdir("cpu", NULL);
1080 if (!res)
1081 return -ENOMEM;
1082 return 0;
1083}
1084fs_initcall(proc_cpu_init);
1085#endif
1086
Linus Torvalds1da177e2005-04-16 15:20:36 -07001087static const char *hwcap_str[] = {
1088 "swp",
1089 "half",
1090 "thumb",
1091 "26bit",
1092 "fastmult",
1093 "fpa",
1094 "vfp",
1095 "edsp",
1096 "java",
Paul Gortmaker8f7f9432006-10-27 05:13:19 +01001097 "iwmmxt",
Lennert Buytenhek99e4a6d2006-12-18 00:59:10 +01001098 "crunch",
Catalin Marinas4369ae12008-11-06 13:23:06 +00001099 "thumbee",
Catalin Marinas2bedbdf2008-11-06 13:23:07 +00001100 "neon",
Catalin Marinas7279dc32009-02-11 13:13:56 +01001101 "vfpv3",
1102 "vfpv3d16",
Linus Torvalds1da177e2005-04-16 15:20:36 -07001103 NULL
1104};
1105
Linus Torvalds1da177e2005-04-16 15:20:36 -07001106static int c_show(struct seq_file *m, void *v)
1107{
1108 int i;
1109
1110 seq_printf(m, "Processor\t: %s rev %d (%s)\n",
Russell King0ba8b9b2008-08-10 18:08:10 +01001111 cpu_name, read_cpuid_id() & 15, elf_platform);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001112
1113#if defined(CONFIG_SMP)
1114 for_each_online_cpu(i) {
Russell King15559722005-11-06 21:41:08 +00001115 /*
1116 * glibc reads /proc/cpuinfo to determine the number of
1117 * online processors, looking for lines beginning with
1118 * "processor". Give glibc what it expects.
1119 */
1120 seq_printf(m, "processor\t: %d\n", i);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001121 seq_printf(m, "BogoMIPS\t: %lu.%02lu\n\n",
1122 per_cpu(cpu_data, i).loops_per_jiffy / (500000UL/HZ),
1123 (per_cpu(cpu_data, i).loops_per_jiffy / (5000UL/HZ)) % 100);
1124 }
1125#else /* CONFIG_SMP */
1126 seq_printf(m, "BogoMIPS\t: %lu.%02lu\n",
1127 loops_per_jiffy / (500000/HZ),
1128 (loops_per_jiffy / (5000/HZ)) % 100);
1129#endif
1130
1131 /* dump out the processor features */
1132 seq_puts(m, "Features\t: ");
1133
1134 for (i = 0; hwcap_str[i]; i++)
1135 if (elf_hwcap & (1 << i))
1136 seq_printf(m, "%s ", hwcap_str[i]);
1137
Russell King0ba8b9b2008-08-10 18:08:10 +01001138 seq_printf(m, "\nCPU implementer\t: 0x%02x\n", read_cpuid_id() >> 24);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001139 seq_printf(m, "CPU architecture: %s\n", proc_arch[cpu_architecture()]);
1140
Russell King0ba8b9b2008-08-10 18:08:10 +01001141 if ((read_cpuid_id() & 0x0008f000) == 0x00000000) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001142 /* pre-ARM7 */
Russell King0ba8b9b2008-08-10 18:08:10 +01001143 seq_printf(m, "CPU part\t: %07x\n", read_cpuid_id() >> 4);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001144 } else {
Russell King0ba8b9b2008-08-10 18:08:10 +01001145 if ((read_cpuid_id() & 0x0008f000) == 0x00007000) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001146 /* ARM7 */
1147 seq_printf(m, "CPU variant\t: 0x%02x\n",
Russell King0ba8b9b2008-08-10 18:08:10 +01001148 (read_cpuid_id() >> 16) & 127);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001149 } else {
1150 /* post-ARM7 */
1151 seq_printf(m, "CPU variant\t: 0x%x\n",
Russell King0ba8b9b2008-08-10 18:08:10 +01001152 (read_cpuid_id() >> 20) & 15);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001153 }
1154 seq_printf(m, "CPU part\t: 0x%03x\n",
Russell King0ba8b9b2008-08-10 18:08:10 +01001155 (read_cpuid_id() >> 4) & 0xfff);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001156 }
Russell King0ba8b9b2008-08-10 18:08:10 +01001157 seq_printf(m, "CPU revision\t: %d\n", read_cpuid_id() & 15);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001158
Linus Torvalds1da177e2005-04-16 15:20:36 -07001159 seq_puts(m, "\n");
1160
1161 seq_printf(m, "Hardware\t: %s\n", machine_name);
1162 seq_printf(m, "Revision\t: %04x\n", system_rev);
1163 seq_printf(m, "Serial\t\t: %08x%08x\n",
1164 system_serial_high, system_serial_low);
1165
1166 return 0;
1167}
1168
1169static void *c_start(struct seq_file *m, loff_t *pos)
1170{
1171 return *pos < 1 ? (void *)1 : NULL;
1172}
1173
1174static void *c_next(struct seq_file *m, void *v, loff_t *pos)
1175{
1176 ++*pos;
1177 return NULL;
1178}
1179
1180static void c_stop(struct seq_file *m, void *v)
1181{
1182}
1183
Jan Engelhardt2ffd6e12008-01-22 20:41:07 +01001184const struct seq_operations cpuinfo_op = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001185 .start = c_start,
1186 .next = c_next,
1187 .stop = c_stop,
1188 .show = c_show
1189};