setup.c 27 KB

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