blob: cbc6ddb1c9bde7204fd2e184ad0bcb80ffc69c31 [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>
22#include <linux/root_dev.h>
23#include <linux/cpu.h>
24#include <linux/interrupt.h>
Russell King7bbb7942006-02-16 11:08:09 +000025#include <linux/smp.h>
Alexey Dobriyan4e950f62007-07-30 02:36:13 +040026#include <linux/fs.h>
Russell Kinge119bff2010-01-10 17:23:29 +000027#include <linux/proc_fs.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070028
Catalin Marinasb86040a2009-07-24 12:32:54 +010029#include <asm/unified.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070030#include <asm/cpu.h>
Russell King0ba8b9b2008-08-10 18:08:10 +010031#include <asm/cputype.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070032#include <asm/elf.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070033#include <asm/procinfo.h>
Russell King37efe642008-12-01 11:53:07 +000034#include <asm/sections.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070035#include <asm/setup.h>
36#include <asm/mach-types.h>
37#include <asm/cacheflush.h>
Russell King46097c72008-08-10 18:10:19 +010038#include <asm/cachetype.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070039#include <asm/tlbflush.h>
40
41#include <asm/mach/arch.h>
42#include <asm/mach/irq.h>
43#include <asm/mach/time.h>
Jason Wessel5cbad0e2008-02-20 13:33:40 -060044#include <asm/traps.h>
Catalin Marinasbff595c2009-02-16 11:41:36 +010045#include <asm/unwind.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070046
Uwe Kleine-König73a65b32010-01-19 10:13:14 +010047#if defined(CONFIG_DEPRECATED_PARAM_STRUCT)
Ben Dooks0fc1c832006-03-15 23:17:30 +000048#include "compat.h"
Uwe Kleine-König73a65b32010-01-19 10:13:14 +010049#endif
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 King0ba8b9b2008-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 King0ba8b9b2008-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 King0ba8b9b2008-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
274static void __init setup_processor(void)
275{
276 struct proc_info_list *list;
277
278 /*
279 * locate processor in the list of supported processor
280 * types. The linker builds this table for us from the
281 * entries in arch/arm/mm/proc-*.S
282 */
Russell King0ba8b9b2008-08-10 18:08:10 +0100283 list = lookup_processor_type(read_cpuid_id());
Linus Torvalds1da177e2005-04-16 15:20:36 -0700284 if (!list) {
285 printk("CPU configuration botched (ID %08x), unable "
Russell King0ba8b9b2008-08-10 18:08:10 +0100286 "to continue.\n", read_cpuid_id());
Linus Torvalds1da177e2005-04-16 15:20:36 -0700287 while (1);
288 }
289
290 cpu_name = list->cpu_name;
291
292#ifdef MULTI_CPU
293 processor = *list->proc;
294#endif
295#ifdef MULTI_TLB
296 cpu_tlb = *list->tlb;
297#endif
298#ifdef MULTI_USER
299 cpu_user = *list->user;
300#endif
301#ifdef MULTI_CACHE
302 cpu_cache = *list->cache;
303#endif
304
Russell King4e190252006-07-03 13:29:38 +0100305 printk("CPU: %s [%08x] revision %d (ARMv%s), cr=%08lx\n",
Russell King0ba8b9b2008-08-10 18:08:10 +0100306 cpu_name, read_cpuid_id(), read_cpuid_id() & 15,
Russell King264edb32006-06-29 15:03:09 +0100307 proc_arch[cpu_architecture()], cr_alignment);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700308
Serge E. Hallyn96b644b2006-10-02 02:18:13 -0700309 sprintf(init_utsname()->machine, "%s%c", list->arch_name, ENDIANNESS);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700310 sprintf(elf_platform, "%s%c", list->elf_name, ENDIANNESS);
311 elf_hwcap = list->elf_hwcap;
Catalin Marinasadeff422006-04-10 21:32:35 +0100312#ifndef CONFIG_ARM_THUMB
313 elf_hwcap &= ~HWCAP_THUMB;
314#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700315
Russell Kingc0e95872008-09-25 15:35:28 +0100316 cacheid_init();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700317 cpu_proc_init();
318}
319
Russell Kingccea7a12005-05-31 22:22:32 +0100320/*
321 * cpu_init - initialise one CPU.
322 *
Russell King90f1e082008-09-25 14:45:02 +0100323 * cpu_init sets up the per-CPU stacks.
Russell Kingccea7a12005-05-31 22:22:32 +0100324 */
Russell King36c5ed22005-06-19 18:39:33 +0100325void cpu_init(void)
Russell Kingccea7a12005-05-31 22:22:32 +0100326{
327 unsigned int cpu = smp_processor_id();
328 struct stack *stk = &stacks[cpu];
329
330 if (cpu >= NR_CPUS) {
331 printk(KERN_CRIT "CPU%u: bad primary CPU number\n", cpu);
332 BUG();
333 }
334
Russell Kingccea7a12005-05-31 22:22:32 +0100335 /*
Catalin Marinasb86040a2009-07-24 12:32:54 +0100336 * Define the placement constraint for the inline asm directive below.
337 * In Thumb-2, msr with an immediate value is not allowed.
338 */
339#ifdef CONFIG_THUMB2_KERNEL
340#define PLC "r"
341#else
342#define PLC "I"
343#endif
344
345 /*
Russell Kingccea7a12005-05-31 22:22:32 +0100346 * setup stacks for re-entrant exception handlers
347 */
348 __asm__ (
349 "msr cpsr_c, %1\n\t"
Catalin Marinasb86040a2009-07-24 12:32:54 +0100350 "add r14, %0, %2\n\t"
351 "mov sp, r14\n\t"
Russell Kingccea7a12005-05-31 22:22:32 +0100352 "msr cpsr_c, %3\n\t"
Catalin Marinasb86040a2009-07-24 12:32:54 +0100353 "add r14, %0, %4\n\t"
354 "mov sp, r14\n\t"
Russell Kingccea7a12005-05-31 22:22:32 +0100355 "msr cpsr_c, %5\n\t"
Catalin Marinasb86040a2009-07-24 12:32:54 +0100356 "add r14, %0, %6\n\t"
357 "mov sp, r14\n\t"
Russell Kingccea7a12005-05-31 22:22:32 +0100358 "msr cpsr_c, %7"
359 :
360 : "r" (stk),
Catalin Marinasb86040a2009-07-24 12:32:54 +0100361 PLC (PSR_F_BIT | PSR_I_BIT | IRQ_MODE),
Russell Kingccea7a12005-05-31 22:22:32 +0100362 "I" (offsetof(struct stack, irq[0])),
Catalin Marinasb86040a2009-07-24 12:32:54 +0100363 PLC (PSR_F_BIT | PSR_I_BIT | ABT_MODE),
Russell Kingccea7a12005-05-31 22:22:32 +0100364 "I" (offsetof(struct stack, abt[0])),
Catalin Marinasb86040a2009-07-24 12:32:54 +0100365 PLC (PSR_F_BIT | PSR_I_BIT | UND_MODE),
Russell Kingccea7a12005-05-31 22:22:32 +0100366 "I" (offsetof(struct stack, und[0])),
Catalin Marinasb86040a2009-07-24 12:32:54 +0100367 PLC (PSR_F_BIT | PSR_I_BIT | SVC_MODE)
Catalin Marinasaaaa3f92005-06-29 15:34:39 +0100368 : "r14");
Russell Kingccea7a12005-05-31 22:22:32 +0100369}
370
Linus Torvalds1da177e2005-04-16 15:20:36 -0700371static struct machine_desc * __init setup_machine(unsigned int nr)
372{
373 struct machine_desc *list;
374
375 /*
376 * locate machine in the list of supported machines.
377 */
378 list = lookup_machine_type(nr);
379 if (!list) {
380 printk("Machine configuration botched (nr %d), unable "
381 "to continue.\n", nr);
382 while (1);
383 }
384
385 printk("Machine: %s\n", list->name);
386
387 return list;
388}
389
Nicolas Pitre4b5f32c2008-10-06 13:24:40 -0400390static int __init arm_add_memory(unsigned long start, unsigned long size)
Russell King3a669412005-06-22 21:43:10 +0100391{
Nicolas Pitre4b5f32c2008-10-06 13:24:40 -0400392 struct membank *bank = &meminfo.bank[meminfo.nr_banks];
393
394 if (meminfo.nr_banks >= NR_BANKS) {
395 printk(KERN_CRIT "NR_BANKS too low, "
396 "ignoring memory at %#lx\n", start);
397 return -EINVAL;
398 }
Russell King05f96ef2006-11-30 20:44:49 +0000399
Russell King3a669412005-06-22 21:43:10 +0100400 /*
401 * Ensure that start/size are aligned to a page boundary.
402 * Size is appropriately rounded down, start is rounded up.
403 */
404 size -= start & ~PAGE_MASK;
Russell King05f96ef2006-11-30 20:44:49 +0000405 bank->start = PAGE_ALIGN(start);
406 bank->size = size & PAGE_MASK;
407 bank->node = PHYS_TO_NID(start);
Nicolas Pitre4b5f32c2008-10-06 13:24:40 -0400408
409 /*
410 * Check whether this memory region has non-zero size or
411 * invalid node number.
412 */
413 if (bank->size == 0 || bank->node >= MAX_NUMNODES)
414 return -EINVAL;
415
416 meminfo.nr_banks++;
417 return 0;
Russell King3a669412005-06-22 21:43:10 +0100418}
419
Linus Torvalds1da177e2005-04-16 15:20:36 -0700420/*
421 * Pick out the memory size. We look for mem=size@start,
422 * where start and size are "size[KkMm]"
423 */
Jeremy Kerr2b0d8c22010-01-11 23:17:34 +0100424static int __init early_mem(char *p)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700425{
426 static int usermem __initdata = 0;
427 unsigned long size, start;
Jeremy Kerr2b0d8c22010-01-11 23:17:34 +0100428 char *endp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700429
430 /*
431 * If the user specifies memory size, we
432 * blow away any automatically generated
433 * size.
434 */
435 if (usermem == 0) {
436 usermem = 1;
437 meminfo.nr_banks = 0;
438 }
439
440 start = PHYS_OFFSET;
Jeremy Kerr2b0d8c22010-01-11 23:17:34 +0100441 size = memparse(p, &endp);
442 if (*endp == '@')
443 start = memparse(endp + 1, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700444
Andrew Morton1c97b732006-04-20 21:41:18 +0100445 arm_add_memory(start, size);
Jeremy Kerr2b0d8c22010-01-11 23:17:34 +0100446
447 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700448}
Jeremy Kerr2b0d8c22010-01-11 23:17:34 +0100449early_param("mem", early_mem);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700450
451static void __init
452setup_ramdisk(int doload, int prompt, int image_start, unsigned int rd_sz)
453{
454#ifdef CONFIG_BLK_DEV_RAM
455 extern int rd_size, rd_image_start, rd_prompt, rd_doload;
456
457 rd_image_start = image_start;
458 rd_prompt = prompt;
459 rd_doload = doload;
460
461 if (rd_sz)
462 rd_size = rd_sz;
463#endif
464}
465
466static void __init
467request_standard_resources(struct meminfo *mi, struct machine_desc *mdesc)
468{
469 struct resource *res;
470 int i;
471
Russell King37efe642008-12-01 11:53:07 +0000472 kernel_code.start = virt_to_phys(_text);
473 kernel_code.end = virt_to_phys(_etext - 1);
474 kernel_data.start = virt_to_phys(_data);
475 kernel_data.end = virt_to_phys(_end - 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700476
477 for (i = 0; i < mi->nr_banks; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700478 if (mi->bank[i].size == 0)
479 continue;
480
Linus Torvalds1da177e2005-04-16 15:20:36 -0700481 res = alloc_bootmem_low(sizeof(*res));
482 res->name = "System RAM";
Nicolas Pitre3319f5e2008-10-02 03:29:22 +0100483 res->start = mi->bank[i].start;
484 res->end = mi->bank[i].start + mi->bank[i].size - 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700485 res->flags = IORESOURCE_MEM | IORESOURCE_BUSY;
486
487 request_resource(&iomem_resource, res);
488
489 if (kernel_code.start >= res->start &&
490 kernel_code.end <= res->end)
491 request_resource(res, &kernel_code);
492 if (kernel_data.start >= res->start &&
493 kernel_data.end <= res->end)
494 request_resource(res, &kernel_data);
495 }
496
497 if (mdesc->video_start) {
498 video_ram.start = mdesc->video_start;
499 video_ram.end = mdesc->video_end;
500 request_resource(&iomem_resource, &video_ram);
501 }
502
503 /*
504 * Some machines don't have the possibility of ever
505 * possessing lp0, lp1 or lp2
506 */
507 if (mdesc->reserve_lp0)
508 request_resource(&ioport_resource, &lp0);
509 if (mdesc->reserve_lp1)
510 request_resource(&ioport_resource, &lp1);
511 if (mdesc->reserve_lp2)
512 request_resource(&ioport_resource, &lp2);
513}
514
515/*
516 * Tag parsing.
517 *
518 * This is the new way of passing data to the kernel at boot time. Rather
519 * than passing a fixed inflexible structure to the kernel, we pass a list
520 * of variable-sized tags to the kernel. The first tag must be a ATAG_CORE
521 * tag for the list to be recognised (to distinguish the tagged list from
522 * a param_struct). The list is terminated with a zero-length tag (this tag
523 * is not parsed in any way).
524 */
525static int __init parse_tag_core(const struct tag *tag)
526{
527 if (tag->hdr.size > 2) {
528 if ((tag->u.core.flags & 1) == 0)
529 root_mountflags &= ~MS_RDONLY;
530 ROOT_DEV = old_decode_dev(tag->u.core.rootdev);
531 }
532 return 0;
533}
534
535__tagtable(ATAG_CORE, parse_tag_core);
536
537static int __init parse_tag_mem32(const struct tag *tag)
538{
Nicolas Pitre4b5f32c2008-10-06 13:24:40 -0400539 return arm_add_memory(tag->u.mem.start, tag->u.mem.size);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700540}
541
542__tagtable(ATAG_MEM, parse_tag_mem32);
543
544#if defined(CONFIG_VGA_CONSOLE) || defined(CONFIG_DUMMY_CONSOLE)
545struct screen_info screen_info = {
546 .orig_video_lines = 30,
547 .orig_video_cols = 80,
548 .orig_video_mode = 0,
549 .orig_video_ega_bx = 0,
550 .orig_video_isVGA = 1,
551 .orig_video_points = 8
552};
553
554static int __init parse_tag_videotext(const struct tag *tag)
555{
556 screen_info.orig_x = tag->u.videotext.x;
557 screen_info.orig_y = tag->u.videotext.y;
558 screen_info.orig_video_page = tag->u.videotext.video_page;
559 screen_info.orig_video_mode = tag->u.videotext.video_mode;
560 screen_info.orig_video_cols = tag->u.videotext.video_cols;
561 screen_info.orig_video_ega_bx = tag->u.videotext.video_ega_bx;
562 screen_info.orig_video_lines = tag->u.videotext.video_lines;
563 screen_info.orig_video_isVGA = tag->u.videotext.video_isvga;
564 screen_info.orig_video_points = tag->u.videotext.video_points;
565 return 0;
566}
567
568__tagtable(ATAG_VIDEOTEXT, parse_tag_videotext);
569#endif
570
571static int __init parse_tag_ramdisk(const struct tag *tag)
572{
573 setup_ramdisk((tag->u.ramdisk.flags & 1) == 0,
574 (tag->u.ramdisk.flags & 2) == 0,
575 tag->u.ramdisk.start, tag->u.ramdisk.size);
576 return 0;
577}
578
579__tagtable(ATAG_RAMDISK, parse_tag_ramdisk);
580
Linus Torvalds1da177e2005-04-16 15:20:36 -0700581static int __init parse_tag_serialnr(const struct tag *tag)
582{
583 system_serial_low = tag->u.serialnr.low;
584 system_serial_high = tag->u.serialnr.high;
585 return 0;
586}
587
588__tagtable(ATAG_SERIAL, parse_tag_serialnr);
589
590static int __init parse_tag_revision(const struct tag *tag)
591{
592 system_rev = tag->u.revision.rev;
593 return 0;
594}
595
596__tagtable(ATAG_REVISION, parse_tag_revision);
597
Alexander Holler92d20402010-02-16 19:04:53 +0100598#ifndef CONFIG_CMDLINE_FORCE
Linus Torvalds1da177e2005-04-16 15:20:36 -0700599static int __init parse_tag_cmdline(const struct tag *tag)
600{
601 strlcpy(default_command_line, tag->u.cmdline.cmdline, COMMAND_LINE_SIZE);
602 return 0;
603}
604
605__tagtable(ATAG_CMDLINE, parse_tag_cmdline);
Alexander Holler92d20402010-02-16 19:04:53 +0100606#endif /* CONFIG_CMDLINE_FORCE */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700607
608/*
609 * Scan the tag table for this tag, and call its parse function.
610 * The tag table is built by the linker from all the __tagtable
611 * declarations.
612 */
613static int __init parse_tag(const struct tag *tag)
614{
615 extern struct tagtable __tagtable_begin, __tagtable_end;
616 struct tagtable *t;
617
618 for (t = &__tagtable_begin; t < &__tagtable_end; t++)
619 if (tag->hdr.tag == t->tag) {
620 t->parse(tag);
621 break;
622 }
623
624 return t < &__tagtable_end;
625}
626
627/*
628 * Parse all tags in the list, checking both the global and architecture
629 * specific tag tables.
630 */
631static void __init parse_tags(const struct tag *t)
632{
633 for (; t->hdr.size; t = tag_next(t))
634 if (!parse_tag(t))
635 printk(KERN_WARNING
636 "Ignoring unrecognised tag 0x%08x\n",
637 t->hdr.tag);
638}
639
640/*
641 * This holds our defaults.
642 */
643static struct init_tags {
644 struct tag_header hdr1;
645 struct tag_core core;
646 struct tag_header hdr2;
647 struct tag_mem32 mem;
648 struct tag_header hdr3;
649} init_tags __initdata = {
650 { tag_size(tag_core), ATAG_CORE },
651 { 1, PAGE_SIZE, 0xff },
652 { tag_size(tag_mem32), ATAG_MEM },
653 { MEM_SIZE, PHYS_OFFSET },
654 { 0, ATAG_NONE }
655};
656
657static void (*init_machine)(void) __initdata;
658
659static int __init customize_machine(void)
660{
661 /* customizes platform devices, or adds new ones */
662 if (init_machine)
663 init_machine();
664 return 0;
665}
666arch_initcall(customize_machine);
667
Uwe Kleine-König73a65b32010-01-19 10:13:14 +0100668static void __init squash_mem_tags(struct tag *tag)
669{
670 for (; tag->hdr.size; tag = tag_next(tag))
671 if (tag->hdr.tag == ATAG_MEM)
672 tag->hdr.tag = ATAG_NONE;
673}
674
Linus Torvalds1da177e2005-04-16 15:20:36 -0700675void __init setup_arch(char **cmdline_p)
676{
677 struct tag *tags = (struct tag *)&init_tags;
678 struct machine_desc *mdesc;
679 char *from = default_command_line;
680
Catalin Marinasbff595c2009-02-16 11:41:36 +0100681 unwind_init();
682
Linus Torvalds1da177e2005-04-16 15:20:36 -0700683 setup_processor();
684 mdesc = setup_machine(machine_arch_type);
685 machine_name = mdesc->name;
686
687 if (mdesc->soft_reboot)
688 reboot_setup("s");
689
Bill Gatliff9d20fdd2007-05-31 22:02:22 +0100690 if (__atags_pointer)
691 tags = phys_to_virt(__atags_pointer);
692 else if (mdesc->boot_params)
Russell Kingf9bd6ea2005-07-04 10:43:36 +0100693 tags = phys_to_virt(mdesc->boot_params);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700694
Uwe Kleine-König73a65b32010-01-19 10:13:14 +0100695#if defined(CONFIG_DEPRECATED_PARAM_STRUCT)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700696 /*
697 * If we have the old style parameters, convert them to
698 * a tag list.
699 */
700 if (tags->hdr.tag != ATAG_CORE)
701 convert_to_tag_list(tags);
Uwe Kleine-König73a65b32010-01-19 10:13:14 +0100702#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700703 if (tags->hdr.tag != ATAG_CORE)
704 tags = (struct tag *)&init_tags;
705
706 if (mdesc->fixup)
707 mdesc->fixup(mdesc, tags, &from, &meminfo);
708
709 if (tags->hdr.tag == ATAG_CORE) {
710 if (meminfo.nr_banks != 0)
711 squash_mem_tags(tags);
Richard Purdie4cd9d6f2008-01-02 00:56:46 +0100712 save_atags(tags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700713 parse_tags(tags);
714 }
715
Russell King37efe642008-12-01 11:53:07 +0000716 init_mm.start_code = (unsigned long) _text;
717 init_mm.end_code = (unsigned long) _etext;
718 init_mm.end_data = (unsigned long) _edata;
719 init_mm.brk = (unsigned long) _end;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700720
Jeremy Kerr2b0d8c22010-01-11 23:17:34 +0100721 /* parse_early_param needs a boot_command_line */
722 strlcpy(boot_command_line, from, COMMAND_LINE_SIZE);
723
Jeremy Kerr48ab7e02010-01-27 01:13:31 +0100724 /* populate cmd_line too for later use, preserving boot_command_line */
725 strlcpy(cmd_line, boot_command_line, COMMAND_LINE_SIZE);
726 *cmdline_p = cmd_line;
Jeremy Kerr2b0d8c22010-01-11 23:17:34 +0100727
728 parse_early_param();
729
Nicolas Pitre4b5f32c2008-10-06 13:24:40 -0400730 paging_init(mdesc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700731 request_standard_resources(&meminfo, mdesc);
732
Russell King7bbb7942006-02-16 11:08:09 +0000733#ifdef CONFIG_SMP
734 smp_init_cpus();
735#endif
736
Russell Kingccea7a12005-05-31 22:22:32 +0100737 cpu_init();
Linus Walleijbc581772009-09-15 17:30:37 +0100738 tcm_init();
Russell Kingccea7a12005-05-31 22:22:32 +0100739
Linus Torvalds1da177e2005-04-16 15:20:36 -0700740 /*
741 * Set up various architecture-specific pointers
742 */
743 init_arch_irq = mdesc->init_irq;
744 system_timer = mdesc->timer;
745 init_machine = mdesc->init_machine;
746
747#ifdef CONFIG_VT
748#if defined(CONFIG_VGA_CONSOLE)
749 conswitchp = &vga_con;
750#elif defined(CONFIG_DUMMY_CONSOLE)
751 conswitchp = &dummy_con;
752#endif
753#endif
Jason Wessel5cbad0e2008-02-20 13:33:40 -0600754 early_trap_init();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700755}
756
757
758static int __init topology_init(void)
759{
760 int cpu;
761
Russell King66fb8bd2007-03-13 09:54:21 +0000762 for_each_possible_cpu(cpu) {
763 struct cpuinfo_arm *cpuinfo = &per_cpu(cpu_data, cpu);
764 cpuinfo->cpu.hotpluggable = 1;
765 register_cpu(&cpuinfo->cpu, cpu);
766 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700767
768 return 0;
769}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700770subsys_initcall(topology_init);
771
Russell Kinge119bff2010-01-10 17:23:29 +0000772#ifdef CONFIG_HAVE_PROC_CPU
773static int __init proc_cpu_init(void)
774{
775 struct proc_dir_entry *res;
776
777 res = proc_mkdir("cpu", NULL);
778 if (!res)
779 return -ENOMEM;
780 return 0;
781}
782fs_initcall(proc_cpu_init);
783#endif
784
Linus Torvalds1da177e2005-04-16 15:20:36 -0700785static const char *hwcap_str[] = {
786 "swp",
787 "half",
788 "thumb",
789 "26bit",
790 "fastmult",
791 "fpa",
792 "vfp",
793 "edsp",
794 "java",
Paul Gortmaker8f7f9432006-10-27 05:13:19 +0100795 "iwmmxt",
Lennert Buytenhek99e4a6d2006-12-18 00:59:10 +0100796 "crunch",
Catalin Marinas4369ae12008-11-06 13:23:06 +0000797 "thumbee",
Catalin Marinas2bedbdf2008-11-06 13:23:07 +0000798 "neon",
Catalin Marinas7279dc32009-02-11 13:13:56 +0100799 "vfpv3",
800 "vfpv3d16",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700801 NULL
802};
803
Linus Torvalds1da177e2005-04-16 15:20:36 -0700804static int c_show(struct seq_file *m, void *v)
805{
806 int i;
807
808 seq_printf(m, "Processor\t: %s rev %d (%s)\n",
Russell King0ba8b9b2008-08-10 18:08:10 +0100809 cpu_name, read_cpuid_id() & 15, elf_platform);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700810
811#if defined(CONFIG_SMP)
812 for_each_online_cpu(i) {
Russell King15559722005-11-06 21:41:08 +0000813 /*
814 * glibc reads /proc/cpuinfo to determine the number of
815 * online processors, looking for lines beginning with
816 * "processor". Give glibc what it expects.
817 */
818 seq_printf(m, "processor\t: %d\n", i);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700819 seq_printf(m, "BogoMIPS\t: %lu.%02lu\n\n",
820 per_cpu(cpu_data, i).loops_per_jiffy / (500000UL/HZ),
821 (per_cpu(cpu_data, i).loops_per_jiffy / (5000UL/HZ)) % 100);
822 }
823#else /* CONFIG_SMP */
824 seq_printf(m, "BogoMIPS\t: %lu.%02lu\n",
825 loops_per_jiffy / (500000/HZ),
826 (loops_per_jiffy / (5000/HZ)) % 100);
827#endif
828
829 /* dump out the processor features */
830 seq_puts(m, "Features\t: ");
831
832 for (i = 0; hwcap_str[i]; i++)
833 if (elf_hwcap & (1 << i))
834 seq_printf(m, "%s ", hwcap_str[i]);
835
Russell King0ba8b9b2008-08-10 18:08:10 +0100836 seq_printf(m, "\nCPU implementer\t: 0x%02x\n", read_cpuid_id() >> 24);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700837 seq_printf(m, "CPU architecture: %s\n", proc_arch[cpu_architecture()]);
838
Russell King0ba8b9b2008-08-10 18:08:10 +0100839 if ((read_cpuid_id() & 0x0008f000) == 0x00000000) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700840 /* pre-ARM7 */
Russell King0ba8b9b2008-08-10 18:08:10 +0100841 seq_printf(m, "CPU part\t: %07x\n", read_cpuid_id() >> 4);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700842 } else {
Russell King0ba8b9b2008-08-10 18:08:10 +0100843 if ((read_cpuid_id() & 0x0008f000) == 0x00007000) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700844 /* ARM7 */
845 seq_printf(m, "CPU variant\t: 0x%02x\n",
Russell King0ba8b9b2008-08-10 18:08:10 +0100846 (read_cpuid_id() >> 16) & 127);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700847 } else {
848 /* post-ARM7 */
849 seq_printf(m, "CPU variant\t: 0x%x\n",
Russell King0ba8b9b2008-08-10 18:08:10 +0100850 (read_cpuid_id() >> 20) & 15);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700851 }
852 seq_printf(m, "CPU part\t: 0x%03x\n",
Russell King0ba8b9b2008-08-10 18:08:10 +0100853 (read_cpuid_id() >> 4) & 0xfff);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700854 }
Russell King0ba8b9b2008-08-10 18:08:10 +0100855 seq_printf(m, "CPU revision\t: %d\n", read_cpuid_id() & 15);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700856
Linus Torvalds1da177e2005-04-16 15:20:36 -0700857 seq_puts(m, "\n");
858
859 seq_printf(m, "Hardware\t: %s\n", machine_name);
860 seq_printf(m, "Revision\t: %04x\n", system_rev);
861 seq_printf(m, "Serial\t\t: %08x%08x\n",
862 system_serial_high, system_serial_low);
863
864 return 0;
865}
866
867static void *c_start(struct seq_file *m, loff_t *pos)
868{
869 return *pos < 1 ? (void *)1 : NULL;
870}
871
872static void *c_next(struct seq_file *m, void *v, loff_t *pos)
873{
874 ++*pos;
875 return NULL;
876}
877
878static void c_stop(struct seq_file *m, void *v)
879{
880}
881
Jan Engelhardt2ffd6e12008-01-22 20:41:07 +0100882const struct seq_operations cpuinfo_op = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700883 .start = c_start,
884 .next = c_next,
885 .stop = c_stop,
886 .show = c_show
887};