setup.c 26 KB

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