setup.c 25 KB

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