setup.c 27 KB

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