setup.c 27 KB

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