setup.c 23 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018
  1. /*
  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. */
  10. #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>
  20. #include <linux/screen_info.h>
  21. #include <linux/init.h>
  22. #include <linux/kexec.h>
  23. #include <linux/crash_dump.h>
  24. #include <linux/root_dev.h>
  25. #include <linux/cpu.h>
  26. #include <linux/interrupt.h>
  27. #include <linux/smp.h>
  28. #include <linux/fs.h>
  29. #include <linux/proc_fs.h>
  30. #include <linux/memblock.h>
  31. #include <asm/unified.h>
  32. #include <asm/cpu.h>
  33. #include <asm/cputype.h>
  34. #include <asm/elf.h>
  35. #include <asm/procinfo.h>
  36. #include <asm/sections.h>
  37. #include <asm/setup.h>
  38. #include <asm/smp_plat.h>
  39. #include <asm/mach-types.h>
  40. #include <asm/cacheflush.h>
  41. #include <asm/cachetype.h>
  42. #include <asm/tlbflush.h>
  43. #include <asm/mach/arch.h>
  44. #include <asm/mach/irq.h>
  45. #include <asm/mach/time.h>
  46. #include <asm/traps.h>
  47. #include <asm/unwind.h>
  48. #if defined(CONFIG_DEPRECATED_PARAM_STRUCT)
  49. #include "compat.h"
  50. #endif
  51. #include "atags.h"
  52. #include "tcm.h"
  53. #ifndef MEM_SIZE
  54. #define MEM_SIZE (16*1024*1024)
  55. #endif
  56. #if defined(CONFIG_FPE_NWFPE) || defined(CONFIG_FPE_FASTFPE)
  57. char fpe_type[8];
  58. static int __init fpe_setup(char *line)
  59. {
  60. memcpy(fpe_type, line, 8);
  61. return 1;
  62. }
  63. __setup("fpe=", fpe_setup);
  64. #endif
  65. extern void paging_init(struct machine_desc *desc);
  66. extern void reboot_setup(char *str);
  67. unsigned int processor_id;
  68. EXPORT_SYMBOL(processor_id);
  69. unsigned int __machine_arch_type __read_mostly;
  70. EXPORT_SYMBOL(__machine_arch_type);
  71. unsigned int cacheid __read_mostly;
  72. EXPORT_SYMBOL(cacheid);
  73. unsigned int __atags_pointer __initdata;
  74. unsigned int system_rev;
  75. EXPORT_SYMBOL(system_rev);
  76. unsigned int system_serial_low;
  77. EXPORT_SYMBOL(system_serial_low);
  78. unsigned int system_serial_high;
  79. EXPORT_SYMBOL(system_serial_high);
  80. unsigned int elf_hwcap __read_mostly;
  81. EXPORT_SYMBOL(elf_hwcap);
  82. #ifdef MULTI_CPU
  83. struct processor processor __read_mostly;
  84. #endif
  85. #ifdef MULTI_TLB
  86. struct cpu_tlb_fns cpu_tlb __read_mostly;
  87. #endif
  88. #ifdef MULTI_USER
  89. struct cpu_user_fns cpu_user __read_mostly;
  90. #endif
  91. #ifdef MULTI_CACHE
  92. struct cpu_cache_fns cpu_cache __read_mostly;
  93. #endif
  94. #ifdef CONFIG_OUTER_CACHE
  95. struct outer_cache_fns outer_cache __read_mostly;
  96. EXPORT_SYMBOL(outer_cache);
  97. #endif
  98. struct stack {
  99. u32 irq[3];
  100. u32 abt[3];
  101. u32 und[3];
  102. } ____cacheline_aligned;
  103. static struct stack stacks[NR_CPUS];
  104. char elf_platform[ELF_PLATFORM_SIZE];
  105. EXPORT_SYMBOL(elf_platform);
  106. static const char *cpu_name;
  107. static const char *machine_name;
  108. static char __initdata cmd_line[COMMAND_LINE_SIZE];
  109. struct machine_desc *machine_desc __initdata;
  110. static char default_command_line[COMMAND_LINE_SIZE] __initdata = CONFIG_CMDLINE;
  111. static union { char c[4]; unsigned long l; } endian_test __initdata = { { 'l', '?', '?', 'b' } };
  112. #define ENDIANNESS ((char)endian_test.l)
  113. DEFINE_PER_CPU(struct cpuinfo_arm, cpu_data);
  114. /*
  115. * Standard memory resources
  116. */
  117. static struct resource mem_res[] = {
  118. {
  119. .name = "Video RAM",
  120. .start = 0,
  121. .end = 0,
  122. .flags = IORESOURCE_MEM
  123. },
  124. {
  125. .name = "Kernel text",
  126. .start = 0,
  127. .end = 0,
  128. .flags = IORESOURCE_MEM
  129. },
  130. {
  131. .name = "Kernel data",
  132. .start = 0,
  133. .end = 0,
  134. .flags = IORESOURCE_MEM
  135. }
  136. };
  137. #define video_ram mem_res[0]
  138. #define kernel_code mem_res[1]
  139. #define kernel_data mem_res[2]
  140. static struct resource io_res[] = {
  141. {
  142. .name = "reserved",
  143. .start = 0x3bc,
  144. .end = 0x3be,
  145. .flags = IORESOURCE_IO | IORESOURCE_BUSY
  146. },
  147. {
  148. .name = "reserved",
  149. .start = 0x378,
  150. .end = 0x37f,
  151. .flags = IORESOURCE_IO | IORESOURCE_BUSY
  152. },
  153. {
  154. .name = "reserved",
  155. .start = 0x278,
  156. .end = 0x27f,
  157. .flags = IORESOURCE_IO | IORESOURCE_BUSY
  158. }
  159. };
  160. #define lp0 io_res[0]
  161. #define lp1 io_res[1]
  162. #define lp2 io_res[2]
  163. static const char *proc_arch[] = {
  164. "undefined/unknown",
  165. "3",
  166. "4",
  167. "4T",
  168. "5",
  169. "5T",
  170. "5TE",
  171. "5TEJ",
  172. "6TEJ",
  173. "7",
  174. "?(11)",
  175. "?(12)",
  176. "?(13)",
  177. "?(14)",
  178. "?(15)",
  179. "?(16)",
  180. "?(17)",
  181. };
  182. int cpu_architecture(void)
  183. {
  184. int cpu_arch;
  185. if ((read_cpuid_id() & 0x0008f000) == 0) {
  186. cpu_arch = CPU_ARCH_UNKNOWN;
  187. } else if ((read_cpuid_id() & 0x0008f000) == 0x00007000) {
  188. cpu_arch = (read_cpuid_id() & (1 << 23)) ? CPU_ARCH_ARMv4T : CPU_ARCH_ARMv3;
  189. } else if ((read_cpuid_id() & 0x00080000) == 0x00000000) {
  190. cpu_arch = (read_cpuid_id() >> 16) & 7;
  191. if (cpu_arch)
  192. cpu_arch += CPU_ARCH_ARMv3;
  193. } else if ((read_cpuid_id() & 0x000f0000) == 0x000f0000) {
  194. unsigned int mmfr0;
  195. /* Revised CPUID format. Read the Memory Model Feature
  196. * Register 0 and check for VMSAv7 or PMSAv7 */
  197. asm("mrc p15, 0, %0, c0, c1, 4"
  198. : "=r" (mmfr0));
  199. if ((mmfr0 & 0x0000000f) == 0x00000003 ||
  200. (mmfr0 & 0x000000f0) == 0x00000030)
  201. cpu_arch = CPU_ARCH_ARMv7;
  202. else if ((mmfr0 & 0x0000000f) == 0x00000002 ||
  203. (mmfr0 & 0x000000f0) == 0x00000020)
  204. cpu_arch = CPU_ARCH_ARMv6;
  205. else
  206. cpu_arch = CPU_ARCH_UNKNOWN;
  207. } else
  208. cpu_arch = CPU_ARCH_UNKNOWN;
  209. return cpu_arch;
  210. }
  211. static int cpu_has_aliasing_icache(unsigned int arch)
  212. {
  213. int aliasing_icache;
  214. unsigned int id_reg, num_sets, line_size;
  215. /* arch specifies the register format */
  216. switch (arch) {
  217. case CPU_ARCH_ARMv7:
  218. asm("mcr p15, 2, %0, c0, c0, 0 @ set CSSELR"
  219. : /* No output operands */
  220. : "r" (1));
  221. isb();
  222. asm("mrc p15, 1, %0, c0, c0, 0 @ read CCSIDR"
  223. : "=r" (id_reg));
  224. line_size = 4 << ((id_reg & 0x7) + 2);
  225. num_sets = ((id_reg >> 13) & 0x7fff) + 1;
  226. aliasing_icache = (line_size * num_sets) > PAGE_SIZE;
  227. break;
  228. case CPU_ARCH_ARMv6:
  229. aliasing_icache = read_cpuid_cachetype() & (1 << 11);
  230. break;
  231. default:
  232. /* I-cache aliases will be handled by D-cache aliasing code */
  233. aliasing_icache = 0;
  234. }
  235. return aliasing_icache;
  236. }
  237. static void __init cacheid_init(void)
  238. {
  239. unsigned int cachetype = read_cpuid_cachetype();
  240. unsigned int arch = cpu_architecture();
  241. if (arch >= CPU_ARCH_ARMv6) {
  242. if ((cachetype & (7 << 29)) == 4 << 29) {
  243. /* ARMv7 register format */
  244. cacheid = CACHEID_VIPT_NONALIASING;
  245. if ((cachetype & (3 << 14)) == 1 << 14)
  246. cacheid |= CACHEID_ASID_TAGGED;
  247. else if (cpu_has_aliasing_icache(CPU_ARCH_ARMv7))
  248. cacheid |= CACHEID_VIPT_I_ALIASING;
  249. } else if (cachetype & (1 << 23)) {
  250. cacheid = CACHEID_VIPT_ALIASING;
  251. } else {
  252. cacheid = CACHEID_VIPT_NONALIASING;
  253. if (cpu_has_aliasing_icache(CPU_ARCH_ARMv6))
  254. cacheid |= CACHEID_VIPT_I_ALIASING;
  255. }
  256. } else {
  257. cacheid = CACHEID_VIVT;
  258. }
  259. printk("CPU: %s data cache, %s instruction cache\n",
  260. cache_is_vivt() ? "VIVT" :
  261. cache_is_vipt_aliasing() ? "VIPT aliasing" :
  262. cache_is_vipt_nonaliasing() ? "VIPT nonaliasing" : "unknown",
  263. cache_is_vivt() ? "VIVT" :
  264. icache_is_vivt_asid_tagged() ? "VIVT ASID tagged" :
  265. icache_is_vipt_aliasing() ? "VIPT aliasing" :
  266. cache_is_vipt_nonaliasing() ? "VIPT nonaliasing" : "unknown");
  267. }
  268. /*
  269. * These functions re-use the assembly code in head.S, which
  270. * already provide the required functionality.
  271. */
  272. extern struct proc_info_list *lookup_processor_type(unsigned int);
  273. extern struct machine_desc *lookup_machine_type(unsigned int);
  274. static void __init feat_v6_fixup(void)
  275. {
  276. int id = read_cpuid_id();
  277. if ((id & 0xff0f0000) != 0x41070000)
  278. return;
  279. /*
  280. * HWCAP_TLS is available only on 1136 r1p0 and later,
  281. * see also kuser_get_tls_init.
  282. */
  283. if ((((id >> 4) & 0xfff) == 0xb36) && (((id >> 20) & 3) == 0))
  284. elf_hwcap &= ~HWCAP_TLS;
  285. }
  286. static void __init setup_processor(void)
  287. {
  288. struct proc_info_list *list;
  289. /*
  290. * locate processor in the list of supported processor
  291. * types. The linker builds this table for us from the
  292. * entries in arch/arm/mm/proc-*.S
  293. */
  294. list = lookup_processor_type(read_cpuid_id());
  295. if (!list) {
  296. printk("CPU configuration botched (ID %08x), unable "
  297. "to continue.\n", read_cpuid_id());
  298. while (1);
  299. }
  300. cpu_name = list->cpu_name;
  301. #ifdef MULTI_CPU
  302. processor = *list->proc;
  303. #endif
  304. #ifdef MULTI_TLB
  305. cpu_tlb = *list->tlb;
  306. #endif
  307. #ifdef MULTI_USER
  308. cpu_user = *list->user;
  309. #endif
  310. #ifdef MULTI_CACHE
  311. cpu_cache = *list->cache;
  312. #endif
  313. printk("CPU: %s [%08x] revision %d (ARMv%s), cr=%08lx\n",
  314. cpu_name, read_cpuid_id(), read_cpuid_id() & 15,
  315. proc_arch[cpu_architecture()], cr_alignment);
  316. sprintf(init_utsname()->machine, "%s%c", list->arch_name, ENDIANNESS);
  317. sprintf(elf_platform, "%s%c", list->elf_name, ENDIANNESS);
  318. elf_hwcap = list->elf_hwcap;
  319. #ifndef CONFIG_ARM_THUMB
  320. elf_hwcap &= ~HWCAP_THUMB;
  321. #endif
  322. feat_v6_fixup();
  323. cacheid_init();
  324. cpu_proc_init();
  325. }
  326. /*
  327. * cpu_init - initialise one CPU.
  328. *
  329. * cpu_init sets up the per-CPU stacks.
  330. */
  331. void cpu_init(void)
  332. {
  333. unsigned int cpu = smp_processor_id();
  334. struct stack *stk = &stacks[cpu];
  335. if (cpu >= NR_CPUS) {
  336. printk(KERN_CRIT "CPU%u: bad primary CPU number\n", cpu);
  337. BUG();
  338. }
  339. /*
  340. * Define the placement constraint for the inline asm directive below.
  341. * In Thumb-2, msr with an immediate value is not allowed.
  342. */
  343. #ifdef CONFIG_THUMB2_KERNEL
  344. #define PLC "r"
  345. #else
  346. #define PLC "I"
  347. #endif
  348. /*
  349. * setup stacks for re-entrant exception handlers
  350. */
  351. __asm__ (
  352. "msr cpsr_c, %1\n\t"
  353. "add r14, %0, %2\n\t"
  354. "mov sp, r14\n\t"
  355. "msr cpsr_c, %3\n\t"
  356. "add r14, %0, %4\n\t"
  357. "mov sp, r14\n\t"
  358. "msr cpsr_c, %5\n\t"
  359. "add r14, %0, %6\n\t"
  360. "mov sp, r14\n\t"
  361. "msr cpsr_c, %7"
  362. :
  363. : "r" (stk),
  364. PLC (PSR_F_BIT | PSR_I_BIT | IRQ_MODE),
  365. "I" (offsetof(struct stack, irq[0])),
  366. PLC (PSR_F_BIT | PSR_I_BIT | ABT_MODE),
  367. "I" (offsetof(struct stack, abt[0])),
  368. PLC (PSR_F_BIT | PSR_I_BIT | UND_MODE),
  369. "I" (offsetof(struct stack, und[0])),
  370. PLC (PSR_F_BIT | PSR_I_BIT | SVC_MODE)
  371. : "r14");
  372. }
  373. static struct machine_desc * __init setup_machine(unsigned int nr)
  374. {
  375. struct machine_desc *list;
  376. /*
  377. * locate machine in the list of supported machines.
  378. */
  379. list = lookup_machine_type(nr);
  380. if (!list) {
  381. printk("Machine configuration botched (nr %d), unable "
  382. "to continue.\n", nr);
  383. while (1);
  384. }
  385. printk("Machine: %s\n", list->name);
  386. return list;
  387. }
  388. static int __init arm_add_memory(unsigned long start, unsigned long size)
  389. {
  390. struct membank *bank = &meminfo.bank[meminfo.nr_banks];
  391. if (meminfo.nr_banks >= NR_BANKS) {
  392. printk(KERN_CRIT "NR_BANKS too low, "
  393. "ignoring memory at %#lx\n", start);
  394. return -EINVAL;
  395. }
  396. /*
  397. * Ensure that start/size are aligned to a page boundary.
  398. * Size is appropriately rounded down, start is rounded up.
  399. */
  400. size -= start & ~PAGE_MASK;
  401. bank->start = PAGE_ALIGN(start);
  402. bank->size = size & PAGE_MASK;
  403. /*
  404. * Check whether this memory region has non-zero size or
  405. * invalid node number.
  406. */
  407. if (bank->size == 0)
  408. return -EINVAL;
  409. meminfo.nr_banks++;
  410. return 0;
  411. }
  412. /*
  413. * Pick out the memory size. We look for mem=size@start,
  414. * where start and size are "size[KkMm]"
  415. */
  416. static int __init early_mem(char *p)
  417. {
  418. static int usermem __initdata = 0;
  419. unsigned long size, start;
  420. char *endp;
  421. /*
  422. * If the user specifies memory size, we
  423. * blow away any automatically generated
  424. * size.
  425. */
  426. if (usermem == 0) {
  427. usermem = 1;
  428. meminfo.nr_banks = 0;
  429. }
  430. start = PHYS_OFFSET;
  431. size = memparse(p, &endp);
  432. if (*endp == '@')
  433. start = memparse(endp + 1, NULL);
  434. arm_add_memory(start, size);
  435. return 0;
  436. }
  437. early_param("mem", early_mem);
  438. static void __init
  439. setup_ramdisk(int doload, int prompt, int image_start, unsigned int rd_sz)
  440. {
  441. #ifdef CONFIG_BLK_DEV_RAM
  442. extern int rd_size, rd_image_start, rd_prompt, rd_doload;
  443. rd_image_start = image_start;
  444. rd_prompt = prompt;
  445. rd_doload = doload;
  446. if (rd_sz)
  447. rd_size = rd_sz;
  448. #endif
  449. }
  450. static void __init
  451. request_standard_resources(struct meminfo *mi, struct machine_desc *mdesc)
  452. {
  453. struct resource *res;
  454. int i;
  455. kernel_code.start = virt_to_phys(_text);
  456. kernel_code.end = virt_to_phys(_etext - 1);
  457. kernel_data.start = virt_to_phys(_sdata);
  458. kernel_data.end = virt_to_phys(_end - 1);
  459. for (i = 0; i < mi->nr_banks; i++) {
  460. if (mi->bank[i].size == 0)
  461. continue;
  462. res = alloc_bootmem_low(sizeof(*res));
  463. res->name = "System RAM";
  464. res->start = mi->bank[i].start;
  465. res->end = mi->bank[i].start + mi->bank[i].size - 1;
  466. res->flags = IORESOURCE_MEM | IORESOURCE_BUSY;
  467. request_resource(&iomem_resource, res);
  468. if (kernel_code.start >= res->start &&
  469. kernel_code.end <= res->end)
  470. request_resource(res, &kernel_code);
  471. if (kernel_data.start >= res->start &&
  472. kernel_data.end <= res->end)
  473. request_resource(res, &kernel_data);
  474. }
  475. if (mdesc->video_start) {
  476. video_ram.start = mdesc->video_start;
  477. video_ram.end = mdesc->video_end;
  478. request_resource(&iomem_resource, &video_ram);
  479. }
  480. /*
  481. * Some machines don't have the possibility of ever
  482. * possessing lp0, lp1 or lp2
  483. */
  484. if (mdesc->reserve_lp0)
  485. request_resource(&ioport_resource, &lp0);
  486. if (mdesc->reserve_lp1)
  487. request_resource(&ioport_resource, &lp1);
  488. if (mdesc->reserve_lp2)
  489. request_resource(&ioport_resource, &lp2);
  490. }
  491. /*
  492. * Tag parsing.
  493. *
  494. * This is the new way of passing data to the kernel at boot time. Rather
  495. * than passing a fixed inflexible structure to the kernel, we pass a list
  496. * of variable-sized tags to the kernel. The first tag must be a ATAG_CORE
  497. * tag for the list to be recognised (to distinguish the tagged list from
  498. * a param_struct). The list is terminated with a zero-length tag (this tag
  499. * is not parsed in any way).
  500. */
  501. static int __init parse_tag_core(const struct tag *tag)
  502. {
  503. if (tag->hdr.size > 2) {
  504. if ((tag->u.core.flags & 1) == 0)
  505. root_mountflags &= ~MS_RDONLY;
  506. ROOT_DEV = old_decode_dev(tag->u.core.rootdev);
  507. }
  508. return 0;
  509. }
  510. __tagtable(ATAG_CORE, parse_tag_core);
  511. static int __init parse_tag_mem32(const struct tag *tag)
  512. {
  513. return arm_add_memory(tag->u.mem.start, tag->u.mem.size);
  514. }
  515. __tagtable(ATAG_MEM, parse_tag_mem32);
  516. #if defined(CONFIG_VGA_CONSOLE) || defined(CONFIG_DUMMY_CONSOLE)
  517. struct screen_info screen_info = {
  518. .orig_video_lines = 30,
  519. .orig_video_cols = 80,
  520. .orig_video_mode = 0,
  521. .orig_video_ega_bx = 0,
  522. .orig_video_isVGA = 1,
  523. .orig_video_points = 8
  524. };
  525. static int __init parse_tag_videotext(const struct tag *tag)
  526. {
  527. screen_info.orig_x = tag->u.videotext.x;
  528. screen_info.orig_y = tag->u.videotext.y;
  529. screen_info.orig_video_page = tag->u.videotext.video_page;
  530. screen_info.orig_video_mode = tag->u.videotext.video_mode;
  531. screen_info.orig_video_cols = tag->u.videotext.video_cols;
  532. screen_info.orig_video_ega_bx = tag->u.videotext.video_ega_bx;
  533. screen_info.orig_video_lines = tag->u.videotext.video_lines;
  534. screen_info.orig_video_isVGA = tag->u.videotext.video_isvga;
  535. screen_info.orig_video_points = tag->u.videotext.video_points;
  536. return 0;
  537. }
  538. __tagtable(ATAG_VIDEOTEXT, parse_tag_videotext);
  539. #endif
  540. static int __init parse_tag_ramdisk(const struct tag *tag)
  541. {
  542. setup_ramdisk((tag->u.ramdisk.flags & 1) == 0,
  543. (tag->u.ramdisk.flags & 2) == 0,
  544. tag->u.ramdisk.start, tag->u.ramdisk.size);
  545. return 0;
  546. }
  547. __tagtable(ATAG_RAMDISK, parse_tag_ramdisk);
  548. static int __init parse_tag_serialnr(const struct tag *tag)
  549. {
  550. system_serial_low = tag->u.serialnr.low;
  551. system_serial_high = tag->u.serialnr.high;
  552. return 0;
  553. }
  554. __tagtable(ATAG_SERIAL, parse_tag_serialnr);
  555. static int __init parse_tag_revision(const struct tag *tag)
  556. {
  557. system_rev = tag->u.revision.rev;
  558. return 0;
  559. }
  560. __tagtable(ATAG_REVISION, parse_tag_revision);
  561. #ifndef CONFIG_CMDLINE_FORCE
  562. static int __init parse_tag_cmdline(const struct tag *tag)
  563. {
  564. strlcpy(default_command_line, tag->u.cmdline.cmdline, COMMAND_LINE_SIZE);
  565. return 0;
  566. }
  567. __tagtable(ATAG_CMDLINE, parse_tag_cmdline);
  568. #endif /* CONFIG_CMDLINE_FORCE */
  569. /*
  570. * Scan the tag table for this tag, and call its parse function.
  571. * The tag table is built by the linker from all the __tagtable
  572. * declarations.
  573. */
  574. static int __init parse_tag(const struct tag *tag)
  575. {
  576. extern struct tagtable __tagtable_begin, __tagtable_end;
  577. struct tagtable *t;
  578. for (t = &__tagtable_begin; t < &__tagtable_end; t++)
  579. if (tag->hdr.tag == t->tag) {
  580. t->parse(tag);
  581. break;
  582. }
  583. return t < &__tagtable_end;
  584. }
  585. /*
  586. * Parse all tags in the list, checking both the global and architecture
  587. * specific tag tables.
  588. */
  589. static void __init parse_tags(const struct tag *t)
  590. {
  591. for (; t->hdr.size; t = tag_next(t))
  592. if (!parse_tag(t))
  593. printk(KERN_WARNING
  594. "Ignoring unrecognised tag 0x%08x\n",
  595. t->hdr.tag);
  596. }
  597. /*
  598. * This holds our defaults.
  599. */
  600. static struct init_tags {
  601. struct tag_header hdr1;
  602. struct tag_core core;
  603. struct tag_header hdr2;
  604. struct tag_mem32 mem;
  605. struct tag_header hdr3;
  606. } init_tags __initdata = {
  607. { tag_size(tag_core), ATAG_CORE },
  608. { 1, PAGE_SIZE, 0xff },
  609. { tag_size(tag_mem32), ATAG_MEM },
  610. { MEM_SIZE, PHYS_OFFSET },
  611. { 0, ATAG_NONE }
  612. };
  613. static int __init customize_machine(void)
  614. {
  615. /* customizes platform devices, or adds new ones */
  616. if (machine_desc->init_machine)
  617. machine_desc->init_machine();
  618. return 0;
  619. }
  620. arch_initcall(customize_machine);
  621. #ifdef CONFIG_KEXEC
  622. static inline unsigned long long get_total_mem(void)
  623. {
  624. unsigned long total;
  625. total = max_low_pfn - min_low_pfn;
  626. return total << PAGE_SHIFT;
  627. }
  628. /**
  629. * reserve_crashkernel() - reserves memory are for crash kernel
  630. *
  631. * This function reserves memory area given in "crashkernel=" kernel command
  632. * line parameter. The memory reserved is used by a dump capture kernel when
  633. * primary kernel is crashing.
  634. */
  635. static void __init reserve_crashkernel(void)
  636. {
  637. unsigned long long crash_size, crash_base;
  638. unsigned long long total_mem;
  639. int ret;
  640. total_mem = get_total_mem();
  641. ret = parse_crashkernel(boot_command_line, total_mem,
  642. &crash_size, &crash_base);
  643. if (ret)
  644. return;
  645. ret = reserve_bootmem(crash_base, crash_size, BOOTMEM_EXCLUSIVE);
  646. if (ret < 0) {
  647. printk(KERN_WARNING "crashkernel reservation failed - "
  648. "memory is in use (0x%lx)\n", (unsigned long)crash_base);
  649. return;
  650. }
  651. printk(KERN_INFO "Reserving %ldMB of memory at %ldMB "
  652. "for crashkernel (System RAM: %ldMB)\n",
  653. (unsigned long)(crash_size >> 20),
  654. (unsigned long)(crash_base >> 20),
  655. (unsigned long)(total_mem >> 20));
  656. crashk_res.start = crash_base;
  657. crashk_res.end = crash_base + crash_size - 1;
  658. insert_resource(&iomem_resource, &crashk_res);
  659. }
  660. #else
  661. static inline void reserve_crashkernel(void) {}
  662. #endif /* CONFIG_KEXEC */
  663. /*
  664. * Note: elfcorehdr_addr is not just limited to vmcore. It is also used by
  665. * is_kdump_kernel() to determine if we are booting after a panic. Hence
  666. * ifdef it under CONFIG_CRASH_DUMP and not CONFIG_PROC_VMCORE.
  667. */
  668. #ifdef CONFIG_CRASH_DUMP
  669. /*
  670. * elfcorehdr= specifies the location of elf core header stored by the crashed
  671. * kernel. This option will be passed by kexec loader to the capture kernel.
  672. */
  673. static int __init setup_elfcorehdr(char *arg)
  674. {
  675. char *end;
  676. if (!arg)
  677. return -EINVAL;
  678. elfcorehdr_addr = memparse(arg, &end);
  679. return end > arg ? 0 : -EINVAL;
  680. }
  681. early_param("elfcorehdr", setup_elfcorehdr);
  682. #endif /* CONFIG_CRASH_DUMP */
  683. static void __init squash_mem_tags(struct tag *tag)
  684. {
  685. for (; tag->hdr.size; tag = tag_next(tag))
  686. if (tag->hdr.tag == ATAG_MEM)
  687. tag->hdr.tag = ATAG_NONE;
  688. }
  689. void __init setup_arch(char **cmdline_p)
  690. {
  691. struct tag *tags = (struct tag *)&init_tags;
  692. struct machine_desc *mdesc;
  693. char *from = default_command_line;
  694. unwind_init();
  695. setup_processor();
  696. mdesc = setup_machine(machine_arch_type);
  697. machine_desc = mdesc;
  698. machine_name = mdesc->name;
  699. if (mdesc->soft_reboot)
  700. reboot_setup("s");
  701. if (__atags_pointer)
  702. tags = phys_to_virt(__atags_pointer);
  703. else if (mdesc->boot_params)
  704. tags = phys_to_virt(mdesc->boot_params);
  705. #if defined(CONFIG_DEPRECATED_PARAM_STRUCT)
  706. /*
  707. * If we have the old style parameters, convert them to
  708. * a tag list.
  709. */
  710. if (tags->hdr.tag != ATAG_CORE)
  711. convert_to_tag_list(tags);
  712. #endif
  713. if (tags->hdr.tag != ATAG_CORE)
  714. tags = (struct tag *)&init_tags;
  715. if (mdesc->fixup)
  716. mdesc->fixup(mdesc, tags, &from, &meminfo);
  717. if (tags->hdr.tag == ATAG_CORE) {
  718. if (meminfo.nr_banks != 0)
  719. squash_mem_tags(tags);
  720. save_atags(tags);
  721. parse_tags(tags);
  722. }
  723. init_mm.start_code = (unsigned long) _text;
  724. init_mm.end_code = (unsigned long) _etext;
  725. init_mm.end_data = (unsigned long) _edata;
  726. init_mm.brk = (unsigned long) _end;
  727. /* parse_early_param needs a boot_command_line */
  728. strlcpy(boot_command_line, from, COMMAND_LINE_SIZE);
  729. /* populate cmd_line too for later use, preserving boot_command_line */
  730. strlcpy(cmd_line, boot_command_line, COMMAND_LINE_SIZE);
  731. *cmdline_p = cmd_line;
  732. parse_early_param();
  733. arm_memblock_init(&meminfo, mdesc);
  734. paging_init(mdesc);
  735. request_standard_resources(&meminfo, mdesc);
  736. #ifdef CONFIG_SMP
  737. if (is_smp())
  738. smp_init_cpus();
  739. #endif
  740. reserve_crashkernel();
  741. cpu_init();
  742. tcm_init();
  743. #ifdef CONFIG_MULTI_IRQ_HANDLER
  744. handle_arch_irq = mdesc->handle_irq;
  745. #endif
  746. #ifdef CONFIG_VT
  747. #if defined(CONFIG_VGA_CONSOLE)
  748. conswitchp = &vga_con;
  749. #elif defined(CONFIG_DUMMY_CONSOLE)
  750. conswitchp = &dummy_con;
  751. #endif
  752. #endif
  753. early_trap_init();
  754. if (mdesc->init_early)
  755. mdesc->init_early();
  756. }
  757. static int __init topology_init(void)
  758. {
  759. int cpu;
  760. for_each_possible_cpu(cpu) {
  761. struct cpuinfo_arm *cpuinfo = &per_cpu(cpu_data, cpu);
  762. cpuinfo->cpu.hotpluggable = 1;
  763. register_cpu(&cpuinfo->cpu, cpu);
  764. }
  765. return 0;
  766. }
  767. subsys_initcall(topology_init);
  768. #ifdef CONFIG_HAVE_PROC_CPU
  769. static int __init proc_cpu_init(void)
  770. {
  771. struct proc_dir_entry *res;
  772. res = proc_mkdir("cpu", NULL);
  773. if (!res)
  774. return -ENOMEM;
  775. return 0;
  776. }
  777. fs_initcall(proc_cpu_init);
  778. #endif
  779. static const char *hwcap_str[] = {
  780. "swp",
  781. "half",
  782. "thumb",
  783. "26bit",
  784. "fastmult",
  785. "fpa",
  786. "vfp",
  787. "edsp",
  788. "java",
  789. "iwmmxt",
  790. "crunch",
  791. "thumbee",
  792. "neon",
  793. "vfpv3",
  794. "vfpv3d16",
  795. NULL
  796. };
  797. static int c_show(struct seq_file *m, void *v)
  798. {
  799. int i;
  800. seq_printf(m, "Processor\t: %s rev %d (%s)\n",
  801. cpu_name, read_cpuid_id() & 15, elf_platform);
  802. #if defined(CONFIG_SMP)
  803. for_each_online_cpu(i) {
  804. /*
  805. * glibc reads /proc/cpuinfo to determine the number of
  806. * online processors, looking for lines beginning with
  807. * "processor". Give glibc what it expects.
  808. */
  809. seq_printf(m, "processor\t: %d\n", i);
  810. seq_printf(m, "BogoMIPS\t: %lu.%02lu\n\n",
  811. per_cpu(cpu_data, i).loops_per_jiffy / (500000UL/HZ),
  812. (per_cpu(cpu_data, i).loops_per_jiffy / (5000UL/HZ)) % 100);
  813. }
  814. #else /* CONFIG_SMP */
  815. seq_printf(m, "BogoMIPS\t: %lu.%02lu\n",
  816. loops_per_jiffy / (500000/HZ),
  817. (loops_per_jiffy / (5000/HZ)) % 100);
  818. #endif
  819. /* dump out the processor features */
  820. seq_puts(m, "Features\t: ");
  821. for (i = 0; hwcap_str[i]; i++)
  822. if (elf_hwcap & (1 << i))
  823. seq_printf(m, "%s ", hwcap_str[i]);
  824. seq_printf(m, "\nCPU implementer\t: 0x%02x\n", read_cpuid_id() >> 24);
  825. seq_printf(m, "CPU architecture: %s\n", proc_arch[cpu_architecture()]);
  826. if ((read_cpuid_id() & 0x0008f000) == 0x00000000) {
  827. /* pre-ARM7 */
  828. seq_printf(m, "CPU part\t: %07x\n", read_cpuid_id() >> 4);
  829. } else {
  830. if ((read_cpuid_id() & 0x0008f000) == 0x00007000) {
  831. /* ARM7 */
  832. seq_printf(m, "CPU variant\t: 0x%02x\n",
  833. (read_cpuid_id() >> 16) & 127);
  834. } else {
  835. /* post-ARM7 */
  836. seq_printf(m, "CPU variant\t: 0x%x\n",
  837. (read_cpuid_id() >> 20) & 15);
  838. }
  839. seq_printf(m, "CPU part\t: 0x%03x\n",
  840. (read_cpuid_id() >> 4) & 0xfff);
  841. }
  842. seq_printf(m, "CPU revision\t: %d\n", read_cpuid_id() & 15);
  843. seq_puts(m, "\n");
  844. seq_printf(m, "Hardware\t: %s\n", machine_name);
  845. seq_printf(m, "Revision\t: %04x\n", system_rev);
  846. seq_printf(m, "Serial\t\t: %08x%08x\n",
  847. system_serial_high, system_serial_low);
  848. return 0;
  849. }
  850. static void *c_start(struct seq_file *m, loff_t *pos)
  851. {
  852. return *pos < 1 ? (void *)1 : NULL;
  853. }
  854. static void *c_next(struct seq_file *m, void *v, loff_t *pos)
  855. {
  856. ++*pos;
  857. return NULL;
  858. }
  859. static void c_stop(struct seq_file *m, void *v)
  860. {
  861. }
  862. const struct seq_operations cpuinfo_op = {
  863. .start = c_start,
  864. .next = c_next,
  865. .stop = c_stop,
  866. .show = c_show
  867. };