setup.c 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158
  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/of_iommu.h>
  22. #include <linux/of_platform.h>
  23. #include <linux/init.h>
  24. #include <linux/kexec.h>
  25. #include <linux/of_fdt.h>
  26. #include <linux/cpu.h>
  27. #include <linux/interrupt.h>
  28. #include <linux/smp.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/cp15.h>
  36. #include <asm/cpu.h>
  37. #include <asm/cputype.h>
  38. #include <asm/elf.h>
  39. #include <asm/procinfo.h>
  40. #include <asm/psci.h>
  41. #include <asm/sections.h>
  42. #include <asm/setup.h>
  43. #include <asm/smp_plat.h>
  44. #include <asm/mach-types.h>
  45. #include <asm/cacheflush.h>
  46. #include <asm/cachetype.h>
  47. #include <asm/tlbflush.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/system_info.h>
  53. #include <asm/system_misc.h>
  54. #include <asm/traps.h>
  55. #include <asm/unwind.h>
  56. #include <asm/memblock.h>
  57. #include <asm/virt.h>
  58. #include "atags.h"
  59. #if defined(CONFIG_FPE_NWFPE) || defined(CONFIG_FPE_FASTFPE)
  60. char fpe_type[8];
  61. static int __init fpe_setup(char *line)
  62. {
  63. memcpy(fpe_type, line, 8);
  64. return 1;
  65. }
  66. __setup("fpe=", fpe_setup);
  67. #endif
  68. extern void init_default_cache_policy(unsigned long);
  69. extern void paging_init(const struct machine_desc *desc);
  70. extern void early_paging_init(const struct machine_desc *);
  71. extern void sanity_check_meminfo(void);
  72. extern enum reboot_mode reboot_mode;
  73. extern void setup_dma_zone(const struct machine_desc *desc);
  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. const char *system_serial;
  84. EXPORT_SYMBOL(system_serial);
  85. unsigned int system_serial_low;
  86. EXPORT_SYMBOL(system_serial_low);
  87. unsigned int system_serial_high;
  88. EXPORT_SYMBOL(system_serial_high);
  89. unsigned int elf_hwcap __read_mostly;
  90. EXPORT_SYMBOL(elf_hwcap);
  91. unsigned int elf_hwcap2 __read_mostly;
  92. EXPORT_SYMBOL(elf_hwcap2);
  93. #ifdef MULTI_CPU
  94. struct processor processor __read_mostly;
  95. #endif
  96. #ifdef MULTI_TLB
  97. struct cpu_tlb_fns cpu_tlb __read_mostly;
  98. #endif
  99. #ifdef MULTI_USER
  100. struct cpu_user_fns cpu_user __read_mostly;
  101. #endif
  102. #ifdef MULTI_CACHE
  103. struct cpu_cache_fns cpu_cache __read_mostly;
  104. #endif
  105. #ifdef CONFIG_OUTER_CACHE
  106. struct outer_cache_fns outer_cache __read_mostly;
  107. EXPORT_SYMBOL(outer_cache);
  108. #endif
  109. /*
  110. * Cached cpu_architecture() result for use by assembler code.
  111. * C code should use the cpu_architecture() function instead of accessing this
  112. * variable directly.
  113. */
  114. int __cpu_architecture __read_mostly = CPU_ARCH_UNKNOWN;
  115. struct stack {
  116. u32 irq[3];
  117. u32 abt[3];
  118. u32 und[3];
  119. u32 fiq[3];
  120. } ____cacheline_aligned;
  121. #ifndef CONFIG_CPU_V7M
  122. static struct stack stacks[NR_CPUS];
  123. #endif
  124. char elf_platform[ELF_PLATFORM_SIZE];
  125. EXPORT_SYMBOL(elf_platform);
  126. static const char *cpu_name;
  127. static const char *machine_name;
  128. static char __initdata cmd_line[COMMAND_LINE_SIZE];
  129. const struct machine_desc *machine_desc __initdata;
  130. static union { char c[4]; unsigned long l; } endian_test __initdata = { { 'l', '?', '?', 'b' } };
  131. #define ENDIANNESS ((char)endian_test.l)
  132. DEFINE_PER_CPU(struct cpuinfo_arm, cpu_data);
  133. /*
  134. * Standard memory resources
  135. */
  136. static struct resource mem_res[] = {
  137. {
  138. .name = "Video RAM",
  139. .start = 0,
  140. .end = 0,
  141. .flags = IORESOURCE_MEM
  142. },
  143. {
  144. .name = "Kernel code",
  145. .start = 0,
  146. .end = 0,
  147. .flags = IORESOURCE_MEM
  148. },
  149. {
  150. .name = "Kernel data",
  151. .start = 0,
  152. .end = 0,
  153. .flags = IORESOURCE_MEM
  154. }
  155. };
  156. #define video_ram mem_res[0]
  157. #define kernel_code mem_res[1]
  158. #define kernel_data mem_res[2]
  159. static struct resource io_res[] = {
  160. {
  161. .name = "reserved",
  162. .start = 0x3bc,
  163. .end = 0x3be,
  164. .flags = IORESOURCE_IO | IORESOURCE_BUSY
  165. },
  166. {
  167. .name = "reserved",
  168. .start = 0x378,
  169. .end = 0x37f,
  170. .flags = IORESOURCE_IO | IORESOURCE_BUSY
  171. },
  172. {
  173. .name = "reserved",
  174. .start = 0x278,
  175. .end = 0x27f,
  176. .flags = IORESOURCE_IO | IORESOURCE_BUSY
  177. }
  178. };
  179. #define lp0 io_res[0]
  180. #define lp1 io_res[1]
  181. #define lp2 io_res[2]
  182. static const char *proc_arch[] = {
  183. "undefined/unknown",
  184. "3",
  185. "4",
  186. "4T",
  187. "5",
  188. "5T",
  189. "5TE",
  190. "5TEJ",
  191. "6TEJ",
  192. "7",
  193. "7M",
  194. "?(12)",
  195. "?(13)",
  196. "?(14)",
  197. "?(15)",
  198. "?(16)",
  199. "?(17)",
  200. };
  201. #ifdef CONFIG_CPU_V7M
  202. static int __get_cpu_architecture(void)
  203. {
  204. return CPU_ARCH_ARMv7M;
  205. }
  206. #else
  207. static int __get_cpu_architecture(void)
  208. {
  209. int cpu_arch;
  210. if ((read_cpuid_id() & 0x0008f000) == 0) {
  211. cpu_arch = CPU_ARCH_UNKNOWN;
  212. } else if ((read_cpuid_id() & 0x0008f000) == 0x00007000) {
  213. cpu_arch = (read_cpuid_id() & (1 << 23)) ? CPU_ARCH_ARMv4T : CPU_ARCH_ARMv3;
  214. } else if ((read_cpuid_id() & 0x00080000) == 0x00000000) {
  215. cpu_arch = (read_cpuid_id() >> 16) & 7;
  216. if (cpu_arch)
  217. cpu_arch += CPU_ARCH_ARMv3;
  218. } else if ((read_cpuid_id() & 0x000f0000) == 0x000f0000) {
  219. /* Revised CPUID format. Read the Memory Model Feature
  220. * Register 0 and check for VMSAv7 or PMSAv7 */
  221. unsigned int mmfr0 = read_cpuid_ext(CPUID_EXT_MMFR0);
  222. if ((mmfr0 & 0x0000000f) >= 0x00000003 ||
  223. (mmfr0 & 0x000000f0) >= 0x00000030)
  224. cpu_arch = CPU_ARCH_ARMv7;
  225. else if ((mmfr0 & 0x0000000f) == 0x00000002 ||
  226. (mmfr0 & 0x000000f0) == 0x00000020)
  227. cpu_arch = CPU_ARCH_ARMv6;
  228. else
  229. cpu_arch = CPU_ARCH_UNKNOWN;
  230. } else
  231. cpu_arch = CPU_ARCH_UNKNOWN;
  232. return cpu_arch;
  233. }
  234. #endif
  235. int __pure cpu_architecture(void)
  236. {
  237. BUG_ON(__cpu_architecture == CPU_ARCH_UNKNOWN);
  238. return __cpu_architecture;
  239. }
  240. static int cpu_has_aliasing_icache(unsigned int arch)
  241. {
  242. int aliasing_icache;
  243. unsigned int id_reg, num_sets, line_size;
  244. /* PIPT caches never alias. */
  245. if (icache_is_pipt())
  246. return 0;
  247. /* arch specifies the register format */
  248. switch (arch) {
  249. case CPU_ARCH_ARMv7:
  250. asm("mcr p15, 2, %0, c0, c0, 0 @ set CSSELR"
  251. : /* No output operands */
  252. : "r" (1));
  253. isb();
  254. asm("mrc p15, 1, %0, c0, c0, 0 @ read CCSIDR"
  255. : "=r" (id_reg));
  256. line_size = 4 << ((id_reg & 0x7) + 2);
  257. num_sets = ((id_reg >> 13) & 0x7fff) + 1;
  258. aliasing_icache = (line_size * num_sets) > PAGE_SIZE;
  259. break;
  260. case CPU_ARCH_ARMv6:
  261. aliasing_icache = read_cpuid_cachetype() & (1 << 11);
  262. break;
  263. default:
  264. /* I-cache aliases will be handled by D-cache aliasing code */
  265. aliasing_icache = 0;
  266. }
  267. return aliasing_icache;
  268. }
  269. static void __init cacheid_init(void)
  270. {
  271. unsigned int arch = cpu_architecture();
  272. if (arch == CPU_ARCH_ARMv7M) {
  273. cacheid = 0;
  274. } else if (arch >= CPU_ARCH_ARMv6) {
  275. unsigned int cachetype = read_cpuid_cachetype();
  276. if ((cachetype & (7 << 29)) == 4 << 29) {
  277. /* ARMv7 register format */
  278. arch = CPU_ARCH_ARMv7;
  279. cacheid = CACHEID_VIPT_NONALIASING;
  280. switch (cachetype & (3 << 14)) {
  281. case (1 << 14):
  282. cacheid |= CACHEID_ASID_TAGGED;
  283. break;
  284. case (3 << 14):
  285. cacheid |= CACHEID_PIPT;
  286. break;
  287. }
  288. } else {
  289. arch = CPU_ARCH_ARMv6;
  290. if (cachetype & (1 << 23))
  291. cacheid = CACHEID_VIPT_ALIASING;
  292. else
  293. cacheid = CACHEID_VIPT_NONALIASING;
  294. }
  295. if (cpu_has_aliasing_icache(arch))
  296. cacheid |= CACHEID_VIPT_I_ALIASING;
  297. } else {
  298. cacheid = CACHEID_VIVT;
  299. }
  300. pr_info("CPU: %s data cache, %s instruction cache\n",
  301. cache_is_vivt() ? "VIVT" :
  302. cache_is_vipt_aliasing() ? "VIPT aliasing" :
  303. cache_is_vipt_nonaliasing() ? "PIPT / VIPT nonaliasing" : "unknown",
  304. cache_is_vivt() ? "VIVT" :
  305. icache_is_vivt_asid_tagged() ? "VIVT ASID tagged" :
  306. icache_is_vipt_aliasing() ? "VIPT aliasing" :
  307. icache_is_pipt() ? "PIPT" :
  308. cache_is_vipt_nonaliasing() ? "VIPT nonaliasing" : "unknown");
  309. }
  310. /*
  311. * These functions re-use the assembly code in head.S, which
  312. * already provide the required functionality.
  313. */
  314. extern struct proc_info_list *lookup_processor_type(unsigned int);
  315. void __init early_print(const char *str, ...)
  316. {
  317. extern void printascii(const char *);
  318. char buf[256];
  319. va_list ap;
  320. va_start(ap, str);
  321. vsnprintf(buf, sizeof(buf), str, ap);
  322. va_end(ap);
  323. #ifdef CONFIG_DEBUG_LL
  324. printascii(buf);
  325. #endif
  326. printk("%s", buf);
  327. }
  328. static void __init cpuid_init_hwcaps(void)
  329. {
  330. int block;
  331. u32 isar5;
  332. if (cpu_architecture() < CPU_ARCH_ARMv7)
  333. return;
  334. block = cpuid_feature_extract(CPUID_EXT_ISAR0, 24);
  335. if (block >= 2)
  336. elf_hwcap |= HWCAP_IDIVA;
  337. if (block >= 1)
  338. elf_hwcap |= HWCAP_IDIVT;
  339. /* LPAE implies atomic ldrd/strd instructions */
  340. block = cpuid_feature_extract(CPUID_EXT_MMFR0, 0);
  341. if (block >= 5)
  342. elf_hwcap |= HWCAP_LPAE;
  343. /* check for supported v8 Crypto instructions */
  344. isar5 = read_cpuid_ext(CPUID_EXT_ISAR5);
  345. block = cpuid_feature_extract_field(isar5, 4);
  346. if (block >= 2)
  347. elf_hwcap2 |= HWCAP2_PMULL;
  348. if (block >= 1)
  349. elf_hwcap2 |= HWCAP2_AES;
  350. block = cpuid_feature_extract_field(isar5, 8);
  351. if (block >= 1)
  352. elf_hwcap2 |= HWCAP2_SHA1;
  353. block = cpuid_feature_extract_field(isar5, 12);
  354. if (block >= 1)
  355. elf_hwcap2 |= HWCAP2_SHA2;
  356. block = cpuid_feature_extract_field(isar5, 16);
  357. if (block >= 1)
  358. elf_hwcap2 |= HWCAP2_CRC32;
  359. }
  360. static void __init elf_hwcap_fixup(void)
  361. {
  362. unsigned id = read_cpuid_id();
  363. /*
  364. * HWCAP_TLS is available only on 1136 r1p0 and later,
  365. * see also kuser_get_tls_init.
  366. */
  367. if (read_cpuid_part() == ARM_CPU_PART_ARM1136 &&
  368. ((id >> 20) & 3) == 0) {
  369. elf_hwcap &= ~HWCAP_TLS;
  370. return;
  371. }
  372. /* Verify if CPUID scheme is implemented */
  373. if ((id & 0x000f0000) != 0x000f0000)
  374. return;
  375. /*
  376. * If the CPU supports LDREX/STREX and LDREXB/STREXB,
  377. * avoid advertising SWP; it may not be atomic with
  378. * multiprocessing cores.
  379. */
  380. if (cpuid_feature_extract(CPUID_EXT_ISAR3, 12) > 1 ||
  381. (cpuid_feature_extract(CPUID_EXT_ISAR3, 12) == 1 &&
  382. cpuid_feature_extract(CPUID_EXT_ISAR3, 20) >= 3))
  383. elf_hwcap &= ~HWCAP_SWP;
  384. }
  385. /*
  386. * cpu_init - initialise one CPU.
  387. *
  388. * cpu_init sets up the per-CPU stacks.
  389. */
  390. void notrace cpu_init(void)
  391. {
  392. #ifndef CONFIG_CPU_V7M
  393. unsigned int cpu = smp_processor_id();
  394. struct stack *stk = &stacks[cpu];
  395. if (cpu >= NR_CPUS) {
  396. pr_crit("CPU%u: bad primary CPU number\n", cpu);
  397. BUG();
  398. }
  399. /*
  400. * This only works on resume and secondary cores. For booting on the
  401. * boot cpu, smp_prepare_boot_cpu is called after percpu area setup.
  402. */
  403. set_my_cpu_offset(per_cpu_offset(cpu));
  404. cpu_proc_init();
  405. /*
  406. * Define the placement constraint for the inline asm directive below.
  407. * In Thumb-2, msr with an immediate value is not allowed.
  408. */
  409. #ifdef CONFIG_THUMB2_KERNEL
  410. #define PLC "r"
  411. #else
  412. #define PLC "I"
  413. #endif
  414. /*
  415. * setup stacks for re-entrant exception handlers
  416. */
  417. __asm__ (
  418. "msr cpsr_c, %1\n\t"
  419. "add r14, %0, %2\n\t"
  420. "mov sp, r14\n\t"
  421. "msr cpsr_c, %3\n\t"
  422. "add r14, %0, %4\n\t"
  423. "mov sp, r14\n\t"
  424. "msr cpsr_c, %5\n\t"
  425. "add r14, %0, %6\n\t"
  426. "mov sp, r14\n\t"
  427. "msr cpsr_c, %7\n\t"
  428. "add r14, %0, %8\n\t"
  429. "mov sp, r14\n\t"
  430. "msr cpsr_c, %9"
  431. :
  432. : "r" (stk),
  433. PLC (PSR_F_BIT | PSR_I_BIT | IRQ_MODE),
  434. "I" (offsetof(struct stack, irq[0])),
  435. PLC (PSR_F_BIT | PSR_I_BIT | ABT_MODE),
  436. "I" (offsetof(struct stack, abt[0])),
  437. PLC (PSR_F_BIT | PSR_I_BIT | UND_MODE),
  438. "I" (offsetof(struct stack, und[0])),
  439. PLC (PSR_F_BIT | PSR_I_BIT | FIQ_MODE),
  440. "I" (offsetof(struct stack, fiq[0])),
  441. PLC (PSR_F_BIT | PSR_I_BIT | SVC_MODE)
  442. : "r14");
  443. #endif
  444. }
  445. u32 __cpu_logical_map[NR_CPUS] = { [0 ... NR_CPUS-1] = MPIDR_INVALID };
  446. void __init smp_setup_processor_id(void)
  447. {
  448. int i;
  449. u32 mpidr = is_smp() ? read_cpuid_mpidr() & MPIDR_HWID_BITMASK : 0;
  450. u32 cpu = MPIDR_AFFINITY_LEVEL(mpidr, 0);
  451. cpu_logical_map(0) = cpu;
  452. for (i = 1; i < nr_cpu_ids; ++i)
  453. cpu_logical_map(i) = i == cpu ? 0 : i;
  454. /*
  455. * clear __my_cpu_offset on boot CPU to avoid hang caused by
  456. * using percpu variable early, for example, lockdep will
  457. * access percpu variable inside lock_release
  458. */
  459. set_my_cpu_offset(0);
  460. pr_info("Booting Linux on physical CPU 0x%x\n", mpidr);
  461. }
  462. struct mpidr_hash mpidr_hash;
  463. #ifdef CONFIG_SMP
  464. /**
  465. * smp_build_mpidr_hash - Pre-compute shifts required at each affinity
  466. * level in order to build a linear index from an
  467. * MPIDR value. Resulting algorithm is a collision
  468. * free hash carried out through shifting and ORing
  469. */
  470. static void __init smp_build_mpidr_hash(void)
  471. {
  472. u32 i, affinity;
  473. u32 fs[3], bits[3], ls, mask = 0;
  474. /*
  475. * Pre-scan the list of MPIDRS and filter out bits that do
  476. * not contribute to affinity levels, ie they never toggle.
  477. */
  478. for_each_possible_cpu(i)
  479. mask |= (cpu_logical_map(i) ^ cpu_logical_map(0));
  480. pr_debug("mask of set bits 0x%x\n", mask);
  481. /*
  482. * Find and stash the last and first bit set at all affinity levels to
  483. * check how many bits are required to represent them.
  484. */
  485. for (i = 0; i < 3; i++) {
  486. affinity = MPIDR_AFFINITY_LEVEL(mask, i);
  487. /*
  488. * Find the MSB bit and LSB bits position
  489. * to determine how many bits are required
  490. * to express the affinity level.
  491. */
  492. ls = fls(affinity);
  493. fs[i] = affinity ? ffs(affinity) - 1 : 0;
  494. bits[i] = ls - fs[i];
  495. }
  496. /*
  497. * An index can be created from the MPIDR by isolating the
  498. * significant bits at each affinity level and by shifting
  499. * them in order to compress the 24 bits values space to a
  500. * compressed set of values. This is equivalent to hashing
  501. * the MPIDR through shifting and ORing. It is a collision free
  502. * hash though not minimal since some levels might contain a number
  503. * of CPUs that is not an exact power of 2 and their bit
  504. * representation might contain holes, eg MPIDR[7:0] = {0x2, 0x80}.
  505. */
  506. mpidr_hash.shift_aff[0] = fs[0];
  507. mpidr_hash.shift_aff[1] = MPIDR_LEVEL_BITS + fs[1] - bits[0];
  508. mpidr_hash.shift_aff[2] = 2*MPIDR_LEVEL_BITS + fs[2] -
  509. (bits[1] + bits[0]);
  510. mpidr_hash.mask = mask;
  511. mpidr_hash.bits = bits[2] + bits[1] + bits[0];
  512. pr_debug("MPIDR hash: aff0[%u] aff1[%u] aff2[%u] mask[0x%x] bits[%u]\n",
  513. mpidr_hash.shift_aff[0],
  514. mpidr_hash.shift_aff[1],
  515. mpidr_hash.shift_aff[2],
  516. mpidr_hash.mask,
  517. mpidr_hash.bits);
  518. /*
  519. * 4x is an arbitrary value used to warn on a hash table much bigger
  520. * than expected on most systems.
  521. */
  522. if (mpidr_hash_size() > 4 * num_possible_cpus())
  523. pr_warn("Large number of MPIDR hash buckets detected\n");
  524. sync_cache_w(&mpidr_hash);
  525. }
  526. #endif
  527. static void __init setup_processor(void)
  528. {
  529. struct proc_info_list *list;
  530. /*
  531. * locate processor in the list of supported processor
  532. * types. The linker builds this table for us from the
  533. * entries in arch/arm/mm/proc-*.S
  534. */
  535. list = lookup_processor_type(read_cpuid_id());
  536. if (!list) {
  537. pr_err("CPU configuration botched (ID %08x), unable to continue.\n",
  538. read_cpuid_id());
  539. while (1);
  540. }
  541. cpu_name = list->cpu_name;
  542. __cpu_architecture = __get_cpu_architecture();
  543. #ifdef MULTI_CPU
  544. processor = *list->proc;
  545. #endif
  546. #ifdef MULTI_TLB
  547. cpu_tlb = *list->tlb;
  548. #endif
  549. #ifdef MULTI_USER
  550. cpu_user = *list->user;
  551. #endif
  552. #ifdef MULTI_CACHE
  553. cpu_cache = *list->cache;
  554. #endif
  555. pr_info("CPU: %s [%08x] revision %d (ARMv%s), cr=%08lx\n",
  556. cpu_name, read_cpuid_id(), read_cpuid_id() & 15,
  557. proc_arch[cpu_architecture()], get_cr());
  558. snprintf(init_utsname()->machine, __NEW_UTS_LEN + 1, "%s%c",
  559. list->arch_name, ENDIANNESS);
  560. snprintf(elf_platform, ELF_PLATFORM_SIZE, "%s%c",
  561. list->elf_name, ENDIANNESS);
  562. elf_hwcap = list->elf_hwcap;
  563. cpuid_init_hwcaps();
  564. #ifndef CONFIG_ARM_THUMB
  565. elf_hwcap &= ~(HWCAP_THUMB | HWCAP_IDIVT);
  566. #endif
  567. #ifdef CONFIG_MMU
  568. init_default_cache_policy(list->__cpu_mm_mmu_flags);
  569. #endif
  570. erratum_a15_798181_init();
  571. elf_hwcap_fixup();
  572. cacheid_init();
  573. cpu_init();
  574. }
  575. void __init dump_machine_table(void)
  576. {
  577. const struct machine_desc *p;
  578. early_print("Available machine support:\n\nID (hex)\tNAME\n");
  579. for_each_machine_desc(p)
  580. early_print("%08x\t%s\n", p->nr, p->name);
  581. early_print("\nPlease check your kernel config and/or bootloader.\n");
  582. while (true)
  583. /* can't use cpu_relax() here as it may require MMU setup */;
  584. }
  585. int __init arm_add_memory(u64 start, u64 size)
  586. {
  587. u64 aligned_start;
  588. /*
  589. * Ensure that start/size are aligned to a page boundary.
  590. * Size is rounded down, start is rounded up.
  591. */
  592. aligned_start = PAGE_ALIGN(start);
  593. if (aligned_start > start + size)
  594. size = 0;
  595. else
  596. size -= aligned_start - start;
  597. #ifndef CONFIG_ARCH_PHYS_ADDR_T_64BIT
  598. if (aligned_start > ULONG_MAX) {
  599. pr_crit("Ignoring memory at 0x%08llx outside 32-bit physical address space\n",
  600. (long long)start);
  601. return -EINVAL;
  602. }
  603. if (aligned_start + size > ULONG_MAX) {
  604. pr_crit("Truncating memory at 0x%08llx to fit in 32-bit physical address space\n",
  605. (long long)start);
  606. /*
  607. * To ensure bank->start + bank->size is representable in
  608. * 32 bits, we use ULONG_MAX as the upper limit rather than 4GB.
  609. * This means we lose a page after masking.
  610. */
  611. size = ULONG_MAX - aligned_start;
  612. }
  613. #endif
  614. if (aligned_start < PHYS_OFFSET) {
  615. if (aligned_start + size <= PHYS_OFFSET) {
  616. pr_info("Ignoring memory below PHYS_OFFSET: 0x%08llx-0x%08llx\n",
  617. aligned_start, aligned_start + size);
  618. return -EINVAL;
  619. }
  620. pr_info("Ignoring memory below PHYS_OFFSET: 0x%08llx-0x%08llx\n",
  621. aligned_start, (u64)PHYS_OFFSET);
  622. size -= PHYS_OFFSET - aligned_start;
  623. aligned_start = PHYS_OFFSET;
  624. }
  625. start = aligned_start;
  626. size = size & ~(phys_addr_t)(PAGE_SIZE - 1);
  627. /*
  628. * Check whether this memory region has non-zero size or
  629. * invalid node number.
  630. */
  631. if (size == 0)
  632. return -EINVAL;
  633. memblock_add(start, size);
  634. return 0;
  635. }
  636. /*
  637. * Pick out the memory size. We look for mem=size@start,
  638. * where start and size are "size[KkMm]"
  639. */
  640. static int __init early_mem(char *p)
  641. {
  642. static int usermem __initdata = 0;
  643. u64 size;
  644. u64 start;
  645. char *endp;
  646. /*
  647. * If the user specifies memory size, we
  648. * blow away any automatically generated
  649. * size.
  650. */
  651. if (usermem == 0) {
  652. usermem = 1;
  653. memblock_remove(memblock_start_of_DRAM(),
  654. memblock_end_of_DRAM() - memblock_start_of_DRAM());
  655. }
  656. start = PHYS_OFFSET;
  657. size = memparse(p, &endp);
  658. if (*endp == '@')
  659. start = memparse(endp + 1, NULL);
  660. arm_add_memory(start, size);
  661. return 0;
  662. }
  663. early_param("mem", early_mem);
  664. static void __init request_standard_resources(const struct machine_desc *mdesc)
  665. {
  666. struct memblock_region *region;
  667. struct resource *res;
  668. kernel_code.start = virt_to_phys(_text);
  669. kernel_code.end = virt_to_phys(_etext - 1);
  670. kernel_data.start = virt_to_phys(_sdata);
  671. kernel_data.end = virt_to_phys(_end - 1);
  672. for_each_memblock(memory, region) {
  673. res = memblock_virt_alloc(sizeof(*res), 0);
  674. res->name = "System RAM";
  675. res->start = __pfn_to_phys(memblock_region_memory_base_pfn(region));
  676. res->end = __pfn_to_phys(memblock_region_memory_end_pfn(region)) - 1;
  677. res->flags = IORESOURCE_MEM | IORESOURCE_BUSY;
  678. request_resource(&iomem_resource, res);
  679. if (kernel_code.start >= res->start &&
  680. kernel_code.end <= res->end)
  681. request_resource(res, &kernel_code);
  682. if (kernel_data.start >= res->start &&
  683. kernel_data.end <= res->end)
  684. request_resource(res, &kernel_data);
  685. }
  686. if (mdesc->video_start) {
  687. video_ram.start = mdesc->video_start;
  688. video_ram.end = mdesc->video_end;
  689. request_resource(&iomem_resource, &video_ram);
  690. }
  691. /*
  692. * Some machines don't have the possibility of ever
  693. * possessing lp0, lp1 or lp2
  694. */
  695. if (mdesc->reserve_lp0)
  696. request_resource(&ioport_resource, &lp0);
  697. if (mdesc->reserve_lp1)
  698. request_resource(&ioport_resource, &lp1);
  699. if (mdesc->reserve_lp2)
  700. request_resource(&ioport_resource, &lp2);
  701. }
  702. #if defined(CONFIG_VGA_CONSOLE) || defined(CONFIG_DUMMY_CONSOLE)
  703. struct screen_info screen_info = {
  704. .orig_video_lines = 30,
  705. .orig_video_cols = 80,
  706. .orig_video_mode = 0,
  707. .orig_video_ega_bx = 0,
  708. .orig_video_isVGA = 1,
  709. .orig_video_points = 8
  710. };
  711. #endif
  712. static int __init customize_machine(void)
  713. {
  714. /*
  715. * customizes platform devices, or adds new ones
  716. * On DT based machines, we fall back to populating the
  717. * machine from the device tree, if no callback is provided,
  718. * otherwise we would always need an init_machine callback.
  719. */
  720. of_iommu_init();
  721. if (machine_desc->init_machine)
  722. machine_desc->init_machine();
  723. #ifdef CONFIG_OF
  724. else
  725. of_platform_populate(NULL, of_default_bus_match_table,
  726. NULL, NULL);
  727. #endif
  728. return 0;
  729. }
  730. arch_initcall(customize_machine);
  731. static int __init init_machine_late(void)
  732. {
  733. struct device_node *root;
  734. int ret;
  735. if (machine_desc->init_late)
  736. machine_desc->init_late();
  737. root = of_find_node_by_path("/");
  738. if (root) {
  739. ret = of_property_read_string(root, "serial-number",
  740. &system_serial);
  741. if (ret)
  742. system_serial = NULL;
  743. }
  744. if (!system_serial)
  745. system_serial = kasprintf(GFP_KERNEL, "%08x%08x",
  746. system_serial_high,
  747. system_serial_low);
  748. return 0;
  749. }
  750. late_initcall(init_machine_late);
  751. #ifdef CONFIG_KEXEC
  752. static inline unsigned long long get_total_mem(void)
  753. {
  754. unsigned long total;
  755. total = max_low_pfn - min_low_pfn;
  756. return total << PAGE_SHIFT;
  757. }
  758. /**
  759. * reserve_crashkernel() - reserves memory are for crash kernel
  760. *
  761. * This function reserves memory area given in "crashkernel=" kernel command
  762. * line parameter. The memory reserved is used by a dump capture kernel when
  763. * primary kernel is crashing.
  764. */
  765. static void __init reserve_crashkernel(void)
  766. {
  767. unsigned long long crash_size, crash_base;
  768. unsigned long long total_mem;
  769. int ret;
  770. total_mem = get_total_mem();
  771. ret = parse_crashkernel(boot_command_line, total_mem,
  772. &crash_size, &crash_base);
  773. if (ret)
  774. return;
  775. ret = memblock_reserve(crash_base, crash_size);
  776. if (ret < 0) {
  777. pr_warn("crashkernel reservation failed - memory is in use (0x%lx)\n",
  778. (unsigned long)crash_base);
  779. return;
  780. }
  781. pr_info("Reserving %ldMB of memory at %ldMB for crashkernel (System RAM: %ldMB)\n",
  782. (unsigned long)(crash_size >> 20),
  783. (unsigned long)(crash_base >> 20),
  784. (unsigned long)(total_mem >> 20));
  785. crashk_res.start = crash_base;
  786. crashk_res.end = crash_base + crash_size - 1;
  787. insert_resource(&iomem_resource, &crashk_res);
  788. }
  789. #else
  790. static inline void reserve_crashkernel(void) {}
  791. #endif /* CONFIG_KEXEC */
  792. void __init hyp_mode_check(void)
  793. {
  794. #ifdef CONFIG_ARM_VIRT_EXT
  795. sync_boot_mode();
  796. if (is_hyp_mode_available()) {
  797. pr_info("CPU: All CPU(s) started in HYP mode.\n");
  798. pr_info("CPU: Virtualization extensions available.\n");
  799. } else if (is_hyp_mode_mismatched()) {
  800. pr_warn("CPU: WARNING: CPU(s) started in wrong/inconsistent modes (primary CPU mode 0x%x)\n",
  801. __boot_cpu_mode & MODE_MASK);
  802. pr_warn("CPU: This may indicate a broken bootloader or firmware.\n");
  803. } else
  804. pr_info("CPU: All CPU(s) started in SVC mode.\n");
  805. #endif
  806. }
  807. void __init setup_arch(char **cmdline_p)
  808. {
  809. const struct machine_desc *mdesc;
  810. setup_processor();
  811. mdesc = setup_machine_fdt(__atags_pointer);
  812. if (!mdesc)
  813. mdesc = setup_machine_tags(__atags_pointer, __machine_arch_type);
  814. machine_desc = mdesc;
  815. machine_name = mdesc->name;
  816. dump_stack_set_arch_desc("%s", mdesc->name);
  817. if (mdesc->reboot_mode != REBOOT_HARD)
  818. reboot_mode = mdesc->reboot_mode;
  819. init_mm.start_code = (unsigned long) _text;
  820. init_mm.end_code = (unsigned long) _etext;
  821. init_mm.end_data = (unsigned long) _edata;
  822. init_mm.brk = (unsigned long) _end;
  823. /* populate cmd_line too for later use, preserving boot_command_line */
  824. strlcpy(cmd_line, boot_command_line, COMMAND_LINE_SIZE);
  825. *cmdline_p = cmd_line;
  826. parse_early_param();
  827. #ifdef CONFIG_MMU
  828. early_paging_init(mdesc);
  829. #endif
  830. setup_dma_zone(mdesc);
  831. sanity_check_meminfo();
  832. arm_memblock_init(mdesc);
  833. paging_init(mdesc);
  834. request_standard_resources(mdesc);
  835. if (mdesc->restart)
  836. arm_pm_restart = mdesc->restart;
  837. unflatten_device_tree();
  838. arm_dt_init_cpu_maps();
  839. psci_init();
  840. #ifdef CONFIG_SMP
  841. if (is_smp()) {
  842. if (!mdesc->smp_init || !mdesc->smp_init()) {
  843. if (psci_smp_available())
  844. smp_set_ops(&psci_smp_ops);
  845. else if (mdesc->smp)
  846. smp_set_ops(mdesc->smp);
  847. }
  848. smp_init_cpus();
  849. smp_build_mpidr_hash();
  850. }
  851. #endif
  852. if (!is_smp())
  853. hyp_mode_check();
  854. reserve_crashkernel();
  855. #ifdef CONFIG_MULTI_IRQ_HANDLER
  856. handle_arch_irq = mdesc->handle_irq;
  857. #endif
  858. #ifdef CONFIG_VT
  859. #if defined(CONFIG_VGA_CONSOLE)
  860. conswitchp = &vga_con;
  861. #elif defined(CONFIG_DUMMY_CONSOLE)
  862. conswitchp = &dummy_con;
  863. #endif
  864. #endif
  865. if (mdesc->init_early)
  866. mdesc->init_early();
  867. }
  868. static int __init topology_init(void)
  869. {
  870. int cpu;
  871. for_each_possible_cpu(cpu) {
  872. struct cpuinfo_arm *cpuinfo = &per_cpu(cpu_data, cpu);
  873. cpuinfo->cpu.hotpluggable = 1;
  874. register_cpu(&cpuinfo->cpu, cpu);
  875. }
  876. return 0;
  877. }
  878. subsys_initcall(topology_init);
  879. #ifdef CONFIG_HAVE_PROC_CPU
  880. static int __init proc_cpu_init(void)
  881. {
  882. struct proc_dir_entry *res;
  883. res = proc_mkdir("cpu", NULL);
  884. if (!res)
  885. return -ENOMEM;
  886. return 0;
  887. }
  888. fs_initcall(proc_cpu_init);
  889. #endif
  890. static const char *hwcap_str[] = {
  891. "swp",
  892. "half",
  893. "thumb",
  894. "26bit",
  895. "fastmult",
  896. "fpa",
  897. "vfp",
  898. "edsp",
  899. "java",
  900. "iwmmxt",
  901. "crunch",
  902. "thumbee",
  903. "neon",
  904. "vfpv3",
  905. "vfpv3d16",
  906. "tls",
  907. "vfpv4",
  908. "idiva",
  909. "idivt",
  910. "vfpd32",
  911. "lpae",
  912. "evtstrm",
  913. NULL
  914. };
  915. static const char *hwcap2_str[] = {
  916. "aes",
  917. "pmull",
  918. "sha1",
  919. "sha2",
  920. "crc32",
  921. NULL
  922. };
  923. static int c_show(struct seq_file *m, void *v)
  924. {
  925. int i, j;
  926. u32 cpuid;
  927. for_each_online_cpu(i) {
  928. /*
  929. * glibc reads /proc/cpuinfo to determine the number of
  930. * online processors, looking for lines beginning with
  931. * "processor". Give glibc what it expects.
  932. */
  933. seq_printf(m, "processor\t: %d\n", i);
  934. cpuid = is_smp() ? per_cpu(cpu_data, i).cpuid : read_cpuid_id();
  935. seq_printf(m, "model name\t: %s rev %d (%s)\n",
  936. cpu_name, cpuid & 15, elf_platform);
  937. #if defined(CONFIG_SMP)
  938. seq_printf(m, "BogoMIPS\t: %lu.%02lu\n",
  939. per_cpu(cpu_data, i).loops_per_jiffy / (500000UL/HZ),
  940. (per_cpu(cpu_data, i).loops_per_jiffy / (5000UL/HZ)) % 100);
  941. #else
  942. seq_printf(m, "BogoMIPS\t: %lu.%02lu\n",
  943. loops_per_jiffy / (500000/HZ),
  944. (loops_per_jiffy / (5000/HZ)) % 100);
  945. #endif
  946. /* dump out the processor features */
  947. seq_puts(m, "Features\t: ");
  948. for (j = 0; hwcap_str[j]; j++)
  949. if (elf_hwcap & (1 << j))
  950. seq_printf(m, "%s ", hwcap_str[j]);
  951. for (j = 0; hwcap2_str[j]; j++)
  952. if (elf_hwcap2 & (1 << j))
  953. seq_printf(m, "%s ", hwcap2_str[j]);
  954. seq_printf(m, "\nCPU implementer\t: 0x%02x\n", cpuid >> 24);
  955. seq_printf(m, "CPU architecture: %s\n",
  956. proc_arch[cpu_architecture()]);
  957. if ((cpuid & 0x0008f000) == 0x00000000) {
  958. /* pre-ARM7 */
  959. seq_printf(m, "CPU part\t: %07x\n", cpuid >> 4);
  960. } else {
  961. if ((cpuid & 0x0008f000) == 0x00007000) {
  962. /* ARM7 */
  963. seq_printf(m, "CPU variant\t: 0x%02x\n",
  964. (cpuid >> 16) & 127);
  965. } else {
  966. /* post-ARM7 */
  967. seq_printf(m, "CPU variant\t: 0x%x\n",
  968. (cpuid >> 20) & 15);
  969. }
  970. seq_printf(m, "CPU part\t: 0x%03x\n",
  971. (cpuid >> 4) & 0xfff);
  972. }
  973. seq_printf(m, "CPU revision\t: %d\n\n", cpuid & 15);
  974. }
  975. seq_printf(m, "Hardware\t: %s\n", machine_name);
  976. seq_printf(m, "Revision\t: %04x\n", system_rev);
  977. seq_printf(m, "Serial\t\t: %s\n", system_serial);
  978. return 0;
  979. }
  980. static void *c_start(struct seq_file *m, loff_t *pos)
  981. {
  982. return *pos < 1 ? (void *)1 : NULL;
  983. }
  984. static void *c_next(struct seq_file *m, void *v, loff_t *pos)
  985. {
  986. ++*pos;
  987. return NULL;
  988. }
  989. static void c_stop(struct seq_file *m, void *v)
  990. {
  991. }
  992. const struct seq_operations cpuinfo_op = {
  993. .start = c_start,
  994. .next = c_next,
  995. .stop = c_stop,
  996. .show = c_show
  997. };