blob: 714cbaaab3aa3f903e7f4c87f6ae8c87ac97dd74 [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>
Linus Torvalds1da177e2005-04-16 15:20:36 -070023#include <linux/root_dev.h>
24#include <linux/cpu.h>
25#include <linux/interrupt.h>
Russell King7bbb7942006-02-16 11:08:09 +000026#include <linux/smp.h>
Alexey Dobriyan4e950f62007-07-30 02:36:13 +040027#include <linux/fs.h>
Russell Kinge119bff2010-01-10 17:23:29 +000028#include <linux/proc_fs.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070029
Catalin Marinasb86040a2009-07-24 12:32:54 +010030#include <asm/unified.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070031#include <asm/cpu.h>
Russell King0ba8b9b2008-08-10 18:08:10 +010032#include <asm/cputype.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070033#include <asm/elf.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070034#include <asm/procinfo.h>
Russell King37efe642008-12-01 11:53:07 +000035#include <asm/sections.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070036#include <asm/setup.h>
37#include <asm/mach-types.h>
38#include <asm/cacheflush.h>
Russell King46097c72008-08-10 18:10:19 +010039#include <asm/cachetype.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070040#include <asm/tlbflush.h>
41
42#include <asm/mach/arch.h>
43#include <asm/mach/irq.h>
44#include <asm/mach/time.h>
Jason Wessel5cbad0e2008-02-20 13:33:40 -060045#include <asm/traps.h>
Catalin Marinasbff595c2009-02-16 11:41:36 +010046#include <asm/unwind.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070047
Ben Dooks0fc1c832006-03-15 23:17:30 +000048#include "compat.h"
Richard Purdie4cd9d6f2008-01-02 00:56:46 +010049#include "atags.h"
Linus Walleijbc581772009-09-15 17:30:37 +010050#include "tcm.h"
Ben Dooks0fc1c832006-03-15 23:17:30 +000051
Linus Torvalds1da177e2005-04-16 15:20:36 -070052#ifndef MEM_SIZE
53#define MEM_SIZE (16*1024*1024)
54#endif
55
56#if defined(CONFIG_FPE_NWFPE) || defined(CONFIG_FPE_FASTFPE)
57char fpe_type[8];
58
59static int __init fpe_setup(char *line)
60{
61 memcpy(fpe_type, line, 8);
62 return 1;
63}
64
65__setup("fpe=", fpe_setup);
66#endif
67
Nicolas Pitre4b5f32c2008-10-06 13:24:40 -040068extern void paging_init(struct machine_desc *desc);
Linus Torvalds1da177e2005-04-16 15:20:36 -070069extern void reboot_setup(char *str);
Linus Torvalds1da177e2005-04-16 15:20:36 -070070
71unsigned int processor_id;
Krzysztof Halasac18f6582007-12-18 03:53:27 +010072EXPORT_SYMBOL(processor_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -070073unsigned int __machine_arch_type;
74EXPORT_SYMBOL(__machine_arch_type);
Russell Kingc0e95872008-09-25 15:35:28 +010075unsigned int cacheid;
76EXPORT_SYMBOL(cacheid);
Linus Torvalds1da177e2005-04-16 15:20:36 -070077
Bill Gatliff9d20fdd2007-05-31 22:02:22 +010078unsigned int __atags_pointer __initdata;
79
Linus Torvalds1da177e2005-04-16 15:20:36 -070080unsigned int system_rev;
81EXPORT_SYMBOL(system_rev);
82
83unsigned int system_serial_low;
84EXPORT_SYMBOL(system_serial_low);
85
86unsigned int system_serial_high;
87EXPORT_SYMBOL(system_serial_high);
88
89unsigned int elf_hwcap;
90EXPORT_SYMBOL(elf_hwcap);
91
92
93#ifdef MULTI_CPU
94struct processor processor;
95#endif
96#ifdef MULTI_TLB
97struct cpu_tlb_fns cpu_tlb;
98#endif
99#ifdef MULTI_USER
100struct cpu_user_fns cpu_user;
101#endif
102#ifdef MULTI_CACHE
103struct cpu_cache_fns cpu_cache;
104#endif
Catalin Marinas953233d2007-02-05 14:48:08 +0100105#ifdef CONFIG_OUTER_CACHE
106struct outer_cache_fns outer_cache;
Santosh Shilimkar6c09f092010-02-16 07:57:43 +0100107EXPORT_SYMBOL(outer_cache);
Catalin Marinas953233d2007-02-05 14:48:08 +0100108#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109
Russell Kingccea7a12005-05-31 22:22:32 +0100110struct stack {
111 u32 irq[3];
112 u32 abt[3];
113 u32 und[3];
114} ____cacheline_aligned;
115
116static struct stack stacks[NR_CPUS];
117
Linus Torvalds1da177e2005-04-16 15:20:36 -0700118char elf_platform[ELF_PLATFORM_SIZE];
119EXPORT_SYMBOL(elf_platform);
120
Linus Torvalds1da177e2005-04-16 15:20:36 -0700121static const char *cpu_name;
122static const char *machine_name;
Jeremy Kerr48ab7e02010-01-27 01:13:31 +0100123static char __initdata cmd_line[COMMAND_LINE_SIZE];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700124
125static char default_command_line[COMMAND_LINE_SIZE] __initdata = CONFIG_CMDLINE;
126static union { char c[4]; unsigned long l; } endian_test __initdata = { { 'l', '?', '?', 'b' } };
127#define ENDIANNESS ((char)endian_test.l)
128
129DEFINE_PER_CPU(struct cpuinfo_arm, cpu_data);
130
131/*
132 * Standard memory resources
133 */
134static struct resource mem_res[] = {
Greg Kroah-Hartman740e5182006-06-12 14:47:06 -0700135 {
136 .name = "Video RAM",
137 .start = 0,
138 .end = 0,
139 .flags = IORESOURCE_MEM
140 },
141 {
142 .name = "Kernel text",
143 .start = 0,
144 .end = 0,
145 .flags = IORESOURCE_MEM
146 },
147 {
148 .name = "Kernel data",
149 .start = 0,
150 .end = 0,
151 .flags = IORESOURCE_MEM
152 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700153};
154
155#define video_ram mem_res[0]
156#define kernel_code mem_res[1]
157#define kernel_data mem_res[2]
158
159static struct resource io_res[] = {
Greg Kroah-Hartman740e5182006-06-12 14:47:06 -0700160 {
161 .name = "reserved",
162 .start = 0x3bc,
163 .end = 0x3be,
164 .flags = IORESOURCE_IO | IORESOURCE_BUSY
165 },
166 {
167 .name = "reserved",
168 .start = 0x378,
169 .end = 0x37f,
170 .flags = IORESOURCE_IO | IORESOURCE_BUSY
171 },
172 {
173 .name = "reserved",
174 .start = 0x278,
175 .end = 0x27f,
176 .flags = IORESOURCE_IO | IORESOURCE_BUSY
177 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700178};
179
180#define lp0 io_res[0]
181#define lp1 io_res[1]
182#define lp2 io_res[2]
183
Linus Torvalds1da177e2005-04-16 15:20:36 -0700184static const char *proc_arch[] = {
185 "undefined/unknown",
186 "3",
187 "4",
188 "4T",
189 "5",
190 "5T",
191 "5TE",
192 "5TEJ",
193 "6TEJ",
Catalin Marinas6b090a22006-01-12 16:28:16 +0000194 "7",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700195 "?(11)",
196 "?(12)",
197 "?(13)",
198 "?(14)",
199 "?(15)",
200 "?(16)",
201 "?(17)",
202};
203
Linus Torvalds1da177e2005-04-16 15:20:36 -0700204int cpu_architecture(void)
205{
206 int cpu_arch;
207
Russell King0ba8b9b2008-08-10 18:08:10 +0100208 if ((read_cpuid_id() & 0x0008f000) == 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700209 cpu_arch = CPU_ARCH_UNKNOWN;
Russell King0ba8b9b2008-08-10 18:08:10 +0100210 } else if ((read_cpuid_id() & 0x0008f000) == 0x00007000) {
211 cpu_arch = (read_cpuid_id() & (1 << 23)) ? CPU_ARCH_ARMv4T : CPU_ARCH_ARMv3;
212 } else if ((read_cpuid_id() & 0x00080000) == 0x00000000) {
213 cpu_arch = (read_cpuid_id() >> 16) & 7;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700214 if (cpu_arch)
215 cpu_arch += CPU_ARCH_ARMv3;
Russell King0ba8b9b2008-08-10 18:08:10 +0100216 } else if ((read_cpuid_id() & 0x000f0000) == 0x000f0000) {
Catalin Marinas180005c2007-09-25 16:49:45 +0100217 unsigned int mmfr0;
218
219 /* Revised CPUID format. Read the Memory Model Feature
220 * Register 0 and check for VMSAv7 or PMSAv7 */
221 asm("mrc p15, 0, %0, c0, c1, 4"
222 : "=r" (mmfr0));
223 if ((mmfr0 & 0x0000000f) == 0x00000003 ||
224 (mmfr0 & 0x000000f0) == 0x00000030)
225 cpu_arch = CPU_ARCH_ARMv7;
226 else if ((mmfr0 & 0x0000000f) == 0x00000002 ||
227 (mmfr0 & 0x000000f0) == 0x00000020)
228 cpu_arch = CPU_ARCH_ARMv6;
229 else
230 cpu_arch = CPU_ARCH_UNKNOWN;
231 } else
232 cpu_arch = CPU_ARCH_UNKNOWN;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700233
234 return cpu_arch;
235}
236
Russell Kingc0e95872008-09-25 15:35:28 +0100237static void __init cacheid_init(void)
238{
239 unsigned int cachetype = read_cpuid_cachetype();
240 unsigned int arch = cpu_architecture();
241
Catalin Marinasb57ee992009-03-03 11:44:12 +0100242 if (arch >= CPU_ARCH_ARMv6) {
243 if ((cachetype & (7 << 29)) == 4 << 29) {
244 /* ARMv7 register format */
245 cacheid = CACHEID_VIPT_NONALIASING;
246 if ((cachetype & (3 << 14)) == 1 << 14)
247 cacheid |= CACHEID_ASID_TAGGED;
248 } else if (cachetype & (1 << 23))
Russell Kingc0e95872008-09-25 15:35:28 +0100249 cacheid = CACHEID_VIPT_ALIASING;
250 else
251 cacheid = CACHEID_VIPT_NONALIASING;
252 } else {
253 cacheid = CACHEID_VIVT;
254 }
Russell King2b4ae1f2008-09-25 15:39:20 +0100255
256 printk("CPU: %s data cache, %s instruction cache\n",
257 cache_is_vivt() ? "VIVT" :
258 cache_is_vipt_aliasing() ? "VIPT aliasing" :
259 cache_is_vipt_nonaliasing() ? "VIPT nonaliasing" : "unknown",
260 cache_is_vivt() ? "VIVT" :
261 icache_is_vivt_asid_tagged() ? "VIVT ASID tagged" :
262 cache_is_vipt_aliasing() ? "VIPT aliasing" :
263 cache_is_vipt_nonaliasing() ? "VIPT nonaliasing" : "unknown");
Russell Kingc0e95872008-09-25 15:35:28 +0100264}
265
Linus Torvalds1da177e2005-04-16 15:20:36 -0700266/*
267 * These functions re-use the assembly code in head.S, which
268 * already provide the required functionality.
269 */
Russell King0f44ba12006-02-24 21:04:56 +0000270extern struct proc_info_list *lookup_processor_type(unsigned int);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700271extern struct machine_desc *lookup_machine_type(unsigned int);
272
Tony Lindgrenf159f4e2010-07-05 14:53:10 +0100273static void __init feat_v6_fixup(void)
274{
275 int id = read_cpuid_id();
276
277 if ((id & 0xff0f0000) != 0x41070000)
278 return;
279
280 /*
281 * HWCAP_TLS is available only on 1136 r1p0 and later,
282 * see also kuser_get_tls_init.
283 */
284 if ((((id >> 4) & 0xfff) == 0xb36) && (((id >> 20) & 3) == 0))
285 elf_hwcap &= ~HWCAP_TLS;
286}
287
Linus Torvalds1da177e2005-04-16 15:20:36 -0700288static void __init setup_processor(void)
289{
290 struct proc_info_list *list;
291
292 /*
293 * locate processor in the list of supported processor
294 * types. The linker builds this table for us from the
295 * entries in arch/arm/mm/proc-*.S
296 */
Russell King0ba8b9b2008-08-10 18:08:10 +0100297 list = lookup_processor_type(read_cpuid_id());
Linus Torvalds1da177e2005-04-16 15:20:36 -0700298 if (!list) {
299 printk("CPU configuration botched (ID %08x), unable "
Russell King0ba8b9b2008-08-10 18:08:10 +0100300 "to continue.\n", read_cpuid_id());
Linus Torvalds1da177e2005-04-16 15:20:36 -0700301 while (1);
302 }
303
304 cpu_name = list->cpu_name;
305
306#ifdef MULTI_CPU
307 processor = *list->proc;
308#endif
309#ifdef MULTI_TLB
310 cpu_tlb = *list->tlb;
311#endif
312#ifdef MULTI_USER
313 cpu_user = *list->user;
314#endif
315#ifdef MULTI_CACHE
316 cpu_cache = *list->cache;
317#endif
318
Russell King4e190252006-07-03 13:29:38 +0100319 printk("CPU: %s [%08x] revision %d (ARMv%s), cr=%08lx\n",
Russell King0ba8b9b2008-08-10 18:08:10 +0100320 cpu_name, read_cpuid_id(), read_cpuid_id() & 15,
Russell King264edb32006-06-29 15:03:09 +0100321 proc_arch[cpu_architecture()], cr_alignment);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700322
Serge E. Hallyn96b644b2006-10-02 02:18:13 -0700323 sprintf(init_utsname()->machine, "%s%c", list->arch_name, ENDIANNESS);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700324 sprintf(elf_platform, "%s%c", list->elf_name, ENDIANNESS);
325 elf_hwcap = list->elf_hwcap;
Catalin Marinasadeff422006-04-10 21:32:35 +0100326#ifndef CONFIG_ARM_THUMB
327 elf_hwcap &= ~HWCAP_THUMB;
328#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700329
Tony Lindgrenf159f4e2010-07-05 14:53:10 +0100330 feat_v6_fixup();
331
Russell Kingc0e95872008-09-25 15:35:28 +0100332 cacheid_init();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700333 cpu_proc_init();
334}
335
Russell Kingccea7a12005-05-31 22:22:32 +0100336/*
337 * cpu_init - initialise one CPU.
338 *
Russell King90f1e082008-09-25 14:45:02 +0100339 * cpu_init sets up the per-CPU stacks.
Russell Kingccea7a12005-05-31 22:22:32 +0100340 */
Russell King36c5ed22005-06-19 18:39:33 +0100341void cpu_init(void)
Russell Kingccea7a12005-05-31 22:22:32 +0100342{
343 unsigned int cpu = smp_processor_id();
344 struct stack *stk = &stacks[cpu];
345
346 if (cpu >= NR_CPUS) {
347 printk(KERN_CRIT "CPU%u: bad primary CPU number\n", cpu);
348 BUG();
349 }
350
Russell Kingccea7a12005-05-31 22:22:32 +0100351 /*
Catalin Marinasb86040a2009-07-24 12:32:54 +0100352 * Define the placement constraint for the inline asm directive below.
353 * In Thumb-2, msr with an immediate value is not allowed.
354 */
355#ifdef CONFIG_THUMB2_KERNEL
356#define PLC "r"
357#else
358#define PLC "I"
359#endif
360
361 /*
Russell Kingccea7a12005-05-31 22:22:32 +0100362 * setup stacks for re-entrant exception handlers
363 */
364 __asm__ (
365 "msr cpsr_c, %1\n\t"
Catalin Marinasb86040a2009-07-24 12:32:54 +0100366 "add r14, %0, %2\n\t"
367 "mov sp, r14\n\t"
Russell Kingccea7a12005-05-31 22:22:32 +0100368 "msr cpsr_c, %3\n\t"
Catalin Marinasb86040a2009-07-24 12:32:54 +0100369 "add r14, %0, %4\n\t"
370 "mov sp, r14\n\t"
Russell Kingccea7a12005-05-31 22:22:32 +0100371 "msr cpsr_c, %5\n\t"
Catalin Marinasb86040a2009-07-24 12:32:54 +0100372 "add r14, %0, %6\n\t"
373 "mov sp, r14\n\t"
Russell Kingccea7a12005-05-31 22:22:32 +0100374 "msr cpsr_c, %7"
375 :
376 : "r" (stk),
Catalin Marinasb86040a2009-07-24 12:32:54 +0100377 PLC (PSR_F_BIT | PSR_I_BIT | IRQ_MODE),
Russell Kingccea7a12005-05-31 22:22:32 +0100378 "I" (offsetof(struct stack, irq[0])),
Catalin Marinasb86040a2009-07-24 12:32:54 +0100379 PLC (PSR_F_BIT | PSR_I_BIT | ABT_MODE),
Russell Kingccea7a12005-05-31 22:22:32 +0100380 "I" (offsetof(struct stack, abt[0])),
Catalin Marinasb86040a2009-07-24 12:32:54 +0100381 PLC (PSR_F_BIT | PSR_I_BIT | UND_MODE),
Russell Kingccea7a12005-05-31 22:22:32 +0100382 "I" (offsetof(struct stack, und[0])),
Catalin Marinasb86040a2009-07-24 12:32:54 +0100383 PLC (PSR_F_BIT | PSR_I_BIT | SVC_MODE)
Catalin Marinasaaaa3f92005-06-29 15:34:39 +0100384 : "r14");
Russell Kingccea7a12005-05-31 22:22:32 +0100385}
386
Linus Torvalds1da177e2005-04-16 15:20:36 -0700387static struct machine_desc * __init setup_machine(unsigned int nr)
388{
389 struct machine_desc *list;
390
391 /*
392 * locate machine in the list of supported machines.
393 */
394 list = lookup_machine_type(nr);
395 if (!list) {
396 printk("Machine configuration botched (nr %d), unable "
397 "to continue.\n", nr);
398 while (1);
399 }
400
401 printk("Machine: %s\n", list->name);
402
403 return list;
404}
405
Nicolas Pitre4b5f32c2008-10-06 13:24:40 -0400406static int __init arm_add_memory(unsigned long start, unsigned long size)
Russell King3a669412005-06-22 21:43:10 +0100407{
Nicolas Pitre4b5f32c2008-10-06 13:24:40 -0400408 struct membank *bank = &meminfo.bank[meminfo.nr_banks];
409
410 if (meminfo.nr_banks >= NR_BANKS) {
411 printk(KERN_CRIT "NR_BANKS too low, "
412 "ignoring memory at %#lx\n", start);
413 return -EINVAL;
414 }
Russell King05f96ef2006-11-30 20:44:49 +0000415
Russell King3a669412005-06-22 21:43:10 +0100416 /*
417 * Ensure that start/size are aligned to a page boundary.
418 * Size is appropriately rounded down, start is rounded up.
419 */
420 size -= start & ~PAGE_MASK;
Russell King05f96ef2006-11-30 20:44:49 +0000421 bank->start = PAGE_ALIGN(start);
422 bank->size = size & PAGE_MASK;
423 bank->node = PHYS_TO_NID(start);
Nicolas Pitre4b5f32c2008-10-06 13:24:40 -0400424
425 /*
426 * Check whether this memory region has non-zero size or
427 * invalid node number.
428 */
429 if (bank->size == 0 || bank->node >= MAX_NUMNODES)
430 return -EINVAL;
431
432 meminfo.nr_banks++;
433 return 0;
Russell King3a669412005-06-22 21:43:10 +0100434}
435
Linus Torvalds1da177e2005-04-16 15:20:36 -0700436/*
437 * Pick out the memory size. We look for mem=size@start,
438 * where start and size are "size[KkMm]"
439 */
Jeremy Kerr2b0d8c22010-01-11 23:17:34 +0100440static int __init early_mem(char *p)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700441{
442 static int usermem __initdata = 0;
443 unsigned long size, start;
Jeremy Kerr2b0d8c22010-01-11 23:17:34 +0100444 char *endp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700445
446 /*
447 * If the user specifies memory size, we
448 * blow away any automatically generated
449 * size.
450 */
451 if (usermem == 0) {
452 usermem = 1;
453 meminfo.nr_banks = 0;
454 }
455
456 start = PHYS_OFFSET;
Jeremy Kerr2b0d8c22010-01-11 23:17:34 +0100457 size = memparse(p, &endp);
458 if (*endp == '@')
459 start = memparse(endp + 1, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700460
Andrew Morton1c97b732006-04-20 21:41:18 +0100461 arm_add_memory(start, size);
Jeremy Kerr2b0d8c22010-01-11 23:17:34 +0100462
463 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700464}
Jeremy Kerr2b0d8c22010-01-11 23:17:34 +0100465early_param("mem", early_mem);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700466
467static void __init
468setup_ramdisk(int doload, int prompt, int image_start, unsigned int rd_sz)
469{
470#ifdef CONFIG_BLK_DEV_RAM
471 extern int rd_size, rd_image_start, rd_prompt, rd_doload;
472
473 rd_image_start = image_start;
474 rd_prompt = prompt;
475 rd_doload = doload;
476
477 if (rd_sz)
478 rd_size = rd_sz;
479#endif
480}
481
482static void __init
483request_standard_resources(struct meminfo *mi, struct machine_desc *mdesc)
484{
485 struct resource *res;
486 int i;
487
Russell King37efe642008-12-01 11:53:07 +0000488 kernel_code.start = virt_to_phys(_text);
489 kernel_code.end = virt_to_phys(_etext - 1);
490 kernel_data.start = virt_to_phys(_data);
491 kernel_data.end = virt_to_phys(_end - 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700492
493 for (i = 0; i < mi->nr_banks; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700494 if (mi->bank[i].size == 0)
495 continue;
496
Linus Torvalds1da177e2005-04-16 15:20:36 -0700497 res = alloc_bootmem_low(sizeof(*res));
498 res->name = "System RAM";
Nicolas Pitre3319f5e2008-10-02 03:29:22 +0100499 res->start = mi->bank[i].start;
500 res->end = mi->bank[i].start + mi->bank[i].size - 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700501 res->flags = IORESOURCE_MEM | IORESOURCE_BUSY;
502
503 request_resource(&iomem_resource, res);
504
505 if (kernel_code.start >= res->start &&
506 kernel_code.end <= res->end)
507 request_resource(res, &kernel_code);
508 if (kernel_data.start >= res->start &&
509 kernel_data.end <= res->end)
510 request_resource(res, &kernel_data);
511 }
512
513 if (mdesc->video_start) {
514 video_ram.start = mdesc->video_start;
515 video_ram.end = mdesc->video_end;
516 request_resource(&iomem_resource, &video_ram);
517 }
518
519 /*
520 * Some machines don't have the possibility of ever
521 * possessing lp0, lp1 or lp2
522 */
523 if (mdesc->reserve_lp0)
524 request_resource(&ioport_resource, &lp0);
525 if (mdesc->reserve_lp1)
526 request_resource(&ioport_resource, &lp1);
527 if (mdesc->reserve_lp2)
528 request_resource(&ioport_resource, &lp2);
529}
530
531/*
532 * Tag parsing.
533 *
534 * This is the new way of passing data to the kernel at boot time. Rather
535 * than passing a fixed inflexible structure to the kernel, we pass a list
536 * of variable-sized tags to the kernel. The first tag must be a ATAG_CORE
537 * tag for the list to be recognised (to distinguish the tagged list from
538 * a param_struct). The list is terminated with a zero-length tag (this tag
539 * is not parsed in any way).
540 */
541static int __init parse_tag_core(const struct tag *tag)
542{
543 if (tag->hdr.size > 2) {
544 if ((tag->u.core.flags & 1) == 0)
545 root_mountflags &= ~MS_RDONLY;
546 ROOT_DEV = old_decode_dev(tag->u.core.rootdev);
547 }
548 return 0;
549}
550
551__tagtable(ATAG_CORE, parse_tag_core);
552
553static int __init parse_tag_mem32(const struct tag *tag)
554{
Nicolas Pitre4b5f32c2008-10-06 13:24:40 -0400555 return arm_add_memory(tag->u.mem.start, tag->u.mem.size);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700556}
557
558__tagtable(ATAG_MEM, parse_tag_mem32);
559
560#if defined(CONFIG_VGA_CONSOLE) || defined(CONFIG_DUMMY_CONSOLE)
561struct screen_info screen_info = {
562 .orig_video_lines = 30,
563 .orig_video_cols = 80,
564 .orig_video_mode = 0,
565 .orig_video_ega_bx = 0,
566 .orig_video_isVGA = 1,
567 .orig_video_points = 8
568};
569
570static int __init parse_tag_videotext(const struct tag *tag)
571{
572 screen_info.orig_x = tag->u.videotext.x;
573 screen_info.orig_y = tag->u.videotext.y;
574 screen_info.orig_video_page = tag->u.videotext.video_page;
575 screen_info.orig_video_mode = tag->u.videotext.video_mode;
576 screen_info.orig_video_cols = tag->u.videotext.video_cols;
577 screen_info.orig_video_ega_bx = tag->u.videotext.video_ega_bx;
578 screen_info.orig_video_lines = tag->u.videotext.video_lines;
579 screen_info.orig_video_isVGA = tag->u.videotext.video_isvga;
580 screen_info.orig_video_points = tag->u.videotext.video_points;
581 return 0;
582}
583
584__tagtable(ATAG_VIDEOTEXT, parse_tag_videotext);
585#endif
586
587static int __init parse_tag_ramdisk(const struct tag *tag)
588{
589 setup_ramdisk((tag->u.ramdisk.flags & 1) == 0,
590 (tag->u.ramdisk.flags & 2) == 0,
591 tag->u.ramdisk.start, tag->u.ramdisk.size);
592 return 0;
593}
594
595__tagtable(ATAG_RAMDISK, parse_tag_ramdisk);
596
Linus Torvalds1da177e2005-04-16 15:20:36 -0700597static int __init parse_tag_serialnr(const struct tag *tag)
598{
599 system_serial_low = tag->u.serialnr.low;
600 system_serial_high = tag->u.serialnr.high;
601 return 0;
602}
603
604__tagtable(ATAG_SERIAL, parse_tag_serialnr);
605
606static int __init parse_tag_revision(const struct tag *tag)
607{
608 system_rev = tag->u.revision.rev;
609 return 0;
610}
611
612__tagtable(ATAG_REVISION, parse_tag_revision);
613
Alexander Holler92d20402010-02-16 19:04:53 +0100614#ifndef CONFIG_CMDLINE_FORCE
Linus Torvalds1da177e2005-04-16 15:20:36 -0700615static int __init parse_tag_cmdline(const struct tag *tag)
616{
617 strlcpy(default_command_line, tag->u.cmdline.cmdline, COMMAND_LINE_SIZE);
618 return 0;
619}
620
621__tagtable(ATAG_CMDLINE, parse_tag_cmdline);
Alexander Holler92d20402010-02-16 19:04:53 +0100622#endif /* CONFIG_CMDLINE_FORCE */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700623
624/*
625 * Scan the tag table for this tag, and call its parse function.
626 * The tag table is built by the linker from all the __tagtable
627 * declarations.
628 */
629static int __init parse_tag(const struct tag *tag)
630{
631 extern struct tagtable __tagtable_begin, __tagtable_end;
632 struct tagtable *t;
633
634 for (t = &__tagtable_begin; t < &__tagtable_end; t++)
635 if (tag->hdr.tag == t->tag) {
636 t->parse(tag);
637 break;
638 }
639
640 return t < &__tagtable_end;
641}
642
643/*
644 * Parse all tags in the list, checking both the global and architecture
645 * specific tag tables.
646 */
647static void __init parse_tags(const struct tag *t)
648{
649 for (; t->hdr.size; t = tag_next(t))
650 if (!parse_tag(t))
651 printk(KERN_WARNING
652 "Ignoring unrecognised tag 0x%08x\n",
653 t->hdr.tag);
654}
655
656/*
657 * This holds our defaults.
658 */
659static struct init_tags {
660 struct tag_header hdr1;
661 struct tag_core core;
662 struct tag_header hdr2;
663 struct tag_mem32 mem;
664 struct tag_header hdr3;
665} init_tags __initdata = {
666 { tag_size(tag_core), ATAG_CORE },
667 { 1, PAGE_SIZE, 0xff },
668 { tag_size(tag_mem32), ATAG_MEM },
669 { MEM_SIZE, PHYS_OFFSET },
670 { 0, ATAG_NONE }
671};
672
673static void (*init_machine)(void) __initdata;
674
675static int __init customize_machine(void)
676{
677 /* customizes platform devices, or adds new ones */
678 if (init_machine)
679 init_machine();
680 return 0;
681}
682arch_initcall(customize_machine);
683
Mika Westerberg3c57fb42010-05-10 09:20:22 +0100684#ifdef CONFIG_KEXEC
685static inline unsigned long long get_total_mem(void)
686{
687 unsigned long total;
688
689 total = max_low_pfn - min_low_pfn;
690 return total << PAGE_SHIFT;
691}
692
693/**
694 * reserve_crashkernel() - reserves memory are for crash kernel
695 *
696 * This function reserves memory area given in "crashkernel=" kernel command
697 * line parameter. The memory reserved is used by a dump capture kernel when
698 * primary kernel is crashing.
699 */
700static void __init reserve_crashkernel(void)
701{
702 unsigned long long crash_size, crash_base;
703 unsigned long long total_mem;
704 int ret;
705
706 total_mem = get_total_mem();
707 ret = parse_crashkernel(boot_command_line, total_mem,
708 &crash_size, &crash_base);
709 if (ret)
710 return;
711
712 ret = reserve_bootmem(crash_base, crash_size, BOOTMEM_EXCLUSIVE);
713 if (ret < 0) {
714 printk(KERN_WARNING "crashkernel reservation failed - "
715 "memory is in use (0x%lx)\n", (unsigned long)crash_base);
716 return;
717 }
718
719 printk(KERN_INFO "Reserving %ldMB of memory at %ldMB "
720 "for crashkernel (System RAM: %ldMB)\n",
721 (unsigned long)(crash_size >> 20),
722 (unsigned long)(crash_base >> 20),
723 (unsigned long)(total_mem >> 20));
724
725 crashk_res.start = crash_base;
726 crashk_res.end = crash_base + crash_size - 1;
727 insert_resource(&iomem_resource, &crashk_res);
728}
729#else
730static inline void reserve_crashkernel(void) {}
731#endif /* CONFIG_KEXEC */
732
Linus Torvalds1da177e2005-04-16 15:20:36 -0700733void __init setup_arch(char **cmdline_p)
734{
735 struct tag *tags = (struct tag *)&init_tags;
736 struct machine_desc *mdesc;
737 char *from = default_command_line;
738
Catalin Marinasbff595c2009-02-16 11:41:36 +0100739 unwind_init();
740
Linus Torvalds1da177e2005-04-16 15:20:36 -0700741 setup_processor();
742 mdesc = setup_machine(machine_arch_type);
743 machine_name = mdesc->name;
744
745 if (mdesc->soft_reboot)
746 reboot_setup("s");
747
Bill Gatliff9d20fdd2007-05-31 22:02:22 +0100748 if (__atags_pointer)
749 tags = phys_to_virt(__atags_pointer);
750 else if (mdesc->boot_params)
Russell Kingf9bd6ea2005-07-04 10:43:36 +0100751 tags = phys_to_virt(mdesc->boot_params);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700752
753 /*
754 * If we have the old style parameters, convert them to
755 * a tag list.
756 */
757 if (tags->hdr.tag != ATAG_CORE)
758 convert_to_tag_list(tags);
759 if (tags->hdr.tag != ATAG_CORE)
760 tags = (struct tag *)&init_tags;
761
762 if (mdesc->fixup)
763 mdesc->fixup(mdesc, tags, &from, &meminfo);
764
765 if (tags->hdr.tag == ATAG_CORE) {
766 if (meminfo.nr_banks != 0)
767 squash_mem_tags(tags);
Richard Purdie4cd9d6f2008-01-02 00:56:46 +0100768 save_atags(tags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700769 parse_tags(tags);
770 }
771
Russell King37efe642008-12-01 11:53:07 +0000772 init_mm.start_code = (unsigned long) _text;
773 init_mm.end_code = (unsigned long) _etext;
774 init_mm.end_data = (unsigned long) _edata;
775 init_mm.brk = (unsigned long) _end;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700776
Jeremy Kerr2b0d8c22010-01-11 23:17:34 +0100777 /* parse_early_param needs a boot_command_line */
778 strlcpy(boot_command_line, from, COMMAND_LINE_SIZE);
779
Jeremy Kerr48ab7e02010-01-27 01:13:31 +0100780 /* populate cmd_line too for later use, preserving boot_command_line */
781 strlcpy(cmd_line, boot_command_line, COMMAND_LINE_SIZE);
782 *cmdline_p = cmd_line;
Jeremy Kerr2b0d8c22010-01-11 23:17:34 +0100783
784 parse_early_param();
785
Nicolas Pitre4b5f32c2008-10-06 13:24:40 -0400786 paging_init(mdesc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700787 request_standard_resources(&meminfo, mdesc);
788
Russell King7bbb7942006-02-16 11:08:09 +0000789#ifdef CONFIG_SMP
790 smp_init_cpus();
791#endif
Mika Westerberg3c57fb42010-05-10 09:20:22 +0100792 reserve_crashkernel();
Russell King7bbb7942006-02-16 11:08:09 +0000793
Russell Kingccea7a12005-05-31 22:22:32 +0100794 cpu_init();
Linus Walleijbc581772009-09-15 17:30:37 +0100795 tcm_init();
Russell Kingccea7a12005-05-31 22:22:32 +0100796
Linus Torvalds1da177e2005-04-16 15:20:36 -0700797 /*
798 * Set up various architecture-specific pointers
799 */
eric miao354e6f72010-06-25 09:46:09 +0100800 arch_nr_irqs = mdesc->nr_irqs;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700801 init_arch_irq = mdesc->init_irq;
802 system_timer = mdesc->timer;
803 init_machine = mdesc->init_machine;
804
805#ifdef CONFIG_VT
806#if defined(CONFIG_VGA_CONSOLE)
807 conswitchp = &vga_con;
808#elif defined(CONFIG_DUMMY_CONSOLE)
809 conswitchp = &dummy_con;
810#endif
811#endif
Jason Wessel5cbad0e2008-02-20 13:33:40 -0600812 early_trap_init();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700813}
814
815
816static int __init topology_init(void)
817{
818 int cpu;
819
Russell King66fb8bd2007-03-13 09:54:21 +0000820 for_each_possible_cpu(cpu) {
821 struct cpuinfo_arm *cpuinfo = &per_cpu(cpu_data, cpu);
822 cpuinfo->cpu.hotpluggable = 1;
823 register_cpu(&cpuinfo->cpu, cpu);
824 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700825
826 return 0;
827}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700828subsys_initcall(topology_init);
829
Russell Kinge119bff2010-01-10 17:23:29 +0000830#ifdef CONFIG_HAVE_PROC_CPU
831static int __init proc_cpu_init(void)
832{
833 struct proc_dir_entry *res;
834
835 res = proc_mkdir("cpu", NULL);
836 if (!res)
837 return -ENOMEM;
838 return 0;
839}
840fs_initcall(proc_cpu_init);
841#endif
842
Linus Torvalds1da177e2005-04-16 15:20:36 -0700843static const char *hwcap_str[] = {
844 "swp",
845 "half",
846 "thumb",
847 "26bit",
848 "fastmult",
849 "fpa",
850 "vfp",
851 "edsp",
852 "java",
Paul Gortmaker8f7f9432006-10-27 05:13:19 +0100853 "iwmmxt",
Lennert Buytenhek99e4a6d2006-12-18 00:59:10 +0100854 "crunch",
Catalin Marinas4369ae12008-11-06 13:23:06 +0000855 "thumbee",
Catalin Marinas2bedbdf2008-11-06 13:23:07 +0000856 "neon",
Catalin Marinas7279dc32009-02-11 13:13:56 +0100857 "vfpv3",
858 "vfpv3d16",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700859 NULL
860};
861
Linus Torvalds1da177e2005-04-16 15:20:36 -0700862static int c_show(struct seq_file *m, void *v)
863{
864 int i;
865
866 seq_printf(m, "Processor\t: %s rev %d (%s)\n",
Russell King0ba8b9b2008-08-10 18:08:10 +0100867 cpu_name, read_cpuid_id() & 15, elf_platform);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700868
869#if defined(CONFIG_SMP)
870 for_each_online_cpu(i) {
Russell King15559722005-11-06 21:41:08 +0000871 /*
872 * glibc reads /proc/cpuinfo to determine the number of
873 * online processors, looking for lines beginning with
874 * "processor". Give glibc what it expects.
875 */
876 seq_printf(m, "processor\t: %d\n", i);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700877 seq_printf(m, "BogoMIPS\t: %lu.%02lu\n\n",
878 per_cpu(cpu_data, i).loops_per_jiffy / (500000UL/HZ),
879 (per_cpu(cpu_data, i).loops_per_jiffy / (5000UL/HZ)) % 100);
880 }
881#else /* CONFIG_SMP */
882 seq_printf(m, "BogoMIPS\t: %lu.%02lu\n",
883 loops_per_jiffy / (500000/HZ),
884 (loops_per_jiffy / (5000/HZ)) % 100);
885#endif
886
887 /* dump out the processor features */
888 seq_puts(m, "Features\t: ");
889
890 for (i = 0; hwcap_str[i]; i++)
891 if (elf_hwcap & (1 << i))
892 seq_printf(m, "%s ", hwcap_str[i]);
893
Russell King0ba8b9b2008-08-10 18:08:10 +0100894 seq_printf(m, "\nCPU implementer\t: 0x%02x\n", read_cpuid_id() >> 24);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700895 seq_printf(m, "CPU architecture: %s\n", proc_arch[cpu_architecture()]);
896
Russell King0ba8b9b2008-08-10 18:08:10 +0100897 if ((read_cpuid_id() & 0x0008f000) == 0x00000000) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700898 /* pre-ARM7 */
Russell King0ba8b9b2008-08-10 18:08:10 +0100899 seq_printf(m, "CPU part\t: %07x\n", read_cpuid_id() >> 4);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700900 } else {
Russell King0ba8b9b2008-08-10 18:08:10 +0100901 if ((read_cpuid_id() & 0x0008f000) == 0x00007000) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700902 /* ARM7 */
903 seq_printf(m, "CPU variant\t: 0x%02x\n",
Russell King0ba8b9b2008-08-10 18:08:10 +0100904 (read_cpuid_id() >> 16) & 127);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700905 } else {
906 /* post-ARM7 */
907 seq_printf(m, "CPU variant\t: 0x%x\n",
Russell King0ba8b9b2008-08-10 18:08:10 +0100908 (read_cpuid_id() >> 20) & 15);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700909 }
910 seq_printf(m, "CPU part\t: 0x%03x\n",
Russell King0ba8b9b2008-08-10 18:08:10 +0100911 (read_cpuid_id() >> 4) & 0xfff);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700912 }
Russell King0ba8b9b2008-08-10 18:08:10 +0100913 seq_printf(m, "CPU revision\t: %d\n", read_cpuid_id() & 15);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700914
Linus Torvalds1da177e2005-04-16 15:20:36 -0700915 seq_puts(m, "\n");
916
917 seq_printf(m, "Hardware\t: %s\n", machine_name);
918 seq_printf(m, "Revision\t: %04x\n", system_rev);
919 seq_printf(m, "Serial\t\t: %08x%08x\n",
920 system_serial_high, system_serial_low);
921
922 return 0;
923}
924
925static void *c_start(struct seq_file *m, loff_t *pos)
926{
927 return *pos < 1 ? (void *)1 : NULL;
928}
929
930static void *c_next(struct seq_file *m, void *v, loff_t *pos)
931{
932 ++*pos;
933 return NULL;
934}
935
936static void c_stop(struct seq_file *m, void *v)
937{
938}
939
Jan Engelhardt2ffd6e12008-01-22 20:41:07 +0100940const struct seq_operations cpuinfo_op = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700941 .start = c_start,
942 .next = c_next,
943 .stop = c_stop,
944 .show = c_show
945};