blob: 04fd01feea86ed82672a406fa5343f6144023875 [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 */
Paul Gortmakerecea4ab2011-07-22 10:58:34 -040010#include <linux/export.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070011#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>
Linus Torvalds1da177e2005-04-16 15:20:36 -070024#include <linux/root_dev.h>
25#include <linux/cpu.h>
26#include <linux/interrupt.h>
Russell King7bbb7942006-02-16 11:08:09 +000027#include <linux/smp.h>
Alexey Dobriyan4e950f62007-07-30 02:36:13 +040028#include <linux/fs.h>
Russell Kinge119bff2010-01-10 17:23:29 +000029#include <linux/proc_fs.h>
Russell King2778f622010-07-09 16:27:52 +010030#include <linux/memblock.h>
Dave Martin2ecccf92011-08-19 17:58:35 +010031#include <linux/bug.h>
32#include <linux/compiler.h>
Nicolas Pitre27a3f0e2011-08-25 19:10:29 -040033#include <linux/sort.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070034
Catalin Marinasb86040a2009-07-24 12:32:54 +010035#include <asm/unified.h>
Russell King15d07dc2012-03-28 18:30:01 +010036#include <asm/cp15.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>
David Howells9f97da72012-03-28 18:30:01 +010053#include <asm/system_info.h>
54#include <asm/system_misc.h>
Jason Wessel5cbad0e2008-02-20 13:33:40 -060055#include <asm/traps.h>
Catalin Marinasbff595c2009-02-16 11:41:36 +010056#include <asm/unwind.h>
Tejun Heo1c16d242011-12-08 10:22:06 -080057#include <asm/memblock.h>
Dave Martin4588c342012-02-17 16:54:28 +000058#include <asm/virt.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070059
Uwe Kleine-König73a65b32010-01-19 10:13:14 +010060#if defined(CONFIG_DEPRECATED_PARAM_STRUCT)
Ben Dooks0fc1c832006-03-15 23:17:30 +000061#include "compat.h"
Uwe Kleine-König73a65b32010-01-19 10:13:14 +010062#endif
Richard Purdie4cd9d6f2008-01-02 00:56:46 +010063#include "atags.h"
Linus Walleijbc581772009-09-15 17:30:37 +010064#include "tcm.h"
Ben Dooks0fc1c832006-03-15 23:17:30 +000065
Linus Torvalds1da177e2005-04-16 15:20:36 -070066#ifndef MEM_SIZE
67#define MEM_SIZE (16*1024*1024)
68#endif
69
70#if defined(CONFIG_FPE_NWFPE) || defined(CONFIG_FPE_FASTFPE)
71char fpe_type[8];
72
73static int __init fpe_setup(char *line)
74{
75 memcpy(fpe_type, line, 8);
76 return 1;
77}
78
79__setup("fpe=", fpe_setup);
80#endif
81
Nicolas Pitre4b5f32c2008-10-06 13:24:40 -040082extern void paging_init(struct machine_desc *desc);
Russell King0371d3f2011-07-05 19:58:29 +010083extern void sanity_check_meminfo(void);
Linus Torvalds1da177e2005-04-16 15:20:36 -070084extern void reboot_setup(char *str);
Marek Szyprowskic7909502011-12-29 13:09:51 +010085extern void setup_dma_zone(struct machine_desc *desc);
Linus Torvalds1da177e2005-04-16 15:20:36 -070086
87unsigned int processor_id;
Krzysztof Halasac18f6582007-12-18 03:53:27 +010088EXPORT_SYMBOL(processor_id);
Russell King0385ebc2010-12-04 17:45:55 +000089unsigned int __machine_arch_type __read_mostly;
Linus Torvalds1da177e2005-04-16 15:20:36 -070090EXPORT_SYMBOL(__machine_arch_type);
Russell King0385ebc2010-12-04 17:45:55 +000091unsigned int cacheid __read_mostly;
Russell Kingc0e95872008-09-25 15:35:28 +010092EXPORT_SYMBOL(cacheid);
Linus Torvalds1da177e2005-04-16 15:20:36 -070093
Bill Gatliff9d20fdd2007-05-31 22:02:22 +010094unsigned int __atags_pointer __initdata;
95
Linus Torvalds1da177e2005-04-16 15:20:36 -070096unsigned int system_rev;
97EXPORT_SYMBOL(system_rev);
98
99unsigned int system_serial_low;
100EXPORT_SYMBOL(system_serial_low);
101
102unsigned int system_serial_high;
103EXPORT_SYMBOL(system_serial_high);
104
Russell King0385ebc2010-12-04 17:45:55 +0000105unsigned int elf_hwcap __read_mostly;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700106EXPORT_SYMBOL(elf_hwcap);
107
108
109#ifdef MULTI_CPU
Russell King0385ebc2010-12-04 17:45:55 +0000110struct processor processor __read_mostly;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700111#endif
112#ifdef MULTI_TLB
Russell King0385ebc2010-12-04 17:45:55 +0000113struct cpu_tlb_fns cpu_tlb __read_mostly;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114#endif
115#ifdef MULTI_USER
Russell King0385ebc2010-12-04 17:45:55 +0000116struct cpu_user_fns cpu_user __read_mostly;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700117#endif
118#ifdef MULTI_CACHE
Russell King0385ebc2010-12-04 17:45:55 +0000119struct cpu_cache_fns cpu_cache __read_mostly;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700120#endif
Catalin Marinas953233d2007-02-05 14:48:08 +0100121#ifdef CONFIG_OUTER_CACHE
Russell King0385ebc2010-12-04 17:45:55 +0000122struct outer_cache_fns outer_cache __read_mostly;
Santosh Shilimkar6c09f092010-02-16 07:57:43 +0100123EXPORT_SYMBOL(outer_cache);
Catalin Marinas953233d2007-02-05 14:48:08 +0100124#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700125
Dave Martin2ecccf92011-08-19 17:58:35 +0100126/*
127 * Cached cpu_architecture() result for use by assembler code.
128 * C code should use the cpu_architecture() function instead of accessing this
129 * variable directly.
130 */
131int __cpu_architecture __read_mostly = CPU_ARCH_UNKNOWN;
132
Russell Kingccea7a12005-05-31 22:22:32 +0100133struct stack {
134 u32 irq[3];
135 u32 abt[3];
136 u32 und[3];
137} ____cacheline_aligned;
138
139static struct stack stacks[NR_CPUS];
140
Linus Torvalds1da177e2005-04-16 15:20:36 -0700141char elf_platform[ELF_PLATFORM_SIZE];
142EXPORT_SYMBOL(elf_platform);
143
Linus Torvalds1da177e2005-04-16 15:20:36 -0700144static const char *cpu_name;
145static const char *machine_name;
Jeremy Kerr48ab7e02010-01-27 01:13:31 +0100146static char __initdata cmd_line[COMMAND_LINE_SIZE];
Russell King8ff14432010-12-20 10:18:36 +0000147struct machine_desc *machine_desc __initdata;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700148
149static char default_command_line[COMMAND_LINE_SIZE] __initdata = CONFIG_CMDLINE;
150static union { char c[4]; unsigned long l; } endian_test __initdata = { { 'l', '?', '?', 'b' } };
151#define ENDIANNESS ((char)endian_test.l)
152
153DEFINE_PER_CPU(struct cpuinfo_arm, cpu_data);
154
155/*
156 * Standard memory resources
157 */
158static struct resource mem_res[] = {
Greg Kroah-Hartman740e5182006-06-12 14:47:06 -0700159 {
160 .name = "Video RAM",
161 .start = 0,
162 .end = 0,
163 .flags = IORESOURCE_MEM
164 },
165 {
Kees Cooka36d8e52012-01-18 01:57:21 +0100166 .name = "Kernel code",
Greg Kroah-Hartman740e5182006-06-12 14:47:06 -0700167 .start = 0,
168 .end = 0,
169 .flags = IORESOURCE_MEM
170 },
171 {
172 .name = "Kernel data",
173 .start = 0,
174 .end = 0,
175 .flags = IORESOURCE_MEM
176 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700177};
178
179#define video_ram mem_res[0]
180#define kernel_code mem_res[1]
181#define kernel_data mem_res[2]
182
183static struct resource io_res[] = {
Greg Kroah-Hartman740e5182006-06-12 14:47:06 -0700184 {
185 .name = "reserved",
186 .start = 0x3bc,
187 .end = 0x3be,
188 .flags = IORESOURCE_IO | IORESOURCE_BUSY
189 },
190 {
191 .name = "reserved",
192 .start = 0x378,
193 .end = 0x37f,
194 .flags = IORESOURCE_IO | IORESOURCE_BUSY
195 },
196 {
197 .name = "reserved",
198 .start = 0x278,
199 .end = 0x27f,
200 .flags = IORESOURCE_IO | IORESOURCE_BUSY
201 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700202};
203
204#define lp0 io_res[0]
205#define lp1 io_res[1]
206#define lp2 io_res[2]
207
Linus Torvalds1da177e2005-04-16 15:20:36 -0700208static const char *proc_arch[] = {
209 "undefined/unknown",
210 "3",
211 "4",
212 "4T",
213 "5",
214 "5T",
215 "5TE",
216 "5TEJ",
217 "6TEJ",
Catalin Marinas6b090a22006-01-12 16:28:16 +0000218 "7",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700219 "?(11)",
220 "?(12)",
221 "?(13)",
222 "?(14)",
223 "?(15)",
224 "?(16)",
225 "?(17)",
226};
227
Dave Martin2ecccf92011-08-19 17:58:35 +0100228static int __get_cpu_architecture(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700229{
230 int cpu_arch;
231
Russell King0ba8b9b2008-08-10 18:08:10 +0100232 if ((read_cpuid_id() & 0x0008f000) == 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700233 cpu_arch = CPU_ARCH_UNKNOWN;
Russell King0ba8b9b2008-08-10 18:08:10 +0100234 } else if ((read_cpuid_id() & 0x0008f000) == 0x00007000) {
235 cpu_arch = (read_cpuid_id() & (1 << 23)) ? CPU_ARCH_ARMv4T : CPU_ARCH_ARMv3;
236 } else if ((read_cpuid_id() & 0x00080000) == 0x00000000) {
237 cpu_arch = (read_cpuid_id() >> 16) & 7;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700238 if (cpu_arch)
239 cpu_arch += CPU_ARCH_ARMv3;
Russell King0ba8b9b2008-08-10 18:08:10 +0100240 } else if ((read_cpuid_id() & 0x000f0000) == 0x000f0000) {
Catalin Marinas180005c2007-09-25 16:49:45 +0100241 unsigned int mmfr0;
242
243 /* Revised CPUID format. Read the Memory Model Feature
244 * Register 0 and check for VMSAv7 or PMSAv7 */
245 asm("mrc p15, 0, %0, c0, c1, 4"
246 : "=r" (mmfr0));
Catalin Marinas315cfe72011-02-15 18:06:57 +0100247 if ((mmfr0 & 0x0000000f) >= 0x00000003 ||
248 (mmfr0 & 0x000000f0) >= 0x00000030)
Catalin Marinas180005c2007-09-25 16:49:45 +0100249 cpu_arch = CPU_ARCH_ARMv7;
250 else if ((mmfr0 & 0x0000000f) == 0x00000002 ||
251 (mmfr0 & 0x000000f0) == 0x00000020)
252 cpu_arch = CPU_ARCH_ARMv6;
253 else
254 cpu_arch = CPU_ARCH_UNKNOWN;
255 } else
256 cpu_arch = CPU_ARCH_UNKNOWN;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700257
258 return cpu_arch;
259}
260
Dave Martin2ecccf92011-08-19 17:58:35 +0100261int __pure cpu_architecture(void)
262{
263 BUG_ON(__cpu_architecture == CPU_ARCH_UNKNOWN);
264
265 return __cpu_architecture;
266}
267
Will Deacon8925ec42010-09-13 16:18:30 +0100268static int cpu_has_aliasing_icache(unsigned int arch)
269{
270 int aliasing_icache;
271 unsigned int id_reg, num_sets, line_size;
272
Will Deacon7f94e9c2011-08-23 22:22:11 +0100273 /* PIPT caches never alias. */
274 if (icache_is_pipt())
275 return 0;
276
Will Deacon8925ec42010-09-13 16:18:30 +0100277 /* arch specifies the register format */
278 switch (arch) {
279 case CPU_ARCH_ARMv7:
Linus Walleij5fb31a92010-10-06 11:07:28 +0100280 asm("mcr p15, 2, %0, c0, c0, 0 @ set CSSELR"
281 : /* No output operands */
Will Deacon8925ec42010-09-13 16:18:30 +0100282 : "r" (1));
Linus Walleij5fb31a92010-10-06 11:07:28 +0100283 isb();
284 asm("mrc p15, 1, %0, c0, c0, 0 @ read CCSIDR"
285 : "=r" (id_reg));
Will Deacon8925ec42010-09-13 16:18:30 +0100286 line_size = 4 << ((id_reg & 0x7) + 2);
287 num_sets = ((id_reg >> 13) & 0x7fff) + 1;
288 aliasing_icache = (line_size * num_sets) > PAGE_SIZE;
289 break;
290 case CPU_ARCH_ARMv6:
291 aliasing_icache = read_cpuid_cachetype() & (1 << 11);
292 break;
293 default:
294 /* I-cache aliases will be handled by D-cache aliasing code */
295 aliasing_icache = 0;
296 }
297
298 return aliasing_icache;
299}
300
Russell Kingc0e95872008-09-25 15:35:28 +0100301static void __init cacheid_init(void)
302{
303 unsigned int cachetype = read_cpuid_cachetype();
304 unsigned int arch = cpu_architecture();
305
Catalin Marinasb57ee992009-03-03 11:44:12 +0100306 if (arch >= CPU_ARCH_ARMv6) {
307 if ((cachetype & (7 << 29)) == 4 << 29) {
308 /* ARMv7 register format */
Will Deacon72dc53a2011-08-03 12:37:04 +0100309 arch = CPU_ARCH_ARMv7;
Catalin Marinasb57ee992009-03-03 11:44:12 +0100310 cacheid = CACHEID_VIPT_NONALIASING;
Will Deacon7f94e9c2011-08-23 22:22:11 +0100311 switch (cachetype & (3 << 14)) {
312 case (1 << 14):
Catalin Marinasb57ee992009-03-03 11:44:12 +0100313 cacheid |= CACHEID_ASID_TAGGED;
Will Deacon7f94e9c2011-08-23 22:22:11 +0100314 break;
315 case (3 << 14):
316 cacheid |= CACHEID_PIPT;
317 break;
318 }
Will Deacon8925ec42010-09-13 16:18:30 +0100319 } else {
Will Deacon72dc53a2011-08-03 12:37:04 +0100320 arch = CPU_ARCH_ARMv6;
321 if (cachetype & (1 << 23))
322 cacheid = CACHEID_VIPT_ALIASING;
323 else
324 cacheid = CACHEID_VIPT_NONALIASING;
Will Deacon8925ec42010-09-13 16:18:30 +0100325 }
Will Deacon72dc53a2011-08-03 12:37:04 +0100326 if (cpu_has_aliasing_icache(arch))
327 cacheid |= CACHEID_VIPT_I_ALIASING;
Russell Kingc0e95872008-09-25 15:35:28 +0100328 } else {
329 cacheid = CACHEID_VIVT;
330 }
Russell King2b4ae1f2008-09-25 15:39:20 +0100331
332 printk("CPU: %s data cache, %s instruction cache\n",
333 cache_is_vivt() ? "VIVT" :
334 cache_is_vipt_aliasing() ? "VIPT aliasing" :
Will Deacon7f94e9c2011-08-23 22:22:11 +0100335 cache_is_vipt_nonaliasing() ? "PIPT / VIPT nonaliasing" : "unknown",
Russell King2b4ae1f2008-09-25 15:39:20 +0100336 cache_is_vivt() ? "VIVT" :
337 icache_is_vivt_asid_tagged() ? "VIVT ASID tagged" :
Will Deacon8925ec42010-09-13 16:18:30 +0100338 icache_is_vipt_aliasing() ? "VIPT aliasing" :
Will Deacon7f94e9c2011-08-23 22:22:11 +0100339 icache_is_pipt() ? "PIPT" :
Russell King2b4ae1f2008-09-25 15:39:20 +0100340 cache_is_vipt_nonaliasing() ? "VIPT nonaliasing" : "unknown");
Russell Kingc0e95872008-09-25 15:35:28 +0100341}
342
Linus Torvalds1da177e2005-04-16 15:20:36 -0700343/*
344 * These functions re-use the assembly code in head.S, which
345 * already provide the required functionality.
346 */
Russell King0f44ba12006-02-24 21:04:56 +0000347extern struct proc_info_list *lookup_processor_type(unsigned int);
Russell King6fc31d52011-01-12 17:50:42 +0000348
Grant Likely93c02ab2011-04-28 14:27:21 -0600349void __init early_print(const char *str, ...)
Russell King6fc31d52011-01-12 17:50:42 +0000350{
351 extern void printascii(const char *);
352 char buf[256];
353 va_list ap;
354
355 va_start(ap, str);
356 vsnprintf(buf, sizeof(buf), str, ap);
357 va_end(ap);
358
359#ifdef CONFIG_DEBUG_LL
360 printascii(buf);
361#endif
362 printk("%s", buf);
363}
364
Tony Lindgrenf159f4e2010-07-05 14:53:10 +0100365static void __init feat_v6_fixup(void)
366{
367 int id = read_cpuid_id();
368
369 if ((id & 0xff0f0000) != 0x41070000)
370 return;
371
372 /*
373 * HWCAP_TLS is available only on 1136 r1p0 and later,
374 * see also kuser_get_tls_init.
375 */
376 if ((((id >> 4) & 0xfff) == 0xb36) && (((id >> 20) & 3) == 0))
377 elf_hwcap &= ~HWCAP_TLS;
378}
379
Russell Kingb69874e2011-06-21 18:57:31 +0100380/*
381 * cpu_init - initialise one CPU.
382 *
383 * cpu_init sets up the per-CPU stacks.
384 */
385void cpu_init(void)
386{
387 unsigned int cpu = smp_processor_id();
388 struct stack *stk = &stacks[cpu];
389
390 if (cpu >= NR_CPUS) {
391 printk(KERN_CRIT "CPU%u: bad primary CPU number\n", cpu);
392 BUG();
393 }
394
395 cpu_proc_init();
396
397 /*
398 * Define the placement constraint for the inline asm directive below.
399 * In Thumb-2, msr with an immediate value is not allowed.
400 */
401#ifdef CONFIG_THUMB2_KERNEL
402#define PLC "r"
403#else
404#define PLC "I"
405#endif
406
407 /*
408 * setup stacks for re-entrant exception handlers
409 */
410 __asm__ (
411 "msr cpsr_c, %1\n\t"
412 "add r14, %0, %2\n\t"
413 "mov sp, r14\n\t"
414 "msr cpsr_c, %3\n\t"
415 "add r14, %0, %4\n\t"
416 "mov sp, r14\n\t"
417 "msr cpsr_c, %5\n\t"
418 "add r14, %0, %6\n\t"
419 "mov sp, r14\n\t"
420 "msr cpsr_c, %7"
421 :
422 : "r" (stk),
423 PLC (PSR_F_BIT | PSR_I_BIT | IRQ_MODE),
424 "I" (offsetof(struct stack, irq[0])),
425 PLC (PSR_F_BIT | PSR_I_BIT | ABT_MODE),
426 "I" (offsetof(struct stack, abt[0])),
427 PLC (PSR_F_BIT | PSR_I_BIT | UND_MODE),
428 "I" (offsetof(struct stack, und[0])),
429 PLC (PSR_F_BIT | PSR_I_BIT | SVC_MODE)
430 : "r14");
431}
432
Will Deaconeb504392012-01-20 12:01:12 +0100433int __cpu_logical_map[NR_CPUS];
434
435void __init smp_setup_processor_id(void)
436{
437 int i;
438 u32 cpu = is_smp() ? read_cpuid_mpidr() & 0xff : 0;
439
440 cpu_logical_map(0) = cpu;
441 for (i = 1; i < NR_CPUS; ++i)
442 cpu_logical_map(i) = i == cpu ? 0 : i;
443
444 printk(KERN_INFO "Booting Linux on physical CPU %d\n", cpu);
445}
446
Linus Torvalds1da177e2005-04-16 15:20:36 -0700447static void __init setup_processor(void)
448{
449 struct proc_info_list *list;
450
451 /*
452 * locate processor in the list of supported processor
453 * types. The linker builds this table for us from the
454 * entries in arch/arm/mm/proc-*.S
455 */
Russell King0ba8b9b2008-08-10 18:08:10 +0100456 list = lookup_processor_type(read_cpuid_id());
Linus Torvalds1da177e2005-04-16 15:20:36 -0700457 if (!list) {
458 printk("CPU configuration botched (ID %08x), unable "
Russell King0ba8b9b2008-08-10 18:08:10 +0100459 "to continue.\n", read_cpuid_id());
Linus Torvalds1da177e2005-04-16 15:20:36 -0700460 while (1);
461 }
462
463 cpu_name = list->cpu_name;
Dave Martin2ecccf92011-08-19 17:58:35 +0100464 __cpu_architecture = __get_cpu_architecture();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700465
466#ifdef MULTI_CPU
467 processor = *list->proc;
468#endif
469#ifdef MULTI_TLB
470 cpu_tlb = *list->tlb;
471#endif
472#ifdef MULTI_USER
473 cpu_user = *list->user;
474#endif
475#ifdef MULTI_CACHE
476 cpu_cache = *list->cache;
477#endif
478
Russell King4e190252006-07-03 13:29:38 +0100479 printk("CPU: %s [%08x] revision %d (ARMv%s), cr=%08lx\n",
Russell King0ba8b9b2008-08-10 18:08:10 +0100480 cpu_name, read_cpuid_id(), read_cpuid_id() & 15,
Russell King264edb32006-06-29 15:03:09 +0100481 proc_arch[cpu_architecture()], cr_alignment);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700482
Will Deacona34dbfb2011-11-11 11:35:58 +0100483 snprintf(init_utsname()->machine, __NEW_UTS_LEN + 1, "%s%c",
484 list->arch_name, ENDIANNESS);
485 snprintf(elf_platform, ELF_PLATFORM_SIZE, "%s%c",
486 list->elf_name, ENDIANNESS);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700487 elf_hwcap = list->elf_hwcap;
Catalin Marinasadeff422006-04-10 21:32:35 +0100488#ifndef CONFIG_ARM_THUMB
489 elf_hwcap &= ~HWCAP_THUMB;
490#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700491
Tony Lindgrenf159f4e2010-07-05 14:53:10 +0100492 feat_v6_fixup();
493
Russell Kingc0e95872008-09-25 15:35:28 +0100494 cacheid_init();
Russell Kingb69874e2011-06-21 18:57:31 +0100495 cpu_init();
Russell Kingccea7a12005-05-31 22:22:32 +0100496}
497
Grant Likely93c02ab2011-04-28 14:27:21 -0600498void __init dump_machine_table(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700499{
Nicolas Pitredce72dd2011-02-21 07:00:32 +0100500 struct machine_desc *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700501
Grant Likely62913192011-04-28 14:27:21 -0600502 early_print("Available machine support:\n\nID (hex)\tNAME\n");
503 for_each_machine_desc(p)
Nicolas Pitredce72dd2011-02-21 07:00:32 +0100504 early_print("%08x\t%s\n", p->nr, p->name);
505
506 early_print("\nPlease check your kernel config and/or bootloader.\n");
507
508 while (true)
509 /* can't use cpu_relax() here as it may require MMU setup */;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700510}
511
Peter Maydella5d5f7d2012-07-12 23:57:35 +0100512int __init arm_add_memory(phys_addr_t start, phys_addr_t size)
Russell King3a669412005-06-22 21:43:10 +0100513{
Nicolas Pitre4b5f32c2008-10-06 13:24:40 -0400514 struct membank *bank = &meminfo.bank[meminfo.nr_banks];
515
516 if (meminfo.nr_banks >= NR_BANKS) {
517 printk(KERN_CRIT "NR_BANKS too low, "
Will Deacon29a38192011-02-15 14:31:37 +0100518 "ignoring memory at 0x%08llx\n", (long long)start);
Nicolas Pitre4b5f32c2008-10-06 13:24:40 -0400519 return -EINVAL;
520 }
Russell King05f96ef2006-11-30 20:44:49 +0000521
Russell King3a669412005-06-22 21:43:10 +0100522 /*
523 * Ensure that start/size are aligned to a page boundary.
524 * Size is appropriately rounded down, start is rounded up.
525 */
526 size -= start & ~PAGE_MASK;
Russell King05f96ef2006-11-30 20:44:49 +0000527 bank->start = PAGE_ALIGN(start);
Will Deacone5ab8582012-04-12 17:15:08 +0100528
529#ifndef CONFIG_LPAE
530 if (bank->start + size < bank->start) {
531 printk(KERN_CRIT "Truncating memory at 0x%08llx to fit in "
532 "32-bit physical address space\n", (long long)start);
533 /*
534 * To ensure bank->start + bank->size is representable in
535 * 32 bits, we use ULONG_MAX as the upper limit rather than 4GB.
536 * This means we lose a page after masking.
537 */
538 size = ULONG_MAX - bank->start;
539 }
540#endif
541
Peter Maydella5d5f7d2012-07-12 23:57:35 +0100542 bank->size = size & ~(phys_addr_t)(PAGE_SIZE - 1);
Nicolas Pitre4b5f32c2008-10-06 13:24:40 -0400543
544 /*
545 * Check whether this memory region has non-zero size or
546 * invalid node number.
547 */
Russell Kingbe370302010-05-07 17:40:33 +0100548 if (bank->size == 0)
Nicolas Pitre4b5f32c2008-10-06 13:24:40 -0400549 return -EINVAL;
550
551 meminfo.nr_banks++;
552 return 0;
Russell King3a669412005-06-22 21:43:10 +0100553}
554
Linus Torvalds1da177e2005-04-16 15:20:36 -0700555/*
556 * Pick out the memory size. We look for mem=size@start,
557 * where start and size are "size[KkMm]"
558 */
Jeremy Kerr2b0d8c22010-01-11 23:17:34 +0100559static int __init early_mem(char *p)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700560{
561 static int usermem __initdata = 0;
Peter Maydella5d5f7d2012-07-12 23:57:35 +0100562 phys_addr_t size;
Will Deaconf60892d2011-02-15 12:44:10 +0100563 phys_addr_t start;
Jeremy Kerr2b0d8c22010-01-11 23:17:34 +0100564 char *endp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700565
566 /*
567 * If the user specifies memory size, we
568 * blow away any automatically generated
569 * size.
570 */
571 if (usermem == 0) {
572 usermem = 1;
573 meminfo.nr_banks = 0;
574 }
575
576 start = PHYS_OFFSET;
Jeremy Kerr2b0d8c22010-01-11 23:17:34 +0100577 size = memparse(p, &endp);
578 if (*endp == '@')
579 start = memparse(endp + 1, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700580
Andrew Morton1c97b732006-04-20 21:41:18 +0100581 arm_add_memory(start, size);
Jeremy Kerr2b0d8c22010-01-11 23:17:34 +0100582
583 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700584}
Jeremy Kerr2b0d8c22010-01-11 23:17:34 +0100585early_param("mem", early_mem);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700586
587static void __init
588setup_ramdisk(int doload, int prompt, int image_start, unsigned int rd_sz)
589{
590#ifdef CONFIG_BLK_DEV_RAM
591 extern int rd_size, rd_image_start, rd_prompt, rd_doload;
592
593 rd_image_start = image_start;
594 rd_prompt = prompt;
595 rd_doload = doload;
596
597 if (rd_sz)
598 rd_size = rd_sz;
599#endif
600}
601
Dima Zavin11b93692011-01-14 23:05:14 +0100602static void __init request_standard_resources(struct machine_desc *mdesc)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700603{
Dima Zavin11b93692011-01-14 23:05:14 +0100604 struct memblock_region *region;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700605 struct resource *res;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700606
Russell King37efe642008-12-01 11:53:07 +0000607 kernel_code.start = virt_to_phys(_text);
608 kernel_code.end = virt_to_phys(_etext - 1);
Russell King842eab42010-10-01 14:12:22 +0100609 kernel_data.start = virt_to_phys(_sdata);
Russell King37efe642008-12-01 11:53:07 +0000610 kernel_data.end = virt_to_phys(_end - 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700611
Dima Zavin11b93692011-01-14 23:05:14 +0100612 for_each_memblock(memory, region) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700613 res = alloc_bootmem_low(sizeof(*res));
614 res->name = "System RAM";
Dima Zavin11b93692011-01-14 23:05:14 +0100615 res->start = __pfn_to_phys(memblock_region_memory_base_pfn(region));
616 res->end = __pfn_to_phys(memblock_region_memory_end_pfn(region)) - 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700617 res->flags = IORESOURCE_MEM | IORESOURCE_BUSY;
618
619 request_resource(&iomem_resource, res);
620
621 if (kernel_code.start >= res->start &&
622 kernel_code.end <= res->end)
623 request_resource(res, &kernel_code);
624 if (kernel_data.start >= res->start &&
625 kernel_data.end <= res->end)
626 request_resource(res, &kernel_data);
627 }
628
629 if (mdesc->video_start) {
630 video_ram.start = mdesc->video_start;
631 video_ram.end = mdesc->video_end;
632 request_resource(&iomem_resource, &video_ram);
633 }
634
635 /*
636 * Some machines don't have the possibility of ever
637 * possessing lp0, lp1 or lp2
638 */
639 if (mdesc->reserve_lp0)
640 request_resource(&ioport_resource, &lp0);
641 if (mdesc->reserve_lp1)
642 request_resource(&ioport_resource, &lp1);
643 if (mdesc->reserve_lp2)
644 request_resource(&ioport_resource, &lp2);
645}
646
647/*
648 * Tag parsing.
649 *
650 * This is the new way of passing data to the kernel at boot time. Rather
651 * than passing a fixed inflexible structure to the kernel, we pass a list
652 * of variable-sized tags to the kernel. The first tag must be a ATAG_CORE
653 * tag for the list to be recognised (to distinguish the tagged list from
654 * a param_struct). The list is terminated with a zero-length tag (this tag
655 * is not parsed in any way).
656 */
657static int __init parse_tag_core(const struct tag *tag)
658{
659 if (tag->hdr.size > 2) {
660 if ((tag->u.core.flags & 1) == 0)
661 root_mountflags &= ~MS_RDONLY;
662 ROOT_DEV = old_decode_dev(tag->u.core.rootdev);
663 }
664 return 0;
665}
666
667__tagtable(ATAG_CORE, parse_tag_core);
668
669static int __init parse_tag_mem32(const struct tag *tag)
670{
Nicolas Pitre4b5f32c2008-10-06 13:24:40 -0400671 return arm_add_memory(tag->u.mem.start, tag->u.mem.size);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700672}
673
674__tagtable(ATAG_MEM, parse_tag_mem32);
675
676#if defined(CONFIG_VGA_CONSOLE) || defined(CONFIG_DUMMY_CONSOLE)
677struct screen_info screen_info = {
678 .orig_video_lines = 30,
679 .orig_video_cols = 80,
680 .orig_video_mode = 0,
681 .orig_video_ega_bx = 0,
682 .orig_video_isVGA = 1,
683 .orig_video_points = 8
684};
685
686static int __init parse_tag_videotext(const struct tag *tag)
687{
688 screen_info.orig_x = tag->u.videotext.x;
689 screen_info.orig_y = tag->u.videotext.y;
690 screen_info.orig_video_page = tag->u.videotext.video_page;
691 screen_info.orig_video_mode = tag->u.videotext.video_mode;
692 screen_info.orig_video_cols = tag->u.videotext.video_cols;
693 screen_info.orig_video_ega_bx = tag->u.videotext.video_ega_bx;
694 screen_info.orig_video_lines = tag->u.videotext.video_lines;
695 screen_info.orig_video_isVGA = tag->u.videotext.video_isvga;
696 screen_info.orig_video_points = tag->u.videotext.video_points;
697 return 0;
698}
699
700__tagtable(ATAG_VIDEOTEXT, parse_tag_videotext);
701#endif
702
703static int __init parse_tag_ramdisk(const struct tag *tag)
704{
705 setup_ramdisk((tag->u.ramdisk.flags & 1) == 0,
706 (tag->u.ramdisk.flags & 2) == 0,
707 tag->u.ramdisk.start, tag->u.ramdisk.size);
708 return 0;
709}
710
711__tagtable(ATAG_RAMDISK, parse_tag_ramdisk);
712
Linus Torvalds1da177e2005-04-16 15:20:36 -0700713static int __init parse_tag_serialnr(const struct tag *tag)
714{
715 system_serial_low = tag->u.serialnr.low;
716 system_serial_high = tag->u.serialnr.high;
717 return 0;
718}
719
720__tagtable(ATAG_SERIAL, parse_tag_serialnr);
721
722static int __init parse_tag_revision(const struct tag *tag)
723{
724 system_rev = tag->u.revision.rev;
725 return 0;
726}
727
728__tagtable(ATAG_REVISION, parse_tag_revision);
729
730static int __init parse_tag_cmdline(const struct tag *tag)
731{
Victor Boivie4394c122011-05-04 17:07:55 +0100732#if defined(CONFIG_CMDLINE_EXTEND)
733 strlcat(default_command_line, " ", COMMAND_LINE_SIZE);
734 strlcat(default_command_line, tag->u.cmdline.cmdline,
735 COMMAND_LINE_SIZE);
736#elif defined(CONFIG_CMDLINE_FORCE)
Alexander Holler22eeb8f2011-01-12 14:08:37 +0100737 pr_warning("Ignoring tag cmdline (using the default kernel command line)\n");
Victor Boivie4394c122011-05-04 17:07:55 +0100738#else
739 strlcpy(default_command_line, tag->u.cmdline.cmdline,
740 COMMAND_LINE_SIZE);
741#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700742 return 0;
743}
744
745__tagtable(ATAG_CMDLINE, parse_tag_cmdline);
746
747/*
748 * Scan the tag table for this tag, and call its parse function.
749 * The tag table is built by the linker from all the __tagtable
750 * declarations.
751 */
752static int __init parse_tag(const struct tag *tag)
753{
754 extern struct tagtable __tagtable_begin, __tagtable_end;
755 struct tagtable *t;
756
757 for (t = &__tagtable_begin; t < &__tagtable_end; t++)
758 if (tag->hdr.tag == t->tag) {
759 t->parse(tag);
760 break;
761 }
762
763 return t < &__tagtable_end;
764}
765
766/*
767 * Parse all tags in the list, checking both the global and architecture
768 * specific tag tables.
769 */
770static void __init parse_tags(const struct tag *t)
771{
772 for (; t->hdr.size; t = tag_next(t))
773 if (!parse_tag(t))
774 printk(KERN_WARNING
775 "Ignoring unrecognised tag 0x%08x\n",
776 t->hdr.tag);
777}
778
779/*
780 * This holds our defaults.
781 */
782static struct init_tags {
783 struct tag_header hdr1;
784 struct tag_core core;
785 struct tag_header hdr2;
786 struct tag_mem32 mem;
787 struct tag_header hdr3;
788} init_tags __initdata = {
789 { tag_size(tag_core), ATAG_CORE },
790 { 1, PAGE_SIZE, 0xff },
791 { tag_size(tag_mem32), ATAG_MEM },
Russell Kingb75c1782011-01-04 19:03:16 +0000792 { MEM_SIZE },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700793 { 0, ATAG_NONE }
794};
795
Linus Torvalds1da177e2005-04-16 15:20:36 -0700796static int __init customize_machine(void)
797{
798 /* customizes platform devices, or adds new ones */
Russell King8ff14432010-12-20 10:18:36 +0000799 if (machine_desc->init_machine)
800 machine_desc->init_machine();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700801 return 0;
802}
803arch_initcall(customize_machine);
804
Shawn Guo90de4132012-04-25 22:24:44 +0800805static int __init init_machine_late(void)
806{
807 if (machine_desc->init_late)
808 machine_desc->init_late();
809 return 0;
810}
811late_initcall(init_machine_late);
812
Mika Westerberg3c57fb42010-05-10 09:20:22 +0100813#ifdef CONFIG_KEXEC
814static inline unsigned long long get_total_mem(void)
815{
816 unsigned long total;
817
818 total = max_low_pfn - min_low_pfn;
819 return total << PAGE_SHIFT;
820}
821
822/**
823 * reserve_crashkernel() - reserves memory are for crash kernel
824 *
825 * This function reserves memory area given in "crashkernel=" kernel command
826 * line parameter. The memory reserved is used by a dump capture kernel when
827 * primary kernel is crashing.
828 */
829static void __init reserve_crashkernel(void)
830{
831 unsigned long long crash_size, crash_base;
832 unsigned long long total_mem;
833 int ret;
834
835 total_mem = get_total_mem();
836 ret = parse_crashkernel(boot_command_line, total_mem,
837 &crash_size, &crash_base);
838 if (ret)
839 return;
840
841 ret = reserve_bootmem(crash_base, crash_size, BOOTMEM_EXCLUSIVE);
842 if (ret < 0) {
843 printk(KERN_WARNING "crashkernel reservation failed - "
844 "memory is in use (0x%lx)\n", (unsigned long)crash_base);
845 return;
846 }
847
848 printk(KERN_INFO "Reserving %ldMB of memory at %ldMB "
849 "for crashkernel (System RAM: %ldMB)\n",
850 (unsigned long)(crash_size >> 20),
851 (unsigned long)(crash_base >> 20),
852 (unsigned long)(total_mem >> 20));
853
854 crashk_res.start = crash_base;
855 crashk_res.end = crash_base + crash_size - 1;
856 insert_resource(&iomem_resource, &crashk_res);
857}
858#else
859static inline void reserve_crashkernel(void) {}
860#endif /* CONFIG_KEXEC */
861
Uwe Kleine-König73a65b32010-01-19 10:13:14 +0100862static void __init squash_mem_tags(struct tag *tag)
863{
864 for (; tag->hdr.size; tag = tag_next(tag))
865 if (tag->hdr.tag == ATAG_MEM)
866 tag->hdr.tag = ATAG_NONE;
867}
868
Grant Likely62913192011-04-28 14:27:21 -0600869static struct machine_desc * __init setup_machine_tags(unsigned int nr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700870{
871 struct tag *tags = (struct tag *)&init_tags;
Grant Likely62913192011-04-28 14:27:21 -0600872 struct machine_desc *mdesc = NULL, *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700873 char *from = default_command_line;
874
Russell Kingb75c1782011-01-04 19:03:16 +0000875 init_tags.mem.start = PHYS_OFFSET;
876
Grant Likely62913192011-04-28 14:27:21 -0600877 /*
878 * locate machine in the list of supported machines.
879 */
880 for_each_machine_desc(p)
881 if (nr == p->nr) {
882 printk("Machine: %s\n", p->name);
883 mdesc = p;
884 break;
885 }
Catalin Marinasbff595c2009-02-16 11:41:36 +0100886
Grant Likely62913192011-04-28 14:27:21 -0600887 if (!mdesc) {
888 early_print("\nError: unrecognized/unsupported machine ID"
889 " (r1 = 0x%08x).\n\n", nr);
890 dump_machine_table(); /* does not return */
891 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700892
Bill Gatliff9d20fdd2007-05-31 22:02:22 +0100893 if (__atags_pointer)
894 tags = phys_to_virt(__atags_pointer);
Nicolas Pitre2bb98392011-07-05 22:38:10 -0400895 else if (mdesc->atag_offset)
896 tags = (void *)(PAGE_OFFSET + mdesc->atag_offset);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700897
Uwe Kleine-König73a65b32010-01-19 10:13:14 +0100898#if defined(CONFIG_DEPRECATED_PARAM_STRUCT)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700899 /*
900 * If we have the old style parameters, convert them to
901 * a tag list.
902 */
903 if (tags->hdr.tag != ATAG_CORE)
904 convert_to_tag_list(tags);
Uwe Kleine-König73a65b32010-01-19 10:13:14 +0100905#endif
Grant Likely93c02ab2011-04-28 14:27:21 -0600906
907 if (tags->hdr.tag != ATAG_CORE) {
908#if defined(CONFIG_OF)
909 /*
910 * If CONFIG_OF is set, then assume this is a reasonably
911 * modern system that should pass boot parameters
912 */
913 early_print("Warning: Neither atags nor dtb found\n");
914#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700915 tags = (struct tag *)&init_tags;
Grant Likely93c02ab2011-04-28 14:27:21 -0600916 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700917
918 if (mdesc->fixup)
Russell King0744a3e2010-12-20 10:37:50 +0000919 mdesc->fixup(tags, &from, &meminfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700920
921 if (tags->hdr.tag == ATAG_CORE) {
922 if (meminfo.nr_banks != 0)
923 squash_mem_tags(tags);
Richard Purdie4cd9d6f2008-01-02 00:56:46 +0100924 save_atags(tags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700925 parse_tags(tags);
926 }
927
Grant Likely62913192011-04-28 14:27:21 -0600928 /* parse_early_param needs a boot_command_line */
929 strlcpy(boot_command_line, from, COMMAND_LINE_SIZE);
930
931 return mdesc;
932}
933
Nicolas Pitre27a3f0e2011-08-25 19:10:29 -0400934static int __init meminfo_cmp(const void *_a, const void *_b)
935{
936 const struct membank *a = _a, *b = _b;
937 long cmp = bank_pfn_start(a) - bank_pfn_start(b);
938 return cmp < 0 ? -1 : cmp > 0 ? 1 : 0;
939}
Grant Likely62913192011-04-28 14:27:21 -0600940
Dave Martin4588c342012-02-17 16:54:28 +0000941void __init hyp_mode_check(void)
942{
943#ifdef CONFIG_ARM_VIRT_EXT
944 if (is_hyp_mode_available()) {
945 pr_info("CPU: All CPU(s) started in HYP mode.\n");
946 pr_info("CPU: Virtualization extensions available.\n");
947 } else if (is_hyp_mode_mismatched()) {
948 pr_warn("CPU: WARNING: CPU(s) started in wrong/inconsistent modes (primary CPU mode 0x%x)\n",
949 __boot_cpu_mode & MODE_MASK);
950 pr_warn("CPU: This may indicate a broken bootloader or firmware.\n");
951 } else
952 pr_info("CPU: All CPU(s) started in SVC mode.\n");
953#endif
954}
955
Grant Likely62913192011-04-28 14:27:21 -0600956void __init setup_arch(char **cmdline_p)
957{
958 struct machine_desc *mdesc;
959
Grant Likely62913192011-04-28 14:27:21 -0600960 setup_processor();
Grant Likely93c02ab2011-04-28 14:27:21 -0600961 mdesc = setup_machine_fdt(__atags_pointer);
962 if (!mdesc)
963 mdesc = setup_machine_tags(machine_arch_type);
Grant Likely62913192011-04-28 14:27:21 -0600964 machine_desc = mdesc;
965 machine_name = mdesc->name;
966
Marek Szyprowskic7909502011-12-29 13:09:51 +0100967 setup_dma_zone(mdesc);
968
Russell Kingb44c3502011-11-01 14:27:33 +0000969 if (mdesc->restart_mode)
970 reboot_setup(&mdesc->restart_mode);
Grant Likely62913192011-04-28 14:27:21 -0600971
Russell King37efe642008-12-01 11:53:07 +0000972 init_mm.start_code = (unsigned long) _text;
973 init_mm.end_code = (unsigned long) _etext;
974 init_mm.end_data = (unsigned long) _edata;
975 init_mm.brk = (unsigned long) _end;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700976
Jeremy Kerr48ab7e02010-01-27 01:13:31 +0100977 /* populate cmd_line too for later use, preserving boot_command_line */
978 strlcpy(cmd_line, boot_command_line, COMMAND_LINE_SIZE);
979 *cmdline_p = cmd_line;
Jeremy Kerr2b0d8c22010-01-11 23:17:34 +0100980
981 parse_early_param();
982
Nicolas Pitre27a3f0e2011-08-25 19:10:29 -0400983 sort(&meminfo.bank, meminfo.nr_banks, sizeof(meminfo.bank[0]), meminfo_cmp, NULL);
Russell King0371d3f2011-07-05 19:58:29 +0100984 sanity_check_meminfo();
Russell King8d717a52010-05-22 19:47:18 +0100985 arm_memblock_init(&meminfo, mdesc);
Russell King2778f622010-07-09 16:27:52 +0100986
Nicolas Pitre4b5f32c2008-10-06 13:24:40 -0400987 paging_init(mdesc);
Dima Zavin11b93692011-01-14 23:05:14 +0100988 request_standard_resources(mdesc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700989
Russell Kinga5287212011-11-04 15:05:24 +0000990 if (mdesc->restart)
991 arm_pm_restart = mdesc->restart;
992
Grant Likely93c02ab2011-04-28 14:27:21 -0600993 unflatten_device_tree();
994
Russell King7bbb7942006-02-16 11:08:09 +0000995#ifdef CONFIG_SMP
Russell Kingf00ec482010-09-04 10:47:48 +0100996 if (is_smp())
997 smp_init_cpus();
Russell King7bbb7942006-02-16 11:08:09 +0000998#endif
Dave Martin4588c342012-02-17 16:54:28 +0000999
1000 if (!is_smp())
1001 hyp_mode_check();
1002
Mika Westerberg3c57fb42010-05-10 09:20:22 +01001003 reserve_crashkernel();
Russell King7bbb7942006-02-16 11:08:09 +00001004
Linus Walleijbc581772009-09-15 17:30:37 +01001005 tcm_init();
Russell Kingccea7a12005-05-31 22:22:32 +01001006
eric miao52108642010-12-13 09:42:34 +01001007#ifdef CONFIG_MULTI_IRQ_HANDLER
1008 handle_arch_irq = mdesc->handle_irq;
1009#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001010
1011#ifdef CONFIG_VT
1012#if defined(CONFIG_VGA_CONSOLE)
1013 conswitchp = &vga_con;
1014#elif defined(CONFIG_DUMMY_CONSOLE)
1015 conswitchp = &dummy_con;
1016#endif
1017#endif
Russell Kingdec12e62010-12-16 13:49:34 +00001018
1019 if (mdesc->init_early)
1020 mdesc->init_early();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001021}
1022
1023
1024static int __init topology_init(void)
1025{
1026 int cpu;
1027
Russell King66fb8bd2007-03-13 09:54:21 +00001028 for_each_possible_cpu(cpu) {
1029 struct cpuinfo_arm *cpuinfo = &per_cpu(cpu_data, cpu);
1030 cpuinfo->cpu.hotpluggable = 1;
1031 register_cpu(&cpuinfo->cpu, cpu);
1032 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001033
1034 return 0;
1035}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001036subsys_initcall(topology_init);
1037
Russell Kinge119bff2010-01-10 17:23:29 +00001038#ifdef CONFIG_HAVE_PROC_CPU
1039static int __init proc_cpu_init(void)
1040{
1041 struct proc_dir_entry *res;
1042
1043 res = proc_mkdir("cpu", NULL);
1044 if (!res)
1045 return -ENOMEM;
1046 return 0;
1047}
1048fs_initcall(proc_cpu_init);
1049#endif
1050
Linus Torvalds1da177e2005-04-16 15:20:36 -07001051static const char *hwcap_str[] = {
1052 "swp",
1053 "half",
1054 "thumb",
1055 "26bit",
1056 "fastmult",
1057 "fpa",
1058 "vfp",
1059 "edsp",
1060 "java",
Paul Gortmaker8f7f9432006-10-27 05:13:19 +01001061 "iwmmxt",
Lennert Buytenhek99e4a6d2006-12-18 00:59:10 +01001062 "crunch",
Catalin Marinas4369ae12008-11-06 13:23:06 +00001063 "thumbee",
Catalin Marinas2bedbdf2008-11-06 13:23:07 +00001064 "neon",
Catalin Marinas7279dc32009-02-11 13:13:56 +01001065 "vfpv3",
1066 "vfpv3d16",
Will Deacon254cdf82011-06-03 14:15:22 +01001067 "tls",
1068 "vfpv4",
1069 "idiva",
1070 "idivt",
Linus Torvalds1da177e2005-04-16 15:20:36 -07001071 NULL
1072};
1073
Linus Torvalds1da177e2005-04-16 15:20:36 -07001074static int c_show(struct seq_file *m, void *v)
1075{
1076 int i;
1077
1078 seq_printf(m, "Processor\t: %s rev %d (%s)\n",
Russell King0ba8b9b2008-08-10 18:08:10 +01001079 cpu_name, read_cpuid_id() & 15, elf_platform);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001080
1081#if defined(CONFIG_SMP)
1082 for_each_online_cpu(i) {
Russell King15559722005-11-06 21:41:08 +00001083 /*
1084 * glibc reads /proc/cpuinfo to determine the number of
1085 * online processors, looking for lines beginning with
1086 * "processor". Give glibc what it expects.
1087 */
1088 seq_printf(m, "processor\t: %d\n", i);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001089 seq_printf(m, "BogoMIPS\t: %lu.%02lu\n\n",
1090 per_cpu(cpu_data, i).loops_per_jiffy / (500000UL/HZ),
1091 (per_cpu(cpu_data, i).loops_per_jiffy / (5000UL/HZ)) % 100);
1092 }
1093#else /* CONFIG_SMP */
1094 seq_printf(m, "BogoMIPS\t: %lu.%02lu\n",
1095 loops_per_jiffy / (500000/HZ),
1096 (loops_per_jiffy / (5000/HZ)) % 100);
1097#endif
1098
1099 /* dump out the processor features */
1100 seq_puts(m, "Features\t: ");
1101
1102 for (i = 0; hwcap_str[i]; i++)
1103 if (elf_hwcap & (1 << i))
1104 seq_printf(m, "%s ", hwcap_str[i]);
1105
Russell King0ba8b9b2008-08-10 18:08:10 +01001106 seq_printf(m, "\nCPU implementer\t: 0x%02x\n", read_cpuid_id() >> 24);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001107 seq_printf(m, "CPU architecture: %s\n", proc_arch[cpu_architecture()]);
1108
Russell King0ba8b9b2008-08-10 18:08:10 +01001109 if ((read_cpuid_id() & 0x0008f000) == 0x00000000) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001110 /* pre-ARM7 */
Russell King0ba8b9b2008-08-10 18:08:10 +01001111 seq_printf(m, "CPU part\t: %07x\n", read_cpuid_id() >> 4);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001112 } else {
Russell King0ba8b9b2008-08-10 18:08:10 +01001113 if ((read_cpuid_id() & 0x0008f000) == 0x00007000) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001114 /* ARM7 */
1115 seq_printf(m, "CPU variant\t: 0x%02x\n",
Russell King0ba8b9b2008-08-10 18:08:10 +01001116 (read_cpuid_id() >> 16) & 127);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001117 } else {
1118 /* post-ARM7 */
1119 seq_printf(m, "CPU variant\t: 0x%x\n",
Russell King0ba8b9b2008-08-10 18:08:10 +01001120 (read_cpuid_id() >> 20) & 15);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001121 }
1122 seq_printf(m, "CPU part\t: 0x%03x\n",
Russell King0ba8b9b2008-08-10 18:08:10 +01001123 (read_cpuid_id() >> 4) & 0xfff);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001124 }
Russell King0ba8b9b2008-08-10 18:08:10 +01001125 seq_printf(m, "CPU revision\t: %d\n", read_cpuid_id() & 15);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001126
Linus Torvalds1da177e2005-04-16 15:20:36 -07001127 seq_puts(m, "\n");
1128
1129 seq_printf(m, "Hardware\t: %s\n", machine_name);
1130 seq_printf(m, "Revision\t: %04x\n", system_rev);
1131 seq_printf(m, "Serial\t\t: %08x%08x\n",
1132 system_serial_high, system_serial_low);
1133
1134 return 0;
1135}
1136
1137static void *c_start(struct seq_file *m, loff_t *pos)
1138{
1139 return *pos < 1 ? (void *)1 : NULL;
1140}
1141
1142static void *c_next(struct seq_file *m, void *v, loff_t *pos)
1143{
1144 ++*pos;
1145 return NULL;
1146}
1147
1148static void c_stop(struct seq_file *m, void *v)
1149{
1150}
1151
Jan Engelhardt2ffd6e12008-01-22 20:41:07 +01001152const struct seq_operations cpuinfo_op = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001153 .start = c_start,
1154 .next = c_next,
1155 .stop = c_stop,
1156 .show = c_show
1157};