blob: 2183bb83ac83b8b461568aafc6941ae380c4e606 [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>
Mika Westerbergcea0bb12010-05-10 09:29:32 +010023#include <linux/crash_dump.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>
Linus Torvalds1da177e2005-04-16 15:20:36 -070030
Catalin Marinasb86040a2009-07-24 12:32:54 +010031#include <asm/unified.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070032#include <asm/cpu.h>
Russell King0ba8b9b22008-08-10 18:08:10 +010033#include <asm/cputype.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070034#include <asm/elf.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070035#include <asm/procinfo.h>
Russell King37efe642008-12-01 11:53:07 +000036#include <asm/sections.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070037#include <asm/setup.h>
38#include <asm/mach-types.h>
39#include <asm/cacheflush.h>
Russell King46097c72008-08-10 18:10:19 +010040#include <asm/cachetype.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070041#include <asm/tlbflush.h>
42
43#include <asm/mach/arch.h>
44#include <asm/mach/irq.h>
45#include <asm/mach/time.h>
Jason Wessel5cbad0e2008-02-20 13:33:40 -060046#include <asm/traps.h>
Catalin Marinasbff595c2009-02-16 11:41:36 +010047#include <asm/unwind.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070048
Ben Dooks0fc1c832006-03-15 23:17:30 +000049#include "compat.h"
Richard Purdie4cd9d6f2008-01-02 00:56:46 +010050#include "atags.h"
Linus Walleijbc581772009-09-15 17:30:37 +010051#include "tcm.h"
Ben Dooks0fc1c832006-03-15 23:17:30 +000052
Linus Torvalds1da177e2005-04-16 15:20:36 -070053#ifndef MEM_SIZE
54#define MEM_SIZE (16*1024*1024)
55#endif
56
57#if defined(CONFIG_FPE_NWFPE) || defined(CONFIG_FPE_FASTFPE)
58char fpe_type[8];
59
60static int __init fpe_setup(char *line)
61{
62 memcpy(fpe_type, line, 8);
63 return 1;
64}
65
66__setup("fpe=", fpe_setup);
67#endif
68
Nicolas Pitre4b5f32c2008-10-06 13:24:40 -040069extern void paging_init(struct machine_desc *desc);
Linus Torvalds1da177e2005-04-16 15:20:36 -070070extern void reboot_setup(char *str);
Linus Torvalds1da177e2005-04-16 15:20:36 -070071
72unsigned int processor_id;
Krzysztof Halasac18f6582007-12-18 03:53:27 +010073EXPORT_SYMBOL(processor_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -070074unsigned int __machine_arch_type;
75EXPORT_SYMBOL(__machine_arch_type);
Russell Kingc0e95872008-09-25 15:35:28 +010076unsigned int cacheid;
77EXPORT_SYMBOL(cacheid);
Linus Torvalds1da177e2005-04-16 15:20:36 -070078
Bill Gatliff9d20fdd2007-05-31 22:02:22 +010079unsigned int __atags_pointer __initdata;
80
Linus Torvalds1da177e2005-04-16 15:20:36 -070081unsigned int system_rev;
82EXPORT_SYMBOL(system_rev);
83
84unsigned int system_serial_low;
85EXPORT_SYMBOL(system_serial_low);
86
87unsigned int system_serial_high;
88EXPORT_SYMBOL(system_serial_high);
89
90unsigned int elf_hwcap;
91EXPORT_SYMBOL(elf_hwcap);
92
93
94#ifdef MULTI_CPU
95struct processor processor;
96#endif
97#ifdef MULTI_TLB
98struct cpu_tlb_fns cpu_tlb;
99#endif
100#ifdef MULTI_USER
101struct cpu_user_fns cpu_user;
102#endif
103#ifdef MULTI_CACHE
104struct cpu_cache_fns cpu_cache;
105#endif
Catalin Marinas953233d2007-02-05 14:48:08 +0100106#ifdef CONFIG_OUTER_CACHE
107struct outer_cache_fns outer_cache;
Santosh Shilimkar6c09f092010-02-16 07:57:43 +0100108EXPORT_SYMBOL(outer_cache);
Catalin Marinas953233d2007-02-05 14:48:08 +0100109#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700110
Russell Kingccea7a12005-05-31 22:22:32 +0100111struct stack {
112 u32 irq[3];
113 u32 abt[3];
114 u32 und[3];
115} ____cacheline_aligned;
116
117static struct stack stacks[NR_CPUS];
118
Linus Torvalds1da177e2005-04-16 15:20:36 -0700119char elf_platform[ELF_PLATFORM_SIZE];
120EXPORT_SYMBOL(elf_platform);
121
Linus Torvalds1da177e2005-04-16 15:20:36 -0700122static const char *cpu_name;
123static const char *machine_name;
Jeremy Kerr48ab7e02010-01-27 01:13:31 +0100124static char __initdata cmd_line[COMMAND_LINE_SIZE];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700125
126static char default_command_line[COMMAND_LINE_SIZE] __initdata = CONFIG_CMDLINE;
127static union { char c[4]; unsigned long l; } endian_test __initdata = { { 'l', '?', '?', 'b' } };
128#define ENDIANNESS ((char)endian_test.l)
129
130DEFINE_PER_CPU(struct cpuinfo_arm, cpu_data);
131
132/*
133 * Standard memory resources
134 */
135static struct resource mem_res[] = {
Greg Kroah-Hartman740e5182006-06-12 14:47:06 -0700136 {
137 .name = "Video RAM",
138 .start = 0,
139 .end = 0,
140 .flags = IORESOURCE_MEM
141 },
142 {
143 .name = "Kernel text",
144 .start = 0,
145 .end = 0,
146 .flags = IORESOURCE_MEM
147 },
148 {
149 .name = "Kernel data",
150 .start = 0,
151 .end = 0,
152 .flags = IORESOURCE_MEM
153 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700154};
155
156#define video_ram mem_res[0]
157#define kernel_code mem_res[1]
158#define kernel_data mem_res[2]
159
160static struct resource io_res[] = {
Greg Kroah-Hartman740e5182006-06-12 14:47:06 -0700161 {
162 .name = "reserved",
163 .start = 0x3bc,
164 .end = 0x3be,
165 .flags = IORESOURCE_IO | IORESOURCE_BUSY
166 },
167 {
168 .name = "reserved",
169 .start = 0x378,
170 .end = 0x37f,
171 .flags = IORESOURCE_IO | IORESOURCE_BUSY
172 },
173 {
174 .name = "reserved",
175 .start = 0x278,
176 .end = 0x27f,
177 .flags = IORESOURCE_IO | IORESOURCE_BUSY
178 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700179};
180
181#define lp0 io_res[0]
182#define lp1 io_res[1]
183#define lp2 io_res[2]
184
Linus Torvalds1da177e2005-04-16 15:20:36 -0700185static const char *proc_arch[] = {
186 "undefined/unknown",
187 "3",
188 "4",
189 "4T",
190 "5",
191 "5T",
192 "5TE",
193 "5TEJ",
194 "6TEJ",
Catalin Marinas6b090a22006-01-12 16:28:16 +0000195 "7",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700196 "?(11)",
197 "?(12)",
198 "?(13)",
199 "?(14)",
200 "?(15)",
201 "?(16)",
202 "?(17)",
203};
204
Linus Torvalds1da177e2005-04-16 15:20:36 -0700205int cpu_architecture(void)
206{
207 int cpu_arch;
208
Russell King0ba8b9b22008-08-10 18:08:10 +0100209 if ((read_cpuid_id() & 0x0008f000) == 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700210 cpu_arch = CPU_ARCH_UNKNOWN;
Russell King0ba8b9b22008-08-10 18:08:10 +0100211 } else if ((read_cpuid_id() & 0x0008f000) == 0x00007000) {
212 cpu_arch = (read_cpuid_id() & (1 << 23)) ? CPU_ARCH_ARMv4T : CPU_ARCH_ARMv3;
213 } else if ((read_cpuid_id() & 0x00080000) == 0x00000000) {
214 cpu_arch = (read_cpuid_id() >> 16) & 7;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700215 if (cpu_arch)
216 cpu_arch += CPU_ARCH_ARMv3;
Russell King0ba8b9b22008-08-10 18:08:10 +0100217 } else if ((read_cpuid_id() & 0x000f0000) == 0x000f0000) {
Catalin Marinas180005c2007-09-25 16:49:45 +0100218 unsigned int mmfr0;
219
220 /* Revised CPUID format. Read the Memory Model Feature
221 * Register 0 and check for VMSAv7 or PMSAv7 */
222 asm("mrc p15, 0, %0, c0, c1, 4"
223 : "=r" (mmfr0));
224 if ((mmfr0 & 0x0000000f) == 0x00000003 ||
225 (mmfr0 & 0x000000f0) == 0x00000030)
226 cpu_arch = CPU_ARCH_ARMv7;
227 else if ((mmfr0 & 0x0000000f) == 0x00000002 ||
228 (mmfr0 & 0x000000f0) == 0x00000020)
229 cpu_arch = CPU_ARCH_ARMv6;
230 else
231 cpu_arch = CPU_ARCH_UNKNOWN;
232 } else
233 cpu_arch = CPU_ARCH_UNKNOWN;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700234
235 return cpu_arch;
236}
237
Russell Kingc0e95872008-09-25 15:35:28 +0100238static void __init cacheid_init(void)
239{
240 unsigned int cachetype = read_cpuid_cachetype();
241 unsigned int arch = cpu_architecture();
242
Catalin Marinasb57ee992009-03-03 11:44:12 +0100243 if (arch >= CPU_ARCH_ARMv6) {
244 if ((cachetype & (7 << 29)) == 4 << 29) {
245 /* ARMv7 register format */
246 cacheid = CACHEID_VIPT_NONALIASING;
247 if ((cachetype & (3 << 14)) == 1 << 14)
248 cacheid |= CACHEID_ASID_TAGGED;
249 } else if (cachetype & (1 << 23))
Russell Kingc0e95872008-09-25 15:35:28 +0100250 cacheid = CACHEID_VIPT_ALIASING;
251 else
252 cacheid = CACHEID_VIPT_NONALIASING;
253 } else {
254 cacheid = CACHEID_VIVT;
255 }
Russell King2b4ae1f2008-09-25 15:39:20 +0100256
257 printk("CPU: %s data cache, %s instruction cache\n",
258 cache_is_vivt() ? "VIVT" :
259 cache_is_vipt_aliasing() ? "VIPT aliasing" :
260 cache_is_vipt_nonaliasing() ? "VIPT nonaliasing" : "unknown",
261 cache_is_vivt() ? "VIVT" :
262 icache_is_vivt_asid_tagged() ? "VIVT ASID tagged" :
263 cache_is_vipt_aliasing() ? "VIPT aliasing" :
264 cache_is_vipt_nonaliasing() ? "VIPT nonaliasing" : "unknown");
Russell Kingc0e95872008-09-25 15:35:28 +0100265}
266
Linus Torvalds1da177e2005-04-16 15:20:36 -0700267/*
268 * These functions re-use the assembly code in head.S, which
269 * already provide the required functionality.
270 */
Russell King0f44ba12006-02-24 21:04:56 +0000271extern struct proc_info_list *lookup_processor_type(unsigned int);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700272extern struct machine_desc *lookup_machine_type(unsigned int);
273
Tony Lindgrenf159f4e2010-07-05 14:53:10 +0100274static void __init feat_v6_fixup(void)
275{
276 int id = read_cpuid_id();
277
278 if ((id & 0xff0f0000) != 0x41070000)
279 return;
280
281 /*
282 * HWCAP_TLS is available only on 1136 r1p0 and later,
283 * see also kuser_get_tls_init.
284 */
285 if ((((id >> 4) & 0xfff) == 0xb36) && (((id >> 20) & 3) == 0))
286 elf_hwcap &= ~HWCAP_TLS;
287}
288
Linus Torvalds1da177e2005-04-16 15:20:36 -0700289static void __init setup_processor(void)
290{
291 struct proc_info_list *list;
292
293 /*
294 * locate processor in the list of supported processor
295 * types. The linker builds this table for us from the
296 * entries in arch/arm/mm/proc-*.S
297 */
Russell King0ba8b9b22008-08-10 18:08:10 +0100298 list = lookup_processor_type(read_cpuid_id());
Linus Torvalds1da177e2005-04-16 15:20:36 -0700299 if (!list) {
300 printk("CPU configuration botched (ID %08x), unable "
Russell King0ba8b9b22008-08-10 18:08:10 +0100301 "to continue.\n", read_cpuid_id());
Linus Torvalds1da177e2005-04-16 15:20:36 -0700302 while (1);
303 }
304
305 cpu_name = list->cpu_name;
306
307#ifdef MULTI_CPU
308 processor = *list->proc;
309#endif
310#ifdef MULTI_TLB
311 cpu_tlb = *list->tlb;
312#endif
313#ifdef MULTI_USER
314 cpu_user = *list->user;
315#endif
316#ifdef MULTI_CACHE
317 cpu_cache = *list->cache;
318#endif
319
Russell King4e190252006-07-03 13:29:38 +0100320 printk("CPU: %s [%08x] revision %d (ARMv%s), cr=%08lx\n",
Russell King0ba8b9b22008-08-10 18:08:10 +0100321 cpu_name, read_cpuid_id(), read_cpuid_id() & 15,
Russell King264edb32006-06-29 15:03:09 +0100322 proc_arch[cpu_architecture()], cr_alignment);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700323
Serge E. Hallyn96b644b2006-10-02 02:18:13 -0700324 sprintf(init_utsname()->machine, "%s%c", list->arch_name, ENDIANNESS);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700325 sprintf(elf_platform, "%s%c", list->elf_name, ENDIANNESS);
326 elf_hwcap = list->elf_hwcap;
Catalin Marinasadeff422006-04-10 21:32:35 +0100327#ifndef CONFIG_ARM_THUMB
328 elf_hwcap &= ~HWCAP_THUMB;
329#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700330
Tony Lindgrenf159f4e2010-07-05 14:53:10 +0100331 feat_v6_fixup();
332
Russell Kingc0e95872008-09-25 15:35:28 +0100333 cacheid_init();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700334 cpu_proc_init();
335}
336
Russell Kingccea7a12005-05-31 22:22:32 +0100337/*
338 * cpu_init - initialise one CPU.
339 *
Russell King90f1e082008-09-25 14:45:02 +0100340 * cpu_init sets up the per-CPU stacks.
Russell Kingccea7a12005-05-31 22:22:32 +0100341 */
Russell King36c5ed22005-06-19 18:39:33 +0100342void cpu_init(void)
Russell Kingccea7a12005-05-31 22:22:32 +0100343{
344 unsigned int cpu = smp_processor_id();
345 struct stack *stk = &stacks[cpu];
346
347 if (cpu >= NR_CPUS) {
348 printk(KERN_CRIT "CPU%u: bad primary CPU number\n", cpu);
349 BUG();
350 }
351
Russell Kingccea7a12005-05-31 22:22:32 +0100352 /*
Catalin Marinasb86040a2009-07-24 12:32:54 +0100353 * Define the placement constraint for the inline asm directive below.
354 * In Thumb-2, msr with an immediate value is not allowed.
355 */
356#ifdef CONFIG_THUMB2_KERNEL
357#define PLC "r"
358#else
359#define PLC "I"
360#endif
361
362 /*
Russell Kingccea7a12005-05-31 22:22:32 +0100363 * setup stacks for re-entrant exception handlers
364 */
365 __asm__ (
366 "msr cpsr_c, %1\n\t"
Catalin Marinasb86040a2009-07-24 12:32:54 +0100367 "add r14, %0, %2\n\t"
368 "mov sp, r14\n\t"
Russell Kingccea7a12005-05-31 22:22:32 +0100369 "msr cpsr_c, %3\n\t"
Catalin Marinasb86040a2009-07-24 12:32:54 +0100370 "add r14, %0, %4\n\t"
371 "mov sp, r14\n\t"
Russell Kingccea7a12005-05-31 22:22:32 +0100372 "msr cpsr_c, %5\n\t"
Catalin Marinasb86040a2009-07-24 12:32:54 +0100373 "add r14, %0, %6\n\t"
374 "mov sp, r14\n\t"
Russell Kingccea7a12005-05-31 22:22:32 +0100375 "msr cpsr_c, %7"
376 :
377 : "r" (stk),
Catalin Marinasb86040a2009-07-24 12:32:54 +0100378 PLC (PSR_F_BIT | PSR_I_BIT | IRQ_MODE),
Russell Kingccea7a12005-05-31 22:22:32 +0100379 "I" (offsetof(struct stack, irq[0])),
Catalin Marinasb86040a2009-07-24 12:32:54 +0100380 PLC (PSR_F_BIT | PSR_I_BIT | ABT_MODE),
Russell Kingccea7a12005-05-31 22:22:32 +0100381 "I" (offsetof(struct stack, abt[0])),
Catalin Marinasb86040a2009-07-24 12:32:54 +0100382 PLC (PSR_F_BIT | PSR_I_BIT | UND_MODE),
Russell Kingccea7a12005-05-31 22:22:32 +0100383 "I" (offsetof(struct stack, und[0])),
Catalin Marinasb86040a2009-07-24 12:32:54 +0100384 PLC (PSR_F_BIT | PSR_I_BIT | SVC_MODE)
Catalin Marinasaaaa3f92005-06-29 15:34:39 +0100385 : "r14");
Russell Kingccea7a12005-05-31 22:22:32 +0100386}
387
Linus Torvalds1da177e2005-04-16 15:20:36 -0700388static struct machine_desc * __init setup_machine(unsigned int nr)
389{
390 struct machine_desc *list;
391
392 /*
393 * locate machine in the list of supported machines.
394 */
395 list = lookup_machine_type(nr);
396 if (!list) {
397 printk("Machine configuration botched (nr %d), unable "
398 "to continue.\n", nr);
399 while (1);
400 }
401
402 printk("Machine: %s\n", list->name);
403
404 return list;
405}
406
Nicolas Pitre4b5f32c2008-10-06 13:24:40 -0400407static int __init arm_add_memory(unsigned long start, unsigned long size)
Russell King3a669412005-06-22 21:43:10 +0100408{
Nicolas Pitre4b5f32c2008-10-06 13:24:40 -0400409 struct membank *bank = &meminfo.bank[meminfo.nr_banks];
410
411 if (meminfo.nr_banks >= NR_BANKS) {
412 printk(KERN_CRIT "NR_BANKS too low, "
413 "ignoring memory at %#lx\n", start);
414 return -EINVAL;
415 }
Russell King05f96ef2006-11-30 20:44:49 +0000416
Russell King3a669412005-06-22 21:43:10 +0100417 /*
418 * Ensure that start/size are aligned to a page boundary.
419 * Size is appropriately rounded down, start is rounded up.
420 */
421 size -= start & ~PAGE_MASK;
Russell King05f96ef2006-11-30 20:44:49 +0000422 bank->start = PAGE_ALIGN(start);
423 bank->size = size & PAGE_MASK;
424 bank->node = PHYS_TO_NID(start);
Nicolas Pitre4b5f32c2008-10-06 13:24:40 -0400425
426 /*
427 * Check whether this memory region has non-zero size or
428 * invalid node number.
429 */
430 if (bank->size == 0 || bank->node >= MAX_NUMNODES)
431 return -EINVAL;
432
433 meminfo.nr_banks++;
434 return 0;
Russell King3a669412005-06-22 21:43:10 +0100435}
436
Linus Torvalds1da177e2005-04-16 15:20:36 -0700437/*
438 * Pick out the memory size. We look for mem=size@start,
439 * where start and size are "size[KkMm]"
440 */
Jeremy Kerr2b0d8c22010-01-11 23:17:34 +0100441static int __init early_mem(char *p)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700442{
443 static int usermem __initdata = 0;
444 unsigned long size, start;
Jeremy Kerr2b0d8c22010-01-11 23:17:34 +0100445 char *endp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700446
447 /*
448 * If the user specifies memory size, we
449 * blow away any automatically generated
450 * size.
451 */
452 if (usermem == 0) {
453 usermem = 1;
454 meminfo.nr_banks = 0;
455 }
456
457 start = PHYS_OFFSET;
Jeremy Kerr2b0d8c22010-01-11 23:17:34 +0100458 size = memparse(p, &endp);
459 if (*endp == '@')
460 start = memparse(endp + 1, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700461
Andrew Morton1c97b732006-04-20 21:41:18 +0100462 arm_add_memory(start, size);
Jeremy Kerr2b0d8c22010-01-11 23:17:34 +0100463
464 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700465}
Jeremy Kerr2b0d8c22010-01-11 23:17:34 +0100466early_param("mem", early_mem);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700467
468static void __init
469setup_ramdisk(int doload, int prompt, int image_start, unsigned int rd_sz)
470{
471#ifdef CONFIG_BLK_DEV_RAM
472 extern int rd_size, rd_image_start, rd_prompt, rd_doload;
473
474 rd_image_start = image_start;
475 rd_prompt = prompt;
476 rd_doload = doload;
477
478 if (rd_sz)
479 rd_size = rd_sz;
480#endif
481}
482
483static void __init
484request_standard_resources(struct meminfo *mi, struct machine_desc *mdesc)
485{
486 struct resource *res;
487 int i;
488
Russell King37efe642008-12-01 11:53:07 +0000489 kernel_code.start = virt_to_phys(_text);
490 kernel_code.end = virt_to_phys(_etext - 1);
491 kernel_data.start = virt_to_phys(_data);
492 kernel_data.end = virt_to_phys(_end - 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700493
494 for (i = 0; i < mi->nr_banks; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700495 if (mi->bank[i].size == 0)
496 continue;
497
Linus Torvalds1da177e2005-04-16 15:20:36 -0700498 res = alloc_bootmem_low(sizeof(*res));
499 res->name = "System RAM";
Nicolas Pitre3319f5e2008-10-02 03:29:22 +0100500 res->start = mi->bank[i].start;
501 res->end = mi->bank[i].start + mi->bank[i].size - 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700502 res->flags = IORESOURCE_MEM | IORESOURCE_BUSY;
503
504 request_resource(&iomem_resource, res);
505
506 if (kernel_code.start >= res->start &&
507 kernel_code.end <= res->end)
508 request_resource(res, &kernel_code);
509 if (kernel_data.start >= res->start &&
510 kernel_data.end <= res->end)
511 request_resource(res, &kernel_data);
512 }
513
514 if (mdesc->video_start) {
515 video_ram.start = mdesc->video_start;
516 video_ram.end = mdesc->video_end;
517 request_resource(&iomem_resource, &video_ram);
518 }
519
520 /*
521 * Some machines don't have the possibility of ever
522 * possessing lp0, lp1 or lp2
523 */
524 if (mdesc->reserve_lp0)
525 request_resource(&ioport_resource, &lp0);
526 if (mdesc->reserve_lp1)
527 request_resource(&ioport_resource, &lp1);
528 if (mdesc->reserve_lp2)
529 request_resource(&ioport_resource, &lp2);
530}
531
532/*
533 * Tag parsing.
534 *
535 * This is the new way of passing data to the kernel at boot time. Rather
536 * than passing a fixed inflexible structure to the kernel, we pass a list
537 * of variable-sized tags to the kernel. The first tag must be a ATAG_CORE
538 * tag for the list to be recognised (to distinguish the tagged list from
539 * a param_struct). The list is terminated with a zero-length tag (this tag
540 * is not parsed in any way).
541 */
542static int __init parse_tag_core(const struct tag *tag)
543{
544 if (tag->hdr.size > 2) {
545 if ((tag->u.core.flags & 1) == 0)
546 root_mountflags &= ~MS_RDONLY;
547 ROOT_DEV = old_decode_dev(tag->u.core.rootdev);
548 }
549 return 0;
550}
551
552__tagtable(ATAG_CORE, parse_tag_core);
553
554static int __init parse_tag_mem32(const struct tag *tag)
555{
Nicolas Pitre4b5f32c2008-10-06 13:24:40 -0400556 return arm_add_memory(tag->u.mem.start, tag->u.mem.size);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700557}
558
559__tagtable(ATAG_MEM, parse_tag_mem32);
560
561#if defined(CONFIG_VGA_CONSOLE) || defined(CONFIG_DUMMY_CONSOLE)
562struct screen_info screen_info = {
563 .orig_video_lines = 30,
564 .orig_video_cols = 80,
565 .orig_video_mode = 0,
566 .orig_video_ega_bx = 0,
567 .orig_video_isVGA = 1,
568 .orig_video_points = 8
569};
570
571static int __init parse_tag_videotext(const struct tag *tag)
572{
573 screen_info.orig_x = tag->u.videotext.x;
574 screen_info.orig_y = tag->u.videotext.y;
575 screen_info.orig_video_page = tag->u.videotext.video_page;
576 screen_info.orig_video_mode = tag->u.videotext.video_mode;
577 screen_info.orig_video_cols = tag->u.videotext.video_cols;
578 screen_info.orig_video_ega_bx = tag->u.videotext.video_ega_bx;
579 screen_info.orig_video_lines = tag->u.videotext.video_lines;
580 screen_info.orig_video_isVGA = tag->u.videotext.video_isvga;
581 screen_info.orig_video_points = tag->u.videotext.video_points;
582 return 0;
583}
584
585__tagtable(ATAG_VIDEOTEXT, parse_tag_videotext);
586#endif
587
588static int __init parse_tag_ramdisk(const struct tag *tag)
589{
590 setup_ramdisk((tag->u.ramdisk.flags & 1) == 0,
591 (tag->u.ramdisk.flags & 2) == 0,
592 tag->u.ramdisk.start, tag->u.ramdisk.size);
593 return 0;
594}
595
596__tagtable(ATAG_RAMDISK, parse_tag_ramdisk);
597
Linus Torvalds1da177e2005-04-16 15:20:36 -0700598static int __init parse_tag_serialnr(const struct tag *tag)
599{
600 system_serial_low = tag->u.serialnr.low;
601 system_serial_high = tag->u.serialnr.high;
602 return 0;
603}
604
605__tagtable(ATAG_SERIAL, parse_tag_serialnr);
606
607static int __init parse_tag_revision(const struct tag *tag)
608{
609 system_rev = tag->u.revision.rev;
610 return 0;
611}
612
613__tagtable(ATAG_REVISION, parse_tag_revision);
614
Alexander Holler92d20402010-02-16 19:04:53 +0100615#ifndef CONFIG_CMDLINE_FORCE
Linus Torvalds1da177e2005-04-16 15:20:36 -0700616static int __init parse_tag_cmdline(const struct tag *tag)
617{
618 strlcpy(default_command_line, tag->u.cmdline.cmdline, COMMAND_LINE_SIZE);
619 return 0;
620}
621
622__tagtable(ATAG_CMDLINE, parse_tag_cmdline);
Alexander Holler92d20402010-02-16 19:04:53 +0100623#endif /* CONFIG_CMDLINE_FORCE */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700624
625/*
626 * Scan the tag table for this tag, and call its parse function.
627 * The tag table is built by the linker from all the __tagtable
628 * declarations.
629 */
630static int __init parse_tag(const struct tag *tag)
631{
632 extern struct tagtable __tagtable_begin, __tagtable_end;
633 struct tagtable *t;
634
635 for (t = &__tagtable_begin; t < &__tagtable_end; t++)
636 if (tag->hdr.tag == t->tag) {
637 t->parse(tag);
638 break;
639 }
640
641 return t < &__tagtable_end;
642}
643
644/*
645 * Parse all tags in the list, checking both the global and architecture
646 * specific tag tables.
647 */
648static void __init parse_tags(const struct tag *t)
649{
650 for (; t->hdr.size; t = tag_next(t))
651 if (!parse_tag(t))
652 printk(KERN_WARNING
653 "Ignoring unrecognised tag 0x%08x\n",
654 t->hdr.tag);
655}
656
657/*
658 * This holds our defaults.
659 */
660static struct init_tags {
661 struct tag_header hdr1;
662 struct tag_core core;
663 struct tag_header hdr2;
664 struct tag_mem32 mem;
665 struct tag_header hdr3;
666} init_tags __initdata = {
667 { tag_size(tag_core), ATAG_CORE },
668 { 1, PAGE_SIZE, 0xff },
669 { tag_size(tag_mem32), ATAG_MEM },
670 { MEM_SIZE, PHYS_OFFSET },
671 { 0, ATAG_NONE }
672};
673
674static void (*init_machine)(void) __initdata;
675
676static int __init customize_machine(void)
677{
678 /* customizes platform devices, or adds new ones */
679 if (init_machine)
680 init_machine();
681 return 0;
682}
683arch_initcall(customize_machine);
684
Mika Westerberg3c57fb42010-05-10 09:20:22 +0100685#ifdef CONFIG_KEXEC
686static inline unsigned long long get_total_mem(void)
687{
688 unsigned long total;
689
690 total = max_low_pfn - min_low_pfn;
691 return total << PAGE_SHIFT;
692}
693
694/**
695 * reserve_crashkernel() - reserves memory are for crash kernel
696 *
697 * This function reserves memory area given in "crashkernel=" kernel command
698 * line parameter. The memory reserved is used by a dump capture kernel when
699 * primary kernel is crashing.
700 */
701static void __init reserve_crashkernel(void)
702{
703 unsigned long long crash_size, crash_base;
704 unsigned long long total_mem;
705 int ret;
706
707 total_mem = get_total_mem();
708 ret = parse_crashkernel(boot_command_line, total_mem,
709 &crash_size, &crash_base);
710 if (ret)
711 return;
712
713 ret = reserve_bootmem(crash_base, crash_size, BOOTMEM_EXCLUSIVE);
714 if (ret < 0) {
715 printk(KERN_WARNING "crashkernel reservation failed - "
716 "memory is in use (0x%lx)\n", (unsigned long)crash_base);
717 return;
718 }
719
720 printk(KERN_INFO "Reserving %ldMB of memory at %ldMB "
721 "for crashkernel (System RAM: %ldMB)\n",
722 (unsigned long)(crash_size >> 20),
723 (unsigned long)(crash_base >> 20),
724 (unsigned long)(total_mem >> 20));
725
726 crashk_res.start = crash_base;
727 crashk_res.end = crash_base + crash_size - 1;
728 insert_resource(&iomem_resource, &crashk_res);
729}
730#else
731static inline void reserve_crashkernel(void) {}
732#endif /* CONFIG_KEXEC */
733
Mika Westerbergcea0bb12010-05-10 09:29:32 +0100734/*
735 * Note: elfcorehdr_addr is not just limited to vmcore. It is also used by
736 * is_kdump_kernel() to determine if we are booting after a panic. Hence
737 * ifdef it under CONFIG_CRASH_DUMP and not CONFIG_PROC_VMCORE.
738 */
739
740#ifdef CONFIG_CRASH_DUMP
741/*
742 * elfcorehdr= specifies the location of elf core header stored by the crashed
743 * kernel. This option will be passed by kexec loader to the capture kernel.
744 */
745static int __init setup_elfcorehdr(char *arg)
746{
747 char *end;
748
749 if (!arg)
750 return -EINVAL;
751
752 elfcorehdr_addr = memparse(arg, &end);
753 return end > arg ? 0 : -EINVAL;
754}
755early_param("elfcorehdr", setup_elfcorehdr);
756#endif /* CONFIG_CRASH_DUMP */
757
Linus Torvalds1da177e2005-04-16 15:20:36 -0700758void __init setup_arch(char **cmdline_p)
759{
760 struct tag *tags = (struct tag *)&init_tags;
761 struct machine_desc *mdesc;
762 char *from = default_command_line;
763
Catalin Marinasbff595c2009-02-16 11:41:36 +0100764 unwind_init();
765
Linus Torvalds1da177e2005-04-16 15:20:36 -0700766 setup_processor();
767 mdesc = setup_machine(machine_arch_type);
768 machine_name = mdesc->name;
769
770 if (mdesc->soft_reboot)
771 reboot_setup("s");
772
Bill Gatliff9d20fdd2007-05-31 22:02:22 +0100773 if (__atags_pointer)
774 tags = phys_to_virt(__atags_pointer);
775 else if (mdesc->boot_params)
Russell Kingf9bd6ea2005-07-04 10:43:36 +0100776 tags = phys_to_virt(mdesc->boot_params);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700777
778 /*
779 * If we have the old style parameters, convert them to
780 * a tag list.
781 */
782 if (tags->hdr.tag != ATAG_CORE)
783 convert_to_tag_list(tags);
784 if (tags->hdr.tag != ATAG_CORE)
785 tags = (struct tag *)&init_tags;
786
787 if (mdesc->fixup)
788 mdesc->fixup(mdesc, tags, &from, &meminfo);
789
790 if (tags->hdr.tag == ATAG_CORE) {
791 if (meminfo.nr_banks != 0)
792 squash_mem_tags(tags);
Richard Purdie4cd9d6f2008-01-02 00:56:46 +0100793 save_atags(tags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700794 parse_tags(tags);
795 }
796
Russell King37efe642008-12-01 11:53:07 +0000797 init_mm.start_code = (unsigned long) _text;
798 init_mm.end_code = (unsigned long) _etext;
799 init_mm.end_data = (unsigned long) _edata;
800 init_mm.brk = (unsigned long) _end;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700801
Jeremy Kerr2b0d8c22010-01-11 23:17:34 +0100802 /* parse_early_param needs a boot_command_line */
803 strlcpy(boot_command_line, from, COMMAND_LINE_SIZE);
804
Jeremy Kerr48ab7e02010-01-27 01:13:31 +0100805 /* populate cmd_line too for later use, preserving boot_command_line */
806 strlcpy(cmd_line, boot_command_line, COMMAND_LINE_SIZE);
807 *cmdline_p = cmd_line;
Jeremy Kerr2b0d8c22010-01-11 23:17:34 +0100808
809 parse_early_param();
810
Nicolas Pitre4b5f32c2008-10-06 13:24:40 -0400811 paging_init(mdesc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700812 request_standard_resources(&meminfo, mdesc);
813
Russell King7bbb7942006-02-16 11:08:09 +0000814#ifdef CONFIG_SMP
815 smp_init_cpus();
816#endif
Mika Westerberg3c57fb42010-05-10 09:20:22 +0100817 reserve_crashkernel();
Russell King7bbb7942006-02-16 11:08:09 +0000818
Russell Kingccea7a12005-05-31 22:22:32 +0100819 cpu_init();
Linus Walleijbc581772009-09-15 17:30:37 +0100820 tcm_init();
Russell Kingccea7a12005-05-31 22:22:32 +0100821
Linus Torvalds1da177e2005-04-16 15:20:36 -0700822 /*
823 * Set up various architecture-specific pointers
824 */
eric miao354e6f72010-06-25 09:46:09 +0100825 arch_nr_irqs = mdesc->nr_irqs;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700826 init_arch_irq = mdesc->init_irq;
827 system_timer = mdesc->timer;
828 init_machine = mdesc->init_machine;
829
830#ifdef CONFIG_VT
831#if defined(CONFIG_VGA_CONSOLE)
832 conswitchp = &vga_con;
833#elif defined(CONFIG_DUMMY_CONSOLE)
834 conswitchp = &dummy_con;
835#endif
836#endif
Jason Wessel5cbad0e2008-02-20 13:33:40 -0600837 early_trap_init();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700838}
839
840
841static int __init topology_init(void)
842{
843 int cpu;
844
Russell King66fb8bd2007-03-13 09:54:21 +0000845 for_each_possible_cpu(cpu) {
846 struct cpuinfo_arm *cpuinfo = &per_cpu(cpu_data, cpu);
847 cpuinfo->cpu.hotpluggable = 1;
848 register_cpu(&cpuinfo->cpu, cpu);
849 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700850
851 return 0;
852}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700853subsys_initcall(topology_init);
854
Russell Kinge119bff2010-01-10 17:23:29 +0000855#ifdef CONFIG_HAVE_PROC_CPU
856static int __init proc_cpu_init(void)
857{
858 struct proc_dir_entry *res;
859
860 res = proc_mkdir("cpu", NULL);
861 if (!res)
862 return -ENOMEM;
863 return 0;
864}
865fs_initcall(proc_cpu_init);
866#endif
867
Linus Torvalds1da177e2005-04-16 15:20:36 -0700868static const char *hwcap_str[] = {
869 "swp",
870 "half",
871 "thumb",
872 "26bit",
873 "fastmult",
874 "fpa",
875 "vfp",
876 "edsp",
877 "java",
Paul Gortmaker8f7f9432006-10-27 05:13:19 +0100878 "iwmmxt",
Lennert Buytenhek99e4a6d2006-12-18 00:59:10 +0100879 "crunch",
Catalin Marinas4369ae12008-11-06 13:23:06 +0000880 "thumbee",
Catalin Marinas2bedbdf2008-11-06 13:23:07 +0000881 "neon",
Catalin Marinas7279dc32009-02-11 13:13:56 +0100882 "vfpv3",
883 "vfpv3d16",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700884 NULL
885};
886
Linus Torvalds1da177e2005-04-16 15:20:36 -0700887static int c_show(struct seq_file *m, void *v)
888{
889 int i;
890
891 seq_printf(m, "Processor\t: %s rev %d (%s)\n",
Russell King0ba8b9b22008-08-10 18:08:10 +0100892 cpu_name, read_cpuid_id() & 15, elf_platform);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700893
894#if defined(CONFIG_SMP)
895 for_each_online_cpu(i) {
Russell King15559722005-11-06 21:41:08 +0000896 /*
897 * glibc reads /proc/cpuinfo to determine the number of
898 * online processors, looking for lines beginning with
899 * "processor". Give glibc what it expects.
900 */
901 seq_printf(m, "processor\t: %d\n", i);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700902 seq_printf(m, "BogoMIPS\t: %lu.%02lu\n\n",
903 per_cpu(cpu_data, i).loops_per_jiffy / (500000UL/HZ),
904 (per_cpu(cpu_data, i).loops_per_jiffy / (5000UL/HZ)) % 100);
905 }
906#else /* CONFIG_SMP */
907 seq_printf(m, "BogoMIPS\t: %lu.%02lu\n",
908 loops_per_jiffy / (500000/HZ),
909 (loops_per_jiffy / (5000/HZ)) % 100);
910#endif
911
912 /* dump out the processor features */
913 seq_puts(m, "Features\t: ");
914
915 for (i = 0; hwcap_str[i]; i++)
916 if (elf_hwcap & (1 << i))
917 seq_printf(m, "%s ", hwcap_str[i]);
918
Russell King0ba8b9b22008-08-10 18:08:10 +0100919 seq_printf(m, "\nCPU implementer\t: 0x%02x\n", read_cpuid_id() >> 24);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700920 seq_printf(m, "CPU architecture: %s\n", proc_arch[cpu_architecture()]);
921
Russell King0ba8b9b22008-08-10 18:08:10 +0100922 if ((read_cpuid_id() & 0x0008f000) == 0x00000000) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700923 /* pre-ARM7 */
Russell King0ba8b9b22008-08-10 18:08:10 +0100924 seq_printf(m, "CPU part\t: %07x\n", read_cpuid_id() >> 4);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700925 } else {
Russell King0ba8b9b22008-08-10 18:08:10 +0100926 if ((read_cpuid_id() & 0x0008f000) == 0x00007000) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700927 /* ARM7 */
928 seq_printf(m, "CPU variant\t: 0x%02x\n",
Russell King0ba8b9b22008-08-10 18:08:10 +0100929 (read_cpuid_id() >> 16) & 127);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700930 } else {
931 /* post-ARM7 */
932 seq_printf(m, "CPU variant\t: 0x%x\n",
Russell King0ba8b9b22008-08-10 18:08:10 +0100933 (read_cpuid_id() >> 20) & 15);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700934 }
935 seq_printf(m, "CPU part\t: 0x%03x\n",
Russell King0ba8b9b22008-08-10 18:08:10 +0100936 (read_cpuid_id() >> 4) & 0xfff);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700937 }
Russell King0ba8b9b22008-08-10 18:08:10 +0100938 seq_printf(m, "CPU revision\t: %d\n", read_cpuid_id() & 15);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700939
Linus Torvalds1da177e2005-04-16 15:20:36 -0700940 seq_puts(m, "\n");
941
942 seq_printf(m, "Hardware\t: %s\n", machine_name);
943 seq_printf(m, "Revision\t: %04x\n", system_rev);
944 seq_printf(m, "Serial\t\t: %08x%08x\n",
945 system_serial_high, system_serial_low);
946
947 return 0;
948}
949
950static void *c_start(struct seq_file *m, loff_t *pos)
951{
952 return *pos < 1 ? (void *)1 : NULL;
953}
954
955static void *c_next(struct seq_file *m, void *v, loff_t *pos)
956{
957 ++*pos;
958 return NULL;
959}
960
961static void c_stop(struct seq_file *m, void *v)
962{
963}
964
Jan Engelhardt2ffd6e12008-01-22 20:41:07 +0100965const struct seq_operations cpuinfo_op = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700966 .start = c_start,
967 .next = c_next,
968 .stop = c_stop,
969 .show = c_show
970};